示例#1
0
 /**
  * add rule for household
  *
  * @params array $fields array of form values
  *
  * @return $error 
  * @static
  * @public
  */
 static function formRule($fields, $files, $contactID = null)
 {
     $errors = array();
     $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
     // make sure that household name is set
     if (!CRM_Utils_Array::value('household_name', $fields)) {
         $errors['household_name'] = 'Household Name should be set.';
     }
     //check for duplicate - dedupe rules
     CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
     return empty($errors) ? true : $errors;
 }
示例#2
0
 static function formRule(&$fields, &$files, $contactID = null)
 {
     $errors = array();
     $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
     // make sure that organization name is set
     if (!CRM_Utils_Array::value('organization_name', $fields)) {
         $errors['organization_name'] = 'Organization Name should be set.';
     }
     //check for duplicate - dedupe rules
     CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Organization');
     // add code to make sure that the uniqueness criteria is satisfied
     return empty($errors) ? true : $errors;
 }
示例#3
0
 /**
  * Global validation rules for the form.
  *
  * @param array $fields
  *   Posted values of the form.
  * @param array $errors
  *   List of errors to be posted back to the form.
  * @param int $contactId
  *   Contact id if doing update.
  *
  * @return bool
  *   email/openId
  */
 public static function formRule($fields, &$errors, $contactId = NULL)
 {
     $config = CRM_Core_Config::singleton();
     // validations.
     //1. for each block only single value can be marked as is_primary = true.
     //2. location type id should be present if block data present.
     //3. check open id across db and other each block for duplicate.
     //4. at least one location should be primary.
     //5. also get primaryID from email or open id block.
     // take the location blocks.
     $blocks = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 1');
     $otherEditOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0');
     //get address block inside.
     if (array_key_exists('Address', $otherEditOptions)) {
         $blocks['Address'] = $otherEditOptions['Address'];
     }
     $openIds = array();
     $primaryID = FALSE;
     foreach ($blocks as $name => $label) {
         $hasData = $hasPrimary = array();
         $name = strtolower($name);
         if (!empty($fields[$name]) && is_array($fields[$name])) {
             foreach ($fields[$name] as $instance => $blockValues) {
                 $dataExists = self::blockDataExists($blockValues);
                 if (!$dataExists && $name == 'address') {
                     $dataExists = CRM_Utils_Array::value('use_shared_address', $fields['address'][$instance]);
                 }
                 if ($dataExists) {
                     // skip remaining checks for website
                     if ($name == 'website') {
                         continue;
                     }
                     $hasData[] = $instance;
                     if (!empty($blockValues['is_primary'])) {
                         $hasPrimary[] = $instance;
                         if (!$primaryID && in_array($name, array('email', 'openid')) && !empty($blockValues[$name])) {
                             $primaryID = $blockValues[$name];
                         }
                     }
                     if (empty($blockValues['location_type_id'])) {
                         $errors["{$name}[{$instance}][location_type_id]"] = ts('The Location Type should be set if there is  %1 information.', array(1 => $label));
                     }
                 }
                 if ($name == 'openid' && !empty($blockValues[$name])) {
                     $oid = new CRM_Core_DAO_OpenID();
                     $oid->openid = $openIds[$instance] = CRM_Utils_Array::value($name, $blockValues);
                     $cid = isset($contactId) ? $contactId : 0;
                     if ($oid->find(TRUE) && $oid->contact_id != $cid) {
                         $errors["{$name}[{$instance}][openid]"] = ts('%1 already exist.', array(1 => $blocks['OpenID']));
                     }
                 }
             }
             if (empty($hasPrimary) && !empty($hasData)) {
                 $errors["{$name}[1][is_primary]"] = ts('One %1 should be marked as primary.', array(1 => $label));
             }
             if (count($hasPrimary) > 1) {
                 $errors["{$name}[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one %1 can be marked as primary.', array(1 => $label));
             }
         }
     }
     //do validations for all opend ids they should be distinct.
     if (!empty($openIds) && count(array_unique($openIds)) != count($openIds)) {
         foreach ($openIds as $instance => $value) {
             if (!array_key_exists($instance, array_unique($openIds))) {
                 $errors["openid[{$instance}][openid]"] = ts('%1 already used.', array(1 => $blocks['OpenID']));
             }
         }
     }
     // street number should be digit + suffix, CRM-5450
     $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'));
     if ($parseStreetAddress) {
         if (isset($fields['address']) && is_array($fields['address'])) {
             $invalidStreetNumbers = array();
             foreach ($fields['address'] as $cnt => $address) {
                 if ($streetNumber = CRM_Utils_Array::value('street_number', $address)) {
                     $parsedAddress = CRM_Core_BAO_Address::parseStreetAddress($address['street_number']);
                     if (empty($parsedAddress['street_number'])) {
                         $invalidStreetNumbers[] = $cnt;
                     }
                 }
             }
             if (!empty($invalidStreetNumbers)) {
                 $first = $invalidStreetNumbers[0];
                 foreach ($invalidStreetNumbers as &$num) {
                     $num = CRM_Contact_Form_Contact::ordinalNumber($num);
                 }
                 $errors["address[{$first}][street_number]"] = ts('The street number you entered for the %1 address block(s) is not in an expected format. Street numbers may include numeric digit(s) followed by other characters. You can still enter the complete street address (unparsed) by clicking "Edit Complete Street Address".', array(1 => implode(', ', $invalidStreetNumbers)));
             }
         }
     }
     return $primaryID;
 }
示例#4
0
文件: OpenID.php 项目: kidaa30/yes
 /**
  * Global validation rules for the form.
  *
  * @param array $fields
  *   Posted values of the form.
  * @param array $errors
  *   List of errors to be posted back to the form.
  *
  * @return array
  */
 public static function formRule($fields, $errors)
 {
     $hasData = $hasPrimary = $errors = array();
     if (!empty($fields['openid']) && is_array($fields['openid'])) {
         foreach ($fields['openid'] as $instance => $blockValues) {
             $dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
             if ($dataExists) {
                 $hasData[] = $instance;
                 if (!empty($blockValues['is_primary'])) {
                     $hasPrimary[] = $instance;
                     if (!$primaryID && !empty($blockValues['openid'])) {
                         $primaryID = $blockValues['openid'];
                     }
                 }
             }
         }
         if (empty($hasPrimary) && !empty($hasData)) {
             $errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
         }
         if (count($hasPrimary) > 1) {
             $errors["openid[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one OpenID can be marked as primary.');
         }
     }
     return $errors;
 }
示例#5
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // Process / save address
     $params['contact_id'] = $this->_contactId;
     $params['updateBlankLocInfo'] = TRUE;
     // process shared contact address.
     CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
     if ($this->_parseStreetAddress) {
         CRM_Contact_Form_Contact::parseAddress($params);
     }
     if ($this->_addressId > 0) {
         $params['address'][$this->_locBlockNo]['id'] = $this->_addressId;
     }
     // save address changes
     $address = CRM_Core_BAO_Address::create($params, TRUE);
     $this->log();
     $this->ajaxResponse['addressId'] = $address[0]->id;
     $this->response();
 }
 /**
  * Add rule for household.
  *
  * @param array $fields
  *   Array of form values.
  * @param array $files
  *   Unused.
  * @param int $contactID
  *
  * @return array|bool
  *   $error
  */
 public static function formRule($fields, $files, $contactID = NULL)
 {
     $errors = array();
     $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
     // make sure that household name is set
     if (empty($fields['household_name'])) {
         $errors['household_name'] = 'Household Name should be set.';
     }
     //check for duplicate - dedupe rules
     CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
     return empty($errors) ? TRUE : $errors;
 }
示例#7
0
文件: IM.php 项目: hguru/224Civi
 /**
  * global validation rules for the form
  *
  * @param array $fields     posted values of the form
  * @param array $errors     list of errors to be posted back to the form
  *
  * @return $errors
  * @static
  * @access public
  */
 static function formRule($fields, $errors)
 {
     $hasData = $hasPrimary = $errors = array();
     if (CRM_Utils_Array::value('im', $fields) && is_array($fields['im'])) {
         foreach ($fields['im'] as $instance => $blockValues) {
             $dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
             if ($dataExists) {
                 $hasData[] = $instance;
                 if (CRM_Utils_Array::value('is_primary', $blockValues)) {
                     $hasPrimary[] = $instance;
                     if (!$primaryID && CRM_Utils_Array::value('im', $blockValues)) {
                         $primaryID = $blockValues['im'];
                     }
                 }
             }
         }
         if (empty($hasPrimary) && !empty($hasData)) {
             $errors["im[1][is_primary]"] = ts('One IM should be marked as primary.');
         }
         if (count($hasPrimary) > 1) {
             $errors["im[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one IM can be marked as primary.');
         }
     }
     return $errors;
 }
示例#8
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param int $contactID
  *
  * @return bool
  *   TRUE if no errors, else array of errors.
  */
 public static function formRule($fields, $files, $contactID = NULL)
 {
     $errors = array();
     $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
     // make sure that firstName and lastName or a primary OpenID is set
     if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) {
         $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
     }
     //check for duplicate - dedupe rules
     CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
     return empty($errors) ? TRUE : $errors;
 }
 /**
  * process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // need to process / save address
     $params['contact_id'] = $this->_contactId;
     $params['updateBlankLocInfo'] = TRUE;
     // process shared contact address.
     CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
     if ($this->_parseStreetAddress) {
         CRM_Contact_Form_Contact::parseAddress($params);
     }
     if ($this->_addressId > 0) {
         $params['address'][$this->_locBlockNo]['id'] = $this->_addressId;
     }
     // save address changes
     $address = CRM_Core_BAO_Address::create($params, TRUE);
     // make entry in log table
     CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId);
     $response = array('status' => 'save', 'addressId' => $address[0]->id);
     $this->postProcessHook();
     echo json_encode($response);
     CRM_Utils_System::civiExit();
 }
示例#10
0
 /**
  * global form rule
  *
  * @param array $fields  the input form values
  * @param array $files   the uploaded files if any
  * @param array $options additional user data
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule(&$fields, &$files, $contactID = null)
 {
     $errors = array();
     //FIXME
     if (CRM_Utils_Array::value('state_province_id', $fields['address'][1]) == 'undefined') {
         $fields['address'][1]['state_province_id'] = '';
     }
     $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
     // check for state/country mapping
     require_once 'CRM/Contact/Form/Edit/Address.php';
     CRM_Contact_Form_Edit_Address::formRule($fields, $errors);
     // make sure that firstName and lastName or a primary OpenID is set
     if (!$primaryID && (!CRM_Utils_Array::value('first_name', $fields) || !CRM_Utils_Array::value('last_name', $fields))) {
         $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
     }
     //check for duplicate - dedupe rules
     CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
     // if use_household_address option is checked, make sure 'valid household_name' is also present.
     if (CRM_Utils_Array::value('use_household_address', $fields) && !CRM_Utils_Array::value('shared_household_id', $fields)) {
         $errors["shared_household"] = ts("Please select a household from the 'Select Household' list");
     }
     return empty($errors) ? true : $errors;
 }
示例#11
0
 /**
  * Global validation rules for the form.
  *
  * @param array $fields
  *   Posted values of the form.
  * @param array $errors
  *   List of errors to be posted back to the form.
  * @param CRM_Contact_Form_Inline_Email $form
  *
  * @return array
  */
 public static function formRule($fields, $errors, $form)
 {
     $hasData = $hasPrimary = $errors = array();
     if (!empty($fields['email']) && is_array($fields['email'])) {
         foreach ($fields['email'] as $instance => $blockValues) {
             $dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
             if ($dataExists) {
                 $hasData[] = $instance;
                 if (!empty($blockValues['is_primary'])) {
                     $hasPrimary[] = $instance;
                 }
             }
         }
         if (empty($hasPrimary) && !empty($hasData)) {
             $errors["email[1][is_primary]"] = ts('One email should be marked as primary.');
         }
         if (count($hasPrimary) > 1) {
             $errors["email[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one email can be marked as primary.');
         }
     }
     if (!$hasData && !$form->contactHasName) {
         $errors["email[1][email]"] = ts('Contact with no name must have an email.');
     }
     return $errors;
 }