changed git call from https to git readonly
[atutor.git] / mods / photo_album / classes / pa.class.php
1 <?php\r
2 /*===============================================================\r
3   Photo Album                                                  \r
4   ===============================================================\r
5   Copyright (c) 2006 by Dylan Cheon & Kelvin Wong              \r
6   Institute for Assistive Technology / University of Victoria  \r
7   http://www.canassist.ca/                                     \r
8                                                               \r
9   This program is free software. You can redistribute it and/or\r
10   modify it under the terms of the GNU General Public License  \r
11   as published by the Free Software Foundation.                \r
12   ===============================================================\r
13  */\r
14 // $Id:\r
15 \r
16 /**\r
17  * @desc        This class structure is the general class to be used for every other class.  This class defines the course id, guest check, enrollment check, etc.\r
18  * @author      Dylan Cheon & Kelvin Wong\r
19  * @copyright   2006, Institute for Assistive Technology / University of Victoria \r
20  * @link        http://www.canassist.ca/                                    \r
21  * @license GNU\r
22  */\r
23  \r
24 if (!defined('PATH')){\r
25         if (preg_match('/'.AT_PRETTY_URL_HANDLER.'\/.*\/(mods\/.*\/)/', $_SERVER['PHP_SELF'], $matches) > 0){\r
26                 define('PATH', $matches[1]);\r
27         } else {\r
28                 define('PATH', './');\r
29         }\r
30 }\r
31 \r
32 require_once (PATH.'define.php');\r
33 require_once (PATH.'include/data_func.php');\r
34 require_once (PATH.'include/general_func.php');\r
35 require_once (PATH.'HTML/Template/ITX.php');\r
36 \r
37 /**\r
38  * @desc        This class is called Pa.  This class is used by every other class\r
39  */\r
40 class Pa {\r
41         var $course_id=-1;\r
42         var $error=0;\r
43         var $error_array=Array();\r
44         \r
45         /**\r
46          * @desc        constructor.  \r
47          */\r
48         function Pa (){\r
49                 Pa::init();\r
50         }\r
51         \r
52         /**\r
53          * @desc        This function initializes the class object \r
54          */\r
55         function init(){\r
56                 Pa::checkGuest();\r
57                 Pa::checkEnrolled();\r
58                 Pa::setCourseId();\r
59         }\r
60         \r
61         /**\r
62          * @desc        This function checks whether the user is enrolled in the course or not\r
63          */\r
64         function checkEnrolled(){\r
65                 if ($_SESSION['privileges']>0){\r
66                         Pa::setVariable('show_modification_buttons', true);\r
67                 } else if (isset($_SESSION['enroll']) && ($_SESSION['enroll']==true)){\r
68                         Pa::setVariable('show_modification_buttons', true);\r
69                 }\r
70         }\r
71         \r
72         /**\r
73          * @desc        This function checks whether the user is guest.  If the user is guest, it redirects the user to login page\r
74          */\r
75         function checkGuest(){\r
76                 if (isset($_SESSION['is_guest']) && ($_SESSION['is_guest']==true)){\r
77                         redirect('../../'.PATH.'login.php');\r
78                 }\r
79         }\r
80                 \r
81         /**\r
82          * @desc        This function sets the course id\r
83          */\r
84         function setCourseId(){\r
85                 if (isset($_POST['course_id']) && course_exist($_POST['course_id'])){\r
86                         Pa::setVariable('course_id', intval($_POST['course_id']));\r
87                 } else if ($_SESSION['course_id']==-1){\r
88                         Pa::setVariable('course_id', intval($_SESSION['pa']['course_id']));\r
89                 } else {\r
90                         Pa::setVariable('course_id', intval($_SESSION['course_id']));\r
91                 }\r
92         }\r
93         \r
94         /**\r
95          * @desc        This function sets the given input string for the class object variable\r
96          * @param       String  $string         string name to be set\r
97          * @param       mixed   $value          string value\r
98          */ \r
99         function setVariable($string, $value){\r
100                 switch ($string){\r
101                         case 'course_id':\r
102                                 if (is_int($value) && ($value > 0) && course_exist($value)){\r
103                                         $this->{$string}=$value;\r
104                                 } else {\r
105                                         $this->storeError("course value is not valid");\r
106                                 }\r
107                         break;\r
108                         case 'error':\r
109                                 if (is_int($value) && ($value > 0)){\r
110                                         $this->{$string}=$value;\r
111                                 } else {\r
112                                         $this->storeError("value ".$value." is not int");\r
113                                 }\r
114                         break;\r
115                         case 'show_modification_buttons':\r
116                                 if (is_bool($value)){\r
117                                   $this->{$string}=$value;\r
118                                 } else {\r
119                                   $this->storeError("value ".$value." is not boolean");\r
120                                 }\r
121                         break;\r
122                 }\r
123         }\r
124         \r
125         /**\r
126          * @desc        This function returns the given variable value\r
127          * @param       String  $string         name of string to be returned\r
128          * @return      mixed                           the required variable value \r
129          */\r
130         function getVariable($string){\r
131                 return $this->{$string};\r
132         }\r
133         \r
134                                 \r
135         /**\r
136          * @desc        This function stores the fatal error for the class object.  This function is only called when a fatal error is occured.\r
137          * @param       String  $string         error string to be stored\r
138          */\r
139         function storeError($string){                   \r
140                 $error=&Pa::getVariable('error');\r
141                 $array=&$this->error_array;\r
142                 $array[$error]=$string;\r
143                 Pa::setVariable('error', $error+1);\r
144         }\r
145         \r
146         /**\r
147          * @desc        This function checks if a fatal error has occurred or not in the class object\r
148          * @return      boolean         true if there is fatal error\r
149          */\r
150         function isError(){\r
151           if (Pa::getVariable('error')==0){\r
152             return false;\r
153           } else {\r
154             return true;\r
155           }\r
156         }\r
157 }