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