Beispiel #1
0
/**
 * @param $type
 * @param $id
 * @param $data
 * @param $num
**/
function plugin_ocsinventoryng_giveItem($type, $id, $data, $num)
{
    global $CFG_GLPI, $DB;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$id]["table"];
    $field = $searchopt[$id]["field"];
    switch ("{$table}.{$field}") {
        case "glpi_plugin_ocsinventoryng_details.action":
            $detail = new PluginOcsinventoryngDetail();
            return $detail->giveActionNameByActionID($data["ITEM_{$num}"]);
        case "glpi_plugin_ocsinventoryng_details.computers_id":
            $comp = new Computer();
            $comp->getFromDB($data["ITEM_{$num}"]);
            return "<a href='" . Toolbox::getItemTypeFormURL('Computer') . "?id=" . $data["ITEM_{$num}"] . "'>" . $comp->getName() . "</a>";
        case "glpi_plugin_ocsinventoryng_details.plugin_ocsinventoryng_ocsservers_id":
            $ocs = new PluginOcsinventoryngOcsServer();
            $ocs->getFromDB($data["ITEM_{$num}"]);
            return "<a href='" . Toolbox::getItemTypeFormURL('PluginOcsinventoryngOcsServer') . "?id=" . $data["ITEM_{$num}"] . "'>" . $ocs->getName() . "</a>";
        case "glpi_plugin_ocsinventoryng_details.rules_id":
            $detail = new PluginOcsinventoryngDetail();
            $detail->getFromDB($data['id']);
            return PluginOcsinventoryngNotimportedcomputer::getRuleMatchedMessage($detail->fields['rules_id']);
        case "glpi_plugin_ocsinventoryng_notimportedcomputers.reason":
            return PluginOcsinventoryngNotimportedcomputer::getReason($data["ITEM_{$num}"]);
    }
    return '';
}
Beispiel #2
0
 /**
  * Show profile form
  *
  * @param $items_id integer id of the profile
  * @param $target value url of target
  *
  * @return nothing
  **/
 function showForm($profiles_id = 0, $openform = TRUE, $closeform = TRUE)
 {
     global $DB, $CFG_GLPI;
     $profile = new Profile();
     $profile->getFromDB($profiles_id);
     echo "<div class='firstbloc'>";
     if (($canedit = Session::haveRightsOr(self::$rightname, array(CREATE, UPDATE, PURGE))) && $openform) {
         echo "<form action='" . $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/profile.form.php' method='post'>";
     }
     //Delegating
     $effective_rights = ProfileRight::getProfileRights($profiles_id, array('plugin_ocsinventoryng'));
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='4' class='center b'>" . sprintf(__('%1$s - %2$s'), 'OcsinventoryNG', $profile->fields["name"]) . "</th>";
     echo "</tr>";
     $used = array();
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . sprintf(__('%1$s : %2$s'), _n('Allowed OCSNG server', 'Allowed OCSNG servers', 2, 'ocsinventoryng'), "&nbsp;");
     //$profile = $this->fields['id'];
     $crit = array('profiles_id' => $profiles_id);
     foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers_profiles", $crit) as $data) {
         $used[$data['plugin_ocsinventoryng_ocsservers_id']] = $data['plugin_ocsinventoryng_ocsservers_id'];
         $configid[$data['plugin_ocsinventoryng_ocsservers_id']] = $data['id'];
     }
     if (Session::haveRight("profile", UPDATE)) {
         Dropdown::show('PluginOcsinventoryngOcsServer', array('width' => '50%', 'used' => $used, 'value' => '', 'condition' => "is_active = 1"));
         echo "&nbsp;&nbsp;<input type='hidden' name='profile' value='{$profiles_id}'>";
         echo "&nbsp;&nbsp;<input type='submit' name='addocsserver' value=\"" . _sx('button', 'Add') . "\" class='submit' >";
     }
     echo "</td><td>";
     echo "<table width='100%'><tr class='tab_bg_1'><td>";
     $nbservers = countElementsInTable('glpi_plugin_ocsinventoryng_ocsservers_profiles', "`profiles_id` = " . $profiles_id);
     $query = "SELECT `glpi_plugin_ocsinventoryng_ocsservers`.`id`,\n                       `glpi_plugin_ocsinventoryng_ocsservers`.`name`\n                FROM `glpi_plugin_ocsinventoryng_ocsservers_profiles`\n                LEFT JOIN `glpi_plugin_ocsinventoryng_ocsservers`\n                   ON `glpi_plugin_ocsinventoryng_ocsservers_profiles`.`plugin_ocsinventoryng_ocsservers_id` = `glpi_plugin_ocsinventoryng_ocsservers`.`id`\n                WHERE `profiles_id`= " . $_SESSION["glpiactiveprofile"]['id'] . "\n                ORDER BY `name` ASC";
     $result = $DB->query($query);
     if ($data = $DB->fetch_assoc($result)) {
         $ocsserver = new PluginOcsinventoryngOcsServer();
         foreach ($used as $id) {
             if ($ocsserver->getFromDB($id)) {
                 echo "<br>";
                 if (Session::haveRight("profile", UPDATE)) {
                     echo "<input type='checkbox' name='item[" . $configid[$id] . "]' value='1'>";
                 }
                 if ($data['id'] == $id) {
                     echo $ocsserver->getLink();
                 } else {
                     echo $ocsserver->getName();
                 }
             }
         }
     }
     if (!$nbservers) {
         _e('None');
     }
     echo "</td></tr>";
     if ($nbservers && Session::haveRight("profile", UPDATE)) {
         echo "<tr class='tab_bg_1 center'><td>";
         echo "<input type='submit' name='delete' value='Supprimer' class='submit' >";
         echo "</td></tr>";
     }
     echo "</table>";
     echo "</td></tr>";
     echo "</table>";
     Html::closeForm();
     if (($canedit = Session::haveRightsOr(self::$rightname, array(CREATE, UPDATE, PURGE))) && $openform) {
         echo "<form method='post' action='" . $profile->getFormURL() . "'>";
     }
     $rights = $this->getAllRights();
     $profile->displayRightsChoiceMatrix($rights, array('canedit' => $canedit, 'default_class' => 'tab_bg_2', 'title' => __('General')));
     if ($canedit && $closeform) {
         echo "<div class='center'>";
         echo Html::hidden('id', array('value' => $profiles_id));
         echo Html::submit(_sx('button', 'Save'), array('name' => 'update'));
         echo "</div>\n";
         Html::closeForm();
     }
     echo "</div>";
 }