コード例 #1
0
ファイル: Activity.php プロジェクト: bhirsch/voipdev
 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' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (!$this->_single && !empty($this->_contactIds)) {
         $withArray = array();
         require_once 'CRM/Contact/BAO/Contact.php';
         foreach ($this->_contactIds as $contactId) {
             $withDisplayName = self::_getDisplayNameById($contactId);
             $withArray[] = "\"{$withDisplayName}\" ";
         }
         $this->assign('with', implode(', ', $withArray));
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //build other activity links
     require_once "CRM/Activity/Form/ActivityLinks.php";
     CRM_Activity_Form_ActivityLinks::buildQuickForm();
     //enable form element (ActivityLinks sets this true)
     $this->assign('suppressForm', false);
     $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], false, array('onchange' => "buildCustomData( 'Activity', this.value );"));
     //freeze for update mode.
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     foreach ($this->_fields as $field => $values) {
         if (CRM_Utils_Array::value($field, $this->_fields)) {
             $attribute = null;
             if (CRM_Utils_Array::value('attributes', $values)) {
                 $attribute = $values['attributes'];
             }
             $required = false;
             if (CRM_Utils_Array::value('required', $values)) {
                 $required = true;
             }
             $this->add($values['type'], $field, $values['label'], $attribute, $required);
         }
     }
     $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     $this->addRule('interval', ts('Please enter the follow-up interval as a number (integers only).'), 'positiveInteger');
     $this->addDateTime('activity_date_time', ts('Date'), true, array('formatType' => 'activityDateTime'));
     //autocomplete url
     $dataUrl = CRM_Utils_System::url("civicrm/ajax/contactlist", "reset=1", false, null, false);
     $this->assign('dataUrl', $dataUrl);
     //tokeninput url
     $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", false, null, false);
     $this->assign('tokenUrl', $tokenUrl);
     $admin = CRM_Core_Permission::check('administer CiviCRM');
     //allow to edit sourcecontactfield field if context is civicase.
     if ($this->_context == 'caseActivity') {
         $admin = true;
     }
     $this->assign('admin', $admin);
     $sourceContactField =& $this->add($this->_fields['source_contact_id']['type'], 'source_contact_id', $this->_fields['source_contact_id']['label'], null, $admin);
     $hiddenSourceContactField =& $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid'));
     $targetContactField =& $this->add('text', 'target_contact_id', ts('target'));
     $assigneeContactField =& $this->add('text', 'assignee_contact_id', ts('assignee'));
     if ($sourceContactField->getValue()) {
         $this->assign('source_contact', $sourceContactField->getValue());
     } else {
         if ($this->_currentUserId) {
             // we're setting currently LOGGED IN user as source for this activity
             $this->assign('source_contact_value', self::_getDisplayNameById($this->_currentUserId));
         }
     }
     //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);
     if ($this->_targetContactId) {
         $defaultTargetContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_targetContactId, 'sort_name');
         $this->assign('target_contact_value', $defaultTargetContactName);
     }
     // 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);
         }
         $buttons = array();
         $config =& CRM_Core_Config::singleton();
         require_once 'CRM/Core/OptionGroup.php';
         $emailActivityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name');
         if (in_array('CiviCase', $config->enableComponents) && $this->_activityTypeId == $emailActivityTypeID) {
             $buttons[] = array('type' => 'cancel', 'name' => ts('File on case'), 'js' => array('onClick' => "Javascript:fileOnCase(); return false;"));
             require_once 'CRM/Case/BAO/Case.php';
             $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases();
             $caseList = array();
             foreach ($unclosedCases as $case_id => $case_data) {
                 $caseList[$case_id . '_' . $case_data['contact_id']] = $case_data['display_name'] . ' - ' . $case_data['case_type'];
             }
             // Don't want to freeze the whole form since then this select gets frozen too,
             // so get the current list of elements, add our element, then freeze the previous list.
             $temp_elementList = array();
             foreach ($this->_elements as $e) {
                 $temp_elementList[] = $e->getName();
             }
             $this->add('select', 'case_select', ts('Open Cases'), array('' => ts('- select case -')) + $caseList, true);
             $this->add('text', 'case_subject', ts('New Subject'), array('size' => 50));
             $this->freeze($temp_elementList);
         } else {
             $this->freeze();
         }
         $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) {
         eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );");
     }
     if ($this->_activityTypeFile) {
         eval('$this->addFormRule' . "(array('CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}', 'formrule'), \$this);");
     }
     $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);
 }
コード例 #2
0
 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' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (!$this->_single && !empty($this->_contactIds)) {
         $withArray = array();
         require_once 'CRM/Contact/BAO/Contact.php';
         foreach ($this->_contactIds as $contactId) {
             $withDisplayName = self::_getDisplayNameById($contactId);
             $withArray[] = "\"{$withDisplayName}\" ";
         }
         $this->assign('with', implode(', ', $withArray));
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //build other activity links
     require_once 'CRM/Activity/Form/ActivityLinks.php';
     CRM_Activity_Form_ActivityLinks::buildQuickForm();
     //enable form element (ActivityLinks sets this true)
     $this->assign('suppressForm', false);
     $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], false, array('onchange' => "buildCustomData( 'Activity', this.value );"));
     //freeze for update mode.
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     foreach ($this->_fields as $field => $values) {
         if (CRM_Utils_Array::value($field, $this->_fields)) {
             $attribute = null;
             if (CRM_Utils_Array::value('attributes', $values)) {
                 $attribute = $values['attributes'];
             }
             $required = false;
             if (CRM_Utils_Array::value('required', $values)) {
                 $required = true;
             }
             if ($values['type'] == 'wysiwyg') {
                 $this->addWysiwyg($field, $values['label'], $attribute, $required);
             } else {
                 $this->add($values['type'], $field, $values['label'], $attribute, $required);
             }
         }
     }
     $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     $this->addRule('interval', ts('Please enter the follow-up interval as a number (integers only).'), 'positiveInteger');
     $this->addDateTime('activity_date_time', ts('Date'), true, array('formatType' => 'activityDateTime'));
     //autocomplete url
     $dataUrl = CRM_Utils_System::url("civicrm/ajax/rest", "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1", false, null, false);
     $this->assign('dataUrl', $dataUrl);
     //tokeninput url
     $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", false, null, false);
     $this->assign('tokenUrl', $tokenUrl);
     $admin = CRM_Core_Permission::check('administer CiviCRM');
     //allow to edit sourcecontactfield field if context is civicase.
     if ($this->_context == 'caseActivity') {
         $admin = true;
     }
     $this->assign('admin', $admin);
     $sourceContactField =& $this->add($this->_fields['source_contact_id']['type'], 'source_contact_id', $this->_fields['source_contact_id']['label'], null, $admin);
     $hiddenSourceContactField =& $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid'));
     $targetContactField =& $this->add('text', 'target_contact_id', ts('target'));
     $assigneeContactField =& $this->add('text', 'assignee_contact_id', ts('assignee'));
     if ($sourceContactField->getValue()) {
         $this->assign('source_contact', $sourceContactField->getValue());
     } else {
         if ($this->_currentUserId) {
             // we're setting currently LOGGED IN user as source for this activity
             $this->assign('source_contact_value', self::_getDisplayNameById($this->_currentUserId));
         }
     }
     //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);
     if ($this->_targetContactId) {
         $defaultTargetContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_targetContactId, 'sort_name');
         $this->assign('target_contact_value', $defaultTargetContactName);
     }
     require_once 'CRM/Core/BAO/Tag.php';
     $tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
     if (!empty($tags)) {
         $this->add('select', 'tag', ts('Tags'), $tags, false, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
     }
     // build tag widget
     require_once 'CRM/Core/Form/Tag.php';
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId, false, true);
     // check for survey activity
     $this->_isSurveyActivity = false;
     if ($this->_activityId) {
         require_once 'CRM/Campaign/BAO/Survey.php';
         $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);
     // 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);
         }
         $buttons = array();
         // do check for permissions
         require_once 'CRM/Case/BAO/Case.php';
         if (CRM_Case_BAO_Case::checkPermission($this->_activityId, 'File On Case', $this->_activityTypeId)) {
             $buttons[] = array('type' => 'cancel', 'name' => ts('File on case'), 'subName' => 'file_on_case', 'js' => array('onClick' => "Javascript:fileOnCase( \"file\", {$this->_activityId} ); return false;"));
         }
         // form should be frozen for view mode
         $this->freeze();
         $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) {
         eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );");
     }
     if ($this->_activityTypeFile) {
         eval('$this->addFormRule' . "(array('CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}', 'formrule'), \$this);");
     }
     $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);
 }