1300d73c7c56ab087601043d26f2eede823dd3da
[atutor.git] / mods / photos / edit_photos.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($_GET['aid']);
22 $pid = intval($_GET['pid']);
23 if(isset($_POST['aid'])){
24         $aid = intval($_POST['aid']);
25 }
26 if(isset($_POST['pid'])){
27         $pid = intval($_POST['pid']);
28 }
29
30 //initialization
31 $pa = new PhotoAlbum($aid);
32
33 //validation
34 if(!($pa->checkPhotoPriv($pid, $_SESSION['member_id']) || $pa->checkAlbumPriv($_SESSION['member_id']))){
35         $msg->addError("ACCESS_DENIED");
36                 header('location: index.php');
37                 exit;
38
39
40 //get details
41 if ($pid > 0){
42         //get only 1 photo
43         $photos = array($pa->getPhotoInfo($pid));
44 } else {
45         $photos = $pa->getAlbumPhotos();
46 }
47 $album_info = $pa->getAlbumInfo();
48
49 //Set pages/submenu
50 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['title']    = _AT('pa_albums') .' - '.$album_info['name'];
51 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['parent']   = AT_PA_BASENAME.'index.php';
52 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['children']  = array(
53                                                                                                                 AT_PA_BASENAME.'edit_photos.php',
54                                                                                                         );
55 $_pages[AT_PA_BASENAME.'edit_photos.php']['parent'] = AT_PA_BASENAME.'albums.php?id='.$aid;
56
57
58 //handle organize
59 if(isset($_GET['org'])){
60         $_custom_head .= '<script type="text/javascript" src="'.AT_PA_BASENAME.'include/imageReorderer.js"></script>';
61         //reset pages/submenu
62         $_pages[AT_PA_BASENAME.'edit_photos.php']['title'] = _AT('pa_organize_photos');
63
64         if (isset($_POST['submit'])){
65                 foreach($photos as $index=>$photo_array){
66                         $ordering = $_POST['image_'.$photo_array['id']];
67                         if(isset($ordering)){
68                                 $result = $pa->editPhotoOrder($photo_array['id'], $ordering);
69                                 if (!$result){
70                                         $msg->addError('PA_EDIT_PHOTO_FAILED');
71                                 }
72                         }
73                 }
74                 exit;
75         }
76         include (AT_INCLUDE_PATH.'header.inc.php');
77         $savant->assign('album_info', $album_info);
78         $savant->assign('photos', $photos);
79         $savant->display('pa_organize_photos.tmpl.php');
80         include (AT_INCLUDE_PATH.'footer.inc.php'); 
81         exit;
82 }
83
84 //handle Edit.
85 if (isset($_POST['submit'])){
86         //update photo description
87         foreach($photos as $index=>$photo_array){
88                 $alt_text = $_POST['alt_text_'.$photo_array['id']];
89                 $description = $_POST['description_'.$photo_array['id']];
90                 $deletion = $_POST['delete_'.$photo_array['id']];
91                 //don't have to update description if it's deleted
92                 if (isset($deletion)){
93                         $pa->deletePhoto($photo_array['id']);
94                 } elseif (isset($description)){
95                         $result = $pa->editPhoto($photo_array['id'], $description, $alt_text);
96                         if (!$result){
97                                 //TODO: sql error
98                                 $msg->addError('PA_EDIT_PHOTO_FAILED');
99                         }
100                 }
101         }
102
103         //update photo album.
104         if (isset($_POST['album_cover'])){
105                 $result = $pa->editAlbumCover($_POST['album_cover']);
106                 if (!$result){
107                         //albumcover error.
108                         $msg->addError('PA_EDIT_PHOTO_FAILED');
109                 }
110         }
111
112         //if no errors
113         if ($_POST['submit'] == 'ajax'){
114                 //ajax, return 200 status
115                 header('HTTP/1.1 200 OK');
116                 exit;
117         }
118         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
119         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
120                 //if admin
121                 header('Location: index_admin.php');
122                 exit;
123         } 
124         header('Location: albums.php?id='.$aid);
125         exit;
126 } elseif (isset($_POST['cancel'])){
127         $msg->addFeedback('CANCELLED');
128         if (admin_authenticate(AT_ADMIN_PRIV_PHOTO_ALBUM, true)) {
129                 //if admin
130                 header('Location: index_admin.php');
131                 exit;
132         }
133         header('Location: albums.php?id='.$aid);
134         exit;
135 }
136
137
138 include (AT_INCLUDE_PATH.'header.inc.php');
139 $savant->assign('album_info', $album_info);
140 $savant->assign('photos', $photos);
141 $savant->display('pa_edit_photos.tmpl.php');
142 include (AT_INCLUDE_PATH.'footer.inc.php'); 
143 ?>