changed git call from https to git readonly
[atutor.git] / mods / photo_album / classes / pa_admin_image.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 all the image data to be used for the admin / instructor pages\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/general_func.php');\r
27 require_once ('include/data_func.php');\r
28 \r
29 /**\r
30  * @desc        Pa_admin_image class.  \r
31  * @see         class Pa\r
32  */\r
33 class Pa_Admin_Image extends PA{\r
34         var $mode=POSTED_NEW;\r
35         var $image_array=Array();\r
36         var $page_array=Array();\r
37         var $current_page=-1;\r
38         var $show_page_left_buttons=false;\r
39         var $show_page_right_buttons=false;\r
40         var $total=NOT_SET;\r
41         var $last_page=NOT_SET;\r
42         \r
43         /** \r
44          * @desc        constructor\r
45          */\r
46         function Pa_Admin_Image(){\r
47                 $this->checkAuthority();\r
48                 parent::init();\r
49                 $this->checkRequest();\r
50                 $this->setMode();\r
51                 $this->checkCurrentPage();\r
52                 $this->setImages();\r
53                 $this->setPages();\r
54         \r
55         }\r
56         \r
57         /**\r
58          * @desc        This function checks the request to change the image status. The request could be make approved, make disapproved, or make new\r
59          */\r
60         function checkRequest(){\r
61                 if (isset($_POST['button_disapprove'])){\r
62                   for ($i=0; $i < ADMIN_NUMBER_OF_IMAGE_PAGE; $i++){\r
63                     $string="imageId".$i;\r
64                     if (isset($_POST[$string])){\r
65                                 modify_image_status($_POST[$string], $this->getVariable('course_id'), DISAPPROVED);  \r
66                     }\r
67                   }\r
68                 } else if (isset($_POST['button_approve'])){\r
69                   for ($i=0; $i< ADMIN_NUMBER_OF_IMAGE_PAGE; $i++){\r
70                     $string="imageId".$i;\r
71                     if (isset($_POST[$string])){\r
72                           modify_image_status($_POST[$string], $this->getVariable('course_id'), APPROVED);\r
73                         }\r
74                   }\r
75                 } else if (isset($_POST['button_post_new'])){\r
76                   for ($i=0; $i < ADMIN_NUMBER_OF_IMAGE_PAGE; $i++){\r
77                         $string="imageId".$i;  \r
78                         if (isset($_POST[$string])){\r
79                             modify_image_status($_POST[$string], $this->getVariable('course_id'), POSTED_NEW);\r
80                         }\r
81                   }  \r
82                 }\r
83         }\r
84         \r
85         /**\r
86          * @desc        This function checks if the user is an instructor or an administrator.  If the user is neither instructor nor administrator, it redirects the user to the index page\r
87          */\r
88         function checkAuthority(){\r
89                 if (is_admin_for_course()!=true){\r
90                         redirect('index.php');\r
91                 }\r
92         }\r
93         \r
94         /**\r
95          * @desc        This function decides whether to display left arrow and right arrow buttons on the page table\r
96          */\r
97         function setPages(){\r
98                 $temp=get_page_array(ADMIN_NUMBER_OF_IMAGE, ADMIN_NUMBER_OF_IMAGE_PAGE, $this->getVariable('current_page'), $this->getVariable('last_page'));\r
99                 $current=$this->getVariable('current_page');\r
100                 if ($current > 1){\r
101                         $this->setVariable('show_page_left_buttons', true);\r
102                 } \r
103                 if ($current < $temp['last_page']){\r
104                         $this->setVariable('show_page_right_buttons', true);\r
105                 }\r
106                 $this->page_array=&$temp;\r
107                 \r
108         }       \r
109         \r
110         /**\r
111          * @desc        This function sets the mode value for the image display.  The mode value can be POSTED_NEW, APPROVED, or DISAPPROVED\r
112          */\r
113         function setMode(){\r
114                 if (isset($_GET['mode'])){\r
115                         $this->setVariable('mode', intval($_GET['mode']));\r
116                 } \r
117         }\r
118         \r
119         /**\r
120          * @desc        This function checks if the current page is valid.  Otherwise, the current page is set to 1\r
121          */\r
122         function checkCurrentPage(){\r
123                 $total=get_total_image_number(ADMIN_PANEL, $this->getVariable('course_id'), $this->getVariable('mode'));\r
124                 $last_page=get_last_page(ADMIN_NUMBER_OF_IMAGE, $total);\r
125                 $this->setVariable('total', $total);\r
126                 $this->setVariable('last_page', $last_page);\r
127                 if (!isset($_GET['current_page'])){\r
128                         $this->setVariable('current_page', FIRST_PAGE);\r
129                 } else {\r
130                         $current_page=to_pos_int($_GET['current_page']);\r
131                         if ($current_page > $last_page){\r
132                                 $this->setVariable('current_page',$last_page);\r
133                         } else {\r
134                                 $this->setVariable('current_page', $current_page);\r
135                         }\r
136                 }\r
137         }\r
138         \r
139         /**\r
140          * @desc        This function sets the image array\r
141          */\r
142         function setImages(){\r
143                 $temp=get_image_array(ADMIN_PANEL, parent::getVariable('course_id'), $this->getVariable('mode'), $this->getVariable('current_page'), ADMIN_NUMBER_OF_IMAGE);\r
144                 $this->image_array=&$temp;\r
145         }\r
146                         \r
147         /**\r
148          * @desc        This function sets the given string value for the class object\r
149          * @param       String  $string         string name to be set\r
150          * @param       mixed   $value          string value\r
151          */\r
152         function setVariable($string, $value){\r
153                 switch ($string){\r
154                         case 'mode':\r
155                                 if ($value==APPROVED || $value==DISAPPROVED || $value==POSTED_NEW){\r
156                                         $this->{$string}=$value;\r
157                                 }\r
158                         break;\r
159                         case 'current_page':\r
160                         case 'last_page':\r
161                         case 'total':\r
162                                 if (is_int($value)){\r
163                                         $this->{$string}=$value;\r
164                                 } else {\r
165                                         parent::storeError("value ".$string." is not integer");\r
166                                 }\r
167                         break;\r
168                         case 'show_page_left_buttons':\r
169                         case 'show_page_right_buttons':\r
170                                 if (is_bool($value)){\r
171                                         $this->{$string}=$value;\r
172                                 } else {\r
173                                         parent::storeError("value ".$string." is not boolean");\r
174                                 }\r
175                         break;\r
176                 }\r
177         }\r
178 }