'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs' ]; } else { foreach ( [ 'Mr', 'Ms' ] as $text ) { $text = fqp__( $text ); $multi_options[$text] = $text; } } $fields['prefix'] = [ 'type' => 'radio', 'multi_options' => $multi_options, 'attribs' => [ 'required' => true ], ]; $fields['first_name'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'First Name', 'required' => true, ], ]; $fields['last_name'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'Last Name', 'required' => true, ], ]; $fields['street'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'Street', 'required' => true, ] ]; $fields['zip'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'Zip', 'required' => true, ], ]; $fields['city'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'City', 'required' => true, ], ]; $fields['nationality'] = [ 'type' => 'select', 'label' => 'Nationality', 'multi_options' => FQP\DB::get_nationality(), 'attribs' => [ 'required' => true ], ]; $fields['hometown'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'Hometown', 'class' => 'hidden', ], ]; $fields['birth_date'] = [ 'type' => 'date', 'label' => 'Birth date', 'attribs' => [ 'required' => true, 'placeholder' => ( 'de' == FQP\FQP::get_curr_lang() ) ? 'tt.mm.jjjj' : 'dd.mm.yyyy' ], ]; static::$fields['person'] = $fields; } protected static function init_function_in_company_fields() { $fields = []; if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG ] ) ) { $fields['vr_function_in_company'] = [ 'type' => 'select', 'label' => 'EN VR-Funktion in der Firma', 'multi_options' => FQP\DB::get_vr_function_in_company(), 'description' => 'EN Die AG benötigt zwingend ein Verwaltungsratsmitglied. Soll der Verwaltungsrat aus mehreren Personen bestehen, so muss zwingend eine Person Präsident/ -in des Verwaltungsrates sein.', 'attribs' => [ 'required' => true, ], ]; } if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG, FQP\FQP::ENTRY_TYPE_LTD ] ) ) { $fields['function_in_company'] = [ 'type' => 'select', 'label' => 'Function in the company', 'multi_options' => FQP\DB::get_function_in_company(), 'description' => static::get_function_in_company_description(), 'attribs' => [ 'required' => true, ], ]; } if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG, FQP\FQP::ENTRY_TYPE_LTD, FQP\FQP::ENTRY_TYPE_COLLECTIVE_COMPANY ] ) ) { $fields['signature_authorization'] = [ 'type' => 'select', 'label' => 'EN Zeichnungsberechtigung', 'multi_options' => FQP\DB::get_signature_authorization(), 'attribs' => [ 'required' => true, ], ]; } static::$fields['function_in_company'] = $fields; } protected static function init_company_fields() { $fields = []; $fields['company_name'] = [ 'type' => 'text', 'description' => 'EN Bitte erfassen Sie den Firmennamen des Unternehmens, welches sich an dem zu gründenden Unternehmen beteiligt.', 'attribs' => [ 'placeholder' => 'Company name', 'required' => true, ], ]; $fields['company_address'] = [ 'type' => 'text', 'description' => 'EN Bitte erfassen Sie den Firmensitz des Unternehmens, welches sich an dem zu gründenden Unternehmen beteiligt.', 'attribs' => [ 'placeholder' => 'Company address', 'required' => true, ] ]; $fields['company_zip'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'Zip', 'required' => true, ], ]; $fields['company_city'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'City', 'required' => true, ], ]; $fields['company_country'] = [ 'type' => 'select', 'label' => 'Country', 'multi_options' => FQP\DB::get_nationality(), 'attribs' => [ 'required' => true ], ]; $fields['company_number'] = [ 'type' => 'text', 'attribs' => [ 'placeholder' => 'EN Handelsregisternummer', ], ]; static::$fields['company'] = $fields; } public static function get_fields( $type = 'person' ) { if ( empty( static::$fields[$type] ) ) { $method = "init_{$type}_fields"; if ( ! method_exists( __CLASS__, $method )) { return false; } static::{$method}(); } return static::$fields[$type]; } public static function sanitize_data( &$data ) { if ( !is_array( $data ) ) { $data = []; } $errors = []; $required_msg = fqp__( '%s is required' ); $wrong_fmt_mgs = fqp__( '%s is in wrong format' ); $fields = static::get_fields( $data['person_type'] ); if ( $fields ) { if ( 'person' == $data['person_type'] && ! empty( $data['nationality'] ) && FQP\Shortcode\QuotePrice::NATIONALITY_SWITZERLAND_VAL == $data['nationality'] ) { $fields['hometown']['attribs']['required'] = true; } foreach ( $fields as $name => $specs ) { $title = ( ! empty( $specs['label'] ) ) ? $specs['label'] : $specs['attribs']['placeholder']; $title = fqp__( $title ); if ( @$specs['attribs']['required'] && empty( $data[$name] ) ) { $errors[] = esc_html( sprintf( $required_msg, $title ) ); } else { if ( in_array( $name, [ 'zip', 'company_zip'] ) && ! empty( $data[$name] ) ) { if ( ! preg_match( FQP\FQP::NUMERIC_REGEX, $data[$name] ) ) { $errors[] = esc_html( sprintf( $wrong_fmt_mgs, $title ) ); } } } } } else { $errors[] = 'Unknown person type!'; } if ( ! preg_match( '/^\d{1,2}\.\d{1,2}\.\d{4}$/', $data['birth_date'] ) ) { $errors[] = esc_html( sprintf( $wrong_fmt_mgs, fqp__( 'Birth date' ) ) ); } return ( empty( $errors ) ) ? true : $errors; } public static function get_filter_fields() { return []; } public static function filter_data( &$data ) { $fields['person'] = static::get_fields( 'person' ) + static::get_fields( 'function_in_company' ); $fields['company'] = static::get_fields( 'company' ) + static::get_fields( 'person' ); $filtered = []; foreach ( array_keys( $fields ) as $type ) { if ( ! empty( $data[$type] ) ) { foreach ( $data[$type] as $person_id => $person) { foreach ( array_keys( $fields[$type] ) as $field ) { $filtered[$type][$person_id][$field] = fqp_array_get( $person, $field ); } } } } $data = $filtered; } }