/**
 * Smarty function for checking change in a property's value, for example
 * when looping through an array.
 *
 * Smarty param:  string $key     unique identifier for this property (REQUIRED)
 * Smarty param:  mixed  $value   the current value of the property
 * Smarty param:  string $assign  name of template variable to which to assign result
 *
 *
 * @param array $params
 *   Template call's parameters.
 * @param CRM_Core_Smarty $smarty
 *   The Smarty object.
 *
 * @return NULL
 */
function smarty_function_isValueChange($params, &$smarty)
{
    static $values = array();
    if (empty($params['key'])) {
        $smarty->trigger_error("Missing required parameter, 'key', in isValueChange plugin.");
        return NULL;
    }
    $is_changed = FALSE;
    if (!array_key_exists($params['key'], $values) || strcasecmp($params['value'], $values[$params['key']]) !== 0) {
        // if we have a new value
        $is_changed = TRUE;
        $values[$params['key']] = $params['value'];
        // clear values on all properties added below/after this property
        $clear = FALSE;
        foreach ($values as $k => $dontcare) {
            if ($clear) {
                unset($values[$k]);
            } elseif ($params['key'] == $k) {
                $clear = TRUE;
            }
        }
    }
    if ($params['assign']) {
        $smarty->assign($params['assign'], $is_changed);
    }
    return NULL;
}
/**
 * Get details for the target and assignee contact of an activity.
 *
 * This is "simple" in that it is only appropriate for activities in which the business-process
 * guarantees that there is only one target and one assignee. If the business-process permits
 * multiple targets or multiple assignees, then consider the more versatile (but less sugary)
 * function "crmAPI".
 *
 * Note: This will perform like a dog, but who cares -- at most, we deal with O(100) iterations
 * as part of a background task.
 *
 * @param array $params
 *   , Array with keys:
 *   - activity_id: int, required
 *   - target_var: string, optional; name of a variable which will store the first/only target contact; default "target"
 *   - assignee_var: string, optional; name of a variable which will store the first/only assignee contact; default "assignee"
 *   - return: string, optional; comma-separated list of fields to return for each contact
 *
 * @param CRM_Core_Smarty $smarty
 *
 * @return string
 */
function smarty_function_simpleActivityContacts($params, &$smarty)
{
    if (empty($params['activity_id'])) {
        $smarty->trigger_error('assign: missing \'activity_id\' parameter');
    }
    if (!isset($params['target_var'])) {
        $params['target_var'] = 'target';
    }
    if (!isset($params['assignee_var'])) {
        $params['assignee_var'] = 'assignee';
    }
    if (!isset($params['return'])) {
        $params['return'] = 'contact_id,contact_type,display_name,sort_name,first_name,last_name';
    }
    require_once 'api/api.php';
    require_once 'api/v3/utils.php';
    $activity = civicrm_api('activity', 'getsingle', array('version' => 3, 'id' => $params['activity_id'], 'return.target_contact_id' => 1, 'return.assignee_contact_id' => 1));
    $baseContactParams = array('version' => 3);
    foreach (explode(',', $params['return']) as $field) {
        $baseContactParams['return.' . $field] = 1;
    }
    foreach (array('target', 'assignee') as $role) {
        $contact = array();
        if (!empty($activity[$role . '_contact_id'])) {
            $contact_id = array_shift($activity[$role . '_contact_id']);
            $contact = civicrm_api('contact', 'getsingle', $baseContactParams + array('contact_id' => $contact_id));
        }
        $smarty->assign($params[$role . '_var'], $contact);
    }
    return '';
}
Beispiel #3
0
/**
 * Adds inline help
 *
 * @param array $params
 *   The function params.
 * @param CRM_Core_Smarty $smarty
 *   Reference to the smarty object.
 *
 * @return string
 *   the help html to be inserted
 */
function smarty_function_help($params, &$smarty)
{
    if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) {
        return NULL;
    }
    if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) {
        $params['file'] = $smarty->_tpl_vars['tplFile'];
    } elseif (empty($params['file'])) {
        return NULL;
    }
    $params['file'] = str_replace(array('.tpl', '.hlp'), '', $params['file']);
    if (empty($params['title'])) {
        $vars = $smarty->get_template_vars();
        $smarty->assign('id', $params['id'] . '-title');
        $name = trim($smarty->fetch($params['file'] . '.hlp'));
        $additionalTPLFile = $params['file'] . '.extra.hlp';
        if ($smarty->template_exists($additionalTPLFile)) {
            $name .= trim($smarty->fetch($additionalTPLFile));
        }
        // Ensure we didn't change any existing vars CRM-11900
        foreach ($vars as $key => $value) {
            if ($smarty->get_template_vars($key) !== $value) {
                $smarty->assign($key, $value);
            }
        }
    } else {
        $name = trim(strip_tags($params['title']));
    }
    $class = "helpicon";
    if (!empty($params['class'])) {
        $class .= " {$params['class']}";
    }
    // Escape for html
    $title = htmlspecialchars(ts('%1 Help', array(1 => $name)));
    // Escape for html and js
    $name = htmlspecialchars(json_encode($name), ENT_QUOTES);
    // Format params to survive being passed through json & the url
    unset($params['text'], $params['title']);
    foreach ($params as &$param) {
        $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param;
    }
    return '<a class="' . $class . '" title="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'>&nbsp;</a>';
}
/**
 * Fetch an attribute from html
 *
 * @param array $params
 * @param CRM_Core_Smarty $smarty
 *
 * @return string
 */
function smarty_function_crmGetAttribute($params, &$smarty)
{
    $ret = '';
    if (preg_match('#\\W' . $params['attr'] . '="([^"]+)#', $params['html'], $matches)) {
        $ret = $matches[1];
    }
    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $ret);
    } else {
        return $ret;
    }
}
Beispiel #5
0
 /**
  * @param $var
  * @param null $value
  */
 public function assign($var, $value = NULL)
 {
     self::$_template->assign($var, $value);
 }
Beispiel #6
0
 /**
  * assign value to name in template
  *
  * @param array|string $name  name  of variable
  * @param mixed $value value of varaible
  *
  * @return void
  * @access public
  */
 function assign($var, $value = null)
 {
     self::$_template->assign($var, $value);
 }
Beispiel #7
0
 /**
  * Assign uf fields to template.
  *
  * @param int $gid
  *   Group id.
  * @param array $values
  * @param CRM_Core_Smarty $template
  */
 public function profileDisplay($gid, $values, $template)
 {
     $groupTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'title');
     $template->assign('grouptitle', $groupTitle);
     if (count($values)) {
         $template->assign('values', $values);
     }
 }
Beispiel #8
0
 /**
  * Show status in the footer
  *
  * @param CRM_Core_Smarty $template
  */
 public static function statusCheck($template)
 {
     if (CRM_Core_Config::isUpgradeMode()) {
         return;
     }
     $statusSeverity = 0;
     $statusMessage = ts('System status OK');
     // TODO: get status from CRM_Utils_Check, if cached
     $template->assign('footer_status_severity', $statusSeverity);
     $template->assign('footer_status_message', $statusMessage);
 }
 /**
  * Move the variables from the session to the template
  *
  * @return void
  * @access public
  */
 function moveFromSessionToTemplate()
 {
     self::$_template->assign_by_ref("{$this->_prefix}pager", $this->_pager);
     $rows = $this->_store->get("{$this->_prefix}rows");
     if ($rows) {
         if ($this->_dynamicAction) {
             $this->_object->addActions($rows);
         }
         self::$_template->assign("{$this->_prefix}aToZ", $this->_store->get("{$this->_prefix}AToZBar"));
     }
     self::$_template->assign_by_ref("{$this->_prefix}sort", $this->_sort);
     self::$_template->assign("{$this->_prefix}columnHeaders", $this->_store->get("{$this->_prefix}columnHeaders"));
     self::$_template->assign("{$this->_prefix}rows", $rows);
     self::$_template->assign("{$this->_prefix}rowsEmpty", $this->_store->get("{$this->_prefix}rowsEmpty"));
     self::$_template->assign("{$this->_prefix}qill", $this->_store->get("{$this->_prefix}qill"));
     self::$_template->assign("{$this->_prefix}summary", $this->_store->get("{$this->_prefix}summary"));
     if ($this->_embedded) {
         return;
     }
     self::$_template->assign('tplFile', $this->_object->getTemplateFileName());
     if ($this->_print) {
         $content = self::$_template->fetch('CRM/common/print.tpl');
     } else {
         $config = CRM_Core_Config::singleton();
         $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl');
     }
     echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print);
 }
Beispiel #10
0
 /**
  * Show status in the footer (admin only)
  *
  * @param CRM_Core_Smarty $template
  */
 public static function statusCheck($template)
 {
     if (CRM_Core_Config::isUpgradeMode() || !CRM_Core_Permission::check('administer CiviCRM')) {
         return;
     }
     // always use cached results - they will be refreshed by the session timer
     $status = Civi::settings()->get('systemStatusCheckResult');
     $template->assign('footer_status_severity', $status);
     $template->assign('footer_status_message', CRM_Utils_Check::toStatusLabel($status));
 }
Beispiel #11
0
 /**
  * Show the message about CiviCRM versions.
  *
  * @param CRM_Core_Smarty $template
  */
 public static function versionCheck($template)
 {
     if (CRM_Core_Config::isUpgradeMode()) {
         return;
     }
     $newerVersion = $securityUpdate = NULL;
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1) & 1) {
         $newerVersion = CRM_Utils_VersionCheck::singleton()->isNewerVersionAvailable();
     }
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityUpdateAlert', NULL, 3) & 1) {
         $securityUpdate = CRM_Utils_VersionCheck::singleton()->isSecurityUpdateAvailable();
     }
     $template->assign('newer_civicrm_version', $newerVersion);
     $template->assign('security_update', $securityUpdate);
 }
Beispiel #12
0
 /**
  * Show status in the footer
  *
  * @param CRM_Core_Smarty $template
  */
 public static function statusCheck($template)
 {
     if (CRM_Core_Config::isUpgradeMode()) {
         return;
     }
     //  check date of last cache and compare to today's date
     $systemCheckDate = Civi::cache()->get('systemCheckDate');
     if ($systemCheckDate > strtotime("one day ago")) {
         $statusSeverity = Civi::cache()->get('systemCheckSeverity');
     }
     //  calls helper function in CRM_Utils_Check
     if (empty($statusSeverity)) {
         $statusSeverity = CRM_Utils_Check::checkAll(TRUE);
     }
     switch ($statusSeverity) {
         case 7:
             $statusMessage = ts('System Status: Emergency');
             break;
         case 6:
             $statusMessage = ts('System Status: Alert');
             break;
         case 5:
             $statusMessage = ts('System Status: Critical');
             break;
         case 4:
             $statusMessage = ts('System Status: Error');
             break;
         case 3:
             $statusMessage = ts('System Status: Warning');
             break;
         case 2:
             $statusMessage = ts('System Status: Notice');
             break;
         default:
             $statusMessage = ts('System Status: Ok');
     }
     // TODO: get status from CRM_Utils_Check, if cached
     $template->assign('footer_status_severity', $statusSeverity);
     $template->assign('footer_status_message', $statusMessage);
 }