static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $private) { global $CFG_GLPI, $DB; $ID = $job->getField('id'); //////////////Tasks/////////// $RESTRICT = ""; if (!$private) { // Don't show private' $RESTRICT = " AND `is_private` = '0' "; } else { if (!Session::haveRight("show_full_ticket", "1")) { // No right, only show connected user private one $RESTRICT = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "' ) "; } } $query = "SELECT *\n FROM `glpi_tickettasks`\n WHERE `tickets_id` = '{$ID}'\n {$RESTRICT}\n ORDER BY `date` DESC"; $result = $DB->query($query); if (!$DB->numrows($result)) { $pdf->setColumnsSize(100); $pdf->displayLine(__('No task found.')); } else { $pdf->displayTitle("<b>" . TicketTask::getTypeName($DB->numrows($result) . "</b>")); $pdf->setColumnsSize(20, 20, 20, 20, 20); $pdf->displayTitle("<b><i>" . __('Type') . "</i></b>", "<b><i>" . __('Date') . "</i></b>", "<b><i>" . __('Duration') . "</i></b>", "<b><i>" . __('Writer') . "</i></b>", "<b><i>" . __('Planning') . "</i></b>"); while ($data = $DB->fetch_array($result)) { $actiontime = Html::timestampToString($data['actiontime'], false); $planification = ''; if (empty($data['begin'])) { if (isset($data["state"])) { $planification = Planning::getState($data["state"]) . "<br>"; } $planification .= _e('None'); } else { if (isset($data["state"])) { $planification = sprintf(__('%1$s: %2$s'), _x('item', 'State'), Planning::getState($data["state"])); } $planificiation = sprintf(__('%1$s - %2$s'), $planification, Html::convDateTime($data["begin"]) . " -> " . Html::convDateTime($data["end"])); $planificiation = sprintf(__('%1$s - %2$s'), $planification, sprintf(__('%1$s %2$s'), __('By'), getUserName($data["users_id_tech"]))); } if ($data['taskcategories_id']) { $lib = Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']); } else { $lib = ''; } if ($data['is_private']) { $lib = sprintf(__('%1$s (%2$s)'), $lib, __('Private')); } toolbox::logdebug("lib", $data); $pdf->displayLine(Html::clean($lib), Html::convDateTime($data["date"]), Html::timestampToString($data["actiontime"], 0), Html::clean(getUserName($data["users_id"])), Html::clean($planification), 1); $pdf->displayText("<b><i>" . sprintf(__('%1$s: %2$s'), __('Description') . "</i></b>", Html::clean($data["content"]), 1)); } } $pdf->displaySpace(); }
function getFromDBbyOcsServer($id) { global $DB; $query = "SELECT *\n FROM `" . $this->getTable() . "`\n WHERE `plugin_ocsinventoryng_ocsservers_id` = '{$id}'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) != 1) { return false; } $this->fields = $DB->fetch_assoc($result); if (is_array($this->fields) && count($this->fields)) { return true; } toolbox::logdebug($this->fields); } return false; }
/** * Constructor * * @param $mailgateID ID of the mailgate * @param $display display messages in MessageAfterRedirect or just return error (default 0=) * * @return if $display = false return messages result string **/ function collect($mailgateID, $display = 0) { global $CFG_GLPI; if ($this->getFromDB($mailgateID)) { $this->mid = -1; $this->fetch_emails = 0; //Connect to the Mail Box $this->connect(); $rejected = new NotImportedEmail(); // Clean from previous collect (from GUI, cron already truncate the table) $rejected->deleteByCriteria(array('mailcollectors_id' => $this->fields['id'])); if ($this->marubox) { // Get Total Number of Unread Email in mail box $tot = $this->getTotalMails(); //Total Mails in Inbox Return integer value $error = 0; $refused = 0; $blacklisted = 0; for ($i = 1; $i <= $tot && $this->fetch_emails < $this->maxfetch_emails; $i++) { $tkt = $this->buildTicket($i, array('mailgates_id' => $mailgateID, 'play_rules' => true)); toolbox::logdebug("tkt", $tkt); //Indicates that the mail must be deleted from the mailbox $delete_mail = false; //If entity assigned, or email refused by rule, or no user and no supplier associated with the email $user_condition = $CFG_GLPI["use_anonymous_helpdesk"] || isset($tkt['_users_id_requester']) && $tkt['_users_id_requester'] > 0 || isset($tkt['_supplier_email']) && $tkt['_supplier_email']; $rejinput = array(); $rejinput['mailcollectors_id'] = $mailgateID; if (!$tkt['_blacklisted']) { $rejinput['from'] = $tkt['_head']['from']; $rejinput['to'] = $tkt['_head']['to']; $rejinput['users_id'] = $tkt['_users_id_requester']; $rejinput['subject'] = $this->textCleaner($tkt['_head']['subject']); $rejinput['messageid'] = $tkt['_head']['message_id']; } $rejinput['date'] = $_SESSION["glpi_currenttime"]; // Manage blacklisted emails if (isset($tkt['_blacklisted']) && $tkt['_blacklisted']) { $this->deleteMails($i, self::REFUSED_FOLDER); $blacklisted++; // entities_id set when new ticket / tickets_id when new followup } else { if ((isset($tkt['entities_id']) || isset($tkt['tickets_id'])) && $user_condition || isset($tkt['_refuse_email_no_response']) || isset($tkt['_refuse_email_with_response'])) { if (isset($tkt['_refuse_email_with_response'])) { $this->sendMailRefusedResponse($tkt['_head']['from'], $tkt['name']); $delete_mail = self::REFUSED_FOLDER; $refused++; } else { if (isset($tkt['_refuse_email_no_response'])) { $delete_mail = self::REFUSED_FOLDER; $refused++; } else { if (isset($tkt['entities_id']) || isset($tkt['tickets_id'])) { // Is a mail responding of an already existing ticket ? if (isset($tkt['tickets_id'])) { $fup = new TicketFollowup(); if ($fup->add($tkt)) { $delete_mail = self::ACCEPTED_FOLDER; } else { $error++; $rejinput['reason'] = NotImportedEmail::FAILED_INSERT; $rejected->add($rejinput); } } else { // New ticket $track = new Ticket(); if ($track->add($tkt)) { $delete_mail = self::ACCEPTED_FOLDER; } else { $error++; $rejinput['reason'] = NotImportedEmail::FAILED_INSERT; $rejected->add($rejinput); } } } else { // Case never raise $delete_mail = self::REFUSED_FOLDER; $refused++; } } } //Delete Mail from Mail box if ticket is added successfully if ($delete_mail) { $this->deleteMails($i, $delete_mail); } } else { if (!$tkt['_users_id_requester']) { $rejinput['reason'] = NotImportedEmail::USER_UNKNOWN; } else { $rejinput['reason'] = NotImportedEmail::MATCH_NO_RULE; } $rejected->add($rejinput); } } $this->fetch_emails++; } imap_expunge($this->marubox); $this->close_mailbox(); //Close Mail Box //TRANS: %1$d, %2$d, %3$d, %4$d and %5$d are number of messages $msg = sprintf(__('Number of messages: available=%1$d, retrieved=%2$d, refused=%3$d, errors=%4$d, blacklisted=%5$d'), $tot, $this->fetch_emails, $refused, $error, $blacklisted); if ($display) { Session::addMessageAfterRedirect($msg, false, $error ? ERROR : INFO); } else { return $msg; } } else { $msg = __('Could not connect to mailgate server'); if ($display) { Session::addMessageAfterRedirect($msg, false, ERROR); } else { return $msg; } } } else { //TRANS: %s is the ID of the mailgate $msg = sprintf(__('Could not find mailgate %d'), $mailgateID); if ($display) { Session::addMessageAfterRedirect($msg, false, ERROR); } else { return $msg; } } }
/** * Constructor * * @param $dbconnexion Database Connnexion (must be a CommonDBTM object) * @param $table string or array table name (optional when $crit have FROM entry) * @param $crit string or array of filed/values, ex array("id"=>1), if empty => all rows * (default '') * @param $debug for log the request (default false) **/ function __construct($dbconnexion, $table, $crit = "", $debug = false) { $this->conn = $dbconnexion; if (is_string($table) && strpos($table, " ")) { //if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { // trigger_error("Deprecated usage of SQL in DB/request (full query)", E_USER_DEPRECATED); //} $this->sql = $table; } else { // Modern way if (is_array($table) && isset($table['FROM'])) { // Shift the args $debug = $crit; $crit = $table; $table = $crit['FROM']; unset($crit['FROM']); } // Check field, orderby, limit, start in criterias $field = ""; $orderby = ""; $limit = 0; $start = 0; $distinct = ''; $where = ''; $count = ''; $join = ''; if (is_array($crit) && count($crit)) { foreach ($crit as $key => $val) { switch ((string) $key) { case 'SELECT': case 'FIELDS': $field = $val; unset($crit[$key]); break; case 'SELECT DISTINCT': case 'DISTINCT FIELDS': $field = $val; $distinct = "DISTINCT"; unset($crit[$key]); break; case 'COUNT': $count = $val; unset($crit[$key]); break; case 'ORDER': $orderby = $val; unset($crit[$key]); break; case 'LIMIT': $limit = $val; unset($crit[$key]); break; case 'START': $start = $val; unset($crit[$key]); break; case 'WHERE': $where = $val; unset($crit[$key]); break; case 'JOIN': if (is_array($val)) { foreach ($val as $jointable => $joincrit) { $join .= " LEFT JOIN " . self::quoteName($jointable) . " ON (" . $this->analyseCrit($joincrit) . ")"; } } else { trigger_error("BAD JOIN, value sould be [ table => criteria ]", E_USER_ERROR); } unset($crit[$key]); break; } } } // SELECT field list if ($count) { $this->sql = "SELECT COUNT(*) AS {$count}"; } else { if (is_array($field)) { $this->sql = ""; foreach ($field as $t => $f) { if (is_numeric($t)) { $this->sql .= (empty($this->sql) ? 'SELECT ' : ', ') . self::quoteName($f); } else { if (is_array($f)) { $t = self::quoteName($t); $f = array_map([__CLASS__, 'quoteName'], $f); $this->sql .= (empty($this->sql) ? "SELECT {$t}." : ",{$t}.") . implode(", {$t}.", $f); } else { $t = self::quoteName($t); $f = $f == '*' ? $f : self::quoteName($f); $this->sql .= (empty($this->sql) ? 'SELECT ' : ', ') . "{$t}.{$f}"; } } } } else { if (empty($field)) { $this->sql = "SELECT *"; } else { $this->sql = "SELECT {$distinct} " . self::quoteName($field); } } } // FROM table list if (is_array($table)) { if (count($table)) { $table = array_map([__CLASS__, 'quoteName'], $table); $this->sql .= ' FROM ' . implode(", ", $table); } else { trigger_error("Missing table name", E_USER_ERROR); } } else { if ($table) { $table = self::quoteName($table); $this->sql .= " FROM {$table}"; } else { /* * TODO filter with if ($where || !empty($crit)) { * but not usefull for now, as we CANNOT write somthing like "SELECT NOW()" */ trigger_error("Missing table name", E_USER_ERROR); } } // JOIN $this->sql .= $join; // WHERE criteria list if (!empty($crit)) { $this->sql .= " WHERE " . $this->analyseCrit($crit); } else { if ($where) { $this->sql .= " WHERE " . $this->analyseCrit($where); } } // ORDER BY if (is_array($orderby)) { $cleanorderby = array(); foreach ($orderby as $o) { $new = ''; $tmp = explode(' ', $o); $new .= self::quoteName($tmp[0]); // ASC OR DESC added if (isset($tmp[1]) && in_array($tmp[1], array('ASC', 'DESC'))) { $new .= ' ' . $tmp[1]; } $cleanorderby[] = $new; } $this->sql .= " ORDER BY " . implode(", ", $cleanorderby); } else { if (!empty($orderby)) { $this->sql .= " ORDER BY "; $tmp = explode(' ', $orderby); $this->sql .= self::quoteName($tmp[0]); // ASC OR DESC added if (isset($tmp[1]) && in_array($tmp[1], array('ASC', 'DESC'))) { $this->sql .= ' ' . $tmp[1]; } } } if (is_numeric($limit) && $limit > 0) { $this->sql .= " LIMIT {$limit}"; if (is_numeric($start) && $start > 0) { $this->sql .= " OFFSET {$start}"; } } } if ($debug) { toolbox::logdebug("Generated query:", $this->getSql()); } $this->res = $this->conn ? $this->conn->query($this->sql) : false; }
/** * Constructor * * @param $dbconnexion Database Connnexion (must be a CommonDBTM object) * @param $table table name * @param $crit string or array of filed/values, ex array("id"=>1), if empty => all rows * (default '') * @param $debug for log the request (default false) **/ function __construct($dbconnexion, $table, $crit = "", $debug = false) { $this->conn = $dbconnexion; if (is_string($table) && strpos($table, " ")) { $this->sql = $table; } else { // Check field, orderby, limit, start in criterias $field = ""; $orderby = ""; $limit = 0; $start = 0; $distinct = ''; $where = ''; if (is_array($crit) && count($crit)) { foreach ($crit as $key => $val) { if ($key === "FIELDS") { $field = $val; unset($crit[$key]); } else { if ($key === "DISTINCT FIELDS") { $field = $val; $distinct = "DISTINCT"; unset($crit[$key]); } else { if ($key === "ORDER") { $orderby = $val; unset($crit[$key]); } else { if ($key === "LIMIT") { $limit = $val; unset($crit[$key]); } else { if ($key === "START") { $start = $val; unset($crit[$key]); } else { if ($key === "WHERE") { $where = $val; unset($crit[$key]); } } } } } } } } // SELECT field list if (is_array($field)) { $this->sql = ""; foreach ($field as $t => $f) { if (is_numeric($t)) { $this->sql .= (empty($this->sql) ? 'SELECT ' : ', ') . self::quoteName($f); } else { if (is_array($f)) { $t = self::quoteName($t); $f = array_map([__CLASS__, 'quoteName'], $f); $this->sql .= (empty($this->sql) ? "SELECT {$t}." : ",{$t}.") . implode(", {$t}.", $f); } else { $t = self::quoteName($t); $f = self::quoteName($f); $this->sql .= (empty($this->sql) ? 'SELECT ' : ', ') . "{$t}.{$f}"; } } } } else { if (empty($field)) { $this->sql = "SELECT *"; } else { $this->sql = "SELECT {$distinct} `{$field}`"; } } // FROM table list if (is_array($table)) { $table = array_map([__CLASS__, 'quoteName'], $table); $this->sql .= ' FROM ' . implode(", ", $table); } else { $table = self::quoteName($table); $this->sql .= " FROM {$table}"; } // WHERE criteria list if (!empty($crit)) { $this->sql .= " WHERE " . $this->analyseCrit($crit); } else { if ($where) { $this->sql .= " WHERE " . $this->analyseCrit($where); } } // ORDER BY if (is_array($orderby)) { $cleanorderby = array(); foreach ($orderby as $o) { $new = ''; $tmp = explode(' ', $o); $new .= self::quoteName($tmp[0]); // ASC OR DESC added if (isset($tmp[1]) && in_array($tmp[1], array('ASC', 'DESC'))) { $new .= ' ' . $tmp[1]; } $cleanorderby[] = $new; } $this->sql .= " ORDER BY " . implode(", ", $cleanorderby); } else { if (!empty($orderby)) { $this->sql .= " ORDER BY "; $tmp = explode(' ', $orderby); $this->sql .= self::quoteName($tmp[0]); // ASC OR DESC added if (isset($tmp[1]) && in_array($tmp[1], array('ASC', 'DESC'))) { $this->sql .= ' ' . $tmp[1]; } } } if (is_numeric($limit) && $limit > 0) { $this->sql .= " LIMIT {$limit}"; if (is_numeric($start) && $start > 0) { $this->sql .= " OFFSET {$start}"; } } } if ($debug) { toolbox::logdebug("Generated query:", $this->getSql()); } $this->res = $this->conn ? $this->conn->query($this->sql) : false; }