/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { $config =& CRM_Core_Config::singleton(); if (($output == CRM_CORE_SELECTOR_CONTROLLER_EXPORT || $output == CRM_CORE_SELECTOR_CONTROLLER_SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') { $includeContactIds = true; } else { $includeContactIds = false; } // note the formvalues were given by CRM_Contact_Form_Search to us // and contain the search criteria (parameters) // note that the default action is basic $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, $includeContactIds); // process the result of the query $rows = array(); $mask = CRM_Core_Action::mask(CRM_Core_Permission::getPermission()); $mapMask = $mask & 4095; // mask value to hide map link if there are not lat/long $gc = CRM_Core_SelectValues::groupContactStatus(); /* Dirty session hack to get at the context */ $session =& CRM_Core_Session::singleton(); $context = $session->get('context', 'CRM_Contact_Controller_Search'); // CRM_Core_Error::debug( 'p', self::$_properties ); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach ($GLOBALS['_CRM_CONTACT_SELECTOR']['_properties'] as $property) { if ($property == 'status') { continue; } $row[$property] = $result->{$property}; } if (!empty($result->postal_code_suffix)) { $row['postal_code'] .= "-" . $result->postal_code_suffix; } if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT || $context == 'smog') { if (empty($result->status)) { $row['status'] = ts('Smart'); } else { $row['status'] = $gc[$result->status]; } } if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT && $output != CRM_CORE_SELECTOR_CONTROLLER_SCREEN) { $row['checkbox'] = CRM_CORE_FORM_CB_PREFIX . $result->contact_id; if (is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) { $row['action'] = CRM_Core_Action::formLink(CRM_Contact_Selector::links(), $mask, array('id' => $result->contact_id)); } else { $row['action'] = CRM_Core_Action::formLink(CRM_Contact_Selector::links(), $mapMask, array('id' => $result->contact_id)); } $contact_type = '<img src="' . $config->resourceBase . 'i/contact_'; switch ($result->contact_type) { case 'Individual': $contact_type .= 'ind.gif" alt="' . ts('Individual') . '" />'; break; case 'Household': $contact_type .= 'house.png" alt="' . ts('Household') . '" height="16" width="16" />'; break; case 'Organization': $contact_type .= 'org.gif" alt="' . ts('Organization') . '" height="16" width="18" />'; break; } $row['contact_type'] = $contact_type; } $rows[] = $row; } return $rows; }
/** * Build the common elements between the search/advanced form. */ public function buildQuickForm() { parent::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'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array(); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { $className = $this->_modeValue['taskClassName']; $tasks += $className::permissionedTaskTitles($permission, FALSE); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // CRM-11788, we might want to do this for all of search where force=1 $formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues); $getQFKey = CRM_Utils_Array::value('qfKey', $_GET); $postQFKey = CRM_Utils_Array::value('qfKey', $_POST); if ($formQFKey && empty($getQFKey) && empty($postQFKey)) { $url = CRM_Utils_System::makeURL('qfKey') . $formQFKey; CRM_Utils_System::redirect($url); } $permissionForGroup = FALSE; if (!empty($this->_groupID)) { // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $permissionForGroup = TRUE; } // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_groupID])) { $this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title'); } // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', $permissionForGroup); } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_amtgID])) { $this->assign('permissionedForGroup', FALSE); $this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title'); } // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'crm-form-submit')); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all'); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); } $selectedContactIds = array(); $qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues); // We use ajax to handle selections only if the search results component_mode is set to "contacts" if ($qfKeyParam && ($this->get('component_mode') <= 1 || $this->get('component_mode') == 7)) { $this->addClass('crm-ajax-selection-form'); $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $rows = $this->get('rows'); if (is_array($rows)) { $this->addRowSelectors($rows); } }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { $config = CRM_Core_Config::singleton(); if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') { $includeContactIds = TRUE; } else { $includeContactIds = FALSE; } // note the formvalues were given by CRM_Contact_Form_Search to us // and contain the search criteria (parameters) // note that the default action is basic if ($rowCount) { $cacheKey = $this->buildPrevNextCache($sort); $result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds); } else { $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds); } // process the result of the query $rows = array(); $permissions = array(CRM_Core_Permission::getPermission()); if (CRM_Core_Permission::check('delete contacts')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); // mask value to hide map link if there are not lat/long $mapMask = $mask & 4095; if ($this->_searchContext == 'smog') { $gc = CRM_Core_SelectValues::groupContactStatus(); } if ($this->_ufGroupID) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $names = array(); static $skipFields = array('group', 'tag'); foreach ($this->_fields as $key => $field) { if (!empty($field['in_selector']) && !in_array($key, $skipFields)) { if (strpos($key, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $key, 3); if ($id == 'Primary') { $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); if (!$locationTypeName) { continue; } } $locationTypeName = str_replace(' ', '_', $locationTypeName); if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = $field['name']; } } } $names[] = "status"; } elseif (!empty($this->_returnProperties)) { $names = self::makeProperties($this->_returnProperties); } else { $names = self::$_properties; } $multipleSelectFields = array('preferred_communication_method' => 1); $links = self::links($this->_context, $this->_contextMenu, $this->_key); //check explicitly added contact to a Smart Group. $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']); $pseudoconstants = array(); // for CRM-3157 purposes if (in_array('world_region', $names)) { $pseudoconstants['world_region'] = array('dbName' => 'world_region_id', 'values' => CRM_Core_PseudoConstant::worldRegion()); } $seenIDs = array(); while ($result->fetch()) { $row = array(); $this->_query->convertToPseudoNames($result); // the columns we are interested in foreach ($names as $property) { if ($property == 'status') { continue; } if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) { $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id); } elseif ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) { $key = $property; $paramsNew = array($key => $result->{$property}); $name = array($key => array('newName' => $key, 'groupName' => $key)); CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); $row[$key] = $paramsNew[$key]; } elseif (strpos($property, '-im')) { $row[$property] = $result->{$property}; if (!empty($result->{$property})) { $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $providerId = $property . "-provider_id"; $providerName = $imProviders[$result->{$providerId}]; $row[$property] = $result->{$property} . " ({$providerName})"; } } elseif (in_array($property, array('addressee', 'email_greeting', 'postal_greeting'))) { $greeting = $property . '_display'; $row[$property] = $result->{$greeting}; } elseif (isset($pseudoconstants[$property])) { $row[$property] = CRM_Utils_Array::value($result->{$pseudoconstants[$property]['dbName']}, $pseudoconstants[$property]['values']); } elseif (strpos($property, '-url') !== FALSE) { $websiteUrl = ''; $websiteKey = 'website-1'; $propertyArray = explode('-', $property); $websiteFld = $websiteKey . '-' . array_pop($propertyArray); if (!empty($result->{$websiteFld})) { $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $websiteType = $websiteTypes[$result->{"{$websiteKey}-website_type_id"}]; $websiteValue = $result->{$websiteFld}; $websiteUrl = "<a href=\"{$websiteValue}\">{$websiteValue} ({$websiteType})</a>"; } $row[$property] = $websiteUrl; } else { $row[$property] = isset($result->{$property}) ? $result->{$property} : NULL; } } if (!empty($result->postal_code_suffix)) { $row['postal_code'] .= "-" . $result->postal_code_suffix; } if ($output != CRM_Core_Selector_Controller::EXPORT && $this->_searchContext == 'smog') { if (empty($result->status) && $groupID) { $contactID = $result->contact_id; if ($contactID) { $gcParams = array('contact_id' => $contactID, 'group_id' => $groupID); $gcDefaults = array(); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults); if (empty($gcDefaults)) { $row['status'] = ts('Smart'); } else { $row['status'] = $gc[$gcDefaults['status']]; } } else { $row['status'] = NULL; } } else { $row['status'] = $gc[$result->status]; } } if ($output != CRM_Core_Selector_Controller::EXPORT) { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id; if (!empty($this->_formValues['deleted_contacts']) && CRM_Core_Permission::check('access deleted contacts')) { $links = array(array('name' => ts('View'), 'url' => 'civicrm/contact/view', 'qs' => 'reset=1&cid=%%id%%', 'class' => 'no-popup', 'title' => ts('View Contact Details')), array('name' => ts('Restore'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&restore=1', 'title' => ts('Restore Contact'))); if (CRM_Core_Permission::check('delete contacts')) { $links[] = array('name' => ts('Delete Permanently'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&skip_undelete=1', 'title' => ts('Permanently Delete Contact')); } $row['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } elseif (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && !empty($row['city']) && CRM_Utils_Array::value('state_province', $row)) { $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } else { $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } // allow components to add more actions CRM_Core_Component::searchAction($row, $result->contact_id); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $row['contact_type_orig'] = $result->contact_sub_type ? $result->contact_sub_type : $result->contact_type; $row['contact_sub_type'] = $result->contact_sub_type ? CRM_Contact_BAO_ContactType::contactTypePairs(FALSE, $result->contact_sub_type, ', ') : $result->contact_sub_type; $row['contact_id'] = $result->contact_id; $row['sort_name'] = $result->sort_name; if (array_key_exists('id', $row)) { $row['id'] = $result->contact_id; } } // Dedupe contacts if (in_array($row['contact_id'], $seenIDs) === FALSE) { $seenIDs[] = $row['contact_id']; $rows[] = $row; } } return $rows; }
/** * Build the common elements between the search/advanced form * * @access public * @return void */ function buildQuickForm() { $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- more actions -')) + CRM_Contact_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // need to figure out how to freeze a bunch of checkboxes, hack for now if ($this->_action != CRM_Core_Action::ADVANCED) { //Fix ME //$this->_groupElement->freeze( ); } // also set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); } if (isset($ssMappingId)) { $this->assign('ssMappingID', $ssMappingId); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = HTML_QuickForm::createElement('checkbox', $k, null, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); /* * commented out to fix CRM-4268 * * $this->addGroupRule( 'group_contact_status', * ts( 'Please select at least Group Status value.' ), 'required', null, 1 ); */ // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Group Members: %1', array(1 => $this->_group[$this->_groupID]))); // check if user has permission to edit members of this group require_once 'CRM/Contact/BAO/Group.php'; $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $this->assign('permissionedForGroup', true); } else { $this->assign('permissionedForGroup', false); } } /* * add the go button for the action form, note it is of type 'next' rather than of type 'submit' * */ if ($this->_context === 'amtg') { // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add Members: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', null, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->addElement('radio', 'radio_ts', null, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );")); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], null, null, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "', '" . $this->getName() . "');")); } } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'id' => 'Print', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->setDefaultAction('refresh'); }
/** * Build the common elements between the search/advanced form * * @access public * * @return void */ function buildQuickForm() { $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- actions -')); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $this->_modeValue['taskClassName']) . '.php'; eval('$tasks += ' . $this->_modeValue['taskClassName'] . '::permissionedTaskTitles( $permission );'); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { if (!empty($this->_groupID)) { // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', FALSE); if (!empty($this->_groupID)) { // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $this->assign('permissionedForGroup', TRUE); } } } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, " . (int) empty($this->_customSearchClass) . ");")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) { $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );toggleContactSelection( 'resetSel', '{$qfKeyParam}', 'reset' );")); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); toggleCheckboxVals('mark_x_',this);return toggleContactSelection( 'toggleSelect', '" . $qfKeyParam . "' , 'multiple' );")); $unselectedContactIds = array(); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleContactSelection( '" . $row['checkbox'] . "', '" . $qfKeyParam . "' , 'single' );toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")); if (!in_array($row['contact_id'], $selectedContactIds)) { $unselectedContactIds[] = $row['contact_id']; } } $this->assign_by_ref('unselectedContactIds', $unselectedContactIds); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'id' => 'Print', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1, 1);")); $this->setDefaultAction('refresh'); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { $config =& CRM_Core_Config::singleton(); if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') { $includeContactIds = true; } else { $includeContactIds = false; } // note the formvalues were given by CRM_Contact_Form_Search to us // and contain the search criteria (parameters) // note that the default action is basic $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, $includeContactIds); // process the result of the query $rows = array(); $permissions = array(CRM_Core_Permission::getPermission()); if (CRM_Core_Permission::check('delete contacts')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $mapMask = $mask & 4095; // mask value to hide map link if there are not lat/long $gc = CRM_Core_SelectValues::groupContactStatus(); if ($this->_ufGroupID) { require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = CRM_Core_PseudoConstant::locationType(); $names = array(); static $skipFields = array('group', 'tag'); foreach ($this->_fields as $key => $field) { if (CRM_Utils_Array::value('in_selector', $field) && !in_array($key, $skipFields)) { if (strpos($key, '-') !== false) { list($fieldName, $id, $type) = explode('-', $key); if ($id == 'Primary') { $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); if (!$locationTypeName) { continue; } } $locationTypeName = str_replace(' ', '_', $locationTypeName); if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = $field['name']; } } } $names[] = "status"; } else { if (!empty($this->_returnProperties)) { $names =& self::makeProperties($this->_returnProperties); } else { $names = self::$_properties; } } //hack for student data (checkboxs) $multipleSelectFields = array('preferred_communication_method' => 1); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $multipleSelectFields = CRM_Quest_BAO_Student::$multipleSelectFields; } $searchType = null; if ($this->_action == CRM_Core_Action::BASIC) { $searchType = 'basic'; } elseif ($this->_action == CRM_Core_Action::ADVANCED) { $searchType = 'advance'; } require_once 'CRM/Core/OptionGroup.php'; $links =& self::links($searchType, $this->_contextMenu); //check explicitly added contact to a Smart Group. $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach ($names as $property) { if ($property == 'status') { continue; } if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) { $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id); } else { if ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) { //fix to display student checkboxes $key = $property; $paramsNew = array($key => $result->{$property}); if ($key == 'test_tutoring') { $name = array($key => array('newName' => $key, 'groupName' => 'test')); } else { if (substr($key, 0, 4) == 'cmr_') { //for readers group $name = array($key => array('newName' => $key, 'groupName' => substr($key, 0, -3))); } else { $name = array($key => array('newName' => $key, 'groupName' => $key)); } } CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false); $row[$key] = $paramsNew[$key]; } else { if (isset($tmfFields) && $tmfFields && array_key_exists($property, $tmfFields) || substr($property, 0, 12) == 'participant_') { if (substr($property, -3) == '_id') { $key = substr($property, 0, -3); $paramsNew = array($key => $result->{$property}); $name = array($key => array('newName' => $key, 'groupName' => $key)); CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false); $row[$key] = $paramsNew[$key]; } else { $row[$property] = $result->{$property}; } } else { if (strpos($property, '-im')) { $row[$property] = $result->{$property}; if (!empty($result->{$property})) { $imProviders = CRM_Core_PseudoConstant::IMProvider(); $providerId = $property . "-provider_id"; $providerName = $imProviders[$result->{$providerId}]; $row[$property] = $result->{$property} . " ({$providerName})"; } } else { if (in_array($property, array('addressee', 'email_greeting', 'postal_greeting'))) { $greeting = $property . '_display'; $row[$property] = $result->{$greeting}; } else { $row[$property] = $result->{$property}; } } } } } if (!empty($result->{$property})) { $empty = false; } } if (!empty($result->postal_code_suffix)) { $row['postal_code'] .= "-" . $result->postal_code_suffix; } if ($output != CRM_Core_Selector_Controller::EXPORT && $this->_searchContext == 'smog') { if (empty($result->status) && $groupID) { $contactID = $result->contact_id; if ($contactID) { $gcParams = array('contact_id' => $contactID, 'group_id' => $groupID); $gcDefaults = array(); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults); if (empty($gcDefaults)) { $row['status'] = ts('Smart'); } else { $row['status'] = $gc[$gcDefaults['status']]; } } else { $row['status'] = null; } } else { $row['status'] = $gc[$result->status]; } } if ($output != CRM_Core_Selector_Controller::EXPORT) { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id; if (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && CRM_Utils_Array::value('city', $row) && $row['state_province']) { $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->contact_id)); } else { $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $result->contact_id)); } // allow components to add more actions CRM_Core_Component::searchAction($row, $result->contact_id); require_once 'CRM/Contact/BAO/Contact/Utils.php'; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); $row['contact_id'] = $result->contact_id; $row['sort_name'] = $result->sort_name; if (array_key_exists('id', $row)) { $row['id'] = $result->contact_id; } } // Dedupe contacts if (!$empty) { $duplicate = false; foreach ($rows as $checkRow) { if ($checkRow['contact_id'] == $row['contact_id']) { $duplicate = true; } } if (!$duplicate) { $rows[] = $row; } } } //CRM_Core_Error::debug( '$rows', $rows ); return $rows; }
/** * Build the common elements between the search/advanced form * * @access public * * @return void */ function buildQuickForm() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js')->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'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- actions -')); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { $className = $this->_modeValue['taskClassName']; $tasks += $className::permissionedTaskTitles($permission, false); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // CRM-11788, we might want to do this for all of search where force=1 $formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues); $getQFKey = CRM_Utils_Array::value('qfKey', $_GET); $postQFKey = CRM_Utils_Array::value('qfKey', $_POST); if ($formQFKey && empty($getQFKey) && empty($postQFKey)) { $url = CRM_Utils_System::makeURL('qfKey') . $formQFKey; CRM_Utils_System::redirect($url); } if (!empty($this->_groupID)) { $permissionForGroup = FALSE; // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $permissionForGroup = TRUE; } // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_groupID])) { $permissionForGroup = FALSE; $this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title'); } $this->assign('permissionedForGroup', $permissionForGroup); // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', FALSE); } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_amtgID])) { $this->assign('permissionedForGroup', FALSE); $this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title'); } // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, 1);")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) { $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );toggleContactSelection( 'resetSel', '{$qfKeyParam}', 'reset' );")); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows', 'onclick' => "toggleTaskAction( true ); toggleContactSelection( 'toggleSelect', '" . $qfKeyParam . "' , 'multiple' );")); $unselectedContactIds = array(); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleContactSelection( '" . $row['checkbox'] . "', '" . $qfKeyParam . "' , 'single' );toggleTaskAction( true );", 'class' => 'select-row')); if (!in_array($row['contact_id'], $selectedContactIds)) { $unselectedContactIds[] = $row['contact_id']; } } $this->assign_by_ref('unselectedContactIds', $unselectedContactIds); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); $this->setDefaultAction('refresh'); }
/** * Construct a SQL WHERE clause * * @return string, sql fragment with conditional expressions */ function where($includeContactIDs = FALSE) { $params = array(); $aWhereClause = array(); $count = 1; #group $atemp = array(); $aSelectedGroups = CRM_Utils_Array::value('group_contact', $this->_formValues); if (!empty($aSelectedGroups)) { foreach ($aSelectedGroups as $groupIds) { $params[$count] = array($groupIds, 'Integer'); $aGroupname = "cgroup.id = %{$count}"; $atemp[] = $aGroupname; $count++; } } if (!empty($atemp)) { $aWhereClause[] = implode(" OR ", $atemp); } #Group end #status /*$oGroupContact = new CRM_Contact_DAO_GroupContact; $aGroupFields = $oGroupContact->fields(); $aStatus = explode(', ', $aGroupFields['status']['enumValues']);*/ $aStatus = CRM_Core_SelectValues::groupContactStatus(); $temp = array(); foreach ($aStatus as $status) { $aSelectedStatus = CRM_Utils_Array::value($status, $this->_formValues); if (!empty($aSelectedStatus)) { $params[$count] = array($status, 'String'); $selectedStatus = " group_contact.status = %{$count} "; $temp[] = $selectedStatus; $count++; } } if (!empty($temp)) { $aWhereClause[] = implode(" OR ", $temp); } #Status end #date range $fromDate = $this->_formValues['start_date'] ? date('Ymd', strtotime($this->_formValues['start_date'])) : NULL; $toDate = $this->_formValues['end_date'] ? date('Ymd', strtotime($this->_formValues['end_date'])) : NULL; if (!empty($fromDate)) { $aWhereClause[] = "history.date >= {$fromDate}"; } if (!empty($toDate)) { $aWhereClause[] = "history.date <= {$toDate}"; } #end date range $sWhere = '( 1 )'; if (!empty($aWhereClause)) { $sWhere = implode(' AND ', $aWhereClause); } return $this->whereClause($sWhere, $params); }