示例#1
0
文件: Group.php 项目: kidaa30/yes
/**
 * Returns array of groups matching a set of one or more Group properties.
 *
 * @param array $params
 *   Array of properties. If empty, all records will be returned.
 *
 * @return array
 *   Array of matching groups
 */
function civicrm_api3_group_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get');
    if ((empty($options['return']) || !in_array('member_count', $options['return'])) && empty($params['check_permissions'])) {
        return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group');
    }
    $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group');
    foreach ($groups as $id => $group) {
        if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Group::checkPermission($group['id'])) {
            unset($groups[$id]);
        } elseif (!empty($options['return']) && in_array('member_count', $options['return'])) {
            $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
        }
    }
    return civicrm_api3_create_success($groups, $params, 'Group', 'get');
}
示例#2
0
 /**
  * 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);
     }
 }
示例#3
0
 /**
  * Returns array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 static function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null, $includeChildGroups = false)
 {
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     require_once 'CRM/Contact/BAO/Group.php';
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT contact_a.id as contact_id,\n                      civicrm_email.email as email";
     } else {
         $query = "SELECT contact_a.id as contact_id , {$grpStatus} as status,";
         $query .= implode(',', $returnProperties);
     }
     $params = array();
     if ($includeChildGroups) {
         require_once 'CRM/Contact/BAO/GroupNesting.php';
         $groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds(array($group->id));
     } else {
         $groupIds = array($group->id);
     }
     foreach ($groupIds as $groupId) {
         $params[] = array('group', 'IN', array($group->id => true), 0, 0);
     }
     require_once 'CRM/Core/BAO/Email.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $tables = array(CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if (!is_null($offset) && !is_null($row_count)) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
示例#4
0
 /**
  * Given a contact id and a field set, return the values from the db
  * for this contact
  *
  * @param int $cid
  * @param array $fields
  *   The profile fields of interest.
  * @param array $values
  *   The values for the above fields.
  * @param bool $searchable
  *   Searchable or not.
  * @param array $componentWhere
  *   Component condition.
  * @param bool $absolute
  *   Return urls in absolute form (useful when sending an email).
  * @param null $additionalWhereClause
  */
 public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL)
 {
     if (empty($cid) && empty($componentWhere)) {
         return NULL;
     }
     // get the contact details (hier)
     $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     $params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array();
     // add conditions specified by components. eg partcipant_id etc
     if (!empty($componentWhere)) {
         $params = array_merge($params, $componentWhere);
     }
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
     $options =& $query->_options;
     $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause);
     if (!$details->fetch()) {
         return;
     }
     $query->convertToPseudoNames($details);
     $config = CRM_Core_Config::singleton();
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     $multipleFields = array('url');
     //start of code to set the default values
     foreach ($fields as $name => $field) {
         // fix for CRM-3962
         if ($name == 'id') {
             $name = 'contact_id';
         }
         // skip fields that should not be displayed separately
         if (!empty($field['skipDisplay'])) {
             continue;
         }
         // Create a unique, non-empty index for each field.
         $index = $field['title'];
         if ($index === '') {
             $index = ' ';
         }
         while (array_key_exists($index, $values)) {
             $index .= ' ';
         }
         $params[$index] = $values[$index] = '';
         $customFieldName = NULL;
         // hack for CRM-665
         if (isset($details->{$name}) || $name == 'group' || $name == 'tag') {
             // to handle gender / suffix / prefix
             if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) {
                 $params[$index] = $details->{$name};
                 $values[$index] = $details->{$name};
             } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
                 $dname = $name . '_display';
                 $values[$index] = $details->{$dname};
                 $name = $name . '_id';
                 $params[$index] = $details->{$name};
             } elseif (in_array($name, array('state_province', 'country', 'county'))) {
                 $values[$index] = $details->{$name};
                 $idx = $name . '_id';
                 $params[$index] = $details->{$idx};
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
                 foreach ($pref as $k) {
                     if ($k) {
                         $compref[] = $communicationFields[$k];
                     }
                 }
                 $params[$index] = $details->{$name};
                 $values[$index] = implode(',', $compref);
             } elseif ($name === 'preferred_language') {
                 $params[$index] = $details->{$name};
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name});
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE);
                 $title = $ids = array();
                 foreach ($groups as $g) {
                     // CRM-8362: User and User Admin visibility groups should be included in display if user has
                     // VIEW permission on that group
                     $groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']);
                     if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) {
                         $title[] = $g['title'];
                         if ($g['visibility'] == 'Public Pages') {
                             $ids[] = $g['group_id'];
                         }
                     }
                 }
                 $values[$index] = implode(', ', $title);
                 $params[$index] = implode(',', $ids);
             } elseif ($name == 'tag') {
                 $entityTags = CRM_Core_BAO_EntityTag::getTag($cid);
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 foreach ($entityTags as $tagId) {
                     $title[] = $allTags[$tagId];
                 }
                 $values[$index] = implode(', ', $title);
                 $params[$index] = implode(',', $entityTags);
             } elseif ($name == 'activity_status_id') {
                 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
                 $values[$index] = $activityStatus[$details->{$name}];
                 $params[$index] = $details->{$name};
             } elseif ($name == 'activity_date_time') {
                 $values[$index] = CRM_Utils_Date::customFormat($details->{$name});
                 $params[$index] = $details->{$name};
             } elseif ($name == 'contact_sub_type') {
                 $contactSubTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
                 if (!empty($contactSubTypeNames)) {
                     $contactSubTypeLabels = array();
                     // get all contact subtypes
                     $allContactSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
                     // build contact subtype labels array
                     foreach ($contactSubTypeNames as $cstName) {
                         if ($cstName) {
                             $contactSubTypeLabels[] = $allContactSubTypes[$cstName]['label'];
                         }
                     }
                     $values[$index] = implode(',', $contactSubTypeLabels);
                 }
                 $params[$index] = $details->{$name};
             } else {
                 if (substr($name, 0, 7) === 'do_not_' || substr($name, 0, 3) === 'is_') {
                     if ($details->{$name}) {
                         $values[$index] = '[ x ]';
                     }
                 } else {
                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                         $htmlType = $field['html_type'];
                         // field_type is only set when we are retrieving profile values
                         // when sending email, we call the same function to get custom field
                         // values etc, i.e. emulating a profile
                         $fieldType = CRM_Utils_Array::value('field_type', $field);
                         if ($htmlType == 'File') {
                             $entityId = $cid;
                             if (!$cid && $fieldType == 'Activity' && !empty($componentWhere[0][2])) {
                                 $entityId = $componentWhere[0][2];
                             }
                             $fileURL = CRM_Core_BAO_CustomField::getFileURL($entityId, $cfID, NULL, $absolute, $additionalWhereClause);
                             $params[$index] = $values[$index] = $fileURL['file_url'];
                         } else {
                             $customVal = NULL;
                             if (isset($dao) && property_exists($dao, 'data_type') && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) {
                                 $customVal = (int) $details->{$name};
                             } elseif (isset($dao) && property_exists($dao, 'data_type') && $dao->data_type == 'Float') {
                                 $customVal = (double) $details->{$name};
                             } elseif (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) {
                                 $customVal = $details->{$name};
                             }
                             //CRM-4582
                             if (CRM_Utils_System::isNull($customVal)) {
                                 continue;
                             }
                             $params[$index] = $customVal;
                             $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                             if ($field['data_type'] == 'ContactReference') {
                                 $params[$index] = $values[$index];
                             }
                             if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                 $customFieldName = "{$name}_from";
                             }
                         }
                     } elseif ($name == 'image_URL') {
                         list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->{$name}));
                         list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height);
                         $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . '  />';
                         $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>";
                     } elseif (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) {
                         $values[$index] = CRM_Utils_Date::customFormat($details->{$name});
                         $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name});
                     } else {
                         $dao = '';
                         if ($index == 'Campaign') {
                             $dao = 'CRM_Campaign_DAO_Campaign';
                         } elseif ($index == 'Contribution Page') {
                             $dao = 'CRM_Contribute_DAO_ContributionPage';
                         }
                         if ($dao) {
                             $value = CRM_Core_DAO::getFieldValue($dao, $details->{$name}, 'title');
                         } else {
                             $value = $details->{$name};
                         }
                         $values[$index] = $value;
                     }
                 }
             }
         } elseif (strpos($name, '-') !== FALSE) {
             list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3);
             if (!in_array($fieldName, $multipleFields)) {
                 if ($id == 'Primary') {
                     // fix for CRM-1543
                     // not sure why we'd every use Primary location type id
                     // we need to fix the source if we are using it
                     // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid );
                     $locationTypeName = 1;
                 } else {
                     $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                 }
                 if (!$locationTypeName) {
                     continue;
                 }
                 $detailName = "{$locationTypeName}-{$fieldName}";
                 $detailName = str_replace(' ', '_', $detailName);
                 if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) {
                     if ($type) {
                         $detailName .= "-{$type}";
                     }
                 }
                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                     $values[$index] = $details->{$detailName};
                     $idx = $detailName . '_id';
                     $params[$index] = $details->{$idx};
                 } elseif ($fieldName == 'im') {
                     $providerId = $detailName . '-provider_id';
                     if (isset($imProviders[$details->{$providerId}])) {
                         $values[$index] = $details->{$detailName} . " (" . $imProviders[$details->{$providerId}] . ")";
                     } else {
                         $values[$index] = $details->{$detailName};
                     }
                     $params[$index] = $details->{$detailName};
                 } elseif ($fieldName == 'phone') {
                     $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
                     if (isset($details->{$phoneExtField})) {
                         $values[$index] = $details->{$detailName} . " (" . $details->{$phoneExtField} . ")";
                     } else {
                         $values[$index] = $details->{$detailName};
                     }
                     $params[$index] = $details->{$detailName};
                 } else {
                     $values[$index] = $params[$index] = $details->{$detailName};
                 }
             } else {
                 $detailName = "website-{$id}-{$fieldName}";
                 $url = CRM_Utils_System::fixURL($details->{$detailName});
                 if ($details->{$detailName}) {
                     $websiteTypeId = "website-{$id}-website_type_id";
                     $websiteType = $websiteTypes[$details->{$websiteTypeId}];
                     $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>";
                 } else {
                     $values[$index] = '';
                 }
             }
         }
         if (CRM_Utils_Array::value('visibility', $field) == 'Public Pages and Listings' && CRM_Core_Permission::check('profile listings and forms')) {
             if (CRM_Utils_System::isNull($params[$index])) {
                 $params[$index] = $values[$index];
             }
             if (!isset($params[$index])) {
                 continue;
             }
             if (!$customFieldName) {
                 $fieldName = $field['name'];
             } else {
                 $fieldName = $customFieldName;
             }
             $url = NULL;
             if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
                 $htmlType = $field['html_type'];
                 if ($htmlType == 'Link') {
                     $url = $params[$index];
                 } elseif (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) {
                     $valSeperator = CRM_Core_DAO::VALUE_SEPARATOR;
                     $selectedOptions = explode($valSeperator, $params[$index]);
                     foreach ($selectedOptions as $key => $multiOption) {
                         if ($multiOption) {
                             $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption));
                         }
                     }
                 } else {
                     $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
                 }
             } else {
                 $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
             }
             if ($url && !empty($values[$index]) && $searchable) {
                 if (is_array($url) && !empty($url)) {
                     $links = array();
                     $eachMultiValue = explode(', ', $values[$index]);
                     foreach ($eachMultiValue as $key => $valueLabel) {
                         $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>';
                     }
                     $values[$index] = implode(', ', $links);
                 } else {
                     $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>';
                 }
             }
         }
     }
 }
示例#5
0
文件: Search.php 项目: ksecor/civicrm
 /**
  * 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');
 }
示例#6
0
 /**
  * This function to get list of groups.
  *
  * @param array $params
  *   Associated array for params.
  *
  * @return array
  */
 public static function getGroupList(&$params)
 {
     $config = CRM_Core_Config::singleton();
     $whereClause = self::whereClause($params, FALSE);
     //$this->pagerAToZ( $whereClause, $params );
     if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
         $limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
     }
     $orderBy = ' ORDER BY groups.title asc';
     if (!empty($params['sort'])) {
         $orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
         // CRM-16905 - Sort by count cannot be done with sql
         if (strpos($params['sort'], 'count') === 0) {
             $orderBy = $limit = '';
         }
     }
     $select = $from = $where = "";
     $groupOrg = FALSE;
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
         $select = ", contact.display_name as org_name, contact.id as org_id";
         $from = " LEFT JOIN civicrm_group_organization gOrg\n                               ON gOrg.group_id = groups.id\n                        LEFT JOIN civicrm_contact contact\n                               ON contact.id = gOrg.organization_id ";
         //get the Organization ID
         $orgID = CRM_Utils_Request::retrieve('oid', 'Positive', CRM_Core_DAO::$_nullObject);
         if ($orgID) {
             $where = " AND gOrg.organization_id = {$orgID}";
         }
         $groupOrg = TRUE;
     }
     $query = "\n        SELECT groups.*, createdBy.sort_name as created_by {$select}\n        FROM  civicrm_group groups\n        LEFT JOIN civicrm_contact createdBy\n          ON createdBy.id = groups.created_id\n        {$from}\n        WHERE {$whereClause} {$where}\n        GROUP BY groups.id\n        {$orderBy}\n        {$limit}";
     $object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contact_DAO_Group');
     //FIXME CRM-4418, now we are handling delete separately
     //if we introduce 'delete for group' make sure to handle here.
     $groupPermissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit groups')) {
         $groupPermissions[] = CRM_Core_Permission::EDIT;
         $groupPermissions[] = CRM_Core_Permission::DELETE;
     }
     // CRM-9936
     $reservedPermission = CRM_Core_Permission::check('administer reserved groups');
     $links = self::actionLinks();
     $allTypes = CRM_Core_OptionGroup::values('group_type');
     $values = $groupsToCount = array();
     $visibility = CRM_Core_SelectValues::ufVisibility();
     while ($object->fetch()) {
         $permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
         //@todo CRM-12209 introduced an ACL check in the whereClause function
         // it may be that this checking is now obsolete - or that what remains
         // should be removed to the whereClause (which is also accessed by getCount)
         if ($permission) {
             $newLinks = $links;
             $values[$object->id] = array('class' => array(), 'count' => '0');
             CRM_Core_DAO::storeValues($object, $values[$object->id]);
             // Wrap with crm-editable. Not an ideal solution.
             if (in_array(CRM_Core_Permission::EDIT, $groupPermissions)) {
                 $values[$object->id]['title'] = '<span class="crm-editable crmf-title">' . $values[$object->id]['title'] . '</span>';
             }
             if ($object->saved_search_id) {
                 $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
                 // check if custom search, if so fix view link
                 $customSearchID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $object->saved_search_id, 'search_custom_id');
                 if ($customSearchID) {
                     $newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
                     $newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
                 }
             }
             $action = array_sum(array_keys($newLinks));
             // CRM-9936
             if (array_key_exists('is_reserved', $object)) {
                 //if group is reserved and I don't have reserved permission, suppress delete/edit
                 if ($object->is_reserved && !$reservedPermission) {
                     $action -= CRM_Core_Action::DELETE;
                     $action -= CRM_Core_Action::UPDATE;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             if (array_key_exists('is_active', $object)) {
                 if ($object->is_active) {
                     $action -= CRM_Core_Action::ENABLE;
                 } else {
                     $values[$object->id]['class'][] = 'disabled';
                     $action -= CRM_Core_Action::VIEW;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             $action = $action & CRM_Core_Action::mask($groupPermissions);
             $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
             $groupsToCount[$object->saved_search_id ? 'civicrm_group_contact_cache' : 'civicrm_group_contact'][] = $object->id;
             if (isset($values[$object->id]['group_type'])) {
                 $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values[$object->id]['group_type'], 1, -1));
                 $types = array();
                 foreach ($groupTypes as $type) {
                     $types[] = CRM_Utils_Array::value($type, $allTypes);
                 }
                 $values[$object->id]['group_type'] = implode(', ', $types);
             }
             $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks, $action, array('id' => $object->id, 'ssid' => $object->saved_search_id), ts('more'), FALSE, 'group.selector.row', 'Group', $object->id);
             // If group has children, add class for link to view children
             $values[$object->id]['is_parent'] = FALSE;
             if (array_key_exists('children', $values[$object->id])) {
                 $values[$object->id]['class'][] = "crm-group-parent";
                 $values[$object->id]['is_parent'] = TRUE;
             }
             // If group is a child, add child class
             if (array_key_exists('parents', $values[$object->id])) {
                 $values[$object->id]['class'][] = "crm-group-child";
             }
             if ($groupOrg) {
                 if ($object->org_id) {
                     $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
                     $values[$object->id]['org_info'] = "<a href='{$contactUrl}'>{$object->org_name}</a>";
                 } else {
                     $values[$object->id]['org_info'] = '';
                     // Empty cell
                 }
             } else {
                 $values[$object->id]['org_info'] = NULL;
                 // Collapsed column if all cells are NULL
             }
             if ($object->created_id) {
                 $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->created_id}");
                 $values[$object->id]['created_by'] = "<a href='{$contactUrl}'>{$object->created_by}</a>";
             }
         }
     }
     // Get group counts - executes one query for regular groups and another for smart groups
     foreach ($groupsToCount as $table => $groups) {
         $where = "g.group_id IN (" . implode(',', $groups) . ")";
         if ($table == 'civicrm_group_contact') {
             $where .= " AND g.status = 'Added'";
         }
         // Exclude deleted contacts
         $where .= " and c.id = g.contact_id AND c.is_deleted = 0";
         $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(g.id) as `count` FROM {$table} g, civicrm_contact c WHERE {$where} GROUP BY g.group_id");
         while ($dao->fetch()) {
             $values[$dao->group_id]['count'] = $dao->count;
         }
     }
     // CRM-16905 - Sort by count cannot be done with sql
     if (!empty($params['sort']) && strpos($params['sort'], 'count') === 0) {
         usort($values, function ($a, $b) {
             return $a['count'] - $b['count'];
         });
         if (strpos($params['sort'], 'desc')) {
             $values = array_reverse($values, TRUE);
         }
         return array_slice($values, $params['offset'], $params['rowCount']);
     }
     return $values;
 }
 /**
  * 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 array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null)
 {
     $query = "SELECT * FROM civicrm_group WHERE id = " . CRM_Utils_Type::escape($group->id, 'Integer');
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT civicrm_contact.id as contact_id,\n                      civicrm_email.email as email";
         //$query = "SELECT *,civicrm_contact.id as contact_id, (talk to lobo before re-enabling this)
         //civicrm_email.email as email";
     } else {
         $query = "SELECT civicrm_contact.id as contact_id ,";
         $query .= implode(',', $returnProperties);
     }
     $fv = array('group' => array($group->id => true));
     if ($status) {
         $fv['group_contact_status'] = array($status => true);
     } else {
         $fv['group_contact_status'] = array('Added' => true, 'Removed' => true, 'Pending' => true);
     }
     $tables = array(CRM_Contact_BAO_GroupContact::getTableName() => true, CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true, CRM_Contact_BAO_Group::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($fv, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_CORE_PERMISSION_VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if ($offset != null && $row_count != null) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     // CRM_Core_Error::debug( 'q', $query );
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
示例#9
0
 /**
  * Make sure that the user has permission to access this group.
  *
  * @param int $id
  *   The id of the object.
  * @param int $title
  *   Name or title of the object.
  *
  * @return string
  *   the permission that the user has (or null)
  */
 public function checkPermission($id, $title)
 {
     return CRM_Contact_BAO_Group::checkPermission($id, $title);
 }
示例#10
0
/**
 *
 * Delete an existing group.
 *
 * @param $group         A valid group object (passed by reference)
 *
 * @return  null, if successful.or  CRM error object, if permissions are insufficient, etc.
 *
 *
 * @access public
 */
function crm_delete_group(&$group)
{
    _crm_initialize();
    if (!is_a($group, 'CRM_Contact_BAO_Group') && !is_a($group, 'CRM_Contact_DAO_Group')) {
        return _crm_error('Invalid group object passed in');
    }
    if ($group->id == null) {
        return _crm_error('Could not locate group with id: $id');
    }
    if (!CRM_Contact_BAO_Group::checkPermission($group->id, $group->title)) {
        return CRM_Core_Error::fatal("You do not have permission to access group with id: {$id}");
    }
    CRM_Contact_BAO_Group::discard($group->id);
    return null;
}
 /**
  * This function to get list of groups
  *
  * @param  array   $params associated array for params
  * @access public
  */
 static function getGroupList(&$params)
 {
     $config = CRM_Core_Config::singleton();
     $whereClause = self::whereClause($params, FALSE);
     //$this->pagerAToZ( $whereClause, $params );
     if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
         $limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
     }
     $orderBy = ' ORDER BY groups.title asc';
     if (CRM_Utils_Array::value('sort', $params)) {
         $orderBy = ' ORDER BY ' . CRM_Utils_Array::value('sort', $params);
     }
     $select = $from = $where = "";
     $groupOrg = FALSE;
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
         $select = ", contact.display_name as org_name, contact.id as org_id";
         $from = " LEFT JOIN civicrm_group_organization gOrg\n                               ON gOrg.group_id = groups.id\n                        LEFT JOIN civicrm_contact contact\n                               ON contact.id = gOrg.organization_id ";
         //get the Organization ID
         $orgID = CRM_Utils_Request::retrieve('oid', 'Positive', CRM_Core_DAO::$_nullObject);
         if ($orgID) {
             $where = " AND gOrg.organization_id = {$orgID}";
         }
         $groupOrg = TRUE;
     }
     $query = "\n        SELECT groups.* {$select}\n        FROM  civicrm_group groups\n              {$from}\n        WHERE {$whereClause} {$where}\n        {$orderBy}\n        {$limit}";
     $object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contact_DAO_Group');
     //FIXME CRM-4418, now we are handling delete separately
     //if we introduce 'delete for group' make sure to handle here.
     $groupPermissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit groups')) {
         $groupPermissions[] = CRM_Core_Permission::EDIT;
         $groupPermissions[] = CRM_Core_Permission::DELETE;
     }
     // CRM-9936
     $reservedPermission = CRM_Core_Permission::check('administer reserved groups');
     $links = self::actionLinks();
     $allTypes = CRM_Core_OptionGroup::values('group_type');
     $values = array();
     while ($object->fetch()) {
         $permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
         if ($permission) {
             $newLinks = $links;
             $values[$object->id] = array();
             CRM_Core_DAO::storeValues($object, $values[$object->id]);
             if ($object->saved_search_id) {
                 $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
                 // check if custom search, if so fix view link
                 $customSearchID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $object->saved_search_id, 'search_custom_id');
                 if ($customSearchID) {
                     $newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
                     $newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
                 }
             }
             $action = array_sum(array_keys($newLinks));
             // CRM-9936
             if (array_key_exists('is_reserved', $object)) {
                 //if group is reserved and I don't have reserved permission, suppress delete/edit
                 if ($object->is_reserved && !$reservedPermission) {
                     $action -= CRM_Core_Action::DELETE;
                     $action -= CRM_Core_Action::UPDATE;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             $values[$object->id]['class'] = '';
             if (array_key_exists('is_active', $object)) {
                 if ($object->is_active) {
                     $action -= CRM_Core_Action::ENABLE;
                 } else {
                     $values[$object->id]['class'] = 'disabled';
                     $action -= CRM_Core_Action::VIEW;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             $action = $action & CRM_Core_Action::mask($groupPermissions);
             $values[$object->id]['visibility'] = CRM_Contact_DAO_Group::tsEnum('visibility', $values[$object->id]['visibility']);
             if (isset($values[$object->id]['group_type'])) {
                 $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values[$object->id]['group_type'], 1, -1));
                 $types = array();
                 foreach ($groupTypes as $type) {
                     $types[] = CRM_Utils_Array::value($type, $allTypes);
                 }
                 $values[$object->id]['group_type'] = implode(', ', $types);
             }
             $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks, $action, array('id' => $object->id, 'ssid' => $object->saved_search_id));
             if ($groupOrg) {
                 if ($object->org_id) {
                     $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
                     $values[$object->id]['org_info'] = "<a href='{$contactUrl}'>{$object->org_name}</a>";
                 } else {
                     $values[$object->id]['org_info'] = '';
                     // Empty cell
                 }
             } else {
                 $values[$object->id]['org_info'] = NULL;
                 // Collapsed column if all cells are NULL
             }
         }
     }
     return $values;
 }
示例#12
0
 /**
  * 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');
 }