10257e638d7d10aacf269613fd94683d60d618f4
[atutor.git] / mods / photos / edit_album.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2009                                                                                         */
6 /* Adaptive Technology Resource Centre / Inclusive Design Institution  */
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 include (AT_PA_INCLUDE.'lib.inc.php');
19 $_custom_css = $_base_path . AT_PA_BASENAME . 'module.css'; // use a custom stylesheet
20
21 $aid = intval($_REQUEST['id']);
22 $pa = new PhotoAlbum($aid);
23
24 if (!$pa->checkAlbumPriv($_SESSION['member_id'])){
25         $msg->addError('ACCESS_DENIED');
26         header('location: index.php');
27         exit;
28 }
29
30 $album_info = $pa->getAlbumInfo();
31
32 //handle Edit album info.
33 if(isset($_POST['submit'])){
34         $pa = new PhotoAlbum($_POST['aid']);    //new object
35         if (isset($_POST['album_type'])){
36                 $album_type     = (intval($_POST['album_type'])==AT_PA_TYPE_MY_ALBUM)?AT_PA_TYPE_MY_ALBUM:AT_PA_TYPE_COURSE_ALBUM;
37         } else {
38                 //default is "my album" 'cause normally user can't create course album.
39                 $album_type     = AT_PA_TYPE_MY_ALBUM;
40         }
41
42         //private or shared album?
43         if (isset($_POST['album_permission'])){
44                 $album_permission = ($_POST['album_permission']==AT_PA_SHARED_ALBUM)?AT_PA_SHARED_ALBUM:AT_PA_PRIVATE_ALBUM;
45         } else {
46                 $album_permission = AT_PA_PRIVATE_ALBUM;
47         }
48
49         if (isset($_POST['album_name']) && $_POST['album_name']!=''){
50                 //TODO: photo_id = 0, should default to use the first one after multi-file uploader works
51                 $result = $pa->editAlbum($_POST['album_name'], $_POST['album_location'], $_POST['album_description'], $album_type, $album_permission);
52
53                 if (!$result){
54                         $msg->addError('PA_EDIT_ALBUM_FAILED');
55                 }
56         } else {
57                 //album name can't be empty
58                 $msg->addError('EMPTY_ALBUM_NAME');
59
60         }
61         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
62         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
63                 //if admin
64                 header('Location: index_admin.php');
65                 exit;
66         } 
67         //header('Location: albums.php?id='.intval($_POST['aid']));
68         header('Location: index.php');
69         exit;
70 } elseif (isset($_POST['cancel'])){
71         $msg->addFeedback('CANCELLED');
72         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
73                 //if admin
74                 header('Location: index_admin.php');
75                 exit;
76         }
77         header('Location: '.AT_PA_BASE);
78         exit;
79 }
80
81
82 include (AT_INCLUDE_PATH.'header.inc.php');
83 $savant->assign('album_info', $album_info);
84 $savant->display('pa_edit_album.tmpl.php');
85 include (AT_INCLUDE_PATH.'footer.inc.php'); 
86 ?>