function processView()
 {
     if (empty($_POST['personid'])) {
         trigger_error("Cannot update persons, no person ID specified", E_USER_WARNING);
         return;
     }
     $customValues = array();
     $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank');
     $dummyField = new Custom_Field();
     foreach ($customFields as $fieldid => $fieldDetails) {
         $dummyField->populate($fieldid, $fieldDetails);
         if ($val = $dummyField->processWidget()) {
             $customValues[$fieldid] = $val;
         }
     }
     foreach ($this->_allowedFields as $field) {
         if (array_get($_POST, $field, '') == '') {
             unset($_POST[$field]);
         }
     }
     if (empty($customValues) && count(array_intersect(array_keys($_POST), $this->_allowedFields)) == 0) {
         add_message("Cannot update; no new values were specified", 'error');
         if (!empty($_REQUEST['backto'])) {
             parse_str($_REQUEST['backto'], $back);
             unset($back['backto']);
             redirect($back['view'], $back);
         }
         return;
     }
     $success = 0;
     $GLOBALS['system']->setFriendlyErrors(TRUE);
     foreach ((array) $_REQUEST['personid'] as $personid) {
         $this->_person = new Person((int) $personid);
         foreach ($this->_allowedFields as $field) {
             if (isset($_POST[$field])) {
                 $this->_person->setValue($field, $_POST[$field]);
             }
         }
         foreach ($customValues as $fieldid => $val) {
             $this->_person->setCustomValue($fieldid, $val, array_get($_POST, 'custom_' . $fieldid . '_add', FALSE));
         }
         if ($this->_person->validateFields() && $this->_person->save()) {
             $success++;
         }
     }
     if ($success == count($_REQUEST['personid'])) {
         add_message('Fields updated for ' . count($_REQUEST['personid']) . ' persons');
     } else {
         if ($success > 0) {
             add_message("Fields updated for {$success} persons; some persons could not be updated");
         } else {
             add_message('There was a problem updating the fields. Check your selected persons.');
         }
     }
     if (!empty($_REQUEST['backto'])) {
         parse_str($_REQUEST['backto'], $back);
         unset($back['backto']);
         redirect($back['view'], $back);
     }
 }
    function printFieldInterface($fieldname, $prefix)
    {
        switch ($fieldname) {
            case 'params':
                ?>
				<div class="indepfield-options" data-indeptype="select">
					<?php 
                Custom_Field::printParamsSelect($prefix, $this->getValue('params'));
                ?>
				</div>
				<?php 
                break;
            default:
                return parent::printFieldInterface($fieldname, $prefix);
        }
    }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Updates the issue fields for the specified location
  *
  * @param   integer $issue_id
  * @param   string $location The name of the location
  * @param   array $values an array of new values
  */
 public static function updateValues($issue_id, $location, $values)
 {
     $fields = self::getFieldsToDisplay($issue_id, $location);
     foreach ($fields as $field_name => $field_options) {
         if ($field_name == 'custom') {
             Custom_Field::updateFromPost();
         } else {
             self::setValue($issue_id, $field_name, $values[$field_name]);
         }
     }
 }
/*
 * 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();
Exemplo n.º 6
0
if (is_array($fields) && count($fields) > 0) {
    foreach ($fields as $field) {
        $custom_fields[$field['fld_id']] = $field['fld_title'];
        $options[$field['fld_id']] = Custom_Field::getOptions($field['fld_id']);
    }
} else {
    echo ev_gettext('No custom fields for this project');
    exit;
}
if (!empty($_REQUEST['start']['Year']) && !empty($_REQUEST['start']['Month']) && !empty($_REQUEST['start']['Day'])) {
    $start = implode('-', $_REQUEST['start']);
} else {
    $start = false;
}
if (!empty($_REQUEST['end']['Year']) && !empty($_REQUEST['end']['Month']) && !empty($_REQUEST['end']['Day'])) {
    $end = implode('-', $_REQUEST['end']);
} else {
    $end = false;
}
if (count(@$_GET['custom_field']) > 0) {
    $data = Report::getCustomFieldReport(@$_GET['custom_field'], @$_GET['custom_options'], @$_GET['group_by'], $start, $end, true, @$_REQUEST['interval'], @$_REQUEST['assignee']);
}
if ($start == false || ($end = false)) {
    $start = '--';
    $end = '--';
}
$tpl->assign(array('custom_fields' => $custom_fields, 'custom_field' => @$_GET['custom_field'], 'options' => $options, 'custom_options' => @$_GET['custom_options'], 'group_by' => @$_GET['group_by'], 'selected_options' => @$_REQUEST['custom_options'], 'data' => @$data, 'start_date' => $start, 'end_date' => $end, 'assignees' => Project::getUserAssocList($prj_id, 'active', User::ROLE_CUSTOMER), 'assignee' => @$_REQUEST['assignee']));
if (isset($_GET['custom_field'])) {
    $tpl->assign(array('field_info' => Custom_Field::getDetails($_GET['custom_field'])));
}
$tpl->displayTemplate();
Exemplo n.º 7
0
 /**
  * Method used to get the previous and next issues that are available
  * according to the current search parameters.
  *
  * @param   integer $issue_id The issue ID
  * @param   array $options The search parameters
  * @return  array The list of issues
  */
 public static function getSides($issue_id, $options)
 {
     $usr_id = Auth::getUserID();
     $role_id = Auth::getCurrentRole();
     $usr_details = User::getDetails($usr_id);
     $stmt = 'SELECT
                 iss_id,
                 ' . self::getLastActionFields() . '
              FROM
                 (
                 {{%issue}},
                 {{%user}}';
     // join custom fields if we are searching by custom fields
     if (is_array($options['custom_field']) && count($options['custom_field']) > 0) {
         foreach ($options['custom_field'] as $fld_id => $search_value) {
             if (empty($search_value)) {
                 continue;
             }
             $field = Custom_Field::getDetails($fld_id);
             if ($field['fld_type'] == '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) {
                     $stmt .= ",\n {{%issue_custom_field}} as cf" . $fld_id . '_' . $cfo_id . "\n";
                 }
             } else {
                 $stmt .= ",\n {{%issue_custom_field}} as cf" . $fld_id . "\n";
             }
         }
     }
     $stmt .= ')';
     // check for the custom fields we want to sort by
     if (strstr($options['sort_by'], 'custom_field') !== false) {
         $fld_id = str_replace('custom_field_', '', $options['sort_by']);
         $stmt .= "\n LEFT JOIN {{%issue_custom_field}} as cf_sort\n                ON\n                    (cf_sort.icf_iss_id = iss_id AND cf_sort.icf_fld_id = {$fld_id}) \n";
     }
     if (!empty($options['users']) || @$options['sort_by'] == 'isu_usr_id') {
         $stmt .= '
              LEFT JOIN
                 {{%issue_user}}
              ON
                 isu_iss_id=iss_id';
     }
     if (!empty($options['show_authorized_issues']) || $role_id == User::ROLE_REPORTER && Project::getSegregateReporters(Auth::getCurrentProject())) {
         $stmt .= '
              LEFT JOIN
                 {{%issue_user_replier}}
              ON
                 iur_iss_id=iss_id';
     }
     if (!empty($options['show_notification_list_issues'])) {
         $stmt .= '
              LEFT JOIN
                 {{%subscription}}
              ON
                 sub_iss_id=iss_id';
     }
     if (!empty($options['product'])) {
         $stmt .= '
              LEFT JOIN
                 {{%issue_product_version}}
              ON
                 ipv_iss_id=iss_id';
     }
     if (@$options['sort_by'] == 'pre_scheduled_date') {
         $stmt .= '
              LEFT JOIN
                 {{%project_release}}
              ON
                 iss_pre_id = pre_id';
     }
     if (@$options['sort_by'] == 'prc_title') {
         $stmt .= '
              LEFT JOIN
                 {{%project_category}}
              ON
                 iss_prc_id = prc_id';
     }
     if (!empty($usr_details['usr_par_code'])) {
         // restrict partners
         $stmt .= '
              LEFT JOIN
                 {{%issue_partner}}
              ON
                 ipa_iss_id=iss_id';
     }
     $stmt .= '
              LEFT JOIN
                 {{%status}}
              ON
                 iss_sta_id=sta_id
              LEFT JOIN
                 {{%project_priority}}
              ON
                 iss_pri_id=pri_id
              LEFT JOIN
                 {{%project_severity}}
              ON
                 iss_sev_id=sev_id
              WHERE
                 iss_prj_id=' . Auth::getCurrentProject();
     $stmt .= Search::buildWhereClause($options);
     if (strstr($options['sort_by'], 'custom_field') !== false) {
         $fld_details = Custom_Field::getDetails($fld_id);
         $sort_by = 'cf_sort.' . Custom_Field::getDBValueFieldNameByType($fld_details['fld_type']);
     } else {
         $sort_by = Misc::escapeString($options['sort_by']);
     }
     $stmt .= '
              GROUP BY
                 iss_id
              ORDER BY
                 ' . $sort_by . ' ' . Misc::escapeString($options['sort_order']) . ',
                 iss_id DESC';
     try {
         $res = DB_Helper::getInstance()->getColumn($stmt);
     } catch (DbException $e) {
         return '';
     }
     $index = array_search($issue_id, $res);
     if (!empty($res[$index + 1])) {
         $next = $res[$index + 1];
     }
     if (!empty($res[$index - 1])) {
         $previous = $res[$index - 1];
     }
     return array('next' => @$next, 'previous' => @$previous);
 }
<?php

/*
 * 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';
// if there is no field ID, return false
if (empty($_GET['fld_id'])) {
    exit(0);
}
$backend = Custom_Field::getBackend($_GET['fld_id']);
if (is_object($backend) && is_subclass_of($backend, 'Dynamic_Custom_Field_Backend')) {
    header('Content-Type: application/json; charset=UTF-8');
    echo json_encode($backend->getDynamicOptions($_GET));
}
 /**
  * Called when a new message is recieved.
  *
  * @param   integer $prj_id The projectID
  * @param   integer $issue_id The ID of the issue.
  * @param   object $message An object containing the new email
  * @param   array $row The array of data that was inserted into the database.
  * @param   boolean $closing If we are closing the issue.
  */
 function handleNewEmail($prj_id, $issue_id, $message, $row = false, $closing = false)
 {
     $subject = $row['subject'];
     $body = $row['body'];
     preg_match('/(H|C)[A-Z0-9]{12,14}/', $subject, $header_matches);
     preg_match_all('/(H|C)[A-Z0-9]{12,14}/', $body, $body_matches);
     if ($header_matches[0]) {
         $refs[] = $header_matches[0];
     }
     foreach ($body_matches[0] as $body_match) {
         if ($body_match) {
             $refs[] = $body_match;
         }
     }
     $refs = @array_unique($refs);
     $stmt = "Select reference_number,ss_subscription_id from " . ETEL_TRANS_SUBS_TABLE_NOSUB . "\n\t\tWHERE\n\t\t\treference_number in ('" . @implode("','", $refs) . "')";
     $res = $GLOBALS["db_api"]->dbh->getRow($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
     } else {
         if ($res[0]) {
             Custom_Field::associateIssue($issue_id, 1, $res[0]);
         }
         if ($res[1]) {
             Custom_Field::associateIssue($issue_id, 4, $res[1]);
         }
     }
     $res = Authorized_Replier::manualInsert($issue_id, $row['from']);
     Issue::updateControlStatus($issue_id);
 }
Exemplo n.º 10
0
 /**
  * Generates a graph for the selected custom field.
  *
  * @param string $type
  * @param int $custom_field The id of the custom field.
  * @param array $custom_options An array of option ids.
  * @param string $group_by How the data should be grouped.
  * @param string $start
  * @param string $end
  * @param string $interval
  * @return bool
  */
 public function CustomFieldGraph($type, $custom_field, $custom_options, $group_by, $start, $end, $interval)
 {
     $data = Report::getCustomFieldReport($custom_field, $custom_options, $group_by, $start, $end, false, $interval);
     if (count($data) < 2) {
         return false;
     }
     $field_details = Custom_Field::getDetails($custom_field);
     // convert to phplot format
     $i = 0;
     $plotData = $labels = array();
     unset($data['All Others']);
     foreach ($data as $label => $value) {
         $plotData[$i] = array($label, $value);
         $labels[] = $label;
         $i++;
     }
     if ($type == 'pie') {
         $plot = $this->create(500, 300);
         $plot->SetPlotType('pie');
         $plot->SetDataType('text-data-single');
     } else {
         // bar chart
         $plot = $this->create(500, 350);
         $plot->SetPlotType('bars');
         $plot->SetDataType('text-data');
         $plot->SetXTitle($field_details['fld_title']);
         $plot->SetYTitle(ev_gettext('Issue Count'));
         $plot->SetXTickLabelPos('none');
         $plot->SetXTickPos('none');
         $plot->SetYDataLabelPos('plotin');
     }
     if ($group_by == 'customers') {
         $title = ev_gettext('Customers by %s', $field_details['fld_title']);
     } else {
         $title = ev_gettext('Issues by %s', $field_details['fld_title']);
     }
     $plot->SetDataValues($plotData);
     $plot->SetLegend($labels);
     $plot->SetImageBorderType('plain');
     $plot->SetTitle($title);
     return $plot->DrawGraph();
 }
Exemplo n.º 11
0
        $time_spent = (int) $_POST['time_spent'];
        $summary = 'Time entry inserted when closing issue.';
        Time_Tracking::addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary);
    }
    if (CRM::hasCustomerIntegration($prj_id) && isset($details['contract'])) {
        $crm = CRM::getInstance($prj_id);
        $contract = $details['contract'];
        if ($contract->hasPerIncident()) {
            $contract->updateRedeemedIncidents($issue_id, @$_REQUEST['redeem']);
        }
    }
    $tpl->assign('close_result', $res);
    if ($res == 1) {
        Misc::setMessage(ev_gettext('Thank you, the issue was closed successfully'));
        Misc::displayNotifiedUsers(Notification::getLastNotifiedAddresses($issue_id));
        Auth::redirect(APP_RELATIVE_URL . 'view.php?id=' . $issue_id);
    }
}
$tpl->assign(array('statuses' => Status::getClosedAssocList($prj_id), 'resolutions' => Resolution::getAssocList(), 'time_categories' => Time_Tracking::getAssocCategories($prj_id), 'notify_list' => Notification::getLastNotifiedAddresses($issue_id), 'custom_fields' => Custom_Field::getListByIssue($prj_id, $issue_id, $usr_id, 'close_form'), 'issue_id' => $issue_id));
if (CRM::hasCustomerIntegration($prj_id) && isset($details['contract'])) {
    $crm = CRM::getInstance($prj_id);
    $contract = $details['contract'];
    if ($contract->hasPerIncident()) {
        $details = Issue::getDetails($issue_id);
        $tpl->assign(array('redeemed' => $contract->getRedeemedIncidentDetails($issue_id), 'incident_details' => $details['customer']['incident_details']));
    }
}
$usr_id = Auth::getUserID();
$user_prefs = Prefs::get($usr_id);
$tpl->assign('current_user_prefs', $user_prefs);
$tpl->displayTemplate();
Exemplo n.º 12
0
// customers should not be able to see this page
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('Standard User')) {
    Auth::redirect(APP_RELATIVE_URL . "list.php");
}
$prj_id = Auth::getCurrentProject();
// generate options for assign list. If there are groups and user is above a customer, include groups
$groups = Group::getAssocList($prj_id);
$users = Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer'));
$assign_options = array("" => "Any", "-1" => "un-assigned", "-2" => "myself and un-assigned");
if (User::getGroupID(Auth::getUserID()) != '') {
    $assign_options['-3'] = 'myself and my group';
    $assign_options['-4'] = 'myself, un-assigned and my group';
}
if (count($groups) > 0 && $role_id > User::getRoleID("Customer")) {
    foreach ($groups as $grp_id => $grp_name) {
        $assign_options["grp:{$grp_id}"] = "Group: " . $grp_name;
    }
}
$assign_options += $users;
$tpl->assign(array("cats" => Category::getAssocList($prj_id), "priorities" => Priority::getList($prj_id), "status" => Status::getAssocStatusList($prj_id), "users" => $assign_options, "releases" => Release::getAssocList($prj_id, TRUE), "custom" => Filter::getListing($prj_id), "custom_fields" => Custom_Field::getListByProject($prj_id, ''), "reporters" => Project::getReporters($prj_id)));
if (!empty($HTTP_GET_VARS["custom_id"])) {
    $check_perm = true;
    if (Filter::isGlobal($HTTP_GET_VARS["custom_id"])) {
        if ($role_id >= User::getRoleID('Manager')) {
            $check_perm = false;
        }
    }
    $tpl->assign("options", Filter::getDetails($HTTP_GET_VARS["custom_id"], $check_perm));
}
$tpl->displayTemplate();
Exemplo n.º 13
0
 /**
  * Returns data for the custom fields report, based on the field and options passed in.
  *
  * @access  public
  * @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   boolean $list If the values should be listed out instead of just counted.
  * @return  array An array of data.
  */
 function getCustomFieldReport($fld_id, $cfo_ids, $group_by = "issue", $list = false)
 {
     $prj_id = Auth::getCurrentProject();
     $fld_id = Misc::escapeInteger($fld_id);
     $cfo_ids = array_map(array('Misc', 'escapeString'), $cfo_ids);
     $backend = Custom_Field::getBackend($fld_id);
     if (is_object($backend)) {
         $options = array();
         foreach ($cfo_ids as $cfo_id) {
             $options[$cfo_id] = Custom_Field::getOptionValue($fld_id, $cfo_id);
         }
         $in_field = 'icf_value';
     } else {
         // get field values
         $stmt = "SELECT\n                        cfo_id,\n                        cfo_value\n                     FROM\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option\n                     WHERE\n                        cfo_fld_id = {$fld_id} AND\n                        cfo_id IN('" . join("','", $cfo_ids) . "')\n                     ORDER BY\n                        cfo_id";
         $options = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
         if (PEAR::isError($options)) {
             Error_Handler::logError(array($options->getMessage(), $options->getDebugInfo()), __FILE__, __LINE__);
             return array();
         }
         $in_field = 'cfo_id';
     }
     if ($group_by == "customer") {
         $group_by_field = "iss_customer_id";
     } else {
         $group_by_field = "iss_id";
     }
     if ($list == true) {
         $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                    FROM\n";
         if (!is_object($backend)) {
             $sql .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n";
         }
         $sql .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                    WHERE\n";
         if (!is_object($backend)) {
             $sql .= "cfo_id = icf_value AND";
         }
         $sql .= "\nicf_iss_id = iss_id AND\n                        icf_fld_id = {$fld_id} AND\n                        {$in_field} IN('" . join("','", array_keys($options)) . "')\n                    GROUP BY\n                        {$group_by_field}\n                    ORDER BY\n                        row_count DESC";
         $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
         if (PEAR::isError($res)) {
             Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
             return array();
         }
         if (Customer::hasCustomerIntegration($prj_id)) {
             Customer::getCustomerTitlesByIssues($prj_id, $res);
             if ($group_by == "issue") {
                 usort($res, create_function('$a,$b', 'if ($a["customer_title"] < $b["customer_title"]) {
                     return -1;
                 } elseif ($a["customer_title"] > $b["customer_title"]) {
                     return 1;
                 } else {
                     return 0;
                 }'));
             }
         }
         return $res;
     }
     $data = array();
     foreach ($options as $cfo_id => $value) {
         $stmt = "SELECT\n                        COUNT(DISTINCT {$group_by_field})\n                    FROM\n";
         if (!is_object($backend)) {
             $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n";
         }
         $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                    WHERE\n";
         if (!is_object($backend)) {
             $stmt .= "cfo_id = icf_value AND";
         }
         $stmt .= "\nicf_iss_id = iss_id AND\n                        icf_fld_id = {$fld_id} AND\n                        {$in_field} = '" . Misc::escapeString($cfo_id) . "'";
         $count = $GLOBALS["db_api"]->dbh->getOne($stmt);
         if (PEAR::isError($count)) {
             Error_Handler::logError(array($count->getMessage(), $count->getDebugInfo()), __FILE__, __LINE__);
             return array();
         }
         $data[$value] = $count;
     }
     // include count of all other values (used in pie chart)
     $stmt = "SELECT\n                    COUNT(DISTINCT {$group_by_field})\n                FROM\n";
     if (!is_object($backend)) {
         $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n";
     }
     $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                WHERE\n";
     if (!is_object($backend)) {
         $stmt .= "cfo_id = icf_value AND";
     }
     $stmt .= "\nicf_iss_id = iss_id AND\n                    icf_fld_id = {$fld_id} AND\n                    {$in_field} NOT IN('" . join("','", $cfo_ids) . "')";
     $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return array();
     }
     $data["All Others"] = $res;
     return $data;
 }
Exemplo n.º 14
0
 /**
  * Formats the return value
  *
  * @access  public
  * @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.
  */
 function formatValue($value, $fld_id, $issue_id, $functional = false)
 {
     $backend = Custom_Field::getBackend($fld_id);
     if (is_object($backend) && method_exists($backend, 'formatValue')) {
         return $backend->formatValue($value, $fld_id, $issue_id, $functional);
     } else {
         return Link_Filter::processText(Auth::getCurrentProject(), htmlspecialchars($value));
     }
 }
Exemplo n.º 15
0
     $show_releases = 0;
 }
 // get if categories should be displayed
 $cats = Category::getList($prj_id);
 if (count($cats) > 0) {
     $show_category = 1;
 } else {
     $show_category = 0;
 }
 $cookie = Auth::getCookieInfo(APP_PROJECT_COOKIE);
 if (!empty($auto_switched_from)) {
     $tpl->assign(array("project_auto_switched" => 1, "old_project" => Project::getName($auto_switched_from)));
 }
 $setup = Setup::load();
 $tpl->assign("allow_unassigned_issues", @$setup["allow_unassigned_issues"]);
 $tpl->assign(array('next_issue' => @$sides['next'], 'previous_issue' => @$sides['previous'], 'subscribers' => Notification::getSubscribers($issue_id), 'custom_fields' => Custom_Field::getListByIssue($prj_id, $issue_id), 'files' => Attachment::getList($issue_id), 'emails' => Support::getEmailsByIssue($issue_id), 'zones' => Date_API::getTimezoneList(), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'ema_id' => Email_Account::getEmailAccount(), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'show_releases' => $show_releases, 'show_category' => $show_category, 'categories' => Category::getAssocList($prj_id), 'quarantine' => Issue::getQuarantineInfo($issue_id)));
 if ($role_id != User::getRoleID('customer')) {
     if (@$_REQUEST['show_all_drafts'] == 1) {
         $show_all_drafts = true;
     } else {
         $show_all_drafts = false;
     }
     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);
     }
     if (!empty($details['iss_sta_id']) && empty($statuses[$details['iss_sta_id']])) {
         $statuses[$details['iss_sta_id']] = Status::getStatusTitle($details['iss_sta_id']);
     }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
 /**
  * @param int $issue_id
  * @return struct
  * @access protected
  */
 public function getIssueDetails($issue_id)
 {
     AuthCookie::setProjectCookie(Issue::getProjectID($issue_id));
     $res = Issue::getDetails($issue_id);
     // flatten some fields
     if (isset($res['customer'])) {
         $details = $res['customer']->getDetails();
         $res['customer'] = $details;
     }
     if (isset($res['contract'])) {
         $res['contract'] = $res['contract']->getDetails();
     }
     if (empty($res)) {
         throw new RemoteApiException("Issue #{$issue_id} could not be found");
     }
     // remove some naughty fields
     unset($res['iss_original_description']);
     // returns custom fields in an array
     $res['custom_fields'] = Custom_Field::getListByIssue($res['iss_prj_id'], $res['iss_id']);
     return $res;
 }
Exemplo n.º 18
0
 function processForm()
 {
     parent::processForm();
     $actions = array('notes' => array(), 'groups' => array(), 'groups_remove' => array(), 'dates' => array(), 'attendance' => NULL);
     $i = 0;
     while ($note = $this->_processNoteForm($i)) {
         $actions['notes'][] = $note;
         $i++;
     }
     $i = 0;
     while (isset($_POST['groups'][$i])) {
         if ($groupid = (int) $_POST['groups'][$i]) {
             $actions['groups'][] = $groupid;
         }
         $i++;
     }
     $i = 0;
     while (isset($_POST['groups_remove'][$i])) {
         if ($groupid = (int) $_POST['groups_remove'][$i]) {
             $actions['groups_remove'][] = $groupid;
         }
         $i++;
     }
     $addValue = array_get($_POST, 'fields_addvalue', array());
     foreach (array_get($_POST, 'fields_enabled', array()) as $k => $v) {
         if (0 === strpos($k, 'custom_')) {
             $fieldID = substr($k, 7);
             $field = new Custom_Field($fieldID);
             if ($field->getValue('type') == 'date') {
                 // FUture expansion: allow static dates here; for now we just support
                 // the reference date, represented by magic number -1.
                 $val = '-1===' . $_POST['custom_' . $fieldID . '_note'];
             } else {
                 $val = $field->processWidget();
                 $val = reset($val);
                 // it comes wrapped in an array
             }
         } else {
             $val = $_POST[$k];
         }
         $actions['fields'][$k] = array('value' => $val, 'add' => array_get($addValue, $k, FALSE));
     }
     $actions['attendance'] = $_POST['mark_present'];
     $this->setValue('actions', $actions);
 }
Exemplo n.º 19
0
 /**
  * Method used to remove a given set of projects from the system.
  *
  * @access  public
  * @return  boolean
  */
 function remove()
 {
     global $HTTP_POST_VARS;
     $items = @implode(", ", Misc::escapeInteger($HTTP_POST_VARS["items"]));
     $stmt = "DELETE FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n                 WHERE\n                    prj_id IN ({$items})";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return false;
     } else {
         Project::removeUserByProjects($HTTP_POST_VARS["items"]);
         Category::removeByProjects($HTTP_POST_VARS["items"]);
         Release::removeByProjects($HTTP_POST_VARS["items"]);
         Filter::removeByProjects($HTTP_POST_VARS["items"]);
         Email_Account::removeAccountByProjects($HTTP_POST_VARS["items"]);
         Issue::removeByProjects($HTTP_POST_VARS["items"]);
         Custom_Field::removeByProjects($HTTP_POST_VARS["items"]);
         $statuses = array_keys(Status::getAssocStatusList($HTTP_POST_VARS["items"]));
         foreach ($HTTP_POST_VARS["items"] as $prj_id) {
             Status::removeProjectAssociations($statuses, $prj_id);
         }
         Group::disassociateProjects($HTTP_POST_VARS["items"]);
         return true;
     }
 }
Exemplo n.º 20
0
 /**
  * Method used to remove a given set of projects from the system.
  *
  * @return  boolean
  */
 public static function remove()
 {
     $items = $_POST['items'];
     $stmt = 'DELETE FROM
                 {{%project}}
              WHERE
                 prj_id IN (' . DB_Helper::buildList($items) . ')';
     try {
         DB_Helper::getInstance()->query($stmt, $items);
     } catch (DbException $e) {
         return -1;
     }
     self::removeUserByProjects($items);
     Category::removeByProjects($items);
     Release::removeByProjects($items);
     Filter::removeByProjects($items);
     Email_Account::removeAccountByProjects($items);
     Issue::removeByProjects($items);
     Custom_Field::removeByProjects($items);
     $statuses = array_keys(Status::getAssocStatusList($items));
     foreach ($items as $prj_id) {
         Status::removeProjectAssociations($statuses, $prj_id);
     }
     Group::disassociateProjects($items);
     return 1;
 }
Exemplo n.º 21
0
        // need to show everything again
        $tpl->assign('error_msg', '1');
    }
} elseif (@$_GET['post_form'] == 'yes') {
    // only list those projects that are allowing anonymous reporting of new issues
    $projects = Project::getAnonymousList();
    if (empty($projects)) {
        $tpl->assign('no_projects', '1');
    } else {
        if (!in_array($_GET['project'], array_keys($projects))) {
            $tpl->assign('no_projects', '1');
        } else {
            // get list of custom fields for the selected project
            $options = Project::getAnonymousPostOptions($_GET['project']);
            if (@$options['show_custom_fields'] == 'yes') {
                $tpl->assign('custom_fields', Custom_Field::getListByProject($_GET['project'], 'anonymous_form'));
            }
            $tpl->assign('project_name', Project::getName($_GET['project']));
        }
    }
} else {
    // only list those projects that are allowing anonymous reporting of new issues
    $projects = Project::getAnonymousList();
    if (empty($projects)) {
        $tpl->assign('no_projects', '1');
    } else {
        if (count($projects) == 1) {
            $project_ids = array_keys($projects);
            Auth::redirect('post.php?post_form=yes&project=' . $project_ids[0]);
        } else {
            $tpl->assign('projects', $projects);
Exemplo n.º 22
0
		
		
		<div class="bulk-action well" id="update-field">
			<table class="valign-middle">
			<?php 
    $dummy = new Person();
    foreach (array('congregationid', 'status', 'age_bracket') as $field) {
        $dummy->fields[$field]['allow_empty'] = TRUE;
        $dummy->fields[$field]['empty_text'] = '(No change)';
        $dummy->setValue($field, NULL);
        echo '<tr><td>Set ' . $dummy->getFieldLabel($field) . ' to: </td><td>';
        $dummy->printFieldInterface($field);
        echo '</td></tr>';
    }
    $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank');
    $dummy = new Custom_Field();
    $addParams = array('type' => 'select', 'options' => array('Replacing existing values ', 'Adding to existing values'));
    foreach ($customFields as $fieldid => $fieldDetails) {
        $dummy->populate($fieldid, $fieldDetails);
        echo '<tr><td>Set ' . ents($dummy->getValue('name')) . ' to: </td><td>';
        $dummy->printWidget('');
        if ($dummy->getValue('allow_multiple')) {
            echo '</td><td>';
            print_widget('custom_' . $fieldid . '_add', $addParams, 0);
        }
        echo '</td></tr>';
    }
    ?>
			</table>
			<input type="submit" class="btn" onclick="return confirm('Are you sure you want to bulk-update these persons?')" value="Go" data-set-form-action="<?php 
    echo BASE_URL;
    function printView()
    {
        if (is_null($this->fields)) {
            return;
        }
        if (empty($this->fields)) {
            ?>
			<p><i>No custom fields have been set up in the system yet.</i></p>
			<?php 
        }
        $field = new Custom_Field();
        $this->fields['_new_'] = $field;
        ?>
		<form method="post">
		<table id="custom-fields-editor" class="table table-auto-width expandable valign-top">
			<thead>
				<tr>
					<th>ID</th>
					<th>Name</th>
					<th>Type</th>
					<th>Multi?</th>
					<th>Parameters</th>
					<th><i class="icon-trash"></i></th>
				</tr>
			</thead>
			<tbody>
			<?php 
        $i = 0;
        foreach ($this->fields as $field) {
            $prefix = 'fields_' . $i . '_';
            ?>
				<tr>
					<td class="cursor-move">
						<?php 
            echo $field->id;
            print_hidden_field($prefix . 'id', $field->id);
            print_hidden_field('index[]', $i);
            ?>
					</td>
					<td>
						<?php 
            $field->printFieldInterface('name', $prefix);
            ?>
					</td>
					<td>
						<?php 
            if ($field->id) {
                $field->printFieldValue('type');
            } else {
                $field->printFieldInterface('type', $prefix);
            }
            ?>
					</td>
					<td class="center">
						<?php 
            $field->printFieldInterface('allow_multiple', $prefix);
            ?>
					</td>
					<td>
						<?php 
            $field->printFieldInterface('params', $prefix);
            ?>
					</td>
					<td class="center">
						<?php 
            if ($field->id) {
                ?>
							<input type="checkbox" name="<?php 
                echo $prefix;
                ?>
delete" value="1"
								   data-toggle="strikethrough" data-target="row"
								   title="Click to delete this field" />
							<?php 
            }
            ?>
					</td>
				</tr>
				<?php 
            $i++;
        }
        ?>
			</tbody>
		</table>
		<input type="submit" class="btn" value="Save" />
		</form>
		<?php 
    }
Exemplo n.º 24
0
    function getSQL($select_fields = NULL)
    {
        $db =& $GLOBALS['db'];
        $params = $this->_convertParams($this->getValue('params'));
        if (empty($params)) {
            return null;
        }
        $query = array();
        $query['from'] = 'person p 
						JOIN family f ON p.familyid = f.id
						';
        $query['where'] = array();
        // BASIC FILTERS
        foreach ($params['rules'] as $field => $values) {
            if ($field == 'date') {
                continue;
            } else {
                if (is_array($values) && isset($values['from'])) {
                    if ($this->_field_details[$field]['type'] == 'datetime' && strlen($values['from']) == 10) {
                        // we're searching on a datetime field using only date values
                        // so extend them to prevent boundary errors
                        $values['from'] .= ' 00:00';
                        $values['to'] .= ' 23:59';
                    }
                    $query['where'][] = $field . ' BETWEEN ' . $db->quote($values['from']) . ' AND ' . $db->quote($values['to']);
                } else {
                    $values = (array) $values;
                    switch (count($values)) {
                        case 0:
                            $query['where'][] = $field . ' = 0';
                        case 1:
                            $query['where'][] = $field . ' = ' . $db->quote(reset($values));
                            break;
                        default:
                            $quoted_vals = array();
                            foreach ($values as $val) {
                                $quoted_vals[] = $db->quote($val);
                            }
                            $query['where'][] = $field . ' IN (' . implode(', ', $quoted_vals) . ')';
                    }
                }
            }
        }
        // CUSTOM FIELD FILTERS
        $customFieldWheres = array();
        foreach (array_get($params, 'custom_fields', array()) as $fieldid => $values) {
            $query['from'] .= ' LEFT JOIN custom_field_value pd' . $fieldid . ' ON pd' . $fieldid . '.personid = p.id AND pd' . $fieldid . '.fieldid = ' . (int) $fieldid . "\n";
            switch ($this->_custom_fields[$fieldid]['type']) {
                case 'date':
                    if ($values['criteria'] == 'between') {
                        $values['criteria'] = $values['anniversary'] ? 'anniversary' : 'exact';
                    }
                    switch ($values['criteria']) {
                        case 'any':
                            $customFieldWheres[] = 'pd' . $fieldid . '.`personid` IS NOT NULL';
                            break;
                        case 'empty':
                            $customFieldWheres[] = 'pd' . $fieldid . '.personid IS NULL';
                            break;
                        case 'exact':
                        case 'anniversary':
                            if (array_get($values, 'periodtype') == 'relative') {
                                $length = $values['periodlength'];
                                if (!preg_match('/^[0-9]+$/', $length)) {
                                    $length = 0;
                                }
                                $offsets = array('before' => array(-$length - 1, -1), 'ending' => array(-$length, 0), 'starting' => array(0, $length), 'after' => array(1, $length + 1));
                                list($so, $eo) = $offsets[$values['periodanchor']];
                                if ($so > 0) {
                                    $so = "+{$so}";
                                }
                                if ($eo > 0) {
                                    $eo = "+{$eo}";
                                }
                                $from = date('Y-m-d', strtotime("{$so} days"));
                                $to = date('Y-m-d', strtotime("{$eo} days"));
                            } else {
                                $from = $values['from'];
                                $to = $values['to'];
                            }
                            $betweenExp = 'BETWEEN ' . $db->quote($from) . ' AND ' . $db->quote($to);
                            $valExp = 'pd' . $fieldid . '.value_date';
                            $w = array();
                            $w[] = "{$valExp} NOT LIKE '-%' AND {$valExp} {$betweenExp}";
                            if ($values['criteria'] == 'anniversary') {
                                $qFromYear = $db->quote(substr($from, 0, 4));
                                $qToYear = $db->quote(substr($to, 0, 4));
                                $w[] = "{$valExp} LIKE '-%' AND (\n\t\t\t\t\t\t\t\t\t\t\tCONCAT({$qFromYear}, {$valExp}) {$betweenExp}\n\t\t\t\t\t\t\t\t\t\t\tOR CONCAT({$qToYear}, {$valExp}) {$betweenExp}\n\t\t\t\t\t\t\t\t\t\t)";
                                $w[] = "{$valExp} NOT LIKE '-%' AND (\n\t\t\t\t\t\t\t\t\t\t\tCONCAT({$qFromYear}, RIGHT({$valExp}, 6)) {$betweenExp}\n\t\t\t\t\t\t\t\t\t\t\tOR CONCAT({$qToYear}, RIGHT({$valExp}, 6)) {$betweenExp}\n\t\t\t\t\t\t\t\t\t\t)";
                            }
                            $customFieldWheres[] = '((' . implode("\n) OR (\n", $w) . '))';
                            break;
                    }
                    break;
                case 'select':
                    switch (array_get($values, 'criteria', 'contains')) {
                        case 'contains':
                            $ids = implode(',', array_map(array($db, 'quote'), $values['val']));
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_optionid IN (' . $ids . '))';
                            break;
                        case 'any':
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_optionid IS NOT NULL)';
                            break;
                        case 'empty':
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_optionid IS NULL)';
                            break;
                    }
                    break;
                case 'text':
                    switch (array_get($values, 'criteria', 'equals')) {
                        case 'equal':
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_text = ' . $db->quote($values['val']) . ')';
                            break;
                        case 'any':
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_text IS NOT NULL)';
                            break;
                        case 'empty':
                            $customFieldWheres[] = '(pd' . $fieldid . '.value_text IS NULL)';
                            break;
                    }
                    break;
                    break;
            }
        }
        if (!empty($customFieldWheres)) {
            $logic = array_get($params, 'custom_field_logic', 'AND');
            $query['where'][] = '((' . implode(') ' . $logic . ' (', $customFieldWheres) . '))';
        }
        // GROUP MEMBERSHIP FILTERS
        if (!empty($params['include_groups'])) {
            $include_groupids_clause = $this->_getGroupAndCategoryRestrictionSQL($params['include_groups'], array_get($params, 'group_join_date_from'), array_get($params, 'group_join_date_to'), array_get($params, 'group_membership_status'));
            $group_members_sql = 'SELECT personid 
								FROM person_group_membership pgm 
								JOIN person_group pg ON pgm.groupid = pg.id
								WHERE (' . $include_groupids_clause . ')';
            $query['where'][] = 'p.id IN (' . $group_members_sql . ')';
        }
        if (!empty($params['exclude_groups'])) {
            $exclude_groupids_clause = $this->_getGroupAndCategoryRestrictionSQL($params['exclude_groups']);
            $query['where'][] = 'p.id NOT IN (
									SELECT personid 
									FROM person_group_membership pgm
									JOIN person_group pg ON pgm.groupid = pg.id
									WHERE (' . $exclude_groupids_clause . ')
								)';
        }
        //NOTE FILTERS
        if (!empty($params['note_phrase'])) {
            $note_sql = 'SELECT pn.personid, GROUP_CONCAT(an.Subject) as subjects
						FROM person_note pn
						JOIN abstract_note an ON an.id = pn.id
						WHERE an.details LIKE ' . $GLOBALS['db']->quote('%' . $params['note_phrase'] . '%') . '
						OR an.subject LIKE ' . $GLOBALS['db']->quote('%' . $params['note_phrase'] . '%') . '
						GROUP BY pn.personid';
            $query['from'] .= ' JOIN (' . $note_sql . ') notes ON notes.personid = p.id ';
        }
        // ATTENDANCE FILTERS
        if (!empty($params['attendance_groupid'])) {
            $groupid = $params['attendance_groupid'] == '__cong__' ? 0 : $params['attendance_groupid'];
            $min_date = date('Y-m-d', strtotime('-' . (int) $params['attendance_weeks'] . ' weeks'));
            $operator = $params['attendance_operator'] == '>' ? '>' : '<';
            // nb whitelist because it will be used in the query directly
            $query['where'][] = '(SELECT SUM(present)/COUNT(*)*100 
									FROM attendance_record 
									WHERE date >= ' . $GLOBALS['db']->quote($min_date) . ' 
									AND groupid = ' . (int) $groupid . '
									AND personid = p.id) ' . $operator . ' ' . (int) $params['attendance_percent'];
        }
        // GROUPING
        $grouping_order = '';
        $grouping_field = '';
        if (empty($params['group_by'])) {
            $grouping_field = '';
        } else {
            if ($params['group_by'] == 'groupid') {
                if (!empty($params['include_groups'])) {
                    $grouping_field = 'CONCAT(pg.name, ' . $db->quote(' (#') . ', pg.id, ' . $db->quote(')') . '), ';
                    $query['from'] .= ' JOIN person_group_membership pgm ON p.id = pgm.personid
									JOIN person_group pg ON pg.id = pgm.groupid
									';
                    $query['where'][] = $this->_getGroupAndCategoryRestrictionSQL($params['include_groups'], array_get($params, 'group_join_date_from'), array_get($params, 'group_join_date_to'), array_get($params, 'group_membership_status'));
                    $grouping_order = 'pg.name, ';
                } else {
                    $grouping_field = '';
                }
            } else {
                $grouping_order = $grouping_field = $params['group_by'] . ', ';
            }
        }
        // DISPLAY FIELDS
        $joined_groups = FALSE;
        if (empty($select_fields)) {
            /*
             * If the user chose to sort by Attendance or Absences but didn't 
             * include them in the list of required columns, just add them to the
             * results.  There is client-side code to deal with this,
             * but this check here is for extra robustness.
             */
            if ($params['sort_by'] == 'attendance_percent' && !in_array('attendance_percent', $params['show_fields'])) {
                array_push($params['show_fields'], 'attendance_percent');
            } else {
                if ($params['sort_by'] == 'attendance_numabsences' && !in_array('attendance_numabsences', $params['show_fields'])) {
                    array_push($params['show_fields'], 'attendance_numabsences');
                }
            }
            if (empty($params['show_fields'])) {
                $params['show_fields'] = array('p.first_name', 'p.last_name');
            }
            foreach ($params['show_fields'] as $field) {
                if (substr($field, 0, 2) == '--') {
                    continue;
                }
                // they selected a separator
                switch ($field) {
                    case 'groups':
                    case 'membershipstatus':
                        if (empty($params['include_groups'])) {
                            continue;
                        }
                        if ($params['group_by'] == 'groupid') {
                            /* pg and pgm already joined for grouping purposes */
                            if ($field == 'groups') {
                                $query['select'][] = 'GROUP_CONCAT(pg.name ORDER BY pg.name SEPARATOR "\\n") as person_groups';
                            } else {
                                if ($field == 'membershipstatus') {
                                    $query['from'] .= ' LEFT JOIN person_group_membership_status pgms ON pgms.id = pgm.membership_status';
                                    $query['select'][] = 'pgms.label as `Membership Status`';
                                }
                            }
                        } else {
                            if (!$joined_groups) {
                                $query['from'] .= ' LEFT JOIN person_group_membership pgm ON p.id = pgm.personid
													JOIN person_group pg ON pg.id = pgm.groupid
													';
                                $query['where'][] = $this->_getGroupAndCategoryRestrictionSQL($params['include_groups'], array_get($params, 'group_join_date_from'), array_get($params, 'group_join_date_to'));
                                $joined_groups = TRUE;
                            }
                            if ($field == 'groups') {
                                $query['select'][] = 'GROUP_CONCAT(pg.name ORDER BY pg.name SEPARATOR "\\n") as person_groups';
                            } else {
                                if ($field == 'membershipstatus') {
                                    $query['from'] .= ' LEFT JOIN person_group_membership_status pgms ON pgms.id = pgm.membership_status';
                                    $query['select'][] = 'GROUP_CONCAT(pgms.label ORDER BY pg.name SEPARATOR "\\n") as `Membership Status`';
                                }
                            }
                        }
                        break;
                    case 'view_link':
                    case 'edit_link':
                    case 'checkbox':
                    case 'photo':
                        $query['select'][] = 'p.id as ' . $field;
                        break;
                    case 'all_members':
                        $query['from'] .= ' 
										JOIN (
											SELECT familyid, IF (
												GROUP_CONCAT(DISTINCT last_name) = ff.family_name, 
												GROUP_CONCAT(first_name ORDER BY age_bracket, gender DESC SEPARATOR ", "),
												GROUP_CONCAT(CONCAT(first_name, " ", last_name) ORDER BY age_bracket, gender DESC SEPARATOR ", ")
											  ) AS `names`
											FROM person pp
											JOIN family ff ON pp.familyid = ff.id
											WHERE pp.status <> "archived"
											GROUP BY familyid
										) all_members ON all_members.familyid = p.familyid
										   ';
                        $query['select'][] = 'all_members.names as `All Family Members`';
                        break;
                    case 'adult_members':
                        /* 
                         * For a left join to be efficient we need to 
                         * create a temp table with an index rather than
                         * just joining a subquery.
                         */
                        $r1 = $GLOBALS['db']->query('CREATE TEMPORARY TABLE _family_adults' . $this->id . ' (
													familyid int(10) not null primary key,
													names varchar(512) not null
													)');
                        check_db_result($r1);
                        $r2 = $GLOBALS['db']->query('INSERT INTO _family_adults' . $this->id . ' (familyid, names)
											SELECT familyid, IF (
												GROUP_CONCAT(DISTINCT last_name) = ff.family_name, 
												GROUP_CONCAT(first_name ORDER BY age_bracket, gender DESC SEPARATOR ", "),
												GROUP_CONCAT(CONCAT(first_name, " ", last_name) ORDER BY age_bracket, gender DESC SEPARATOR ", ")
											  )
											FROM person pp
											JOIN family ff ON pp.familyid = ff.id
											WHERE pp.status <> "archived" AND pp.age_bracket = 0
											GROUP BY familyid');
                        check_db_result($r2);
                        $query['from'] .= 'LEFT JOIN _family_adults' . $this->id . ' ON _family_adults' . $this->id . '.familyid = p.familyid
											';
                        $query['select'][] = '_family_adults' . $this->id . '.names as `Adult Family Members`';
                        break;
                    case 'attendance_percent':
                        $groupid = $params['attendance_groupid'] == '__cong__' ? 0 : $params['attendance_groupid'];
                        $min_date = date('Y-m-d', strtotime('-' . (int) $params['attendance_weeks'] . ' weeks'));
                        $query['select'][] = '(SELECT CONCAT(ROUND(SUM(present)/COUNT(*)*100), "%") 
													FROM attendance_record 
													WHERE date >= ' . $GLOBALS['db']->quote($min_date) . ' 
													AND groupid = ' . (int) $groupid . '
													AND personid = p.id) AS `Attendance`';
                        break;
                    case 'attendance_numabsences':
                        /* The number of "absents" recorded since the last "present".*/
                        $groupid = $params['attendance_groupid'] == '__cong__' ? 0 : $params['attendance_groupid'];
                        $query['select'][] = '(SELECT COUNT(*)
													FROM attendance_record ar
													WHERE groupid = ' . (int) $groupid . '
													AND personid = p.id
													AND date > (SELECT COALESCE(MAX(date), "2000-01-01") FROM attendance_record ar2 WHERE ar2.personid = ar.personid AND present = 1)) AS `Running Absences`';
                        break;
                    case 'actionnotes.subjects':
                        $query['select'][] = '(SELECT GROUP_CONCAT(subject SEPARATOR ", ") 
												FROM abstract_note an 
												JOIN person_note pn ON an.id = pn.id 
												WHERE pn.personid = p.id
												AND an.status = "pending"
												AND an.action_date <= NOW()) AS `Notes`';
                        break;
                    case 'notes.subjects':
                        if (empty($params['note_phrase'])) {
                            $query['select'][] = '"" AS subjects';
                            break;
                        }
                        // else deliberate fallthrough...
                    // else deliberate fallthrough...
                    default:
                        $customFieldID = NULL;
                        if (substr($field, 0, 7) == 'date---') {
                            // backwards compat
                            $customFieldID = substr($field, 7);
                        } else {
                            if (0 === strpos($field, self::CUSTOMFIELD_PREFIX)) {
                                $customFieldID = substr($field, 14);
                            }
                        }
                        if ($customFieldID) {
                            if (isset($this->_custom_fields[$customFieldID])) {
                                $field = new Custom_Field();
                                $field->populate($customFieldID, $this->_custom_fields[$customFieldID]);
                                $query['from'] .= 'LEFT JOIN custom_field_value cfv' . $customFieldID . ' ON cfv' . $customFieldID . '.personid = p.id AND cfv' . $customFieldID . '.fieldid = ' . $db->quote($customFieldID) . "\n";
                                $query['select'][] = 'GROUP_CONCAT(DISTINCT ' . Custom_Field::getRawValueSQLExpr('cfv' . $customFieldID) . ' ORDER BY ' . Custom_Field::getRawValueSQLExpr('cfv' . $customFieldID) . ' SEPARATOR "' . self::CUSTOMFIELDVAL_SEP . '") as ' . $db->quote(self::CUSTOMFIELD_PREFIX . $customFieldID) . "\n";
                            }
                        } else {
                            $query['select'][] = $this->_quoteAliasAndColumn($field) . ' AS ' . $db->quote($field);
                        }
                }
            }
            $select_fields = $grouping_field . 'p.id as ID, ' . implode(', ', $query['select']);
        }
        // ORDER BY
        $customOrder = NULL;
        if (substr($params['sort_by'], 0, 7) == 'date---') {
            // backwards compatibility
            $customOrder = substr($params['sort_by'], 8);
        } else {
            if (0 === strpos($params['sort_by'], self::CUSTOMFIELD_PREFIX)) {
                $customOrder = substr($params['sort_by'], 14);
            }
        }
        if ($customOrder) {
            $query['from'] .= 'LEFT JOIN custom_field_value cfvorder ON cfvorder.personid = p.id AND cfvorder.fieldid = ' . $db->quote($customOrder) . "\n";
            $query['from'] .= "LEFT JOIN custom_field_option cfoorder ON cfoorder.id = cfvorder.value_optionid \n";
            $order = array();
            $order[] = 'IF(cfvorder.personid IS NULL, 1, 0)';
            // put those without a value last
            if ($this->_custom_fields[$customOrder]['type'] == 'date') {
                $order[] = 'IF(cfvorder.value_date LIKE "-%", 1, 0)';
                // put full dates before partial dates
            }
            $order[] = 'GROUP_CONCAT(' . Custom_Field::getSortValueSQLExpr('cfvorder', 'cfoorder') . ')';
            $query['order_by'] = implode(', ', $order);
        } else {
            if ($params['sort_by'] == 'p.congregationid') {
                // Order by congregation meeting time then congregation name
                $query['from'] .= '
				LEFT JOIN congregation cord ON p.congregationid = cord.id ';
                $query['order_by'] = 'IF(cord.id IS NULL, 1, 0), IF(LENGTH(cord.meeting_time)>0, 0, 1), cord.meeting_time, cord.name';
            } else {
                $query['order_by'] = $this->_quoteAliasAndColumn($params['sort_by']);
            }
        }
        if ($grouping_order) {
            $query['order_by'] = $grouping_order . $query['order_by'];
        }
        if ($params['sort_by'] == 'f.family_name') {
            // Stop members of identically-named families from being intermingled
            $query['order_by'] .= ', f.id';
        }
        /*
         * We can order by attendances or absences safely,
         * because we have already ensured they will appear
         * the select clause.
         */
        $rewrites = array('`attendance_percent`' => '`Attendance` ASC', '`attendance_numabsences`' => '`Running Absences` DESC', '`membershipstatus`' => 'pgms.rank');
        $query['order_by'] = str_replace(array_keys($rewrites), array_values($rewrites), $query['order_by']);
        if (!strlen(trim($query['order_by'], '`'))) {
            $query['order_by'] = 1;
        }
        // Build SQL
        $sql = 'SELECT ' . $select_fields . '
				FROM ' . $query['from'] . '
				';
        if (!empty($query['where'])) {
            $sql .= 'WHERE
					(' . implode(")\n\tAND (", $query['where']) . ')
				';
        }
        $sql .= 'GROUP BY p.id ';
        if (array_get($params, 'group_by') == 'groupid') {
            $sql .= ', pg.id ';
        }
        $sql .= 'ORDER BY ' . $query['order_by'] . ', p.last_name, p.first_name';
        return $sql;
    }
Exemplo n.º 25
0
        if (count($item) == 1) {
            $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($item[0]), $item[0]);
            $tpl->assign(array('issue_summary' => $email_details['sup_subject'], 'issue_description' => $email_details['seb_body']));
            // also auto pre-fill the customer contact text fields
            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));
Exemplo n.º 26
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;
 }
Exemplo n.º 27
0
 /**
  * Returns data for the custom fields weekly 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 $start_date
  * @param   string $end_date
  * @param   boolean $per_user Show time spent per user
  * @return  array An array of data.
  */
 public static function getCustomFieldWeeklyReport($fld_id, $cfo_ids, $start_date, $end_date, $per_user = false)
 {
     $fld_id = (int) $fld_id;
     $cfo_ids = (array) $cfo_ids;
     // get field values
     $options = Custom_Field::getOptions($fld_id, $cfo_ids);
     $params = array();
     $sql = 'SELECT
                 iss_id,
                 SUM(ttr_time_spent) ttr_time_spent_sum,
                 iss_summary,
                 iss_customer_id,
                 iss_private
            ';
     if ($per_user) {
         $sql .= ', usr_full_name ';
     }
     $sql .= '
              FROM
                 {{%time_tracking}},';
     if ($per_user) {
         $sql .= '{{%user}}, ';
     }
     $sql .= '
                     {{%issue}}
                 WHERE
                     iss_prj_id=? AND
                     ttr_created_date BETWEEN ? AND ? AND
                     ttr_iss_id = iss_id AND
                     ';
     $params[] = Auth::getCurrentProject();
     $params[] = "{$start_date} 00:00:00";
     $params[] = "{$end_date} 23:59:59";
     if ($per_user) {
         $sql .= ' usr_id = ttr_usr_id AND ';
     }
     $sql .= '
                     ttr_iss_id = iss_id
                     ';
     if (count($options) > 0) {
         $ids = array_keys($options);
         $list = DB_Helper::buildList($ids);
         $sql .= " AND (\n                SELECT\n                    count(*)\n                FROM\n                    {{%issue_custom_field}} a\n                WHERE\n                    a.icf_fld_id = ? AND\n                    a.icf_value IN({$list}) AND\n                    a.icf_iss_id = ttr_iss_id\n                ) > 0";
         $params[] = $fld_id;
         $params = array_merge($params, $ids);
     }
     if ($per_user) {
         $sql .= '
                 GROUP BY
                 iss_id, ttr_usr_id';
     } else {
         $sql .= '
                 GROUP BY
                 iss_id';
     }
     try {
         $res = DB_Helper::getInstance()->getAll($sql, $params);
     } catch (DbException $e) {
         return array();
     }
     foreach ($res as &$row) {
         $row['field_value'] = Custom_Field::getDisplayValue($row['iss_id'], $fld_id);
         $row['ttr_time_spent_sum_formatted'] = Misc::getFormattedTime($row['ttr_time_spent_sum'], false);
     }
     return $res;
 }
                <td class="default" width="100%" bgcolor="<?php 
        echo $this->_tpl_vars['row_color'];
        ?>
">
                  <?php 
        if ($this->_tpl_vars['custom_fields'][$this->_sections['i']['index']]['fld_type'] == 'textarea') {
            ?>
                    <?php 
            echo is_array($_tmp = is_array($_tmp = is_array($_tmp = $this->_tpl_vars['custom_fields'][$this->_sections['i']['index']]['icf_value']) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')) ? $this->_run_mod_handler('activateLinks', true, $_tmp, 'link') : Link_Filter::activateLinks($_tmp, 'link')) ? $this->_run_mod_handler('nl2br', true, $_tmp) : smarty_modifier_nl2br($_tmp);
            ?>

                  <?php 
        } else {
            ?>
                    <?php 
            echo is_array($_tmp = $this->_tpl_vars['custom_fields'][$this->_sections['i']['index']]['icf_value']) ? $this->_run_mod_handler('formatCustomValue', true, $_tmp, $this->_tpl_vars['custom_fields'][$this->_sections['i']['index']]['fld_id'], $_GET['id'], true) : Custom_Field::formatValue($_tmp, $this->_tpl_vars['custom_fields'][$this->_sections['i']['index']]['fld_id'], $_GET['id'], true);
            ?>

                  <?php 
        }
        ?>
                </td>
              </tr>
              <?php 
    }
} else {
    ?>
              <tr id="custom_fields1" <?php 
    echo smarty_function_get_display_style(array('element_name' => 'custom_fields', 'total' => count($this->_tpl_vars['custom_fields'])), $this);
    ?>
>
Exemplo n.º 29
0
    function printForm($prefix = '', $fields = NULL)
    {
        include_once 'include/size_detector.class.php';
        if ($GLOBALS['system']->featureEnabled('PHOTOS') && (is_null($fields) || in_array('photo', $fields)) && !SizeDetector::isNarrow()) {
            $this->fields['photo'] = array('divider_before' => true);
            // fake field for interface purposes
            if ($this->id) {
                ?>
				<div class="person-photo-container">
					<img src="?call=photo&personid=<?php 
                echo (int) $this->id;
                ?>
" />
				</div>
				<?php 
            }
        }
        if (!$this->id) {
            unset($this->fields['familyid']);
        }
        parent::printForm($prefix, $fields);
        unset($this->fields['photo']);
        if (empty($fields) || in_array('custom', $fields)) {
            $customFields = $this->getCustomFields();
            $dummyField = new Custom_Field();
            if ($customFields) {
                ?>
				<hr />
				<div class="form-horizontal">
				<?php 
                foreach ($customFields as $fieldid => $fieldDetails) {
                    $dummyField->populate($fieldid, $fieldDetails);
                    $tableClass = $fieldDetails['allow_multiple'] ? 'expandable' : '';
                    $values = isset($this->_custom_values[$fieldid]) ? $this->_custom_values[$fieldid] : array('');
                    if ($fieldDetails['divider_before']) {
                        echo '<hr />';
                    }
                    ?>
					<div class="control-group">
						<?php 
                    if (strlen($fieldDetails['heading_before'])) {
                        ?>
								<h4><?php 
                        echo ents($fieldDetails['heading_before']);
                        ?>
</h4>
							<?php 
                    }
                    ?>

						<label class="control-label" for="custom_<?php 
                    echo $fieldid;
                    ?>
"><?php 
                    echo ents($fieldDetails['name']);
                    ?>
</label>
						<div class="controls">
							<table class="<?php 
                    echo $tableClass;
                    ?>
">
							<?php 
                    foreach ($values as $value) {
                        ?>
								<tr><td>
									<?php 
                        $dummyField->printWidget($value);
                        ?>
								</td></tr>
								<?php 
                    }
                    ?>
							</table>
						</div>
					</div>
					<?php 
                }
                ?>
				</div>
				<?php 
            }
        }
    }
Exemplo n.º 30
0
// | 59 Temple Place - Suite 330                                          |
// | Boston, MA 02111-1307, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// @(#) $Id: s.custom_fields.php 1.5 03/11/01 01:08:09-00:00 jpradomaia $
//
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.custom_field.php";
include_once APP_INC_PATH . "db_access.php";
$tpl = new Template_API();
$tpl->setTemplate("custom_fields_form.tpl.html");
Auth::checkAuthentication(APP_COOKIE);
$prj_id = Auth::getCurrentProject();
$issue_id = @$HTTP_POST_VARS["issue_id"] ? $HTTP_POST_VARS["issue_id"] : $HTTP_GET_VARS["issue_id"];
if (!Issue::canAccess($issue_id, Auth::getUserID())) {
    $tpl = new Template_API();
    $tpl->setTemplate("permission_denied.tpl.html");
    $tpl->displayTemplate();
    exit;
}
if (@$HTTP_POST_VARS["cat"] == "update_values") {
    $res = Custom_Field::updateValues();
    $tpl->assign("update_result", $res);
    $tpl->assign("current_user_prefs", Prefs::get(Auth::getUserID()));
}
$tpl->assign("custom_fields", Custom_Field::getListByIssue($prj_id, $issue_id));
$tpl->displayTemplate();