/**
  * Overridden parent method to initiate form
  *
  * @access public
  */
 function preProcess()
 {
     if ($this->_action != CRM_Core_Action::ADD) {
         $this->getContactSegment();
     } else {
         $exportValues = CRM_Utils_Request::exportValues();
         if (isset($exportValues['cid'])) {
             $this->_contactId = $exportValues['cid'];
         } else {
             if (isset($exportValues['contact_id'])) {
                 $this->_contactId = $exportValues['contact_id'];
             }
         }
     }
     $this->getSegmentLabels();
     switch ($this->_action) {
         case CRM_Core_Action::ADD:
             $actionLabel = "Add";
             break;
         case CRM_Core_Action::CLOSE:
             $this->closeContactSegmentAndReturn();
             break;
         case CRM_Core_Action::UPDATE:
             $actionLabel = "Edit";
             break;
     }
     $headerLabel = $this->_parentLabel . " or " . $this->_childLabel;
     CRM_Utils_System::setTitle($actionLabel . " " . $headerLabel);
     $this->assign('actionLabel', $actionLabel);
     $this->assign('headerLabel', $headerLabel);
     $contactName = (string) civicrm_api3('Contact', 'Getvalue', array('id' => $this->_contactId, 'return' => 'display_name'));
     $this->assign('contactName', $contactName);
 }
 /**
  * Method to process civicrm pre hook:
  * If objectName = GroupContact and Group is a protected group, check if user has permission.
  * When user does not have permission, redirect to user context with status message
  *
  */
 public static function pre($op, $objectName, $objectId, $params)
 {
     if ($objectName == 'GroupContact' && self::groupIsProtected($objectId) == TRUE) {
         // check if request is from webform, and allow groupcontact action if from webform
         $webFormRequest = FALSE;
         $request = CRM_Utils_Request::exportValues();
         if (isset($request['form_id'])) {
             $requestParts = explode('_', $request['form_id']);
             if (isset($requestParts[2])) {
                 if ($requestParts[0] == 'webform' && $requestParts[1] == 'client' && ($requestParts[2] = 'form')) {
                     $webFormRequest = TRUE;
                 }
             }
         }
         if (!$webFormRequest) {
             if (!CRM_Core_Permission::check('manage protected groups')) {
                 CRM_Core_Session::setStatus(ts("You are not allowed to add or remove contacts to this group"), ts("Not allowed"), "error");
                 // if from report, redirect to report instance
                 if (isset($request['q']) && substr($request['q'], 0, 15) == "civicrm/report/") {
                     CRM_Utils_System::redirect(CRM_Utils_System::url($request['q'], 'reset=1', true));
                 } else {
                     $session = CRM_Core_Session::singleton();
                     CRM_Utils_System::redirect($session->readUserContext());
                 }
             }
         }
     }
 }
Example #3
0
File: REST.php Project: kidaa30/yes
 /**
  * @return array|NULL
  *   NULL if execution should proceed; array if the response is already known
  */
 public function loadCMSBootstrap()
 {
     $requestParams = CRM_Utils_Request::exportValues();
     $q = CRM_Utils_array::value('q', $requestParams);
     $args = explode('/', $q);
     // Proceed with bootstrap for "?entity=X&action=Y"
     // Proceed with bootstrap for "?q=civicrm/X/Y" but not "?q=civicrm/ping"
     if (!empty($q)) {
         if (count($args) == 2 && $args[1] == 'ping') {
             return NULL;
             // this is pretty wonky but maybe there's some reason I can't see
         }
         if (count($args) != 3) {
             return self::error('ERROR: Malformed REST path');
         }
         if ($args[0] != 'civicrm') {
             return self::error('ERROR: Malformed REST path');
         }
         // Therefore we have reasonably well-formed "?q=civicrm/X/Y"
     }
     if (!CRM_Utils_System::authenticateKey(FALSE)) {
         // FIXME: At time of writing, this doesn't actually do anything because
         // authenticateKey abends, but that's a bad behavior which sends a
         // malformed response.
         return self::error('Failed to authenticate key');
     }
     $uid = NULL;
     if (!$uid) {
         $store = NULL;
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
         if (empty($api_key)) {
             return self::error("FATAL: mandatory param 'api_key' (user key) missing");
         }
         $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
         if ($contact_id) {
             $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
         }
     }
     if ($uid) {
         CRM_Utils_System::loadBootStrap(array('uid' => $uid), TRUE, FALSE);
         return NULL;
     } else {
         return self::error('ERROR: No CMS user associated with given api-key');
     }
 }
Example #4
0
 /**
  * Build the form object.
  */
 public function preProcess()
 {
     $this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($this->_action & CRM_Core_Action::ADD && !$this->_currentlyViewedContactId) {
         // check for add contacts permissions
         if (!CRM_Core_Permission::check('add contacts')) {
             CRM_Utils_System::permissionDenied();
             return;
         }
     }
     //CRM-4418
     if (!CRM_Core_Permission::checkActionPermission('CiviCase', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
         return TRUE;
     }
     if (!$this->_caseId) {
         $caseAttributes = array('case_type_id' => ts('Case Type'), 'status_id' => ts('Case Status'), 'medium_id' => ts('Activity Medium'));
         foreach ($caseAttributes as $key => $label) {
             if (!CRM_Case_BAO_Case::buildOptions($key, 'create')) {
                 CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => $label)));
             }
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->_activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
         if (!$this->_activityTypeId) {
             CRM_Core_Error::fatal(ts('The Open Case activity type is missing or disabled. Please have your site administrator check Administer > Option Lists > Activity Types for the CiviCase component.'));
         }
     }
     //check for case permissions.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::ADD && (!CRM_Core_Permission::check('access all cases and activities') && !CRM_Core_Permission::check('add cases'))) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     if ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, 'Case')) {
         $this->assign('activityTypeFile', $this->_activityTypeFile);
     }
     $details = CRM_Case_PseudoConstant::caseActivityType(FALSE);
     CRM_Utils_System::setTitle($details[$this->_activityTypeId]['label']);
     $this->assign('activityType', $details[$this->_activityTypeId]['label']);
     $this->assign('activityTypeDescription', $details[$this->_activityTypeId]['description']);
     if (isset($this->_currentlyViewedContactId)) {
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $this->_currentlyViewedContactId;
         if (!$contact->find(TRUE)) {
             CRM_Core_Error::statusBounce(ts('Client contact does not exist: %1', array(1 => $this->_currentlyViewedContactId)));
         }
         $this->assign('clientName', $contact->display_name);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     //when custom data is included in this page
     CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
     $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
     $className::preProcess($this);
     $activityGroupTree = $this->_groupTree;
     // for case custom fields to populate with defaults
     if (!empty($_POST['hidden_custom'])) {
         $params = CRM_Utils_Request::exportValues();
         CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     // so that grouptree is not populated with case fields, since the grouptree is used
     // for populating activity custom fields.
     $this->_groupTree = $activityGroupTree;
 }
Example #5
0
 public function fixFormValues()
 {
     if (!$this->_force) {
         return;
     }
     $status = CRM_Utils_Request::retrieve('status', 'String', $this);
     if ($status) {
         $this->_formValues['activity_status_id'] = $status;
         $this->_defaults['activity_status_id'] = $status;
     }
     $survey = CRM_Utils_Request::retrieve('survey', 'Positive', CRM_Core_DAO::$_nullObject);
     if ($survey) {
         $this->_formValues['activity_survey_id'] = $this->_defaults['activity_survey_id'] = $survey;
         $sid = CRM_Utils_Array::value('activity_survey_id', $this->_formValues);
         $activity_type_id = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
         // since checkbox are replaced by multiple select option
         $this->_formValues['activity_type_id'] = $activity_type_id;
         $this->_defaults['activity_type_id'] = $activity_type_id;
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($cid) {
         $cid = CRM_Utils_Type::escape($cid, 'Integer');
         if ($cid > 0) {
             $this->_formValues['contact_id'] = $cid;
             $activity_role = CRM_Utils_Request::retrieve('activity_role', 'Positive', $this);
             if ($activity_role) {
                 $this->_formValues['activity_role'] = $activity_role;
             } else {
                 $this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
             }
             // also assign individual mode to the template
             $this->_single = TRUE;
         }
     }
     // Added for membership search
     $signupType = CRM_Utils_Request::retrieve('signupType', 'Positive', CRM_Core_DAO::$_nullObject);
     if ($signupType) {
         //$this->_formValues['activity_type_id'] = array();
         $this->_formValues['activity_role'] = 1;
         $this->_defaults['activity_role'] = 1;
         $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
         $renew = CRM_Utils_Array::key('Membership Renewal', $activityTypes);
         $signup = CRM_Utils_Array::key('Membership Signup', $activityTypes);
         switch ($signupType) {
             case 3:
                 // signups and renewals
                 $this->_formValues['activity_type_id'][$renew] = 1;
                 $this->_defaults['activity_type_id'][$renew] = 1;
             case 1:
                 // signups only
                 $this->_formValues['activity_type_id'][$signup] = 1;
                 $this->_defaults['activity_type_id'][$signup] = 1;
                 break;
             case 2:
                 // renewals only
                 $this->_formValues['activity_type_id'][$renew] = 1;
                 $this->_defaults['activity_type_id'][$renew] = 1;
                 break;
         }
     }
     $dateLow = CRM_Utils_Request::retrieve('dateLow', 'String', CRM_Core_DAO::$_nullObject);
     if ($dateLow) {
         $dateLow = date('m/d/Y', strtotime($dateLow));
         $this->_formValues['activity_date_relative'] = 0;
         $this->_defaults['activity_date_relative'] = 0;
         $this->_formValues['activity_date_low'] = $dateLow;
         $this->_defaults['activity_date_low'] = $dateLow;
     }
     $dateHigh = CRM_Utils_Request::retrieve('dateHigh', 'String', CRM_Core_DAO::$_nullObject);
     if ($dateHigh) {
         // Activity date time assumes midnight at the beginning of the date
         // This sets it to almost midnight at the end of the date
         /*   if ($dateHigh <= 99999999) {
              $dateHigh = 1000000 * $dateHigh + 235959;
              } */
         $dateHigh = date('m/d/Y', strtotime($dateHigh));
         $this->_formValues['activity_date_relative'] = 0;
         $this->_defaults['activity_date_relative'] = 0;
         $this->_formValues['activity_date_high'] = $dateHigh;
         $this->_defaults['activity_date_high'] = $dateHigh;
     }
     // Enable search activity by custom value
     $requestParams = CRM_Utils_Request::exportValues();
     foreach (array_keys($requestParams) as $key) {
         if (substr($key, 0, 7) != 'custom_') {
             continue;
         } elseif (empty($requestParams[$key])) {
             continue;
         }
         $customValue = CRM_Utils_Request::retrieve($key, 'String', $this);
         if ($customValue) {
             $this->_formValues[$key] = $customValue;
             $this->_defaults[$key] = $customValue;
         }
     }
     if (!empty($this->_defaults)) {
         $this->setDefaults($this->_defaults);
     }
 }
Example #6
0
 /**
  * Form preProcess function.
  *
  * @throws \Exception
  */
 public function preProcess()
 {
     // This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
     $this->assign('formClass', 'membership');
     parent::preProcess();
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
         // check delete permission for contribution
         if ($this->_id && $contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) {
             // all possible statuses are disabled - redirect back to contact form
             CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured'));
         }
         if ($this->_contactID) {
             //check whether contact has a current membership so we can alert user that they may want to do a renewal instead
             $contactMemberships = array();
             $memParams = array('contact_id' => $this->_contactID);
             CRM_Member_BAO_Membership::getValues($memParams, $contactMemberships, TRUE);
             $cMemTypes = array();
             foreach ($contactMemberships as $mem) {
                 $cMemTypes[] = $mem['membership_type_id'];
             }
             if (count($cMemTypes) > 0) {
                 $memberorgs = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($cMemTypes);
                 $mems_by_org = array();
                 foreach ($contactMemberships as $mem) {
                     $mem['member_of_contact_id'] = CRM_Utils_Array::value($mem['membership_type_id'], $memberorgs);
                     if (!empty($mem['membership_end_date'])) {
                         $mem['membership_end_date'] = CRM_Utils_Date::customformat($mem['membership_end_date']);
                     }
                     $mem['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $mem['membership_type_id'], 'name', 'id');
                     $mem['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $mem['status_id'], 'label', 'id');
                     $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member" . ($this->_mode ? '&mode=live' : ''));
                     $mem['membershipTab'] = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
                     $mems_by_org[$mem['member_of_contact_id']] = $mem;
                 }
                 $this->assign('existingContactMemberships', $mems_by_org);
             }
         } else {
             // In standalone mode we don't have a contact id yet so lookup will be done client-side with this script:
             $resources = CRM_Core_Resources::singleton();
             $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js');
             $passthru = array('typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), 'memtypes' => CRM_Core_PseudoConstant::get('CRM_Member_BAO_Membership', 'membership_type_id'), 'statuses' => CRM_Core_PseudoConstant::get('CRM_Member_BAO_Membership', 'status_id'));
             $resources->addSetting(array('existingMems' => $passthru));
         }
     }
     if (!$this->_memType) {
         $params = CRM_Utils_Request::exportValues();
         if (!empty($params['membership_type_id'][1])) {
             $this->_memType = $params['membership_type_id'][1];
         }
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_memType, 1, 'Membership', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership');
     }
     $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId);
     $this->setPageTitle(ts('Membership'));
 }
Example #7
0
 /**
  * Process the user submitted custom data values.
  */
 public function postProcess()
 {
     // Get the form values and groupTree
     $params = CRM_Utils_Request::exportValues();
     CRM_Core_BAO_CustomValueTable::postProcess($params, 'civicrm_contact', $this->_tableID, $this->_entityType);
     $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name');
     $cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE);
     $cgcount += 1;
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('upload', 'new')) {
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add"));
     }
     // Add entry in the log table
     CRM_Core_BAO_Log::register($this->_tableID, 'civicrm_contact', $this->_tableID);
     if (CRM_Core_Resources::isAjaxMode()) {
         $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID);
     }
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
 }
Example #8
0
 public function preProcess()
 {
     $this->_contactId = $this->get('contactId');
     $this->_contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
     $this->_relationshipId = $this->get('id');
     $this->_rtype = CRM_Utils_Request::retrieve('rtype', 'String', $this);
     $this->_rtypeId = CRM_Utils_Request::retrieve('relTypeId', 'String', $this);
     $this->_display_name_a = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name');
     $this->assign('display_name_a', $this->_display_name_a);
     //get the relationship values.
     $this->_values = array();
     if ($this->_relationshipId) {
         $params = array('id' => $this->_relationshipId);
         CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Relationship', $params, $this->_values);
     }
     // Check for permissions
     if (in_array($this->_action, array(CRM_Core_Action::ADD, CRM_Core_Action::UPDATE, CRM_Core_Action::DELETE))) {
         if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT) && !CRM_Contact_BAO_Contact_Permission::allow($this->_values['contact_id_b'], CRM_Core_Permission::EDIT)) {
             CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
         }
     }
     // Set page title based on action
     switch ($this->_action) {
         case CRM_Core_Action::VIEW:
             CRM_Utils_System::setTitle(ts('View Relationship for %1', array(1 => $this->_display_name_a)));
             break;
         case CRM_Core_Action::ADD:
             CRM_Utils_System::setTitle(ts('Add Relationship for %1', array(1 => $this->_display_name_a)));
             break;
         case CRM_Core_Action::UPDATE:
             CRM_Utils_System::setTitle(ts('Edit Relationship for %1', array(1 => $this->_display_name_a)));
             break;
         case CRM_Core_Action::DELETE:
             CRM_Utils_System::setTitle(ts('Delete Relationship for %1', array(1 => $this->_display_name_a)));
             break;
     }
     $this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
     if (!$this->_rtypeId) {
         $params = CRM_Utils_Request::exportValues();
         if (isset($params['relationship_type_id'])) {
             $this->_rtypeId = $params['relationship_type_id'];
         } elseif (!empty($this->_values)) {
             $this->_rtypeId = $this->_values['relationship_type_id'] . '_' . $this->_rtype;
         }
     }
     //get the relationship type id
     $this->_relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $this->_rtypeId);
     //get the relationship type
     if (!$this->_rtype) {
         $this->_rtype = str_replace($this->_relationshipTypeId . '_', '', $this->_rtypeId);
     }
     //need to assign custom data type and subtype to the template - FIXME: explain why
     $this->assign('customDataType', 'Relationship');
     $this->assign('customDataSubType', $this->_relationshipTypeId);
     $this->assign('entityID', $this->_relationshipId);
     //use name as it remain constant, CRM-3336
     $this->_allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name');
     // Current employer?
     if ($this->_action & CRM_Core_Action::UPDATE) {
         if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_a_b"] == 'Employee of') {
             $this->_isCurrentEmployer = $this->_values['contact_id_b'] == CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_values['contact_id_a'], 'employer_id');
         }
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_relationshipTypeId, 1, 'Relationship', $this->_relationshipId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
 }