/** * 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; }
/** * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_reminder($params, &$smarty) { $object = array_var($params, 'object'); $reminder_date = null; if (instance_of($object, 'ProjectObject')) { if ($object->isCompleted()) { return ''; } // if $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME, $link); $query = "select reminder_date from healingcrystals_project_object_misc where object_id='" . $object->getId() . "'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $info = mysql_fetch_assoc($result); if (!empty($info['reminder_date'])) { $reminder_date = DateTimeValue::makeFromString($info['reminder_date']); } } mysql_close($link); } else { return new InvalidParamError('object', $object, '$object is not expected to be an instance of ProjectObject', true); } // if $offset = get_user_gmt_offset(); if (instance_of($reminder_date, 'DateTimeValue')) { require_once SMARTY_PATH . '/plugins/modifier.datetime.php'; $date = smarty_modifier_datetime($reminder_date, 0); // just printing date, offset is 0! if ($reminder_date->isToday($offset)) { return '<span class="today"><span class="number">Reminder set for: ' . lang('Today') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>'; } elseif ($reminder_date->isYesterday($offset)) { return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . lang('<span class="number">Yesterday ' . date('h:i A', $reminder_date->getTimestamp()) . '</span>') . '</span>'; } elseif ($reminder_date->isTomorrow($offset)) { return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: <span class="number">' . lang('Tomorrow') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>'; } else { $now = new DateTimeValue(); $now->advance($offset); $now = $now->beginningOfDay(); $reminder_date->beginningOfDay(); if ($reminder_date->getTimestamp() > $now->getTimestamp()) { return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($reminder_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>'; } else { return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $reminder_date->getTimestamp()) / 86400))) . '</span>'; } // if } // if } else { return ''; } // if }
/** * Return '*** ago' message * * @param DateTimeValue $input * @param integer $offset * @return string */ function smarty_modifier_ago($input, $offset = null) { if (!instance_of($input, 'DateValue')) { return '<span class="ago">' . lang('-- Unknown --') . '</span>'; } // if if ($offset === null) { $offset = get_user_gmt_offset(); } // if $datetime = new DateTimeValue($input->getTimestamp() + $offset); $reference = new DateTimeValue(time() + $offset); $diff = $reference->getTimestamp() - $datetime->getTimestamp(); // Get exact number of seconds between current time and yesterday morning $reference_timestamp = $reference->getTimestamp(); $yesterday_begins_at = 86400 + date('G', $reference_timestamp) * 3600 + date('i', $reference_timestamp) * 60 + date('s', $reference_timestamp); if ($diff < 60) { $value = lang('Few seconds ago'); } elseif ($diff < 120) { $value = lang('A minute ago'); } elseif ($diff < 3600) { $value = lang(':num minutes ago', array('num' => floor($diff / 60))); } elseif ($diff < 7200) { $value = lang('An hour ago'); } elseif ($diff < 86400) { if (date('j', $datetime->getTimestamp()) != date('j', $reference->getTimestamp())) { $value = lang('Yesterday'); } else { $mod = $diff % 3600; if ($mod < 900) { $value = lang(':num hours ago', array('num' => floor($diff / 3600))); } elseif ($mod > 2700) { $value = lang(':num hours ago', array('num' => ceil($diff / 3600))); } else { $value = lang(':num and a half hours ago', array('num' => floor($diff / 3600))); } // if } // if } elseif ($diff <= $yesterday_begins_at) { $value = lang('Yesterday'); } elseif ($diff < 2592000) { $value = lang(':num days ago', array('num' => floor($diff / 86400))); } else { require_once SMARTY_PATH . '/plugins/modifier.date.php'; require_once SMARTY_PATH . '/plugins/modifier.datetime.php'; return '<span class="ago" title="' . clean(smarty_modifier_datetime($datetime, 0)) . '">' . lang('On') . ' ' . smarty_modifier_date($datetime, 0) . '</span>'; } // if require_once SMARTY_PATH . '/plugins/modifier.datetime.php'; return '<span class="ago" title="' . clean(smarty_modifier_datetime($datetime, 0)) . '">' . $value . '</span>'; }
?> <?php $this->_tag_stack[] = array('form_table_column', array('columnid' => 'periodbegin', 'header' => "[BILLING_PERIOD]")); $_block_repeat = true; smarty_form_table_column($this->_tag_stack[count($this->_tag_stack) - 1][1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start(); ?> <?php echo is_array($_tmp = $this->_tpl_vars['invoices']['periodbegin']) ? $this->_run_mod_handler('datetime', true, $_tmp, 'date') : smarty_modifier_datetime($_tmp, 'date'); ?> - <?php echo is_array($_tmp = $this->_tpl_vars['invoices']['periodend']) ? $this->_run_mod_handler('datetime', true, $_tmp, 'date') : smarty_modifier_datetime($_tmp, 'date'); ?> <?php $_block_content = ob_get_contents(); ob_end_clean(); $_block_repeat = false; echo smarty_form_table_column($this->_tag_stack[count($this->_tag_stack) - 1][1], $_block_content, $this, $_block_repeat); } array_pop($this->_tag_stack); ?> <?php $this->_tag_stack[] = array('form_table_column', array('columnid' => 'total', 'header' => "[INVOICE_TOTAL]")); $_block_repeat = true;
echo smarty_form_table_column($this->_tag_stack[count($this->_tag_stack) - 1][1], $_block_content, $this, $_block_repeat); } array_pop($this->_tag_stack); ?> <?php $this->_tag_stack[] = array('form_table_column', array('columnid' => 'expiredate', 'header' => "[EXPIRATION_DATE]")); $_block_repeat = true; smarty_form_table_column($this->_tag_stack[count($this->_tag_stack) - 1][1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start(); ?> <?php echo is_array($_tmp = $this->_tpl_vars['domains']['expiredate']) ? $this->_run_mod_handler('datetime', true, $_tmp, 'date') : smarty_modifier_datetime($_tmp, 'date'); ?> <?php $_block_content = ob_get_contents(); ob_end_clean(); $_block_repeat = false; echo smarty_form_table_column($this->_tag_stack[count($this->_tag_stack) - 1][1], $_block_content, $this, $_block_repeat); } array_pop($this->_tag_stack); ?> <?php $this->_tag_stack[] = array('form_table_footer', array()); $_block_repeat = true;
/** * * @param array $params * @param Smarty $smarty * @return string * HISTORY * 22 May 2012 (SA) Ticket #841: check recurring task reminder script */ function smarty_function_reminder($params, &$smarty) { $object = array_var($params, 'object'); $reminder_date = null; if (instance_of($object, 'ProjectObject')) { if ($object->isCompleted()) { return ''; } // if $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME, $link); //BOF:mod 20120904 /* //EOF:mod 20120904 $query = "select * from healingcrystals_project_object_misc where object_id='" . $object->getId() . "'"; //BOF:mod 20120904 */ $query = "select a.reminder_date, a.recurring_period, a.recurring_period_type, b.completed_on from healingcrystals_project_object_misc a inner join healingcrystals_project_objects b on a.object_id=b.id where a.object_id='" . $object->getId() . "'"; //EOF:mod 20120904 $result = mysql_query($query); if (mysql_num_rows($result)) { $info = mysql_fetch_assoc($result); if (!empty($info['reminder_date']) && $info['reminder_date'] != '0000-00-00 00:00:00') { $reminder_date = DateTimeValue::makeFromString($info['reminder_date']); } //BOF:mod 20120904 if (!empty($info['completed_on'])) { //EOF:mod 20120904 if ($info['recurring_period_type'] != '' && $info['recurring_period'] != '') { $recurring_period = $info['recurring_period']; $recurring_period_type = $info['recurring_period_type']; switch ($recurring_period_type) { case 'D': $recurring_period_type = 'day' . ($recurring_period == 1 ? '' : 's'); break; case 'W': $recurring_period_type = 'week' . ($recurring_period == 1 ? '' : 's'); break; case 'M': $recurring_period_type = 'month' . ($recurring_period == 1 ? '' : 's'); break; case 'Y': $recurring_period_type = 'year' . ($recurring_period == 1 ? '' : 's'); break; } $datetime = new DateTime(); $datetime->modify('+' . $recurring_period . ' ' . $recurring_period_type); //BOF:mod 20120703 if (!empty($reminder_date)) { $temp_date = $reminder_date; } //EOF:mod 20120703 $reminder_date = DateTimeValue::makeFromString($datetime->format('Y-m-d H:00')); //BOF:mod 20120703 if (!empty($temp_date) && $temp_date->getTimestamp() >= time()) { $reminder_date = $temp_date; } //EOF:mod 20120703 } //BOF:mod 20120904 } //EOF:mod 20120904 } mysql_close($link); } else { return new InvalidParamError('object', $object, '$object is not expected to be an instance of ProjectObject', true); } // if $offset = get_user_gmt_offset(); if (instance_of($reminder_date, 'DateTimeValue')) { require_once SMARTY_PATH . '/plugins/modifier.datetime.php'; $date = smarty_modifier_datetime($reminder_date, 0); // just printing date, offset is 0! if ($reminder_date->isToday($offset)) { return '<span class="today"><span class="number">Reminder set for: ' . lang('Today') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>'; } elseif ($reminder_date->isYesterday($offset)) { return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . lang('<span class="number">Yesterday ' . date('h:i A', $reminder_date->getTimestamp()) . '</span>') . '</span>'; } elseif ($reminder_date->isTomorrow($offset)) { return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: <span class="number">' . lang('Tomorrow') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>'; } else { $now = new DateTimeValue(); $now->advance($offset); $now = $now->beginningOfDay(); $reminder_date->beginningOfDay(); if ($reminder_date->getTimestamp() > $now->getTimestamp()) { return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($reminder_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>'; } else { return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $reminder_date->getTimestamp()) / 86400))) . '</span>'; } // if } // if } else { return ''; } // if }
/** * Refresh session * * @param void * @return null */ function refresh_session() { require_once SMARTY_PATH . '/plugins/modifier.datetime.php'; print 'Session refreshed on: ' . smarty_modifier_datetime(new DateTimeValue()); die; }
/** * Set page properties with following object * * Parameters: * * - object - Application object instance * * @param array $params * @param Smarty $smarty * @return null */ function smarty_function_page_object($params, &$smarty) { static $private_roles = false; $object = array_var($params, 'object'); if (!instance_of($object, 'ApplicationObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ApplicationObject class', true); } // if require_once SMARTY_DIR . '/plugins/modifier.datetime.php'; $wireframe =& Wireframe::instance(); $logged_user =& get_logged_user(); $construction =& PageConstruction::instance(); if ($construction->page_title == '') { $construction->setPageTitle($object->getName()); } // if if (instance_of($object, 'ProjectObject') && $wireframe->details == '') { $in = $object->getParent(); $created_on = $object->getCreatedOn(); $created_by = $object->getCreatedBy(); if (instance_of($created_by, 'User') && instance_of($in, 'ApplicationObject') && instance_of($created_on, 'DateValue')) { //BOF:mod 20120913 /* //EOF:mod 20120913 $wireframe->details = lang('By <a href=":by_url">:by_name</a> in <a href=":in_url">:in_name</a> on <span>:on</span>', array( //BOF:mod 20120913 */ $wireframe->details = lang('Created on <span>:on</span>', array('by_url' => $created_by->getViewUrl(), 'by_name' => $created_by->getDisplayName(), 'in_url' => $in->getViewUrl(), 'in_name' => $in->getName(), 'on' => smarty_modifier_datetime($created_on))); } elseif (instance_of($created_by, 'User') && instance_of($created_on, 'DateValue')) { //BOF:mod 20120913 /* //EOF:mod 20120913 $wireframe->details = lang('By <a href=":by_url">:by_name</a> on <span>:on</span>', array( //BOF:mod 20120913 */ $wireframe->details = lang('Created on <span>:on</span>', array('by_url' => $created_by->getViewUrl(), 'by_name' => $created_by->getDisplayName(), 'on' => smarty_modifier_datetime($created_on))); } elseif (instance_of($created_by, 'User')) { //BOF:mod 20120913 /* //EOF:mod 20120913 $wireframe->details = lang('By <a href=":by_url">:by_name</a>', array( //BOF:mod 20120913 */ $wireframe->details = lang('Created on <span>:on</span>', array('by_url' => $created_by->getViewUrl(), 'by_name' => $created_by->getDisplayName(), 'on' => smarty_modifier_datetime($created_on))); } elseif (instance_of($created_by, 'AnonymousUser') && instance_of($created_on, 'DateValue')) { //BOF:mod 20120913 /* //EOF:mod 20120913 $wireframe->details = lang('By <a href=":by_url">:by_name</a> on <span>:on</span>', array( //BOF:mod 20120913 */ $wireframe->details = lang('Created on <span>:on</span>', array('by_url' => 'mailto:' . $created_by->getEmail(), 'by_name' => $created_by->getName(), 'on' => smarty_modifier_datetime($created_on))); } elseif (instance_of($created_by, 'AnonymousUser')) { //BOF:mod 20120913 /* //EOF:mod 20120913 $wireframe->details = lang('By <a href=":by_url">:by_name</a>', array( //BOF:mod 20120913 */ $wireframe->details = lang('Created on <span>:on</span>', array('by_url' => 'mailto:' . $created_by->getEmail(), 'by_name' => $created_by->getName(), 'on' => smarty_modifier_datetime($created_on))); } // if } // if $smarty->assign('page_object', $object); // Need to do a case sensitive + case insensitive search to have PHP4 covered $class_methods = get_class_methods($object); if (in_array('getOptions', $class_methods) || in_array('getoptions', $class_methods)) { $options = $object->getOptions($logged_user); if (instance_of($options, 'NamedList') && $options->count()) { $wireframe->addPageAction(lang('Options'), '#', $options->data, array('id' => 'project_object_options'), 1000); } // if if (instance_of($object, 'ProjectObject')) { if ($object->getState() > STATE_DELETED) { if ($object->getVisibility() <= VISIBILITY_PRIVATE) { //Ticket ID #362 - modify Private button (SA) 14March2012 BOF $users_table = TABLE_PREFIX . 'users'; $assignments_table = TABLE_PREFIX . 'assignments'; $subscription_table = TABLE_PREFIX . 'subscriptions'; // $rows = db_execute_all("SELECT $assignments_table.is_owner AS is_assignment_owner, $users_table.id AS user_id, $users_table.company_id, $users_table.first_name, $users_table.last_name, $users_table.email FROM $users_table, $assignments_table WHERE $users_table.id = $assignments_table.user_id AND $assignments_table.object_id = ? ORDER BY $assignments_table.is_owner DESC", $object->getId()); $rows = db_execute_all("SELECT {$assignments_table}.is_owner AS is_assignment_owner, {$users_table}.id AS user_id, {$users_table}.company_id, {$users_table}.first_name, {$users_table}.last_name, {$users_table}.email FROM {$users_table}, {$assignments_table} WHERE {$users_table}.id = {$assignments_table}.user_id AND {$assignments_table}.object_id = " . $object->getId() . " UNION SELECT '0' AS is_assignment_owner, {$users_table}.id AS user_id, {$users_table}.company_id, {$users_table}.first_name, {$users_table}.last_name, {$users_table}.email FROM {$users_table}, {$subscription_table} WHERE {$users_table}.id = {$subscription_table}.user_id AND {$subscription_table}.parent_id = " . $object->getId()); if (is_foreachable($rows)) { $owner = null; $other_assignees = array(); $users_dropdown_for_tickets = ''; foreach ($rows as $row) { if (empty($row['first_name']) && empty($row['last_name'])) { $user_link = clean($row['email']); } else { $user_link = clean($row['first_name'] . ' ' . $row['last_name']); } // if if ($row['is_assignment_owner']) { $owner = $user_link; } else { $other_assignees[] = $user_link; } if ($owner) { if (instance_of($object, 'Ticket')) { if (count($other_assignees) > 0) { $users = $owner; if (!empty($users)) { $users .= ', '; } $users .= implode(', ', $other_assignees); } else { $users = $owner; } // if } else { if (count($other_assignees) > 0) { $users = $owner . ' ' . lang('is responsible', null, true, $language) . '. ' . lang('Other assignees', null, true, $language) . ': ' . implode(', ', $other_assignees) . '.'; } else { $users = $owner . ' ' . lang('is responsible', null, true, $language) . '.'; } // if } } elseif (count($other_assignees) > 0) { $users = implode(', ', $other_assignees); } } } $wireframe->addPageMessage(lang('<b>Private</b> - This Ticket has been marked as "Private" and is Visible by these Users: :users', array('users' => $users)), PAGE_MESSAGE_PRIVATE); //Ticket ID #362 - modify Private button (SA) 14March2012 EOF } // if } else { $wireframe->addPageMessage(lang('<b>Trashed</b> - this :type is located in trash.', array('type' => $object->getVerboseType(true))), PAGE_MESSAGE_TRASHED); } // if } // if } // if return ''; }
/** * 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 = ' <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 }