3b2be5c25d788d3e0f008f48c6d6a817ec261aa2
[atutor.git] / mods / photos / profile_album.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.'lib.inc.php');
18 include (AT_PA_INCLUDE.'classes/PhotoAlbum.class.php');
19 $_custom_css = $_base_path . AT_PA_BASENAME . 'module.css'; // use a custom stylesheet
20 $_custom_head .= '<script src="'.$_base_path . AT_PA_BASENAME . 'include/ajaxupload.js" type="text/javascript"></script>';
21 $member_id = intval($_GET['member_id']);
22 $member_id = ($member_id==0)? $_SESSION['member_id']: $member_id;
23
24 //run a check to see if any personal album exists, if not, create one.
25 $sql = 'SELECT * FROM '.TABLE_PREFIX.'pa_albums WHERE member_id='.$_SESSION['member_id'].' AND type_id='.AT_PA_TYPE_PERSONAL;
26 $result = mysql_query($sql, $db);
27 if ($result){
28         $rows = mysql_num_rows($result);
29         if ($rows==0){
30                 //create one.
31                 $pa = new PhotoAlbum();
32                 $result = $pa->createAlbum(_AT('pa_profile_album'), '', '', AT_PA_TYPE_PERSONAL, AT_PA_PRIVATE_ALBUM, $_SESSION['member_id']);
33                 $id = mysql_insert_id();
34         } else {
35                 $row = mysql_fetch_assoc($result);      //album info.
36                 $id = $row['id'];
37         }
38 }
39
40 //instantiate obj
41 $pa = new PhotoAlbum($id);
42 $info = $pa->getAlbumInfo();
43
44 //paginator settings
45 $page = intval($_GET['p']);
46 $photos_count = sizeof($pa->getAlbumPhotos());
47 $last_page = ceil($photos_count/AT_PA_PHOTOS_PER_PAGE);
48
49 if (!$page || $page < 0) {
50         $page = 1;
51 } elseif ($page > $last_page){
52         $page = $last_page;
53 }
54
55 $count  = (($page-1) * AT_PA_PHOTOS_PER_PAGE) + 1;
56 $offset = ($page-1) * AT_PA_PHOTOS_PER_PAGE;
57
58 //get details
59 $photos = $pa->getAlbumPhotos($offset);
60 $comments = $pa->getComments($id, false);
61 //TODO: Can improve performance by adding this to a session variable
62 $memory_usage = memoryUsage($_SESSION['member_id']);    
63
64 include (AT_INCLUDE_PATH.'header.inc.php');
65 $savant->assign('album_info', $info);
66 $savant->assign('photos', $photos);
67 $savant->assign('comments', $comments);
68 $savant->assign('page', $page);
69 $savant->assign('num_rows', $photos_count);
70 $savant->assign('memory_usage', $memory_usage/(1024*1024));     //mb
71 $savant->assign('allowable_memory_usage', $_config['pa_max_memory_per_member']);        //mb
72 $savant->assign('action_permission', $pa->checkAlbumPriv($_SESSION['member_id']));
73 $savant->display('pa_albums.tmpl.php');
74 include (AT_INCLUDE_PATH.'footer.inc.php'); 
75 ?>