372d31e9666ff39cb8f719d7377d122586e7bbf1
[atutor.git] / docs / mods / _standard / photos / edit_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 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 //Set pages/submenu
31 if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
32         //this is admin
33         $_pages[AT_PA_BASENAME.'edit_album.php']['parent']   = AT_PA_BASENAME.'index_admin.php';
34
35 }
36
37 $album_info = $pa->getAlbumInfo();
38
39 //handle Edit album info.
40 if(isset($_POST['submit'])){
41         $pa = new PhotoAlbum($_POST['aid']);    //new object
42         if (isset($_POST['album_type'])){
43                 $album_type     = (intval($_POST['album_type'])==AT_PA_TYPE_MY_ALBUM)?AT_PA_TYPE_MY_ALBUM:AT_PA_TYPE_COURSE_ALBUM;
44         } else {
45                 //default is "my album" 'cause normally user can't create course album.
46                 $album_type     = AT_PA_TYPE_MY_ALBUM;
47         }
48
49         //private or shared album?
50         if (isset($_POST['album_permission'])){
51                 $album_permission = ($_POST['album_permission']==AT_PA_SHARED_ALBUM)?AT_PA_SHARED_ALBUM:AT_PA_PRIVATE_ALBUM;
52         } else {
53                 $album_permission = AT_PA_PRIVATE_ALBUM;
54         }
55
56         if (isset($_POST['album_name']) && $_POST['album_name']!=''){
57                 //TODO: photo_id = 0, should default to use the first one after multi-file uploader works
58                 $result = $pa->editAlbum($_POST['album_name'], $_POST['album_location'], $_POST['album_description'], $album_type, $album_permission);
59
60                 if (!$result){
61                         $msg->addError('PA_EDIT_ALBUM_FAILED');
62                 }
63         } else {
64                 //album name can't be empty
65                 $msg->addError('EMPTY_ALBUM_NAME');
66
67         }
68         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
69         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
70                 //if admin
71                 header('Location: index_admin.php');
72                 exit;
73         } 
74         //header('Location: albums.php?id='.intval($_POST['aid']));
75         header('Location: index.php');
76         exit;
77 } elseif (isset($_POST['cancel'])){
78         $msg->addFeedback('CANCELLED');
79         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
80                 //if admin
81                 header('Location: index_admin.php');
82                 exit;
83         }
84         header('Location: '.AT_PA_BASE);
85         exit;
86 }
87
88
89 include (AT_INCLUDE_PATH.'header.inc.php');
90 $savant->assign('album_info', $album_info);
91 $savant->display('photos/pa_edit_album.tmpl.php');
92 include (AT_INCLUDE_PATH.'footer.inc.php'); 
93 ?>