本文整理汇总了PHP中Toolbox::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::strlen方法的具体用法?PHP Toolbox::strlen怎么用?PHP Toolbox::strlen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toolbox
的用法示例。
在下文中一共展示了Toolbox::strlen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateVcard
/**
* Generate the Vcard for the current Contact
*
*@return Nothing (display)
**/
function generateVcard()
{
if (!$this->can($this->fields['id'], READ)) {
return false;
}
// build the Vcard
$vcard = new VObject\Component\VCard(['N' => [$this->fields["name"], $this->fields["firstname"]], 'EMAIL' => $this->fields["email"], 'NOTE' => $this->fields["comment"]]);
$vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']);
$vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']);
$vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']);
$vcard->add('URL', $this->GetWebsite(), ['type' => 'WORK']);
$addr = $this->GetAddress();
if (is_array($addr)) {
$addr_string = implode(";", array_filter($addr));
$vcard->add('ADR', $addr_string, ['type' => 'WORK;POSTAL']);
}
// send the VCard
$output = $vcard->serialize();
$filename = $this->fields["name"] . "_" . $this->fields["firstname"] . ".vcf";
@Header("Content-Disposition: attachment; filename=\"{$filename}\"");
@Header("Content-Length: " . Toolbox::strlen($output));
@Header("Connection: close");
@Header("content-type: text/x-vcard; charset=UTF-8");
echo $output;
}
示例2: pdfMain
static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
{
global $DB;
$ID = $item->getField('id');
if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) {
return false;
}
$knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id');
$fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id));
$question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8")));
$answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8")));
$pdf->setColumnsSize(100);
if (Toolbox::strlen($fullcategoryname) > 0) {
$pdf->displayTitle('<b>' . __('Category name') . '</b>');
$pdf->displayLine($fullcategoryname);
}
if (Toolbox::strlen($question) > 0) {
$pdf->displayTitle('<b>' . __('Subject') . '</b>');
$pdf->displayText('', $question, 5);
} else {
$pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>');
}
if (Toolbox::strlen($answer) > 0) {
$pdf->displayTitle('<b>' . __('Content') . '</b>');
$pdf->displayText('', $answer, 5);
} else {
$pdf->displayTitle('<b>' . __('No answer found') . '</b>');
}
$pdf->setColumnsSize(50, 15, 15, 10, 10);
$pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2));
$pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]);
$pdf->displaySpace();
}
示例3: showFirstLevel
public function showFirstLevel($message)
{
global $LANG, $CFG_GLPI;
$menu = $this->getMenu();
if ($message != '') {
echo "<div class='ui-loader ui-body-a ui-corner-all' id='messagebox' style='top: 75px;display:block'>";
echo "<h1>{$message}</h1>";
echo "</div>";
echo "<script>\n \$('#messagebox').delay(800).fadeOut(2000);\n </script>";
}
echo "<div data-role='content'>";
echo "<ul data-role='listview' data-inset='true' data-theme='c' data-dividertheme='a'>";
echo "<li data-role='list-divider'>" . $LANG['plugin_mobile']["title"] . "</li>";
$i = 1;
foreach ($menu as $part => $data) {
if (isset($data['content']) && count($data['content'])) {
echo "<li id='menu{$i}'>";
$link = $CFG_GLPI["root_doc"] . "/plugins/mobile/front/ss_menu.php?menu=" . $part;
if (Toolbox::strlen($data['title']) > 14) {
$data['title'] = utf8_substr($data['title'], 0, 14) . "...";
}
if (isset($data['icon'])) {
echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/pics/" . $data['icon'] . "' class='ui-li-icon round-icon' />";
}
echo "<a href=\"{$link}\" data-back='false'>" . $data['title'] . "</a>";
echo "</li>";
$i++;
}
}
echo "</ul>";
echo "</div>";
}
示例4: dropdownReferencesByEnterprise
/**
* Permet l'affichage dynamique d'une liste d�roulante imbriquee
*
* @static
* @param array ($itemtype,$options)
*/
public static function dropdownReferencesByEnterprise($itemtype, $options = array())
{
global $DB, $CFG_GLPI;
$item = getItemForItemtype($itemtype);
if ($itemtype && !($item = getItemForItemtype($itemtype))) {
return false;
}
$table = $item->getTable();
$params['comments'] = true;
$params['condition'] = '';
$params['entity'] = -1;
$params['name'] = "reference";
$params['value'] = 0;
$params['entity_sons'] = false;
$params['rand'] = mt_rand();
$params['used'] = array();
$params['table'] = $table;
$params['emptylabel'] = Dropdown::EMPTY_VALUE;
//specific
$params['action'] = "";
$params['itemtype'] = "";
$params['span'] = "";
$params['orders_id'] = 0;
$params['suppliers_id'] = 0;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$name = $params['emptylabel'];
$comment = "";
$limit_length = $_SESSION["glpidropdown_chars_limit"];
if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
$params['value'] = 0;
}
if ($params['value'] > 0) {
$tmpname = Dropdown::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'])) {
echo "entity_sons options is not available with array of entity";
} else {
$params['entity'] = getSonsOf('glpi_entities', $params['entity']);
}
}
$use_ajax = false;
if ($CFG_GLPI["use_ajax_autocompletion"]) {
$nb = 0;
$query = "SELECT COUNT(*) AS cpt\n FROM `{$table}` as t\n LEFT JOIN `glpi_plugin_order_references_suppliers` as s\n ON (`t`.`id` = `s`.`plugin_order_references_id`)\n WHERE `s`.`suppliers_id` = '{$params['suppliers_id']}'\n AND `t`.`itemtype` = '{$params['itemtype']}'";
if ($item->isEntityAssign()) {
if (!($params['entity'] < 0)) {
$query .= getEntitiesRestrictRequest("AND", 't', '', $params['entity'], true);
} else {
$query .= getEntitiesRestrictRequest("AND", 't', '', '', true);
}
}
$result = $DB->query($query);
if ($DB->numrows($result) == 1) {
$nb = $DB->result($result, 0, "cpt");
}
$nb -= count($params['used']);
if ($nb > $CFG_GLPI["ajax_limit_count"]) {
$use_ajax = true;
}
}
$param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $params['itemtype'], 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'table' => $params['table'], 'action' => $params['action'], 'span' => $params['span'], 'orders_id' => $params['orders_id'], 'suppliers_id' => $params['suppliers_id']);
$default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
$default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
Ajax::Dropdown($use_ajax, "/plugins/order/ajax/dropdownValue.php", $param, $default, $params['rand']);
// Display comment
if ($params['comments']) {
$options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']);
if ($params['value'] && $item->getFromDB($params['value'])) {
$options_tooltip['link'] = $item->getLinkURL();
$options_tooltip['linktarget'] = '_blank';
}
//.........这里部分代码省略.........
示例5: history
/**
* Log history
*
* @param $items_id
* @param $itemtype
* @param $changes
* @param $itemtype_link (default '')
* @param $linked_action (default '0')
*
* @return boolean success
**/
static function history($items_id, $itemtype, $changes, $itemtype_link = '', $linked_action = '0')
{
global $DB;
$date_mod = $_SESSION["glpi_currenttime"];
if (empty($changes)) {
return false;
}
// create a query to insert history
$id_search_option = $changes[0];
$old_value = $changes[1];
$new_value = $changes[2];
if ($uid = Session::getLoginUserID(false)) {
if (is_numeric($uid)) {
$username = sprintf(__('%1$s (%2$s)'), getUserName($uid), $uid);
} else {
// For cron management
$username = $uid;
}
} else {
$username = "";
}
$old_value = $DB->escape(Toolbox::substr(stripslashes($old_value), 0, 180));
$new_value = $DB->escape(Toolbox::substr(stripslashes($new_value), 0, 180));
// Security to be sure that values do not pass over the max length
if (Toolbox::strlen($old_value) > 255) {
$old_value = Toolbox::substr($old_value, 0, 250);
}
if (Toolbox::strlen($new_value) > 255) {
$new_value = Toolbox::substr($new_value, 0, 250);
}
// Build query
$query = "INSERT INTO `glpi_logs`\n (`items_id`, `itemtype`, `itemtype_link`, `linked_action`, `user_name`,\n `date_mod`, `id_search_option`, `old_value`, `new_value`)\n VALUES ('{$items_id}', '{$itemtype}', '{$itemtype_link}', '{$linked_action}',\n '" . addslashes($username) . "', '{$date_mod}', '{$id_search_option}',\n '{$old_value}', '{$new_value}')";
if ($DB->query($query)) {
return $_SESSION['glpi_maxhistory'] = $DB->insert_id();
}
return false;
}
示例6: dropdownVlan
function dropdownVlan($used = array())
{
global $DB;
$limit = $_SESSION["glpidropdown_chars_limit"];
$where = "";
if (count($used)) {
$where = "WHERE `id` NOT IN (0";
foreach ($used as $ID) {
$where .= ",{$ID}";
}
$where .= ")";
}
$query = "SELECT *\n FROM `glpi_vlans`\n {$where}\n ORDER BY `name`";
$result = $DB->query($query);
$number = $DB->numrows($result);
if ($number != "0") {
echo "<select name='vlans_id'>\n";
echo "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n";
echo "<option value='-1'>" . __('All VLANs', 'archires') . "</option>\n";
while ($data = $DB->fetch_array($result)) {
$output = $data["name"];
if (Toolbox::strlen($output) > $limit) {
$output = Toolbox::substr($output, 0, $limit) . "…";
}
echo "<option value='" . $data["id"] . "'>" . $output . "</option>";
}
echo "</select>";
}
}
示例7: pdfNote
static function pdfNote(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
$ID = $item->getField('id');
$note = trim($item->getField('notepad'));
$pdf->setColumnsSize(100);
if (Toolbox::strlen($note) > 0) {
$pdf->displayTitle('<b>' . __('Notes') . '</b>');
$pdf->displayText('', $note, 5);
} else {
$pdf->displayTitle('<b>' . __('No note found', 'pdf') . '</b>');
}
$pdf->displaySpace();
}
示例8: str_repeat
}
$to_display = "<option disabled value='{$work_parentID}' {$class2}\n title=\"" . Html::cleanInputText($item->fields['completename'] . $addcomment) . "\">" . str_repeat(" ", $work_level) . $raquo2 . $output2 . "</option>" . $to_display;
$last_level_displayed[$work_level] = $item->fields['id'];
$work_level--;
$work_parentID = $item->fields[$item->getForeignKeyField()];
} else {
// Error getting item : stop
$work_level = -1;
}
} while ($work_level > 1 && (!isset($last_level_displayed[$work_level]) || $last_level_displayed[$work_level] != $work_parentID));
echo $to_display;
}
}
$last_level_displayed[$level] = $data['id'];
}
if (Toolbox::strlen($output) > $_POST["limit"]) {
if ($_SESSION['glpiuse_flat_dropdowntree']) {
$output = "…" . Toolbox::substr($output, -$_POST["limit"]);
} else {
$output = Toolbox::substr($output, 0, $_POST["limit"]) . "…";
}
}
if ($_SESSION["glpiis_ids_visible"] || strlen($output) == 0) {
$output .= " ({$ID})";
}
$addcomment = "";
if (isset($data["comment"])) {
$addcomment = " - " . $data["comment"];
}
echo "<option value='{$ID}' {$class} title=\"" . Html::cleanInputText($data['completename'] . $addcomment) . "\">" . str_repeat(" ", $level) . $raquo . $output . "</option>";
}
示例9: showItem
/**
* Print generic normal Item Cell
*
* @param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
* @param $value value to display
* @param &$num column number
* @param $row row number
* @param $extraparam extra parameters for display (default '')
*
*@return string to display
**/
static function showItem($type, $value, &$num, $row, $extraparam = '')
{
$out = "";
switch ($type) {
case self::PDF_OUTPUT_LANDSCAPE:
//pdf
//pdf
case self::PDF_OUTPUT_PORTRAIT:
global $PDF_TABLE;
$value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
$PDF_TABLE .= "<td {$extraparam} valign='top'>";
$PDF_TABLE .= Html::weblink_extract(Html::clean($value));
$PDF_TABLE .= "</td>\n";
break;
case self::SYLK_OUTPUT:
//sylk
global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
$value = Html::weblink_extract($value);
$value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
$SYLK_ARRAY[$row][$num] = self::sylk_clean($value);
$SYLK_SIZE[$num] = max($SYLK_SIZE[$num], Toolbox::strlen($SYLK_ARRAY[$row][$num]));
break;
case self::CSV_OUTPUT:
//csv
$value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
$value = Html::weblink_extract($value);
$out = "\"" . self::csv_clean($value) . "\"" . $_SESSION["glpicsv_delimiter"];
break;
default:
$out = "<td {$extraparam} valign='top'>";
if (!preg_match('/' . self::LBHR . '/', $value)) {
$values = preg_split('/' . self::LBBR . '/i', $value);
$line_delimiter = '<br>';
} else {
$values = preg_split('/' . self::LBHR . '/i', $value);
$line_delimiter = '<hr>';
}
$limitto = 20;
if (count($values) > $limitto) {
for ($i = 0; $i < $limitto; $i++) {
$out .= $values[$i] . $line_delimiter;
}
// $rand=mt_rand();
$out .= "... ";
$value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
$out .= Html::showToolTip($value, array('display' => false, 'autoclose' => false));
} else {
$value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
$out .= $value;
}
$out .= "</td>\n";
}
$num++;
return $out;
}
示例10: generateIcal
/**
* Generate ical file content
*
* @param $who user ID
* @param $who_group group ID
* @param $limititemtype itemtype only display this itemtype (default '')
*
* @return icalendar string
**/
static function generateIcal($who, $who_group, $limititemtype = '')
{
global $CFG_GLPI;
if ($who === 0 && $who_group === 0) {
return false;
}
if (!empty($CFG_GLPI["version"])) {
$unique_id = "GLPI-Planning-" . trim($CFG_GLPI["version"]);
} else {
$unique_id = "GLPI-Planning-UnknownVersion";
}
// create vcalendar
$vcalendar = new VObject\Component\VCalendar();
// $xprops = array( "X-LIC-LOCATION" => $tz );
// iCalUtilityFunctions::createTimezone( $v, $tz, $xprops );
$interv = array();
$begin = time() - MONTH_TIMESTAMP * 12;
$end = time() + MONTH_TIMESTAMP * 12;
$begin = date("Y-m-d H:i:s", $begin);
$end = date("Y-m-d H:i:s", $end);
$params = array('genical' => true, 'who' => $who, 'who_group' => $who_group, 'whogroup' => $who_group, 'begin' => $begin, 'end' => $end);
$interv = array();
if (empty($limititemtype)) {
foreach ($CFG_GLPI['planning_types'] as $itemtype) {
$interv = array_merge($interv, $itemtype::populatePlanning($params));
}
} else {
$interv = $limititemtype::populatePlanning($params);
}
if (count($interv) > 0) {
foreach ($interv as $key => $val) {
if (isset($val['itemtype'])) {
if (isset($val[getForeignKeyFieldForItemType($val['itemtype'])])) {
$uid = $val['itemtype'] . "#" . $val[getForeignKeyFieldForItemType($val['itemtype'])];
} else {
$uid = "Other#" . $key;
}
} else {
$uid = "Other#" . $key;
}
$vevent['UID'] = $uid;
$vevent['DTSTART'] = new \DateTime($val["begin"]);
$vevent['DTEND'] = new \DateTime($val["end"]);
if (isset($val["tickets_id"])) {
$summary = sprintf(__('Ticket #%1$s %2$s'), $val["tickets_id"], $val["name"]);
} else {
if (isset($val["name"])) {
$summary = $val["name"];
}
}
$vevent['SUMMARY'] = $summary;
if (isset($val["content"])) {
$description = $val["content"];
// be sure to replace nl by \r\n
$description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
$description = Html::clean($description);
} else {
if (isset($val["name"])) {
$description = $val["name"];
// be sure to replace nl by \r\n
$description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
$description = Html::clean($description);
}
}
$vevent['DESCRIPTION'] = $description;
if (isset($val["url"])) {
$vevent['URL'] = $val["url"];
}
$vcalendar->add('VEVENT', $vevent);
}
}
$output = $vcalendar->serialize();
$filename = date('YmdHis') . '.ics';
@Header("Content-Disposition: attachment; filename=\"{$filename}\"");
@Header("Content-Length: " . Toolbox::strlen($output));
@Header("Connection: close");
@Header("content-type: text/calendar; charset=utf-8");
echo $output;
}
示例11: update0713to072
//.........这里部分代码省略.........
// oldstate present if migration run more than once
if (isset($soft["oldstate"])) {
$soft["state"] = $soft["oldstate"];
}
// Foreach lics
$query_versions = "SELECT `glpi_licenses`.*,\n `glpi_infocoms`.`ID` AS infocomID\n FROM `glpi_licenses`\n LEFT JOIN `glpi_infocoms`\n ON (`glpi_infocoms`.`device_type` = '9999'\n AND `glpi_infocoms`.`FK_device` = `glpi_licenses`.`ID`)\n WHERE `sID` = '" . $soft['ID'] . "'\n ORDER BY `ID`";
if ($result_vers = $DB->query($query_versions)) {
if ($DB->numrows($result_vers) > 0) {
while ($vers = $DB->fetch_assoc($result_vers)) {
$install_count = 0;
$vers_ID = $vers['ID'];
// init : count installations
$query_count = "SELECT COUNT(*)\n FROM `glpi_inst_software`\n WHERE `vID` = '" . $vers['ID'] . "'";
if ($result_count = $DB->query($query_count)) {
$install_count = $DB->result($result_count, 0, 0);
$DB->free_result($result_count);
}
// 1 - Is version already exists ?
$query_search_version = "SELECT *\n FROM `glpi_softwareversions`\n WHERE `sID` = '" . $soft['ID'] . "'\n AND `name` = '" . $vers['version'] . "'";
if ($result_searchvers = $DB->query($query_search_version)) {
// Version already exists : update inst_software
if ($DB->numrows($result_searchvers) == 1) {
$found_vers = $DB->fetch_assoc($result_searchvers);
$vers_ID = $found_vers['ID'];
$query = "UPDATE `glpi_inst_software`\n SET `vID` = '" . $found_vers['ID'] . "'\n WHERE `vID` = '" . $vers['ID'] . "'";
$DB->query($query);
} else {
// Re Create new entry
$query = "INSERT INTO `glpi_softwareversions`\n SELECT `ID`, `sID`, '" . $soft["state"] . "', `version`,''\n FROM `glpi_licenses`\n WHERE `ID` = '" . $vers_ID . "'";
$DB->query($query);
// Transfert History for this version
$findstr = " (v. " . $vers['version'] . ")";
// Log event format in 0.71
$findlen = Toolbox::strlen($findstr);
$DB->query("UPDATE `glpi_history`\n SET `FK_glpi_device` = '" . $vers_ID . "',\n `device_type` = '" . SOFTWAREVERSION_TYPE . "'\n WHERE `FK_glpi_device` = '" . $soft['ID'] . "'\n AND `device_type` = '" . SOFTWARE_TYPE . "'\n AND ((`linked_action` = '" . Log::HISTORY_INSTALL_SOFTWARE . "'\n AND RIGHT(new_value, {$findlen}) = '{$findstr}')\n OR (`linked_action` = '" . Log::HISTORY_UNINSTALL_SOFTWARE . "'\n AND RIGHT(old_value, {$findlen}) = '{$findstr}'))");
}
$DB->free_result($result_searchvers);
}
// 2 - Create glpi_licenses
if ($vers['buy'] || !empty($vers['serial']) && !in_array($vers['serial'], array('free', 'global')) || !empty($vers['comments']) || !empty($vers['expire']) || $vers['oem_computer'] > 0 || !empty($vers['infocomID'])) {
// with and infocoms
$found_lic = -1;
// No infocoms try to find already exists license
if (empty($vers['infocomID'])) {
$query_search_lic = "SELECT `ID`\n FROM `glpi_softwarelicenses`\n WHERE `buy_version` = '{$vers_ID}'\n AND `serial` = '" . $vers['serial'] . "'\n AND `FK_computers` = '" . $vers['oem_computer'] . "'\n AND `comments` = '" . $vers['comments'] . "'";
if (empty($vers['expire'])) {
$query .= " AND `expire` IS NULL";
} else {
$query .= " AND `expire` = '" . $vers['expire'] . "'";
}
if ($result_searchlic = $DB->query($query_search_lic)) {
if ($DB->numrows($result_searchlic) > 0) {
$found_lic = $DB->result($result_searchlic, 0, 0);
$DB->free_result($result_searchlic);
}
}
}
if ($install_count == 0) {
$install_count = 1;
// license exists so count 1
}
// Found license : merge with found one
if ($found_lic > 0) {
$query = "UPDATE `glpi_softwarelicenses`\n SET `number` = `number`+1\n WHERE `ID` = '{$found_lic}'";
$DB->query($query);
} else {
示例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)
* - 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"];
}
}
}
}
//.........这里部分代码省略.........
示例13: showItem
/**
* Print generic normal Item Cell
*
* @param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
* @param $value value to display
* @param &$num column number
* @param $row row number
* @param $extraparam extra parameters for display (default '')
*
*@return string to display
**/
static function showItem($type, $value, &$num, $row, $extraparam = '')
{
$out = "";
switch ($type) {
case self::PDF_OUTPUT_LANDSCAPE:
//pdf
//pdf
case self::PDF_OUTPUT_PORTRAIT:
global $PDF_ARRAY, $PDF_HEADER;
$value = Html::weblink_extract($value);
$PDF_ARRAY[$row][$num] = Toolbox::decodeFromUtf8(Html::clean($value), 'windows-1252');
break;
case self::SYLK_OUTPUT:
//sylk
global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
$value = Html::weblink_extract($value);
$SYLK_ARRAY[$row][$num] = self::sylk_clean($value);
$SYLK_SIZE[$num] = max($SYLK_SIZE[$num], Toolbox::strlen($SYLK_ARRAY[$row][$num]));
break;
case self::CSV_OUTPUT:
//csv
$value = Html::weblink_extract($value);
$out = "\"" . self::csv_clean($value) . "\"" . $_SESSION["glpicsv_delimiter"];
break;
default:
//TODO supprimer valign pour mettre class mais conflit avec $extraparam
$out = "<td {$extraparam} valign='top'>";
/* if (!preg_match('/<hr>/',$value)) {
$values = preg_split("/<br>/i",$value);
$line_delimiter = '<br>';
} else {
$values = preg_split("/<hr>/i",$value);
$line_delimiter = '<hr>';
}
$limitto = 20;
if (count($values) > $limitto) {
for ( $i=0 ; $i<$limitto ; $i++) {
$out .= $values[$i].$line_delimiter;
}
$rand=mt_rand();
$out .= "... ";
$out .= Html::showToolTip($value,array('display' => false,
'autoclose' => false));
} else {*/
$out .= $value;
// }
$out .= "</td>\n";
}
$num++;
return $out;
}
示例14: 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;
//.........这里部分代码省略.........
示例15: 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;
}