ea7466b11d18d7be3c280b30f9a135e51a95d2c4
[atutor.git] / docs / mods / _standard / photos / create_album.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 //$_custom_css = $_base_path . AT_PA_BASENAME . 'module.css'; // use a custom stylesheet
19
20 //quit if this is not a member
21 if(!(isset($_SESSION['member_id']) && $_SESSION['member_id'] > 0)){
22         $msg->addError('ACCESS_DENIED');
23         header('Location: index.php');
24         exit;
25 }
26
27 //instantiate obj
28 $pa = new PhotoAlbum();
29
30 //handles submit
31 if(isset($_POST['submit'])){
32         //TODO: Check if the user have permission to add a course album
33         //              TA and Instructors can
34         if (isset($_POST['album_type'])){
35                 $album_type     = (intval($_POST['album_type'])==AT_PA_TYPE_MY_ALBUM)?AT_PA_TYPE_MY_ALBUM:AT_PA_TYPE_COURSE_ALBUM;
36         } else {
37                 //default is "my album" 'cause normally user can't create course album.
38                 $album_type     = AT_PA_TYPE_MY_ALBUM;
39         }
40
41         //private or shared album?
42         if (isset($_POST['album_permission'])){
43                 $album_permission = ($_POST['album_permission']==AT_PA_SHARED_ALBUM)?AT_PA_SHARED_ALBUM:AT_PA_PRIVATE_ALBUM;
44         } else {
45                 $album_permission = AT_PA_PRIVATE_ALBUM;
46         }
47
48         if (isset($_POST['album_name']) && $_POST['album_name']!=''){
49                 //TODO: photo_id = 0, should default to use the first one after multi-file uploader works
50                 $result = $pa->createAlbum($_POST['album_name'], $_POST['album_location'], $_POST['album_description'], $album_type, $album_permission, $_SESSION['member_id'], 0);
51
52                 if (!$result){
53                         //TODO: sql failure.
54                         $msg->addError('PA_CREATE_ALBUM_FAILED');
55                 }
56         } else {
57                 //album name can't be empty
58                 //TODO: user input failure
59                 $msg->addError('PA_EMTPY_ALBUM_NAME');
60         }
61         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
62
63         if($_POST['album_type'] == AT_PA_TYPE_COURSE_ALBUM){
64                 header('Location: course_albums.php');
65                 exit;
66         }else{
67                 header('Location: index.php');
68                 exit;
69         
70         }
71
72 } elseif (isset($_POST['cancel'])){
73         $msg->addFeedback('CANCELLED');
74         header('Location: '.AT_PA_BASE);
75         exit;
76 }
77
78 include (AT_INCLUDE_PATH.'header.inc.php'); 
79 $savant->display('photos/pa_create_album.tmpl.php');
80 include (AT_INCLUDE_PATH.'footer.inc.php'); 
81 ?>