553d8bcc0395591cdb9069320ea635aa9af151ba
[atutor.git] / docs / mods / _standard / photos / include / edit_photos.inc.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
15 if($isadmin){
16         include (AT_PA_INCLUDE.'classes/PhotoAlbum.class.php');
17         include (AT_PA_INCLUDE.'lib.inc.php');
18
19         $aid = intval($_GET['aid']);
20         $pid = intval($_GET['pid']);
21         if(isset($_POST['aid'])){
22                 $aid = intval($_POST['aid']);
23         }
24         if(isset($_POST['pid'])){
25                 $pid = intval($_POST['pid']);
26         }
27
28         //initialization
29         $pa = new PhotoAlbum($aid);
30
31         //validation
32         if(!($pa->checkPhotoPriv($pid, $_SESSION['member_id']) || $pa->checkAlbumPriv($_SESSION['member_id']))){
33                 $msg->addError("ACCESS_DENIED");
34                         header('location: index.php');
35                         exit;
36         } 
37
38         //get details
39         if ($pid > 0){
40                 //get only 1 photo
41                 $photos = array($pa->getPhotoInfo($pid));
42         } else {
43                 $photos = $pa->getAlbumPhotos();
44         }
45         $album_info = $pa->getAlbumInfo();
46 }
47 //Set pages/submenu
48 /*
49 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['title']    = _AT('pa_albums') .' - '.$album_info['name'];
50 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['parent']   = AT_PA_BASENAME.'index.php';
51 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['children']  = array(
52                                                                                                                 AT_PA_BASENAME.'edit_photos.php',
53                                                                                                         );
54 $_pages[AT_PA_BASENAME.'edit_photos.php']['parent'] = AT_PA_BASENAME.'albums.php?id='.$aid;
55 if ($isadmin) {
56         $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['parent']   = AT_PA_BASENAME.'index_admin.php';
57
58 }
59 */
60
61 //handle Edit.
62 if (isset($_POST['submit'])){
63         //update photo description
64         foreach($photos as $index=>$photo_array){
65                 $alt_text = $_POST['alt_text_'.$photo_array['id']];
66                 $description = $_POST['description_'.$photo_array['id']];
67                 $deletion = $_POST['delete_'.$photo_array['id']];
68                 //don't have to update description if it's deleted
69                 if (isset($deletion)){
70                         $pa->deletePhoto($photo_array['id']);
71                 } elseif (isset($description)){
72                         $result = $pa->editPhoto($photo_array['id'], $description, $alt_text);
73                         if (!$result){
74                                 //TODO: sql error
75                                 $msg->addError('PA_EDIT_PHOTO_FAILED');
76                         }
77                 }
78         }
79
80         //update photo album.
81         if (isset($_POST['album_cover'])){
82                 $result = $pa->editAlbumCover($_POST['album_cover']);
83                 if (!$result){
84                         //albumcover error.
85                         $msg->addError('PA_EDIT_PHOTO_FAILED');
86                 }
87         }
88
89         //if no errors
90         if ($_POST['submit'] == 'ajax'){
91                 //ajax, return 200 status
92                 header('HTTP/1.1 200 OK');
93                 exit;
94         }
95         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
96         if ($isadmin) {
97                 //if admin
98                 header('Location: '.AT_PA_INCLUDE.'../index_admin.php');
99                 exit;
100         } 
101         header('Location: albums.php?id='.$aid);
102         exit;
103 } elseif (isset($_POST['cancel'])){
104         $msg->addFeedback('CANCELLED');
105         if ($isadmin) {
106                 //if admin
107                 header('Location: '.AT_PA_INCLUDE.'../index_admin.php');
108                 exit;
109         }
110         header('Location: albums.php?id='.$aid);
111         exit;
112 }
113
114 //template goes here
115 $savant->assign('album_info', $album_info);
116 $savant->assign('photos', $photos);
117 $savant->display('photos/pa_edit_photos.tmpl.php');
118 ?>