コード例 #1
0
ファイル: Contact.php プロジェクト: nganivet/civicrm-core
 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
     $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
     CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header');
     $session = CRM_Core_Session::singleton();
     if ($this->_action == CRM_Core_Action::ADD) {
         // check for add contacts permissions
         if (!CRM_Core_Permission::check('add contacts')) {
             CRM_Utils_System::permissionDenied();
             CRM_Utils_System::civiExit();
         }
         $this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST');
         if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) {
             CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type'));
         }
         $this->_isContactSubType = FALSE;
         if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) {
             $this->_isContactSubType = TRUE;
         }
         if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) {
             CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType)));
         }
         $this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         $this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         $typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType);
         $typeLabel = implode(' / ', $typeLabel);
         CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel)));
         $session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
         $this->_contactId = NULL;
     } else {
         //update mode
         if (!$this->_contactId) {
             $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
         }
         if ($this->_contactId) {
             $defaults = array();
             $params = array('id' => $this->_contactId);
             $returnProperities = array('id', 'contact_type', 'contact_sub_type', 'modified_date', 'is_deceased');
             CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
             if (empty($defaults['id'])) {
                 CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
             }
             $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
             $this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults);
             // check for permissions
             $session = CRM_Core_Session::singleton();
             if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
                 CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
             }
             $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
             if ($defaults['is_deceased']) {
                 $displayName .= '  <span class="crm-contact-deceased">(deceased)</span>';
             }
             $displayName = ts('Edit %1', array(1 => $displayName));
             // Check if this is default domain contact CRM-10482
             if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) {
                 $displayName .= ' (' . ts('default organization') . ')';
             }
             // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
             CRM_Utils_System::setTitle($displayName);
             $context = CRM_Utils_Request::retrieve('context', 'String', $this);
             $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
             $urlParams = 'reset=1&cid=' . $this->_contactId;
             if ($context) {
                 $urlParams .= "&context={$context}";
             }
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&key={$qfKey}";
             }
             $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams));
             $values = $this->get('values');
             // get contact values.
             if (!empty($values)) {
                 $this->_values = $values;
             } else {
                 $params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE);
                 $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE);
                 $this->set('values', $this->_values);
             }
         } else {
             CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
         }
     }
     // parse street address, CRM-5450
     $this->_parseStreetAddress = $this->get('parseStreetAddress');
     if (!isset($this->_parseStreetAddress)) {
         $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options');
         $this->_parseStreetAddress = FALSE;
         if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
             $this->_parseStreetAddress = TRUE;
         }
         $this->set('parseStreetAddress', $this->_parseStreetAddress);
     }
     $this->assign('parseStreetAddress', $this->_parseStreetAddress);
     $this->_editOptions = $this->get('contactEditOptions');
     if (CRM_Utils_System::isNull($this->_editOptions)) {
         $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0');
         $this->set('contactEditOptions', $this->_editOptions);
     }
     // build demographics only for Individual contact type
     if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) {
         unset($this->_editOptions['Demographics']);
     }
     // in update mode don't show notes
     if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) {
         unset($this->_editOptions['Notes']);
     }
     $this->assign('editOptions', $this->_editOptions);
     $this->assign('contactType', $this->_contactType);
     $this->assign('contactSubType', $this->_contactSubType);
     //build contact subtype form element, CRM-6864
     $buildContactSubType = TRUE;
     if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) {
         $buildContactSubType = FALSE;
     }
     $this->assign('buildContactSubType', $buildContactSubType);
     // get the location blocks.
     $this->_blocks = $this->get('blocks');
     if (CRM_Utils_System::isNull($this->_blocks)) {
         $this->_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');
         $this->set('blocks', $this->_blocks);
     }
     $this->assign('blocks', $this->_blocks);
     // this is needed for custom data.
     $this->assign('entityID', $this->_contactId);
     // also keep the convention.
     $this->assign('contactId', $this->_contactId);
     // location blocks.
     CRM_Contact_Form_Location::preProcess($this);
     // retain the multiple count custom fields value
     if (!empty($_POST['hidden_custom'])) {
         $customGroupCount = CRM_Utils_Array::value('hidden_custom_group_count', $_POST);
         if ($contactSubType = CRM_Utils_Array::value('contact_sub_type', $_POST)) {
             $paramSubType = implode(',', $contactSubType);
         }
         $this->_getCachedTree = FALSE;
         unset($customGroupCount[0]);
         foreach ($customGroupCount as $groupID => $groupCount) {
             if ($groupCount > 1) {
                 $this->set('groupID', $groupID);
                 //loop the group
                 for ($i = 0; $i <= $groupCount; $i++) {
                     CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, $i, $this->_contactType);
                     CRM_Contact_Form_Edit_CustomData::buildQuickForm($this);
                 }
             }
         }
         //reset all the ajax stuff, for normal processing
         if (isset($this->_groupTree)) {
             $this->_groupTree = NULL;
         }
         $this->set('groupID', NULL);
         $this->_getCachedTree = TRUE;
     }
     // execute preProcess dynamically by js else execute normal preProcess
     if (array_key_exists('CustomData', $this->_editOptions)) {
         //assign a parameter to pass for sub type multivalue
         //custom field to load
         if ($this->_contactSubType || isset($paramSubType)) {
             $paramSubType = isset($paramSubType) ? $paramSubType : str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($this->_contactSubType, CRM_Core_DAO::VALUE_SEPARATOR));
             $this->assign('paramSubType', $paramSubType);
         }
         if (CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject)) {
             CRM_Contact_Form_Edit_CustomData::preProcess($this);
         } else {
             $contactSubType = $this->_contactSubType;
             // need contact sub type to build related grouptree array during post process
             if (!empty($_POST['contact_sub_type'])) {
                 $contactSubType = $_POST['contact_sub_type'];
             }
             //only custom data has preprocess hence directly call it
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, 1, $this->_contactType, $this->_contactId);
             $this->assign('customValueCount', $this->_customValueCount);
         }
     }
 }
コード例 #2
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
     $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
     $session = CRM_Core_Session::singleton();
     if ($this->_action == CRM_Core_Action::ADD) {
         // check for add contacts permissions
         if (!CRM_Core_Permission::check('add contacts')) {
             CRM_Utils_System::permissionDenied();
             CRM_Utils_System::civiExit();
         }
         $this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST');
         if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) {
             CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type'));
         }
         $this->_isContactSubType = FALSE;
         if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) {
             $this->_isContactSubType = TRUE;
         }
         if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) {
             CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType)));
         }
         $this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         $this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         $typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType);
         $typeLabel = implode(' / ', $typeLabel);
         CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel)));
         $session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
         $this->_contactId = NULL;
     } else {
         //update mode
         if (!$this->_contactId) {
             $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
         }
         if ($this->_contactId) {
             $defaults = array();
             $params = array('id' => $this->_contactId);
             $returnProperities = array('id', 'contact_type', 'contact_sub_type');
             CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
             if (!CRM_Utils_Array::value('id', $defaults)) {
                 CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
             }
             $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
             $this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults);
             // check for permissions
             $session = CRM_Core_Session::singleton();
             if ($session->get('userID') != $this->_contactId && !CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
                 CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
             }
             list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
             CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
             $context = CRM_Utils_Request::retrieve('context', 'String', $this);
             $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
             $urlParams = 'reset=1&cid=' . $this->_contactId;
             if ($context) {
                 $urlParams .= "&context={$context}";
             }
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&key={$qfKey}";
             }
             $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams));
             $values = $this->get('values');
             // get contact values.
             if (!empty($values)) {
                 $this->_values = $values;
             } else {
                 $params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE);
                 $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE);
                 $this->set('values', $this->_values);
             }
         } else {
             CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
         }
     }
     // parse street address, CRM-5450
     $this->_parseStreetAddress = $this->get('parseStreetAddress');
     if (!isset($this->_parseStreetAddress)) {
         $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options');
         $this->_parseStreetAddress = FALSE;
         if (CRM_Utils_Array::value('street_address', $addressOptions) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
             $this->_parseStreetAddress = TRUE;
         }
         $this->set('parseStreetAddress', $this->_parseStreetAddress);
     }
     $this->assign('parseStreetAddress', $this->_parseStreetAddress);
     $this->_editOptions = $this->get('contactEditOptions');
     if (CRM_Utils_System::isNull($this->_editOptions)) {
         $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0');
         $this->set('contactEditOptions', $this->_editOptions);
     }
     // build demographics only for Individual contact type
     if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) {
         unset($this->_editOptions['Demographics']);
     }
     // in update mode don't show notes
     if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) {
         unset($this->_editOptions['Notes']);
     }
     $this->assign('editOptions', $this->_editOptions);
     $this->assign('contactType', $this->_contactType);
     $this->assign('contactSubType', $this->_contactSubType);
     //build contact subtype form element, CRM-6864
     $buildContactSubType = TRUE;
     if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) {
         $buildContactSubType = FALSE;
     }
     $this->assign('buildContactSubType', $buildContactSubType);
     // get the location blocks.
     $this->_blocks = $this->get('blocks');
     if (CRM_Utils_System::isNull($this->_blocks)) {
         $this->_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');
         $this->set('blocks', $this->_blocks);
     }
     $this->assign('blocks', $this->_blocks);
     // this is needed for custom data.
     $this->assign('entityID', $this->_contactId);
     // also keep the convention.
     $this->assign('contactId', $this->_contactId);
     // location blocks.
     CRM_Contact_Form_Location::preProcess($this);
     // execute preProcess dynamically by js else execute normal preProcess
     if (array_key_exists('CustomData', $this->_editOptions)) {
         if (CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject)) {
             CRM_Contact_Form_Edit_CustomData::preProcess($this);
         } else {
             $contactSubType = $this->_contactSubType;
             // need contact sub type to build related grouptree array during post process
             if (CRM_Utils_Array::value('contact_sub_type', $_POST)) {
                 $contactSubType = $_POST['contact_sub_type'];
             }
             //only custom data has preprocess hence directly call it
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, 1, $this->_contactType, $this->_contactId);
         }
     }
 }