예제 #1
0
 /**
  * function to build location block
  *
  * @param object $form the object of the form (QF Object)
  * @param int $maxLocationBlocks no of location blocks
  *
  * @static 
  * @access public
  */
 function &buildLocationBlock(&$form, $maxLocationBlocks)
 {
     $location = array();
     for ($locationId = 1; $locationId <= $maxLocationBlocks; $locationId++) {
         $location[$locationId]['location_type_id'] = $form->addElement('select', "location[{$locationId}][location_type_id]", null, CRM_Core_PseudoConstant::locationType());
         $location[$locationId]['is_primary'] = $form->addElement('checkbox', "location[{$locationId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), array('onchange' => "location_is_primary_onclick('" . $form->getName() . "', {$locationId}, {$maxLocationBlocks});"));
         $location[$locationId]['name'] = $form->addElement('text', "location[{$locationId}][name]", ts('Location Name'), CRM_Core_PseudoConstant::locationType());
         CRM_Contact_Form_Address::buildAddressBlock($form, $location, $locationId);
         CRM_Contact_Form_Phone::buildPhoneBlock($form, $location, $locationId, CRM_CONTACT_FORM_LOCATION_BLOCKS);
         CRM_Contact_Form_Email::buildEmailBlock($form, $location, $locationId, CRM_CONTACT_FORM_LOCATION_BLOCKS);
         CRM_Contact_Form_IM::buildIMBlock($form, $location, $locationId, CRM_CONTACT_FORM_LOCATION_BLOCKS);
         CRM_Core_ShowHideBlocks::linksForArray($form, $locationId, $maxLocationBlocks, "location", '', '');
     }
     return $location;
 }
예제 #2
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
  */
 function formRule(&$fields, &$files, $options)
 {
     $errors = array();
     $primaryEmail = CRM_Contact_Form_Edit::formRule($fields, $errors);
     // check for state/country mapping
     CRM_Contact_Form_Address::formRule($fields, $errors);
     // make sure that firstName and lastName or a primary email is set
     if (!(CRM_Utils_Array::value('first_name', $fields) && CRM_Utils_Array::value('last_name', $fields) || !empty($primaryEmail))) {
         $errors['_qf_default'] = ts('First Name and Last Name OR an email in the Primary Location should be set.');
     }
     // if this is a forced save, ignore find duplicate rule
     if (!CRM_Utils_Array::value('_qf_Edit_next_duplicate', $fields)) {
         $cid = null;
         if ($options) {
             $cid = (int) $options;
         }
         $ids = CRM_Core_BAO_UFGroup::findContact($fields, $cid, true);
         if ($ids) {
             $urls = array();
             foreach (explode(',', $ids) as $id) {
                 $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $id, 'display_name');
                 $urls[] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view', 'reset=1&action=update&cid=' . $id) . '">' . $displayName . '</a>';
             }
             $url = implode(', ', $urls);
             $errors['_qf_default'] = ts('One matching contact was found. You can edit it here: %1, or click Save Duplicate Contact button below.', array(1 => $url, 'count' => count($urls), 'plural' => '%count matching contacts were found. You can edit them here: %1, or click Save Duplicate Contact button below.'));
             // let smarty know that there are duplicates
             $template =& CRM_Core_Smarty::singleton();
             $template->assign('isDuplicate', 1);
         } else {
             if (CRM_Utils_Array::value('_qf_Edit_refresh_dedupe', $fields)) {
                 // add a session message for no matching contacts
                 CRM_Core_Session::setStatus('No matching contact found.');
             }
         }
     }
     return empty($errors) ? true : $errors;
 }