public function __construct(CRM $crm, $level_id)
 {
     $this->crm = $crm;
     $this->connection =& $crm->getConnection();
     $this->level_id = $level_id;
     $this->load();
 }
Example #2
0
 /**
  * Constructs the object representing this contact and loads contact data.
  *
  * @param CRM $crm
  * @param string  $contact_id
  * @throws ContactNotFoundException
  */
 public function __construct(CRM $crm, $contact_id)
 {
     $this->crm = $crm;
     $this->connection =& $crm->getConnection();
     $this->contact_id = $contact_id;
     // attempt to load the data
     $this->load();
 }
Example #3
0
 private function processResult(&$data, $date_field, $issue_field)
 {
     $timezone = Date_Helper::getPreferredTimezone($this->usr_id);
     foreach ($data as &$res) {
         if (!Issue::canAccess($res[$issue_field], $this->usr_id)) {
             continue;
         }
         $res['customer'] = null;
         if ($this->crm) {
             try {
                 $customer = $this->crm->getCustomer(Issue::getCustomerID($res[$issue_field]));
                 $res['customer'] = $customer->getName();
             } catch (CRMException $e) {
             }
         }
         $res['date'] = Date_Helper::getFormattedDate($res[$date_field], $timezone);
         // need to decode From:, To: mail headers
         if (isset($res['sup_from'])) {
             $res['sup_from'] = Mime_Helper::fixEncoding($res['sup_from']);
         }
         if (isset($res['sup_to'])) {
             $res['sup_to'] = Mime_Helper::fixEncoding($res['sup_to']);
         }
     }
 }
 /**
  * Returns the columns that should be displayed for the specified page.
  * This method will remove columns that should not be displayed, due to
  * lack of customer integration or insufficient role.
  *
  * @param   integer $prj_id The ID of the project.
  * @param   string $page The page to return columns for.
  * @return  array An array of columns that should be displayed.
  */
 public static function getColumnsToDisplay($prj_id, $page)
 {
     static $returns;
     // poor man's caching system
     if (!empty($returns[$prj_id][$page])) {
         return $returns[$prj_id][$page];
     }
     $current_role = Auth::getCurrentRole();
     $data = self::getSelectedColumns($prj_id, $page);
     $has_customer_integration = CRM::hasCustomerIntegration($prj_id);
     $only_with_customers = array('iss_customer_id', 'support_level');
     // remove groups if there are no groups in the system.
     if (count(Group::getAssocList($prj_id)) < 1) {
         unset($data['iss_grp_id']);
     }
     // remove category column if there are no categories in the system
     if (count(Category::getAssocList($prj_id)) < 1) {
         unset($data['prc_title']);
     }
     // remove custom fields column if there are no custom fields
     if (count(Custom_Field::getFieldsToBeListed($prj_id)) < 1) {
         unset($data['custom_fields']);
     }
     // remove customer field if user has a role of customer
     if ($current_role == User::getRoleID('Customer')) {
         unset($data['iss_customer_id']);
     }
     foreach ($data as $field => $info) {
         // remove fields based on role
         if ($info['min_role'] > $current_role) {
             unset($data[$field]);
             continue;
         }
         // remove fields based on customer integration
         if (!$has_customer_integration && in_array($field, $only_with_customers)) {
             unset($data[$field]);
             continue;
         }
         // get title
         $data[$field] = self::getColumnInfo($page, $field);
         if (!isset($data[$field]['width'])) {
             $data[$field]['width'] = '';
         }
     }
     $returns[$prj_id][$page] = $data;
     return $data;
 }
Example #5
0
 /**
  * Method used to get the list of technical account managers for
  * a given customer ID.
  *
  * @return  array The list of account managers
  */
 public function getEventumAccountManagers()
 {
     $stmt = 'SELECT
                 cam_usr_id,
                 usr_email,
                 cam_type
              FROM
                 {{%customer_account_manager}},
                 {{%user}}
              WHERE
                 cam_usr_id=usr_id AND
                 cam_prj_id=? AND
                 cam_customer_id=?';
     $params = array($this->crm->getProjectID(), $this->customer_id);
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, $params);
     } catch (DbException $e) {
         return array();
     }
     if (empty($res)) {
         return array();
     }
     return $res;
 }
Example #6
0
// if currently selected release is in the past, manually add it to list
$releases = Release::getAssocList($prj_id);
if ($details['iss_pre_id'] != 0 && empty($releases[$details['iss_pre_id']])) {
    $releases = array($details['iss_pre_id'] => $details['pre_title']) + $releases;
}
if (Workflow::hasWorkflowIntegration($prj_id)) {
    $statuses = Workflow::getAllowedStatuses($prj_id, $issue_id);
    // if currently selected release is not on list, go ahead and add it.
} else {
    $statuses = Status::getAssocStatusList($prj_id, false);
}
if (!empty($details['iss_sta_id']) && empty($statuses[$details['iss_sta_id']])) {
    $statuses[$details['iss_sta_id']] = Status::getStatusTitle($details['iss_sta_id']);
}
$columns = array(0 => array(), 1 => array());
if (CRM::hasCustomerIntegration($prj_id) and !empty($details['iss_customer_id'])) {
    $columns[0][] = array('title' => 'Customer', 'field' => 'customer_0');
    $columns[1][] = array('title' => 'Customer Contract', 'field' => 'customer_1');
}
$categories = Category::getAssocList($prj_id);
if (count($categories) > 0) {
    $columns[0][] = array('title' => ev_gettext('Category'), 'data' => $details['prc_title'], 'field' => 'category');
}
$columns[0][] = array('title' => ev_gettext('Status'), 'data' => $details['sta_title'], 'data_bgcolor' => $details['status_color'], 'field' => 'status');
$severities = Severity::getAssocList($prj_id);
if (count($severities) > 0) {
    $columns[0][] = array('title' => ev_gettext('Severity'), 'data' => $details['sev_title'], 'field' => 'severity');
}
$priorities = Priority::getAssocList($prj_id);
if (count($priorities) > 0 && (!isset($issue_fields_display['priority']) || $issue_fields_display['priority'] != false)) {
    if (isset($issue_fields_display['priority']['min_role']) && $issue_fields_display['priority']['min_role'] > User::getRoleID('Customer')) {
Example #7
0
 /**
  * Returns data for the custom fields report, based on the field and options passed in.
  *
  * @param   integer $fld_id The id of the custom field.
  * @param   array $cfo_ids An array of option ids.
  * @param   string $group_by How the data should be grouped.
  * @param   string $start_date
  * @param   string $end_date
  * @param   boolean $list If the values should be listed out instead of just counted.
  * @param   string $interval The interval values should be grouped over time, empty (none) by default.
  * @param   integer $assignee The assignee the issue should belong to.
  * @return  array An array of data.
  */
 public static function getCustomFieldReport($fld_id, $cfo_ids, $group_by = 'issue', $start_date = null, $end_date = null, $list = false, $interval = null, $assignee = null)
 {
     $prj_id = Auth::getCurrentProject();
     $fld_id = (int) $fld_id;
     // get field values
     $options = Custom_Field::getOptions($fld_id, $cfo_ids);
     if ($group_by == 'customer') {
         $group_by_field = 'iss_customer_id';
     } else {
         $group_by_field = 'iss_id';
     }
     if ($assignee == -1) {
         $assignee = null;
     }
     $label_field = '';
     $interval_group_by_field = '';
     switch ($interval) {
         case 'day':
             $label_field = "CONCAT(YEAR(iss_created_date), '-', MONTH(iss_created_date), '-', DAY(iss_created_date))";
             $interval_group_by_field = 'CONCAT(YEAR(iss_created_date), MONTH(iss_created_date), DAY(iss_created_date))';
             break;
         case 'week':
             $label_field = "CONCAT(YEAR(iss_created_date), '/', WEEK(iss_created_date))";
             $interval_group_by_field = 'WEEK(iss_created_date)';
             break;
         case 'month':
             $label_field = "CONCAT(YEAR(iss_created_date), '/', MONTH(iss_created_date))";
             $interval_group_by_field = 'MONTH(iss_created_date)';
             break;
         case 'year':
             $label_field = 'YEAR(iss_created_date)';
             $interval_group_by_field = 'YEAR(iss_created_date)';
             break;
     }
     if ($list == true) {
         $params = array();
         $sql = "SELECT\n                        DISTINCT({$group_by_field}),\n                        iss_id,\n                        iss_summary,\n                        iss_customer_id,\n                        count(DISTINCT(iss_id)) as row_count,\n                        iss_private,\n                        fld_id";
         if ($label_field) {
             $sql .= ",\n                        {$label_field} as interval_label";
         }
         $sql .= '
                 FROM
                     {{%custom_field}},';
         if (count($options) > 0) {
             $sql .= '
                     {{%custom_field_option}},';
         }
         $sql .= '
                     {{%issue_custom_field}},
                     {{%issue}},
                     {{%issue_user}}
                 WHERE
                     fld_id = icf_fld_id AND';
         if (count($options) > 0) {
             $sql .= ' cfo_id = icf_value AND';
         }
         $sql .= '
                     icf_iss_id = iss_id AND
                     isu_iss_id = iss_id AND
                     icf_fld_id = ?';
         $params[] = $fld_id;
         if (count($options) > 0) {
             $ids = array_keys($options);
             $list = DB_Helper::buildList($ids);
             $sql .= " AND cfo_id IN({$list})";
             $params = array_merge($params, $ids);
         }
         if ($start_date && $end_date) {
             $sql .= " AND\niss_created_date BETWEEN ? AND ?";
             $params[] = $start_date;
             $params[] = $end_date;
         }
         if ($assignee) {
             $sql .= " AND\nisu_usr_id = ?";
             $params[] = $assignee;
         }
         $sql .= "\n                    GROUP BY\n                        {$group_by_field}\n                    ORDER BY";
         if ($label_field) {
             $sql .= "\n                        {$label_field} DESC,";
         }
         $sql .= '
                     row_count DESC';
         try {
             $res = DB_Helper::getInstance()->getAll($sql, $params);
         } catch (DbException $e) {
             return array();
         }
         if (CRM::hasCustomerIntegration($prj_id)) {
             $crm = CRM::getInstance($prj_id);
             $crm->processListIssuesResult($res);
             if ($group_by == 'issue') {
                 usort($res, function ($a, $b) {
                     if ($a['customer_title'] < $b['customer_title']) {
                         return -1;
                     } elseif ($a['customer_title'] > $b['customer_title']) {
                         return 1;
                     } else {
                         return 0;
                     }
                 });
             }
         }
         foreach ($res as &$row) {
             $row['field_value'] = Custom_Field::getDisplayValue($row['iss_id'], $row['fld_id']);
         }
         return $res;
     }
     $data = array();
     foreach ($options as $cfo_id => $value) {
         $params = array();
         $stmt = 'SELECT';
         if ($label_field != '') {
             $stmt .= "\n                        {$label_field} as label,";
         }
         $stmt .= "\n                        COUNT(DISTINCT {$group_by_field})\n                    FROM\n                        {{%issue_custom_field}},\n                        {{%issue}},\n                        {{%issue_user}}\n                    WHERE\n                        icf_iss_id = iss_id AND\n                        isu_iss_id = iss_id AND\n                        icf_fld_id = ? AND\n                        icf_value = ?";
         $params = array($fld_id, $cfo_id);
         if ($start_date && $end_date) {
             $stmt .= " AND\niss_created_date BETWEEN ? AND ?";
             $params[] = $start_date;
             $params[] = $end_date;
         }
         if ($assignee) {
             $stmt .= " AND\nisu_usr_id = ?";
             $params[] = $assignee;
         }
         if ($interval_group_by_field != '') {
             $stmt .= "\n                    GROUP BY\n                        {$interval_group_by_field}\n                    ORDER BY\n                        {$label_field} ASC";
             try {
                 $res = DB_Helper::getInstance()->fetchAssoc($stmt, $params);
             } catch (DbException $e) {
                 return array();
             }
         } else {
             try {
                 $res = DB_Helper::getInstance()->getOne($stmt, $params);
             } catch (DbException $e) {
                 return array();
             }
         }
         $data[$value] = $res;
     }
     // include count of all other values (used in pie chart)
     $list = DB_Helper::buildList($cfo_ids);
     $stmt = "SELECT\n                    COUNT(DISTINCT {$group_by_field})\n                FROM\n                    {{%custom_field_option}},\n                    {{%issue_custom_field}},\n                    {{%issue}}\n                WHERE\n                    cfo_id = icf_value AND\n                    icf_iss_id = iss_id AND\n                    cfo_id NOT IN({$list}) AND\n                    icf_fld_id = ?\n                    ";
     $params = $cfo_ids;
     $params[] = $fld_id;
     try {
         $res = DB_Helper::getInstance()->getOne($stmt, $params);
     } catch (DbException $e) {
         return array();
     }
     $data['All Others'] = $res;
     return $data;
 }
Example #8
0
 public function crmSignup($user, $member)
 {
     $CRM = new CRM();
     $res = $CRM->signup($user, $member);
     return $res;
 }
Example #9
0
 /**
  * Method used to get the details for a specific issue.
  *
  * @param   integer $issue_id The issue ID
  * @param   boolean $force_refresh If the cache should not be used.
  * @return  array The details for the specified issue
  */
 public static function getDetails($issue_id, $force_refresh = false)
 {
     static $returns;
     if (empty($issue_id)) {
         return '';
     }
     if (!empty($returns[$issue_id]) && $force_refresh != true) {
         return $returns[$issue_id];
     }
     $stmt = 'SELECT
                 {{%issue}}.*,
                 prj_title,
                 prc_title,
                 pre_title,
                 pri_title,
                 sev_title,
                 sta_title,
                 sta_abbreviation,
                 sta_color status_color,
                 sta_is_closed
              FROM
                 (
                 {{%issue}},
                 {{%project}}
                 )
              LEFT JOIN
                 {{%project_priority}}
              ON
                 iss_pri_id=pri_id
              LEFT JOIN
                 {{%project_severity}}
              ON
                 iss_sev_id=sev_id
              LEFT JOIN
                 {{%status}}
              ON
                 iss_sta_id=sta_id
              LEFT JOIN
                 {{%project_category}}
              ON
                 iss_prc_id=prc_id
              LEFT JOIN
                 {{%project_release}}
              ON
                 iss_pre_id=pre_id
              WHERE
                 iss_id=? AND
                 iss_prj_id=prj_id';
     try {
         $res = DB_Helper::getInstance()->getRow($stmt, array($issue_id));
     } catch (DbException $e) {
         return '';
     }
     if (empty($res)) {
         return '';
     }
     $created_date_ts = Date_Helper::getUnixTimestamp($res['iss_created_date'], Date_Helper::getDefaultTimezone());
     // get customer information, if any
     if (!empty($res['iss_customer_id']) && CRM::hasCustomerIntegration($res['iss_prj_id'])) {
         $crm = CRM::getInstance($res['iss_prj_id']);
         try {
             $customer = $crm->getCustomer($res['iss_customer_id']);
             $contract = $crm->getContract($res['iss_customer_contract_id']);
             $res['contact_local_time'] = Date_Helper::getFormattedDate(Date_Helper::getCurrentDateGMT(), $res['iss_contact_timezone']);
             $res['customer'] = $customer;
             $res['contract'] = $contract;
             $res['contact'] = $crm->getContact($res['iss_customer_contact_id']);
             // TODOCRM: Deal with incidents
             //                    $res['redeemed_incidents'] = Customer::getRedeemedIncidentDetails($res['iss_prj_id'], $res['iss_id']);
             $max_first_response_time = $contract->getMaximumFirstResponseTime($issue_id);
             $res['max_first_response_time'] = Misc::getFormattedTime($max_first_response_time / 60);
             if (empty($res['iss_first_response_date'])) {
                 $first_response_deadline = $created_date_ts + $max_first_response_time;
                 if (time() <= $first_response_deadline) {
                     $res['max_first_response_time_left'] = Date_Helper::getFormattedDateDiff($first_response_deadline, time());
                 } else {
                     $res['overdue_first_response_time'] = Date_Helper::getFormattedDateDiff(time(), $first_response_deadline);
                 }
             }
         } catch (CRMException $e) {
             // TODOCRM: Log exception?
         }
     }
     $res['iss_original_description'] = $res['iss_description'];
     $res['iss_original_percent_complete'] = $res['iss_percent_complete'];
     $res['iss_description'] = nl2br(htmlspecialchars($res['iss_description']));
     $res['iss_resolution'] = Resolution::getTitle($res['iss_res_id']);
     $res['iss_impact_analysis'] = nl2br(htmlspecialchars($res['iss_impact_analysis']));
     $res['iss_created_date_ts'] = $created_date_ts;
     $res['assignments'] = @implode(', ', array_values(self::getAssignedUsers($res['iss_id'])));
     list($res['authorized_names'], $res['authorized_repliers']) = Authorized_Replier::getAuthorizedRepliers($res['iss_id']);
     $temp = self::getAssignedUsersStatus($res['iss_id']);
     $res['has_inactive_users'] = 0;
     $res['assigned_users'] = array();
     $res['assigned_inactive_users'] = array();
     foreach ($temp as $usr_id => $usr_status) {
         if (!User::isActiveStatus($usr_status)) {
             $res['assigned_inactive_users'][] = $usr_id;
             $res['has_inactive_users'] = 1;
         } else {
             $res['assigned_users'][] = $usr_id;
         }
     }
     if (@in_array(Auth::getUserID(), $res['assigned_users'])) {
         $res['is_current_user_assigned'] = 1;
     } else {
         $res['is_current_user_assigned'] = 0;
     }
     $res['associated_issues_details'] = self::getAssociatedIssuesDetails($res['iss_id']);
     $res['associated_issues'] = self::getAssociatedIssues($res['iss_id']);
     $res['reporter'] = User::getFullName($res['iss_usr_id']);
     if (empty($res['iss_updated_date'])) {
         $res['iss_updated_date'] = $res['iss_created_date'];
     }
     $res['estimated_formatted_time'] = Misc::getFormattedTime($res['iss_dev_time']);
     if (Release::isAssignable($res['iss_pre_id'])) {
         $release = Release::getDetails($res['iss_pre_id']);
         $res['pre_title'] = $release['pre_title'];
         $res['pre_status'] = $release['pre_status'];
     }
     // need to return the list of issues that are duplicates of this one
     $res['duplicates'] = self::getDuplicateList($res['iss_id']);
     $res['duplicates_details'] = self::getDuplicateDetailsList($res['iss_id']);
     // also get the issue title of the duplicated issue
     if (!empty($res['iss_duplicated_iss_id'])) {
         $res['duplicated_issue'] = self::getDuplicatedDetails($res['iss_duplicated_iss_id']);
     }
     // get group information
     if (!empty($res['iss_grp_id'])) {
         $res['group'] = Group::getDetails($res['iss_grp_id']);
     }
     // get quarantine issue
     $res['quarantine'] = self::getQuarantineInfo($res['iss_id']);
     $res['products'] = Product::getProductsByIssue($res['iss_id']);
     $returns[$issue_id] = $res;
     return $res;
 }
Example #10
0
if ($role_id < User::getRoleID('administrator')) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
$tpl->assign('project_list', Project::getAll());
if (@$_POST['cat'] == 'new') {
    $res = Status::insertCustomization($_POST['project'], $_POST['status'], $_POST['date_field'], $_POST['label']);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the customization was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the new customization.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this new customization'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = Status::updateCustomization($_POST['id'], $_POST['project'], $_POST['status'], $_POST['date_field'], $_POST['label']);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the customization was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the customization information.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this customization.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    $res = Status::removeCustomization(@$_POST['items']);
    Misc::mapMessages($res, array(true => array(ev_gettext('Thank you, the customization was deleted successfully.'), Misc::MSG_INFO), false => array(ev_gettext('An error occurred while trying to delete the customization information.'), Misc::MSG_ERROR)));
}
if (@$_GET['cat'] == 'edit') {
    $details = Status::getCustomizationDetails($_GET['id']);
    $tpl->assign(array('info' => $details, 'project_id' => $details['psd_prj_id'], 'status_list' => Status::getAssocStatusList($details['psd_prj_id'], true)));
}
$display_customer_fields = false;
@($prj_id = $_POST['prj_id'] ? $_POST['prj_id'] : $_GET['prj_id']);
if (!empty($prj_id)) {
    $tpl->assign('status_list', Status::getAssocStatusList($prj_id, true));
    $tpl->assign('project_id', $prj_id);
    $display_customer_fields = CRM::hasCustomerIntegration($prj_id);
}
$tpl->assign('date_fields', Issue::getDateFieldsAssocList($display_customer_fields));
$tpl->assign('project_list', Project::getAll());
$tpl->assign('list', Status::getCustomizationList());
$tpl->displayTemplate();
Example #11
0
 /**
  * @static
  * @return Contact
  */
 public static function getCurrentContact()
 {
     $crm = CRM::getInstance(self::getCurrentProject());
     return $crm->getContact(User::getCustomerContactID(self::getUserID()));
 }
Example #12
0
 * 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';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/projects.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_MANAGER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
if (@$_POST['cat'] == 'new') {
    Misc::mapMessages(Project::insert(), array(1 => array(ev_gettext('Thank you, the project was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the new project.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this new project.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    Misc::mapMessages(Project::update(), array(1 => array(ev_gettext('Thank you, the project was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the project information.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this project.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    Misc::mapMessages(Project::remove(), array(1 => array(ev_gettext('Thank you, the project was deleted successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to delete the project.'), Misc::MSG_ERROR)));
}
$tpl->assign('active_projects', Project::getAssocList(Auth::getUserID(), true));
if (@$_GET['cat'] == 'edit') {
    $tpl->assign('info', Project::getDetails($_GET['id']));
}
$tpl->assign('list', Project::getList());
$tpl->assign('user_options', User::getActiveAssocList());
$tpl->assign('status_options', Status::getAssocList());
$tpl->assign('customer_backends', CRM::getBackendList());
$tpl->assign('workflow_backends', Workflow::getBackendList());
$tpl->displayTemplate();
Example #13
0
Auth::checkAuthentication(APP_COOKIE);
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('manager')) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
if (@$_POST['cat'] == 'new') {
    $res = CRM::insertNote($_POST['project'], $_POST['customer'], $_POST['note']);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the note was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the new note.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = CRM::updateNote($_POST['id'], $_POST['project'], $_POST['customer'], $_POST['note']);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the note was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the note.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    $res = CRM::removeNotes($_POST['items']);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the note was deleted successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to delete the note.'), Misc::MSG_ERROR)));
} elseif (!empty($_GET['prj_id'])) {
    $tpl->assign('info', array('cno_prj_id' => $_GET['prj_id']));
    $tpl->assign('customers', CRM::getInstance($_GET['prj_id'])->getCustomerAssocList());
}
if (@$_GET['cat'] == 'edit') {
    $info = CRM::getNoteDetailsByID($_GET['id']);
    if (!empty($_GET['prj_id'])) {
        $info['cno_prj_id'] = $_GET['prj_id'];
    }
    $tpl->assign('customers', CRM::getInstance($info['cno_prj_id'])->getCustomerAssocList());
    $tpl->assign('info', $info);
}
$tpl->assign('list', CRM::getNoteList());
$tpl->assign('project_list', Project::getAll(false));
$tpl->displayTemplate();
Example #14
0
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/issue_auto_creation.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
@($ema_id = $_POST['ema_id'] ? $_POST['ema_id'] : $_GET['ema_id']);
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('administrator')) {
    Misc::setMessage('Sorry, you are not allowed to access this page.', Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
$prj_id = Email_Account::getProjectID($ema_id);
if (@$_POST['cat'] == 'update') {
    @Email_Account::updateIssueAutoCreation($ema_id, $_POST['issue_auto_creation'], $_POST['options']);
}
// load the form fields
$tpl->assign('info', Email_Account::getDetails($ema_id));
$tpl->assign('cats', Category::getAssocList($prj_id));
$tpl->assign('priorities', Priority::getList($prj_id));
$tpl->assign('users', Project::getUserAssocList($prj_id, 'active'));
$tpl->assign('options', Email_Account::getIssueAutoCreationOptions($ema_id));
$tpl->assign('ema_id', $ema_id);
$tpl->assign('prj_title', Project::getName($prj_id));
$tpl->assign('uses_customer_integration', CRM::hasCustomerIntegration($prj_id));
$tpl->displayTemplate();
 /**
  * Processes the template and assign common variables automatically.
  * @return $this
  */
 private function processTemplate()
 {
     $core = array('rel_url' => APP_RELATIVE_URL, 'base_url' => APP_BASE_URL, 'app_title' => APP_NAME, 'app_version' => APP_VERSION, 'app_setup' => Setup::load(), 'messages' => Misc::getMessages(), 'roles' => User::getAssocRoleIDs(), 'auth_backend' => APP_AUTH_BACKEND, 'current_url' => $_SERVER['PHP_SELF']);
     // If VCS version is present "Eventum 2.3.3-148-g78b3368", link ref to github
     $vcsVersion = self::getVcsVersion();
     if ($vcsVersion) {
         $link = "https://github.com/eventum/eventum/commit/{$vcsVersion}";
         $core['application_version_link'] = $link;
         // append VCS version if not yet there
         if (!preg_match('/-g[0-9a-f]+$/', APP_VERSION)) {
             $core['app_version'] = "v{$core['app_version']}-g{$vcsVersion}";
         }
     }
     $usr_id = Auth::getUserID();
     if ($usr_id) {
         $core['user'] = User::getDetails($usr_id);
         $prj_id = Auth::getCurrentProject();
         $setup = Setup::load();
         if (!empty($prj_id)) {
             $role_id = User::getRoleByUser($usr_id, $prj_id);
             $has_crm = CRM::hasCustomerIntegration($prj_id);
             $core = $core + array('project_id' => $prj_id, 'project_name' => Auth::getCurrentProjectName(), 'has_crm' => $has_crm, 'current_role' => $role_id, 'current_role_name' => User::getRole($role_id), 'feature_access' => Access::getFeatureAccessArray($usr_id));
             if ($has_crm) {
                 $crm = CRM::getInstance($prj_id);
                 $core['crm_template_path'] = $crm->getTemplatePath();
                 if ($role_id == User::getRoleID('Customer')) {
                     try {
                         $contact = $crm->getContact($core['user']['usr_customer_contact_id']);
                         $core['allowed_customers'] = $contact->getCustomers();
                         $core['current_customer'] = $crm->getCustomer(Auth::getCurrentCustomerID(false));
                     } catch (CRMException $e) {
                     }
                 }
             }
         }
         $info = User::getDetails($usr_id);
         $raw_projects = Project::getAssocList(Auth::getUserID(), false, true);
         $active_projects = array();
         foreach ($raw_projects as $prj_id => $prj_info) {
             if ($prj_info['status'] == 'archived') {
                 $prj_info['prj_title'] .= ' ' . ev_gettext('(archived)');
             }
             $active_projects[$prj_id] = $prj_info['prj_title'];
         }
         $core = $core + array('active_projects' => $active_projects, 'current_full_name' => $info['usr_full_name'], 'current_email' => $info['usr_email'], 'current_user_id' => $usr_id, 'current_user_datetime' => Date_Helper::getISO8601date('now', '', true), 'is_current_user_clocked_in' => User::isCLockedIn($usr_id), 'is_anon_user' => Auth::isAnonUser(), 'is_current_user_partner' => !empty($info['usr_par_code']), 'roles' => User::getAssocRoleIDs(), 'current_user_prefs' => Prefs::get(Auth::getUserID()));
         $this->assign('current_full_name', $core['user']['usr_full_name']);
         $this->assign('current_email', $core['user']['usr_email']);
         $this->assign('current_user_id', $usr_id);
         $this->assign('handle_clock_in', $setup['handle_clock_in'] == 'enabled');
         $this->assign('is_current_user_clocked_in', User::isClockedIn($usr_id));
         $this->assign('roles', User::getAssocRoleIDs());
     }
     $this->assign('core', $core);
     return $this;
 }
Example #16
0
function checkCustomerAuthentication($prj_id)
{
    if (CRM::hasCustomerIntegration($prj_id)) {
        $crm = CRM::getInstance($prj_id);
        // check if customer is expired
        $usr_id = Auth::getUserID();
        $contact_id = User::getCustomerContactID($usr_id);
        if (User::getRoleByUser($usr_id, $prj_id) == User::ROLE_CUSTOMER) {
            $crm->authenticateCustomer();
        }
    }
}
Example #17
0
 /**
  * Method used to get the list of associated support levels for a given
  * FAQ entry.
  *
  * @param   integer $prj_id The project ID
  * @param   integer $faq_id The FAQ ID
  * @return  array The list of projects
  */
 public function getAssociatedSupportLevels($prj_id, $faq_id)
 {
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         $stmt = 'SELECT
                     fsl_support_level_id
                  FROM
                     {{%faq_support_level}}
                  WHERE
                     fsl_faq_id=?';
         $ids = DB_Helper::getInstance()->getColumn($stmt, array($faq_id));
         $t = array();
         $levels = $crm->getSupportLevelAssocList();
         foreach ($levels as $support_level_id => $support_level) {
             if (in_array($support_level_id, $ids)) {
                 $t[$support_level_id] = $support_level;
             }
         }
         return $t;
     } else {
         return array();
     }
 }
Example #18
0
 /**
  * Attach uploaded files to an issue
  * It also notifies any subscribers of this new attachment.
  *
  * @param int $issue_id The issue ID
  * @param int $usr_id The user ID
  * @param int[] $iaf_ids attachment file id-s to attach
  * @param boolean $internal_only Whether this attachment is supposed to be internal only or not
  * @param string $file_description File description text
  * @param string $unknown_user The email of the user who originally sent this email, who doesn't have an account.
  * @param integer $associated_note_id The note ID that these attachments should be associated with
  */
 public static function attachFiles($issue_id, $usr_id, $iaf_ids, $internal_only, $file_description, $unknown_user = null, $associated_note_id = null)
 {
     if (!$iaf_ids) {
         throw new LogicException('No attachment ids');
     }
     $attachment_id = self::add($issue_id, $usr_id, $file_description, $internal_only, $unknown_user, $associated_note_id);
     self::associateFiles($attachment_id, $iaf_ids);
     Issue::markAsUpdated($issue_id, 'file uploaded');
     History::add($issue_id, $usr_id, 'attachment_added', 'Attachment uploaded by {user}', array('user' => User::getFullName($usr_id)));
     // if there is customer integration, mark last customer action
     $prj_id = Issue::getProjectID($issue_id);
     $has_crm = CRM::hasCustomerIntegration($prj_id);
     $is_customer = User::getRoleByUser($usr_id, $prj_id) == User::ROLE_CUSTOMER;
     if ($has_crm && $is_customer) {
         Issue::recordLastCustomerAction($issue_id);
     }
     Workflow::handleAttachment($prj_id, $issue_id, $usr_id);
     Notification::notify($issue_id, 'files', $attachment_id, $internal_only);
 }
 /**
  * method Delete()
  * Delete a record
  */
 function Delete($param)
 {
     try {
         // get the parameter $key
         $key = $param['key'];
         // open a transaction with database 'samples'
         TTransaction::open('db_crmbf');
         // instantiates object Customer
         $customer = new CRM($key);
         // deletes the object from the database
         $customer->delete();
         // close the transaction
         TTransaction::close();
         // reload the listing
         $this->onReload($param);
         // shows the success message
         new TMessage('info', "Registro Deletado");
     } catch (Exception $e) {
         // in case of exception
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
Example #20
0
    $tpl->displayTemplate();
    exit;
}
if (@$_POST['cat'] == 'new') {
    $res = CRM::insertAccountManager();
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the account manager was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the the account manager.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = CRM::updateAccountManager();
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the account manager was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the the account manager.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    CRM::removeAccountManager();
} elseif (!empty($_GET['prj_id'])) {
    $tpl->assign('info', array('cam_prj_id' => $_GET['prj_id']));
    $crm = CRM::getInstance($_GET['prj_id']);
    $tpl->assign('customers', $crm->getCustomerAssocList());
}
if (@$_GET['cat'] == 'edit') {
    $info = CRM::getAccountManagerDetails($_GET['id']);
    if (!empty($_GET['prj_id'])) {
        $info['cam_prj_id'] = $_GET['prj_id'];
    }
    $tpl->assign('customers', CRM::getInstance($info['cam_prj_id'])->getCustomerAssocList());
    $tpl->assign('user_options', User::getActiveAssocList($info['cam_prj_id'], User::ROLE_CUSTOMER));
    $tpl->assign('info', $info);
}
$tpl->assign('list', CRM::getAccountManagerList());
if (!empty($_REQUEST['prj_id'])) {
    $tpl->assign('user_options', User::getActiveAssocList($_REQUEST['prj_id'], User::ROLE_CUSTOMER));
}
$tpl->assign('project_list', Project::getAll(false));
$tpl->displayTemplate();
Example #21
0
 /**
  * @param int $issue_id
  * @param bool $redeemed_only
  * @return array
  * @access protected
  */
 public function getIncidentTypes($issue_id, $redeemed_only)
 {
     $prj_id = Issue::getProjectID($issue_id);
     AuthCookie::setProjectCookie($prj_id);
     // FIXME: $customer_id unused
     $customer_id = Issue::getCustomerID($issue_id);
     if (!CRM::hasCustomerIntegration($prj_id)) {
         // no customer integration
         throw new RemoteApiException("No customer integration for issue #{$issue_id}");
     }
     $crm = CRM::getInstance($prj_id);
     // FIXME: $all_types unused
     $all_types = $crm->getIncidentTypes();
     $contract = $crm->getContract(Issue::getContractID($issue_id));
     if (!$contract->hasPerIncident()) {
         // check if is per incident contract
         throw new RemoteApiException("Customer for issue #{$issue_id} does not have a per-incident contract");
     }
     $incidents = $contract->getIncidents();
     foreach ($incidents as $type_id => $type_details) {
         $is_redeemed = $contract->isRedeemedIncident($issue_id, $type_id);
         if ($redeemed_only && !$is_redeemed || !$redeemed_only && $is_redeemed) {
             unset($incidents[$type_id]);
         }
     }
     return $incidents;
 }
Example #22
0
 /**
  * Returns an array of active filters
  *
  * @param   array $options The options array
  * @return array
  */
 public static function getActiveFilters($options)
 {
     $prj_id = Auth::getCurrentProject();
     $filter_info = self::getFiltersInfo();
     $return = array();
     foreach ($filter_info as $filter_key => $filter) {
         $display = false;
         if (isset($filter['param']) && isset($options[$filter['param']])) {
             $filter_details = $options[$filter['param']];
         }
         if (isset($filter['is_custom'])) {
             // custom fields
             $fld_id = $filter['fld_id'];
             if (!isset($options['custom_field'][$fld_id]) || empty($options['custom_field'][$fld_id])) {
                 continue;
             } elseif ($filter['fld_type'] == 'date' && empty($options['custom_field'][$fld_id]['Year'])) {
                 continue;
             } elseif ($filter['fld_type'] == 'integer') {
                 if (!isset($options['custom_field'][$fld_id]['value']) || empty($options['custom_field'][$fld_id]['value'])) {
                     continue;
                 } else {
                     $filter_details = $options['custom_field'][$fld_id];
                     switch ($filter_details['filter_type']) {
                         case 'ge':
                             $display = ev_gettext('%1$s or greater', $filter_details['value']);
                             break;
                         case 'le':
                             $display = ev_gettext('%1$s or less', $filter_details['value']);
                             break;
                         case 'gt':
                             $display = ev_gettext('Greater than %1$s', $filter_details['value']);
                             break;
                         case 'lt':
                             $display = ev_gettext('Less than %1$s', $filter_details['value']);
                             break;
                         default:
                             $display = $filter_details['value'];
                     }
                 }
             } elseif (in_array($filter['fld_type'], array('multiple', 'combo'))) {
                 $display = implode(', ', Custom_Field::getOptions($fld_id, $options['custom_field'][$fld_id]));
             } else {
                 $display = $options['custom_field'][$fld_id];
             }
         } elseif (!isset($options[$filter['param']]) || empty($options[$filter['param']]) || in_array($filter_key, array('sort_order', 'sort_by', 'rows', 'search_type'))) {
             continue;
         } elseif (isset($filter['is_date']) && $filter['is_date'] == true) {
             if (!empty($filter_details['Year']) || isset($filter_details['time_period'])) {
                 switch ($filter_details['filter_type']) {
                     case 'in_past':
                         $display = ev_gettext('In Past %1$s hours', $filter_details['time_period']);
                         break;
                     case 'null':
                         $display = ev_gettext('Is NULL');
                         break;
                     case 'between':
                         $end = $options[$filter['param'] . '_end'];
                         $display = ev_gettext('Is between %1$s-%2$s-%3$s AND %4$s-%5$s-%6$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day'], $end['Year'], $end['Month'], $end['Day']);
                         break;
                     case 'greater':
                         $display = ev_gettext('Is greater than %1$s-%2$s-%3$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day']);
                         break;
                     case 'less':
                         $display = ev_gettext('Is less than %1$s-%2$s-%3$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day']);
                 }
             }
         } elseif ($filter['param'] == 'status') {
             $statuses = Status::getAssocStatusList($prj_id);
             $display = $statuses[$filter_details];
         } elseif ($filter['param'] == 'category') {
             $categories = Category::getAssocList($prj_id);
             if (is_array($filter_details)) {
                 $active_categories = array();
                 foreach ($filter_details as $category) {
                     $active_categories[] = $categories[$category];
                 }
                 $display = implode(', ', $active_categories);
             } else {
                 $display = $categories[$filter_details];
             }
         } elseif ($filter['param'] == 'priority') {
             $priorities = Priority::getAssocList($prj_id);
             $display = $priorities[$filter_details];
         } elseif ($filter['param'] == 'severity') {
             $severities = Severity::getAssocList($prj_id);
             $display = $severities[$filter_details];
         } elseif ($filter['param'] == 'users') {
             if ($filter_details == -1) {
                 $display = ev_gettext('un-assigned');
             } elseif ($filter_details == -2) {
                 $display = ev_gettext('myself and un-assigned');
             } elseif ($filter_details == -3) {
                 $display = ev_gettext('myself and my group');
             } elseif ($filter_details == -4) {
                 $display = ev_gettext('myself, un-assigned and my group');
             } elseif (substr($filter_details, 0, 3) == 'grp') {
                 $display = ev_gettext('%1$s Group', Group::getName(substr($filter_details, 4)));
             } else {
                 $display = User::getFullName($filter_details);
             }
         } elseif ($filter['param'] == 'hide_closed') {
             if ($filter_details == true) {
                 $display = ev_gettext('Yes');
             }
         } elseif ($filter['param'] == 'reporter') {
             $display = User::getFullName($filter_details);
         } elseif ($filter['param'] == 'release') {
             $display = Release::getTitle($filter_details);
         } elseif ($filter['param'] == 'customer_id') {
             try {
                 $crm = CRM::getInstance($prj_id);
                 $customer = $crm->getCustomer($filter_details);
                 $display = $customer->getName();
             } catch (CRMException $e) {
                 $display = $filter_details;
             }
         } elseif ($filter['param'] == 'product') {
             $display = Product::getTitle($filter_details);
         } else {
             $display = $filter_details;
         }
         if ($display != false) {
             $return[$filter['title']] = array('value' => $display, 'remove_link' => 'list.php?view=clearandfilter&' . self::buildUrl($filter_info, $options, $filter_key, true));
         }
     }
     return $return;
 }
Example #23
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();
Example #24
0
$tpl->setTemplate('select_customer.tpl.html');
session_start();
// check if cookies are enabled, first of all
if (!Auth::hasCookieSupport(APP_COOKIE)) {
    Auth::redirect('index.php?err=11');
}
if (!Auth::hasValidCookie(APP_COOKIE)) {
    Auth::redirect('index.php?err=5');
}
$prj_id = Auth::getCurrentProject();
$usr_id = Auth::getUserID();
$contact_id = User::getCustomerContactID($usr_id);
if (!CRM::hasCustomerIntegration($prj_id) || empty($contact_id)) {
    Auth::redirect('main.php');
}
$crm = CRM::getInstance($prj_id);
$contact = $crm->getContact($contact_id);
$customers = $contact->getCustomers();
if (isset($_REQUEST['customer_id'])) {
    $customer_id = $_REQUEST['customer_id'];
    if (in_array($customer_id, array_keys($customers))) {
        Auth::setCurrentCustomerID($customer_id);
        if (!empty($_POST['url'])) {
            Auth::redirect($_REQUEST['url']);
        } else {
            Auth::redirect('main.php');
        }
    }
}
$tpl->assign('customers', $customers);
$tpl->displayTemplate();
Example #25
0
 /**
  * Method to determine if user can access a particular issue
  *
  * @param   integer $issue_id The ID of the issue.
  * @param   integer $usr_id The ID of the user
  * @return  boolean If the user can access the issue
  */
 public static function canAccessIssue($issue_id, $usr_id)
 {
     static $access;
     if (empty($issue_id)) {
         return false;
     }
     if (isset($access[$issue_id . '-' . $usr_id])) {
         return $access[$issue_id . '-' . $usr_id];
     }
     $details = Issue::getDetails($issue_id);
     if (empty($details)) {
         return true;
     }
     $usr_details = User::getDetails($usr_id);
     $usr_role = User::getRoleByUser($usr_id, $details['iss_prj_id']);
     $prj_id = $details['iss_prj_id'];
     $can_access_contract = false;
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         try {
             if (!empty($usr_details['usr_customer_contact_id']) && !empty($details['iss_customer_contract_id'])) {
                 $contact = $crm->getContact($usr_details['usr_customer_contact_id']);
                 $can_access_contract = $contact->canAccessContract($crm->getContract($details['iss_customer_contract_id']));
             }
         } catch (CRMException $e) {
             // TODOCRM: Log exception?
         }
     }
     if (empty($usr_role)) {
         // check if they are even allowed to access the project
         $return = false;
     } elseif (CRM::hasCustomerIntegration($details['iss_prj_id']) && $usr_role == User::getRoleID('Customer') && $can_access_contract === false) {
         // check customer permissions
         $return = false;
     } elseif (!empty($usr_details['usr_par_code']) && !Partner::isPartnerEnabledForIssue($usr_details['usr_par_code'], $issue_id)) {
         // check if the user is a partner
         $return = false;
     } elseif ($details['iss_private'] == 1) {
         // check if the issue is even private
         // check role, reporter, assignment and group
         if ($usr_role > User::getRoleID('Developer')) {
             $return = true;
         } elseif ($details['iss_usr_id'] == $usr_id) {
             $return = true;
         } elseif (Issue::isAssignedToUser($issue_id, $usr_id)) {
             $return = true;
         } elseif (!empty($details['iss_grp_id']) && !empty($usr_details['usr_grp_id']) && $details['iss_grp_id'] == $usr_details['usr_grp_id']) {
             $return = true;
         } elseif (Authorized_Replier::isUserAuthorizedReplier($issue_id, $usr_id)) {
             $return = true;
         } else {
             $return = false;
         }
     } elseif (Auth::getCurrentRole() == User::getRoleID('Reporter') && Project::getSegregateReporters($prj_id) && $details['iss_usr_id'] != $usr_id && !Authorized_Replier::isUserAuthorizedReplier($issue_id, $usr_id)) {
         return false;
     } else {
         $return = true;
     }
     $access[$issue_id . '-' . $usr_id] = $return;
     return $return;
 }
Example #26
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 #27
0
 /**
  * Converts a note to a draft or an email
  *
  * @param int $note_id The id of the note
  * @param string $target What the note should be converted too (email, etc)
  * @param bool $authorize_sender If $authorize_sender If the sender should be added to authorized senders list.
  * @return int
  */
 public static function convertNote($note_id, $target, $authorize_sender = false)
 {
     $issue_id = self::getIssueID($note_id);
     $email_account_id = Email_Account::getEmailAccount();
     $blocked_message = self::getBlockedMessage($note_id);
     $unknown_user = self::getUnknownUser($note_id);
     $structure = Mime_Helper::decode($blocked_message, true, true);
     $body = $structure->body;
     $sender_email = strtolower(Mail_Helper::getEmailAddress($structure->headers['from']));
     $current_usr_id = Auth::getUserID();
     if ($target == 'email') {
         if (Mime_Helper::hasAttachments($structure)) {
             $has_attachments = 1;
         } else {
             $has_attachments = 0;
         }
         list($blocked_message, $headers) = Mail_Helper::rewriteThreadingHeaders($issue_id, $blocked_message, @$structure->headers);
         $t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_Helper::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$blocked_message, 'has_attachment' => $has_attachments, 'headers' => $headers);
         // need to check for a possible customer association
         if (!empty($structure->headers['from'])) {
             $details = Email_Account::getDetails($email_account_id);
             // check from the associated project if we need to lookup any customers by this email address
             if (CRM::hasCustomerIntegration($details['ema_prj_id'])) {
                 $crm = CRM::getInstance($details['ema_prj_id']);
                 // check for any customer contact association
                 try {
                     $contact = $crm->getContactByEmail($sender_email);
                     $issue_contract = $crm->getContract(Issue::getContractID($issue_id));
                     if ($contact->canAccessContract($issue_contract)) {
                         $t['customer_id'] = $issue_contract->getCustomerID();
                     }
                 } catch (CRMException $e) {
                 }
             }
         }
         if (empty($t['customer_id'])) {
             $update_type = 'staff response';
             $t['customer_id'] = null;
         } else {
             $update_type = 'customer action';
         }
         $res = Support::insertEmail($t, $structure, $sup_id);
         if ($res != -1) {
             Support::extractAttachments($issue_id, $structure);
             // notifications about new emails are always external
             $internal_only = false;
             // special case when emails are bounced back, so we don't want to notify the customer about those
             if (Notification::isBounceMessage($sender_email)) {
                 $internal_only = true;
             }
             Notification::notifyNewEmail($current_usr_id, $issue_id, $t, $internal_only, false, '', $sup_id);
             Issue::markAsUpdated($issue_id, $update_type);
             self::remove($note_id, false);
             History::add($issue_id, $current_usr_id, 'note_converted_email', 'Note converted to e-mail (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id)));
             // now add sender as an authorized replier
             if ($authorize_sender) {
                 Authorized_Replier::manualInsert($issue_id, @$structure->headers['from']);
             }
         }
         return $res;
     }
     // save message as a draft
     $res = Draft::saveEmail($issue_id, $structure->headers['to'], $structure->headers['cc'], $structure->headers['subject'], $body, false, $unknown_user);
     // remove the note, if the draft was created successfully
     if ($res) {
         self::remove($note_id, false);
         $usr_id = $current_usr_id;
         History::add($issue_id, $usr_id, 'note_converted_draft', 'Note converted to draft (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id)));
     }
     return $res;
 }
Example #28
0
 /**
  * TODO: merge use of $options and $email arrays to just $email
  *
  * @param int $issue_id
  * @param string $type type of email
  * @param string $from
  * @param string $to
  * @param string $cc
  * @param string $subject
  * @param string $body
  * @param array $options optional parameters
  * - (int) parent_sup_id
  * - (array) iaf_ids attachment file ids
  * - (bool) add_unknown
  * - (int) ema_id
  * @return int 1 if it worked, -1 otherwise
  */
 public static function sendEmail($issue_id, $type, $from, $to, $cc, $subject, $body, $options = array())
 {
     $parent_sup_id = $options['parent_sup_id'];
     $iaf_ids = $options['iaf_ids'];
     $add_unknown = $options['add_unknown'];
     $ema_id = $options['ema_id'];
     $current_usr_id = Auth::getUserID();
     $prj_id = Issue::getProjectID($issue_id);
     // if we are replying to an existing email, set the In-Reply-To: header accordingly
     $in_reply_to = $parent_sup_id ? self::getMessageIDByID($parent_sup_id) : false;
     // get ID of whoever is sending this.
     $sender_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($from)) ?: false;
     // remove extra 'Re: ' from subject
     $subject = Mail_Helper::removeExcessRe($subject, true);
     $internal_only = false;
     $message_id = Mail_Helper::generateMessageID();
     // process any files being uploaded
     // from ajax upload, attachment file ids
     if ($iaf_ids) {
         // FIXME: is it correct to use sender from post data?
         $attach_usr_id = $sender_usr_id ?: $current_usr_id;
         Attachment::attachFiles($issue_id, $attach_usr_id, $iaf_ids, false, 'Attachment originated from outgoing email');
     }
     // hack needed to get the full headers of this web-based email
     $full_email = self::buildFullHeaders($issue_id, $message_id, $from, $to, $cc, $subject, $body, $in_reply_to, $iaf_ids);
     // email blocking should only be done if this is an email about an associated issue
     if ($issue_id) {
         $user_info = User::getNameEmail($current_usr_id);
         // check whether the current user is allowed to send this email to customers or not
         if (!self::isAllowedToEmail($issue_id, $user_info['usr_email'])) {
             // add the message body as a note
             $note = Mail_Helper::getCannedBlockedMsgExplanation() . $body;
             $note_options = array('full_message' => $full_email, 'is_blocked' => true);
             Note::insertNote($current_usr_id, $issue_id, $subject, $note, $note_options);
             $email_details = array('from' => $from, 'to' => $to, 'cc' => $cc, 'subject' => $subject, 'body' => &$body, 'message' => &$body, 'title' => $subject);
             Workflow::handleBlockedEmail($prj_id, $issue_id, $email_details, '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 (($add_unknown || Workflow::shouldAutoAddToNotificationList($prj_id)) && $issue_id) {
         // add the recipients to the notification list of the associated issue
         $recipients = array($to);
         $recipients = array_merge($recipients, self::getRecipientsCC($cc));
         foreach ($recipients as $address) {
             if ($address && !Notification::isIssueRoutingSender($issue_id, $address)) {
                 $actions = Notification::getDefaultActions($issue_id, $address, 'add_unknown_user');
                 Notification::subscribeEmail($current_usr_id, $issue_id, Mail_Helper::getEmailAddress($address), $actions);
             }
         }
     } 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 ($issue_id) {
             // send direct emails only to the unknown addresses, and leave the rest to be
             // catched by the notification list
             $from = Notification::getFixedFromHeader($issue_id, $from, 'issue');
             // build the list of unknown recipients
             if ($to) {
                 $recipients = array($to);
                 $recipients = array_merge($recipients, self::getRecipientsCC($cc));
             } else {
                 $recipients = self::getRecipientsCC($cc);
             }
             $unknowns = array();
             foreach ($recipients as $address) {
                 if (!Notification::isSubscribedToEmails($issue_id, $address)) {
                     $unknowns[] = $address;
                 }
             }
             if ($unknowns) {
                 $to2 = array_shift($unknowns);
                 $cc2 = implode('; ', $unknowns);
                 // send direct emails
                 self::sendDirectEmail($issue_id, $from, $to2, $cc2, $subject, $body, $_FILES['attachment'], $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_Helper::getFormattedName(User::getFullName($current_usr_id), $project_info['email']);
             } else {
                 // otherwise, use the real email address for the current user
                 $from = User::getFromHeader($current_usr_id);
             }
             // send direct emails
             self::sendDirectEmail($issue_id, $from, $to, $cc, $subject, $body, $_FILES['attachment'], $message_id);
         }
     }
     $email = array('customer_id' => 'NULL', 'issue_id' => $issue_id, 'ema_id' => $ema_id, 'message_id' => $message_id, 'date' => Date_Helper::getCurrentDateGMT(), 'from' => $from, 'to' => $to, 'cc' => $cc, 'subject' => $subject, 'body' => $body, 'full_email' => $full_email);
     // associate this new email with a customer, if appropriate
     if (Auth::getCurrentRole() == User::getRoleID('Customer')) {
         if ($issue_id) {
             $crm = CRM::getInstance($prj_id);
             try {
                 $contact = $crm->getContact(User::getCustomerContactID($current_usr_id));
                 $issue_contract = $crm->getContract(Issue::getContractID($issue_id));
                 if ($contact->canAccessContract($issue_contract)) {
                     $email['customer_id'] = $issue_contract->getCustomerID();
                 }
             } catch (CRMException $e) {
             }
         } else {
             $customer_id = User::getCustomerID($current_usr_id);
             if ($customer_id && $customer_id != -1) {
                 $email['customer_id'] = $customer_id;
             }
         }
     }
     $email['has_attachment'] = $iaf_ids ? 1 : 0;
     $structure = Mime_Helper::decode($full_email, true, false);
     $email['headers'] = $structure->headers;
     self::insertEmail($email, $structure, $sup_id);
     if ($issue_id) {
         // need to send a notification
         Notification::notifyNewEmail($current_usr_id, $issue_id, $email, $internal_only, false, $type, $sup_id);
         // mark this issue as updated
         $has_customer = $email['customer_id'] && $email['customer_id'] != 'NULL';
         if ($has_customer && (!$current_usr_id || User::getRoleByUser($current_usr_id, $prj_id) == User::getRoleID('Customer'))) {
             Issue::markAsUpdated($issue_id, 'customer action');
         } else {
             if ($sender_usr_id && User::getRoleByUser($sender_usr_id, $prj_id) > User::getRoleID('Customer')) {
                 Issue::markAsUpdated($issue_id, 'staff response');
             } else {
                 Issue::markAsUpdated($issue_id, 'user response');
             }
         }
         History::add($issue_id, $current_usr_id, 'email_sent', 'Outgoing email sent by {user}', array('user' => User::getFullName($current_usr_id)));
     }
     return 1;
 }
Example #29
0
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/field_display.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
$tpl->assign('type', 'field_display');
$prj_id = @$_GET['prj_id'];
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_MANAGER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
if (count(@$_POST['fields']) > 0) {
    $res = Project::updateFieldDisplaySettings($prj_id, $_POST['fields']);
    $tpl->assign('result', $res);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the information was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the information.'), Misc::MSG_ERROR)));
}
$fields = Project::getDisplayFields();
$excluded_roles = array('viewer');
if (!CRM::hasCustomerIntegration($prj_id)) {
    $excluded_roles[] = 'customer';
}
$user_roles = User::getRoles($excluded_roles);
$user_roles[9] = 'Never Display';
$tpl->assign('prj_id', $prj_id);
$tpl->assign('fields', $fields);
$tpl->assign('user_roles', $user_roles);
$tpl->assign('display_settings', Project::getFieldDisplaySettings($prj_id));
$tpl->displayTemplate();
Example #30
0
if (@$_POST['cat'] == 'new') {
    $res = FAQ::insert();
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the FAQ entry was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the FAQ entry.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this FAQ entry.'), Misc::MSG_ERROR), -3 => array(ev_gettext('Please enter the message for this FAQ entry.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = FAQ::update();
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the FAQ entry was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the FAQ entry information.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this FAQ entry.'), Misc::MSG_ERROR), -3 => array(ev_gettext('Please enter the message for this FAQ entry.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    FAQ::remove();
} elseif (!empty($_GET['prj_id'])) {
    $tpl->assign('info', array('faq_prj_id' => $_GET['prj_id']));
    if (CRM::hasCustomerIntegration($_GET['prj_id'])) {
        $crm = CRM::getInstance($_GET['prj_id']);
        $tpl->assign('support_levels', $crm->getSupportLevelAssocList());
    }
}
if (@$_GET['cat'] == 'edit') {
    $info = FAQ::getDetails($_GET['id']);
    if (!empty($_GET['prj_id'])) {
        $info['faq_prj_id'] = $_GET['prj_id'];
    }
    if (CRM::hasCustomerIntegration($info['faq_prj_id'])) {
        $crm = CRM::getInstance($info['faq_prj_id']);
        $tpl->assign('support_levels', $crm->getSupportLevelAssocList());
    }
    $tpl->assign('info', $info);
} elseif (@$_GET['cat'] == 'change_rank') {
    FAQ::changeRank($_GET['id'], $_GET['rank']);
}
$tpl->assign('list', FAQ::getList());
$tpl->assign('project_list', Project::getAll());
$tpl->displayTemplate();