exit getphoto.php => photo
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class ProfileModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
adbdf493 27 'photo' => $this->make_hook('photo', AUTH_PUBLIC),
7d8b17cb 28 'trombi' => $this->make_hook('trombi', AUTH_COOKIE),
29 );
30 }
31
32 function _trombi_getlist($offset, $limit)
33 {
34 global $globals;
35
36 $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" );
37
38 $res = $globals->xdb->query(
39 "SELECT COUNT(*)
40 FROM auth_user_md5 AS u
41 RIGHT JOIN photo AS p ON u.user_id=p.uid
42 $where");
43 $pnb = $res->fetchOneCell();
44
45 $res = $globals->xdb->query(
46 "SELECT promo,user_id,a.alias AS forlife,IF(nom_usage='', nom, nom_usage) AS nom,prenom
47 FROM photo AS p
48 INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
49 INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
50 $where
51 ORDER BY promo,nom,prenom LIMIT {?}, {?}", $offset*$limit, $limit);
52
53 return array($pnb, $res->fetchAllAssoc());
54 }
55
adbdf493 56 function handler_photo(&$page, $x = null, $req = null)
57 {
58 if (is_null($x)) {
59 return PL_NOT_FOUND;
60 }
61
62 global $globals;
63
64 $res = $globals->xdb->query("SELECT id, pub FROM aliases
65 LEFT JOIN photo ON(id = uid)
66 WHERE alias = {?}", $x);
67 list($uid, $photo_pub) = $res->fetchOneRow();
68
69 if ($req && logged()) {
70 include 'validations.inc.php';
71 $myphoto = PhotoReq::get_request($uid);
72 Header('Content-type: image/'.$myphoto->mimetype);
73 echo $myphoto->data;
74 } else {
75 $res = $globals->xdb->query(
76 "SELECT attachmime, attach
77 FROM photo
78 WHERE uid={?}", $uid);
79
80 if ((list($type,$data) = $res->fetchOneRow()) && ($photo_pub == 'public' || logged())) {
81 Header("Content-type: image/$type");
82 echo $data;
83 } else {
84 Header('Content-type: image/png');
85 echo file_get_contents(dirname(__FILE__).'../htdocs/images/none.png');
86 }
87 }
88 exit;
89 }
90
7d8b17cb 91 function handler_trombi(&$page, $promo = null)
92 {
93 require_once 'trombi.inc.php';
94
95 $page->changeTpl('trombipromo.tpl');
96 $page->assign('xorg_title','Polytechnique.org - Trombi Promo');
97
98 if (is_null($promo)) {
99 return PL_OK;
100 }
101
102 $this->promo = $promo = intval($promo);
103
104 if ($promo >= 1900 && $promo < intval(date('Y'))
105 || ($promo == -1 && has_perms()))
106 {
107 $trombi = new Trombi(array($this, '_trombi_getlist'));
108 $trombi->hidePromo();
109 $trombi->setAdmin();
110 $page->assign_by_ref('trombi', $trombi);
111 } else {
112 $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.');
113 }
114
115 return PL_OK;
116 }
117}
118
119?>