Example #1
0
 public function submit($problem_id)
 {
     try {
         $problem = new Problem($problem_id);
         $language = fRequest::get('language', 'integer');
         if (!array_key_exists($language, static::$languages)) {
             throw new fValidationException('Invalid language.');
         }
         fSession::set('last_language', $language);
         $code = trim(fRequest::get('code', 'string'));
         if (strlen($code) == 0) {
             throw new fValidationException('Code cannot be empty.');
         }
         if ($problem->isSecretNow()) {
             if (!User::can('view-any-problem')) {
                 throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.');
             }
         }
         $record = new Record();
         $record->setOwner(fAuthorization::getUserToken());
         $record->setProblemId($problem->getId());
         $record->setSubmitCode($code);
         $record->setCodeLanguage($language);
         $record->setSubmitDatetime(Util::currentTime());
         $record->setJudgeStatus(JudgeStatus::PENDING);
         $record->setJudgeMessage('Judging... PROB=' . $problem->getId() . ' LANG=' . static::$languages[$language]);
         $record->setVerdict(Verdict::UNKNOWN);
         $record->store();
         Util::redirect('/status');
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
         fMessaging::create('code', '/submit', fRequest::get('code', 'string'));
         Util::redirect("/submit?problem={$problem_id}");
     }
 }
Example #2
0
 public function homework()
 {
     if (fAuthorization::checkLoggedIn()) {
         $this->cache_control('private', 5);
     } else {
         $this->cache_control('private', 10);
     }
     $conditions = array('title~' => array('homework', '作业'));
     if (!User::can('view-any-report')) {
         $conditions['visible='] = TRUE;
     }
     $this->reports = fRecordSet::build('Report', $conditions, array('id' => 'desc'));
     $this->nav_class = 'homework';
     $this->render('report/homework');
 }
Example #3
0
 function run()
 {
     $this->events->add_filter('admin_menus', function ($menus) {
         if (User::can($this->privilege)) {
             $menus[$this->namespace] = array(array('title' => $this->label, 'href' => '#', 'disable' => true, 'icon' => $this->menu_icon), array('title' => $this->posts_list_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'list'))), array('title' => $this->new_post_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'new'))));
             if ($this->comment_enabled === TRUE) {
                 $menus[$this->namespace][] = array('title' => $this->post_comment_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'comments')));
             }
             foreach (force_array($this->query->get_defined_taxonomies()) as $taxonomy) {
                 $menus[$this->namespace][] = array('title' => riake('taxonomy-list-label', $taxonomy, sprintf(__('%s list'), riake('namespace', $taxonomy))), 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'taxonomy', riake('namespace', $taxonomy), 'list')));
                 $menus[$this->namespace][] = array('title' => riake('new-taxonomy-label', $taxonomy, sprintf(__('New %s'), riake('namespace', $taxonomy))), 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'taxonomy', riake('namespace', $taxonomy), 'new')));
             }
         }
         return $menus;
     });
 }
Example #4
0
 public function show($id)
 {
     if (fAuthorization::checkLoggedIn()) {
         $this->cache_control('private', 30);
     } else {
         $this->cache_control('private', 60);
     }
     try {
         $this->problem = new Problem($id);
         if ($this->problem->isSecretNow()) {
             if (!User::can('view-any-problem')) {
                 throw new fAuthorizationException('Problem is secret now.');
             }
         }
         $this->nav_class = 'problems';
         $this->render('problem/show');
     } catch (fExpectedException $e) {
         fMessaging::create('warning', $e->getMessage());
         fURL::redirect(Util::getReferer());
     } catch (fUnexpectedException $e) {
         fMessaging::create('error', $e->getMessage());
         fURL::redirect(Util::getReferer());
     }
 }
 /**
  * Show rights of a user
  *
  * @param $user User object
  **/
 static function showForUser(User $user)
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $user->getField('id');
     if (!$user->can($ID, 'r')) {
         return false;
     }
     $canedit = $user->can($ID, 'w');
     $strict_entities = self::getUserEntities($ID, false);
     if (!haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
         $canedit = false;
     }
     $canshowentity = haveRight("entity", "r");
     $rand = mt_rand();
     echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
     echo getItemTypeFormURL(__CLASS__) . "'>";
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['setup'][605] . "</tr>";
         echo "<tr class='tab_bg_2'><td class='center'>";
         echo "<input type='hidden' name='users_id' value='{$ID}'>";
         Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities']));
         echo "</td><td class='center'>" . $LANG['profiles'][22] . "&nbsp;: ";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td class='center'>" . $LANG['profiles'][28] . "&nbsp;: ";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
     }
     echo "<div class='spaced'><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='2'>" . $LANG['Menu'][37] . "</th>";
     echo "<th>" . $LANG['profiles'][22] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")";
     echo "</th></tr>";
     $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);
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_array($result)) {
             echo "<tr class='tab_bg_1'>";
             echo "<td width='10'>";
             if ($canedit && in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
                 echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>";
             } else {
                 echo "&nbsp;";
             }
             echo "</td>";
             if ($data["entities_id"] == 0) {
                 $data["completename"] = $LANG['entity'][2];
             }
             echo "<td>";
             if ($canshowentity) {
                 echo "<a href='" . getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
             }
             echo $data["completename"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["entities_id"] . ")" : "");
             if ($canshowentity) {
                 echo "</a>";
             }
             echo "</td>";
             echo "<td>" . $data["name"];
             if ($data["is_dynamic"] || $data["is_recursive"]) {
                 echo "<strong>&nbsp;(";
                 if ($data["is_dynamic"]) {
                     echo "D";
                 }
                 if ($data["is_dynamic"] && $data["is_recursive"]) {
                     echo ", ";
                 }
                 if ($data["is_recursive"]) {
                     echo "R";
                 }
                 echo ")</strong>";
             }
             echo "</td>";
         }
         echo "</tr>";
     }
     echo "</table>";
     if ($canedit) {
         openArrowMassive("entityuser_form{$rand}", true);
         closeArrowMassive('delete', $LANG['buttons'][6]);
     }
     echo "</form></div>";
 }
 /**
  * @param $user
  **/
 static function showAddEmailButton(User $user)
 {
     $users_id = $user->getID();
     if (!$user->can($users_id, READ) && $users_id != Session::getLoginUserID()) {
         return false;
     }
     $canedit = $user->can($users_id, UPDATE) || $users_id == Session::getLoginUserID();
     parent::showAddChildButtonForItemForm($user, '_useremails', $canedit);
     return;
 }
Example #7
0
    $_POST["start"] = 0;
}
if (!isset($_POST["sort"])) {
    $_POST["sort"] = "";
}
if (!isset($_POST["order"])) {
    $_POST["order"] = "";
}
if (empty($_POST["id"]) && isset($_POST["name"])) {
    $user->getFromDBbyName($_POST["name"]);
    glpi_header($CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $user->fields['id']);
}
if (empty($_POST["name"])) {
    $_POST["name"] = "";
}
if ($_POST["id"] > 0 && $user->can($_POST["id"], 'r')) {
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            Profile_User::showForUser($user);
            Group_User::showForUser($user);
            $config = new Config();
            $user->computePreferences();
            $config->showFormUserPrefs($user->fields);
            $user->showItems();
            Reservation::showForUser($_POST["id"]);
            Ticket::showListForUser($_POST["id"]);
            Plugin::displayAction($user, $_REQUEST['glpi_tab']);
            break;
        case 2:
            $user->showItems();
            break;
Example #8
0
 /**
  * @param int $image_id
  * @param User $user
  * @param string $comment
  * @throws CommentPostingException
  */
 private function comment_checks($image_id, User $user, $comment)
 {
     global $config, $page;
     // basic sanity checks
     if (!$user->can("create_comment")) {
         throw new CommentPostingException("Anonymous posting has been disabled");
     } else {
         if (is_null(Image::by_id($image_id))) {
             throw new CommentPostingException("The image does not exist");
         } else {
             if (trim($comment) == "") {
                 throw new CommentPostingException("Comments need text...");
             } else {
                 if (strlen($comment) > 9000) {
                     throw new CommentPostingException("Comment too long~");
                 } else {
                     if (strlen($comment) / strlen(gzcompress($comment)) > 10) {
                         throw new CommentPostingException("Comment too repetitive~");
                     } else {
                         if ($user->is_anonymous() && !$this->hash_match()) {
                             $page->add_cookie("nocache", "Anonymous Commenter", time() + 60 * 60 * 24, "/");
                             throw new CommentPostingException("Comment submission form is out of date; refresh the " . "comment form to show you aren't a spammer~");
                         } else {
                             if ($this->is_comment_limit_hit()) {
                                 throw new CommentPostingException("You've posted several comments recently; wait a minute and try again...");
                             } else {
                                 if ($this->is_dupe($image_id, $comment)) {
                                     throw new CommentPostingException("Someone already made that comment on that image -- try and be more original?");
                                 } else {
                                     if ($config->get_bool('comment_captcha') && !captcha_check()) {
                                         throw new CommentPostingException("Error in captcha");
                                     } else {
                                         if ($user->is_anonymous() && $this->is_spam_akismet($comment)) {
                                             throw new CommentPostingException("Akismet thinks that your comment is spam. Try rewriting the comment, or logging in.");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #9
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>";
 }
Example #10
0
 public function managePermission($action)
 {
     try {
         $user_name = fRequest::get('user_name');
         $permission_name = fRequest::get('permission_name');
         if ($action == 'Add') {
             if (User::can('add-permission')) {
                 $permission = new Permission();
                 $permission->setUserName($user_name);
                 $permission->setPermissionName($permission_name);
                 $permission->store();
                 fMessaging::create('success', 'Permission added successfully.');
             } else {
                 throw new fAuthorizationException('You are not allowed to add permissions.');
             }
         } else {
             if ($action == 'Remove') {
                 if (User::can('remove-permission')) {
                     $permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name));
                     $permission->delete();
                     fMessaging::create('success', 'Permission removed successfully.');
                 } else {
                     throw new fAuthorizationException('You are not allowed to remove permissions.');
                 }
             }
         }
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
     }
     fURL::redirect(Util::getReferer());
 }
Example #11
0
    }
    ?>
    </ul>
    <?php 
    foreach ($this->variables as $v) {
        ?>
      <h3 id="<?php 
        echo fHTML::encode($v->getName());
        ?>
"><?php 
        echo fHTML::prepare($v->getName());
        ?>
</h3>
      <a href="#variables">[list]</a>
      <?php 
        if (User::can('set-variable')) {
            ?>
        <a href="?edit=<?php 
            echo fHTML::encode($v->getName());
            ?>
#set_variable">[edit]</a>
        <a href="?remove=<?php 
            echo fHTML::encode($v->getName());
            ?>
#set_variable">[remove]</a>
      <?php 
        }
        ?>
      <pre><?php 
        echo fHTML::encode($v->getValue());
        ?>
Example #12
0
 /**
  * Admin Roles
  *
  * Handle Groups management
  * @since 1.5
  **/
 function groups($page = 'list', $index = 1)
 {
     // Display all roles
     if ($page == 'list') {
         $groups = $this->users->auth->list_groups();
         $this->gui->set_title(sprintf(__('Roles &mdash; %s'), get('core_signature')));
         $this->load->view('../modules/aauth/views/groups/body', array('groups' => $groups));
     } else {
         if ($page == 'new') {
             if (!User::can('manage_users')) {
                 redirect(array('dashboard?notice=access-denied'));
             }
             // permission checks
             // Validating role creation form
             $this->load->library('form_validation');
             $this->form_validation->set_rules('role_name', __('Role Name'), 'required');
             $this->form_validation->set_rules('role_type', __('Role Type'), 'required');
             if ($this->form_validation->run()) {
                 $exec = $this->users->set_group($this->input->post('role_name'), $this->input->post('role_definition'), $this->input->post('role_type'));
                 if ($exec == 'group-created') {
                     redirect(array('dashboard', 'groups?notice=' . $exec));
                 }
                 $this->notice->push_notice($this->lang->line($exec));
             }
             $this->gui->set_title(sprintf(__('Create new role &mdash; %s'), get('core_signature')));
             $this->load->view('../modules/aauth/views/groups/create');
         } else {
             if ($page == 'edit') {
                 if (!User::can('manage_users')) {
                     redirect(array('dashboard?notice=access-denied'));
                 }
                 // permission checks
                 $this->load->library('form_validation');
                 $this->form_validation->set_rules('role_name', __('Role Name'), 'required');
                 $this->form_validation->set_rules('role_type', __('Role Type'), 'required');
                 if ($this->form_validation->run()) {
                     $exec = $this->users->set_group($this->input->post('role_name'), $this->input->post('role_definition'), $this->input->post('role_type'), 'edit', $index);
                     if ($exec == 'group-updated') {
                         redirect(current_url() . '?notice=' . $exec);
                     }
                     $this->notice->push_notice($this->lang->line($exec));
                 }
                 // Fetch role or redirect
                 $group = $this->users->auth->get_group_id($index);
                 if (is_object($group) === FALSE) {
                     redirect(array('dashboard', 'group-not-found'));
                 }
                 $usergroup = $this->users->auth->get_user_groups($index);
                 $this->gui->set_title(sprintf(__('Edit Roles &mdash; %s'), get('core_signature')));
                 $this->load->view('../modules/aauth/views/groups/edit', array('group' => $group));
             }
         }
     }
 }
Example #13
0
 public function isReadable()
 {
     return fAuthorization::getUserToken() == $this->getOwner() or User::can('view-any-record');
 }
Example #14
0
 /**
  * @param User $a
  * @param User $b
  * @return bool
  */
 private function user_can_edit_user(User $a, User $b)
 {
     if ($a->is_anonymous()) {
         $this->theme->display_error(401, "Error", "You aren't logged in");
         return false;
     }
     if ($a->name == $b->name || $b->can("protected") && $a->class->name == "admin" || !$b->can("protected") && $a->can("edit_user_info")) {
         return true;
     } else {
         $this->theme->display_error(401, "Error", "You need to be an admin to change other people's details");
         return false;
     }
 }
Example #15
0
 function link_to_destroy(&$record)
 {
     if (User::can('destroy action', 'Admin::Users') && $this->_controller->CurrentUser->id != $record->id && (User::can('Edit other users', 'Admin::Users') || $this->_controller->CurrentUser->id == $record->id)) {
         return $this->_controller->url_helper->link_to($this->_controller->t('Delete'), array('action' => 'destroy', 'id' => $record->getId()), array('class' => 'action'));
     }
 }
Example #16
0
 function link_to_destroy(&$record)
 {
     if (AK_DEV_MODE && User::can('destroy action', 'Admin::Permissions')) {
         return $this->_controller->url_helper->link_to($this->_controller->t('delete'), array('action' => 'destroy', 'id' => $record->getId()), array('class' => 'seccondary'));
     }
 }
Example #17
0
            ?>
                    <li class="divider"></li>
                    <li class="nav-header">Permissions</li>
                    <?php 
            if (User::can('add-permission') and User::can('remove-permission')) {
                ?>
                      <li><a href="<?php 
                echo SITE_BASE;
                ?>
/dashboard#permissions">Add/Remove Permission</a></li>
                      <li><a href="<?php 
                echo SITE_BASE;
                ?>
/dashboard#assigned_permissions">View Assigned Permissions</a></li>
                    <?php 
            } elseif (User::can('add-permission')) {
                ?>
                      <li><a href="<?php 
                echo SITE_BASE;
                ?>
/dashboard#permissions">Add Permission</a></li>
                    <?php 
            } else {
                ?>
                      <li><a href="<?php 
                echo SITE_BASE;
                ?>
/dashboard#permissions">Remove Permission</a></li>
                    <?php 
            }
            ?>
Example #18
0
 /**
  * @param User $user
  * @param Page $page
  *
  * @return bool
  */
 public function destroy($user, $page)
 {
     return $user->can('site.page.destroy');
 }
Example #19
0
 public function can()
 {
     $d = $this->webDBUtils->getUserByEmail('*****@*****.**');
     $user = new User($d[0]['id']);
     $res = $user->loadRoles();
     print_r($res);
     $res = $user->can('yodel');
     if (false == $res) {
         $this->printMSG('UserTest::can(): succeeded: user cannot \'yodel\'');
     } else {
         $this->printErr('UserTest::can(): failed: user can NOT yodel');
         $this->printErr($this->session->flushError());
         print_r($res);
         print PHP_EOL;
     }
     $res = $user->can(Policy::LOGIN_AS_ADMIN);
     if (false == $res) {
         $this->printErr('UserTest::can(): failed: user CAN ' . Policy::LOGIN_AS_ADMIN);
         $this->printErr($this->session->flushError());
     } else {
         $this->printMSG('UserTest::can(): succeeded: user can ' . Policy::LOGIN_AS_ADMIN);
         print_r($res);
         print PHP_EOL;
     }
     $res = $user->can(Policy::LOGIN_AS_TENANT);
     if (false == $res) {
         $this->printMsg('UserTest::can(): succeeded: user can NOT ' . Policy::LOGIN_AS_TENANT);
     } else {
         $this->printErr('UserTest::can(): failed: user CAN NOT ' . Policy::LOGIN_AS_TENANT);
         $this->printErr($this->session->flushError());
         print_r($res);
         print PHP_EOL;
     }
 }
Example #20
0
 /**
  * See if the given user is allowed to edit the given page.
  *
  * @param User $user
  * @param WikiPage $page
  * @return bool
  */
 public static function can_edit(User $user, WikiPage $page)
 {
     // admins can edit everything
     if ($user->is_admin()) {
         return true;
     }
     // anon / user can't ever edit locked pages
     if ($page->is_locked()) {
         return false;
     }
     // anon / user can edit if allowed by config
     if ($user->can("edit_wiki_page")) {
         return true;
     }
     return false;
 }
Example #21
0
 function _protectUserFromBeingModified()
 {
     $self_editing = $this->User->getId() == $this->CurrentUser->getId();
     if($this->User->isNewRecord()){
         return ;
     }elseif(!User::can('Set roles', 'Admin::Users') && $this->User->hasRootPrivileges() && !$self_editing){
         $this->flash['error'] = $this->t('You don\'t have the privileges to modify selected user.');
         $this->redirectToAction('listing');
     }elseif (!$self_editing && !User::can('Edit other users', 'Admin::Users')){
         $this->flash['error'] = $this->t('You can\' modify other users account.');
         $this->redirectToAction('listing');
     }
 }
Example #22
0
 public static function isSuper()
 {
     return User::can('view-any-report') and User::can('view-any-record') and User::can('view-any-problem');
 }
 /**
  * Show users of a group
  *
  * @param $target string : where to go on action
  * @param $group the group
  **/
 static function showForGroup($target, Group $group)
 {
     global $DB, $LANG;
     $ID = $group->fields['id'];
     if (!haveRight("user", "r") || !$group->can($ID, 'r')) {
         return false;
     }
     // Have right to manage members
     $canedit = $group->can($ID, 'r') && $group->canUpdate();
     $rand = mt_rand();
     $nb_per_line = 3;
     $query = "SELECT `glpi_users`.*,\n                       `glpi_groups_users`.`id` AS linkID,\n                       `glpi_groups_users`.`is_dynamic` AS is_dynamic\n                FROM `glpi_groups_users`\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_groups_users`.`users_id`)\n                WHERE `glpi_groups_users`.`groups_id`='{$ID}'\n                ORDER BY `glpi_users`.`name`,\n                         `glpi_users`.`realname`,\n                         `glpi_users`.`firstname`";
     $used = array();
     $result = $DB->query($query);
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_array($result)) {
             $used[$data["id"]] = $data;
         }
     }
     $used_ids = array_keys($used);
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
         echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'\n                action='{$target}'>";
         echo "<input type='hidden' name='groups_id' value='{$ID}'>";
         if ($group->fields['is_recursive']) {
             $entityrestrict = getSonsOf('glpi_entities', $group->fields['entities_id']);
             // active entity could be a child of object entity
             if ($_SESSION['glpiactive_entity'] != $group->fields['entities_id'] && in_array($_SESSION['glpiactive_entity'], $entityrestrict)) {
                 $entityrestrict = getSonsOf('glpi_entities', $_SESSION['glpiactive_entity']);
             }
         } else {
             $entityrestrict = $group->fields['entities_id'];
         }
         $res = User::getSqlSearchResult(true, "all", $entityrestrict, 0, $used_ids);
         $nb = $res ? $DB->result($res, 0, "CPT") : 0;
         if ($nb) {
             echo "<div class='firstbloc'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['setup'][603] . "</tr>";
             echo "<tr><td class='tab_bg_2 center'>";
             User::dropdown(array('right' => "all", 'entity' => $entityrestrict, 'used' => $used_ids));
             echo "</td><td class='tab_bg_2 center'>";
             echo "<input type='hidden' name'is_dynamic' value='0'>";
             echo "<input type='submit' name='adduser' value=\"" . $LANG['buttons'][8] . "\"\n                   class='submit'>";
             echo "</td></tr>";
             echo "</table></div>";
         }
     } else {
         $headerspan = $nb_per_line;
     }
     if (count($used)) {
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='{$headerspan}'>" . $LANG['Menu'][14] . " (D=" . $LANG['profiles'][29] . ")";
         echo "</th></tr>";
         initNavigateListItems('User', $group->getTypeName() . " = " . $group->getName());
         $i = 0;
         $user = new User();
         foreach ($used as $id => $data) {
             if (!$user->can($id, 'r')) {
                 // For recursive group, could be in another (sister) entity
                 continue;
             }
             addToNavigateListItems('User', $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>";
             echo $user->getLink();
             if ($data["is_dynamic"]) {
                 echo "<strong>&nbsp;(D)</strong>";
             }
             echo "</td>";
             $i++;
         }
         while ($i % $nb_per_line != 0) {
             echo "<td>&nbsp;</td>";
             if ($canedit) {
                 echo "<td>&nbsp;</td>";
             }
             $i++;
         }
         echo "</tr>";
         echo "</table>";
         if ($canedit) {
             openArrowMassive("groupuser_form{$rand}", true);
             closeArrowMassive('deleteuser', $LANG['buttons'][6]);
         }
         echo "</div>";
     }
     if ($canedit) {
         echo "</form>";
     }
 }
 /**  Show groups of a user
  *
  * @param $user   User object
  **/
 static function showForUser(User $user)
 {
     global $CFG_GLPI;
     $ID = $user->fields['id'];
     if (!Group::canView() || !$user->can($ID, READ)) {
         return false;
     }
     $canedit = $user->can($ID, UPDATE);
     $rand = mt_rand();
     $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 "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'";
         echo " action='" . Toolbox::getItemTypeFormURL('User') . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Associate to a group') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='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 (!Session::haveAccessToEntity($val)) {
                 unset($strict_entities[$key]);
             }
         }
         $nb = countElementsInTableForEntity("glpi_groups", $strict_entities, '`is_usergroup`');
         if ($nb > count($used)) {
             Group::dropdown(array('entity' => $strict_entities, 'used' => $used, 'condition' => '`is_usergroup`'));
             echo "</td><td>" . __('Manager') . "</td><td>";
             Dropdown::showYesNo('is_manager');
             echo "</td><td>" . __('Delegatee') . "</td><td>";
             Dropdown::showYesNo('is_userdelegate');
             echo "</td><td class='tab_bg_2 center'>";
             echo "<input type='submit' name='addgroup' value=\"" . _sx('button', 'Add') . "\"\n                   class='submit'>";
         } else {
             _e('None');
         }
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && count($used)) {
         $rand = mt_rand();
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         echo "<input type='hidden' name='users_id' value='" . $user->fields['id'] . "'>";
         $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && count($used)) {
         $header_begin .= "<th width='10'>";
         $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_end .= "</th>";
     }
     $header_end .= "<th>" . Group::getTypeName(1) . "</th>";
     $header_end .= "<th>" . __('Dynamic') . "</th>";
     $header_end .= "<th>" . __('Manager') . "</th>";
     $header_end .= "<th>" . __('Delegatee') . "</th></tr>";
     echo $header_begin . $header_top . $header_end;
     $group = new Group();
     if (!empty($groups)) {
         Session::initNavigateListItems('Group', sprintf(__('%1$s = %2$s'), User::getTypeName(1), $user->getName()));
         foreach ($groups as $data) {
             if (!$group->getFromDB($data["id"])) {
                 continue;
             }
             Session::addToNavigateListItems('Group', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit && count($used)) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             $link = $data["completename"];
             if ($_SESSION["glpiis_ids_visible"]) {
                 $link = sprintf(__('%1$s (%2$s)'), $link, $data["id"]);
             }
             $href = "<a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $link . "</a>";
             if ($data["is_dynamic"]) {
                 $href = sprintf(__('%1$s (%2$s)'), $href, "<span class='b'>" . __('D') . "</span>");
             }
             echo "<td>" . $group->getLink() . "</td>";
             echo "<td class='center'>";
             if ($data['is_dynamic']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">";
             }
             echo "<td class='center'>";
             if ($data['is_manager']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">";
             }
             echo "</td><td class='center'>";
             if ($data['is_userdelegate']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">";
             }
             echo "</td></tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     } else {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='5' class='center'>" . __('None') . "</td></tr>";
     }
     echo "</table>";
     if ($canedit && count($used)) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Example #25
0
 function can($task, $extension = null, $force_reload = false)
 {
     return User::can($task, $extension, $force_reload);
 }
Example #26
0
 /**
  * Checks whether user is granted to access modules
  **/
 function module_access()
 {
     if (!User::can('manage_modules')) {
         redirect(array('dashboard?notice=access-denied'));
     }
 }
Example #27
0
      <th>结束时间</th>
      <th>比赛时长</th>
      <th colspan="2">参赛人数</th>
    </tr>
  </thead>
  <tbody>
    <?php 
foreach ($this->reports as $r) {
    ?>
      <tr>
        <td><?php 
    echo $r->getId();
    ?>
</td>
        <?php 
    if (User::can('view-any-report')) {
        ?>
          <td>
            <?php 
        if ($r->getVisible()) {
            ?>
              <i class="icon-ok"></i>
            <?php 
        }
        ?>
          </td>
        <?php 
    }
    ?>
        <td><a href="<?php 
    echo SITE_BASE;
Example #28
0
 public function isReadable()
 {
     return $this->getVisible() or User::can('view-any-report');
 }
Example #29
0
 function link_to_destroy(&$record)
 {
     if (User::can('destroy action', 'Admin::Roles')) {
         return $this->_controller->url_helper->link_to($this->_controller->t('Delete'), array('action' => 'destroy', 'id' => $record->getId()), array('class' => 'action'));
     }
 }