Example #1
0
 /**
  * Perform an upgrade without using the web-frontend
  *
  * @param bool $enablePrint
  *
  * @throws Exception
  * @return array, with keys:
  *   - message: string, HTML-ish blob
  */
 public function run($enablePrint = TRUE)
 {
     // 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();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         throw new Exception($error);
     }
     // Disable our SQL triggers
     CRM_Core_DAO::dropTriggers();
     // CRM-11156
     $preUpgradeMessage = NULL;
     $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
     $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile)));
     $queueResult = $queueRunner->runAll();
     if ($queueResult !== TRUE) {
         $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
         CRM_Core_Error::debug_log_message($errorMessage);
         if ($enablePrint) {
             print $errorMessage;
         }
         throw $queueResult['exception'];
         // FIXME test
     }
     CRM_Upgrade_Form::doFinish();
     $message = file_get_contents($postUpgradeMessageFile);
     return array('latestVer' => $latestVer, 'message' => $message, 'text' => CRM_Utils_String::htmlToText($message));
 }
 /**
  * Determine if an API request should be treated as transactional
  *
  * @param \Civi\API\Provider\ProviderInterface $apiProvider
  * @param array $apiRequest
  * @return bool
  */
 public function isTransactional($apiProvider, $apiRequest)
 {
     if (isset($apiRequest['params']['is_transactional'])) {
         return \CRM_Utils_String::strtobool($apiRequest['params']['is_transactional']);
     }
     return strtolower($apiRequest['action']) == 'create' || strtolower($apiRequest['action']) == 'delete' || strtolower($apiRequest['action']) == 'submit';
 }
Example #3
0
 public static function mungeCaseType($caseType)
 {
     // trim all spaces from $caseType
     $caseType = str_replace('_', ' ', $caseType);
     $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
     return $caseType;
 }
Example #4
0
 /**
  * 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();
 }
 /**
  * @param CRM_Core_Form $form
  *
  * @return array
  */
 public static function process(&$form)
 {
     if ($form->getVar('_surveyId') <= 0) {
         return NULL;
     }
     $tabs = array('main' => array('title' => ts('Main Information'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'questions' => array('title' => ts('Questions'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'results' => array('title' => ts('Results'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE));
     $surveyID = $form->getVar('_surveyId');
     $class = $form->getVar('_name');
     $class = CRM_Utils_String::getClassName($class);
     $class = strtolower($class);
     if (array_key_exists($class, $tabs)) {
         $tabs[$class]['current'] = TRUE;
         $qfKey = $form->get('qfKey');
         if ($qfKey) {
             $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
         }
     }
     if ($surveyID) {
         $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
         foreach ($tabs as $key => $value) {
             if (!isset($tabs[$key]['qfKey'])) {
                 $tabs[$key]['qfKey'] = NULL;
             }
             $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}", "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}");
             $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
         }
     }
     return $tabs;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * @return string
  */
 public static function getFilePrefix()
 {
     if (!self::$filePrefix) {
         self::$filePrefix = "test_" . CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_';
     }
     return self::$filePrefix;
 }
Example #8
0
 /**
  * Get a unique ID for the request.
  *
  * This unique ID is assigned to mysql when the connection is opened and is
  * available in PHP.
  *
  * The intent is that it is available for logging purposes and for triggers.
  *
  * The resulting string is 17 characters long. This consists of 13 characters of uniqid
  * and 4 more random characters.
  *
  * Uniqid is unique to the microsecond - to make it more unique we add 4 more characters
  * but stop short of the full 23 character string that a prefix would generate.
  *
  * It is intended that this string will be saved to log tables so striking a balance between
  * uniqueness and length is important. Note that I did check & lining up with byte values
  * (e.g 16 characters) does not confer any benefits. Using a CHAR field rather than VARCHAR
  * may improve speed, if indexed.
  *
  * @return string
  */
 public static function id()
 {
     if (!isset(\Civi::$statics[__CLASS__]['id'])) {
         \Civi::$statics[__CLASS__]['id'] = uniqid() . CRM_Utils_String::createRandom(CRM_Utils_String::ALPHANUMERIC, 4);
     }
     return \Civi::$statics[__CLASS__]['id'];
 }
 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;
 }
Example #10
0
/**
 * 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();
}
 function testHtmlToText()
 {
     foreach ($this->_testInput as $html => $text) {
         $output = CRM_Utils_String::htmlToText($html);
         $this->assertEquals(trim($output), trim($text), "Text Output did not match for {$html}");
     }
 }
Example #12
0
 public function postProcess()
 {
     $values = $this->exportValues();
     // check if EmailTyped matches Email address
     $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE);
     $job_id = $this->_job_id;
     $queue_id = $this->_queue_id;
     $hash = $this->_hash;
     $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
     $this->assign('confirmURL', $confirmURL);
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext($confirmURL);
     if ($result == TRUE) {
         // Email address verified
         if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
             CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
         }
         $statusMsg = ts('Email: %1 has been successfully opted out', array(1 => $values['email_confirm']));
         CRM_Core_Session::setStatus($statusMsg, '', 'success');
     } elseif ($result == FALSE) {
         // Email address not verified
         $statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.', array(1 => $values['email_confirm']));
         CRM_Core_Session::setStatus($statusMsg, '', 'fail');
     }
 }
 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];
 }
/**
 * 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})");
    }
}
/**
 * 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');
}
Example #16
0
 /**
  * Instantiate a signature-processor
  *
  * @param $secret string, private
  * @param $paramNames array, fields which should be part of the signature
  */
 function __construct($secret, $paramNames)
 {
     sort($paramNames);
     // ensure consistent serialization of payloads
     $this->secret = $secret;
     $this->paramNames = $paramNames;
     $this->signDelim = "_";
     // chosen to be valid in URLs but not in salt or md5
     $this->defaultSalt = CRM_Utils_String::createRandom(self::SALT_LEN, CRM_Utils_String::ALPHANUMERIC);
 }
 /**
  * Create a new batch
  *
  * @return batch array
  * @access public
  */
 static function create(&$params)
 {
     if (!CRM_Utils_Array::value('id', $params)) {
         $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
     $batch = new CRM_Core_DAO_Batch();
     $batch->copyValues($params);
     $batch->save();
     return $batch;
 }
Example #18
0
/**
 * 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);
}
Example #19
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();
 }
Example #20
0
 /**
  * Create a new batch.
  *
  * @param array $params
  * @param array $ids
  *   Associated array of ids.
  * @param string $context
  *   String.
  *
  * @return object
  *   $batch batch object
  */
 public static function create(&$params, $ids = NULL, $context = NULL)
 {
     if (empty($params['id'])) {
         $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
     $batch = new CRM_Batch_DAO_Batch();
     $batch->copyValues($params);
     if ($context == 'financialBatch' && !empty($ids['batchID'])) {
         $batch->id = $ids['batchID'];
     }
     $batch->save();
     return $batch;
 }
Example #21
0
 /**
  * @param CRM_Core_Form $form
  *
  * @return array
  */
 public static function process(&$form)
 {
     if ($form->getVar('_id') <= 0) {
         return NULL;
     }
     $tabs = array('settings' => array('title' => ts('Title'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'amount' => array('title' => ts('Amounts'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'membership' => array('title' => ts('Memberships'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'thankyou' => array('title' => ts('Receipt'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'friend' => array('title' => ts('Tell a Friend'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'custom' => array('title' => ts('Profiles'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'premium' => array('title' => ts('Premiums'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'widget' => array('title' => ts('Widgets'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'pcp' => array('title' => ts('Personal Campaigns'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE));
     $contribPageId = $form->getVar('_id');
     CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, array('contribution_page_id' => $contribPageId));
     $fullName = $form->getVar('_name');
     $className = CRM_Utils_String::getClassName($fullName);
     // Hack for special cases.
     switch ($className) {
         case 'Contribute':
             $attributes = $form->getVar('_attributes');
             $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
             break;
         case 'MembershipBlock':
             $class = 'membership';
             break;
         default:
             $class = strtolower($className);
             break;
     }
     if (array_key_exists($class, $tabs)) {
         $tabs[$class]['current'] = TRUE;
         $qfKey = $form->get('qfKey');
         if ($qfKey) {
             $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
         }
     }
     if ($contribPageId) {
         $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
         foreach ($tabs as $key => $value) {
             if (!isset($tabs[$key]['qfKey'])) {
                 $tabs[$key]['qfKey'] = NULL;
             }
             $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/admin/contribute/{$key}", "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}");
             $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
         }
         //get all section info.
         $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId));
         foreach ($contriPageInfo[$contribPageId] as $section => $info) {
             if (!$info) {
                 $tabs[$section]['valid'] = FALSE;
             }
         }
     }
     return $tabs;
 }
/**
 * Generate the html for a button-style link
 *
 * @param array $params
 *   Params of the {crmButton} call.
 * @param string $text
 *   Contents of block.
 * @param CRM_Core_Smarty $smarty
 *   The Smarty object.
 *
 * @return string
 *   The generated html.
 */
function smarty_block_crmButton($params, $text, &$smarty)
{
    // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes)
    if (empty($params['href'])) {
        $params['href'] = CRM_Utils_System::crmURL($params + array('h' => FALSE));
    }
    // Always add class 'button' - fixme probably should be crm-button
    $params['class'] = empty($params['class']) ? 'button' : 'button ' . $params['class'];
    // Any FA icon works
    $icon = CRM_Utils_Array::value('icon', $params, 'pencil');
    // All other params are treated as html attributes
    CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe');
    $attributes = CRM_Utils_String::htmlAttributes($params);
    return "<a {$attributes}><span><i class='crm-i fa-{$icon}'></i>&nbsp; {$text}</span></a>";
}
Example #23
0
 public function run($ctx)
 {
     $allKeys = \CRM_Extension_System::singleton()->getFullContainer()->getKeys();
     $names = \CRM_Utils_String::filterByWildcards($this->names, $allKeys, TRUE);
     $manager = \CRM_Extension_System::singleton()->getManager();
     switch ($this->action) {
         case 'install':
             $manager->install($names);
             break;
         case 'uninstall':
             $manager->disable($names);
             $manager->uninstall($names);
             break;
     }
 }
Example #24
0
 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;
 }
Example #25
0
File: Base.php Project: kidaa30/yes
 /**
  * Translate permission.
  *
  * @param string $perm
  *   Permission string e.g "administer CiviCRM", "cms:access user record", "Drupal:administer content",
  *   "Joomla:action:com_asset"
  *
  * @param string $nativePrefix
  * @param array $map
  *   Array($portableName => $nativeName).
  *
  * @return NULL|string
  *   a permission name
  */
 public function translatePermission($perm, $nativePrefix, $map)
 {
     list($civiPrefix, $name) = CRM_Utils_String::parsePrefix(':', $perm, NULL);
     switch ($civiPrefix) {
         case $nativePrefix:
             return $name;
             // pass through
         // pass through
         case 'cms':
             return CRM_Utils_Array::value($name, $map, CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
         case NULL:
             return $name;
         default:
             return CRM_Core_Permission::ALWAYS_DENY_PERMISSION;
     }
 }
Example #26
0
 static function process(&$form)
 {
     if ($form->getVar('_id') <= 0) {
         return null;
     }
     $tabs = array('eventInfo' => array('title' => ts('Info and Settings'), 'link' => null, 'valid' => false, 'active' => false, 'current' => false), 'location' => array('title' => ts('Event Location'), 'link' => null, 'valid' => false, 'active' => false, 'current' => false), 'fee' => array('title' => ts('Fees'), 'link' => null, 'valid' => false, 'active' => false, 'current' => false), 'registration' => array('title' => ts('Online Registration'), 'link' => null, 'valid' => false, 'active' => false, 'current' => false), 'friend' => array('title' => ts('Tell a Friend'), 'link' => null, 'valid' => false, 'active' => false, 'current' => false));
     $eventID = $form->getVar('_id');
     $fullName = $form->getVar('_name');
     $className = CRM_Utils_String::getClassName($fullName);
     $class = strtolower($className);
     // hack for tell a friend, since class name is different
     if ($className == 'Event') {
         $class = 'friend';
     } elseif ($className == 'EventInfo') {
         $class = 'eventInfo';
     }
     if (array_key_exists($class, $tabs)) {
         $tabs[$class]['current'] = true;
     }
     if ($eventID) {
         $reset = CRM_Utils_Array::value('reset', $_GET) ? 'reset=1&' : '';
         //add qf key
         $qfKey = $form->get('qfKey');
         $form->assign('qfKey', $qfKey);
         foreach ($tabs as $key => $value) {
             $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/event/manage/{$key}", "{$reset}action=update&snippet=4&id={$eventID}&qfKey={$qfKey}");
             $tabs[$key]['active'] = $tabs[$key]['valid'] = true;
         }
         // retrieve info about paid event, tell a friend and online reg
         $sql = "\nSELECT     e.is_online_registration, e.is_monetary, taf.is_active\nFROM       civicrm_event e\nLEFT JOIN  civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )\nWHERE      e.id = %1\n";
         $params = array(1 => array($eventID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if (!$dao->fetch()) {
             CRM_Core_Error::fatal();
         }
         if (!$dao->is_online_registration) {
             $tabs['registration']['valid'] = false;
         }
         if (!$dao->is_monetary) {
             $tabs['fee']['valid'] = false;
         }
         if (!$dao->is_active) {
             $tabs['friend']['valid'] = false;
         }
     }
     return $tabs;
 }
Example #27
0
 /**
  * Takes an associative array and creates a campaign 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.
  *
  * @return CRM_Campaign_DAO_Campaign
  */
 public static function create(&$params)
 {
     if (empty($params)) {
         return NULL;
     }
     if (!CRM_Utils_Array::value('id', $params)) {
         if (!CRM_Utils_Array::value('created_id', $params)) {
             $session = CRM_Core_Session::singleton();
             $params['created_id'] = $session->get('userID');
         }
         if (!CRM_Utils_Array::value('created_date', $params)) {
             $params['created_date'] = date('YmdHis');
         }
         if (!CRM_Utils_Array::value('name', $params)) {
             $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64);
         }
         CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params);
     } else {
         CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params);
     }
     $campaign = new CRM_Campaign_DAO_Campaign();
     $campaign->copyValues($params);
     $campaign->save();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign);
     } else {
         CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign);
     }
     /* Create the campaign group record */
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) {
         foreach ($params['groups']['include'] as $entityId) {
             $dao = new CRM_Campaign_DAO_CampaignGroup();
             $dao->campaign_id = $campaign->id;
             $dao->entity_table = $groupTableName;
             $dao->entity_id = $entityId;
             $dao->group_type = 'Include';
             $dao->save();
             $dao->free();
         }
     }
     //store custom data
     if (!empty($params['custom']) && is_array($params['custom'])) {
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id);
     }
     return $campaign;
 }
 /**
  * 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++;
     }
 }
/**
 * File for the CiviCRM APIv3 group functions
 *
 * @package CiviCRM_APIv3
 * @subpackage API_pcpteams
 * @copyright CiviCRM LLC (c) 2004-2014
 */
function civicrm_api3_pcpteams_create($params)
{
    // since we are allowing html input from the user
    // we also need to purify it, so lets clean it up
    // $params['pcp_title']      = $pcp['title'];
    // $params['pcp_contact_id'] = $pcp['contact_id'];
    $htmlFields = array('intro_text', 'page_text', 'title');
    foreach ($htmlFields as $field) {
        if (!empty($params[$field])) {
            $params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
        }
    }
    $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
    $pcpBlock = new CRM_PCP_DAO_PCPBlock();
    $pcpBlock->entity_table = $entity_table;
    $pcpBlock->entity_id = $params['page_id'];
    $pcpBlock->find(TRUE);
    $params['pcp_block_id'] = $pcpBlock->id;
    $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
    // 1 -> waiting review
    // 2 -> active / approved (default for now)
    $params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2);
    // active by default for now
    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
    $pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE);
    //Custom Set
    $customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE);
    $isCustomValueSet = FALSE;
    foreach ($customFields as $fieldID => $fieldValue) {
        list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
        if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) {
            $isCustomValueSet = TRUE;
            //FIXME: to find out the custom value exists, set -1 as default now
            $params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"];
        }
    }
    if ($isCustomValueSet) {
        $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP');
        CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id);
    }
    //end custom set
    $values = array();
    @_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]);
    return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create');
}
Example #30
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'] = 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;
 }