public function process(&$return, $req) { $cf = new Change($this->settings, $this->changeFactory, $this->changeFactory->getCacher()); $cf->parseFile(DBC_EXECUTION_MODE == 'web' ? $req['file'] : $req[0]); $cf->setIsExecuted(true); $return['data'] = $cf->getAsyncStatus(); }
public function process(&$return, $req) { $cf = new Change($this->settings, $this->changeFactory, $this->changeFactory->getCacher()); $cf->parseFile(DBC_EXECUTION_MODE == 'web' ? $req['file'] : $req[0]); //only if the setting api_execute_async is true and execution_mode is web, then execute it async $async = $this->settings->getApiExecuteAsync() && DBC_EXECUTION_MODE == 'web'; $return['data'] = $cf->executeSql($async); }
function test_for_pennies() { //Arrange $test_user_input = new Change(); $user_change = 4; //Act $result = $test_user_input->giveChange($user_change); //Assert $this->assertEquals([0, 0, 0, 4], $result); }
function test_getPennies() { // Arrange $new_Change = new Change(); $input = 46; // Act $result = $new_Change->makeChange($input); // Assert $this->assertEquals("quarters:1 dimes:2 nickels:0 pennies:1", $result); }
function test_calculateOneQuarterOneDimeOneNickelFourPennies() { //Arrange $test_Change = new Change(); $input = 44; //Act $result = $test_Change->calculateChange($input); //Assert $this->assertEquals(array('pennies' => 4, 'nickels' => 1, 'dimes' => 1, 'quarters' => 1), $result); }
/** * Is the current user have right to create the current task ? * * @return boolean **/ function canCreateItem() { if (!parent::canReadITILItem()) { return false; } $change = new Change(); if ($change->getFromDB($this->fields['changes_id'])) { return Session::haveRight('change', UPDATE) || Session::haveRight('change', Change::READMY) && ($change->isUser(CommonITILActor::ASSIGN, Session::getLoginUserID()) || isset($_SESSION["glpigroups"]) && $change->haveAGroup(CommonITILActor::ASSIGN, $_SESSION['glpigroups'])); } return false; }
public function run($context) { $changes = changes_eurotlx(); $change = new Change(); $change->data = date('Y-m-d H:i:s'); foreach ($changes as $key => $val) { $change->{$key} = $val; } $change->_force_create = TRUE; $change->save(); printf("%s saved currency change rates\n", get_called_class()); }
function _populate_transactions() { $conn = $this->get_connection(); if (count($this->transactions) > 0) { foreach ($this->transactions as $transaction) { $transaction->stock = new Stock(); $transaction->stock->find_by_id($transaction->isin); $transaction->importo = 0; $parts = $transaction->find_all(array('where_clause' => "`negot_id` = '{$conn->escape($transaction->negot_id)}'")); if (count($parts) > 0) { foreach ($parts as $part) { $importo = $part->quantita * $part->prezzo; $importo /= $transaction->stock->divisa == 'USD' ? Change::usd2eur($part->data) : 1; $importo *= $part->azione == 'acquisto' ? -1 : 1; $importo /= $transaction->stock->tipo == 'obbligazione' ? 100 : 1; $comm = abs($importo) * $this->preference->comm_percent; if (strtotime($part->data) >= strtotime("2007-08-01")) { $comm = $comm > $this->preference->comm_percent_min ? $comm : $this->preference->comm_percent_min; } $importo -= $comm; $importo -= $this->preference->comm_fissa; $transaction->importo += $importo; } } $this->bilancio += $transaction->importo; } } }
public function importo_eur() { if (!isset($this->importo_eur)) { $this->importo_eur = Change::convert($this->importo, $this->stock->divisa, date('Y-m-d', $this->timestamp)); } return $this->importo_eur; }
public function __construct($productName) { self::$rootPath = str_replace('\\', '/', dirname(__FILE__)) . '/'; self::loadConfig(self::$rootPath . 'config.php'); $pro = self::getConfig('product'); self::$product = $pro[$productName]; }
public static function roi_with_timeline($isin, $username, $month_from, $month_to) { $conn = Db::get_connection(); $stock = new Stock(); if (!$stock->find_by_id($isin)) { return; } $portfolio_stock_factory = new PortfolioStock(); $portfolio_stocks = $portfolio_stock_factory->find_all(array('where_clause' => "`isin` = '{$conn->escape($isin)}' " . "AND `utente` = '{$conn->escape($username)}'")); if (count($portfolio_stocks) == 0) { return; } $portfolio_stock = $portfolio_stocks[0]; $quantita = self::quantita_history($isin, $username, $month_from); switch ($stock->tipo) { case 'obbligazione': $investito = $portfolio_stock->prezzo * $portfolio_stock->quantita / 100; break; default: $investito = $portfolio_stock->prezzo * $portfolio_stock->quantita; } $investito = Change::convert($investito, $stock->divisa); $roi = PianificatoreHelper::roi_with_timeline($isin, $quantita, $month_from, $month_to, $investito); foreach ($roi->payments as $payment) { $payment->portfolio_stock = $portfolio_stock; } // print_r($roi); return $roi; }
/** * Action methods */ public function index() { //$this->last = Change::usd2eur(); $conn = $this->get_connection(); $yesterday = date('Y-m-d', mktime(0, 0, 0, isset($_REQUEST['month']) ? $_REQUEST['month'] : date('m'), (isset($_REQUEST['day']) ? $_REQUEST['day'] : date('d')) - 1, isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y'))); $tomorrow = date('Y-m-d', mktime(0, 0, 0, isset($_REQUEST['month']) ? $_REQUEST['month'] : date('m'), (isset($_REQUEST['day']) ? $_REQUEST['day'] : date('d')) + 1, isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y'))); $change = new Change(); $changes = $change->find_by_query('SELECT `data`, `usd2eur` ' . 'FROM `creso_cambi` ' . "WHERE 1 " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `usd2eur` DESC ' . 'LIMIT 1'); $this->day_max = $changes[0]; $changes = $change->find_by_query('SELECT `data`, `usd2eur` ' . 'FROM `creso_cambi` ' . "WHERE 1 " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `usd2eur` ASC ' . 'LIMIT 1'); $this->day_min = $changes[0]; $changes = $change->find_by_query('SELECT `data`, `usd2eur` ' . 'FROM `creso_cambi` ' . "WHERE 1 " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `data` ASC ' . 'LIMIT 1'); $this->open = $changes[0]; $changes = $change->find_by_query('SELECT `data`, `usd2eur` ' . 'FROM `creso_cambi` ' . "WHERE 1 " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `data` DESC ' . 'LIMIT 1'); $this->last = $changes[0]; $this->redirect_to(array_merge($_REQUEST, array('query_string' => $this->request->querystring, 'after' => 300))); }
/** * Returns the changes partitioned by change type. * * @return array An array of type => array of changes. */ protected function _partitionByType() { $types = Change::types(); $result = array_combine(array_keys($types), array_fill(0, count($types), [])); foreach ($this->_changes as $change) { $result[$change->getType()][] = $change; } return array_filter($result); }
public function test_accessors() { /** === Test Data === */ $CUST_ID = 'cust ID'; $DATE_CHANGED = 'changed at'; $ID = 'id'; $PARENT_ID = 'id'; /** === Call and asserts === */ $this->obj->setCustomerId($CUST_ID); $this->obj->setDateChanged($DATE_CHANGED); $this->obj->setId($ID); $this->obj->setParentId($PARENT_ID); $this->assertEquals($CUST_ID, $this->obj->getCustomerId()); $this->assertEquals($DATE_CHANGED, $this->obj->getDateChanged()); $this->assertEquals($ID, $this->obj->getId()); $this->assertEquals($PARENT_ID, $this->obj->getParentId()); }
public function process(&$return, $req) { if (DBC_EXECUTION_MODE != 'cli') { throw new Exception('runAll is only valid in CLI mode.'); } parent::process($return, $req); $cardStack = (array) $return['data']; $cardStack = array_reverse($cardStack); //execute in reverse order $errCount = 0; $cardCount = sizeof($cardStack); foreach ($cardStack as $entry) { try { $changeFile = $entry['file']; $cf = new Change($this->settings, $this->changeFactory, $this->changeFactory->getCacher()); $cf->parseFile($changeFile); try { if (!$cf->doExecuteSql()) { $errStat = $cf->getAsyncStatus(); throw new Exception($errStat['message']); } echo '[DONE] ' . $changeFile . PHP_EOL; } catch (Exception $e) { $errCount++; echo '[FAILED] ' . $changeFile . ' :: ' . $e->getMessage() . PHP_EOL; echo $cf->getSql() . PHP_EOL; if (in_array('--force', $req) || in_array('-f', $req)) { try { $cf->failedToExecuted(); echo '[IGNORE] ' . $changeFile . PHP_EOL; } catch (Exception $e) { echo '[FAILED] ' . $changeFile . ' IGNORE FAILED :: ' . $e->getMessage() . PHP_EOL; } } } } catch (Execution $e) { echo '[FAILED] ' . $changeFile . ' Unrecoverable error :: ' . $e->getMessage() . PHP_EOL; } if (sizeof($cf->getExecute())) { echo '[IGNORE] ' . $changeFile . ' PATCHES: ' . implode(', ', $cf->getExecute()) . PHP_EOL; } } $return['data'] = PHP_EOL . '*** FINISHED ' . $cardCount . ' CHANGES' . ($errCount ? ' WITH ' . $errCount . ' FAIL(S)' : ' SUCCESSFULLY'); $return['status'] = 'ok'; }
/** * @param ChangeFile $cf * @param bool $overwrite * @throws Exception */ public function store(Change $cf, $overwrite = true) { if ($cf->getIssueNumber() == '') { throw new Exception('Issue# is empty.'); } if ((int) $cf->getIssueCount() == 0) { throw new Exception('Issue Count is empty.'); } $filename = $cf->generateFilename($cf->getIssueNumber(), $cf->getIssueCount()); if (!$overwrite) { if (parent::fileExists($this->getDir(self::FILE_ROOT), $filename)) { throw new Exception('Change already exists.'); } } parent::save($this->getDir(self::FILE_ROOT), $filename, $cf->stringify()); }
/** * Action methods */ public function index() { switch ($_REQUEST['evento']) { case 'cedola': $events = $this->get_cedole(); break; case 'dividendo': $events = $this->get_dividendi(); break; case 'rimborso': $events = $this->get_rimborsi(); break; default: if (isset($_REQUEST['isin']) && isset($_REQUEST['use_helper'])) { $this->roi = PortfolioHelper::roi_with_timeline($_REQUEST['isin'], $_COOKIE['username'], $_REQUEST['month-from'], $_REQUEST['month-to']); $events = $this->roi->payments; $this->investito = $this->roi->investito; $this->totale = $this->roi->totale; $this->plusminus = $this->roi->plusminus; } else { $events = array_merge($this->get_cedole(), $this->get_rimborsi(), $this->get_dividendi()); $this->investito = 0; $this->plusminus = 0; foreach ($events as $event) { $investito = $event->portfolio_stock->prezzo * $event->quantita / 100; $investito = Change::convert($investito, $event->stock->divisa); if ($event->tipo == 'rimborso') { $this->investito += $investito; } $plusminus = $event->importo_eur() - $investito; $this->plusminus += $plusminus; } } } $this->payments($events); $this->render(array('action' => 'payments')); }
/** * Returns a short markdown snippet of the pull request for use in release notes. * * @return string A short representation of the pull request. */ public function displayShort() { return parent::displayShort() . " <sup>[PR #{$this->_number}]</sup>"; }
/** * Generic Function to display Items * * @param $itemtype item type * @param $ID ID of the SEARCH_OPTION item * @param $data array containing data results * @param $num item num in the request * @param $meta is a meta item ? (default 0) * @param $addobjectparams array added parameters for union search * * @return string to print **/ static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array()) { global $CFG_GLPI, $DB; $searchopt =& self::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) { return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']); } return self::giveItem($data["TYPE"], $ID, $data, $num, $meta); } if (count($addobjectparams)) { $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams); } // Plugin can override core definition for its type if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } $NAME = "ITEM_"; // if ($meta) { // $NAME = "META_"; // } if (isset($searchopt[$ID]["table"])) { $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $linkfield = $searchopt[$ID]["linkfield"]; /// TODO try to clean all specific cases using SpecificToDisplay switch ($table . '.' . $field) { case "glpi_users.name": // USER search case if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) { $out = ""; $count_display = 0; $added = array(); $showuserlink = 0; if (Session::haveRight('user', READ)) { $showuserlink = 1; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0 || isset($data[$num][$k][2]) && $data[$num][$k][2] != '') { if ($count_display) { $out .= self::LBBR; } if ($itemtype == 'Ticket') { if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0) { $userdata = getUserName($data[$num][$k]['name'], 2); $tooltip = ""; if (Session::haveRight('user', READ)) { $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip); $count_display++; } } else { $out .= getUserName($data[$num][$k]['name'], $showuserlink); $count_display++; } // Manage alternative_email for tickets_users if ($itemtype == 'Ticket' && isset($data[$num][$k][2])) { $split = explode(self::LONGSEP, $data[$num][$k][2]); for ($l = 0; $l < count($split); $l++) { $split2 = explode(" ", $split[$l]); if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>"; } } } } } return $out; } if ($itemtype != 'User') { $toadd = ''; if ($itemtype == 'Ticket' && $data[$num][0]['id'] > 0) { $userdata = getUserName($data[$num][0]['id'], 2); $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } $usernameformat = formatUserName($data[$num][0]['id'], $data[$num][0]['name'], $data[$num][0]['realname'], $data[$num][0]['firstname'], 1); return sprintf(__('%1$s %2$s'), $usernameformat, $toadd); } break; case "glpi_profiles.name": if ($itemtype == 'User' && $ID == 20) { $out = ""; $count_display = 0; $added = array(); for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_entities', $data[$num][$k]['entities_id'])); $comp = ''; if ($data[$num][$k]['is_recursive']) { $comp = __('R'); if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, __('D')); } if (!empty($comp)) { $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")"); } if (!in_array($text, $added)) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_entities.completename": if ($itemtype == 'User') { $out = ""; $added = array(); $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_profiles', $data[$num][$k]['profiles_id'])); $comp = ''; if ($data[$num][$k]['is_recursive']) { $comp = __('R'); if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, __('D')); } if (!empty($comp)) { $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")"); } if (!in_array($text, $added)) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_documenttypes.icon": if (!empty($data[$num][0]['name'])) { return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$num][0]['name'] . "'>"; } return " "; case "glpi_documents.filename": $doc = new Document(); if ($doc->getFromDB($data['id'])) { return $doc->getDownloadLink(); } return NOT_AVAILABLE; case "glpi_tickets_tickets.tickets_id_1": $out = ""; $displayed = array(); for ($k = 0; $k < $data[$num]['count']; $k++) { $linkid = $data[$num][$k]['tickets_id_2'] == $data['id'] ? $data[$num][$k]['name'] : $data[$num][$k]['tickets_id_2']; if ($linkid > 0 && !isset($displayed[$linkid])) { $text = "<a "; $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">"; $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>"; if (count($displayed)) { $out .= self::LBBR; } $displayed[$linkid] = $linkid; $out .= $text; } } return $out; case "glpi_problems.id": if ($searchopt[$ID]["datatype"] == 'count') { if ($data[$num][0]['name'] > 0 && Session::haveRight("problem", Problem::READALL)) { if ($itemtype == 'ITILCategory') { $options['criteria'][0]['field'] = 7; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } else { $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $itemtype; $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $data['id']; $options['metacriteria'][0]['link'] = 'AND'; } $options['reset'] = 'reset'; $out = "<a id='problem{$itemtype}" . $data['id'] . "' "; $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&') . "\">"; $out .= $data[$num][0]['name'] . "</a>"; return $out; } } break; case "glpi_tickets.id": if ($searchopt[$ID]["datatype"] == 'count') { if ($data[$num][0]['name'] > 0 && Session::haveRight("ticket", Ticket::READALL)) { if ($itemtype == 'User') { // Requester if ($ID == 60) { $options['criteria'][0]['field'] = 4; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } // Writer if ($ID == 61) { $options['criteria'][0]['field'] = 22; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } // Assign if ($ID == 64) { $options['criteria'][0]['field'] = 5; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } } else { if ($itemtype == 'ITILCategory') { $options['criteria'][0]['field'] = 7; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } else { $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $itemtype; $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $data['id']; $options['metacriteria'][0]['link'] = 'AND'; } } $options['reset'] = 'reset'; $out = "<a id='ticket{$itemtype}" . $data['id'] . "' "; $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "\">"; $out .= $data[$num][0]['name'] . "</a>"; return $out; } } break; case "glpi_tickets.due_date": case "glpi_problems.due_date": case "glpi_changes.due_date": // Due date + progress if ($ID == 151) { $out = Html::convDate($data[$num][0]['name']); // No due date in waiting status if ($data[$num][0]['status'] == CommonITILObject::WAITING) { return ''; } if (empty($data[$num][0]['name'])) { return ''; } if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) { return $out; } $itemtype = getItemTypeForTable($table); $item = new $itemtype(); $item->getFromDB($data['id']); $percentage = 0; $totaltime = 0; $currenttime = 0; if ($item->isField('slas_id') && $item->fields['slas_id'] != 0) { // Have SLA $sla = new SLA(); $sla->getFromDB($item->fields['slas_id']); $currenttime = $sla->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s')); $totaltime = $sla->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']); } else { $calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']); if ($calendars_id != 0) { // Ticket entity have calendar $calendar = new Calendar(); $calendar->getFromDB($calendars_id); $currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s')); $totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']); } else { // No calendar $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']); $totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']); } } if ($totaltime != 0) { $percentage = round(100 * $currenttime / $totaltime); } else { // Total time is null : no active time $percentage = 100; } if ($percentage > 100) { $percentage = 100; } $percentage_text = $percentage; if ($_SESSION['glpiduedatewarning_unit'] == '%') { $less_warn_limit = $_SESSION['glpiduedatewarning_less']; $less_warn = 100 - $percentage; } else { if ($_SESSION['glpiduedatewarning_unit'] == 'hour') { $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP; $less_warn = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatewarning_unit'] == 'day') { $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP; $less_warn = $totaltime - $currenttime; } } } if ($_SESSION['glpiduedatecritical_unit'] == '%') { $less_crit_limit = $_SESSION['glpiduedatecritical_less']; $less_crit = 100 - $percentage; } else { if ($_SESSION['glpiduedatecritical_unit'] == 'hour') { $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP; $less_crit = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatecritical_unit'] == 'day') { $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP; $less_crit = $totaltime - $currenttime; } } } $color = $_SESSION['glpiduedateok_color']; if ($less_crit < $less_crit_limit) { $color = $_SESSION['glpiduedatecritical_color']; } else { if ($less_warn < $less_warn_limit) { $color = $_SESSION['glpiduedatewarning_color']; } } //Calculate bar progress $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n border: 1px solid #9BA563; position: relative;' >"; $out .= "<div style='position:absolute;'> " . $percentage_text . "%</div>"; $out .= "<div class='center' style='background-color: " . $color . ";\n width: " . $percentage . "%; height: 12px' ></div>"; $out .= "</div>"; return $out; } break; case "glpi_softwarelicenses.number": if ($data[$num][0]['min'] == -1) { return __('Unlimited'); } if (empty($data[$num][0]['name'])) { return 0; } return $data[$num][0]['name']; case "glpi_auth_tables.name": return Auth::getMethodName($data[$num][0]['name'], $data[$num][0]['auths_id'], 1, $data[$num][0]['ldapname'] . $data[$num][0]['mailname']); case "glpi_reservationitems.comment": if (empty($data[$num][0]['name'])) { return "<a title=\"" . __s('Modify the comment') . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>"; } return "<a title=\"" . __s('Modify the comment') . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$num][0]['name']) . "</a>"; case 'glpi_crontasks.description': $tmp = new CronTask(); return $tmp->getDescription($data[$num][0]['name']); case 'glpi_changes.status': $status = Change::getStatus($data[$num][0]['name']); return "<img src=\"" . Change::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_problems.status': $status = Problem::getStatus($data[$num][0]['name']); return "<img src=\"" . Problem::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.status': $status = Ticket::getStatus($data[$num][0]['name']); return "<img src=\"" . Ticket::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_projectstates.name': $out = ''; $query = "SELECT `color`\n FROM `glpi_projectstates`\n WHERE `name` = '" . $data[$num][0]['name'] . "'"; foreach ($DB->request($query) as $color) { $color = $color['color']; $out = "<div style=\"background-color:" . $color . ";\">"; $name = $data[$num][0]['name']; if (isset($data[$num][0]['trans'])) { $name = $data[$num][0]['trans']; } if ($itemtype == 'ProjectState') { $out .= "<a href='" . $CFG_GLPI["root_doc"] . "/front/projectstate.form.php?id=" . $data[$num][0]["id"] . "'>" . $name . "</a></div>"; } else { $out .= $name . "</div>"; } } return $out; case 'glpi_items_tickets.items_id': case 'glpi_items_problems.items_id': if (!empty($data[$num])) { $items = array(); foreach ($data[$num] as $key => $val) { if (is_numeric($key)) { if (!empty($val['itemtype']) && ($item = getItemForItemtype($val['itemtype']))) { if ($item->getFromDB($val['name'])) { $items[] = $item->getLink(array('comments' => true)); } } } } if (!empty($items)) { return implode("<br>", $items); } } return ' '; case 'glpi_items_tickets.itemtype': case 'glpi_items_problems.itemtype': if (!empty($data[$num])) { $itemtypes = array(); foreach ($data[$num] as $key => $val) { if (is_numeric($key)) { if (!empty($val['name'])) { if (substr($val['name'], 0, 6) == 'Plugin') { $plug = new $val['name'](); $name = $plug->getTypeName(); $itemtypes[] = __($name); } else { $itemtypes[] = __($val['name']); } } } } if (!empty($itemtypes)) { return implode("<br>", $itemtypes); } } return ' '; case 'glpi_tickets.name': case 'glpi_problems.name': case 'glpi_changes.name': if (isset($data[$num][0]['content']) && isset($data[$num][0]['id']) && isset($data[$num][0]['status'])) { $link = Toolbox::getItemTypeFormURL($itemtype); $out = "<a id='{$itemtype}" . $data[$num][0]['id'] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$num][0]['id']; // Force solution tab if solved if ($item = getItemForItemtype($itemtype)) { if (in_array($data[$num][0]['status'], $item->getSolvedStatusArray())) { $out .= "&forcetab={$itemtype}\$2"; } } $out .= "\">"; $name = $data[$num][0]['name']; if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][0]['id']); } $out .= $name . "</a>"; $hdecode = Html::entity_decode_deep($data[$num][0]['content']); $content = Toolbox::unclean_cross_side_scripting_deep($hdecode); $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br(Html::Clean($content)), array('applyto' => $itemtype . $data[$num][0]['id'], 'display' => false))); return $out; } case 'glpi_ticketvalidations.status': $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if ($data[$num][$k]['name']) { $status = TicketValidation::getStatus($data[$num][$k]['name']); $bgcolor = TicketValidation::getStatusColor($data[$num][$k]['name']); $out .= (empty($out) ? '' : self::LBBR) . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } } return $out; case 'glpi_ticketsatisfactions.satisfaction': if (self::$output_type == self::HTML_OUTPUT) { return TicketSatisfaction::displaySatisfaction($data[$num][0]['name']); } break; case 'glpi_projects._virtual_planned_duration': return Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($data["id"]), false); case 'glpi_projects._virtual_effective_duration': return Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($data["id"]), false); case 'glpi_cartridgeitems._virtual': return Cartridge::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT); case 'glpi_printers._virtual': return Cartridge::getCountForPrinter($data["id"], self::$output_type != self::HTML_OUTPUT); case 'glpi_consumableitems._virtual': return Consumable::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT); case 'glpi_links._virtual': $out = ''; $link = new Link(); if (($item = getItemForItemtype($itemtype)) && $item->getFromDB($data['id']) && $link->getfromDB($data[$num][0]['id']) && $item->fields['entities_id'] == $link->fields['entities_id']) { if (count($data[$num])) { $count_display = 0; foreach ($data[$num] as $val) { if (is_array($val)) { $links = Link::getAllLinksFor($item, $val); foreach ($links as $link) { if ($count_display) { $out .= self::LBBR; } $out .= $link; $count_display++; } } } } } return $out; case 'glpi_reservationitems._virtual': if ($data[$num][0]['is_active']) { return "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>"; } else { return " "; } } } //// Default case // Link with plugin tables : need to know left join structure if (isset($table)) { if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) { if (count($matches) == 2) { $plug = $matches[1]; $function = 'plugin_' . $plug . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } } } $unit = ''; if (isset($searchopt[$ID]['unit'])) { $unit = $searchopt[$ID]['unit']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]); $out = ""; $count_display = 0; $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (isset($data[$num][$k]['id'])) { if ($count_display) { $out .= $separate; } $count_display++; $page = $linkitemtype::getFormUrl(); $page .= strpos($page, '?') ? '&id' : '?id'; $name = Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit); if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][$k]['name'])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][$k]['id']); } $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $data[$num][$k]['id'] . "' href='{$page}=" . $data[$num][$k]['id'] . "'>" . $name . "</a>"; } } return $out; case "text": $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } $out = ''; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= $separate; } $count_display++; $text = ""; if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) { $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($data[$num][$k]['name']))); } else { $text = nl2br($data[$num][$k]['name']); } if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) { $rand = mt_rand(); $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false))); } else { $out .= $text; } } } return $out; case "date": case "date_delay": $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) { $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel']; } else { $out .= (empty($out) ? '' : self::LBBR) . Html::convDate($data[$num][$k]['name']); } } return $out; case "datetime": $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) { $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel']; } else { $out .= (empty($out) ? '' : self::LBBR) . Html::convDateTime($data[$num][$k]['name']); } } return $out; case "timestamp": $withseconds = false; if (isset($searchopt[$ID]['withseconds'])) { $withseconds = $searchopt[$ID]['withseconds']; } $withdays = true; if (isset($searchopt[$ID]['withdays'])) { $withdays = $searchopt[$ID]['withdays']; } $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($data[$num][$k]['name'], $withseconds, $withdays); } return $out; case "email": $out = ''; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (!empty($data[$num][$k]['name'])) { $out .= empty($out) ? '' : self::LBBR; $out .= "<a href='mailto:" . $data[$num][$k]['name'] . "'>" . $data[$num][$k]['name']; $out .= "</a>"; } } return empty($out) ? " " : $out; case "weblink": $orig_link = trim($data[$num][0]['name']); if (!empty($orig_link)) { // strip begin of link $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link); $link = preg_replace('/\\/$/', '', $link); if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) { $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "..."; } return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>"; } return " "; case "count": case "number": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { $number = str_replace(' ', ' ', Html::formatNumber($data[$num][$k]['name'], false, 0)); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; case "decimal": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { $number = str_replace(' ', ' ', Html::formatNumber($data[$num][$k]['name'])); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; case "bool": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$num][$k]['name']), $unit); } } return $out; case "itemtypename": if ($obj = getItemForItemtype($data[$num][0]['name'])) { return $obj->getTypeName(); } return ""; case "language": if (isset($CFG_GLPI['languages'][$data[$num][0]['name']])) { return $CFG_GLPI['languages'][$data[$num][0]['name']][0]; } return __('Default value'); } } // Manage items with need group by / group_concat $out = ""; $count_display = 0; $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= $separate; } $count_display++; // Get specific display if available $itemtype = getItemTypeForTable($table); if ($item = getItemForItemtype($itemtype)) { $tmpdata = $data[$num][$k]; // Copy name to real field $tmpdata[$field] = $data[$num][$k]['name']; $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true, 'searchopt' => $searchopt[$ID])); } if (!empty($specific)) { $out .= $specific; } else { if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { // Empty is 0 or empty if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) { $out .= $searchopt[$ID]['emptylabel']; } else { // Trans field exists if (isset($data[$num][$k]['trans']) && !empty($data[$num][$k]['trans'])) { $out .= Dropdown::getValueWithUnit($data[$num][$k]['trans'], $unit); } else { $out .= Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit); } } } } } } return $out; // Trans in group concat if (count($split) == 3 && !empty($split[1])) { return Dropdown::getValueWithUnit($split[1], $unit); } return Dropdown::getValueWithUnit($split[0], $unit); }
function post_deleteFromDB() { global $CFG_GLPI; $donotif = $CFG_GLPI["use_mailing"]; // if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) { // $donotif = false; // } $item = $this->getConnexityItem(static::$itemtype_1, static::getItilObjectForeignKey()); if ($item instanceof CommonDBTM) { if ($item->countSuppliers(CommonITILActor::ASSIGN) == 0 && $item->countUsers(CommonITILActor::ASSIGN) == 0 && $item->countGroups(CommonITILActor::ASSIGN) == 0 && $item->fields['status'] != CommonITILObject::CLOSED && $item->fields['status'] != CommonITILObject::SOLVED) { $status = CommonITILObject::INCOMING; if (in_array($item->fields['status'], Change::getNewStatusArray())) { $status = $item->fields['status']; } $item->update(array('id' => $this->fields[static::getItilObjectForeignKey()], 'status' => $status)); } else { $item->updateDateMod($this->fields[static::getItilObjectForeignKey()]); if ($donotif) { $options = array(); if (isset($this->fields['users_id'])) { $options = array('_old_user' => $this->fields); } NotificationEvent::raiseEvent("update", $item, $options); } } } parent::post_deleteFromDB(); }
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'Change': self::showForChange($item); break; default: Change::showListForItem($item); } return true; }
/** * @see NotificationTargetCommonITILObject::getDatasForObject() **/ function getDatasForObject(CommonDBTM $item, array $options, $simple = false) { global $CFG_GLPI; // Common ITIL datas $datas = parent::getDatasForObject($item, $options, $simple); $datas['##ticket.description##'] = Html::clean($datas['##ticket.description##']); $datas['##ticket.description##'] = $item->convertContentForNotification($datas['##ticket.description##'], $item); $datas['##ticket.content##'] = $datas['##ticket.description##']; // Specific datas $datas['##ticket.urlvalidation##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . "_TicketValidation\$1"); $datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($item->getField('global_validation')); $datas['##ticket.type##'] = Ticket::getTicketTypeName($item->getField('type')); $datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $item->getField('requesttypes_id')); $autoclose_value = Entity::getUsedConfig('autoclose_delay', $this->getEntity(), '', Entity::CONFIG_NEVER); $datas['##ticket.autoclose##'] = __('Never'); $datas['##lang.ticket.autoclosewarning##'] = ""; if ($autoclose_value > 0) { $datas['##ticket.autoclose##'] = $autoclose_value; $datas['##lang.ticket.autoclosewarning##'] = sprintf(_n('Without a reply, the ticket will be automatically closed after %s day', 'Without a reply, the ticket will be automatically closed after %s days', $autoclose_value), $autoclose_value); } $datas['##ticket.sla##'] = ''; if ($item->getField('slas_id')) { $datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $item->getField('slas_id')); } $datas['##ticket.location##'] = ''; if ($item->getField('locations_id')) { $datas['##ticket.location##'] = Dropdown::getDropdownName('glpi_locations', $item->getField('locations_id')); } // is ticket deleted $datas['##ticket.isdeleted##'] = Dropdown::getYesNo($item->getField('is_deleted')); //Tags associated with the object linked to the ticket $datas['##ticket.itemtype##'] = ''; $datas['##ticket.item.name##'] = ''; $datas['##ticket.item.serial##'] = ''; $datas['##ticket.item.otherserial##'] = ''; $datas['##ticket.item.location##'] = ''; $datas['##ticket.item.contact##'] = ''; $datas['##ticket.item.contactnumber##'] = ''; $datas['##ticket.item.user##'] = ''; $datas['##ticket.item.group##'] = ''; $datas['##ticket.item.model##'] = ''; $item_ticket = new Item_Ticket(); $items = $item_ticket->find("`tickets_id` = '" . $item->getField('id') . "'"); $datas['items'] = array(); if (count($items)) { foreach ($items as $val) { if (isset($val['itemtype']) && ($hardware = getItemForItemtype($val['itemtype'])) && isset($val["items_id"]) && $hardware->getFromDB($val["items_id"])) { $tmp = array(); //Object type $tmp['##ticket.itemtype##'] = $hardware->getTypeName(); //Object name $tmp['##ticket.item.name##'] = $hardware->getField('name'); //Object serial if ($hardware->isField('serial')) { $tmp['##ticket.item.serial##'] = $hardware->getField('serial'); } //Object contact if ($hardware->isField('contact')) { $tmp['##ticket.item.contact##'] = $hardware->getField('contact'); } //Object contact num if ($hardware->isField('contact_num')) { $tmp['##ticket.item.contactnumber##'] = $hardware->getField('contact_num'); } //Object otherserial if ($hardware->isField('otherserial')) { $tmp['##ticket.item.otherserial##'] = $hardware->getField('otherserial'); } //Object location if ($hardware->isField('locations_id')) { $tmp['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $hardware->getField('locations_id')); } //Object user if ($hardware->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($hardware->getField('users_id'))) { $tmp['##ticket.item.user##'] = $user_tmp->getName(); } } //Object group if ($hardware->getField('groups_id')) { $tmp['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $hardware->getField('groups_id')); } $modeltable = getSingular($hardware->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($hardware->isField($modelfield)) { $tmp['##ticket.item.model##'] = Dropdown::getDropdownName($modeltable, $hardware->getField($modelfield)); } $datas['items'][] = $tmp; } } } $datas['##ticket.numberofitems##'] = count($datas['items']); // Get followups, log, validation, satisfaction, linked tickets if (!$simple) { // Linked tickets $linked_tickets = Ticket_Ticket::getLinkedTicketsTo($item->getField('id')); $datas['linkedtickets'] = array(); if (count($linked_tickets)) { $linkedticket = new Ticket(); foreach ($linked_tickets as $data) { if ($linkedticket->getFromDB($data['tickets_id'])) { $tmp = array(); $tmp['##linkedticket.id##'] = $data['tickets_id']; $tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']); $tmp['##linkedticket.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $data['tickets_id']); $tmp['##linkedticket.title##'] = $linkedticket->getField('name'); $tmp['##linkedticket.content##'] = $linkedticket->getField('content'); $datas['linkedtickets'][] = $tmp; } } } $datas['##ticket.numberoflinkedtickets##'] = count($datas['linkedtickets']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $problems = getAllDatasFromTable('glpi_problems_tickets', $restrict); $datas['problems'] = array(); if (count($problems)) { $problem = new Problem(); foreach ($problems as $data) { if ($problem->getFromDB($data['problems_id'])) { $tmp = array(); $tmp['##problem.id##'] = $data['problems_id']; $tmp['##problem.date##'] = $problem->getField('date'); $tmp['##problem.title##'] = $problem->getField('name'); $tmp['##problem.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "problem_" . $data['problems_id']); $tmp['##problem.content##'] = $problem->getField('content'); $datas['problems'][] = $tmp; } } } $datas['##ticket.numberofproblems##'] = count($datas['problems']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $changes = getAllDatasFromTable('glpi_changes_tickets', $restrict); $datas['changes'] = array(); if (count($changes)) { $change = new Change(); foreach ($changes as $data) { if ($change->getFromDB($data['changes_id'])) { $tmp = array(); $tmp['##change.id##'] = $data['changes_id']; $tmp['##change.date##'] = $change->getField('date'); $tmp['##change.title##'] = $change->getField('name'); $tmp['##change.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "change_" . $data['changes_id']); $tmp['##change.content##'] = $change->getField('content'); $datas['changes'][] = $tmp; } } } $datas['##ticket.numberofchanges##'] = count($datas['changes']); if (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private']) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; //Followup infos $followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $datas['followups'] = array(); foreach ($followups as $followup) { $tmp = array(); $tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']); $tmp['##followup.author##'] = Html::clean(getUserName($followup['users_id'])); $tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']); $tmp['##followup.date##'] = Html::convDateTime($followup['date']); $tmp['##followup.description##'] = $followup['content']; $datas['followups'][] = $tmp; } $datas['##ticket.numberoffollowups##'] = count($datas['followups']); // Approbation of solution $restrict .= " LIMIT 1"; $replysolved = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $data = current($replysolved); $datas['##ticket.solution.approval.description##'] = $data['content']; $datas['##ticket.solution.approval.date##'] = Html::convDateTime($data['date']); $datas['##ticket.solution.approval.author##'] = Html::clean(getUserName($data['users_id'])); //Validation infos $restrict = "`tickets_id`='" . $item->getField('id') . "'"; if (isset($options['validation_id']) && $options['validation_id']) { $restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'"; } $restrict .= " ORDER BY `submission_date` DESC, `id` ASC"; $validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict); $datas['validations'] = array(); foreach ($validations as $validation) { $tmp = array(); $tmp['##validation.submission.title##'] = sprintf(__('An approval request has been submitted by %s'), Html::clean(getUserName($validation['users_id']))); $tmp['##validation.answer.title##'] = sprintf(__('An answer to an an approval request was produced by %s'), Html::clean(getUserName($validation['users_id_validate']))); $tmp['##validation.author##'] = Html::clean(getUserName($validation['users_id'])); $tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']); $tmp['##validation.storestatus##'] = $validation['status']; $tmp['##validation.submissiondate##'] = Html::convDateTime($validation['submission_date']); $tmp['##validation.commentsubmission##'] = $validation['comment_submission']; $tmp['##validation.validationdate##'] = Html::convDateTime($validation['validation_date']); $tmp['##validation.validator##'] = Html::clean(getUserName($validation['users_id_validate'])); $tmp['##validation.commentvalidation##'] = $validation['comment_validation']; $datas['validations'][] = $tmp; } // Ticket Satisfaction $inquest = new TicketSatisfaction(); $datas['##satisfaction.type##'] = ''; $datas['##satisfaction.datebegin##'] = ''; $datas['##satisfaction.dateanswered##'] = ''; $datas['##satisfaction.satisfaction##'] = ''; $datas['##satisfaction.description##'] = ''; if ($inquest->getFromDB($item->getField('id'))) { // internal inquest if ($inquest->fields['type'] == 1) { $datas['##ticket.urlsatisfaction##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . '_Ticket$3'); // external inquest } else { if ($inquest->fields['type'] == 2) { $datas['##ticket.urlsatisfaction##'] = Entity::generateLinkSatisfaction($item); } } $datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type')); $datas['##satisfaction.datebegin##'] = Html::convDateTime($inquest->fields['date_begin']); $datas['##satisfaction.dateanswered##'] = Html::convDateTime($inquest->fields['date_answered']); $datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction']; $datas['##satisfaction.description##'] = $inquest->fields['comment']; } } return $datas; }
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.85 */ if (!defined('GLPI_ROOT')) { include '../inc/includes.php'; } $link = new Change_User(); $item = new Change(); Session::checkLoginUser(); Html::popHeader(__('Email followup'), $_SERVER['PHP_SELF']); if (isset($_POST["update"])) { $link->check($_POST["id"], UPDATE); $link->update($_POST); echo "<script type='text/javascript' >\n"; echo "window.parent.location.reload();"; echo "</script>"; } else { if (isset($_POST['delete'])) { $link->check($_POST['id'], DELETE); $link->delete($_POST); Event::log($link->fields['changes_id'], "change", 4, "maintain", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"])); if ($item->can($link->fields["changes_id"], READ)) { Html::redirect($CFG_GLPI["root_doc"] . "/front/change.form.php?id=" . $link->fields['changes_id']);
based on GLPI - Gestionnaire Libre de Parc Informatique Copyright (C) 2003-2014 by the INDEPNET Development Team. ------------------------------------------------------------------------- LICENSE This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::haveRightsOr('change', array(Change::READALL, Change::READMY)); Html::header(Change::getTypeName(Session::getPluralNumber()), '', "helpdesk", "change"); Search::show('Change'); Html::footer();
/** * Show changes for a ticket * * @param $ticket Ticket object **/ static function showForTicket(Ticket $ticket) { global $DB, $CFG_GLPI; $ID = $ticket->getField('id'); if (!$ticket->can($ID, READ)) { return false; } $canedit = $ticket->canEdit($ID); $rand = mt_rand(); $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n `glpi_changes`.*\n FROM `glpi_changes_tickets`\n LEFT JOIN `glpi_changes`\n ON (`glpi_changes_tickets`.`changes_id` = `glpi_changes`.`id`)\n WHERE `glpi_changes_tickets`.`tickets_id` = '{$ID}'\n ORDER BY `glpi_changes`.`name`"; $result = $DB->query($query); $changes = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $changes[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeticket_form{$rand}' id='changeticket_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a change') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; Change::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID())); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td><td>"; if (Session::haveRight('change', CREATE)) { echo "<a href='" . Toolbox::getItemTypeFormURL('Change') . "?tickets_id={$ID}'>"; _e('Create a change from this ticket'); echo "</a>"; } echo "</td></tr></table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'><th colspan='12'>" . Change::getTypeName($numrows) . "</th>"; echo "</tr>"; if ($numrows) { Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand); Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"])); $i = 0; foreach ($changes as $data) { Session::addToNavigateListItems('Change', $data["id"]); Change::showShort($data['id'], array('row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID'])); $i++; } Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand); } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
<tr class="row0"> <td class="cell10"><div class="vstrut17"></div></td> <td class="cell10">Dividendo</td> <td class="cell10"><b><?php print $dividend->pretty_date(); ?> </b></td> <td class="cell10"><?php $portfolio = new PortfolioStock(); $ports = $portfolio->find_all(array('where_clause' => "`isin` = '{$this->stock->isin}'")); if (count($ports) > 0) { $port = $ports[0]; $revenue = $port->quantita * $dividend->importo; printf('%.2f %s', $revenue, $this->stock->divisa); if ($this->stock->divisa != 'EUR') { $revenue /= $this->stock->divisa == 'USD' ? Change::usd2eur() : 1; printf(' (%.2f EUR)', $revenue); } } ?> <?php printf('(%.2f%%)', $dividend->importo / $this->stock->last->quotazione * 100); ?> </td> <td class="cell10"><b><?php printf('%s %s', $dividend->amount(), $this->stock->divisa); ?> </b></td> </tr> <?php
/** * Returns a short markdown snippet of the merge for use in release notes. * * @return string A short representation of the merge. */ public function displayShort() { return parent::displayShort() . " <sup>[{$this->_branch}]</sup>"; }
/** * Print the Life Cycles form for the current profile * * @param $openform boolean open the form (true by default) * @param $closeform boolean close the form (true by default) **/ function showFormLifeCycle($openform = true, $closeform = true) { if (!self::canView()) { return false; } echo "<div class='spaced'>"; if (($canedit = Session::haveRightsOr(self::$rightname, array(CREATE, UPDATE, PURGE))) && $openform) { echo "<form method='post' action='" . $this->getFormURL() . "'>"; } $this->displayLifeCycleMatrix(__('Life cycle of tickets'), '_cycle_ticket', 'ticket_status', Ticket::getAllStatusArray(), $canedit); $this->displayLifeCycleMatrix(__('Life cycle of problems'), '_cycle_problem', 'problem_status', Problem::getAllStatusArray(), $canedit); $this->displayLifeCycleMatrix(__('Life cycle of changes'), '_cycle_change', 'change_status', Change::getAllStatusArray(), $canedit); if ($canedit && $closeform) { echo "<div class='center'>"; echo "<input type='hidden' name='id' value='" . $this->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; echo "</div>\n"; Html::closeForm(); } echo "</div>"; }
/** * @since version 0.84 **/ static function title() { global $PLUGIN_HOOKS, $CFG_GLPI; $opt_list["Ticket"] = __('Tickets'); $stat_list["Ticket"]["Ticket_Global"]["name"] = __('Global'); $stat_list["Ticket"]["Ticket_Global"]["file"] = "stat.global.php?itemtype=Ticket"; $stat_list["Ticket"]["Ticket_Ticket"]["name"] = __('By ticket'); $stat_list["Ticket"]["Ticket_Ticket"]["file"] = "stat.tracking.php?itemtype=Ticket"; $stat_list["Ticket"]["Ticket_Location"]["name"] = __('By hardware characteristics'); $stat_list["Ticket"]["Ticket_Location"]["file"] = "stat.location.php?itemtype=Ticket"; $stat_list["Ticket"]["Ticket_Item"]["name"] = __('By hardware'); $stat_list["Ticket"]["Ticket_Item"]["file"] = "stat.item.php"; if (Problem::canView()) { $opt_list["Problem"] = _n('Problem', 'Problems', Session::getPluralNumber()); $stat_list["Problem"]["Problem_Global"]["name"] = __('Global'); $stat_list["Problem"]["Problem_Global"]["file"] = "stat.global.php?itemtype=Problem"; $stat_list["Problem"]["Problem_Problem"]["name"] = __('By problem'); $stat_list["Problem"]["Problem_Problem"]["file"] = "stat.tracking.php?itemtype=Problem"; } if (Change::canView()) { $opt_list["Change"] = _n('Change', 'Changes', Session::getPluralNumber()); $stat_list["Change"]["Change_Global"]["name"] = __('Global'); $stat_list["Change"]["Change_Global"]["file"] = "stat.global.php?itemtype=Change"; $stat_list["Change"]["Change_Change"]["name"] = __('By change'); $stat_list["Change"]["Change_Change"]["file"] = "stat.tracking.php?itemtype=Change"; } //Affichage du tableau de presentation des stats echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Select statistics to be displayed') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; $values = array($CFG_GLPI["root_doc"] . '/front/stat.php' => Dropdown::EMPTY_VALUE); $i = 0; $selected = -1; $count = count($stat_list); foreach ($opt_list as $opt => $group) { while ($data = each($stat_list[$opt])) { $name = $data[1]["name"]; $file = $data[1]["file"]; $comment = ""; if (isset($data[1]["comment"])) { $comment = $data[1]["comment"]; } $key = $CFG_GLPI["root_doc"] . "/front/" . $file; $values[$group][$key] = $name; if (stripos($_SERVER['REQUEST_URI'], $key) !== false) { $selected = $key; } } } // Manage plugins $names = array(); $optgroup = array(); if (isset($PLUGIN_HOOKS["stats"]) && is_array($PLUGIN_HOOKS["stats"])) { foreach ($PLUGIN_HOOKS["stats"] as $plug => $pages) { if (is_array($pages) && count($pages)) { foreach ($pages as $page => $name) { $names[$plug . '/' . $page] = array("name" => $name, "plug" => $plug); $optgroup[$plug] = Plugin::getInfo($plug, 'name'); } } } asort($names); } foreach ($optgroup as $opt => $title) { $group = $title; foreach ($names as $key => $val) { if ($opt == $val["plug"]) { $file = $CFG_GLPI["root_doc"] . "/plugins/" . $key; $values[$group][$file] = $val["name"]; if (stripos($_SERVER['REQUEST_URI'], $file) !== false) { $selected = $file; } } } } Dropdown::showFromArray('statmenu', $values, array('on_change' => "window.location.href=this.options[this.selectedIndex].value", 'value' => $selected)); echo "</td>"; echo "</tr>"; echo "</table>"; }
/** * Show problems for a change * * @param $change Change object **/ static function showForChange(Change $change) { global $DB, $CFG_GLPI; $ID = $change->getField('id'); if (!$change->can($ID, 'r')) { return false; } $canedit = $change->can($ID, 'w'); $rand = mt_rand(); $showentities = Session::isMultiEntitiesMode(); $query = "SELECT DISTINCT `glpi_changes_problems`.`id` AS linkID,\n `glpi_problems`.*\n FROM `glpi_changes_problems`\n LEFT JOIN `glpi_problems`\n ON (`glpi_changes_problems`.`problems_id` = `glpi_problems`.`id`)\n WHERE `glpi_changes_problems`.`changes_id` = '{$ID}'\n ORDER BY `glpi_problems`.`name`"; $result = $DB->query($query); $problems = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $problems[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a problem') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; echo "<input type='hidden' name='changes_id' value='{$ID}'>"; Problem::dropdown(array('used' => $used, 'entity' => $change->getEntityID())); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr></table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr>"; if ($canedit && $numrows) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . _n('Problem', 'Problems', 2) . "</th>"; if ($showentities) { echo "<th>" . __('Entity') . "</th>"; } echo "</tr>"; $used = array(); if ($numrows) { Session::initNavigateListItems('Problem', sprintf(__('%1$s = %2$s'), Change::getTypeName(1), $change->fields["name"])); foreach ($problems as $data) { Session::addToNavigateListItems('Problem', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } echo "<td><a href='" . Toolbox::getItemTypeFormURL('Problem') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>"; if ($showentities) { echo "<td>" . Dropdown::getDropdownName('glpi_entities', $data["entities_id"]) . "</td>"; } echo "</tr>"; } } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }