99157ad41998a12b1e59736a0dc953ed96e21f60
[atutor.git] / docs / mods / _standard / photos / addComment.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010                                             */
6 /* Inclusive Design Institute                                          */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
9 /* This program is free software. You can redistribute it and/or           */
10 /* modify it under the terms of the GNU General Public License             */
11 /* as published by the Free Software Foundation.                                           */
12 /***********************************************************************/
13 // $Id$
14 $_user_location = 'public';
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 include (AT_PA_INCLUDE.'classes/PhotoAlbum.class.php');
18
19 //quit if this is not a member
20 if(!(isset($_SESSION['member_id']) && $_SESSION['member_id'] > 0)){
21         $msg->addError('ACCESS_DENIED');
22         header('Location: index.php');
23         exit;
24 }
25
26 //check what comment this is for. Album or Photo.
27 $pid = intval($_POST['pid']);
28 $aid = intval($_POST['aid']);
29
30 if (isset($_POST['pid']) && $pid>0){
31         $isPhoto = true;
32         $id = $pid;
33 } else {
34         $isPhoto = false;
35         $id = $aid;
36 }
37
38
39 //Error checking
40 if (trim($_POST['comment']) == ''){
41         //if comment is empty
42         $msg->addError('PA_EMPTY_COMMENT'); //sql
43 } else {
44         $pa = new PhotoAlbum();
45         $result = $pa->addComment($id, $_POST['comment'], $_SESSION['member_id'], $isPhoto);
46
47         if ($result){
48                 //TODO: AJAX
49                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
50         } else {
51                 $msg->addError('PA_ADD_COMMENT_FAILED'); //sql
52         }
53 }
54
55 if ($isPhoto){
56         header('Location: photo.php?pid='.$pid.SEP.'aid='.$aid);
57 } else {
58         header('Location: albums.php?id='.$aid);
59 }
60 exit;
61 ?>