changed git call from https to git readonly
[atutor.git] / mods / photo_album / classes / pa_view.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 file generates the image data and comment data to be displayed in the view page\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 require_once ('define.php');\r
25 require_once ('classes/pa.class.php');\r
26 require_once ('include/data_func.php');\r
27 require_once ('include/general_func.php');\r
28 \r
29 /** \r
30  * @desc        class View\r
31  * @see         class Pa\r
32  */\r
33 class View extends Pa {\r
34         var $image_id=NOT_SET;\r
35         var $comment_array=Array();\r
36         var $image_array=Array();\r
37         \r
38         /**\r
39          * @desc        class constructor\r
40          */\r
41         function View (){\r
42                 parent::init();\r
43                 $this->checkImageId();  \r
44                 $this->checkAuthority();\r
45                 $this->setImage();\r
46                 $this->setComments();\r
47         }\r
48         \r
49         /**\r
50          * @desc        This function checks if the image has approved status.  If the image is not set to approved and user is neither admin nor instructor, it redirects user to the index page\r
51          */\r
52         function checkAuthority(){\r
53                 $image_array=get_single_data(IMAGE, $this->getVariable('image_id'), parent::getVariable('course_id'));\r
54                 if (!(($_SESSION['is_admin']==true) || ($_SESSION['privileges'] > 0))){\r
55                         if ($image_array['status']!=APPROVED){\r
56                                 global $msg;\r
57                                 $msg->addError('pa_var_unauthorized');\r
58                                 redirect('index.php');\r
59                         }\r
60                 }\r
61         }\r
62         \r
63         /**\r
64          * @desc        This function checks whether the given image_id exists in the database\r
65          */\r
66         function checkImageId(){\r
67                 global $msg;\r
68                 if (isset($_GET['image_id'])){\r
69                         if (image_exist(intval($_GET['image_id']), parent::getVariable('course_id'))){\r
70                                 $this->setVariable('image_id', intval($_GET['image_id']));\r
71                         } else {\r
72                                 $msg->addError('pa_var_unauthorized');\r
73                                 redirect('index.php');\r
74                         }\r
75                 } else {\r
76                         $msg->addError('pa_var_unauthorized');\r
77                         redirect ('index.php');\r
78                 }\r
79         }\r
80         \r
81         /**\r
82          * @desc        This function sets the string to a value\r
83          * @param       String  $string         string name to set up\r
84          * @param       mixed   $value          string value\r
85          */\r
86         function setVariable($string, $value){\r
87           switch ($string){\r
88             case 'image_id':\r
89                         if (is_int($value) && ($value > 0)){\r
90                            $this->{$string}=$value;\r
91                         } else {\r
92                           parent::storeError("string ".$string." is not integer");\r
93                         }\r
94                 break;  \r
95           }\r
96         }\r
97         \r
98         /**\r
99          * @desc        This function sets the image array\r
100          */\r
101         function setImage(){\r
102                 $this->image_array=&get_single_data(IMAGE, $this->getVariable('image_id'), parent::getVariable('course_id'));\r
103         }\r
104         \r
105         /**\r
106          * @desc        This function sets the comment array \r
107          */\r
108         function setComments(){\r
109                 $this->comment_array=&get_comment_array(ADMIN_VIEW, $this->getVariable('course_id'), NOT_SET, $this->getVariable('image_id'));  \r
110         }       \r
111 }