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