geoloc sur xnet
[platal.git] / include / banana.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2004 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
22require_once('banana/banana.inc.php');
23
24function hook_formatDisplayHeader($_header,$_text) {
25 global $banana;
26 if ($_header == 'x-org-id') {
27 return "$_text [<a href=\"../fiche.php?user=$_text\" class='popup2'>fiche</a>]";
28 }
29}
30
31function hook_headerTranslate($hdr) {
32 if ($hdr == 'x-org-id') {
33 return 'Identité';
34 }
35}
36
37function hook_checkcancel($_headers) {
38 return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
39}
40
41class PlatalBanana extends Banana
42{
4475197c 43 var $profile = Array( 'name' => '', 'sig' => '', 'org' => 'Utilisateur de Polytechnique.org',
0337d704 44 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
4475197c 45 var $can_attach = false;
0337d704 46
47 function PlatalBanana()
48 {
49 global $globals;
50
51 $uid = Session::getInt('uid');
52 $req = $globals->xdb->query(
53 "SELECT nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
54 FROM {$globals->banana->table_prefix}profils
55 WHERE uid={?}", $uid);
56
57 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
58 $nom = Session::get('prenom')." ".Session::get('nom');
59 $mail = Session::get('forlife')."@polytechnique.org";
60 $sig = $nom." (".Session::getInt('promo').")";
61 $disp = 0;
62 $maj = 1;
63 }
64 $this->profile['name'] = "$nom <$mail>";
65 $this->profile['sig'] = $sig;
66 $this->profile['display'] = $disp;
67 $this->profile['autoup'] = $maj;
68 $this->profile['lastnews'] = Session::get('banana_last');
69
70 if ($maj) {
71 $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
72 }
73
74 $req = $globals->xdb->query(
75 "SELECT nom
76 FROM {$globals->banana->table_prefix}abos
77 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
78 WHERE uid={?}", $uid);
79 $this->profile['subscribe'] = $req->fetchColumn();
80
81 array_splice($this->show_hdr, count($this->show_hdr) - 2, 0, 'x-org-id');
82 array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id');
83
84 $this->host = 'news://web_'.Session::get('forlife')
85 .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
86
87 parent::Banana();
88 }
89
90 function run()
91 {
92 global $banana, $globals;
93
94 if (Get::get('banana') == 'updateall') {
95 $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
96 $_SESSION['banana_last'] = time();
fa36e526 97 redirect($_SERVER['PHP_SELF']);
0337d704 98 }
99 return Banana::run('PlatalBanana');
100 }
101
102 function action_saveSubs()
103 {
104 global $globals;
105 $uid = Session::getInt('uid');
106
107 $this->profile['subscribe'] = Array();
108 $globals->xdb->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
109 if (!count($_POST['subscribe'])) {
110 return true;
111 }
112
113 $req = $globals->xdb->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
114 $fids = array();
115 while (list($fid,$fnom) = $req->next()) {
116 $fids[$fnom] = $fid;
117 }
118
119 $diff = array_diff($_POST['subscribe'], array_keys($fids));
120 foreach ($diff as $g) {
121 $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
122 $fids[$g] = mysql_insert_id();
123 }
124
125 foreach ($_POST['subscribe'] as $g) {
126 $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
127 $this->profile['subscribe'][] = $g;
128 }
129 }
130}
131
132?>