move code up one directory
[atutor.git] / mods / _standard / photos / edit_photos.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
20 $aid = intval($_GET['aid']);
21 $pid = intval($_GET['pid']);
22 if(isset($_POST['aid'])){
23         $aid = intval($_POST['aid']);
24 }
25 if(isset($_POST['pid'])){
26         $pid = intval($_POST['pid']);
27 }
28
29 //initialization
30 $pa = new PhotoAlbum($aid);
31
32 //validation
33 if(!($pa->checkPhotoPriv($pid, $_SESSION['member_id']) || $pa->checkAlbumPriv($_SESSION['member_id']))){
34         $msg->addError("ACCESS_DENIED");
35                 header('location: index.php');
36                 exit;
37
38
39 //get details
40 if ($pid > 0){
41         //get only 1 photo
42         $photos = array($pa->getPhotoInfo($pid));
43 } else {
44         $photos = $pa->getAlbumPhotos();
45 }
46 $album_info = $pa->getAlbumInfo();
47
48 $isadmin   = FALSE;
49
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 if ($isadmin) {
57         $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['parent']   = AT_PA_BASENAME.'index_admin.php';
58
59 }
60
61 //handle organize
62 if(isset($_GET['org'])){
63         $_custom_head .= '<script type="text/javascript" src="'.AT_PA_BASENAME.'include/imageReorderer.js"></script>';
64         //$_custom_css = $_base_path . AT_PA_BASENAME . 'module.css'; // use a custom stylesheet
65         //reset pages/submenu
66         $_pages[AT_PA_BASENAME.'edit_photos.php']['title'] = _AT('pa_organize_photos');
67
68         if (isset($_POST['submit'])){
69                 foreach($photos as $index=>$photo_array){
70                         $ordering = $_POST['image_'.$photo_array['id']];
71                         if(isset($ordering)){
72                                 $result = $pa->editPhotoOrder($photo_array['id'], $ordering);
73                                 if (!$result){
74                                         $msg->addError('PA_EDIT_PHOTO_FAILED');
75                                 }
76                         }
77                 }
78                 exit;
79         }
80         include (AT_INCLUDE_PATH.'header.inc.php');
81         $savant->assign('album_info', $album_info);
82         $savant->assign('photos', $photos);
83         $savant->display('photos/pa_organize_photos.tmpl.php');
84         include (AT_INCLUDE_PATH.'footer.inc.php'); 
85         exit;
86 }
87
88 //printer header iff this is not a POST request 
89 //a hack to avoid 'header already sent...' error.
90 if (!isset($_POST['submit']) && !isset($_POST['cancel'])){
91         //$_custom_css = $_base_path . AT_PA_BASENAME . 'module.css'; // use a custom stylesheet
92         require(AT_INCLUDE_PATH.'header.inc.php'); 
93         $msg->printAll();
94 }
95 require(AT_PA_INCLUDE.'edit_photos.inc.php');
96 require(AT_INCLUDE_PATH.'footer.inc.php'); 
97 ?>