/** * Selects all profiles (array (id => name)) or profiles filtered * * @param mixed Array with filter conditions to retrieve profiles or false. * * @return array List of all profiles */ function profile_get_profiles($filter = false) { if ($filter === false) { $profiles = get_db_all_rows_in_table("tprofile", "name"); } else { $profiles = get_db_all_rows_filter("tprofile", $filter); } $return = array(); if ($profiles === false) { return $return; } foreach ($profiles as $profile) { $return[$profile["id"]] = $profile["name"]; } return $return; }
echo "</h1>"; /* Users affected by the incident */ $table->width = '100%'; $table->class = "none"; $table->size = array (); $table->size[0] = '50%'; $table->size[1] = '50%'; $table->style = array(); $table->data = array (); $table->style [0] = "vertical-align: top;"; $table->style [1] = "vertical-align: top"; $custom = ''; $custom_searches = get_db_all_rows_filter ("tcustom_search", array("id_user" => $config["id_user"], "section" => "incidents")); $counter = 0; $max_per_file = 5; if ($custom_searches === false) { $custom .= "<table style='margin: 10px auto;'>"; $custom .= "<tr>"; $custom .= "<td>"; $custom .= "<em>".__("There aren't custom search defined for this user")."</em>"; $custom .= "</td>"; $custom .= "</tr>"; $custom .= "</table>"; } else { foreach ($custom_searches as $cs) {
foreach ($fields as $f) { $f["data"] = safe_output($f["data"]); $f["blocked"] = $blocked; if ($f["type"] == "linked") { // Label parent $label_parent = get_db_value('label', 'tincident_type_field', 'id', $f['parent']); $f['label_parent'] = !empty($label_parent) ? $label_parent : ''; $f['label_parent_enco'] = base64_encode($f['label_parent']); // Label childs if (empty($f['global_id'])) { $filter = array('parent' => $f['id']); } else { // Search for the childrem items created under the incident type $filter = array('parent' => $f['global_id'], 'id_incident_type' => $f['id_incident_type']); } $label_childs = get_db_all_rows_filter('tincident_type_field', $filter, 'label'); $f['label_childs'] = ''; $f['label_childs_enco'] = ''; if ($label_childs !== false) { $i = 0; foreach ($label_childs as $label) { if ($i == 0) { $f['label_childs'] = $label['label']; $f['label_childs_enco'] = base64_encode($label['label']); } else { $f['label_childs'] .= ',' . $label['label']; $f['label_childs_enco'] .= ',' . base64_encode($label['label']); } $i++; } }
return; } // Get the roles assigned to user in the project of a given task if ($get_task_roles) { $id_user = get_parameter ('id_user'); $id_task = get_parameter ('id_task'); $id_project = get_db_value('id_project','ttask','id',$id_task); // If the user is Project Manager, all the roles are retrieved. // If not, only the assigned roles if(give_acl($id_user, 0, "PM")) { $roles = get_db_all_rows_filter('trole',array(),'id, name'); } else { $roles = get_db_all_rows_sql('SELECT trole.id, trole.name FROM trole, trole_people_project WHERE id_role = trole.id AND id_user = "******" AND id_project = '.$id_project); } echo json_encode($roles); return; } if (get_parameter("get_new_mult_wu")) { $number = get_parameter ("next"); $date = get_parameter("given_date"); create_new_table_multiworkunit($number, $date);
function combo_roles_people_task($id_task, $id_user, $label = '', $return = false) { $roles = get_db_all_rows_filter('trole_people_task', array('id_task' => $id_task, 'id_user' => $id_user), 'id_role'); $user_roles = array(); $output = ''; if ($roles !== false) { foreach ($roles as $key => $rol) { $rol_name = get_db_value('name', 'trole', 'id', $rol['id_role']); $user_roles[$rol['id_role']] = $rol_name; } } return print_select($user_roles, 'id_profile', '', '', 0, 0, true, 0, false, $label); }
function incidents_get_incident_stats($id) { //Get all incident $raw_stats = get_db_all_rows_filter('tincident_stats', array('id_incident' => $id)); if (!$raw_stats) { return array(); } //Sort incident by type and metric into a hash table :) $stats = array(); $stats[INCIDENT_METRIC_USER] = array(); $stats[INCIDENT_METRIC_STATUS] = array(STATUS_NEW => 0, STATUS_UNCONFIRMED => 0, STATUS_ASSIGNED => 0, STATUS_REOPENED => 0, STATUS_VERIFIED => 0, STATUS_RESOLVED => 0, STATUS_PENDING_THIRD_PERSON => 0, STATUS_CLOSED => 0); $stats[INCIDENT_METRIC_GROUP] = array(); $stats[INCIDENT_METRIC_TOTAL_TIME] = 0; $stats[INCIDENT_METRIC_TOTAL_TIME_NO_THIRD] = 0; foreach ($raw_stats as $st) { switch ($st["metric"]) { case INCIDENT_METRIC_USER: $stats[INCIDENT_METRIC_USER][$st["id_user"]] = $st["seconds"]; break; case INCIDENT_METRIC_STATUS: $stats[INCIDENT_METRIC_STATUS][$st["status"]] = $st["seconds"]; break; case INCIDENT_METRIC_GROUP: $stats[INCIDENT_METRIC_GROUP][$st["id_group"]] = $st["seconds"]; break; case INCIDENT_METRIC_TOTAL_TIME_NO_THIRD: $stats[INCIDENT_METRIC_TOTAL_TIME_NO_THIRD] = $st["seconds"]; break; case INCIDENT_METRIC_TOTAL_TIME: $stats[INCIDENT_METRIC_TOTAL_TIME] = $st["seconds"]; break; } } //Get last metrics and update times until now $now = time(); //Get last incident update check for total time metric $time_str = get_db_value_filter("last_stat_check", "tincidencia", array("id_incidencia" => $id)); $unix_time = strtotime($time_str); $global_diff = $now - $unix_time; //Time diff in seconds //Get non-working days from last stat update and delete the seconds :) $last_stat_check = get_db_value("last_stat_check", "tincidencia", "id_incidencia", $id); //Avoid to check for holidays since the begining of the time! if ($last_stat_check !== "0000-00-00 00:00:00") { $last_stat_check_time = strtotime($last_stat_check); } else { $last_stat_check_time = $now; } $holidays_seconds = incidents_get_holidays_seconds_by_timerange($last_stat_check_time, $now); $global_diff -= $holidays_seconds; $stats[INCIDENT_METRIC_TOTAL_TIME] += $global_diff; //Fix last time track per metric $sql = sprintf("SELECT id_aditional FROM tincident_track WHERE state = %d AND id_incident = %d ORDER BY timestamp DESC LIMIT 1", INCIDENT_USER_CHANGED, $id); $last_track_user_id = get_db_sql($sql, "id_aditional"); //If defined sum if not just assign the diff if (isset($stats[INCIDENT_METRIC_USER][$last_track_user_id])) { $stats[INCIDENT_METRIC_USER][$last_track_user_id] += $global_diff; } $sql = sprintf("SELECT id_aditional FROM tincident_track WHERE state = %d AND id_incident = %d ORDER BY timestamp DESC LIMIT 1", INCIDENT_GROUP_CHANGED, $id); $last_track_group_id = get_db_sql($sql, "id_aditional"); //If defined sum if not just assign the diff if (isset($stats[INCIDENT_METRIC_GROUP][$last_track_group_id])) { $stats[INCIDENT_METRIC_GROUP][$last_track_group_id] += $global_diff; } $sql = sprintf("SELECT id_aditional FROM tincident_track WHERE state = %d AND id_incident = %d ORDER BY timestamp DESC LIMIT 1", INCIDENT_STATUS_CHANGED, $id); $last_track_status_id = get_db_sql($sql, "id_aditional"); //If defined sum if not just assign the diff if (isset($stats[INCIDENT_METRIC_STATUS][$last_track_status_id])) { $stats[INCIDENT_METRIC_STATUS][$last_track_status_id] += $global_diff; } //If status not equal to pending on third person add this time to metric if ($last_track_status_id != STATUS_PENDING_THIRD_PERSON) { $stats[INCIDENT_METRIC_TOTAL_TIME_NO_THIRD] += $global_diff; } return $stats; }
} $show_agenda_entry = (bool) get_parameter('show_agenda_entry'); $update_agenda_entry = (bool) get_parameter('update_agenda_entry'); $delete_agenda_entry = (bool) get_parameter('delete_agenda_entry'); $id = (int) get_parameter('id'); $permission = agenda_get_entry_permission($config['id_user'], $id); if ($show_agenda_entry) { $date = (string) get_parameter('date'); $entry = array(); if (!empty($id)) { $entry = get_db_row('tagenda', 'id', $id); if (!$entry) { $entry = array(); } else { // Get the entry privacy $groups = get_db_all_rows_filter('tagenda_groups', array('agenda_id' => $id), 'group_id'); if (empty($groups)) { $groups = array(); } // Extract the groups from the result $groups = array_map(function ($item) { return $item['group_id']; }, $groups); if (!empty($groups)) { $entry['groups'] = $groups; } else { $entry['groups'] = array(0); } } } echo "<div id='calendar_entry'>";
function run_mail_queue() { global $config; // Get pending mails $filter = array('status' => 0); $mails = get_db_all_rows_filter('tpending_mail', $filter); // No pending mails if ($mails === false) { return; } // Init mailer $mailer = null; try { // Use local mailer if host not provided - Attach not supported !! if (empty($config['smtp_host'])) { // Empty snmp conf. System sendmail transport $transport = mail_get_transport(); $mailer = mail_get_mailer($transport); } else { $mailer = mail_get_mailer(); } } catch (Exception $e) { integria_logwrite(sprintf("Mail transport failure: %s", $e->getMessage())); return; } foreach ($mails as $email) { try { //Check if the email was sent at least once if (mail_send($email, $mailer) > 0) { process_sql_delete('tpending_mail', array('id' => (int) $email['id'])); } else { throw new Exception(__('The mail send failed')); } } catch (Exception $e) { $retries = $email['attempts'] + 1; if ($retries > $config['smtp_queue_retries']) { $status = 1; insert_event('MAIL_FAILURE', 0, 0, $email['recipient'] . ' - ' . $e->getMessage()); } else { $status = 0; } $values = array('status' => $status, 'attempts' => $retries); $where = array('id' => (int) $email['id']); process_sql_update('tpending_mail', $values, $where); $to = trim(ascii_output($email['recipient'])); integria_logwrite(sprintf('SMTP error sending to %s (%s)', $to, $e->getMessage())); } } }
function inventories_get_info($id_item, $id_father) { global $config; $result = array(); $info_inventory = get_db_row('tinventory', 'id', $id_item); $info_fields = get_db_all_rows_filter('tobject_type_field', array('id_object_type' => $id_father)); if ($info_inventory !== false) { $result['name'] = $info_inventory['name']; $result['data'] = array(); if (!empty($info_inventory['owner'])) { $owner = $info_inventory['owner']; $name_owner = get_db_value('nombre_real', 'tusuario', 'id_usuario', $owner); if (empty($name_owner)) { $name_owner = '--'; } } else { $name_owner = '--'; } $row = array(); $row['label'] = __('Owner'); $row['data'] = $name_owner; $result['data'][] = $row; if (!empty($info_inventory['id_parent'])) { $parent = $info_inventory['id_parent']; $name_parent = get_db_value('name', 'tinventory', 'id', $parent); if (empty($name_parent)) { $name_parent = '--'; } } else { $name_parent = '--'; } $row = array(); $row['label'] = __('Parent'); $row['data'] = $name_parent; $result['data'][] = $row; if (!empty($info_inventory['id_manufacturer'])) { $manufacturer = $info_inventory['id_manufacturer']; $name_manufacturer = get_db_value('name', 'tmanufacturer', 'id', $info_inventory['id_manufacturer']); if (empty($name_manufacturer)) { $name_manufacturer = '--'; } } else { $name_manufacturer = '--'; } $row = array(); $row['label'] = __('Manufacturer'); $row['data'] = $name_manufacturer; $result['data'][] = $row; if (!empty($info_inventory['id_contract'])) { $contract = $info_inventory['id_contract']; $name_contract = get_db_value('name', 'tcontract', 'id', $info_inventory['id_contract']); if (empty($name_contract)) { $name_contract = '--'; } } else { $name_contract = '--'; } $row = array(); $row['label'] = __('Contract'); $row['data'] = $name_contract; $result['data'][] = $row; if ($info_fields !== false) { foreach ($info_fields as $info) { $filter = array('id_inventory' => $id_item, 'id_object_type_field' => $info['id']); $value = get_db_value_filter('data', 'tobject_field_data', $filter); $data = '--'; if (!empty($value)) { $data = $value; } $info_field = array(); $info_field['label'] = $info['label']; $info_field['data'] = $data; $result['data'][] = $info_field; if ($info['type'] == 'external' && $value != false) { $all_fields_ext = inventories_get_all_external_field($info['external_table_name'], $info['external_reference_field'], $info['id']); foreach ($all_fields_ext as $field) { $data = '--'; if (!empty($field['data'])) { $data = $field['data']; } $info_field_external = array(); $info_field['label'] = $field['label']; $info_field['data'] = $data; $result['data'][] = $info_field_external; } } } } } return $result; }
function groups_get_user_groups($id_user) { global $config; if ($id_user == "") { $id_user = $config['id_user']; } $groups = get_db_all_rows_filter('tusuario_perfil', array('id_usuario' => $id_user), 'id_grupo'); if ($groups === false) { $groups = array(); } $group_ids = "("; $i = 0; foreach ($groups as $group) { if ($i == 0) { $group_ids .= $group['id_grupo']; } else { $group_ids .= "," . $group['id_grupo']; } $i++; } $group_ids .= ")"; return $group_ids; }
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. global $config; include_once 'include/functions_user.php'; $get_external_data = get_parameter('get_external_data', 0); $get_inventory_search = get_parameter('get_inventory_search', 0); $get_company_associated = get_parameter('get_company_associated', 0); $get_user_associated = get_parameter('get_user_associated', 0); $get_inventory_name = (bool) get_parameter('get_inventory_name', 0); $select_fields = get_parameter('select_fields', 0); $printTable = get_parameter('printTable', 0); $printTableMoreInfo = get_parameter('printTableMoreInfo', 0); $get_item_info = (bool) get_parameter('get_item_info', 0); if ($select_fields) { $id_object_type = get_parameter('id_object_type'); $fields = get_db_all_rows_filter('tobject_type_field', array('id_object_type' => $id_object_type), 'label, id'); if ($fields === false) { $fields = array(); } $object_fields = array(); foreach ($fields as $key => $field) { $object_fields[$field['id']] = $field['label']; } echo json_encode($object_fields); return; } if ($printTable) { $id_item = get_parameter('id_item'); $type = get_parameter('type'); $id_father = get_parameter('id_father'); inventories_printTable($id_item, $type, $id_father);
} } $values_insert['id_object_type_field'] = $id_object_field; $id_object_type_field = get_db_value('id', 'tobject_type_field', 'id_object_type', $id_object_type); if ($is_unique) { process_sql_insert('tobject_field_data', $values_insert); } } inventory_tracking($id, INVENTORY_OBJECT_TYPE, $id_object_type); } //parent if ($id_parent != 0) { $id_object_type_inherit = get_db_value('id_object_type', 'tinventory', 'id', $id_parent); //parent has object if ($id_object_type_inherit !== false) { $inherit_fields = get_db_all_rows_filter('tobject_type_field', array('id_object_type' => $id_object_type_inherit, 'inherit' => 1)); if ($inherit_fields === false) { $inherit_fields = array(); } foreach ($inherit_fields as $key => $field) { $values = array(); $values['id_object_type_field'] = $field['id']; $values['id_inventory'] = $id; $data = get_db_value_filter('data', 'tobject_field_data', array('id_inventory' => $id_parent, 'id_object_type_field' => $field['id'])); $values['data'] = $data; process_sql_insert('tobject_field_data', $values); } } inventory_tracking($id, INVENTORY_PARENT_CREATED, $id_parent); } $result_companies = enterprise_hook('inventory_update_companies', array($id, get_parameter('companies')));
function crm_get_campaign_email_stats($id_campaign) { $email_issues = get_db_all_rows_filter('tnewsletter_content', array('id_campaign' => $id_campaign)); //Get email sent //Get issue reads $total_reads = 0; $total_sent = 0; foreach ($email_issues as $ei) { $total_reads = $total_reads + crm_get_issue_reads($ei["id"]); $total_sent = $total_sent + get_db_sql("SELECT COUNT(id) FROM tnewsletter_queue_data WHERE status = 1 AND id_newsletter_content = " . $ei["id"]); } $ratio = $total_reads / $total_sent * 100; $stats = array(); $stats["reads"] = $total_reads; $stats["sent"] = $total_sent; $stats["ratio"] = $ratio; return $stats; }
public function getTracking($filter = false) { $result = false; if (isset($this->id) && !empty($this->id)) { if ($filter === false) { $filter = array(); } $filter['id_attachment'] = $this->id; $result = get_db_all_rows_filter(self::$dbTableTrack, $filter); if ($result !== false && is_array($result)) { $trackingInfo = array(); foreach ($result as $row) { if (isset($row['data']) && !empty($row['data'])) { $row['data'] = safe_output($row['data']); $row['data'] = json_decode($row['data'], true); } if (isset($row['id_user']) && !empty($row['id_user'])) { $row['id_user'] = safe_output($row['id_user']); } $trackingInfo[] = $row; } $result = $trackingInfo; } } return $result; }