Example #1
0
 static function pdfForGroup(PluginPdfSimplePDF $pdf, Group $group, $tree)
 {
     global $DB, $CFG_GLPI;
     $used = array();
     $ids = array();
     // Retrieve member list
     $entityrestrict = Group_User::getDataForGroup($group, $used, $ids, '', $tree);
     $title = "<b>" . sprintf(__('%1$s (%2$s)'), _n('User', 'Users', 2) . "</b>", __('D=Dynamic'));
     $number = count($used);
     if ($number > $_SESSION['glpilist_limit']) {
         $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . "/" . $number);
     } else {
         $title = sprintf(__('%1$s (%2$s)'), $title, $number);
     }
     $pdf->setColumnsSize(100);
     $pdf->displayTitle($title);
     if ($number) {
         $user = new User();
         $group = new Group();
         if ($tree) {
             $pdf->setColumnsSize(35, 45, 10, 10);
             $pdf->displayTitle(User::getTypeName(1), Group::getTypeName(1), __('Manager'), __('Delegatee'));
         } else {
             $pdf->setColumnsSize(60, 20, 20);
             $pdf->displayTitle(User::getTypeName(1), __('Manager'), __('Delegatee'));
         }
         for ($i = 0; $i < $number && $i < $_SESSION['glpilist_limit']; $i++) {
             $data = $used[$i];
             $name = Html::clean(getUserName($data["id"]));
             if ($data["is_dynamic"]) {
                 $name = sprintf(__('%1$s (%2$s)'), $name, '<b>' . __('D') . '</b>');
             }
             if ($tree) {
                 $group->getFromDB($data["groups_id"]);
                 $pdf->displayLine($name, $group->getName(), Dropdown::getYesNo($data['is_manager']), Dropdown::getYesNo($data['is_userdelegate']));
             } else {
                 $pdf->displayLine($name, Dropdown::getYesNo($data['is_manager']), Dropdown::getYesNo($data['is_userdelegate']));
             }
         }
     } else {
         $pdf->setColumnsAlign('center');
         $pdf->displayLine(__('No item found'));
     }
     $pdf->displaySpace();
 }
                                                    AuthLdap::importUserFromServers(array('name' => $_POST['login']));
                                                }
                                                Html::back();
                                            } else {
                                                if (isset($_POST['add_ext_auth_simple'])) {
                                                    if (isset($_POST['login']) && !empty($_POST['login'])) {
                                                        Session::checkRight("user", User::IMPORTEXTAUTHUSERS);
                                                        $input = array('name' => $_POST['login'], '_extauth' => 1, 'add' => 1);
                                                        $user->check(-1, CREATE, $input);
                                                        $newID = $user->add($input);
                                                        Event::log($newID, "users", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["login"]));
                                                    }
                                                    Html::back();
                                                } else {
                                                    Session::checkRight("user", READ);
                                                    Html::header(User::getTypeName(Session::getPluralNumber()), '', "admin", "user");
                                                    $user->display(array('id' => $_GET["id"]));
                                                    Html::footer();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #3
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     global $DB;
     if (!$withtemplate) {
         $nb = 0;
         $query_nb = "SELECT COUNT(*) as cpt\n                      FROM `" . $this->getTable() . "`\n                      LEFT JOIN glpi_users \n                        ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                      WHERE `glpi_users`.`is_deleted` = '0' ";
         switch ($item->getType()) {
             case 'Entity':
                 if (Session::haveRight('user', READ)) {
                     if ($_SESSION['glpishow_count_on_tabs']) {
                         $query_nb .= "AND entities_id = '" . $item->getID() . "'";
                         $result_nb = $DB->query($query_nb);
                         $data_nb = $DB->fetch_assoc($result_nb);
                         $nb = $data_nb['cpt'];
                     }
                     return self::createTabEntry(User::getTypeName(Session::getPluralNumber()), $nb);
                 }
                 break;
             case 'Profile':
                 if (Session::haveRight('user', READ)) {
                     if ($_SESSION['glpishow_count_on_tabs']) {
                         $query_nb .= "AND `glpi_profiles_users`.`profiles_id` = '" . $item->getID() . "'" . getEntitiesRestrictRequest('AND', 'glpi_profiles_users', 'entities_id', $_SESSION['glpiactiveentities'], true);
                         $result_nb = $DB->query($query_nb);
                         $data_nb = $DB->fetch_assoc($result_nb);
                         $nb = $data_nb['cpt'];
                     }
                     return self::createTabEntry(User::getTypeName(Session::getPluralNumber()), $nb);
                 }
                 break;
             case 'User':
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nb = countElementsInTable($this->getTable(), "users_id = '" . $item->getID() . "'");
                 }
                 return self::createTabEntry(_n('Authorization', 'Authorizations', Session::getPluralNumber()), $nb);
         }
     }
     return '';
 }
Example #4
0
 /**
  * Show items for the group
  *
  * @param $tech   boolean  false search groups_id, true, search groups_id_tech
  **/
 function showItems($tech)
 {
     global $DB, $CFG_GLPI;
     $rand = mt_rand();
     $ID = $this->fields['id'];
     if ($tech) {
         $types = $CFG_GLPI['linkgroup_tech_types'];
         $field = 'groups_id_tech';
         $title = __('Managed items');
     } else {
         $types = $CFG_GLPI['linkgroup_types'];
         $field = 'groups_id';
         $title = __('Used items');
     }
     $tree = Session::getSavedOption(__CLASS__, 'tree', 0);
     $user = Session::getSavedOption(__CLASS__, 'user', 0);
     $type = Session::getSavedOption(__CLASS__, 'onlytype', '');
     if (!in_array($type, $types)) {
         $type = '';
     }
     echo "<div class='spaced'>";
     // Mini Search engine
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'><th colspan='3'>{$title}</tr>";
     echo "<tr class='tab_bg_1'><td class='center'>";
     echo __('Type') . "&nbsp;";
     Dropdown::showItemType($types, array('value' => $type, 'name' => 'onlytype', 'plural' => true, 'on_change' => 'reloadTab("start=0&onlytype="+this.value)', 'checkright' => true));
     if ($this->haveChildren()) {
         echo "</td><td class='center'>" . __('Child groups') . "&nbsp;";
         Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
     } else {
         $tree = 0;
     }
     if ($this->getField('is_usergroup')) {
         echo "</td><td class='center'>" . User::getTypeName(Session::getPluralNumber()) . "&nbsp;";
         Dropdown::showYesNo('user', $user, -1, array('on_change' => 'reloadTab("start=0&user="******"</td></tr></table>";
     $datas = array();
     if ($type) {
         $types = array($type);
     }
     $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
     $nb = $this->getDataItems($types, $field, $tree, $user, $start, $datas);
     $nbcan = 0;
     if ($nb) {
         Html::printAjaxPager('', $start, $nb);
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         echo Html::hidden('field', array('value' => $field, 'data-glpicore-ma-tags' => 'common'));
         $massiveactionparams = array('num_displayed' => $nb, 'check_itemtype' => 'Group', 'check_items_id' => $ID, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('is_tech' => $tech, 'massive_action_fields' => array('field')), 'specific_actions' => array(__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'changegroup' => __('Move')));
         Html::showMassiveActions($massiveactionparams);
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr><th width='10'>";
         $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_end = '</th>';
         $header_end .= "<th>" . __('Type') . "</th><th>" . __('Name') . "</th><th>" . __('Entity') . "</th>";
         if ($tree || $user) {
             $header_end .= "<th>" . sprintf(__('%1$s / %2$s'), self::getTypeName(1), User::getTypeName(1)) . "</th>";
         }
         $header_end .= "</tr>";
         echo $header_begin . $header_top . $header_end;
         $tuser = new User();
         $group = new Group();
         foreach ($datas as $data) {
             if (!($item = getItemForItemtype($data['itemtype']))) {
                 continue;
             }
             echo "<tr class='tab_bg_1'><td>";
             if ($item->canEdit($data['items_id'])) {
                 Html::showMassiveActionCheckBox($data['itemtype'], $data['items_id']);
             }
             echo "</td><td>" . $item->getTypeName(1);
             echo "</td><td>" . $item->getLink(array('comments' => true));
             echo "</td><td>" . Dropdown::getDropdownName("glpi_entities", $item->getEntityID());
             if ($tree || $user) {
                 echo "</td><td>";
                 if ($grp = $item->getField($field)) {
                     if ($group->getFromDB($grp)) {
                         echo $group->getLink(array('comments' => true));
                     }
                 } else {
                     if ($usr = $item->getField(str_replace('groups', 'users', $field))) {
                         if ($tuser->getFromDB($usr)) {
                             echo $tuser->getLink(array('comments' => true));
                         }
                     }
                 }
             }
             echo "</td></tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
     } else {
         echo "<p class='center b'>" . __('No item found') . "</p>";
     }
     if ($nb) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
     }
     Html::closeForm();
     if ($nb) {
         Html::printAjaxPager('', $start, $nb);
     }
     echo "</div>";
 }
Example #5
0
 static function pdfItems(PluginPdfSimplePDF $pdf, Group $group, $tech, $tree, $user)
 {
     global $CFG_GLPI;
     if ($tech) {
         $types = $CFG_GLPI['linkgroup_tech_types'];
         $field = 'groups_id_tech';
         $title = __('Managed items');
     } else {
         $types = $CFG_GLPI['linkgroup_types'];
         $field = 'groups_id';
         $title = __('Used items');
     }
     $datas = array();
     $max = $group->getDataItems($types, $field, $tree, $user, 0, $datas);
     $nb = count($datas);
     if ($nb < $max) {
         $title = sprintf(__('%1$s (%2$s)'), $title, $nb / $max);
     } else {
         $title = sprintf(__('%1$s (%2$s)'), $title, $nb);
     }
     $pdf->setColumnsSize(100);
     $pdf->displayTitle($title);
     if ($nb) {
         if ($tree || $user) {
             $pdf->setColumnsSize(16, 20, 34, 30);
             $pdf->displayTitle(__('Type'), __('Name'), __('Entity'), Group::getTypeName(1) . " / " . User::getTypeName(1));
         } else {
             $pdf->setColumnsSize(20, 25, 55);
             $pdf->displayTitle(__('Type'), __('Name'), __('Entity'));
         }
     } else {
         $pdf->displayLine(__('No item found'));
     }
     $tmpgrp = new Group();
     $tmpusr = new User();
     foreach ($datas as $data) {
         if (!($item = getItemForItemtype($data['itemtype']))) {
             continue;
         }
         $item->getFromDB($data['items_id']);
         $col4 = '';
         if ($tree || $user) {
             if ($grp = $item->getField($field)) {
                 if ($tmpgrp->getFromDB($grp)) {
                     $col4 = $tmpgrp->getNameID();
                 }
             } else {
                 if ($usr = $item->getField(str_replace('groups', 'users', $field))) {
                     $col4 = Html::clean(getUserName($usr));
                 }
             }
         }
         $pdf->displayLine($item->getTypeName(1), $item->getName(), Html::clean(Dropdown::getDropdownName("glpi_entities", $item->getEntityID())), $col4);
     }
     $pdf->displaySpace();
 }
 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 '';
 }
Example #7
0
                                                    AuthLdap::importUserFromServers(array('name' => $_POST['login']));
                                                }
                                                Html::back();
                                            } else {
                                                if (isset($_POST['add_ext_auth_simple'])) {
                                                    if (isset($_POST['login']) && !empty($_POST['login'])) {
                                                        Session::checkRight("import_externalauth_users", "w");
                                                        $input = array('name' => $_POST['login'], '_extauth' => 1, 'add' => 1);
                                                        $user->check(-1, 'w', $input);
                                                        $newID = $user->add($input);
                                                        Event::log($newID, "users", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["login"]));
                                                    }
                                                    Html::back();
                                                } else {
                                                    Session::checkRight("user", "r");
                                                    Html::header(User::getTypeName(2), '', "admin", "user");
                                                    $user->showForm($_GET["id"]);
                                                    Html::footer();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**  Show groups of a user
  *
  * @param $user the user
  **/
 static function showForUser(User $user)
 {
     global $CFG_GLPI, $LANG;
     $ID = $user->fields['id'];
     if (!haveRight("group", "r") || !$user->can($ID, 'r')) {
         return false;
     }
     $canedit = $user->can($ID, 'w');
     $rand = mt_rand();
     $nb_per_line = 3;
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
         echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'";
         echo " action='" . getItemTypeFormURL('User') . "'>";
     } else {
         $headerspan = $nb_per_line;
     }
     $groups = self::getUserGroups($ID);
     $used = array();
     if (!empty($groups)) {
         foreach ($groups as $data) {
             $used[$data["id"]] = $data["id"];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['setup'][604] . "</th></tr>";
         echo "<tr><td class='tab_bg_2 center'>";
         echo "<input type='hidden' name='users_id' value='{$ID}'>";
         // All entities "edited user" have access
         $strict_entities = Profile_User::getUserEntities($ID, true);
         // Keep only entities "connected user" have access
         foreach ($strict_entities as $key => $val) {
             if (!haveAccessToEntity($val)) {
                 unset($strict_entities[$key]);
             }
         }
         if (countElementsInTableForEntity("glpi_groups", $strict_entities) > count($used)) {
             Dropdown::show('Group', array('entity' => $strict_entities, 'used' => $used));
             echo "</td><td class='tab_bg_2 center'>";
             echo "<input type='submit' name='addgroup' value=\"" . $LANG['buttons'][8] . "\"\n                   class='submit'>";
         } else {
             echo $LANG['common'][49];
         }
         echo "</td></tr>";
         echo "</table></div>";
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixehov'><tr>";
     echo "<th colspan='{$headerspan}'>" . $LANG['Menu'][36] . "&nbsp;(D=" . $LANG['profiles'][29] . ")</th>";
     echo "</tr>";
     if (!empty($groups)) {
         initNavigateListItems('Group', $user->getTypeName() . " = " . $user->getName());
         $i = 0;
         foreach ($groups as $data) {
             addToNavigateListItems('Group', $data["id"]);
             if ($i % $nb_per_line == 0) {
                 if ($i != 0) {
                     echo "</tr>";
                 }
                 echo "<tr class='tab_bg_1'>";
             }
             if ($canedit) {
                 echo "<td width='10'>";
                 $sel = "";
                 if (isset($_GET["select"]) && $_GET["select"] == "all") {
                     $sel = "checked";
                 }
                 echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1' {$sel}>";
                 echo "</td>";
             }
             echo "<td><a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $data["name"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : "") . "</a>";
             echo "&nbsp;";
             if ($data["is_dynamic"]) {
                 echo "<strong>&nbsp;(D)</strong>";
             }
             echo "</td>";
             $i++;
         }
         while ($i % $nb_per_line != 0) {
             if ($canedit) {
                 echo "<td>&nbsp;</td>";
             }
             echo "<td>&nbsp;</td>";
             $i++;
         }
         echo "</tr>";
     } else {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='{$headerspan}' class='center'>" . $LANG['common'][49] . "</td></tr>";
     }
     echo "</table>";
     if ($canedit) {
         if (count($used)) {
             openArrowMassive("groupuser_form{$rand}", true);
             closeArrowMassive('deletegroup', $LANG['buttons'][6]);
         }
         echo "</form>";
     }
     echo "</div>";
 }
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'SoftwareLicense':
             if (!$withtemplate) {
                 $nb = 0;
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nb = self::countForLicense($item->getID());
                 }
                 return array(1 => self::createTabEntry(User::getTypeName(2), $nb));
             }
             break;
     }
     return '';
 }
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($withtemplate || !self::isSoftwareTabActive($item)) {
         return '';
     }
     $recordsCount = $_SESSION['glpishow_count_on_tabs'] ? self::countLicenses($item) : 0;
     return self::createTabEntry(SoftwareLicense::getTypeName(2) . ' - ' . User::getTypeName(2), $recordsCount);
 }
Example #11
0
 /**
  * Add consumable to cart
  * 
  * @param type $params
  * @return array
  */
 function addToCart($params)
 {
     list($success, $message) = $this->checkMandatoryFields($params);
     $result = array('success' => $success, 'message' => $message, 'rowId' => mt_rand(), 'fields' => array('requesters_id' => array('label' => getUserName(Session::getLoginUserID()), 'value' => Session::getLoginUserID()), 'consumableitemtypes_id' => array('label' => Dropdown::getDropdownName("glpi_consumableitemtypes", $params['consumableitemtypes_id']), 'value' => $params['consumableitemtypes_id']), 'consumables_id' => array('label' => Dropdown::getDropdownName("glpi_consumableitems", $params['consumables_id']), 'value' => $params['consumables_id']), 'number' => array('label' => $params['number'], 'value' => $params['number']), 'give_items_id' => array('label' => getUserName(Session::getLoginUserID()), 'value' => Session::getLoginUserID()), 'give_itemtype' => array('label' => User::getTypeName(), 'value' => "User", 'hidden' => 1)));
     // Give to
     if (!empty($params['give_itemtype'])) {
         $give_item = getItemForItemtype($params['give_itemtype']);
         $result['fields']['give_itemtype'] = array('label' => $give_item::getTypeName(), 'value' => $params['give_itemtype'], 'hidden' => 1);
         $result['fields']['give_items_id'] = array('label' => Dropdown::getDropdownName($give_item->getTable(), $params['give_items_id']), 'value' => $params['give_items_id']);
     }
     return $result;
 }