/**
 * Renders action string with time when action was taken
 * 
 * Parameteres:
 * 
 * - action - Action string, default is 'Posted'. It is used for lang retrival
 * - datetime - Datetime object when action was taken
 * - format - Format in with time is displayed. Possible values are ago, 
 *   datetime, date and time. Default is 'ago'
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_action_on($params, &$smarty)
{
    $action = clean(array_var($params, 'action', 'Posted'));
    $datetime = array_var($params, 'datetime');
    if (!instance_of($datetime, 'DateValue')) {
        return new InvalidParamError('datetime', $datetime, '$datetime is expected to be an instance of DateValue or DateTimeValue class', true);
    }
    // if
    $format = array_var($params, 'format', 'ago');
    if (!in_array($format, array('ago', 'date', 'datetime', 'time'))) {
        return new InvalidParamError('format', $format, 'Format is requred to be one of following four values: ago, date, datetime or time', true);
    }
    // if
    switch ($format) {
        case 'date':
            require_once SMARTY_DIR . '/plugins/modifier.date.php';
            $formatted_datetime = smarty_modifier_date($datetime);
            break;
        case 'time':
            require_once SMARTY_DIR . '/plugins/modifier.time.php';
            $formatted_datetime = smarty_modifier_time($datetime);
            break;
        case 'datetime':
            require_once SMARTY_DIR . '/plugins/modifier.datetime.php';
            $formatted_datetime = smarty_modifier_datetime($datetime);
            break;
        default:
            require_once SMARTY_DIR . '/plugins/modifier.ago.php';
            $formatted_datetime = smarty_modifier_ago($datetime);
    }
    // switch
    return lang($action) . ' ' . $formatted_datetime;
}
/**
 * Show users local time based on his or hers local settings
 * 
 * Parameters:
 * 
 * - user - User, if NULL logged user will be used
 * - datetime - Datetime value that need to be displayed. If NULL request time 
 *   will be used
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_user_time($params, &$smarty)
{
    $user = array_var($params, 'user');
    if (!instance_of($user, 'User')) {
        $user = get_logged_user();
    }
    // if
    if (!instance_of($user, 'User')) {
        return lang('Unknown time');
    }
    // if
    $value = array_var($params, 'datetime');
    if (!instance_of($value, 'DateValue')) {
        $value = $smarty->get_template_vars('request_time');
    }
    // if
    if (!instance_of($value, 'DateValue')) {
        return lang('Unknown time');
    }
    // if
    require_once SMARTY_PATH . '/plugins/modifier.time.php';
    return clean(smarty_modifier_time($value, get_user_gmt_offset($user)));
}
/**
 * Renders action string with time when action was taken and link to profile of 
 * user who acted
 * 
 * Parameteres:
 * 
 * - action - Action string, default is 'Posted'. It is used for lang retrival
 * - user - User who took the action. Can be registered user or anonymous user
 * - datetime - Datetime object when action was taken
 * - format - Format in with time is displayed. Possible values are ago, 
 *   datetime, date and time. Default is 'ago'
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_action_on_by($params, &$smarty)
{
    $action = clean(array_var($params, 'action', 'Posted'));
    $datetime = array_var($params, 'datetime');
    if (!instance_of($datetime, 'DateValue')) {
        return new InvalidParamError('datetime', $datetime, '$datetime is expected to be an instance of DateValue or DateTimeValue class', true);
    }
    // if
    $format = array_var($params, 'format', 'ago');
    if (!in_array($format, array('ago', 'date', 'datetime', 'time'))) {
        return new InvalidParamError('format', $format, 'Format is requred to be one of following four values: ago, date, datetime or time', true);
    }
    // if
    $offset = array_var($params, 'offset', null);
    switch ($format) {
        case 'date':
            require_once SMARTY_DIR . '/plugins/modifier.date.php';
            $formatted_datetime = smarty_modifier_date($datetime, $offset);
            break;
        case 'time':
            require_once SMARTY_DIR . '/plugins/modifier.time.php';
            $formatted_datetime = smarty_modifier_time($datetime, $offset);
            break;
        case 'datetime':
            require_once SMARTY_DIR . '/plugins/modifier.datetime.php';
            $formatted_datetime = smarty_modifier_datetime($datetime, $offset);
            break;
        default:
            require_once SMARTY_DIR . '/plugins/modifier.ago.php';
            $formatted_datetime = smarty_modifier_ago($datetime, $offset);
    }
    // switch
    $user = array_var($params, 'user');
    //BOF:mod 20110708 ticketid202
    /*
    //EOF:mod 20110708 ticketid202
    if(instance_of($user, 'User')) {
      return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by') . ' <a href="'. $user->getViewUrl() .'">' . clean($user->getDisplayName()) . '</a>';
    } elseif(instance_of($user, 'AnonymousUser')) {
      return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by') . ' <a href="mailto:'. $user->getEmail() .'">' . clean($user->getName()) . '</a>';
    } else {
      return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by unknown user');
    } // if
    //BOF:mod 20110708 ticketid202
    */
    $comment_link = '';
    $parent_obj = array_var($params, 'parent_obj');
    if ($parent_obj) {
        $type = $parent_obj->getType();
        if ($type == 'Comment') {
            $comment_link = '&nbsp;&nbsp;<a href="' . $parent_obj->getViewUrl() . '">View Comment</a>';
        }
    }
    //BOF:mod 20120913
    /*
    //EOF:mod 20120913
        if(instance_of($user, 'User')) {
          return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by') . ' <a href="'. $user->getViewUrl() .'">' . clean($user->getDisplayName()) . '</a>' . $comment_link;
        } elseif(instance_of($user, 'AnonymousUser')) {
          return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by') . ' <a href="mailto:'. $user->getEmail() .'">' . clean($user->getName()) . '</a>' . $comment_link;
        } else {
          return lang($action) . ' ' . $formatted_datetime . ' ' . lang('by unknown user') . $comment_link;
        } // if
    //BOF:mod 20120913
    */
    return lang($action) . ' ' . $formatted_datetime . ' ' . $comment_link;
    //EOF:mod 20120913
    //EOF:mod 20110708 ticketid202
}
                ?>
)</small></td>
<?php 
            }
            if ($this->_tpl_vars['idtouse'] == 'exit') {
                ?>
<td class="columndetail"><?php 
                echo is_array($_tmp = $this->_tpl_vars['info']['exitrate']) ? $this->_run_mod_handler('string_format', true, $_tmp, "%.2f") : smarty_modifier_string_format($_tmp, "%.2f");
                ?>
 %</td>
<?php 
            }
            if ($this->_tpl_vars['idtouse'] == 'sumtime') {
                ?>
<td class="columndetail"><?php 
                echo is_array($_tmp = $this->_tpl_vars['info']['avgtime']) ? $this->_run_mod_handler('time', true, $_tmp) : smarty_modifier_time($_tmp);
                ?>
</td>
<?php 
            }
            ?>
</tr>
<?php 
        }
    }
}
unset($_from);
if ($this->_tpl_vars['includeFromPage'] != 'true') {
    ?>
</div>
<?php