function _buildContentWhereArray() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $config = HelpdeskProHelper::getConfig(); $managedCategoryIds = HelpdeskProHelper::getTicketCategoryIds($user->get('username')); $where = parent::_buildContentWhereArray(); $state = $this->getState(); if ($state->category_id) { $where[] = ' a.category_id = ' . $state->category_id; } if ($state->status_id) { if ($state->status_id == -1) { if (!$user->authorise('core.admin')) { if (count($managedCategoryIds)) { //Show open and pending tickets to managers by default $where[] = ' (a.status_id=' . $config->new_ticket_status_id . ' OR a.status_id=' . $config->ticket_status_when_customer_add_comment . ') '; } else { //Show open tickets and require feedback tickets to customers //$where[] = ' (a.status_id='.$config->new_ticket_status_id.' OR a.status_id='.$config->ticket_status_when_admin_add_comment.') '; $where[] = " a.status_id != {$config->closed_ticket_status} "; } } else { //Show open and pending tickets to managers by default $where[] = ' (a.status_id=' . $config->new_ticket_status_id . ' OR a.status_id=' . $config->ticket_status_when_customer_add_comment . ') '; } } else { $where[] = ' a.status_id = ' . $state->status_id; } } if ($state->priority_id) { $where[] = ' a.priority_id = ' . $state->priority_id; } if (!$user->authorise('core.admin')) { //Super administrator can view all tickets if ($managedCategoryIds) { //He is ticket managers, so all tickets belong to him $where[] = ' a.category_id IN (' . implode(',', $managedCategoryIds) . ')'; } else { //Registered user, only show tickets submitted by himself $userId = $user->get('id'); $email = $user->get('email'); // $where[] = "(a.user_id=$userId OR a.email='$email') " ; $where[] = ' a.status_id = 4'; } } return $where; }
function _buildListArray(&$lists, $state) { $db =& JFactory::getDbo(); $user = JFactory::getUser(); $dateFormat = HelpdeskProHelper::getConfigValue('date_format'); if (!$user->authorise('core.admin')) { $managedCategoryIds = HelpdeskProHelper::getTicketCategoryIds($user->get('username')); if (count($managedCategoryIds)) { $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE id IN (" . implode(',', $managedCategoryIds) . ") AND published=1 ORDER BY ordering"; } else { $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE published=1 ORDER BY ordering"; } } else { $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE published=1 ORDER BY ordering"; } $db->setQuery($sql); $rows = $db->loadObjectList(); $children = array(); if ($rows) { // first pass - collect children foreach ($rows as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } } $list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_CATEGORIES')); foreach ($list as $listItem) { $options[] = JHTML::_('select.option', $listItem->id, ' ' . $listItem->treename); } $lists['category_id'] = JHTML::_('select.genericlist', $options, 'category_id', array('option.text.toHtml' => false, 'option.text' => 'text', 'option.value' => 'value', 'list.attr' => 'class="inputbox" onchange="submit();"', 'list.select' => $state->category_id)); $options = array(); $options[] = JHtml::_('select.option', -1, JText::_('HDP_SELECT'), 'id', 'title'); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_STATUSES'), 'id', 'title'); $sql = 'SELECT id, title FROM #__helpdeskpro_statuses WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $rowStatuses = $db->loadObjectList(); $options = array_merge($options, $rowStatuses); $lists['status_id'] = JHTML::_('select.genericlist', $options, 'status_id', array('option.text.toHtml' => false, 'option.text' => 'title', 'option.key' => 'id', 'list.attr' => 'class="inputbox" onchange="submit();" ', 'list.select' => $state->status_id)); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_PRIORITIES'), 'id', 'title'); $sql = 'SELECT id, title FROM #__helpdeskpro_priorities WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $rowPriorities = $db->loadObjectList(); $options = array_merge($options, $rowPriorities); $lists['priority_id'] = JHTML::_('select.genericlist', $options, 'priority_id', array('option.text.toHtml' => false, 'option.text' => 'title', 'option.key' => 'id', 'list.attr' => 'class="inputbox" onchange="submit();" ', 'list.select' => $state->priority_id)); $statusList = array(); foreach ($rowStatuses as $status) { $statusList[$status->id] = $status->title; } $priorityList = array(); foreach ($rowPriorities as $priority) { $priorityList[$priority->id] = $priority->title; } $this->dateFormat = $dateFormat; $this->statusList = $statusList; $this->priorityList = $priorityList; return true; }
function _buildListArray(&$lists, $state) { $user = JFactory::getUser(); $db =& JFactory::getDbo(); $dateFormat = HelpdeskProHelper::getConfigValue('date_format'); if (!$user->authorise('core.admin')) { $managedCategoryIds = HelpdeskProHelper::getTicketCategoryIds($user->get('username')); if (count($managedCategoryIds)) { $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE id IN (" . implode(',', $managedCategoryIds) . ") AND published=1 ORDER BY ordering"; } elseif (!$user->get('id')) { $userId = 0; $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE published=1 ORDER BY ordering"; } else { $userId = $user->get('id'); $email = $user->get('email'); $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE published=1 AND id IN (SELECT DISTINCT category_id FROM #__helpdeskpro_tickets AS t WHERE t.user_id={$userId} OR t.email='{$email}') ORDER BY ordering"; } } else { $sql = "SELECT id, parent_id, title FROM #__helpdeskpro_categories WHERE published=1 ORDER BY ordering"; } $db->setQuery($sql); $rows = $db->loadObjectList(); $children = array(); if ($rows) { // first pass - collect children foreach ($rows as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } } $list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_CATEGORIES')); foreach ($list as $listItem) { $options[] = JHTML::_('select.option', $listItem->id, ' ' . $listItem->treename); } $lists['cat'] = '<ul class="nav menu">'; foreach ($list as $listItem) { if ($listItem->id == $state->category_id && isset($_GET['category_id'])) { $active = ' class="active"'; } else { $active = ''; } $lists['cat'] .= '<li' . $active . '><a href="' . JRoute::_('index.php?option=com_helpdeskpro&view=tickets&category_id=' . $listItem->id) . '">' . $listItem->treename . '</a></li>'; } $lists['cat'] .= '</ul>'; $lists['category_id'] = JHTML::_('select.genericlist', $options, 'category_id', array('option.text.toHtml' => false, 'option.text' => 'text', 'option.value' => 'value', 'list.attr' => 'class="inputbox" ', 'list.select' => $state->category_id)); $options = array(); $options[] = JHtml::_('select.option', -1, JText::_('HDP_SELECT'), 'id', 'title'); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_STATUSES'), 'id', 'title'); $sql = 'SELECT id, title FROM #__helpdeskpro_statuses WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $rowStatuses = $db->loadObjectList(); $options = array_merge($options, $rowStatuses); $lists['status_id'] = JHTML::_('select.genericlist', $options, 'status_id', array('option.text.toHtml' => false, 'option.text' => 'title', 'option.key' => 'id', 'list.attr' => 'class="inputbox" onchange="submit();"', 'list.select' => $state->status_id)); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('HDP_ALL_PRIORITIES'), 'id', 'title'); $sql = 'SELECT id, title FROM #__helpdeskpro_priorities WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $rowPriorities = $db->loadObjectList(); $options = array_merge($options, $rowPriorities); $lists['priority_id'] = JHTML::_('select.genericlist', $options, 'priority_id', array('option.text.toHtml' => false, 'option.text' => 'title', 'option.key' => 'id', 'list.attr' => 'class="inputbox" ', 'list.select' => $state->priority_id)); $statusList = array(); foreach ($rowStatuses as $status) { $statusList[$status->id] = $status->title; } $priorityList = array(); foreach ($rowPriorities as $priority) { $priorityList[$priority->id] = $priority->title; } $sql = 'SELECT title FROM #__helpdeskpro_categories WHERE id=' . $state->category_id; $db->setQuery($sql); $categoryTitle = $db->loadResult(); $sql = "SELECT config_value FROM #__helpdeskpro_configs WHERE config_key='home_page_text'"; $db->setQuery($sql); $home_page_text = $db->loadResult(); $this->home_page_text = $home_page_text; $this->dateFormat = $dateFormat; $this->statusList = $statusList; $this->priorityList = $priorityList; if (isset($_GET['category_id'])) { $this->category_id = $state->category_id; } else { $this->category_id = 0; } $this->categoryTitle = $categoryTitle; return true; }
/** * Check ticket access * @param Ticket object $item */ public static function checkTicketAccess($item) { $user = JFactory::getUser(); if (!$item->id) { return false; } if ($item->is_ticket_code) { return true; } if (!$user->id) { return false; } if ($user->id == $item->user_id) { return true; } if ($user->authorise('core.admin')) { return true; } $managedCategoryIds = HelpdeskProHelper::getTicketCategoryIds($user->get('username')); if (in_array($item->category_id, $managedCategoryIds)) { return true; } return false; }