Beispiel #1
0
    include '../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkLoginUser();
if (isset($_POST['type']) && !empty($_POST['type']) && isset($_POST['items_id']) && $_POST['items_id'] > 0) {
    $prefix = '';
    $suffix = '';
    if (isset($_POST['prefix']) && !empty($_POST['prefix'])) {
        $prefix = $_POST['prefix'] . '[';
        $suffix = ']';
    }
    switch ($_POST['type']) {
        case 'Group':
        case 'Profile':
            $params = array('value' => $_SESSION['glpiactive_entity'], 'name' => $prefix . 'entities_id' . $suffix);
            if (Session::isViewAllEntities()) {
                $params['toadd'] = array(-1 => __('No restriction'));
            }
            echo "<table class='tab_format'><tr><td>";
            _e('Entity');
            echo "</td><td>";
            Entity::dropdown($params);
            echo "</td><td>";
            _e('Child entities');
            echo "</td><td>";
            Dropdown::showYesNo($prefix . 'is_recursive' . $suffix);
            echo "</td></tr></table>";
            break;
    }
}
Beispiel #2
0
 function pre_deleteItem()
 {
     global $DB;
     $entities = Profile_User::getUserEntities($this->fields["id"]);
     $view_all = Session::isViewAllEntities();
     // Have right on all entities ?
     $all = true;
     if (!$view_all) {
         foreach ($entities as $ent) {
             if (!Session::haveAccessToEntity($ent)) {
                 $all = false;
             }
         }
     }
     if ($all) {
         // Mark as deleted
         return true;
     }
     // only delete profile
     foreach ($entities as $ent) {
         if (Session::haveAccessToEntity($ent)) {
             $all = false;
             $query = "DELETE\n                      FROM `glpi_profiles_users`\n                      WHERE `users_id` = '" . $this->fields["id"] . "'\n                            AND `entities_id` = '{$ent}'";
             $DB->query($query);
         }
         return false;
     }
 }
Beispiel #3
0
 /**
  * Generic Function to add default where to a request
  *
  * @param $itemtype device type
  *
  * @return select string
  **/
 static function addDefaultWhere($itemtype)
 {
     global $CFG_GLPI;
     switch ($itemtype) {
         case 'Reminder':
             return Reminder::addVisibilityRestrict();
         case 'RSSFeed':
             return RSSFeed::addVisibilityRestrict();
         case 'Notification':
             if (!Config::canView()) {
                 return " `glpi_notifications`.`itemtype` NOT IN ('Crontask', 'DBConnection') ";
             }
             break;
             // No link
         // No link
         case 'User':
             // View all entities
             if (Session::isViewAllEntities()) {
                 return "";
             }
             return getEntitiesRestrictRequest("", "glpi_profiles_users");
         case 'ProjectTask':
             $condition = '';
             $teamtable = 'glpi_projecttaskteams';
             $condition .= "((`{$teamtable}`.`itemtype` = 'User'\n                             AND `{$teamtable}`.`items_id` = '" . Session::getLoginUserID() . "')";
             if (count($_SESSION['glpigroups'])) {
                 $condition .= " OR (`{$teamtable}`.`itemtype` = 'Group'\n                                    AND `{$teamtable}`.`items_id`\n                                       IN (" . implode(",", $_SESSION['glpigroups']) . "))";
             }
             $condition .= ") ";
             return $condition;
         case 'Project':
             $condition = '';
             if (!Session::haveRight("project", Project::READALL)) {
                 $teamtable = 'glpi_projectteams';
                 $condition .= "(`glpi_projects`.users_id = '" . Session::getLoginUserID() . "'\n                               OR (`{$teamtable}`.`itemtype` = 'User'\n                                   AND `{$teamtable}`.`items_id` = '" . Session::getLoginUserID() . "')";
                 if (count($_SESSION['glpigroups'])) {
                     $condition .= " OR (`glpi_projects`.`groups_id`\n                                       IN (" . implode(",", $_SESSION['glpigroups']) . "))";
                     $condition .= " OR (`{$teamtable}`.`itemtype` = 'Group'\n                                      AND `{$teamtable}`.`items_id`\n                                          IN (" . implode(",", $_SESSION['glpigroups']) . "))";
                 }
                 $condition .= ") ";
             }
             return $condition;
         case 'Ticket':
             // Same structure in addDefaultJoin
             $condition = '';
             if (!Session::haveRight("ticket", Ticket::READALL)) {
                 $searchopt =& self::getOptions($itemtype);
                 $requester_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[4]['joinparams']['beforejoin']['joinparams']) . '`';
                 $requestergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[71]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assign_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[5]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assigngroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[8]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observer_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[66]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[65]['joinparams']['beforejoin']['joinparams']) . '`';
                 $condition = "(";
                 if (Session::haveRight("ticket", Ticket::READMY)) {
                     $condition .= " {$requester_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR {$observer_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR `glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'";
                 } else {
                     $condition .= "0=1";
                 }
                 if (Session::haveRight("ticket", Ticket::READGROUP)) {
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$requestergroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                         $condition .= " OR {$observergroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                     }
                 }
                 if (Session::haveRight("ticket", Ticket::OWN)) {
                     // Can own ticket : show assign to me
                     $condition .= " OR {$assign_table}.users_id = '" . Session::getLoginUserID() . "' ";
                 }
                 if (Session::haveRight("ticket", Ticket::READASSIGN)) {
                     // assign to me
                     $condition .= " OR {$assign_table}.`users_id` = '" . Session::getLoginUserID() . "'";
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$assigngroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                     }
                     if (Session::haveRight('ticket', Ticket::ASSIGN)) {
                         $condition .= " OR `glpi_tickets`.`status`='" . CommonITILObject::INCOMING . "'";
                     }
                 }
                 if (Session::haveRightsOr('ticketvalidation', array(TicketValidation::VALIDATEINCIDENT, TicketValidation::VALIDATEREQUEST))) {
                     $condition .= " OR `glpi_ticketvalidations`.`users_id_validate`\n                                          = '" . Session::getLoginUserID() . "'";
                 }
                 $condition .= ") ";
             }
             return $condition;
         case 'Change':
         case 'Problem':
             if ($itemtype == 'Change') {
                 $right = 'change';
                 $table = 'changes';
                 $groupetable = "`glpi_changes_groups_";
             } else {
                 if ($itemtype == 'Problem') {
                     $right = 'problem';
                     $table = 'problems';
                     $groupetable = "`glpi_groups_problems";
                 }
             }
             // Same structure in addDefaultJoin
             $condition = '';
             if (!Session::haveRight("{$right}", $itemtype::READALL)) {
                 $searchopt =& self::getOptions($itemtype);
                 if (Session::haveRight("{$right}", $itemtype::READMY)) {
                     $requester_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[4]['joinparams']['beforejoin']['joinparams']) . '`';
                     $requestergroup_table = $groupetable . self::computeComplexJoinID($searchopt[71]['joinparams']['beforejoin']['joinparams']) . '`';
                     $observer_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[66]['joinparams']['beforejoin']['joinparams']) . '`';
                     $observergroup_table = $groupetable . self::computeComplexJoinID($searchopt[65]['joinparams']['beforejoin']['joinparams']) . '`';
                     $assign_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[5]['joinparams']['beforejoin']['joinparams']) . '`';
                     $assigngroup_table = $groupetable . self::computeComplexJoinID($searchopt[8]['joinparams']['beforejoin']['joinparams']) . '`';
                 }
                 $condition = "(";
                 if (Session::haveRight("{$right}", $itemtype::READMY)) {
                     $condition .= " {$requester_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR {$observer_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR `glpi_" . $table . "`.`users_id_recipient` = '" . Session::getLoginUserID() . "'";
                 } else {
                     $condition .= "0=1";
                 }
                 $condition .= ") ";
             }
             return $condition;
         default:
             // Plugin can override core definition for its type
             if ($plug = isPluginItemType($itemtype)) {
                 $function = 'plugin_' . $plug['plugin'] . '_addDefaultWhere';
                 if (function_exists($function)) {
                     $out = $function($itemtype);
                     if (!empty($out)) {
                         return $out;
                     }
                 }
             }
             return "";
     }
 }
Beispiel #4
0
 /**
  * Show rights of a user
  *
  * @param $user User object
  **/
 static function showForUser(User $user)
 {
     global $DB, $CFG_GLPI;
     $ID = $user->getField('id');
     if (!$user->can($ID, READ)) {
         return false;
     }
     $canedit = $user->canEdit($ID);
     $strict_entities = self::getUserEntities($ID, false);
     if (!Session::haveAccessToOneOfEntities($strict_entities) && !Session::isViewAllEntities()) {
         $canedit = false;
     }
     $canshowentity = Entity::canView();
     $rand = mt_rand();
     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_2'><td class='center'>";
         echo "<input type='hidden' name='users_id' value='{$ID}'>";
         Entity::dropdown(array('entity' => $_SESSION['glpiactiveentities']));
         echo "</td><td class='center'>" . self::getTypeName(1) . "</td><td>";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='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_users`.`id` AS linkID,\n                       `glpi_profiles`.`id`,\n                       `glpi_profiles`.`name`,\n                       `glpi_profiles_users`.`is_recursive`,\n                       `glpi_profiles_users`.`is_dynamic`,\n                       `glpi_entities`.`completename`,\n                       `glpi_profiles_users`.`entities_id`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_profiles_users`.`entities_id` = `glpi_entities`.`id`)\n                WHERE `glpi_profiles_users`.`users_id` = '{$ID}'\n                ORDER BY `glpi_profiles`.`name`, `glpi_entities`.`completename`";
     $result = $DB->query($query);
     $num = $DB->numrows($result);
     echo "<div class='spaced'>";
     Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     if ($canedit && $num) {
         $massiveactionparams = array('num_displayed' => $num, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     if ($num > 0) {
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_begin .= "<th>";
             $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . _n('Entity', 'Entities', Session::getPluralNumber()) . "</th>";
         $header_end .= "<th>" . sprintf(__('%1$s (%2$s)'), self::getTypeName(Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
         $header_end .= "</th></tr>";
         echo $header_begin . $header_top . $header_end;
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 if (in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
                     Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 } else {
                     echo "&nbsp;";
                 }
                 echo "</td>";
             }
             echo "<td>";
             $link = $data["completename"];
             if ($_SESSION["glpiis_ids_visible"]) {
                 $link = sprintf(__('%1$s (%2$s)'), $link, $data["entities_id"]);
             }
             if ($canshowentity) {
                 echo "<a href='" . Toolbox::getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
             }
             echo $link . ($canshowentity ? "</a>" : '');
             echo "</td>";
             if (Profile::canView()) {
                 $entname = "<a href='" . Toolbox::getItemTypeFormURL('Profile') . "?id=" . $data["id"] . "'>" . $data["name"] . "</a>";
             } else {
                 $entname = $data["name"];
             }
             if ($data["is_dynamic"] || $data["is_recursive"]) {
                 $entname = sprintf(__('%1$s %2$s'), $entname, "<span class='b'>(");
                 if ($data["is_dynamic"]) {
                     //TRANS: letter 'D' for Dynamic
                     $entname = sprintf(__('%1$s%2$s'), $entname, __('D'));
                 }
                 if ($data["is_dynamic"] && $data["is_recursive"]) {
                     $entname = sprintf(__('%1$s%2$s'), $entname, ", ");
                 }
                 if ($data["is_recursive"]) {
                     //TRANS: letter 'R' for Recursive
                     $entname = sprintf(__('%1$s%2$s'), $entname, __('R'));
                 }
                 $entname = sprintf(__('%1$s%2$s'), $entname, ")</span>");
             }
             echo "<td>" . $entname . "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
     } else {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No item found') . "</th></tr>";
         echo "</table>\n";
     }
     if ($canedit && $num) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
     }
     Html::closeForm();
     echo "</div>";
 }
Beispiel #5
0
This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
if (isset($_POST['reinit_network'])) {
    if (Session::haveRight('internet', 'w') && Session::isViewAllEntities()) {
        IPNetwork::recreateTree();
        Session::addMessageAfterRedirect(__('Successfully recreated network tree'));
        Html::back();
    } else {
        Html::displayRightError();
    }
}
$dropdown = new IPNetwork();
include GLPI_ROOT . "/front/dropdown.common.form.php";
Beispiel #6
0
 /**
  * Override title function to display the link to reinitialisation of the network tree
  **/
 function title()
 {
     parent::title();
     if (Session::haveRight('internet', UPDATE) && Session::isViewAllEntities()) {
         echo "<div class='spaced' id='tabsbody'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><td class='center'>";
         Html::showSimpleForm(IPNetwork::getFormURL(), 'reinit_network', __('Reinit the network topology'));
         echo "</td></tr>";
         echo "</table>";
         echo "</div>";
     }
 }
Beispiel #7
0
 /**
  * Generic Function to add default where to a request
  *
  * @param $itemtype device type
  *
  * @return select string
  **/
 static function addDefaultWhere($itemtype)
 {
     global $CFG_GLPI;
     switch ($itemtype) {
         case 'Reminder':
             return Reminder::addVisibilityRestrict();
         case 'RSSFeed':
             return RSSFeed::addVisibilityRestrict();
         case 'Notification':
             if (!Session::haveRight('config', CREATE)) {
                 return " `glpi_notifications`.`itemtype` NOT IN ('Crontask', 'DBConnection') ";
             }
             break;
             // No link
         // No link
         case 'User':
             // View all entities
             if (Session::isViewAllEntities()) {
                 return "";
             }
             return getEntitiesRestrictRequest("", "glpi_profiles_users");
         case 'Ticket':
             // Same structure in addDefaultJoin
             $condition = '';
             // if (!Session::haveRight("show_all_ticket","1")) {
             if (!Session::haveRight("ticket", Ticket::READALL)) {
                 $searchopt =& self::getOptions($itemtype);
                 $requester_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[4]['joinparams']['beforejoin']['joinparams']) . '`';
                 $requestergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[71]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assign_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[5]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assigngroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[8]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observer_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[66]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[65]['joinparams']['beforejoin']['joinparams']) . '`';
                 $condition = "(";
                 $condition .= " {$requester_table}.users_id = '" . Session::getLoginUserID() . "'\n                              OR {$observer_table}.users_id = '" . Session::getLoginUserID() . "'\n                              OR `glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "' ";
                 if (Session::haveRight("show_group_ticket", 1)) {
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$requestergroup_table}.`groups_id`\n                                             IN ('" . implode("','", $_SESSION['glpigroups']) . "')";
                         $condition .= " OR {$observergroup_table}.`groups_id`\n                                             IN ('" . implode("','", $_SESSION['glpigroups']) . "')";
                     }
                 }
                 if (Session::haveRight("own_ticket", "1")) {
                     // Can own ticket : show assign to me
                     $condition .= " OR {$assign_table}.users_id = '" . Session::getLoginUserID() . "' ";
                 }
                 if (Session::haveRight("show_assign_ticket", "1")) {
                     // show mine + assign to me
                     $condition .= " OR {$assign_table}.`users_id` = '" . Session::getLoginUserID() . "'";
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$assigngroup_table}.`groups_id`\n                                             IN ('" . implode("','", $_SESSION['glpigroups']) . "')";
                     }
                     if (Session::haveRight('assign_ticket', 1)) {
                         $condition .= " OR `glpi_tickets`.`status`='" . CommonITILObject::INCOMING . "'";
                     }
                 }
                 if (Session::haveRight('validate_incident', 1) || Session::haveRight('validate_request', 1)) {
                     $condition .= " OR `glpi_ticketvalidations`.`users_id_validate`\n                                          = '" . Session::getLoginUserID() . "'";
                 }
                 $condition .= ") ";
             }
             return $condition;
         default:
             // Plugin can override core definition for its type
             if ($plug = isPluginItemType($itemtype)) {
                 $function = 'plugin_' . $plug['plugin'] . '_addDefaultWhere';
                 if (function_exists($function)) {
                     $out = $function($itemtype);
                     if (!empty($out)) {
                         return $out;
                     }
                 }
             }
             return "";
     }
 }