Example #1
0
 /**
  * Adds an email to the outgoing mail queue.
  *
  * @param   string $recipient The recipient of this email
  * @param   array $headers The list of headers that should be sent with this email
  * @param   string $body The body of the message
  * @param   integer $save_email_copy Whether to send a copy of this email to a configurable address or not (eventum_sent@)
  * @param   integer $issue_id The ID of the issue. If false, email will not be associated with issue.
  * @param   string $type The type of message this is.
  * @param   integer $sender_usr_id The id of the user sending this email.
  * @param   integer $type_id The ID of the event that triggered this notification (issue_id, sup_id, not_id, etc)
  * @return  true, or a PEAR_Error object
  */
 public static function add($recipient, $headers, $body, $save_email_copy = 0, $issue_id = false, $type = '', $sender_usr_id = false, $type_id = false)
 {
     Workflow::modifyMailQueue(Auth::getCurrentProject(false), $recipient, $headers, $body, $issue_id, $type, $sender_usr_id, $type_id);
     // avoid sending emails out to users with inactive status
     $recipient_email = Mail_Helper::getEmailAddress($recipient);
     $usr_id = User::getUserIDByEmail($recipient_email);
     if (!empty($usr_id)) {
         $user_status = User::getStatusByEmail($recipient_email);
         // if user is not set to an active status, then silently ignore
         if (!User::isActiveStatus($user_status) && !User::isPendingStatus($user_status)) {
             return false;
         }
     }
     $to_usr_id = User::getUserIDByEmail($recipient_email);
     $recipient = Mail_Helper::fixAddressQuoting($recipient);
     $reminder_addresses = Reminder::_getReminderAlertAddresses();
     // add specialized headers
     if (!empty($issue_id) && (!empty($to_usr_id) && User::getRoleByUser($to_usr_id, Issue::getProjectID($issue_id)) != User::getRoleID('Customer')) || @in_array(Mail_Helper::getEmailAddress($recipient), $reminder_addresses)) {
         $headers += Mail_Helper::getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id);
     }
     // try to prevent triggering absence auto responders
     $headers['precedence'] = 'bulk';
     // the 'classic' way, works with e.g. the unix 'vacation' tool
     $headers['Auto-submitted'] = 'auto-generated';
     // the RFC 3834 way
     if (empty($issue_id)) {
         $issue_id = 'null';
     }
     // if the Date: header is missing, add it.
     if (empty($headers['Date'])) {
         $headers['Date'] = Mime_Helper::encode(date('D, j M Y H:i:s O'));
     }
     if (!empty($headers['To'])) {
         $headers['To'] = Mail_Helper::fixAddressQuoting($headers['To']);
     }
     // encode headers and add special mime headers
     $headers = Mime_Helper::encodeHeaders($headers);
     $res = Mail_Helper::prepareHeaders($headers);
     if (Misc::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return $res;
     }
     // convert array of headers into text headers
     list(, $text_headers) = $res;
     $params = array('maq_save_copy' => $save_email_copy, 'maq_queued_date' => Date_Helper::getCurrentDateGMT(), 'maq_sender_ip_address' => !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'maq_recipient' => $recipient, 'maq_headers' => $text_headers, 'maq_body' => $body, 'maq_iss_id' => $issue_id, 'maq_subject' => $headers['Subject'], 'maq_type' => $type);
     if ($sender_usr_id) {
         $params['maq_usr_id'] = $sender_usr_id;
     }
     if ($type_id) {
         $params['maq_type_id'] = $type_id;
     }
     $stmt = 'INSERT INTO {{%mail_queue}} SET ' . DB_Helper::buildSet($params);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return $res;
     }
     return true;
 }
 public function getIssueIDs($options)
 {
     // Build the Sphinx client
     $this->sphinx->SetSortMode(SPH_SORT_RELEVANCE);
     //        $this->sphinx->SetWeights(array(1, 1));
     $this->sphinx->SetLimits(0, 500, 100000);
     $this->sphinx->SetArrayResult(true);
     if (empty($options['match_mode'])) {
         $options['match_mode'] = SPH_MATCH_ALL;
     }
     $this->sphinx->SetMatchMode($options['match_mode']);
     $this->sphinx->SetFilter('prj_id', array(Auth::getCurrentProject()));
     // TODO: Add support for selecting indexes to search
     $indexes = implode('; ', $this->getIndexes(Auth::getCurrentRole() > User::ROLE_CUSTOMER));
     if (isset($options['customer_id']) && !empty($options['customer_id'])) {
         $this->sphinx->SetFilter('customer_id', array($options['customer_id']));
     }
     $this->keywords = $options['keywords'];
     $this->match_mode = $options['match_mode'];
     $res = $this->sphinx->Query($options['keywords'], $indexes);
     // TODO: report these somehow back to the UI
     // probably easy to do with Logger framework (add new handler?)
     if (method_exists($this->sphinx, 'IsConnectError') && $this->sphinx->IsConnectError()) {
         Logger::app()->error('sphinx_fulltext_search: Network Error');
     }
     if ($this->sphinx->GetLastWarning()) {
         Logger::app()->warning('sphinx_fulltext_search: ' . $this->sphinx->GetLastWarning());
     }
     if ($this->sphinx->GetLastError()) {
         Logger::app()->error('sphinx_fulltext_search: ' . $this->sphinx->GetLastError());
     }
     $issue_ids = array();
     if (isset($res['matches'])) {
         foreach ($res['matches'] as $match_details) {
             // Variable translation
             $match_id = $match_details['id'];
             $issue_id = $match_details['attrs']['issue_id'];
             $weight = $match_details['weight'];
             $index_id = $match_details['attrs']['index_id'];
             // if sphinx returns 0 as a weight, make it one because it
             // did find a match in the result set
             if ($weight <= 0) {
                 $weight = 1;
             }
             $index_name = $this->getIndexNameByID($index_id);
             $this->matches[$issue_id][] = array('weight' => $weight, 'index' => $index_name, 'match_id' => $match_id);
             $issue_ids[] = $issue_id;
         }
     }
     return $issue_ids;
 }
Example #3
0
 /**
  * Returns the list of FAQ entries associated to a given support level.
  *
  * @param   array $support_level_ids The support level IDs
  * @return  array The list of FAQ entries
  */
 public static function getListBySupportLevel($support_level_ids)
 {
     if (!is_array($support_level_ids)) {
         $support_level_ids = array($support_level_ids);
     }
     $prj_id = Auth::getCurrentProject();
     if (count($support_level_ids) == 0) {
         $stmt = 'SELECT
                     *
                  FROM
                     {{%faq}}
                  WHERE
                     faq_prj_id = ?
                  ORDER BY
                     faq_rank ASC';
         $params = array($prj_id);
     } else {
         $stmt = 'SELECT
                     *
                  FROM
                     {{%faq}},
                     {{%faq_support_level}}
                  WHERE
                     faq_id=fsl_faq_id AND
                     fsl_support_level_id IN (' . DB_Helper::buildList($support_level_ids) . ') AND
                     faq_prj_id = ?
                  GROUP BY
                     faq_id
                  ORDER BY
                     faq_rank ASC';
         $params = $support_level_ids;
         $params[] = $prj_id;
     }
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, $params);
     } catch (DbException $e) {
         return '';
     }
     foreach ($res as &$row) {
         if (empty($row['faq_updated_date'])) {
             $row['faq_updated_date'] = $row['faq_created_date'];
         }
         $row['faq_updated_date'] = Date_Helper::getSimpleDate($row['faq_updated_date']);
     }
     return $res;
 }
Example #4
0
 public function __construct()
 {
     $this->usr_id = Auth::getUserID();
     if (!Access::canAccessReports($this->usr_id)) {
         throw new LogicException('Invalid role');
     }
     $this->prj_id = Auth::getCurrentProject();
     $this->activity_types = !empty($_REQUEST['activity_types']) ? (array) $_REQUEST['activity_types'] : array();
     $this->report_type = isset($_REQUEST['report_type']) ? (string) $_REQUEST['report_type'] : null;
     $this->unit = $this->getParam('unit', array('hour', 'day'));
     $this->amount = isset($_REQUEST['amount']) ? $_REQUEST['amount'] : null;
     $this->developer = isset($_REQUEST['developer']) ? $_REQUEST['developer'] : null;
     $this->start_date = $this->parseDate(isset($_POST['start']) ? $_POST['start'] : null);
     $this->end_date = $this->parseDate(isset($_POST['end']) ? $_POST['end'] : null);
     $this->sort_order = $this->getParam('sort_order', array('ASC', 'DESC'));
     if (CRM::hasCustomerIntegration($this->prj_id)) {
         $this->crm = CRM::getInstance($this->prj_id);
     }
 }
Example #5
0
 /**
  * Returns the list of FAQ entries associated to a given support level.
  *
  * @access  public
  * @param   integer $support_level_id The support level ID
  * @return  array The list of FAQ entries
  */
 function getListBySupportLevel($support_level_id)
 {
     $support_level_id = Misc::escapeInteger($support_level_id);
     $prj_id = Auth::getCurrentProject();
     if ($support_level_id == -1) {
         $stmt = "SELECT\n                        *\n                     FROM\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "faq\n                     WHERE\n                        faq_prj_id = {$prj_id}\n                     ORDER BY\n                        faq_rank ASC";
     } else {
         $stmt = "SELECT\n                        *\n                     FROM\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "faq,\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "faq_support_level\n                     WHERE\n                        faq_id=fsl_faq_id AND\n                        fsl_support_level_id={$support_level_id} AND\n                        faq_prj_id = {$prj_id}\n                     ORDER BY\n                        faq_rank ASC";
     }
     $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return "";
     } else {
         for ($i = 0; $i < count($res); $i++) {
             if (empty($res[$i]['faq_updated_date'])) {
                 $res[$i]['faq_updated_date'] = $res[$i]['faq_created_date'];
             }
             $res[$i]['faq_updated_date'] = Date_API::getSimpleDate($res[$i]["faq_updated_date"]);
         }
         return $res;
     }
 }
Example #6
0
 /**
  * Returns workload information for the specified date range and interval.
  *
  * @param   string $interval The interval to use in this report.
  * @param   string $type If this report is aggregate or individual
  * @param   string $start The start date of this report.
  * @param   string $end The end date of this report.
  * @param   integer $category_id The category to restrict this report to
  * @return  array An array containing workload data.
  */
 public static function getWorkloadByDateRange($interval, $type, $start, $end, $category_id)
 {
     $data = array();
     $category_id = (int) $category_id;
     // figure out the correct format code
     switch ($interval) {
         case 'day':
             $format = '%m/%d/%y';
             $order_by = "%1\$s";
             break;
         case 'dow':
             $format = '%W';
             $order_by = "CASE WHEN DATE_FORMAT(%1\$s, '%%w') = 0 THEN 7 ELSE DATE_FORMAT(%1\$s, '%%w') END";
             break;
         case 'week':
             if ($type == 'aggregate') {
                 $format = '%v';
             } else {
                 $format = '%v/%y';
             }
             $order_by = "%1\$s";
             break;
         case 'dom':
             $format = '%d';
             break;
         case 'month':
             if ($type == 'aggregate') {
                 $format = '%b';
                 $order_by = "DATE_FORMAT(%1\$s, '%%m')";
             } else {
                 $format = '%b/%y';
                 $order_by = "%1\$s";
             }
             break;
         default:
             throw new LogicException('Invalid interval');
     }
     // get issue counts
     $stmt = 'SELECT
                 DATE_FORMAT(iss_created_date, ?),
                 count(*)
              FROM
                 {{%issue}}
              WHERE
                 iss_prj_id=? AND
                 iss_created_date BETWEEN ? AND ?';
     $params = array($format, Auth::getCurrentProject(), $start, $end);
     if (!empty($category_id)) {
         $stmt .= ' AND
                 iss_prc_id = ?';
         $params[] = $category_id;
     }
     $stmt .= '
              GROUP BY
                 DATE_FORMAT(iss_created_date, ?)';
     $params[] = $format;
     if (!empty($order_by)) {
         $stmt .= "\nORDER BY " . sprintf($order_by, 'iss_created_date');
     }
     try {
         $res = DB_Helper::getInstance()->fetchAssoc($stmt, $params);
     } catch (DbException $e) {
         return array();
     }
     $data['issues']['points'] = $res;
     $data['issues']['stats'] = array('total' => 0, 'avg' => 0, 'median' => 0, 'max' => 0);
     if ($res) {
         $stats = new Math_Stats();
         $stats->setData($res);
         $data['issues']['stats'] = array('total' => $stats->sum(), 'avg' => $stats->mean(), 'median' => $stats->median(), 'max' => $stats->max());
     }
     // get email counts
     $params = array();
     $stmt = 'SELECT
                 DATE_FORMAT(sup_date, ?),
                 count(*)
              FROM
                 {{%support_email}},
                 {{%email_account}}';
     $params[] = $format;
     if (!empty($category_id)) {
         $stmt .= ',
                  {{%issue}}';
     }
     $stmt .= '
              WHERE
                 sup_ema_id=ema_id AND
                 ema_prj_id=? AND
                 sup_date BETWEEN ? AND ?';
     $params[] = Auth::getCurrentProject();
     $params[] = $start;
     $params[] = $end;
     if (!empty($category_id)) {
         $stmt .= ' AND
                 sup_iss_id = iss_id AND
                 iss_prc_id = ?';
         $params[] = $category_id;
     }
     $stmt .= '
              GROUP BY
                 DATE_FORMAT(sup_date, ?)';
     $params[] = $format;
     if (!empty($order_by)) {
         $stmt .= "\nORDER BY " . sprintf($order_by, 'sup_date');
     }
     try {
         $res = DB_Helper::getInstance()->fetchAssoc($stmt, $params);
     } catch (DbException $e) {
         return array();
     }
     $data['emails']['points'] = $res;
     if (count($res) > 0) {
         $stats = new Math_Stats();
         $stats->setData($res);
         $data['emails']['stats'] = array('total' => $stats->sum(), 'avg' => $stats->mean(), 'median' => $stats->median(), 'max' => $stats->max());
     } else {
         $data['emails']['stats'] = array('total' => 0, 'avg' => 0, 'median' => 0, 'max' => 0);
     }
     return $data;
 }
Example #7
0
 /**
  * Returns the number of notes by a user in a time range.
  *
  * @param   string $usr_id The ID of the user
  * @param   integer $start The timestamp of the start date
  * @param   integer $end The timestanp of the end date
  * @return  integer The number of notes by the user
  */
 public static function getCountByUser($usr_id, $start, $end)
 {
     $stmt = 'SELECT
                 COUNT(not_id)
              FROM
                 {{%note}},
                 {{%issue}}
              WHERE
                 not_iss_id = iss_id AND
                 iss_prj_id = ? AND
                 not_created_date BETWEEN ? AND ? AND
                 not_usr_id = ? AND
                 not_removed = 0';
     $params = array(Auth::getCurrentProject(), $start, $end, $usr_id);
     try {
         $res = DB_Helper::getInstance()->getOne($stmt, $params);
     } catch (DbException $e) {
         return '';
     }
     return $res;
 }
Example #8
0
 /**
  * Formats the return value
  *
  * @param   mixed   $value The value to format
  * @param   integer $fld_id The ID of the field
  * @param   integer $issue_id The ID of the issue
  * @return  mixed   the formatted value.
  */
 public function formatValue($value, $fld_id, $issue_id)
 {
     $backend = self::getBackend($fld_id);
     if (is_object($backend) && method_exists($backend, 'formatValue')) {
         return $backend->formatValue($value, $fld_id, $issue_id);
     } else {
         return Link_Filter::processText(Auth::getCurrentProject(), Misc::htmlentities($value));
     }
 }
Example #9
0
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/products.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_MANAGER) {
    Misc::setMessage('Sorry, you are not allowed to access this page.', Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
if (@$_POST['cat'] == 'new') {
    $res = Product::insert($_POST['title'], $_POST['version_howto'], $_POST['rank'], @$_POST['removed'], @$_POST['email']);
    Misc::mapMessages($res, array(1 => array('Thank you, the product was added successfully.', Misc::MSG_INFO), -1 => array('An error occurred while trying to add the product.', Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = Product::update($_POST['id'], $_POST['title'], $_POST['version_howto'], $_POST['rank'], @$_POST['removed'], @$_POST['email']);
    Misc::mapMessages($res, array(1 => array('Thank you, the product was updated successfully.', Misc::MSG_INFO), -1 => array('An error occurred while trying to update the product.', Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    Product::remove($_POST['items']);
}
if (@$_GET['cat'] == 'edit') {
    $info = Product::getDetails($_GET['id']);
    $tpl->assign('info', $info);
    $user_options = User::getActiveAssocList(Auth::getCurrentProject(), User::ROLE_CUSTOMER, false, $_GET['id']);
} else {
    $user_options = User::getActiveAssocList(Auth::getCurrentProject(), User::ROLE_CUSTOMER, true);
}
$tpl->assign('list', Product::getList());
$tpl->assign('project_list', Project::getAll());
$tpl->displayTemplate();
Example #10
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 #11
0
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('emails.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
if (!Access::canAccessAssociateEmails(Auth::getUserID())) {
    $tpl->assign('no_access', 1);
    $tpl->displayTemplate();
    exit;
}
$pagerRow = Support::getParam('pagerRow');
if (empty($pagerRow)) {
    $pagerRow = 0;
}
$rows = Support::getParam('rows');
if (empty($rows)) {
    $rows = APP_DEFAULT_PAGER_SIZE;
}
$options = Support::saveSearchParams();
$tpl->assign('options', $options);
$tpl->assign('sorting', Support::getSortingInfo($options));
$list = Support::getEmailListing($options, $pagerRow, $rows);
$tpl->assign('list', $list['list']);
$tpl->assign('list_info', $list['info']);
$tpl->assign('issues', Issue::getColList());
$tpl->assign('accounts', Email_Account::getAssocList(Auth::getCurrentProject()));
$prefs = Prefs::get(Auth::getUserID());
$tpl->assign('refresh_rate', $prefs['email_refresh_rate'] * 60);
$tpl->assign('refresh_page', 'emails.php');
$tpl->displayTemplate();
Example #12
0
 /**
  * Gets the current role in the current project.
  *
  * @access  public
  * @return  integer The current role ID
  */
 function getCurrentRole()
 {
     $usr_id = Auth::getUserID();
     if (!$usr_id) {
         return 1;
     }
     $prj_id = Auth::getCurrentProject();
     if (!empty($prj_id) && !empty($usr_id)) {
         return User::getRoleByUser($usr_id, $prj_id);
     } else {
         return 1;
     }
 }
Example #13
0
 /**
  * Returns an array of information about all the different filter fields.
  *
  * @return  array an array of information.
  */
 public static function getFiltersInfo()
 {
     // format is "name_of_db_field" => array(
     //      "title" => human readable title,
     //      "param" => name that appears in get, post or cookie
     $fields = array('iss_pri_id' => array('title' => ev_gettext('Priority'), 'param' => 'priority', 'quickfilter' => true), 'iss_sev_id' => array('title' => ev_gettext('Severity'), 'param' => 'severity', 'quickfilter' => true), 'keywords' => array('title' => ev_gettext('Keyword(s)'), 'param' => 'keywords', 'quickfilter' => true), 'users' => array('title' => ev_gettext('Assigned'), 'param' => 'users', 'quickfilter' => true), 'iss_prc_id' => array('title' => ev_gettext('Category'), 'param' => 'category', 'quickfilter' => true), 'iss_sta_id' => array('title' => ev_gettext('Status'), 'param' => 'status', 'quickfilter' => true), 'iss_pre_id' => array('title' => ev_gettext('Release'), 'param' => 'release'), 'created_date' => array('title' => ev_gettext('Created Date'), 'param' => 'created_date', 'is_date' => true), 'updated_date' => array('title' => ev_gettext('Updated Date'), 'param' => 'updated_date', 'is_date' => true), 'last_response_date' => array('title' => ev_gettext('Last Response Date'), 'param' => 'last_response_date', 'is_date' => true), 'first_response_date' => array('title' => ev_gettext('First Response Date'), 'param' => 'first_response_date', 'is_date' => true), 'closed_date' => array('title' => ev_gettext('Closed Date'), 'param' => 'closed_date', 'is_date' => true), 'rows' => array('title' => ev_gettext('Rows Per Page'), 'param' => 'rows'), 'sort_by' => array('title' => ev_gettext('Sort By'), 'param' => 'sort_by'), 'sort_order' => array('title' => ev_gettext('Sort Order'), 'param' => 'sort_order'), 'hide_closed' => array('title' => ev_gettext('Hide Closed Issues'), 'param' => 'hide_closed'), 'show_authorized' => array('title' => ev_gettext('Authorized to Send Emails'), 'param' => 'show_authorized_issues'), 'show_notification_list' => array('title' => ev_gettext('In Notification List'), 'param' => 'show_notification_list_issues'), 'search_type' => array('title' => ev_gettext('Search Type'), 'param' => 'search_type'), 'reporter' => array('title' => ev_gettext('Reporter'), 'param' => 'reporter'), 'customer_id' => array('title' => ev_gettext('Customer'), 'param' => 'customer_id'), 'pro_id' => array('title' => ev_gettext('Product'), 'param' => 'product'));
     // add custom fields
     $custom_fields = Custom_Field::getFieldsByProject(Auth::getCurrentProject());
     if (count($custom_fields) > 0) {
         foreach ($custom_fields as $fld_id) {
             $field = Custom_Field::getDetails($fld_id);
             $fields['custom_field_' . $fld_id] = array('title' => $field['fld_title'], 'is_custom' => 1, 'fld_id' => $fld_id, 'fld_type' => $field['fld_type']);
         }
     }
     return $fields;
 }
Example #14
0
 /**
  * Processes the template and assigns common variables automatically.
  * 
  * @access	private
  */
 function processTemplate()
 {
     global $HTTP_SERVER_VARS;
     // determine the correct CSS file to use
     if (ereg('MSIE ([0-9].[0-9]{1,2})', @$HTTP_SERVER_VARS["HTTP_USER_AGENT"], $log_version)) {
         $user_agent = 'ie';
     } else {
         $user_agent = 'other';
     }
     $this->assign("user_agent", $user_agent);
     // create the list of projects
     $usr_id = Auth::getUserID();
     if ($usr_id != '') {
         $prj_id = Auth::getCurrentProject();
         if (!empty($prj_id)) {
             $role_id = User::getRoleByUser($usr_id, $prj_id);
             $this->assign("current_project", $prj_id);
             $this->assign("current_project_name", Auth::getCurrentProjectName());
             $has_customer_integration = Customer::hasCustomerIntegration($prj_id);
             $this->assign("has_customer_integration", $has_customer_integration);
             if ($has_customer_integration) {
                 $this->assign("customer_backend_name", Customer::getBackendImplementationName($prj_id));
             }
             if ($role_id == User::getRoleID('administrator') || $role_id == User::getRoleID('manager')) {
                 $this->assign("show_admin_link", true);
             }
             if ($role_id > 0) {
                 $this->assign("current_role", (int) $role_id);
                 $this->assign("current_role_name", User::getRole($role_id));
             }
         }
         $info = User::getNameEmail($usr_id);
         $this->assign("active_projects", Project::getAssocList($usr_id));
         $this->assign("current_full_name", $info["usr_full_name"]);
         $this->assign("current_email", $info["usr_email"]);
         $this->assign("current_user_id", $usr_id);
         $this->assign("is_current_user_clocked_in", User::isClockedIn($usr_id));
         $this->assign("roles", User::getAssocRoleIDs());
     }
     $this->assign("app_setup", Setup::load());
     $this->assign("app_setup_path", APP_SETUP_PATH);
     $this->assign("app_setup_file", APP_SETUP_FILE);
     $this->assign("application_version", APP_VERSION);
     $this->assign("application_title", APP_NAME);
     $this->assign("app_base_url", APP_BASE_URL);
     $this->assign("rel_url", APP_RELATIVE_URL);
     $this->assign("lang", APP_CURRENT_LANG);
     $this->assign("SID", SID);
     // now for the browser detection stuff
     Net_UserAgent_Detect::detect();
     $this->assign("browser", Net_UserAgent_Detect::_getStaticProperty('browser'));
     $this->assign("os", Net_UserAgent_Detect::_getStaticProperty('os'));
     // this is only used by the textarea resize script
     $js_script_name = str_replace('/', '_', str_replace('.php', '', $HTTP_SERVER_VARS['PHP_SELF']));
     $this->assign("js_script_name", $js_script_name);
     $this->assign("total_queries", $GLOBALS['TOTAL_QUERIES']);
     $this->assign(array("cell_color" => APP_CELL_COLOR, "light_color" => APP_LIGHT_COLOR, "middle_color" => APP_MIDDLE_COLOR, "dark_color" => APP_DARK_COLOR, "cycle" => APP_CYCLE_COLORS, "internal_color" => APP_INTERNAL_COLOR));
 }
Example #15
0
 /**
  * Method used to send an email from the user interface.
  *
  * @access  public
  * @return  integer 1 if it worked, -1 otherwise
  */
 function sendEmail($parent_sup_id = FALSE)
 {
     global $HTTP_POST_VARS, $HTTP_SERVER_VARS;
     // if we are replying to an existing email, set the In-Reply-To: header accordingly
     if ($parent_sup_id) {
         $in_reply_to = Support::getMessageIDByID($parent_sup_id);
     } else {
         $in_reply_to = false;
     }
     // get ID of whoever is sending this.
     $sender_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($HTTP_POST_VARS["from"]));
     if (empty($sender_usr_id)) {
         $sender_usr_id = false;
     }
     // get type of email this is
     if (!empty($HTTP_POST_VARS['type'])) {
         $type = $HTTP_POST_VARS['type'];
     } else {
         $type = '';
     }
     // remove extra 'Re: ' from subject
     $HTTP_POST_VARS['subject'] = Mail_API::removeExcessRe($HTTP_POST_VARS['subject'], true);
     $internal_only = false;
     $message_id = Mail_API::generateMessageID();
     // hack needed to get the full headers of this web-based email
     $full_email = Support::buildFullHeaders($HTTP_POST_VARS["issue_id"], $message_id, $HTTP_POST_VARS["from"], $HTTP_POST_VARS["to"], $HTTP_POST_VARS["cc"], $HTTP_POST_VARS["subject"], $HTTP_POST_VARS["message"], $in_reply_to);
     // email blocking should only be done if this is an email about an associated issue
     if (!empty($HTTP_POST_VARS['issue_id'])) {
         $user_info = User::getNameEmail(Auth::getUserID());
         // check whether the current user is allowed to send this email to customers or not
         if (!Support::isAllowedToEmail($HTTP_POST_VARS["issue_id"], $user_info['usr_email'])) {
             // add the message body as a note
             $HTTP_POST_VARS['blocked_msg'] = $full_email;
             $HTTP_POST_VARS['title'] = $HTTP_POST_VARS["subject"];
             $HTTP_POST_VARS['note'] = Mail_API::getCannedBlockedMsgExplanation() . $HTTP_POST_VARS["message"];
             Note::insert(Auth::getUserID(), $HTTP_POST_VARS["issue_id"]);
             Workflow::handleBlockedEmail(Issue::getProjectID($HTTP_POST_VARS['issue_id']), $HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS, 'web');
             return 1;
         }
     }
     // only send a direct email if the user doesn't want to add the Cc'ed people to the notification list
     if (@$HTTP_POST_VARS['add_unknown'] == 'yes') {
         if (!empty($HTTP_POST_VARS['issue_id'])) {
             // add the recipients to the notification list of the associated issue
             $recipients = array($HTTP_POST_VARS['to']);
             $recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
             for ($i = 0; $i < count($recipients); $i++) {
                 if (!empty($recipients[$i]) && !Notification::isIssueRoutingSender($HTTP_POST_VARS["issue_id"], $recipients[$i])) {
                     Notification::subscribeEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], Mail_API::getEmailAddress($recipients[$i]), array('emails'));
                 }
             }
         }
     } else {
         // Usually when sending out emails associated to an issue, we would
         // simply insert the email in the table and call the Notification::notifyNewEmail() method,
         // but on this case we need to actually send the email to the recipients that are not
         // already in the notification list for the associated issue, if any.
         // In the case of replying to an email that is not yet associated with an issue, then
         // we are always directly sending the email, without using any notification list
         // functionality.
         if (!empty($HTTP_POST_VARS['issue_id'])) {
             // send direct emails only to the unknown addresses, and leave the rest to be
             // catched by the notification list
             $from = Notification::getFixedFromHeader($HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS['from'], 'issue');
             // build the list of unknown recipients
             if (!empty($HTTP_POST_VARS['to'])) {
                 $recipients = array($HTTP_POST_VARS['to']);
                 $recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
             } else {
                 $recipients = Support::getRecipientsCC($HTTP_POST_VARS['cc']);
             }
             $unknowns = array();
             for ($i = 0; $i < count($recipients); $i++) {
                 if (!Notification::isSubscribedToEmails($HTTP_POST_VARS['issue_id'], $recipients[$i])) {
                     $unknowns[] = $recipients[$i];
                 }
             }
             if (count($unknowns) > 0) {
                 $to = array_shift($unknowns);
                 $cc = implode('; ', $unknowns);
                 // send direct emails
                 Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $to, $cc, $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id, $sender_usr_id);
             }
         } else {
             // send direct emails to all recipients, since we don't have an associated issue
             $project_info = Project::getOutgoingSenderAddress(Auth::getCurrentProject());
             // use the project-related outgoing email address, if there is one
             if (!empty($project_info['email'])) {
                 $from = Mail_API::getFormattedName(User::getFullName(Auth::getUserID()), $project_info['email']);
             } else {
                 // otherwise, use the real email address for the current user
                 $from = User::getFromHeader(Auth::getUserID());
             }
             // send direct emails
             Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $HTTP_POST_VARS['to'], $HTTP_POST_VARS['cc'], $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id);
         }
     }
     $t = array('customer_id' => 'NULL', 'issue_id' => $HTTP_POST_VARS["issue_id"] ? $HTTP_POST_VARS["issue_id"] : 0, 'ema_id' => $HTTP_POST_VARS['ema_id'], 'message_id' => $message_id, 'date' => Date_API::getCurrentDateGMT(), 'from' => $HTTP_POST_VARS['from'], 'to' => $HTTP_POST_VARS['to'], 'cc' => @$HTTP_POST_VARS['cc'], 'subject' => @$HTTP_POST_VARS['subject'], 'body' => $HTTP_POST_VARS['message'], 'full_email' => $full_email, 'has_attachment' => 0);
     // associate this new email with a customer, if appropriate
     if (Auth::getCurrentRole() == User::getRoleID('Customer')) {
         $customer_id = User::getCustomerID(Auth::getUserID());
         if (!empty($customer_id) && $customer_id != -1) {
             $t['customer_id'] = $customer_id;
         }
     }
     $structure = Mime_Helper::decode($full_email, true, false);
     $t['headers'] = $structure->headers;
     $res = Support::insertEmail($t, $structure, $sup_id);
     if (!empty($HTTP_POST_VARS["issue_id"])) {
         // need to send a notification
         Notification::notifyNewEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], $t, $internal_only, false, $type, $sup_id);
         // mark this issue as updated
         if (!empty($t['customer_id']) && $t['customer_id'] != 'NULL') {
             Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'customer action');
         } else {
             if (!empty($sender_usr_id) && User::getRoleByUser($sender_usr_id, Issue::getProjectID($HTTP_POST_VARS['issue_id'])) > User::getRoleID('Customer')) {
                 Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'staff response');
             } else {
                 Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'user response');
             }
         }
         // save a history entry for this
         History::add($HTTP_POST_VARS["issue_id"], Auth::getUserID(), History::getTypeID('email_sent'), 'Outgoing email sent by ' . User::getFullName(Auth::getUserID()));
         // also update the last_response_date field for the associated issue
         if (Auth::getCurrentRole() > User::getRoleID('Customer')) {
             $stmt = "UPDATE\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                         SET\n                            iss_last_response_date='" . Date_API::getCurrentDateGMT() . "'\n                         WHERE\n                            iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
             $GLOBALS["db_api"]->dbh->query($stmt);
             $stmt = "UPDATE\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                         SET\n                            iss_first_response_date='" . Date_API::getCurrentDateGMT() . "'\n                         WHERE\n                            iss_first_response_date IS NULL AND\n                            iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
             $GLOBALS["db_api"]->dbh->query($stmt);
         }
     }
     return 1;
 }
 function getList($fld_id)
 {
     return User::getActiveAssocList(Auth::getCurrentProject(), User::getRoleID("Standard User"));
 }
Example #17
0
 /**
  * Plot various stats charts
  *
  * @param string $plotType
  * @param bool $hide_closed
  * @return bool return false if no data is available
  */
 public function StatsChart($plotType, $hide_closed)
 {
     // don't bother if user has no access
     $prj_id = Auth::getCurrentProject();
     if (Auth::getCurrentRole() <= User::getRoleID('Reporter') && Project::getSegregateReporters($prj_id)) {
         return false;
     }
     $colors = array();
     switch ($plotType) {
         case 'status':
             $data = Stats::getAssocStatus($hide_closed);
             $graph_title = ev_gettext('Issues by Status');
             // use same colors as defined for statuses
             foreach ($data as $sta_title => $trash) {
                 $sta_id = Status::getStatusID($sta_title);
                 $status_details = Status::getDetails($sta_id);
                 $colors[] = $status_details['sta_color'];
             }
             break;
         case 'release':
             $data = Stats::getAssocRelease($hide_closed);
             $graph_title = ev_gettext('Issues by Release');
             break;
         case 'priority':
             $data = Stats::getAssocPriority($hide_closed);
             $graph_title = ev_gettext('Issues by Priority');
             break;
         case 'user':
             $data = Stats::getAssocUser($hide_closed);
             $graph_title = ev_gettext('Issues by Assignment');
             break;
         case 'category':
             $data = Stats::getAssocCategory($hide_closed);
             $graph_title = ev_gettext('Issues by Category');
             break;
         default:
             return false;
     }
     // check the values coming from the database and if they are all empty, then
     // output a pre-generated 'No Data Available' picture
     if (!Stats::hasData($data)) {
         return false;
     }
     $plot = $this->create(360, 200);
     $plot->SetImageBorderType('plain');
     $plot->SetTitle($graph_title);
     $plot->SetPlotType('pie');
     $plot->SetDataType('text-data-single');
     if ($colors) {
         $plot->SetDataColors($colors);
     }
     $legend = $dataValue = array();
     foreach ($data as $label => $count) {
         $legend[] = $label . ' (' . $count . ')';
         $dataValue[] = array($label, $count);
     }
     $plot->SetDataValues($dataValue);
     foreach ($legend as $label) {
         $plot->SetLegend($label);
     }
     return $plot->DrawGraph();
 }
Example #18
0
 public function getList($fld_id)
 {
     return User::getActiveAssocList(Auth::getCurrentProject(), User::getRoleID('Viewer'));
 }
Example #19
0
 /**
  * Method used to get the full list of issue IDs and their respective
  * titles.
  *
  * @param   string $extra_condition An extra condition in the WHERE clause
  * @return  array The list of issues
  */
 public function getAssocList($extra_condition = null)
 {
     $stmt = 'SELECT
                 iss_id,
                 iss_summary
              FROM
                 {{%issue}}
              WHERE
                 iss_prj_id=' . Auth::getCurrentProject();
     if (!empty($extra_condition)) {
         $stmt .= " AND {$extra_condition} ";
     }
     $stmt .= '
              ORDER BY
                 iss_id ASC';
     try {
         $res = DB_Helper::getInstance()->getPair($stmt);
     } catch (DbException $e) {
         return '';
     }
     return $res;
 }
Example #20
0
 /**
  * Returns the number of emails sent by a user in a time range.
  *
  * @param   string $usr_id The ID of the user
  * @param   integer $start The timestamp of the start date
  * @param   integer $end The timestamp of the end date
  * @param   boolean $associated If this should return emails associated with issues or non associated emails.
  * @return  integer The number of emails sent by the user.
  */
 public static function getSentEmailCountByUser($usr_id, $start, $end, $associated)
 {
     $usr_info = User::getNameEmail($usr_id);
     $stmt = 'SELECT
                 COUNT(sup_id)
              FROM
                 {{%support_email}},
                 {{%email_account}}
              WHERE
                 ema_id = sup_ema_id AND
                 ema_prj_id = ? AND
                 sup_date BETWEEN ? AND ? AND
                 sup_from LIKE ? AND
                 sup_iss_id ';
     if ($associated == true) {
         $stmt .= '!= 0';
     } else {
         $stmt .= '= 0';
     }
     $params = array(Auth::getCurrentProject(), $start, $end, "%{$usr_info['usr_email']}%");
     try {
         $res = DB_Helper::getInstance()->getOne($stmt, $params);
     } catch (DbException $e) {
         return '';
     }
     return $res;
 }
Example #21
0
            if (CRM::hasCustomerIntegration($prj_id)) {
                $sender_email = Mail_Helper::getEmailAddress($email_details['sup_from']);
                try {
                    $contact = $crm->getContactByEmail($sender_email);
                    $tpl->assign('contact_details', $contact->getDetails());
                } catch (CRMException $e) {
                }
            }
        }
    }
}
$tpl->assign(array('cats' => Category::getAssocList($prj_id), 'priorities' => Priority::getAssocList($prj_id), 'severities' => Severity::getList($prj_id), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'releases' => Release::getAssocList($prj_id), 'custom_fields' => Custom_Field::getListByProject($prj_id, 'report_form'), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'max_attachment_bytes' => Attachment::getMaxAttachmentSize(true), 'field_display_settings' => Project::getFieldDisplaySettings($prj_id), 'groups' => Group::getAssocList($prj_id), 'products' => Product::getList(false)));
$prefs = Prefs::get($usr_id);
$tpl->assign('user_prefs', $prefs);
$tpl->assign('zones', Date_Helper::getTimezoneList());
if (Auth::getCurrentRole() == User::getRoleID('Customer')) {
    $crm = CRM::getInstance(Auth::getCurrentProject());
    $customer_contact_id = User::getCustomerContactID($usr_id);
    $contact = $crm->getContact($customer_contact_id);
    $customer_id = Auth::getCurrentCustomerID();
    $customer = $crm->getCustomer($customer_id);
    // TODOCRM: Pull contacts via ajax when user selects contract
    $tpl->assign(array('customer_id' => $customer_id, 'contact_id' => $customer_contact_id, 'customer' => $customer, 'contact' => $contact));
}
$clone_iss_id = isset($_GET['clone_iss_id']) ? (int) $_GET['clone_iss_id'] : null;
if ($clone_iss_id && Access::canCloneIssue($clone_iss_id, $usr_id)) {
    $tpl->assign(Issue::getCloneIssueTemplateVariables($clone_iss_id));
} else {
    $tpl->assign('defaults', $_REQUEST);
}
$tpl->displayTemplate();
 /**
  * Method used to get the system-wide defaults.
  *
  * @return  string array of the default parameters
  */
 public static function getDefaults()
 {
     $defaults = array('host' => 'localhost', 'port' => 443, 'context' => '/cas', 'customer_id_attribute' => '', 'contact_id_attribute' => '', 'create_users' => null, 'default_role' => array());
     if (Auth::hasValidCookie(APP_COOKIE)) {
         // ensure there is entry for current project
         $prj_id = Auth::getCurrentProject();
         $defaults['default_role'][$prj_id] = 0;
     }
     return $defaults;
 }
Example #23
0
 public static function canExportData($usr_id)
 {
     $prj_id = Auth::getCurrentProject();
     if (User::isPartner($usr_id)) {
         $partner = Partner::canUserAccessFeature($usr_id, 'reports');
         if (is_bool($partner)) {
             return $partner;
         }
     }
     return true;
 }
Example #24
0
/**
 * Selects a mail queue entry from the table and returns the contents.
 *
 * @param   string $id The mail queue entry ID.
 * @return  A string containing the body.
 */
function getMailQueue($id)
{
    if (Auth::getCurrentRole() < User::getRoleID('Developer')) {
        return;
    }
    $res = Mail_Queue::getEntry($id);
    if (!Issue::canAccess($res['maq_iss_id'], $GLOBALS['usr_id'])) {
        return '';
    }
    if (empty($_GET['ec_id'])) {
        return $res['maq_body'];
    }
    return Link_Filter::processText(Auth::getCurrentProject(), nl2br(htmlspecialchars($res['maq_headers'] . "\n" . $res['maq_body'])));
}
Example #25
0
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// @(#) $Id$
//
include_once "config.inc.php";
include_once APP_INC_PATH . "class.template.php";
include_once APP_INC_PATH . "class.auth.php";
include_once APP_INC_PATH . "class.user.php";
include_once APP_INC_PATH . "class.note.php";
include_once APP_INC_PATH . "db_access.php";
$tpl = new Template_API();
$tpl->setTemplate("post_note.tpl.html");
Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true);
$prj_id = Auth::getCurrentProject();
$usr_id = Auth::getUserID();
@($issue_id = $HTTP_GET_VARS["issue_id"] ? $HTTP_GET_VARS["issue_id"] : $HTTP_POST_VARS["issue_id"]);
$details = Issue::getDetails($issue_id);
$tpl->assign("issue_id", $issue_id);
$tpl->assign("issue", $details);
if (!Issue::canAccess($issue_id, $usr_id)) {
    $tpl->setTemplate("permission_denied.tpl.html");
    $tpl->displayTemplate();
    exit;
}
if (@$HTTP_POST_VARS["cat"] == "post_note") {
    // change status
    if (!@empty($HTTP_POST_VARS['new_status'])) {
        $res = Issue::setStatus($issue_id, $HTTP_POST_VARS['new_status']);
        if ($res != -1) {
Example #26
0
 /**
  * @param int $week
  * @param string $start
  * @param string $end
  * @param bool $separate_closed
  * @return string
  * @access protected
  * @deprecated use getWeeklyReportData() and format data yourself
  */
 public function getWeeklyReport($week, $start, $end, $separate_closed)
 {
     $usr_id = Auth::getUserID();
     $week = abs($week);
     // we have to set a project so the template class works, even though the weekly report doesn't actually need it
     $projects = Project::getAssocList(Auth::getUserID());
     $prj_id = current(array_keys($projects));
     AuthCookie::setProjectCookie($prj_id);
     $prj_id = Auth::getCurrentProject();
     // figure out the correct week
     if (empty($start) || empty($end)) {
         $start = date('U') - Date_Helper::DAY * (date('w') - 1);
         if ($week > 0) {
             $start = $start - Date_Helper::WEEK * $week;
         }
         $end = date('Y-m-d', $start + Date_Helper::DAY * 6);
         $start = date('Y-m-d', $start);
     }
     if ($separate_closed) {
         // emulate smarty value for reports/weekly_data.tpl.tmpl:
         // {if $smarty.post.separate_closed == 1}
         $_POST['separate_closed'] = true;
     }
     $options = array('separate_closed' => $separate_closed);
     $tpl = new Template_Helper();
     $tpl->setTemplate('reports/weekly_data.tpl.html');
     $tpl->assign(array('report_type' => 'weekly', 'data' => Report::getWeeklyReport($usr_id, $prj_id, $start, $end, $options)));
     $ret = $tpl->getTemplateContents() . "\n";
     return $ret;
 }
 /**
  * Method used to get the first support email account associated
  * with the current activated project.
  *
  * @access  public
  * @param   integer $prj_id The ID of the project. If blank the currently project will be used.
  * @return  integer The email account ID
  */
 function getEmailAccount($prj_id = false)
 {
     if ($prj_id == false) {
         $prj_id = Auth::getCurrentProject();
     }
     $stmt = "SELECT\n                    ema_id\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account\n                 WHERE\n                    ema_prj_id=" . Misc::escapeInteger($prj_id) . "\n                 LIMIT\n                    0, 1";
     $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return "";
     } else {
         return $res;
     }
 }
    exit;
}
// TODO: move this query to some class
$sql = 'SELECT
            prc_id,
        	prc_title,
        	SUM(iss_dev_time) as dev_time
        FROM
        	{{%issue}},
        	{{%project_category}},
        	{{%status}}
        WHERE
        	iss_prc_id = prc_id AND
        	iss_sta_id = sta_id AND
        	sta_is_closed != 1 AND
        	iss_prj_id = ?
        GROUP BY
        	iss_prc_id';
try {
    $res = DB_Helper::getInstance()->getAll($sql, array(Auth::getCurrentProject()));
} catch (DbException $e) {
    return false;
}
$total = 0;
foreach ($res as $id => $row) {
    $total += $row['dev_time'];
    $res[$id]['dev_time'] = str_replace(' ', '&nbsp;', str_pad($row['dev_time'], 5, ' ', STR_PAD_LEFT));
}
$res[] = array('dev_time' => str_replace(' ', '&nbsp;', str_pad($total, 5, ' ', STR_PAD_LEFT)), 'prc_title' => 'Total');
$tpl->assign('data', $res);
$tpl->displayTemplate();
/*
 * This file is part of the Eventum (Issue Tracking System) package.
 *
 * @copyright (c) Eventum Team
 * @license GNU General Public License, version 2 or later (GPL-2+)
 *
 * For the full copyright and license information,
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
Auth::checkAuthentication();
if (!empty($_REQUEST['iss_id'])) {
    $fields = Custom_Field::getListByIssue(Auth::getCurrentProject(), $_REQUEST['iss_id']);
} else {
    $fields = Custom_Field::getListByProject(Auth::getCurrentProject(), $_REQUEST['form_type']);
}
$data = array();
foreach ($fields as $field) {
    $backend = Custom_Field::getBackend($field['fld_id']);
    if (is_object($backend) && is_subclass_of($backend, 'Dynamic_Custom_Field_Backend')) {
        $field['structured_data'] = $backend->getStructuredData();
        $data[] = $field;
    }
}
header('Content-Type: text/javascript; charset=UTF-8');
$tpl = new Template_Helper();
$tpl->setTemplate('js/dynamic_custom_field.tpl.js');
$tpl->assign('fields', $data);
$tpl->displayTemplate();
Example #30
0
 /**
  * Method used to get the list of users available in the system.
  *
  * @param   boolean $show_customers Whether to return customers or not
  * @return  array The list of users
  */
 public static function getList($show_customers, $show_inactive)
 {
     // FIXME: what about other statuses like "pending"?
     $stmt = 'SELECT
                 *
              FROM
                 {{%user}}
              WHERE
                 usr_id != ?';
     $params = array(APP_SYSTEM_USER_ID);
     if (!$show_inactive) {
         $stmt .= ' AND usr_status != ?';
         $params[] = 'inactive';
     }
     $stmt .= '
             ORDER BY
                 usr_status ASC,
                 usr_full_name ASC';
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, $params);
     } catch (DbException $e) {
         return '';
     }
     $data = array();
     foreach ($res as &$row) {
         $roles = Project::getAssocList($row['usr_id'], false, true);
         $role = current($roles);
         $role = $role['pru_role'];
         if ($show_customers == false && (@$roles[Auth::getCurrentProject()]['pru_role'] == self::getRoleID('Customer') || count($roles) == 1 && $role == self::getRoleID('Customer'))) {
             continue;
         }
         $row['roles'] = $roles;
         if (!empty($row['usr_grp_id'])) {
             $row['group_name'] = Group::getName($row['usr_grp_id']);
         }
         if (!empty($row['usr_par_code'])) {
             $row['partner_name'] = Partner::getName($row['usr_par_code']);
         }
         // add email aliases
         $row['aliases'] = User::getAliases($row['usr_id']);
         $data[] = $row;
     }
     return $data;
 }