function action_list($input) { global $prefs; $unifiedsearchlib = TikiLib::lib('unifiedsearch'); $index = $unifiedsearchlib->getIndex(); $dataSource = $unifiedsearchlib->getDataSource(); $start = 'tracker_field_' . $input->beginField->word(); $end = 'tracker_field_' . $input->endField->word(); if ($resource = $input->resourceField->word()) { $resource = 'tracker_field_' . $resource; } if ($coloring = $input->coloringField->word()) { $coloring = 'tracker_field_' . $coloring; } $query = $unifiedsearchlib->buildQuery(array()); $query->filterRange($input->start->int(), $input->end->int(), array($start, $end)); $query->setRange(0, $prefs['unified_lucene_max_result']); if ($body = $input->filters->none()) { $builder = new Search_Query_WikiBuilder($query); $builder->apply(WikiParser_PluginMatcher::match($body)); } $result = $query->search($index); $result = $dataSource->getInformation($result, array('title', $start, $end)); $response = array(); $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_sefurl'); foreach ($result as $row) { $item = Tracker_Item::fromId($row['object_id']); $response[] = array('id' => $row['object_id'], 'trackerId' => isset($row['tracker_id']) ? $row['tracker_id'] : null, 'title' => $row['title'], 'description' => '', 'url' => smarty_modifier_sefurl($row['object_id'], $row['object_type']), 'allDay' => false, 'start' => (int) $row[$start], 'end' => (int) $row[$end], 'editable' => $item->canModify(), 'color' => $this->getColor(isset($row[$coloring]) ? $row[$coloring] : ''), 'textColor' => '#000', 'resource' => $resource && isset($row[$resource]) ? $row[$resource] : ''); } return $response; }
function getDocument($objectId, Search_Type_Factory_Interface $typeFactory) { /* If you wonder why this method uses straight SQL and not trklib, it's because trklib performs no meaningful work when extracting the data and strips all required semantics. */ $data = array('title' => $typeFactory->sortable(tr('Unknown')), 'language' => $typeFactory->identifier('unknown')); $item = $this->trklib->get_tracker_item($objectId); if (empty($item)) { return false; } $itemObject = Tracker_Item::fromInfo($item); if (empty($itemObject) || !$itemObject->getDefinition()) { // ignore corrupted items, e.g. where trackerId == 0 return false; } $permNeeded = $itemObject->getViewPermission(); $specialUsers = $itemObject->getSpecialPermissionUsers($objectId, 'Modify'); $definition = Tracker_Definition::get($item['trackerId']); if (!$definition) { return $data; } foreach (self::getIndexableHandlers($definition, $item) as $handler) { $data = array_merge($data, $handler->getDocumentPart($typeFactory)); } $ownerGroup = $itemObject->getOwnerGroup(); $data = array_merge($data, array('title' => $typeFactory->sortable($this->trklib->get_isMain_value($item['trackerId'], $objectId)), 'modification_date' => $typeFactory->timestamp($item['lastModif']), 'creation_date' => $typeFactory->timestamp($item['created']), 'contributors' => $typeFactory->multivalue(array_unique(array($item['createdBy'], $item['lastModifBy']))), 'tracker_status' => $typeFactory->identifier($item['status']), 'tracker_id' => $typeFactory->identifier($item['trackerId']), 'view_permission' => $typeFactory->identifier($permNeeded), '_extra_users' => $specialUsers, '_permission_accessor' => $itemObject->getPerms(), '_extra_groups' => $ownerGroup ? array($ownerGroup) : null)); return $data; }
private function infobox_trackeritem($input) { $itemId = $input->object->int(); $trklib = TikiLib::lib('trk'); if (!($item = $trklib->get_tracker_item($itemId))) { throw new Services_Exception_NotFound(); } if (!($definition = Tracker_Definition::get($item['trackerId']))) { throw new Services_Exception_NotFound(); } $itemObject = Tracker_Item::fromInfo($item); if (!$itemObject->canView()) { throw new Services_Exception('Permission denied', 403); } $fields = array(); foreach ($definition->getPopupFields() as $fieldId) { if ($itemObject->canViewField($fieldId) && ($field = $definition->getField($fieldId))) { $fields[] = $field; } } $smarty = TikiLib::lib('smarty'); $smarty->assign('fields', $fields); $smarty->assign('item', $item); $smarty->assign('can_modify', $itemObject->canModify()); $smarty->assign('can_remove', $itemObject->canRemove()); $smarty->assign('mode', $input->mode->text() ? $input->mode->text() : ''); // default divs mode return $smarty->fetch('object/infobox/trackeritem.tpl'); }
function wikiplugin_insert_rewrite($data, $params, $context) { $tikilib = TikiLib::lib('tiki'); $trackerIds = $tikilib->get_preference('tracker_insert_allowed', array(), true); foreach ($trackerIds as $trackerId) { $utilities = new Services_Tracker_Utilities(); $item = Tracker_Item::newItem($trackerId); if (!$item->canModify()) { continue; } $definition = $item->getDefinition(); if (!$definition->canInsert(array_keys($params))) { continue; } $available = array(); foreach ($params as $key => $value) { if ($item->canModifyField($key)) { $available[$key] = $value; } } $id = $utilities->insertItem($definition, array('status' => 'o', 'fields' => $available)); if (false !== $id) { $relationlib = TikiLib::lib('relation'); $relationlib->add_relation('tiki.source.creator', 'trackeritem', $id, $context['type'], $context['itemId']); return "{objectlink type=trackeritem id={$id}}"; } } return false; }
function wikiplugin_trackercalendar($data, $params) { static $id = 0; $headerlib = TikiLib::lib('header'); $headerlib->add_cssfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.css'); $headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js'); $jit = new JitFilter($params); $definition = Tracker_Definition::get($jit->trackerId->int()); $itemObject = Tracker_Item::newItem($jit->trackerId->int()); if (!$definition) { return WikiParser_PluginOutput::userError(tr('Tracker not found.')); } $beginField = $definition->getFieldFromPermName($jit->begin->word()); $endField = $definition->getFieldFromPermName($jit->end->word()); if (!$beginField || !$endField) { return WikiParser_PluginOutput::userError(tr('Fields not found.')); } $views = array('month', 'agendaWeek', 'agendaDay'); $resources = array(); if ($resourceField = $jit->resource->word()) { $field = $definition->getFieldFromPermName($resourceField); $resources = wikiplugin_trackercalendar_get_resources($field); $views[] = 'resourceMonth'; $views[] = 'resourceWeek'; $views[] = 'resourceDay'; } $smarty = TikiLib::lib('smarty'); $smarty->assign('trackercalendar', array('id' => 'trackercalendar' . ++$id, 'trackerId' => $jit->trackerId->int(), 'begin' => $jit->begin->word(), 'end' => $jit->end->word(), 'resource' => $resourceField, 'resourceList' => $resources, 'coloring' => $jit->coloring->word(), 'beginFieldName' => 'ins_' . $beginField['fieldId'], 'endFieldName' => 'ins_' . $endField['fieldId'], 'firstDayofWeek' => 0, 'views' => implode(',', $views), 'viewyear' => (int) date('Y'), 'viewmonth' => (int) date('n'), 'viewday' => (int) date('j'), 'minHourOfDay' => 7, 'maxHourOfDay' => 20, 'addTitle' => tr('Insert'), 'canInsert' => $itemObject->canModify(), 'body' => $data)); return $smarty->fetch('wiki-plugins/trackercalendar.tpl'); }
function smarty_block_trackeritemcheck($params, $content, $smarty, $repeat) { if ($repeat) { return; } if (empty($params['itemId'])) { return tra('itemId required'); } if (empty($params['mode'])) { $params['mode'] = ''; // default is to view } $item = Tracker_Item::fromId($params['itemId']); $allowed = false; switch ($params['mode']) { case 'edit': $allowed = $item->canModify(); break; case 'delete': $allowed = $item->canRemove(); break; case 'view': $allowed = $item->canView(); default: break; } if ($allowed) { return $content; } else { return ''; } }
function action_list($input) { global $prefs; $unifiedsearchlib = TikiLib::lib('unifiedsearch'); $index = $unifiedsearchlib->getIndex(); $dataSource = $unifiedsearchlib->getDataSource(); $start = 'tracker_field_' . $input->beginField->word(); $end = 'tracker_field_' . $input->endField->word(); if ($resource = $input->resourceField->word()) { $resource = 'tracker_field_' . $resource; } if ($coloring = $input->coloringField->word()) { $coloring = 'tracker_field_' . $coloring; } $query = $unifiedsearchlib->buildQuery(array()); $query->filterRange($input->start->int(), $input->end->int(), array($start, $end)); $query->setRange(0, $prefs['unified_lucene_max_result']); if ($body = $input->filters->none()) { $builder = new Search_Query_WikiBuilder($query); $builder->apply(WikiParser_PluginMatcher::match($body)); } $result = $query->search($index); $result = $dataSource->getInformation($result, array('title', $start, $end)); $response = array(); $fields = array(); if ($definition = Tracker_Definition::get($input->trackerId->int())) { foreach ($definition->getPopupFields() as $fieldId) { if ($field = $definition->getField($fieldId)) { $fields[] = $field; } } } $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_sefurl'); $trklib = TikiLib::lib('trk'); foreach ($result as $row) { $item = Tracker_Item::fromId($row['object_id']); $description = ''; foreach ($fields as $field) { if ($item->canViewField($field['fieldId'])) { $val = trim($trklib->field_render_value(array('field' => $field, 'item' => $item->getData(), 'process' => 'y'))); if ($val) { if (count($fields) > 1) { $description .= "<h5>{$field['name']}</h5>"; } $description .= $val; } } } $response[] = array('id' => $row['object_id'], 'trackerId' => isset($row['tracker_id']) ? $row['tracker_id'] : null, 'title' => $row['title'], 'description' => $description, 'url' => smarty_modifier_sefurl($row['object_id'], $row['object_type']), 'allDay' => false, 'start' => $this->getTimestamp($row[$start]), 'end' => $this->getTimestamp($row[$end]), 'editable' => $item->canModify(), 'color' => $this->getColor(isset($row[$coloring]) ? $row[$coloring] : ''), 'textColor' => '#000', 'resource' => $resource && isset($row[$resource]) ? strtolower($row[$resource]) : ''); } return $response; }
/** * @param $mod_reference * @param $module_params */ function module_tracker_input($mod_reference, $module_params) { global $prefs; $smarty = TikiLib::lib('smarty'); $trackerId = $module_params['trackerId']; $itemObject = Tracker_Item::newItem($trackerId); $definition = Tracker_Definition::get($trackerId); if (!$itemObject->canModify()) { $smarty->assign('tracker_input', array('trackerId' => 0, 'textInput' => array(), 'hiddenInput' => array(), 'location' => null)); return; } $textinput = isset($module_params['textinput']) ? $module_params['textinput'] : ''; $hiddeninput = isset($module_params['hiddeninput']) ? $module_params['hiddeninput'] : ''; $streetview = isset($module_params['streetview']) ? $module_params['streetview'] : ''; $streetViewField = $definition->getFieldFromPermName($streetview); $success = isset($module_params['success']) ? $module_params['success'] : ''; $insertmode = isset($module_params['insertmode']) ? $module_params['insertmode'] : ''; if (!$streetview || $prefs['fgal_upload_from_source'] != 'y' || !$streetViewField) { $streetview = ''; } $location = null; $locationMode = null; if (isset($module_params['location'])) { $parts = explode(':', $module_params['location'], 2); $location = array_shift($parts); $locationMode = array_shift($parts); if (!$locationMode) { $locationMode = 'marker'; } $hiddeninput .= " {$location}()"; } preg_match_all('/(\\w+)\\(([^\\)]+)\\)/', $textinput, $parts, PREG_SET_ORDER); $text = array(); foreach ($parts as $p) { $text[$p[1]] = tra($p[2]); } preg_match_all('/(\\w+)\\(([^\\)]*)\\)/', $hiddeninput, $parts, PREG_SET_ORDER); $hidden = array(); foreach ($parts as $p) { $hidden[$p[1]] = $p[2]; } $galleryId = null; if ($streetview) { $galleryId = TikiLib::lib('filegal')->check_user_file_gallery($streetViewField['options_array'][0]); } $operation = null; $operationArgument = null; if (preg_match("/(\\w+)\\(([^\\)]*)\\)/", $success, $parts)) { $operation = $parts[1]; $operationArgument = $parts[2]; } $smarty->assign('tracker_input', array('trackerId' => $trackerId, 'textInput' => $text, 'hiddenInput' => $hidden, 'location' => $location, 'locationMode' => $locationMode, 'streetview' => $streetview, 'galleryId' => $galleryId, 'submit' => isset($module_params['submit']) ? $module_params['submit'] : tr('Create'), 'success' => array('operation' => $operation, 'argument' => $operationArgument), 'insertMode' => $insertmode)); }
function wikiplugin_archivebuilder_trackeratt($basepath, $trackerItem) { $trklib = TikiLib::lib('trk'); $data = $trklib->get_tracker_item($trackerItem); $item = Tracker_Item::fromInfo($data); if (!$item->canView()) { return array(); } $basepath = rtrim($basepath, '/') . '/'; $attachments = array(); $files = $trklib->list_item_attachments($trackerItem, 0, -1, 'attId_asc'); foreach ($files['data'] as $file) { $name = $basepath . $file['filename']; $complete = $trklib->get_item_attachment($file['attId']); $attachments[$name] = wikiplugin_archivebuilder_tracker_get_attbody($complete); } return $attachments; }
function smarty_block_permission($params, $content, $smarty, &$repeat) { if ($repeat) { return; } // Removing and Modifying a tracker item require a special permissions check if ($params['type'] == 'trackeritem') { $removePerms = ['remove_tracker_items', 'remove_tracker_items_pending', 'remove_tracker_items_closed']; $modifyPerms = ['modify_tracker_items', 'modify_tracker_items_pending', 'modify_tracker_items_closed']; $trklib = TikiLib::lib('trk'); $itemInfo = $trklib->get_tracker_item($params['object']); if (!$itemInfo) { return ""; //invalid tracker item. } $itemObject = Tracker_Item::fromInfo($itemInfo); if (in_array($params['name'], $removePerms)) { if ($itemObject->canRemove()) { return $content; } } elseif (in_array($params['name'], $modifyPerms)) { if ($itemObject->canModify()) { return $content; } } } //Standard permissions check $context = array(); if (isset($params['type'], $params['object'])) { $context['type'] = $params['type']; $context['object'] = $params['object']; } $perms = Perms::get($context); $name = $params['name']; if ($perms->{$name}) { return $content; } else { return ''; } }
function smarty_function_object_link_trackeritem($smarty, $object, $title = null, $type = 'wiki page', $url = null) { $pre = null; $item = Tracker_Item::fromId($object); if ($item && ($status = $item->getDisplayedStatus())) { $alt = tr($status); $pre = "<img src=\"img/icons/status_{$status}.gif\" alt=\"{$status}\"/> "; } return $pre . smarty_function_object_link_default($smarty, $object, $title, $type, $url); }
function wikiplugin_trackercalendar($data, $params) { static $id = 0; $headerlib = TikiLib::lib('header'); $headerlib->add_cssfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.css'); $headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js'); $jit = new JitFilter($params); $definition = Tracker_Definition::get($jit->trackerId->int()); $itemObject = Tracker_Item::newItem($jit->trackerId->int()); if (!$definition) { return WikiParser_PluginOutput::userError(tr('Tracker not found.')); } $beginField = $definition->getFieldFromPermName($jit->begin->word()); $endField = $definition->getFieldFromPermName($jit->end->word()); if (!$beginField || !$endField) { return WikiParser_PluginOutput::userError(tr('Fields not found.')); } $views = array(); if (!empty($params['amonth']) and $params['amonth'] != 'y') { $amonth = 'n'; } else { $amonth = 'y'; $views[] = 'month'; } if (!empty($params['aweek']) and $params['aweek'] != 'y') { $aweek = 'n'; } else { $aweek = 'y'; $views[] = 'agendaWeek'; } if (!empty($params['aday']) and $params['aday'] != 'y') { $aday = 'n'; } else { $aday = 'y'; $views[] = 'agendaDay'; } $resources = array(); if ($resourceField = $jit->resource->word()) { $field = $definition->getFieldFromPermName($resourceField); $resources = wikiplugin_trackercalendar_get_resources($field); if (!empty($params['rmonth']) and $params['rmonth'] != 'y') { $rmonth = 'n'; } else { $rmonth = 'y'; $views[] = 'resourceMonth'; } if (!empty($params['rweek']) and $params['rweek'] != 'y') { $rweek = 'n'; } else { $rweek = 'y'; $views[] = 'resourceWeek'; } if (!empty($params['rday']) and $params['rday'] != 'y') { $rday = 'n'; } else { $rday = 'y'; $views[] = 'resourceDay'; } } // Define the default View (dView) if (!empty($params['dView'])) { $dView = $params['dView']; } else { $dView = 'month'; } // Define the default date (dYear, dMonth, dDay) if (!empty($params['dYear'])) { $dYear = $params['dYear']; } else { $dYear = (int) date('Y'); } if (!empty($params['dMonth']) and $params['dMonth'] > 0 and $params['dMonth'] < 13) { $dMonth = $params['dMonth']; } else { $dMonth = (int) date('n'); } if (!empty($params['dDay']) and $params['dDay'] > 0 and $params['dDay'] < 32) { $dDay = $params['dDay']; } else { $dDay = (int) date('j'); } global $prefs; if (!empty($params['fDayofWeek']) and $params['fDayofWeek'] > -1 and $params['fDayofWeek'] < 7) { $firstDayofWeek = $params['fDayofWeek']; } elseif ($prefs['calendar_firstDayofWeek'] !== 'user') { $firstDayofWeek = $prefs['calendar_firstDayofWeek']; } else { $firstDayofWeek = 0; } $params['addAllFields'] = empty($params['addAllFields']) ? 'y' : $params['addAllFields']; $params['useSessionStorage'] = empty($params['useSessionStorage']) ? 'y' : $params['useSessionStorage']; $params['weekends'] = empty($params['weekends']) ? 'y' : $params['weekends']; $smarty = TikiLib::lib('smarty'); $smarty->assign('trackercalendar', array('id' => 'trackercalendar' . ++$id, 'trackerId' => $jit->trackerId->int(), 'begin' => $jit->begin->word(), 'end' => $jit->end->word(), 'resource' => $resourceField, 'resourceList' => $resources, 'coloring' => $jit->coloring->word(), 'beginFieldName' => 'ins_' . $beginField['fieldId'], 'endFieldName' => 'ins_' . $endField['fieldId'], 'firstDayofWeek' => $firstDayofWeek, 'views' => implode(',', $views), 'viewyear' => $dYear, 'viewmonth' => $dMonth, 'viewday' => $dDay, 'minHourOfDay' => 7, 'maxHourOfDay' => 24, 'addTitle' => tr('Insert'), 'canInsert' => $itemObject->canModify(), 'dView' => $dView, 'body' => $data, 'url' => $params['external'] === 'y' ? $params['url'] : '', 'trkitemid' => $params['external'] === 'y' ? $params['trkitemid'] : '', 'addAllFields' => $params['external'] === 'y' ? $params['addAllFields'] : '', 'useSessionStorage' => $params['external'] === 'y' ? $params['useSessionStorage'] : '', 'timeFormat' => $prefs['display_12hr_clock'] === 'y' ? 'h(:mm)TT' : 'HH:mm', 'weekends' => $params['weekends'] === 'y' ? 1 : 0)); return $smarty->fetch('wiki-plugins/trackercalendar.tpl'); }
} } else { //new file if ($isConversion) { $_REQUEST['name'] = preg_replace('/\\.(:?jpg|gif|png|tif[f]?)$/', '', $_REQUEST['name']) . tra(' drawing'); // strip extension } $galleryId = $_REQUEST["galleryId"]; if ($prefs['feature_draw_in_userfiles'] === 'y') { $galleryId = TikiLib::lib('filegal')->get_user_file_gallery(); } $fileId = $filegallib->insert_file($galleryId, $_REQUEST['name'], $_REQUEST['description'], $_REQUEST['name'] . ".svg", $_REQUEST['data'], strlen($_REQUEST['data']), $type, $user, null); } if (!empty($_REQUEST['fromItemId'])) { // a tracker item, so update the item field $item = Tracker_Item::fromId($_REQUEST['fromItemId']); if ($item->canModifyField($_REQUEST['fromFieldId'])) { $definition = $item->getDefinition(); $field = $definition->getField($_REQUEST['fromFieldId']); $trackerInput = $item->prepareFieldInput($field, array($_REQUEST['fromFieldId']->{$fileId})); $trackerInput['value'] = $fileId; TikiLib::lib('trk')->replace_item($field['trackerId'], $_REQUEST['fromItemId'], array('data' => array($trackerInput))); } } echo $fileId; die; } if ($fileInfo['filetype'] == $mimetypes["svg"]) { $data = $fileInfo["data"]; } else { //we already confirmed that this is an image, here we make it compatible with svg
function renderOutput($context = array()) { global $prefs; global $mimetypes; include 'lib/mime/mimetypes.php'; $galleryId = (int) $this->getOption('galleryId'); if (!isset($context['list_mode'])) { $context['list_mode'] = 'n'; } $value = $this->getValue(); if ($context['list_mode'] === 'csv') { return $value; } $ret = ''; if (!empty($value)) { if ($this->getOption('displayMode')) { // images etc $params = array('fileId' => $value); if ($context['list_mode'] === 'y') { $otherParams = $this->getOption('displayParamsForLists'); } else { $otherParams = $this->getOption('displayParams'); } if ($otherParams) { parse_str($otherParams, $otherParams); $params = array_merge($params, $otherParams); } $params['fromFieldId'] = $this->getConfiguration('fieldId'); $params['fromItemId'] = $this->getItemId(); $item = Tracker_Item::fromInfo($this->getItemData()); $params['checkItemPerms'] = $item->canModify() ? 'n' : 'y'; if ($this->getOption('displayMode') == 'img') { // img if ($context['list_mode'] === 'y') { $params['thumb'] = $context['list_mode']; $params['rel'] = 'box[' . $this->getInsertId() . ']'; } include_once 'lib/wiki-plugins/wikiplugin_img.php'; $ret = wikiplugin_img('', $params); } else { if ($this->getOption('displayMode') == 'vimeo') { // Vimeo videos stored as filegal REMOTEs include_once 'lib/wiki-plugins/wikiplugin_vimeo.php'; $ret = wikiplugin_vimeo('', $params); } else { if ($this->getOption('displayMode') == 'moodlescorm') { include_once 'lib/wiki-plugins/wikiplugin_playscorm.php'; foreach ($this->getConfiguration('files') as $fileId => $file) { $params['fileId'] = $fileId; $ret .= wikiplugin_playscorm('', $params); } } else { if ($this->getOption('displayMode') == 'googleviewer') { if ($prefs['auth_token_access'] != 'y') { $ret = tra('Token access needs to be enabled for Google viewer to be used'); } else { $files = array(); foreach ($this->getConfiguration('files') as $fileId => $file) { global $base_url, $tikiroot, $https_mode; if ($https_mode) { $scheme = 'https'; } else { $scheme = 'http'; } $googleurl = $scheme . "://docs.google.com/viewer?url="; $fileurl = urlencode($base_url . "tiki-download_file.php?fileId=" . $fileId); require_once 'lib/auth/tokens.php'; $tokenlib = AuthTokens::build($prefs); $token = $tokenlib->createToken($tikiroot . "tiki-download_file.php", array('fileId' => $fileId), array('Registered'), array('timeout' => 300, 'hits' => 3)); $fileurl .= urlencode("&TOKEN=" . $token); $url = $googleurl . $fileurl . '&embedded=true'; $title = $file['name']; $files[] = array('url' => $url, 'title' => $title, 'id' => $fileId); } $smarty = TikiLib::lib('smarty'); $smarty->assign('files', $files); $ret = $smarty->fetch('trackeroutput/files_googleviewer.tpl'); } } } } } $ret = preg_replace('/~\\/?np~/', '', $ret); } else { $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_function_object_link'); $ret = '<ol class="tracker-item-files">'; foreach ($this->getConfiguration('files') as $fileId => $file) { $ret .= '<li>'; $ret .= smarty_function_object_link(array('type' => 'file', 'id' => $fileId, 'title' => $file['name']), $smarty); $globalperms = Perms::get(array('type' => 'file gallery', 'object' => $galleryId)); if ($prefs['feature_draw'] == 'y' && $globalperms->upload_files == 'y' && ($file['filetype'] == $mimetypes["svg"] || $file['filetype'] == $mimetypes["gif"] || $file['filetype'] == $mimetypes["jpg"] || $file['filetype'] == $mimetypes["png"] || $file['filetype'] == $mimetypes["tiff"])) { $ret .= " <a href='tiki-edit_draw.php?fileId=" . $file['fileId'] . "' onclick='return \$(this).ajaxEditDraw();' title='Edit: " . $file['name'] . "' data-fileid='" . $file['fileId'] . "' data-galleryid='" . $galleryId . "'>\n\t\t\t\t\t\t\t<img width='16' height='16' class='icon' alt='Edit' src='img/icons/page_edit.png' />\n\t\t\t\t\t\t</a>"; } $ret .= '</li>'; } $ret .= '</ol>'; } } return $ret; }
if (isset($_REQUEST["returntracker"]) || isset($_REQUEST["save_return"])) { require_once 'lib/smarty_tiki/block.self_link.php'; header('Location: ' . smarty_block_self_link(array('_script' => 'tiki-view_tracker.php', '_tag' => 'n', '_urlencode' => 'n', 'itemId' => 'NULL', 'trackerId' => $_REQUEST['trackerId']), '', $smarty)); die; } // ******************************************************** if (isset($tracker_info['useRatings']) and $tracker_info['useRatings'] == 'y' and $tiki_p_tracker_vote_ratings == 'y') { if ($user and $tiki_p_tracker_vote_ratings == 'y' and isset($rateFieldId) and isset($_REQUEST['ins_' . $rateFieldId])) { $trklib->replace_rating($_REQUEST['trackerId'], $_REQUEST['itemId'], $rateFieldId, $user, $_REQUEST['ins_' . $rateFieldId]); header('Location: tiki-view_tracker_item.php?trackerId=' . $_REQUEST['trackerId'] . '&itemId=' . $_REQUEST['itemId']); die; } } if ($_REQUEST["itemId"]) { $info = $trklib->get_tracker_item($_REQUEST["itemId"]); $itemObject = Tracker_Item::fromInfo($info); if (!isset($info['trackerId'])) { $info['trackerId'] = $_REQUEST['trackerId']; } if (!$itemObject->canView()) { $smarty->assign('errortype', 401); $smarty->assign('msg', tra('Permission denied')); $smarty->display('error.tpl'); die; } $last = array(); $lst = ''; $tracker_item_main_value = ''; $fieldFactory = $definition->getFieldFactory(); foreach ($xfields["data"] as $i => $current_field) { $current_field_ins = null;
function wikiplugin_trackeritemfield($data, $params) { global $userTracker, $group, $user, $userlib, $tiki_p_admin_trackers, $prefs, $smarty, $tikilib; global $trklib; include_once 'lib/trackers/trackerlib.php'; static $memoItemId = 0; static $memoTrackerId = 0; static $memoStatus = 0; static $memoUserTracker = false; static $memoItemObject = null; extract($params, EXTR_SKIP); if (empty($itemId) && !empty($_REQUEST['itemId'])) { if (!empty($trackerId)) { $info = $trklib->get_item_info($_REQUEST['itemId']); if (!empty($info) && $info['trackerId'] == $trackerId) { $itemId = $_REQUEST['itemId']; } } else { $itemId = $_REQUEST['itemId']; } } if (empty($itemId) && !empty($trackerId) && ($tracker_info = $trklib->get_tracker($trackerId))) { if ($t = $trklib->get_tracker_options($trackerId)) { $tracker_info = array_merge($tracker_info, $t); } $itemId = $trklib->get_user_item($trackerId, $tracker_info); } if (!empty($itemId) && $memoItemId == $itemId || empty($itemId) && !empty($memoItemId)) { $itemId = $memoItemId; if (empty($memoTrackerId)) { return tra('Incorrect param'); } $trackerId = $memoTrackerId; $itemObject = $memoItemObject; } else { if (!empty($trackerId) && !empty($_REQUEST['view_user'])) { $itemId = $trklib->get_user_item($trackerId, $tracker_info, $_REQUEST['view_user']); } if (empty($trackerId) && empty($itemId) && (isset($userTracker) && $userTracker == 'y' || isset($prefs) && $prefs['userTracker'] == 'y') && !empty($group) && ($utid = $userlib->get_tracker_usergroup($user)) && $utid['usersTrackerId']) { $trackerId = $utid['usersTrackerId']; $itemId = $trklib->get_item_id($trackerId, $utid['usersFieldId'], $user); } else { if (empty($trackerId) && !empty($itemId)) { $item = $trklib->get_tracker_item($itemId); $trackerId = $item['trackerId']; } } if (empty($itemId) && empty($test) && empty($status)) { // need an item return tra('Incorrect param') . ': itemId'; } if (!empty($status) && !$trklib->valid_status($status)) { return tra('Incorrect param') . ': status'; } $info = $trklib->get_tracker_item($itemId); if (!empty($info) && empty($trackerId)) { $trackerId = $info['trackerId']; } $itemObject = Tracker_Item::fromInfo($info); if (!$itemObject->canView()) { return WikiParser_PluginOutput::error(tr('Permission denied'), tr('You are not allowed to view this item.')); } $memoStatus = $info['status']; $memoItemId = $itemId; $memoTrackerId = $info['trackerId']; $memoItemObject = $itemObject; if (isset($_REQUEST['itemId']) && $_REQUEST['itemId'] != $itemId) { global $logslib; include_once 'lib/logs/logslib.php'; $logslib->add_action('Viewed', $itemId, 'trackeritem', $_SERVER['REQUEST_URI'] . '&trackeritemfield'); } } if (!isset($data)) { $data = $dataelse = ''; } elseif (!empty($data) && strpos($data, '{ELSE}')) { $dataelse = substr($data, strpos($data, '{ELSE}') + 6); $data = substr($data, 0, strpos($data, '{ELSE}')); } else { $dataelse = ''; } if (!empty($status)) { if (!strstr($status, $memoStatus)) { return $dataelse; } } if (empty($itemId) && !empty($test)) { return $dataelse; } elseif (empty($itemId)) { return tra('Incorrect param') . ': itemId'; } elseif (isset($fields)) { $all_fields = $trklib->list_tracker_fields($trackerId, 0, -1); $all_fields = $all_fields['data']; if (!empty($fields)) { foreach ($all_fields as $i => $fopt) { if (!in_array($fopt['fieldId'], $fields)) { unset($all_fields[$i]); } } if (empty($all_fields)) { return tra('Incorrect param'); } } $field_values = $trklib->get_item_fields($trackerId, $itemId, $all_fields, $itemUser); foreach ($field_values as $field_value) { if ($field_value['type'] == 'p' && $field_value['options_array'][0] == 'password' || $field_value['isHidden'] != 'n' && $field_value['isHidden'] != 'c') { continue; } if (!$itemObject->canViewField($field_value['fieldId'])) { continue; } if (empty($field_value['value'])) { return $dataelse; } } } elseif (!empty($fieldId)) { if (!($field = $trklib->get_tracker_field($fieldId))) { return tra('Incorrect param') . ': fieldId'; } if (!$itemObject->canViewField($fieldId)) { return WikiParser_PluginOutput::error(tr('Permission denied'), tr('You are not allowed to view this field.')); } if (empty($test)) { $test = false; } if (($val = $trklib->get_item_value($trackerId, $itemId, $fieldId)) !== false) { if ($test) { if (!empty($value) && $val != $value) { return $dataelse; } return $data; } else { $field['value'] = $val; $handler = $trklib->get_field_handler($field, $info); // gets the handler to blend back the value into the definitions array $out = $handler->renderOutput(array('showlinks' => 'n')); return $out; } } elseif ($test) { // testing the value of a field that does not exist yet return $dataelse; } } return $data; }
function action_process($input) { $id = $input->id->int(); $userid = $input->userid->int(); $username = $input->username->text(); $fieldId = $input->fieldId->int(); $command = $input->command->word(); $svntag = $input->svntag->text(); $item = Tracker_Item::fromId($id); if (!$item->canViewField($fieldId)) { throw new Services_Exception_Denied(); } $field = TikiLib::lib('trk')->get_tracker_field($fieldId); $options = json_decode($field['options']); if (!is_object($options) && is_array($field['options_array'])) { // Support Tiki 11 $options = new stdClass(); $options->domain = $field['options_array'][0]; $options->remoteShellUser = $field['options_array'][1]; $options->publicKey = $field['options_array'][2]; $options->privateKey = $field['options_array'][3]; } $domain = $options->domain; $conn = ssh2_connect($domain, 22); $conntry = ssh2_auth_pubkey_file($conn, $options->remoteShellUser, $options->publicKey, $options->privateKey); if (!$conntry) { $ret['status'] = 'DISCO'; return $ret; } $infostring = "info -i {$id} -U {$userid}"; $infostream = ssh2_exec($conn, $infostring); stream_set_blocking($infostream, TRUE); $infooutput = stream_get_contents($infostream); $ret['debugoutput'] = $infooutput; if (strpos($infooutput, 'MAINTENANCE: ') !== false) { $maintpos = strpos($infooutput, 'MAINTENANCE: '); $maintreason = substr($infooutput, $maintpos + 13); $maintreason = substr($maintreason, 0, strpos($maintreason, '"')); $ret['maintreason'] = $maintreason; $ret['status'] = 'MAINT'; return $ret; } $versionpos = strpos($infooutput, 'VERSION: '); $version = substr($infooutput, $versionpos + 9); $version = substr($version, 0, strpos($version, PHP_EOL)); $version = trim($version); $ret['version'] = $version; $statuspos = strpos($infooutput, 'STATUS: '); $status = substr($infooutput, $statuspos + 8, 5); $status = trim($status); if (!$status || $status == 'FAIL') { $ret['status'] = 'FAIL'; } else { $ret['status'] = $status; $sitepos = strpos($infooutput, 'SITE: '); $site = substr($infooutput, $sitepos + 6); $site = substr($site, 0, strpos($site, ' ')); $ret['showurl'] = $site; $ret['showlogurl'] = $site . '/info.txt'; $ret['snapshoturl'] = $site . '/snapshots/'; if ($site && $ret['status'] == 'ACTIV') { $value = 'active ' . substr($site, 0, strpos($site, '.')); // the 'active' is useful for filtering on TikiLib::lib('trk')->modify_field($id, $fieldId, $value); require_once 'lib/search/refresh-functions.php'; refresh_index('trackeritem', $id); } elseif ($ret['status'] == 'NONE') { $value = 'none'; TikiLib::lib('trk')->modify_field($id, $fieldId, $value); require_once 'lib/search/refresh-functions.php'; refresh_index('trackeritem', $id); } } if (!empty($command)) { if (($command == 'update' || $command == 'reset' || $command == 'destroy') && !TikiLib::lib('user')->user_has_permission($user, 'tiki_p_admin') && $user != $creator) { throw new Services_Exception_Denied(); } if (empty($svntag)) { $fullstring = "{$command} -u {$creator} -i {$id} -U {$userid}"; } else { $fullstring = "{$command} -t {$svntag} -u {$username} -i {$id} -U {$userid}"; } $stream = ssh2_exec($conn, $fullstring); stream_set_blocking($stream, TRUE); $output = stream_get_contents($stream); fclose($stream); $ret['debugoutput'] = $fullstring . "\n" . $output; if ($command == 'snapshot') { $ret['status'] = 'SNAPS'; } else { if ($command == 'destroy') { $ret['status'] = 'DESTR'; } else { if ($command == 'create' || $command == 'update') { $ret['status'] = 'BUILD'; } else { if ($command == 'reset') { if (strpos('ERROR', $fullstring) !== false) { $ret['status'] = 'RENOK'; } else { $ret['status'] = 'RESOK'; } } } } } } $ret['debugoutput'] = '-' . $status . '- ' . $ret['debugoutput']; $cachelib = TikiLib::lib('cache'); $cacheKey = 'STO-' . $options->domain . '-' . $fieldId . "-" . $id; $cachelib->invalidate($cacheKey); return $ret; }
/** * @param $mod_reference * @param null $params * @return bool */ function module_since_last_visit_new($mod_reference, $params = null) { global $user; $smarty = TikiLib::lib('smarty'); include_once 'tiki-sefurl.php'; if (!$user) { return false; } if (!isset($params['use_jquery_ui']) || $params['use_jquery_ui'] != 'y') { $smarty->assign('use_jquery_ui', 'n'); } else { $smarty->assign('use_jquery_ui', 'y'); } if (!isset($params['date_as_link']) || $params['date_as_link'] != 'n') { $smarty->assign('date_as_link', 'y'); } else { $smarty->assign('date_as_link', 'n'); } if (!isset($params['fold_sections']) || $params['fold_sections'] != 'y') { $smarty->assign('default_folding', 'block'); $smarty->assign('opposite_folding', 'none'); } else { $smarty->assign('default_folding', 'none'); $smarty->assign('opposite_folding', 'block'); } if (empty($params['commentlength'])) { $params['commentlength'] = 40; } $resultCount = $mod_reference['rows']; global $prefs; $userlib = TikiLib::lib('user'); $tikilib = TikiLib::lib('tiki'); $smarty->loadPlugin('smarty_modifier_username'); $ret = array(); if ($params == null) { $params = array(); } if ((empty($params['calendar_focus']) || $params['calendar_focus'] != 'ignore') && strpos($_SERVER['SCRIPT_NAME'], 'tiki-calendar.php') !== false && !empty($_REQUEST['todate'])) { $last = $_REQUEST['todate']; $_SESSION['slvn_last_login'] = $last; $smarty->assign('tpl_module_title', tra('Changes since')); } else { if (isset($_SESSION['slvn_last_login'])) { $last = $_SESSION['slvn_last_login']; $smarty->assign('tpl_module_title', tra('Changes since')); } else { $last = $tikilib->getOne('select `lastLogin` from `users_users` where `login`=?', array($user)); $smarty->assign('tpl_module_title', tra('Since your last visit...')); if (!$last || !empty($params['daysAtLeast'])) { $now = TikiLib::lib('tiki')->now; if (!$last) { $last = $now; } if (!empty($params['daysAtLeast']) && $now - $last < $params['daysAtLeast'] * 60 * 60 * 24) { $last = $now - $params['daysAtLeast'] * 60 * 60 * 24; $smarty->assign('tpl_module_title', tr('In the last %0 days...', $params['daysAtLeast'])); } } } } $ret['lastLogin'] = $last; $ret['items']['comments']['label'] = tra('new comments'); $ret['items']['comments']['cname'] = 'slvn_comments_menu'; //TODO: should be a function on commentslib.php or use one of the existent functions $query = 'select `object`,`objectType`,`title`,`commentDate`,`userName`,`threadId`, `parentId`, `approved`, `archived`, `data`' . " from `tiki_comments` where `commentDate`>? and `objectType` != 'forum' order by `commentDate` desc"; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { $ret['items']['comments']['list'][$count]['href'] = TikiLib::lib('comments')->getHref($res['objectType'], $res['object'], $res['threadId']); switch ($res['objectType']) { case 'article': $perm = 'tiki_p_read_article'; $ret['items']['comments']['list'][$count]['href'] = filter_out_sefurl($ret['items']['comments']['list'][$count]['href'], 'article', $res['title']); break; case 'post': $perm = 'tiki_p_read_blog'; $ret['items']['comments']['list'][$count]['href'] = filter_out_sefurl($ret['items']['comments']['list'][$count]['href'], 'blogpost', $res['title']); break; case 'blog': $perm = 'tiki_p_read_blog'; $ret['items']['comments']['list'][$count]['href'] = filter_out_sefurl($ret['items']['comments']['list'][$count]['href'], 'blog', $res['title']); break; case 'faq': $perm = 'tiki_p_view_faqs'; break; case 'file gallery': $perm = 'tiki_p_view_file_gallery'; break; case 'image gallery': $perm = 'tiki_p_view_image_gallery'; break; case 'poll': // no perm check for viewing polls, only a perm for taking them break; case 'wiki page': $perm = 'tiki_p_view'; break; default: // note trackeritme needs more complex perms checking due to status and ownership $perm = 'tiki_p_read_comments'; break; } if ($res['approved'] == 'n' || $res['archived'] == 'y') { $visible = $userlib->user_has_perm_on_object($user, $res['object'], $res['objectType'], 'tiki_p_admin_comments'); } else { if ($res['objectType'] === 'trackeritem') { $item = Tracker_Item::fromId($res['object']); $visible = $item->canView(); } else { $visible = !isset($perm) || $userlib->user_has_perm_on_object($user, $res['object'], $res['objectType'], $perm); } } if ($visible) { $ret['items']['comments']['list'][$count]['title'] = $tikilib->get_short_datetime($res['commentDate']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['userName']); $ret['items']['comments']['list'][$count]['label'] = TikiLib::lib('comments')->process_comment_title($res, $params['commentlength']); if ($res['archived'] == 'y') { $ret['items']['comments']['list'][$count]['label'] .= tra(' (archived)'); } $count++; } } $ret['items']['comments']['count'] = $count; ///////////////////////////////////////////////////////////////////////// // FORUMS if ($prefs['feature_forums'] == 'y') { $ret['items']['posts']['label'] = tra('new posts'); $ret['items']['posts']['cname'] = 'slvn_posts_menu'; $query = 'select `posts`.`object`,`posts`.`objectType`,`posts`.`title`,`posts`.`commentDate`,' . ' `posts`.`userName`,`posts`.`threadId`, `posts`.`parentId`,`topics`.`title` `topic_title`' . ' from `tiki_comments` `posts`' . ' left join `tiki_comments` `topics` ON `posts`.`parentId` = `topics`.`threadId`' . " where `posts`.`commentDate`>? and `posts`.`objectType` = 'forum'" . ' order by `posts`.`commentDate` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['object'], $res['objectType'], 'tiki_p_forum_read')) { $ret['items']['posts']['list'][$count]['href'] = 'tiki-view_forum_thread.php?forumId=' . $res['object'] . '&comments_parentId='; if ($res['parentId']) { $ret['items']['posts']['list'][$count]['href'] .= $res['parentId'] . '#threadId' . $res['threadId']; } else { $ret['items']['posts']['list'][$count]['href'] .= $res['threadId']; } $ret['items']['posts']['list'][$count]['title'] = $tikilib->get_short_datetime($res['commentDate']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['userName']); if ($res['parentId'] == 0 || $prefs['forum_reply_notitle'] != 'y') { $ret['items']['posts']['list'][$count]['label'] = $res['title']; } else { $ret['items']['posts']['list'][$count]['label'] = $res['topic_title']; } ++$count; } } $ret['items']['posts']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // WIKI PAGES if ($prefs['feature_wiki'] == 'y') { $ret['items']['pages']['label'] = tra('wiki pages changed'); $ret['items']['pages']['cname'] = 'slvn_pages_menu'; $query = 'select `pageName`, `user`, `lastModif` from `tiki_pages` where `lastModif`>? order by `lastModif` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['pageName'], 'wiki page', 'tiki_p_view')) { $ret['items']['pages']['list'][$count]['href'] = filter_out_sefurl('tiki-index.php?page=' . urlencode($res['pageName'])); $ret['items']['pages']['list'][$count]['title'] = $tikilib->get_short_datetime($res['lastModif']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['pages']['list'][$count]['label'] = $res['pageName']; $count++; } } $ret['items']['pages']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // ARTICLES if ($prefs['feature_articles'] == 'y') { $ret['items']['articles']['label'] = tra('new articles'); $ret['items']['articles']['cname'] = 'slvn_articles_menu'; if ($userlib->user_has_permission($user, 'tiki_p_edit_article')) { $query = 'select `articleId`,`title`,`publishDate`,`authorName` from `tiki_articles` where `created`>? and `expireDate`>? order by `articleId` desc'; $bindvars = array((int) $last, time()); } else { $query = 'select `articleId`,`title`,`publishDate`,`authorName` from `tiki_articles` where `publishDate`>? and `publishDate`<=? and `expireDate`>? order by `articleId` desc'; $bindvars = array((int) $last, time(), time()); } $result = $tikilib->query($query, $bindvars, $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['articleId'], 'article', 'tiki_p_read_article')) { $ret['items']['articles']['list'][$count]['href'] = filter_out_sefurl('tiki-read_article.php?articleId=' . $res['articleId'], 'article', $res['title']); $ret['items']['articles']['list'][$count]['title'] = $tikilib->get_short_datetime($res['publishDate']) . ' ' . tra('by') . ' ' . $res['authorName']; $ret['items']['articles']['list'][$count]['label'] = $res['title']; $count++; } } $ret['items']['articles']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // FAQs if ($prefs['feature_faqs'] == 'y') { $ret['items']['faqs']['label'] = tra('new FAQs'); $ret['items']['faqs']['cname'] = 'slvn_faqs_menu'; $query = 'select `faqId`, `title`, `created` from `tiki_faqs` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['faqId'], 'faq', 'tiki_p_view_faq')) { $ret['items']['faqs']['list'][$count]['href'] = 'tiki-view_faq.php?faqId=' . $res['faqId']; $ret['items']['faqs']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']); $ret['items']['faqs']['list'][$count]['label'] = $res['title']; $count++; } } $ret['items']['faqs']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // BLOGS if ($prefs['feature_blogs'] == 'y') { $ret['items']['blogs']['label'] = tra('new blogs'); $ret['items']['blogs']['cname'] = 'slvn_blogs_menu'; $query = "select `blogId`, `title`, `user`, `created` from `tiki_blogs` where `created`>? order by `created` desc"; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['blogId'], 'blog', 'tiki_p_read_blog')) { $ret['items']['blogs']['list'][$count]['href'] = filter_out_sefurl('tiki-view_blog.php?blogId=' . $res['blogId'], 'blog', $res['title']); $ret['items']['blogs']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['blogs']['list'][$count]['label'] = $res['title']; $count++; } } $ret['items']['blogs']['count'] = $count; $ret['items']['blogPosts']['label'] = tra('new blog posts'); $ret['items']['blogPosts']['cname'] = 'slvn_blogPosts_menu'; $query = 'select `postId`, `blogId`, `title`, `user`, `created` from `tiki_blog_posts` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['blogId'], 'blog', 'tiki_p_read_blog')) { $ret['items']['blogPosts']['list'][$count]['href'] = filter_out_sefurl('tiki-view_blog_post.php?postId=' . $res['postId'], 'blogpost', $res['title']); $ret['items']['blogPosts']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['blogPosts']['list'][$count]['label'] = $res['title']; $count++; } } $ret['items']['blogPosts']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // IMAGE GALLERIES if ($prefs['feature_galleries'] == 'y') { // image galleries $ret['items']['imageGalleries']['label'] = tra('new image galleries'); $ret['items']['imageGalleries']['cname'] = 'slvn_imageGalleries_menu'; $query = "select `galleryId`,`name`,`created`,`user` from `tiki_galleries` where `created`>? order by `created` desc"; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['galleryId'], 'image gallery', 'tiki_p_view_image_gallery')) { $ret['items']['imageGalleries']['list'][$count]['href'] = 'tiki-browse_gallery.php?galleryId=' . $res['galleryId']; $ret['items']['imageGalleries']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['imageGalleries']['list'][$count]['label'] = $res['name']; $count++; } } $ret['items']['imageGalleries']['count'] = $count; // images $ret['items']['images']['label'] = tra('new images'); $ret['items']['images']['cname'] = 'slvn_images_menu'; $query = 'select `imageId`,`galleryId`,`name`,`created`,`user` from `tiki_images` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['galleryId'], 'image gallery', 'tiki_p_view_image_gallery')) { $ret['items']['images']['list'][$count]['href'] = 'tiki-browse_image.php?galleryId=' . $res['galleryId'] . '&imageId=' . $res['imageId']; $ret['items']['images']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['images']['list'][$count]['label'] = $res['name']; $count++; } } $ret['items']['images']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // FILE GALLERIES if ($prefs['feature_file_galleries'] == 'y') { // file galleries $ret['items']['fileGalleries']['label'] = tra('new file galleries'); $ret['items']['fileGalleries']['cname'] = 'slvn_fileGalleries_menu'; $query = 'select `galleryId`,`name`,`created`,`user` from `tiki_file_galleries` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['galleryId'], 'file gallery', 'tiki_p_view_file_gallery')) { $ret['items']['fileGalleries']['list'][$count]['href'] = filter_out_sefurl('tiki-list_file_gallery.php?galleryId=' . $res['galleryId'], 'file gallery'); $ret['items']['fileGalleries']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['fileGalleries']['list'][$count]['label'] = $res['name']; $count++; } } $ret['items']['fileGalleries']['count'] = $count; // files $ret['items']['files']['label'] = tra('new files'); //get_strings tra('new files'); $ret['items']['files']['cname'] = 'slvn_files_menu'; $query = 'select `fileId`, `galleryId`,`name`,`filename`,`created`,`user` from `tiki_files` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['galleryId'], 'file gallery', 'tiki_p_view_file_gallery')) { $ret['items']['files']['list'][$count]['href'] = filter_out_sefurl('tiki-list_file_gallery.php?galleryId=' . $res['galleryId'] . '&fileId=' . $res['fileId'] . '&view=page', 'file gallery'); $ret['items']['files']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['files']['list'][$count]['label'] = $res['name'] . ' (' . $res['filename'] . ')'; $count++; } } $ret['items']['files']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // POLLS if ($prefs['feature_polls'] == 'y') { $ret['items']['polls']['label'] = tra('new polls'); $ret['items']['polls']['cname'] = 'slvn_polls_menu'; $query = 'select `pollId`, `title`, `publishDate` from `tiki_polls` where `publishDate`>? order by `publishDate` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { $ret['items']['polls']['list'][$count]['href'] = 'tiki-poll_results.php?pollId=' . $res['pollId']; $ret['items']['polls']['list'][$count]['title'] = $tikilib->get_short_datetime($res['publishDate']); $ret['items']['polls']['list'][$count]['label'] = $res['title']; $count++; } $ret['items']['polls']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // NEW USERS if (!isset($params['showuser']) || $params['showuser'] != 'n') { $ret['items']['users']['label'] = tra('new users'); $ret['items']['users']['cname'] = 'slvn_users_menu'; $query = 'select `login`, `registrationDate` from `users_users` where `registrationDate`>? and `provpass`=?'; $result = $tikilib->query($query, array((int) $last, ''), $resultCount); $count = 0; $slvn_tmp_href = $userlib->user_has_permission($user, 'tiki_p_admin') ? 'tiki-assignuser.php?assign_user='******'tiki-user_information.php?view_user='******'items']['users']['list'][$count]['href'] = $slvn_tmp_href . rawurlencode($res['login']); $ret['items']['users']['list'][$count]['title'] = $tikilib->get_short_datetime($res['registrationDate']); $ret['items']['users']['list'][$count]['label'] = smarty_modifier_username($res['login']); $count++; } $ret['items']['users']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // TRACKER ITEMS // This breaks out tracker updates into sub-sections, by tracker, separating new items and updated items. // NEW TRACKER ITEMS if ($prefs['feature_trackers'] == 'y' && (!isset($params['showtracker']) || $params['showtracker'] != 'n')) { $ret['items']['trackers']['label'] = tra('new tracker items'); $ret['items']['trackers']['cname'] = 'slvn_trackers_menu'; $query = 'select `itemId`, `trackerId`, `created`, `lastModif` from `tiki_tracker_items` where `created`>? order by `created` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; $counta = array(); $tracker_name = array(); $cachelib = TikiLib::lib('cache'); while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['trackerId'], 'tracker', 'tiki_p_view_trackers')) { // Initialize tracker counter if needed. if (!isset($counta[$res['trackerId']])) { $counta[$res['trackerId']] = 0; } // Pull Tracker Name if ($res['trackerId'] > 0 && !isset($tracker_name[$res['trackerId']])) { $query = "select `name` from `tiki_trackers` where `trackerId` = ?"; $tracker_name[$res['trackerId']] = $tikilib->getOne($query, $res['trackerId']); } $ret['items']['trackers']['tid'][$res['trackerId']]['label'] = tra('in') . ' ' . tra($tracker_name[$res['trackerId']]); $ret['items']['trackers']['tid'][$res['trackerId']]['cname'] = 'slvn_tracker' . $res['trackerId'] . '_menu'; $ret['items']['trackers']['tid'][$res['trackerId']]['list'][$counta[$res['trackerId']]]['href'] = filter_out_sefurl('tiki-view_tracker_item.php?itemId=' . $res['itemId'], 'trackeritem'); $ret['items']['trackers']['tid'][$res['trackerId']]['list'][$counta[$res['trackerId']]]['title'] = $tikilib->get_short_datetime($res['created']); // routine to verify field in tracker that's used as label $cacheKey = 'trackerItemLabel' . $res['itemId']; if (!($label = $cachelib->getCached($cacheKey))) { $query = 'select `fieldId` from `tiki_tracker_fields` where `isMain` = ? and `trackerId` = ? order by `position`'; $fieldId = $tikilib->getOne($query, array('y', $res['trackerId'])); $query = 'select `value` from `tiki_tracker_item_fields` where `fieldId` = ? and `itemId` = ?'; $label = $tikilib->getOne($query, array($fieldId, $res['itemId'])); $cachelib->cacheItem($cacheKey, $label); } // If the label is empty (b:0;), then use the item ID if ($label == 'b:0;' || $label == '') { $label = 'Trk i' . $res['trackerId'] . ' - ID: ' . $res['itemId']; } $ret['items']['trackers']['tid'][$res['trackerId']]['list'][$counta[$res['trackerId']]]['label'] = $label; $counta[$res['trackerId']]++; $ret['items']['trackers']['tid'][$res['trackerId']]['count'] = $counta[$res['trackerId']]; $count++; } } $ret['items']['trackers']['count'] = $count; ///////////////////////////////////////////////////////////////////////// // UPDATED TRACKER ITEMS - ignore updates on same day as creation $ret['items']['utrackers']['label'] = tra('updated tracker items'); $ret['items']['utrackers']['cname'] = 'slvn_utrackers_menu'; $query = 'select `itemId`, `trackerId`, `created`, `lastModif`' . ' from `tiki_tracker_items` where `lastModif`>? and `lastModif`!=`created`' . ' order by `lastModif` desc'; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; $countb = array(); $cachelib = TikiLib::lib('cache'); while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['trackerId'], 'tracker', 'tiki_p_view_trackers')) { // Initialize tracker counter if needed. if (!isset($countb[$res['trackerId']])) { $countb[$res['trackerId']] = 0; } // Pull Tracker Name if (!isset($tracker_name[$res['trackerId']])) { $query = 'select `name` from `tiki_trackers` where `trackerId` = ?'; $tracker_name[$res['trackerId']] = $tikilib->getOne($query, $res['trackerId']); } $ret['items']['utrackers']['tid'][$res['trackerId']]['label'] = tra('in') . ' ' . tra($tracker_name[$res['trackerId']]); $ret['items']['utrackers']['tid'][$res['trackerId']]['cname'] = 'slvn_utracker' . $res['trackerId'] . '_menu'; $ret['items']['utrackers']['tid'][$res['trackerId']]['list'][$countb[$res['trackerId']]]['href'] = filter_out_sefurl('tiki-view_tracker_item.php?itemId=' . $res['itemId'], 'trackeritem'); $ret['items']['utrackers']['tid'][$res['trackerId']]['list'][$countb[$res['trackerId']]]['title'] = $tikilib->get_short_datetime($res['lastModif']); // routine to verify field in tracker that's used as label $cacheKey = 'trackerItemLabel' . $res['itemId']; if (!($label = $cachelib->getCached($cacheKey))) { $query = 'select `fieldId` from `tiki_tracker_fields` where `isMain` = ? and `trackerId` = ? order by `position`'; $fieldId = $tikilib->getOne($query, array('y', $res['trackerId'])); $query = 'select `value` from `tiki_tracker_item_fields` where `fieldId` = ? and `itemId` = ?'; $label = $tikilib->getOne($query, array($fieldId, $res['itemId'])); $cachelib->cacheItem($cacheKey, $label); } // If the label is empty (b:0;), then use the item ID if ($label == 'b:0;' || $label == '') { $label = 'Trk i' . $res['trackerId'] . ' - ID: ' . $res['itemId']; } $ret['items']['utrackers']['tid'][$res['trackerId']]['list'][$countb[$res['trackerId']]]['label'] = $label; $countb[$res['trackerId']]++; $ret['items']['utrackers']['tid'][$res['trackerId']]['count'] = $countb[$res['trackerId']]; $count++; } } $ret['items']['utrackers']['count'] = $count; } ///////////////////////////////////////////////////////////////////////// // CALENDARS & THEIR EVENTS if ($prefs['feature_calendar'] == 'y') { $ret['items']['calendar']['label'] = tra('new calendars'); $ret['items']['calendar']['cname'] = 'slvn_calendar_menu'; $query = "select `calendarId`, `name`, `user`, `created` from `tiki_calendars` where `created`>? order by `created` desc"; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['calendarId'], 'calendar', 'tiki_p_view_calendar')) { $ret['items']['calendar']['list'][$count]['href'] = filter_out_sefurl('tiki-calendar.php?calIds[]=' . $res['calendarId'], 'calendar', $res['name']); $ret['items']['calendar']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']); $ret['items']['calendar']['list'][$count]['label'] = $res['name']; $count++; } } $ret['items']['calendar']['count'] = $count; $ret['items']['events']['label'] = tra('new events'); $ret['items']['events']['cname'] = 'slvn_events_menu'; $query = "select `calitemId`, `calendarId`, `name`, `user`, `created`, `start` from `tiki_calendar_items` where `created`>? order by `created` desc"; $result = $tikilib->query($query, array((int) $last), $resultCount); $count = 0; while ($res = $result->fetchRow()) { if ($userlib->user_has_perm_on_object($user, $res['calendarId'], 'calendar', 'tiki_p_view_events')) { $ret['items']['events']['list'][$count]['href'] = filter_out_sefurl('tiki-calendar_edit_item.php?viewcalitemId=' . $res['calitemId'], 'event', $res['name']); $ret['items']['events']['list'][$count]['title'] = $tikilib->get_short_datetime($res['created']) . ' ' . tra('by') . ' ' . smarty_modifier_username($res['user']) . ', ' . tra('starting on') . ' ' . $tikilib->get_short_datetime($res['start']); $ret['items']['events']['list'][$count]['label'] = $res['name']; $count++; } } $ret['items']['events']['count'] = $count; } ////////////////////////////////////////////////////////////////////////// // SUMMARY //get the total of items $ret['cant'] = 0; $ret['nonempty'] = 0; foreach ($ret['items'] as $item) { $ret['cant'] += $item['count']; if ($item['count'] > 0) { $ret['nonempty']++; } } if ($ret['nonempty'] > 0) { $ret['li_width'] = min(22, (int) 90 / $ret['nonempty']); } else { $ret['li_width'] = 90; } $smarty->assign('slvn_info', $ret); }
public function list_items($trackerId, $offset = 0, $maxRecords = -1, $sort_mode = '', $listfields = '', $filterfield = '', $filtervalue = '', $status = '', $initial = '', $exactvalue = '', $filter = '', $allfields = null, $skip_status_perm_check = false, $skip_permission_check = false) { //echo '<pre>FILTERFIELD:'; print_r($filterfield); echo '<br />FILTERVALUE:';print_r($filtervalue); echo '<br />EXACTVALUE:'; print_r($exactvalue); echo '<br />STATUS:'; print_r($status); echo '<br />FILTER:'; print_r($filter); /*echo '<br />LISTFIELDS'; print_r($listfields);*/ echo '</pre>'; global $prefs; $cat_table = ''; $sort_tables = ''; $sort_join_clauses = ''; $csort_mode = ''; $corder = ''; $trackerId = (int) $trackerId; $numsort = false; $mid = ' WHERE tti.`trackerId` = ? '; $bindvars = array($trackerId); $join = ''; if (!empty($filter)) { $mid2 = array(); $this->parse_filter($filter, $mid2, $bindvars); if (!empty($mid2)) { $mid .= ' AND ' . implode(' AND ', $mid2); } } if (!$this->getSqlStatus($status, $mid, $bindvars, $trackerId, $skip_status_perm_check) && !$skip_status_perm_check && $status) { return array('cant' => 0, 'data' => ''); } if (substr($sort_mode, 0, 2) == 'f_') { list($a, $asort_mode, $corder) = preg_split('/_/', $sort_mode); } if ($initial) { $mid .= ' AND ttif.`value` LIKE ?'; $bindvars[] = $initial . '%'; if (isset($asort_mode)) { $mid .= ' AND ttif.`fieldId` = ?'; $bindvars[] = $asort_mode; } } if (!$sort_mode) { $sort_mode = 'lastModif_desc'; } if (substr($sort_mode, 0, 2) == 'f_' or !empty($filterfield)) { $cat_table = ''; if (substr($sort_mode, 0, 2) == 'f_') { $csort_mode = 'sttif.`value` '; $sort_tables = ' LEFT JOIN (`tiki_tracker_item_fields` sttif)' . ' ON (tti.`itemId` = sttif.`itemId`' . (!empty($asort_mode) ? " AND sttif.`fieldId` = {$asort_mode}" : '') . ')'; // Do we need a numerical sort on the field ? $field = $this->get_tracker_field($asort_mode); switch ($field['type']) { case 'C': case '*': case 'q': case 'n': $numsort = true; break; case 'l': // Do nothing, value is dynamic and thus cannot be sorted on $csort_mode = 1; $csort_tables = ''; break; case 'r': $link_field = intval($field['fieldId']); $remote_field = intval($field['options_array'][1]); $sort_tables = ' LEFT JOIN `tiki_tracker_item_fields` itemlink ON tti.itemId = itemlink.itemId AND itemlink.fieldId = ' . $link_field . ' LEFT JOIN `tiki_tracker_item_fields` sttif ON itemlink.value = sttif.itemId AND sttif.fieldId = ' . $remote_field . ' '; break; case 's': // if ($field['name'] == 'Rating' || $field['name'] == tra('Rating')) { // No need to have that string, isn't it? Admins can replace for a more suited string in their use case $numsort = true; // } break; } } else { list($csort_mode, $corder) = preg_split('/_/', $sort_mode); $csort_mode = 'tti.`' . $csort_mode . '` '; } if (empty($filterfield)) { $nb_filtered_fields = 0; } elseif (!is_array($filterfield)) { $fv = $filtervalue; $ev = $exactvalue; $ff = (int) $filterfield; $nb_filtered_fields = 1; } else { $nb_filtered_fields = count($filterfield); } $last = 0; for ($i = 0; $i < $nb_filtered_fields; $i++) { if (is_array($filterfield)) { //multiple filter on an exact value or a like value - each value can be simple or an array $ff = (int) $filterfield[$i]; $ff_array = $filterfield[$i]; // Need value as array used below $ev = !empty($exactvalue[$i]) ? $exactvalue[$i] : ''; $fv = !empty($filtervalue[$i]) ? $filtervalue[$i] : ''; } $filter = $this->get_tracker_field($ff); // Determine if field is an item list field and postpone filtering till later if so if ($filter["type"] == 'l' && isset($filter['options_array'][2]) && isset($filter['options_array'][2]) && isset($filter['options_array'][3])) { $linkfilter[] = array('filterfield' => $ff, 'exactvalue' => $ev, 'filtervalue' => $fv); continue; } $j = $last > 0 ? '0' : ''; $cat_table .= " INNER JOIN `tiki_tracker_item_fields` ttif{$i} ON (ttif{$i}.`itemId` = ttif{$j}.`itemId`)"; $last++; if (isset($ff_array['sqlsearch']) && is_array($ff_array['sqlsearch'])) { $mid .= " AND ttif{$i}.`fieldId` in (" . implode(',', array_fill(0, count($ff_array['sqlsearch']), '?')) . ')'; $bindvars = array_merge($bindvars, $ff_array['sqlsearch']); } elseif ($ff) { $mid .= " AND ttif{$i}.`fieldId`=? "; $bindvars[] = $ff; } if ($filter['type'] == 'e' && $prefs['feature_categories'] == 'y' && (!empty($ev) || !empty($fv))) { //category $value = empty($fv) ? $ev : $fv; if (!is_array($value) && $value != '') { $value = array($value); $not = ''; } elseif (is_array($value) && array_key_exists('not', $value)) { $value = array($value['not']); $not = 'not'; } if (empty($not)) { $cat_table .= " INNER JOIN `tiki_objects` tob{$ff} ON (tob{$ff}.`itemId` = tti.`itemId`)" . " INNER JOIN `tiki_category_objects` tco{$ff} ON (tob{$ff}.`objectId` = tco{$ff}.`catObjectId`)"; $mid .= " AND tob{$ff}.`type` = 'trackeritem' AND tco{$ff}.`categId` IN ( "; } else { $cat_table .= " left JOIN `tiki_objects` tob{$ff} ON (tob{$ff}.`itemId` = tti.`itemId`)" . " left JOIN `tiki_category_objects` tco{$ff} ON (tob{$ff}.`objectId` = tco{$ff}.`catObjectId`)"; $mid .= " AND tob{$ff}.`type` = 'trackeritem' AND tco{$ff}.`categId` NOT IN ( "; } $first = true; foreach ($value as $k => $catId) { if (is_array($catId)) { // this is a grouped AND logic for optimization indicated by the value being array $innerfirst = true; foreach ($catId as $c) { if (is_array($c)) { $innerfirst = true; foreach ($c as $d) { $bindvars[] = $d; if ($innerfirst) { $innerfirst = false; } else { $mid .= ','; } $mid .= '?'; } } else { $bindvars[] = $c; $mid .= '?'; } } if ($k < count($value) - 1) { $mid .= " ) AND "; if (empty($not)) { $ff2 = $ff . '_' . $k; $cat_table .= " INNER JOIN `tiki_category_objects` tco{$ff2} ON (tob{$ff}.`objectId` = tco{$ff2}.`catObjectId`)"; $mid .= "tco{$ff2}.`categId` IN ( "; } else { $ff2 = $ff . '_' . $k; $cat_table .= " left JOIN `tiki_category_objects` tco{$ff2} ON (tob{$ff}.`objectId` = tco{$ff2}.`catObjectId`)"; $mid .= "tco{$ff2}.`categId` NOT IN ( "; } } } else { $bindvars[] = $catId; if ($first) { $first = false; } else { $mid .= ','; } $mid .= '?'; } } $mid .= " ) "; if (!empty($not)) { $mid .= " OR tco{$ff}.`categId` IS NULL "; } } elseif ($filter['type'] == 'usergroups') { $definition = Tracker_Definition::get($trackerId); $userFieldId = $definition->getUserField(); $cat_table .= " INNER JOIN `tiki_tracker_item_fields` ttifu ON (tti.`itemId`=ttifu.`itemId`) INNER JOIN `users_users` uu ON (ttifu.`value`=uu.`login`) INNER JOIN `users_usergroups` uug ON (uug.`userId`=uu.`userId`)"; $mid .= ' AND ttifu.`fieldId`=? AND uug.`groupName`=? '; $bindvars[] = $userFieldId; $bindvars[] = empty($ev) ? $fv : $ev; } elseif ($filter['type'] == '*') { // star $mid .= " AND ttif{$i}.`value`*1>=? "; $bindvars[] = $ev; if (($j = array_search($ev, $filter['options_array'])) !== false && $j + 1 < count($filter['options_array'])) { $mid .= " AND ttif{$i}.`value`*1<? "; $bindvars[] = $filter['options_array'][$j + 1]; } } elseif ($filter['type'] == 'r' && ($fv || $ev)) { $cv = $fv ? $fv : $ev; if (is_numeric($cv)) { $mid .= " AND ttif{$i}.`value` = ? "; $bindvars[] = $cv; } else { $cat_table .= " INNER JOIN tiki_tracker_item_fields ttif{$i}_remote ON ttif{$i}.`value` = ttif{$i}_remote.`itemId` AND ttif{$i}_remote.`fieldId` = " . intval($filter['options_array'][1]) . ' '; $mid .= " AND ttif{$i}_remote.`value` LIKE ? "; $bindvars[] = $ev ? $ev : "%{$fv}%"; } } elseif ($ev > '') { if (is_array($ev)) { $keys = array_keys($ev); if (in_array((string) $keys[0], array('<', '>'))) { $mid .= " AND ttif{$i}.`value`" . $keys[0] . "? + 0"; $bindvars[] = $ev[$keys[0]]; } elseif (in_array((string) $keys[0], array('<=', '>='))) { $mid .= " AND (ttif{$i}.`value`" . $keys[0] . "? + 0 OR ttif{$i}.`value` = ?)"; $bindvars[] = $ev[$keys[0]]; $bindvars[] = $ev[$keys[0]]; } elseif ($keys[0] === 'not') { $mid .= " AND ttif{$i}.`value` not in (" . implode(',', array_fill(0, count($ev), '?')) . ")"; $bindvars = array_merge($bindvars, array_values($ev)); } else { $mid .= " AND ttif{$i}.`value` in (" . implode(',', array_fill(0, count($ev), '?')) . ")"; $bindvars = array_merge($bindvars, array_values($ev)); } } elseif (isset($ff_array['sqlsearch']) && is_array($ff_array['sqlsearch'])) { $mid .= " AND MATCH(ttif{$i}.`value`) AGAINST(? IN BOOLEAN MODE)"; $bindvars[] = $ev; } else { $mid .= " AND ttif{$i}.`value`=? "; $bindvars[] = $ev == '' ? $fv : $ev; } } elseif ($fv > '') { if (!is_array($fv)) { $value = array($fv); } else { $value = $fv; } $mid .= ' AND('; $cpt = 0; foreach ($value as $v) { if ($cpt++) { $mid .= ' OR '; } $mid .= " upper(ttif{$i}.`value`) like upper(?) "; if (substr($v, 0, 1) == '*' || substr($v, 0, 1) == '%') { $bindvars[] = '%' . substr($v, 1); } elseif (substr($v, -1, 1) == '*' || substr($v, -1, 1) == '%') { $bindvars[] = substr($v, 0, strlen($v) - 1) . '%'; } else { $bindvars[] = '%' . $v . '%'; } } $mid .= ')'; } elseif (is_null($ev) && is_null($fv)) { // test null value $mid .= " AND ttif{$i}.`value`=? OR ttif{$i}.`value` IS NULL"; $bindvars[] = ''; } } } else { if (strpos($sort_mode, '_') !== false) { list($csort_mode, $corder) = preg_split('/_/', $sort_mode); } else { $csort_mode = $sort_mode; $corder = 'asc'; } $csort_mode = "`" . $csort_mode . "`"; if ($csort_mode == '`itemId`') { $csort_mode = 'tti.`itemId`'; } $sort_tables = ''; $cat_tables = ''; } $categlib = TikiLib::lib('categ'); if ($jail = $categlib->get_jail()) { $categlib->getSqlJoin($jail, 'trackeritem', 'tti.`itemId`', $join, $mid, $bindvars); } $base_tables = '(' . ' `tiki_tracker_items` tti' . ' INNER JOIN `tiki_tracker_item_fields` ttif ON tti.`itemId` = ttif.`itemId`' . ' INNER JOIN `tiki_tracker_fields` ttf ON ttf.`fieldId` = ttif.`fieldId`' . ')' . $join; $fieldIds = array(); foreach ($listfields as $k => $f) { if (isset($f['fieldId'])) { $fieldIds[] = $f['fieldId']; } else { $fieldIds[] = $k; // sometimes filterfields are provided with the fieldId only on the array keys } } if (!empty($filterfield)) { // fix: could be that there is just one field. in this case it might be a scalar, // not an array due to not handle $filterfield proper somewhere else in the code if (!is_array($filterfield)) { $filterfield = array($filterfield); } foreach ($filterfield as $f) { if (!in_array($f, $fieldIds)) { $fieldIds[] = $f; } } } if (!empty($fieldIds)) { $mid .= ' AND ' . $this->in('ttif.fieldId', $fieldIds, $bindvars); } if ($csort_mode == '`created`') { $csort_mode = 'tti.created'; } $query = 'SELECT tti.*' . ', ' . ($numsort ? "cast(max({$csort_mode}) as decimal)" : "max({$csort_mode})") . ' as `sortvalue`' . ' FROM ' . $base_tables . $sort_tables . $cat_table . $mid . ' GROUP BY tti.`itemId`' . ' ORDER BY ' . $this->convertSortMode('sortvalue_' . $corder); if ($numsort) { $query .= ',' . $this->convertSortMode($csort_mode); } //echo htmlentities($query); print_r($bindvars); $query_cant = 'SELECT count(DISTINCT ttif.`itemId`) FROM ' . $base_tables . $sort_tables . $cat_table . $mid; // save the result $ret = array(); // Start loop to get the required number of items if permissions / filters are in use. // The problem: If $maxItems and $offset are given, // but the sql query returns items the user has no permissions or the filter criteria does not match, // then only a subset of what is available would be returned. // Due to performance issues with trackers having more than 5k items, we make it optional // $exactPaging true : slow on large tracker, check each item for permission and filtering // false: pass offset directly to sql, could lead to wrong pagination if perms / filter are used on items // Need to get this into tracker setup, so one can decide for each tracker how $exactPaging should work. // $definition = Tracker_Definition::get($trackerId); // default is old behaviour as of tiki14 - get offset directly from sql without taking permissions or filter into account. $exactPaging = false; // defaults for $exactPaging == false // original requested number of items $maxRecordsRequested = $maxRecords; // original page (from pagination) $offsetRequested = $offset; // offset calculated on $offsetRequested $currentOffset = 0; // set to true when we have enough records or no records left. $finished = false; // used internaly - one time query that returns the total number of records without taking into account filter or permissions $cant = $this->getOne($query_cant, $bindvars); // $cant will be modified bc its used otherwise. so save the totalCount value $totalCount = $cant; // total number of records read so far $currentCount = 0; // number of records in the result set $resultCount = 0; // settings for $exactPaging == true if ($exactPaging == true) { // outer loop - grab more records bc it might be we must filter out records. // 300 seems to be ok, bc paganination offers this as well as the size of the resultset // NOTE: This value is important with respect to memory usage and performance - especially when lots of items (like 10k+) are in use. $maxRecords = 300; // offset used for sql query $offset = 0; } while (!$finished) { $ret1 = $this->fetchAll($query, $bindvars, $maxRecords, $offset); // add. security - should not be necessary bc of check at the end. no records left - end outer loop if (count($ret1) == 0) { $finished = true; } foreach ($ret1 as $res) { $mem = TikiLib::lib('tiki')->get_memory_avail(); if ($mem < 1048576 * 10) { // Less than 10MB left? // post an error even though it doesn't get displayed when using export as the output goes into the output file TikiLib::lib('errorreport')->report(tr('Tracker list_items ran out of memory after %0 items.', count($ret))); break; } $res['itemUser'] = ''; if ($listfields !== null) { $res['field_values'] = $this->get_item_fields($trackerId, $res['itemId'], $listfields, $res['itemUser']); } if (!$skip_permission_check) { $itemObject = Tracker_Item::fromInfo($res); if (!$itemObject->canView()) { $cant--; // skipped record bc of permissions - need to count for outer loop $currentCount++; continue; } } if (!empty($asort_mode)) { foreach ($res['field_values'] as $i => $field) { if ($field['fieldId'] == $asort_mode) { $kx = $field['value'] . '.' . $res['itemId']; } } } if (isset($linkfilter) && $linkfilter) { $filterout = false; // NOTE: This implies filterfield if is link field has to be in fields set foreach ($res['field_values'] as $i => $field) { foreach ($linkfilter as $lf) { if ($field['fieldId'] == $lf["filterfield"]) { // extra comma at the front and back of filtervalue to avoid ambiguity in partial match if ($lf["filtervalue"] && strpos(',' . implode(',', $field['items']) . ',', $lf["filtervalue"]) === false) { $filterout = true; break 2; } elseif ($lf["exactvalue"] && !in_array($lf['exactvalue'], $field['items'])) { $filterout = true; break 2; } } } } if ($filterout) { $cant--; // skipped record bc of filter criteria - need to count for outer loop $currentCount++; continue; } } $res['geolocation'] = TikiLib::lib('geo')->get_coordinates('trackeritem', $res['itemId']); // have a field, adjust counter and check if we have enough items $currentCount++; $currentOffset++; // field is stored in $res. See wether we can add it to the resultset, based on the requested offset // if clause logic mainly for $exactPaging == true if ($currentOffset > $offsetRequested || $exactPaging == false) { $resultCount++; if (empty($kx)) { // ex: if the sort field is non visible, $kx is null $ret[] = $res; } else { $ret[$kx] = $res; } } // logic for $exactPaging == true. enough items - need to leave the foreach loop if ($resultCount == $maxRecordsRequested) { $finished = true; break; } } // foreach // foreach loop done - depending on $exactPaging we finish or might need to go ahead if ($exactPaging == false) { $finished = true; } // are items left? - this part is only relevant when $exactPaging == true if ($currentCount == $totalCount) { $finished = true; } else { $offset += $maxRecords; } } // while // End loop to get the required number of items if permissions / filters are in use $retval = array(); $retval['data'] = array_values($ret); $retval['cant'] = $cant; return $retval; }
function action_update_item_status($input) { if ($input->status->word() == 'DONE') { return array('status' => 'DONE', 'redirect' => $input->redirect->word()); } $trackerId = $input->trackerId->int(); $definition = Tracker_Definition::get($trackerId); if (!$definition) { throw new Services_Exception_NotFound(); } if (!($itemId = $input->itemId->int())) { throw new Services_Exception_MissingValue('itemId'); } $itemInfo = TikiLib::lib('trk')->get_tracker_item($itemId); if (!$itemInfo || $itemInfo['trackerId'] != $trackerId) { throw new Services_Exception_NotFound(); } if (empty($input->item_label->text())) { $item_label = "item"; } else { $item_label = $input->item_label->text(); } if (empty($input->title->text())) { $title = "Change item status"; } else { $title = $input->title->text(); } if (empty($input->button_label->text())) { $button_label = "Update " . $item_label; } else { $button_label = $input->button_label->text(); } $itemObject = Tracker_Item::fromInfo($itemInfo); if (!$itemObject->canModify()) { throw new Services_Exception_Denied(); } if ($input->confirm->int()) { $result = $this->utilities->updateItem($definition, array('itemId' => $itemId, 'trackerId' => $trackerId, 'status' => $input->status->text())); return array('FORWARD' => array('controller' => 'tracker', 'action' => 'update_item_status', 'status' => 'DONE', 'redirect' => $input->redirect->text())); } else { return array('trackerId' => $trackerId, 'itemId' => $itemId, 'item_label' => $item_label, 'status' => $input->status->text(), 'redirect' => $input->redirect->text(), 'confirmation_message' => $input->confirmation_message->text(), 'title' => $title, 'button_label' => $button_label); } if (false === $result) { throw new Services_Exception(tr('Validation error'), 406); } }
$item_info = $trklib->get_item_info($batchid); $actionObject = Tracker_Item::fromInfo($item_info); if ($actionObject->canRemove()) { $trklib->remove_tracker_item($batchid); } } $transaction->commit(); } elseif (isset($_REQUEST['batchaction']) and ($_REQUEST['batchaction'] == 'o' || $_REQUEST['batchaction'] == 'p' || $_REQUEST['batchaction'] == 'c')) { check_ticket('view-trackers'); $transaction = $tikilib->begin(); foreach ($_REQUEST['action'] as $batchid) { $item_info = $trklib->get_item_info($batchid); $actionObject = Tracker_Item::fromInfo($item_info); if ($actionObject->canModify()) { $trklib->replace_item($_REQUEST['trackerId'], $batchid, array('data' => ''), $_REQUEST['batchaction']); } } $transaction->commit(); } $smarty->assign('mail_msg', ''); $smarty->assign('email_mon', ''); if ($prefs['feature_user_watches'] == 'y' and $tiki_p_watch_trackers == 'y') { if ($user and isset($_REQUEST['watch'])) { check_ticket('view-trackers'); if ($_REQUEST['watch'] == 'add') { $tikilib->add_user_watch($user, 'tracker_modified', $_REQUEST["trackerId"], 'tracker', $tracker_info['name'], "tiki-view_tracker.php?trackerId=" . $_REQUEST["trackerId"]); } else {
public function list_items($trackerId, $offset = 0, $maxRecords = -1, $sort_mode = '', $listfields = '', $filterfield = '', $filtervalue = '', $status = '', $initial = '', $exactvalue = '', $filter = '', $allfields = null, $skip_status_perm_check = false, $skip_permission_check = false) { //echo '<pre>FILTERFIELD:'; print_r($filterfield); echo '<br />FILTERVALUE:';print_r($filtervalue); echo '<br />EXACTVALUE:'; print_r($exactvalue); echo '<br />STATUS:'; print_r($status); echo '<br />FILTER:'; print_r($filter); /*echo '<br />LISTFIELDS'; print_r($listfields);*/ echo '</pre>'; global $prefs; $cat_table = ''; $sort_tables = ''; $sort_join_clauses = ''; $csort_mode = ''; $corder = ''; $trackerId = (int) $trackerId; $numsort = false; $mid = ' WHERE tti.`trackerId` = ? '; $bindvars = array($trackerId); $join = ''; if (!empty($filter)) { $mid2 = array(); $this->parse_filter($filter, $mid2, $bindvars); if (!empty($mid2)) { $mid .= ' AND ' . implode(' AND ', $mid2); } } if (!$this->getSqlStatus($status, $mid, $bindvars, $trackerId) && !$skip_status_perm_check && $status) { return array('cant' => 0, 'data' => ''); } if (substr($sort_mode, 0, 2) == 'f_') { list($a, $asort_mode, $corder) = preg_split('/_/', $sort_mode); } if ($initial) { $mid .= ' AND ttif.`value` LIKE ?'; $bindvars[] = $initial . '%'; if (isset($asort_mode)) { $mid .= ' AND ttif.`fieldId` = ?'; $bindvars[] = $asort_mode; } } if (!$sort_mode) { $sort_mode = 'lastModif_desc'; } if (substr($sort_mode, 0, 2) == 'f_' or !empty($filterfield)) { $cat_table = ''; if (substr($sort_mode, 0, 2) == 'f_') { $csort_mode = 'sttif.`value` '; $sort_tables = ' LEFT JOIN (`tiki_tracker_item_fields` sttif)' . ' ON (tti.`itemId` = sttif.`itemId`' . (!empty($asort_mode) ? " AND sttif.`fieldId` = {$asort_mode}" : '') . ')'; // Do we need a numerical sort on the field ? $field = $this->get_tracker_field($asort_mode); switch ($field['type']) { case 'C': case '*': case 'q': case 'n': $numsort = true; break; case 'l': // Do nothing, value is dynamic and thus cannot be sorted on $csort_mode = 1; $csort_tables = ''; break; case 'r': $link_field = intval($field['fieldId']); $remote_field = intval($field['options_array'][1]); $sort_tables = ' LEFT JOIN `tiki_tracker_item_fields` itemlink ON tti.itemId = itemlink.itemId AND itemlink.fieldId = ' . $link_field . ' LEFT JOIN `tiki_tracker_item_fields` sttif ON itemlink.value = sttif.itemId AND sttif.fieldId = ' . $remote_field . ' '; break; case 's': // if ($field['name'] == 'Rating' || $field['name'] == tra('Rating')) { // No need to have that string, isn't it? Admins can replace for a more suited string in their use case $numsort = true; // } break; } } else { list($csort_mode, $corder) = preg_split('/_/', $sort_mode); $csort_mode = 'tti.`' . $csort_mode . '` '; } if (empty($filterfield)) { $nb_filtered_fields = 0; } elseif (!is_array($filterfield)) { $fv = $filtervalue; $ev = $exactvalue; $ff = (int) $filterfield; $nb_filtered_fields = 1; } else { $nb_filtered_fields = count($filterfield); } $last = 0; for ($i = 0; $i < $nb_filtered_fields; $i++) { if (is_array($filterfield)) { //multiple filter on an exact value or a like value - each value can be simple or an array $ff = (int) $filterfield[$i]; $ev = !empty($exactvalue[$i]) ? $exactvalue[$i] : ''; $fv = !empty($filtervalue[$i]) ? $filtervalue[$i] : ''; } $filter = $this->get_tracker_field($ff); // Determine if field is an item list field and postpone filtering till later if so if ($filter["type"] == 'l' && isset($filter['options_array'][2]) && isset($filter['options_array'][2]) && isset($filter['options_array'][3])) { $linkfilter[] = array('filterfield' => $ff, 'exactvalue' => $ev, 'filtervalue' => $fv); continue; } $j = $last > 0 ? '0' : ''; $cat_table .= " INNER JOIN `tiki_tracker_item_fields` ttif{$i} ON (ttif{$i}.`itemId` = ttif{$j}.`itemId`)"; $last++; if (isset($ff['sqlsearch']) && is_array($ff['sqlsearch'])) { $mid .= " AND ttif{$i}.`fieldId` in (" . implode(',', array_fill(0, count($ff['sqlsearch']), '?')) . ')'; $bindvars = array_merge($bindvars, $ff['sqlsearch']); } elseif ($ff) { $mid .= " AND ttif{$i}.`fieldId`=? "; $bindvars[] = $ff; } if ($filter['type'] == 'e' && $prefs['feature_categories'] == 'y' && (!empty($ev) || !empty($fv))) { //category $value = empty($fv) ? $ev : $fv; if (!is_array($value) && $value != '') { $value = array($value); $not = ''; } elseif (is_array($value) && array_key_exists('not', $value)) { $value = array($value['not']); $not = 'not'; } if (empty($not)) { $cat_table .= " INNER JOIN `tiki_objects` tob{$ff} ON (tob{$ff}.`itemId` = tti.`itemId`)" . " INNER JOIN `tiki_category_objects` tco{$ff} ON (tob{$ff}.`objectId` = tco{$ff}.`catObjectId`)"; $mid .= " AND tob{$ff}.`type` = 'trackeritem' AND tco{$ff}.`categId` IN ( "; } else { $cat_table .= " left JOIN `tiki_objects` tob{$ff} ON (tob{$ff}.`itemId` = tti.`itemId`)" . " left JOIN `tiki_category_objects` tco{$ff} ON (tob{$ff}.`objectId` = tco{$ff}.`catObjectId`)"; $mid .= " AND tob{$ff}.`type` = 'trackeritem' AND tco{$ff}.`categId` NOT IN ( "; } $first = true; foreach ($value as $k => $catId) { if (is_array($catId)) { // this is a grouped AND logic for optimization indicated by the value being array $innerfirst = true; foreach ($catId as $c) { if (is_array($c)) { $innerfirst = true; foreach ($c as $d) { $bindvars[] = $d; if ($innerfirst) { $innerfirst = false; } else { $mid .= ','; } $mid .= '?'; } } else { $bindvars[] = $c; $mid .= '?'; } } if ($k < count($value) - 1) { $mid .= " ) AND "; if (empty($not)) { $ff2 = $ff . '_' . $k; $cat_table .= " INNER JOIN `tiki_category_objects` tco{$ff2} ON (tob{$ff}.`objectId` = tco{$ff2}.`catObjectId`)"; $mid .= "tco{$ff2}.`categId` IN ( "; } else { $ff2 = $ff . '_' . $k; $cat_table .= " left JOIN `tiki_category_objects` tco{$ff2} ON (tob{$ff}.`objectId` = tco{$ff2}.`catObjectId`)"; $mid .= "tco{$ff2}.`categId` NOT IN ( "; } } } else { $bindvars[] = $catId; if ($first) { $first = false; } else { $mid .= ','; } $mid .= '?'; } } $mid .= " ) "; if (!empty($not)) { $mid .= " OR tco{$ff}.`categId` IS NULL "; } } elseif ($filter['type'] == 'usergroups') { $definition = Tracker_Definition::get($trackerId); $userFieldId = $definition->getUserField(); $cat_table .= " INNER JOIN `tiki_tracker_item_fields` ttifu ON (tti.`itemId`=ttifu.`itemId`) INNER JOIN `users_users` uu ON (ttifu.`value`=uu.`login`) INNER JOIN `users_usergroups` uug ON (uug.`userId`=uu.`userId`)"; $mid .= ' AND ttifu.`fieldId`=? AND uug.`groupName`=? '; $bindvars[] = $userFieldId; $bindvars[] = empty($ev) ? $fv : $ev; } elseif ($filter['type'] == '*') { // star $mid .= " AND ttif{$i}.`value`*1>=? "; $bindvars[] = $ev; if (($j = array_search($ev, $filter['options_array'])) !== false && $j + 1 < count($filter['options_array'])) { $mid .= " AND ttif{$i}.`value`*1<? "; $bindvars[] = $filter['options_array'][$j + 1]; } } elseif ($filter['type'] == 'r' && ($fv || $ev)) { $cv = $fv ? $fv : $ev; if (is_numeric($cv)) { $mid .= " AND ttif{$i}.`value` = ? "; $bindvars[] = $cv; } else { $cat_table .= " INNER JOIN tiki_tracker_item_fields ttif{$i}_remote ON ttif{$i}.`value` = ttif{$i}_remote.`itemId` AND ttif{$i}_remote.`fieldId` = " . intval($filter['options_array'][1]) . ' '; $mid .= " AND ttif{$i}_remote.`value` LIKE ? "; $bindvars[] = $ev ? $ev : "%{$fv}%"; } } elseif ($ev > '') { if (is_array($ev)) { $keys = array_keys($ev); if (in_array((string) $keys[0], array('<', '>'))) { $mid .= " AND ttif{$i}.`value`" . $keys[0] . "? + 0"; $bindvars[] = $ev[$keys[0]]; } elseif (in_array((string) $keys[0], array('<=', '>='))) { $mid .= " AND (ttif{$i}.`value`" . $keys[0] . "? + 0 OR ttif{$i}.`value` = ?)"; $bindvars[] = $ev[$keys[0]]; $bindvars[] = $ev[$keys[0]]; } elseif ($keys[0] === 'not') { $mid .= " AND ttif{$i}.`value` not in (" . implode(',', array_fill(0, count($ev), '?')) . ")"; $bindvars = array_merge($bindvars, array_values($ev)); } else { $mid .= " AND ttif{$i}.`value` in (" . implode(',', array_fill(0, count($ev), '?')) . ")"; $bindvars = array_merge($bindvars, array_values($ev)); } } elseif (isset($ff['sqlsearch']) && is_array($ff['sqlsearch'])) { $mid .= " AND MATCH(ttif{$i}.`value`) AGAINST(? IN BOOLEAN MODE)"; $bindvars[] = $ev; } else { $mid .= " AND ttif{$i}.`value`=? "; $bindvars[] = $ev == '' ? $fv : $ev; } } elseif ($fv > '') { if (!is_array($fv)) { $value = array($fv); } else { $value = $fv; } $mid .= ' AND('; $cpt = 0; foreach ($value as $v) { if ($cpt++) { $mid .= ' OR '; } $mid .= " upper(ttif{$i}.`value`) like upper(?) "; if (substr($v, 0, 1) == '*' || substr($v, 0, 1) == '%') { $bindvars[] = '%' . substr($v, 1); } elseif (substr($v, -1, 1) == '*' || substr($v, -1, 1) == '%') { $bindvars[] = substr($v, 0, strlen($v) - 1) . '%'; } else { $bindvars[] = '%' . $v . '%'; } } $mid .= ')'; } elseif (is_null($ev) && is_null($fv)) { // test null value $mid .= " AND ttif{$i}.`value`=? OR ttif{$i}.`value` IS NULL"; $bindvars[] = ''; } } } else { if (strpos($sort_mode, '_') !== false) { list($csort_mode, $corder) = preg_split('/_/', $sort_mode); } else { $csort_mode = $sort_mode; $corder = 'asc'; } $csort_mode = "`" . $csort_mode . "`"; if ($csort_mode == '`itemId`') { $csort_mode = 'tti.`itemId`'; } $sort_tables = ''; $cat_tables = ''; } $categlib = TikiLib::lib('categ'); if ($jail = $categlib->get_jail()) { $categlib->getSqlJoin($jail, 'trackeritem', 'tti.`itemId`', $join, $mid, $bindvars); } $base_tables = '(' . ' `tiki_tracker_items` tti' . ' INNER JOIN `tiki_tracker_item_fields` ttif ON tti.`itemId` = ttif.`itemId`' . ' INNER JOIN `tiki_tracker_fields` ttf ON ttf.`fieldId` = ttif.`fieldId`' . ')' . $join; $fieldIds = array(); foreach ($listfields as $k => $f) { if (isset($f['fieldId'])) { $fieldIds[] = $f['fieldId']; } else { $fieldIds[] = $k; // sometimes filterfields are provided with the fieldId only on the array keys } } if (!empty($filterfield)) { foreach ($filterfield as $f) { if (!in_array($f, $fieldIds)) { $fieldIds[] = $f; } } } if (!empty($fieldIds)) { $mid .= ' AND ' . $this->in('ttif.fieldId', $fieldIds, $bindvars); } if ($csort_mode == '`created`') { $csort_mode = 'tti.created'; } $query = 'SELECT tti.*, ttif.`value`, ttf.`type`' . ', ' . ($numsort ? "cast({$csort_mode} as decimal)" : $csort_mode) . ' as `sortvalue`' . ' FROM ' . $base_tables . $sort_tables . $cat_table . $mid . ' GROUP BY tti.`itemId`' . ' ORDER BY ' . $this->convertSortMode('sortvalue_' . $corder); if ($numsort) { $query .= ',' . $this->convertSortMode($csort_mode); } //echo htmlentities($query); print_r($bindvars); $query_cant = 'SELECT count(DISTINCT ttif.`itemId`) FROM ' . $base_tables . $sort_tables . $cat_table . $mid; $ret1 = $this->fetchAll($query, $bindvars, $maxRecords, $offset); $cant = $this->getOne($query_cant, $bindvars); $type = ''; $ret = array(); foreach ($ret1 as $res) { $mem = TikiLib::lib('tiki')->get_memory_avail(); if ($mem < 1048576 * 10) { // Less than 10MB left? // post an error even though it doesn't get displayed when using export as the output goes into the output file TikiLib::lib('errorreport')->report(tr('Tracker list_items ran out of memory after %0 items.', count($ret))); break; } $res['itemUser'] = ''; if ($listfields !== null) { $res['field_values'] = $this->get_item_fields($trackerId, $res['itemId'], $listfields, $res['itemUser']); } if (!$skip_permission_check) { $itemObject = Tracker_Item::fromInfo($res); if (!$itemObject->canView()) { $cant--; continue; } } if (!empty($asort_mode)) { foreach ($res['field_values'] as $i => $field) { if ($field['fieldId'] == $asort_mode) { $kx = $field['value'] . '.' . $res['itemId']; } } } if (isset($linkfilter) && $linkfilter) { $filterout = false; // NOTE: This implies filterfield if is link field has to be in fields set foreach ($res['field_values'] as $i => $field) { foreach ($linkfilter as $lf) { if ($field['fieldId'] == $lf["filterfield"]) { // extra comma at the front and back of filtervalue to avoid ambiguity in partial match if ($lf["filtervalue"] && strpos(',' . implode(',', $field['items']) . ',', $lf["filtervalue"]) === false) { $filterout = true; break 2; } elseif ($lf["exactvalue"] && !in_array($lf['exactvalue'], $field['items'])) { $filterout = true; break 2; } } } } if ($filterout) { $cant--; continue; } } $res['geolocation'] = TikiLib::lib('geo')->get_coordinates('trackeritem', $res['itemId']); if (empty($kx)) { // ex: if the sort field is non visible, $kx is null $ret[] = $res; } else { $ret[$kx] = $res; } } $retval = array(); $retval['data'] = array_values($ret); $retval['cant'] = $cant; return $retval; }
function wikiplugin_invite($data, $params) { global $prefs, $user, $tiki_p_invite_to_my_groups; $userlib = TikiLib::lib('user'); $tikilib = TikiLib::lib('tiki'); $smarty = TikiLib::lib('smarty'); if ($tiki_p_invite_to_my_groups != 'y') { return; } $userGroups = $userlib->get_user_groups_inclusion($user); if (!empty($params['including'])) { $groups = $userlib->get_including_groups($params['including']); foreach ($userGroups as $gr => $inc) { if (!in_array($gr, $groups)) { unset($userGroups[$gr]); } } } $errors = array(); $feedbacks = array(); if (isset($_REQUEST['invite'])) { if (empty($_REQUEST['email'])) { $errors[] = tra('The following mandatory fields are missing') . ' ' . tra('Email address'); } if (!validate_email($_REQUEST['email'])) { $errors[] = tra('Invalid Email') . ' ' . $_REQUEST['email']; } if (!empty($_REQUEST['groups'])) { foreach ($_REQUEST['groups'] as $group) { if (empty($userGroups[$group])) { $errors[] = tra('Incorrect param') . ' ' . $group; } } } if (empty($errors)) { $email = $_REQUEST['email']; if (!($invite = $userlib->get_user_by_email($email))) { $new_user = true; $password = '******'; //$tikilib->genPass(); $codedPassword = md5($password); if ($prefs['login_autogenerate'] == 'y') { $uname = ''; } else { $uname = $email; } $uname = $userlib->add_user($uname, $password, $email, $password, true, NULL); $smarty->assign('codedPassword', $codedPassword); $invite = $email; } else { $new_user = false; } $smarty->assign_by_ref('new_user', $new_user); $smarty->assign_by_ref('invite', $invite); if (!empty($_REQUEST['groups'])) { foreach ($_REQUEST['groups'] as $group) { $userlib->assign_user_to_group($uname, $group); $invitedGroups[] = $userlib->get_group_info($group); } } include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $machine = parse_url($_SERVER['REQUEST_URI']); $machine = $tikilib->httpPrefix(true) . dirname($machine['path']); $smarty->assign_by_ref('machine', $machine); $subject = sprintf($smarty->fetch('mail/mail_invite_subject.tpl'), $_SERVER['SERVER_NAME']); $mail->setSubject($subject); if (!empty($_REQUEST['message'])) { $smarty->assign('message', $_REQUEST['message']); } $smarty->assign_by_ref('groups', $invitedGroups); $txt = $smarty->fetch('mail/mail_invite.tpl'); $mail->setText($txt); $mail->send(array($email)); return $data; } else { $smarty->assign_by_ref('errors', $errors); $smarty->assign_by_ref('email', $_REQUEST['email']); if (!empty($_REQUEST['groups'])) { $smarty->assign_by_ref('groups', $_REQUEST['groups']); } if (!empty($_REQUEST['message'])) { $smarty->assign_by_ref('message', $_REQUEST['message']); } } } if (!empty($_REQUEST['itemId'])) { $params['itemId'] = $_REQUEST['itemId']; } if (!empty($params['itemId'])) { $item = Tracker_Item::fromId($params['itemId']); $params['defaultgroup'] = $item->getOwnerGroup(); } $smarty->assign_by_ref('params', $params); $smarty->assign_by_ref('userGroups', $userGroups); return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_invite.tpl') . '~/np~'; }
function renderOutput($context = array()) { global $prefs; global $mimetypes; include 'lib/mime/mimetypes.php'; $galleryId = (int) $this->getOption('galleryId'); if (!isset($context['list_mode'])) { $context['list_mode'] = 'n'; } $value = $this->getValue(); if ($context['list_mode'] === 'csv') { return $value; } $ret = ''; if (!empty($value)) { if ($this->getOption('displayImages')) { // images $params = array('fileId' => $value); if ($context['list_mode'] === 'y') { $params['thumb'] = $context['list_mode']; $params['rel'] = 'box[' . $this->getInsertId() . ']'; $otherParams = $this->getOption('imageParamsForLists'); } else { $otherParams = $this->getOption('imageParams'); } if ($otherParams) { parse_str($otherParams, $otherParams); $params = array_merge($params, $otherParams); } include_once 'lib/wiki-plugins/wikiplugin_img.php'; $params['fromFieldId'] = $this->getConfiguration('fieldId'); $params['fromItemId'] = $this->getItemId(); $item = Tracker_Item::fromInfo($this->getItemData()); $params['checkItemPerms'] = $item->canModify() ? 'n' : 'y'; $ret = wikiplugin_img('', $params, 0); $ret = preg_replace('/~\\/?np~/', '', $ret); } else { $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_function_object_link'); $ret = '<ol>'; foreach ($this->getConfiguration('files') as $fileId => $file) { $ret .= '<li>'; $ret .= smarty_function_object_link(array('type' => 'file', 'id' => $fileId, 'title' => $file['name']), $smarty); $globalperms = Perms::get(array('type' => 'file gallery', 'object' => $galleryId)); if ($prefs['feature_draw'] == 'y' && $globalperms->upload_files == 'y' && ($file['filetype'] == $mimetypes["svg"] || $file['filetype'] == $mimetypes["gif"] || $file['filetype'] == $mimetypes["jpg"] || $file['filetype'] == $mimetypes["png"] || $file['filetype'] == $mimetypes["tiff"])) { $ret .= " <a href='tiki-edit_draw.php?fileId=" . $file['fileId'] . "' onclick='return \$(this).ajaxEditDraw();' title='Edit: " . $file['name'] . "' data-fileid='" . $file['fileId'] . "' data-galleryid='" . $file['galleryId'] . "'>\n\t\t\t\t\t\t\t<img width='16' height='16' class='icon' alt='Edit' src='img/icons/page_edit.png' />\n\t\t\t\t\t\t</a>"; } $ret .= '</li>'; } $ret .= '</ol>'; } } return $ret; }
function smarty_function_object_link_trackeritem($smarty, $object, $title = null, $type = 'wiki page', $url = null) { global $prefs; $pre = null; $item = Tracker_Item::fromId($object); //Set show status to 'y' by default if (!empty($prefs['tracker_status_in_objectlink'])) { $show_status = $prefs['tracker_status_in_objectlink']; } else { $show_status = 'y'; } if ($show_status == 'y' && $item && ($status = $item->getDisplayedStatus())) { $alt = tr($status); $pre = "<img src=\"img/icons/status_{$status}.gif\" alt=\"{$status}\"/> "; } return $pre . smarty_function_object_link_default($smarty, $object, $title, $type, $url); }
function wikiplugin_tracker($data, $params) { global $user, $group, $page, $prefs; $parserlib = TikiLib::lib('parser'); $trklib = TikiLib::lib('trk'); $userlib = TikiLib::lib('user'); $tikilib = TikiLib::lib('tiki'); $smarty = TikiLib::lib('smarty'); $captchalib = TikiLib::lib('captcha'); static $iTRACKER = 0; ++$iTRACKER; if (isset($params['itemId']) && empty($params['itemId'])) { return; } $smarty->assign('trackerEditFormId', $iTRACKER); $default = array('overwrite' => 'n', 'embedded' => 'n', 'showtitle' => 'n', 'showdesc' => 'n', 'showfieldsdesc' => 'y', 'sort' => 'n', 'showmandatory' => 'y', 'status' => '', 'transactionFinalStep' => 'y', 'registration' => 'n', 'chosenGroup' => 'Registered', 'validateusers' => '', 'emailformat' => 'text'); $params = array_merge($default, $params); $item = array(); extract($params, EXTR_SKIP); if (empty($transactionName) xor empty($transactionStep)) { return '<b>' . tra("You need to define both transaction name and transaction step, or none of the two.") . '</b>'; } else { if (isset($transactionName) && !isset($_SESSION[$transactionName])) { $_SESSION[$transactionName] = array(); } if (isset($transactionStep) && !isset($_SESSION[$transactionName][$transactionStep])) { $_SESSION[$transactionName][$transactionStep] = array(); } if (!isset($_SESSION[$transactionName]['transactionStep'])) { $_SESSION[$transactionName]['transactionStep'] = 0; } if ($_SESSION[$transactionName]['transactionStep'] != $transactionStep) { return; } } if ($prefs['feature_trackers'] != 'y') { return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } if (empty($trackerId) || !($definition = Tracker_Definition::get($trackerId))) { return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } $tracker = $definition->getInformation(); if (empty($trackerId) && !empty($view) && $view == 'user' && $prefs['userTracker'] == 'y') { // the user tracker item $utid = $userlib->get_tracker_usergroup($user); if (!empty($utid) && !empty($utid['usersTrackerId'])) { $itemId = $trklib->get_item_id($utid['usersTrackerId'], $utid['usersFieldId'], $user); $trackerId = $utid['usersTrackerId']; $usertracker = true; } } elseif (!empty($trackerId) && !empty($view) && $view == 'user') { // the user item of a tracker $itemId = $trklib->get_user_item($trackerId, $tracker, null, null, strlen($status) == 1 ? $status : ''); $usertracker = true; } elseif (!empty($trackerId) && !empty($view) && $view == 'page' && !empty($_REQUEST['page']) && ($f = $trklib->get_page_field($trackerId))) { // the page item $itemId = $trklib->get_item_id($trackerId, $f['fieldId'], $_REQUEST['page']); } elseif (!empty($trackerId) && !empty($_REQUEST['view_user'])) { $itemId = $trklib->get_user_item($trackerId, $tracker, $_REQUEST['view_user']); } elseif (!empty($_REQUEST['itemId']) && (empty($ignoreRequestItemId) || $ignoreRequestItemId != 'y')) { $itemId = $_REQUEST['itemId']; $item = $trklib->get_tracker_item($itemId); $trackerId = $item['trackerId']; } elseif (!empty($view) && $view == 'group') { $gtid = $userlib->get_grouptrackerid($group); if (isset($gtid['groupTrackerId'])) { $trackerId = $gtid['groupTrackerId']; $itemId = $trklib->get_item_id($trackerId, $gtid['groupFieldId'], $group); $grouptracker = true; } } if (!isset($trackerId)) { return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } //test for validation errors for registration tracker calls if (isset($_REQUEST['register']) && ($_REQUEST['register'] == 'Register' || $_REQUEST['register'] == 'register')) { $regtracker = $userlib->get_usertrackerid('Registered'); if ($trackerId == $regtracker['usersTrackerId'] && $_REQUEST['valerror'] !== false) { if (is_array($_REQUEST['valerror'])) { foreach ($_REQUEST['valerror'] as $valerror) { if (is_a($valerror, 'RegistrationError')) { return false; break; } } } elseif (is_a($_REQUEST['valerror'], 'RegistrationError')) { return false; } } } if (!isset($action)) { $action = array('Save'); } if (!is_array($action)) { $action = array($action); } $dynamicSave = false; if (count($action) == 1 && reset($action) == 'NONE') { $action = array(); $dynamicSave = true; } if (!isset($action_style)) { $action_style = array(); foreach ($action as $ac) { $action_style[] = 'btn btn-primary'; } } if (isset($preview)) { if (empty($preview)) { $preview = 'Preview'; } } else { unset($_REQUEST['tr_preview']); } if (isset($reset)) { if (empty($reset)) { $reset = 'reset'; } } else { unset($_REQUEST['tr_reset']); } $smarty->assign('showmandatory', empty($wiki) && empty($tpl) ? 'n' : $showmandatory); if (!empty($wiki)) { if (preg_match('/^wiki:(.+)$/', $wiki, $wiki_matches)) { $wiki = $wiki_matches[1]; } $wiki = trim($wiki); } if (!isset($params['formtag'])) { $params['formtag'] = 'y'; } $fields_prefix = 'ins_'; if (isset($values)) { if (!is_array($values)) { $values = $parserlib->quotesplit(':', $values); foreach ($values as $i => $v) { $values[$i] = preg_replace('/^"(.*)"$/', '$1', $v); } } } if (isset($_REQUEST['values'])) { if (is_array($_REQUEST['values'])) { foreach ($_REQUEST['values'] as $i => $k) { $_REQUEST['values'][$i] = urldecode($k); } } else { $_REQUEST['values'] = urldecode($_REQUEST['values']); } } $perms = $tikilib->get_perm_object($trackerId, 'tracker', $tracker, false); if (empty($_SERVER['SCRIPT_NAME']) || strpos($_SERVER['SCRIPT_NAME'], 'tiki-register.php') === false) { if ($perms['tiki_p_create_tracker_items'] == 'n' && empty($itemId)) { return '<b>' . tra("You do not have permission to insert an item") . '</b>'; } elseif (!empty($itemId)) { $item_info = $trklib->get_tracker_item($itemId); if (empty($item_info)) { return '<b>' . tra("Incorrect item") . '</b>'; } $itemObject = Tracker_Item::fromInfo($item_info); if (!$itemObject->canModify()) { return '<b>' . tra("You do not have permission to modify an item") . '</b>'; } } } if (!empty($itemId)) { $logslib = TikiLib::lib('logs'); $logslib->add_action('Viewed', $itemId, 'trackeritem', $_SERVER['REQUEST_URI']); } if (isset($_REQUEST['removeattach']) && $tracker['useAttachments'] == 'y') { $owner = $trklib->get_item_attachment_owner($_REQUEST['removeattach']); if ($perms['tiki_p_admin_trackers'] == 'y' || $user && $user == $owner) { $trklib->remove_item_attachment($_REQUEST["removeattach"]); unset($_REQUEST['removeattach']); } } if (isset($_REQUEST['removeImage']) && !empty($_REQUEST['trackerId']) && !empty($_REQUEST['itemId']) && !empty($_REQUEST['fieldId']) && !empty($_REQUEST['fieldName'])) { $img_field = array('data' => array()); $img_field['data'][] = array('fieldId' => $_REQUEST['fieldId'], 'type' => 'i', 'name' => $_REQUEST['fieldName'], 'value' => 'blank'); $trklib->replace_item($_REQUEST['trackerId'], $_REQUEST['itemId'], $img_field); } $back = ''; $thisIsThePlugin = isset($_REQUEST['iTRACKER']) && $_REQUEST['iTRACKER'] == $iTRACKER; if (!isset($_REQUEST["ok"]) || $_REQUEST["ok"] == "n" || !$thisIsThePlugin || isset($_REQUEST['tr_preview'])) { $field_errors = array('err_mandatory' => array(), 'err_value' => array()); $notificationlib = TikiLib::lib('notification'); $tracker = $trklib->get_tracker($trackerId); $tracker = array_merge($tracker, $trklib->get_tracker_options($trackerId)); if (!empty($tracker['start']) && $tikilib->now < $tracker['start'] || !empty($tracker['end']) && $tikilib->now > $tracker['end']) { return; } $outf = array(); $auto_fieldId = array(); $hidden_fieldId = array(); if (!empty($fields) || !empty($wiki) || !empty($tpl)) { if ($registration == 'y' && $prefs["user_register_prettytracker"] == 'y' && !empty($prefs["user_register_prettytracker_tpl"])) { $registrationlib = TikiLib::lib('registration'); $smarty->assign('listgroups', $registrationlib->merged_prefs['choosable_groups']); $smarty->assign('register_login', $smarty->fetch('register-login.tpl')); $smarty->assign('register_email', $smarty->fetch('register-email.tpl')); $smarty->assign('register_pass', $smarty->fetch('register-pass.tpl')); $smarty->assign('register_pass2', $smarty->fetch('register-pass2.tpl')); $smarty->assign('register_passcode', $smarty->fetch('register-passcode.tpl')); $smarty->assign('register_groupchoice', $smarty->fetch('register-groupchoice.tpl')); if ($prefs['feature_antibot'] == 'y') { $smarty->assign('showantibot', true); $smarty->assign('form', 'register'); $smarty->assign('register_antibot', $smarty->fetch('antibot.tpl')); } $wiki = $prefs["user_register_prettytracker_tpl"]; } if (!empty($wiki)) { $outf = $trklib->get_pretty_fieldIds($wiki, 'wiki', $prettyModifier, $trackerId); } elseif (!empty($tpl)) { $outf = $trklib->get_pretty_fieldIds($tpl, 'tpl', $prettyModifier, $trackerId); } elseif (!empty($fields)) { $outf = $fields; } if (!empty($_REQUEST['autosavefields'])) { $autosavefields = explode(':', $_REQUEST['autosavefields']); $autosavevalues = explode(':', $_REQUEST['autosavevalues']); if (isset($params['autosavefields'])) { $autosavefields = array_merge($autosavefields, $params['autosavefields']); $autosavevalues = array_merge($autosavevalues, $params['autosavevalues']); } } if (!empty($autosavefields)) { $auto_fieldId = array_merge($auto_fieldId, $autosavefields); } foreach ($definition->getFields() as $field) { // User and group on autoassign create/modify if (($user || $registration == 'y' || isset($_SESSION[$transactionName]) && isset($_SESSION[$transactionName]['registrationName'])) && ($field['type'] == 'u' || $field['type'] == 'g')) { $autoassign = $field['options_map']['autoassign']; if ($autoassign == 1 || $autoassign == 2) { if ($user) { $hidden_fieldId[] = $field['fieldId']; } $userField = $field['fieldId']; } } // IP and page on autoassign if ($field['type'] == 'I' || $field['type'] == 'k') { $autoassign = $field['options_map']['autoassign']; if ($autoassign == 1) { $hidden_fieldId[] = $field['fieldId']; } } // Auto-increment if ($field['type'] == 'q') { $auto_fieldId[] = $field['fieldId']; } } foreach ($auto_fieldId as $k => $v) { if (empty($v) || in_array($v, $outf)) { unset($auto_fieldId[$k]); } else { $outf[] = $v; } } foreach ($hidden_fieldId as $k => $v) { if (empty($v) || in_array($v, $outf)) { unset($hidden_fieldId[$k]); } else { $outf[] = $v; } } } $definition = Tracker_Definition::get($trackerId); $item_info = isset($item_info) ? $item_info : array(); $factory = $definition->getFieldFactory(); if (empty($item_info)) { $itemObject = Tracker_Item::newItem($trackerId); } elseif (!isset($itemObject)) { $itemObject = Tracker_Item::fromInfo($item_info); } if (empty($outf)) { $unfiltered = array('data' => $definition->getFields()); } else { $unfiltered = array('data' => array()); foreach ($outf as $fieldId) { $unfiltered['data'][] = $definition->getField($fieldId); } } $flds = array('data' => array()); foreach ($unfiltered['data'] as $f) { if ($itemObject->canModifyField($f['fieldId']) || $registration == 'y' && empty($item_info)) { $flds['data'][] = $f; } } // If we create multiple items, get field Ids, default values and separator if (!empty($fieldsfill)) { $fill_fields = $fieldsfill; // Allow for superfluous spaces and ignore them $fill_flds = array('data' => array()); $fill_defaults = array(); $fill_flds_defaults = array(); // May be different from fill_defaults if some fields are not editable $fieldsfillnames = array(); if (trim($fieldsfilldefaults) != '') { $fill_defaults = preg_split('/ *: */', $fieldsfilldefaults); } foreach ($fill_fields as $k => $fieldId) { if ($itemObject->canModifyField($fieldId)) { $tmp = $definition->getField($fieldId); $fill_flds['data'][] = $tmp; if (isset($fill_defaults[$k])) { $fill_flds_defaults[] = $fill_defaults[$k]; } else { $fill_flds_defaults[] = ''; } $fieldsfillnames[] = $tmp['name']; } } $fill_line_cant = count($fill_flds['data']); if ($fieldsfillseparator == '') { $fieldsfillseparator = '|'; } } $bad = array(); $embeddedId = false; $onemandatory = false; $full_fields = array(); $mainfield = ''; if ($thisIsThePlugin) { /* ------------------------------------- Recup all values from REQUEST -------------- */ if (!empty($autosavefields)) { foreach ($autosavefields as $i => $f) { if (!($ff = $trklib->get_field($f, $flds['data']))) { continue; } if (preg_match('/categories\\(([0-9]+)\\)/', $autosavevalues[$i], $matches)) { if (ctype_digit($matches[1]) && $matches[1] > 0) { $filter = array('identifier' => $matches[1], 'type' => 'descendants'); } else { $filter = NULL; } $categlib = TikiLib::lib('categ'); $categs = $categlib->getCategories($filter, true, false); $_REQUEST["{$fields_prefix}{$f}"][] = $categs[0]['categId']; } elseif (preg_match('/preference\\((.*)\\)/', $autosavevalues[$i], $matches)) { $_REQUEST["{$fields_prefix}{$f}"] = $prefs[$matches[1]]; } elseif (isset($transactionName) && preg_match('/#TSTEP\\[(\\d+)\\]\\[(\\d+|name|pass)\\]/', $autosavevalues[$i], $matches)) { $traStep = $matches[1]; $traStepInsField = $matches[2]; if (preg_match('/\\d+/', $matches[2])) { $traStepInsField = "{$fields_prefix}{$traStepInsField}"; } $_REQUEST["{$fields_prefix}{$f}"] = str_replace($matches[0], $_SESSION[$transactionName][$traStep]['request'][$traStepInsField], $autosavevalues[$i]); } elseif ($ff['type'] == 'e') { $_REQUEST["{$fields_prefix}{$f}"][] = $autosavevalues[$i]; } else { if (isset($params['levelupfields']) && in_array($f, $params['levelupfields'])) { $current_levelup_val = $trklib->get_item_value($trackerId, $itemId, $f); if ($autosavevalues[$i] <= $current_levelup_val) { continue; } } $_REQUEST["{$fields_prefix}{$f}"] = $autosavevalues[$i]; } } } if ($registration == 'y' && isset($userField) && isset($_REQUEST['name'])) { $_REQUEST["{$fields_prefix}{$userField}"] = $_REQUEST['name']; } foreach ($flds['data'] as $k => $field) { $handler = $factory->getHandler($field, $item_info); if ($handler) { $value_field = $handler->getFieldData($_REQUEST); $ins_fields['data'][$k] = array_merge($field, $value_field); if (isset($ins_fields['data'][$k]['value'])) { // add ins value into field if creating or editing item $flds['data'][$k] = $ins_fields['data'][$k]; // to keep user input in case of errors (not only value) } } } $cpt = 0; if (isset($fields)) { $fields_plugin = $fields; } if (!isset($itemId) && $tracker['oneUserItem'] == 'y' && $registration != 'y') { $itemId = $trklib->get_user_item($trackerId, $tracker); } if ($embedded == 'y' && isset($_REQUEST['page'])) { $ins_fields["data"][] = array('fieldId' => $embeddedId, 'value' => $_REQUEST['page']); } if (isset($userField) && ($registration == 'y' && isset($_REQUEST['name']) || isset($_SESSION[$transactionName]) && isset($_SESSION[$transactionName]['registrationName']))) { $userFieldDef = $definition->getField($userField); if (isset($_REQUEST['name'])) { $userFieldDef['value'] = $_REQUEST['name']; if (isset($_SESSION[$transactionName])) { $_SESSION[$transactionName]['registrationName'] = $_REQUEST['name']; } } elseif (isset($_SESSION[$transactionName]) && isset($_SESSION[$transactionName]['registrationName'])) { $userFieldDef['value'] = $_SESSION[$transactionName]['registrationName']; } $ins_fields['data'][] = $userFieldDef; } $ins_categs = 0; // important: non-array ins_categs means categories should remain unchanged $parent_categs_only = array(); foreach ($ins_fields['data'] as $current_field) { if ($current_field['type'] == 'e' && isset($current_field['selected_categories'])) { if (!is_array($ins_categs)) { $ins_categs = array(); } $ins_categs = array_merge($ins_categs, $current_field['selected_categories']); $parent_categs_only[] = $current_field['options_array'][0]; } } $categorized_fields = $definition->getCategorizedFields(); /* ------------------------------------- End recup all values from REQUEST -------------- */ /* ------------------------------------- Check field values for each type and presence of mandatory ones ------------------- */ $field_errors = $trklib->check_field_values($ins_fields, $categorized_fields, $trackerId, empty($itemId) ? '' : $itemId); if ($prefs['feature_antibot'] === 'y' && $registration === 'y' && isset($_REQUEST['valerror'])) { // in_tracker session var checking is for tiki-register.php if (isset($_REQUEST['valerror'])) { $rve = $_REQUEST['valerror']; if (is_array($rve)) { foreach ($rve as $ve) { if (is_a($ve, 'RegistrationError')) { if (isset($ve->field) && $ve->field == 'antibotcode') { $field_errors['err_antibot'] = 'y'; continue; } } } } elseif (is_a($rve, 'RegistrationError')) { if (isset($rve->field) && $rve->field == 'antibotcode') { $field_errors['err_antibot'] = 'y'; } } } else { if (!$captchalib->validate()) { $field_errors['err_antibot'] = 'y'; } } } // check valid page name for wiki output if requested if (isset($outputtowiki) && !empty($outputwiki)) { $newpagename = ''; foreach ($ins_fields["data"] as $fl) { if ($fl["fieldId"] == $outputtowiki) { $newpagename = $fl["value"]; } if ($fl["type"] == 'F') { $newpagefreetags = $fl["value"]; } $newpagefields[] = $fl["fieldId"]; } if ($newpagename) { if ($prefs['namespace_enabled'] == 'y' && !empty($outputwikinamespace)) { $newpagename = $outputwikinamespace . $prefs['namespace_separator'] . $newpagename; } if ($tikilib->page_exists($newpagename)) { $field_errors['err_outputwiki'] = tra('The page to output the results to already exists. Try another name.'); } $page_badchars_display = TikiLib::lib('wiki')->get_badchars(); if (TikiLib::lib('wiki')->contains_badchars($newName)) { $field_errors['err_outputwiki'] = tr("The page to output the results to contains the following prohibited characters: %0. Try another name.", $page_badchars_display); } } else { unset($outputtowiki); } } if (count($field_errors['err_mandatory']) == 0 && count($field_errors['err_value']) == 0 && empty($field_errors['err_antibot']) && empty($field_errors['err_outputwiki']) && !isset($_REQUEST['tr_preview'])) { if (isset($_REQUEST['status'])) { $status = $_REQUEST['status']; } elseif (isset($newstatus) && ($newstatus == 'o' || $newstatus == 'c' || $newstatus == 'p')) { $status = $newstatus; } elseif (empty($itemId) && isset($tracker['newItemStatus'])) { $status = $tracker['newItemStatus']; } else { $status = ''; } $saveThis = array('trackerId' => $trackerId, 'request' => $_REQUEST, 'chosenGroup' => $chosenGroup, 'registration' => $registration, 'registrationTrackerId' => $registrationTrackerId, 'validateusers' => $validateusers, 'status' => $status, 'ins_fields' => $ins_fields, 'itemId' => $itemId, 'ins_categs' => $ins_categs, 'newItemRate' => $newItemRate); //-- check if we are in a transaction if (isset($transactionName)) { $_SESSION[$transactionName][$transactionStep] = $saveThis; if ($transactionFinalStep == 'y') { //-- final step: commit the transaction of registrations and tracker changes of all the transaction steps foreach ($_SESSION[$transactionName] as $saveStep) { $rid = wikiplugin_tracker_save($saveStep); } unset($_SESSION[$transactionName]); // the tracker transaction can be closed } else { $_SESSION[$transactionName]['transactionStep'] += 1; // switch to the next step } } else { // no transaction is used $rid = wikiplugin_tracker_save($saveThis); } // now for wiki output if desired if (isset($outputtowiki) && !empty($outputwiki)) { // note that values will be raw - that is the limit of the capability of this feature for now $newpageinfo = $tikilib->get_page_info($outputwiki); $wikioutput = $newpageinfo["data"]; $newpagefields = $trklib->get_pretty_fieldIds($outputwiki, 'wiki', $prettyModifier, $trackerId); $tracker_definition = Tracker_Definition::get($trackerId); foreach ($newpagefields as $lf) { $field = $tracker_definition->getField($lf); $lfpermname = $field['permName']; $wikioutput = str_replace('{$f_' . $lf . '}', $trklib->get_item_value($trackerId, $rid, $lf), $wikioutput); $wikioutput = str_replace('{$f_' . $lfpermname . '}', $trklib->get_item_value($trackerId, $rid, $lf), $wikioutput); } if (isset($registration)) { $wikioutput = str_replace('{$register_login}', $user, $wikioutput); $wikioutput = str_replace('{$register_email}', $_REQUEST['email'], $wikioutput); } $tikilib->create_page($newpagename, 0, $wikioutput, $tikilib->now, '', $user, $tikilib->get_ip_address()); $cat_desc = ''; $cat_type = 'wiki page'; $cat_name = $newpagename; $cat_objid = $newpagename; $cat_href = "tiki-index.php?page=" . urlencode($newpagename); if (count($ins_categs)) { $_REQUEST['cat_categories'] = $ins_categs; $_REQUEST['cat_categorize'] = 'on'; include_once "categorize.php"; } if (isset($newpagefreetags) && $newpagefreetags) { $_REQUEST['freetag_string'] = $newpagefreetags; include_once "freetag_apply.php"; } if ($discarditem == 'y') { $trklib->remove_tracker_item($rid); } elseif ($outputwikirelation == 'y') { TikiLib::lib('relation')->add_relation('tiki.wiki.linkeditem', 'wiki page', $newpagename, 'trackeritem', $rid); TikiLib::lib('relation')->add_relation('tiki.wiki.linkedfield', 'wiki page', $newpagename, 'trackerfield', $outputtowiki); } if (empty($url)) { $wikilib = TikiLib::lib('wiki'); $url[0] = $wikilib->sefurl($newpagename); } } // end wiki output // send emails if email param is set and tracker_always_notify or something was changed (mail_data is set in \TrackerLib::send_replace_item_notifications) if (!empty($email) && ($prefs['tracker_always_notify'] === 'y' || !empty($smarty->getTemplateVars('mail_data')))) { // expose the pretty tracker fields to the email tpls foreach ($flds['data'] as $f) { $prettyout = strip_tags(wikiplugin_tracker_render_value($f, $item)); $smarty->assign('f_' . $f['fieldId'], $prettyout); $smarty->assign('f_' . $f['permName'], $prettyout); } $emailOptions = preg_split("#\\|#", $email); if (is_numeric($emailOptions[0])) { $emailOptions[0] = $trklib->get_item_value($trackerId, $rid, $emailOptions[0]); } if (empty($emailOptions[0])) { // from $emailOptions[0] = $prefs['sender_email']; } if (empty($emailOptions[1])) { // to $emailOptions[1][0] = $prefs['sender_email']; } else { $emailOptions[1] = preg_split('/ *, */', $emailOptions[1]); foreach ($emailOptions[1] as $key => $email) { if (is_numeric($email)) { $emailOptions[1][$key] = $trklib->get_item_value($trackerId, $rid, $email); } } } include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $mail->setFrom($emailOptions[0]); if (!empty($emailOptions[2])) { //tpl $emailOptions[2] = preg_split('/ *, */', $emailOptions[2]); foreach ($emailOptions[2] as $ieo => $eo) { if (!preg_match('/\\.tpl$/', $eo)) { $emailOptions[2][$ieo] = $eo . '.tpl'; } $tplSubject[$ieo] = str_replace('.tpl', '_subject.tpl', $emailOptions[2][$ieo]); } } else { $emailOptions[2] = array('tracker_changed_notification.tpl'); } if (empty($tplSubject)) { $tplSubject = array('tracker_changed_notification_subject.tpl'); } $itpl = 0; $smarty->assign('mail_date', $tikilib->now); $smarty->assign('mail_itemId', $rid); foreach ($emailOptions[1] as $ieo => $ueo) { @($mail_data = $smarty->fetch('mail/' . $tplSubject[$itpl])); if (empty($mail_data)) { $mail_data = tra('Tracker was modified at ') . $_SERVER["SERVER_NAME"]; } $mail->setSubject($mail_data); $mail_data = $smarty->fetch('mail/' . $emailOptions[2][$itpl]); if ($emailformat == 'html') { $mail->setHtml($mail_data); } else { $mail->setText($mail_data); } try { $mail->send($ueo); $title = 'mail'; } catch (Zend_Mail_Exception $e) { $title = 'mail error'; } if ($title == 'mail error') { // Log the email error at the tiki syslog $logslib = TikiLib::lib('logs'); $logslib->add_log('mail error', 'plugin tracker email error / ' . $emailOptions[1][$ieo] . ' / item' . $rid); } elseif ($title == 'mail' && $prefs['log_mail'] == 'y') { // Log the email at the tiki syslog $logslib = TikiLib::lib('logs'); $logslib->add_log('mail', 'plugin tracker email sent / ' . $emailOptions[1][$ieo] . ' / item' . $rid); } if (isset($tplSubject[$itpl + 1])) { ++$itpl; } } } if (empty($url)) { if (!empty($_REQUEST['ajax_add'])) { // called by tracker ItemLink fields when adding new list items while (ob_get_level()) { ob_end_clean(); } if ($prefs['feature_obzip'] == 'y') { ob_start('ob_gzhandler'); } else { ob_start(); } // Need to add newly created itemId for item link selector $ins_fields['itemId'] = $rid; $access = TikiLib::lib('access'); $access->output_serialized($ins_fields); ob_end_flush(); die; } else { if (!empty($page)) { $url = "tiki-index.php?page=" . urlencode($page); if (!empty($itemId)) { $url .= "&itemId=" . $itemId; } $url .= "&ok=y&iTRACKER={$iTRACKER}"; $url .= "#wikiplugin_tracker{$iTRACKER}"; TikiLib::lib('access')->redirect($url); exit; } else { return ''; } } } else { $key = 0; foreach ($action as $key => $act) { if (!empty($_REQUEST["action{$key}"])) { break; } } $itemIdPos = strpos($url[$key], 'itemId'); if ($itemIdPos !== false) { if (strstr($url[$key], '#itemId')) { $url[$key] = str_replace('#itemId', $rid, $url[$key]); } else { if ($itemIdPos + strlen('itemId') >= strlen($url[$key]) - 1 || substr($url[$key], $itemIdPos + strlen('itemId'), 1) == "&") { // replace by the itemId if in the end (or -1: for backward compatibility so that "&itemId=" also works) or if it is followed by an '&' $url[$key] = str_replace('itemId', 'itemId=' . $rid, $url[$key]); } } } TikiLib::lib('access')->redirect($url[$key]); exit; } } elseif (isset($_REQUEST['trackit']) and $_REQUEST['trackit'] == $trackerId) { $smarty->assign('wikiplugin_tracker', $trackerId); //used in vote plugin } } else { if ((empty($itemId) || $overwrite == 'y') && !empty($values) || (!empty($_REQUEST['values']) and empty($_REQUEST['prefills']))) { // assign default values for each filedId specify if (empty($values)) { // url with values[]=x&values[] witouth the list of fields $values = $_REQUEST['values']; } if (!is_array($values)) { $values = array($values); } if (isset($fields)) { $fl = $fields; for ($j = 0, $count_fl = count($fl); $j < $count_fl; $j++) { for ($i = 0, $count_flds = count($flds['data']); $i < $count_flds; $i++) { if ($flds['data'][$i]['fieldId'] == $fl[$j]) { $flds['data'][$i]['value'] = $values[$j]; } } } } else { // values contains all the fields value in the default order $i = 0; foreach ($values as $value) { $flds['data'][$i++]['value'] = $value; } } } elseif (!empty($itemId)) { if (isset($fields)) { $fl = $fields; $filter = ''; foreach ($flds['data'] as $f) { if (in_array($f['fieldId'], $fl)) { $filter[] = $f; } } } else { $filter =& $flds['data']; } if (!empty($filter)) { foreach ($filter as $f) { $filter2[$f['fieldId']] = $f; } $flds['data'] = $trklib->get_item_fields($trackerId, $itemId, $filter2, $itemUser, true); } // todo: apply the values for fields with no values } else { if (isset($_REQUEST['values']) && isset($_REQUEST['prefills'])) { //url:prefills=1:2&values[]=x&values[]=y if (!is_array($_REQUEST['values'])) { $_REQUEST['values'] = array($_REQUEST['values']); } $fl = preg_split('/:/', $_REQUEST['prefills']); } else { unset($fl); } for ($i = 0, $count_flds2 = count($flds['data']); $i < $count_flds2; $i++) { if (isset($fl) && ($j = array_search($flds['data'][$i]['fieldId'], $fl)) !== false) { $flds['data'][$i]['value'] = $_REQUEST['values'][$j]; } else { // setting default value prevent dropdown default value working $options = $flds['data'][$i]['options_array']; if (!in_array($flds['data'][$i]['type'], array('d', 'D', 'R', 'M')) || count($options) === count(array_unique($options))) { $flds['data'][$i]['value'] = ''; // initialize fields with blank values } } } } } // Check that individual fields are in the tracker if (!empty($fields)) { $fl = $fields; if ($sort == 'y') { $flds = $trklib->sort_fields($flds, $fl); } foreach ($fl as $l) { $ok = false; foreach ($flds['data'] as $f) { if ($f['fieldId'] == $l) { $ok = true; break; } } if (!$ok) { $back .= '<div class="alert alert-warning"><strong>' . tra('Incorrect fieldId:') . ' ' . $l . '</strong>.<br> ' . tra("Please ensure you are using the correct field ID and that it is properly included in the template, if any.") . '</div>'; } } } elseif (empty($fields) && empty($wiki) && empty($tpl)) { // in this case outf still be blank and needs to be filled foreach ($flds['data'] as $f) { $outf[] = $f['fieldId']; } } // Check that multiple fill fields are in the tracker if (!empty($fieldsfill)) { foreach ($fill_fields as $l) { $ok = false; foreach ($fill_flds['data'] as $f) { if ($f['fieldId'] == $l) { $ok = true; break; } } if (!$ok) { $back .= '<div class="alert alert-warning">' . tra('Incorrect fieldId:') . ' ' . $l . '</div>'; } } } // Display warnings when needed if (count($field_errors['err_mandatory']) > 0 || count($field_errors['err_value']) > 0) { $back .= $smarty->fetch('tracker_error.tpl'); $_REQUEST['error'] = 'y'; if (count($field_errors['err_mandatory']) > 0) { $msg = tra('Following mandatory fields are missing'); foreach ($field_errors['err_mandatory'] as $err) { $msg .= '<br> ' . $err['name']; } TikiLib::lib('errorreport')->report($msg); } if (count($field_errors['err_value']) > 0) { $msg = tra('Following fields are incorrect'); foreach ($field_errors['err_value'] as $err) { $msg .= '<br> ' . $err['name']; } TikiLib::lib('errorreport')->report($msg); } if ($registration && !empty($userField) && isset($_REQUEST['name']) && $_REQUEST['name'] === $userField['value'] && $_REQUEST['name'] === $user) { // if in registration and creating a user tracker item for the new user // remove the user if they did not complete the tracker correctly $userlib->remove_user($userField['value']); if ($prefs['eponymousGroups'] == 'y') { // eponymous group will contain only this (former) user so remove that too $userlib->remove_group($userField['value']); } $user = ''; // needed to re-include the captcha inputs $hidden_fieldId = array(); // remove hidden user fields which are otherwise required foreach ($flds['data'] as $k => $v) { // remove the login field otherwise it gets rendered in the form also required if ($v['fieldId'] == $userField['fieldId']) { unset($flds['data'][$k]); } } } if (isset($field_errors['err_antibot'])) { $_REQUEST['error'] = 'y'; } if (isset($field_errors['err_outputwiki'])) { $smarty->loadPlugin('smarty_function_icon'); $icon = smarty_function_icon(['name' => 'warning'], $smarty); $back .= '<div class="alert alert-warning">' . $icon . ' '; $back .= $field_errors['err_outputwiki']; $back .= '</div><br />'; $_REQUEST['error'] = 'y'; } if (count($field_errors['err_mandatory']) > 0 || count($field_errors['err_value']) > 0 || isset($field_errors['err_antibot']) || isset($field_errors['err_outputwiki'])) { $smarty->assign('input_err', 'y'); } } if (!empty($page)) { $back .= '~np~'; $smarty->assign_by_ref('tiki_p_admin_trackers', $perms['tiki_p_admin_trackers']); } if (!empty($params['_ajax_form_ins_id'])) { $headerlib = TikiLib::lib('header'); $old_js['js'] = $headerlib->js; // of tracker form JS into a function to initialise it when the dialog is created $old_js['jq_onready'] = $headerlib->jq_onready; $headerlib->clear_js(); // so store existing js for later and clear } if ($prefs['feature_jquery'] == 'y' && $prefs['feature_jquery_validation'] == 'y') { $validatorslib = TikiLib::lib('validators'); $customvalidation = ''; $customvalidation_m = ''; if ($registration == 'y') { // email validation $customvalidation .= 'email: { '; $customvalidation .= 'required: true, '; $customvalidation .= 'email: true }, '; $customvalidation_m .= 'email: { email: "' . tra("Invalid email") . '", required: "' . tra("This field is required") . '"}, '; // password validation $customvalidation .= 'pass: { '; $customvalidation .= 'required: true, '; $customvalidation .= 'remote: { '; $customvalidation .= 'url: "validate-ajax.php", '; $customvalidation .= 'type: "post", '; $customvalidation .= 'data: { '; $customvalidation .= 'validator: "password", '; $customvalidation .= 'input: function() { '; $customvalidation .= 'return $("#pass1").val(); '; $customvalidation .= '} } } '; $customvalidation .= '}, '; $customvalidation_m .= 'pass: { required: "' . tra("This field is required") . '"}, '; // password repeat validation $customvalidation .= 'passAgain: { equalTo: "#pass1" }, '; $customvalidation_m .= 'passAgain: { equalTo: "' . tra("Passwords do not match") . '"}, '; // username validation $customvalidation .= 'name: { '; $customvalidation .= 'required: true, '; $customvalidation .= 'remote: { '; $customvalidation .= 'url: "validate-ajax.php", '; $customvalidation .= 'type: "post", '; $customvalidation .= 'data: { '; $customvalidation .= 'validator: "username", '; $customvalidation .= 'input: function() { '; $customvalidation .= 'return $("#name").val(); '; $customvalidation .= '} } } '; $customvalidation .= '}, '; $customvalidation_m .= 'name: { required: "' . tra("This field is required") . '"}, '; if (extension_loaded('gd') && function_exists('imagepng') && function_exists('imageftbbox') && $prefs['feature_antibot'] == 'y' && empty($user) && $prefs['recaptcha_enabled'] != 'y') { // antibot validation $customvalidation .= '"captcha[input]": { '; $customvalidation .= 'required: true, '; $customvalidation .= 'remote: { '; $customvalidation .= 'url: "validate-ajax.php", '; $customvalidation .= 'type: "post", '; $customvalidation .= 'data: { '; $customvalidation .= 'validator: "captcha", '; $customvalidation .= 'parameter: function() { '; $customvalidation .= 'return $("#captchaId").val(); '; $customvalidation .= '}, '; $customvalidation .= 'input: function() { '; $customvalidation .= 'return $("#antibotcode").val(); '; $customvalidation .= '} } } '; $customvalidation .= '}, '; $customvalidation_m .= '"captcha[input]": { required: "' . tra("This field is required") . '"}, '; } if ($prefs['useRegisterPasscode'] == 'y') { $customvalidation .= 'passcode: { required: true, remote: { url: "validate-ajax.php", type: "post", data: { validator: "passcode", input: function() { return $("#passcode").val(); } } } }, '; $customvalidation_m .= 'passcode: { required: "' . tra("This field is required") . '"}, '; } } $validationjs = $validatorslib->generateTrackerValidateJS($flds['data'], $fields_prefix, $customvalidation, $customvalidation_m); if (!empty($params['_ajax_form_ins_id']) && $params['_ajax_form_ins_id'] === 'group') { $headerlib->add_jq_onready("var ajaxTrackerValidation_group={validation:{" . $validationjs . '};'); // return clean rules and messages object for ajax } else { $smarty->assign('validationjs', $validationjs); $back .= $smarty->fetch('tracker_validator.tpl'); } } if ($params['formtag'] == 'y') { //check if tracker has custom form classes, else default to form-horizontal $formClasses = $tracker['useFormClasses'] == 'y' ? $tracker['formClasses'] : "form-horizontal"; $back .= '<form class="' . $formClasses . '" name="editItemForm' . $iTRACKER . '" id="editItemForm' . $iTRACKER . '" enctype="multipart/form-data" method="post"' . (isset($target) ? ' target="' . $target . '"' : '') . ' action="' . $_SERVER['REQUEST_URI'] . '"><input type="hidden" name="trackit" value="' . $trackerId . '" />'; $back .= '<input type="hidden" name="refresh" value="1" />'; } $back .= '<input type="hidden" name="iTRACKER" value="' . $iTRACKER . '" />'; if (isset($_REQUEST['page'])) { $back .= '<input type="hidden" name="page" value="' . $_REQUEST["page"] . '" />'; } // for registration if (isset($_REQUEST['name'])) { $back .= '<input type="hidden" name="name" value="' . $_REQUEST["name"] . '" />'; } if (isset($_REQUEST['pass'])) { $back .= '<input type="hidden" name="pass" value="' . $_REQUEST["pass"] . '" />'; $back .= '<input type="hidden" name="passAgain" value="' . $_REQUEST["pass"] . '" />'; } if (isset($_REQUEST['email'])) { $back .= '<input type="hidden" name="email" value="' . $_REQUEST["email"] . '" />'; } if (isset($_REQUEST['antibotcode'])) { $back .= '<input type="hidden" name="antibotcode" value="' . $_REQUEST["antibotcode"] . '" />'; } if (isset($_REQUEST['chosenGroup'])) { // for registration $back .= '<input type="hidden" name="chosenGroup" value="' . $_REQUEST["chosenGroup"] . '" />'; } if (isset($_REQUEST['register'])) { $back .= '<input type="hidden" name="register" value="' . $_REQUEST["register"] . '" />'; } if ($showtitle == 'y') { $back .= '<div class="h1">' . $tracker["name"] . '</div>'; } if ($showdesc == 'y' && $tracker['description']) { if ($tracker['descriptionIsParsed'] == 'y') { $back .= '<div class="wikitext">' . $tikilib->parse_data($tracker['description']) . '</div><br />'; } else { $back .= '<div class="wikitext">' . tra($tracker["description"]) . '</div><br />'; } } if (isset($_REQUEST['tr_preview'])) { // use for the computed and join fields $assocValues = array(); $assocNumerics = array(); foreach ($flds['data'] as $f) { if (empty($f['value']) && ($f['type'] == 'u' || $f['type'] == 'g' || $f['type'] == 'I') && ($f['options_array'][0] == '1' || $f['options_array'][0] == '2')) { //need to fill the selector fields for the join $f['value'] = $f['type'] == 'I' ? $tikilib->get_ip_address() : ($f['type'] == 'g' ? $group : $user); } $assocValues[$f['fieldId']] = $f['value']; $assocNumerics[$f['fieldId']] = preg_replace('/[^0-9\\.\\+]/', '', $f['value']); // get rid off the $ and such unit } } if (!empty($itemId)) { $item = array('itemId' => $itemId, 'trackerId' => $trackerId); } else { $item = array('itemId' => ''); } foreach ($flds['data'] as $i => $f) { // collect additional infos if (in_array($f['fieldId'], $outf)) { $flds['data'][$i]['ins_id'] = $f['type'] == 'e' ? 'ins_' . $f['fieldId'] : $fields_prefix . $f['fieldId']; if (($f['isHidden'] == 'c' || $f['isHidden'] == 'p') && !empty($itemId) && !isset($item['creator'])) { $item['creator'] = $trklib->get_item_creator($trackerId, $itemId); } } } if (!empty($showstatus) && $showstatus == 'y') { $status_types = $trklib->status_types(); $smarty->assign_by_ref('status_types', $status_types); $smarty->assign('form_status', 'status'); $smarty->assign_by_ref('tracker', $tracker); if (!empty($item_info)) { $smarty->assign_by_ref('item', $item_info); } $status_input = $smarty->fetch('tracker_status_input.tpl'); } $labelclass = 'col-md-3'; $inputclass = 'col-md-9'; $buttonclass = 'col-md-9 col-md-offset-3'; if ($registration == "y") { $back .= '<input type="hidden" name="register" value="Register">'; $labelclass = 'col-md-4 col-sm-3'; $inputclass = 'col-md-4 col-sm-6'; $buttonclass = 'col-md-8 col-md-offset-4'; } // Loop on tracker fields and display form if (empty($tpl) && empty($wiki)) { $back .= '<div class="wikiplugin_tracker">'; if (!empty($showstatus) && $showstatus == 'y') { $back .= '<div class="alert alert-info">' . tra('Status') . $status_input . '</div>'; // <tr><td>'.tra('Status').'</td><td>'.$status_input.'</td></tr> } if ($registration == 'y' && $prefs["user_register_prettytracker"] != 'y') { $back .= $smarty->fetch('register-form.tpl'); } } else { $back .= '<div class="wikiplugin_tracker">'; if (!empty($showstatus) && $showstatus == 'y') { $smarty->assign_by_ref('f_status_input', $status_input); } } $backLength0 = strlen($back); foreach ($flds['data'] as $f) { if (!in_array($f['fieldId'], $auto_fieldId) && in_array($f['fieldId'], $hidden_fieldId)) { // Show in hidden form $back .= '<span style="display:none;">' . wikiplugin_tracker_render_input($f, $item, $dynamicSave) . '</span>'; } elseif (!in_array($f['fieldId'], $auto_fieldId) && in_array($f['fieldId'], $outf)) { if ($showmandatory == 'y' and $f['isMandatory'] == 'y') { $onemandatory = true; } if ($f['type'] == 'A') { $smarty->assign_by_ref('tiki_p_attach_trackers', $perms['tiki_p_attach_trackers']); } if (!empty($tpl) || !empty($wiki)) { if ($prettyModifier[$f['fieldId']] == "output") { //check if modifier is set to "output" ( set in getPrettyFieldIds() in trackerlib ) $prettyout = '<span class="outputPretty" id="track_' . $f['fieldId'] . '" name="track_' . $f['fieldId'] . '">' . wikiplugin_tracker_render_value($f, $item) . '</span>'; $smarty->assign('f_' . $f['fieldId'], $prettyout); $smarty->assign('f_' . $f['permName'], $prettyout); } else { $mand = ($showmandatory == 'y' and $f['isMandatory'] == 'y') ? " <strong class='mandatory_star'>*</strong> " : ''; if (!empty($f['description'])) { $desc = $f['descriptionIsParsed'] == 'y' ? $tikilib->parse_data($f['description']) : tra($f['description']); $desc = '<div class="trackerplugindesc">' . $desc . '</div>'; } else { $desc = ''; } if (!empty($prettyModifier[$f['fieldId']])) { // check if a template was specified in prettyModifier $smarty->assign("field_name", $f['name']); $smarty->assign("field_id", $f['fieldId']); $smarty->assign("permname", $f['permName']); $smarty->assign("mandatory_sym", $mand); $smarty->assign("field_input", wikiplugin_tracker_render_input($f, $item, $dynamicSave)); $smarty->assign("description", $desc); $smarty->assign("field_type", $f['type']); $prettyout = $smarty->fetch($prettyModifier[$f['fieldId']]); //fetch template identified in prettyModifier } else { $prettyout = wikiplugin_tracker_render_input($f, $item, $dynamicSave) . $mand . $desc; } $smarty->assign('f_' . $f['fieldId'], $prettyout); $smarty->assign('f_' . $f['permName'], $prettyout); } } else { $back .= '<div class="form-group tracker_input_label"'; // <tr><td class="tracker_input_label" // If type is has a samerow param and samerow is "No", show text on one line and the input field on the next $isTextOnSameRow = true; switch ($f['type']) { case 't': // Text field // Text field case 'n': // Numeric field // Numeric field case 'b': // Currency if (empty($f['options_array']) || isset($f['options_array']['0']) && strlen($f['options_array']['0']) == 0) { // Use default // Pending: Unable to locate the object to check to determine the default (in the tracker field definitions). Hardcode true. Arild $isTextOnSameRow = true; } else { $isTextOnSameRow = intval($f['options_array']['0']) == 0 ? false : true; } break; case 'a': // Text area $isTextOnSameRow = true; if (isset($f['options_array']['8'])) { if (empty($f['options_array']) || isset($f['options_array']['8']) && strlen($f['options_array']['8']) == 0) { // Use default // Pending: Unable to locate the object to check to determine the default (in the tracker field definitions). Hardcode true. Arild $isTextOnSameRow = true; } else { $isTextOnSameRow = intval($f['options_array']['8']) == 0 ? false : true; } } break; } if (!empty($colwidth)) { $back .= " width='" . $colwidth . "'"; } $back .= '><label class="' . $labelclass . ' control-label" for="' . $f['ins_id'] . '">' . wikiplugin_tracker_name($f['fieldId'], tra($f['name']), $field_errors); // if ($showmandatory == 'y' and $f['isMandatory'] == 'y' && $registration != 'y') { $back .= " <strong class='mandatory_star'>*</strong> "; } $back .= '</label>'; // If use different lines, add a line break. // Otherwise a new column if (!$isTextOnSameRow) { $back .= "<br/>"; } else { $back .= '<div class="' . $inputclass . ' tracker_input_value tracker_field' . $f['fieldId'] . '">'; // '</td><td class="tracker_input_value">'; } $back .= wikiplugin_tracker_render_input($f, $item, $dynamicSave) . "</div>"; // chibaguy added /divs if ($showmandatory == 'y' and $f['isMandatory'] == 'y' && $registration == 'y') { $back .= '<div class="col-md-1 col-sm-1"><span class="text-danger tips" title=":' . tra('This field is mandatory') . '">*</span></div>'; } if ($isTextOnSameRow) { $back .= '</div>'; } } if ($f['type'] != 'S' && empty($tpl) && empty($wiki)) { if ($showfieldsdesc == 'y') { $back .= '<div class="form-group tracker-help-block"><div class="' . $labelclass . ' control-label sr-only">Label</div><div class="' . $inputclass . ' trackerplugindesc help-block">'; if ($f['descriptionIsParsed'] == 'y') { $back .= $tikilib->parse_data($f['description']); } else { $back .= tra($f['description']); } $back .= '</div></div>'; } } } } if (isset($params['fieldsfill']) && !empty($params['fieldsfill']) && empty($itemId)) { // $back.= '<tr><td><label for="ins_fill">' . tra("Create multiple items (one per line).") . '</label>'; $back .= '<div class="form-group"><label class="col-md-3" for="ins_fill">' . tra("Insert one item per line:") . '<br />' . '<br />' . '<br />' . '</label>'; $back .= <<<FILL // </td><td> <input type="hidden" value="" name="mode_wysiwyg"/> <input type="hidden" value="" name="mode_normal"/> <div class="edit-zone"> <textarea id="ins_fill" class="wikiedit class="form-control" data-syntax="" data-codemirror="" onkeyup="" rows="15" name="ins_fill" > </textarea> </div> <input type="hidden" value="n" name="wysiwyg"/> <div name="ins_fill_desc" class="trackerplugindesc" > FILL; $back .= sprintf(tra('Each line is a list of %d field values separated with: %s'), $fill_line_cant, htmlspecialchars($fieldsfillseparator)); $back .= '</div><div name="ins_fill_desc2" class="trackerplugindesc" >' . htmlspecialchars(implode($fieldsfillseparator, $fieldsfillnames)); $back .= '</div>'; // $back .= '</td></tr>'; } if ($prefs['feature_antibot'] == 'y' && (empty($user) || !empty($user) && isset($_REQUEST['error']) && $_REQUEST['error'] == 'y')) { $smarty->assign('showantibot', true); } if (!empty($tpl)) { $smarty->security = true; $back .= $smarty->fetch($tpl); } elseif (!empty($wiki)) { $smarty->security = true; if ($tikilib->page_exists($wiki)) { $back .= $smarty->fetch('wiki:' . $wiki); } else { $back .= '<span class="alert-warning">' . tr('Missing wiki template page "%0"', htmlspecialchars($wiki)) . '</span>'; } } $smarty->assign('showmandatory', $showmandatory); if ($prefs['feature_antibot'] == 'y' && empty($user) && (!isset($transactionStep) || $transactionStep == 0) && $params['formtag'] != 'n' && ($registration != 'y' || $prefs["user_register_prettytracker"] != 'y')) { // in_tracker session var checking is for tiki-register.php $smarty->assign('antibot_table', empty($wiki) && empty($tpl) ? 'n' : 'y'); $captchalib = TikiLib::lib('captcha'); $smarty->assign('captchalib', $captchalib); if ($registration == 'y') { $smarty->assign('form', 'register'); } $back .= $smarty->fetch('antibot.tpl'); } $back .= '</div>'; if ($params['formtag'] == 'y') { if (empty($wiki) && empty($tpl)) { $back .= '<div class="form-group"><div class="input_submit_container btn-bar ' . $buttonclass . '">'; } else { $back .= '<div class="form-group"><div class="input_submit_container btn-bar">'; } if (!empty($reset)) { $back .= '<input class="button submit preview" type="reset" name="tr_reset" value="' . tra($reset) . '" />'; } if (!empty($preview)) { $back .= '<input class="btn btn-default button submit preview" type="submit" name="tr_preview" value="' . tra($preview) . '" />'; } foreach ($action as $key => $act) { $back .= '<input class="button submit ' . $action_style[$key] . '" type="submit" name="action' . $key . '" value="' . tra($act) . '" onclick="needToConfirm=false" />'; } $back .= '</div></div>'; } if ($showmandatory == 'y' and $onemandatory) { if (empty($wiki) && empty($tpl)) { $back .= "<div class='form-group'><div class='" . $buttonclass . "'><div class='text-center alert alert-danger'><em>" . tra("Fields marked with an * are mandatory.") . "</em></div></div></div>"; } else { $back .= "<div class='form-group'><div class='text-center alert alert-danger'><em>" . tra("Fields marked with an * are mandatory.") . "</em></div></div>"; } } if ($params['formtag'] == 'y') { $back .= '</form>'; } if (!empty($params['_ajax_form_ins_id'])) { // save new js in a function for the form init fn $headerlib->add_js(' var ajaxTrackerFormInit_' . $params['_ajax_form_ins_id'] . ' = function() {' . $headerlib->output_js(false) . '}', 10); // put back the pre-existing js $headerlib->js = array_merge($headerlib->js, $old_js['js']); $headerlib->jq_onready = array_merge($headerlib->jq_onready, $old_js['jq_onready']); } if (!empty($page)) { $back .= '~/np~'; } $smarty->assign_by_ref('tiki_p_admin_trackers', $perms['tiki_p_admin_trackers']); return $back; } else { if (isset($_REQUEST['trackit']) and $_REQUEST['trackit'] == $trackerId) { $smarty->assign('wikiplugin_tracker', $trackerId); } //used in vote plugin $id = ' id="wikiplugin_tracker' . $iTRACKER . '"'; if ($showtitle == 'y') { $back .= '<div class="h1"' . $id . '>' . $tracker["name"] . '</div>'; $id = ''; } if ($showdesc == 'y') { $back .= '<div class="wikitext"' . $id . '>' . $tracker["description"] . '</div><br />'; $id = ''; } $back .= "<div{$id}>" . $data . '</div>'; return $back; } }
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; }
protected function getItem($id) { global $prefs; $tracker = Tracker_Definition::get($prefs['mustread_tracker']); $item = Tracker_Item::fromId($id); if (!$item || $tracker !== $item->getDefinition()) { throw new Services_Exception_NotFound(tr('Must Read Item not found')); } if (!$item->canView()) { throw new Services_Exception_Denied(tr('Permission denied')); } return $item; }
private function getApplicablePermissions($type, $objectId) { switch ($type) { case 'trackeritem': $item = Tracker_Item::fromId($objectId); return $item->getPerms(); default: return Perms::get($type, $objectId); } }
function wikiplugin_vimeo($data, $params) { global $prefs; static $instance = 0; $instance++; if (isset($params['url'])) { $params['vimeo'] = $params['url']; unset($params['url']); return wikiplugin_flash($data, $params); } elseif (isset($params['fileId'])) { $fileIds = preg_split('/\\D+/', $params['fileId'], -1, PREG_SPLIT_NO_EMPTY); unset($params['fileId']); $out = ''; foreach ($fileIds as $fileId) { $attributelib = TikiLib::lib('attribute'); $attributes = $attributelib->get_attributes('file', $fileId); if (!empty($attributes['tiki.content.url'])) { $params['vimeo'] = $attributes['tiki.content.url']; $out .= wikiplugin_flash($data, $params); } else { TikiLib::lib('errorreport')->report(tr('Vimeo video not found for file #%0', $fileId)); } } return $out; } else { global $page; $smarty = TikiLib::lib('smarty'); if ($prefs['vimeo_upload'] !== 'y') { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return smarty_block_remarksbox(array('type' => 'error', 'title' => tra('Feature required')), tra('Feature "vimeo_upload" is required to be able to add videos here.'), $smarty, $repeat); } // old perms access to get "special" gallery perms to handle user gals etc $perms = TikiLib::lib('tiki')->get_perm_object(!empty($params['galleryId']) ? $params['galleryId'] : $prefs['vimeo_default_gallery'], 'file gallery', TikiLib::lib('filegal')->get_file_gallery_info($prefs['vimeo_default_gallery']), false); if ($perms['tiki_p_upload_files'] !== 'y') { return ''; //$permMessage = tra('You do not have permsission to add files here.'); } else { if (!empty($params['fromFieldId'])) { $fieldInfo = TikiLib::lib('trk')->get_tracker_field($params['fromFieldId']); if (empty($params['fromItemId'])) { $item = Tracker_Item::newItem($fieldInfo['trackerId']); } else { $item = Tracker_Item::fromId($params['fromItemId']); } if (!$item->canModify()) { return ''; //$permMessage = tra('You do not have permsission modify this tracker item.'); } } else { if ($page) { $pagePerms = Perms::get(array('type' => 'wiki page', 'object' => $page))->edit; if (!$pagePerms) { return ''; //$permMessage = tra('You do not have permsission modify this page.'); } } } } // set up for an upload $smarty->loadPlugin('smarty_function_button'); $smarty->loadPlugin('smarty_function_service'); $html = smarty_function_button(array('_keepall' => 'y', '_class' => 'vimeo dialog', 'href' => smarty_function_service(array('controller' => 'vimeo', 'action' => 'upload'), $smarty), '_text' => tra('Upload Video')), $smarty); $js = ' $(".vimeo.dialog").click(function () { var link = this; $(this).serviceDialog({ title: tr("Upload Video"), data: { controller: "vimeo", action: "upload"' . (!empty($params['galleryId']) ? ',galleryId:' . $params['galleryId'] : '') . (!empty($params['fromFieldId']) ? ',fieldId:' . $params['fromFieldId'] : '') . (!empty($params['fromItemId']) ? ',itemId:' . $params['fromItemId'] : '') . ' }, load: function(data) { var $dialog = $(".vimeo_upload").parents(".ui-dialog-content"); // odd its the content, not the outer div $(".vimeo_upload").on("vimeo_uploaded", function(event, data) {'; if (!empty($page) && empty($params['fromFieldId'])) { $js .= ' var params = { page: ' . json_encode($page) . ', content: "", index: ' . $instance . ', type: "vimeo", params: { url: data.url } }; $.post("tiki-wikiplugin_edit.php", params, function() { $("input[type=file]", $dialog).val(""); // webkit reloads the dialog as it destroys it for some reason $dialog.dialog("destroy").remove(); $.get($.service("wiki", "get_page", {page:' . json_encode($page) . '}), function (data) { if (data) { $("#page-data").html(data); } }); });'; } else { $js .= ' $dialog.dialog("destroy").remove(); handleVimeoFile(link, data); '; } $js .= ' }); } }); return false; });'; TikiLib::lib('header')->add_jq_onready($js); return $html; } }