示例#1
0
文件: Note.php 项目: bhirsch/voipdev
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     $note =& new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_contact';
     $note->entity_id = $this->_contactId;
     $note->orderBy('modified_date desc');
     //CRM-4418, handling edit and delete separately.
     $permissions = array($this->_permission);
     if ($this->_permission == CRM_Core_Permission::EDIT) {
         //previously delete was subset of edit
         //so for consistency lets grant delete also.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $values = array();
     $links =& self::links();
     $action = array_sum(array_keys($links)) & $mask;
     $note->find();
     while ($note->fetch()) {
         $values[$note->id] = array();
         CRM_Core_DAO::storeValues($note, $values[$note->id]);
         $values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $note->id, 'cid' => $this->_contactId));
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $note->contact_id;
         $contact->find();
         $contact->fetch();
         $values[$note->id]['createdBy'] = $contact->display_name;
     }
     $this->assign('notes', $values);
 }
示例#2
0
文件: Tab.php 项目: ksecor/civicrm
 /**
  * This function is called when action is browse
  * 
  * return null
  * @access public
  */
 function browse()
 {
     $links =& self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
     $idList = array('membership_type' => 'MembershipType', 'status' => 'MembershipStatus');
     $membership = array();
     require_once 'CRM/Member/DAO/Membership.php';
     $dao =& new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     //$dao->orderBy('name');
     $dao->find();
     //CRM--4418, check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     //checks membership of contact itself
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         foreach ($idList as $name => $file) {
             if ($membership[$dao->id][$name . '_id']) {
                 $membership[$dao->id][$name] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_' . $file, $membership[$dao->id][$name . '_id']);
             }
         }
         if ($dao->status_id) {
             $active = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $dao->status_id, 'is_current_member');
             if ($active) {
                 $membership[$dao->id]['active'] = $active;
             }
         }
         if (!$dao->owner_membership_id) {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('all'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId));
         } else {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId));
         }
     }
     //Below code gives list of all Membership Types associated
     //with an Organization(CRM-2016)
     include_once 'CRM/Member/BAO/MembershipType.php';
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId);
     foreach ($membershipTypes as $key => $value) {
         $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), $mask, array('id' => $value['id'], 'cid' => $this->_contactId));
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
     $this->assign('membershipTypes', $membershipTypes);
 }
 /**
  * This function is called when action is browse
  * 
  * return null
  * @access public
  */
 function browse()
 {
     $links =& CRM_Contact_Page_View_Relationship::links();
     $mask = CRM_Core_Action::mask($this->_permission);
     $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_CURRENT, 0, 0, 0, $links, $mask);
     $pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_PAST, 0, 0, 0, $links, $mask);
     $disableRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_CONTACT_BAO_RELATIONSHIP_DISABLED, 0, 0, 0, $links, $mask);
     $this->assign('currentRelationships', $currentRelationships);
     $this->assign('pastRelationships', $pastRelationships);
     $this->assign('disableRelationships', $disableRelationships);
 }
示例#4
0
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     $note =& new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_contact';
     $note->entity_id = $this->_contactId;
     $note->orderBy('modified_date desc');
     $values = array();
     $links =& CRM_Contact_Page_View_Note::links();
     $action = array_sum(array_keys($links)) & CRM_Core_Action::mask($this->_permission);
     $note->find();
     while ($note->fetch()) {
         $values[$note->id] = array();
         CRM_Core_DAO::storeValues($note, $values[$note->id]);
         $values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $note->id, 'cid' => $this->_contactId));
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $note->contact_id;
         $contact->find();
         $contact->fetch();
         $values[$note->id]['createdBy'] = $contact->display_name;
     }
     $this->assign('notes', $values);
 }
示例#5
0
 /**
  * Retrieve cases related to particular contact or whole contact
  * used in Dashboad and Tab
  *
  * @param boolean $allCases
  *
  * @param int $userID
  *
  * @param String $type /upcoming,recent,all/
  *
  * @param string $context
  *
  * @return array     Array of Cases
  *
  * @access public
  */
 static function getCases($allCases = TRUE, $userID = NULL, $type = 'upcoming', $context = 'dashboard')
 {
     $condition = NULL;
     $casesList = array();
     //validate access for own cases.
     if (!self::accessCiviCase()) {
         return $casesList;
     }
     if (!$userID) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
     }
     //validate access for all cases.
     if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
         $allCases = FALSE;
     }
     $condition = " AND civicrm_case.is_deleted = 0 ";
     if (!$allCases) {
         $condition .= " AND case_relationship.contact_id_b = {$userID} ";
     }
     if ($type == 'upcoming' || $type == 'any') {
         $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name');
         $condition .= "\nAND civicrm_case.status_id != {$closedId}";
     }
     $query = self::getCaseActivityQuery($type, $userID, $condition);
     $queryParams = array();
     $result = CRM_Core_DAO::executeQuery($query, $queryParams);
     $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
     $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_subject', 'case_type', 'case_type_id', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_start_date', 'case_role');
     if ($type == 'upcoming') {
         $resultFields[] = 'case_scheduled_activity_date';
         $resultFields[] = 'case_scheduled_activity_type_name';
         $resultFields[] = 'case_scheduled_activity_type';
         $resultFields[] = 'case_scheduled_activity_id';
     } elseif ($type == 'recent') {
         $resultFields[] = 'case_recent_activity_date';
         $resultFields[] = 'case_recent_activity_type_name';
         $resultFields[] = 'case_recent_activity_type';
         $resultFields[] = 'case_recent_activity_id';
     } elseif ($type == 'any') {
         $resultFields[] = 'case_activity_date';
         $resultFields[] = 'case_activity_type_name';
         $resultFields[] = 'case_activity_type';
         $resultFields[] = 'case_activity_id';
     }
     // we're going to use the usual actions, so doesn't make sense to duplicate definitions
     $actions = CRM_Case_Selector_Search::links();
     // check is the user has view/edit signer permission
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('access all cases and activities') || !$allCases && CRM_Core_Permission::check('access my cases and activities')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         foreach ($resultFields as $donCare => $field) {
             $casesList[$result->case_id][$field] = $result->{$field};
             if ($field == 'contact_type') {
                 $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
                 $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions['primaryActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), FALSE, 'case.actions.primary', 'Case', $result->case_id);
                 $casesList[$result->case_id]['moreActions'] = CRM_Core_Action::formLink($actions['moreActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), TRUE, 'case.actions.more', 'Case', $result->case_id);
             } elseif ($field == 'case_status') {
                 if (in_array($result->{$field}, $caseStatus)) {
                     $casesList[$result->case_id]['class'] = "status-urgent";
                 } else {
                     $casesList[$result->case_id]['class'] = "status-normal";
                 }
             }
         }
         //CRM-4510.
         $caseTypes = CRM_Case_PseudoConstant::caseType('name');
         $caseManagerContact = self::getCaseManagerContact($caseTypes[$result->case_type_id], $result->case_id);
         if (!empty($caseManagerContact)) {
             $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
         //do check user permissions for edit/view activity.
         if (($actId = CRM_Utils_Array::value('case_scheduled_activity_id', $casesList[$result->case_id])) || ($actId = CRM_Utils_Array::value('case_recent_activity_id', $casesList[$result->case_id]))) {
             $casesList[$result->case_id]["case_{$type}_activity_editable"] = self::checkPermission($actId, 'edit', $casesList[$result->case_id]['activity_type_id'], $userID);
             $casesList[$result->case_id]["case_{$type}_activity_viewable"] = self::checkPermission($actId, 'view', $casesList[$result->case_id]['activity_type_id'], $userID);
         }
     }
     return $casesList;
 }
示例#6
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $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 string $output
  *   What should the result set include (web/email/csv).
  *
  * @return array
  *   rows in the given offset and rowCount
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_eventClause);
     // process the result of the query
     $rows = array();
     //lets handle view, edit and delete separately. CRM-4418
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit event participants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviEvent')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $statusTypes = CRM_Event_PseudoConstant::participantStatus();
     $statusClasses = CRM_Event_PseudoConstant::participantStatusClass();
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->participant_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->participant_campaign_id;
         // gross hack to show extra information for pending status
         $statusClass = NULL;
         if (isset($row['participant_status_id']) && ($statusId = array_search($row['participant_status_id'], $statusTypes))) {
             $statusClass = $statusClasses[$statusId];
         }
         $row['showConfirmUrl'] = $statusClass == 'Pending' ? TRUE : FALSE;
         if (!empty($row['participant_is_test'])) {
             $row['participant_status'] .= ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id;
         $links = self::links($this->_key, $this->_context, $this->_compContext);
         if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
             $links[CRM_Core_Action::ADD] = array('name' => ts('Record Payment'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Payment'));
         }
         if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
             $links[CRM_Core_Action::ADD] = array('name' => ts('Record Refund'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Refund'));
         }
         $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->participant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'participant.selector.row', 'Participant', $result->participant_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['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']);
         if (!empty($row['participant_fee_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']);
         }
         if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
             // add line item details if applicable
             $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
         }
         if (!empty($row['participant_role_id'])) {
             $viewRoles = array();
             foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
                 $viewRoles[] = $participantRoles[$v];
             }
             $row['participant_role_id'] = implode(', ', $viewRoles);
         }
         $rows[] = $row;
     }
     CRM_Core_Selector_Controller::$_template->assign_by_ref('lineItems', $lineItems);
     return $rows;
 }
示例#7
0
 /**
  * Given an object, get the actions that can be associated with this
  * object. Check the is_active and is_required flags to display valid
  * actions
  *
  * @param CRM_Core_DAO $object
  *   The object being considered.
  * @param int $action
  *   The base set of actions.
  * @param array $values
  *   The array of values that we send to the template.
  * @param array $links
  *   The array of links.
  * @param string $permission
  *   The permission assigned to this object.
  *
  * @param bool $forceAction
  */
 public function action(&$object, $action, &$values, &$links, $permission, $forceAction = FALSE)
 {
     $values['class'] = '';
     $newAction = $action;
     $hasDelete = $hasDisable = TRUE;
     if (!empty($values['name']) && in_array($values['name'], array('encounter_medium', 'case_type', 'case_status'))) {
         static $caseCount = NULL;
         if (!isset($caseCount)) {
             $caseCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE);
         }
         if ($caseCount > 0) {
             $hasDelete = $hasDisable = FALSE;
         }
     }
     if (!$forceAction) {
         if (array_key_exists('is_reserved', $object) && $object->is_reserved) {
             $values['class'] = 'reserved';
             // check if object is relationship type
             $object_type = get_class($object);
             $exceptions = array('CRM_Contact_BAO_RelationshipType', 'CRM_Core_BAO_LocationType', 'CRM_Badge_BAO_Layout');
             if (in_array($object_type, $exceptions)) {
                 $newAction = CRM_Core_Action::VIEW + CRM_Core_Action::UPDATE;
             } else {
                 $newAction = 0;
                 $values['action'] = '';
                 return;
             }
         } else {
             if (array_key_exists('is_active', $object)) {
                 if ($object->is_active) {
                     if ($hasDisable) {
                         $newAction += CRM_Core_Action::DISABLE;
                     }
                 } else {
                     $newAction += CRM_Core_Action::ENABLE;
                 }
             }
         }
     }
     //CRM-4418, handling edit and delete separately.
     $permissions = array($permission);
     if ($hasDelete && $permission == CRM_Core_Permission::EDIT) {
         //previously delete was subset of edit
         //so for consistency lets grant delete also.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     // make sure we only allow those actions that the user is permissioned for
     $newAction = $newAction & CRM_Core_Action::mask($permissions);
     $values['action'] = CRM_Core_Action::formLink($links, $newAction, array('id' => $object->id));
 }
示例#8
0
 /**
  * This function is a wrapper for ajax activity selector
  *
  * @param  array   $params associated array for params record id.
  *
  * @return array   $contactActivities associated array of contact activities
  * @access public
  */
 public static function getContactActivitySelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['caseId'] = NULL;
     $context = CRM_Utils_Array::value('context', $params);
     // get contact activities
     $activities = CRM_Activity_BAO_Activity::getActivities($params);
     // add total
     $params['total'] = CRM_Activity_BAO_Activity::getActivitiesCount($params);
     // format params and add links
     $contactActivities = array();
     if (!empty($activities)) {
         $activityStatus = CRM_Core_PseudoConstant::activityStatus();
         // check logged in user for permission
         $page = new CRM_Core_Page();
         CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
         $permissions = array($page->_permission);
         if (CRM_Core_Permission::check('delete activities')) {
             $permissions[] = CRM_Core_Permission::DELETE;
         }
         $mask = CRM_Core_Action::mask($permissions);
         foreach ($activities as $activityId => $values) {
             $contactActivities[$activityId]['activity_type'] = $values['activity_type'];
             $contactActivities[$activityId]['subject'] = $values['subject'];
             if ($params['contact_id'] == $values['source_contact_id']) {
                 $contactActivities[$activityId]['source_contact'] = $values['source_contact_name'];
             } elseif ($values['source_contact_id']) {
                 $contactActivities[$activityId]['source_contact'] = CRM_Utils_System::href($values['source_contact_name'], 'civicrm/contact/view', "reset=1&cid={$values['source_contact_id']}");
             } else {
                 $contactActivities[$activityId]['source_contact'] = '<em>n/a</em>';
             }
             if (isset($values['mailingId']) && !empty($values['mailingId'])) {
                 $contactActivities[$activityId]['target_contact'] = CRM_Utils_System::href($values['recipients'], 'civicrm/mailing/report/event', "mid={$values['source_record_id']}&reset=1&event=queue&cid={$params['contact_id']}&context=activitySelector");
             } elseif (CRM_Utils_Array::value('recipients', $values)) {
                 $contactActivities[$activityId]['target_contact'] = $values['recipients'];
             } elseif (!$values['target_contact_name']) {
                 $contactActivities[$activityId]['target_contact'] = '<em>n/a</em>';
             } elseif (!empty($values['target_contact_name'])) {
                 $count = 0;
                 $contactActivities[$activityId]['target_contact'] = '';
                 foreach ($values['target_contact_name'] as $tcID => $tcName) {
                     if ($tcID && $count < 5) {
                         $contactActivities[$activityId]['target_contact'] .= CRM_Utils_System::href($tcName, 'civicrm/contact/view', "reset=1&cid={$tcID}");
                         $count++;
                         if ($count) {
                             $contactActivities[$activityId]['target_contact'] .= ";&nbsp;";
                         }
                         if ($count == 4) {
                             $contactActivities[$activityId]['target_contact'] .= "(" . ts('more') . ")";
                             break;
                         }
                     }
                 }
             }
             if (empty($values['assignee_contact_name'])) {
                 $contactActivities[$activityId]['assignee_contact'] = '<em>n/a</em>';
             } elseif (!empty($values['assignee_contact_name'])) {
                 $count = 0;
                 $contactActivities[$activityId]['assignee_contact'] = '';
                 foreach ($values['assignee_contact_name'] as $acID => $acName) {
                     if ($acID && $count < 5) {
                         $contactActivities[$activityId]['assignee_contact'] .= CRM_Utils_System::href($acName, 'civicrm/contact/view', "reset=1&cid={$acID}");
                         $count++;
                         if ($count) {
                             $contactActivities[$activityId]['assignee_contact'] .= ";&nbsp;";
                         }
                         if ($count == 4) {
                             $contactActivities[$activityId]['assignee_contact'] .= "(" . ts('more') . ")";
                             break;
                         }
                     }
                 }
             }
             $contactActivities[$activityId]['activity_date'] = CRM_Utils_Date::customFormat($values['activity_date_time']);
             $contactActivities[$activityId]['status'] = $activityStatus[$values['status_id']];
             // add class to this row if overdue
             $contactActivities[$activityId]['class'] = '';
             if (CRM_Utils_Date::overdue(CRM_Utils_Array::value('activity_date_time', $values)) && CRM_Utils_Array::value('status_id', $values) == 1) {
                 $contactActivities[$activityId]['class'] = 'status-overdue';
             } else {
                 $contactActivities[$activityId]['class'] = 'status-ontime';
             }
             // build links
             $contactActivities[$activityId]['links'] = '';
             $accessMailingReport = FALSE;
             if (CRM_Utils_Array::value('mailingId', $values)) {
                 $accessMailingReport = TRUE;
             }
             $actionLinks = CRM_Activity_Selector_Activity::actionLinks(CRM_Utils_Array::value('activity_type_id', $values), CRM_Utils_Array::value('source_record_id', $values), $accessMailingReport, CRM_Utils_Array::value('activity_id', $values));
             $actionMask = array_sum(array_keys($actionLinks)) & $mask;
             $contactActivities[$activityId]['links'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('id' => $values['activity_id'], 'cid' => $params['contact_id'], 'cxt' => $context, 'caseid' => CRM_Utils_Array::value('case_id', $values)));
         }
     }
     return $contactActivities;
 }
示例#9
0
 /**
  * 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)
 {
     $includeContactIDs = false;
     if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIDs = true;
     }
     $sql = $this->_search->all($offset, $rowCount, $sort, $includeContactIDs);
     $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     $columns = $this->_search->columns();
     $columnNames = array_values($columns);
     $links = self::links();
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $alterRow = false;
     if (method_exists($this->_customSearchClass, 'alterRow')) {
         $alterRow = true;
     }
     $image = false;
     if (is_a($this->_search, 'CRM_Contact_Form_Search_Custom_Basic')) {
         $image = true;
     }
     // process the result of the query
     $rows = array();
     while ($dao->fetch()) {
         $row = array();
         $empty = true;
         // the columns we are interested in
         foreach ($columnNames as $property) {
             $row[$property] = $dao->{$property};
             if (!empty($dao->{$property})) {
                 $empty = false;
             }
         }
         if (!$empty) {
             $contactID = isset($dao->contact_id) ? $dao->contact_id : NULL;
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $contactID;
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $contactID));
             $row['contact_id'] = $contactID;
             if ($alterRow) {
                 $this->_search->alterRow($row);
             }
             if ($image) {
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, false, $contactID);
             }
             $rows[] = $row;
         }
     }
     return $rows;
 }
示例#10
0
文件: Custom.php 项目: kidaa30/yes
 /**
  * Add actions.
  *
  * @param array $rows
  */
 public function addActions(&$rows)
 {
     $links = self::links($this->_key);
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     foreach ($rows as $id => &$row) {
         $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $row['contact_id']), ts('more'), FALSE, 'contact.custom.actions', 'Contact', $row['contact_id']);
     }
 }
示例#11
0
文件: Case.php 项目: bhirsch/voipdev
 /**
  * Retrieve cases related to particular contact or whole contact
  * used in Dashboad and Tab
  *
  * @param boolean    $allCases  
  * 
  * @param int        $userID 
  *
  * @param String     $type /upcoming,recent,all/ 
  *
  * @return array     Array of Cases
  * 
  * @access public
  * 
  */
 function getCases($allCases = true, $userID = null, $type = 'upcoming')
 {
     $condition = null;
     if (!$allCases) {
         $condition = " AND case_relationship.contact_id_b = {$userID}";
     }
     $condition .= " \nAND civicrm_activity.is_deleted = 0\nAND civicrm_case.is_deleted     = 0";
     if ($type == 'upcoming') {
         $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name');
         $condition .= "\nAND civicrm_case.status_id != {$closedId}";
     }
     $query = self::getCaseActivityQuery($type, $userID, $condition);
     $queryParams = array();
     $result = CRM_Core_DAO::executeQuery($query, $queryParams);
     require_once 'CRM/Core/OptionGroup.php';
     $caseStatus = CRM_Core_OptionGroup::values('case_status', false, false, false, " AND v.name = 'Urgent' ");
     $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_type', 'case_type_name', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_role');
     if ($type == 'upcoming') {
         $resultFields[] = 'case_scheduled_activity_date';
         $resultFields[] = 'case_scheduled_activity_type_name';
         $resultFields[] = 'case_scheduled_activity_type';
         $resultFields[] = 'case_scheduled_activity_id';
     } else {
         if ($type == 'recent') {
             $resultFields[] = 'case_recent_activity_date';
             $resultFields[] = 'case_recent_activity_type_name';
             $resultFields[] = 'case_recent_activity_type';
             $resultFields[] = 'case_recent_activity_id';
         }
     }
     // we're going to use the usual actions, so doesn't make sense to duplicate definitions
     require_once 'CRM/Case/Selector/Search.php';
     $actions = CRM_Case_Selector_Search::links();
     require_once "CRM/Contact/BAO/Contact/Utils.php";
     $casesList = array();
     // check is the user has view/edit signer permission
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit cases')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         foreach ($resultFields as $donCare => $field) {
             $casesList[$result->case_id][$field] = $result->{$field};
             if ($field == 'contact_type') {
                 $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
                 $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions, $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => 'dashboard'));
             } elseif ($field == 'case_status') {
                 if (in_array($result->{$field}, $caseStatus)) {
                     $casesList[$result->case_id]['class'] = "status-urgent";
                 } else {
                     $casesList[$result->case_id]['class'] = "status-normal";
                 }
             }
         }
         //CRM-4510.
         $caseManagerContact = self::getCaseManagerContact($result->case_type_name, $result->case_id);
         if (!empty($caseManagerContact)) {
             $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
     }
     return $casesList;
 }
示例#12
0
 /**
  * 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)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_bookingClause);
     //lets handle view, edit and delete separately.
     $permissions = array(CRM_Core_Permission::VIEW, CRM_Core_Permission::EDIT, CRM_Core_Permission::DELETE);
     /*if (CRM_Core_Permission::check('edit event Booking')) {
         $permissions[] = CRM_Core_Permission::EDIT;
       }
       if (CRM_Core_Permission::check('delete in Booking')) {
         $permissions[] = CRM_Core_Permission::DELETE;
       }*/
     $mask = CRM_Core_Action::mask($permissions);
     // process the result of the query
     $rows = array();
     $params = array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED);
     $ov = civicrm_api3('OptionValue', 'get', $params);
     $cancelStatusId = CRM_Utils_Array::value('value', CRM_Utils_Array::value($ov['id'], $ov['values']));
     while ($result->fetch()) {
         $row = array();
         //Fixed - CVB-84
         //Make sure we don't return contact that doesn't have booking
         if (!$result->booking_id) {
             continue;
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
             $isCancelled = FALSE;
             if ($result->booking_status_id == $cancelStatusId) {
                 $isCancelled = TRUE;
             }
             $links = self::links($this->_key, $this->_context);
             if ($isCancelled) {
                 unset($links[CRM_Core_Action::UPDATE]);
                 unset($links[CRM_Core_Action::BASIC]);
                 unset($links[CRM_Core_Action::CLOSE]);
             }
             //Fixed CVB-144
             if ($result->booking_payment_status_id) {
                 unset($links[CRM_Core_Action::ADVANCED]);
             }
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->booking_id, 'cid' => $result->contact_id, 'cxt' => $this->_context));
         }
         $rows[] = $row;
     }
     return $rows;
 }
示例#13
0
 /**
  * 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)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_additionalClause);
     // process the result of the query
     $rows = array();
     // get all pledge status
     $pledgeStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //4418 check for view, edit and delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit pledges')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviPledge')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->pledge_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->pledge_campaign_id;
         // add pledge status name
         $row['pledge_status_name'] = CRM_Utils_Array::value($row['pledge_status_id'], $pledgeStatuses);
         // append (test) to status label
         if (!empty($row['pledge_is_test'])) {
             $row['pledge_status'] .= ' (test)';
         }
         $hideOption = array();
         if (CRM_Utils_Array::key('Cancelled', $row) || CRM_Utils_Array::key('Completed', $row)) {
             $hideOption[] = 'Cancel';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->pledge_id;
         $row['action'] = CRM_Core_Action::formLink(self::links($hideOption, $this->_key), $mask, array('id' => $result->pledge_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'pledge.selector.row', 'Pledge', $result->pledge_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);
         $rows[] = $row;
     }
     return $rows;
 }
示例#14
0
文件: Group.php 项目: bhirsch/voipdev
 /**
  * We need to do slightly different things for groups vs saved search groups, hence we
  * reimplement browse from Page_Basic
  * @param int $action
  *
  * @return void
  * @access public
  */
 function browse($action = null)
 {
     require_once 'CRM/Contact/BAO/GroupNesting.php';
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     if ($this->_sortByCharacter == 1 || !empty($_POST)) {
         $this->_sortByCharacter = '';
         $this->set('sortByCharacter', '');
     }
     $query = " SELECT COUNT(*) FROM civicrm_group";
     $groupExists = CRM_Core_DAO::singleValueQuery($query);
     $this->assign('groupExists', $groupExists);
     $this->search();
     $config =& CRM_Core_Config::singleton();
     $params = array();
     $whereClause = $this->whereClause($params, false);
     $this->pagerAToZ($whereClause, $params);
     $params = array();
     $whereClause = $this->whereClause($params, true);
     $this->pager($whereClause, $params);
     list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
     $select = $from = $where = "";
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && CRM_Core_Permission::check('administer Multiple Organizations')) {
         $select = ", contact.display_name as orgName, contact.id as orgID";
         $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}";
         }
         $this->assign('groupOrg', true);
     }
     $query = "\n        SELECT groups.* {$select}\n        FROM  civicrm_group groups \n              {$from}\n        WHERE {$whereClause} {$where}\n        ORDER BY groups.title asc\n        LIMIT {$offset}, {$rowCount}";
     $object = CRM_Core_DAO::executeQuery($query, $params, true, 'CRM_Contact_DAO_Group');
     $groupPermission = CRM_Core_Permission::check('edit groups') ? CRM_Core_Permission::EDIT : CRM_Core_Permission::VIEW;
     $this->assign('groupPermission', $groupPermission);
     //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;
     }
     require_once 'CRM/Core/OptionGroup.php';
     $links =& $this->links();
     $allTypes = CRM_Core_OptionGroup::values('group_type');
     $values = array();
     while ($object->fetch()) {
         $permission = $this->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));
             if (array_key_exists('is_active', $object)) {
                 if ($object->is_active) {
                     $action -= CRM_Core_Action::ENABLE;
                 } else {
                     $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[] = $allTypes[$type];
                 }
                 $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 (array_key_exists('orgName', $object)) {
                 if ($object->orgName) {
                     $values[$object->id]['org_name'] = $object->orgName;
                     $values[$object->id]['org_id'] = $object->orgID;
                 }
             }
         }
     }
     if (isset($values)) {
         $this->assign('rows', $values);
     }
 }
示例#15
0
 /**
  * This function is called when action is browse
  * 
  * return null
  * @access public
  */
 function browse()
 {
     $links =& self::links();
     //CRM-4418, handling edit and delete separately.
     $permissions = array($this->_permission);
     if ($this->_permission == CRM_Core_Permission::EDIT) {
         //previously delete was subset of edit
         //so for consistency lets grant delete also.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, $mask);
     $inactiveRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::INACTIVE, 0, 0, 0, $links, $mask);
     $this->assign('currentRelationships', $currentRelationships);
     // to show the 'Current Relationships' title and links only when viewed
     // from relationship tab, not from dashboard
     $this->assign('relationshipTabContext', true);
     $this->assign('inactiveRelationships', $inactiveRelationships);
 }
示例#16
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $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 string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_additionalClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('access all cases and activities') || CRM_Core_Permission::check('access my cases and activities')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
     $scheduledInfo = array();
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         $isDeleted = FALSE;
         if ($result->case_deleted) {
             $isDeleted = TRUE;
             $row['case_status_id'] = empty($row['case_status_id']) ? "" : $row['case_status_id'] . '<br />(deleted)';
         }
         $scheduledInfo['case_id'][] = $result->case_id;
         $scheduledInfo['contact_id'][] = $result->contact_id;
         $scheduledInfo['case_deleted'] = $result->case_deleted;
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->case_id;
         $links = self::links($isDeleted, $this->_key);
         $row['action'] = CRM_Core_Action::formLink($links['primaryActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'case.selector.actions', 'Case', $result->case_id);
         $row['moreActions'] = CRM_Core_Action::formLink(CRM_Utils_Array::value('moreActions', $links), $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), TRUE, 'case.selector.moreActions', 'Case', $result->case_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         //adding case manager to case selector.CRM-4510.
         $caseType = CRM_Case_BAO_Case::getCaseType($result->case_id, 'name');
         $caseManagerContact = CRM_Case_BAO_Case::getCaseManagerContact($caseType, $result->case_id);
         if (!empty($caseManagerContact)) {
             $row['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $row['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
         if (isset($result->case_status_id) && array_key_exists($result->case_status_id, $caseStatus)) {
             $row['class'] = "status-urgent";
         } else {
             $row['class'] = "status-normal";
         }
         $rows[$result->case_id] = $row;
     }
     //retrive the scheduled & recent Activity type and date for selector
     if (!empty($scheduledInfo)) {
         $schdeduledActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'upcoming');
         foreach ($schdeduledActivity as $key => $value) {
             $rows[$key]['case_scheduled_activity_date'] = $value['date'];
             $rows[$key]['case_scheduled_activity_type'] = $value['type'];
         }
         $recentActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'recent');
         foreach ($recentActivity as $key => $value) {
             $rows[$key]['case_recent_activity_date'] = $value['date'];
             $rows[$key]['case_recent_activity_type'] = $value['type'];
         }
     }
     return $rows;
 }
示例#17
0
文件: Search.php 项目: kidaa30/yes
 /**
  * Returns all the rows in the given offset and rowCount     *
  *
  * @param string $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 string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_grantClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit grants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviGrant')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         if ($this->_context == 'search') {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->grant_id;
         }
         $row['action'] = CRM_Core_Action::formLink(self::links($this->_key), $mask, array('id' => $result->grant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'grant.selector.row', 'Grant', $result->grant_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);
         $rows[] = $row;
     }
     return $rows;
 }
示例#18
0
文件: Tab.php 项目: kidaa30/yes
 /**
  * called when action is browse.
  */
 public function browse()
 {
     $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     //$dao->orderBy('name');
     $dao->find();
     //CRM--4418, check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // get deceased status id
     $allStatus = CRM_Member_PseudoConstant::membershipStatus();
     $deceasedStatusId = array_search('Deceased', $allStatus);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //checks membership of contact itself
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //carry campaign.
         $membership[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (!empty($statusANDType[$dao->id]['is_current_member'])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         if (empty($dao->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($dao->status_id == $deceasedStatusId) {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isUpdateBilling = FALSE;
             $paymentObject = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($membership[$dao->id]['membership_id'], 'membership', 'obj');
             if (!empty($paymentObject)) {
                 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($membership[$dao->id]['membership_id']);
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('all', NULL, NULL, $isCancelSupported, $isUpdateBilling), $currentMask, array('id' => $dao->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'membership.tab.row', 'Membership', $dao->id);
         } else {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'membership.tab.row', 'Membership', $dao->id);
         }
         //does membership have auto renew CRM-7137.
         if (!empty($membership[$dao->id]['contribution_recur_id']) && !CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])) {
             $membership[$dao->id]['auto_renew'] = 1;
         } else {
             $membership[$dao->id]['auto_renew'] = 0;
         }
         // if relevant, count related memberships
         if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id]) && CRM_Utils_Array::value('relationship_type_id', $statusANDType[$dao->id]) && empty($dao->owner_membership_id)) {
             // not an related membership
             $query = "\n SELECT COUNT(m.id)\n   FROM civicrm_membership m\n     LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n     LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id\n  WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
             $num_related = CRM_Core_DAO::singleValueQuery($query);
             $max_related = CRM_Utils_Array::value('max_related', $membership[$dao->id]);
             $membership[$dao->id]['related_count'] = $max_related == '' ? ts('%1 created', array(1 => $num_related)) : ts('%1 out of %2', array(1 => $num_related, 2 => $max_related));
         } else {
             $membership[$dao->id]['related_count'] = ts('N/A');
         }
     }
     //Below code gives list of all Membership Types associated
     //with an Organization(CRM-2016)
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId);
     foreach ($membershipTypes as $key => $value) {
         $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), $mask, array('id' => $value['id'], 'cid' => $this->_contactId), ts('more'), FALSE, 'membershipType.organization.action', 'MembershipType', $value['id']);
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
     $this->assign('membershipTypes', $membershipTypes);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
         $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
         // Refresh other tabs with related data
         $this->ajaxResponse['updateTabs'] = array('#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), '#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId));
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
         }
     }
 }
示例#19
0
 /**
  * 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)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     require_once 'CRM/Event/BAO/Participant.php';
     require_once 'CRM/Contact/BAO/Contact/Utils.php';
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = null;
     if ($this->_context != 'contribute') {
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, null, false, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', false, false, false, null, 'name', false);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (Pay Later)';
         } else {
             if (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
                 $row['contribution_status'] .= ' (Incomplete Transaction)';
             }
         }
         if ($row['is_test']) {
             $row['contribution_type'] = $row['contribution_type'] . ' (test)';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink(self::links($componentId, $componentAction, $qfKey, $componentContext), $mask, $actions);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, false, $result->contact_id);
         if (CRM_Utils_Array::value('amount_level', $row)) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }
示例#20
0
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     //$dao->orderBy('name');
     $dao->find();
     //CRM--4418, check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // get deceased status id
     $allStatus = CRM_Member_PseudoConstant::membershipStatus();
     $deceasedStatusId = array_search('Deceased', $allStatus);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //checks membership of contact itself
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //carry campaign.
         $membership[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         if (empty($dao->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($dao->status_id == $deceasedStatusId) {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isUpdateBilling = false;
             $paymentObject = CRM_Core_BAO_PaymentProcessor::getProcessorForEntity($membership[$dao->id]['membership_id'], 'membership', 'obj');
             if (!empty($paymentObject)) {
                 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($membership[$dao->id]['membership_id']);
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('all', NULL, NULL, $isCancelSupported, $isUpdateBilling), $currentMask, array('id' => $dao->id, 'cid' => $this->_contactId));
         } else {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId));
         }
         //does membership have auto renew CRM-7137.
         if (CRM_Utils_Array::value('contribution_recur_id', $membership[$dao->id]) && !CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])) {
             $membership[$dao->id]['auto_renew'] = 1;
         } else {
             $membership[$dao->id]['auto_renew'] = 0;
         }
     }
     //Below code gives list of all Membership Types associated
     //with an Organization(CRM-2016)
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId);
     foreach ($membershipTypes as $key => $value) {
         $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), $mask, array('id' => $value['id'], 'cid' => $this->_contactId));
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
     $this->assign('membershipTypes', $membershipTypes);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
     }
 }
示例#21
0
 /**
  * Wrapper for contact relationship selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of contact relationships
  */
 public static function getContactRelationshipSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     if ($params['context'] == 'past') {
         $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE;
     } elseif ($params['context'] == 'all') {
         $relationshipStatus = CRM_Contact_BAO_Relationship::ALL;
     } else {
         $relationshipStatus = CRM_Contact_BAO_Relationship::CURRENT;
     }
     // check logged in user for permission
     $page = new CRM_Core_Page();
     CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
     $permissions = array($page->_permission);
     if ($page->_permission == CRM_Core_Permission::EDIT) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $permissionedContacts = TRUE;
     if ($params['context'] != 'user') {
         $links = CRM_Contact_Page_View_Relationship::links();
     } else {
         $links = CRM_Contact_Page_View_UserDashBoard::links();
         $mask = NULL;
     }
     // get contact relationships
     $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, $params['rp'], 0, 0, $links, $mask, $permissionedContacts, $params);
     $contactRelationships = array();
     $params['total'] = 0;
     if (!empty($relationships)) {
         // FIXME: we cannot directly determine total permissioned relationship, hence re-fire query
         $permissionedRelationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, 0, 0, 0, NULL, NULL, $permissionedContacts);
         $params['total'] = count($permissionedRelationships);
         // format params
         foreach ($relationships as $relationshipId => $values) {
             $relationship = array();
             $relationship['DT_RowId'] = $values['id'];
             $relationship['DT_RowClass'] = 'crm-entity';
             if ($values['is_active'] == 0) {
                 $relationship['DT_RowClass'] .= ' disabled';
             }
             $relationship['DT_RowAttr'] = array();
             $relationship['DT_RowAttr']['data-entity'] = 'relationship';
             $relationship['DT_RowAttr']['data-id'] = $values['id'];
             //Add image icon for related contacts: CRM-14919
             $icon = CRM_Contact_BAO_Contact_Utils::getImage($values['contact_type'], FALSE, $values['cid']);
             $relationship['sort_name'] = $icon . ' ' . CRM_Utils_System::href($values['name'], 'civicrm/contact/view', "reset=1&cid={$values['cid']}");
             $relationship['relation'] = CRM_Utils_System::href($values['relation'], 'civicrm/contact/view/rel', "action=view&reset=1&cid={$values['cid']}&id={$values['id']}&rtype={$values['rtype']}");
             if ($params['context'] == 'current') {
                 if ($params['contact_id'] == $values['contact_id_a'] and $values['is_permission_a_b'] == 1 or $params['contact_id'] == $values['contact_id_b'] and $values['is_permission_b_a'] == 1) {
                     $relationship['sort_name'] .= '<span id="permission-a-b" class="crm-marker permission-relationship"> *</span>';
                 }
                 if ($values['cid'] == $values['contact_id_a'] and $values['is_permission_a_b'] == 1 or $values['cid'] == $values['contact_id_b'] and $values['is_permission_b_a'] == 1) {
                     $relationship['relation'] .= '<span id="permission-b-a" class="crm-marker permission-relationship"> *</span>';
                 }
             }
             if (!empty($values['description'])) {
                 $relationship['relation'] .= "<p class='description'>{$values['description']}</p>";
             }
             $relationship['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
             $relationship['end_date'] = CRM_Utils_Date::customFormat($values['end_date']);
             $relationship['city'] = $values['city'];
             $relationship['state'] = $values['state'];
             $relationship['email'] = $values['email'];
             $relationship['phone'] = $values['phone'];
             $relationship['links'] = $values['action'];
             array_push($contactRelationships, $relationship);
         }
     }
     $relationshipsDT = array();
     $relationshipsDT['data'] = $contactRelationships;
     $relationshipsDT['recordsTotal'] = $params['total'];
     $relationshipsDT['recordsFiltered'] = $params['total'];
     return $relationshipsDT;
 }
示例#22
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $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 string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     if ($this->_includeSoftCredits) {
         // especial sort order when rows include soft credits
         $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id";
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = NULL;
     if ($this->_context != 'contribute') {
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $links = self::links($componentId, $componentAction, $qfKey, $componentContext);
         $checkLineItem = FALSE;
         $row = array();
         // Now check for lineItems
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
             $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id);
             foreach ($lineItems as $items) {
                 if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     $checkLineItem = TRUE;
                     break;
                 }
                 if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::UPDATE]);
                 }
                 if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::DELETE]);
                 }
             }
             if ($checkLineItem) {
                 continue;
             }
             if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::UPDATE]);
             }
             if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::DELETE]);
             }
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->contribution_campaign_id;
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
         } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
         }
         if ($row['is_test']) {
             $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_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);
         if (!empty($row['amount_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }
示例#23
0
 /**
  * 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)
 {
     // check if we can process credit card registration
     $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
     if (count($processors) > 0) {
         $this->_isPaymentProcessor = TRUE;
     } else {
         $this->_isPaymentProcessor = FALSE;
     }
     // Only show credit card membership signup and renewal if user has CiviContribute permission
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_accessContribution = TRUE;
     } else {
         $this->_accessContribution = FALSE;
     }
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->member_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->member_campaign_id;
         if (!empty($row['member_is_test'])) {
             $row['membership_type'] = $row['membership_type'] . " (test)";
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id;
         if (!isset($result->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($result->membership_status == 'Deceased') {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']);
             $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported), $currentMask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         } else {
             $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         }
         //does membership have auto renew CRM-7137.
         $autoRenew = FALSE;
         if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id'])) {
             $autoRenew = TRUE;
         }
         $row['auto_renew'] = $autoRenew;
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
示例#24
0
 /**
  * Browse all saved searches.
  *
  * @return content of the parents run method
  *
  */
 function browse()
 {
     $rows = array();
     $savedSearch =& new CRM_Contact_DAO_SavedSearch();
     $savedSearch->is_active = 1;
     $savedSearch->selectAdd();
     $savedSearch->selectAdd('id, form_values');
     $savedSearch->find();
     $properties = array('id', 'name', 'description');
     while ($savedSearch->fetch()) {
         // get name and description from group object
         $group =& new CRM_Contact_DAO_Group();
         $group->saved_search_id = $savedSearch->id;
         if ($group->find(true)) {
             $permissions = CRM_Group_Page_Group::checkPermission($group->id, $group->title);
             if (!CRM_Utils_System::isNull($permissions)) {
                 $row = array();
                 $row['name'] = $group->title;
                 $row['description'] = $group->description;
                 $row['id'] = $savedSearch->id;
                 $formValues = unserialize($savedSearch->form_values);
                 $query =& new CRM_Contact_BAO_Query($formValues);
                 $row['query_detail'] = $query->qill();
                 $action = array_sum(array_keys(self::links()));
                 $action = $action & CRM_Core_Action::mask($permissions);
                 $row['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $row['id']));
                 $rows[] = $row;
             }
         }
     }
     $this->assign('rows', $rows);
     return parent::run();
 }
示例#25
0
 /**
  * Wrapper for ajax activity selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   Associated array of contact activities
  */
 public static function getContactActivitySelector(&$params)
 {
     // Format the params.
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['caseId'] = NULL;
     $context = CRM_Utils_Array::value('context', $params);
     // Get contact activities.
     $activities = CRM_Activity_BAO_Activity::getActivities($params);
     // Add total.
     $params['total'] = CRM_Activity_BAO_Activity::getActivitiesCount($params);
     // Format params and add links.
     $contactActivities = array();
     if (!empty($activities)) {
         $activityStatus = CRM_Core_PseudoConstant::activityStatus();
         // Check logged in user for permission.
         $page = new CRM_Core_Page();
         CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
         $permissions = array($page->_permission);
         if (CRM_Core_Permission::check('delete activities')) {
             $permissions[] = CRM_Core_Permission::DELETE;
         }
         $mask = CRM_Core_Action::mask($permissions);
         foreach ($activities as $activityId => $values) {
             $activity = array();
             $activity['DT_RowId'] = $activityId;
             // Add class to this row if overdue.
             $activity['DT_RowClass'] = 'crm-entity';
             if (CRM_Utils_Date::overdue(CRM_Utils_Array::value('activity_date_time', $values)) && CRM_Utils_Array::value('status_id', $values) == 1) {
                 $activity['DT_RowClass'] .= ' status-overdue';
             } else {
                 $activity['DT_RowClass'] .= ' status-ontime';
             }
             $activity['DT_RowAttr'] = array();
             $activity['DT_RowAttr']['data-entity'] = 'activity';
             $activity['DT_RowAttr']['data-id'] = $activityId;
             $activity['activity_type'] = $values['activity_type'];
             $activity['subject'] = $values['subject'];
             $activity['source_contact_name'] = '';
             if ($params['contact_id'] == $values['source_contact_id']) {
                 $activity['source_contact_name'] = $values['source_contact_name'];
             } elseif ($values['source_contact_id']) {
                 $activity['source_contact_name'] = CRM_Utils_System::href($values['source_contact_name'], 'civicrm/contact/view', "reset=1&cid={$values['source_contact_id']}");
             } else {
                 $activity['source_contact_name'] = '<em>n/a</em>';
             }
             $activity['target_contact_name'] = '';
             if (isset($values['mailingId']) && !empty($values['mailingId'])) {
                 $activity['target_contact'] = CRM_Utils_System::href($values['recipients'], 'civicrm/mailing/report/event', "mid={$values['source_record_id']}&reset=1&event=queue&cid={$params['contact_id']}&context=activitySelector");
             } elseif (!empty($values['recipients'])) {
                 $activity['target_contact_name'] = $values['recipients'];
             } elseif (isset($values['target_contact_counter']) && $values['target_contact_counter']) {
                 $activity['target_contact_name'] = '';
                 foreach ($values['target_contact_name'] as $tcID => $tcName) {
                     $activity['target_contact_name'] .= CRM_Utils_System::href($tcName, 'civicrm/contact/view', "reset=1&cid={$tcID}");
                 }
                 if ($extraCount = $values['target_contact_counter'] - 1) {
                     $activity['target_contact_name'] .= ";<br />" . "(" . ts('%1 more', array(1 => $extraCount)) . ")";
                 }
             } elseif (!$values['target_contact_name']) {
                 $activity['target_contact_name'] = '<em>n/a</em>';
             }
             $activity['assignee_contact_name'] = '';
             if (empty($values['assignee_contact_name'])) {
                 $activity['assignee_contact_name'] = '<em>n/a</em>';
             } elseif (!empty($values['assignee_contact_name'])) {
                 $count = 0;
                 $activity['assignee_contact_name'] = '';
                 foreach ($values['assignee_contact_name'] as $acID => $acName) {
                     if ($acID && $count < 5) {
                         $activity['assignee_contact_name'] .= CRM_Utils_System::href($acName, 'civicrm/contact/view', "reset=1&cid={$acID}");
                         $count++;
                         if ($count) {
                             $activity['assignee_contact_name'] .= ";&nbsp;";
                         }
                         if ($count == 4) {
                             $activity['assignee_contact_name'] .= "(" . ts('more') . ")";
                             break;
                         }
                     }
                 }
             }
             $activity['activity_date_time'] = CRM_Utils_Date::customFormat($values['activity_date_time']);
             $activity['status_id'] = $activityStatus[$values['status_id']];
             // build links
             $activity['links'] = '';
             $accessMailingReport = FALSE;
             if (!empty($values['mailingId'])) {
                 $accessMailingReport = TRUE;
             }
             $actionLinks = CRM_Activity_Selector_Activity::actionLinks(CRM_Utils_Array::value('activity_type_id', $values), CRM_Utils_Array::value('source_record_id', $values), $accessMailingReport, CRM_Utils_Array::value('activity_id', $values));
             $actionMask = array_sum(array_keys($actionLinks)) & $mask;
             $activity['links'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('id' => $values['activity_id'], 'cid' => $params['contact_id'], 'cxt' => $context, 'caseid' => CRM_Utils_Array::value('case_id', $values)), ts('more'), FALSE, 'activity.tab.row', 'Activity', $values['activity_id']);
             if ($values['is_recurring_activity']) {
                 $activity['is_recurring_activity'] = CRM_Core_BAO_RecurringEntity::getPositionAndCount($values['activity_id'], 'civicrm_activity');
             }
             array_push($contactActivities, $activity);
         }
     }
     $activitiesDT = array();
     $activitiesDT['data'] = $contactActivities;
     $activitiesDT['recordsTotal'] = $params['total'];
     $activitiesDT['recordsFiltered'] = $params['total'];
     return $activitiesDT;
 }
示例#26
0
 /**
  * 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)
 {
     $multipleFields = array('url');
     //$sort object processing for location fields
     if ($sort) {
         $vars = $sort->_vars;
         $varArray = array();
         foreach ($vars as $key => $field) {
             $field = $vars[$key];
             $fieldArray = explode('-', $field['name']);
             $fieldType = CRM_Utils_Array::value('2', $fieldArray);
             if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) {
                 if (!in_array($fieldType, $multipleFields)) {
                     $locationType = new CRM_Core_DAO_LocationType();
                     $locationType->id = $fieldArray[1];
                     $locationType->find(TRUE);
                     if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`";
                     } else {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`";
                     }
                 } else {
                     $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`";
                 }
             }
             $varArray[$key] = $field;
         }
         $sort->_vars = $varArray;
     }
     $additionalWhereClause = 'contact_a.is_deleted = 0';
     $returnQuery = NULL;
     if ($this->_multiRecordTableName) {
         $returnQuery = TRUE;
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, NULL, NULL, $returnQuery, $additionalWhereClause);
     if ($returnQuery) {
         $resQuery = preg_replace('/GROUP BY contact_a.id[\\s]+ORDER BY/', ' ORDER BY', $result);
         $result = CRM_Core_DAO::executeQuery($resQuery);
     }
     // process the result of the query
     $rows = array();
     // check if edit is configured in profile settings
     if ($this->_gid) {
         $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link');
     }
     //FIXME : make sure to handle delete separately. CRM-4418
     $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission()));
     if ($editLink && $mask & CRM_Core_Permission::EDIT) {
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config = CRM_Core_Config::singleton();
         if (!$config->userFrameworkFrontend) {
             $this->_editLink = TRUE;
         }
     }
     $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds);
     $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) {
         // skip pseudo fields
         if (substr($key, 0, 9) == 'phone_ext') {
             continue;
         }
         if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
             if (strpos($key, '-') !== FALSE) {
                 $value = explode('-', $key);
                 $fieldName = CRM_Utils_Array::value(0, $value);
                 $id = CRM_Utils_Array::value(1, $value);
                 $type = CRM_Utils_Array::value(2, $value);
                 if (!in_array($fieldName, $multipleFields)) {
                     $locationTypeName = NULL;
                     if (is_numeric($id)) {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                     } else {
                         if ($id == 'Primary') {
                             $locationTypeName = 1;
                         }
                     }
                     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[] = "website-{$id}-{$fieldName}";
                 }
             } elseif ($field['name'] == 'id') {
                 $names[] = 'contact_id';
             } else {
                 $names[] = $field['name'];
             }
         }
     }
     $multipleSelectFields = array('preferred_communication_method' => 1);
     $multiRecordTableId = NULL;
     if ($this->_multiRecordTableName) {
         $multiRecordTableId = "{$this->_multiRecordTableName}_id";
     }
     // we need to determine of overlay profile should be shown
     $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile();
     while ($result->fetch()) {
         $this->_query->convertToPseudoNames($result);
         if (isset($result->country)) {
             // the query returns the untranslated country name
             $i18n = CRM_Core_I18n::singleton();
             $result->country = $i18n->translate($result->country);
         }
         $row = array();
         $empty = TRUE;
         $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id, $showProfileOverlay);
         if ($result->sort_name) {
             $row[] = $result->sort_name;
             $empty = FALSE;
         } else {
             continue;
         }
         foreach ($names as $name) {
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id);
             } elseif (substr($name, -4) == '-url' && !empty($result->{$name})) {
                 $url = CRM_Utils_System::fixURL($result->{$name});
                 $typeId = substr($name, 0, -4) . "-website_type_id";
                 $typeName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Website', 'website_type_id', $result->{$typeId});
                 if ($typeName) {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}} ({$typeName})</a>";
                 } else {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>";
                 }
             } elseif ($name == 'preferred_language') {
                 $row[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $result->{$name});
             } elseif ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) {
                 $paramsNew = array($name => $result->{$name});
                 $name = array($name => array('newName' => $name, 'groupName' => $name));
                 CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE);
                 $row[] = $paramsNew[$key];
             } elseif (strpos($name, '-im')) {
                 if (!empty($result->{$name})) {
                     $providerId = $name . "-provider_id";
                     $providerName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $result->{$providerId});
                     $row[] = $result->{$name} . " ({$providerName})";
                 } else {
                     $row[] = '';
                 }
             } elseif (strpos($name, '-phone-')) {
                 $phoneExtField = str_replace('phone', 'phone_ext', $name);
                 if (isset($result->{$phoneExtField})) {
                     $row[] = $result->{$name} . " (" . $result->{$phoneExtField} . ")";
                 } else {
                     $row[] = $result->{$name};
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $dname = $name . '_display';
                 $row[] = $result->{$dname};
             } elseif (in_array($name, array('birth_date', 'deceased_date'))) {
                 $row[] = CRM_Utils_Date::customFormat($result->{$name});
             } elseif (isset($result->{$name})) {
                 $row[] = $result->{$name};
             } else {
                 $row[] = '';
             }
             if (!empty($result->{$name})) {
                 $empty = FALSE;
             }
         }
         $newLinks = $links;
         $params = array('id' => $result->contact_id, 'gid' => implode(',', $this->_profileIds));
         // pass record id param to view url for multi record view
         if ($multiRecordTableId && $newLinks) {
             if ($result->{$multiRecordTableId}) {
                 if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') {
                     $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1";
                     $params['recordId'] = $result->{$multiRecordTableId};
                 }
             }
         }
         if ($this->_linkToUF) {
             $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id);
             if (!$ufID) {
                 unset($newLinks[CRM_Core_Action::PROFILE]);
             } else {
                 $params['ufID'] = $ufID;
             }
         }
         $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params, ts('more'), FALSE, 'profile.selector.row', 'Contact', $result->contact_id);
         if (!$empty) {
             $rows[] = $row;
         }
     }
     return $rows;
 }
示例#27
0
 /**
  * @param $rows
  */
 function addActions(&$rows)
 {
     $config = CRM_Core_Config::singleton();
     $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;
     // mask value to hide map link if there are not lat/long
     $mapMask = $mask & 4095;
     $links = self::links($this->_context, $this->_contextMenu, $this->_key);
     foreach ($rows as $id => &$row) {
         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' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['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' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['contact_id']);
         } else {
             $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['contact_id']);
         }
         // allow components to add more actions
         CRM_Core_Component::searchAction($row, $row['contact_id']);
         if (!empty($row['contact_type_orig'])) {
             $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($row['contact_type_orig'], FALSE, $row['contact_id']);
         }
     }
 }
示例#28
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;
 }
示例#29
0
 /**
  * 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;
 }
示例#30
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $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 string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     if ($this->_includeSoftCredits) {
         // especial sort order when rows include soft credits
         $sort = $sort->orderBy() . ", civicrm_contribution.id, civicrm_contribution_soft.id";
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = NULL;
     if ($this->_context != 'contribute') {
         // @todo explain the significance of context & why we do not get these i that context.
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             // @todo explain when this condition might occur.
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
         // CRM-17628 for some reason qfKey is not always set when searching from contribution search.
         // as a result if the edit link is opened using right-click + open in new tab
         // then the browser is not returned to the search results on save.
         // This is an effort to getting the qfKey without, sadly, understanding the intent of those who came before me.
         if (empty($qfKey)) {
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $links = self::links($componentId, $componentAction, $qfKey, $componentContext);
         $checkLineItem = FALSE;
         $row = array();
         // Now check for lineItems
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
             $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id);
             foreach ($lineItems as $items) {
                 if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     $checkLineItem = TRUE;
                     break;
                 }
                 if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::UPDATE]);
                 }
                 if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::DELETE]);
                 }
             }
             if ($checkLineItem) {
                 continue;
             }
             if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::UPDATE]);
             }
             if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::DELETE]);
             }
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         // @todo - I can't find any evidence that 'carrying' the campaign on selectors actually
         // results in it being displayed anywhere so why do we do this???
         $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->contribution_campaign_id;
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
             $links[CRM_Core_Action::ADD] = array('name' => ts('Pay with Credit Card'), 'url' => 'civicrm/contact/view/contribution', 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&mode=live', 'title' => ts('Pay with Credit Card'));
         } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
         }
         if ($row['is_test']) {
             $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_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);
         if (!empty($row['amount_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }