コード例 #1
0
ファイル: ActivityView.php プロジェクト: hguru/224Civi
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     //get the activity values
     $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //check for required permissions, CRM-6264
     if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $session = CRM_Core_Session::singleton();
     if (!in_array($context, array('home', 'dashlet', 'dashletFullscreen'))) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
     } else {
         $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
     }
     $session->pushUserContext($url);
     $defaults = array();
     $params = array('id' => $activityId);
     CRM_Activity_BAO_Activity::retrieve($params, $defaults);
     //set activity type name and description to template
     list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
     $this->assign('activityTypeName', $activityTypeName);
     $this->assign('activityTypeDescription', $activityTypeDescription);
     if (CRM_Utils_Array::value('mailingId', $defaults)) {
         $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
         $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
         CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
         $this->assign('mailingReport', $mailingReport);
         $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
         $this->assign('openreport', $full_open_report);
         $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
         $this->assign('clickreport', $click_thru_report);
     }
     foreach ($defaults as $key => $value) {
         if (substr($key, -3) != '_id') {
             $values[$key] = $value;
         }
     }
     //get the campaign
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
         $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
         $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
     }
     $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
     $this->assign('values', $values);
 }
コード例 #2
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     //get the activity values
     $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //check for required permissions, CRM-6264
     if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $session = CRM_Core_Session::singleton();
     if ($context != 'home') {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
     } else {
         $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
     }
     $session->pushUserContext($url);
     $params = array('id' => $activityId);
     CRM_Activity_BAO_Activity::retrieve($params, $defaults);
     //set activity type name and description to template
     require_once 'CRM/Core/BAO/OptionValue.php';
     list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
     $this->assign('activityTypeName', $activityTypeName);
     $this->assign('activityTypeDescription', $activityTypeDescription);
     if (CRM_Utils_Array::value('mailingId', $defaults)) {
         $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
         require_once 'CRM/Mailing/BAO/Mailing.php';
         $mailingReport =& CRM_Mailing_BAO_Mailing::report($this->_mailing_id, true);
         CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
         $this->assign('mailingReport', $mailingReport);
     }
     foreach ($defaults as $key => $value) {
         if (substr($key, -3) != '_id') {
             $values[$key] = $value;
         }
     }
     require_once 'CRM/Core/BAO/File.php';
     $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
     $this->assign('values', $values);
 }
コード例 #3
0
 /**
  * Build the form object.
  */
 public function preProcess()
 {
     CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', FALSE);
     if ($this->_atypefile) {
         $this->assign('atypefile', TRUE);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->assign('contactId', $this->_currentlyViewedContactId);
     // Give the context.
     if (!isset($this->_context)) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
             $this->_context = 'search';
         } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) {
             $this->_context = 'activity';
         }
         $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     // CRM-6957
     // When we come from contact search, activity id never comes.
     // So don't try to get from object, it might gives you wrong one.
     // if we're not adding new one, there must be an id to
     // an activity we're trying to work on.
     if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') {
         $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     $this->assign('activityId', $this->_activityId);
     // Check for required permissions, CRM-6264.
     if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) {
         $this->assign('permission', 'edit');
     }
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     // Assigning Activity type name.
     if ($this->_activityTypeId) {
         $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label');
         if ($activityTName[$this->_activityTypeId]) {
             $this->_activityTypeName = $activityTName[$this->_activityTypeId];
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     // Set title.
     if (isset($activityTName)) {
         $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
         $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName)));
         if ($this->_currentlyViewedContactId) {
             $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
             // Check if this is default domain contact CRM-10482.
             if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) {
                 $displayName .= ' (' . ts('default organization') . ')';
             }
             CRM_Utils_System::setTitle($displayName . ' - ' . $activityName);
         } else {
             CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName)));
         }
     }
     // Check the mode when this form is called either single or as
     // search task action.
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         // Set the appropriate action.
         $url = CRM_Utils_System::currentPath();
         $urlArray = explode('/', $url);
         $searchPath = array_pop($urlArray);
         $searchType = 'basic';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($searchPath) {
             case 'basic':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'advanced':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'custom':
                 $this->_action = CRM_Core_Action::COPY;
                 $searchType = $searchPath;
                 break;
         }
         parent::preProcess();
         $this->_single = FALSE;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // Get the tree of custom fields.
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         // Set activity type name and description to template.
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     // set user context
     $urlParams = $urlString = NULL;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     if (!$qfKey) {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     }
     // Validate the qfKey.
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = NULL;
     }
     if ($this->_context == 'fulltext') {
         $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $keyName = '&key';
             $urlParams .= '&context=fulltext&action=view';
             $urlString = 'civicrm/contact/view/activity';
         }
         if ($qfKey) {
             $urlParams .= "{$keyName}={$qfKey}";
         }
         $this->assign('searchKey', $qfKey);
     } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) {
         $urlParams = 'reset=1';
         $urlString = 'civicrm/dashboard';
     } elseif ($this->_context == 'search') {
         $urlParams = 'force=1';
         if ($qfKey) {
             $urlParams .= "&qfKey={$qfKey}";
         }
         $path = CRM_Utils_System::currentPath();
         if ($this->_compContext == 'advanced') {
             $urlString = 'civicrm/contact/search/advanced';
         } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') {
             $urlString = $path;
         } else {
             $urlString = 'civicrm/activity/search';
         }
         $this->assign('searchKey', $qfKey);
     } elseif ($this->_context != 'caseActivity') {
         $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity";
         $urlString = 'civicrm/contact/view';
     }
     if ($urlString) {
         $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // We need to set it in the session for the code below to work.
         // CRM-3014
         // Need to assign custom data subtype to the template.
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::preProcess($this);
     }
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_activityId) && $this->_activityId) {
             $params = array('id' => $this->_activityId);
             CRM_Activity_BAO_Activity::retrieve($params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     }
 }
コード例 #4
0
ファイル: Activity.php プロジェクト: bhirsch/voipdev
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 function preProcess()
 {
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', false);
     if ($this->_cdType) {
         $this->assign('cdType', true);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', false);
     if ($this->_atypefile) {
         $this->assign('atypefile', true);
     }
     $this->_addAssigneeContact = CRM_Utils_Array::value('assignee_contact', $_GET);
     $this->assign('addAssigneeContact', false);
     if ($this->_addAssigneeContact) {
         $this->assign('addAssigneeContact', true);
     }
     $this->_addTargetContact = CRM_Utils_Array::value('target_contact', $_GET);
     $this->assign('addTargetContact', false);
     if ($this->_addTargetContact) {
         $this->assign('addTargetContact', true);
     }
     $session =& CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     // this is used for setting jQuery tabs
     if (!$this->_context) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
         }
     }
     if ($this->_context != 'search') {
         // if we're not adding new one, there must be an id to
         // an activity we're trying to work on.
         if ($this->_action != CRM_Core_Action::ADD) {
             $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
         }
     }
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     //Assigning Activity type name
     if ($this->_activityTypeId) {
         require_once 'CRM/Core/OptionGroup.php';
         $activityTName = CRM_Core_OptionGroup::values('activity_type', false, false, false, 'AND v.value = ' . $this->_activityTypeId, 'name');
         if ($activityTName[$this->_activityTypeId]) {
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     //check the mode when this form is called either single or as
     //search task action
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = true;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         //set the appropriate action
         $advanced = null;
         $builder = null;
         $session =& CRM_Core_Session::singleton();
         $advanced = $session->get('isAdvanced');
         $builder = $session->get('isSearchBuilder');
         $searchType = "basic";
         if ($advanced == 1) {
             $this->_action = CRM_Core_Action::ADVANCED;
             $searchType = "advanced";
         } else {
             if ($advanced == 2 && ($builder = 1)) {
                 $this->_action = CRM_Core_Action::PROFILE;
                 $searchType = "builder";
             } else {
                 if ($advanced == 3) {
                     $searchType = "custom";
                 }
             }
         }
         parent::preProcess();
         $this->_single = false;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // get the tree of custom fields
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree("Activity", $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         //set activity type name and description to template
         require_once 'CRM/Core/BAO/OptionValue.php';
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     $url = null;
     // set user context
     if (in_array($this->_context, array('standalone', 'home', 'search'))) {
         $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
     } else {
         if ($this->_context != 'caseActivity') {
             $url = CRM_Utils_System::url('civicrm/contact/view', "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity");
         }
     }
     if ($url) {
         $session->pushUserContext($url);
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value("hidden_custom", $_POST)) {
         // we need to set it in the session for the below code to work
         // CRM-3014
         //need to assign custom data subtype to the template
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         require_once "CRM/{$this->_crmDir}/Form/Activity/{$this->_activityTypeFile}.php";
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );");
     }
 }
コード例 #5
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 function preProcess()
 {
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', false);
     if ($this->_cdType) {
         $this->assign('cdType', true);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', false);
     if ($this->_atypefile) {
         $this->assign('atypefile', true);
     }
     $this->_addAssigneeContact = CRM_Utils_Array::value('assignee_contact', $_GET);
     $this->assign('addAssigneeContact', false);
     if ($this->_addAssigneeContact) {
         $this->assign('addAssigneeContact', true);
     }
     $this->_addTargetContact = CRM_Utils_Array::value('target_contact', $_GET);
     $this->assign('addTargetContact', false);
     if ($this->_addTargetContact) {
         $this->assign('addTargetContact', true);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     //give the context.
     if (!$this->_context) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         require_once 'CRM/Contact/Form/Search.php';
         if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
             $this->_context = 'search';
         }
         $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
         }
     }
     //CRM-6957
     //when we come from contact search, activity id never comes.
     //so don't try to get from object, it might gives you wrong one.
     // if we're not adding new one, there must be an id to
     // an activity we're trying to work on.
     if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') {
         $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     //check for required permissions, CRM-6264
     require_once 'CRM/Case/BAO/Case.php';
     if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     //Assigning Activity type name
     if ($this->_activityTypeId) {
         require_once 'CRM/Core/OptionGroup.php';
         $activityTName = CRM_Core_OptionGroup::values('activity_type', false, false, false, 'AND v.value = ' . $this->_activityTypeId, 'name');
         if ($activityTName[$this->_activityTypeId]) {
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     // Assign pageTitle to be "Activity - "+ activity name
     $pageTitle = 'Activity - ' . CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
     $this->assign('pageTitle', $pageTitle);
     //check the mode when this form is called either single or as
     //search task action
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = true;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         //set the appropriate action
         $url = CRM_Utils_System::currentPath();
         $seachPath = array_pop(explode('/', $url));
         $searchType = 'basic';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($seachPath) {
             case 'basic':
                 $searchType = $seachPath;
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'advanced':
                 $searchType = $seachPath;
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $searchType = $seachPath;
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'custom':
                 $this->_action = CRM_Core_Action::COPY;
                 $searchType = $seachPath;
                 break;
         }
         parent::preProcess();
         $this->_single = false;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // get the tree of custom fields
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         //set activity type name and description to template
         require_once 'CRM/Core/BAO/OptionValue.php';
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     // set user context
     $urlParams = $urlString = null;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     //validate the qfKey
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = null;
     }
     if ($this->_context == 'fulltext') {
         $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $keyName = '&key';
             $urlParams .= '&context=fulltext&action=view';
             $urlString = 'civicrm/contact/view/activity';
         }
         if ($qfKey) {
             $urlParams .= "{$keyName}={$qfKey}";
         }
         $this->assign('searchKey', $qfKey);
     } else {
         if (in_array($this->_context, array('standalone', 'home'))) {
             $urlParams = 'reset=1';
             $urlString = 'civicrm/dashboard';
         } else {
             if ($this->_context == 'search') {
                 $urlParams = 'force=1';
                 if ($qfKey) {
                     $urlParams .= "&qfKey={$qfKey}";
                 }
                 if ($this->_compContext == 'advanced') {
                     $urlString = 'civicrm/contact/search/advanced';
                 }
                 $this->assign('searchKey', $qfKey);
             } else {
                 if ($this->_context != 'caseActivity') {
                     $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity";
                     $urlString = 'civicrm/contact/view';
                 }
             }
         }
     }
     if ($urlString) {
         $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
         // we need to set it in the session for the below code to work
         // CRM-3014
         //need to assign custom data subtype to the template
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         require_once "CRM/{$this->_crmDir}/Form/Activity/{$this->_activityTypeFile}.php";
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );");
     }
 }