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 stores or updates the image / comment data in the database
\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 define('AT_INCLUDE_PATH', '../../../include/');
\r
25 require_once(AT_INCLUDE_PATH.'vitals.inc.php');
\r
26 $_custom_css = $_base_path . 'mods/photo_album/module.css'; // use a custom stylesheet
\r
27 require_once (AT_INCLUDE_PATH.'header.inc.php');
\r
30 require_once ('../define.php');
\r
31 require_once ('../include/general_func.php');
\r
32 require_once ('../include/data_func.php');
\r
33 $config_mode=get_config_mode($_SESSION['pa']['course_id']);
\r
35 if (isset($_POST['cancel_image'])){
\r
36 if ($_SESSION['pa']['mode']=='add'){
\r
37 if ($_SESSION['pa']['administrator_mode']==true){
\r
38 $action='admin_image_list.php';
\r
39 } else if ($_SESSION['pa']['instructor_mode']==true){
\r
40 $action='instructor_image.php';
\r
42 $action='index.php';
\r
44 } else if ($_SESSION['pa']['mode']=='edit'){
\r
45 if ($_SESSION['pa']['my_pic_mode']==true){
\r
46 $action='my_photo.php';
\r
48 $action='view.php?image_id='.$_SESSION['pa']['image_id'];
\r
51 $msg->addError('pa_var_unauthorized');
\r
55 } else if ($_POST['cancel_comment']){
\r
56 $action='view.php?image_id='.$_SESSION['pa']['image_id'];
\r
58 } else if ((isset($_POST['submit'])) && ($_SESSION['pa']['mode']=='add')){ //mode add
\r
59 if ($_SESSION['pa']['completed']==true){
\r
62 $goback_url='handler/add_begin.php';
\r
63 if (($_SESSION['pa']['choose']==IMAGE) && ($_SESSION['pa']['image_uploaded']==true)){
\r
64 $store_path=ALBUM_IMAGE_STORE.$_SESSION['login'].'/';
\r
65 $_SESSION['pa']['title']=$_POST['title'];
\r
66 $_SESSION['pa']['alt']=$_POST['alt'];
\r
67 $_SESSION['pa']['description']=$_POST['description'];
\r
68 unset($_SESSION['pa']['error']);
\r
69 if ((empty($_POST['title']) || (strlen($_POST['title'])==0))){
\r
70 $_SESSION['pa']['error']['title']=true;
\r
71 $msg->addError('pa_user_title_empty');
\r
72 redirect($goback_url);
\r
73 } else if (is_admin_for_course() && (empty($_POST['alt']) || (strlen($_POST['alt'])==0))){
\r
74 $_SESSION['pa']['error']['alt']=true;
\r
75 $msg->addError('pa_user_alt_empty');
\r
76 redirect($goback_url);
\r
77 } else { //input has no error
\r
78 $view_image_name=modify_image_name($store_path, $_SESSION['pa']['view_image_name']);
\r
79 $thumb_image_name=modify_image_name($store_path, $_SESSION['pa']['thumb_image_name']);
\r
80 $store_dir=AT_CONTENT_DIR.$store_path;
\r
81 if (!is_dir($store_dir)){
\r
82 if (!@mkdir($store_dir)){
\r
83 $msg->addError('pa_func_mkdir');
\r
86 chmod ($store_dir, 0757);
\r
89 if (!copy(AT_CONTENT_DIR.$_SESSION['pa']['temp_folder'].$_SESSION['pa']['view_image_name'], AT_CONTENT_DIR.$store_path.$view_image_name)){
\r
90 $msg->addError('pa_func_copy');
\r
93 if (!copy(AT_CONTENT_DIR.$_SESSION['pa']['temp_folder'].$_SESSION['pa']['thumb_image_name'], AT_CONTENT_DIR.$store_path.$thumb_image_name)){
\r
94 $msg->addError('pa_func_copy');
\r
98 if (is_admin_for_course()==true){
\r
99 $store=store_image_in_database($_SESSION['pa']['course_id'], $_SESSION['login'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $view_image_name, $store_path, $thumb_image_name, htmlspecialchars($_SESSION['pa']['alt']), APPROVED);
\r
100 } else if ($config_mode==CONFIG_ENABLED){ //student image add when config is enabled
\r
101 $store=store_image_in_database($_SESSION['pa']['course_id'], $_SESSION['login'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $view_image_name, $store_path, $thumb_image_name, htmlspecialchars($_SESSION['pa']['title']), POSTED_NEW);
\r
102 } else { //student image add when config is disabled
\r
103 $store=store_image_in_database($_SESSION['pa']['course_id'], $_SESSION['login'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $view_image_name, $store_path, $thumb_image_name, htmlspecialchars($_SESSION['pa']['title']), APPROVED);
\r
107 $msg->addError('pa_func_store_image_in_database');
\r
110 $_SESSION['pa']['completed']=true;
\r
111 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
112 $msg->addFeedback('pa_add_image_success_config_disabled');
\r
113 } else if ($config_mode==CONFIG_ENABLED){
\r
114 $msg->addFeedback('pa_add_image_success_config_enabled');
\r
119 } else if ($_SESSION['pa']['choose']==COMMENT){ //store comment
\r
120 $comment=trim($_POST['comment']);
\r
121 if (empty($comment)){
\r
122 $_SESSION['pa']['error']['comment']=true;
\r
123 $msg->addError('pa_user_comment_empty');
\r
124 redirect($goback_url);
\r
126 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
127 $store=store_comment_in_database($_SESSION['pa']['course_id'], $_SESSION['login'], htmlspecialchars($_POST['comment']), $_SESSION['pa']['image_id'], APPROVED);
\r
129 $store=store_comment_in_database($_SESSION['pa']['course_id'], $_SESSION['login'], htmlspecialchars($_POST['comment']), $_SESSION['pa']['image_id'], POSTED_NEW);
\r
133 $_SESSION['pa']['completed']=true;
\r
134 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
135 $msg->addFeedback('pa_add_comment_success_config_disable');
\r
136 } else if ($config_mode==CONFIG_ENABLED){
\r
137 $msg->addFeedback('pa_add_comment_success_config_enabled');
\r
139 redirect('view.php?image_id='.$_SESSION['pa']['image_id']);
\r
141 $msg->addError('pa_func_store_comment_in_database');
\r
145 $msg->addError('pa_var_unauthorized');
\r
151 } else if (($_SESSION['pa']['mode']=='edit')&& (isset($_POST['submit']))){
\r
152 if ($_SESSION['pa']['completed']==true){
\r
155 $goback_url='handler/edit_begin.php';
\r
156 if (($_SESSION['pa']['choose']==IMAGE) && ($_SESSION['pa']['image_checked']==true)){
\r
157 $_SESSION['pa']['description']=$_POST['description'];
\r
158 $_SESSION['pa']['title']=$_POST['title'];
\r
159 $_SESSION['pa']['alt']=$_POST['alt'];
\r
160 if ((empty($_SESSION['pa']['title'])) || ((strlen($_SESSION['pa']['title']))==0)){
\r
161 $_SESSION['pa']['error']['title']=true;
\r
162 $msg->addError('pa_user_title_empty');
\r
163 redirect($goback_url);
\r
164 } else if (is_admin_for_course() && (empty($_SESSION['pa']['alt']) || (strlen($_SESSION['pa']['alt'])==0))){
\r
165 $msg->addError('pa_user_alt_empty');
\r
166 $_SESSION['pa']['error']['alt']=true;
\r
167 redirect($goback_url);
\r
169 if ($_SESSION['pa']['image_copy_required']==true){
\r
170 $data_array=get_single_data(IMAGE, $_SESSION['pa']['image_id'], $_SESSION['pa']['course_id']);
\r
171 $store_dir=AT_CONTENT_DIR.ALBUM_IMAGE_STORE.$data_array['login'].'/';
\r
172 $old_view_image=AT_CONTENT_DIR.$data_array['location'].$data_array['view_image_name'];
\r
173 $old_thumb_image=AT_CONTENT_DIR.$data_array['location'].$data_array['thumb_image_name'];
\r
174 $image_view_name=modify_image_name($data_array['location'], $_SESSION['pa']['view_image_name']);
\r
175 $image_thumb_name=modify_image_name($data_array['location'], $_SESSION['pa']['thumb_image_name']);
\r
176 if (!copy(AT_CONTENT_DIR.$_SESSION['pa']['temp_folder'].$_SESSION['pa']['view_image_name'], $store_dir.$image_view_name)){
\r
177 $msg->addError('pa_func_copy');
\r
180 if (!copy(AT_CONTENT_DIR.$_SESSION['pa']['temp_folder'].$_SESSION['pa']['thumb_image_name'], $store_dir.$image_thumb_name)){
\r
181 $msg->addError('pa_func_copy');
\r
184 if (!@unlink($old_view_image)){
\r
185 $msg->addError('pa_func_unlink');
\r
187 if (!@unlink($old_thumb_image)){
\r
188 $msg->addError('pa_func_unlink');
\r
191 if (is_admin_for_course() || $config_mode==CONFIG_DISABLED){
\r
192 $update=update_image_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $image_view_name, $_SESSION['pa']['image_id'], $image_thumb_name, htmlspecialchars($_SESSION['pa']['alt']), APPROVED);
\r
194 $update=update_image_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $image_view_name, $_SESSION['pa']['image_id'], $image_thumb_name, htmlspecialchars($_SESSION['pa']['title']), POSTED_NEW);
\r
197 if ($update==false){
\r
198 $msg->addError('pa_func_update_image_in_database');
\r
201 $_SESSION['pa']['completed']=true;
\r
202 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
203 $msg->addFeedback('pa_edit_image_success_config_disabled');
\r
204 } else if ($config_mode==CONFIG_ENABLED){
\r
205 $msg->addFeedback('pa_edit_image_success_config_enabled');
\r
209 } else { //image copy is not required, so just update the database with title and description
\r
210 $data_array=get_single_data(IMAGE, $_SESSION['pa']['image_id'], $_SESSION['pa']['course_id']);
\r
211 if (is_admin_for_course() || $config_mode==CONFIG_DISABLED){
\r
212 $update=update_image_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $data_array['view_image_name'], $_SESSION['pa']['image_id'], $data_array['thumb_image_name'], htmlspecialchars($_SESSION['pa']['alt']), APPROVED);
\r
214 $update=update_image_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_SESSION['pa']['title']), htmlspecialchars($_SESSION['pa']['description']), $data_array['view_image_name'], $_SESSION['pa']['image_id'], $data_array['thumb_image_name'], htmlspecialchars($_SESSION['pa']['title']), POSTED_NEW);
\r
217 if ($update==false){
\r
218 $msg->addError('pa_func_update_image_in_database');
\r
221 $_SESSION['pa']['completed']=true;
\r
222 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
223 $msg->addFeedback('pa_edit_image_success_config_disabled');
\r
224 } else if ($config_mode==CONFIG_ENABLED){
\r
225 $msg->addFeedback('pa_edit_image_success_config_enabled');
\r
230 } else if ($_SESSION['pa']['choose']==COMMENT){
\r
231 $_SESSION['pa']['comment_checked']=true;
\r
232 $comment=trim($_POST['comment']);
\r
233 if (empty($comment)){
\r
234 $_SESSION['pa']['error']['comment']=true;
\r
235 $msg->addError('pa_user_comment_empty');
\r
236 redirect($goback_url);
\r
239 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
240 $update=update_comment_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_POST['comment']), $_SESSION['pa']['image_id'], $_SESSION['pa']['comment_id'], APPROVED);
\r
242 $update=update_comment_in_database($_SESSION['pa']['course_id'], htmlspecialchars($_POST['comment']), $_SESSION['pa']['image_id'], $_SESSION['pa']['comment_id'], POSTED_NEW);
\r
245 if ($update==false){
\r
246 $msg->addError('pa_func_update_comment_in_database');
\r
249 if ((is_admin_for_course()==true) || ($config_mode==CONFIG_DISABLED)){
\r
250 $msg->addFeedback('pa_edit_comment_success_config_disable');
\r
251 } else if ($config_mode==CONFIG_ENABLED){
\r
252 $msg->addFeedback('pa_edit_comment_success_config_enabled');
\r
254 redirect('view.php?image_id='.$_SESSION['pa']['image_id']);
\r
257 $msg->addError('pa_var_unauthorized');
\r
262 $msg->addError('pa_var_unauthorized');
\r
268 <?php require_once(AT_INCLUDE_PATH.'footer.inc.php'); ?>