• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 define('IL_REG_ACCESS_LIMITATION_MISSING_MODE',1);
00034 define('IL_REG_ACCESS_LIMITATION_OUT_OF_DATE',2);
00035 
00036 class ilRegistrationRoleAccessLimitations
00037 {
00038         var $access_limits = array();
00039 
00040         function ilRegistrationRoleAccessLimitations()
00041         {
00042                 global $ilDB;
00043 
00044                 $this->db =& $ilDB;
00045                 $this->__read();
00046         }
00047         
00048         // Private
00049         function __read()
00050         {
00051                 global $ilias;
00052 
00053                 $query = "SELECT * FROM reg_access_limitation ";
00054                 $res = $this->db->query($query);
00055 
00056                 $this->access_limitations = array();
00057                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00058                 {
00059                         $this->access_limitations[$row->role_id]['id'] =  $row->role_id;
00060                         $this->access_limitations[$row->role_id]['absolute'] = $row->limit_absolute;
00061                         $this->access_limitations[$row->role_id]['relative_d'] = $row->limit_relative_d;
00062                         $this->access_limitations[$row->role_id]['relative_m'] = $row->limit_relative_m;
00063                         $this->access_limitations[$row->role_id]['relative_y'] = $row->limit_relative_y;
00064                         $this->access_limitations[$row->role_id]['mode'] = $row->limit_mode;
00065                 }
00066                 
00067                 return true;
00068         }
00069         
00070         function save()
00071         {
00072                 global $ilias, $ilDB;
00073 
00074                 foreach($this->access_limitations as $key => $data)
00075                 {
00076                         $limit_value = "";
00077                         
00078                         if ($data['mode'] == 'absolute')
00079                         {
00080                                 $limit_value = ", limit_absolute = ".$ilDB->quote($data['absolute'])." ";
00081                         }
00082                         
00083                         if ($data['mode'] == 'relative')
00084                         {
00085                                 $limit_value = ", limit_relative_d = ".$ilDB->quote($data['relative_d'])." ".
00086                                                            ", limit_relative_m = ".$ilDB->quote($data['relative_m'])." ".
00087                                                            ", limit_relative_y = ".$ilDB->quote($data['relative_y'])." ";
00088                         }
00089                         
00090                         $query = "REPLACE INTO reg_access_limitation ".
00091                                          "SET role_id = ".$ilDB->quote($key).", ".
00092                                          "limit_mode = ".$ilDB->quote($data['mode'])." ".
00093                                          $limit_value;
00094 
00095                         $this->db->query($query);
00096                 }
00097                 
00098                 return true;
00099         }
00100         
00101         function validate()
00102         {
00103                 foreach ($this->access_limitations as $data)
00104                 {
00105                         if ($data['mode'] == "null")
00106                         {
00107                                 return IL_REG_ACCESS_LIMITATION_MISSING_MODE;
00108                         }
00109                         
00110                         if ($data['mode'] == 'absolute' and $data['absolute'] < time())
00111                         {
00112                                 return IL_REG_ACCESS_LIMITATION_OUT_OF_DATE;
00113                         }
00114                         
00115                         if ($data['mode'] == 'relative' and ($data['relative_d'] < 1 and $data['relative_m'] < 1 and $data['relative_y'] < 1))
00116                         {
00117                                 return IL_REG_ACCESS_LIMITATION_OUT_OF_DATE;
00118                         }       
00119                 }
00120                 
00121                 return 0;
00122         }
00123         
00124         function getMode($a_role_id)
00125         {
00126                 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['mode'] : 'null';
00127         }
00128         
00129         function setMode($a_mode,$a_role_id)
00130         {
00131                 $this->access_limitations[$a_role_id]['mode'] = $a_mode;
00132         }
00133         
00134         function getAbsolute($a_role_id)
00135         {
00136                 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['absolute'] : time();
00137         }
00138         
00139         function setAbsolute($a_arr,$a_role_id)
00140         {
00141                 $this->access_limitations[$a_role_id]['absolute'] = mktime(23,59,59,$a_arr['m'],$a_arr['d'],$a_arr['y']);
00142         }
00143         
00144         function getRelative($a_role_id,$a_type)
00145         {
00146                 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['relative_'.$a_type] : 0;
00147         }
00148 
00149         function setRelative($a_arr,$a_role_id)
00150         {
00151                 $this->access_limitations[$a_role_id]['relative_d'] = $a_arr['d'];
00152                 $this->access_limitations[$a_role_id]['relative_m'] = $a_arr['m'];
00153                 $this->access_limitations[$a_role_id]['relative_y'] = $a_arr['y'];
00154         }
00155 }
00156 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1