コード例 #1
0
 /**
  * Get action Links
  *
  * @return array (reference) of action links
  */
 function &links()
 {
     if (!self::$_links) {
         // helper variable for nicer formatting
         $links = array();
         $view = array_search(CRM_Core_Action::VIEW, CRM_Core_Action::$_names);
         $update = array_search(CRM_Core_Action::UPDATE, CRM_Core_Action::$_names);
         $delete = array_search(CRM_Core_Action::DELETE, CRM_Core_Action::$_names);
         $links[CRM_Core_Action::VIEW] = array('name' => ts('View'), 'url' => 'civicrm/profile/view', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('View %1', array(1 => $this->_customGroupTitle . ' record')));
         $links[CRM_Core_Action::UPDATE] = array('name' => ts('Edit'), 'url' => 'civicrm/profile/edit', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('Edit %1', array(1 => $this->_customGroupTitle . ' record')));
         $links[CRM_Core_Action::DELETE] = array('name' => ts('Delete'), 'url' => 'civicrm/profile/edit', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('Delete %1', array(1 => $this->_customGroupTitle . ' record')));
         self::$_links = $links;
     }
     return self::$_links;
 }
コード例 #2
0
ファイル: AJAX.php プロジェクト: kcristiano/civicrm-core
 /**
  * Get list of Multi Record Fields.
  *
  */
 public static function getMultiRecordFieldList()
 {
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
     $params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
     $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
     $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
     $obj->_pageViewType = 'customDataView';
     $obj->_contactId = $params['cid'];
     $obj->_customGroupId = $params['cgid'];
     $obj->_contactType = $contactType;
     $obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
     $obj->_DTparams['rowCount'] = $params['rp'];
     if (!empty($params['sortBy'])) {
         $obj->_DTparams['sort'] = $params['sortBy'];
     }
     list($fields, $attributes) = $obj->browse();
     // format params and add class attributes
     $fieldList = array();
     foreach ($fields as $id => $value) {
         $field = array();
         foreach ($value as $fieldId => &$fieldName) {
             if (!empty($attributes[$fieldId][$id]['class'])) {
                 $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
             }
             if (is_numeric($fieldId)) {
                 $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
                 CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
             }
         }
         $field = $value;
         array_push($fieldList, $field);
     }
     $totalRecords = !empty($obj->_total) ? $obj->_total : 0;
     $multiRecordFields = array();
     $multiRecordFields['data'] = $fieldList;
     $multiRecordFields['recordsTotal'] = $totalRecords;
     $multiRecordFields['recordsFiltered'] = $totalRecords;
     if (!empty($_GET['is_unit_test'])) {
         return $multiRecordFields;
     }
     CRM_Utils_JSON::output($multiRecordFields);
 }
コード例 #3
0
ファイル: Form.php プロジェクト: hyebahi/civicrm-core
 /**
  * Pre processing work done here.
  *
  * gets session variables for table name, id of entity in table, type of entity and stores them.
  *
  * @param
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_id = $this->get('id');
     $this->_profileIds = $this->get('profileIds');
     $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     //unset from session when $_GET doesn't have it
     //except when the form is submitted
     if (empty($_POST)) {
         if (!array_key_exists('multiRecord', $_GET)) {
             $this->set('multiRecord', NULL);
         }
         if (!array_key_exists('recordId', $_GET)) {
             $this->set('recordId', NULL);
         }
     }
     $this->_session = CRM_Core_Session::singleton();
     $this->_currentUserID = $this->_session->get('userID');
     if ($this->_mode == self::MODE_EDIT) {
         //specifies the action being done on a multi record field
         $multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this);
         $this->_multiRecord = !is_numeric($multiRecordAction) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
         if ($this->_multiRecord) {
             $this->set('multiRecord', $this->_multiRecord);
         }
         if ($this->_multiRecord && !in_array($this->_multiRecord, array(CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE))) {
             CRM_Core_Error::fatal(ts('Proper action not specified for this custom value record profile'));
         }
     }
     $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
     $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0));
     if (count($gids) > 1 && !$this->_profileIds && empty($this->_profileIds)) {
         if (!empty($gids)) {
             foreach ($gids as $pfId) {
                 $this->_profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
             }
         }
         // check if we are rendering mixed profiles
         if (CRM_Core_BAO_UFGroup::checkForMixProfiles($this->_profileIds)) {
             CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.'));
         }
         // for now consider 1'st profile as primary profile and validate it
         // i.e check for profile type etc.
         // FIX ME: validations for other than primary
         $this->_gid = $this->_profileIds[0];
         $this->set('gid', $this->_gid);
         $this->set('profileIds', $this->_profileIds);
     }
     if (!$this->_gid) {
         $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
         $this->set('gid', $this->_gid);
     }
     $this->_activityId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0, 'GET');
     if (is_numeric($this->_activityId)) {
         $latestRevisionId = CRM_Activity_BAO_Activity::getLatestActivityId($this->_activityId);
         if ($latestRevisionId) {
             $this->_activityId = $latestRevisionId;
         }
     }
     $this->_isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($this->_gid);
     //get values for ufGroupName, captch and dupe update.
     if ($this->_gid) {
         $dao = new CRM_Core_DAO_UFGroup();
         $dao->id = $this->_gid;
         if ($dao->find(TRUE)) {
             $this->_isUpdateDupe = $dao->is_update_dupe;
             $this->_isAddCaptcha = $dao->add_captcha;
             $this->_ufGroup = (array) $dao;
         }
         $dao->free();
         if (!CRM_Utils_Array::value('is_active', $this->_ufGroup)) {
             CRM_Core_Error::fatal(ts('The requested profile (gid=%1) is inactive or does not exist.', array(1 => $this->_gid)));
         }
     }
     $this->assign('ufGroupName', $this->_ufGroup['name']);
     $gids = empty($this->_profileIds) ? $this->_gid : $this->_profileIds;
     // if we dont have a gid use the default, else just use that specific gid
     if (($this->_mode == self::MODE_REGISTER || $this->_mode == self::MODE_CREATE) && !$this->_gid) {
         $this->_ctype = CRM_Utils_Request::retrieve('ctype', 'String', $this, FALSE, 'Individual', 'REQUEST');
         $this->_fields = CRM_Core_BAO_UFGroup::getRegistrationFields($this->_action, $this->_mode, $this->_ctype);
     } elseif ($this->_mode == self::MODE_SEARCH) {
         $this->_fields = CRM_Core_BAO_UFGroup::getListingFields($this->_action, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $gids, TRUE, NULL, $this->_skipPermission, CRM_Core_Permission::SEARCH);
     } else {
         $this->_fields = CRM_Core_BAO_UFGroup::getFields($gids, FALSE, NULL, NULL, NULL, FALSE, NULL, $this->_skipPermission, NULL, $this->_action == CRM_Core_Action::ADD ? CRM_Core_Permission::CREATE : CRM_Core_Permission::EDIT);
         $multiRecordFieldListing = FALSE;
         //using selector for listing of multirecord fields
         if ($this->_mode == self::MODE_EDIT && $this->_gid) {
             CRM_Core_BAO_UFGroup::shiftMultiRecordFields($this->_fields, $this->_multiRecordFields);
             if ($this->_multiRecord) {
                 if ($this->_multiRecord != CRM_Core_Action::ADD) {
                     $this->_recordId = CRM_Utils_Request::retrieve('recordId', 'Positive', $this);
                 } else {
                     $this->_recordId = NULL;
                     $this->set('recordId', NULL);
                 }
                 //record id is necessary for _multiRecord view and update/edit action
                 if (!$this->_recordId && ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE)) {
                     CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) requires record id while performing this action', array(1 => $this->_gid)));
                 } elseif (empty($this->_multiRecordFields)) {
                     CRM_Core_Error::fatal(ts('No Multi-Record Fields configured for this profile (gid=%1)', array(1 => $this->_gid)));
                 }
                 $fieldId = CRM_Core_BAO_CustomField::getKeyID(key($this->_multiRecordFields));
                 $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId));
                 $this->_customGroupTitle = $customGroupDetails[$fieldId]['groupTitle'];
                 $this->_customGroupId = $customGroupDetails[$fieldId]['groupID'];
                 if ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE) {
                     //record exists check
                     foreach ($this->_multiRecordFields as $key => $field) {
                         $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
                     }
                     $getValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
                     if (array_key_exists($this->_recordId, $getValues)) {
                         $this->_recordExists = TRUE;
                     } else {
                         $this->_recordExists = FALSE;
                         if ($this->_multiRecord & CRM_Core_Action::UPDATE) {
                             CRM_Core_Session::setStatus(ts('Note: The record %1 doesnot exists. Upon save a new record will be create', array(1 => $this->_recordId)), ts('Record doesnot exist'), 'alert');
                         }
                     }
                 }
                 if ($this->_multiRecord & CRM_Core_Action::ADD) {
                     $this->_maxRecordLimit = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupDetails[$fieldId]['groupID'], $this->_id);
                     if ($this->_maxRecordLimit) {
                         CRM_Core_Session::setStatus(ts('You cannot add a new record as  maximum allowed limit is reached'), ts('Sorry'), 'error');
                     }
                 }
             } elseif (!empty($this->_multiRecordFields) && (!$this->_multiRecord || !in_array($this->_multiRecord, array(CRM_Core_Action::DELETE, CRM_Core_Action::UPDATE)))) {
                 CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
                 //multirecord listing page
                 $multiRecordFieldListing = TRUE;
                 $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
                 $cs = $this->get('cs');
                 $page->set('pageCheckSum', $cs);
                 $page->set('contactId', $this->_id);
                 $page->set('profileId', $this->_gid);
                 $page->set('action', CRM_Core_Action::BROWSE);
                 $page->set('multiRecordFieldListing', $multiRecordFieldListing);
                 $page->run();
             }
         }
         $this->assign('multiRecordFieldListing', $multiRecordFieldListing);
         // is profile double-opt in?
         if (!empty($this->_fields['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) {
             $emailField = FALSE;
             foreach ($this->_fields as $name => $values) {
                 if (substr($name, 0, 6) == 'email-') {
                     $emailField = TRUE;
                 }
             }
             if (!$emailField) {
                 $status = ts("Email field should be included in profile if you want to use Group(s) when Profile double-opt in process is enabled.");
                 $this->_session->setStatus($status);
             }
         }
         //transferring all the multi-record custom fields in _fields
         if ($this->_multiRecord && !empty($this->_multiRecordFields)) {
             $this->_fields = $this->_multiRecordFields;
             $this->_multiRecordProfile = TRUE;
         } elseif ($this->_multiRecord && empty($this->_multiRecordFields)) {
             CRM_Core_Session::setStatus(ts('This feature is not currently available.'), ts('Sorry'), 'error');
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1'));
         }
     }
     if (!is_array($this->_fields)) {
         CRM_Core_Session::setStatus(ts('This feature is not currently available.'), ts('Sorry'), 'error');
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1'));
     }
 }
コード例 #4
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  *
  * @return void
  */
 public function run()
 {
     $this->preProcess();
     //set the userContext stack
     $doneURL = 'civicrm/contact/view';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
     // get permission detail view or edit
     // use a comtact id specific function which gives us much better granularity
     // CRM-12646
     $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
     $this->assign('editCustomData', $editCustomData);
     //allow to edit own customdata CRM-5518
     $editOwnCustomData = FALSE;
     if ($session->get('userID') == $this->_contactId) {
         $editOwnCustomData = TRUE;
     }
     $this->assign('editOwnCustomData', $editOwnCustomData);
     if ($this->_action == CRM_Core_Action::BROWSE) {
         //Custom Groups Inline
         $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
         $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType);
         $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'style');
         if ($this->_multiRecordDisplay != 'single') {
             $id = "custom_{$this->_groupId}";
             $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
         }
         if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
             $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
             $this->assign('displayStyle', 'tableOriented');
             // here the multi custom data listing code will go
             $multiRecordFieldListing = TRUE;
             $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
             $page->set('contactId', $this->_contactId);
             $page->set('customGroupId', $this->_groupId);
             $page->set('action', CRM_Core_Action::BROWSE);
             $page->set('multiRecordFieldListing', $multiRecordFieldListing);
             $page->set('pageViewType', 'customDataView');
             $page->set('contactType', $ctype);
             $page->run();
         } else {
             $recId = NULL;
             if ($this->_multiRecordDisplay == 'single') {
                 $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
                 CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
                 $recId = $this->_recId;
                 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
                 $this->assign('skipTitle', 1);
             }
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
         }
     } else {
         $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action);
         $controller->setEmbedded(TRUE);
         $controller->set('tableId', $this->_contactId);
         $controller->set('groupId', $this->_groupId);
         $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
         $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
         $controller->process();
         $controller->run();
     }
     return parent::run();
 }
コード例 #5
0
ファイル: AJAX.php プロジェクト: konadave/civicrm-core
 /**
  * Get list of Multi Record Fields.
  *
  */
 public static function getMultiRecordFieldList()
 {
     $params = $_GET;
     $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
     $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 10;
     $sortMapper = array();
     foreach ($_GET['columns'] as $key => $value) {
         $sortMapper[$key] = $value['data'];
     }
     $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
     $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
     $obj->_pageViewType = 'customDataView';
     $obj->_contactId = $params['cid'];
     $obj->_customGroupId = $params['cgid'];
     $obj->_contactType = $contactType;
     $obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
     $obj->_DTparams['rowCount'] = $params['rp'];
     if ($sort && $sortOrder) {
         $sort = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $sort, 'column_name', 'label');
         $obj->_DTparams['sort'] = $sort . ' ' . $sortOrder;
     }
     list($fields, $attributes) = $obj->browse();
     // format params and add class attributes
     $fieldList = array();
     foreach ($fields as $id => $value) {
         $field = array();
         foreach ($value as $fieldId => &$fieldName) {
             if (!empty($attributes[$fieldId][$id]['class'])) {
                 $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
             }
             if (is_numeric($fieldId)) {
                 $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'label');
                 CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
             }
         }
         $field = $value;
         array_push($fieldList, $field);
     }
     $totalRecords = !empty($obj->_total) ? $obj->_total : 0;
     $multiRecordFields = array();
     $multiRecordFields['data'] = $fieldList;
     $multiRecordFields['recordsTotal'] = $totalRecords;
     $multiRecordFields['recordsFiltered'] = $totalRecords;
     CRM_Utils_JSON::output($multiRecordFields);
 }