Exemple #1
0
 /**
  * View details of a relationship
  *
  * @return void
  *
  * @access public
  */
 function view()
 {
     require_once 'CRM/Core/DAO.php';
     $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, null, null, null, $this->_id);
     //To check whether selected contact is a contact_id_a in
     //relationship type 'a_b' in relationship table, if yes then
     //revert the permissionship text in template
     $relationship =& new CRM_Contact_DAO_Relationship();
     $relationship->id = $viewRelationship[$this->_id]['id'];
     if ($relationship->find(true)) {
         if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) {
             $this->assign("is_contact_id_a", true);
         }
     }
     $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id'];
     $this->assign('viewRelationship', $viewRelationship);
     $viewNote = CRM_Core_BAO_Note::getNote($this->_id);
     $this->assign('viewNote', $viewNote);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     // add viewed contribution to recent items list
     require_once 'CRM/Utils/Recent.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home");
     $title = CRM_Contact_BAO_Contact::displayName($this->_contactId) . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')';
     // add the recently viewed Relationship
     CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, null);
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  */
 public function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST);
     $cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST);
     //custom groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType);
     $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId);
     //get the fields of single custom group record
     if ($customRecId == 1) {
         $fields = reset($details[$cgId]);
     } else {
         $fields = CRM_Utils_Array::value($customRecId, $details[$cgId]);
     }
     $this->assign('cgcount', $cgcount);
     $this->assign('customRecId', $customRecId);
     $this->assign('contactId', $contactId);
     $this->assign('customGroupId', $cgId);
     $this->assign_by_ref('cd_edit', $fields);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 /**
  * View details of a recurring contribution.
  */
 public function view()
 {
     $recur = new CRM_Contribute_DAO_ContributionRecur();
     $recur->id = $this->_id;
     if ($recur->find(TRUE)) {
         $values = array();
         CRM_Core_DAO::storeValues($recur, $values);
         // if there is a payment processor ID, get the name of the payment processor
         if (!empty($values['payment_processor_id'])) {
             $values['payment_processor'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
         $idFields = array('contribution_status_id', 'campaign_id');
         if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($values['id'])) {
             $idFields[] = 'financial_type_id';
         }
         foreach ($idFields as $idField) {
             if (!empty($values[$idField])) {
                 $values[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $values[$idField]);
             }
         }
         // Get financial type name
         if (!empty($values['financial_type_id'])) {
             $values['financial_type_name'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'financial_type_id', $values['financial_type_id']);
         }
         // Get Paid By label
         if (!empty($values['payment_instrument_id'])) {
             $values['payment_instrument'] = CRM_Core_OptionGroup::getLabel('payment_instrument', $values['payment_instrument_id']);
         }
         $this->assign('recur', $values);
         $this->assign('customDataType', 'ContributionRecur');
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', $this, $this->_id);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     }
 }
Exemple #4
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  */
 public function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
     $address = array();
     if ($addressId > 0) {
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
         $entityBlock = array('id' => $addressId);
         $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
         if (!empty($address)) {
             foreach ($address as $key => &$value) {
                 $value['location_type'] = $locationTypes[$value['location_type_id']];
             }
         }
     }
     // we just need current address block
     $currentAddressBlock['address'][$locBlockNo] = array_pop($address);
     if (!empty($currentAddressBlock['address'][$locBlockNo])) {
         // get contact name of shared contact names
         $sharedAddresses = array();
         $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
         foreach ($currentAddressBlock['address'] as $key => $addressValue) {
             if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
                 $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
             }
         }
         $idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
         if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
             $idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
         }
         // add custom data of type address
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $idValue);
         // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
         $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
         $this->assign("dnc_viewCustomData", NULL);
         $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
         $this->assign('sharedAddresses', $sharedAddresses);
     }
     $contact = new CRM_Contact_BAO_Contact();
     $contact->id = $contactId;
     $contact->find(TRUE);
     $privacy = array();
     foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
         if (isset($contact->{$name})) {
             $privacy[$name] = $contact->{$name};
         }
     }
     $this->assign('contactId', $contactId);
     $this->assign('locationIndex', $locBlockNo);
     $this->assign('addressId', $addressId);
     $this->assign('privacy', $privacy);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
     $address = array();
     if ($addressId > 0) {
         $locationTypes = CRM_Core_PseudoConstant::locationDisplayName();
         $entityBlock = array('id' => $addressId);
         $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
         if (!empty($address)) {
             foreach ($address as $key => &$value) {
                 $value['location_type'] = $locationTypes[$value['location_type_id']];
             }
         }
     }
     // we just need current address block
     $currentAddressBlock['address'][$locBlockNo] = array_pop($address);
     if (!empty($currentAddressBlock['address'][$locBlockNo])) {
         // get contact name of shared contact names
         $sharedAddresses = array();
         $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
         foreach ($currentAddressBlock['address'] as $key => $addressValue) {
             if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
                 $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
             }
         }
         // add custom data of type address
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $currentAddressBlock['address'][$locBlockNo]['id']);
         // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
         $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
         $this->assign("dnc_viewCustomData", NULL);
         $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
         $this->assign('sharedAddresses', $sharedAddresses);
     }
     $this->assign('contactId', $contactId);
     $this->assign('locationIndex', $locBlockNo);
     $this->assign('addressId', $addressId);
     $appendBlockIndex = CRM_Core_BAO_Address::getAddressCount($contactId);
     // check if we are adding new address, then only append add link
     if ($appendBlockIndex == $locBlockNo) {
         if ($appendBlockIndex) {
             $appendBlockIndex++;
         }
     } else {
         $appendBlockIndex = 0;
     }
     $this->assign('appendBlockIndex', $appendBlockIndex);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao = new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (!empty($values['contribution_page_id'])) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['financial_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther);
     // Check if this is default domain contact CRM-10482
     if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
         $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(ts('View Pledge by') . ' ' . $displayName);
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
Exemple #7
0
 /** 
  * Heart of the viewing process. The runner gets all the meta data for 
  * the contact and calls the appropriate type of page to view. 
  * 
  * @return void 
  * @access public 
  * 
  */
 function preProcess()
 {
     parent::preProcess();
     //retrieve inline custom data
     $entityType = $this->get('contactType');
     $entitySubType = $this->get('contactSubtype');
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, null, $entitySubType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     // also create the form element for the activity links box
     $controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_ActivityLinks', ts('Activity Links'), null);
     $controller->setEmbedded(true);
     $controller->run();
 }
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Pledge/BAO/Pledge.php';
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao = new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     require_once 'CRM/Utils/Money.php';
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null, $recentOther);
     $this->assign($values);
 }
 /**
  * View details of a relationship.
  */
 public function view()
 {
     $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id);
     //To check whether selected contact is a contact_id_a in
     //relationship type 'a_b' in relationship table, if yes then
     //revert the permissionship text in template
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->id = $viewRelationship[$this->_id]['id'];
     if ($relationship->find(TRUE)) {
         if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) {
             $this->assign("is_contact_id_a", TRUE);
         }
     }
     $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id'];
     $this->assign('viewRelationship', $viewRelationship);
     $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id');
     $this->assign('isCurrentEmployer', FALSE);
     $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
     if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) {
         $this->assign('isCurrentEmployer', TRUE);
     } elseif ($relType == $relTypes['Employee of']['id'] && $viewRelationship[$this->_id]['cid'] == $employerId) {
         // make sure we are viewing employee of relationship
         $this->assign('isCurrentEmployer', TRUE);
     }
     $viewNote = CRM_Core_BAO_Note::getNote($this->_id);
     $this->assign('viewNote', $viewNote);
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home");
     $session = CRM_Core_Session::singleton();
     $recentOther = array();
     if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
         $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"));
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
     $this->assign('displayName', $displayName);
     CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName);
     $title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')';
     // add the recently viewed Relationship
     CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, NULL, $recentOther);
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     //custom groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType);
     $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $fields = array_pop($details[$cgId]);
     $this->assign('contactId', $contactId);
     $this->assign('customGroupId', $cgId);
     $this->assign_by_ref('cd_edit', $fields);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
Exemple #11
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         // build associated contributions
         require_once 'CRM/Member/Page/Tab.php';
         CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
             $direction = strrev($membershipType['relationship_direction']);
             $values['relationship'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id');
         }
         $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $this->assign('displayName', $displayName);
         // add viewed membership to recent items list
         require_once 'CRM/Utils/Recent.php';
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
         $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], null);
         CRM_Member_Page_Tab::setContext($values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     }
     if ($values['is_test']) {
         $values['membership_type'] .= ' (test) ';
     }
     $this->assign($values);
 }
Exemple #12
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Event/BAO/Participant.php';
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Event_BAO_Participant::getValues($params, $values, $ids);
     CRM_Event_BAO_Participant::resolveDefaults($values[$params['id']]);
     if (CRM_Utils_Array::value('fee_level', $values[$params['id']])) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$params['id']]['fee_level']);
     }
     if ($values[$params['id']]['is_test']) {
         $values[$params['id']]['status'] .= ' (test) ';
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($values[$params['id']]['id'], 'civicrm_participant');
     $values[$params['id']]['note'] = array_values($noteValue);
     require_once 'CRM/Price/BAO/LineItem.php';
     // Get Line Items
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($params['id']);
     if (!CRM_Utils_System::isNull($lineItem)) {
         $values[$params['id']]['lineItem'][] = $lineItem;
     }
     $values[$params['id']]['totalAmount'] = $values[$params['id']]['fee_amount'];
     // get the option value for custom data type
     $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     $roleGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id'], null, $values[$params['id']]['role_id'], $roleCustomDataTypeID);
     $eventGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id'], null, $values[$params['id']]['event_id'], $eventNameCustomDataTypeID);
     $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
     $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id']));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign($values[$params['id']]);
     // add viewed participant to recent items list
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$params['id']]['id']}&cid={$values[$params['id']]['contact_id']}");
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$params['id']]['event_id'], 'title');
     $title = CRM_Contact_BAO_Contact::displayName($values[$params['id']]['contact_id']) . ' (' . $participantRoles[$values[$params['id']]['role_id']] . ' - ' . $eventTitle . ')';
     // add the recently created Activity
     CRM_Utils_Recent::add($title, $url, $values[$params['id']]['id'], 'Participant', $values[$params['id']]['contact_id'], null);
 }
Exemple #13
0
 /**
  * View details of a relationship
  *
  * @return void
  *
  * @access public
  */
 function view()
 {
     require_once 'CRM/Core/DAO.php';
     $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, null, null, null, $this->_id);
     //To check whether selected contact is a contact_id_a in
     //relationship type 'a_b' in relationship table, if yes then
     //revert the permissionship text in template
     $relationship =& new CRM_Contact_DAO_Relationship();
     $relationship->id = $viewRelationship[$this->_id]['id'];
     if ($relationship->find(true)) {
         if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) {
             $this->assign("is_contact_id_a", true);
         }
     }
     $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id'];
     $this->assign('viewRelationship', $viewRelationship);
     $viewNote = CRM_Core_BAO_Note::getNote($this->_id);
     $this->assign('viewNote', $viewNote);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
 }
Exemple #14
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
         // Do the action on related Membership if needed
         $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
         if ($relAction) {
             $this->relAction($relAction, $values);
         }
         // build associated contributions
         $this->assign('accessContribution', FALSE);
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->assign('accessContribution', TRUE);
             CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         }
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE\n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $typeId = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $typeId) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id');
                 }
             }
         }
         $this->assign('has_related', FALSE);
         // if membership can be granted, and we are the owner of the membership
         if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
             // display related contacts/membership block
             $this->assign('has_related', TRUE);
             $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
             // split the relations in 2 arrays based on direction
             $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             foreach ($relTypeId as $rid) {
                 $dir = each($relDirection);
                 $relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
             }
             // build query in 2 parts with a UNION if necessary
             // _x and _y are replaced with _a and _b first, then vice-versa
             // comment is a qualifier for the relationship - now just job_title
             $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n       rt.name_x_y as relation, r.start_date, r.end_date,\n       m.id as mid, ms.is_current_member, ms.label as status\n  FROM civicrm_relationship r\n  LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n  LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n  LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n  AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n  LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1  AND c.is_deleted = 0";
             $query = '';
             foreach (array('a', 'b') as $dir) {
                 if (isset($relTypeDir[$dir])) {
                     $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
                 }
             }
             $query .= " ORDER BY is_current_member DESC";
             $dao = CRM_Core_DAO::executeQuery($query);
             $related = array();
             $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
             $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status');
             while ($dao->fetch()) {
                 $row = array();
                 foreach ($rowElememts as $field) {
                     $row[$field] = $dao->{$field};
                 }
                 if ($row['mid'] && $row['is_current_member'] == 1) {
                     $relatedRemaining--;
                     $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                 } else {
                     if ($relatedRemaining > 0) {
                         $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                     }
                 }
                 $related[] = $row;
             }
             $this->assign('related', $related);
             if ($relatedRemaining <= 0) {
                 $this->assign('related_text', ts('None available'));
             } else {
                 if ($relatedRemaining < 100000) {
                     $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
                 } else {
                     $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
                 }
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
         $this->assign('displayName', $displayName);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
         CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
         // add viewed membership to recent items list
         $recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($recentTitle, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (!empty($values['is_test'])) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
 /**
  * @param CRM_Core_Form $form
  * @param null|string $subName
  * @param null|string $subType
  * @param null|int $groupCount
  * @param string $type
  * @param null|int $entityID
  * @param null $onlySubType
  */
 public static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL)
 {
     if ($type) {
         $form->_type = $type;
     } else {
         $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
     }
     if (isset($subType)) {
         $form->_subType = $subType;
     } else {
         $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
     }
     if ($form->_subType == 'null') {
         $form->_subType = NULL;
     }
     if (isset($subName)) {
         $form->_subName = $subName;
     } else {
         $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
     }
     if ($form->_subName == 'null') {
         $form->_subName = NULL;
     }
     if ($groupCount) {
         $form->_groupCount = $groupCount;
     } else {
         $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
     }
     $form->assign('cgCount', $form->_groupCount);
     //carry qf key, since this form is not inhereting core form.
     if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) {
         $form->assign('qfKey', $qfKey);
     }
     if ($entityID) {
         $form->_entityId = $entityID;
     } else {
         $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
     }
     $typeCheck = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject);
     $urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject);
     if (isset($typeCheck) && $urlGroupId) {
         $form->_groupID = $urlGroupId;
     } else {
         $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
     }
     $gid = isset($form->_groupID) ? $form->_groupID : NULL;
     $getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE;
     $subType = $form->_subType;
     if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
         $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
     if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
         $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
     }
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
     } else {
         $form->_groupTree = $groupTree;
     }
 }
Exemple #16
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     $cancelledStatus = TRUE;
     $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) {
         $cancelledStatus = FALSE;
     }
     $this->assign('cancelledStatus', $cancelledStatus);
     if (!empty($values['contribution_page_id'])) {
         $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
         $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
     }
     // get recieved into i.e to_financial_account_id from last trxn
     $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
     $values['to_financial_account'] = '';
     if (!empty($financialTrxnId['financialTrxnId'])) {
         $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
         if ($values['to_financial_account_id']) {
             $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']);
         }
         $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
         if ($values['payment_processor_id']) {
             $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
     }
     if (!empty($values['contribution_recur_id'])) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values['recur_installments'] = $dao->installments;
             $values['recur_frequency_unit'] = $dao->frequency_unit;
             $values['recur_frequency_interval'] = $dao->frequency_interval;
         }
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = NULL;
     if ($id) {
         $dao = new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(TRUE)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(TRUE);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (!empty($values['address_id'])) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //assign soft credit record if exists.
     $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE);
     if (!empty($SCRecords['soft_credit'])) {
         $this->assign('softContributions', $SCRecords['soft_credit']);
         unset($SCRecords['soft_credit']);
     }
     //assign pcp record if exists
     foreach ($SCRecords as $name => $value) {
         $this->assign($name, $value);
     }
     $lineItems = array();
     if ($id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE);
         if (!empty($lineItem)) {
             $lineItems[] = $lineItem;
         }
     }
     $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     // assign values to the template
     $this->assign($values);
     $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     if ($invoicing && isset($values['tax_amount'])) {
         $this->assign('totalTaxAmount', $values['tax_amount']);
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     // Check if this is default domain contact CRM-10482
     if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
         $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(ts('View Contribution from') . ' ' . $displayName);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther);
 }
Exemple #17
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     $values = array();
     $params['id'] = $this->_id;
     CRM_Grant_BAO_Grant::retrieve($params, $values);
     $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id');
     $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id');
     $this->assign('grantType', $grantType[$values['grant_type_id']]);
     $this->assign('grantStatus', $grantStatus[$values['status_id']]);
     $grantTokens = array('amount_total', 'amount_requested', 'amount_granted', 'rationale', 'grant_report_received', 'application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($grantTokens as $token) {
         $this->assign($token, CRM_Utils_Array::value($token, $values));
     }
     if (isset($this->_id)) {
         $noteDAO = new CRM_Core_BAO_Note();
         $noteDAO->entity_table = 'civicrm_grant';
         $noteDAO->entity_id = $this->_id;
         if ($noteDAO->find(TRUE)) {
             $this->_noteId = $noteDAO->id;
         }
     }
     if (isset($this->_noteId)) {
         $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
     }
     // add Grant to Recent Items
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], NULL, $recentOther);
     $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
     $this->assign('attachment', $attachment);
     $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id");
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0, $grantType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('id', $this->_id);
     $this->setPageTitle(ts('Grant'));
 }
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = $ids = array();
     $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $params = array('id' => $participantID);
     CRM_Event_BAO_Participant::getValues($params, $values, $ids);
     if (empty($values)) {
         CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).'));
     }
     CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]);
     if (!empty($values[$participantID]['fee_level'])) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']);
     }
     $this->assign('contactId', $contactID);
     $this->assign('participantId', $participantID);
     $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $participantID, 'id', 'participant_id');
     $this->assign('hasPayment', $paymentId);
     if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'registered_by_id')) {
         $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $parentParticipantId, 'id', 'participant_id');
         $this->assign('parentHasPayment', $parentHasPayment);
     }
     $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
     $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
     $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
     if ($status == 'Transferred') {
         $transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id');
         $pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id');
         $transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId));
         $this->assign('pid', $pid);
         $this->assign('transferId', $transferId);
         $this->assign('transferName', $transferName);
     }
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     if ($values[$participantID]['is_test']) {
         $values[$participantID]['status'] .= ' (test) ';
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant');
     $values[$participantID]['note'] = array_values($noteValue);
     // Get Line Items
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
     if (!CRM_Utils_System::isNull($lineItem)) {
         $values[$participantID]['lineItem'][] = $lineItem;
     }
     $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]);
     // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
     if (!empty($values[$participantID]['participant_registered_by_id'])) {
         $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $values[$participantID]['participant_registered_by_id'], 'contact_id', 'id');
         $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']);
     }
     // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true  (CRM-4859)
     if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) {
         $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID);
     }
     // get the option value for custom data type
     $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
     $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']);
     $groupTree = array();
     $finalTree = array();
     foreach ($allRoleIDs as $k => $v) {
         $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID);
         $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $values[$participantID]['event_id'], $eventNameCustomDataTypeID);
         $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
         $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
         $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
         $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
         $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID));
         foreach ($groupTree as $treeId => $trees) {
             $finalTree[$treeId] = $trees;
         }
     }
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID);
     $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
     //CRM-7150, show event name on participant view even if the event is disabled
     if (empty($values[$participantID]['event'])) {
         $values[$participantID]['event'] = $eventTitle;
     }
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values[$participantID]['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values[$participantID]);
     // add viewed participant to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::check('edit event participants')) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::check('delete in CiviEvent')) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home");
     }
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']);
     $participantCount = array();
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $totalTaxAmount = 0;
     foreach ($lineItem as $k => $v) {
         if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
             $participantCount[] = $lineItem[$k]['participant_count'];
         }
         $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount;
     }
     if ($invoicing) {
         $this->assign('totalTaxAmount', $totalTaxAmount);
     }
     if ($participantCount) {
         $this->assign('pricesetFieldsCount', $participantCount);
     }
     $this->assign('displayName', $displayName);
     // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
     CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName);
     $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]);
     $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     $viewRoles = array();
     foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
         $viewRoles[] = $participantRoles[$v];
     }
     $values[$participantID]['role_id'] = implode(', ', $viewRoles);
     $this->assign('role', $values[$participantID]['role_id']);
     // add Participant to Recent Items
     CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], NULL, $recentOther);
 }
 public function buildQuickForm()
 {
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
         //enable form element (ActivityLinks sets this true)
         $this->assign('suppressForm', FALSE);
         $button = ts('Delete');
         if ($this->_action & CRM_Core_Action::RENEW) {
             $button = ts('Restore');
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $button, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     // Build other activity links.
     CRM_Activity_Form_ActivityLinks::commonBuildQuickForm($this);
     // Enable form element (ActivityLinks sets this true).
     $this->assign('suppressForm', FALSE);
     $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), array('' => '- ' . ts('select') . ' -') + $this->_fields['followup_activity_type_id']['attributes'], FALSE, array('onchange' => "CRM.buildCustomData( 'Activity', this.value );", 'class' => 'crm-select2 required'));
     // Freeze for update mode.
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     // Call to RecurringEntity buildQuickForm for add/update mode.
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         CRM_Core_Form_RecurringEntity::buildQuickForm($this);
     }
     foreach ($this->_fields as $field => $values) {
         if (!empty($this->_fields[$field])) {
             $attribute = CRM_Utils_Array::value('attributes', $values);
             $required = !empty($values['required']);
             if ($values['type'] == 'select' && empty($attribute)) {
                 $this->addSelect($field, array('entity' => 'activity'), $required);
             } elseif ($values['type'] == 'entityRef') {
                 $this->addEntityRef($field, $values['label'], $attribute, $required);
             } else {
                 $this->add($values['type'], $field, $values['label'], $attribute, $required, CRM_Utils_Array::value('extra', $values));
             }
         }
     }
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     // Add engagement level CRM-7775
     $buildEngagementLevel = FALSE;
     if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $buildEngagementLevel = TRUE;
         $this->addSelect('engagement_level', array('entity' => 'activity'));
         $this->addRule('engagement_level', ts('Please enter the engagement index as a number (integers only).'), 'positiveInteger');
     }
     $this->assign('buildEngagementLevel', $buildEngagementLevel);
     // check for survey activity
     $this->_isSurveyActivity = FALSE;
     if ($this->_activityId && CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $this->_isSurveyActivity = CRM_Campaign_BAO_Survey::isSurveyActivity($this->_activityId);
         if ($this->_isSurveyActivity) {
             $surveyId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'source_record_id');
             $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId);
             if ($responseOptions) {
                 $this->add('select', 'result', ts('Result'), array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions));
             }
             $surveyTitle = NULL;
             if ($surveyId) {
                 $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'title');
             }
             $this->assign('surveyTitle', $surveyTitle);
         }
     }
     $this->assign('surveyActivity', $this->_isSurveyActivity);
     // this option should be available only during add mode
     if ($this->_action != CRM_Core_Action::UPDATE) {
         $this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each contact.'));
     }
     $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     $this->addDateTime('activity_date_time', ts('Date'), TRUE, array('formatType' => 'activityDateTime'));
     // Add followup date.
     $this->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime'));
     // Only admins and case-workers can change the activity source
     if (!CRM_Core_Permission::check('administer CiviCRM') && $this->_context != 'caseActivity') {
         $this->getElement('source_contact_id')->freeze();
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Activity');
     $this->assign('customDataSubType', $this->_activityTypeId);
     $this->assign('entityID', $this->_activityId);
     CRM_Core_BAO_Tag::getTags('civicrm_activity', $tags, NULL, '&nbsp;&nbsp;', TRUE);
     if (!empty($tags)) {
         $this->add('select', 'tag', ts('Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2 huge'));
     }
     // we need to hide activity tagset for special activities
     $specialActivities = array('Open Case');
     if (!in_array($this->_activityTypeName, $specialActivities)) {
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
         CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId);
     }
     // if we're viewing, we're assigning different buttons than for adding/editing
     if ($this->_action & CRM_Core_Action::VIEW) {
         if (isset($this->_groupTree)) {
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree);
         }
         // form should be frozen for view mode
         $this->freeze();
         $buttons = array();
         $buttons[] = array('type' => 'cancel', 'name' => ts('Done'));
         $this->addButtons($buttons);
     } else {
         $message = array('completed' => ts('Are you sure? This is a COMPLETED activity with the DATE in the FUTURE. Click Cancel to change the date / status. Otherwise, click OK to save.'), 'scheduled' => ts('Are you sure? This is a SCHEDULED activity with the DATE in the PAST. Click Cancel to change the date / status. Otherwise, click OK to save.'));
         $js = array('onclick' => "return activityStatus(" . json_encode($message) . ");");
         $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     }
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::buildQuickForm($this);
         $this->addFormRule(array($className, 'formRule'), $this);
     }
     $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);
     if (Civi::settings()->get('activity_assignee_notification')) {
         $this->assign('activityAssigneeNotification', TRUE);
     } else {
         $this->assign('activityAssigneeNotification', FALSE);
     }
 }
Exemple #20
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     require_once 'CRM/Contribute/BAO/Contribution.php';
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     $softParams = array('contribution_id' => $values['contribution_id']);
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, true)) {
         $values = array_merge($values, $softContribution);
     }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     if (CRM_Utils_Array::value('honor_contact_id', $values)) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1";
         $params = array(1 => array($values['honor_contact_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     if (CRM_Utils_Array::value('contribution_recur_id', $values)) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values["recur_installments"] = $dao->installments;
             $values["recur_frequency_unit"] = $dao->frequency_unit;
             $values["recur_frequency_interval"] = $dao->frequency_interval;
         }
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, $values['contribution_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = null;
     if ($id) {
         require_once 'CRM/Contribute/DAO/ContributionProduct.php';
         $dao =& new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(true)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         require_once 'CRM/Contribute/DAO/Product.php';
         $productDAO =& new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(true);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (CRM_Utils_Array::value('address_id', $values)) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, false, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //get soft credit record if exists.
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
         $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name');
         //hack to avoid dispalyName conflict
         //for viewing softcredit record.
         $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $values = array_merge($values, $softContribution);
     }
     require_once 'CRM/Price/BAO/Set.php';
     $lineItems = array();
     if ($id && CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         require_once 'CRM/Price/BAO/LineItem.php';
         $lineItems[] = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution');
     }
     $this->assign('lineItem', empty($lineItems) ? false : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     // assign values to the template
     $this->assign($values);
     // add viewed contribution to recent items list
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
     $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name') . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')';
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], null);
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  *
  * @return void
  */
 public function run()
 {
     $this->preProcess();
     //set the userContext stack
     $doneURL = 'civicrm/contact/view';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
     // get permission detail view or edit
     // use a comtact id specific function which gives us much better granularity
     // CRM-12646
     $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
     $this->assign('editCustomData', $editCustomData);
     //allow to edit own customdata CRM-5518
     $editOwnCustomData = FALSE;
     if ($session->get('userID') == $this->_contactId) {
         $editOwnCustomData = TRUE;
     }
     $this->assign('editOwnCustomData', $editOwnCustomData);
     if ($this->_action == CRM_Core_Action::BROWSE) {
         //Custom Groups Inline
         $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
         $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType);
         $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'style');
         if ($this->_multiRecordDisplay != 'single') {
             $id = "custom_{$this->_groupId}";
             $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
         }
         if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
             $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
             $this->assign('displayStyle', 'tableOriented');
             // here the multi custom data listing code will go
             $multiRecordFieldListing = TRUE;
             $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
             $page->set('contactId', $this->_contactId);
             $page->set('customGroupId', $this->_groupId);
             $page->set('action', CRM_Core_Action::BROWSE);
             $page->set('multiRecordFieldListing', $multiRecordFieldListing);
             $page->set('pageViewType', 'customDataView');
             $page->set('contactType', $ctype);
             $page->run();
         } else {
             $recId = NULL;
             if ($this->_multiRecordDisplay == 'single') {
                 $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
                 CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
                 $recId = $this->_recId;
                 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
                 $this->assign('skipTitle', 1);
             }
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
         }
     } else {
         $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action);
         $controller->setEmbedded(TRUE);
         $controller->set('tableId', $this->_contactId);
         $controller->set('groupId', $this->_groupId);
         $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
         $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
         $controller->process();
         $controller->run();
     }
     return parent::run();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
     $this->assign('multiClient', $isMultiClient);
     //pull the related cases.
     $this->assign('showRelatedCases', FALSE);
     if ($this->_showRelatedCases) {
         $relatedCases = $this->get('relatedCases');
         if (!isset($relatedCases)) {
             $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
             $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject);
             $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId);
         }
         $this->assign('relatedCases', $relatedCases);
         $this->assign('showRelatedCases', TRUE);
         CRM_Utils_System::setTitle(ts('Related Cases'));
         return;
     }
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
     $this->_contactID = $this->get('cid');
     $this->_caseID = $this->get('id');
     $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject);
     if ($fulltext == 'fulltext') {
         $this->assign('fulltext', $fulltext);
     }
     $this->assign('caseID', $this->_caseID);
     $this->assign('contactID', $this->_contactID);
     //validate case id.
     $this->_userCases = array();
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if (!$this->_hasAccessToAllCases) {
         $this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'any');
         if (!array_key_exists($this->_caseID, $this->_userCases)) {
             CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
         }
     }
     $this->assign('userID', $userID);
     if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) {
         $this->_mergeCases = TRUE;
     }
     $this->assign('mergeCases', $this->_mergeCases);
     //retrieve details about case
     $params = array('id' => $this->_caseID);
     $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
     CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
     $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name');
     $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID);
     $this->_caseDetails = array('case_type' => $caseType, 'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses), 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']);
     $this->_caseType = $caseTypeName;
     $this->assign('caseDetails', $this->_caseDetails);
     $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", FALSE, NULL, FALSE);
     $this->assign('reportUrl', $reportUrl);
     // add to recently viewed
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
     $this->assign('displayName', $displayName);
     CRM_Utils_System::setTitle($displayName . ' - ' . $caseType);
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     }
     // Add the recently viewed case
     CRM_Utils_Recent::add($displayName . ' - ' . $caseType, $url, $this->_caseID, 'Case', $this->_contactID, NULL, $recentOther);
     //get the related cases for given case.
     $relatedCases = $this->get('relatedCases');
     if (!isset($relatedCases)) {
         $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID);
         $relatedCases = empty($relatedCases) ? FALSE : $relatedCases;
         $this->set('relatedCases', $relatedCases);
     }
     $this->assign('hasRelatedCases', (bool) $relatedCases);
     if ($relatedCases) {
         $this->assign('relatedCaseLabel', ts('%1 Related Case', array('count' => count($relatedCases), 'plural' => '%1 Related Cases')));
         $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array('id' => $this->_caseID, 'cid' => $this->_contactID, 'relatedCases' => 1, 'action' => 'view')));
     }
     $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL;
     $this->assign('caseTypeID', $entitySubType);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_caseID, NULL, $entitySubType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
 }
Exemple #23
0
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true));
     foreach ($communicationType as $key => $value) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false);
                 if (!CRM_Utils_Array::value('skip', $value)) {
                     eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false);
                 }
             }
             if (isset($value['customData'])) {
                 foreach ($defaults[$key] as $blockId => $blockVal) {
                     $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']);
                     // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
                     $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_");
                 }
                 // reset template variable since that won't be of any use, and could be misleading
                 $this->assign("dnc_viewCustomData", null);
             }
         }
     }
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // to make contact type label available in the template -
     $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
     $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType);
     // get contact tags
     require_once 'CRM/Core/BAO/EntityTag.php';
     $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
     if (!empty($contactTags)) {
         $defaults['contactTag'] = implode(', ', $contactTags);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options');
     $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes');
     foreach ($configItems as $c => $t) {
         $varName = '_show' . $c;
         $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions);
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     // get contact name of shared contact names
     $sharedAddresses = array();
     $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
     foreach ($defaults['address'] as $key => $addressValue) {
         if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
             $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
         }
     }
     $this->assign('sharedAddresses', $sharedAddresses);
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         if ($contact->employer_id && $contact->organization_name) {
             $defaults['current_employer'] = $contact->organization_name;
             $defaults['current_employer_id'] = $contact->employer_id;
         }
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $this->assign($defaults);
     // also assign the last modifed details
     require_once 'CRM/Core/BAO/Log.php';
     $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true);
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     require_once 'CRM/Core/Component.php';
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q = $q . "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId));
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log'));
     $config = CRM_Core_Config::singleton();
     if (isset($config->sunlight) && $config->sunlight) {
         $title = ts('Elected Officials');
         $rest['sunlight'] = $title;
         $this->_viewOptions[$title] = true;
     }
     foreach ($rest as $k => $v) {
         if (CRM_Utils_Array::value($k, $this->_viewOptions)) {
             $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $entityType = $this->get('contactType');
     $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']));
         $weight += 10;
     }
     // see if any other modules want to add any tabs
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     // now sort the tabs based on weight
     require_once 'CRM/Utils/Sort.php';
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary');
     $this->assign('selectedChild', $selectedChild);
     // hook for contact summary
     require_once 'CRM/Utils/Hook.php';
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     // ignored but needed to prevent warnings
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
Exemple #24
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
 /**
  * @param $form
  * @param $subType
  * @param $gid
  * @param $onlySubType
  * @param $getCachedTree
  *
  * @return array
  */
 public static function setGroupTree(&$form, $subType, $gid, $onlySubType, $getCachedTree = FALSE)
 {
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
     if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
         $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
     }
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
         return array($form, $groupTree);
     } else {
         $form->_groupTree = $groupTree;
         return array($form, $groupTree);
     }
 }
 /**
  * Set the default form values.
  *
  *
  * @return array
  *   the default array reference
  */
 public function setDefaultValues()
 {
     if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
         if ($this->_copyValueId) {
             // cached tree is fetched
             $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $this->_entityId, $this->_groupID);
             $valueIdDefaults = array();
             $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this);
             CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action'));
             $tableId = $groupTreeValueId[$this->_groupID]['table_id'];
             foreach ($valueIdDefaults as $valueIdElementName => $value) {
                 // build defaults for COPY action for new record saving
                 $valueIdElementNamePieces = explode('_', $valueIdElementName);
                 $valueIdElementNamePieces[2] = "-{$this->_groupCount}";
                 $elementName = implode('_', $valueIdElementNamePieces);
                 $customDefaultValue[$elementName] = $value;
             }
         } else {
             $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
         return $customDefaultValue;
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
     if (empty($_POST['hidden_custom_group_count'])) {
         // custom data building in edit mode (required to handle multi-value)
         $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
         $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
     } else {
         $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
     }
     $this->assign('customValueCount', $customValueCount);
     $defaults = array();
     return $defaults;
 }
Exemple #27
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $values = array();
     $params['id'] = $this->_id;
     require_once 'CRM/Grant/BAO/Grant.php';
     CRM_Grant_BAO_Grant::retrieve($params, $values);
     require_once 'CRM/Grant/PseudoConstant.php';
     $grantType = CRM_Grant_PseudoConstant::grantType();
     $grantStatus = CRM_Grant_PseudoConstant::grantStatus();
     $this->assign('grantType', $grantType[$values['grant_type_id']]);
     $this->assign('grantStatus', $grantStatus[$values['status_id']]);
     $grantTokens = array('amount_total', 'amount_requested', 'amount_granted', 'rationale', 'grant_report_received', 'application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($grantTokens as $token) {
         $this->assign($token, CRM_Utils_Array::value($token, $values));
     }
     if (isset($this->_id)) {
         require_once 'CRM/Core/BAO/Note.php';
         $noteDAO =& new CRM_Core_BAO_Note();
         $noteDAO->entity_table = 'civicrm_grant';
         $noteDAO->entity_id = $this->_id;
         if ($noteDAO->find(true)) {
             $this->_noteId = $noteDAO->id;
         }
     }
     if (isset($this->_noteId)) {
         $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
     }
     // add Grant to Recent Items
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Utils/Money.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], null);
     require_once 'CRM/Core/BAO/File.php';
     $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
     $this->assign('attachment', $attachment);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @access public
  *
  * @param object $page - the view page which created this one
  *
  * @return none
  * @static
  *
  */
 function run()
 {
     $this->preProcess();
     //set the userContext stack
     $doneURL = 'civicrm/contact/view';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
     // get permission detail view or edit
     $permUser = CRM_Core_Permission::getPermission();
     $editCustomData = CRM_Core_Permission::VIEW == $permUser ? 0 : 1;
     $this->assign('editCustomData', $editCustomData);
     //allow to edit own customdata CRM-5518
     $editOwnCustomData = FALSE;
     if ($session->get('userID') == $this->_contactId) {
         $editOwnCustomData = TRUE;
     }
     $this->assign('editOwnCustomData', $editOwnCustomData);
     if ($this->_action == CRM_Core_Action::BROWSE) {
         //Custom Groups Inline
         $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
         $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     } else {
         $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action);
         $controller->setEmbedded(TRUE);
         $controller->set('tableId', $this->_contactId);
         $controller->set('groupId', $this->_groupId);
         $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
         $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
         $controller->process();
         $controller->run();
     }
     return parent::run();
 }
Exemple #29
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Event/BAO/Event.php';
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) {
         CRM_Core_Error::fatal(ts('You do not have permission to view this event'));
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, false, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url("civicrm/event/info", "id={$this->_id}&reset=1");
     $additionalBreadCrumb = "<a href=\"{$breadCrumbPath}\">" . ts('Events') . '</a>';
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     require_once 'CRM/Price/BAO/Set.php';
     if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
         // get price set options, - CRM-5209
         if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id)) {
             $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId);
             eval("\$priceSetFields = \$setDetails[{$priceSetId}][fields];");
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options'])) {
                         continue;
                     }
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['value'][$fieldCnt] = $optionVal['value'];
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['description'];
                         $fieldCnt++;
                     }
                 }
             }
         } else {
             //retrieve event fee block.
             require_once 'CRM/Core/OptionGroup.php';
             require_once 'CRM/Core/BAO/Discount.php';
             $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
             if ($discountId) {
                 CRM_Core_OptionGroup::getAssoc(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'), $values['feeBlock'], false, 'id');
             } else {
                 CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$this->_id}", $values['feeBlock']);
             }
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     require_once 'CRM/Core/BAO/Location.php';
     $values['location'] = CRM_Core_BAO_Location::getValues($params, true);
     //retrieve custom field information
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Event", $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations =& CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = +400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
     }
     require_once 'CRM/Event/BAO/Participant.php';
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id);
     if ($eventFullMessage and $noFullMsg == 'false') {
         if (CRM_Utils_Array::value('has_waitlist', $values['event'])) {
             $eventFullMessage = null;
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event'], 'Event is currently full, but you can register and be a part of waiting list.');
         } else {
             $statusMessage = $eventFullMessage;
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     if (CRM_Utils_Array::value('is_online_registration', $values['event'])) {
         if (CRM_Event_BAO_Event::validRegistrationDate($values['event'], $this->_id)) {
             if (!$eventFullMessage) {
                 $registerText = ts('Register Now');
                 if (CRM_Utils_Array::value('registration_link_text', $values['event'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 //Fixed for CRM-4855
                 if (CRM_Event_BAO_Event::showHideRegistrationLink($values)) {
                     $this->assign('allowRegistration', true);
                 }
                 $this->assign('registerText', $registerText);
             }
             // we always generate urls for the front end in joomla
             if ($action == CRM_Core_Action::PREVIEW) {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1&action=preview", true, null, true, true);
             } else {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1", true, null, true, true);
             }
             if (!$eventFullMessage) {
                 $this->assign('registerURL', $url);
             }
         }
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", true, null, true, true);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", true, null, true, true);
         }
         $this->assign('mapURL', $mapURL);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     parent::run();
 }
Exemple #30
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     $this->_jobHoursTime = CRM_Hrjobcontract_Page_JobContractTab::getJobHoursTime();
     $this->assign('jobHoursTime', $this->_jobHoursTime);
     $this->_aid = CRM_Utils_Request::retrieve('aid', 'Int', $this);
     $session = CRM_Core_Session::singleton();
     $this->_loginUserID = $session->get('userID');
     if (CRM_Utils_Request::retrieve('cid', 'Positive', $this)) {
         $this->assign('contactId', CRM_Utils_Request::retrieve('cid', 'Positive', $this));
     }
     $activityTypes = CRM_Core_PseudoConstant::activityType();
     $resultHoliday = civicrm_api3('Activity', 'get', array('activity_type_id' => array_search('Public Holiday', $activityTypes)));
     $publicHolidays = array();
     foreach ($resultHoliday['values'] as $key => $val) {
         $pubDate = date("M j, Y", strtotime($val['activity_date_time']));
         $publicHolidays[$pubDate] = $val['subject'];
     }
     $publicHolidays = json_encode($publicHolidays);
     $this->assign('publicHolidays', $publicHolidays);
     // Load the activity entity
     $main_activity = entity_load_single('civicrm_activity', $this->_aid);
     // Check if attachment is set
     if (isset($main_activity->field_attachment['und'][0]['uri'])) {
         $imgpath = $main_activity->field_attachment['und'][0]['uri'];
         $markup = '<div class="show-attached-file"><div class="show-attached-file-label"><b>' . t('Attached file: ') . '</b></div>' . l("View Attachment", file_create_url($imgpath), array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . '</div>';
     } else {
         $markup = ts('No File Attached!');
     }
     // Assign the attached file URL
     $this->assign('attachedFile', $markup);
     if ($this->_action == CRM_Core_Action::VIEW || $this->_action == CRM_Core_Action::UPDATE) {
         $this->_activityId = CRM_Utils_Request::retrieve('aid', 'String', $this);
         $this->assign('upActivityId', $this->_activityId);
         $resultAct = civicrm_api3('Activity', 'get', array('sequential' => 1, 'id' => $this->_activityId, 'return.target_contact_id' => 1, 'return.assignee_contact_id' => 1, 'return.source_contact_id' => 1, 'option.limit' => 365));
         $this->_activityTypeID = $resultAct['values'][0]['activity_type_id'];
         $this->_targetContactID = $resultAct['values'][0]['target_contact_id'][0];
         $this->_actStatusId = $resultAct['values'][0]['status_id'];
         //condition to check if it has any manager against this absence
         if (array_key_exists(0, $resultAct['values'][0]['assignee_contact_id'])) {
             $this->_managerContactID = self::getManagerContacts($this->_targetContactID);
         }
         //Mode is edit if user has edit or admisniter permission or is manager to this absence or
         //(target/requested user and action is update and has manage own Absence permission)
         //(else mode is view if the action is view or already reviewed) and has (view permission
         //or (manage own absence permission and logged in user is target contact itself)
         $absenceStatuses = CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus();
         if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Core_Permission::check('edit HRAbsences') || in_array($this->_loginUserID, $this->_managerContactID) || $absenceStatuses[$this->_actStatusId] == 'Requested' && $this->_action == CRM_Core_Action::UPDATE && $this->_targetContactID == $this->_loginUserID && CRM_Core_Permission::check('manage own HRAbsences')) {
             $this->_mode = 'edit';
         } elseif (($this->_action == CRM_Core_Action::VIEW || $absenceStatuses[$this->_actStatusId] != 'Requested') && (CRM_Core_Permission::check('view HRAbsences') || CRM_Core_Permission::check('manage own HRAbsences') && ($this->_targetContactID = $this->_loginUserID))) {
             $this->_mode = 'view';
         }
         //check for ACL View/Edit permission
         if (empty($this->_mode)) {
             if (self::isContactAccessible($this->_targetContactID) == CRM_Core_Permission::EDIT) {
                 $this->_mode = 'edit';
             } elseif (self::isContactAccessible($this->_targetContactID) == CRM_Core_Permission::VIEW) {
                 $this->_mode = 'view';
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_targetContactID);
         $activityTypes = CRM_HRAbsence_BAO_HRAbsenceType::getActivityTypes();
         $activityType = $activityTypes[$this->_activityTypeID];
         $activity = CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus();
         $activityStatus = $activity[$this->_actStatusId];
         CRM_Utils_System::setTitle(ts("Absence for  %1 (%2, %3)", array(1 => $displayName, 2 => $activityType, 3 => $activityStatus)));
         if ($this->_action == CRM_Core_Action::VIEW) {
             $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeID);
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         } else {
             $this->assign('activityType', $this->_activityTypeID);
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeID, 1, 'Activity', $this->_activityId, TRUE);
             $this->assign('customValueCount', $this->_customValueCount);
         }
     } elseif ($this->_action == CRM_Core_Action::ADD) {
         $this->_mode = 'edit';
         CRM_Utils_System::setTitle(ts('Absence Request: Add'));
         $this->_activityTypeID = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
         if ($this->_activityTypeID) {
             //only custom data has preprocess hence directly call it
             $this->assign('activityType', $this->_activityTypeID);
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeID, 1, 'Activity', NULL, TRUE);
             $this->assign('customValueCount', $this->_customValueCount);
         }
         $this->_targetContactID = 0;
         if (CRM_Utils_Request::retrieve('cid', 'Positive', $this) !== NULL) {
             $this->_targetContactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
         } else {
             //if there is no cid passed then consider target contact as logged in user
             //who will applying leave for himself
             $this->_targetContactID = $this->_loginUserID;
         }
         $this->_managerContactID = self::getManagerContacts($this->_targetContactID);
     }
     $this->assign('mode', $this->_mode);
     CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.hrabsence', 'css/hrabsence.css');
     parent::preProcess();
 }