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 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
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
30 * @desc class pa_admin_comment generates all the comment data to be used for admin/instructor
\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
42 var $last_page=NOT_SET;
\r
47 function Pa_Admin_Comment(){
\r
48 $this->checkAuthority();
\r
50 $this->checkRequest();
\r
52 $this->checkCurrentPage();
\r
53 $this->setComments();
\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
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
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
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
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
89 function checkAuthority(){
\r
90 if (is_admin_for_course()!=true){
\r
91 redirect('index.php');
\r
96 * @desc This function decides whether to display left arrow and right arrow buttons in the page table
\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
102 $this->setVariable('show_page_left_buttons', true);
\r
104 if ($current < $temp['last_page']){
\r
105 $this->setVariable('show_page_right_buttons', true);
\r
107 $this->page_array=&$temp;
\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
114 function setMode(){
\r
115 if (isset($_GET['mode'])){
\r
116 $this->setVariable('mode', intval($_GET['mode']));
\r
121 * @desc This function checks if the current page is valid. Otherwise, the current page is set to 1
\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
129 if (!isset($_GET['current_page'])){
\r
130 $this->setVariable('current_page', FIRST_PAGE);
\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
136 $this->setVariable('current_page', $current_page);
\r
142 * @desc This function sets the data for the comment array
\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
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
154 function setVariable($string, $value){
\r
157 if ($value==APPROVED || $value==DISAPPROVED || $value==POSTED_NEW){
\r
158 $this->{$string}=$value;
\r
161 case 'current_page':
\r
164 if (is_int($value)){
\r
165 $this->{$string}=$value;
\r
167 parent::storeError("value ".$string." is not integer");
\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
175 parent::storeError("value ".$string." is not boolean");
\r