ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRegistrationRoleAccessLimitations.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
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; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 define('IL_REG_ACCESS_LIMITATION_MISSING_MODE',1);
34 define('IL_REG_ACCESS_LIMITATION_OUT_OF_DATE',2);
35 
37 {
38  var $access_limits = array();
39 
41  {
42  global $ilDB;
43 
44  $this->db =& $ilDB;
45  $this->__read();
46  }
47 
48  // Private
49  function __read()
50  {
51  global $ilias;
52 
53  $query = "SELECT * FROM reg_access_limitation ";
54  $res = $this->db->query($query);
55 
56  $this->access_limitations = array();
57  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
58  {
59  $this->access_limitations[$row->role_id]['id'] = $row->role_id;
60  $this->access_limitations[$row->role_id]['absolute'] = $row->limit_absolute;
61  $this->access_limitations[$row->role_id]['relative_d'] = $row->limit_relative_d;
62  $this->access_limitations[$row->role_id]['relative_m'] = $row->limit_relative_m;
63  $this->access_limitations[$row->role_id]['relative_y'] = $row->limit_relative_y;
64  $this->access_limitations[$row->role_id]['mode'] = $row->limit_mode;
65  }
66 
67  return true;
68  }
69 
70  function save()
71  {
72  global $ilias, $ilDB;
73 
74  foreach($this->access_limitations as $key => $data)
75  {
76  $limit_value = "";
77 
78  if ($data['mode'] == 'absolute')
79  {
80  $limit_value = ", limit_absolute = ".$ilDB->quote($data['absolute'])." ";
81  }
82 
83  if ($data['mode'] == 'relative')
84  {
85  $limit_value = ", limit_relative_d = ".$ilDB->quote($data['relative_d'])." ".
86  ", limit_relative_m = ".$ilDB->quote($data['relative_m'])." ".
87  ", limit_relative_y = ".$ilDB->quote($data['relative_y'])." ";
88  }
89 
90  $query = "REPLACE INTO reg_access_limitation ".
91  "SET role_id = ".$ilDB->quote($key).", ".
92  "limit_mode = ".$ilDB->quote($data['mode'])." ".
93  $limit_value;
94 
95  $this->db->query($query);
96  }
97 
98  return true;
99  }
100 
101  function validate()
102  {
103  foreach ($this->access_limitations as $data)
104  {
105  if ($data['mode'] == "null")
106  {
108  }
109 
110  if ($data['mode'] == 'absolute' and $data['absolute'] < time())
111  {
113  }
114 
115  if ($data['mode'] == 'relative' and ($data['relative_d'] < 1 and $data['relative_m'] < 1 and $data['relative_y'] < 1))
116  {
118  }
119  }
120 
121  return 0;
122  }
123 
124  function getMode($a_role_id)
125  {
126  return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['mode'] : 'null';
127  }
128 
129  function setMode($a_mode,$a_role_id)
130  {
131  $this->access_limitations[$a_role_id]['mode'] = $a_mode;
132  }
133 
134  function getAbsolute($a_role_id)
135  {
136  return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['absolute'] : time();
137  }
138 
139  function setAbsolute($a_arr,$a_role_id)
140  {
141  $this->access_limitations[$a_role_id]['absolute'] = mktime(23,59,59,$a_arr['m'],$a_arr['d'],$a_arr['y']);
142  }
143 
144  function getRelative($a_role_id,$a_type)
145  {
146  return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['relative_'.$a_type] : 0;
147  }
148 
149  function setRelative($a_arr,$a_role_id)
150  {
151  $this->access_limitations[$a_role_id]['relative_d'] = $a_arr['d'];
152  $this->access_limitations[$a_role_id]['relative_m'] = $a_arr['m'];
153  $this->access_limitations[$a_role_id]['relative_y'] = $a_arr['y'];
154  }
155 }
156 ?>