41c70260b80fdfdffa6ee07763654b2df484a1c4
[atutor.git] / docs / mods / _standard / photos / photo.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 $_custom_head .= '<script type="text/javascript" src="'.AT_PA_BASENAME.'include/imageReorderer.js"></script>';
21
22 $aid = intval($_GET['aid']);
23 $pid = intval($_GET['pid']);
24
25 //init
26 $pa = new PhotoAlbum($aid);
27
28 //get details
29 $info = $pa->getAlbumInfo();
30 $photos = $pa->getAlbumPhotos();
31 $photo_info = $pa->getPhotoInfo($pid);
32 $comments = $pa->getComments($pid, true);
33
34 //Set pages/submenu
35 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['title']    = _AT('pa_albums') .' - '.$info['name'];
36 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['parent']   = AT_PA_BASENAME.'index.php';
37 $_pages[AT_PA_BASENAME.'albums.php?id='.$aid]['children']  = array(
38                                                                                                                 AT_PA_BASENAME.'photo.php',
39                                                                                                         );
40 $_pages[AT_PA_BASENAME.'photo.php']['parent'] = AT_PA_BASENAME.'albums.php?id='.$aid;
41
42 //TODO: Validate users, using permission and course album control.
43 if ($info['member_id'] != $_SESSION['member_id'] && $info['type_id']!=AT_PA_TYPE_PERSONAL){
44         $visible_albums = $pa->getAlbums($_SESSION['member_id'], $info['type_id']);
45         if(!isset($visible_albums[$aid]) && $info['permission']==AT_PA_PRIVATE_ALBUM){
46                 //TODO msg;
47                 $msg->addError("ACCESS_DENIED");
48                 header('location: index.php');
49                 exit;
50         }
51 }
52
53 if($pa->checkPhotoPriv($pid, $_SESSION['member_id']) || $pa->checkAlbumPriv($_SESSION['member_id'])){
54         $action_permission = true;
55 } else {
56         $action_permission = false;
57 }
58
59 //run a quick query to get the next and previous id
60 if (sizeof($photos) > 1){
61         $sql = 'SELECT id, ordering FROM '.TABLE_PREFIX.'pa_photos WHERE album_id='.$aid.' AND (ordering='.($photo_info['ordering']-1).' OR ordering='.($photo_info['ordering']+1).') ORDER BY ordering';
62         $result = mysql_query($sql, $db);
63         if ($result){
64                 $prev = mysql_fetch_assoc($result);
65                 $next = mysql_fetch_assoc($result);
66
67                 //then reassign prev and next
68                 if (empty($next)){
69                         if ($prev['ordering'] > $photo_info['ordering']){
70                                 $next = $prev;
71                                 unset($prev);
72                         } else {
73                                 unset($next);
74                         }
75                 }
76         }
77 }
78
79 include (AT_INCLUDE_PATH.'header.inc.php');
80 $savant->assign('total_photos', sizeof($photos));
81 $savant->assign('prev', $prev);
82 $savant->assign('next', $next);
83 $savant->assign('aid', $aid);
84 $savant->assign('photo_info', $photo_info);
85 $savant->assign('comments', $comments);
86 $savant->assign('action_permission', $action_permission);
87 $savant->display('photos/pa_photo.tmpl.php');
88 include (AT_INCLUDE_PATH.'footer.inc.php'); 
89 ?>