コード例 #1
0
ファイル: PriceSet.php プロジェクト: kcristiano/civicrm-core
 /**
  * Takes an associative array and creates a price set object.
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Price_DAO_PriceSet
  */
 public static function create(&$params)
 {
     if (empty($params['id']) && empty($params['name'])) {
         $params['name'] = CRM_Utils_String::munge($params['title'], '_', 242);
     }
     $priceSetID = NULL;
     $validatePriceSet = TRUE;
     if (!empty($params['extends']) && is_array($params['extends'])) {
         if (!array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $params['extends']) || !array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $params['extends'])) {
             $validatePriceSet = FALSE;
         }
         $params['extends'] = CRM_Utils_Array::implodePadded($params['extends']);
     } else {
         $priceSetID = CRM_Utils_Array::value('id', $params);
     }
     // CRM-16189
     if ($validatePriceSet && !empty($params['financial_type_id'])) {
         CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id'], $priceSetID);
     }
     $priceSetBAO = new CRM_Price_BAO_PriceSet();
     $priceSetBAO->copyValues($params);
     if (self::eventPriceSetDomainID()) {
         $priceSetBAO->domain_id = CRM_Core_Config::domainID();
     }
     return $priceSetBAO->save();
 }
コード例 #2
0
 function retrieve($caseType)
 {
     require_once 'CRM/Utils/String.php';
     require_once 'CRM/Utils/Array.php';
     // trim all spaces from $caseType
     $caseType = str_replace('_', ' ', $caseType);
     $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
     if (!CRM_Utils_Array::value($caseType, self::$_xml)) {
         if (!self::$_xml) {
             self::$_xml = array();
         }
         // first check custom templates directory
         $fileName = null;
         $config = CRM_Core_Config::singleton();
         if (isset($config->customTemplateDir) && $config->customTemplateDir) {
             // check if the file exists in the custom templates directory
             $fileName = implode(DIRECTORY_SEPARATOR, array($config->customTemplateDir, 'CRM', 'Case', 'xml', 'configuration', "{$caseType}.xml"));
         }
         if (!$fileName || !file_exists($fileName)) {
             // check if file exists locally
             $fileName = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'xml', 'configuration', "{$caseType}.xml"));
             if (!file_exists($fileName)) {
                 return false;
             }
         }
         // read xml file
         $dom = DomDocument::load($fileName);
         $dom->xinclude();
         self::$_xml[$caseType] = simplexml_import_dom($dom);
     }
     return self::$_xml[$caseType];
 }
コード例 #3
0
 static function formRule($fields)
 {
     $errors = array();
     require_once 'api/api.php';
     $apiRequest = array();
     $apiRequest['entity'] = CRM_Utils_String::munge($fields['api_entity']);
     $apiRequest['action'] = CRM_Utils_String::munge($fields['api_action']);
     $apiRequest['version'] = substr($fields['api_prefix'], -1);
     // ie. civicrm_api3
     $apiRequest += _civicrm_api_resolve($apiRequest);
     // look up function, file, is_generic
     if (!$apiRequest['function']) {
         $errors['api_action'] = ts('Given API command is not defined.');
     }
     // CRM-9868- don't allow Enabled (is_active) for jobs that should never be run automatically via execute action or runjobs url
     if (($fields['api_action'] == 'process_membership_reminder_date' || $fields['api_action'] == 'update_greeting') && CRM_Utils_Array::value('is_active', $fields) == 1) {
         // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
         $docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
         $errors['is_active'] = ts('You can not save this Scheduled Job as Active with the specified api action (%2). That action should not be run regularly - it should only be run manually for special conditions. %1', array(1 => $docLink, 2 => $fields['api_action']));
     }
     if (!empty($errors)) {
         return $errors;
     }
     return empty($errors) ? TRUE : $errors;
 }
コード例 #4
0
ファイル: WordPress.php プロジェクト: hguru/224Civi
 /**
  * given a permission string, check for access requirements
  *
  * @param string $str the permission to check
  *
  * @return boolean true if yes, else false
  * @access public
  */
 function check($str)
 {
     // Generic cms 'administer users' role tranlates to 'administrator' WordPress role
     $str = $this->translatePermission($str, 'WordPress', array('administer users' => 'administrator'));
     if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
         return FALSE;
     }
     if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
         return TRUE;
     }
     // for administrators give them all permissions
     if (!function_exists('current_user_can')) {
         return TRUE;
     }
     if (current_user_can('super admin') || current_user_can('administrator')) {
         return TRUE;
     }
     // Make string lowercase and convert spaces into underscore
     $str = CRM_Utils_String::munge(strtolower($str));
     if (is_user_logged_in()) {
         // Check whether the logged in user has the capabilitity
         if (current_user_can($str)) {
             return TRUE;
         }
     } else {
         //check the capabilities of Anonymous user)
         $roleObj = new WP_Roles();
         if ($roleObj->get_role('anonymous_user') != NULL && array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)) {
             return TRUE;
         }
     }
     return FALSE;
 }
コード例 #5
0
ファイル: XMLProcessor.php プロジェクト: hguru/224Civi
 public static function mungeCaseType($caseType)
 {
     // trim all spaces from $caseType
     $caseType = str_replace('_', ' ', $caseType);
     $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
     return $caseType;
 }
コード例 #6
0
ファイル: hrjobcontract.php プロジェクト: JoeMurray/civihr
/**
 * Implementation of hook_civicrm_uninstall
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
 */
function hrjobcontract_civicrm_uninstall()
{
    $subTypeInfo = CRM_Contact_BAO_ContactType::subTypeInfo('Organization');
    $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider');
    foreach ($sub_type_name as $sub_type_name) {
        $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name));
        $orid = array_key_exists($subTypeName, $subTypeInfo);
        if ($orid) {
            $id = $subTypeInfo[$subTypeName]['id'];
            CRM_Contact_BAO_ContactType::del($id);
        }
    }
    $jobContractMenu = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'job_contracts', 'id', 'name');
    if (!empty($jobContractMenu)) {
        CRM_Core_BAO_Navigation::processDelete($jobContractMenu);
    }
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_navigation WHERE name IN ('job_contracts', 'import_export_job_contracts', 'jobImport', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason')");
    CRM_Core_BAO_Navigation::resetNavigation();
    //delete custom groups and field
    $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
    $customGroupData = CRM_Utils_Array::first($customGroup['values']);
    if (!empty($customGroupData['id'])) {
        civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
    }
    $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
    $customGroupData = CRM_Utils_Array::first($customGroup['values']);
    if (!empty($customGroupData['id'])) {
        civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
    }
    //delete all option group and values
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('job_contracts', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason', 'hrjc_contract_type', 'hrjc_level_type', 'hrjc_department', 'hrjc_hours_type', 'hrjc_pay_grade', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_location', 'hrjc_pension_type', 'hrjc_region', 'hrjc_pay_scale')");
    //delete job contract files to entities relations
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_entity_file WHERE entity_table LIKE 'civicrm_hrjobcontract_%'");
    return _hrjobcontract_civix_civicrm_uninstall();
}
コード例 #7
0
/**
 * params must contain at least id=xx & {one of the fields from getfields}=value
 */
function civicrm_api3_generic_setValue($apiRequest)
{
    $entity = $apiRequest['entity'];
    $params = $apiRequest['params'];
    // we can't use _spec, doesn't work with generic
    civicrm_api3_verify_mandatory($params, NULL, array('id', 'field', 'value'));
    $id = $params['id'];
    if (!is_numeric($id)) {
        return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id"));
    }
    $field = CRM_Utils_String::munge($params['field']);
    $value = $params['value'];
    $fields = civicrm_api($entity, 'getFields', array("version" => 3, "sequential"));
    // getfields error, shouldn't happen.
    if ($fields['is_error']) {
        return $fields;
    }
    $fields = $fields['values'];
    if (!array_key_exists($field, $fields)) {
        return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields)));
    }
    $def = $fields[$field];
    if (array_key_exists('required', $def) && empty($value)) {
        return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field));
    }
    switch ($def['type']) {
        case 1:
            //int
            if (!is_numeric($value)) {
                return civicrm_api3_create_error("Param '{$field}' must be a number", array('error_code' => 'NaN'));
            }
        case 2:
            //string
            require_once "CRM/Utils/Rule.php";
            if (!CRM_Utils_Rule::xssString($value)) {
                return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS'));
            }
            if (array_key_exists('maxlength', $def)) {
                $value = substr($value, 0, $def['maxlength']);
            }
            break;
        case 16:
            //boolean
            $value = (bool) $value;
            break;
        case 4:
            //date
        //date
        default:
            return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet. Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED'));
    }
    if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) {
        $entity = array('id' => $id, $field => $value);
        CRM_Utils_Hook::post('edit', $entity, $id, $entity);
        return civicrm_api3_create_success($entity);
    } else {
        return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})");
    }
}
コード例 #8
0
/**
 * Create a new ActionSchedule.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_action_schedule_create($params)
{
    civicrm_api3_verify_one_mandatory($params, NULL, array('start_action_date', 'absolute_date'));
    if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) {
        $params['name'] = CRM_Utils_String::munge($params['title']);
    }
    return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ActionSchedule');
}
コード例 #9
0
ファイル: String.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * Convert a display name into a potential variable
  * name that we could use in forms/code
  * 
  * @param  name    Name of the string
  * @return string  An equivalent variable name
  *
  * @access public
  * @return string (or null)
  * @static
  */
 function titleToVar($title)
 {
     if (!CRM_Utils_Rule::title($title)) {
         return null;
     }
     $variable = CRM_Utils_String::munge($title);
     if (CRM_Utils_Rule::variable($variable)) {
         return $variable;
     }
     return null;
 }
コード例 #10
0
ファイル: ContactType.php プロジェクト: hguru/224Civi
/**
 * create/update contact_type
 *
 * This API is used to create new contact_type or update any of the existing
 * In case of updating existing contact_type, id of that particular contact_type must
 * be in $params array.
 *
 * @param array $params  (referance) Associative array of property
 *                       name/value pairs to insert in new 'contact_type'
 *
 * @return array   contact_type array
 *
 * @access public
 */
function civicrm_api3_contact_type_create($params)
{
    civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__), array('name', 'parent_id'));
    if (!array_key_exists('label', $params)) {
        $params['label'] = $params['name'];
    }
    if (!array_key_exists('is_active', $params)) {
        $params['is_active'] = TRUE;
    }
    $params['name'] = CRM_Utils_String::munge($params['name']);
    return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
コード例 #11
0
 /**
  * takes an associative array and creates a price set object
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_PriceSet object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     if (empty($params['id']) && empty($params['name'])) {
         $params['name'] = CRM_Utils_String::munge($params['title'], '_', 242);
     }
     $priceSetBAO = new CRM_Price_BAO_PriceSet();
     $priceSetBAO->copyValues($params);
     if (self::eventPriceSetDomainID()) {
         $priceSetBAO->domain_id = CRM_Core_Config::domainID();
     }
     return $priceSetBAO->save();
 }
コード例 #12
0
ファイル: Custom.php プロジェクト: ksecor/civicrm
 function createGroup($group, $extends = null, $isMultiple = false)
 {
     if (empty($group)) {
         $group = array('title' => 'Test_Group', 'name' => 'test_group', 'extends' => $extends, 'style' => 'Inline', 'is_multiple' => $isMultiple, 'is_active' => 1);
     }
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Utils/String.php';
     $customGroupBAO =& new CRM_Core_BAO_CustomGroup();
     $customGroupBAO->copyValues($group);
     $customGroup = $customGroupBAO->save();
     $customGroup->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group['title'], '_', 32));
     $customGroup->table_name = $customGroup->table_name . '_' . $customGroup->id;
     $customGroup = $customGroupBAO->save();
     $customTable = CRM_Core_BAO_CustomGroup::createTable($customGroup);
     return $customGroup;
 }
コード例 #13
0
 /**
  * Class constructor
  * 
  * @param     string    Input field name attribute
  * @param     mixed     Label(s) for a field
  * @param     string    Text to display near the radio
  * @param     string    Input field value
  * @param     mixed     Either a typical HTML attribute string or an associative array
  * @since     1.0
  * @access    public
  * @return    void
  */
 function HTML_QuickForm_radio($elementName = null, $elementLabel = null, $text = null, $value = null, $attributes = null)
 {
     $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     if (isset($value)) {
         $this->setValue($value);
     }
     $this->_persistantFreeze = true;
     $this->setType('radio');
     $this->_text = $text;
     // $this->_generateId();
     if (!$this->getAttribute('id')) {
         //hack to add 'id' for checkbox
         static $idTextStr = 1;
         $this->updateAttributes(array('id' => CRM_Utils_String::munge("CIVICRM_QFID_{$value}_{$idTextStr}")));
         $idTextStr++;
     }
 }
コード例 #14
0
ファイル: Job.php プロジェクト: archcidburnziso/civicrm-core
 static function formRule($fields)
 {
     $errors = array();
     require_once 'api/api.php';
     $apiRequest = array();
     $apiRequest['entity'] = CRM_Utils_String::munge($fields['api_entity']);
     $apiRequest['action'] = CRM_Utils_String::munge($fields['api_action']);
     $apiRequest['version'] = 3;
     $apiRequest += _civicrm_api_resolve($apiRequest);
     // look up function, file, is_generic
     if (!$apiRequest['function']) {
         $errors['api_action'] = ts('Given API command is not defined.');
     }
     if (!empty($errors)) {
         return $errors;
     }
     return empty($errors) ? TRUE : $errors;
 }
コード例 #15
0
ファイル: Joomla.php プロジェクト: hguru/224Civi
 /**
  * @param string $name e.g. "administer CiviCRM", "cms:access user record", "Drupal:administer content", "Joomla:example.action:com_some_asset"
  * @return ALWAYS_DENY_PERMISSION|ALWAYS_ALLOW_PERMISSION|array(0 => $joomlaAction, 1 => $joomlaAsset)
  */
 function translateJoomlaPermission($perm)
 {
     if ($perm === CRM_Core_Permission::ALWAYS_DENY_PERMISSION || $perm === CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
         return $perm;
     }
     list($civiPrefix, $name) = CRM_Utils_String::parsePrefix(':', $perm, NULL);
     switch ($civiPrefix) {
         case 'Joomla':
             return explode(':', $name);
         case 'cms':
             // FIXME: This needn't be DENY, but we don't currently have any translations.
             return CRM_Core_Permission::ALWAYS_DENY_PERMISSION;
         case NULL:
             return array('civicrm.' . CRM_Utils_String::munge(strtolower($name)), 'com_civicrm');
         default:
             return CRM_Core_Permission::ALWAYS_DENY_PERMISSION;
     }
 }
コード例 #16
0
ファイル: HRAbsenceType.php プロジェクト: JoeMurray/civihr
 public static function create($params)
 {
     $entityName = 'HRAbsenceType';
     $hook = empty($params['id']) ? 'create' : 'edit';
     if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) {
         $params['name'] = CRM_Utils_String::munge($params['title']);
     }
     // If this is an existing type, we'll need to know about previously linked activity-type-ids
     if (!empty($params['id'])) {
         $existing = civicrm_api3('HRAbsenceType', 'getsingle', array('id' => $params['id']));
         $params = array_merge($existing, $params);
     }
     $activityTypesResult = civicrm_api3('activity_type', 'get', array());
     if (CRM_Utils_Array::value('allow_debits', $params) && empty($params['debit_activity_type_id'])) {
         $weight = count($activityTypesResult["values"]);
         $debitActivityLabel = $params['name'];
         $debitActivityTypeId = array_search($debitActivityLabel, $activityTypesResult["values"]);
         if (!$debitActivityTypeId) {
             $weight = $weight + 1;
             $paramsCreate = array('weight' => $weight, 'label' => $debitActivityLabel, 'filter' => 1, 'is_active' => 1, 'is_optgroup' => 0, 'is_default' => 0, 'grouping' => 'Timesheet');
             $resultCreateActivityType = civicrm_api3('activity_type', 'create', $paramsCreate);
             $debitActivityTypeId = $resultCreateActivityType['values'][$resultCreateActivityType["id"]]['value'];
         }
         $params["debit_activity_type_id"] = $debitActivityTypeId;
     }
     if (CRM_Utils_Array::value('allow_credits', $params) && empty($params["credit_activity_type_id"])) {
         $weight = count($activityTypesResult["values"]);
         $creditActivityLabel = ts('%1 (Credit)', array(1 => $params["name"]));
         $creditActivityTypeId = array_search($creditActivityLabel, $activityTypesResult["values"]);
         if (!$creditActivityTypeId) {
             $weight = $weight + 1;
             $paramsCreate = array('weight' => $weight, 'label' => $creditActivityLabel, 'filter' => 1, 'is_active' => 1, 'is_optgroup' => 0, 'is_default' => 0, 'grouping' => 'Timesheet');
             $resultCreateActivityType = civicrm_api3('activity_type', 'create', $paramsCreate);
             $creditActivityTypeId = $resultCreateActivityType['values'][$resultCreateActivityType["id"]]['value'];
             $params["credit_activity_type_id"] = $creditActivityTypeId;
         }
     }
     CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
     $instance = new self();
     $instance->copyValues($params);
     $instance->save();
     CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
     return $instance;
 }
コード例 #17
0
/**
 * @param $version
 */
function generateJoomlaConfig($version)
{
    global $targetDir, $sourceCheckoutDir, $pkgType;
    $smarty = new Smarty();
    $smarty->template_dir = $sourceCheckoutDir . '/xml/templates';
    $smarty->compile_dir = '/tmp/templates_c_u' . posix_geteuid();
    createDir($smarty->compile_dir);
    $smarty->assign('CiviCRMVersion', $version);
    $smarty->assign('creationDate', date('F d Y'));
    $smarty->assign('pkgType', $pkgType);
    $xml = $smarty->fetch('joomla.tpl');
    $output = $targetDir . '/civicrm.xml';
    $fd = fopen($output, "w");
    fputs($fd, $xml);
    fclose($fd);
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton(FALSE);
    require_once 'CRM/Core/Permission.php';
    require_once 'CRM/Utils/String.php';
    $permissions = CRM_Core_Permission::getCorePermissions();
    $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM';
    require_once 'CRM/Core/Component.php';
    $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir);
    foreach ($components as $comp) {
        $perm = $comp->getPermissions();
        if ($perm) {
            $info = $comp->getInfo();
            foreach ($perm as $p) {
                $permissions[$p] = $info['translatedName'] . ': ' . $p;
            }
        }
    }
    $perms_array = array();
    foreach ($permissions as $perm => $title) {
        //order matters here, but we deal with that later
        $perms_array[CRM_Utils_String::munge(strtolower($perm))] = $title;
    }
    $smarty->assign('permissions', $perms_array);
    $output = $targetDir . '/admin/access.xml';
    $xml = $smarty->fetch('access.tpl');
    $fd = fopen($output, "w");
    fputs($fd, $xml);
    fclose($fd);
}
コード例 #18
0
 /**
  *  This function is called to create name label pdf.
  *
  * @param array $participants
  *   Associated array with participant info.
  * @param array $layoutInfo
  *   Associated array which contains meta data about format/layout.
  *
  * @return void
  */
 public function createLabels(&$participants, &$layoutInfo)
 {
     $this->pdf = new CRM_Utils_PDF_Label($layoutInfo['format'], 'mm');
     $this->pdf->Open();
     $this->pdf->setPrintHeader(FALSE);
     $this->pdf->setPrintFooter(FALSE);
     $this->pdf->AddPage();
     $this->pdf->SetGenerator($this, "generateLabel");
     // this is very useful for debugging, by default set to FALSE
     if ($this->debug) {
         $this->border = "LTRB";
     }
     foreach ($participants as $participant) {
         $formattedRow = self::formatLabel($participant, $layoutInfo);
         $this->pdf->AddPdfLabel($formattedRow);
     }
     $this->pdf->Output(CRM_Utils_String::munge($layoutInfo['title'], '_', 64) . '.pdf', 'D');
     CRM_Utils_System::civiExit(1);
 }
コード例 #19
0
/**
 * Create a new Action Schedule
 *
 * @param array $params
 *
 * @return array
 *
 * {@getfields action_schedule_create}
 */
function civicrm_api3_action_schedule_create($params)
{
    if (empty($params['id'])) {
        // an update does not require any mandatory parameters
        civicrm_api3_verify_one_mandatory($params, NULL, array('title', 'mapping_id', 'entity_status', 'entity_value'));
    }
    $ids = array();
    if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_api3_create_error('Invalid value for ID');
    }
    if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) {
        $params['name'] = CRM_Utils_String::munge($params['title']);
    }
    $actionSchedule = new CRM_Core_BAO_ActionSchedule();
    $actionSchedule = CRM_Core_BAO_ActionSchedule::add($params, $ids);
    $actSchedule = array();
    _civicrm_api3_object_to_array($actionSchedule, $actSchedule[$actionSchedule->id]);
    return civicrm_api3_create_success($actSchedule, $params, 'action_schedule', 'create', $actionSchedule);
}
コード例 #20
0
 /**
  * Given a permission string, check for access requirements
  *
  * @param string $str
  *   The permission to check.
  *
  * @return bool
  *   true if yes, else false
  */
 public function check($str)
 {
     // Generic cms 'administer users' role tranlates to 'administrator' WordPress role
     $str = $this->translatePermission($str, 'WordPress', array('administer users' => 'edit_users'));
     if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
         return FALSE;
     }
     if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
         return TRUE;
     }
     // CRM-15629
     // During some extern/* calls we don't bootstrap CMS hence
     // below constants are not set. In such cases, we don't need to
     // check permission, hence directly return TRUE
     if (!defined('ABSPATH') || !defined('WPINC')) {
         require_once 'CRM/Utils/System.php';
         CRM_Utils_System::loadBootStrap();
     }
     require_once ABSPATH . WPINC . '/pluggable.php';
     // for administrators give them all permissions
     if (!function_exists('current_user_can')) {
         return TRUE;
     }
     if (current_user_can('super admin') || current_user_can('administrator')) {
         return TRUE;
     }
     // Make string lowercase and convert spaces into underscore
     $str = CRM_Utils_String::munge(strtolower($str));
     if (is_user_logged_in()) {
         // Check whether the logged in user has the capabilitity
         if (current_user_can($str)) {
             return TRUE;
         }
     } else {
         //check the capabilities of Anonymous user)
         $roleObj = new WP_Roles();
         if ($roleObj->get_role('anonymous_user') != NULL && array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)) {
             return TRUE;
         }
     }
     return FALSE;
 }
コード例 #21
0
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Queryrunner_DAO_Query');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Queryrunner_BAO_Query::del($this->_id);
         CRM_Core_Session::setStatus("", ts('Query Deleted.'), "success");
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     $ts = strtotime(trim("{$values['scheduled_run_date']} {$values['scheduled_run_date_time']}"));
     $dao = new CRM_Queryrunner_DAO_Query();
     $dao->id = $this->_id;
     $dao->name = $values['name'];
     $dao->machine_name = strtolower(CRM_Utils_String::munge($dao->name, '_', null));
     $dao->description = $values['description'];
     $dao->query = $values['query'];
     $dao->run_frequency = $values['run_frequency'];
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->scheduled_run = $ts ?: 0;
     $dao->save();
 }
コード例 #22
0
function civicrm_api3_generic_getActions($params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('entity'));
    $r = civicrm_api('Entity', 'Get', array('version' => 3));
    $entity = CRM_Utils_String::munge($params['entity']);
    if (!in_array($entity, $r['values'])) {
        return civicrm_api3_create_error("Entity " . $entity . " invalid. Use api.entity.get to have the list", array('entity' => $r['values']));
    }
    _civicrm_api_loadEntity($entity);
    $functions = get_defined_functions();
    $actions = array();
    $prefix = 'civicrm_api3_' . strtolower($entity) . '_';
    $prefixGeneric = 'civicrm_api3_generic_';
    foreach ($functions['user'] as $fct) {
        if (strpos($fct, $prefix) === 0) {
            $actions[] = substr($fct, strlen($prefix));
        } elseif (strpos($fct, $prefixGeneric) === 0) {
            $actions[] = substr($fct, strlen($prefixGeneric));
        }
    }
    return civicrm_api3_create_success($actions);
}
コード例 #23
0
ファイル: XMLProcessor.php プロジェクト: bhirsch/voipdev
 function retrieve($caseType)
 {
     require_once 'CRM/Utils/String.php';
     require_once 'CRM/Utils/Array.php';
     // trim all spaces from $caseType
     $caseType = str_replace('_', ' ', $caseType);
     $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
     if (!CRM_Utils_Array::value($caseType, self::$_xml)) {
         if (!self::$_xml) {
             self::$_xml = array();
         }
         // ensure that the file exists
         $fileName = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'xml', 'configuration', "{$caseType}.xml"));
         if (!file_exists($fileName)) {
             return false;
         }
         // read xml file
         $dom = DomDocument::load($fileName);
         $dom->xinclude();
         self::$_xml[$caseType] = simplexml_import_dom($dom);
     }
     return self::$_xml[$caseType];
 }
コード例 #24
0
ファイル: radio.php プロジェクト: bhirsch/voipdev
 /**
  * Class constructor
  * 
  * @param     string    Input field name attribute
  * @param     mixed     Label(s) for a field
  * @param     string    Text to display near the radio
  * @param     string    Input field value
  * @param     mixed     Either a typical HTML attribute string or an associative array
  * @since     1.0
  * @access    public
  * @return    void
  */
 function HTML_QuickForm_radio($elementName = null, $elementLabel = null, $text = null, $value = null, $attributes = null)
 {
     $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     if (isset($value)) {
         $this->setValue($value);
     }
     $this->_persistantFreeze = true;
     $this->setType('radio');
     $this->_text = $text;
     // $this->_generateId();
     if (!$this->getAttribute('id')) {
         static $idTextStr = 1;
         //hack to add 'id' for checkbox
         if (empty($text)) {
             $idText = $idTextStr++;
         } else {
             // use only first 8 characters of text
             $idText = substr($text, 0, 7);
         }
         $idValue = CRM_Utils_String::munge("CIVICRM_QFID_{$value}_{$idText}");
         $this->updateAttributes(array('id' => CRM_Utils_String::munge("CIVICRM_QFID_{$value}_{$idText}")));
     }
 }
コード例 #25
0
ファイル: Export.php プロジェクト: jenlampton/civicrm-core
 /**
  * Merge household record into the individual record
  * if exists
  *
  * @param string $exportTempTable
  *   Temporary temp table that stores the records.
  * @param array $headerRows
  *   Array of headers for the export file.
  * @param array $sqlColumns
  *   Array of names of the table columns of the temp table.
  * @param string $prefix
  *   Name of the relationship type that is prefixed to the table columns.
  */
 public static function mergeSameHousehold($exportTempTable, &$headerRows, &$sqlColumns, $prefix)
 {
     $prefixColumn = $prefix . '_';
     $allKeys = array_keys($sqlColumns);
     $replaced = array();
     $headerRows = array_values($headerRows);
     // name map of the non standard fields in header rows & sql columns
     $mappingFields = array('civicrm_primary_id' => 'id', 'contact_source' => 'source', 'current_employer_id' => 'employer_id', 'contact_is_deleted' => 'is_deleted', 'name' => 'address_name', 'provider_id' => 'im_service_provider', 'phone_type_id' => 'phone_type');
     //figure out which columns are to be replaced by which ones
     foreach ($sqlColumns as $columnNames => $dontCare) {
         if ($rep = CRM_Utils_Array::value($columnNames, $mappingFields)) {
             $replaced[$columnNames] = CRM_Utils_String::munge($prefixColumn . $rep, '_', 64);
         } else {
             $householdColName = CRM_Utils_String::munge($prefixColumn . $columnNames, '_', 64);
             if (!empty($sqlColumns[$householdColName])) {
                 $replaced[$columnNames] = $householdColName;
             }
         }
     }
     $query = "UPDATE {$exportTempTable} SET ";
     $clause = array();
     foreach ($replaced as $from => $to) {
         $clause[] = "{$from} = {$to} ";
         unset($sqlColumns[$to]);
         if ($key = CRM_Utils_Array::key($to, $allKeys)) {
             unset($headerRows[$key]);
         }
     }
     $query .= implode(",\n", $clause);
     $query .= " WHERE {$replaced['civicrm_primary_id']} != ''";
     CRM_Core_DAO::executeQuery($query);
     //drop the table columns that store redundant household info
     $dropQuery = "ALTER TABLE {$exportTempTable} ";
     foreach ($replaced as $householdColumns) {
         $dropClause[] = " DROP {$householdColumns} ";
     }
     $dropQuery .= implode(",\n", $dropClause);
     CRM_Core_DAO::executeQuery($dropQuery);
     // also drop the temp table if exists
     $sql = "DROP TABLE IF EXISTS {$exportTempTable}_temp";
     CRM_Core_DAO::executeQuery($sql);
     // clean up duplicate records
     $query = "\nCREATE TABLE {$exportTempTable}_temp SELECT *\nFROM {$exportTempTable}\nGROUP BY civicrm_primary_id ";
     CRM_Core_DAO::executeQuery($query);
     $query = "DROP TABLE {$exportTempTable}";
     CRM_Core_DAO::executeQuery($query);
     $query = "ALTER TABLE {$exportTempTable}_temp RENAME TO {$exportTempTable}";
     CRM_Core_DAO::executeQuery($query);
 }
コード例 #26
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         // delete reminder
         CRM_Core_BAO_ActionSchedule::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
         return;
     }
     $values = $this->controller->exportValues($this->getName());
     $keys = array('title', 'subject', 'absolute_date', 'group_id', 'record_activity', 'limit_to');
     foreach ($keys as $key) {
         $params[$key] = CRM_Utils_Array::value($key, $values);
     }
     $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date');
     if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
         $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
         foreach ($moreKeys as $mkey) {
             $params[$mkey] = 'null';
         }
     } else {
         $params['absolute_date'] = 'null';
         foreach ($moreKeys as $mkey) {
             $params[$mkey] = CRM_Utils_Array::value($mkey, $values);
         }
     }
     $params['body_text'] = CRM_Utils_Array::value('text_message', $values);
     $params['body_html'] = CRM_Utils_Array::value('html_message', $values);
     if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
         $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
         $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
     } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
         $params['group_id'] = $values['group_id'];
         $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
     } elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) {
         $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
         $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values));
         $params['group_id'] = $params['recipient_manual'] = 'null';
     } else {
         $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
         $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
     }
     $params['mapping_id'] = $this->_mappingID;
     $params['entity_value'] = $this->_id;
     $params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
     $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
     if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
         $params['repetition_frequency_unit'] = 'null';
         $params['repetition_frequency_interval'] = 'null';
         $params['end_frequency_unit'] = 'null';
         $params['end_frequency_interval'] = 'null';
         $params['end_action'] = 'null';
         $params['end_date'] = 'null';
     }
     $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = NULL;
     //mail template is composed
     $composeParams = array();
     foreach ($composeFields as $key) {
         if (!empty($values[$key])) {
             $composeParams[$key] = $values[$key];
         }
     }
     if (!empty($composeParams['updateTemplate'])) {
         $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
         $templateParams['id'] = $values['template'];
         $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
     }
     if (!empty($composeParams['saveTemplate'])) {
         $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
         $templateParams['msg_title'] = $composeParams['saveTemplateName'];
         $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
     }
     if (isset($msgTemplate->id)) {
         $params['msg_template_id'] = $msgTemplate->id;
     } else {
         $params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
     }
     CRM_Core_BAO_ActionSchedule::add($params, $ids);
     $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>"));
     CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
     parent::endPostProcess();
 }
コード例 #27
0
ファイル: Fee.php プロジェクト: saurabhbatra96/civicrm-core
 /**
  * Process the form.
  */
 public function postProcess()
 {
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (!empty($_POST['_qf_Fee_submit'])) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (!empty($params['payment_processor'])) {
         $params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     $params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         //@todo note that this removes the reference from existing participants -
         // even where there is not change - redress?
         // note that a more tentative form of this is invoked by passing price_set_id as an array
         // to event.create see CRM-14069
         // @todo get all of this logic out of form layer (currently partially in BAO/api layer)
         if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (!empty($params['price_set_id'])) {
             //@todo this is now being done in the event BAO if passed price_set_id as an array
             // per notes on that fn - looking at the api converting to an array
             // so calling via the api may cause this to be done in the api
             CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (!empty($params['price_field_id'])) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (empty($params['price_set_id'])) {
                         if (empty($params['price_field_id'])) {
                             $setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             $eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode('.', microtime(TRUE));
                                 $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['financial_type_id'] = $params['financial_type_id'];
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet = new CRM_Price_BAO_PriceSet();
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                             if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                 CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
                             }
                         }
                         $fieldParams['label'] = $params['fee_label'];
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = $params['financial_type_id'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = !empty($this->_defaultValues['discount_price_set']) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = !empty($this->_defaultValues['discount_option_id']) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             $setParams = array();
                             if (empty($discountPriceSets[$keyCheck])) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode('.', microtime(TRUE));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['financial_type_id'] = $params['financial_type_id'];
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 $setParams = array('title' => $params['discount_name'][$j], 'id' => $priceSetID);
                                 if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                     $setParams['financial_type_id'] = $params['financial_type_id'];
                                 }
                                 CRM_Price_BAO_PriceSet::create($setParams);
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             $fieldParams['financial_type_id'] = $params['financial_type_id'];
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (!empty($value['is_default'])) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
                                     unset($discountFieldIDs[$j][$value['weight']]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                             if (!empty($discountFieldIDs[$j])) {
                                 foreach ($discountFieldIDs[$j] as $fID) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'price_set_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]), 'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (!empty($params['price_field_id'])) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
         }
         $params['financial_type_id'] = '';
         $params['is_pay_later'] = 0;
         $params['is_billing_required'] = 0;
     }
     //update 'is_billing_required'
     if (empty($params['is_pay_later'])) {
         $params['is_billing_required'] = FALSE;
     }
     //update events table
     $params['id'] = $this->_id;
     // skip update of financial type in price set
     $params['skipFinancialType'] = TRUE;
     CRM_Event_BAO_Event::add($params);
     // Update tab "disabled" css class
     $this->ajaxResponse['tabValid'] = !empty($params['is_monetary']);
     parent::endPostProcess();
 }
コード例 #28
0
 /**
  * takes an associative array and creates a price field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_PriceField object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     if (empty($params['id']) && empty($params['name'])) {
         $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
     }
     $transaction = new CRM_Core_Transaction();
     $priceField = self::add($params);
     if (is_a($priceField, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $priceField;
     }
     $optionsIds = array();
     $maxIndex = CRM_Price_Form_Field::NUM_OPTION;
     if ($priceField->html_type == 'Text') {
         $maxIndex = 1;
         $fieldValue = new CRM_Price_DAO_PriceFieldValue();
         $fieldValue->price_field_id = $priceField->id;
         // update previous field values( if any )
         if ($fieldValue->find(TRUE)) {
             $optionsIds['id'] = $fieldValue->id;
         }
     }
     $defaultArray = array();
     //html type would be empty in update scenario not sure what would happen ...
     if (!empty($params['html_type']) && $params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         foreach ($tempArray as $v) {
             if ($params['option_amount'][$v]) {
                 $defaultArray[$v] = 1;
             }
         }
     } else {
         if (!empty($params['default_option'])) {
             $defaultArray[$params['default_option']] = 1;
         }
     }
     for ($index = 1; $index <= $maxIndex; $index++) {
         if (array_key_exists('option_amount', $params) && array_key_exists($index, $params['option_amount']) && (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_label', $params)) || !empty($params['is_quick_config'])) && !CRM_Utils_System::isNull($params['option_amount'][$index])) {
             $options = array('price_field_id' => $priceField->id, 'label' => trim($params['option_label'][$index]), 'name' => CRM_Utils_String::munge($params['option_label'][$index], '_', 64), 'amount' => CRM_Utils_Rule::cleanMoney(trim($params['option_amount'][$index])), 'count' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_count', $params), NULL), 'max_value' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_max_value', $params), NULL), 'description' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_description', $params), NULL), 'membership_type_id' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_type_id', $params), NULL), 'weight' => $params['option_weight'][$index], 'is_active' => 1, 'is_default' => CRM_Utils_Array::value($params['option_weight'][$index], $defaultArray) ? $defaultArray[$params['option_weight'][$index]] : 0, 'membership_num_terms' => NULL);
             if ($options['membership_type_id']) {
                 $options['membership_num_terms'] = CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_num_terms', $params), 1);
             }
             if (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_financial_type_id', $params))) {
                 $options['financial_type_id'] = $params['option_financial_type_id'][$index];
             } elseif (!empty($params['financial_type_id'])) {
                 $options['financial_type_id'] = $params['financial_type_id'];
             }
             if ($opIds = CRM_Utils_Array::value('option_id', $params)) {
                 if ($opId = CRM_Utils_Array::value($index, $opIds)) {
                     $optionsIds['id'] = $opId;
                 } else {
                     $optionsIds['id'] = NULL;
                 }
             }
             CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
         }
     }
     $transaction->commit();
     return $priceField;
 }
コード例 #29
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         // delete reminder
         CRM_Core_BAO_ActionSchedule::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'));
         if ($this->_context == 'event' && $this->_eventId) {
             $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}");
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext($url);
         }
         return;
     }
     $values = $this->controller->exportValues($this->getName());
     $keys = array('title', 'subject', 'absolute_date', 'group_id');
     foreach ($keys as $key) {
         $params[$key] = CRM_Utils_Array::value($key, $values);
     }
     $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date');
     if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
         $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
         foreach ($moreKeys as $mkey) {
             $params[$mkey] = 'null';
         }
     } else {
         $params['absolute_date'] = 'null';
         foreach ($moreKeys as $mkey) {
             $params[$mkey] = CRM_Utils_Array::value($mkey, $values);
         }
     }
     $params['body_text'] = CRM_Utils_Array::value('text_message', $values);
     $params['body_html'] = CRM_Utils_Array::value('html_message', $values);
     if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
         $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
         $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
     } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
         $params['group_id'] = $values['group_id'];
         $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
     } elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) {
         $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
         $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values));
         $params['group_id'] = $params['recipient_manual'] = 'null';
     } else {
         $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
         $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
     }
     $params['mapping_id'] = $values['entity'][0];
     $entity_value = $values['entity'][1];
     $entity_status = $values['entity'][2];
     //force recording activity for membership reminder
     if ($params['mapping_id'] == 4) {
         $params['record_activity'] = 1;
     }
     foreach (array('entity_value', 'entity_status') as $key) {
         $params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, ${$key});
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
     $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
     if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
         $params['repetition_frequency_unit'] = 'null';
         $params['repetition_frequency_interval'] = 'null';
         $params['end_frequency_unit'] = 'null';
         $params['end_frequency_interval'] = 'null';
         $params['end_action'] = 'null';
         $params['end_date'] = 'null';
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         // we do this only once, so name never changes
         $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
     }
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = NULL;
     //mail template is composed
     $composeParams = array();
     foreach ($composeFields as $key) {
         if (CRM_Utils_Array::value($key, $values)) {
             $composeParams[$key] = $values[$key];
         }
     }
     if (CRM_Utils_Array::value('updateTemplate', $composeParams)) {
         $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
         $templateParams['id'] = $values['template'];
         $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
     }
     if (CRM_Utils_Array::value('saveTemplate', $composeParams)) {
         $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
         $templateParams['msg_title'] = $composeParams['saveTemplateName'];
         $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
     }
     if (isset($msgTemplate->id)) {
         $params['msg_template_id'] = $msgTemplate->id;
     } else {
         $params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
     }
     CRM_Core_BAO_ActionSchedule::add($params, $ids);
     $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>"));
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $status = ts("Your Reminder titled %1 has been updated.", array(1 => "<strong>{$values['title']}</strong>"));
         if ($this->_context == 'event' && $this->_eventId) {
             $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}");
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext($url);
         }
     }
     CRM_Core_Session::setStatus($status);
 }
コード例 #30
0
 /**
  * Get Activity specific File according activity type Id.
  *
  * @param int $activityTypeId
  *   Activity id.
  * @param string $crmDir
  *
  * @return string|bool
  *   if file exists returns $activityTypeFile activity filename otherwise false.
  */
 public static function getFileForActivityTypeId($activityTypeId, $crmDir = 'Activity')
 {
     $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE);
     if ($activityTypes[$activityTypeId]['name']) {
         $activityTypeFile = CRM_Utils_String::munge(ucwords($activityTypes[$activityTypeId]['name']), '', 0);
     } else {
         return FALSE;
     }
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     if (!file_exists(rtrim($civicrm_root, '/') . "/CRM/{$crmDir}/Form/Activity/{$activityTypeFile}.php")) {
         if (empty($config->customPHPPathDir)) {
             return FALSE;
         } elseif (!file_exists(rtrim($config->customPHPPathDir, '/') . "/CRM/{$crmDir}/Form/Activity/{$activityTypeFile}.php")) {
             return FALSE;
         }
     }
     return $activityTypeFile;
 }