/** * Check user permissions and authentication */ public function checkAuth() { $user = User::getInstance(); $uid = false; if ($user->isAuthorized()) { $uid = $user->id; } if (!$uid || !$user->isAdmin()) { if (Request::isAjax()) { Response::jsonError($this->_lang->MSG_AUTHORIZE); } else { $this->loginAction(); } } /* * Check CSRF token */ if ($this->_configBackend->get('use_csrf_token') && Request::hasPost()) { $csrf = new Security_Csrf(); $csrf->setOptions(array('lifetime' => $this->_configBackend->get('use_csrf_token_lifetime'), 'cleanupLimit' => $this->_configBackend->get('use_csrf_token_garbage_limit'))); if (!$csrf->checkHeader() && !$csrf->checkPost()) { $this->_errorResponse($this->_lang->MSG_NEED_CSRF_TOKEN); } } $this->_user = $user; $isSysController = in_array(get_called_class(), $this->_configBackend->get('system_controllers'), true); if ($isSysController) { return; } if (!$this->_user->canView($this->_module)) { $this->_errorResponse($this->_lang->CANT_VIEW); } $moduleManager = new Backend_Modules_Manager(); // $modules = Config::factory(Config::File_Array , $this->_configMain['backend_modules']); /* * Redirect for undefined module */ if (!$moduleManager->isValidModule($this->_module)) { $this->_errorResponse($this->_lang->WRONG_REQUEST); } $moduleCfg = $moduleManager->getModuleConfig($this->_module); /* * Redirect for disabled module */ if ($moduleCfg['active'] == false) { $this->_errorResponse($this->_lang->CANT_VIEW); } /* * Redirect for dev module at prouction */ if ($moduleCfg['dev'] && !$this->_configMain['development']) { $this->_errorResponse($this->_lang->CANT_VIEW); } }
function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; if (!static::canView()) { return false; } // In percent $colsize1 = '13'; $colsize2 = '37'; $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1); // Set default options if (!$ID) { $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_suppliers_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => '', 'itilcategories_id' => 0); foreach ($values as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val; } } if (isset($options['tickets_id'])) { $ticket = new Ticket(); if ($ticket->getFromDB($options['tickets_id'])) { $options['content'] = $ticket->getField('content'); $options['name'] = $ticket->getField('name'); $options['impact'] = $ticket->getField('impact'); $options['urgency'] = $ticket->getField('urgency'); $options['priority'] = $ticket->getField('priority'); $options['itilcategories_id'] = $ticket->getField('itilcategories_id'); $options['due_date'] = $ticket->getField('due_date'); } } if (isset($options['problems_id'])) { $problem = new Problem(); if ($problem->getFromDB($options['problems_id'])) { $options['content'] = $problem->getField('content'); $options['name'] = $problem->getField('name'); $options['impact'] = $problem->getField('impact'); $options['urgency'] = $problem->getField('urgency'); $options['priority'] = $problem->getField('priority'); $options['itilcategories_id'] = $problem->getField('itilcategories_id'); $options['due_date'] = $problem->getField('due_date'); } } } if ($ID > 0) { $this->check($ID, READ); } else { // Create item $this->check(-1, CREATE, $options); } $showuserlink = 0; if (User::canView()) { $showuserlink = 1; } $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<th class='left' width='{$colsize1}%'>" . __('Opening date') . "</th>"; echo "<td class='left' width='{$colsize2}%'>"; if (isset($options['tickets_id'])) { echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>"; } if (isset($options['problems_id'])) { echo "<input type='hidden' name='_problems_id' value='" . $options['problems_id'] . "'>"; } $date = $this->fields["date"]; if (!$ID) { $date = date("Y-m-d H:i:s"); } Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Due date') . "</th>"; echo "<td width='{$colsize2}%' class='left'>"; if ($this->fields["due_date"] == 'NULL') { $this->fields["due_date"] = ''; } Html::showDateTimeField("due_date", array('value' => $this->fields["due_date"], 'timestep' => 1)); echo "</td></tr>"; if ($ID) { echo "<tr class='tab_bg_1'><th>" . __('By') . "</th><td>"; User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<th>" . __('Last update') . "</th>"; echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "\n"; if ($this->fields['users_id_lastupdater'] > 0) { printf(__('%1$s: %2$s'), __('By'), getUserName($this->fields["users_id_lastupdater"], $showuserlink)); } echo "</td></tr>"; } if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) { echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Date of solving') . "</th>"; echo "<td>"; Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; if (in_array($this->fields["status"], $this->getClosedStatusArray())) { echo "<th>" . __('Closing date') . "</th>"; echo "<td>"; Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; } echo "</table>"; echo "<table class='tab_cadre_fixe' id='mainformtable2'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Status') . "</th>"; echo "<td width='{$colsize2}%'>"; self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed')); ChangeValidation::alertValidation($this, 'status'); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>"; echo "<td width='{$colsize2}%'>"; // Only change during creation OR when allowed to change priority OR when user is the creator $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Category') . "</th>"; echo "<td >"; $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_change`='1'"); ITILCategory::dropdown($opt); echo "</td>"; echo "<th>" . __('Impact') . "</th>"; echo "<td>"; $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Total duration') . "</th>"; echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>"; echo "<th class='left'>" . __('Priority') . "</th>"; echo "<td>"; $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true)); $idajax = 'change_priority_' . mt_rand(); echo " <span id='{$idajax}' style='display:none'></span>"; $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => 'dropdown_priority' . $idpriority); Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); echo "</td>"; echo "</tr>"; echo "</table>"; $this->showActorsPartForm($ID, $options); echo "<table class='tab_cadre_fixe' id='mainformtable3'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Title') . "</th>"; echo "<td colspan='3'>"; echo "<input type='text' size='90' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Description') . "</th>"; echo "<td colspan='3'>"; $rand = mt_rand(); echo "<textarea id='content{$rand}' name='content' cols='90' rows='6'>" . Html::clean(Html::entity_decode_deep($this->fields["content"])) . "</textarea>"; echo "</td>"; echo "</tr>"; $options['colspan'] = 3; $this->showFormButtons($options); return true; }
/** * Show the current ticketfollowup summary * * @param $ticket Ticket object **/ function showSummary($ticket) { global $DB, $CFG_GLPI; if (!Session::haveRightsOr(self::$rightname, array(self::SEEPUBLIC, self::SEEPRIVATE))) { return false; } $tID = $ticket->fields['id']; // Display existing Followups $showprivate = Session::haveRight(self::$rightname, self::SEEPRIVATE); $caneditall = Session::haveRight(self::$rightname, self::UPDATEALL); $tmp = array('tickets_id' => $tID); $canadd = $this->can(-1, CREATE, $tmp); $showuserlink = 0; if (User::canView()) { $showuserlink = 1; } $techs = $ticket->getAllUsers(CommonITILActor::ASSIGN); $reopen_case = false; if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray()) && $ticket->isAllowedStatus($ticket->fields['status'], Ticket::INCOMING)) { $reopen_case = true; } $tech = Session::haveRight(self::$rightname, self::ADDALLTICKET) || $ticket->isUser(CommonITILActor::ASSIGN, Session::getLoginUserID()) || isset($_SESSION["glpigroups"]) && $ticket->haveAGroup(CommonITILActor::ASSIGN, $_SESSION['glpigroups']); $RESTRICT = ""; if (!$showprivate) { $RESTRICT = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') "; } $query = "SELECT `glpi_ticketfollowups`.*, `glpi_users`.`picture`\n FROM `glpi_ticketfollowups`\n LEFT JOIN `glpi_users` ON (`glpi_ticketfollowups`.`users_id` = `glpi_users`.`id`)\n WHERE `tickets_id` = '{$tID}'\n {$RESTRICT}\n ORDER BY `date` DESC"; $result = $DB->query($query); $rand = mt_rand(); if ($caneditall || $canadd) { echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n"; } if ($canadd) { echo "<script type='text/javascript' >\n"; echo "function viewAddFollowup" . $ticket->fields['id'] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $ticket->fields['id'], 'id' => -1); Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo Html::jsHide('addbutton' . $ticket->fields['id'] . "{$rand}"); echo "};"; echo "</script>\n"; // Not closed ticket or closed if (!in_array($ticket->fields["status"], array_merge($ticket->getSolvedStatusArray(), $ticket->getClosedStatusArray())) || $reopen_case) { if (isset($_GET['_openfollowup']) && $_GET['_openfollowup']) { echo Html::scriptBlock("viewAddFollowup" . $ticket->fields['id'] . "{$rand}()"); } else { echo "<div id='addbutton" . $ticket->fields['id'] . "{$rand}' class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddFollowup" . $ticket->fields['id'] . "{$rand}();'>"; if ($reopen_case) { _e('Reopen the ticket'); } else { _e('Add a new followup'); } echo "</a></div>\n"; } } } if ($DB->numrows($result) == 0) { echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>"; echo "<th class='b'>" . __('No followup for this ticket.') . "</th></tr></table>"; } else { $today = strtotime('today'); $lastmonday = strtotime('last monday'); $lastlastmonday = strtotime('last monday', strtotime('last monday')); // Case of monday if ($today - $lastmonday == 7 * DAY_TIMESTAMP) { $lastlastmonday = $lastmonday; $lastmonday = $today; } $steps = array(0 => array('end' => $today, 'name' => __('Today')), 1 => array('end' => $lastmonday, 'name' => __('This week')), 2 => array('end' => $lastlastmonday, 'name' => __('Last week')), 3 => array('end' => strtotime('midnight first day of'), 'name' => __('This month')), 4 => array('end' => strtotime('midnight first day of last month'), 'name' => __('Last month')), 5 => array('end' => 0, 'name' => __('Before the last month'))); $currentpos = -1; while ($data = $DB->fetch_assoc($result)) { $this->getFromDB($data['id']); $candelete = $this->canPurge() && $this->canPurgeItem(); $canedit = $this->canUpdate() && $this->canUpdateItem(); $time = strtotime($data['date']); if (!isset($steps[$currentpos]) || $steps[$currentpos]['end'] > $time) { $currentpos++; while ($steps[$currentpos]['end'] > $time && isset($steps[$currentpos + 1])) { $currentpos++; } if (isset($steps[$currentpos])) { echo "<h3>" . $steps[$currentpos]['name'] . "</h3>"; } } $id = 'followup' . $data['id'] . $rand; $color = 'byuser'; if (isset($techs[$data['users_id']])) { $color = 'bytech'; } $classtoadd = ''; if ($canedit) { $classtoadd = " pointer"; } echo "<div class='boxnote {$color}' id='view{$id}'"; echo ">"; echo "<div class='boxnoteleft'>"; echo "<img class='user_picture_verysmall' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($data['picture']) . "'>"; echo "</div>"; // boxnoteleft echo "<div class='boxnotecontent'"; echo ">"; echo "<div class='boxnotefloatleft'>"; $username = NOT_AVAILABLE; if ($data['users_id']) { $username = getUserName($data['users_id'], $showuserlink); } $name = sprintf(__('Create by %1$s on %2$s'), $username, Html::convDateTime($data['date'])); if ($data['requesttypes_id']) { $name = sprintf(__('%1$s - %2$s'), $name, Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id'])); } if ($showprivate && $data["is_private"]) { $name = sprintf(__('%1$s - %2$s'), $name, __('Private')); } echo $name; echo "</div>"; // floatright echo "<div class='boxnotetext {$classtoadd}'"; if ($canedit) { echo " onClick=\"viewEditFollowup" . $ticket->fields['id'] . $data['id'] . "{$rand}(); " . Html::jsHide("view{$id}") . " " . Html::jsShow("viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}") . "\" "; } echo ">"; $content = nl2br($data['content']); if (empty($content)) { $content = NOT_AVAILABLE; } echo $content . '</div>'; // boxnotetext echo "</div>"; // boxnotecontent echo "<div class='boxnoteright'>"; if ($candelete) { Html::showSimpleForm(Toolbox::getItemTypeFormURL('TicketFollowup'), array('purge' => 'purge'), _x('button', 'Delete permanently'), array('id' => $data['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png", '', __('Confirm the final deletion?')); } echo "</div>"; // boxnoteright echo "</div>"; // boxnote if ($canedit) { echo "<div id='viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}' class='starthidden'></div>\n"; echo "\n<script type='text/javascript' >\n"; echo "function viewEditFollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $data["tickets_id"], 'id' => $data["id"]); Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } } } }
/** Get users which have followup assigned to between 2 dates * * @param $date1 date : begin date (default '') * @param $date2 date : end date (default '') * * @return array contains the distinct users which have any followup assigned to. **/ function getUsedTechTaskBetween($date1 = '', $date2 = '') { global $DB; $tasktable = getTableForItemType($this->getType() . 'Task'); $showlink = User::canView(); $query = "SELECT DISTINCT `glpi_users`.`id` AS users_id,\n `glpi_users`.`name` AS name,\n `glpi_users`.`realname` AS realname,\n `glpi_users`.`firstname` AS firstname\n FROM `" . $this->getTable() . "`\n LEFT JOIN `{$tasktable}`\n ON (`" . $this->getTable() . "`.`id` = `{$tasktable}`.`" . $this->getForeignKeyField() . "`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `{$tasktable}`.`users_id`)\n LEFT JOIN `glpi_profiles_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n LEFT JOIN `glpi_profilerights`\n ON (`glpi_profiles`.`id` = `glpi_profilerights`.`profiles_id`)\n WHERE NOT `" . $this->getTable() . "`.`is_deleted` " . getEntitiesRestrictRequest("AND", $this->getTable()); if (!empty($date1) || !empty($date2)) { $query .= " AND (" . getDateRequest("`" . $this->getTable() . "`.`date`", $date1, $date2) . "\n OR " . getDateRequest("`" . $this->getTable() . "`.`closedate`", $date1, $date2) . ") "; } $query .= " AND `glpi_profilerights`.`name` = 'ticket'\n AND (`glpi_profilerights`.`rights` & " . Ticket::OWN . ")\n AND `{$tasktable}`.`users_id` <> '0'\n AND `{$tasktable}`.`users_id` IS NOT NULL\n ORDER BY realname, firstname, name"; $result = $DB->query($query); $tab = array(); if ($DB->numrows($result) >= 1) { while ($line = $DB->fetch_assoc($result)) { $tmp['id'] = $line["users_id"]; $tmp['link'] = formatUserName($line["users_id"], $line["name"], $line["realname"], $line["firstname"], $showlink); $tab[] = $tmp; } } return $tab; }
/** Show LDAP users to add or synchronise * * @return nothing **/ static function showLdapUsers() { global $CFG_GLPI; $values['order'] = 'DESC'; $values['start'] = 0; foreach ($_SESSION['ldap_import'] as $option => $value) { $values[$option] = $value; } $rand = mt_rand(); $results = array(); $limitexceeded = false; $ldap_users = self::getAllUsers($values, $results, $limitexceeded); if (is_array($ldap_users)) { $numrows = count($ldap_users); if ($numrows > 0) { self::displaySizeLimitWarning($limitexceeded); Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], ''); // delete end array_splice($ldap_users, $values['start'] + $_SESSION['glpilist_limit']); // delete begin if ($values['start'] > 0) { array_splice($ldap_users, 0, $values['start']); } $form_action = ''; $textbutton = ''; if ($_SESSION['ldap_import']['mode']) { $textbutton = _x('button', 'Synchronize'); $form_action = __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'sync'; } else { $textbutton = _x('button', 'Import'); $form_action = __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'import'; } Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => min(count($ldap_users), $_SESSION['glpilist_limit']), 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array($form_action => $textbutton)); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; $num = 0; echo Search::showHeaderItem(Search::HTML_OUTPUT, _n('User', 'Users', Session::getPluralNumber()), $num, $_SERVER['PHP_SELF'] . "?order=" . ($values['order'] == "DESC" ? "ASC" : "DESC")); echo "<th>" . __('Last update in the LDAP directory') . "</th>"; if ($_SESSION['ldap_import']['mode']) { echo "<th>" . __('Last update in GLPI') . "</th>"; } echo "</tr>"; foreach ($ldap_users as $userinfos) { $link = $user = $userinfos["user"]; if (isset($userinfos['id']) && User::canView()) { $link = "<a href='" . Toolbox::getItemTypeFormURL('User') . '?id=' . $userinfos['id'] . "'>{$user}</a>"; } if (isset($userinfos["timestamp"])) { $stamp = $userinfos["timestamp"]; } else { $stamp = ''; } if (isset($userinfos["date_sync"])) { $date_sync = $userinfos["date_sync"]; } else { $date_sync = ''; } echo "<tr class='tab_bg_2 center'>"; //Need to use " instead of ' because it doesn't work with names with ' inside ! echo "<td>"; echo Html::getMassiveActionCheckBox(__CLASS__, $user); //echo "<input type='checkbox' name=\"item[" . $user . "]\" value='1'>"; echo "</td>"; echo "<td>" . $link . "</td>"; if ($stamp != '') { echo "<td>" . Html::convDateTime(date("Y-m-d H:i:s", $stamp)) . "</td>"; } else { echo "<td> </td>"; } if ($_SESSION['ldap_import']['mode']) { if ($date_sync != '') { echo "<td>" . Html::convDateTime($date_sync) . "</td>"; } else { echo "<td> </td>"; } } echo "</tr>"; } echo "<tr>"; echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; $num = 0; echo Search::showHeaderItem(Search::HTML_OUTPUT, _n('User', 'Users', Session::getPluralNumber()), $num, $_SERVER['PHP_SELF'] . "?order=" . ($values['order'] == "DESC" ? "ASC" : "DESC")); echo "<th>" . __('Last update in the LDAP directory') . "</th>"; if ($_SESSION['ldap_import']['mode']) { echo "<th>" . __('Last update in GLPI') . "</th>"; } echo "</tr>"; echo "</table>"; $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], ''); } else { echo "<div class='center b'>" . ($_SESSION['ldap_import']['mode'] ? __('No user to be synchronized') : __('No user to be imported')) . "</div>"; } } else { echo "<div class='center b'>" . ($_SESSION['ldap_import']['mode'] ? __('No user to be synchronized') : __('No user to be imported')) . "</div>"; } }
/** * Show users of an entity * * @param $entity Entity object **/ static function showForEntity(Entity $entity) { global $DB; $ID = $entity->getField('id'); if (!$entity->can($ID, READ)) { return false; } $canedit = $entity->canEdit($ID); $canshowuser = User::canView(); $nb_per_line = 3; $rand = mt_rand(); if ($canedit) { $headerspan = $nb_per_line * 2; } else { $headerspan = $nb_per_line; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>"; echo "<tr class='tab_bg_1'><td class='tab_bg_2 center'>" . __('User') . " "; echo "<input type='hidden' name='entities_id' value='{$ID}'>"; User::dropdown(array('right' => 'all')); echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>"; Profile::dropdownUnder(array('value' => Profile::getDefault())); echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>"; Dropdown::showYesNo("is_recursive", 0); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'"; $result = $DB->query($query); $nb = $DB->numrows($result); echo "<div class='spaced'>"; if ($canedit && $nb) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<thead><tr>"; echo "<th class='noHover' colspan='{$headerspan}'>"; printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive')); echo "</th></tr></thead>"; if ($nb) { Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName())); while ($data = $DB->fetch_assoc($result)) { echo "<tbody><tr class='noHover'>"; $reduce_header = 0; if ($canedit && $nb) { echo "<th width='10'>"; echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}"); echo "</th>"; $reduce_header++; } echo "<th colspan='" . ($headerspan - $reduce_header) . "'>"; printf(__('%1$s: %2$s'), __('Profile'), $data["name"]); echo "</th></tr></tbody>"; echo "<tbody id='profile" . $data['id'] . "_{$rand}'>"; $query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'\n AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n ORDER BY `glpi_profiles_users`.`profiles_id`,\n `glpi_users`.`name`,\n `glpi_users`.`realname`,\n `glpi_users`.`firstname`"; $result2 = $DB->query($query); if ($DB->numrows($result2) > 0) { $i = 0; while ($data2 = $DB->fetch_assoc($result2)) { Session::addToNavigateListItems('User', $data2["id"]); if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>"; } echo "<tr class='tab_bg_1'>"; } if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]); echo "</td>"; } $username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser); if ($data2["is_dynamic"] || $data2["is_recursive"]) { $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>("); if ($data2["is_dynamic"]) { $username = sprintf(__('%1$s%2$s'), $username, __('D')); } if ($data2["is_dynamic"] && $data2["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, ", "); } if ($data2["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, __('R')); } $username = sprintf(__('%1$s%2$s'), $username, ")</span>"); } echo "<td>" . $username . "</td>"; $i++; } while ($i % $nb_per_line != 0) { echo "<td> </td>"; if ($canedit) { echo "<td> </td>"; } $i++; } echo "</tr>"; echo "</tbody>"; } else { echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>"; } } } echo "</table>"; if ($canedit && $nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Print out (html) show item : question and answer * * @param $options array of options * * @return nothing (display item : question and answer) **/ function showFull($options = array()) { global $DB, $CFG_GLPI; if (!$this->can($this->fields['id'], READ)) { return false; } $linkusers_id = true; // show item : question and answer if (Session::getLoginUserID() === false && $CFG_GLPI["use_public_faq"] || $_SESSION["glpiactiveprofile"]["interface"] == "helpdesk" || !User::canView()) { $linkusers_id = false; } $this->updateCounter(); $knowbaseitemcategories_id = $this->fields["knowbaseitemcategories_id"]; $fullcategoryname = getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id); $tmp = "<a href='" . $this->getSearchURL() . "?knowbaseitemcategories_id={$knowbaseitemcategories_id}'>" . $fullcategoryname . "</a>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Category'), $tmp); echo "</th></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Subject') . "</h2>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { echo KnowbaseItemTranslation::getTranslatedValue($this, 'name'); } else { echo $this->fields["name"]; } echo "</td></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Content') . "</h2>\n"; echo "<div id='kbanswer'>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { $answer = KnowbaseItemTranslation::getTranslatedValue($this, 'answer'); } else { $answer = $this->fields["answer"]; } echo Toolbox::unclean_html_cross_side_scripting_deep($answer); echo "</div>"; echo "</td></tr>"; echo "<tr><th class='tdkb' colspan='2'>"; if ($this->fields["users_id"]) { // Integer because true may be 2 and getUserName return array if ($linkusers_id) { $linkusers_id = 1; } else { $linkusers_id = 0; } printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $linkusers_id)); echo "<br>"; } if ($this->fields["date"]) { //TRANS: %s is the datetime of update printf(__('Created on %s'), Html::convDateTime($this->fields["date"])); echo "<br>"; } if ($this->fields["date_mod"]) { //TRANS: %s is the datetime of update printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } echo "</th>"; echo "<th class='tdkb' colspan='2'>"; if ($this->countVisibilities() == 0) { echo "<span class='red'>" . __('Unpublished') . "</span><br>"; } printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]); echo "<br>"; if ($this->fields["is_faq"]) { _e('This item is part of the FAQ'); } else { _e('This item is not part of the FAQ'); } echo "</th></tr>"; echo "</table>"; return true; }
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { switch ($item->getType()) { case 'User': if (Group::canView()) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(Group::getTypeName(Session::getPluralNumber()), countElementsInTable($this->getTable(), "users_id\n = '" . $item->getID() . "'")); } return Group::getTypeName(Session::getPluralNumber()); } break; case 'Group': if (User::canView()) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(User::getTypeName(Session::getPluralNumber()), countElementsInTable("glpi_groups_users", "`groups_id`\n = '" . $item->getID() . "'")); } return User::getTypeName(Session::getPluralNumber()); } break; } } return ''; }
/** * Show computers linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI; $searchID = $license->getField('id'); if (!Software::canView() || !$searchID) { return false; } $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE)); $canshowcomputer = Computer::canView(); if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"])) { // manage several param like location,compname : order first $tmp = explode(",", $_GET["sort"]); $sort = "`" . implode("` {$order},`", $tmp) . "`"; } else { $sort = "`entity` {$order}, `compname`"; } //SoftwareLicense ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id`\n = `glpi_computers`.`id`)\n WHERE `glpi_computers_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'"; $number = 0; if ($result = $DB->query($query_number)) { $number = $DB->result($result, 0, 0); } echo "<div class='center'>"; if ($canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td>"; Computer::dropdown(array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive'])); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(__('Affected computers'), $start, $number); $query = "SELECT `glpi_computers_softwarelicenses`.*,\n `glpi_computers`.`name` AS compname,\n `glpi_computers`.`id` AS cID,\n `glpi_computers`.`serial`,\n `glpi_computers`.`otherserial`,\n `glpi_users`.`name` AS username,\n `glpi_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\n `glpi_softwarelicenses`.`name` AS license,\n `glpi_softwarelicenses`.`id` AS vID,\n `glpi_softwarelicenses`.`name` AS vername,\n `glpi_entities`.`completename` AS entity,\n `glpi_locations`.`completename` AS location,\n `glpi_states`.`name` AS state,\n `glpi_groups`.`name` AS groupe,\n `glpi_softwarelicenses`.`name` AS lname,\n `glpi_softwarelicenses`.`id` AS lID,\n `glpi_softwarelicenses`.`softwares_id` AS softid\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n LEFT JOIN `glpi_locations`\n ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n WHERE (`glpi_softwarelicenses`.`id` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); // show transfer only if multi licenses for this software if (self::countLicenses($data['softid']) > 1) { $massiveactionparams['specific_actions'][__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'move_license'] = _x('button', 'Move'); } // Options to update license $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID); $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id']; Html::showMassiveActions($massiveactionparams); } $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $showEntity = $license->isRecursive(); $linkUser = User::canView(); $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]); $text = sprintf(__('%1$s - %2$s'), $text, $data["vername"]); Session::initNavigateListItems('Computer', $text); $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>"; echo "<table class='tab_cadre_fixehov'>"; $columns = array('compname' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'otherserial' => __('Inventory number'), 'location,compname' => __('Location'), 'state,compname' => __('Status'), 'groupe,compname' => __('Group'), 'username,compname' => __('User')); if (!$showEntity) { unset($columns['entity']); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; do { Session::addToNavigateListItems('Computer', $data["cID"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } $compname = $data['compname']; if (empty($compname) || $_SESSION['glpiis_ids_visible']) { $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']); } if ($canshowcomputer) { echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>"; } else { echo "<td>" . $compname . "</td>"; } if ($showEntity) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td>" . $data['otherserial'] . "</td>"; echo "<td>" . $data['location'] . "</td>"; echo "<td>" . $data['state'] . "</td>"; echo "<td>" . $data['groupe'] . "</td>"; echo "<td>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo $header_begin . $header_bottom . $header_end; echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { // Not found _e('No item found'); } } // Query Html::printAjaxPager(__('Affected computers'), $start, $number); echo "</div>\n"; }
/** * Show notepads for an item * * @param $item CommonDBTM object * @param $withtemplate integer template or basic item (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI; if (!Session::haveRight($item::$rightname, READNOTE)) { return false; } $notes = static::getAllForItem($item); $rand = mt_rand(); $canedit = Session::haveRight($item::$rightname, UPDATENOTE); $showuserlink = 0; if (User::canView()) { $showuserlink = 1; } if ($canedit) { echo "<div class='boxnote center'>"; echo "<div class='boxnoteleft'></div>"; echo "<form name='addnote_form{$rand}' id='addnote_form{$rand}' "; echo " method='post' action='" . Toolbox::getItemTypeFormURL('Notepad') . "'>"; echo Html::hidden('itemtype', array('value' => $item->getType())); echo Html::hidden('items_id', array('value' => $item->getID())); echo "<div class='boxnotecontent'>"; echo "<div class='floatleft'>"; echo "<textarea name='content' rows=5 cols=100></textarea>"; echo "</div>"; echo "</div>"; // box notecontent echo "<div class='boxnoteright'><br>"; echo Html::submit(_x('button', 'Add'), array('name' => 'add')); echo "</div>"; Html::closeForm(); echo "</div>"; // boxnote } if (count($notes)) { foreach ($notes as $note) { $id = 'note' . $note['id'] . $rand; $classtoadd = ''; if ($canedit) { $classtoadd = " pointer"; } echo "<div class='boxnote' id='view{$id}'>"; echo "<div class='boxnoteleft'>"; echo "<img class='user_picture_verysmall' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($note['picture']) . "'>"; echo "</div>"; // boxnoteleft echo "<div class='boxnotecontent'>"; echo "<div class='boxnotefloatright'>"; $username = NOT_AVAILABLE; if ($note['users_id_lastupdater']) { $username = getUserName($note['users_id_lastupdater'], $showuserlink); } $update = sprintf(__('Last update by %1$s on %2$s'), $username, Html::convDateTime($note['date_mod'])); $username = NOT_AVAILABLE; if ($note['users_id']) { $username = getUserName($note['users_id'], $showuserlink); } $create = sprintf(__('Create by %1$s on %2$s'), $username, Html::convDateTime($note['date'])); printf(__('%1$s / %2$s'), $update, $create); echo "</div>"; // floatright echo "<div class='boxnotetext {$classtoadd}' "; if ($canedit) { echo "onclick=\"" . Html::jsHide("view{$id}") . " " . Html::jsShow("edit{$id}") . "\""; } echo ">"; $content = nl2br($note['content']); if (empty($content)) { $content = NOT_AVAILABLE; } echo $content . '</div>'; // boxnotetext echo "</div>"; // boxnotecontent echo "<div class='boxnoteright'>"; if ($canedit) { Html::showSimpleForm(Toolbox::getItemTypeFormURL('Notepad'), array('purge' => 'purge'), _x('button', 'Delete permanently'), array('id' => $note['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png", '', __('Confirm the final deletion?')); } echo "</div>"; // boxnoteright echo "</div>"; // boxnote if ($canedit) { echo "<div class='boxnote starthidden' id='edit{$id}'>"; echo "<form name='update_form{$id}{$rand}' id='update_form{$id}{$rand}' "; echo " method='post' action='" . Toolbox::getItemTypeFormURL('Notepad') . "'>"; echo "<div class='boxnoteleft'></div>"; echo "<div class='boxnotecontent'>"; echo Html::hidden('id', array('value' => $note['id'])); echo "<textarea name='content' rows=5 cols=100>" . $note['content'] . "</textarea>"; echo "</div>"; // boxnotecontent echo "<div class='boxnoteright'><br>"; echo Html::submit(_x('button', 'Update'), array('name' => 'update')); echo "</div>"; // boxnoteright Html::closeForm(); echo "</div>"; // boxnote } } } return true; }
function displayReport(&$result, $PluginAddressingAddressing) { global $DB, $CFG_GLPI; $network = $PluginAddressingAddressing->fields["networks_id"]; $ping = $PluginAddressingAddressing->fields["use_ping"]; $PluginAddressingConfig = new PluginAddressingConfig(); $PluginAddressingConfig->getFromDB('1'); $system = $PluginAddressingConfig->fields["used_system"]; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } $header_num = 1; $nbcols = 6; $ping_response = 0; $parameters = "id="; $row_num = 1; echo Search::showHeader($output_type, 1, $nbcols, 1); echo $this->displaySearchNewLine($output_type); echo Search::showHeaderItem($output_type, __('IP'), $header_num); echo Search::showHeaderItem($output_type, __('Connected to'), $header_num); echo Search::showHeaderItem($output_type, _n('User', 'Users', 1), $header_num); echo Search::showHeaderItem($output_type, __('MAC address'), $header_num); echo Search::showHeaderItem($output_type, __('Item type'), $header_num); echo Search::showHeaderItem($output_type, __('Free Ip', 'addressing'), $header_num); // End Line for column headers echo Search::showEndLine($output_type); $user = new User(); foreach ($result as $num => $lines) { $ip = long2ip(substr($num, 2)); if (count($lines)) { if (count($lines) > 1) { $disp = $PluginAddressingAddressing->fields["double_ip"]; } else { $disp = $PluginAddressingAddressing->fields["alloted_ip"]; } if ($disp) { foreach ($lines as $line) { $row_num++; $item_num = 1; $name = $line["dname"]; $namep = $line["pname"]; // IP echo $this->displaySearchNewLine($output_type, count($lines) > 1 ? "double" : $row_num % 2); echo Search::showItem($output_type, $ip, $item_num, $row_num); // Device $item = new $line["itemtype"](); $link = Toolbox::getItemTypeFormURL($line["itemtype"]); if ($line["itemtype"] != 'NetworkEquipment') { if ($item->canView()) { $output_iddev = "<a href='" . $link . "?id=" . $line["on_device"] . "'>" . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "") . "</a>"; } else { $output_iddev = $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : ""); } } else { if ($item->canView()) { if (empty($namep)) { $linkp = ''; } else { $linkp = $namep . " - "; } $output_iddev = "<a href='" . $link . "?id=" . $line["on_device"] . "'>" . $linkp . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "") . "</a>"; } else { $output_iddev = $namep . " - " . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : ""); } } echo Search::showItem($output_type, $output_iddev, $item_num, $row_num); // User if ($line["users_id"] && $user->getFromDB($line["users_id"])) { $username = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); if ($user->canView()) { $output_iduser = "******" . $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $line["users_id"] . "'>" . $username . "</a>"; } else { $output_iduser = $username; } echo Search::showItem($output_type, $output_iduser, $item_num, $row_num); } else { echo Search::showItem($output_type, " ", $item_num, $row_num); } // Mac if ($line["id"]) { if ($item->canView()) { $output_mac = "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $line["id"] . "'>" . $line["mac"] . "</a>"; } else { $output_mac = $line["mac"]; } echo Search::showItem($output_type, $output_mac, $item_num, $row_num); } else { echo Search::showItem($output_type, " ", $item_num, $row_num); } // Type echo Search::showItem($output_type, $item::getTypeName(), $item_num, $row_num); // Reserved if ($PluginAddressingAddressing->fields["reserved_ip"] && strstr($line["pname"], "reserv")) { echo Search::showItem($output_type, __('Reserved Address', 'addressing'), $item_num, $row_num); } else { echo Search::showItem($output_type, " ", $item_num, $row_num); } // End echo Search::showEndLine($output_type); } } } else { if ($PluginAddressingAddressing->fields["free_ip"]) { $row_num++; $item_num = 1; if (!$ping) { echo $this->displaySearchNewLine($output_type, "free"); echo Search::showItem($output_type, $ip, $item_num, $row_num); echo Search::showItem($output_type, " ", $item_num, $row_num); } else { if ($output_type == Search::HTML_OUTPUT) { Html::glpi_flush(); } if ($this->ping($system, $ip)) { $ping_response++; echo $this->displaySearchNewLine($output_type, "ping_off"); echo Search::showItem($output_type, $ip, $item_num, $row_num); echo Search::showItem($output_type, __('Ping: got a response - used Ip', 'addressing'), $item_num, $row_num); } else { echo $this->displaySearchNewLine($output_type, "ping_on"); echo Search::showItem($output_type, $ip, $item_num, $row_num); echo Search::showItem($output_type, __('Ping: no response - free Ip', 'addressing'), $item_num, $row_num); } } echo Search::showItem($output_type, " ", $item_num, $row_num); echo Search::showItem($output_type, " ", $item_num, $row_num); echo Search::showItem($output_type, " ", $item_num, $row_num); echo Search::showItem($output_type, " ", $item_num, $row_num); echo Search::showEndLine($output_type); } } } // Display footer echo Search::showFooter($output_type, $PluginAddressingAddressing->getTitle()); return $ping_response; }
/** * Show users linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI; $searchID = $license->getField('id'); if (!Software::canView() || !$searchID) { return false; } $canedit = PluginFpsoftwareVersionhelper::checkRights("software", array(CREATE, UPDATE, DELETE, PURGE), "Or"); $canshowuser = User::canView(); if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } //SoftwareLicense ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_users_softwarelicenses`\n INNER JOIN `glpi_users`\n ON (`glpi_users_softwarelicenses`.`users_id`\n = `glpi_users`.`id`)\n WHERE `glpi_users_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'"; $number = 0; if ($result = $DB->query($query_number)) { $number = $DB->result($result, 0, 0); } echo "<div class='center'>"; if ($canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . self::$front_url . "/front/user_softwarelicense.form.php'>"; echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td>"; //FOR NOW ALL USERS ARE SHOWN, DON'T KNOW IF THERE SHOULD BE ANY RESTRICTION. //ALSO IT CAUSES A POSSIBILITY TO ONE USER MANY TIMES. User::dropdown(array('right' => 'all')); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(__('Affected users'), $start, $number); $query = "SELECT `glpi_users_softwarelicenses`.*,\n `glpi_users`.`name` AS username,\n `glpi_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\n `glpi_softwarelicenses`.`name` AS license,\n `glpi_softwarelicenses`.`id` AS lID\n FROM `glpi_users_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_users_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_users`\n ON (`glpi_users_softwarelicenses`.`users_id` = `glpi_users`.`id`)\n WHERE `glpi_softwarelicenses`.`id` = '{$searchID}'\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); list($higher_version, $massiveactionparams) = PluginFpsoftwareVersionhelper::massiveActionParams($rand, __CLASS__); // Options to update license $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID); $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id']; Html::showMassiveActions($higher_version ? $massiveactionparams : __CLASS__, $massiveactionparams); } $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]); $text = sprintf(__('%1$s - ID %2$s'), $text, $license->fields['softwares_id']); Session::initNavigateListItems('User', $text); echo "<table class='tab_cadre_fixehov'>"; $columns = array('username' => __('Username'), 'userrealname' => __('Surname'), 'userfirstname' => __('First name'), 'added' => __('Added')); $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } foreach ($columns as $key => $val) { // Non order column $header_end .= "<th>{$val}</th>"; } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; do { Session::addToNavigateListItems('User', $data["userid"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } if ($canshowuser) { echo "<td><a href='user.form.php?id=" . $data['userid'] . "'>" . $data['username'] . "</a></td>"; } else { echo "<td>" . $data['username'] . "</td>"; } echo "<td>" . $data['userrealname'] . "</td>"; echo "<td>" . $data['userfirstname'] . "</td>"; echo "<td style=\"text-align:center;\">" . $data['added'] . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo $header_begin . $header_bottom . $header_end; echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { // Not found _e('No item found'); } } // Query Html::printAjaxPager(__('Affected users'), $start, $number); echo "</div>\n"; }