config migration in source code; config page is not needed anymore
[iserv-mod-error-reporter.git] / inc / class_erConfig.inc
1 <?php
2 /**
3 * @file class_erConfig.inc
4 * Class that handles the configuration
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 21.10.2007
7 *
8 * Copyright © 2007 Roland Hieber
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * THE SOFTWARE.
27 */
28
29 require_once("sec/secure.inc");
30 require_once("mod_error-reporter/functions.inc");
31 require_once("db.inc");
32
33 /** @todo document */
34 class erConfig {
35
36 /**
37 * Determine if a privilege has been assigned
38 * @param $sPriv (string) Privilege to test
39 * @return bool
40 */
41 public static function privilegeAssigned($sPriv) {
42 $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1;",
43 $sPriv);
44 return pg_num_rows($h) > 0;
45 }
46
47 /**
48 * Retrieve all groups that have a privilege assigned
49 * @param $strPriv (string) Privilege to test
50 * @return array
51 */
52 public static function privilegedGroups($strPriv) {
53 $aReturn = array();
54 $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1 ".
55 "ORDER BY act;", $strPriv);
56 if(pg_num_rows($h) > 0) {
57 while($a = pg_fetch_array($h)) {
58 $aReturn[] = $a["act"];
59 }
60 }
61 return $aReturn;
62 }
63
64 /**
65 * Determine if the current user is allowed to see and report errors. This
66 * function tests if the user is member of a group which has the
67 * <tt>mod-errorreporter_access</tt> privilege.
68 * @return bool
69 */
70 public static function userHasAccess() {
71 if(erConfig::userIsAdmin() ||
72 !erConfig::privilegeAssigned("mod_errorreporter_access")) {
73 // user is admin or privilege is not assigned
74 return true;
75 } else {
76 return secure_privilege("mod_errorreporter_access");
77 }
78 }
79
80 /**
81 * Determine if the current user has admin rights. This function tests if
82 * the user is member of a group which has the
83 * <tt>mod-errorreporter_access</tt> privilege
84 * @return bool
85 */
86 public static function userIsAdmin() {
87 return secure_privilege("mod_errorreporter_admin");
88 }
89
90 /** @} */
91 }
92 ?>
This page took 0.049697 seconds and 5 git commands to generate.