2 /*===============================================================
\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
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
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
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
28 define('PATH', './');
\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
38 * @desc This class is called Pa. This class is used by every other class
\r
43 var $error_array=Array();
\r
46 * @desc constructor.
\r
53 * @desc This function initializes the class object
\r
57 Pa::checkEnrolled();
\r
62 * @desc This function checks whether the user is enrolled in the course or not
\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
73 * @desc This function checks whether the user is guest. If the user is guest, it redirects the user to login page
\r
75 function checkGuest(){
\r
76 if (isset($_SESSION['is_guest']) && ($_SESSION['is_guest']==true)){
\r
77 redirect('../../'.PATH.'login.php');
\r
82 * @desc This function sets the course id
\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
90 Pa::setVariable('course_id', intval($_SESSION['course_id']));
\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
99 function setVariable($string, $value){
\r
102 if (is_int($value) && ($value > 0) && course_exist($value)){
\r
103 $this->{$string}=$value;
\r
105 $this->storeError("course value is not valid");
\r
109 if (is_int($value) && ($value > 0)){
\r
110 $this->{$string}=$value;
\r
112 $this->storeError("value ".$value." is not int");
\r
115 case 'show_modification_buttons':
\r
116 if (is_bool($value)){
\r
117 $this->{$string}=$value;
\r
119 $this->storeError("value ".$value." is not boolean");
\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
130 function getVariable($string){
\r
131 return $this->{$string};
\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
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
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
150 function isError(){
\r
151 if (Pa::getVariable('error')==0){
\r