/**
  * Here's our custom validation callback
  */
 static function myRules($values)
 {
     $errors = array();
     // Default checks
     // check contact id
     $contact_id = CRM_Utils_Array::value('contact_id', $values);
     if (!isset($contact_id) or empty($contact_id)) {
         // contact id exists or empty
         $errors['contact_id'] = ts('Contact id bestaat niet of is leeg !');
     } else {
         if (!is_numeric($contact_id)) {
             // contact id is not a number
             $errors['contact_id'] = ts('Contact id is geen nummer !');
         }
     }
     // check request
     $request = CRM_Utils_Array::value('request', $values);
     if (!isset($request) or empty($request)) {
         // contact id exists or empty
         $errors['request'] = ts('Aanvraag bestaat niet of is leeg !');
     }
     // empty
     if ('empty' == $request) {
     }
     // choose
     if ('choose' == $request) {
         // check relationship_id
         $membership_id = CRM_Utils_Array::value('membership_id', $values);
         if (!isset($membership_id) or empty($membership_id)) {
             // exists or empty
             $errors['membership_id'] = ts('Lidmaatschap id a bestaat niet of is leeg !');
         } else {
             if (!is_numeric($membership_id)) {
                 // is not a number
                 $errors['membership_id'] = ts('Lidmaatschap id a is geen nummer !');
             }
         }
     }
     // update
     if ('update' == $request) {
         // check relationship_id
         $membership_id = CRM_Utils_Array::value('membership_id', $values);
         if (!isset($membership_id) or empty($membership_id)) {
             // exists or empty
             $errors['membership_id'] = ts('Lidmaatschap id a bestaat niet of is leeg !');
         } else {
             if (!is_numeric($membership_id)) {
                 // is not a number
                 $errors['membership_id'] = ts('Lidmaatschap id a is geen nummer !');
             }
         }
         // check end_date
         if (isset($values['end_date']) and !empty($values['end_date'])) {
             if ($values['start_date'] > $values['end_date']) {
                 $errors['end_date'] = ts('Einddatum moet gelijk of later dan de begindatum zijn.');
             }
         }
         // check custom fields
         $configMembership = CRM_Lidmaatschapwijziging_ConfigMembership::singleton($values['contact_id']);
         // Vnv Info
         // we do not need all the fields
         $lidmaatschapMaatschappijFields = $configMembership->getMembershipCustomFieldsByName();
         $lidmaatschapMaatschappijFieldsNeeded = array('Maatschappij_lid', 'Maatschappij_anders');
         $customFields = array();
         foreach ($lidmaatschapMaatschappijFieldsNeeded as $key => $name) {
             $customFields[$name] = $lidmaatschapMaatschappijFields[$name];
         }
         // return can be empty if there is no error
         $errors = array_merge($errors, CRM_Lidmaatschapwijziging_ValidateCustomFields::Validate($customFields, $values));
     }
     return empty($errors) ? TRUE : $errors;
 }
 /**
  * Here's our custom validation callback
  */
 static function myRules($values)
 {
     $errors = array();
     // check contact_id
     $contact_id = CRM_Utils_Array::value('contact_id', $values);
     if (!isset($contact_id) or empty($contact_id)) {
         // contact id exists or empty
         $errors['contact_id'] = ts('Contact id bestaat niet of is leeg !');
     } else {
         if (!is_numeric($contact_id)) {
             // contact id is not a number
             $errors['contact_id'] = ts('Contact id is geen nummer !');
         }
     }
     // check custom fields
     $configRegiOplBel = CRM_Lidmaatschapwijziging_ConfigRegistratieOpleidingBelangstelling::singleton($values['contact_id']);
     // we do not need all the fields
     $regiOplBelFields = $configRegiOplBel->getRegiOplBelCustomFieldsByName();
     $regiOplBelFieldsOptions = $configRegiOplBel->getRegiOplBelCustomFieldsOptionValues();
     $regiOplBelFieldsNeeded = array('Luchtvaartopleiding', 'Vliegschool', 'Vliegschool_anders_namelijk_', 'Vooropleiding', 'Vooropleiding__Anders', 'Overige_opleiding', 'Overige_opleiding__t_w_', 'Nevenfuncties__Activiteiten__vroeger_', 'Nevenfuncties__Activiteiten__huidige_', 'Eventuele_vorige_werkgevers_en_werkervaring', 'Aanvang_opleiding', 'Afronding_opleiding', 'Algemene_onderwerpen', 'Commissies', 'Groepscommissie');
     $customFields = array();
     foreach ($regiOplBelFieldsNeeded as $key => $name) {
         switch ($name) {
             case 'Vliegschool':
             case 'Vooropleiding':
             case 'Overige_opleiding':
                 // if there is a value submitted, than the checkboxes with name exist and have a
                 // value of 1, the 1 must be the value of the chekcbox (the same as the name of the option)
                 if (isset($values[$name]) and !empty($values[$name])) {
                     foreach ($values[$name] as $option_name => $boolean) {
                         $values[$name][$option_name] = $option_name;
                     }
                 }
                 break;
             case 'Algemene_onderwerpen':
             case 'Commissies':
             case 'Groepscommissie':
                 // the advanced select have a array like [0 => label, 1 => label], and it
                 // must be [name => name, name => name]
                 if (isset($values[$name]) and !empty($values[$name])) {
                     foreach ($values[$name] as $key => $label) {
                         // get the value from the option label
                         foreach ($regiOplBelFieldsOptions[$name] as $id => $option) {
                             if ($label == $option['label']) {
                                 // if he found the correct option
                                 $values[$name][$option['value']] = $option['value'];
                             }
                         }
                     }
                 }
                 break;
         }
         $customFields[$name] = $regiOplBelFields[$name];
     }
     // return can be empty if there is no error
     $errors = array_merge($errors, CRM_Lidmaatschapwijziging_ValidateCustomFields::Validate($customFields, $values));
     return empty($errors) ? TRUE : $errors;
 }
 /**
  * Here's our custom validation callback
  */
 static function myRules($values)
 {
     $errors = array();
     // check contact id
     $contact_id = CRM_Utils_Array::value('contact_id', $values);
     if (!isset($contact_id) or empty($contact_id)) {
         // contact id exists or empty
         $errors['contact_id'] = ts('Contact id bestaat niet of is leeg !');
     } else {
         if (!is_numeric($contact_id)) {
             // contact id is not a number
             $errors['contact_id'] = ts('Contact id is geen nummer !');
         }
     }
     // check current employer id
     $current_employer_id = trim(CRM_Utils_Array::value('current_employer_id', $values));
     // needs to be trimed, there is by default a whitespace after the number
     /*if(!isset($current_employer_id) or empty($current_employer_id)){ // current employer id exists or empty
         $errors['current_employer'] = ts('Huidige werkgever bestaat niet of is leeg !');
       }else if(!is_numeric($current_employer_id)){ // current employer id is not a number
         $errors['current_employer'] = ts('Current employer id is not a n number !');
       }*/
     // current employer is not required
     if (!empty($current_employer_id) and !is_numeric($current_employer_id)) {
         $errors['current_employer'] = ts('Huidige werkgever id is geen nummer !');
     }
     // check custom fields
     $configContact = CRM_Lidmaatschapwijziging_ConfigContact::singleton($contact_id);
     // Vnv Info
     // we do not need all the fields
     $vnvInfoFields = $configContact->getVnvInfoCustomFieldsByName();
     $vnvInfoFieldsNeeded = array('Lid_kandidaat_voldoet_aan_een_van_de_volgende_criteria', 'Lid_beroepsvereniging_voldoet_aan_een_van_de_volgende_criteria');
     $customFields = array();
     foreach ($vnvInfoFieldsNeeded as $key => $name) {
         $customFields[$name] = $vnvInfoFields[$name];
     }
     // return can be empty if there is no error
     $errors = array_merge($errors, CRM_Lidmaatschapwijziging_ValidateCustomFields::Validate($customFields, $values));
     // Werkgever
     // we do not need all the fields
     $werkgeverFields = $configContact->getWerkgeverCustomFieldsByName();
     $werkgeverFieldsNeeded = array('Vl_type', 'Datum_in_dienst', 'Pers_code_let_', 'Postvak', 'persnr', 'Standplaats_Werkgever');
     $customFields = array();
     foreach ($werkgeverFieldsNeeded as $key => $name) {
         $customFields[$name] = $werkgeverFields[$name];
     }
     // return can be empty if there is no error
     $errors = array_merge($errors, CRM_Lidmaatschapwijziging_ValidateCustomFields::Validate($customFields, $values));
     return empty($errors) ? TRUE : $errors;
 }