Example #1
0
 public function getDriversLocation()
 {
     $user = new User();
     $group_id = $user->getGroupID();
     if ($group_id > 0) {
         return DBHelper::getAssoc("\n                SELECT d.`driver_id`, d.`lat`, d.`lng`, d.`busy`, d.`accuracy`, d.`last_activity`\n                FROM `drivers` d, `drivers_groups` g\n                WHERE d.driver_id = g.driver_id AND g.`group_id` = " . $group_id);
     } else {
         return DBHelper::getAssoc("\n                SELECT `driver_id`, `lat`, `lng`, `busy`, `accuracy`, `last_activity`\n                FROM `drivers`");
     }
 }
Example #2
0
 /**
  * Returns the data used by the weekly report.
  *
  * @param string $usr_id The ID of the user this report is for.
  * @param int $prj_id The project id
  * @param string|DateTime $start The start date of this report.
  * @param string|DateTime $end The end date of this report.
  * @param array $options extra options for report:
  * - $separate_closed If closed issues should be separated from other issues.
  * - $ignore_statuses If issue status changes should be ignored in report.
  * - $separate_not_assigned_to_user Separate Issues Not Assigned to User
  * - $show_per_issue Add time spent on issue to issues
  * - $separate_no_time Separate No time spent issues
  * @return array An array of data containing all the elements of the weekly report.
  */
 public static function getWeeklyReport($usr_id, $prj_id, $start, $end, $options = array())
 {
     // figure out timezone
     $user_prefs = Prefs::get($usr_id);
     $tz = $user_prefs['timezone'];
     // if start or end is string, convert assume min and max date are specified
     if (!$start instanceof DateTime) {
         $start = Date_Helper::getDateTime($start, $tz)->setTime(0, 0, 0);
     }
     if (!$end instanceof DateTime) {
         $end = Date_Helper::getDateTime($end, $tz)->setTime(23, 59, 59);
     }
     $start_ts = Date_Helper::getSqlDateTime($start);
     $end_ts = Date_Helper::getSqlDateTime($end);
     $time_tracking = Time_Tracking::getSummaryByUser($usr_id, $prj_id, $start_ts, $end_ts);
     // replace spaces in index with _ and calculate total time
     $total_time = 0;
     foreach ($time_tracking as $category => $data) {
         unset($time_tracking[$category]);
         $time_tracking[str_replace(' ', '_', $category)] = $data;
         $total_time += $data['total_time'];
     }
     // get count of issues assigned in week of report.
     $stmt = 'SELECT
                 COUNT(*)
              FROM
                 {{%issue}},
                 {{%issue_user}},
                 {{%status}}
              WHERE
                 iss_id = isu_iss_id AND
                 iss_sta_id = sta_id AND
                 isu_usr_id = ? AND
                 iss_prj_id = ? AND
                 isu_assigned_date BETWEEN ? AND ?';
     $params = array($usr_id, Auth::getCurrentProject(), $start_ts, $end_ts);
     try {
         $newly_assigned = DB_Helper::getInstance()->getOne($stmt, $params);
     } catch (DbException $e) {
         $newly_assigned = null;
     }
     $email_count = array('associated' => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, true), 'other' => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, false));
     $htt_exclude = array();
     if (!empty($options['ignore_statuses'])) {
         $htt_exclude[] = 'status_changed';
         $htt_exclude[] = 'status_auto_changed';
         $htt_exclude[] = 'remote_status_change';
     }
     $issue_list = History::getTouchedIssuesByUser($usr_id, $prj_id, $start_ts, $end_ts, $htt_exclude);
     $issues = array('no_time' => array(), 'not_mine' => array(), 'closed' => array(), 'other' => array());
     // organize issues into categories
     if ($issue_list) {
         if (!empty($options['show_per_issue']) || !empty($options['separate_no_time'])) {
             Time_Tracking::fillTimeSpentByIssueAndTime($issue_list, $usr_id, $start_ts, $end_ts);
         }
         foreach ($issue_list as $row) {
             if (!empty($row['iss_customer_id']) && CRM::hasCustomerIntegration($row['iss_prj_id'])) {
                 $row['customer_name'] = CRM::getCustomerName($row['iss_prj_id'], $row['iss_customer_id']);
             } else {
                 $row['customer_name'] = null;
             }
             if (!empty($options['separate_closed']) && $row['sta_is_closed'] == 1) {
                 $issues['closed'][] = $row;
             } elseif (!empty($options['separate_not_assigned_to_user']) && !Issue::isAssignedToUser($row['iss_id'], $usr_id)) {
                 $issues['not_mine'][] = $row;
             } elseif (!empty($options['separate_no_time']) && empty($row['it_spent'])) {
                 $issues['no_time'][] = $row;
             } else {
                 $issues['other'][] = $row;
             }
         }
         $sort_function = function ($a, $b) {
             return strcasecmp($a['customer_name'], $b['customer_name']);
         };
         usort($issues['closed'], $sort_function);
         usort($issues['other'], $sort_function);
     }
     return array('start' => $start_ts, 'end' => $end_ts, 'user' => User::getDetails($usr_id), 'group_name' => Group::getName(User::getGroupID($usr_id)), 'issues' => $issues, 'status_counts' => History::getTouchedIssueCountByStatus($usr_id, $prj_id, $start_ts, $end_ts), 'new_assigned_count' => $newly_assigned, 'time_tracking' => $time_tracking, 'email_count' => $email_count, 'phone_count' => Phone_Support::getCountByUser($usr_id, $start_ts, $end_ts), 'note_count' => Note::getCountByUser($usr_id, $start_ts, $end_ts), 'total_time' => Misc::getFormattedTime($total_time, false));
 }
Example #3
0
    // Update the events access level for new groups
    $update = "UPDATE " . DB_PREFIX . "groups SET events = :events WHERE id = :id";
    $st = $conn->prepare($update);
    $st->bindValue(":events", $_SESSION['postevents'], PDO::PARAM_INT);
    $st->bindValue(":id", $_GET['newGroup'], PDO::PARAM_INT);
    $st->execute();
} else {
    if (isset($_POST['events']) && !isset($_GET['newGroup'])) {
        // Update the events access level for existing groups
        $update = "UPDATE " . DB_PREFIX . "groups SET events = :events WHERE id = :id";
        $st = $conn->prepare($update);
        $st->bindValue(":events", $_POST['events'] != '' ? $_POST['events'] : 0, PDO::PARAM_INT);
        $st->bindValue(":id", $_GET['editId'], PDO::PARAM_INT);
        $st->execute();
    }
}
// Get the current edit access level for events
$editaccess = "SELECT events FROM " . DB_PREFIX . "groups WHERE id = :id";
$ea = $conn->prepare($editaccess);
$ea->bindValue(":id", $_GET['groupId'], PDO::PARAM_INT);
$ea->execute();
$ea = $ea->fetch();
$_SESSION['editaccess'] = $ea['events'];
// Get the logged in admin access level for events
$sessionaccess = "SELECT events FROM " . DB_PREFIX . "groups WHERE id = :id";
$sa = $conn->prepare($sessionaccess);
$sa->bindValue(":id", User::getGroupID($_SESSION['authuser']), PDO::PARAM_INT);
$sa->execute();
$sa = $sa->fetch();
$_SESSION['access']->events = $sa['events'];
$conn = null;
Example #4
0
 /**
  * Method used to get the list of issues to be displayed in the grid layout.
  *
  * @param   array $options The search parameters
  * @return  string The where clause
  */
 public static function buildWhereClause($options)
 {
     $usr_id = Auth::getUserID();
     $prj_id = Auth::getCurrentProject();
     $role_id = User::getRoleByUser($usr_id, $prj_id);
     $usr_details = User::getDetails($usr_id);
     $stmt = ' AND iss_usr_id = usr_id';
     if ($role_id == User::getRoleID('Customer')) {
         $crm = CRM::getInstance($prj_id);
         $contact = $crm->getContact($usr_details['usr_customer_contact_id']);
         $stmt .= " AND iss_customer_contract_id IN('" . implode("','", $contact->getContractIDS()) . "')";
         $stmt .= " AND iss_customer_id ='" . Auth::getCurrentCustomerID() . "'";
     } elseif ($role_id == User::getRoleID('Reporter') && Project::getSegregateReporters($prj_id)) {
         $stmt .= " AND (\n                        iss_usr_id = {$usr_id} OR\n                        iur_usr_id = {$usr_id}\n                        )";
     }
     if (!empty($usr_details['usr_par_code'])) {
         // restrict partners
         $stmt .= " AND ipa_par_code = '" . Misc::escapeString($usr_details['usr_par_code']) . "'";
     }
     if (!empty($options['users'])) {
         $stmt .= " AND (\n";
         if (stristr($options['users'], 'grp') !== false) {
             $chunks = explode(':', $options['users']);
             $stmt .= 'iss_grp_id = ' . Misc::escapeInteger($chunks[1]);
         } else {
             if ($options['users'] == '-1') {
                 $stmt .= 'isu_usr_id IS NULL';
             } elseif ($options['users'] == '-2') {
                 $stmt .= 'isu_usr_id IS NULL OR isu_usr_id=' . $usr_id;
             } elseif ($options['users'] == '-3') {
                 $stmt .= 'isu_usr_id = ' . $usr_id . ' OR iss_grp_id = ' . User::getGroupID($usr_id);
             } elseif ($options['users'] == '-4') {
                 $stmt .= 'isu_usr_id IS NULL OR isu_usr_id = ' . $usr_id . ' OR iss_grp_id = ' . User::getGroupID($usr_id);
             } else {
                 $stmt .= 'isu_usr_id =' . Misc::escapeInteger($options['users']);
             }
         }
         $stmt .= ')';
     }
     if (!empty($options['reporter'])) {
         $stmt .= ' AND iss_usr_id = ' . Misc::escapeInteger($options['reporter']);
     }
     if (!empty($options['show_authorized_issues'])) {
         $stmt .= " AND (iur_usr_id={$usr_id})";
     }
     if (!empty($options['show_notification_list_issues'])) {
         $stmt .= " AND (sub_usr_id={$usr_id})";
     }
     if (!empty($options['keywords'])) {
         $stmt .= " AND (\n";
         if ($options['search_type'] == 'all_text' && APP_ENABLE_FULLTEXT) {
             $stmt .= 'iss_id IN(' . implode(', ', self::getFullTextIssues($options)) . ')';
         } elseif ($options['search_type'] == 'customer' && CRM::hasCustomerIntegration($prj_id)) {
             // check if the user is trying to search by customer name / email
             $crm = CRM::getInstance($prj_id);
             $customer_ids = $crm->getCustomerIDsByString($options['keywords'], true);
             if (count($customer_ids) > 0) {
                 $stmt .= ' iss_customer_id IN (' . implode(', ', $customer_ids) . ')';
             } else {
                 // no results, kill query
                 $stmt .= ' iss_customer_id = -1';
             }
         } else {
             $stmt .= '(' . Misc::prepareBooleanSearch('iss_summary', $options['keywords']);
             $stmt .= ' OR ' . Misc::prepareBooleanSearch('iss_description', $options['keywords']) . ')';
         }
         $stmt .= "\n) ";
     }
     if (!empty($options['customer_id'])) {
         $stmt .= " AND iss_customer_id='" . Misc::escapeString($options['customer_id']) . "'";
     }
     if (!empty($options['priority'])) {
         $stmt .= ' AND iss_pri_id=' . Misc::escapeInteger($options['priority']);
     }
     if (!empty($options['status'])) {
         $stmt .= ' AND iss_sta_id=' . Misc::escapeInteger($options['status']);
     }
     if (!empty($options['category'])) {
         if (!is_array($options['category'])) {
             $options['category'] = array($options['category']);
         }
         $stmt .= ' AND iss_prc_id IN(' . implode(', ', Misc::escapeInteger($options['category'])) . ')';
     }
     if (!empty($options['hide_closed'])) {
         $stmt .= ' AND sta_is_closed=0';
     }
     if (!empty($options['release'])) {
         $stmt .= ' AND iss_pre_id = ' . Misc::escapeInteger($options['release']);
     }
     if (!empty($options['product'])) {
         $stmt .= ' AND ipv_pro_id = ' . Misc::escapeInteger($options['product']);
     }
     // now for the date fields
     $date_fields = array('created_date', 'updated_date', 'last_response_date', 'first_response_date', 'closed_date');
     foreach ($date_fields as $field_name) {
         if (!empty($options[$field_name])) {
             switch ($options[$field_name]['filter_type']) {
                 case 'greater':
                     $stmt .= " AND iss_{$field_name} >= '" . Misc::escapeString($options[$field_name]['start']) . "'";
                     break;
                 case 'less':
                     $stmt .= " AND iss_{$field_name} <= '" . Misc::escapeString($options[$field_name]['start']) . "'";
                     break;
                 case 'between':
                     $stmt .= " AND iss_{$field_name} BETWEEN '" . Misc::escapeString($options[$field_name]['start']) . "' AND '" . Misc::escapeString($options[$field_name]['end']) . "'";
                     break;
                 case 'null':
                     $stmt .= " AND iss_{$field_name} IS NULL";
                     break;
                 case 'in_past':
                     if (strlen($options[$field_name]['time_period']) == 0) {
                         $options[$field_name]['time_period'] = 0;
                     }
                     $stmt .= " AND (UNIX_TIMESTAMP('" . Date_Helper::getCurrentDateGMT() . "') - UNIX_TIMESTAMP(iss_{$field_name})) <= (" . Misc::escapeInteger($options[$field_name]['time_period']) . '*3600)';
                     break;
             }
         }
     }
     // custom fields
     if (is_array($options['custom_field']) && count($options['custom_field']) > 0) {
         foreach ($options['custom_field'] as $fld_id => $search_value) {
             if (empty($search_value)) {
                 continue;
             }
             $field = Custom_Field::getDetails($fld_id);
             $fld_db_name = Custom_Field::getDBValueFieldNameByType($field['fld_type']);
             if ($field['fld_type'] == 'date' && (empty($search_value['Year']) || empty($search_value['Month']) || empty($search_value['Day']))) {
                 continue;
             }
             if ($field['fld_type'] == 'integer' && empty($search_value['value'])) {
                 continue;
             }
             if ($field['fld_type'] == 'multiple') {
                 $search_value = Misc::escapeString($search_value);
                 foreach ($search_value as $cfo_id) {
                     $cfo_id = Misc::escapeString($cfo_id);
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . '.icf_iss_id = iss_id';
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . ".icf_fld_id = {$fld_id}";
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . '.' . $fld_db_name . " = '{$cfo_id}'";
                 }
             } elseif ($field['fld_type'] == 'date') {
                 if (empty($search_value['Year']) || empty($search_value['Month']) || empty($search_value['Day'])) {
                     continue;
                 }
                 $search_value = $search_value['Year'] . '-' . $search_value['Month'] . '-' . $search_value['Day'];
                 $stmt .= " AND\n (iss_id = cf" . $fld_id . '.icf_iss_id AND
                     cf' . $fld_id . '.' . $fld_db_name . " = '" . Misc::escapeString($search_value) . "')";
             } elseif ($field['fld_type'] == 'integer') {
                 $value = $search_value['value'];
                 switch ($search_value['filter_type']) {
                     case 'ge':
                         $cmp = '>=';
                         break;
                     case 'le':
                         $cmp = '<=';
                         break;
                     case 'gt':
                         $cmp = '>';
                         break;
                     case 'lt':
                         $cmp = '<';
                         break;
                     default:
                         $cmp = '=';
                         break;
                 }
                 $stmt .= " AND\n (iss_id = cf" . $fld_id . '.icf_iss_id';
                 $stmt .= " AND\n cf" . $fld_id . ".icf_fld_id = {$fld_id}";
                 $stmt .= ' AND cf' . $fld_id . '.' . $fld_db_name . $cmp . Misc::escapeString($value) . ')';
             } else {
                 $stmt .= " AND\n (iss_id = cf" . $fld_id . '.icf_iss_id';
                 $stmt .= " AND\n cf" . $fld_id . ".icf_fld_id = {$fld_id}";
                 if ($field['fld_type'] == 'combo') {
                     $stmt .= ' AND cf' . $fld_id . '.' . $fld_db_name . " IN('" . implode("', '", Misc::escapeString($search_value)) . "')";
                 } else {
                     $stmt .= ' AND cf' . $fld_id . '.' . $fld_db_name . " LIKE '%" . Misc::escapeString($search_value) . "%'";
                 }
                 $stmt .= ')';
             }
         }
     }
     // clear cached full-text values if we are not searching fulltext anymore
     if (APP_ENABLE_FULLTEXT && @$options['search_type'] != 'all_text') {
         Session::set('fulltext_string', '');
         Session::set('fulltext_issues', '');
     }
     return $stmt;
 }
Example #5
0
} else {
    $now = time();
    // checking the time now when home page starts
    if ($now > $_SESSION['sessionExpire']) {
        session_destroy();
        $_SESSION['oldURL'] = isset($_GET['action']) ? 'index.php?action=' . $_GET['action'] : '';
        if ($_SERVER['REQUEST_URI'] != 'login.php' && $_SERVER['REQUEST_URI'] != $_SESSION['oldURL']) {
            $_SESSION['oldURL'] = $_SERVER['REQUEST_URI'];
        }
        header("Location: login.php?action=sessionExpired");
    } else {
        $_SESSION['sessionStart'] = time();
        $_SESSION['sessionExpire'] = $_SESSION['sessionStart'] + sessionExpire * 60;
    }
}
// include class files
require_once 'inc/class/Content.class.php';
require_once 'inc/class/Group.class.php';
require_once 'inc/class/Setting.class.php';
require_once 'inc/class/User.class.php';
// get user group access and set it into session
$_SESSION['access'] = Group::getById(User::getGroupID($_SESSION['authuser']));
// add any rci class logic needed for addons
echo $gns_admin_RCI->get('class', 'add', false);
if (!strpos($_SERVER['REQUEST_URI'], 'index.php') && !strpos($_SERVER['REQUEST_URI'], 'search.php')) {
    header("Location: index.php?action=dashboard");
}
// get action
$action = isset($_GET['action']) ? $_GET['action'] : '';
$page_title = '';
echo $gns_admin_RCI->get('top', 'add', false);
Example #6
0
 /**
  * Returns the data used by the weekly report.
  *
  * @access  public
  * @param   string $usr_id The ID of the user this report is for.
  * @param   string The start date of this report.
  * @param   string The end date of this report.
  * @param   boolean If closed issues should be separated from other issues.
  * @return  array An array of data containing all the elements of the weekly report.
  */
 function getWeeklyReport($usr_id, $start, $end, $separate_closed = false)
 {
     $usr_id = Misc::escapeInteger($usr_id);
     // figure out timezone
     $user_prefs = Prefs::get($usr_id);
     $tz = @$user_prefs["timezone"];
     $start_dt = new Date();
     $end_dt = new Date();
     // set timezone to that of user.
     $start_dt->setTZById($tz);
     $end_dt->setTZById($tz);
     // set the dates in the users time zone
     $start_dt->setDate($start . " 00:00:00");
     $end_dt->setDate($end . " 23:59:59");
     // convert time to GMT
     $start_dt->toUTC();
     $end_dt->toUTC();
     $start_ts = $start_dt->getDate();
     $end_ts = $end_dt->getDate();
     $time_tracking = Time_Tracking::getSummaryByUser($usr_id, $start_ts, $end_ts);
     // replace spaces in index with _ and calculate total time
     $total_time = 0;
     foreach ($time_tracking as $category => $data) {
         unset($time_tracking[$category]);
         $time_tracking[str_replace(" ", "_", $category)] = $data;
         $total_time += $data["total_time"];
     }
     // get count of issues assigned in week of report.
     $stmt = "SELECT\n                    COUNT(*)\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n                 WHERE\n                    iss_id = isu_iss_id AND\n                    iss_sta_id = sta_id AND\n                    isu_usr_id = {$usr_id} AND\n                    isu_assigned_date BETWEEN '{$start_ts}' AND '{$end_ts}'";
     $newly_assigned = $GLOBALS["db_api"]->dbh->getOne($stmt);
     if (PEAR::isError($newly_assigned)) {
         Error_Handler::logError(array($newly_assigned->getMessage(), $newly_assigned->getDebugInfo()), __FILE__, __LINE__);
     }
     $email_count = array("associated" => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, true), "other" => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, false));
     $data = array("start" => str_replace('-', '.', $start), "end" => str_replace('-', '.', $end), "user" => User::getDetails($usr_id), "group_name" => Group::getName(User::getGroupID($usr_id)), "issues" => History::getTouchedIssuesByUser($usr_id, $start_ts, $end_ts, $separate_closed), "status_counts" => History::getTouchedIssueCountByStatus($usr_id, $start_ts, $end_ts), "new_assigned_count" => $newly_assigned, "time_tracking" => $time_tracking, "email_count" => $email_count, "phone_count" => Phone_Support::getCountByUser($usr_id, $start_ts, $end_ts), "note_count" => Note::getCountByUser($usr_id, $start_ts, $end_ts), "total_time" => Misc::getFormattedTime($total_time, false));
     return $data;
 }
Example #7
0
include_once APP_INC_PATH . "class.status.php";
include_once APP_INC_PATH . "class.user.php";
$tpl = new Template_API();
$tpl->setTemplate("adv_search.tpl.html");
Auth::checkAuthentication(APP_COOKIE);
// customers should not be able to see this page
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('Standard User')) {
    Auth::redirect(APP_RELATIVE_URL . "list.php");
}
$prj_id = Auth::getCurrentProject();
// generate options for assign list. If there are groups and user is above a customer, include groups
$groups = Group::getAssocList($prj_id);
$users = Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer'));
$assign_options = array("" => "Any", "-1" => "un-assigned", "-2" => "myself and un-assigned");
if (User::getGroupID(Auth::getUserID()) != '') {
    $assign_options['-3'] = 'myself and my group';
    $assign_options['-4'] = 'myself, un-assigned and my group';
}
if (count($groups) > 0 && $role_id > User::getRoleID("Customer")) {
    foreach ($groups as $grp_id => $grp_name) {
        $assign_options["grp:{$grp_id}"] = "Group: " . $grp_name;
    }
}
$assign_options += $users;
$tpl->assign(array("cats" => Category::getAssocList($prj_id), "priorities" => Priority::getList($prj_id), "status" => Status::getAssocStatusList($prj_id), "users" => $assign_options, "releases" => Release::getAssocList($prj_id, TRUE), "custom" => Filter::getListing($prj_id), "custom_fields" => Custom_Field::getListByProject($prj_id, ''), "reporters" => Project::getReporters($prj_id)));
if (!empty($HTTP_GET_VARS["custom_id"])) {
    $check_perm = true;
    if (Filter::isGlobal($HTTP_GET_VARS["custom_id"])) {
        if ($role_id >= User::getRoleID('Manager')) {
            $check_perm = false;
Example #8
0
if (!empty($_REQUEST['nosave'])) {
    $options = Search::saveSearchParams(false);
} else {
    $options = Search::saveSearchParams();
}
$options += $options_override;
$options = array_merge($options, $options_override);
$tpl->assign('options', $options);
$tpl->assign('sorting', Search::getSortingInfo($options));
// generate options for assign list. If there are groups and user is above a customer, include groups
$groups = Group::getAssocList($prj_id);
$users = Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer'));
$assign_options = array('' => ev_gettext('Any'), '-1' => ev_gettext('un-assigned'), '-2' => ev_gettext('myself and un-assigned'));
if (Auth::isAnonUser()) {
    unset($assign_options['-2']);
} elseif (User::getGroupID($usr_id)) {
    $assign_options['-3'] = ev_gettext('myself and my group');
    $assign_options['-4'] = ev_gettext('myself, un-assigned and my group');
}
if (count($groups) > 0 && Auth::getCurrentRole() > User::getRoleID('Customer')) {
    foreach ($groups as $grp_id => $grp_name) {
        $assign_options["grp:{$grp_id}"] = ev_gettext('Group') . ': ' . $grp_name;
    }
}
$assign_options += $users;
$list = Search::getListing($prj_id, $options, $pagerRow, $rows);
$tpl->assign('list', $list['list']);
$tpl->assign('list_info', $list['info']);
$tpl->assign('csv_data', base64_encode(@$list['csv']));
$tpl->assign('match_modes', Search::getMatchModes());
$tpl->assign('supports_excerpts', Search::doesBackendSupportExcerpts());
Example #9
0
 /**
  * Generates the specialized headers for an email.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   string $type The type of message this is
  * @param   string $headers The existing headers of this message.
  * @param   integer $sender_usr_id The id of the user sending this email.
  * @return  array An array of specialized headers
  */
 function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id)
 {
     $new_headers = array();
     if (!empty($issue_id)) {
         $prj_id = Issue::getProjectID($issue_id);
         if (count(Group::getAssocList($prj_id)) > 0) {
             // group issue is currently assigned too
             $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id));
             // group of whoever is sending this message.
             if (empty($sender_usr_id)) {
                 $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue'];
             } else {
                 $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id));
             }
             // group of current assignee
             $assignees = Issue::getAssignedUserIDs($issue_id);
             if (empty($assignees[0])) {
                 $new_headers['X-Eventum-Group-Assignee'] = '';
             } else {
                 $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0]));
             }
         }
         if (Customer::hasCustomerIntegration($prj_id)) {
             if (empty($support_levels)) {
                 $support_levels = Customer::getSupportLevelAssocList($prj_id);
             }
             $customer_id = Issue::getCustomerID($issue_id);
             if (!empty($customer_id)) {
                 $customer_details = Customer::getDetails($prj_id, $customer_id);
                 $new_headers['X-Eventum-Customer'] = $customer_details['customer_name'];
             }
             if (count($support_levels) > 0) {
                 $new_headers['X-Eventum-Level'] = $support_levels[Customer::getSupportLevelID($prj_id, $customer_id)];
             }
         }
         $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id));
         $new_headers['X-Eventum-Project'] = Project::getName($prj_id);
     }
     $new_headers['X-Eventum-Type'] = $type;
     return $new_headers;
 }
Example #10
0
 /**
  * Generates the specialized headers for an email.
  *
  * @param   integer $issue_id The issue ID
  * @param   string $type The type of message this is
  * @param   string $headers The existing headers of this message.
  * @param   integer $sender_usr_id The id of the user sending this email.
  * @return  array An array of specialized headers
  */
 public static function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id)
 {
     $new_headers = array();
     if (!empty($issue_id)) {
         $prj_id = Issue::getProjectID($issue_id);
         if (count(Group::getAssocList($prj_id)) > 0) {
             // group issue is currently assigned too
             $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id));
             // group of whoever is sending this message.
             if (empty($sender_usr_id)) {
                 $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue'];
             } else {
                 $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id));
             }
             // group of current assignee
             $assignees = Issue::getAssignedUserIDs($issue_id);
             if (empty($assignees[0])) {
                 $new_headers['X-Eventum-Group-Assignee'] = '';
             } else {
                 $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0]));
             }
         }
         if (CRM::hasCustomerIntegration($prj_id)) {
             $crm = CRM::getInstance($prj_id);
             try {
                 $customer = $crm->getCustomer(Issue::getCustomerID($issue_id));
                 $new_headers['X-Eventum-Customer'] = $customer->getName();
             } catch (CustomerNotFoundException $e) {
             }
             try {
                 $contract = $crm->getContract(Issue::getContractID($issue_id));
                 $support_level = $contract->getSupportLevel();
                 if (is_object($support_level)) {
                     $new_headers['X-Eventum-Level'] = $support_level->getName();
                 }
             } catch (ContractNotFoundException $e) {
             }
         }
         // add assignee header
         $new_headers['X-Eventum-Assignee'] = implode(',', User::getEmail(Issue::getAssignedUserIDs($issue_id)));
         $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id));
         $new_headers['X-Eventum-Project'] = Project::getName($prj_id);
         $new_headers['X-Eventum-Priority'] = Priority::getTitle(Issue::getPriority($issue_id));
         // handle custom fields
         $cf_values = Custom_Field::getValuesByIssue($prj_id, $issue_id);
         $cf_titles = Custom_Field::getFieldsToBeListed($prj_id);
         foreach ($cf_values as $fld_id => $values) {
             // skip empty titles
             // TODO: why they are empty?
             if (!isset($cf_titles[$fld_id])) {
                 continue;
             }
             // skip empty values
             if (empty($values)) {
                 continue;
             }
             $cf_value = implode(', ', (array) $values);
             // value could be empty after multivalued field join
             if (empty($cf_value)) {
                 continue;
             }
             // convert spaces for header fields
             $cf_title = str_replace(' ', '_', $cf_titles[$fld_id]);
             $new_headers['X-Eventum-CustomField-' . $cf_title] = $cf_value;
         }
     }
     $new_headers['X-Eventum-Type'] = $type;
     return $new_headers;
 }
Example #11
0
 /**
  * Method used to get the list of issues to be displayed in the grid layout.
  *
  * @access  public
  * @param   array $options The search parameters
  * @return  string The where clause
  */
 function buildWhereClause($options)
 {
     $usr_id = Auth::getUserID();
     $prj_id = Auth::getCurrentProject();
     $role_id = User::getRoleByUser($usr_id, $prj_id);
     $stmt = ' AND iss_usr_id = en_ID';
     if (User::getRole($role_id) == "Customer") {
         $stmt .= " AND iss_customer_id=" . User::getCustomerID($usr_id);
     } elseif ($role_id <= User::getRoleID("Standard User") && Project::getSegregateReporters($prj_id)) {
         $stmt .= " AND (\n                        iss_usr_id = {$usr_id} OR\n                        iur_usr_id = {$usr_id} OR\n                        isu_usr_id = {$usr_id}\n                        )";
     }
     if (!empty($options["users"])) {
         $stmt .= " AND (\n";
         if (stristr($options["users"], "grp") !== false) {
             $chunks = explode(":", $options["users"]);
             $stmt .= 'iss_grp_id = ' . Misc::escapeInteger($chunks[1]);
         } else {
             if ($options['users'] == '-1') {
                 $stmt .= 'isu_usr_id IS NULL';
             } elseif ($options['users'] == '-2') {
                 $stmt .= 'isu_usr_id IS NULL OR isu_usr_id=' . $usr_id;
             } elseif ($options['users'] == '-3') {
                 $stmt .= 'isu_usr_id = ' . $usr_id . ' OR iss_grp_id = ' . User::getGroupID($usr_id);
             } elseif ($options['users'] == '-4') {
                 $stmt .= 'isu_usr_id IS NULL OR isu_usr_id = ' . $usr_id . ' OR iss_grp_id = ' . User::getGroupID($usr_id);
             } else {
                 $stmt .= 'isu_usr_id =' . Misc::escapeInteger($options["users"]);
             }
         }
         $stmt .= ')';
     }
     if (!empty($options["reporter"])) {
         $stmt .= " AND iss_usr_id = " . Misc::escapeInteger($options["reporter"]);
     }
     if (!empty($options["show_authorized_issues"])) {
         $stmt .= " AND (iur_usr_id={$usr_id})";
     }
     if (!empty($options["show_notification_list_issues"])) {
         $stmt .= " AND (sub_usr_id={$usr_id})";
     }
     if (!empty($options["keywords"])) {
         $stmt .= " AND (\n";
         if ($options['search_type'] == 'all_text' && APP_ENABLE_FULLTEXT) {
             $stmt .= "iss_id IN(" . join(', ', Issue::getFullTextIssues($options)) . ")";
         } elseif ($options['search_type'] == 'customer' && Customer::hasCustomerIntegration($prj_id)) {
             // check if the user is trying to search by customer email
             $customer_ids = Customer::getCustomerIDsLikeEmail($prj_id, $options['keywords']);
             if (count($customer_ids) > 0) {
                 $stmt .= " iss_customer_id IN (" . implode(', ', $customer_ids) . ")";
             } else {
                 // no results, kill query
                 $stmt .= " iss_customer_id = -1";
             }
         } else {
             $stmt .= "(" . Misc::prepareBooleanSearch('iss_summary', $options["keywords"]);
             $stmt .= " OR " . Misc::prepareBooleanSearch('iss_description', $options["keywords"]) . ")";
         }
         $stmt .= "\n) ";
     }
     if (!empty($options["priority"])) {
         $stmt .= " AND iss_pri_id=" . Misc::escapeInteger($options["priority"]);
     }
     if (!empty($options["status"])) {
         $stmt .= " AND iss_sta_id=" . Misc::escapeInteger($options["status"]);
     }
     if (!empty($options["category"])) {
         $stmt .= " AND iss_prc_id=" . Misc::escapeInteger($options["category"]);
     }
     if (!empty($options["hide_closed"])) {
         $stmt .= " AND sta_is_closed=0";
     }
     if (!empty($options["hide_answered"])) {
         $stmt .= " AND iss_control_status='Unanswered'";
     }
     if (!empty($options['release'])) {
         $stmt .= " AND iss_pre_id = " . Misc::escapeInteger($options['release']);
     }
     // now for the date fields
     $date_fields = array('created_date', 'updated_date', 'last_response_date', 'first_response_date', 'closed_date');
     foreach ($date_fields as $field_name) {
         if (!empty($options[$field_name])) {
             switch ($options[$field_name]['filter_type']) {
                 case 'greater':
                     $stmt .= " AND iss_{$field_name} >= '" . Misc::escapeString($options[$field_name]['start']) . "'";
                     break;
                 case 'less':
                     $stmt .= " AND iss_{$field_name} <= '" . Misc::escapeString($options[$field_name]['start']) . "'";
                     break;
                 case 'between':
                     $stmt .= " AND iss_{$field_name} BETWEEN '" . Misc::escapeString($options[$field_name]['start']) . "' AND '" . Misc::escapeString($options[$field_name]['end']) . "'";
                     break;
                 case 'null':
                     $stmt .= " AND iss_{$field_name} IS NULL";
                     break;
                 case 'in_past':
                     if (strlen($options[$field_name]['time_period']) == 0) {
                         $options[$field_name]['time_period'] = 0;
                     }
                     $stmt .= " AND (UNIX_TIMESTAMP('" . Date_API::getCurrentDateGMT() . "') - UNIX_TIMESTAMP(iss_{$field_name})) <= (" . Misc::escapeInteger($options[$field_name]['time_period']) . "*3600)";
                     break;
                 case 'not_in_past':
                     if (strlen($options[$field_name]['time_period']) == 0) {
                         $options[$field_name]['time_period'] = 0;
                     }
                     $stmt .= " AND \n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tiss_{$field_name} is NULL || \n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t(UNIX_TIMESTAMP('" . Date_API::getCurrentDateGMT() . "') - UNIX_TIMESTAMP(iss_{$field_name})) > (" . Misc::escapeInteger($options[$field_name]['time_period']) . "*3600)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
                     break;
             }
         }
     }
     // custom fields
     if (is_array($options['custom_field']) && count($options['custom_field']) > 0) {
         foreach ($options['custom_field'] as $fld_id => $search_value) {
             if (empty($search_value)) {
                 continue;
             }
             $field = Custom_Field::getDetails($fld_id);
             if ($field['fld_type'] == 'multiple') {
                 $search_value = Misc::escapeInteger($search_value);
                 foreach ($search_value as $cfo_id) {
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . ".icf_iss_id = iss_id";
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . ".icf_fld_id = {$fld_id}";
                     $stmt .= " AND\n cf" . $fld_id . '_' . $cfo_id . ".icf_value = {$cfo_id}";
                 }
             } elseif ($field['fld_type'] == 'date') {
                 if (empty($search_value['Year']) || empty($search_value['Month']) || empty($search_value['Day'])) {
                     continue;
                 }
                 $search_value = $search_value['Year'] . "-" . $search_value['Month'] . "-" . $search_value['Day'];
                 $stmt .= " AND\n (iss_id = cf" . $fld_id . ".icf_iss_id AND\n                        cf" . $fld_id . ".icf_value = '" . Misc::escapeString($search_value) . "')";
             } else {
                 $stmt .= " AND\n (iss_id = cf" . $fld_id . ".icf_iss_id";
                 $stmt .= " AND\n cf" . $fld_id . ".icf_fld_id = {$fld_id}";
                 if (in_array($field['fld_type'], array('text', 'textarea'))) {
                     $stmt .= " AND cf" . $fld_id . ".icf_value LIKE '%" . Misc::escapeString($search_value) . "%'";
                 } elseif ($field['fld_type'] == 'combo') {
                     $stmt .= " AND cf" . $fld_id . ".icf_value IN(" . join(', ', Misc::escapeInteger($search_value)) . ")";
                 }
                 $stmt .= ')';
             }
         }
     }
     // clear cached full-text values if we are not searching fulltext anymore
     if (APP_ENABLE_FULLTEXT && @$options['search_type'] != 'all_text') {
         Session::set('fulltext_string', '');
         Session::set('fulltext_issues', '');
     }
     return $stmt;
 }
Example #12
0
if (empty($rows)) {
    $rows = APP_DEFAULT_PAGER_SIZE;
}
if (@$_REQUEST['view'] == 'my_assignments') {
    $profile = Search_Profile::getProfile($usr_id, $prj_id, 'issue');
    Search_Profile::remove($usr_id, $prj_id, 'issue');
    Auth::redirect(APP_RELATIVE_URL . "list.php?users={$usr_id}&hide_closed=1&hide_answered=1&rows={$rows}&sort_by=" . $profile['sort_by'] . "&sort_order=" . $profile['sort_order']);
}
$options = Issue::saveSearchParams();
$tpl->assign("options", $options);
$tpl->assign("sorting", Issue::getSortingInfo($options));
// generate options for assign list. If there are groups and user is above a customer, include groups
$groups = Group::getAssocList($prj_id);
$users = Project::getUserAssocList($prj_id, 'active', User::getRoleID('Developer'));
$assign_options = array("" => "Any", "-1" => "un-assigned", "-2" => "myself and un-assigned");
if (User::getGroupID($usr_id) != '') {
    $assign_options['-3'] = 'myself and my group';
    $assign_options['-4'] = 'myself, un-assigned and my group';
}
if (count($groups) > 0 && Auth::getCurrentRole() > User::getRoleID("Customer")) {
    foreach ($groups as $grp_id => $grp_name) {
        $assign_options["grp:{$grp_id}"] = "Group: " . $grp_name;
    }
}
$assign_options += $users;
// get display values for custom fields
$custom_fields_display = array();
if (is_array($options['custom_field']) && count($options['custom_field']) > 0) {
    foreach ($options['custom_field'] as $fld_id => $search_value) {
        if (empty($search_value)) {
            continue;