/** * Build the form object. * * @return void */ public function buildQuickForm() { // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); // let's not load jstree if there are not children. This also fixes blank // display at the beginning of checkboxes $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children'); $this->assign('loadjsTree', FALSE); if (!empty($loadJsTree)) { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $this->assign('loadjsTree', TRUE); } $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); if ($this->_action & CRM_Core_Action::BROWSE) { $this->freeze(); } else { $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); if ($this->_action & CRM_Core_Action::BROWSE) { $this->freeze(); } else { $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
/** * Method to get groups * * @return array * @access protected */ protected function getTags() { $tags = CRM_Core_BAO_Tag::getTagsUsedFor(); $options = array(); foreach ($tags as $tag_id => $tag) { $options[$tag_id] = $tag; } return $options; }
/** * Deletes an existing Tag * * @param object $tag valid tag object * @return NULL | error if delete successfull then NULL otherwise object of CRM_Core_Error * @access public */ function crm_delete_tag(&$tag) { require_once 'CRM/Core/BAO/Tag.php'; if (!isset($tag->id)) { return _crm_error('Invalid Tag object passed in'); } if (CRM_Core_BAO_Tag::del($tag->id)) { return null; } else { return _crm_error('Error while deleting Tag object'); } }
/** * Function to process the form * * @access public * @return None */ function postProcess() { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); $ids['tag'] = $this->_id; if ($this->_action == CRM_CORE_ACTION_DELETE) { if ($this->_id > 0) { CRM_Core_BAO_Tag::del($this->_id); } } else { CRM_Core_BAO_Tag::add($params, $ids); } }
/** * Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions). * * Allowed @params array keys are: * * {@example TagCreate.php} * * @return array of newly created tag property values. * {@getfields tag_create} * @access public */ function civicrm_api3_tag_create($params) { $ids = array('tag' => CRM_Utils_Array::value('tag', $params)); if (CRM_Utils_Array::value('tag', $params)) { $ids['tag'] = $params['tag']; } if (CRM_Utils_Array::value('id', $params)) { $ids['tag'] = $params['id']; } $tagBAO = CRM_Core_BAO_Tag::add($params, $ids); $values = array(); _civicrm_api3_object_to_array($tagBAO, $values[$tagBAO->id]); return civicrm_api3_create_success($values, $params, 'tag', 'create', $tagBAO); }
function addTag($param) { if (array_key_exists($param['name'], $this->tags)) { echo "\n- exists already: " . $param['name']; return; } $key = array('tag' => ''); if ($param['parent']) { if (array_key_exists($param['parent'], $this->tags)) { $param['parent_id'] = $this->tags[$param['parent']]; } else { $param['parent_id'] = $this->addTag(array(parent => '', name => $param['parent'])); } $tag = CRM_Core_BAO_Tag::add($param, $key); echo "\n" . $tag->id . ": create " . $param['name'] . " below " . $param['parent']; } else { $tag = CRM_Core_BAO_Tag::add($param, $key); echo "\n" . $tag->id . ": create " . $param['name'] . " (root)"; } $this->tags[$param['name']] = $tag->id; return $tag->id; }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_batchStatusId == 2) { $this->add('submit', 'export_batch', ts('Export Batch')); } // do not build rest of form unless it is open batch if ($this->_batchStatusId != 1) { return; } parent::buildQuickForm(); $this->add('submit', 'close_batch', ts('Close Batch')); $this->add('submit', 'export_batch', ts('Close & Export Batch')); // text for sort_name $this->addElement('text', 'sort_name', ts('Contributor Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $this->_group = CRM_Core_PseudoConstant::group(); // multiselect for groups if ($this->_group) { $this->add('select', 'group', ts('Groups'), $this->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))); } $contactTags = CRM_Core_BAO_Tag::getTags(); if ($contactTags) { $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); } CRM_Contribute_BAO_Query::buildSearchForm($this); $this->addElement('checkbox', 'toggleSelects', NULL, NULL); $this->add('select', 'trans_remove', ts('Task'), array('' => ts('- actions -')) + array('Remove' => ts('Remove from Batch'))); $this->add('submit', 'rSubmit', ts('Go'), array('class' => 'form-submit', 'id' => 'GoRemove')); self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive'); $this->addButtons(array(array('type' => 'submit', 'name' => ts('Search'), 'isDefault' => TRUE))); $this->addElement('checkbox', 'toggleSelect', NULL, NULL); $this->add('select', 'trans_assign', ts('Task'), array('' => ts('- actions -')) + array('Assign' => ts('Assign to Batch'))); $this->add('submit', 'submit', ts('Go'), array('class' => 'form-submit', 'id' => 'Go')); $this->applyFilter('__ALL__', 'trim'); $this->addElement('hidden', 'batch_id', self::$_entityID); $this->add('text', 'name', ts('Batch Name')); }
static function buildAttachment(&$form, $entityTable, $entityID = NULL, $numAttachments = NULL, $ajaxDelete = FALSE) { if (!$numAttachments) { $numAttachments = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'max_attachments'); } // Assign maxAttachments count to template for help message $form->assign('maxAttachments', $numAttachments); $config = CRM_Core_Config::singleton(); // set default max file size as 2MB $maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2; $currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE); $totalAttachments = 0; if ($currentAttachmentInfo) { $totalAttachments = count($currentAttachmentInfo); $form->add('checkbox', 'is_delete_attachment', ts('Delete All Attachment(s)')); $form->assign('currentAttachmentInfo', $currentAttachmentInfo); } else { $form->assign('currentAttachmentInfo', NULL); } if ($totalAttachments) { if ($totalAttachments >= $numAttachments) { $numAttachments = 0; } else { $numAttachments -= $totalAttachments; } } $form->assign('numAttachments', $numAttachments); $tags = CRM_Core_BAO_Tag::getTags('civicrm_file'); // get tagset info $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_file'); // add attachments for ($i = 1; $i <= $numAttachments; $i++) { $form->addElement('file', "attachFile_{$i}", ts('Attach File'), 'size=30 maxlength=60'); $form->addUploadElement("attachFile_{$i}"); $form->setMaxFileSize($maxFileSize * 1024 * 1024); $form->addRule("attachFile_{$i}", ts('File size should be less than %1 MByte(s)', array(1 => $maxFileSize)), 'maxfilesize', $maxFileSize * 1024 * 1024); $form->addElement('text', "attachDesc_{$i}", ts('Description'), 'size=40 maxlength=255'); if (!empty($tags)) { $form->add('select', "tag_{$i}", ts('Tags'), $tags, FALSE, array('id' => "tags_{$i}", 'multiple' => 'multiple', 'title' => ts('- select -'))); } } // build tagset widget CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, TRUE, TRUE, FALSE); }
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; } // 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, ' ', 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); } }
/** * Build the tag filter field to display on the filters tab. */ public function buildTagFilter() { $contactTags = CRM_Core_BAO_Tag::getTags($this->_tagFilterTable); if (!empty($contactTags)) { $this->_columns['civicrm_tag'] = array('dao' => 'CRM_Core_DAO_Tag', 'filters' => array('tagid' => array('name' => 'tag_id', 'title' => ts('Tag'), 'tag' => TRUE, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $contactTags))); } }
/** * Add all the elements shared between case search and advanaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); $form->add('select', 'case_type_id', ts('Case Type'), CRM_Case_PseudoConstant::caseType('title', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'case_status_id', ts('Case Status'), CRM_Case_PseudoConstant::caseStatus('label', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); $form->assign('validCiviCase', TRUE); //give options when all cases are accessible. $accessAllCases = FALSE; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = TRUE; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); $caseTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE); if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } // add all the custom searchable fields $extends = array('Case'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('caseGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->setDefaults(array('case_owner' => 1)); }
/** * build form elements. * params object $form object of the form * * @param CRM_Core_Form $form * The form object that we are operating on. * @param int $contactId * Contact id. * @param int $type * What components are we interested in. * @param bool $visibility * Visibility of the field. * @param null $isRequired * @param string $groupName * If used for building group block. * @param string $tagName * If used for building tag block. * @param string $fieldName * This is used in batch profile(i.e to build multiple blocks). * * @param string $groupElementType * */ public static function buildQuickForm(&$form, $contactId = 0, $type = self::ALL, $visibility = FALSE, $isRequired = NULL, $groupName = 'Group(s)', $tagName = 'Tag(s)', $fieldName = NULL, $groupElementType = 'checkbox') { if (!isset($form->_tagGroup)) { $form->_tagGroup = array(); } // NYSS 5670 if (!$contactId && !empty($form->_contactId)) { $contactId = $form->_contactId; } $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } $groupID = isset($form->_grid) ? $form->_grid : NULL; if ($groupID && $visibility) { $ids = array($groupID => $groupID); } else { if ($visibility) { $group = CRM_Core_PseudoConstant::allGroup(); } else { $group = CRM_Core_PseudoConstant::group(); } $ids = $group; } if ($groupID || !empty($group)) { $groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids); $attributes['skiplabel'] = TRUE; $elements = array(); $groupsOptions = array(); foreach ($groups as $id => $group) { // make sure that this group has public visibility if ($visibility && $group['visibility'] == 'User and User Admin Only') { continue; } if ($groupElementType == 'select') { $groupsOptions[$id] = $group['title']; } else { $form->_tagGroup[$fName][$id]['description'] = $group['description']; $elements[] =& $form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes); } } if ($groupElementType == 'select' && !empty($groupsOptions)) { $form->add('select', $fName, $groupName, $groupsOptions, FALSE, array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->assign('groupCount', count($groupsOptions)); } if ($groupElementType == 'checkbox' && !empty($elements)) { $form->addGroup($elements, $fName, $groupName, ' <br />'); $form->assign('groupCount', count($elements)); if ($isRequired) { $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required'); } } $form->assign('groupElementType', $groupElementType); } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } $form->_tagGroup[$fName] = 1; // get the list of all the categories $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree('civicrm_contact', TRUE); // let's not load jstree if there are not children. This also fixes blank // display at the beginning of checkboxes $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children'); $form->assign('loadjsTree', FALSE); if (!empty($loadJsTree)) { // CODE FROM CRM/Tag/Form/Tag.php // CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $form->assign('loadjsTree', TRUE); } $elements = array(); self::climbtree($form, $tree, $elements); $form->addGroup($elements, $fName, $tagName, '<br />'); $form->assign('tagCount', count($elements)); $form->assign('tree', $tree); $form->assign('tag', $tree); $form->assign('entityID', $contactId); $form->assign('entityTable', 'civicrm_contact'); if ($isRequired) { $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required'); } // build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); } $form->assign('tagGroup', $form->_tagGroup); }
private function _tagImportedContactsWithNewTag($contactIds, $newTagName, $newTagDesc) { $newTagId = NULL; if ($newTagName) { /* Create a new Tag */ $tagParams = array('name' => $newTagName, 'title' => $newTagName, 'description' => $newTagDesc, 'is_selectable' => TRUE, 'used_for' => 'civicrm_contact'); $id = array(); $addedTag = CRM_Core_BAO_Tag::add($tagParams, $id); $this->_tag[$addedTag->id] = 1; } //add Tag to Import if (is_array($this->_tag)) { $tagAdditions = array(); foreach ($this->_tag as $tagId => $val) { $addTagCount = CRM_Core_BAO_EntityTag::addEntitiesToTag($contactIds, $tagId); $totalTagCount = $addTagCount[1]; if (isset($addedTag) && $tagId == $addedTag->id) { $tagName = $newTagName; $new = TRUE; } else { $tagName = $this->_allTags[$tagId]; $new = FALSE; } $tagAdditions[] = array('url' => CRM_Utils_System::url('civicrm/contact/search', 'reset=1&force=1&context=smog&id=' . $tagId), 'name' => $tagName, 'added' => $totalTagCount, 'notAdded' => $addTagCount[2], 'new' => $new); } return $tagAdditions; } return FALSE; }
static function basic(&$form) { $form->addElement('hidden', 'hidden_basic', 1); if ($form->_searchOptions['contactType']) { // add checkboxes for contact type $contact_type = array(); require_once 'CRM/Contact/BAO/ContactType.php'; $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); foreach ($contactTypes as $k => $v) { if (!empty($k)) { $contact_type[] = HTML_QuickForm::createElement('checkbox', $k, null, $v); } } $form->addGroup($contact_type, 'contact_type', ts('Contact Type(s)'), '<br />'); } if ($form->_searchOptions['groups']) { // checkboxes for groups foreach ($form->_group as $groupID => $group) { $form->_groupElement =& $form->addElement('checkbox', "group[{$groupID}]", null, $group); } } if ($form->_searchOptions['tags']) { // checkboxes for categories require_once 'CRM/Core/BAO/Tag.php'; $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree(); $form->assign('tree', $tags->getTree()); foreach ($form->_tag as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "tag[{$tagID}]", null, $tagName); } } // add text box for last name, first name, street name, city $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); // add text box for last name, first name, street name, city $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); //added contact source $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source')); // add checkbox for cms users only if (CIVICRM_UF != 'Standalone') { $form->addYesNo('uf_user', ts('CMS User?')); } // add search profiles require_once 'CRM/Core/BAO/UFGroup.php'; // FIXME: This is probably a part of profiles - need to be // FIXME: eradicated from here when profiles are reworked. $types = array('Participant', 'Contribution', 'Membership'); // get component profiles $componentProfiles = array(); $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types); $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1); $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW); $searchProfiles = array(); foreach ($ufGroups as $key => $var) { if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) { $searchProfiles[$key] = $var['title']; } } $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles); // checkboxes for DO NOT phone, email, mail // we take labels from SelectValues $t = CRM_Core_SelectValues::privacy(); $t['do_not_toggle'] = ts('Include contacts who have these privacy option(s).'); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_sms', null, $t['do_not_sms']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_toggle', null, $t['do_not_toggle']); $form->addGroup($privacy, 'privacy', ts('Privacy'), array(' ', ' ', ' ', '<br/>')); // preferred communication method require_once 'CRM/Core/PseudoConstant.php'; $comm = CRM_Core_PseudoConstant::pcm(); $commPreff = array(); foreach ($comm as $k => $v) { $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v); } $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method')); }
static function processTags() { $skipTagCreate = $skipEntityAction = $entityId = NULL; $action = CRM_Utils_Type::escape($_POST['action'], 'String'); $parentId = CRM_Utils_Type::escape($_POST['parentId'], 'Integer'); if ($_POST['entityId']) { $entityId = CRM_Utils_Type::escape($_POST['entityId'], 'Integer'); } $entityTable = CRM_Utils_Type::escape($_POST['entityTable'], 'String'); if ($_POST['skipTagCreate']) { $skipTagCreate = CRM_Utils_Type::escape($_POST['skipTagCreate'], 'Integer'); } if ($_POST['skipEntityAction']) { $skipEntityAction = CRM_Utils_Type::escape($_POST['skipEntityAction'], 'Integer'); } // check if user has selected existing tag or is creating new tag // this is done to allow numeric tags etc. $tagValue = explode(':::', $_POST['tagID']); $createNewTag = FALSE; $tagID = $tagValue[0]; if (isset($tagValue[1]) && $tagValue[1] == 'value') { $createNewTag = TRUE; } $tagInfo = array(); // if action is select if ($action == 'select') { // check the value of tagID // if numeric that means existing tag // else create new tag if (!$skipTagCreate && $createNewTag) { $params = array('name' => $tagID, 'parent_id' => $parentId); $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray); $tagInfo = array('name' => $tagID, 'id' => $tagObject->id, 'action' => $action); $tagID = $tagObject->id; } if (!$skipEntityAction && $entityId) { // save this tag to contact $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::add($params); } // if action is delete } elseif ($action == 'delete') { if (!is_numeric($tagID)) { $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name'); } if (!$skipEntityAction && $entityId) { // delete this tag entry for the entity $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::del($params); } $tagInfo = array('id' => $tagID, 'action' => $action); } CRM_Utils_JSON::output($tagInfo); }
/** * @param CRM_Core_Form $form */ public static function basic(&$form) { $form->addElement('hidden', 'hidden_basic', 1); if ($form->_searchOptions['contactType']) { // add checkboxes for contact type //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form // this is loaded onto then replace with something like '__' & test $separator = CRM_Core_DAO::VALUE_SEPARATOR; $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator); if ($contactTypes) { $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')); } } if ($form->_searchOptions['groups']) { // multiselect for groups if ($form->_group) { // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, ' ', TRUE); $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')); $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type'); $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->add('hidden', 'group_search_selected', 'group'); } } if ($form->_searchOptions['tags']) { // multiselect for categories $contactTags = CRM_Core_BAO_Tag::getTags(); if ($contactTags) { $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')); } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE); $used_for = CRM_Core_OptionGroup::values('tag_used_for'); $tagsTypes = array(); $showAllTagTypes = FALSE; foreach ($used_for as $key => $value) { //check tags for every type and find if there are any defined $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL); // check if there are tags other than contact type, if no - keep checkbox hidden on adv search // we will hide searching contact by attachments tags until it will be implemented in core if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') { //if tags exists then add type to display in adv search form help text $tagsTypes[] = ts($value); $showAllTagTypes = TRUE; } } $tagTypesText = implode(" or ", $tagsTypes); if ($showAllTagTypes) { $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText))); $form->add('hidden', 'tag_types_text', $tagTypesText); } } // add text box for last name, first name, street name, city $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); // add text box for last name, first name, street name, city $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); //added contact source $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source')); //added job title $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title')); //added internal ID $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id')); $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger'); //added external ID $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier')); if (CRM_Core_Permission::check('access deleted contacts') and CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL)) { $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)')); } // add checkbox for cms users only $form->addYesNo('uf_user', ts('CMS User?'), TRUE); // tag all search $form->add('text', 'tag_search', ts('All Tags')); // add search profiles // FIXME: This is probably a part of profiles - need to be // FIXME: eradicated from here when profiles are reworked. $types = array('Participant', 'Contribution', 'Membership'); // get component profiles $componentProfiles = array(); $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types); $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1); $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW); $searchProfiles = array(); foreach ($ufGroups as $key => $var) { if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) { $searchProfiles[$key] = $var['title']; } } $form->add('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles, FALSE, array('class' => 'crm-select2')); $componentModes = CRM_Contact_Form_Search::getModeSelect(); // unset contributions or participants if user does not have // permission on them if (!CRM_Core_Permission::access('CiviContribute')) { unset($componentModes['2']); } if (!CRM_Core_Permission::access('CiviEvent')) { unset($componentModes['3']); } if (!CRM_Core_Permission::access('CiviMember')) { unset($componentModes['5']); } if (!CRM_Core_Permission::check('view all activities')) { unset($componentModes['4']); } if (count($componentModes) > 1) { $form->add('select', 'component_mode', ts('Display Results As'), $componentModes, FALSE, array('class' => 'crm-select2')); } $form->addRadio('operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')), array('allowClear' => FALSE)); // add the option to display relationships $rTypes = CRM_Core_PseudoConstant::relationshipType(); $rSelect = array('' => ts('- Select Relationship Type-')); foreach ($rTypes as $rid => $rValue) { if ($rValue['label_a_b'] == $rValue['label_b_a']) { $rSelect[$rid] = $rValue['label_a_b']; } else { $rSelect["{$rid}_a_b"] = $rValue['label_a_b']; $rSelect["{$rid}_b_a"] = $rValue['label_b_a']; } } $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect, array('class' => 'crm-select2')); // checkboxes for DO NOT phone, email, mail // we take labels from SelectValues $t = CRM_Core_SelectValues::privacy(); $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND'))); $options = array(1 => ts('Exclude'), 2 => ts('Include by Privacy Option(s)')); $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE)); // preferred communication method $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); $commPreff = array(); foreach ($comm as $k => $v) { $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v); } $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ''); $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold')); $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method')); //CRM-6138 Preferred Language $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search')); // Phone search $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2')); $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2')); }
/** * Deletes an existing Tag * * @param array $params * * @return boolean | error true if successfull, error otherwise * @access public */ function civicrm_tag_delete(&$params) { if (!is_array($params)) { return civicrm_create_error(ts('Input parameters is not an array')); } $tagID = CRM_Utils_Array::value('tag_id', $params); if (!$tagID) { return civicrm_create_error(ts('Could not find tag_id in input parameters')); } require_once 'CRM/Core/BAO/Tag.php'; return CRM_Core_BAO_Tag::del($tagID) ? civicrm_create_success() : civicrm_create_error(ts('Could not delete tag')); }
/** * Get a Tag. * * This api is used for finding an existing tag. * Either id or name of tag are required parameters for this api. * * @param array $params an associative array of name/value pairs. * * @return array details of found tag else error * @access public */ function civicrm_tag_get($params) { _civicrm_initialize(); require_once 'CRM/Core/BAO/Tag.php'; $tagBAO = new CRM_Core_BAO_Tag(); if (!is_array($params)) { return civicrm_create_error('Params is not an array.'); } if (!isset($params['id']) && !isset($params['name'])) { return civicrm_create_error('Required parameters missing.'); } $properties = array('id', 'name', 'description', 'parent_id', 'is_selectable', 'is_hidden', 'is_reserved', 'used_for'); foreach ($properties as $name) { if (array_key_exists($name, $params)) { $tagBAO->{$name} = $params[$name]; } } if (!$tagBAO->find(TRUE)) { return civicrm_create_error('Exact match not found.'); } _civicrm_object_to_array($tagBAO, $tag); $tag['is_error'] = 0; return $tag; }
/** * Build the form object. */ public function buildQuickForm() { parent::buildQuickForm(); // text for sort_name $this->addElement('text', 'sort_name', ts('Contributor Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $this->_group = CRM_Core_PseudoConstant::nestedGroup(); // multiselect for groups if ($this->_group) { $this->add('select', 'group', ts('Groups'), $this->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')); } // multiselect for tags $contactTags = CRM_Core_BAO_Tag::getTags(); if ($contactTags) { $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); } CRM_Contribute_BAO_Query::buildSearchForm($this); $rows = $this->get('rows'); if (is_array($rows)) { if (!$this->_single) { $this->addRowSelectors($rows); } $permission = CRM_Core_Permission::getPermission(); $queryParams = $this->get('queryParams'); $softCreditFiltering = FALSE; if (!empty($queryParams)) { $softCreditFiltering = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams); } $tasks = CRM_Contribute_Task::permissionedTaskTitles($permission, $softCreditFiltering); $this->addTaskMenu($tasks); } }
/** * add all the elements shared between case activity search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(true, true, false, 'label', true); asort($activityOptions); foreach ($activityOptions as $activityID => $activity) { $form->_activityElement =& $form->addElement('checkbox', "activity_type_id[{$activityID}]", null, $activity, array('onClick' => 'showCustomData( this.id );')); } $form->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); $activityRoles = array(1 => ts('Created by'), 2 => ts('Assigned to')); $form->addRadio('activity_role', null, $activityRoles, null, '<br />'); $form->setDefaults(array('activity_role' => 1)); $form->addElement('text', 'activity_contact_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); foreach ($activityStatus as $activityStatusID => $activityStatusName) { $activity_status[] = HTML_QuickForm::createElement('checkbox', $activityStatusID, null, $activityStatusName); } $form->addGroup($activity_status, 'activity_status', ts('Activity Status')); $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1)); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addElement('checkbox', 'activity_test', ts('Find Test Activities?')); require_once 'CRM/Core/BAO/Tag.php'; $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", null, $tagName); } } require_once 'CRM/Campaign/BAO/Survey.php'; $surveys = array('' => ts('- none -')) + CRM_Campaign_BAO_Survey::getSurveyList(); $form->add('select', 'activity_survey_id', ts('Survey'), $surveys, false); require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } }
public function buildQuickForm() { $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) { $title = 'Delete'; if ($this->_action & CRM_Core_Action::RENEW) { $title = 'Restore'; } $this->addButtons(array(array('type' => 'next', 'name' => $title, 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Case'); CRM_Custom_Form_CustomData::buildQuickForm($this); // we don't want to show button on top of custom form $this->assign('noPreCustomButton', TRUE); $s = CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject'); if (!is_array($s)) { $s = array(); } $this->add('text', 'activity_subject', ts('Subject'), array_merge($s, array('maxlength' => '128')), TRUE); $tags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($tags)) { $this->add('select', 'tag', ts('Select Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); } // build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', NULL, FALSE, TRUE); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );"); }
/** * Get options for a given field. * * @see CRM_Core_DAO::buildOptions * @see CRM_Core_DAO::buildOptionsContext * * @param string $fieldName * @param string $context * As per CRM_Core_DAO::buildOptionsContext. * @param array $props * whatever is known about this dao object. * * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { $params = array(); if ($fieldName == 'tag' || $fieldName == 'tag_id') { if (!empty($props['entity_table'])) { $entity = CRM_Utils_Type::escape($props['entity_table'], 'String'); $params[] = "used_for LIKE '%{$entity}%'"; } // Output tag list as nested hierarchy // TODO: This will only work when api.entity is "entity_tag". What about others? if ($context == 'search' || $context == 'create') { return CRM_Core_BAO_Tag::getTags(CRM_Utils_Array::value('entity_table', $props, 'civicrm_contact'), CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- '); } } $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); return $options; }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcessOld() { $doGeocodeAddress = $this->controller->exportValue('DataSource', 'doGeocodeAddress'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $newGroupName = $this->controller->exportValue($this->_name, 'newGroupName'); $newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc'); $groups = $this->controller->exportValue($this->_name, 'groups'); $allGroups = $this->get('groups'); $newTagName = $this->controller->exportValue($this->_name, 'newTagName'); $newTagDesc = $this->controller->exportValue($this->_name, 'newTagDesc'); $tag = $this->controller->exportValue($this->_name, 'tag'); $allTags = $this->get('tag'); $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocTypes = array(); $mapperPhoneTypes = array(); $mapperRelated = array(); $mapperRelatedContactType = array(); $mapperRelatedContactDetails = array(); $mapperRelatedContactLocType = array(); $mapperRelatedContactPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocTypes[$key] = $mapper[$key][1]; } else { $mapperLocTypes[$key] = NULL; } if (CRM_Utils_Array::value($key, $mapperKeys) == 'phone') { $mapperPhoneTypes[$key] = $mapper[$key][2]; } else { $mapperPhoneTypes[$key] = NULL; } list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(TRUE); $fieldName = "contact_type_{$second}"; $mapperRelatedContactType[$key] = $relationType->{$fieldName}; $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; $mapperRelatedContactPhoneType[$key] = $mapper[$key][3]; } else { $mapperRelated[$key] = NULL; $mapperRelatedContactType[$key] = NULL; $mapperRelatedContactDetails[$key] = NULL; $mapperRelatedContactLocType[$key] = NULL; $mapperRelatedContactPhoneType[$key] = NULL; } } $parser = new CRM_Contact_Import_Parser_Contact($mapperKeys, $mapperLocTypes, $mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType, $mapperRelatedContactDetails, $mapperRelatedContactLocType, $mapperRelatedContactPhoneType); $mapFields = $this->get('fields'); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); foreach ($mapper as $key => $value) { $header = array(); list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(TRUE); $header[] = $relationType->name_a_b; $header[] = ucwords(str_replace("_", " ", $mapper[$key][1])); if (isset($mapper[$key][2])) { $header[] = $locationTypes[$mapper[$key][2]]; } if (isset($mapper[$key][3])) { $header[] = $phoneTypes[$mapper[$key][3]]; } } else { if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; if (isset($mapper[$key][1])) { $header[] = $locationTypes[$mapper[$key][1]]; } if (isset($mapper[$key][2])) { $header[] = $phoneTypes[$mapper[$key][2]]; } } } $mapperFields[] = implode(' - ', $header); } $tableName = $this->get('importTableName'); //print "Running parser on table: $tableName<br/>"; $parser->run($tableName, $mapperFields, CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $this->get('primaryKeyName'), $this->get('statusFieldName'), $onDuplicate, $this->get('statusID'), $this->get('totalRowCount'), $doGeocodeAddress, CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'), $this->get('dedupe')); // add the new contacts to selected groups $contactIds =& $parser->getImportedContacts(); // add the new related contacts to selected groups $relatedContactIds =& $parser->getRelatedImportedContacts(); $this->set('relatedCount', count($relatedContactIds)); $newGroupId = NULL; //changed below if-statement "if ($newGroup) {" to "if ($newGroupName) {" if ($newGroupName) { /* Create a new group */ $gParams = array('name' => $newGroupName, 'title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => TRUE); $group = CRM_Contact_BAO_Group::create($gParams); $groups[] = $newGroupId = $group->id; } if (is_array($groups)) { $groupAdditions = array(); foreach ($groups as $groupId) { $addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); if (!empty($relatedContactIds)) { $addRelCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($relatedContactIds, $groupId); } $totalCount = $addCount[1] + $addRelCount[1]; if ($groupId == $newGroupId) { $name = $newGroupName; $new = TRUE; } else { $name = $allGroups[$groupId]; $new = FALSE; } $groupAdditions[] = array('url' => CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $groupId), 'name' => $name, 'added' => $totalCount, 'notAdded' => $addCount[2] + $addRelCount[2], 'new' => $new); } $this->set('groupAdditions', $groupAdditions); } $newTagId = NULL; if ($newTagName) { /* Create a new Tag */ $tagParams = array('name' => $newTagName, 'title' => $newTagName, 'description' => $newTagDesc, 'is_active' => TRUE); $id = array(); $addedTag = CRM_Core_BAO_Tag::add($tagParams, $id); $tag[$addedTag->id] = 1; } //add Tag to Import if (is_array($tag)) { $tagAdditions = array(); foreach ($tag as $tagId => $val) { $addTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId); if (!empty($relatedContactIds)) { $addRelTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($relatedContactIds, $tagId); } $totalTagCount = $addTagCount[1] + $addRelTagCount[1]; if ($tagId == $addedTag->id) { $tagName = $newTagName; $new = TRUE; } else { $tagName = $allTags[$tagId]; $new = FALSE; } $tagAdditions[] = array('url' => CRM_Utils_System::url('civicrm/contact/search', 'reset=1&force=1&context=smog&id=' . $tagId), 'name' => $tagName, 'added' => $totalTagCount, 'notAdded' => $addTagCount[2] + $addRelTagCount[2], 'new' => $new); } $this->set('tagAdditions', $tagAdditions); } // add all the necessary variables to the form $parser->set($this, CRM_Import_Parser::MODE_IMPORT); // check if there is any error occured $errorStack = CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } // there is no fileName since this is a sql import // so fudge it $config = CRM_Core_Config::singleton(); $errorFile = $config->uploadDir . "sqlImport.error.log"; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlparams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } }
/** * Add all the elements shared between case activity search and advanced search. * * * @param CRM_Core_Form $form * @return void */ public static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); $form->addSelect('activity_type_id', array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $followUpActivity = array(1 => ts('Yes'), 2 => ts('No')); $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $activityRoles = array(3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by')); $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); $form->setDefaults(array('activity_role' => 3)); $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); $form->addSelect('status_id', array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addYesNo('activity_test', ts('Activity is a Test?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), array('' => ts('- none -')) + $surveys, FALSE, array('class' => 'crm-select2')); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); $resultOptions = array(); foreach ($optionGroups as $gid => $name) { if ($name) { $value = array(); $value = CRM_Core_OptionGroup::values($name); if (!empty($value)) { while (list($k, $v) = each($value)) { $resultOptions[$v] = $v; } } } } // If no survey result options have been created, don't build // the field to avoid clutter. if (count($resultOptions) > 0) { $buildSurveyResult = TRUE; asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2')); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); }
/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { //get the submitted values in an array $params = $this->controller->exportValues($this->_name); $contactTags = $tagList = array(); // check if contact tags exists if (!empty($params['tag'])) { $contactTags = $params['tag']; } // check if tags are selected from taglists if (!empty($params['contact_taglist'])) { foreach ($params['contact_taglist'] as $val) { if ($val) { if (is_numeric($val)) { $tagList[$val] = 1; } else { $tagIDs = explode(',', $val); if (!empty($tagIDs)) { foreach ($tagIDs as $tagID) { if (is_numeric($tagID)) { $tagList[$tagID] = 1; } } } } } } } $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE, TRUE); foreach ($tagSets as $key => $value) { $this->_tags[$key] = $value['name']; } // merge contact and taglist tags $allTags = CRM_Utils_Array::crmArrayMerge($contactTags, $tagList); $this->_name = array(); foreach ($allTags as $key => $dnc) { $this->_name[] = $this->_tags[$key]; list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_contactIds, $key); $status = array(ts('%count contact tagged', array('count' => $added, 'plural' => '%count contacts tagged'))); if ($notAdded) { $status[] = ts('%count contact already had this tag', array('count' => $notAdded, 'plural' => '%count contacts already had this tag')); } $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>'; CRM_Core_Session::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0)); } }
/** * add all the elements shared between case search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. require_once 'CRM/Case/BAO/Case.php'; $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); require_once "CRM/Case/PseudoConstant.php"; $caseTypes = CRM_Case_PseudoConstant::caseType('label', false); foreach ($caseTypes as $id => $Name) { $form->addElement('checkbox', "case_type_id[{$id}]", null, $Name); } $statuses = CRM_Case_PseudoConstant::caseStatus('label', false); $form->add('select', 'case_status_id', ts('Case Status'), array('' => ts('- any status -')) + $statuses); $form->assign('validCiviCase', true); //give options when all cases are accessible. $accessAllCases = false; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = true; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); require_once 'CRM/Core/BAO/Tag.php'; $caseTags = CRM_Core_BAO_Tag::getTagsUsedFor(array('civicrm_case')); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", null, $tagName); } } require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } }
/** * Processing needed for buildForm and later. */ public function preProcess() { // set the various class variables $this->_group = CRM_Core_PseudoConstant::group(); $this->_groupIterator = CRM_Core_PseudoConstant::groupIterator(); $this->_tag = CRM_Core_BAO_Tag::getTags(); $this->_done = FALSE; /* * we allow the controller to set force/reset externally, useful when we are being * driven by the wizard framework */ $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_groupID = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $this->_amtgID = CRM_Utils_Request::retrieve('amtgID', 'Positive', $this); $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this); $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $this->_ufGroupID = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_componentMode = CRM_Utils_Request::retrieve('component_mode', 'Positive', $this, FALSE, 1, $_REQUEST); $this->_operator = CRM_Utils_Request::retrieve('operator', 'String', $this, FALSE, 1, $_REQUEST, 'AND'); /** * set the button names */ $this->_searchButtonName = $this->getButtonName('refresh'); $this->_actionButtonName = $this->getButtonName('next', 'action'); $this->assign('actionButtonName', $this->_actionButtonName); // reset from session, CRM-3526 $session = CRM_Core_Session::singleton(); if ($this->_force && $session->get('selectedSearchContactIds')) { $session->resetScope('selectedSearchContactIds'); } // if we dont get this from the url, use default if one exsts $config = CRM_Core_Config::singleton(); if ($this->_ufGroupID == NULL && $config->defaultSearchProfileID != NULL) { $this->_ufGroupID = $config->defaultSearchProfileID; } // assign context to drive the template display, make sure context is valid $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search'); if (!CRM_Utils_Array::value($this->_context, self::validContext())) { $this->_context = 'search'; } $this->set('context', $this->_context); $this->assign('context', $this->_context); $this->_modeValue = self::getModeValue($this->_componentMode); $this->assign($this->_modeValue); $this->set('selectorName', self::$_selectorName); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this // $this->controller->isModal( ) returns TRUE if page is // valid, i.e all the validations are TRUE if (!empty($_POST) && !$this->controller->isModal()) { $this->_formValues = $this->controller->exportValues($this->_name); $this->normalizeFormValues(); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); // also get the uf group id directly from the post value $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $_POST, $this->_ufGroupID); $this->_formValues['uf_group_id'] = $this->_ufGroupID; $this->set('id', $this->_ufGroupID); // also get the object mode directly from the post value $this->_componentMode = CRM_Utils_Array::value('component_mode', $_POST, $this->_componentMode); // also get the operator from the post value if set $this->_operator = CRM_Utils_Array::value('operator', $_POST, $this->_operator); $this->_formValues['operator'] = $this->_operator; $this->set('operator', $this->_operator); } else { $this->_formValues = $this->get('formValues'); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); if (!empty($this->_ufGroupID)) { $this->set('id', $this->_ufGroupID); } } if (empty($this->_formValues)) { //check if group is a smart group (fix for CRM-1255) if ($this->_groupID) { if ($ssId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id')) { $this->_ssID = $ssId; } } // fix for CRM-1907 if (isset($this->_ssID) && $this->_context != 'smog') { // we only retrieve the saved search values if out current values are null $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); //fix for CRM-1505 if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) { $this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID); } else { $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); } $this->_returnProperties =& $this->returnProperties(); } else { if (isset($this->_ufGroupID)) { // also set the uf group id if not already present $this->_formValues['uf_group_id'] = $this->_ufGroupID; } if (isset($this->_componentMode)) { $this->_formValues['component_mode'] = $this->_componentMode; } if (isset($this->_operator)) { $this->_formValues['operator'] = $this->_operator; } // FIXME: we should generalise in a way that components could inject url-filters // just like they build their own form elements foreach (array('mailing_id', 'mailing_delivery_status', 'mailing_open_status', 'mailing_click_status', 'mailing_reply_status', 'mailing_optout', 'mailing_forward', 'mailing_unsubscribe', 'mailing_date_low', 'mailing_date_high') as $mailingFilter) { $type = 'String'; if ($mailingFilter == 'mailing_id' && ($filterVal = CRM_Utils_Request::retrieve('mailing_id', 'Positive', $this))) { $this->_formValues[$mailingFilter] = array($filterVal); } elseif ($filterVal = CRM_Utils_Request::retrieve($mailingFilter, $type, $this)) { $this->_formValues[$mailingFilter] = $filterVal; } if ($filterVal) { $this->_openedPanes['Mailings'] = 1; $this->_formValues['hidden_CiviMail'] = 1; } } } } $this->assign('id', CRM_Utils_Array::value('uf_group_id', $this->_formValues)); $operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND'); $this->set('queryOperator', $operator); if ($operator == 'OR') { $this->assign('operator', ts('OR')); } else { $this->assign('operator', ts('AND')); } // show the context menu only when we’re not searching for deleted contacts; CRM-5673 if (empty($this->_formValues['deleted_contacts'])) { $menuItems = CRM_Contact_BAO_Contact::contextMenu(); $primaryActions = CRM_Utils_Array::value('primaryActions', $menuItems, array()); $this->_contextMenu = CRM_Utils_Array::value('moreActions', $menuItems, array()); $this->assign('contextMenu', $primaryActions + $this->_contextMenu); } if (!isset($this->_componentMode)) { $this->_componentMode = CRM_Contact_BAO_Query::MODE_CONTACTS; } $modeValues = self::getModeValue($this->_componentMode); self::$_selectorName = $this->_modeValue['selectorName']; $setDynamic = FALSE; if (strpos(self::$_selectorName, 'CRM_Contact_Selector') !== FALSE) { $selector = new self::$_selectorName($this->_customSearchClass, $this->_formValues, $this->_params, $this->_returnProperties, $this->_action, FALSE, TRUE, $this->_context, $this->_contextMenu); $setDynamic = TRUE; } else { $selector = new self::$_selectorName($this->_params, $this->_action, NULL, FALSE, NULL, "search", "advanced"); } $selector->setKey($this->controller->_key); $controller = new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(TRUE); $controller->setDynamicAction($setDynamic); if ($this->_force) { $this->postProcess(); /* * Note that we repeat this, since the search creates and stores * values that potentially change the controller behavior. i.e. things * like totalCount etc */ $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $controller = new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(TRUE); $controller->setDynamicAction($setDynamic); } $controller->moveFromSessionToTemplate(); }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { unset($aTypes[$linkActTypeId]); } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { if ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-clipboard')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-play')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = FALSE; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases, FALSE, array('class' => 'crm-select2 huge')); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'crm-form-submit-inline hiddenElement')); } } //call activity form self::activityForm($this); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types $baoRel = new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', TRUE); } else { $this->assign('showTagsets', FALSE); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }