コード例 #1
0
ファイル: ApiRouter.php プロジェクト: rameshrr99/civicrm-core
 /**
  * @param array $cxn
  * @param string $entity
  * @param string $action
  * @param array $params
  * @return mixed
  */
 public static function route($cxn, $entity, $action, $params)
 {
     $SUPER_PERM = array('administer CiviCRM');
     require_once 'api/v3/utils.php';
     // FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()?
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') {
         return civicrm_api3_create_error('System policy requires HTTPS.');
     }
     // Note: $cxn and cxnId are authenticated before router is called.
     $dao = new CRM_Cxn_DAO_Cxn();
     $dao->cxn_id = $cxn['cxnId'];
     if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) {
         return civicrm_api3_create_error('Failed to lookup connection authorizations.');
     }
     if (!$dao->is_active) {
         return civicrm_api3_create_error('Connection is inactive.');
     }
     if (!is_string($entity) || !is_string($action) || !is_array($params)) {
         return civicrm_api3_create_error('API parameters are malformed.');
     }
     if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) {
         return civicrm_api3_create_error('Connection has no permissions.');
     }
     $whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
     \Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
     CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
     if ($cxn['perm']['grant'] === '*') {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM);
     } else {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']);
     }
     $params['check_permissions'] = 'whitelist';
     return civicrm_api($entity, $action, $params);
 }
コード例 #2
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:k:pre";
    $longOptions = array('name=', 'pass='******'key=', 'prefix=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('name' => 'n', 'pass' => 'p', 'key' => 'k', 'prefix' => 'pre');
    foreach ($vars as $var => $short) {
        ${$var} = NULL;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(TRUE, $name, $pass);
    //log the execution of script
    CRM_Core_Error::debug_log_message('NormalizePhone.php');
    // process all phones
    processPhones($config, $prefix);
}
コード例 #3
0
 /**
  * Method to build where part of query
  */
 function where()
 {
     $clauses = array();
     foreach ($this->_columns as $tableName => $table) {
         if (array_key_exists('filters', $table)) {
             foreach ($table['filters'] as $fieldName => $field) {
                 $clause = NULL;
                 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
                 // if user id value contains 0 for current user, replace value with current user
                 if ($fieldName == 'account_id') {
                     foreach ($this->_params['account_id_value'] as $paramKey => $userIdValue) {
                         if ($userIdValue == 0) {
                             $session = CRM_Core_Session::singleton();
                             $this->_params['account_id_value'][$paramKey] = $session->get('userID');
                         }
                     }
                 }
                 $clause = $this->whereClause($field, $op, CRM_Utils_Array::value("{$fieldName}_value", $this->_params), CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params));
                 if (!empty($clause)) {
                     $clauses[] = $clause;
                 }
             }
         }
     }
     if (empty($clauses)) {
         $this->_where = "";
     } else {
         $this->_where = "WHERE " . implode(' AND ', $clauses);
     }
 }
コード例 #4
0
 function select()
 {
     $select = array();
     $this->_columnHeaders = array();
     foreach ($this->_columns as $tableName => $table) {
         if (array_key_exists('fields', $table)) {
             foreach ($table['fields'] as $fieldName => $field) {
                 if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
                     if ($tableName == 'civicrm_email') {
                         $this->_emailField = TRUE;
                     } elseif ($tableName == 'civicrm_phone') {
                         $this->_phoneField = TRUE;
                     } elseif ($tableName == 'civicrm_country') {
                         $this->_countryField = TRUE;
                     }
                     $alias = "{$tableName}_{$fieldName}";
                     $select[] = "{$field['dbAlias']} as {$alias}";
                     $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
                     $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
                     $this->_selectAliases[] = $alias;
                 }
             }
         }
     }
     $this->_select = "SELECT " . implode(', ', $select) . " ";
 }
コード例 #5
0
ファイル: MessageTemplates.php プロジェクト: kidaa30/yes
 /**
  * Set default values for the form.
  * The default values are retrieved from the database.
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = $this->_values;
     if (empty($defaults['pdf_format_id'])) {
         $defaults['pdf_format_id'] = 'null';
     }
     $this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults);
     $this->assign('workflow_id', $this->_workflow_id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
         //set the context for redirection after form submit or cancel
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
     }
     // FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
     if ($this->_action & CRM_Core_Action::UPDATE) {
         if ($this->_workflow_id) {
             $selectedChild = 'workflow';
         } else {
             $selectedChild = 'user';
         }
         $cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
         $cancelURL = str_replace('&', '&', $cancelURL);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
     }
     return $defaults;
 }
コード例 #6
0
 static function importableFields($contactType = 'HRJobContractRevision', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     if (empty($contactType)) {
         $contactType = 'HRJobContractRevision';
     }
     $cacheKeyString = "";
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $showAll ? '_1' : '_0';
     $cacheKeyString .= $isProfile ? '_1' : '_0';
     $cacheKeyString .= $checkPermission ? '_1' : '_0';
     $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
     if (!$fields) {
         $fields = CRM_Hrjobcontract_DAO_HRJobContractRevision::import();
         $fields = array_merge($fields, CRM_Hrjobcontract_DAO_HRJobContractRevision::import());
         //Sorting fields in alphabetical order(CRM-1507)
         $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
         $fields = CRM_Utils_Array::index(array('name'), $fields);
         CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
     }
     self::$_importableFields[$cacheKeyString] = $fields;
     if (!$isProfile) {
         $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
     }
     return $fields;
 }
コード例 #7
0
ファイル: Location.php プロジェクト: hguru/224Civi
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 static function buildQuickForm(&$form)
 {
     // required for subsequent AJAX requests.
     $ajaxRequestBlocks = array();
     $generateAjaxRequest = 0;
     //build 1 instance of all blocks, without using ajax ...
     foreach ($form->_blocks as $blockName => $label) {
         require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_Form_Edit_' . $blockName) . '.php';
         $name = strtolower($blockName);
         $instances = array(1);
         if (CRM_Utils_Array::value($name, $_POST) && is_array($_POST[$name])) {
             $instances = array_keys($_POST[$name]);
         } elseif (property_exists($form, '_values') && CRM_Utils_Array::value($name, $form->_values) && is_array($form->_values[$name])) {
             $instances = array_keys($form->_values[$name]);
         }
         foreach ($instances as $instance) {
             if ($instance == 1) {
                 $form->assign('addBlock', FALSE);
                 $form->assign('blockId', $instance);
             } else {
                 //we are going to build other block instances w/ AJAX
                 $generateAjaxRequest++;
                 $ajaxRequestBlocks[$blockName][$instance] = TRUE;
             }
             $form->set($blockName . '_Block_Count', $instance);
             $formName = 'CRM_Contact_Form_Edit_' . $blockName;
             $formName::buildQuickForm($form);
         }
     }
     //assign to generate AJAX request for building extra blocks.
     $form->assign('generateAjaxRequest', $generateAjaxRequest);
     $form->assign('ajaxRequestBlocks', $ajaxRequestBlocks);
 }
コード例 #8
0
ファイル: LocationType.php プロジェクト: ksecor/civicrm
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_LocationType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'));
         return;
     }
     // store the submitted values in an array
     $params = $this->exportValues();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, false);
     // action is taken depending upon the mode
     $locationType =& new CRM_Core_DAO_LocationType();
     $locationType->name = $params['name'];
     $locationType->vcard_name = $params['vcard_name'];
     $locationType->description = $params['description'];
     $locationType->is_active = $params['is_active'];
     $locationType->is_default = $params['is_default'];
     if ($params['is_default']) {
         $query = "UPDATE civicrm_location_type SET is_default = 0";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $locationType->id = $this->_id;
     }
     $locationType->save();
     CRM_Core_Session::setStatus(ts('The location type \'%1\' has been saved.', array(1 => $locationType->name)));
 }
コード例 #9
0
 /**
  * Retrieve records.
  */
 public static function getBatchList()
 {
     $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $params = $_REQUEST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     if ($context != 'financialBatch') {
         // data entry status batches
         $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name');
     }
     $params['context'] = $context;
     // get batch list
     $batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
     $iFilteredTotal = $iTotal = $params['total'];
     if ($context == 'financialBatch') {
         $selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links');
     } else {
         $selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links');
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #10
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_LocationType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
         return;
     }
     // store the submitted values in an array
     $params = $this->exportValues();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
     // action is taken depending upon the mode
     $locationType = new CRM_Core_DAO_LocationType();
     $locationType->name = $params['name'];
     $locationType->display_name = $params['display_name'];
     $locationType->vcard_name = $params['vcard_name'];
     $locationType->description = $params['description'];
     $locationType->is_active = $params['is_active'];
     $locationType->is_default = $params['is_default'];
     if ($params['is_default']) {
         $query = "UPDATE civicrm_location_type SET is_default = 0";
         CRM_Core_DAO::executeQuery($query);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $locationType->id = $this->_id;
     }
     $locationType->save();
     CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.", array(1 => $locationType->name)), ts('Saved'), 'success');
 }
コード例 #11
0
 /**
  * Used to store selected contacts across multiple pages in advanced search.
  */
 public static function selectUnselectRelationships()
 {
     $name = CRM_Utils_Array::value('name', $_REQUEST);
     $cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST);
     $state = CRM_Utils_Array::value('state', $_REQUEST, 'checked');
     $variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single');
     $actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select');
     if ($variableType == 'multiple') {
         // action post value only works with multiple type variable
         if ($name) {
             //multiple names like mark_x_1-mark_x_2 where 1,2 are cids
             $elements = explode('-', $name);
             foreach ($elements as $key => $element) {
                 $elements[$key] = self::_convertToId($element);
             }
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements, 'civicrm_relationship');
         } else {
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, NULL, 'civicrm_relationship');
         }
     } elseif ($variableType == 'single') {
         $cId = self::_convertToId($name);
         $action = $state == 'checked' ? 'select' : 'unselect';
         CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId, 'civicrm_relationship');
     }
     $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, 'get', 'civicrm_relationship');
     $countSelectionCids = count($contactIds[$cacheKey]);
     $arrRet = array('getCount' => $countSelectionCids);
     CRM_Utils_JSON::output($arrRet);
 }
コード例 #12
0
ファイル: Summary.php プロジェクト: JoeMurray/civihr
 function select()
 {
     $select = array();
     $this->_columnHeaders = array();
     foreach ($this->_columns as $tableName => $table) {
         if (array_key_exists('fields', $table)) {
             foreach ($table['fields'] as $fieldName => $field) {
                 if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
                     if ($tableName == 'civicrm_hrjobcontract_leave' && $fieldName == 'leave_leave_type') {
                         $select[] = "GROUP_CONCAT(DISTINCT hrjobcontract_leave_civireport.leave_type SEPARATOR ',') AS {$tableName}_{$fieldName}";
                     } elseif ($tableName == 'civicrm_hrjobcontract_leave' && $fieldName == 'leave_leave_amount') {
                         $select[] = "GROUP_CONCAT(DISTINCT hrjobcontract_leave_civireport.leave_type , ':', hrjobcontract_leave_civireport.leave_amount SEPARATOR ',') AS {$tableName}_{$fieldName}";
                     } elseif ($tableName == 'civicrm_hrjobcontract_health' && $fieldName == 'health_provider') {
                         $select[] = "CONCAT({$this->_aliases['civicrm_contact']}_health1.sort_name, ' (InternalID: ', hrjobcontract_health_civireport.provider , ', Email: ', COALESCE({$this->_aliases['civicrm_email']}_health1.email, '-'), ', ExternalID: ', COALESCE({$this->_aliases['civicrm_contact']}_health1.external_identifier, '-'), ')') AS {$tableName}_{$fieldName}";
                     } elseif ($tableName == 'civicrm_hrjobcontract_health' && $fieldName == 'health_provider_life_insurance') {
                         $select[] = "CONCAT({$this->_aliases['civicrm_contact']}_health2.sort_name, ' (InternalID: ', hrjobcontract_health_civireport.provider_life_insurance , ', Email: ', COALESCE({$this->_aliases['civicrm_email']}_health2.email, '-'), ', ExternalID: ', COALESCE({$this->_aliases['civicrm_contact']}_health2.external_identifier, '-'), ')') AS {$tableName}_{$fieldName}";
                     } else {
                         $alias = "{$tableName}_{$fieldName}";
                         $select[] = "{$field['dbAlias']} as {$alias}";
                     }
                     $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
                     $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
                     $this->_selectAliases[] = $alias;
                 }
             }
         }
     }
     $this->_select = "SELECT " . implode(', ', $select) . " ";
 }
コード例 #13
0
 /**
  * takes an associative array and creates a contact object
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Contact_BAO_Household object
  * @access public
  * @static
  */
 function add(&$params, &$ids)
 {
     $household =& new CRM_Contact_BAO_Household();
     $household->copyValues($params);
     $household->id = CRM_Utils_Array::value('household', $ids);
     return $household->save();
 }
コード例 #14
0
 /**
  * process website
  *
  * @param array $params associated array
  * @param int   $contactID contact id
  *
  * @return void
  * @access public
  * @static
  */
 static function create(&$params, $contactID, $skipDelete)
 {
     if (empty($params)) {
         return FALSE;
     }
     $ids = self::allWebsites($contactID);
     foreach ($params as $key => $values) {
         $websiteId = CRM_Utils_Array::value('id', $values);
         if ($websiteId) {
             if (array_key_exists($websiteId, $ids)) {
                 unset($ids[$websiteId]);
             } else {
                 unset($values['id']);
             }
         }
         if (!CRM_Utils_Array::value('id', $values) && is_array($ids) && !empty($ids)) {
             foreach ($ids as $id => $value) {
                 if ($value['website_type_id'] == $values['website_type_id']) {
                     $values['id'] = $id;
                     unset($ids[$id]);
                     break;
                 }
             }
         }
         $values['contact_id'] = $contactID;
         self::add($values);
     }
     if ($skipDelete && !empty($ids)) {
         self::del(array_keys($ids));
     }
 }
コード例 #15
0
ファイル: Upgrade.php プロジェクト: rameshrr99/civicrm-core
 public function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template = CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     $action = CRM_Utils_Array::value('action', $_REQUEST, 'intro');
     switch ($action) {
         case 'intro':
             $this->runIntro();
             break;
         case 'begin':
             $this->runBegin();
             break;
         case 'finish':
             $this->runFinish();
             break;
         default:
             CRM_Core_Error::fatal(ts('Unrecognized upgrade action'));
     }
 }
コード例 #16
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         if (!empty($this->_BAOName)) {
             $baoName = $this->_BAOName;
             $baoName::retrieve($params, $defaults);
         }
     }
     if ($this->_action == CRM_Core_Action::DELETE && !empty($defaults['name'])) {
         $this->assign('delName', $defaults['name']);
     } elseif ($this->_action == CRM_Core_Action::ADD) {
         $condition = " AND is_default = 1";
         $values = CRM_Core_OptionGroup::values('financial_account_type', FALSE, FALSE, FALSE, $condition);
         $defaults['financial_account_type_id'] = array_keys($values);
         $defaults['is_active'] = 1;
     } elseif ($this->_action & CRM_Core_Action::UPDATE) {
         if (!empty($defaults['contact_id']) || !empty($defaults['created_id'])) {
             $contactID = !empty($defaults['created_id']) ? $defaults['created_id'] : $defaults['contact_id'];
             $this->assign('created_id', $contactID);
             $this->assign('organisationId', $contactID);
         }
         if ($parentId = CRM_Utils_Array::value('parent_id', $defaults)) {
             $this->assign('parentId', $parentId);
         }
     }
     return $defaults;
 }
コード例 #17
0
 /**
  * Generate a query to locate recipients who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  *   The schedule as configured by the administrator.
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_membership e';
     $query['casContactIdField'] = 'e.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     $query['casDateField'] = str_replace('membership_', 'e.', $schedule->start_action_date);
     // FIXME: Numbers should be constants.
     if (in_array(2, $selectedStatuses)) {
         //auto-renew memberships
         $query->where("e.contribution_recur_id IS NOT NULL");
     } elseif (in_array(1, $selectedStatuses)) {
         $query->where("e.contribution_recur_id IS NULL");
     }
     if (!empty($selectedValues)) {
         $query->where("e.membership_type_id IN (@memberTypeValues)")->param('memberTypeValues', $selectedValues);
     } else {
         $query->where("e.membership_type_id IS NULL");
     }
     $query->where("( e.is_override IS NULL OR e.is_override = 0 )");
     $query->merge($this->prepareMembershipPermissionsFilter());
     $query->where("e.status_id IN (#memberStatus)")->param('memberStatus', \CRM_Member_PseudoConstant::membershipStatus(NULL, "(is_current_member = 1 OR name = 'Expired')", 'id'));
     // Why is this only for civicrm_membership?
     if ($schedule->start_action_date && $schedule->is_repeat == FALSE) {
         $query['casUseReferenceDate'] = TRUE;
     }
     return $query;
 }
コード例 #18
0
 /**
  * Takes an associative array and adds email.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return object
  *   CRM_Core_BAO_Email object on success, null otherwise
  */
 public static function add(&$params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'Email', CRM_Utils_Array::value('id', $params), $params);
     $email = new CRM_Core_DAO_Email();
     $email->copyValues($params);
     // lower case email field to optimize queries
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $email->email = $strtolower($email->email);
     /*
      * since we're setting bulkmail for 1 of this contact's emails, first reset all their other emails to is_bulkmail false
      *  We shouldn't not set the current email to false even though we
      *  are about to reset it to avoid contaminating the changelog if logging is enabled
      * (only 1 email address can have is_bulkmail = true)
      */
     if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) {
         $sql = "\nUPDATE civicrm_email\nSET    is_bulkmail = 0\nWHERE  contact_id = {$params['contact_id']}\n";
         if ($hook == 'edit') {
             $sql .= " AND id <> {$params['id']}";
         }
         CRM_Core_DAO::executeQuery($sql);
     }
     // handle if email is on hold
     self::holdEmail($email);
     $email->save();
     if ($email->is_primary) {
         // update the UF user email if that has changed
         CRM_Core_BAO_UFMatch::updateUFName($email->contact_id);
     }
     CRM_Utils_Hook::post($hook, 'Email', $email->id, $email);
     return $email;
 }
コード例 #19
0
ファイル: Money.php プロジェクト: bhirsch/voipdev
 /**
  * format a monetary string
  *
  * Format a monetary string basing on the amount provided,
  * ISO currency code provided and a format string consisting of:
  *
  * %a - the formatted amount
  * %C - the currency ISO code (e.g., 'USD') if provided
  * %c - the currency symbol (e.g., '$') if available
  *
  * @param float  $amount    the monetary amount to display (1234.56)
  * @param string $currency  the three-letter ISO currency code ('USD')
  * @param string $format    the desired currency format
  *
  * @return string  formatted monetary string
  *
  * @static
  */
 static function format($amount, $currency = null, $format = null)
 {
     if (CRM_Utils_System::isNull($amount)) {
         return '';
     }
     $config =& CRM_Core_Config::singleton();
     if (!self::$_currencySymbols) {
         require_once "CRM/Core/PseudoConstant.php";
         $currencySymbolName = CRM_Core_PseudoConstant::currencySymbols('name');
         $currencySymbol = CRM_Core_PseudoConstant::currencySymbols();
         self::$_currencySymbols = array_combine($currencySymbolName, $currencySymbol);
     }
     if (!$currency) {
         $currency = $config->defaultCurrency;
     }
     if (!$format) {
         $format = $config->moneyformat;
     }
     // money_format() exists only in certain PHP install (CRM-650)
     if (is_numeric($amount) and function_exists('money_format')) {
         $amount = money_format($config->moneyvalueformat, $amount);
     }
     $replacements = array('%a' => $amount, '%C' => $currency, '%c' => CRM_Utils_Array::value($currency, self::$_currencySymbols, $currency));
     return strtr($format, $replacements);
 }
コード例 #20
0
ファイル: MailSettings.php プロジェクト: nielosz/civicrm-core
 /**
  * Browse all mail settings.
  */
 public function browse()
 {
     //get all mail settings.
     $allMailSettings = array();
     $mailSetting = new CRM_Core_DAO_MailSettings();
     $allProtocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol');
     //multi-domain support for mail settings. CRM-5244
     $mailSetting->domain_id = CRM_Core_Config::domainID();
     //find all mail settings.
     $mailSetting->find();
     while ($mailSetting->fetch()) {
         //replace protocol value with name
         $mailSetting->protocol = CRM_Utils_Array::value($mailSetting->protocol, $allProtocols);
         CRM_Core_DAO::storeValues($mailSetting, $allMailSettings[$mailSetting->id]);
         //form all action links
         $action = array_sum(array_keys($this->links()));
         // disallow the DELETE action for the default set of settings
         if ($mailSetting->is_default) {
             $action &= ~CRM_Core_Action::DELETE;
         }
         //add action links.
         $allMailSettings[$mailSetting->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $mailSetting->id), ts('more'), FALSE, 'mailSetting.manage.action', 'MailSetting', $mailSetting->id);
     }
     $this->assign('rows', $allMailSettings);
 }
コード例 #21
0
ファイル: DedupeException.php プロジェクト: kidaa30/yes
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  */
 public function preProcess()
 {
     //fetch the dedupe exception contacts.
     $dedupeExceptions = array();
     $exception = new CRM_Dedupe_DAO_Exception();
     $exception->find();
     $contactIds = array();
     while ($exception->fetch()) {
         $key = "{$exception->contact_id1}_{$exception->contact_id2}";
         $contactIds[$exception->contact_id1] = $exception->contact_id1;
         $contactIds[$exception->contact_id2] = $exception->contact_id2;
         $dedupeExceptions[$key] = array('main' => array('id' => $exception->contact_id1), 'other' => array('id' => $exception->contact_id2));
     }
     //get the dupe contacts display names.
     if (!empty($dedupeExceptions)) {
         $sql = 'select id, display_name from civicrm_contact where id IN ( ' . implode(', ', $contactIds) . ' )';
         $contact = CRM_Core_DAO::executeQuery($sql);
         $displayNames = array();
         while ($contact->fetch()) {
             $displayNames[$contact->id] = $contact->display_name;
         }
         foreach ($dedupeExceptions as $key => &$values) {
             $values['main']['name'] = CRM_Utils_Array::value($values['main']['id'], $displayNames);
             $values['other']['name'] = CRM_Utils_Array::value($values['other']['id'], $displayNames);
         }
     }
     $this->assign('dedupeExceptions', $dedupeExceptions);
 }
コード例 #22
0
ファイル: Main.php プロジェクト: riyadennis/my_civicrm
  function getTemplateFileName () {
    $request = CRM_Utils_System::currentPath();
    if (false !== strpos($request, '..')) {
      die ("SECURITY FATAL: the url can't contain '..'. Please report the issue on the forum at civicrm.org");
    }

    $request = split ('/',$request);
    $tplfile = NULL;
    $smarty= CRM_Core_Smarty::singleton( );
    $smarty->assign("options",array());
    if (CRM_Utils_Array::value(2, $request)) {
      $tplfile = _civicrm_api_get_camel_name($request[2]);
      $tplfile = explode('?', $tplfile);
      $tpl = 'dataviz/'.$tplfile[0].'.tpl';
    }
    if (CRM_Utils_Array::value(3, $request)) {
      $r3 = _civicrm_api_get_camel_name($request[3]);
      $smarty->assign("id",$r3);
    }
    if (!$tplfile) {
      $tpl = "CRM/Civizualise/Page/Main.tpl";
    }
    if( !$smarty->template_exists($tpl) ){
      header("Status: 404 Not Found");
      die ("Can't find the requested template file templates/$tpl");
    }
    return $tpl;
  }
コード例 #23
0
/**
 * Implements hook_civicrm_navigationMenu().
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
 */
function statelegemail_civicrm_navigationMenu(&$menu)
{
    // We'd like the item to be beneath these two items.
    $idealTree = array('Administer', 'CiviCampaign');
    // Walk down the menu to see if we can find them where we expect them.
    $walkMenu = $menu;
    $branches = array();
    foreach ($idealTree as $limb) {
        foreach ($walkMenu as $id => $item) {
            if ($item['attributes']['name'] == $limb) {
                $walkMenu = CRM_Utils_Array::value('child', $item, array());
                $branches[] = $id;
                $branches[] = 'child';
                continue 2;
            }
        }
        // If the expected parent isn't at this level of the menu, we'll just drop
        // it here.
        break;
    }
    $item = array('attributes' => array('label' => ts('State Legislators Email Settings', array('domain' => 'com.aghstrategies.statelegemail')), 'name' => 'statelegemail_settings', 'url' => 'civicrm/statelegemail/settings?reset=1', 'permission' => 'administer CiviCRM', 'operator' => 'AND', 'separator' => 0, 'active' => 1));
    if (!empty($id)) {
        $item['parentID'] = $id;
    }
    // Need to put together exactly where the item should be added;
    $treeMenu =& $menu;
    foreach ($branches as $branch) {
        $treeMenu =& $treeMenu[$branch];
    }
    $newId = 0;
    statelegemail_scanMaxNavId($menu, $newId);
    $newId++;
    $item['navID'] = $newId;
    $treeMenu[$newId] = $item;
}
コード例 #24
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     if (!CRM_Core_Permission::check('administer Reports')) {
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
     }
     $optionVal = CRM_Report_Utils_Report::getValueFromUrl();
     $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', FALSE);
     $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.');
     $reportClass = NULL;
     if ($extKey !== FALSE) {
         $ext = CRM_Extension_System::singleton()->getMapper();
         $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
         $templateInfo['name'] = $reportClass;
     }
     if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) {
         CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template');
         $this->assign('reportTitle', $templateInfo['label']);
         $session = CRM_Core_Session::singleton();
         $session->set('reportDescription', $templateInfo['description']);
         $wrapper = new CRM_Utils_Wrapper();
         return $wrapper->run($templateInfo['name'], NULL, NULL);
     }
     if ($optionVal) {
         CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'), ts('Template Not Found'), 'error');
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
 }
コード例 #25
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
     $this->_cc = CRM_Utils_Request::retrieve('cc', 'String', $this);
     //get the contact and event id and assing to session.
     $values = array();
     $csContactID = NULL;
     if ($this->_participantId) {
         $params = array('id' => $this->_participantId);
         CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Participant', $params, $values, array('contact_id', 'event_id', 'status_id'));
     }
     $this->_participantStatusId = CRM_Utils_Array::value('status_id', $values);
     $this->_eventId = CRM_Utils_Array::value('event_id', $values);
     $csContactId = CRM_Utils_Array::value('contact_id', $values);
     // make sure we have right permission to edit this user
     $this->_csContactID = NULL;
     if ($csContactId && $this->_eventId) {
         $session = CRM_Core_Session::singleton();
         if ($csContactId == $session->get('userID')) {
             $this->_csContactID = $csContactId;
         } else {
             if (CRM_Contact_BAO_Contact_Permission::validateChecksumContact($csContactId, $this)) {
                 //since we have landing page so get this contact
                 //id in session if user really want to walk wizard.
                 $this->_csContactID = $csContactId;
             }
         }
     }
     if (!$this->_csContactID) {
         $config = CRM_Core_Config::singleton();
         CRM_Core_Error::statusBounce(ts('You do not have permission to access this event registration. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL);
     }
 }
コード例 #26
0
 /**
  * Creates or updates a participant payment record.
  *
  * @param array $params
  *   of values to initialize the record with.
  * @param array $ids
  *   with one values of id for this participantPayment record (for update).
  *
  * @return object
  *   the partcipant payment record
  */
 public static function create(&$params, &$ids)
 {
     if (isset($ids['id'])) {
         CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params);
     }
     $participantPayment = new CRM_Event_BAO_ParticipantPayment();
     $participantPayment->copyValues($params);
     if (isset($ids['id'])) {
         $participantPayment->id = CRM_Utils_Array::value('id', $ids);
     } else {
         $participantPayment->find(TRUE);
     }
     $participantPayment->save();
     if (isset($ids['id'])) {
         CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment);
     } else {
         CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment);
     }
     //generally if people are creating participant_payments via the api they won't be setting the line item correctly - we can't help them if they are doing complex transactions
     // but if they have a single line item for the contribution we can assume it should refer to the participant line
     $lineItemCount = CRM_Core_DAO::singleValueQuery("select count(*) FROM civicrm_line_item WHERE contribution_id = %1", array(1 => array($participantPayment->contribution_id, 'Integer')));
     if ($lineItemCount == 1) {
         $sql = "UPDATE civicrm_line_item li\n      SET entity_table = 'civicrm_participant', entity_id = %1\n      WHERE contribution_id = %2 AND entity_table = 'civicrm_contribution'";
         CRM_Core_DAO::executeQuery($sql, array(1 => array($participantPayment->participant_id, 'Integer'), 2 => array($participantPayment->contribution_id, 'Integer')));
     }
     return $participantPayment;
 }
コード例 #27
0
ファイル: Search.php プロジェクト: ksecor/civicrm
 /**
  * Determine the form name based on the action. This allows us
  * to avoid using  conditional state machine, much more efficient
  * and simpler
  *
  * @param CRM_Core_Controller $controller the controller object
  *
  * @return string the name of the form that will handle the task
  * @access protected
  */
 function taskName($controller, $formName = 'Search')
 {
     // total hack, check POST vars and then session to determine stuff
     // fix value if print button is pressed
     if (CRM_Utils_Array::value('_qf_' . $formName . '_next_print', $_POST)) {
         $value = CRM_Case_Task::PRINT_CASES;
     } else {
         $value = CRM_Utils_Array::value('task', $_POST);
     }
     if (!isset($value)) {
         $value = $this->_controller->get('task');
     }
     $this->_controller->set('task', $value);
     $result = false;
     switch ($value) {
         case CRM_Case_Task::DELETE_CASES:
             $task = 'CRM_Case_Form_Task_Delete';
             break;
         case CRM_Case_Task::EXPORT_CASES:
             $task = array('CRM_Export_Form_Select', 'CRM_Export_Form_Map');
             break;
         case CRM_Case_Task::RESTORE_CASES:
             $task = 'CRM_Case_Form_Task_Restore';
             break;
         default:
             // the print task is the default and catch=all task
             $task = 'CRM_Case_Form_Task_Print';
             break;
     }
     return array($task, $result);
 }
コード例 #28
0
 /**
  * get the variable information from the request (GET/POST/SESSION
  *
  * @param $name    name of the variable to be retrieved
  * @param $store   session scope where variable is stored
  * @param $abort   is this variable required
  * @param $default default value of the variable if not present
  * @param $method  where should we look for the variable
  *
  * @return string  the value of the variable
  * @access public
  * @static
  *
  */
 function retrieve($name, &$store, $abort = false, $default = null, $method = 'GET')
 {
     $value = null;
     switch ($method) {
         case 'GET':
             $value = CRM_Utils_Array::value($name, $_GET);
             break;
         case 'POST':
             $value = CRM_Utils_Array::value($name, $_POST);
             break;
         default:
             $value = CRM_Utils_Array::value($name, $_REQUEST);
             break;
     }
     if (!isset($value) && $store) {
         $value = $store->get($name);
     }
     if (!isset($value) && $abort) {
         CRM_Core_Error::fatal("Could not find valid value for {$name}");
     }
     if (!isset($value) && $default) {
         $value = $default;
     }
     if (isset($value) && $store) {
         // minor hack for action
         if ($name == 'action' && is_string($value)) {
             $value = CRM_Core_Action::resolve($value);
         }
         $store->set($name, $value);
     }
     return $value;
 }
コード例 #29
0
ファイル: Group.php プロジェクト: sarehag/civicrm-core
 /**
  * Set default values for the form.
  * The default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL);
     $defaults = array();
     if ($mailingID) {
         $mailing = new CRM_Mailing_DAO_Mailing();
         $mailing->id = $mailingID;
         $mailing->addSelect('name');
         $mailing->find(TRUE);
         $defaults['name'] = $mailing->name;
         if (!$continue) {
             $defaults['name'] = ts('Copy of %1', array(1 => $mailing->name));
         } else {
             // CRM-7590, reuse same mailing ID if we are continuing
             $this->set('mailing_id', $mailingID);
         }
         $dao = new CRM_Mailing_DAO_MailingGroup();
         $mailingGroups = array();
         $dao->mailing_id = $mailingID;
         $dao->find();
         while ($dao->fetch()) {
             $mailingGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
         }
         $defaults['includeGroups'] = $mailingGroups['civicrm_group']['Include'];
         $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']);
         $defaults['includeMailings'] = CRM_Utils_Array::value('Include', CRM_Utils_Array::value('civicrm_mailing', $mailingGroups));
         $defaults['excludeMailings'] = CRM_Utils_Array::value('Exclude', CRM_Utils_Array::value('civicrm_mailing', $mailingGroups));
     }
     return $defaults;
 }
コード例 #30
0
ファイル: SearchCustom.php プロジェクト: ksecor/civicrm
 static function details($csID, $ssID = null, $gID = null)
 {
     $error = array(null, null, null);
     if (!$csID && !$ssID && !$gID) {
         return $error;
     }
     $customSearchID = $csID;
     $formValues = array();
     if ($ssID || $gID) {
         if ($gID) {
             $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
         }
         $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID);
         $customSearchID = CRM_Utils_Array::value('customSearchID', $formValues);
     }
     if (!$customSearchID) {
         return $error;
     }
     // check that the csid exists in the db along with the right file
     // and implements the right interface
     require_once 'CRM/Core/OptionGroup.php';
     $customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID);
     if (!$customSearchClass) {
         return $error;
     }
     $customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
     $error = (include_once $customSearchFile);
     if ($error == false) {
         CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
     }
     return array($customSearchID, $customSearchClass, $formValues);
 }