AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / include / classes / DAO / PrivilegesDAO.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 /**
14 * DAO for "themes" table
15 * @access       public
16 * @author       Cindy Qi Li
17 * @package      DAO
18 */
19
20 if (!defined('TR_INCLUDE_PATH')) exit;
21
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23
24 class PrivilegesDAO extends DAO {
25
26         /**
27         * Return privileges that are open to public
28         * @access  public
29         * @param   none
30         * @return  table rows
31         * @author  Cindy Qi Li
32         */
33         function getAll()
34         {
35                 $sql = 'SELECT *
36                                 FROM '.TABLE_PREFIX.'privileges p
37                                 ORDER BY privilege_id';
38
39                 return $this->execute($sql);
40         }
41
42         /**
43         * Return privileges that are open to public
44         * @access  public
45         * @param   none
46         * @return  table rows
47         * @author  Cindy Qi Li
48         */
49         function getPublicPrivileges()
50         {
51                 $sql = 'SELECT *
52                                                 FROM '.TABLE_PREFIX.'privileges p
53                                                 WHERE open_to_public = 1
54                                                 ORDER BY p.menu_sequence';
55
56                 return $this->execute($sql);
57         }
58
59         /**
60         * Return privileges of the given user
61         * @access  public
62         * @param   $userID
63         * @return  table rows
64         * @author  Cindy Qi Li
65         */
66         function getUserPrivileges($userID)
67         {
68                 $sql = 'SELECT *
69                                 FROM '.TABLE_PREFIX.'users u, '.TABLE_PREFIX.'user_groups ug, '.TABLE_PREFIX.'user_group_privilege ugp, '.TABLE_PREFIX.'privileges p
70                                 WHERE u.user_id = '.$userID.'
71                                 AND u.user_group_id = ug.user_group_id
72                                 AND ug.user_group_id = ugp.user_group_id
73                                 AND ugp.privilege_id = p.privilege_id
74                                 ORDER BY p.menu_sequence';
75
76             return $this->execute($sql);
77           }
78
79         /**
80         * Return privileges of the given user group
81         * @access  public
82         * @param   $userGroupID
83         * @return  table rows
84         * @author  Cindy Qi Li
85         */
86         function getUserGroupPrivileges($userGroupID)
87         {
88                 $sql = 'SELECT *, ug.description user_group_desc, p.description privilege_desc
89                                 FROM '.TABLE_PREFIX.'user_groups ug, '.TABLE_PREFIX.'user_group_privilege ugp, '.TABLE_PREFIX.'privileges p
90                                 WHERE ug.user_group_id = '.$userGroupID.'
91                                 AND ug.user_group_id = ugp.user_group_id
92                                 AND ugp.privilege_id = p.privilege_id
93                                 ORDER BY p.menu_sequence';
94         
95                 return $this->execute($sql);
96         }
97
98         /**
99         * Return all privileges except the privilege ids in given string  
100         * @access  public
101         * @param   $privilegeIDs : a string of check ids separated by comma. for example: 1, 2, 3
102         * @return  table rows
103         * @author  Cindy Qi Li
104         */
105         function getAllPrivsExceptListed($privilegeIDs)
106         {
107                 if (trim($privilegeIDs) == '')
108                         return $this->getAll();
109                 else
110                 {
111                         $sql = "SELECT * FROM ". TABLE_PREFIX ."privileges 
112                                  WHERE privilege_id NOT IN (".$privilegeIDs.")";
113                         return $this->execute($sql);
114                 }
115         }
116         
117 }
118 ?>