public function emailBody($user_data, $report_preferences, $report_cache) { global $prefs; include_once 'lib/smarty_tiki/modifier.username.php'; if (isset($report_cache[0])) { $base_url = $report_cache[0]['data']['base_url']; } else { $base_url = "http://" . $prefs['cookie_domain'] . "/"; // TODO: better handling for https and such } $smarty = TikiLib::lib('smarty'); $smarty->assign('report_preferences', $report_preferences); $smarty->assign('report_user', ucfirst(smarty_modifier_username($user_data['login']))); $smarty->assign('report_interval', ucfirst($report_preferences['interval'])); $smarty->assign('report_date', date("l d.m.Y")); $smarty->assign('report_site', $this->tikilib->get_preference('browsertitle')); if ($report_preferences['last_report'] != '0000-00-00 00:00:00') { $smarty->assign('report_last_report_date', TikiLib::date_format($this->tikilib->get_preference('long_date_format'), strtotime($report_preferences['last_report']))); } $smarty->assign('report_total_changes', count($report_cache)); $smarty->assign('report_body', $this->makeEmailBody($report_cache, $report_preferences)); $userWatchesUrl = $base_url . 'tiki-user_watches.php'; if ($report_preferences['type'] == 'html') { $userWatchesUrl = "<a href=\"{$userWatchesUrl}\">{$userWatchesUrl}</a>"; } $smarty->assign('userWatchesUrl', $userWatchesUrl); $mail_data = $smarty->fetch("mail/report.tpl"); return $mail_data; }
function wikiplugin_bloglist($data, $params) { global $tikilib; extract($params, EXTR_SKIP); if (!isset($Id)) { $text = "<b>missing blog Id for BLOGLIST plugins</b><br />"; $text .= wikiplugin_bloglist_help(); return $text; } // if (!isset($Field)) { // $Field = 'heading'; // } $text = "<div class=\"blogtools\"><table><tr><th>" . tra("Date") . "</th><th>" . tra("Title") . "</th><th>" . tra("Author") . "</th></tr>\n"; $query = "select `postId`, `title`, `user`, `created` from `tiki_blog_posts` where `blogId`=? order by `created` desc"; $result = $tikilib->query($query, array($Id)); $i = 0; while (($res = $result->fetchRow()) && $i < $Items) { $text .= "<tr><td>" . TikiLib::date_format("%d/%M/%Y %H:%M", $res["created"]) . "</td>"; $text .= "<td><a href=\"tiki-view_blog_post.php?blogId=" . $Id . "&postId=" . $res["postId"] . "\">" . $res["title"] . "</a></td>"; $text .= "<td>" . $res["user"] . "</td></tr>\n"; $i++; } $text .= "</table></div>\n"; return $text; }
function testNext() { $calendarlib = TikiLib::lib('calendar'); $date = TikiLib::make_time(0, 0, 0, 8, 31, 2010); $previous = $calendarlib->focusNext($calendarlib->infoDate($date), 'month'); $this->assertEquals('2010-09-30', TikiLib::date_format('%Y-%m-%d', $previous['date'])); }
protected function setSubject($reportCache) { $subject = tr('Report on %0 from %1 ', $this->tikiPrefs['browsertitle'], TikiLib::date_format($this->tikiPrefs['short_date_format'], $this->dt->format('U'))); if (!is_array($reportCache)) { $subject .= tr('(no changes)'); } elseif (count($reportCache) == 1) { $subject .= tr('(1 change)'); } else { $subject .= tr('(%0 changes)', count($reportCache)); } $this->mail->setSubject($subject); }
function smarty_modifier_tiki_short_date($string) { global $prefs; $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_tiki_date_format'); $date = smarty_modifier_tiki_date_format($string, $prefs['short_date_format']); if ($prefs['jquery_timeago'] === 'y') { TikiLib::lib('header')->add_jq_onready('$("time.timeago").timeago();'); return '<time class="timeago" datetime="' . TikiLib::date_format('c', $string, false, 5, false) . '">' . $date . '</time>'; } else { return $date; } }
protected function setSubject($reportCache) { if (is_array($reportCache) && count($reportCache) >= 1) { if (count($reportCache) == 1) { $subject = tr('Report from %0 (1 change)', TikiLib::date_format($this->tikiPrefs['short_date_format'], $this->dt->format('U'))); } else { $subject = tr('Report from %0 (%1 changes)', TikiLib::date_format($this->tikiPrefs['short_date_format'], $this->dt->format('U')), count($reportCache)); } } else { $subject = tr('Report from %0 (no changes)', TikiLib::date_format($this->tikiPrefs['short_date_format'], $this->dt->format('U'))); } $this->mail->setSubject($subject); }
function wikiplugin_now($data, $params) { global $prefs; $default = TikiLib::date_format($prefs['long_date_format'] . ' ' . $prefs['long_time_format']); if (!empty($params['format'])) { $ret = TikiLib::date_format($params['format']); //see if the user format setting results in a valid date, return default format if not try { $dateObj = new DateTime($ret); } catch (Exception $e) { return $default; } return $ret; } else { return $default; } }
public function emailBody($user_data, $report_preferences, $report_cache) { $base_url = $report_cache[0]['data']['base_url']; $smarty = TikiLib::lib('smarty'); $smarty->assign('report_preferences', $report_preferences); $smarty->assign('report_user', ucfirst($user_data['login'])); $smarty->assign('report_interval', ucfirst($report_preferences['interval'])); $smarty->assign('report_date', date("l d.m.Y")); if ($report_preferences['last_report'] != '0000-00-00 00:00:00') { $smarty->assign('report_last_report_date', TikiLib::date_format($this->tikilib->get_preference('long_date_format'), strtotime($report_preferences['last_report']))); } $smarty->assign('report_total_changes', count($report_cache)); $smarty->assign('report_body', $this->makeEmailBody($report_cache, $report_preferences)); $userWatchesUrl = $base_url . 'tiki-user_watches.php'; if ($report_preferences['type'] == 'html') { $userWatchesUrl = "<a href=\"{$userWatchesUrl}\">{$userWatchesUrl}</a>"; } $smarty->assign('userWatchesUrl', $userWatchesUrl); $mail_data = $smarty->fetch("mail/report.tpl"); return $mail_data; }
function smarty_modifier_tiki_short_datetime($string, $intro = '', $same = 'y') { global $prefs; $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_tiki_date_format'); $date = smarty_modifier_tiki_date_format($string, $prefs['short_date_format']); $time = smarty_modifier_tiki_date_format($string, $prefs['short_time_format']); $intro = !empty($intro) ?: tra($intro) . ' '; if ($prefs['jquery_timeago'] === 'y' && $same === 'y') { TikiLib::lib('header')->add_jq_onready('$("time.timeago").timeago();'); return '<time class="timeago" datetime="' . TikiLib::date_format('c', $string, false, 5, false) . '">' . $date . ' ' . $time . '</time>'; } else { if ($same != 'n' && $prefs['tiki_same_day_time_only'] == 'y' && $date == smarty_modifier_tiki_date_format(time(), $prefs['short_date_format'])) { //tra('on') tra('on:') tra('at') tra('at:') return str_replace(array('on', 'On'), array('at', 'At'), $intro) . $time; } else { // if you change the separator do not forget to change the translation instruction in lib/prefs/short.php $time = $date . ' ' . $time; return $intro . ' ' . $time; } } }
/** * @param $tikiobj * @param $user * @param $tstart * @param $tstop * @param $offset * @param $maxRecords * @param string $sort_mode * @param string $find * @return array */ function list_tiki_items($tikiobj, $user, $tstart, $tstop, $offset, $maxRecords, $sort_mode = 'name_desc', $find = '') { global $user; $ret = array(); if (!is_array($tikiobj)) { return $ret; } $tikiobj = array_unique($tikiobj); if (in_array('wiki', $tikiobj)) { $tikiobj[] = 'wiki page'; $tikiobj[] = 'wiki comment'; } foreach ($tikiobj as $type) { if ($type != '' && $type != 'wiki') { $objectType = $type == 'wiki comment' ? 'wiki page' : $type; $result = $this->get_object_cal_infos($type, array($tstart, $tstop, $objectType)); if (is_object($result)) { while ($res = $result->fetchRow()) { if ($res['start'] > 0) { $res['show_description'] = 'y'; $res['visible'] = 'y'; $res['type'] = $type; $dstart = TikiLib::make_time(0, 0, 0, TikiLib::date_format('%m', $res['start']), TikiLib::date_format('%d', $res['start']), TikiLib::date_format('%Y', $res['start'])); $res['time'] = TikiLib::date_format('%H%M', $res['start']); $res['when'] = TikiLib::date_format('%H:%M', $res['start']); $when = '<b>' . $res['when'] . '</b>'; $url_vars = array($res['id'], $res['id2']); switch ($res['type']) { case 'art': $res['description'] = $this->parse_data($res['description']); break; case 'blog': $res['name'] = $res['parent'] . ' :: ' . $res['name']; break; case 'dir': $res['description'] = addslashes($res['dir_url']) . '<br />' . $res['description']; break; case 'forum': if ($res['fid'] > 0) { $url_vars = array($res['fid'], $res['id2'], 'threadId' . $res['id']); } break; case 'gal': $res['description'] = tra('New Image Uploaded by') . ' %s'; break; case 'nl': $res['description'] = tra('New Subscriptions'); $res['head'] = ' ... ' . $res['head']; break; case 'track': $res['description'] = tra('New Item in Tracker'); $res['parent'] = tra('tracker'); break; case 'wiki page': $res['parent'] = 'wiki'; break; } $res['url'] = $this->get_object_url($res['type'], $url_vars); if ($res['user'] != '') { include_once 'lib/smarty_tiki/modifier.username.php'; $res['user'] = smarty_modifier_username($res['user']); if (!strpos($res['description'], '%s')) { $br = $res['description'] == '' ? '' : '<br />'; $res['description'] = '<i>' . tra('by') . ' %s</i>' . $br . $res['description']; } $res['description'] = sprintf($res['description'], $res['user']); } $res['description'] = str_replace(array('"', "\n|\r"), array("'", ''), $res['description']); if ($res['name'] == '') { $res['name'] = $res['id']; } $res['where'] = str_replace("\n|\r", '', addslashes($res['parent'])); if ((!isset($where) || $where == '') && $res['parent'] != '') { $where = ' ' . tra('in') . ' <b>' . $res['where'] . '</b>'; } if ($res['head'] == '') { $res['head'] = $when . $where; } $res['group_description'] = $res['name']; $ret[$dstart][] = $res; unset($where); unset($when); } } } } } return $ret; }
$smarty->assign('currMonth', $dday); $cell[$i][$w]['firstDay'] = true; } else $cell[$i][$w]['firstDay'] = false; $cell[$i][$w]['focus'] = true; } else { $cell[$i][$w]['firstDay'] = false; $cell[$i][$w]['focus'] = false; } if (isset($listevents["$dday"])) { $e = 0; foreach ($listevents["$dday"] as $le) { $nbDaysLeftThisWeek = min(ceil(($le['endTimeStamp'] - $dday)/86400), (7-$w)); if ($calendarViewMode['casedefault'] == 'month') { $endOfCurrentMonth = $tikilib->make_time(23, 59, 59, TikiLib::date_format('m', $dday) + 1, 0, TikiLib::date_format2('Y', $dday)); $nbDaysLeftThisWeek = min(ceil(($endOfCurrentMonth - $dday)/86400), $nbDaysLeftThisWeek); } elseif ($calendarViewMode['casedefault'] == 'year') { $endOfCurrentYear = $tikilib->make_time(23, 59, 59, 12, 31, TikiLib::date_format2('Y', $dday)); $nbDaysLeftThisWeek = min(ceil(($endOfCurrentYear - $dday)/86400), $nbDaysLeftThisWeek); } if (!array_key_exists('nbDaysLeftThisWeek', $le)) { $le['nbDaysLeftThisWeek'] = $nbDaysLeftThisWeek; } $le['modifiable'] = in_array($le['calendarId'], $modifiable)? "y": "n"; $le['visible'] = in_array($le['calendarId'], $visible)? "y": "n"; $lec = $infocals['data']["{$le['calendarId']}"]; $leday["{$le['time']}$e"] = $le; $smarty->assign('allday', $le["result"]["allday"]); $smarty->assign('cellcalendarId', $le["calendarId"]); $smarty->assign('cellhead', $le["head"]);
$sort_mode = "start_asc"; } $listevents = $calendarlib->list_raw_items($_SESSION['CalendarViewGroups'], $user, $viewstart, $viewend, 0, -1, $sort_mode); for ($i = count($listevents) - 1; $i >= 0; --$i) { $listevents[$i]['modifiable'] = in_array($listevents[$i]['calendarId'], $modifiable) ? "y" : "n"; } } else { $listevents = $calendarlib->list_items($_SESSION['CalendarViewGroups'], $user, $viewstart, $viewend, 0, -1); } $smarty->assign_by_ref('listevents', $listevents); } else { $listevents = array(); } $mloop = TikiLib::date_format("%m", $viewstart); $dloop = TikiLib::date_format("%d", $viewstart); $yloop = TikiLib::date_format("%Y", $viewstart); $curtikidate = new TikiDate(); $display_tz = $tikilib->get_display_timezone(); if ($display_tz == '') { $display_tz = 'UTC'; } $curtikidate->setTZbyID($display_tz); $curtikidate->setLocalTime($dloop, $mloop, $yloop, 0, 0, 0, 0); $smarty->assign('display_tz', $display_tz); for ($i = 0; $i <= $numberofweeks; $i++) { $weeks[] = $curtikidate->getWeekOfYear(); foreach ($weekdays as $w) { $leday = array(); if ($calendarViewMode == 'day') { $dday = $daystart; } else {
/** * Smarty {html_select_time} function plugin * * Type: function<br> * Name: html_select_time<br> * Purpose: Prints the dropdowns for time selection * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time} * (Smarty online manual) * @param array * @param Smarty * @return string * @uses smarty_make_timestamp() */ function smarty_function_html_select_time($params, $smarty) { global $tikilib; $smarty->loadPlugin('smarty_shared_make_timestamp'); $smarty->loadPlugin('smarty_function_html_options'); /* Default values. */ $prefix = "Time_"; $time = time(); $display_hours = true; $display_minutes = true; $display_seconds = true; $display_meridian = true; $use_24_hours = true; $minute_interval = 1; $second_interval = 1; $hour_minmax = '0-23'; /* Should the select boxes be part of an array when returned from PHP? e.g. setting it to "birthday", would create "birthday[Hour]", "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]". Can be combined with prefix. */ $field_array = null; $all_extra = null; $hour_extra = null; $minute_extra = null; $second_extra = null; $meridian_extra = null; $hour_empty = null; $minute_empty = null; $second_empty = null; $all_empty = null; extract($params); if (!empty($all_empty)) { $hour_empty = $minute_empty = $second_empty = $all_empty; } if (!isset($time) or !$time) { $time = $tikilib->now; } else { if (is_string($time) && strpos($time, ':') !== false) { $e = explode(':', $time, 3); $time = $tikilib->make_time(isset($e[0]) ? $e[0] : 0, isset($e[1]) ? $e[1] : 0, isset($e[2]) ? $e[2] : 0, $tikilib->date_format('%m'), $tikilib->date_format('%d'), $tikilib->date_format('%Y')); } } if (empty($hour_minmax) || !preg_match('/^[0-2]?[0-9]-[0-2]?[0-9]$/', $hour_minmax)) { $hour_minmax = '0-23'; } //only needed for end_ and the static variable in the date_format functions seem to cause problems without the if if ($prefix == 'end_') { $time_hr24 = TikiLib::date_format('%H%M%s', $time); } $html_result = ''; if ($display_hours) { if ($use_24_hours) { list($hour_min, $hour_max) = explode('-', $hour_minmax); $hours = range($hour_min == 24 ? 0 : $hour_min, $hour_max == 0 || $hour_max == 24 ? 23 : $hour_max); $hour_fmt = '%H'; $latest = 23; //12-hour clock } else { $hours = range(1, 12); $hour_fmt = '%I'; $latest = 11; } for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) { $hours[$i] = sprintf('%02d', $hours[$i]); } if ($prefix == 'end_' && $time_hr24 == '000000') { $selected = $latest; } elseif ($prefix == 'duration_' || $prefix == 'startday_' || $prefix == 'endday_') { if ($use_24_hours) { $selected = floor($time / (60 * 60)); } else { $selected = date('h', strtotime(floor($time / (60 * 60)) . ':00 ')); } } else { $selected = $time == '--' ? $hour_empty : TikiLib::date_format($hour_fmt, $time); } $html_result .= '<select class="form-control date" name='; if (null !== $field_array) { $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"'; } else { $html_result .= '"' . $prefix . 'Hour"'; } if (null !== $hour_extra) { $html_result .= ' ' . $hour_extra; } if (null !== $all_extra) { $html_result .= ' ' . $all_extra; } $html_result .= '>' . "\n"; if (!empty($hour_empty)) { $hours = array_merge(array($hour_empty == ' ' ? '' : $hour_empty), $hours); } $html_result .= smarty_function_html_options(array('output' => $hours, 'values' => $hours, 'selected' => $selected, 'print_result' => false), $smarty); $html_result .= "</select>\n"; } if ($display_minutes) { $all_minutes = range(0, 59); for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i += $minute_interval) { $minutes[] = sprintf('%02d', $all_minutes[$i]); } if ($minute_interval > 1) { $minutes[] = 59; } if ($time !== '--') { $minute = strftime('%M', $time); } else { $minute = '00'; } if (in_array($minute, $minutes) == false) { for ($i = 0, $for_max = count($minutes); $i < $for_max; $i++) { if ((int) $minute > (int) $minutes[$i] && ((int) $minute < (int) $minutes[$i + 1] || empty($minutes[$i + 1]))) { array_splice($minutes, $i + 1, 0, $minute); $i = $for_max; } } } if ($prefix == 'end_' && ($time_hr24 == '000000' || $minute == 59)) { $selected = 59; } else { if ($time == '--') { $selected = $minute_empty; } else { if (in_array($minute, $minutes)) { $selected = $minute; } else { $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval); } } } //minute intervals less than 10 are followed by a '0', here we ensure that they are selectable if (strlen($selected) == 1) { $selected = '0' . $selected; } $html_result .= '<select class="form-control date" name='; if (null !== $field_array) { $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"'; } else { $html_result .= '"' . $prefix . 'Minute"'; } if (null !== $minute_extra) { $html_result .= ' ' . $minute_extra; } if (null !== $all_extra) { $html_result .= ' ' . $all_extra; } $html_result .= '>' . "\n"; if (!empty($minute_empty)) { $minutes = array_merge(array($minute_empty == ' ' ? '' : $minute_empty), $minutes); } $html_result .= smarty_function_html_options(array('output' => $minutes, 'values' => $minutes, 'selected' => $selected, 'print_result' => false), $smarty); $html_result .= "</select>\n"; } if ($display_seconds) { $all_seconds = range(0, 59); for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i += $second_interval) { $seconds[] = sprintf('%02d', $all_seconds[$i]); } if ($second_interval > 1) { $seconds[] = 59; } if ($prefix == 'end_' && ($time_hr24 == '000000' || strftime('%M', $time) == 59)) { $selected = 59; } else { $selected = $time == '--' ? $second_empty : intval(floor(strftime('%S', $time) / $second_interval) * $second_interval); } $html_result .= '<select class="form-control date" name='; if (null !== $field_array) { $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"'; } else { $html_result .= '"' . $prefix . 'Second"'; } if (null !== $second_extra) { $html_result .= ' ' . $second_extra; } if (null !== $all_extra) { $html_result .= ' ' . $all_extra; } $html_result .= '>' . "\n"; if (!empty($seconde_empty)) { $secondes = array_merge(array($seconde_empty == ' ' ? '' : $seconde_empty), $secondes); } $html_result .= smarty_function_html_options(array('output' => $seconds, 'values' => $seconds, 'selected' => $selected, 'print_result' => false), $smarty); $html_result .= "</select>\n"; } if (!$use_24_hours) { $html_result .= '<select class="form-control date" name='; if (null !== $field_array) { $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"'; } else { $html_result .= '"' . $prefix . 'Meridian"'; } if (null !== $meridian_extra) { $html_result .= ' ' . $meridian_extra; } if (null !== $all_extra) { $html_result .= ' ' . $all_extra; } $html_result .= '>' . "\n"; $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'), 'values' => array('am', 'pm'), 'selected' => TikiLib::date_format('%p', $time), 'print_result' => false), $smarty); $html_result .= "</select>\n"; } $html_result = '<span dir="ltr">' . $html_result . '</span>'; return $html_result; }
/** * Get calendar and its events * * @param $calIds * @param $viewstart * @param $viewend * @param $group_by * @param $item_name * @param bool $listmode if set to true populate listevents key of the returned array * @return array */ function getCalendar($calIds, &$viewstart, &$viewend, $group_by = '', $item_name = 'events', $listmode = false) { global $user, $prefs; // Global vars used by tiki-calendar_setup.php (this has to be changed) global $calendarViewMode, $request_day, $request_month; global $request_year, $dayend, $myurl; global $weekdays, $daysnames, $daysnames_abr; include 'tiki-calendar_setup.php'; $smarty = TikiLib::lib('smarty'); $tikilib = TikiLib::lib('tiki'); //FIXME : maxrecords = 50 $listtikievents = $this->list_items_by_day($calIds, $user, $viewstart, $viewend, 0, 50); $mloop = TikiLib::date_format('%m', $viewstart); $dloop = TikiLib::date_format('%d', $viewstart); $yloop = TikiLib::date_format('%Y', $viewstart); $curtikidate = new TikiDate(); $display_tz = $tikilib->get_display_timezone(); if ($display_tz == '') { $display_tz = 'UTC'; } $curtikidate->setTZbyID($display_tz); $curtikidate->setLocalTime($dloop, $mloop, $yloop, 0, 0, 0, 0); $listevents = array(); // note that number of weeks starts at ZERO (i.e., zero = 1 week to display). for ($i = 0; $i <= $numberofweeks; $i++) { $weeks[] = $curtikidate->getWeekOfYear(); foreach ($weekdays as $w) { $leday = array(); if ($group_by == 'day') { $key = 0; } if ($calendarViewMode['casedefault'] == 'day') { $dday = $daystart; } else { $dday = $curtikidate->getTime(); $curtikidate->addDays(1); } $cell[$i][$w]['day'] = $dday; if ($calendarViewMode['casedefault'] == 'day' or $dday >= $daystart && $dday <= $dayend) { $cell[$i][$w]['focus'] = true; } else { $cell[$i][$w]['focus'] = false; } if (isset($listtikievents["{$dday}"])) { $e = -1; foreach ($listtikievents["{$dday}"] as $lte) { $lte['desc_name'] = $lte['name']; if ($group_by_item != 'n') { if ($group_by != 'day') { $key = $lte['id'] . '|' . $lte['type']; } if (!isset($leday[$key])) { $leday[$key] = $lte; if ($group_by == 'day') { $leday[$key]['description'] = array($lte['where'] => array($lte['group_description'])); $leday[$key]['head'] = TikiLib::date_format($prefs['short_date_format'], $cell[$i][$w]['day']); } else { $leday[$key]['description'] = ' - <b>' . $lte['when'] . '</b> : ' . tra($lte['action']) . ' ' . $lte['description']; $leday[$key]['head'] = $lte['name'] . ', <i>' . tra('in') . ' ' . $lte['where'] . '</i>'; } $leday[$key]['desc_name'] = ''; } else { $leday_item =& $leday[$key]; $leday_item['user'] .= ', ' . $lte['user']; if (!isset($leday_item['action']) || !is_integer($leday_item['action'])) { $leday_item['action'] = 1; } $leday_item['action']++; if ($group_by == 'day') { $leday_item['name'] .= '<br />' . $lte['name']; $leday_item['desc_name'] = $leday_item['action'] . ' ' . tra($item_name) . ': '; $leday_item['description'][$lte['where']][] = $lte['group_description']; } else { $leday_item['name'] = $lte['name'] . ' (x<b>' . $leday_item['action'] . '</b>)'; $leday_item['desc_name'] = $leday_item['action'] . ' ' . tra($item_name); if ($lte['show_description'] == 'y' && !empty($lte['description'])) { $leday_item['description'] .= ",\n<br /> - <b>" . $lte['when'] . '</b> : ' . tra($lte['action']) . ' ' . $lte['description']; $leday_item['show_description'] = 'y'; } } } } else { $e++; $key = "{$lte['time']}{$e}"; $leday[$key] = $lte; $lte['desc_name'] .= tra($lte['action']); } } foreach ($leday as $key => $lte) { if ($group_by == 'day') { $desc = ''; foreach ($lte['description'] as $desc_where => $desc_items) { $desc_items = array_unique($desc_items); foreach ($desc_items as $desc_item) { if ($desc != '') { $desc .= '<br />'; } $desc .= '- ' . $desc_item; if (!empty($lte['show_location']) && $lte['show_location'] == 'y' && $desc_where != '') { $desc .= ' <i>[' . $desc_where . ']</i>'; } } } $lte['description'] = $desc; } $smarty->assign('calendar_type', $myurl == 'tiki-action_calendar.php' ? 'tiki_actions' : 'calendar'); $smarty->assign_by_ref('item_url', $lte["url"]); $smarty->assign_by_ref('cellhead', $lte["head"]); $smarty->assign_by_ref('cellprio', $lte["prio"]); $smarty->assign_by_ref('cellcalname', $lte["calname"]); $smarty->assign('celllocation', ""); $smarty->assign('cellcategory', ""); $smarty->assign_by_ref('cellname', $lte["desc_name"]); $smarty->assign('cellid', ""); $smarty->assign_by_ref('celldescription', $lte["description"]); $smarty->assign('show_description', $lte["show_description"]); if (!isset($leday[$key]["over"])) { $leday[$key]["over"] = ''; } else { $leday[$key]["over"] .= "<br />\n"; } $leday[$key]["over"] .= $smarty->fetch("tiki-calendar_box.tpl"); } } if (is_array($leday)) { ksort($leday); $cell[$i][$w]['items'] = array_values($leday); } } } if (isset($_SESSION['CalendarViewList']) && $_SESSION['CalendarViewList'] == 'list' || $listmode) { if (is_array($listtikievents)) { foreach ($listtikievents as $le) { if (is_array($le)) { foreach ($le as $e) { $listevents[] = $e; } } } } } return array('cell' => $cell, 'listevents' => $listevents, 'weeks' => $weeks, 'weekdays' => $weekdays, 'daysnames' => $daysnames, 'daysnames_abr' => $daysnames_abr, 'trunc' => $trunc); }
/** * Transform a last period to a 2 dates * */ public function period2dates($when) { global $prefs; $tikilib = TikiLib::lib('tiki'); $now = $tikilib->now; $sec = TikiLib::date_format("%s", $now); $min = TikiLib::date_format("%i", $now); $hour = TikiLib::date_format("%H", $now); $day = TikiLib::date_format("%d", $now); $month = TikiLib::date_format("%m", $now); $year = TikiLib::date_format("%Y", $now); switch ($when) { case 'lasthour': $begin = $now - 60 * 60; break; case 'day': $begin = TikiLib::make_time(0, 0, 0, $month, $day, $year); break; case 'lastday': $begin = Tikilib::make_time($hour - 24, $min, $sec, $month, $day, $year); break; case 'week': $iweek = TikiLib::date_format("%w", $now); // 0 for Sunday... $calendarlib = TikiLib::lib('calendar'); $firstDayofWeek = $calendarlib->firstDayofWeek(); $iweek -= $firstDayofWeek; if ($iweek < 0) { $iweek += 7; } $begin = TikiLib::make_time(0, 0, 0, $month, $day - $iweek, $year); break; case 'lastweek': $begin = Tikilib::make_time($hour, $min, $sec, $month, $day - 7, $year); break; case 'month': $begin = TikiLib::make_time(0, 0, 0, $month, 1, $year); break; case 'lastmonth': $begin = TikiLib::make_time($hour, $min, $sec, $month - 1, $day, $year); break; case 'year': $begin = TikiLib::make_time(0, 0, 0, 1, 1, $year); break; case 'lastyear': $begin = TikiLib::make_time($hour, $min, $sec, $month, $day, $year - 1); break; default: $begin = $now; break; } return array((int) $begin, (int) $now); }
/** * @param $format * @param bool $timestamp * @param bool $_user * @param int $input_format * @return string */ static function date_format2($format, $timestamp = false, $_user = false, $input_format = 5) { return TikiLib::date_format($format, $timestamp, $_user, $input_format, false); }
$smarty->assign('edit', true); $hour_minmax = ceil($calendar['startday'] / (60 * 60)) . '-' . ceil($calendar['endday'] / (60 * 60)); //Add event buttons - either button on top of page or one of the buttons on a specific day } elseif (isset($calID) and $tiki_p_add_events == 'y') { $calendar = $calendarlib->get_calendar($calID); if (isset($_REQUEST['todate'])) { $now = $_REQUEST['todate']; } else { $now = $tikilib->now; } //if current time of day is within the calendar day (between startday and endday), then use now as start, otherwise use beginning of calendar day $now_start = $tikilib->make_time(abs(ceil($calendar['startday'] / (60 * 60))), TikiLib::date_format('%M', $now), TikiLib::date_format('%S', $now), TikiLib::date_format('%m', $now), TikiLib::date_format('%d', $now), TikiLib::date_format('%Y', $now)); $now_end = $tikilib->make_time(abs(ceil($calendar['endday'] / (60 * 60))), TikiLib::date_format('%M', $now), TikiLib::date_format('%S', $now), TikiLib::date_format('%m', $now), TikiLib::date_format('%d', $now), TikiLib::date_format('%Y', $now)); $now_start = $now_start <= $now && $now_start + 60 * 60 < $now_end ? $now : $now_start; //if $now_end is midnight, make it one second before $now_end = TikiLib::date_format('%H%M%s', $now_start + 60 * 60) == '000000' ? $now_start + 60 * 60 - 1 : $now_start + 60 * 60; $calitem = array('calitemId' => 0, 'user' => $user, 'name' => '', 'url' => '', 'description' => '', 'status' => $calendar['defaulteventstatus'], 'priority' => 0, 'locationId' => 0, 'categoryId' => 0, 'nlId' => 0, 'start' => $now_start, 'end' => $now_end, 'duration' => 60 * 60, 'recurrenceId' => 0, 'allday' => $calendar['allday'] == 'y' ? true : false); $hour_minmax = abs(ceil(($calendar['startday'] - 1) / (60 * 60))) . '-' . ceil($calendar['endday'] / (60 * 60)); $id = 0; $smarty->assign('edit', true); } else { $smarty->assign('errortype', 401); $smarty->assign('msg', tra("You do not have permission to view this page")); $smarty->display("error.tpl"); die; } if (!empty($id) && $calendar['personal'] == 'y' && $calitem['user'] != $user) { $smarty->assign('errortype', 401); $smarty->assign('msg', tra("You do not have permission to view this page")); $smarty->display("error.tpl"); die;
$date_min = 0; if ($_SESSION["thedate"] < $tikilib->now) { $date_max = $_SESSION["thedate"]; } else { if ($tiki_p_admin == 'y' || $tiki_p_admin_cms == 'y') { $date_max = $_SESSION["thedate"]; } else { $date_max = $tikilib->now; } } } else { $date_min = 0; $date_max = $tikilib->now; } //Keep track of month of last viewed article for article months_links module foldable display $_SESSION['cms_last_viewed_month'] = TikiLib::date_format("%Y-%m", $date_max); $min_rating = isset($_REQUEST['min_rating']) ? $_REQUEST['min_rating'] : ''; $max_rating = isset($_REQUEST['max_rating']) ? $_REQUEST['max_rating'] : ''; if (isset($_REQUEST["find"])) { $find = $_REQUEST["find"]; } else { $find = ''; } $smarty->assign_by_ref('find', $find); if (isset($_REQUEST["type"])) { $type = $_REQUEST["type"]; } else { $type = ''; } if (isset($_REQUEST["topic"])) { $topic = $_REQUEST["topic"];
} $viewstart = $tikilib->make_time(0, 0, 0, $viewstart_m, $viewstart_d, $viewstart_y); } $daystart = $viewstart; // then go to the end of the week for $viewend // $viewend = $viewstart + (7 * $d) - 1; $viewend = $tikilib->make_time(0, 0, 0, TikiLib::date_format("%m", $daystart), TikiLib::date_format("%d", $daystart) + 7, TikiLib::date_format("%Y", $daystart)) - 1; $dayend = $viewend; $numberofweeks = 0; } else { $firstweek = $currentweek; $lastweek = $currentweek; // $viewend = $viewstart + ($d - 1); $viewend = $tikilib->make_time(0, 0, 0, TikiLib::date_format("%m", $viewstart), TikiLib::date_format("%d", $viewstart) + 1, TikiLib::date_format("%Y", $viewstart)) - 1; $dayend = $daystart; $weekdays = array(TikiLib::date_format('%w', $focusdate)); $numberofweeks = 0; } $smarty->assign('viewstart', $viewstart); $smarty->assign('viewend', $viewend); $smarty->assign('numberofweeks', $numberofweeks); $smarty->assign('daystart', $daystart); $smarty->assign('dayend', $dayend); $calendarlib->getDayNames($firstDayofWeek, $daysnames, $daysnames_abr); $weeks = array(); $cell = array(); if (!function_exists('correct_start_day')) { /** * @param $d * @return int */
} else { $postId = $_REQUEST['postId']; } $post_info = $bloglib->get_post($postId); if (!$post_info) { $smarty->assign('msg', tra("Post not found")); $smarty->display("error.tpl"); die; } else { $bloglib->add_blog_post_hit($postId); } $blogId = $post_info['blogId']; //Keep track of month of last viewed posts for months_links module foldable display $_SESSION['blogs_last_viewed_month'] = TikiLib::date_format("%Y-%m", $post_info['created']); $blog_data = $bloglib->get_blog($blogId); if (!$blog_data) { $smarty->assign('msg', tra("Blog not found")); $smarty->display("error.tpl"); die; } $tikilib->get_perm_object($blogId, 'blog'); $access->check_permission('tiki_p_read_blog'); $ownsblog = 'n'; if ($user && $user == $blog_data["user"]) { $ownsblog = 'y';
public function Quiz() { global $user; $userlib = TikiLib::lib('user'); $this->dbFields = array("id", "bDeleted", "timestamp", "nAuthor", "bOnline", "nTaken", "sName", "sDescription", "datePub", "dateExp", "bRandomQuestions", "nRandomQuestions", "bShuffleQuestions", "bShuffleAnswers", "bLimitQuestionsPerPage", "nLimitQuestionsPerPage", "bTimeLimited", "nTimeLimit", "bMultiSession", "bCanRepeat", "nCanRepeat", "sGradingMethod", "sShowScore", "sShowCorrectAnswers", "sPublishStats", "bAdditionalQuestions", "bForum", "sForum", "sPrologue", "sData", "sEpilogue"); $this->id = 0; $this->bDeleted = 0; $this->timestamp = $this->now; $this->nAuthor = $userlib->get_user_id($user); $this->sAuthor = $user; $this->bOnline = 'n'; $this->nTaken = 'n'; $this->sName = ""; $this->sDescription = ""; $this->datePub = $this->now; $this->dateExp = TikiLib::make_time(0, 0, 0, 1, 1, TikiLib::date_format("%Y") + 10); $this->bRandomQuestions = "y"; $this->nRandomQuestions = 10; $this->nShuffleQuestions = "y"; $this->bShuffleAnswers = "y"; $this->bLimitQuestionsPerPage = "y"; $this->nLimitQuestionsPerPage = 1; $this->bTimeLimited = "n"; $this->nTimeLimit = "1"; $this->bMultiSession = "n"; $this->bCanRepeat = "y"; $this->nCanRepeat = "unlimited"; $this->sGradingMethod = "machine"; $this->sShowScore = "immediately"; $this->sShowCorrectAnswers = "immediately"; $this->sPublishStats = "immediately"; $this->bAdditionalQuestions = "n"; $this->forum = "n"; $this->forumName = ""; $this->prologue = ""; $this->epilogue = ""; }
function unixtime2dostime($unix_time) { if ($unix_time % 1) $unix_time++; // Round up to even seconds. list($year, $month, $mday, $hour, $min, $sec) = explode(' ', TikiLib::date_format('%Y %m %e %H %M %S', $unix_time)); if ($year < 1980) list($year, $month, $mday, $hour, $min, $sec) = array( 1980, 1, 1, 0, 0, 0 ); $dosdate = (($year - 1980) << 9) | ($month << 5) | $mday; $dostime = ($hour << 11) | ($min << 5) | ($sec >> 1); return array( $dosdate, $dostime ); }
function smarty_modifier_tiki_date_format($string, $format, $_user = false) { return TikiLib::date_format(tra($format), $string, $_user); }
function wikiplugin_trackerlist($data, $params) { global $smarty, $tikilib, $dbTiki, $userlib, $tiki_p_admin_trackers, $prefs, $_REQUEST, $tiki_p_view_trackers, $user, $page, $tiki_p_tracker_vote_ratings, $tiki_p_tracker_view_ratings, $trklib, $tiki_p_traker_vote_rating, $tiki_p_export_tracker, $tiki_p_watch_trackers; require_once("lib/trackers/trackerlib.php"); global $notificationlib; include_once('lib/notifications/notificationlib.php');//needed if plugin tracker after plugin trackerlist static $iTRACKERLIST = 0; ++$iTRACKERLIST; $smarty->assign('iTRACKERLIST', $iTRACKERLIST); $default = array( 'calendarfielddate' => '', 'wiki' => '', 'calendarviewmode' => 'month', 'calendarstickypopup' => 'n', 'calendarbeginmonth' => 'y', 'calendarviewnavbar' => 'y', 'calendartitle'=>'', 'calendardelta' => '', 'force_compile' => 'n' ); $params = array_merge($default, $params); extract($params, EXTR_SKIP); $skip_status_perm_check = false; if ($prefs['feature_trackers'] != 'y' || !isset($trackerId) || !($tracker_info = $trklib->get_tracker($trackerId))) { return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } else { global $auto_query_args; $auto_query_args_local = array('trackerId', 'tr_initial',"tr_sort_mode$iTRACKERLIST",'tr_user', 'filterfield', 'filtervalue', 'exactvalue', 'itemId'); $auto_query_args = empty($auto_query_args)? $auto_query_args_local: array_merge($auto_query_args, $auto_query_args_local); $smarty->assign('listTrackerId', $trackerId); $tracker_info = $trklib->get_tracker($trackerId); if ($t = $trklib->get_tracker_options($trackerId)) { $tracker_info = array_merge($tracker_info, $t); } if (!isset($sort)) { $sort = 'n'; } if ($tiki_p_admin_trackers != 'y') { $perms = $tikilib->get_perm_object($trackerId, 'tracker', $tracker_info, false); if ($perms['tiki_p_view_trackers'] != 'y' && !$user) { return; } $userCreatorFieldId = $trklib->get_field_id_from_type($trackerId, 'u', '1%'); $groupCreatorFieldId = $trklib->get_field_id_from_type($trackerId, 'g', '1%'); if ($perms['tiki_p_view_trackers'] != 'y' && $tracker_info['writerCanModify'] != 'y' && empty($userCreatorFieldId) && empty($groupCreatorFieldId)) { return; } $smarty->assign_by_ref('perms', $perms); } global $trklib; require_once("lib/trackers/trackerlib.php"); if (!empty($fields)) { $limit = $fields; } else { $limit = ''; } if (!empty($filterfield) && !empty($limit)) { $limit = array_unique(array_merge($limit, $filterfield)); } if (!empty($popup)) { $limit = array_unique(array_merge($limit, $popup)); } if (!empty($calendarfielddate)) { $limit = array_unique(array_merge($limit, $calendarfielddate)); } if (!empty($limit) && $trklib->test_field_type($limit, array('C'))) { $limit = ''; } $allfields = $trklib->list_tracker_fields($trackerId, 0, -1, 'position_asc', '', true, '', $trklib->flaten($limit)); if (!empty($fields)) { $listfields = $fields; //We must include the $calendarfielddate, even if they are not in the listfields if (!empty($calendarfielddate)) { foreach($calendarfielddate as $f) { if (!in_array($f, $listfields)) { $listfields[] = $f; } } } if ($sort == 'y') { $allfields = $trklib->sort_fields($allfields, $listfields); } } elseif (!empty($wiki) || !empty($tpl) || !empty($tplwiki)) { if (!empty($wiki)) { $listfields = $trklib->get_pretty_fieldIds($wiki, 'wiki', $outputPretty); } elseif (!empty($tplwiki)) { $listfields = $trklib->get_pretty_fieldIds($tplwiki, 'wiki', $outputPretty); } else { $listfields = $trklib->get_pretty_fieldIds($tpl, 'tpl', $outputPretty); } } else { $listfields = ''; } if (!empty($compute) && !empty($listfields)) { if (preg_match_all('/[0-9.]+/', $compute, $matches)) { foreach ($matches[0] as $f) { if (!in_array($f, $listfields)) $listfields[] = $f; } } } if (!empty($filterfield)) { if (is_array($filterfield)) { foreach ($filterfield as $ff) { unset($filterfieldok); if (is_array($ff)) {// already checked in trackerfilter $filterfieldok=true; break; } else { foreach ($allfields['data'] as $f) { if ($f['fieldId'] == $ff) { $filterfieldok=true; break; } } } if (!isset($filterfieldok)) break; } } else { foreach ($allfields['data'] as $f) { if ($f['fieldId'] == $filterfield) { $filterfieldok=true; break; } } } if (!isset($filterfieldok)) { return tra('incorrect filterfield'); } } $filter = array(); if (isset($periodQuantity)) { switch ($periodUnit) { case 'hour': $periodUnit = 3600; break; case 'day': $periodUnit = 86400; break; case 'week': $periodUnit = 604800; break; case 'month': $periodUnit = 2628000; break; default: break; } if (!isset($periodType)) { $periodType = 'c'; } if (is_int($periodUnit) && ($periodType == 'm' ) ) { $filter['lastModifAfter'] = $tikilib->now - ($periodQuantity * $periodUnit); $filter['lastModifBefore'] = $tikilib->now; } elseif (is_int($periodUnit)) { # case for periodType beig c or anything else (therefore, set as case for default) $filter['createdAfter'] = $tikilib->now - ($periodQuantity * $periodUnit); $filter['createdBefore'] = $tikilib->now; } } if (isset($_REQUEST['reloff']) && empty($_REQUEST['itemId']) && !empty($_REQUEST['trackerId'])) { //coming from a pagination $items = $trklib->list_items( $_REQUEST['trackerId'], $_REQUEST['reloff'], 1, '', '', isset($_REQUEST['filterfield']) ? preg_split('/\s*:\s*/', $_REQUEST['filterfield']) : '', isset($_REQUEST['filtervalue']) ? preg_split('/\s*:\s*/', $_REQUEST['filtervalue']) : '', isset($_REQUEST['status']) ? preg_split('/\s*:\s*/', $_REQUEST['status']) : '', isset($_REQUEST['initial']) ? $_REQUEST['initial'] : '', isset($_REQUEST['exactvalue']) ? preg_split('/\s*:\s*/', $_REQUEST['exactvalue']) : '', $filter ); if (isset($items['data'][0]['itemId'])) { $_REQUEST['cant'] = $items['cant']; $_REQUEST['itemId'] = $items['data'][0]['itemId']; } } if (!empty($_REQUEST['itemId']) && $tiki_p_tracker_vote_ratings == 'y' && $user) { $hasVoted = false; foreach ($allfields['data'] as $f) { if ($f['type'] == 's' && isset($tracker_info['useRatings']) and $tracker_info['useRatings'] == 'y' && ($f['name'] == 'Rating' || $f['name'] = tra('Rating'))) { $i = $f['fieldId']; if (isset($_REQUEST["ins_$i"]) && ($_REQUEST["ins_$i"] == 'NULL' || in_array($_REQUEST["ins_$i"], explode(',', $tracker_info['ratingOptions'])))) { $trklib->replace_rating($trackerId, $_REQUEST['itemId'], $i, $user, $_REQUEST["ins_$i"]); $hasVoted = true; } } elseif ($f['type'] == '*' || $f['type'] == 'STARS') { $i = $f['fieldId']; if (isset($_REQUEST["ins_$i"])) { $trklib->replace_star($_REQUEST["ins_$i"], $trackerId, $_REQUEST['itemId'], $f, $user); $hasVoted = true; } } } if ($hasVoted) { // Must strip NULL for remove my vote case $url = preg_replace('/[(\?)|&]vote=y/', '$1', preg_replace('/[(\?)|&]ins_[0-9]+=-?[0-9|N|U|L]*/', '$1', $_SERVER['REQUEST_URI'])); // reduce duplicate itemIds in query string $occurences = preg_match_all('/[(\?)|&]itemId=[0-9]+/', $url, $matches); if ($params['list_mode'] == 'y' && $occurences > 0) { $url = preg_replace('/[(\?)|&]itemId=[0-9]+/', '$1', $url, $occurences); } elseif ($occurences > 1) { $url = preg_replace('/&itemId=[0-9]+/', '', $url, $occurences - 1); } header("Location: $url"); die; } } if (!empty($showwatch) && $showwatch == 'y' && $prefs['feature_user_watches'] == 'y' && $tiki_p_watch_trackers == 'y' && !empty($user)) { if (isset($_REQUEST['watch']) && isset($_REQUEST['trackerId']) && $_REQUEST['trackerId'] == $trackerId) { if ($_REQUEST['watch'] == 'add') { $tikilib->add_user_watch($user, 'tracker_modified', $trackerId, 'tracker', $tracker_info['name'], "tiki-view_tracker.php?trackerId=" . $trackerId); } elseif ($_REQUEST['watch'] == 'stop') { $tikilib->remove_user_watch($user, 'tracker_modified', $trackerId, 'tracker'); } } if ($tikilib->user_watches($user, 'tracker_modified', $trackerId, 'tracker')) { $smarty->assign('user_watching_tracker', 'y'); } else { $smarty->assign('user_watching_tracker', 'n'); } } else { $smarty->clear_assign('user_watching_tracker'); } if (empty($showrss) || $showrss == 'n') { $smarty->assign('showrss', 'n'); } else { $smarty->assign('showrss', 'y'); } if (empty($listfields)) { foreach ($allfields['data'] as $f) { $listfields[] = $f['fieldId']; } } if (!empty($popup)) { $popupfields = $popup; } else { $popupfields = array(); } if ($t = $trklib->get_tracker_options($trackerId)) $tracker_info = array_merge($tracker_info, $t); $smarty->assign_by_ref('tracker_info', $tracker_info); //$query_array = array(); //$quarray = array(); //TikiLib::parse_str($_SERVER['QUERY_STRING'],$query_array); if (isset($stickypopup) && $stickypopup == 'y') { $stickypopup = true; } else { $stickypopup = false; } $smarty->assign_by_ref('stickypopup', $stickypopup); if (!isset($showtitle)) { $showtitle = 'n'; } $smarty->assign_by_ref('showtitle', $showtitle); if (!isset($showlinks)) { $showlinks = 'n'; } $smarty->assign_by_ref('showlinks', $showlinks); if (!isset($showdesc)) { $showdesc = 'n'; } $smarty->assign_by_ref('showdesc', $showdesc); if (!isset($showinitials)) { $showinitials = 'n'; } $smarty->assign_by_ref('showinitials', $showinitials); if (!isset($shownbitems)) { $shownbitems = 'n'; } $smarty->assign_by_ref('shownbitems', $shownbitems); if (!isset($showstatus)) { $showstatus = 'n'; } $smarty->assign_by_ref('showstatus', $showstatus); if (!isset($showfieldname)) { $showfieldname = 'y'; } $smarty->assign_by_ref('showfieldname', $showfieldname); if (!isset($showitemrank)) { $showitemrank = 'n'; } $smarty->assign_by_ref('showitemrank', $showitemrank); if (!isset($showdelete)) { $showdelete = 'n'; } $smarty->assign_by_ref('showdelete', $showdelete); if (!isset($showpenditem)) { $showpenditem = 'n'; } $smarty->assign_by_ref('showpenditem', $showpenditem); if (!isset($showcloseitem)) { $showcloseitem = 'n'; } $smarty->assign_by_ref('showcloseitem', $showcloseitem); if (!isset($showopenitem)) { $showopenitem = 'n'; } $smarty->assign_by_ref('showopenitem', $showopenitem); if (!isset($showpagination)) { $showpagination = 'y'; } $smarty->assign_by_ref('showpagination', $showpagination); if (!isset($sortchoice)) { $sortchoice = ''; } else { foreach ($sortchoice as $i=>$sc) { $sc = explode('|', $sc); $sortchoice[$i] = array('value'=>$sc[0], 'label'=>empty($sc[1])?$sc[0]: $sc[1]); } } $smarty->assign_by_ref('sortchoice', $sortchoice); if (!isset($status)) { $status = 'o'; } $tr_status = $status; $smarty->assign_by_ref('tr_status', $tr_status); if (!isset($list_mode)) { $list_mode = 'y'; } $smarty->assign_by_ref('list_mode', $list_mode); if (!isset($showcreated)) { $showcreated = $tracker_info['showCreated']; } $smarty->assign_by_ref('showcreated', $showcreated); if (!isset($showlastmodif)) { $showlastmodif = $tracker_info['showLastModif']; } $smarty->assign_by_ref('showlastmodif', $showlastmodif); if (!isset($more)) $more = 'n'; $smarty->assign_by_ref('more', $more); if (!isset($moreurl)) $moreurl = 'tiki-view_tracker.php'; $smarty->assign_by_ref('moreurl', $moreurl); if (!isset($url)) $url = ''; $smarty->assign_by_ref('url', $url); if (!isset($export)) $export = 'n'; $smarty->assign_by_ref('export', $export); if (!empty($ldelim)) $smarty->left_delimiter = $ldelim; if (!empty($rdelim)) $smarty->right_delimiter = $rdelim; if (isset($checkbox)) { $check = array('ix' => -1, 'type' => 'checkbox'); $cb = explode('/', $checkbox); if (isset($cb[0])) $check['fieldId'] = $cb[0]; if (isset($cb[1])) $check['name'] = $cb[1]; if (isset($cb[2])) $check['title'] = $cb[2]; if (isset($cb[3])) $check['submit'] = $cb[3]; if (isset($cb[4])) $check['action'] = $cb[4]; if (isset($cb[5])) $check['tpl'] = $cb[5]; if (isset($cb[6]) && $cb[6] == 'radio') { $check['radio'] = 'y'; $check['type'] = 'radio'; } if (isset($cb[6]) && $cb[6] == 'dropdown') $check['dropdown'] = 'y'; // is this actually used? $smarty->assign_by_ref('checkbox', $check); } if (isset($_REQUEST["tr_sort_mode$iTRACKERLIST"])) { $sort_mode = $_REQUEST["tr_sort_mode$iTRACKERLIST"]; } elseif (!isset($sort_mode)) { if (!empty($tracker_info['defaultOrderKey'])) { if ($tracker_info['defaultOrderKey'] == -1) $sort_mode = 'lastModif'; elseif ($tracker_info['defaultOrderKey'] == -2) $sort_mode = 'created'; elseif ($tracker_info['defaultOrderKey'] == -3) $sort_mode = 'itemId'; else $sort_mode = 'f_'.$tracker_info['defaultOrderKey']; if (isset($tracker_info['defaultOrderDir'])) { $sort_mode.= "_".$tracker_info['defaultOrderDir']; } else { $sort_mode.= "_asc"; } } else { $sort_mode = ''; } } elseif ($sort_mode != 'created_asc' && $sort_mode != 'lastModif_asc' && $sort_mode != 'created_desc' && $sort_mode != 'lastModif_desc' && !preg_match('/f_[0-9]+_(asc|desc)/', $sort_mode)) { return tra('Incorrect param').' sort_mode'; } $tr_sort_mode = $sort_mode; $smarty->assign_by_ref('tr_sort_mode', $tr_sort_mode); if (isset($compute)) { $max = -1; // to avoid confusion compute is on what you see or all the items } elseif (!isset($max)) { $max = $prefs['maxRecords']; } if (isset($_REQUEST['tr_offset']) && (!isset($forceoffset) || $forceoffset == 'n')) { $tr_offset = $_REQUEST['tr_offset']; } else if (isset($offset) && $offset >= 0) { $tr_offset = $offset; } else { $tr_offset = 0; } $smarty->assign_by_ref('tr_offset', $tr_offset); $tr_initial = ''; if ($showinitials == 'y') { if (isset($_REQUEST['tr_initial'])) { //$query_array['tr_initial'] = $_REQUEST['tr_initial']; $tr_initial = $_REQUEST['tr_initial']; } $smarty->assign('initials', explode(' ', 'a b c d e f g h i j k l m n o p q r s t u v w x y z')); } $smarty->assign_by_ref('tr_initial', $tr_initial); if ((isset($view) && $view == 'user') || isset($view_user) || isset($_REQUEST['tr_user'])) { if ($f = $trklib->get_field_id_from_type($trackerId, 'u', '1%')) { $filterfield[] = $f; $filtervalue[] = ''; if (!isset($_REQUEST['tr_user'])) { $exactvalue[] = isset($view)? (empty($user)?'Anonymous':$user): $view_user; } else { $exactvalue[] = $_REQUEST['tr_user']; $smarty->assign_by_ref('tr_user', $exactvalue); } if ($tracker_info['writerCanModify'] == 'y') { $skip_status_perm_check = true; } } } if (isset($view) && $view == 'page' && isset($_REQUEST['page'])) { if (($f = $trklib->get_field_id_from_type($trackerId, 'k', '1%')) || ($f = $trklib->get_field_id_from_type($trackerId, 'k', '%,1%')) || ($f = $trklib->get_field_id_from_type($trackerId, 'k'))) { $filterfield[] = $f; $filtervalue[] = ''; $exactvalue[] = $_REQUEST['page']; } } if (isset($view) && $view == 'ip') { if ($f = $trklib->get_field_id_from_type($trackerId, 'I', '1%')) { $filterfield[] = $f; $filtervalue[] = ''; $ip = $tikilib->get_ip_address(); $exactvalue[] = $ip; } } if (!isset($filtervalue)) { $filtervalue = ''; } else { foreach ($filtervalue as $i=>$f) { if ($f == '#user') { $filtervalue[$i] = $user; } else if ($f == '#default_group') { $filtervalue[$i] = $_SESSION['u_info']['group']; } } } if (!isset($exactvalue)) { $exactvalue = ''; } else { foreach ($exactvalue as $i=>$f) { if ($f == '#user') { $exactvalue[$i] = $user; } } } if (!empty($_REQUEST['itemId']) && (empty($ignoreRequestItemId) || $ignoreRequestItemId != 'y') ) { $itemId = $_REQUEST['itemId']; } if (isset($itemId)) { if (is_string($itemId) && strstr($itemId, ':')) { // JB Tiki7: This doesn't quite make sense as itemId is an array $itemId = explode(':', $itemId); // Probably just some redundant code TOKIL } $filter['tti.`itemId`'] = $itemId; } $newItemRateField = false; $status_types = $trklib->status_types(); $smarty->assign('status_types', $status_types); if (!isset($filterfield)) { $filterfield = ''; } else { if (!empty($filterfield)) { if (!empty($filtervalue)) { $fvs = $filtervalue; unset($filtervalue); for ($i = 0, $count_ff = count($filterfield); $i < $count_ff; ++$i) { $filtervalue[] = isset($fvs[$i])? $fvs[$i]:''; } } if (!empty($exactvalue)) { $evs = $exactvalue; unset($exactvalue); for ($i = 0, $count_ff2 = count($filterfield); $i < $count_ff2; ++$i) { if (isset($evs[$i])) { if (is_array($evs[$i])) { // already processed $exactvalue[] = $evs[$i]; } elseif (preg_match('/(not)?categories\(([0-9]+)\)/', $evs[$i], $matches)) { global $categlib; include_once('lib/categories/categlib.php'); if (ctype_digit($matches[2]) && $matches[2] > 0) { $filter = array('identifier'=>$matches[2], 'type'=>'descendants'); } else { $filter = NULL; } $categs = $categlib->getCategories($filter, true, false); $l = array($matches[2]); foreach ($categs as $cat) { $l[] = $cat['categId']; } if (empty($matches[1])) { $exactvalue[] = $l; } else { $exactvalue[] = array('not'=>$l); } } elseif (preg_match('/(not)?preference\((.*)\)/', $evs[$i], $matches)) { if (empty($matches[1])) { $exactvalue[] = $prefs[$matches[2]]; } else { $exactvalue[] = array('not'=>$prefs[$matches[2]]); } } elseif (preg_match('/(not)?field\(([0-9]+)(,([0-9]+|user)(,([0-9]+))?)?\)/', $evs[$i], $matches)) { // syntax field(fieldId, user, trackerId) or field(fieldId)(need the REQUEST['itemId'] or field(fieldId, itemId) or field(fieldId, user) if (empty($matches[4]) && !empty($_REQUEST['itemId'])) { // user the itemId of the url $matches[4] = $_REQUEST['itemId']; } if (!empty($matches[4]) && $matches[4] == 'user') { if (!empty($matches[6])) { // pick the user item of this tracker $t_i = $trklib->get_tracker($matches[6]); $matches[4] = $trklib->get_user_item($matches[6], $t_i, $user); } elseif ($prefs['userTracker'] == 'y') { //pick the generic user tracker global $userlib; $utid = $userlib->get_tracker_usergroup($user); $matches[4] = $trklib->get_item_id($utid['usersTrackerId'], $utid['usersFieldId'], $user); } } if (!empty($matches[4])) { $l = $trklib->get_item_value(0, $matches[4], $matches[2]); $field = $trklib->get_tracker_field($matches[2]); if ($field['type'] == 'r') { $refItemId = $l; $l = $trklib->get_item_value($field['options_array'][0], $refItemId, $field['options_array'][3]); } } if (empty($matches[1])) { $exactvalue[] = $l; } else { $exactvalue[] = array('not'=>$l); } } elseif (preg_match('/(less|greater|lessequal|greaterequal)\((.+)\)/', $evs[$i], $matches)) { $conv = array('less'=>'<', 'greater'=>'>', 'lessequal'=>'<=', 'greaterequal'=>'>='); $field = $trklib->get_tracker_field($filterfield[$i]); if ($field['type'] == 'f' || $field['type'] == 'j') { if ($matches[2] == 'now') { $matches[2] = $tikilib->now; } elseif (($r = strtotime($matches[2])) !== false) { $matches[2] = $r; } } $exactvalue[] = array($conv[$matches[1]]=>$matches[2]); } elseif (preg_match('/not\((.+)\)/', $evs[$i], $matches)) { $exactvalue[] = array('not' => $matches[1]); } else { $exactvalue[] = $evs[$i]; } } else { $exactvalue[] = ''; } } } } } if ($tiki_p_admin_trackers != 'y' && $perms['tiki_p_view_trackers'] != 'y' && $tracker_info['writerCanModify'] == 'y' && $user && $userCreatorFieldId) { //patch this should be in list_items if ($filterfield != $userCreatorFieldId || (is_array($filterfield) && !in_array($$userCreatorFieldId, $filterfield))) { if (is_array($filterfield)) $filterfield[] = $userCreatorFieldId; elseif (empty($filterfield)) $filterfield = $userCreatorFieldId; else $filterfield = array($filterfield, $fieldId); if (is_array($exactvalue)) $exactvalue[] = $user; elseif (empty($exactvalue)) $exactvalue = $user; else $exactvalue = array($exactvalue, $user); } } if ($tiki_p_admin_trackers != 'y' && $perms['tiki_p_view_trackers'] != 'y' && $user && $groupCreatorFieldId) { if ($filterfield != $groupCreatorFieldId || (is_array($filterfield) && !in_array($groupCreatorFieldId, $filterfield))) { $groups = $userlib->get_user_groups($user); if (is_array($filterfield)) $filterfield[] = $groupCreatorFieldId; elseif (empty($filterfield)) $filterfield = $groupCreatorFieldId; else $filterfield = array($filterfield, $fieldId); if (is_array($exactvalue)) $exactvalue[] = array_merge($exactvalue, $groups); elseif (empty($exactvalue)) $exactvalue = $groups; else $exactvalue = array_merge(array($exactvalue), $groups); global $group;// awful trick - but the filter garantee that the group is ok $smarty->assign_by_ref('ours', $group); $perms = array_merge($perms, $trklib->get_special_group_tracker_perm($tracker_info)); } } for ($i = 0, $count_allf = count($allfields['data']); $i < $count_allf; $i++) { if ($allfields['data'][$i]['type'] == 'C') { $infoComputed = $trklib->get_computed_info($allfields['data'][$i]['options_array'][0], $trackerId, $allfields['data']); if (!empty($infoComputed)) { $allfields['data'][$i] = array_merge($infoComputed, $allfields['data'][$i]); } } elseif ($allfields["data"][$i]['type'] == 'w') { /* keep track of dynamic list items referring to user selectors */ $refFieldId = $allfields["data"][$i]['options_array'][3]; $refField = $trklib->get_tracker_field($refFieldId); if ($refField['type'] == 'u') { $allfields["data"][$i]['type'] = $refField['type']; } } if ((in_array($allfields["data"][$i]['fieldId'], $listfields) or in_array($allfields["data"][$i]['fieldId'], $popupfields))and $allfields["data"][$i]['isPublic'] == 'y') { $passfields["{$allfields["data"][$i]['fieldId']}"] = $allfields["data"][$i]; } if (isset($check['fieldId']) && $allfields["data"][$i]['fieldId'] == $check['fieldId']) { $passfields["{$allfields["data"][$i]['fieldId']}"] = $allfields["data"][$i]; if (!in_array($allfields["data"][$i]['fieldId'], $listfields)) $allfields["data"][$i]['isPublic'] == 'n'; //don't show it $check['ix'] = count($passfields) -1; } if ($allfields["data"][$i]['name'] == 'page' && empty($filterfield) && empty($displayList) && !empty($view) && $view == 'page') { $filterfield = $allfields["data"][$i]['fieldId']; $filtervalue = $_REQUEST['page']; } if (isset($tracker_info['useRatings']) and $tracker_info['useRatings'] == 'y' and $allfields["data"][$i]['type'] == 's' and $allfields["data"][$i]['name'] == 'Rating') { $newItemRateField = $allfields["data"][$i]['fieldId']; } } $smarty->assign_by_ref('filterfield', $filterfield); $smarty->assign_by_ref('filtervalue', $filtervalue); $smarty->assign_by_ref('fields', $passfields); $smarty->assign_by_ref('exactvalue', $exactvalue); $smarty->assign_by_ref('listfields', $listfields); $smarty->assign_by_ref('popupfields', $popupfields); if (!empty($filterfield)) { $urlquery['filterfield'] = is_array($filtervalue) ? implode(':', $filterfield) : $filterfield; if (!is_array($filtervalue)) { $filtervalue = array($filtervalue); } $urlquery['filtervalue'] = is_array($filtervalue) ? implode(':', $filtervalue) : $filtervalue; $urlquery['exactvalue'] = is_array($exactvalue) ? implode(':', $exactvalue) : $exactvalue; $urlquery['trackerId'] = $trackerId; $smarty->assign('urlquery', $urlquery); } else { $smarty->assign('urlquery', ''); } if (!empty($export) && $export != 'n' && $tiki_p_export_tracker == 'y') { $exportUrl = "tiki-tracker-export?trackerId=$trackerId"; if (!empty($fields)) { $exportUrl .= '&displayedFields='.(is_array($fields)? implode(':', $fields): $fields); } if (is_array($filterfield)) { foreach ($filterfield as $i=>$fieldId) { $exportUrl .= "&f_$fieldId="; if (empty($filtervalue[$i])) { $exportUrl .= $exactvalue[$i]; } else { $exportUrl .= $filtervalue[$i]; } } } elseif (!empty($filterfield)) { $exportUrl .= "&f_$filterfield="; if (empty($filtervalue)) $exportUrl .= $exactvalue; else $exportUrl .= $filtervalue; } $smarty->assign('exportUrl', $exportUrl); } if (!empty($_REQUEST['delete'])) { if (($item_info = $trklib->get_item_info($_REQUEST['delete'])) && $trackerId == $item_info['trackerId']) { if ($tiki_p_admin_trackers == 'y' || ($perms['tiki_p_remove_tracker_items'] == 'y' && $item_info['status'] != 'p' && $item_info['status'] != 'c') || ($perms['tiki_p_remove_tracker_items_pending'] == 'y' && $item_info['status'] == 'p') || ($perms['tiki_p_remove_tracker_items_closed'] == 'y' && $item_info['status'] == 'c') ) { $trklib->remove_tracker_item($_REQUEST['delete']); } } } if (!empty($_REQUEST['closeitem'])) { if (($item_info = $trklib->get_item_info($_REQUEST['closeitem'])) && $trackerId == $item_info['trackerId']) { if ($tiki_p_admin_trackers == 'y' || ($perms['tiki_p_modify_tracker_items'] == 'y' && $item_info['status'] != 'p' && $item_info['status'] != 'c') || ($perms['tiki_p_modify_tracker_items_pending'] == 'y' && $item_info['status'] == 'p') || ($perms['tiki_p_modify_tracker_items_closed'] == 'y' && $item_info['status'] == 'c') ) { $trklib->change_status(array(array('itemId' => $_REQUEST['closeitem'])), 'c'); } } } if (!empty($_REQUEST['penditem'])) { if (($item_info = $trklib->get_item_info($_REQUEST['penditem'])) && $trackerId == $item_info['trackerId']) { if ($tiki_p_admin_trackers == 'y' || ($perms['tiki_p_modify_tracker_items'] == 'y' && $item_info['status'] != 'p' && $item_info['status'] != 'c') || ($perms['tiki_p_modify_tracker_items_pending'] == 'y' && $item_info['status'] == 'p') || ($perms['tiki_p_modify_tracker_items_closed'] == 'y' && $item_info['status'] == 'c') ) { $trklib->change_status(array(array('itemId' => $_REQUEST['penditem'])), 'p'); } } } if (!empty($_REQUEST['openitem'])) { if (($item_info = $trklib->get_item_info($_REQUEST['openitem'])) && $trackerId == $item_info['trackerId']) { if ($tiki_p_admin_trackers == 'y' || ($perms['tiki_p_modify_tracker_items'] == 'y' && $item_info['status'] != 'p' && $item_info['status'] != 'c') || ($perms['tiki_p_modify_tracker_items_pending'] == 'y' && $item_info['status'] == 'p') || ($perms['tiki_p_modify_tracker_items_closed'] == 'y' && $item_info['status'] == 'c') ) { $trklib->change_status(array(array('itemId' => $_REQUEST['openitem'])), 'o'); } } } if (!empty($calendarfielddate)) { global $calendarlib; include_once('lib/calendar/calendarlib.php'); $focusDate = empty($_REQUEST['todate'])? $tikilib->now: $_REQUEST['todate']; $focus = $calendarlib->infoDate($focusDate); if (!empty($calendardelta)) { if ($calendardelta[0] == '-') { $focus = $calendarlib->focusPrevious($focus, str_replace('-', '', $calendardelta)); } else { $focus = $calendarlib->focusNext($focus, str_replace('+', '', $calendardelta)); } } $calendarlib->focusStartEnd($focus, $calendarviewmode, $calendarbeginmonth, $startPeriod, $startNextPeriod); $cell = $calendarlib->getTableViewCells($startPeriod, $startNextPeriod, $calendarviewmode, $calendarlib->firstDayofWeek($user)); $filterfield[] = $calendarfielddate[0]; $filtervalue[] = ''; $exactvalue[] = array('>=' => $startPeriod['date']); $filterfield[] = empty($calendarfielddate[1])?$calendarfielddate[0]: $calendarfielddate[1]; $filtervalue[] = ''; $exactvalue[] = array('<' => $startNextPeriod['date']); } if (count($passfields)) { // Optimization: Group category fields using AND logic indicated by sub-array $catfilters = array(); $catfiltervalue = array(); $catfilternotvalue = array(); if (!empty($filterfield)) { foreach ($filterfield as $k => $ff) { $filterfieldinfo = $trklib->get_tracker_field($ff); if ($filterfieldinfo['type'] == 'e') { $catfilters[] = $k; if (!empty($filtervalue[$k]) && empty($exactvalue[$k]) ) { // Some people use filtervalue instead of exactvalue for category filters $exactvalue[$k] = $filtervalue[$k]; for ($i = 0; $i < $k; $i++) { if (!isset($exactvalue[$i])) { $exactvalue[$i] = ''; } } } if (array_key_exists('not', array($exactvalue[$k]))) { $catfilternotfield[0] = $ff; $catfilternotvalue[] = array($exactvalue[$k]); } else { $catfilterfield[0] = $ff; $catfiltervalue[] = array($exactvalue[$k]); } } } } if ($catfilters) { foreach ($catfilters as $cf) { unset($filterfield[$cf]); unset($exactvalue[$cf]); } if ($catfiltervalue) { // array_merge is used because it reindexes $filterfield = array_merge($filterfield, $catfilterfield); $exactvalue = array_merge($exactvalue, array($catfiltervalue)); } if ($catfilternotvalue) { $filterfield = array_merge($filterfield, $catfilternotfield); $exactvalue[] = array('not' => $catfilternotvalue); } } // End Optimization $items = $trklib->list_items( $trackerId, $tr_offset, $max, $tr_sort_mode, $passfields, (!empty($calendarfielddate) ? null : $filterfield), $filtervalue, $tr_status, $tr_initial, $exactvalue, $filter, $allfields, $skip_status_perm_check ); if (isset($silent) && $silent == 'y' && empty($items['cant'])) { return; } if ($items['cant'] == 1 && isset($goIfOne) && ($goIfOne == 'y' || $goIfOne == 1)) { header('Location: tiki-view_tracker_item.php?itemId='.$items['data'][0]['itemId'].'&trackerId='.$items['data'][0]['trackerId']); die; } if ($newItemRateField && !empty($items['data'])) { foreach ($items['data'] as $f=>$v) { $items['data'][$f]['my_rate'] = $tikilib->get_user_vote("tracker.".$trackerId.'.'.$items['data'][$f]['itemId'], $user); } } if ($tracker_info['useComments'] == 'y' && $tracker_info['showComments'] == 'y') { foreach ($items['data'] as $itkey=>$oneitem) { $items['data'][$itkey]['comments'] = $trklib->get_item_nb_comments($items['data'][$itkey]['itemId']); } } if ($tracker_info['useAttachments'] == 'y' && $tracker_info['showAttachments'] == 'y') { foreach ($items["data"] as $itkey=>$oneitem) { $res = $trklib->get_item_nb_attachments($items["data"][$itkey]['itemId']); $items["data"][$itkey]['attachments'] = $res['attachments']; } } if (!empty($compute) && !empty($items['data'])) { $fs = preg_split('/ *: */', $compute); foreach ($fs as $fieldId) { if (strstr($fieldId, "/")) { list($fieldId, $oper) = preg_split('/ *\/ */', $fieldId); $oper = strtolower($oper); if ($oper == 'average') { $oper = 'avg'; } elseif ($oper != 'sum' && $oper != 'avg') { $oper = 'sum'; } } else { $oper = 'sum'; } foreach ($items['data'] as $i=>$item) { foreach ($item['field_values'] as $field) { if ($field['fieldId'] == $fieldId) { if (preg_match('/^ *$/', $field['value']) || !is_numeric($field['value'])) $amount[$i] = '0'; else $amount[$i] = $field['value']; break; } } } eval('$value='.implode('+', $amount).';'); if ($oper == 'avg') $value = round($value / count($amount)); $computedFields[$fieldId][] = array_merge(array('computedtype' => 'n', 'operator'=>$oper, 'value'=>$value), $passfields[$fieldId]); } $smarty->assign_by_ref('computedFields', $computedFields); } else { $smarty->assign('computedFields', ''); } if (!empty($calendarfielddate)) { foreach ($items['data'] as $i => $item) { if (!empty($wiki)) { $smarty->assign('fields', $item['field_values']); $smarty->assign('item', $item); $smarty->assign('wiki', "wiki:$wiki"); $smarty->assign('showpopup', 'n'); $items['data'][$i]['over'] = $smarty->fetch('tracker_pretty_item.tpl'); } if (!empty($tplwiki)) { $smarty->assign('fields', $item['field_values']); $smarty->assign('item', $item); $smarty->assign('wiki', "tplwiki:$tplwiki"); $smarty->assign('showpopup', 'n'); $items['data'][$i]['over'] = $smarty->fetch('tracker_pretty_item.tpl'); } if (empty($items['data'][$i]['over'])) { $items['data'][$i]['over'] = $trklib->get_isMain_value($trackerId, $item['itemId']); } $items['data'][$i]['visible'] = 'y'; } $trklib->fillTableViewCell($items['data'], $calendarfielddate, $cell); $smarty->assign('cell', $cell); $smarty->assign('show_calendar_module', 'y'); $calendarlib->getDayNames($calendarlib->firstDayofWeek($user), $daysnames, $daysnames_abr); $smarty->assign('daysnames_abr', $daysnames_abr); $smarty->assign('focusmonth', TikiLib::date_format("%m", $focusDate)); $smarty->assign('module_params', array('viewmode'=>'n', 'showaction'=>'n', 'notitle'=>empty($calendartitle)?'y':'n', 'title'=>$calendartitle, 'viewnavbar' => $calendarviewnavbar, 'decorations'=> empty($calendartitle)?'n':'y')); $smarty->assign('tpl_module_title', tra($calendartitle)); $smarty->assign('now', $tikilib->now); $smarty->assign('calendarViewMode', $calendarviewmode); $smarty->assign('viewmodelink', $calendarviewmode); $smarty->assign('viewmode', $calendarviewmode); $focus_prev = $calendarlib->focusPrevious($focus, $calendarviewmode); $smarty->assign('focus_prev', $focus_prev['date']); $focus_next = $calendarlib->focusNext($focus, $calendarviewmode); $smarty->assign('focus_next', $focus_next['date']); $smarty->assign('daystart', $startPeriod['date']); $dayend = $calendarlib->infoDate($startNextPeriod['date']-1); $smarty->assign('dayend', $dayend['date']); $smarty->assign('today', TikiLib::make_time(0, 0, 0, TikiLib::date_format('%m'), TikiLib::date_format('%d'), TikiLib::date_format('%Y'))); $smarty->assign('sticky_popup', $calendarstickypopup); $smarty->assign('calendar_popup', $calendarpopup); $smarty->assign('showpopup', 'n'); global $headerlib; include_once('lib/headerlib.php'); $headerlib->add_cssfile('css/calendar.css', 20); return $smarty->fetch('modules/mod-calendar_new.tpl'); } if (!empty($wiki)) { $tpl = "wiki:$wiki"; } elseif (!empty($tplwiki)) { $tpl = "tplwiki:$tplwiki"; } elseif (empty($tpl)) { $tpl = ''; } if (!empty($tpl)) $smarty->security = true; $smarty->assign('tpl', $tpl); if (!empty($itemId) && $showpagination == 'y' && !empty($_REQUEST['cant'])) { $smarty->assign('max', 1); $smarty->assign('count_item', $_REQUEST['cant']); $smarty->assign('offset_arg', 'reloff'); $smarty->assign('tr_offset', $_REQUEST['reloff']); } else { $smarty->assign_by_ref('max', $max); $smarty->assign_by_ref('item_count', $items['cant']); $smarty->assign_by_ref('count_item', $items['cant']); $smarty->assign('offset_arg', 'tr_offset'); } $smarty->assign_by_ref('items', $items["data"]); $smarty->assign('daformat', $tikilib->get_long_date_format()." ".tra("at")." %H:%M"); if (!empty($params['googlemap']) && $params['googlemap'] == 'y') { $smarty->assign('trackerlistmapview', true); $smarty->assign('trackerlistmapname', "trackerlistgmap_$iTRACKERLIST"); // Check for custom bubble text $unlimitedallfields = $trklib->list_tracker_fields($trackerId); $markerfields = array(); foreach ($unlimitedallfields["data"] as $f) { if ($f["type"] == 'G' && $f["options_array"][0] == 'y' && !empty($f["options_array"][1])) { $markerfields = explode('|', $f["options_array"][1]); break; } } // Generate Google map plugin data if (!empty($params["googlemapicon"])) { $googlemapicon = $params["googlemapicon"]; } else { $googlemapicon = ''; } global $gmapobjectarray; $gmapobjectarray = array(); foreach ($items["data"] as $i) { if (!empty($params["url"])) { $href = str_replace('itemId', $i["itemId"], $params["url"]); } else { $href = 'tiki-view_tracker_item.php?itemId=' . $i["itemId"]; } $markertext = ''; $markertitle = $i["value"]; foreach ($markerfields as $k => $m) { foreach ($i["field_values"] as $f) { if ($f["fieldId"] == $m) { if ($k == 0 && !empty($f["value"])) { $markertitle = preg_replace("/[\r\n|\r|\n]/", "<br />", htmlspecialchars($f["value"])); } elseif (!empty($f["value"])) { if ($markertext) { $markertext .= '<br /><br />'; } $markertext .= preg_replace("/[\r\n|\r|\n]/", "<br />", htmlspecialchars($f["value"])); } break; } } } $gmapobjectarray[] = array('type' => 'trackeritem', 'id' => $i["itemId"], 'title' => $markertitle, 'href' => $href, 'icon' => $googlemapicon, 'text' => $markertext, ); } } else { $smarty->assign('trackerlistmapview', false); } $tracker = $trklib->get_tracker($trackerId, 0, -1); /*foreach ($query_array as $k=>$v) { if (!is_array($v)) { //only to avoid an error: eliminate the params that are not simple (ex: if you have in the same page a tracker list plugin and a tracker plugin, filling the tracker plugin interfers with the tracker list. In any case this is buggy if two tracker list plugins in the same page and if one needs the query value.... $quarray[] = urlencode($k) ."=". urlencode($v); } } if (is_array($quarray)) { $query_string = implode("&",$quarray); } else { $quering_string = ''; } $smarty->assign('query_string', $query_string); */ if (!$tracker) { $smarty->assign('msg', tra("Error in tracker ID")); return $smarty->fetch("error_raw.tpl"); } else { $save_fc = null; if (!empty($wiki) && $params['force_compile'] === 'y') { // some pretty trackers need to compile fresh for each item $save_fc = $smarty->force_compile; $smarty->force_compile = true; } //this options preloads the javascript for displaying sheets if (!empty($displaysheet) && $displaysheet == 'y') { $headerlib = TikiLib::lib("header"); $sheetlib = TikiLib::lib("sheet"); $sheetlib->setup_jquery_sheet(); $headerlib->add_jq_onready( '$("div.trackercontainer").sheet($.extend($.sheet.tikiOptions,{ editable:false, buildSheet: true, minSize: {rows: 0, cols: 0} }));' ); $smarty->assign('displaysheet', 'true'); } //this method sets up the sheet just like it would for jquery.sheet, but assumes that the javascript will be handled elsewere if (!empty($tableassheet) && $tableassheet == 'y') { $smarty->assign('tableassheet', 'true'); } $smarty->assign('context', $params); try { $str = $smarty->fetch('wiki-plugins/wikiplugin_trackerlist.tpl'); } catch (SmartyException $e) { $str = $e->getMessage(); } if ($save_fc !== null) { $smarty->force_compile = $save_fc; // presumably will be false but put it back anyway } return $str; } } else { $smarty->assign('msg', tra("No field indicated")); return $smarty->fetch("error_raw.tpl"); } } return $back; }
if (isset($prefs['feature_categoryobjects']) and $prefs['feature_categories'] == 'y') { if ($prefs['feature_categoryobjects'] == 'y') { $catids = $categlib->get_object_categories('article', $objId); $display_catobjects = $categlib->get_categoryobjects($catids); $smarty->assign('display_catobjects', $display_catobjects); } } if ($prefs['feature_categories'] == 'y' && $prefs['category_morelikethis_algorithm'] != '') { $freetaglib = TikiLib::lib('freetag'); $category_related_objects = $freetaglib->get_similar('article', $_REQUEST['articleId'], empty($prefs['category_morelikethis_mincommon_max']) ? $prefs['maxRecords'] : $prefs['category_morelikethis_mincommon_max'], null, 'category'); $smarty->assign_by_ref('category_related_objects', $category_related_objects); } } else { $smarty->assign('is_categorized', 'n'); } if ($prefs['feature_multilingual'] == 'y' && $article_data['lang']) { $multilinguallib = TikiLib::lib('multilingual'); $trads = $multilinguallib->getTranslations('article', $article_data['articleId'], $article_data["title"], $article_data['lang']); $smarty->assign('trads', $trads); } //Keep track of month of last viewed article for article months_links module foldable display $_SESSION['cms_last_viewed_month'] = TikiLib::date_format("%Y-%m", $article_data["publishDate"]); ask_ticket('article-read'); //add a hit $statslib->stats_hit($article_data["title"], "article", $article_data['articleId']); if ($prefs['feature_actionlog'] == 'y') { $logslib->add_action('Viewed', $_REQUEST['articleId'], 'article'); } // Display the Index Template $smarty->assign('mid', 'tiki-read_article.tpl'); $smarty->display("tiki.tpl");
private function format($date, $format) { if ($date) { return TikiLib::date_format($format, $date); } }
/** * @param $mod_reference * @param $module_params */ function module_calendar_new($mod_reference, $module_params) { global $prefs, $user, $tiki_p_admin_calendars, $tikilib, $smarty; global $calendarlib; include_once 'lib/calendar/calendarlib.php'; global $userlib; include_once 'lib/userslib.php'; // Note: calendar css file now loaded in tiki-modules.php // global $headerlib; $headerlib->add_cssfile('css/calendar.css', 20); global $calendarViewMode, $focusdate; $default = array('viewnavbar' => 'y', 'viewmodelink' => 'week', 'showaction' => 'y', 'linkall' => 'n'); $module_params = array_merge($default, $module_params); if (isset($_REQUEST['viewmode'])) { $save_viewmode = $_REQUEST['viewmode']; } if (!empty($module_params['viewmode'])) { $calendarViewMode['casedefault'] = $module_params['viewmode']; } if (isset($_REQUEST['todate'])) { $save_todate = $_REQUEST['todate']; } if (isset($module_params['month_delta'])) { $calendarViewMode['casedefault'] = 'month'; list($focus_day, $focus_month, $focus_year) = array(TikiLib::date_format("%d", $focusdate), TikiLib::date_format("%m", $focusdate), TikiLib::date_format("%Y", $focusdate)); $_REQUEST['todate'] = $tikilib->make_time(0, 0, 0, $focus_month + $module_params['month_delta'], 1, $focus_year); } if (!empty($module_params['calIds'])) { $calIds = $module_params['calIds']; if (!is_array($module_params['calIds'])) { $calIds = preg_split('/[\\|:\\&,]/', $calIds); } } elseif (!empty($_SESSION['CalendarViewGroups'])) { $calIds = $_SESSION['CalendarViewGroups']; } elseif ($prefs['feature_default_calendars'] == 'n') { $calendars = $calendarlib->list_calendars(); $calIds = array_keys($calendars['data']); } elseif (!empty($prefs['default_calendars'])) { $calIds = $_SESSION['CalendarViewGroups'] = is_array($prefs['default_calendars']) ? $prefs['default_calendars'] : unserialize($prefs['default_calendars']); } else { $calIds = array(); } $_REQUEST['gbi'] = 'y'; if (!empty($module_params['viewlist'])) { $_REQUEST['viewlistmodule'] = $module_params['viewlist']; } else { $_REQUEST['viewlistmodule'] = 'table'; } foreach ($calIds as $i => $cal_id) { if ($tiki_p_admin_calendars != 'y' && !$userlib->user_has_perm_on_object($user, $cal_id, 'calendar', 'tiki_p_view_calendar')) { unset($calIds[$i]); } } if (!empty($calIds)) { $tc_infos = $calendarlib->getCalendar($calIds, $viewstart, $viewend, 'day', 'events', true); if ($_REQUEST['viewlistmodule'] == 'list') { foreach ($tc_infos['listevents'] as $i => $e) { $tc_infos['listevents'][$i]['head'] = ''; $tc_infos['listevents'][$i]['group_description'] = ''; } } foreach ($tc_infos as $tc_key => $tc_val) { $smarty->assign($tc_key, $tc_val); } $smarty->assign('name', 'calendar_new'); $smarty->assign('daformat2', $tikilib->get_long_date_format()); $smarty->assign('var', ''); $smarty->assign('myurl', 'tiki-calendar.php'); $smarty->assign('show_calendar_module', 'y'); $smarty->assign_by_ref('viewmodelink', $module_params['viewmodelink']); $smarty->assign_by_ref('linkall', $module_params['linkall']); $smarty->assign('calendarViewMode', $calendarViewMode['casedefault']); if (isset($save_todate)) { $_REQUEST['todate'] = $save_todate; } else { unset($_REQUEST['todate']); } } }
function module_months_links($mod_reference, $module_params) { global $prefs, $sections, $smarty; if (isset($module_params['feature']) && isset($sections[$module_params['feature']]) && isset($sections[$module_params['feature']]['feature']) && $prefs[$sections[$module_params['feature']]['feature']] == 'y' ) { $default_date_args = 'date_min=%d&date_max=%d'; switch ($module_params['feature']) { case 'blogs': if ($prefs['feature_blogs'] == 'y' && isset($module_params['id'])) { $link = 'tiki-view_blog.php?blogId=' . $module_params['id'] . '&' . $default_date_args; $object_key = 'itemObjectType'; } break; case 'cms': if ($prefs['feature_articles'] == 'y') { $link = 'tiki-view_articles.php?' . $default_date_args; $object_key = 'objectType'; } break; } } if (isset($link)) { global $tikilib; if ($module_params['feature'] == 'blogs') { global $bloglib; include_once ('lib/blogs/bloglib.php'); } elseif ($module_params['feature'] == 'cms') { global $artlib; include_once ('lib/articles/artlib.php'); } $month_names = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); $current_month_num = TikiLib::date_format('%m', $tikilib->now); $current_year = TikiLib::date_format('%Y', $tikilib->now); $timestamp_month_start = 0; if ($_SESSION['cms_last_viewed_month'] && $module_params['feature'] == 'cms') { list($year_expanded,$month_expanded_num) = explode('-', $_SESSION['cms_last_viewed_month']); $month_expanded = $month_names[$month_expanded_num-1]; } elseif ($_SESSION['blogs_last_viewed_month'] && $module_params['feature'] == 'blogs') { list($year_expanded,$month_expanded_num) = explode('-', $_SESSION['blogs_last_viewed_month']); $month_expanded = $month_names[$month_expanded_num-1]; } else { $year_expanded = $current_year; $month_expanded = $month_names[$current_month_num-1]; } $archives = array(); $numrows = $mod_reference['rows'] > 0 ? $mod_reference['rows'] : 12; for ($i = 0 ; $i < $numrows ; $i++, $current_month_num--) { if ($current_month_num == 0) { $current_month_num = 12; $current_year--; } $real_month_name = ucfirst(tra($month_names[$current_month_num - 1])); if ($timestamp_month_start > 0) { $timestamp_month_end = $timestamp_month_start - 1; // Optimisation to save one make_time() call per iteration } else { $timestamp_month_end = $tikilib->make_time(0, 0, 0, $current_month_num + 1, 1, $current_year) - 1; } $timestamp_month_start = $tikilib->make_time(0, 0, 0, $current_month_num, 1, $current_year); if ($module_params['feature'] == 'blogs') { $posts_of_month = $bloglib->list_blog_posts($module_params['id'], true, 0, -1, 'created_desc', '', $timestamp_month_start, $timestamp_month_end); if ($posts_of_month['cant'] > 0) { $archives[$current_year]['monthlist'][$real_month_name]['link'] = sprintf($link, $timestamp_month_start, $timestamp_month_end); $archives[$current_year]['monthlist'][$real_month_name]['cant'] = $posts_of_month['cant']; // Clicking on the year number displays the first non-empty month if (!isset($archives[$current_year]['link'])) { $archives[$current_year]['link'] = $archives[$current_year]['monthlist'][$real_month_name]['link']; } $archives[$current_year]['cant'] += $posts_of_month['cant']; for ($post=0; $post < $posts_of_month['cant']; $post++) { $archives[$current_year]['monthlist'][$real_month_name]['postlist'][$posts_of_month['data'][$post]['postId']] = $posts_of_month['data'][$post]['title']; } } } elseif ($module_params['feature'] == 'cms') { $posts_of_month = $artlib->list_articles( 0, -1, 'publishDate_desc', '', $timestamp_month_start, $timestamp_month_end, false, '', '', 'y', '', '', '', '', '', '', '', false, '', '' ); if ($posts_of_month["cant"] > 0) { $archives[$current_year]['monthlist'][$real_month_name]['link'] = sprintf($link, $timestamp_month_start, $timestamp_month_end); $archives[$current_year]['monthlist'][$real_month_name]['cant'] = $posts_of_month['cant']; // Clicking on the year number displays the first non-empty month if (!isset($archives[$current_year]['link'])) { $archives[$current_year]['link'] = $archives[$current_year]['monthlist'][$real_month_name]['link']; } $archives[$current_year]['cant'] += $posts_of_month['cant']; for ($post=0; $post < $posts_of_month['cant']; $post++) { $archives[$current_year]['monthlist'][$real_month_name]['postlist'][$posts_of_month['data'][$post]['articleId']] = $posts_of_month['data'][$post]['title']; } } } } $title = ucwords($sections[$module_params['feature']][$object_key]) . ' - ' . tra('List by month'); $smarty->assign('feature', $module_params['feature']); $smarty->assign('archives', $archives); $smarty->assign('year_expanded', $year_expanded); $smarty->assign('month_expanded', $month_expanded); $smarty->assign('module_id', $mod_reference['moduleId']); $smarty->assign('tpl_module_title', $title); } else { // We don't know if this is used for blogs or articles $title = tra('List by month'); $smarty->assign('tpl_module_title', $title); } }
function wikiplugin_trackerlist($data, $params) { global $tiki_p_admin_trackers, $prefs, $tiki_p_view_trackers, $user, $page, $tiki_p_tracker_vote_ratings, $tiki_p_tracker_view_ratings, $tiki_p_export_tracker, $tiki_p_watch_trackers, $tiki_p_edit; $userlib = TikiLib::lib('user'); $tikilib = TikiLib::lib('tiki'); $trklib = TikiLib::lib('trk'); $smarty = TikiLib::lib('smarty'); $notificationlib = TikiLib::lib('notification'); static $iTRACKERLIST = 0; ++$iTRACKERLIST; $smarty->assign('iTRACKERLIST', $iTRACKERLIST); $default = array('calendarfielddate' => '', 'wiki' => '', 'calendarviewmode' => 'month', 'calendarstickypopup' => 'n', 'calendarbeginmonth' => 'y', 'calendarviewnavbar' => 'y', 'calendartitle' => '', 'calendardelta' => '', 'force_compile' => 'n', 'editable' => array(), 'editableall' => 'n'); $params = array_merge($default, $params); extract($params, EXTR_SKIP); $skip_status_perm_check = false; if (isset($force_separate_compile) && $force_separate_compile == 'y') { $smarty->assign('force_separate_compile', 'y'); } if ($prefs['feature_trackers'] != 'y' || !isset($trackerId) || !($tracker_info = $trklib->get_tracker($trackerId))) { return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } else { global $auto_query_args; $auto_query_args_local = array('trackerId', 'tr_initial', "tr_sort_mode{$iTRACKERLIST}", 'tr_user', 'filterfield', 'filtervalue', 'exactvalue', 'itemId', "tr_offset{$iTRACKERLIST}"); $auto_query_args = empty($auto_query_args) ? $auto_query_args_local : array_merge($auto_query_args, $auto_query_args_local); $smarty->assign('listTrackerId', $trackerId); $definition = Tracker_Definition::get($trackerId); $tracker_info = $definition->getInformation(); if (!isset($sort)) { $sort = 'n'; } $perms = $tikilib->get_perm_object($trackerId, 'tracker', $tracker_info, false); if ($perms['tiki_p_view_trackers'] != 'y' && !$user) { return; } $userCreatorFieldId = $definition->getAuthorField(); $groupCreatorFieldId = $definition->getWriterGroupField(); if ($perms['tiki_p_view_trackers'] != 'y' && !$definition->isEnabled('writerCanModify') && !$definition->isEnabled('userCanSeeOwn') && empty($userCreatorFieldId) && empty($groupCreatorFieldId)) { return; } $smarty->assign_by_ref('perms', $perms); if (!empty($fields)) { $limit = $fields; } else { $limit = ''; } // Make sure limit is an array if (!is_array($limit) && !empty($limit)) { $limit = explode(':', $limit); } if (!empty($filterfield) && !empty($limit)) { $limit = array_unique(array_merge($limit, $filterfield)); } // for some reason if param popup is set but empty, the array contains 2 empty elements. We filter them out. if (isset($popup)) { $popup = array_filter($popup); if (!empty($popup)) { $limit = array_unique(array_merge($limit, $popup)); } } if (!empty($calendarfielddate)) { $limit = array_unique(array_merge($limit, $calendarfielddate)); } if (!empty($limit) && $trklib->test_field_type($limit, array('C'))) { $limit = array(); } $allfields = $trklib->list_tracker_fields($trackerId, 0, -1, 'position_asc', '', true, '', $trklib->flaten($limit)); if (!empty($fields)) { $listfields = $fields; //We must include the $calendarfielddate, even if they are not in the listfields if (!empty($calendarfielddate)) { foreach ($calendarfielddate as $f) { if (!in_array($f, $listfields)) { $listfields[] = $f; } } } if ($sort == 'y') { $allfields = $trklib->sort_fields($allfields, $listfields); } } elseif (!empty($wiki) || !empty($tpl) || !empty($tplwiki)) { if (!empty($wiki)) { $listfields = $trklib->get_pretty_fieldIds($wiki, 'wiki', $prettyModifier, $trackerId); } elseif (!empty($tplwiki)) { $listfields = $trklib->get_pretty_fieldIds($tplwiki, 'wiki', $prettyModifier, $trackerId); } else { $listfields = $trklib->get_pretty_fieldIds($tpl, 'tpl', $prettyModifier, $trackerId); } } else { $listfields = ''; } if (!empty($compute) && !empty($listfields)) { if (preg_match_all('/[0-9.]+/', $compute, $matches)) { foreach ($matches[0] as $f) { if (!in_array($f, $listfields)) { $listfields[] = $f; } } } } /*** tablesorter ***/ //note whether ajax is needed $tsServer = isset($params['server']) && $params['server'] === 'y' ? true : false; $tsOn = isset($sortable) && $sortable !== 'n' && Table_Check::isEnabled($tsServer); $smarty->assign('tsOn', $tsOn); //note whether this is the initial tablesorter ajax call or a subsequent ajax call $tsAjax = Table_Check::isAjaxCall(); $smarty->assign('tsAjax', $tsAjax); if ($tsAjax) { // if status is enabled, need to adjust field index by -1 - need to check both - tracker config and plugin config $adjustCol = isset($showstatus) && $showstatus == 'y' && $definition->isEnabled('showStatus') ? -1 : 0; //convert tablesorter filter syntax to tiki syntax if (!empty($_REQUEST['filter'])) { $i = 0; $tsfiltersArray = explode('|', $tsfilters); foreach ($_REQUEST['filter'] as $col => $ajaxfilter) { $fieldtype = $allfields['data'][$col + $adjustCol]['type']; $id = $allfields['data'][$col + $adjustCol]['fieldId']; //handle status filter if ($adjustCol === -1 && $col === 0 && in_array($ajaxfilter, ['o', 'p', 'c'])) { $status = $ajaxfilter; /* * handle date filter - these are always one filter, in the form of: * from: >=1427389832000; to: <=1427389832000; both from and to: 1427389832000 - 1427880000000 * which is unix timestamp in milliseconds */ } elseif (strpos($tsfiltersArray[$col], 'type:date') !== false && in_array($fieldtype, ['f', 'j'])) { $datefilter = explode(' - ', $ajaxfilter); $filterfield[$i] = $id; //a range (from and to filters) will have 2 items in the array if (count($datefilter) == 2) { $filterfield[$i + 1] = $id; //use substr to leave off milliseconds since date is stored in seconds in the database $exactvalue[$i] = 'greaterequal(@' . substr($datefilter[0], 0, 10) . ')'; $exactvalue[$i + 1] = 'lessequal(@' . substr($datefilter[1], 0, 10) . ')'; } else { //use substr to leave off milliseconds since date is stored in seconds in the database $stamp = '(@' . substr($datefilter[0], 2, 10) . ')'; $symbol = substr($datefilter[0], 0, 2); if ($symbol === '<=') { $compare = 'lessequal'; } elseif ($symbol === '>=') { $compare = 'greaterequal'; } $exactvalue[$i] = $compare . $stamp; } } else { $filterfield[$i] = $id; //convert category filters entered as text if ($fieldtype === 'e' && !is_numeric($ajaxfilter)) { $categlib = TikiLib::lib('categ'); $ajaxfilter = $categlib->get_category_id($ajaxfilter); } $filtervalue[$i] = $ajaxfilter; } $i++; } } //convert tablesorter sort syntax to tiki syntax if (!empty($_REQUEST['sort'])) { foreach ($_REQUEST['sort'] as $sortcol => $ajaxsort) { if ($ajaxsort == '0') { $dir = '_asc'; } elseif ($ajaxsort == '1') { $dir = '_desc'; } //avoid setting sort_mode based on status field - will return error. Handle later once records are retrieved if ($adjustCol !== -1 || $sortcol !== 0) { $sort_mode = 'f_' . $allfields['data'][$sortcol + $adjustCol]['fieldId'] . $dir; } } } //set max records if (isset($_REQUEST['numrows'])) { $max = $_REQUEST['numrows']; } } /*** end first tablesorter section ***/ if (!empty($filterfield)) { if (is_array($filterfield)) { foreach ($filterfield as $ff) { unset($filterfieldok); if (is_array($ff)) { // already checked in trackerfilter $filterfieldok = true; break; } else { foreach ($allfields['data'] as $f) { if ($f['fieldId'] == $ff) { $filterfieldok = true; break; } } } if (!isset($filterfieldok)) { break; } } } else { foreach ($allfields['data'] as $f) { if ($f['fieldId'] == $filterfield) { $filterfieldok = true; break; } } } if (!isset($filterfieldok)) { return tra('incorrect filterfield'); } } $filter = array(); if (isset($periodQuantity)) { switch ($periodUnit) { case 'hour': $periodUnit = 3600; break; case 'day': $periodUnit = 86400; break; case 'week': $periodUnit = 604800; break; case 'month': $periodUnit = 2628000; break; default: break; } if (!isset($periodType)) { $periodType = 'c'; } if (is_int($periodUnit) && $periodType == 'm') { $filter['lastModifAfter'] = $tikilib->now - $periodQuantity * $periodUnit; $filter['lastModifBefore'] = $tikilib->now; } elseif (is_int($periodUnit)) { # case for periodType beig c or anything else (therefore, set as case for default) $filter['createdAfter'] = $tikilib->now - $periodQuantity * $periodUnit; $filter['createdBefore'] = $tikilib->now; } } if (isset($_REQUEST['reloff']) && empty($_REQUEST['itemId']) && !empty($_REQUEST['trackerId'])) { //coming from a pagination $items = $trklib->list_items($_REQUEST['trackerId'], $_REQUEST['reloff'], 1, '', '', isset($_REQUEST['filterfield']) ? preg_split('/\\s*:\\s*/', $_REQUEST['filterfield']) : '', isset($_REQUEST['filtervalue']) ? preg_split('/\\s*:\\s*/', $_REQUEST['filtervalue']) : '', isset($_REQUEST['status']) ? preg_split('/\\s*:\\s*/', $_REQUEST['status']) : '', isset($_REQUEST['initial']) ? $_REQUEST['initial'] : '', isset($_REQUEST['exactvalue']) ? preg_split('/\\s*:\\s*/', $_REQUEST['exactvalue']) : '', $filter); if (isset($items['data'][0]['itemId'])) { $_REQUEST['cant'] = $items['cant']; $_REQUEST['itemId'] = $items['data'][0]['itemId']; } } if (!empty($_REQUEST['itemId']) && $tiki_p_tracker_vote_ratings == 'y' && $user) { $hasVoted = false; foreach ($allfields['data'] as $f) { if ($f['type'] == 's' && $definition->isEnabled('useRatings') && ($f['name'] == 'Rating' || ($f['name'] = tra('Rating')))) { $i = $f['fieldId']; if (isset($_REQUEST["ins_{$i}"]) && ($_REQUEST["ins_{$i}"] == 'NULL' || in_array($_REQUEST["ins_{$i}"], explode(',', $tracker_info['ratingOptions'])))) { $trklib->replace_rating($trackerId, $_REQUEST['itemId'], $i, $user, $_REQUEST["ins_{$i}"]); $hasVoted = true; } } elseif ($f['type'] == '*' || $f['type'] == 'STARS') { $i = $f['fieldId']; if (isset($_REQUEST["ins_{$i}"])) { $trklib->replace_star($_REQUEST["ins_{$i}"], $trackerId, $_REQUEST['itemId'], $f, $user); $hasVoted = true; } } } if ($hasVoted) { // Must strip NULL for remove my vote case $url = preg_replace('/[(\\?)|&]vote=y/', '$1', preg_replace('/[(\\?)|&]ins_[0-9]+=-?[0-9|N|U|L]*/', '$1', $_SERVER['REQUEST_URI'])); // reduce duplicate itemIds in query string $occurences = preg_match_all('/[(\\?)|&]itemId=[0-9]+/', $url, $matches); if ($params['list_mode'] == 'y' && $occurences > 0) { $url = preg_replace('/[(\\?)|&]itemId=[0-9]+/', '$1', $url, $occurences); } elseif ($occurences > 1) { $url = preg_replace('/&itemId=[0-9]+/', '', $url, $occurences - 1); } header("Location: {$url}"); die; } } if (!empty($showwatch) && $showwatch == 'y' && $prefs['feature_user_watches'] == 'y' && $tiki_p_watch_trackers == 'y' && !empty($user)) { if (isset($_REQUEST['watch']) && isset($_REQUEST['trackerId']) && $_REQUEST['trackerId'] == $trackerId) { if ($_REQUEST['watch'] == 'add') { $tikilib->add_user_watch($user, 'tracker_modified', $trackerId, 'tracker', $tracker_info['name'], "tiki-view_tracker.php?trackerId=" . $trackerId); } elseif ($_REQUEST['watch'] == 'stop') { $tikilib->remove_user_watch($user, 'tracker_modified', $trackerId, 'tracker'); } } if ($tikilib->user_watches($user, 'tracker_modified', $trackerId, 'tracker')) { $smarty->assign('user_watching_tracker', 'y'); } else { $smarty->assign('user_watching_tracker', 'n'); } } else { $smarty->clear_assign('user_watching_tracker'); } if (empty($showrss) || $showrss == 'n') { $smarty->assign('showrss', 'n'); } else { $smarty->assign('showrss', 'y'); } if (empty($listfields)) { foreach ($allfields['data'] as $f) { $listfields[] = $f['fieldId']; } } if (!empty($popup)) { $popupfields = $popup; } else { $popupfields = array(); } $smarty->assign_by_ref('tracker_info', $tracker_info); //$query_array = array(); //$quarray = array(); //TikiLib::parse_str($_SERVER['QUERY_STRING'],$query_array); if (isset($stickypopup) && $stickypopup == 'y') { $stickypopup = true; } else { $stickypopup = false; } $smarty->assign_by_ref('stickypopup', $stickypopup); if (!isset($showtitle)) { $showtitle = 'n'; } $smarty->assign_by_ref('showtitle', $showtitle); if (!isset($showlinks)) { $showlinks = 'n'; } $smarty->assign_by_ref('showlinks', $showlinks); if (!isset($showdesc)) { $showdesc = 'n'; } $smarty->assign_by_ref('showdesc', $showdesc); if (!isset($showinitials)) { $showinitials = 'n'; } $smarty->assign_by_ref('showinitials', $showinitials); if (!isset($shownbitems)) { $shownbitems = 'n'; } $smarty->assign_by_ref('shownbitems', $shownbitems); if (!isset($showstatus)) { $showstatus = 'n'; } $smarty->assign_by_ref('showstatus', $showstatus); if (!isset($showfieldname)) { $showfieldname = 'y'; } $smarty->assign_by_ref('showfieldname', $showfieldname); if (!isset($showitemrank)) { $showitemrank = 'n'; } $smarty->assign_by_ref('showitemrank', $showitemrank); if (!isset($showdelete)) { $showdelete = 'n'; } $smarty->assign_by_ref('showdelete', $showdelete); if (!isset($showpenditem)) { $showpenditem = 'n'; } $smarty->assign_by_ref('showpenditem', $showpenditem); if (!isset($showcloseitem)) { $showcloseitem = 'n'; } $smarty->assign_by_ref('showcloseitem', $showcloseitem); if (!isset($showopenitem)) { $showopenitem = 'n'; } $smarty->assign_by_ref('showopenitem', $showopenitem); if (!isset($showpagination)) { $showpagination = 'y'; } $smarty->assign_by_ref('showpagination', $showpagination); if (!isset($sortchoice)) { $sortchoice = ''; } else { foreach ($sortchoice as $i => $sc) { $sc = explode('|', $sc); $sortchoice[$i] = array('value' => $sc[0], 'label' => empty($sc[1]) ? $sc[0] : $sc[1]); } } $smarty->assign_by_ref('sortchoice', $sortchoice); if (!isset($status)) { $status = 'o'; } $tr_status = $status; $smarty->assign_by_ref('tr_status', $tr_status); if (!isset($list_mode)) { $list_mode = 'y'; } $smarty->assign_by_ref('list_mode', $list_mode); if (!isset($showcreated)) { $showcreated = $tracker_info['showCreated']; } $smarty->assign_by_ref('showcreated', $showcreated); if (!isset($showlastmodif)) { $showlastmodif = $tracker_info['showLastModif']; } $smarty->assign_by_ref('showlastmodif', $showlastmodif); if (!isset($showlastmodifby)) { $showlastmodifby = $tracker_info['showLastModifBy']; } $smarty->assign_by_ref('showlastmodifby', $showlastmodifby); if (!isset($more)) { $more = 'n'; } $smarty->assign_by_ref('more', $more); if (!isset($moreurl)) { $moreurl = 'tiki-view_tracker.php'; } $smarty->assign_by_ref('moreurl', $moreurl); if (!isset($url)) { $url = ''; } $smarty->assign_by_ref('url', $url); if (!isset($export)) { $export = 'n'; } $smarty->assign_by_ref('export', $export); if (!empty($ldelim)) { $smarty->left_delimiter = $ldelim; } if (!empty($rdelim)) { $smarty->right_delimiter = $rdelim; } if (isset($checkbox)) { $check = array('ix' => -1, 'type' => 'checkbox'); $cb = explode('/', $checkbox); if (isset($cb[0])) { $check['fieldId'] = $cb[0]; } if (isset($cb[1])) { $check['name'] = $cb[1]; } if (isset($cb[2])) { $check['title'] = $cb[2]; } if (isset($cb[3])) { $check['submit'] = $cb[3]; } if (isset($cb[4])) { $check['action'] = $cb[4]; } if (isset($cb[5])) { $check['tpl'] = $cb[5]; } if (isset($cb[6]) && $cb[6] == 'radio') { $check['radio'] = 'y'; $check['type'] = 'radio'; } if (isset($cb[6]) && $cb[6] == 'dropdown') { $check['dropdown'] = 'y'; } // is this actually used? $smarty->assign_by_ref('checkbox', $check); } if (isset($_REQUEST["tr_sort_mode{$iTRACKERLIST}"])) { $sort_mode = $_REQUEST["tr_sort_mode{$iTRACKERLIST}"]; } elseif (!isset($sort_mode)) { if (!empty($tracker_info['defaultOrderKey'])) { if ($tracker_info['defaultOrderKey'] == -1) { $sort_mode = 'lastModif'; } elseif ($tracker_info['defaultOrderKey'] == -2) { $sort_mode = 'created'; } elseif ($tracker_info['defaultOrderKey'] == -3) { $sort_mode = 'itemId'; } else { $sort_mode = 'f_' . $tracker_info['defaultOrderKey']; } if (isset($tracker_info['defaultOrderDir'])) { $sort_mode .= "_" . $tracker_info['defaultOrderDir']; } else { $sort_mode .= "_asc"; } } else { $sort_mode = ''; } } elseif ($sort_mode != 'created_asc' && $sort_mode != 'lastModif_asc' && $sort_mode != 'created_desc' && $sort_mode != 'lastModif_desc' && !preg_match('/f_[0-9]+_(asc|desc)/', $sort_mode)) { return tra('Incorrect param') . ' sort_mode'; } $tr_sort_mode = $sort_mode; $smarty->assign_by_ref('tr_sort_mode', $tr_sort_mode); if (!isset($max)) { $max = $prefs['maxRecords']; } if (isset($_REQUEST["tr_offset{$iTRACKERLIST}"]) && (!isset($forceoffset) || $forceoffset == 'n')) { $tr_offset = $_REQUEST["tr_offset{$iTRACKERLIST}"]; } else { if (isset($offset) && $offset >= 0) { $tr_offset = $offset; } else { $tr_offset = 0; } } $smarty->assign_by_ref("tr_offset{$iTRACKERLIST}", $tr_offset); $tr_initial = ''; if ($showinitials == 'y') { if (isset($_REQUEST['tr_initial'])) { //$query_array['tr_initial'] = $_REQUEST['tr_initial']; $tr_initial = $_REQUEST['tr_initial']; } $smarty->assign('initials', explode(' ', 'a b c d e f g h i j k l m n o p q r s t u v w x y z')); } $smarty->assign_by_ref('tr_initial', $tr_initial); if (isset($view) && $view == 'user' || isset($view_user) || isset($_REQUEST['tr_user'])) { if ($f = $definition->getAuthorField()) { $filterfield[] = $f; $filtervalue[] = ''; if (!isset($_REQUEST['tr_user'])) { $exactvalue[] = isset($view) ? empty($user) ? 'Anonymous' : $user : $view_user; } else { $exactvalue[] = $_REQUEST['tr_user']; $smarty->assign_by_ref('tr_user', $exactvalue); } if ($definition->isEnabled('writerCanModify') or $definition->isEnabled('userCanSeeOwn')) { $skip_status_perm_check = true; } } } if (isset($view) && $view == 'page' && isset($_REQUEST['page'])) { if ($f = $trklib->get_page_field($trackerId)) { $filterfield[] = $f['fieldId']; $filtervalue[] = ''; $exactvalue[] = $_REQUEST['page']; } } if (isset($view) && $view == 'ip') { if ($f = $definition->getAuthorIpField()) { $filterfield[] = $f; $filtervalue[] = ''; $ip = $tikilib->get_ip_address(); $exactvalue[] = $ip; } } if (!isset($filtervalue)) { $filtervalue = ''; } else { foreach ($filtervalue as $i => $f) { if ($f == '#user') { $filtervalue[$i] = $user; } else { if ($f == '#default_group') { $filtervalue[$i] = $_SESSION['u_info']['group']; } } } } if (!isset($exactvalue)) { $exactvalue = ''; } else { foreach ($exactvalue as $i => $f) { if ($f == '#user') { $exactvalue[$i] = $user; } } } if (!empty($_REQUEST['itemId']) && (empty($ignoreRequestItemId) || $ignoreRequestItemId != 'y')) { $itemId = $_REQUEST['itemId']; } if (isset($itemId)) { if (is_string($itemId) && strstr($itemId, ':')) { // JB Tiki7: This doesn't quite make sense as itemId is an array $itemId = explode(':', $itemId); // Probably just some redundant code TOKIL } $filter['tti.`itemId`'] = $itemId; } $newItemRateField = false; $status_types = $trklib->status_types(); $smarty->assign('status_types', $status_types); if (!isset($filterfield)) { $filterfield = ''; } else { if (!empty($filterfield)) { if (!empty($filtervalue)) { $fvs = $filtervalue; unset($filtervalue); for ($i = 0, $count_ff = count($filterfield); $i < $count_ff; ++$i) { $filtervalue[] = isset($fvs[$i]) ? $fvs[$i] : ''; } } if (!empty($exactvalue)) { $evs = $exactvalue; unset($exactvalue); for ($i = 0, $count_ff2 = count($filterfield); $i < $count_ff2; ++$i) { if (isset($evs[$i])) { if (is_array($evs[$i])) { // already processed $exactvalue[] = $evs[$i]; } elseif (preg_match('/(not)?categories\\(([0-9]+)\\)/', $evs[$i], $matches)) { $categlib = TikiLib::lib('categ'); if (ctype_digit($matches[2]) && $matches[2] > 0) { $cfilter = array('identifier' => $matches[2], 'type' => 'descendants'); } else { $cfilter = NULL; } $categs = $categlib->getCategories($cfilter, true, false); $l = array($matches[2]); foreach ($categs as $cat) { $l[] = $cat['categId']; } if (empty($matches[1])) { $exactvalue[] = $l; } else { $exactvalue[] = array('not' => $l); } } elseif (preg_match('/(not)?preference\\((.*)\\)/', $evs[$i], $matches)) { if (empty($matches[1])) { $exactvalue[] = $prefs[$matches[2]]; } else { $exactvalue[] = array('not' => $prefs[$matches[2]]); } } elseif (preg_match('/(not)?field\\(([0-9]+)(,([0-9]+|user)(,([0-9]+))?)?\\)/', $evs[$i], $matches)) { // syntax field(fieldId, user, trackerId) or field(fieldId)(need the REQUEST['itemId'] or field(fieldId, itemId) or field(fieldId, user) if (empty($matches[4]) && !empty($_REQUEST['itemId'])) { // user the itemId of the url $matches[4] = $_REQUEST['itemId']; } if (!empty($matches[4]) && $matches[4] == 'user') { if (!empty($matches[6])) { // pick the user item of this tracker $t_i = $trklib->get_tracker($matches[6]); $matches[4] = $trklib->get_user_item($matches[6], $t_i, $user); } elseif ($prefs['userTracker'] == 'y') { //pick the generic user tracker $utid = $userlib->get_tracker_usergroup($user); $matches[4] = $trklib->get_item_id($utid['usersTrackerId'], $utid['usersFieldId'], $user); } } if (!empty($matches[4])) { $l = $trklib->get_item_value(0, $matches[4], $matches[2]); $field = $trklib->get_tracker_field($matches[2]); if ($field['type'] == 'r') { $refItemId = $l; $l = $trklib->get_item_value($field['options_array'][0], $refItemId, $field['options_array'][3]); } } if (empty($matches[1])) { $exactvalue[] = $l; } else { $exactvalue[] = array('not' => $l); } } elseif (preg_match('/(less|greater|lessequal|greaterequal)\\((.+)\\)/', $evs[$i], $matches)) { $conv = array('less' => '<', 'greater' => '>', 'lessequal' => '<=', 'greaterequal' => '>='); $field = $trklib->get_tracker_field($filterfield[$i]); if ($field['type'] == 'f' || $field['type'] == 'j') { if ($matches[2] == 'now') { $matches[2] = $tikilib->now; } elseif (($r = strtotime($matches[2])) !== false) { $matches[2] = $r; } } $exactvalue[] = array($conv[$matches[1]] => $matches[2]); } elseif (preg_match('/not\\((.+)\\)/', $evs[$i], $matches)) { $exactvalue[] = array('not' => $matches[1]); } else { $exactvalue[] = $evs[$i]; } } else { $exactvalue[] = ''; } } } } } if ($tiki_p_admin_trackers != 'y' && $perms['tiki_p_view_trackers'] != 'y' && ($definition->isEnabled('writerCanModify') or $definition->isEnabled('userCanSeeOwn')) && $user && $userCreatorFieldId) { //patch this should be in list_items if ($filterfield != $userCreatorFieldId || is_array($filterfield) && !in_array(${$userCreatorFieldId}, $filterfield)) { if (is_array($filterfield)) { $filterfield[] = $userCreatorFieldId; } elseif (empty($filterfield)) { $filterfield = $userCreatorFieldId; } else { $filterfield = array($filterfield, $fieldId); } if (is_array($exactvalue)) { $exactvalue[] = $user; } elseif (empty($exactvalue)) { $exactvalue = $user; } else { $exactvalue = array($exactvalue, $user); } } } if ($tiki_p_admin_trackers != 'y' && $perms['tiki_p_view_trackers'] != 'y' && $user && $groupCreatorFieldId) { if ($filterfield != $groupCreatorFieldId || is_array($filterfield) && !in_array($groupCreatorFieldId, $filterfield)) { $groups = $userlib->get_user_groups($user); if (is_array($filterfield)) { $filterfield[] = $groupCreatorFieldId; } elseif (empty($filterfield)) { $filterfield = $groupCreatorFieldId; } else { $filterfield = array($filterfield, $fieldId); } if (is_array($exactvalue)) { $exactvalue[] = array_merge($exactvalue, $groups); } elseif (empty($exactvalue)) { $exactvalue = $groups; } else { $exactvalue = array_merge(array($exactvalue), $groups); } global $group; // awful trick - but the filter garantee that the group is ok $smarty->assign_by_ref('ours', $group); $perms = array_merge($perms, $trklib->get_special_group_tracker_perm($tracker_info)); } } for ($i = 0, $count_allf = count($allfields['data']); $i < $count_allf; $i++) { if ($allfields['data'][$i]['type'] == 'C') { $infoComputed = $trklib->get_computed_info($allfields['data'][$i]['options_array'][0], $trackerId, $allfields['data']); if (!empty($infoComputed)) { $allfields['data'][$i] = array_merge($infoComputed, $allfields['data'][$i]); } } elseif ($allfields["data"][$i]['type'] == 'w') { /* keep track of dynamic list items referring to user selectors */ $refFieldId = $allfields["data"][$i]['options_array'][3]; $refField = $trklib->get_tracker_field($refFieldId); if ($refField['type'] == 'u') { $allfields["data"][$i]['type'] = $refField['type']; } } // If listfields is a colon separated string, convert it to an array if (!is_array($listfields)) { $listfields = explode(':', $listfields); } if ((in_array($allfields["data"][$i]['fieldId'], $listfields) or in_array($allfields["data"][$i]['fieldId'], $popupfields)) and $allfields["data"][$i]['isPublic'] == 'y') { $passfields["{$allfields["data"][$i]['fieldId']}"] = $allfields["data"][$i]; } if (isset($check['fieldId']) && $allfields["data"][$i]['fieldId'] == $check['fieldId']) { $passfields["{$allfields["data"][$i]['fieldId']}"] = $allfields["data"][$i]; if (!in_array($allfields["data"][$i]['fieldId'], $listfields)) { $allfields["data"][$i]['isPublic'] == 'n'; } //don't show it $check['ix'] = count($passfields) - 1; } if ($allfields["data"][$i]['name'] == 'page' && empty($filterfield) && empty($displayList) && !empty($view) && $view == 'page') { $filterfield = $allfields["data"][$i]['fieldId']; $filtervalue = $_REQUEST['page']; } if ($definition->isEnabled('useRatings') and $allfields["data"][$i]['type'] == 's' and $allfields["data"][$i]['name'] == 'Rating') { $newItemRateField = $allfields["data"][$i]['fieldId']; } } $nonPublicFieldsWarning = ''; if ($tiki_p_edit === 'y') { foreach ($allfields['data'] as $field) { if ($field['isPublic'] !== 'y' && in_array($field['fieldId'], array_merge($listfields, $popupfields))) { $nonPublicFieldsWarning = tra('You have attempted to view data of a tracker field which is not public. You need to ask the admin to change the setting to public for this field.'); } } } if ($editableall == 'y') { $editable = $listfields; } $smarty->assign('nonPublicFieldsWarning', $nonPublicFieldsWarning); $smarty->assign_by_ref('filterfield', $filterfield); $smarty->assign_by_ref('filtervalue', $filtervalue); $smarty->assign_by_ref('fields', $passfields); $smarty->assign_by_ref('exactvalue', $exactvalue); $smarty->assign_by_ref('listfields', $listfields); $smarty->assign_by_ref('popupfields', $popupfields); $smarty->assign('editableFields', $editable); if (!empty($filterfield)) { $urlquery['filterfield'] = is_array($filtervalue) ? implode(':', $filterfield) : $filterfield; if (!is_array($filtervalue)) { $filtervalue = array($filtervalue); } $urlquery['filtervalue'] = is_array($filtervalue) ? implode(':', $filtervalue) : $filtervalue; $urlquery['exactvalue'] = is_array($exactvalue) ? implode(':', $exactvalue) : $exactvalue; $urlquery['trackerId'] = $trackerId; $smarty->assign('urlquery', $urlquery); } else { $smarty->assign('urlquery', ''); } if (!empty($export) && $export != 'n' && $perms['tiki_p_export_tracker'] == 'y') { $smarty->loadPlugin('smarty_function_service'); $exportParams = array('controller' => 'tracker', 'action' => 'export', 'trackerId' => $trackerId); if (!empty($fields)) { $exportParams['displayedFields'] = is_array($fields) ? implode(':', $fields) : $fields; } if (is_array($filterfield)) { foreach ($filterfield as $i => $fieldId) { $exportParams["f_{$fieldId}"] = empty($filtervalue[$i]) ? $exactvalue[$i] : $filtervalue[$i]; } } elseif (!empty($filterfield)) { $exportParams["f_{$filterfield}"] = empty($filtervalue) ? $exactvalue : $filtervalue; } $exportUrl = smarty_function_service($exportParams, $smarty); $smarty->assign('exportUrl', $exportUrl); } if (!empty($_REQUEST['delete'])) { $itemToDelete = Tracker_Item::fromId($_REQUEST['delete']); if ($itemToDelete->canRemove()) { $trklib->remove_tracker_item($_REQUEST['delete']); } if (!empty($urlafterdelete)) { header("Location: {$urlafterdelete}"); exit; } } if (!empty($_REQUEST['closeitem'])) { $itemToModify = Tracker_Item::fromId($_REQUEST['closeitem']); if ($itemToModify->canModify()) { $trklib->change_status(array(array('itemId' => $_REQUEST['closeitem'])), 'c'); } } if (!empty($_REQUEST['penditem'])) { $itemToModify = Tracker_Item::fromId($_REQUEST['penditem']); if ($itemToModify->canModify()) { $trklib->change_status(array(array('itemId' => $_REQUEST['penditem'])), 'p'); } } if (!empty($_REQUEST['openitem'])) { $itemToModify = Tracker_Item::fromId($_REQUEST['openitem']); if ($itemToModify->canModify()) { $trklib->change_status(array(array('itemId' => $_REQUEST['openitem'])), 'o'); } } if (!empty($calendarfielddate)) { $calendarlib = TikiLib::lib('calendar'); $focusDate = empty($_REQUEST['todate']) ? $tikilib->now : $_REQUEST['todate']; $focus = $calendarlib->infoDate($focusDate); if (!empty($calendardelta)) { if ($calendardelta[0] == '-') { $focus = $calendarlib->focusPrevious($focus, str_replace('-', '', $calendardelta)); } else { $focus = $calendarlib->focusNext($focus, str_replace('+', '', $calendardelta)); } } $calendarlib->focusStartEnd($focus, $calendarviewmode, $calendarbeginmonth, $startPeriod, $startNextPeriod); $cell = $calendarlib->getTableViewCells($startPeriod, $startNextPeriod, $calendarviewmode, $calendarlib->firstDayofWeek($user)); if (is_array($filterfield) == false) { $filterfield = array($filterfield); } if (is_array(${$filtervalue}) == false) { $filtervalue = array($filtervalue); } $filterfield[] = $calendarfielddate[0]; $filtervalue[] = ''; $exactvalue[] = array('>=' => $startPeriod['date']); $filterfield[] = empty($calendarfielddate[1]) ? $calendarfielddate[0] : $calendarfielddate[1]; $filtervalue[] = ''; $exactvalue[] = array('<' => $startNextPeriod['date']); } if (count($passfields)) { // Optimization: Group category fields using AND logic indicated by sub-array $catfilters = array(); $catfiltervalue = array(); $catfilternotvalue = array(); if (!empty($filterfield)) { foreach ($filterfield as $k => $ff) { $filterfieldinfo = $trklib->get_tracker_field($ff); if ($filterfieldinfo['type'] == 'e') { $catfilters[] = $k; if (!empty($filtervalue[$k]) && empty($exactvalue[$k])) { // Some people use filtervalue instead of exactvalue for category filters $exactvalue[$k] = $filtervalue[$k]; for ($i = 0; $i < $k; $i++) { if (!isset($exactvalue[$i])) { $exactvalue[$i] = ''; } } } if (array_key_exists('not', array($exactvalue[$k]))) { $catfilternotfield[0] = $ff; $catfilternotvalue[] = array($exactvalue[$k]); } else { $catfilterfield[0] = $ff; $catfiltervalue[] = array($exactvalue[$k]); } } } } if ($catfilters) { foreach ($catfilters as $cf) { unset($filterfield[$cf]); unset($exactvalue[$cf]); } if ($catfiltervalue) { // array_merge is used because it reindexes $filterfield = array_merge($filterfield, $catfilterfield); $exactvalue = array_merge($exactvalue, array($catfiltervalue)); } if ($catfilternotvalue) { $filterfield = array_merge($filterfield, $catfilternotfield); $exactvalue[] = array('not' => $catfilternotvalue); } } // End Optimization //fetch tracker items $items = $trklib->list_items($trackerId, $tr_offset, $max, $tr_sort_mode, $passfields, !empty($calendarfielddate) ? null : $filterfield, $filtervalue, $tr_status, $tr_initial, $exactvalue, $filter, $allfields, $skip_status_perm_check); /*** tablesorter ***/ if ($tsOn && !$tsAjax) { // when using serverside filtering check wether a dropdown is in use // and we must take params from tracker definition because no explicit options have been defined if ($tsServer) { //format from plugin: type:text|type:dropdown;option:1=Open;option:2=Closed|type:text|type:nofilter|type:nofilter|type:nofilter if (!empty($tsfilters) && strpos($tsfilters, 'dropdown') !== false) { $tsfiltersArray = explode('|', $tsfilters); $adjustCol = isset($showstatus) && $showstatus == 'y' && $definition->isEnabled('showStatus') ? -1 : 0; foreach ($tsfiltersArray as $col => &$tsfilterField) { // only consider dropdown definitions without explicit option if (strpos($tsfilterField, 'dropdown') !== false && strpos($tsfilterField, 'option') === false) { //content from options (json object): {"options":["1=Open"," 2=Closed]} - note there can be whitespaces - it should not but there can be - yet another fix required if ($allfields['data'][$col + $adjustCol]['type'] == 'd') { $options = $allfields['data'][$col + $adjustCol]['options']; $options = json_decode($options); $options = $options->options; // construct the new dropdown filterfield entry from the trackerfield definition $newTsfilterField = 'type:dropdown'; foreach ($options as $option) { $newTsfilterField .= ";option:" . trim($option); } // update field - note that we used a ref $tsfilterField = $newTsfilterField; } } } // update tsfilters $tsfilters = implode('|', $tsfiltersArray); } } $ts_id = 'wptrackerlist' . $trackerId . '-' . $iTRACKERLIST; $ts = new Table_Plugin(); $ts->setSettings($ts_id, isset($server) ? $server : null, $sortable, isset($sortList) ? $sortList : null, isset($tsortcolumns) ? $tsortcolumns : null, isset($tsfilters) ? $tsfilters : null, isset($tsfilteroptions) ? $tsfilteroptions : null, isset($tspaginate) ? $tspaginate : null, isset($tscolselect) ? $tscolselect : null, $GLOBALS['requestUri'], $items['cant'], isset($tstotals) ? $tstotals : null, isset($tstotalformat) ? $tstotalformat : null, isset($tstotaloptions) ? $tstotaloptions : null); //loads the jquery tablesorter code if (is_array($ts->settings)) { $ts->settings['ajax']['offset'] = 'tr_offset' . $iTRACKERLIST; Table_Factory::build('PluginWithAjax', $ts->settings); } } //determine whether totals will be added to bottom of table if (isset($ts->settings)) { Table_Totals::setTotals($ts->settings); } //handle certain tablesorter sorts if (isset($sortcol) && $items['cant'] > 1) { $fieldtype = $items['data'][0]['field_values'][$sortcol + $adjustCol]['type']; //convert categoryId sort to category name sort when tablesorter server side sorting is used if ($fieldtype === 'e') { foreach ($items['data'] as $key => $record) { $catfield = $record['field_values'][$sortcol + $adjustCol]; $sortarray[$key] = $catfield['list'][$catfield['value']]['name']; } //sort status } elseif ($adjustCol === -1 && $sortcol === 0) { $sortarray = array_column($items['data'], 'status'); } array_multisort($sortarray, $dir == '_desc' ? SORT_DESC : SORT_ASC, $items['data']); } /*** end second tablesorter section ***/ if (isset($silent) && $silent == 'y' && empty($items['cant'])) { return; } if (isset($items['cant']) && $items['cant'] == 1 && isset($goIfOne) && ($goIfOne == 'y' || $goIfOne == 1)) { header('Location: tiki-view_tracker_item.php?itemId=' . $items['data'][0]['itemId'] . '&trackerId=' . $items['data'][0]['trackerId']); die; } if ($newItemRateField && !empty($items['data'])) { foreach ($items['data'] as $f => $v) { $items['data'][$f]['my_rate'] = $tikilib->get_user_vote("tracker." . $trackerId . '.' . $items['data'][$f]['itemId'], $user); } } if (!empty($items['data']) && ($definition->isEnabled('useComments') && $definition->isEnabled('showComments') || $definition->isEnabled('showLastComment'))) { foreach ($items['data'] as $itkey => $oneitem) { if ($definition->isEnabled('showComments')) { $items['data'][$itkey]['comments'] = $trklib->get_item_nb_comments($items['data'][$itkey]['itemId']); } if ($definition->isEnabled('showLastComment')) { $l = $trklib->list_last_comments($items['data'][$itkey]['trackerId'], $items['data'][$itkey]['itemId'], 0, 1); $items['data'][$itkey]['lastComment'] = !empty($l['cant']) ? $l['data'][0] : ''; } } } if (!empty($items['data']) && ($definition->isEnabled('useAttachments') && $definition->isEnabled('showAttachments'))) { foreach ($items["data"] as $itkey => $oneitem) { $res = $trklib->get_item_nb_attachments($items["data"][$itkey]['itemId']); $items["data"][$itkey]['attachments'] = $res['attachments']; } } if (!empty($compute) && !empty($items['data'])) { $fs = preg_split('/ *: */', $compute); foreach ($fs as $fieldId) { if (strstr($fieldId, "/")) { list($fieldId, $oper) = preg_split('/ *\\/ */', $fieldId); $oper = strtolower($oper); if ($oper == 'average') { $oper = 'avg'; } elseif ($oper != 'sum' && $oper != 'avg') { $oper = 'sum'; } } else { $oper = 'sum'; } foreach ($items['data'] as $i => $item) { foreach ($item['field_values'] as $field) { if ($field['fieldId'] == $fieldId) { if (preg_match('/^ *$/', $field['value']) || !is_numeric($field['value'])) { $amount[$i] = '0'; } else { $amount[$i] = $field['value']; } break; } } } $value = array_sum($amount); if ($oper == 'avg') { $value = round($value / count($amount)); } $computedFields[$fieldId][] = array_merge(array('computedtype' => 'n', 'operator' => $oper, 'value' => $value), $passfields[$fieldId]); } $smarty->assign_by_ref('computedFields', $computedFields); } else { $smarty->assign('computedFields', ''); } if (!empty($calendarfielddate)) { foreach ($items['data'] as $i => $item) { if (!empty($wiki)) { $smarty->assign('fields', $item['field_values']); $smarty->assign('item', $item); $smarty->assign('wiki', "wiki:{$wiki}"); $smarty->assign('showpopup', 'n'); $items['data'][$i]['over'] = $smarty->fetch('tracker_pretty_item.tpl'); } if (!empty($tplwiki)) { $smarty->assign('fields', $item['field_values']); $smarty->assign('item', $item); $smarty->assign('wiki', "tplwiki:{$tplwiki}"); $smarty->assign('showpopup', 'n'); $items['data'][$i]['over'] = $smarty->fetch('tracker_pretty_item.tpl'); } if (empty($items['data'][$i]['over'])) { $items['data'][$i]['over'] = $trklib->get_isMain_value($trackerId, $item['itemId']); } $items['data'][$i]['visible'] = 'y'; } $trklib->fillTableViewCell($items['data'], $calendarfielddate, $cell); $smarty->assign('cell', $cell); $smarty->assign('show_calendar_module', 'y'); $calendarlib->getDayNames($calendarlib->firstDayofWeek($user), $daysnames, $daysnames_abr); $smarty->assign('daysnames_abr', $daysnames_abr); $smarty->assign('focusmonth', TikiLib::date_format("%m", $focusDate)); $smarty->assign('module_params', array('viewmode' => 'n', 'showaction' => 'n', 'notitle' => empty($calendartitle) ? 'y' : 'n', 'title' => $calendartitle, 'viewnavbar' => $calendarviewnavbar, 'decorations' => empty($calendartitle) ? 'n' : 'y')); $smarty->assign('tpl_module_title', tra($calendartitle)); $smarty->assign('now', $tikilib->now); $smarty->assign('calendarViewMode', $calendarviewmode); $smarty->assign('viewmodelink', $calendarviewmode); $smarty->assign('viewmode', $calendarviewmode); $focus_prev = $calendarlib->focusPrevious($focus, $calendarviewmode); $smarty->assign('focus_prev', $focus_prev['date']); $focus_next = $calendarlib->focusNext($focus, $calendarviewmode); $smarty->assign('focus_next', $focus_next['date']); $smarty->assign('daystart', $startPeriod['date']); $dayend = $calendarlib->infoDate($startNextPeriod['date'] - 1); $smarty->assign('dayend', $dayend['date']); $smarty->assign('today', TikiLib::make_time(0, 0, 0, TikiLib::date_format('%m'), TikiLib::date_format('%d'), TikiLib::date_format('%Y'))); $smarty->assign('sticky_popup', $calendarstickypopup); $smarty->assign('calendar_popup', $calendarpopup); $smarty->assign('showpopup', 'n'); $headerlib = TikiLib::lib('header'); $headerlib->add_cssfile('themes/base_files/feature_css/calendar.css', 20); return $smarty->fetch('modules/mod-calendar_new.tpl'); } if (!empty($wiki)) { $tpl = "wiki:{$wiki}"; } elseif (!empty($tplwiki)) { $tpl = "tplwiki:{$tplwiki}"; } elseif (empty($tpl)) { $tpl = ''; } if (!empty($tpl)) { $smarty->security = true; } $smarty->assign('tpl', $tpl); if (!empty($itemId) && $showpagination == 'y' && !empty($_REQUEST['cant'])) { $smarty->assign('max', 1); $smarty->assign('count_item', $_REQUEST['cant']); $smarty->assign('offset_arg', 'reloff'); $smarty->assign("tr_offset{$iTRACKERLIST}", $_REQUEST['reloff']); } else { $smarty->assign_by_ref('max', $max); $smarty->assign_by_ref('item_count', $items['cant']); $smarty->assign_by_ref('count_item', $items['cant']); $smarty->assign('offset_arg', "tr_offset{$iTRACKERLIST}"); } $smarty->assign_by_ref('items', $items["data"]); $smarty->assign('daformat', $tikilib->get_long_date_format() . " " . tra("at") . " %H:%M"); if (!empty($params['showmap']) && $params['showmap'] == 'y') { $smarty->assign('trackerlistmapview', true); $smarty->assign('trackerlistmapname', "trackerlistmap_{$iTRACKERLIST}"); } else { $smarty->assign('trackerlistmapview', false); } if (isset($items['data'])) { foreach ($items['data'] as $score_item) { $item_info = $trklib->get_tracker_item($score_item['itemId']); $currentItemId = $score_item['itemId']; TikiLib::events()->trigger('tiki.trackeritem.view', array('type' => 'trackeritem', 'object' => $currentItemId, 'owner' => $item_info['createdBy'], 'user' => $GLOBALS['user'])); } } $tracker = $trklib->get_tracker($trackerId, 0, -1); /*foreach ($query_array as $k=>$v) { if (!is_array($v)) { //only to avoid an error: eliminate the params that are not simple (ex: if you have in the same page a tracker list plugin and a tracker plugin, filling the tracker plugin interfers with the tracker list. In any case this is buggy if two tracker list plugins in the same page and if one needs the query value.... $quarray[] = urlencode($k) ."=". urlencode($v); } } if (is_array($quarray)) { $query_string = implode("&",$quarray); } else { $quering_string = ''; } $smarty->assign('query_string', $query_string); */ if (!$tracker) { $smarty->assign('msg', tra("Error in tracker ID")); return $smarty->fetch("error_raw.tpl"); } else { $save_fc = null; if (!empty($wiki) && $params['force_compile'] === 'y') { // some pretty trackers need to compile fresh for each item $save_fc = $smarty->force_compile; $smarty->force_compile = true; } //this options preloads the javascript for displaying sheets if (!empty($displaysheet) && $displaysheet == 'y') { $headerlib = TikiLib::lib("header"); $sheetlib = TikiLib::lib("sheet"); $sheetlib->setup_jquery_sheet(); $headerlib->add_jq_onready('$("div.trackercontainer").sheet($.extend($.sheet.tikiOptions,{ editable:false, buildSheet: true, minSize: {rows: 0, cols: 0} }));'); $smarty->assign('displaysheet', 'true'); } //this method sets up the sheet just like it would for jquery.sheet, but assumes that the javascript will be handled elsewere if (!empty($tableassheet) && $tableassheet == 'y') { $smarty->assign('tableassheet', 'true'); } $smarty->assign('context', $params); try { $str = $smarty->fetch('wiki-plugins/wikiplugin_trackerlist.tpl'); } catch (SmartyException $e) { $str = $e->getMessage(); } if ($save_fc !== null) { $smarty->force_compile = $save_fc; // presumably will be false but put it back anyway } return $str; } } else { $smarty->assign('msg', tra("No field indicated")); return $smarty->fetch("error_raw.tpl"); } } return $back; }
function wikiplugin_now($data, $params) { extract($params, EXTR_SKIP); return TikiLib::date_format(tra($format)); }