本文整理汇总了PHP中Toolbox::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::substr方法的具体用法?PHP Toolbox::substr怎么用?PHP Toolbox::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toolbox
的用法示例。
在下文中一共展示了Toolbox::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: giveItem
//.........这里部分代码省略.........
return $out;
case "timestamp":
return timestampToString($data[$NAME . $num]);
case "realtime":
return Ticket::getRealtime($data[$NAME . $num]);
case "date_delay":
$split = explode('$$$$', $data[$NAME . $num]);
$out = '';
foreach ($split as $val) {
if (strpos($val, ',')) {
list($dat, $dur) = explode(',', $val);
if (!empty($dat)) {
$out .= (empty($out) ? '' : '<br>') . getWarrantyExpir($dat, $dur);
}
}
}
return empty($out) ? " " : $out;
case "email":
// Stevenes
// $email=trim($data[$NAME.$num]);
$email = explode('$$', $data[$NAME . $num]);
if (!empty($email['0'])) {
return $email['0'];
//return "<a href='mailto:$email'>$email</a>";
}
return " ";
case "weblink":
$orig_link = trim($data[$NAME . $num]);
if (!empty($orig_link)) {
// strip begin of link
$link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
$link = preg_replace('/\\/$/', '', $link);
if (utf8_strlen($link) > 30) {
$link = Toolbox::substr($link, 0, 30) . "...";
}
//return "<a href=\"".formatOutputWebLink($orig_link)."\" target='_blank'>$link</a>";
return $orig_link;
}
return " ";
case "number":
if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
$out = "";
$split = explode("\$\$\$\$", $data[$NAME . $num]);
$count_display = 0;
for ($k = 0; $k < count($split); $k++) {
if (strlen(trim($split[$k])) > 0) {
if ($count_display) {
$out .= "<br>";
}
$count_display++;
$out .= str_replace(' ', ' ', Html::formatNumber($split[$k], false, 0)) . $unit;
}
}
return $out;
}
return str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num], false, 0)) . $unit;
case "decimal":
if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
$out = "";
$split = explode("\$\$\$\$", $data[$NAME . $num]);
$count_display = 0;
for ($k = 0; $k < count($split); $k++) {
if (strlen(trim($split[$k])) > 0) {
if ($count_display) {
$out .= "<br>";
}
示例2: printPager
/**
* Print pager for search option (first/previous/next/last)
*
* @param $start from witch item we start
* @param $numrows total items
* @param $target page would be open when click on the option (last,previous etc)
* @param $parameters parameters would be passed on the URL.
* @param $item_type_output item type display - if >0 display export PDF et Sylk form
* (default 0)
* @param $item_type_output_param item type parameter for export (default 0)
* @param $additional_info Additional information to display (default '')
*
* @return nothing (print a pager)
*
**/
static function printPager($start, $numrows, $target, $parameters, $item_type_output = 0, $item_type_output_param = 0, $additional_info = '')
{
global $CFG_GLPI;
$list_limit = $_SESSION['glpilist_limit'];
// Forward is the next step forward
$forward = $start + $list_limit;
// This is the end, my friend
$end = $numrows - $list_limit;
// Human readable count starts here
$current_start = $start + 1;
// And the human is viewing from start to end
$current_end = $current_start + $list_limit - 1;
if ($current_end > $numrows) {
$current_end = $numrows;
}
// Empty case
if ($current_end == 0) {
$current_start = 0;
}
// Backward browsing
if ($current_start - $list_limit <= 0) {
$back = 0;
} else {
$back = $start - $list_limit;
}
// Print it
echo "<div><table class='tab_cadre_pager'>";
echo "<tr>";
if (strpos($target, '?') == false) {
$fulltarget = $target . "?" . $parameters;
} else {
$fulltarget = $target . "&" . $parameters;
}
// Back and fast backward button
if (!$start == 0) {
echo "<th class='left'>";
echo "<a href='{$fulltarget}&start=0'>";
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\" class='pointer'>";
echo "</a></th>";
echo "<th class='left'>";
echo "<a href='{$fulltarget}&start={$back}'>";
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\" class='pointer'>";
echo "</a></th>";
}
// Print the "where am I?"
echo "<td width='31%' class='tab_bg_2'>";
self::printPagerForm("{$fulltarget}&start={$start}");
echo "</td>";
if (!empty($additional_info)) {
echo "<td class='tab_bg_2'>";
echo $additional_info;
echo "</td>";
}
if (!empty($item_type_output) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
echo "<td class='tab_bg_2 responsive_hidden' width='30%'>";
echo "<form method='GET' action='" . $CFG_GLPI["root_doc"] . "/front/report.dynamic.php'\n target='_blank'>";
echo Html::hidden('item_type', array('value' => $item_type_output));
if ($item_type_output_param != 0) {
echo Html::hidden('item_type_param', array('value' => Toolbox::prepareArrayForInput($item_type_output_param)));
}
$split = explode("&", $parameters);
for ($i = 0; $i < count($split); $i++) {
$pos = Toolbox::strpos($split[$i], '=');
$length = Toolbox::strlen($split[$i]);
echo Html::hidden(Toolbox::substr($split[$i], 0, $pos), array('value' => urldecode(Toolbox::substr($split[$i], $pos + 1))));
}
Dropdown::showOutputFormat();
Html::closeForm();
echo "</td>";
}
echo "<td width='20%' class='tab_bg_2 b'>";
//TRANS: %1$d, %2$d, %3$d are page numbers
printf(__('From %1$d to %2$d on %3$d'), $current_start, $current_end, $numrows);
echo "</td>\n";
// Forward and fast forward button
if ($forward < $numrows) {
echo "<th class='right'>";
echo "<a href='{$fulltarget}&start={$forward}'>";
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\" class='pointer'>";
echo "</a></th>\n";
echo "<th class='right'>";
echo "<a href='{$fulltarget}&start={$end}'>";
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\" class='pointer'>";
echo "</a></th>\n";
}
//.........这里部分代码省略.........
示例3: dropdown
/**
* Make a select box with all glpi users where select key = name
*
* @param $options array of possible options:
* - name : string / name of the select (default is users_id)
* - value
* - right : string / limit user who have specific right :
* id -> only current user (default case);
* interface -> central ;
* all -> all users ;
* specific right like show_all_ticket, create_ticket.... (is array passed one of all passed right is needed)
* - comments : boolean / is the comments displayed near the dropdown (default true)
* - entity : integer or array / restrict to a defined entity or array of entities
* (default -1 : no restriction)
* - entity_sons : boolean / if entity restrict specified auto select its sons
* only available if entity is a single value not an array(default false)
* - all : Nobody or All display for none selected
* all=0 (default) -> Nobody
* all=1 -> All
* all=-1-> nothing
* - rand : integer / already computed rand value
* - toupdate : array / Update a specific item on select change on dropdown
* (need value_fieldname, to_update, url
* (see Ajax::updateItemOnSelectEvent for information)
* and may have moreparams)
* - used : array / Already used items ID: not to display in dropdown (default empty)
* - ldap_import
* - on_change : string / value to transmit to "onChange"
* - display : boolean / display or get string (default true)
*
* @return rand value if displayed / string if not
**/
static function dropdown($options = array())
{
global $DB, $CFG_GLPI;
// Default values
$p['name'] = 'users_id';
$p['value'] = '';
$p['right'] = 'id';
$p['all'] = 0;
$p['on_change'] = '';
$p['comments'] = 1;
$p['entity'] = -1;
$p['entity_sons'] = false;
$p['used'] = array();
$p['ldap_import'] = false;
$p['toupdate'] = '';
$p['rand'] = mt_rand();
$p['display'] = true;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$p[$key] = $val;
}
}
$output = '';
if (!($p['entity'] < 0) && $p['entity_sons']) {
if (is_array($p['entity'])) {
$output .= "entity_sons options is not available with array of entity";
} else {
$p['entity'] = getSonsOf('glpi_entities', $p['entity']);
}
}
// Make a select box with all glpi users
$use_ajax = false;
if ($CFG_GLPI["use_ajax"]) {
$res = self::getSqlSearchResult(true, $p['right'], $p['entity'], $p['value'], $p['used']);
$nb = $res ? $DB->result($res, 0, "CPT") : 0;
if ($nb > $CFG_GLPI["ajax_limit_count"]) {
$use_ajax = true;
}
}
$user = getUserName($p['value'], 2);
$default_display = "<select id='dropdown_" . $p['name'] . $p['rand'] . "' name='" . $p['name'] . "'>";
$default_display .= "<option value='" . $p['value'] . "'>";
$default_display .= Toolbox::substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]);
$default_display .= "</option></select>";
$view_users = Session::haveRight("user", "r");
$params = array('searchText' => '__VALUE__', 'value' => $p['value'], 'myname' => $p['name'], 'all' => $p['all'], 'right' => $p['right'], 'comment' => $p['comments'], 'rand' => $p['rand'], 'on_change' => $p['on_change'], 'entity_restrict' => $p['entity'], 'used' => $p['used'], 'update_item' => $p['toupdate']);
if ($view_users) {
$params['update_link'] = $view_users;
}
$default = "";
if (!empty($p['value']) && $p['value'] > 0) {
$default = $default_display;
} else {
$default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $p['rand'] . "'>";
if ($p['all']) {
$default .= "<option value='0'>--" . __('All') . "--</option></select>";
} else {
$default .= "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>\n";
}
}
$output .= Ajax::dropdown($use_ajax, "/ajax/dropdownUsers.php", $params, $default, $p['rand'], false);
// Display comment
if ($p['comments']) {
if (!$view_users) {
$user["link"] = '';
} else {
if (empty($user["link"])) {
$user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
//.........这里部分代码省略.........
示例4: showSystemInformations
/**
* @param $width
**/
function showSystemInformations($width)
{
// No need to translate, this part always display in english (for copy/paste to forum)
echo "\n<tr class='tab_bg_2'><th>Plugins list</th></tr>";
echo "<tr class='tab_bg_1'><td><pre>\n \n";
$plug = new Plugin();
$pluglist = $plug->find("", "name, directory");
foreach ($pluglist as $plugin) {
$msg = substr(str_pad($plugin['directory'], 30), 0, 20) . " Name: " . Toolbox::substr(str_pad($plugin['name'], 40), 0, 30) . " Version: " . str_pad($plugin['version'], 10) . " State: ";
switch ($plugin['state']) {
case self::ANEW:
$msg .= 'New';
break;
case self::ACTIVATED:
$msg .= 'Enabled';
break;
case self::NOTINSTALLED:
$msg .= 'Not installed';
break;
case self::TOBECONFIGURED:
$msg .= 'To be configured';
break;
case self::NOTACTIVATED:
$msg .= 'Not activated';
break;
case self::TOBECLEANED:
default:
$msg .= 'To be cleaned';
break;
}
echo wordwrap("\t" . $msg . "\n", $width, "\n\t\t");
}
echo "\n</pre></td></tr>";
}
示例5: giveItem
//.........这里部分代码省略.........
}
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']);
示例6: dropdown
/**
* Print a select with contracts
*
* Print a select named $name with contracts options and selected value $value
* @param $options array of possible options:
* - name : string / name of the select (default is contracts_id)
* - value : integer / preselected value (default 0)
* - entity : integer or array / restrict to a defined entity or array of entities
* (default -1 : no restriction)
* - entity_sons : boolean / if entity restrict specified auto select its sons
* only available if entity is a single value not an array (default false)
* - used : array / Already used items ID: not to display in dropdown (default empty)
* - nochecklimit : boolean / disable limit for nomber of device (for supplier, default false)
*
* @return Nothing (display)
**/
static function dropdown($options = array())
{
global $DB;
//$name,$entity_restrict=-1,$alreadyused=array(),$nochecklimit=false
$p['name'] = 'contracts_id';
$p['value'] = '';
$p['entity'] = '';
$p['entity_sons'] = false;
$p['used'] = array();
$p['nochecklimit'] = false;
$p['on_change'] = '';
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$p[$key] = $val;
}
}
if (!($p['entity'] < 0) && $p['entity_sons']) {
if (is_array($p['entity'])) {
// no translation needed (only for dev)
echo "entity_sons options is not available with array of entity";
} else {
$p['entity'] = getSonsOf('glpi_entities', $p['entity']);
}
}
$entrest = "";
$idrest = "";
if ($p['entity'] >= 0) {
$entrest = getEntitiesRestrictRequest("AND", "glpi_contracts", "entities_id", $p['entity'], true);
}
if (count($p['used'])) {
$idrest = " AND `glpi_contracts`.`id` NOT IN('" . implode("','", $p['used']) . "') ";
}
$query = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id` = `glpi_entities`.`id`)\n WHERE `glpi_contracts`.`is_deleted` = '0' {$entrest} {$idrest}\n ORDER BY `glpi_entities`.`completename`,\n `glpi_contracts`.`name` ASC,\n `glpi_contracts`.`begin_date` DESC";
$result = $DB->query($query);
echo "<select name='" . $p['name'] . "'";
if (!empty($p["on_change"])) {
echo " onChange='" . $p["on_change"] . "'";
}
echo '>';
if ($p['value'] > 0) {
$output = Dropdown::getDropdownName('glpi_contracts', $p['value']);
if ($_SESSION["glpiis_ids_visible"]) {
$output = sprintf(__('%1$s (%2$s)'), $output, $p['value']);
}
echo "<option selected value='" . $p['value'] . "'>" . $output . "</option>";
} else {
echo "<option value='-1'>" . Dropdown::EMPTY_VALUE . "</option>";
}
$prev = -1;
while ($data = $DB->fetch_assoc($result)) {
if ($p['nochecklimit'] || $data["max_links_allowed"] == 0 || $data["max_links_allowed"] > countElementsInTable("glpi_contracts_items", "contracts_id\n = '" . $data['id'] . "'")) {
if ($data["entities_id"] != $prev) {
if ($prev >= 0) {
echo "</optgroup>";
}
$prev = $data["entities_id"];
echo "<optgroup label=\"" . Dropdown::getDropdownName("glpi_entities", $prev) . "\">";
}
$name = $data["name"];
if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
}
echo "<option value='" . $data["id"] . "'>";
$tmp = sprintf(__('%1$s - %2$s'), $name, $data["num"]);
$tmp = sprintf(__('%1$s - %2$s'), $tmp, Html::convDateTime($data["begin_date"]));
echo Toolbox::substr($tmp, 0, $_SESSION["glpidropdown_chars_limit"]);
echo "</option>";
}
}
if ($prev >= 0) {
echo "</optgroup>";
}
echo "</select>";
}
示例7: header
* @brief
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownSelectSoftware.php")) {
$AJAX_INCLUDE = 1;
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Session::checkRight("software", "w");
// Make a select box
$rand = mt_rand();
$where = "";
if (strlen($_POST['searchText']) > 0 && $_POST['searchText'] != $CFG_GLPI["ajax_wildcard"]) {
$where .= " AND `name` " . Search::makeTextSearch($_POST['searchText']) . " ";
}
$where .= getEntitiesRestrictRequest(' AND', 'glpi_softwares', 'entities_id', $_POST["entity_restrict"], true);
$query = "SELECT DISTINCT `glpi_softwares`.`id`,\n `glpi_softwares`.`name`\n FROM `glpi_softwares`\n WHERE `glpi_softwares`.`is_deleted` = '0'\n AND `glpi_softwares`.`is_template` = '0'\n {$where}\n ORDER BY `glpi_softwares`.`name`";
$result = $DB->query($query);
echo "<select name='softwares_id' id='item_type{$rand}'>\n";
echo "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n";
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$softwares_id = $data["id"];
$output = $data["name"];
echo "<option value='{$softwares_id}' title=\"" . Html::cleanInputText($output) . "\">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
}
}
echo "</select>\n";
$paramsselsoft = array('softwares_id' => '__VALUE__', 'myname' => $_POST["myname"]);
Ajax::updateItemOnSelectEvent("item_type{$rand}", "show_" . $_POST["myname"] . $rand, $CFG_GLPI["root_doc"] . "/ajax/dropdownInstallVersion.php", $paramsselsoft);
echo "<span id='show_" . $_POST["myname"] . "{$rand}'> </span>\n";
示例8: showGantt
/** show GANTT diagram for a project or for all
*
* @param $ID ID of the project or -1 for all projects
*/
static function showGantt($ID)
{
global $DB;
if ($ID > 0) {
$project = new Project();
if ($project->getFromDB($ID) && $project->canView()) {
$todisplay = static::getDataToDisplayOnGantt($ID);
} else {
return false;
}
} else {
$todisplay = array();
// Get all root projects
$query = "SELECT *\n FROM `glpi_projects`\n WHERE `projects_id` = '0'\n AND `show_on_global_gantt` = '1'\n " . getEntitiesRestrictRequest("AND", 'glpi_projects', "", '', true);
foreach ($DB->request($query) as $data) {
$todisplay += static::getDataToDisplayOnGantt($data['id'], false);
}
ksort($todisplay);
}
$data = array();
$invalid = array();
if (count($todisplay)) {
// Prepare for display
foreach ($todisplay as $key => $val) {
if (!empty($val['from']) && !empty($val['to'])) {
$temp = array();
$color = 'ganttRed';
if ($val['percent'] > 50) {
$color = 'ganttOrange';
}
if ($val['percent'] == 100) {
$color = 'ganttGreen';
}
switch ($val['type']) {
case 'project':
$temp = array('name' => $val['link'], 'desc' => '', 'values' => array(array('from' => "/Date(" . strtotime($val['from']) . "000)/", 'to' => "/Date(" . strtotime($val['to']) . "000)/", 'desc' => $val['desc'], 'label' => $val['percent'] . "%", 'customClass' => $color)));
break;
case 'task':
if (isset($val['is_milestone']) && $val['is_milestone']) {
$color = 'ganttMilestone';
}
$temp = array('name' => ' ', 'desc' => str_repeat('-', $val['parents']) . $val['link'], 'values' => array(array('from' => "/Date(" . strtotime($val['from']) . "000)/", 'to' => "/Date(" . strtotime($val['to']) . "000)/", 'desc' => $val['desc'], 'label' => strlen($val['percent'] == 0) ? '' : $val['percent'] . "%", 'customClass' => $color)));
break;
}
$data[] = $temp;
} else {
$invalid[] = $val['link'];
}
}
// Html::printCleanArray($data);
}
if (count($invalid)) {
echo sprintf(__('Invalid items (no start or end date): %s'), implode(',', $invalid));
echo "<br><br>";
}
if (count($data)) {
$months = array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'), __('September'), __('October'), __('November'), __('December'));
$dow = array(Toolbox::substr(__('Sunday'), 0, 1), Toolbox::substr(__('Monday'), 0, 1), Toolbox::substr(__('Tuesday'), 0, 1), Toolbox::substr(__('Wednesday'), 0, 1), Toolbox::substr(__('Thursday'), 0, 1), Toolbox::substr(__('Friday'), 0, 1), Toolbox::substr(__('Saturday'), 0, 1));
echo "<div class='gantt'></div>";
$js = "\n \$('.gantt').gantt({\n source: " . json_encode($data) . ",\n navigate: 'scroll',\n maxScale: 'months',\n itemsPerPage: 20,\n months: " . json_encode($months) . ",\n dow: " . json_encode($dow) . ",\n onItemClick: function(data) {\n // alert('Item clicked - show some details');\n },\n onAddClick: function(dt, rowId) {\n // alert('Empty space clicked - add an item!');\n },\n });";
echo Html::scriptBlock($js);
} else {
_e('No item to display');
}
}
示例9: giveItem
//.........这里部分代码省略.........
$withdays = true;
if (isset($searchopt[$ID]['withdays'])) {
$withdays = $searchopt[$ID]['withdays'];
}
$split = explode("\$\$\$\$", $data[$NAME . $num]);
$out = '';
foreach ($split as $val) {
$out .= (empty($out) ? '' : '<br>') . Html::timestampToString($val, $withseconds, $withdays);
}
return $out;
case "email":
$split = explode('$$$$', $data[$NAME . $num]);
$out = '';
$count_display = 0;
foreach ($split as $val) {
$split2 = self::explodeWithID("\$\$", $val);
if ($count_display) {
$out .= "<br>";
}
$count_display++;
if (!empty($val)) {
$out .= empty($out) ? '' : '<br>';
$out .= "<a href='mailto:{$split2['0']}'>{$split2['0']}</a>";
}
}
return empty($out) ? " " : $out;
case "weblink":
$orig_link = trim($data[$NAME . $num]);
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 "number":
if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
$out = "";
$split = explode("\$\$\$\$", $data[$NAME . $num]);
$count_display = 0;
for ($k = 0; $k < count($split); $k++) {
if (strlen(trim($split[$k])) > 0) {
$split2 = self::explodeWithID("\$\$", $split[$k]);
if ($count_display) {
$out .= "<br>";
}
$count_display++;
if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) {
$out .= $searchopt[$ID]['toadd'][$split2[0]];
} else {
$number = str_replace(' ', ' ', Html::formatNumber($split2[0], false, 0));
$out .= Dropdown::getValueWithUnit($number, $unit);
}
}
}
return $out;
}
if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$NAME . $num]])) {
return $searchopt[$ID]['toadd'][$data[$NAME . $num]];
} else {
$number = str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num], false, 0));
return Dropdown::getValueWithUnit($number, $unit);
}
示例10: reconstrucTimeline
function reconstrucTimeline()
{
global $DB;
$query = "TRUNCATE `" . $this->getTable() . "`";
$DB->query($query);
$query = "SELECT id\n FROM `glpi_tickets`";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
$queryGroup = "SELECT * FROM `glpi_logs`";
$queryGroup .= " WHERE `itemtype_link` = 'Group'";
$queryGroup .= " AND `items_id` = " . $data['id'];
$queryGroup .= " AND `itemtype` = 'Ticket'";
$queryGroup .= " ORDER BY date_mod ASC";
$resultGroup = $DB->query($queryGroup);
if ($resultGroup) {
while ($dataGroup = $DB->fetch_array($resultGroup)) {
if ($dataGroup['new_value'] != null) {
$start = Toolbox::strpos($dataGroup['new_value'], "(");
$end = Toolbox::strpos($dataGroup['new_value'], ")");
$length = $end - $start;
$groups_id = Toolbox::substr($dataGroup['new_value'], $start + 1, $length - 1);
$group = new Group();
if ($group->getFromDB($groups_id)) {
if ($group->fields['is_requester'] == 0 && $group->fields['is_assign'] == 1) {
$ticket = new Ticket();
$ticket->getFromDB($data['id']);
$this->createGroup($ticket, $dataGroup['date_mod'], $groups_id, 'new');
}
}
} else {
if ($dataGroup['old_value'] != null) {
$start = Toolbox::strpos($dataGroup['old_value'], "(");
$end = Toolbox::strpos($dataGroup['old_value'], ")");
$length = $end - $start;
$groups_id = Toolbox::substr($dataGroup['old_value'], $start + 1, $length - 1);
$group = new Group();
if ($group->getFromDB($groups_id)) {
if ($group->fields['is_requester'] == 0 && $group->fields['is_assign'] == 1) {
$ticket = new Ticket();
$ticket->getFromDB($data['id']);
$this->createGroup($ticket, $dataGroup['date_mod'], $groups_id, 'delete');
}
}
}
}
}
}
}
}
示例11: show
/**
* Print out an HTML "<select>" for a dropdown with preselected value
*
* @param $itemtype itemtype used for create dropdown
* @param $options array of possible options:
* - name : string / name of the select (default is depending itemtype)
* - value : integer / preselected value (default -1)
* - comments : boolean / is the comments displayed near the dropdown (default true)
* - toadd : array / array of specific values to add at the begining
* - entity : integer or array / restrict to a defined entity or array of entities
* (default -1 : no restriction)
* - entity_sons : boolean / if entity restrict specified auto select its sons
* only available if entity is a single value not an array
* (default false)
* - toupdate : array / Update a specific item on select change on dropdown
* (need value_fieldname, to_update,
* url (see Ajax::updateItemOnSelectEvent for information)
* and may have moreparams)
* - used : array / Already used items ID: not to display in dropdown
* (default empty)
* - on_change : string / value to transmit to "onChange"
* - rand : integer / already computed rand value
* - condition : string / aditional SQL condition to limit display
* - displaywith : array / array of field to display with request
* - emptylabel : Empty choice's label (default self::EMPTY_VALUE)
* - display_emptychoice : Display emptychoice ? (default true)
* - display : boolean / display or get string (default true)
* - width : specific width needed (default 80%)
* - permit_select_parent : boolean / for tree dropdown permit to see parent items
* not available by default (default false)
* - specific_tags : array of HTML5 tags to add the the field
*
* @return boolean : false if error and random id if OK
**/
static function show($itemtype, $options = array())
{
global $DB, $CFG_GLPI;
if ($itemtype && !($item = getItemForItemtype($itemtype))) {
return false;
}
$table = $item->getTable();
$params['name'] = $item->getForeignKeyField();
$params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : '';
$params['comments'] = true;
$params['entity'] = -1;
$params['entity_sons'] = false;
$params['toupdate'] = '';
$params['width'] = '80%';
$params['used'] = array();
$params['toadd'] = array();
$params['on_change'] = '';
$params['condition'] = '';
$params['rand'] = mt_rand();
$params['displaywith'] = array();
//Parameters about choice 0
//Empty choice's label
$params['emptylabel'] = self::EMPTY_VALUE;
//Display emptychoice ?
$params['display_emptychoice'] = $itemtype != 'Entity';
$params['display'] = true;
$params['permit_select_parent'] = false;
$params['addicon'] = true;
$params['specific_tags'] = array();
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$output = '';
$name = $params['emptylabel'];
$comment = "";
$limit_length = $_SESSION["glpidropdown_chars_limit"];
// Check default value for dropdown : need to be a numeric
if (strlen($params['value']) == 0 || !is_numeric($params['value']) && $params['value'] != 'mygroups') {
$params['value'] = 0;
}
if (isset($params['toadd'][$params['value']])) {
$name = $params['toadd'][$params['value']];
} else {
if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) {
$tmpname = self::getDropdownName($table, $params['value'], 1);
if ($tmpname["name"] != " ") {
$name = $tmpname["name"];
$comment = $tmpname["comment"];
if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
if ($item instanceof CommonTreeDropdown) {
$pos = strrpos($name, ">");
$limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
if (Toolbox::strlen($name) > $limit_length) {
$name = "..." . Toolbox::substr($name, -$limit_length);
}
} else {
$limit_length = Toolbox::strlen($name);
}
} else {
$limit_length = $_SESSION["glpidropdown_chars_limit"];
}
}
}
}
//.........这里部分代码省略.........
示例12: show
/**
* Print out an HTML "<select>" for a dropdown with preselected value
*
* @param $itemtype itemtype used for create dropdown
* @param $options array of possible options:
* - name : string / name of the select (default is depending itemtype)
* - value : integer / preselected value (default -1)
* - comments : boolean / is the comments displayed near the dropdown (default true)
* - toadd : array / array of specific values to add at the begining
* - entity : integer or array / restrict to a defined entity or array of entities
* (default -1 : no restriction)
* - entity_sons : boolean / if entity restrict specified auto select its sons
* only available if entity is a single value not an array
* (default false)
* - toupdate : array / Update a specific item on select change on dropdown
* (need value_fieldname, to_update,
* url (see Ajax::updateItemOnSelectEvent for information)
* and may have moreparams)
* - used : array / Already used items ID: not to display in dropdown
* (default empty)
* - on_change : string / value to transmit to "onChange"
* - rand : integer / already computed rand value
* - condition : string / aditional SQL condition to limit display
* - displaywith : array / array of field to display with request
* - emptylabel : Empty choice's label (default self::EMPTY_VALUE)
* - display_emptychoice : Display emptychoice ? (default true)
* - display : boolean / display or get string (default true)
* - permit_select_parent : boolean / for tree dropdown permit to see parent items not available by default (default false)
*
* @return boolean : false if error and random id if OK
**/
static function show($itemtype, $options = array())
{
global $DB, $CFG_GLPI;
if ($itemtype && !($item = getItemForItemtype($itemtype))) {
return false;
}
$table = $item->getTable();
$params['name'] = $item->getForeignKeyField();
$params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : '';
$params['comments'] = true;
$params['entity'] = -1;
$params['entity_sons'] = false;
$params['toupdate'] = '';
$params['used'] = array();
$params['toadd'] = array();
$params['on_change'] = '';
$params['condition'] = '';
$params['rand'] = mt_rand();
$params['displaywith'] = array();
//Parameters about choice 0
//Empty choice's label
$params['emptylabel'] = self::EMPTY_VALUE;
//Display emptychoice ?
$params['display_emptychoice'] = $itemtype != 'Entity';
$params['display'] = true;
$params['permit_select_parent'] = false;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$output = '';
$name = $params['emptylabel'];
$comment = "";
$limit_length = $_SESSION["glpidropdown_chars_limit"];
// Check default value for dropdown : need to be a numeric
if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
$params['value'] = 0;
}
if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) {
$tmpname = self::getDropdownName($table, $params['value'], 1);
if ($tmpname["name"] != " ") {
$name = $tmpname["name"];
$comment = $tmpname["comment"];
if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
if ($item instanceof CommonTreeDropdown) {
$pos = strrpos($name, ">");
$limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
if (Toolbox::strlen($name) > $limit_length) {
$name = "…" . Toolbox::substr($name, -$limit_length);
}
} else {
$limit_length = Toolbox::strlen($name);
}
} else {
$limit_length = $_SESSION["glpidropdown_chars_limit"];
}
}
}
// Manage entity_sons
if (!($params['entity'] < 0) && $params['entity_sons']) {
if (is_array($params['entity'])) {
// translation not needed - only for debug
$output .= "entity_sons options is not available with entity option as array";
} else {
$params['entity'] = getSonsOf('glpi_entities', $params['entity']);
}
}
$use_ajax = false;
//.........这里部分代码省略.........
示例13: getValueToDisplay
//.........这里部分代码省略.........
if ($options['html']) {
$text = nl2br($value);
} else {
$text = $value;
}
if (isset($searchoptions['htmltext']) && $searchoptions['htmltext']) {
$text = Html::clean(Toolbox::unclean_cross_side_scripting_deep($text));
}
return $text;
case "bool":
return Dropdown::getYesNo($value);
case "date":
case "date_delay":
if (isset($options['relative_dates']) && $options['relative_dates']) {
$dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true));
return $dates[$value];
}
return Html::convDate(Html::computeGenericDateTimeSearch($value, true));
case "datetime":
if (isset($options['relative_dates']) && $options['relative_dates']) {
$dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true));
return $dates[$value];
}
return Html::convDateTime(Html::computeGenericDateTimeSearch($value, false));
case "timestamp":
if ($value == 0 && isset($searchoptions['emptylabel'])) {
return $searchoptions['emptylabel'];
}
$withseconds = false;
if (isset($searchoptions['withseconds'])) {
$withseconds = $searchoptions['withseconds'];
}
return Html::timestampToString($value, $withseconds);
case "email":
if ($options['html']) {
return "<a href='mailto:{$value}'>{$value}</a>";
}
return $value;
case "weblink":
$orig_link = trim($value);
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 "itemlink":
if ($searchoptions['table'] == $this->getTable()) {
break;
}
case "dropdown":
if (isset($searchoptions['toadd']) && isset($searchoptions['toadd'][$value])) {
return $searchoptions['toadd'][$value];
}
if (!is_numeric($value)) {
return $value;
}
if ($value == 0 && isset($searchoptions['emptylabel'])) {
return $searchoptions['emptylabel'];
}
if ($searchoptions['table'] == 'glpi_users') {
if ($param['comments']) {
$tmp = getUserName($value, 2);
return $tmp['name'] . ' ' . Html::showToolTip($tmp['comment'], array('display' => false));
}
return getUserName($value);
}
if ($param['comments']) {
$tmp = Dropdown::getDropdownName($searchoptions['table'], $value, 1);
return $tmp['name'] . ' ' . Html::showToolTip($tmp['comment'], array('display' => false));
}
return Dropdown::getDropdownName($searchoptions['table'], $value);
case "itemtypename":
if ($obj = getItemForItemtype($value)) {
return $obj->getTypeName(1);
}
break;
case "language":
if (isset($CFG_GLPI['languages'][$value])) {
return $CFG_GLPI['languages'][$value][0];
}
return __('Default value');
}
}
// Get specific display if available
$itemtype = getItemTypeForTable($searchoptions['table']);
if ($item = getItemForItemtype($itemtype)) {
$options['searchopt'] = $searchoptions;
$specific = $item->getSpecificValueToDisplay($field, $values, $options);
if (!empty($specific)) {
return $specific;
}
}
}
return $value;
}
示例14: autoName
/**
* Create a new name using a autoname field defined in a template
*
* @param $objectName autoname template
* @param $field field to autoname
* @param $isTemplate true if create an object from a template
* @param $itemtype item type
* @param $entities_id limit generation to an entity (default -1)
*
* @return new auto string
**/
function autoName($objectName, $field, $isTemplate, $itemtype, $entities_id = -1)
{
global $DB, $CFG_GLPI;
$len = Toolbox::strlen($objectName);
if ($isTemplate && $len > 8 && Toolbox::substr($objectName, 0, 4) === '<' && Toolbox::substr($objectName, $len - 4, 4) === '>') {
$autoNum = Toolbox::substr($objectName, 4, $len - 8);
$mask = '';
if (preg_match("/\\#{1,10}/", $autoNum, $mask)) {
$global = strpos($autoNum, '\\g') !== false && $itemtype != 'Infocom' ? 1 : 0;
$autoNum = str_replace(array('\\y', '\\Y', '\\m', '\\d', '_', '%', '\\g'), array(date('y'), date('Y'), date('m'), date('d'), '\\_', '\\%', ''), $autoNum);
$mask = $mask[0];
$pos = strpos($autoNum, $mask) + 1;
$len = Toolbox::strlen($mask);
$like = str_replace('#', '_', $autoNum);
if ($global == 1) {
$query = "";
$first = 1;
$types = array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer');
foreach ($types as $t) {
$table = getTableForItemType($t);
$query .= ($first ? "SELECT " : " UNION SELECT ") . " {$field} AS code\n FROM `{$table}`\n WHERE `{$field}` LIKE '{$like}'\n AND `is_deleted` = '0'\n AND `is_template` = '0'";
if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
$query .= " AND `entities_id` = '{$entities_id}' ";
}
$first = 0;
}
$query = "SELECT CAST(SUBSTRING(code, {$pos}, {$len}) AS unsigned) AS no\n FROM ({$query}) AS codes";
} else {
$table = getTableForItemType($itemtype);
$query = "SELECT CAST(SUBSTRING({$field}, {$pos}, {$len}) AS unsigned) AS no\n FROM `{$table}`\n WHERE `{$field}` LIKE '{$like}' ";
if ($itemtype != 'Infocom') {
$query .= " AND `is_deleted` = '0'\n AND `is_template` = '0'";
if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
$query .= " AND `entities_id` = '{$entities_id}' ";
}
}
}
$query = "SELECT MAX(Num.no) AS lastNo\n FROM (" . $query . ") AS Num";
$resultNo = $DB->query($query);
if ($DB->numrows($resultNo) > 0) {
$data = $DB->fetch_assoc($resultNo);
$newNo = $data['lastNo'] + 1;
} else {
$newNo = 0;
}
$objectName = str_replace(array($mask, '\\_', '\\%'), array(Toolbox::str_pad($newNo, $len, '0', STR_PAD_LEFT), '_', '%'), $autoNum);
}
}
return $objectName;
}
示例15: showTabs
function showTabs($options = array())
{
global $CFG_GLPI;
// for objects not in table like central
$ID = 0;
if (isset($this->fields['id'])) {
$ID = $this->fields['id'];
}
$target = $_SERVER['PHP_SELF'];
$extraparamhtml = "";
$extraparam = "";
$withtemplate = "";
if (is_array($options) && count($options)) {
if (isset($options['withtemplate'])) {
$withtemplate = $options['withtemplate'];
}
foreach ($options as $key => $val) {
$extraparamhtml .= "&{$key}={$val}";
$extraparam .= "&{$key}={$val}";
}
}
if (empty($withtemplate) && $ID && $this->getType() && $this->displaylist) {
$glpilistitems =& $_SESSION['glpilistitems'][$this->getType()];
$glpilisttitle =& $_SESSION['glpilisttitle'][$this->getType()];
$glpilisturl =& $_SESSION['glpilisturl'][$this->getType()];
if (empty($glpilisturl)) {
$glpilisturl = $this->getSearchURL();
}
echo "<div id='menu_navigate'>";
$next = $prev = $first = $last = -1;
$current = false;
if (is_array($glpilistitems)) {
$current = array_search($ID, $glpilistitems);
if ($current !== false) {
if (isset($glpilistitems[$current + 1])) {
$next = $glpilistitems[$current + 1];
}
if (isset($glpilistitems[$current - 1])) {
$prev = $glpilistitems[$current - 1];
}
$first = $glpilistitems[0];
if ($first == $ID) {
$first = -1;
}
$last = $glpilistitems[count($glpilistitems) - 1];
if ($last == $ID) {
$last = -1;
}
}
}
$cleantarget = Html::cleanParametersURL($target);
echo "<ul>";
echo "<li><a href=\"javascript:showHideDiv('tabsbody','tabsbodyimg','" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png','" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png')\">";
echo "<img alt='' name='tabsbodyimg' src=\"" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png\">";
echo "</a></li>";
echo "<li><a href=\"" . $glpilisturl . "\">";
if ($glpilisttitle) {
if (Toolbox::strlen($glpilisttitle) > $_SESSION['glpidropdown_chars_limit']) {
$glpilisttitle = Toolbox::substr($glpilisttitle, 0, $_SESSION['glpidropdown_chars_limit']) . "…";
}
echo $glpilisttitle;
} else {
echo __('List');
}
echo "</a> : </li>";
if ($first > 0) {
echo "<li><a href='{$cleantarget}?id={$first}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __('First') . "\" title=\"" . __('First') . "\"></a></li>";
} else {
echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/first_off.png' alt=\"" . __('First') . "\" title=\"" . __('First') . "\"></li>";
}
if ($prev > 0) {
echo "<li><a href='{$cleantarget}?id={$prev}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __('Previous') . "\" title=\"" . __('Previous') . "\"></a></li>";
} else {
echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/left_off.png' alt=\"" . __('Previous') . "\" title=\"" . __('Previous') . "\"></li>";
}
if ($current !== false) {
echo "<li>" . ($current + 1) . "/" . count($glpilistitems) . "</li>";
}
if ($next > 0) {
echo "<li><a href='{$cleantarget}?id={$next}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __('Next') . "\" title=\"" . __('Next') . "\"></a></li>";
} else {
echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/right_off.png' alt=\"" . __('Next') . "\" title=\"" . __('Next') . "\"></li>";
}
if ($last > 0) {
echo "<li><a href='{$cleantarget}?id={$last}{$extraparamhtml}'><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/last.png\" alt=\"" . __('Last') . "\" title=\"" . __('Last') . "\"></a></li>";
} else {
echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/last_off.png' alt=\"" . __('Last') . "\" title=\"" . __('Last') . "\"></li>";
}
echo "</ul></div>";
echo "<div class='sep'></div>";
}
echo "<div id='tabspanel' class='center-h'></div>";
$onglets = $this->defineTabs($options);
$display_all = true;
if (isset($onglets['no_all_tab'])) {
$display_all = false;
unset($onglets['no_all_tab']);
}
$class = $this->getType();
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && ($ID > 0 || $this->showdebug) && (method_exists($class, 'showDebug') || in_array($class, $CFG_GLPI["infocom_types"]) || in_array($class, $CFG_GLPI["reservation_types"]))) {
//.........这里部分代码省略.........