Example #1
0
 public static function parse($isAddress = TRUE)
 {
     $SCA = new self($isAddress);
     $size = hexdec(PDU::getPduSubstr(2));
     if ($size) {
         // if is OA or DA size in digits
         if ($isAddress) {
             if ($size % 2 != 0) {
                 $size++;
             }
             // else size in octets
         } else {
             $size--;
             $size *= 2;
         }
         $SCA->setType(new SCA\Type(hexdec(PDU::getPduSubstr(2))));
         $hex = PDU::getPduSubstr($size);
         switch ($SCA->getType()->getType()) {
             case SCA\Type::TYPE_UNKNOWN:
             case SCA\Type::TYPE_INTERNATIONAL:
             case SCA\Type::TYPE_ACCEPTER_INTO_NET:
             case SCA\Type::TYPE_SUBSCRIBER_NET:
             case SCA\Type::TYPE_TRIMMED:
                 $SCA->setPhone(rtrim(implode("", array_map('strrev', array_map(array('self', '_map_filter_decode'), str_split($hex, 2)))), 'F'));
                 break;
             case SCA\Type::TYPE_ALPHANUMERICAL:
                 $SCA->setPhone(PDU\Helper::decode7bit($hex));
                 break;
         }
     }
     return $SCA;
 }
 static function showForDocumentCategory($item)
 {
     $documentCategory = new self();
     if (!$documentCategory->getFromDBByQuery(" WHERE `documentcategories_id` = " . $item->fields['id'])) {
         $documentCategory->getEmpty();
     }
     echo "<form name='form' method='post' action='" . Toolbox::getItemTypeFormURL($documentCategory->getType()) . "'>";
     echo "<div align='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Document category prefix', 'order') . "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     // Dropdown group
     echo "<td>";
     echo __('Document category prefix', 'order');
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='documentcategories_prefix' value='" . $documentCategory->fields['documentcategories_prefix'] . "'>";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 center' colspan='6'>";
     echo "<input type='submit' name='update' class='submit' value='" . _sx('button', 'Save') . "' >";
     echo "<input type='hidden' name='documentcategories_id' class='submit' value='" . $item->fields['id'] . "' >";
     echo "</td>";
     echo "</tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Example #3
0
 public static function loadPath($path, $type = null)
 {
     $model = new self();
     $model->path = $path;
     $model->originalPath = $path;
     if ($type) {
         $model->type = $type;
     }
     $model->getType();
     if ($model->isDirectory()) {
         return false;
     }
     if ($model->isPhp()) {
         $attributes = $model->attributes;
         $model = new PhpFile();
         $model->attributes = $attributes;
     }
     if ($type === self::TYPE_HOSTS) {
         $attributes = $model->attributes;
         $model = new HostsFile();
         $model->attributes = $attributes;
     }
     $model->getContents();
     return $model;
 }
 /**
  * @param $tt           TicketTemplate object
  * @param $withtemplate (default '')
  **/
 static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $itilcategory = new self();
     $ID = $tt->fields['id'];
     if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) {
         return false;
     }
     $ttm = new self();
     $rand = mt_rand();
     echo "<div class='center'>";
     $query = "SELECT `glpi_itilcategories`.*\n                FROM `glpi_itilcategories`\n                WHERE (`tickettemplates_id_incident` = '{$ID}')\n                       OR (`tickettemplates_id_demand` = '{$ID}')\n                ORDER BY `name`";
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='3'>";
         echo "<a href='" . Toolbox::getItemTypeSearchURL($itilcategory->getType()) . "'>";
         echo self::getTypeName($DB->numrows($result));
         echo "</a>";
         echo "</th></tr>";
         $used_incident = array();
         $used_demand = array();
         if ($DB->numrows($result)) {
             echo "<th>" . __('Name') . "</th>";
             echo "<th>" . __('Incident') . "</th>";
             echo "<th>" . __('Request') . "</th>";
             echo "</tr>";
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2'>";
                 $itilcategory->getFromDB($data['id']);
                 echo "<td>" . $itilcategory->getLink(array('comments' => true)) . "</td>";
                 if ($data['tickettemplates_id_incident'] == $ID) {
                     echo "<td class='center'>\n                        <img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt=\"" . __('OK') . "\" width='14' height='14'>\n                        </td>";
                     $used_incident[] = $data["id"];
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
                 if ($data['tickettemplates_id_demand'] == $ID) {
                     echo "<td class='center'>\n                        <img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt=\"" . __('OK') . "\" width='14' height='14'>\n                        </td>";
                     $used_demand[] = $data["id"];
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
             }
         } else {
             echo "<tr><th colspan='3'>" . __('No item found') . "</th></tr>";
         }
         echo "</table></div>";
     }
 }
 /**
  * Show the aliases contained by the alias
  *
  * @param $item                     the FQDN owning the aliases
  * @param $withtemplate  integer    withtemplate param
  **/
 static function showForFQDN(CommonGLPI $item, $withtemplate)
 {
     global $DB;
     $alias = new self();
     $address = new NetworkName();
     $item->check($item->getID(), 'r');
     $canedit = $item->can($item->getID(), 'w');
     if (isset($_POST["start"])) {
         $start = $_POST["start"];
     } else {
         $start = 0;
     }
     if (!empty($_POST["order"])) {
         $order = $_POST["order"];
     } else {
         $order = "alias";
     }
     $number = countElementsInTable($alias->getTable(), "`fqdns_id`='" . $item->getID() . "'");
     echo "<br><div class='center'>";
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . self::getTypeName(1) . "</th><th>" . __('No item found') . "</th></tr>";
         echo "</table>\n";
     } else {
         Html::printAjaxPager(self::getTypeName($number), $start, $number);
         echo "<table class='tab_cadre_fixe'><tr>";
         echo "<th><a href='javascript:reloadTab(\"order=alias\");'>" . self::getTypeName(1) . "</a></th>";
         // Alias
         echo "<th><a href='javascript:reloadTab(\"order=realname\");'>" . __("Computer's name") . "</a></th>";
         echo "<th>" . __('Comments') . "</th>";
         echo "</tr>\n";
         Session::initNavigateListItems($item->getType(), sprintf(__('%1$s = %2$s'), self::getTypeName(1), $item->fields['name']));
         $query = "SELECT `glpi_networkaliases`.`id` AS alias_id,\n                          `glpi_networkaliases`.`name` AS alias,\n                          `glpi_networknames`.`id` AS address_id,\n                          `glpi_networkaliases`.`comment` AS comment\n                   FROM `glpi_networkaliases`, `glpi_networknames`\n                   WHERE `glpi_networkaliases`.`fqdns_id` = '" . $item->getID() . "'\n                         AND  `glpi_networknames`.`id` = `glpi_networkaliases`.`networknames_id`\n                   ORDER BY `{$order}`\n                   LIMIT " . $_SESSION['glpilist_limit'] . "\n                   OFFSET {$start}";
         foreach ($DB->request($query) as $data) {
             Session::addToNavigateListItems($alias->getType(), $data["alias_id"]);
             if ($address->getFromDB($data["address_id"])) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td><a href='" . $alias->getFormURL() . '?id=' . $data['alias_id'] . "'>" . $data['alias'] . "</a></td>";
                 echo "<td><a href='" . $address->getLinkURL() . "'>" . $address->getInternetName() . "</a></td>";
                 echo "<td>" . $data['comment'] . "</td>";
                 echo "</tr>\n";
             }
         }
         echo "</table>\n";
         Html::printAjaxPager(self::getTypeName($number), $start, $number);
     }
     echo "</div>\n";
 }
Example #6
0
 static function showMinimalList($params = array())
 {
     global $DB, $CFG_GLPI;
     $item = new self();
     $itemtype = $item->getType();
     $itemtable = $item->getTable();
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['is_deleted'] = 0;
     $p['id'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     $p['withtemplate'] = 0;
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     $PluginResourcesResource = new PluginResourcesResource();
     $PluginResourcesResource->getFromDB($p['id']);
     $canedit = $PluginResourcesResource->can($p['id'], 'w');
     if (isset($_POST["start"])) {
         $p['start'] = $_POST["start"];
     } else {
         $p['start'] = 0;
     }
     if (isset($_POST["sort"])) {
         $p['sort'] = $_POST["sort"];
     } else {
         $p['sort'] = 1;
     }
     if (isset($_POST["order"]) && $_POST["order"] == "DESC") {
         $p['order'] = "DESC";
     } else {
         $p['order'] = "ASC";
     }
     // Manage defautll seachtype value : for bookmark compatibility
     if (count($p['contains'])) {
         foreach ($p['contains'] as $key => $val) {
             if (!isset($p['searchtype'][$key])) {
                 $p['searchtype'][$key] = 'contains';
             }
         }
     }
     if (is_array($p['contains2']) && count($p['contains2'])) {
         foreach ($p['contains2'] as $key => $val) {
             if (!isset($p['searchtype2'][$key])) {
                 $p['searchtype2'][$key] = 'contains';
             }
         }
     }
     $target = Toolbox::getItemTypeSearchURL($itemtype);
     $limitsearchopt = Search::getCleanedOptions($itemtype);
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $entity_restrict = $item->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID());
     if (count($displaypref)) {
         foreach ($displaypref as $val) {
             array_push($toview, $val);
         }
     }
     // Add searched items
     if (count($p['field']) > 0) {
         foreach ($p['field'] as $key => $val) {
             if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
                 array_push($toview, $val);
             }
         }
     }
     // Add order item
     if (!in_array($p['sort'], $toview)) {
         array_push($toview, $p['sort']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect($itemtype);
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= Search::addSelect($itemtype, $val, $key, 0);
     }
     $query .= "`" . $itemtable . "`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " FROM `" . $itemtable . "`";
     // Init already linked tables array in order not to link a table several times
     $already_link_tables = array();
     // Put reference table
     array_push($already_link_tables, $itemtable);
     // Add default join
     $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt[$itemtype] =& Search::getOptions($itemtype);
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
     }
     // Search all case :
     if (in_array("all", $p['field'])) {
         foreach ($searchopt[$itemtype] as $key => $val) {
             // Do not search on Group Name
             if (is_array($val)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
             }
         }
     }
     $query .= " WHERE `" . $itemtable . "`.`plugin_resources_resources_id` = '" . $p['id'] . "'";
     $query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (in_array('all', $p['field'])) {
         $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
     }
     if (empty($GROUPBY)) {
         foreach ($toview as $key2 => $val2) {
             if (!empty($GROUPBY)) {
                 break;
             }
             if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $item->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             if ($output_type == Search::HTML_OUTPUT && !$p['withtemplate']) {
                 echo "<div align='center'>";
                 echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?contains%5B0%5D=" . $p['id'] . "&field%5B0%5D=13&sort=1&is_deleted=0&start=0'>" . _x('button', 'Search') . "</a><br>";
                 echo "</div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if ($item->canCreate() && $canedit) {
                     $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&amp;itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\"";
                     $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']);
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows, $search_config);
                 echo "<br>";
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 Html::openMassiveActionsForm('massform' . $itemtype);
                 $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => true, 'is_deleted' => $p['is_deleted']);
                 Html::showMassiveActions($itemtype, $massiveactionparams);
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols, 1);
             $header_num = 1;
             // Display column Headers for toview items
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo Search::showNewLine($output_type);
             if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) {
                 // HTML display - massive modif
                 $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) {
                     $linkto = "javascript:reloadTab('sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto . "')";
                 }
                 $headers_line .= Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             $headers_line .= Search::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             $DB->data_seek($result, $p['start']);
             // Define begin and end var for loop
             // Search case
             $i = $begin_display;
             // Init list of items displayed
             if ($output_type == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype, PluginResourcesResource::getTypeName(2) . " = " . (empty($PluginResourcesResource->fields['name']) ? "(" . $p['id'] . ")" : $PluginResourcesResource->fields['name']));
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 $tmpcheck = "";
                 if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                     $sel = "";
                     $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                 }
                 echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= __('Tasks list', 'resources');
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($itemtype, $massiveactionparams);
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
 /**
  * Delete all delivered files of user
  *
  * @param int $a_exc_id excercise id
  * @param int $a_user_id user id
  */
 static function deleteAllDeliveredFilesOfUser($a_exc_id, $a_user_id)
 {
     global $ilDB;
     include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php";
     $delete_ids = array();
     // get the files and...
     $set = $ilDB->query("SELECT * FROM exc_returned " . " WHERE obj_id = " . $ilDB->quote($a_exc_id, "integer") . " AND user_id = " . $ilDB->quote($a_user_id, "integer"));
     while ($rec = $ilDB->fetchAssoc($set)) {
         $ass = new self($rec["ass_id"]);
         if ($ass->getType() == self::TYPE_UPLOAD_TEAM) {
             // switch upload to other team member
             $team = self::getTeamMembersByAssignmentId($ass->getId(), $a_user_id);
             if (sizeof($team) > 1) {
                 $new_owner = array_pop($team);
                 while ($new_owner == $a_user_id && sizeof($team)) {
                     $new_owner = array_pop($team);
                 }
                 $ilDB->manipulate("UPDATE exc_returned" . " SET user_id = " . $ilDB->quote($new_owner, "integer") . " WHERE returned_id = " . $ilDB->quote($rec["returned_id"], "integer"));
                 // no need to delete
                 continue;
             }
         }
         $delete_ids[] = $rec["returned_id"];
         $fs = new ilFSStorageExercise($a_exc_id, $rec["ass_id"]);
         // ...delete files
         $filename = $fs->getAbsoluteSubmissionPath() . "/" . $a_user_id . "/" . basename($rec["filename"]);
         if (is_file($filename)) {
             unlink($filename);
         }
     }
     // delete exc_returned records
     if ($delete_ids) {
         $ilDB->manipulate("DELETE FROM exc_returned" . " WHERE " . $ilDB->in("returned_id", $delete_ids, "", "integer"));
     }
     // delete il_exc_team records
     $ass_ids = array();
     foreach (self::getAssignmentDataOfExercise($a_exc_id) as $item) {
         $ass_ids[] = $item["id"];
     }
     if ($ass_ids) {
         $ilDB->manipulate($d = "DELETE FROM il_exc_team WHERE " . "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " . $ilDB->in("ass_id", $ass_ids, "", "integer"));
     }
 }
Example #8
0
 /**
  * Print the HTML array for SLTs linked to a SLA
  *
  * @param SLA $sla
  * @return boolean
  */
 static function showForSla(SLA $sla)
 {
     global $CFG_GLPI;
     $instID = $sla->fields['id'];
     $slt = new self();
     $calendar = new Calendar();
     if (!$sla->can($instID, READ)) {
         return false;
     }
     $canedit = $sla->canEdit($instID) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewslt{$instID}{$rand}'></div>\n";
         echo "<script type='text/javascript' >";
         echo "function viewAddSlt{$instID}{$rand}() {";
         $params = array('type' => $slt->getType(), 'parenttype' => $sla->getType(), $sla->getForeignKeyField() => $instID, 'id' => -1);
         Ajax::updateItemJsCode("viewslt{$instID}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "}";
         echo "</script>";
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddSlt{$instID}{$rand}();'>";
         echo __('Add a new SLT') . "</a></div>\n";
     }
     // SLT list
     $sltList = $slt->find("`slas_id` = '" . $instID . "'");
     Session::initNavigateListItems('SLT', sprintf(__('%1$s = %2$s'), $sla::getTypeName(1), $sla->getName()));
     echo "<div class='spaced'>";
     if (count($sltList)) {
         if ($canedit) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_top .= "</th>";
             $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom .= "</th>";
         }
         $header_end .= "<th>" . __('Name') . "</th>";
         $header_end .= "<th>" . __('Type') . "</th>";
         $header_end .= "<th>" . __('Maximum time') . "</th>";
         $header_end .= "<th>" . __('Calendar') . "</th>";
         echo $header_begin . $header_top . $header_end;
         foreach ($sltList as $val) {
             $edit = $canedit ? "style='cursor:pointer' onClick=\"viewEditSlt" . $instID . $val["id"] . "{$rand}();\"" : '';
             echo "\n<script type='text/javascript' >\n";
             echo "function viewEditSlt" . $instID . $val["id"] . "{$rand}() {\n";
             $params = array('type' => $slt->getType(), 'parenttype' => $sla->getType(), $sla->getForeignKeyField() => $instID, 'id' => $val["id"]);
             Ajax::updateItemJsCode("viewslt{$instID}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
             echo "};";
             echo "</script>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td width='10' {$edit}>";
             if ($canedit) {
                 Html::showMassiveActionCheckBox($slt->getType(), $val['id']);
             }
             echo "</td>";
             $slt->getFromDB($val['id']);
             echo "<td {$edit}>" . $slt->getLink() . "</td>";
             echo "<td {$edit}>" . $slt->getSpecificValueToDisplay('type', $slt->fields['type']) . "</td>";
             echo "<td {$edit}>";
             echo $slt->getSpecificValueToDisplay('number_time', array('number_time' => $slt->fields['number_time'], 'definition_time' => $slt->fields['definition_time']));
             echo "</td>";
             if (!$sla->fields['calendars_id']) {
                 $link = __('24/7');
             } else {
                 if ($sla->fields['calendars_id'] == -1) {
                     $link = __('Calendar of the ticket');
                 } else {
                     if ($calendar->getFromDB($sla->fields['calendars_id'])) {
                         $link = $calendar->getLink();
                     }
                 }
             }
             echo "<td {$edit}>" . $link . "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     } else {
         echo __('No item to display');
     }
     echo "</div>";
 }
 /** 
  * 用一张PNG图片给原始图片加水印,水印图片将自动调整到目标图片大小 
  * 
  * @param string $png png图片的路径 
  * @param string $hp 水平位置 left|center|right 
  * @param string $vp 垂直位置 top|center|bottom 
  * @param int    $pct 水印的透明度 0-100, 0为完全透明,100为完全不透明,只适用于非PNG图片水印 
  * @param string $path 如果指定则生成图片到$path 
  * @param  
  * @return 
  */
 function waterMark($markImg, $hp = 'center', $vp = 'center', $pct = 50, $path = null)
 {
     //原图信息
     $srcw = $this->getWidth();
     $srch = $this->getHeight();
     //水印图信息
     $mark = new self($markImg);
     $markw = $mark->getWidth();
     $markh = $mark->getHeight();
     //水印图片大于目标图片,调整大小
     if ($markw > $srcw || $markh > $srch) {
         //先将水印图片调整到原始图片大小-10个像素
         $mark->resize($srcw - 10, $srch - 10, true);
         $markw = $mark->getWidth();
         $markh = $mark->getHeight();
     }
     //判断水印位置
     $arrx = array('left' => 0, 'center' => floor(($srcw - $markw) / 2), 'right' => $srcw - $markw);
     $arry = array('top' => 0, 'center' => floor(($srch - $markh) / 2), 'bottom' => $srch - $markh);
     $x = isset($arrx[$hp]) ? $arrx[$hp] : $arrx['center'];
     $y = isset($arry[$vp]) ? $arry[$vp] : $arry['center'];
     //png图片水印
     if ($mark->getType() == 3) {
         //打开混色模式
         imagealphablending($this->img, true);
         imagecopy($this->img, $mark->getResource(), $x, $y, 0, 0, $markw, $markh);
     } else {
         imagecopymerge($this->img, $mark->getResource(), $x, $y, 0, 0, $markw, $markh, $pct);
     }
     unset($mark);
     if ($path) {
         return $this->save($path);
     }
     return $this;
 }
Example #10
0
 /**
  * @static function showMap : affiche tous les éléments de la carte (menus, onglets...)
  * @param $options
  */
 static function showMap($options)
 {
     global $CFG_GLPI;
     if (!$options['locations_id']) {
         $self = new self();
         $self->getFromDB($options["id"]);
         if (isset($self->fields["itemtype"])) {
             $options['locations_id'] = $self->fields['locations_id'];
         }
     }
     if ($options['locations_id']) {
         $documents_id = self::getDocument($options['locations_id']);
         $Doc = new Document();
         if (isset($documents_id) && $Doc->getFromDB($documents_id)) {
             $params = array("locations_id" => $options['locations_id'], "id" => $options['id'], "itemtype" => $options['itemtype'], "target" => $options['target']);
             $params['docid'] = $documents_id;
             $path = GLPI_DOC_DIR . "/" . $Doc->fields["filepath"];
             if ($handle = fopen($path, "r")) {
                 $infos_image = @getImageSize($path);
                 $params["largeur"] = $infos_image[0];
                 $params["hauteur"] = $infos_image[1];
                 $params["download"] = 1;
                 if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
                     $params["download"] = 0;
                 }
                 echo "<div class='center'><table class='plugin_positions_tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_2' valign='top'>";
                 $items = self::getMapItems($params['locations_id']);
                 if (!isset($options['menuoff'])) {
                     echo "<td>";
                     self::showLocationForm($params["locations_id"], "100%");
                     echo "</td>";
                 }
                 if (Session::haveRight('plugin_positions', UPDATE) && !isset($options['menuoff'])) {
                     echo "<td>";
                     self::showAddFromPlugin($params['locations_id']);
                     echo "</td>";
                     echo "<td>";
                     self::selectDisplay($params, $items);
                     echo "</td>";
                 }
                 echo "</tr>";
                 echo "</table></div>";
                 if (isset($options['menuoff'])) {
                     $params["menuoff"] = $options['menuoff'];
                 }
                 if (Session::haveRight('plugin_positions', UPDATE) && !isset($options['menuoff'])) {
                     echo "<form method='post' name='pointform' id='pointform' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/positions/front/position.form.php\">";
                     echo "<div class='center'>";
                     echo "<table class='plugin_positions_tab_cadre_fixe' width='30%'>";
                     if ($options['id']) {
                         echo "<tr class='tab_bg_2'>";
                         $form = Toolbox::getItemTypeFormURL($self->getType());
                         echo "<td colspan='4' class='center'>" . $self->getLink();
                         echo "</td></tr>";
                     }
                     echo "<tr class='tab_bg_2'>";
                     echo "<td colspan='2' class='center'>";
                     echo "<input type='submit' name='update' value=\"" . __s('Change the coordinates', 'positions') . "\" class='submit'>";
                     echo "</td>";
                     //création d'un nouveau bouton pour la création de nouvelles pièces
                     echo "<td colspan='2' class='center'>";
                     echo "<input type='submit' name='addLocation' value=\"" . __s('Add a sub-area', 'positions') . "\" class='submit'>";
                     echo "</td>";
                     echo "<input type='hidden' name='locations_id' value='" . $options['locations_id'] . "'>";
                     echo "<input type='hidden' name='id' value='" . $options['id'] . "'>";
                     echo "<input type='hidden' name ='x_coordinates'>";
                     echo "<input type='hidden' name ='y_coordinates'>";
                     echo "<input type='hidden' name ='multi'>";
                     echo "<input type='hidden' name ='referrer' value='" . $options['id'] . "'>";
                     echo "</tr>";
                     echo "</table></div>";
                 }
                 echo "<div class='center'><table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><th>";
                 echo $Doc->fields["name"];
                 echo "</th></tr>";
                 echo "<tr class='tab_bg_1'><td>";
                 self::displayMap($items, $params);
                 echo "</td></tr>";
                 echo "</table>";
                 if (Session::haveRight('plugin_positions', UPDATE) && !isset($options['menuoff'])) {
                     Html::closeForm();
                 }
             } else {
                 echo "<div class='center'>";
                 _e('No location has a configured map', 'positions');
                 echo "</div>";
             }
         } else {
             echo "<div class='center'>";
             echo __('The object location does not match a map', 'positions') . "<br><br>";
             Html::displayBackLink();
             echo "</div>";
         }
     } else {
         echo "<div class='center'>";
         _e('No location selected', 'positions');
         echo "</div>";
     }
 }