root / nephthys_buckets.php

View | Annotate | Download (27.6 KB)

1 f49348b2 Andreas
 <?php
2 f49348b2 Andreas
3 f49348b2 Andreas
 /***************************************************************************
4 f49348b2 Andreas
  *
5 9a37d81c Andreas
  * Nephthys - file sharing management
6 f49348b2 Andreas
  * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
7 f49348b2 Andreas
  *
8 9a37d81c Andreas
  *  This file is part of Nephthys.
9 9a37d81c Andreas
  *
10 9a37d81c Andreas
  *  Nephthys is free software: you can redistribute it and/or modify
11 f49348b2 Andreas
  *  it under the terms of the GNU General Public License as published by
12 9a37d81c Andreas
  *  the Free Software Foundation, either version 3 of the License, or
13 f49348b2 Andreas
  *  (at your option) any later version.
14 f49348b2 Andreas
  *
15 9a37d81c Andreas
  *  Nephthys is distributed in the hope that it will be useful,
16 f49348b2 Andreas
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 f49348b2 Andreas
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 f49348b2 Andreas
  *  GNU General Public License for more details.
19 f49348b2 Andreas
  *
20 f49348b2 Andreas
  *  You should have received a copy of the GNU General Public License
21 9a37d81c Andreas
  *  along with Nephthys. If not, see <http://www.gnu.org/licenses/>.
22 f49348b2 Andreas
  *
23 f49348b2 Andreas
  ***************************************************************************/
24 f49348b2 Andreas
25 f49348b2 Andreas
 class NEPHTHYS_BUCKETS {
26 f49348b2 Andreas
27 f49348b2 Andreas
    private $db;
28 f49348b2 Andreas
    private $parent;
29 f49348b2 Andreas
    private $tmpl;
30 f49348b2 Andreas
    private $id;
31 f49348b2 Andreas
    private $avail_buckets = Array();
32 f49348b2 Andreas
    private $buckets = Array();
33 f49348b2 Andreas
34 f49348b2 Andreas
    /**
35 f49348b2 Andreas
     * NEPHTHYS_BUCKET constructor
36 f49348b2 Andreas
     *
37 f49348b2 Andreas
     * Initialize the NEPHTHYS_BUCKET class
38 f49348b2 Andreas
     */
39 8569ba82 Andreas
    public function __construct($id = NULL)
40 f49348b2 Andreas
    {
41 f49348b2 Andreas
       global $nephthys;
42 f49348b2 Andreas
       $this->parent =& $nephthys;
43 f49348b2 Andreas
       $this->db =& $nephthys->db;
44 f49348b2 Andreas
       $this->tmpl =& $nephthys->tmpl;
45 f49348b2 Andreas
46 8569ba82 Andreas
       if(!empty($id))
47 8569ba82 Andreas
          $this->id = $id;
48 8569ba82 Andreas
49 f49348b2 Andreas
       $this->tmpl->register_block("bucket_list", array(&$this, "smarty_bucket_list"));
50 f49348b2 Andreas
51 28fad955 Andreas
       $query_str = "
52 fbaee801 Andreas
          SELECT
53 305613a2 Andreas
             b.bucket_idx as bucket_idx,
54 305613a2 Andreas
             b.bucket_name as bucket_name,
55 305613a2 Andreas
             b.bucket_sender as bucket_sender,
56 305613a2 Andreas
             b.bucket_receiver as bucket_receiver,
57 305613a2 Andreas
             b.bucket_hash as bucket_hash,
58 305613a2 Andreas
             b.bucket_created as bucket_created,
59 305613a2 Andreas
             b.bucket_expire as bucket_expire,
60 305613a2 Andreas
             b.bucket_note as bucket_note,
61 305613a2 Andreas
             b.bucket_owner as bucket_owner,
62 305613a2 Andreas
             b.bucket_active as bucket_active,
63 305613a2 Andreas
             b.bucket_notified as bucket_notified,
64 305613a2 Andreas
             b.bucket_notify_on_expire as bucket_notify_on_expire
65 fbaee801 Andreas
          FROM
66 ae2d18b9 Andreas
             nephthys_buckets b
67 28fad955 Andreas
       ";
68 28fad955 Andreas
69 ae2d18b9 Andreas
       /* get the current sort-order */
70 ae2d18b9 Andreas
       $column = $this->parent->get_sort_column('buckets');
71 ae2d18b9 Andreas
       $order  = $this->parent->get_sort_order('buckets');
72 ae2d18b9 Andreas
73 ae2d18b9 Andreas
       // if sort should happen on bucket-owners, sort by the real
74 ae2d18b9 Andreas
       // user_name instead of the user_idx (which is stored in
75 ae2d18b9 Andreas
       // bucket_owner).
76 ae2d18b9 Andreas
       if($column == 'bucket_owner') {
77 305613a2 Andreas
78 ae2d18b9 Andreas
          $query_str.= "
79 305613a2 Andreas
             LEFT OUTER JOIN
80 ae2d18b9 Andreas
                nephthys_users u
81 ae2d18b9 Andreas
             ON
82 ae2d18b9 Andreas
                b.bucket_owner=u.user_idx
83 305613a2 Andreas
          ";
84 305613a2 Andreas
85 305613a2 Andreas
          /* equipped with just user privileges, show only personal buckets */
86 305613a2 Andreas
          if(!$this->parent->check_privileges('admin') &&
87 70c9514a Andreas
             !$this->parent->check_privileges('manager') &&
88 70c9514a Andreas
             isset($_SESSION['login_idx'])) {
89 305613a2 Andreas
             $query_str.= "WHERE b.bucket_owner LIKE '". $_SESSION['login_idx'] ."'";
90 305613a2 Andreas
          }
91 305613a2 Andreas
92 305613a2 Andreas
          $query_str.= "
93 ae2d18b9 Andreas
             ORDER BY
94 ae2d18b9 Andreas
                u.user_name ". $order;
95 ae2d18b9 Andreas
       }
96 ae2d18b9 Andreas
       else {
97 305613a2 Andreas
98 305613a2 Andreas
          /* equipped with just user privileges, show only personal buckets */
99 305613a2 Andreas
          if(!$this->parent->check_privileges('admin') &&
100 70c9514a Andreas
             !$this->parent->check_privileges('manager') &&
101 70c9514a Andreas
             isset($_SESSION['login_idx'])) {
102 305613a2 Andreas
             $query_str.= "WHERE b.bucket_owner LIKE '". $_SESSION['login_idx'] ."'";
103 305613a2 Andreas
          }
104 305613a2 Andreas
105 ae2d18b9 Andreas
          $query_str.= "
106 ae2d18b9 Andreas
             ORDER BY
107 ae2d18b9 Andreas
                ". $column ." ". $order;
108 ae2d18b9 Andreas
       }
109 28fad955 Andreas
110 28fad955 Andreas
       $res_buckets = $nephthys->db->db_query($query_str);
111 f49348b2 Andreas
112 f49348b2 Andreas
       $cnt_buckets = 0;
113 f49348b2 Andreas
114 f49348b2 Andreas
       while($bucket = $res_buckets->fetchrow()) {
115 f49348b2 Andreas
          $this->avail_buckets[$cnt_buckets] = $bucket->bucket_idx;
116 f49348b2 Andreas
          $this->buckets[$bucket->bucket_idx] = $bucket;
117 f49348b2 Andreas
          $cnt_buckets++;
118 f49348b2 Andreas
       }
119 f49348b2 Andreas
120 1b35dd59 Andreas
       $this->tmpl->assign('user_has_buckets', $cnt_buckets);
121 f49348b2 Andreas
122 f49348b2 Andreas
    } // __construct()
123 f49348b2 Andreas
124 f49348b2 Andreas
    /* interface output */
125 f49348b2 Andreas
    public function show()
126 f49348b2 Andreas
    {
127 f49348b2 Andreas
       if(!$this->parent->is_logged_in()) {
128 b340940a Andreas
          $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##"));
129 f49348b2 Andreas
          return 0;
130 f49348b2 Andreas
       }
131 f49348b2 Andreas
        if(!isset($_GET['mode']))
132 f49348b2 Andreas
          $_GET['mode'] = "show";
133 f49348b2 Andreas
       if(!isset($_GET['idx']) ||
134 f49348b2 Andreas
          (isset($_GET['idx']) && !is_numeric($_GET['idx'])))
135 f49348b2 Andreas
          $_GET['idx'] = 0;
136 f49348b2 Andreas
137 f49348b2 Andreas
       switch($_GET['mode']) {
138 f49348b2 Andreas
          case 'receive':
139 b77ba60d Andreas
             $this->tmpl->assign('bucket_owner', $_SESSION['login_idx']);
140 017c4db4 Andreas
             $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx']));
141 bc003de0 Andreas
             return $this->tmpl->fetch('receive_form.tpl');
142 f49348b2 Andreas
          case 'send':
143 b77ba60d Andreas
             $this->tmpl->assign('bucket_owner', $_SESSION['login_idx']);
144 017c4db4 Andreas
             $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx']));
145 bc003de0 Andreas
             return $this->tmpl->fetch('send_form.tpl');
146 28fad955 Andreas
          case 'edit':
147 bc003de0 Andreas
             return $this->showEdit($_GET['idx']);
148 28fad955 Andreas
             break;
149 f49348b2 Andreas
          case 'notify':
150 07133b9a Andreas
             return $this->notify();
151 f49348b2 Andreas
             break;
152 f49348b2 Andreas
       }
153 f49348b2 Andreas
154 f49348b2 Andreas
    } // show()
155 f49348b2 Andreas
156 b190d01b Andreas
    /**
157 b190d01b Andreas
     * display a page containing bucket info
158 b190d01b Andreas
     *
159 b190d01b Andreas
     * this function returns a page containing information
160 b190d01b Andreas
     * about the requested (or previously created) bucket.
161 b190d01b Andreas
     *
162 b190d01b Andreas
     * @return string
163 b190d01b Andreas
     */
164 b190d01b Andreas
    public function showBucket()
165 b190d01b Andreas
    {
166 b190d01b Andreas
       if(!$this->parent->is_logged_in()) {
167 b340940a Andreas
          $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##"));
168 b190d01b Andreas
          return 0;
169 b190d01b Andreas
       }
170 b190d01b Andreas
171 b190d01b Andreas
       if(!isset($_GET['idx']) || empty($_GET['idx']) ||
172 b190d01b Andreas
          !is_numeric($_GET['idx']))
173 b190d01b Andreas
          return;
174 b190d01b Andreas
175 b190d01b Andreas
       if($bucket = $this->db->db_fetchSingleRow("
176 b190d01b Andreas
          SELECT *
177 b190d01b Andreas
          FROM
178 b190d01b Andreas
             nephthys_buckets
179 b190d01b Andreas
          WHERE
180 b190d01b Andreas
             bucket_idx LIKE '". $_GET['idx'] ."'")) {
181 b190d01b Andreas
182 69f0963f Andreas
          $this->tmpl->assign('bucket_idx', $bucket->bucket_idx);
183 ccc35b9d Andreas
          $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name));
184 b190d01b Andreas
          $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx']));
185 b190d01b Andreas
186 b190d01b Andreas
          if($bucket->bucket_expire != "-1")
187 b190d01b Andreas
             $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
188 b190d01b Andreas
189 b190d01b Andreas
          $bucket_ftp = $this->parent->get_url('ftp', $bucket->bucket_hash);
190 b190d01b Andreas
          $bucket_webdav = $this->parent->get_url('dav', $bucket->bucket_hash);
191 eef6b66a Andreas
          $bucket_webdav_vista = $this->parent->get_url('dav_vista', $bucket->bucket_hash);
192 b190d01b Andreas
193 b190d01b Andreas
          if($bucket->bucket_expire != "-1")
194 b190d01b Andreas
             $this->tmpl->assign('bucket_expire', strftime("%Y-%m-%d", $bucket_expire));
195 b190d01b Andreas
          else
196 4a23938d Andreas
             $this->tmpl->assign('bucket_expire', $this->parent->_('##NEVER##'));
197 b190d01b Andreas
198 ccc35b9d Andreas
          $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver));
199 b190d01b Andreas
          $this->tmpl->assign('bucket_webdav_path', $bucket_webdav);
200 eef6b66a Andreas
          $this->tmpl->assign('bucket_webdav_path_vista', $bucket_webdav_vista);
201 b190d01b Andreas
          $this->tmpl->assign('bucket_ftp_path', $bucket_ftp);
202 b190d01b Andreas
203 bc003de0 Andreas
          return $this->tmpl->fetch('saved_bucket.tpl');
204 b190d01b Andreas
205 b190d01b Andreas
       }
206 b190d01b Andreas
207 b190d01b Andreas
       return;
208 b190d01b Andreas
209 4a23938d Andreas
    } // showBucket()
210 b190d01b Andreas
211 45ec4be6 Andreas
    /**
212 45ec4be6 Andreas
     * get bucket information & details
213 45ec4be6 Andreas
     *
214 45ec4be6 Andreas
     * this function returns informations about the requested
215 45ec4be6 Andreas
     * bucket. how much diskspace it uses, ...
216 45ec4be6 Andreas
     *
217 45ec4be6 Andreas
     * @return string
218 45ec4be6 Andreas
     */
219 45ec4be6 Andreas
    public function get_bucket_info()
220 45ec4be6 Andreas
    {
221 45ec4be6 Andreas
       if(!($bucket = $this->get_bucket_details($this->id)))
222 45ec4be6 Andreas
          return "unkown bucket";
223 45ec4be6 Andreas
224 45ec4be6 Andreas
       $bucket_path = $this->parent->cfg->data_path
225 45ec4be6 Andreas
          ."/"
226 45ec4be6 Andreas
          . $bucket->bucket_hash;
227 45ec4be6 Andreas
228 45ec4be6 Andreas
       if(($used_diskspace = $this->parent->get_used_diskspace($bucket_path)) === false) {
229 45ec4be6 Andreas
          return "Can not locate bucket in filesystem to get used diskspace";
230 45ec4be6 Andreas
       }
231 45ec4be6 Andreas
232 45ec4be6 Andreas
       $bucket_size = $this->parent->get_unit($used_diskspace);
233 45ec4be6 Andreas
       $bucket_details = $this->parent->get_dir_info($bucket_path);
234 45ec4be6 Andreas
235 45ec4be6 Andreas
       $this->tmpl->assign('count_files', $bucket_details['files']);
236 45ec4be6 Andreas
       $this->tmpl->assign('count_dirs', $bucket_details['dirs']);
237 45ec4be6 Andreas
       $this->tmpl->assign('bucket_size', $bucket_size);
238 45ec4be6 Andreas
       if($bucket_details['last_mod'] > 0) {
239 45ec4be6 Andreas
          $this->tmpl->assign('bucket_last_mod', strftime("%c", $bucket_details['last_mod']));
240 45ec4be6 Andreas
       }
241 45ec4be6 Andreas
242 45ec4be6 Andreas
       $body = $this->tmpl->fetch('bucket_info.tpl');
243 45ec4be6 Andreas
244 45ec4be6 Andreas
       return $body;
245 45ec4be6 Andreas
246 45ec4be6 Andreas
    } // get_bucket_info()
247 45ec4be6 Andreas
248 f49348b2 Andreas
    public function notify()
249 f49348b2 Andreas
    {
250 8bcf59aa Andreas
       if(!($bucket = $this->get_bucket_details($this->id)))
251 f49348b2 Andreas
          return;
252 f49348b2 Andreas
253 53614d9d Andreas
       $bucket->bucket_sender = $this->parent->unescape($bucket->bucket_sender, false);
254 53614d9d Andreas
       $bucket->bucket_receiver = $this->parent->unescape($bucket->bucket_receiver, false);
255 53614d9d Andreas
256 72c89ff1 Andreas
       /* the bucket sender */
257 7223a210 Andreas
       $sender = $bucket->bucket_sender;
258 72c89ff1 Andreas
       $sender_text = $bucket->bucket_sender;
259 72c89ff1 Andreas
260 72c89ff1 Andreas
       /* if a bucket receiver has been specified, send mail to the receiver
261 72c89ff1 Andreas
          and in CC also to the sender
262 72c89ff1 Andreas
       */
263 72c89ff1 Andreas
       if(isset($bucket->bucket_receiver) && !empty($bucket->bucket_receiver)) {
264 72c89ff1 Andreas
          $receiver = Array($bucket->bucket_receiver, $bucket->bucket_sender);
265 72c89ff1 Andreas
          $receiver_text = $bucket->bucket_receiver;
266 72c89ff1 Andreas
       }
267 72c89ff1 Andreas
       else {
268 72c89ff1 Andreas
          $receiver = Array($bucket->bucket_sender);
269 72c89ff1 Andreas
          $receiver_text = $bucket->bucket_sender;
270 72c89ff1 Andreas
       }
271 092b8a0f Andreas
272 092b8a0f Andreas
       $ftp_url = $this->parent->get_url('ftp', $bucket->bucket_hash);
273 092b8a0f Andreas
       $http_url = $this->parent->get_url('dav', $bucket->bucket_hash);
274 092b8a0f Andreas
275 3124afa5 Andreas
       if($bucket->bucket_expire != -1) {
276 3124afa5 Andreas
          $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
277 3124afa5 Andreas
          $bucket_expire = strftime("%d. %b. %Y", $bucket_expire);
278 3124afa5 Andreas
       }
279 3124afa5 Andreas
       else {
280 3124afa5 Andreas
          $bucket_expire = "never";
281 3124afa5 Andreas
       }
282 df87e84e Andreas
283 109e13ac Andreas
       /* prepare the mail headers */
284 72c89ff1 Andreas
       $header['From'] = $sender_text;
285 72c89ff1 Andreas
       $header['To'] = $receiver_text;
286 f49348b2 Andreas
       $header['Subject'] = "File sharing information";
287 53614d9d Andreas
       $header['Content-Type'] = "text/plain; charset=UTF-8";
288 72c89ff1 Andreas
       /* if a bucket receiver has been specified, send mail to the receiver
289 72c89ff1 Andreas
          and in CC also to the sender
290 72c89ff1 Andreas
       */
291 72c89ff1 Andreas
       if(isset($bucket->bucket_receiver) && !empty($bucket->bucket_receiver))
292 72c89ff1 Andreas
          $header['CC'] = $bucket->bucket_sender;
293 f49348b2 Andreas
294 109e13ac Andreas
295 109e13ac Andreas
       /* prepare the notification text out of the smarty template */
296 f49348b2 Andreas
       $text = new NEPHTHYS_TMPL($this->parent);
297 72c89ff1 Andreas
       $text->assign('bucket_sender', $sender_text);
298 72c89ff1 Andreas
       $text->assign('bucket_receiver', $receiver_text);
299 109e13ac Andreas
300 109e13ac Andreas
       /* if the user has updated his profile with the full name, use it, otherwise
301 109e13ac Andreas
          take the login name instead.
302 109e13ac Andreas
       */
303 72c89ff1 Andreas
       if($this->parent->get_user_fullname($bucket->bucket_owner))
304 72c89ff1 Andreas
          $text->assign('bucket_sender_name', $this->parent->get_user_fullname($bucket->bucket_owner));
305 72c89ff1 Andreas
       else
306 72c89ff1 Andreas
          $text->assign('bucket_sender_name', $this->parent->get_user_name($bucket->bucket_owner));
307 7223a210 Andreas
308 092b8a0f Andreas
       $text->assign('bucket_ftp_url', $ftp_url);
309 092b8a0f Andreas
       $text->assign('bucket_http_url', $http_url);
310 458035ce Andreas
       $text->assign('bucket_servername', $this->parent->cfg->servername);
311 df87e84e Andreas
       $text->assign('bucket_expire', $bucket_expire);
312 3b9b2bd2 Andreas
       $text->assign('bucket_hash', $bucket->bucket_hash);
313 109e13ac Andreas
314 109e13ac Andreas
       /* if a bucket description has been specified, assign it to the template */
315 53614d9d Andreas
       if(isset($bucket->bucket_note) && !empty($bucket->bucket_note)) {
316 53614d9d Andreas
          $bucket->bucket_note = $this->parent->unescape($bucket->bucket_note, false);
317 109e13ac Andreas
          $text->assign('bucket_note', $bucket->bucket_note);
318 53614d9d Andreas
       }
319 109e13ac Andreas
320 109e13ac Andreas
       /* now translate the template and return the result as a string */
321 f49348b2 Andreas
       $body = $text->fetch('notify.tpl');
322 f49348b2 Andreas
323 7b3f0e39 Andreas
       // if you want to use php's own mail() function, remove the
324 7b3f0e39 Andreas
       // comment from the next two lines and wipe out the sendmail
325 7b3f0e39 Andreas
       // lines below.
326 7b3f0e39 Andreas
       // $mailer =& Mail::factory('mail');
327 7b3f0e39 Andreas
       // $status = $mailer->send($receiver, $header, $body);
328 7b3f0e39 Andreas
329 7b3f0e39 Andreas
       // usually this do not need to be set.
330 7b3f0e39 Andreas
       // $params['sendmail_path'] = '/usr/bin/sendmail';
331 7b3f0e39 Andreas
       $params['sendmail_arg'] = '-f'. $sender;
332 7b3f0e39 Andreas
333 7b3f0e39 Andreas
       $mailer =& Mail::factory('sendmail', $params);
334 7223a210 Andreas
       $status = $mailer->send($receiver, $header, $body);
335 7b3f0e39 Andreas
336 f49348b2 Andreas
       if(PEAR::isError($status)) {
337 f49348b2 Andreas
          return $status->getMessage();
338 f49348b2 Andreas
       }
339 f49348b2 Andreas
340 0ed27f2a Andreas
       /* set a flag in the database, that the bucket has been notified */
341 0ed27f2a Andreas
       $this->db->db_query("
342 0ed27f2a Andreas
          UPDATE nephthys_buckets
343 0ed27f2a Andreas
          SET
344 0ed27f2a Andreas
             bucket_notified='Y'
345 0ed27f2a Andreas
          WHERE
346 0ed27f2a Andreas
             bucket_idx LIKE '". $this->id ."'
347 0ed27f2a Andreas
       ");
348 0ed27f2a Andreas
349 d95362e3 Andreas
       return "ok;". $this->parent->_("##NOTIFY_SUCCESS##");
350 f49348b2 Andreas
351 f49348b2 Andreas
    } // notify()
352 f49348b2 Andreas
353 385f188a Andreas
    /**
354 385f188a Andreas
     * notify expired bucket
355 385f188a Andreas
     *
356 385f188a Andreas
     * this bucket notifies the bucket-owner about expiring buckets
357 385f188a Andreas
     * @param int $bucket_idx
358 385f188a Andreas
     */
359 385f188a Andreas
    public function notify_expired_bucket($bucket_idx)
360 385f188a Andreas
    {
361 385f188a Andreas
       $bucket = $this->get_bucket_details($bucket_idx);
362 385f188a Andreas
363 385f188a Andreas
       $owner_email = $this->parent->get_user_email($bucket->bucket_owner);
364 385f188a Andreas
       $owner_email = $this->parent->unescape($owner_email, false);
365 385f188a Andreas
366 385f188a Andreas
       /* the bucket sender */
367 385f188a Andreas
       if(isset($this->parent->cfg->system_mail)) {
368 385f188a Andreas
          $sender = $this->parent->cfg->system_mail;
369 385f188a Andreas
          $sender_text = $this->parent->cfg->system_mail;
370 385f188a Andreas
       }
371 385f188a Andreas
       else {
372 385f188a Andreas
          $sender = $owner_email;
373 385f188a Andreas
          $sender_text = $owner_email;
374 385f188a Andreas
       }
375 385f188a Andreas
376 385f188a Andreas
       /* the bucket receiver */
377 385f188a Andreas
       $receiver = Array($owner_email);
378 385f188a Andreas
       $receiver_text = $owner_email;
379 385f188a Andreas
380 385f188a Andreas
       /* prepare the mail headers */
381 385f188a Andreas
       $header['From'] = $sender_text;
382 385f188a Andreas
       $header['To'] = $receiver_text;
383 385f188a Andreas
       $header['Subject'] = "Your Nephthys bucket has expired";
384 385f188a Andreas
       $header['Content-Type'] = "text/plain; charset=UTF-8";
385 385f188a Andreas
386 385f188a Andreas
       /* prepare the notification text out of the Smarty template */
387 385f188a Andreas
       $text = new NEPHTHYS_TMPL($this->parent);
388 385f188a Andreas
       $text->assign('bucket_name', $bucket->bucket_name);
389 385f188a Andreas
390 385f188a Andreas
       /* now translate the template and return the result as a string */
391 385f188a Andreas
       $body = $text->fetch('notify_expired.tpl');
392 385f188a Andreas
393 385f188a Andreas
       // if you want to use php's own mail() function, remove the
394 385f188a Andreas
       // comment from the next two lines and wipe out the sendmail
395 385f188a Andreas
       // lines below.
396 385f188a Andreas
       // $mailer =& Mail::factory('mail');
397 385f188a Andreas
       // $status = $mailer->send($receiver, $header, $body);
398 385f188a Andreas
399 385f188a Andreas
       // usually this do not need to be set.
400 385f188a Andreas
       // $params['sendmail_path'] = '/usr/bin/sendmail';
401 385f188a Andreas
       $params['sendmail_arg'] = '-f'. $sender;
402 385f188a Andreas
403 385f188a Andreas
       $mailer =& Mail::factory('sendmail', $params);
404 385f188a Andreas
       $status = $mailer->send($receiver, $header, $body);
405 385f188a Andreas
406 385f188a Andreas
       if(PEAR::isError($status)) {
407 385f188a Andreas
          die($status->getMessage());
408 385f188a Andreas
       }
409 385f188a Andreas
410 385f188a Andreas
       return true;
411 385f188a Andreas
412 385f188a Andreas
    } // notify_expired_buckets()
413 385f188a Andreas
414 f49348b2 Andreas
    public function store()
415 f49348b2 Andreas
    {
416 6ca17b5b Andreas
       /* if not a privileged user, then set the email address from his profile */
417 3a36047f Andreas
       if($this->parent->check_privileges('user')) {
418 385f188a Andreas
          $_POST['bucket_sender'] = $this->parent->get_my_email();
419 6ca17b5b Andreas
       }
420 28fad955 Andreas
       /* if not a privilged user, then set the owner to his id */
421 3a36047f Andreas
       if($this->parent->check_privileges('user')) {
422 b77ba60d Andreas
          $_POST['bucket_owner'] = $_SESSION['login_idx'];
423 28fad955 Andreas
       }
424 6ca17b5b Andreas
425 f49348b2 Andreas
       isset($_POST['bucket_new']) && $_POST['bucket_new'] == 1 ? $new = 1 : $new = NULL;
426 f49348b2 Andreas
427 f49348b2 Andreas
       if(!isset($_POST['bucket_name']) || empty($_POST['bucket_name'])) {
428 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_BUCKET_NAME##");
429 f49348b2 Andreas
       }
430 f49348b2 Andreas
       if(!isset($_POST['bucket_sender']) || empty($_POST['bucket_name'])) {
431 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_BUCKET_SENDER##");
432 f49348b2 Andreas
       }
433 8f9d867a Andreas
       if(!$this->parent->is_valid_email($_POST['bucket_sender'])) {
434 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_VALID_SENDER##");
435 f49348b2 Andreas
       }
436 f49348b2 Andreas
       if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" &&
437 f49348b2 Andreas
          !isset($_POST['bucket_receiver']) || empty($_POST['bucket_name'])) {
438 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_BUCKET_RECEIVER##");
439 f49348b2 Andreas
       }
440 f49348b2 Andreas
       if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" &&
441 8f9d867a Andreas
          !$this->parent->is_valid_email($_POST['bucket_receiver'])) {
442 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_VALID_RECEIVER##");
443 72c89ff1 Andreas
       }
444 72c89ff1 Andreas
       /* for "send" it's not a must to specify a receiver, anyway, if one is there
445 72c89ff1 Andreas
          validate it...
446 72c89ff1 Andreas
       */
447 72c89ff1 Andreas
       if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "send" &&
448 04135226 Andreas
          isset($_POST['bucket_receiver']) && !empty($_POST['bucket_receiver']) &&
449 8f9d867a Andreas
          !$this->parent->is_valid_email($_POST['bucket_receiver'])) {
450 4a23938d Andreas
          return $this->parent->_("##FAILURE_ENTER_VALID_RECEIVER##");
451 f49348b2 Andreas
       }
452 f49348b2 Andreas
453 d08c99b8 Andreas
       /* first of all we add the email address to the addressbook if requested.
454 d08c99b8 Andreas
          If after something goes wrong, the address is already in the database
455 d08c99b8 Andreas
          and user saves some keystrokes...
456 62f5d516 Andreas
457 62f5d516 Andreas
          but only if the "add email to address-book" is checked and a receiver
458 62f5d516 Andreas
          address has been specified.
459 d08c99b8 Andreas
       */
460 d08c99b8 Andreas
       if(isset($_POST['bucket_receiver_to_ab']) &&
461 62f5d516 Andreas
          $_POST['bucket_receiver_to_ab'] == 'Y' &&
462 62f5d516 Andreas
          isset($_POST['bucket_receiver']) &&
463 62f5d516 Andreas
          !empty($_POST['bucket_receiver'])) {
464 d08c99b8 Andreas
          $this->parent->add_to_addressbook($_POST['bucket_receiver']);
465 d08c99b8 Andreas
       }
466 d08c99b8 Andreas
467 68b8bbc2 Andreas
       if(!isset($_POST['bucket_notify_on_expire']))
468 68b8bbc2 Andreas
          $_POST['bucket_notify_on_expire'] = 'N';
469 68b8bbc2 Andreas
470 f49348b2 Andreas
       if(isset($new)) {
471 f49348b2 Andreas
472 f49348b2 Andreas
          if(isset($_POST['bucket_receiver']))
473 f49348b2 Andreas
             $hash = $this->parent->get_sha_hash($_POST['bucket_sender'], $_POST['bucket_receiver']);
474 f49348b2 Andreas
          else {
475 f49348b2 Andreas
             $_POST['bucket_receiver'] = "";
476 f49348b2 Andreas
             $hash = $this->parent->get_sha_hash($_POST['bucket_sender']);
477 f49348b2 Andreas
          }
478 f49348b2 Andreas
479 b1fa0a38 Andreas
          $sth = $this->db->db_prepare("
480 f49348b2 Andreas
             INSERT INTO nephthys_buckets (
481 cc1b5b35 Andreas
                bucket_idx,
482 8cb76e60 Andreas
                bucket_name, bucket_sender, bucket_receiver, bucket_created,
483 6ca17b5b Andreas
                bucket_expire, bucket_note, bucket_hash, bucket_owner,
484 385f188a Andreas
                bucket_active, bucket_notify_on_expire
485 f49348b2 Andreas
             ) VALUES (
486 cc1b5b35 Andreas
                NULL,
487 b1fa0a38 Andreas
                ?, ?, ?, '". mktime() ."',
488 b1fa0a38 Andreas
                ?, ?, '". $hash ."', ?,
489 385f188a Andreas
                'Y', ?
490 b1fa0a38 Andreas
             )
491 f49348b2 Andreas
          ");
492 f49348b2 Andreas
493 b1fa0a38 Andreas
          $this->db->db_execute($sth, array(
494 b1fa0a38 Andreas
             $_POST['bucket_name'],
495 b1fa0a38 Andreas
             $_POST['bucket_sender'],
496 b1fa0a38 Andreas
             $_POST['bucket_receiver'],
497 b1fa0a38 Andreas
             $_POST['bucket_expire'],
498 b1fa0a38 Andreas
             $_POST['bucket_note'],
499 b1fa0a38 Andreas
             $_POST['bucket_owner'],
500 385f188a Andreas
             $_POST['bucket_notify_on_expire'],
501 b1fa0a38 Andreas
          ));
502 b1fa0a38 Andreas
503 a8f45296 Andreas
          $this->id = $this->db->db_getid();
504 b190d01b Andreas
          $last_id = $this->id;
505 a8f45296 Andreas
506 f49348b2 Andreas
          if(!mkdir($this->parent->cfg->data_path ."/". $hash)) {
507 f49348b2 Andreas
             return "There was a error creating the bucket directory. Contact your administrator!";
508 f49348b2 Andreas
          }
509 f49348b2 Andreas
510 a8f45296 Andreas
          if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" &&
511 a8f45296 Andreas
             isset($_POST['notifybucket']) && $_POST['notifybucket'] == "true") {
512 a8f45296 Andreas
513 a8f45296 Andreas
             $this->notify();
514 a8f45296 Andreas
515 a8f45296 Andreas
          }
516 ea61d598 Andreas
517 ea61d598 Andreas
          // Create IE WebDAV-open-HTML file
518 ea61d598 Andreas
          $bucket_webdav = $this->parent->get_url('dav', $hash);
519 ea61d598 Andreas
          $this->tmpl->assign('bucket_webdav_path', $bucket_webdav);
520 ea61d598 Andreas
          $html_file = $this->tmpl->fetch("ie_webdav.tpl");
521 ea61d598 Andreas
522 15d92761 Andreas
          if($fileh = fopen($this->parent->cfg->data_path ."/". $hash ."/webdav.html", 'w')) {
523 ea61d598 Andreas
             fwrite($fileh, $html_file);
524 ea61d598 Andreas
             fclose($fileh);
525 ea61d598 Andreas
          }
526 ea61d598 Andreas
527 f49348b2 Andreas
       }
528 f49348b2 Andreas
       else {
529 b1fa0a38 Andreas
530 b1fa0a38 Andreas
         $sth = $this->db->db_prepare("
531 b1fa0a38 Andreas
             UPDATE nephthys_buckets
532 b1fa0a38 Andreas
             SET
533 b1fa0a38 Andreas
                bucket_name=?,
534 b1fa0a38 Andreas
                bucket_sender=?,
535 b1fa0a38 Andreas
                bucket_receiver=?,
536 b1fa0a38 Andreas
                bucket_expire=?,
537 b1fa0a38 Andreas
                bucket_note=?,
538 b1fa0a38 Andreas
                bucket_owner=?,
539 385f188a Andreas
                bucket_active='Y',
540 385f188a Andreas
                bucket_notify_on_expire=?
541 b1fa0a38 Andreas
             WHERE
542 b1fa0a38 Andreas
                bucket_idx=?
543 b1fa0a38 Andreas
          ");
544 b1fa0a38 Andreas
545 b1fa0a38 Andreas
          $this->db->db_execute($sth, array(
546 b1fa0a38 Andreas
             $_POST['bucket_name'],
547 b1fa0a38 Andreas
             $_POST['bucket_sender'],
548 b1fa0a38 Andreas
             $_POST['bucket_receiver'],
549 b1fa0a38 Andreas
             $_POST['bucket_expire'],
550 b1fa0a38 Andreas
             $_POST['bucket_note'],
551 b1fa0a38 Andreas
             $_POST['bucket_owner'],
552 385f188a Andreas
             $_POST['bucket_notify_on_expire'],
553 b1fa0a38 Andreas
             $_POST['bucket_idx'],
554 b1fa0a38 Andreas
          ));
555 b1fa0a38 Andreas
556 f49348b2 Andreas
       }
557 f49348b2 Andreas
558 b190d01b Andreas
       if(!isset($last_id))
559 b190d01b Andreas
          return "ok";
560 b190d01b Andreas
561 b190d01b Andreas
       return "ok;". $last_id;
562 f49348b2 Andreas
563 6ca17b5b Andreas
    } // store()
564 f49348b2 Andreas
565 f49348b2 Andreas
    public function showList()
566 f49348b2 Andreas
    {
567 bc003de0 Andreas
       return $this->tmpl->fetch("bucket_list.tpl");
568 f49348b2 Andreas
569 f49348b2 Andreas
    } // showList()
570 f49348b2 Andreas
571 f49348b2 Andreas
    /**
572 f49348b2 Andreas
     * template function which will be called from the buckets listing template
573 f49348b2 Andreas
     */
574 f49348b2 Andreas
    public function smarty_bucket_list($params, $content, &$smarty, &$repeat)
575 f49348b2 Andreas
    {
576 f49348b2 Andreas
       $index = $this->tmpl->get_template_vars('smarty.IB.bucket_list.index');
577 f49348b2 Andreas
       if(!$index) {
578 f49348b2 Andreas
          $index = 0;
579 f49348b2 Andreas
       }
580 f49348b2 Andreas
581 f49348b2 Andreas
       if($index < count($this->avail_buckets)) {
582 f49348b2 Andreas
583 f49348b2 Andreas
          $bucket_idx = $this->avail_buckets[$index];
584 f49348b2 Andreas
          $bucket =  $this->buckets[$bucket_idx];
585 f49348b2 Andreas
586 b77ba60d Andreas
          $user_priv = $this->parent->get_user_priv($_SESSION['login_idx']);
587 6ca17b5b Andreas
588 b1297d89 Andreas
          if($bucket->bucket_expire != "-1")
589 b1297d89 Andreas
             $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
590 6ca17b5b Andreas
          $bucket_owner = $this->parent->get_user_name($bucket->bucket_owner);
591 485e530f Andreas
          $bucket_owner_full = $this->parent->get_user_fullname($bucket->bucket_owner);
592 1b57569b Andreas
593 092b8a0f Andreas
          $bucket_ftp = $this->parent->get_url('ftp', $bucket->bucket_hash);
594 092b8a0f Andreas
          $bucket_webdav = $this->parent->get_url('dav', $bucket->bucket_hash);
595 eef6b66a Andreas
          $bucket_webdav_vista = $this->parent->get_url('dav_vista', $bucket->bucket_hash);
596 b4377ade Andreas
597 f49348b2 Andreas
          $this->tmpl->assign('bucket_idx', $bucket_idx);
598 ccc35b9d Andreas
          $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name));
599 1b57569b Andreas
          $this->tmpl->assign('bucket_created', strftime("%Y-%m-%d", $bucket->bucket_created));
600 b1297d89 Andreas
          if($bucket->bucket_expire != "-1")
601 b1297d89 Andreas
             $this->tmpl->assign('bucket_expire', strftime("%Y-%m-%d", $bucket_expire));
602 b1297d89 Andreas
          else
603 4a23938d Andreas
             $this->tmpl->assign('bucket_expire', $this->parent->_('##NEVER##'));
604 ccc35b9d Andreas
          $this->tmpl->assign('bucket_owner', $this->parent->unescape($bucket_owner));
605 485e530f Andreas
          $this->tmpl->assign('bucket_owner_full', $this->parent->unescape($bucket_owner_full));
606 aa5d3373 Andreas
          $this->tmpl->assign('bucket_owner_idx', $bucket->bucket_owner);
607 ccc35b9d Andreas
          $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver));
608 b4377ade Andreas
          $this->tmpl->assign('bucket_webdav_path', $bucket_webdav);
609 eef6b66a Andreas
          $this->tmpl->assign('bucket_webdav_path_vista', $bucket_webdav_vista);
610 b4377ade Andreas
          $this->tmpl->assign('bucket_ftp_path', $bucket_ftp);
611 4a23938d Andreas
          $this->tmpl->assign('bucket_notified', $bucket->bucket_notified);
612 27af6e13 Andreas
          $this->tmpl->assign('bucket_hash', $bucket->bucket_hash);
613 0ed27f2a Andreas
614 f49348b2 Andreas
          $index++;
615 f49348b2 Andreas
          $this->tmpl->assign('smarty.IB.bucket_list.index', $index);
616 f49348b2 Andreas
          $repeat = true;
617 f49348b2 Andreas
       }
618 f49348b2 Andreas
       else {
619 f49348b2 Andreas
          $repeat =  false;
620 f49348b2 Andreas
       }
621 f49348b2 Andreas
622 f49348b2 Andreas
       return $content;
623 f49348b2 Andreas
624 f49348b2 Andreas
    } // smarty_bucket_list()
625 f49348b2 Andreas
626 cffe5b99 Andreas
    public function delete()
627 cffe5b99 Andreas
    {
628 cffe5b99 Andreas
       if(isset($_POST['idx']) && is_numeric($_POST['idx'])) {
629 cffe5b99 Andreas
630 d0f1d464 Andreas
          /* ensure unprivileged users can only delete their own buckets */
631 3a36047f Andreas
          if($this->parent->check_privileges('user') && !$this->parent->is_bucket_owner($_POST['idx'])) {
632 d0f1d464 Andreas
             return "You are only allowed to delete buckets you own!";
633 d0f1d464 Andreas
          }
634 d0f1d464 Andreas
635 cffe5b99 Andreas
          $hash = $this->get_bucket_hash($_POST['idx']);
636 cffe5b99 Andreas
637 cffe5b99 Andreas
          if(!$hash) {
638 d7bf12d4 Andreas
             return "Can't locate hash value of the bucket that was requested to be deleted.";
639 cffe5b99 Andreas
          }
640 cffe5b99 Andreas
641 cffe5b99 Andreas
          if(!$this->del_data_directory($hash)) {
642 b340940a Andreas
             $this->parent->_error("Removing bucket directory ". $this->parent->cfg->data_path ."/". $hash ." not possible");
643 cffe5b99 Andreas
          }
644 cffe5b99 Andreas
645 385f188a Andreas
          $this->delete_bucket($_POST['idx']);
646 cffe5b99 Andreas
       }
647 cffe5b99 Andreas
648 cffe5b99 Andreas
       print "ok";
649 cffe5b99 Andreas
650 cffe5b99 Andreas
    } // delete()
651 cffe5b99 Andreas
652 cffe5b99 Andreas
    /**
653 cffe5b99 Andreas
     * return bucket's SHA1 hash
654 cffe5b99 Andreas
     *
655 cffe5b99 Andreas
     * this function will return the SHA1 hash of the
656 cffe5b99 Andreas
     * requested bucket (by database primary key)
657 cffe5b99 Andreas
     */
658 cffe5b99 Andreas
    private function get_bucket_hash($idx)
659 cffe5b99 Andreas
    {
660 cffe5b99 Andreas
       if($row = $this->db->db_fetchSingleRow("
661 cffe5b99 Andreas
             SELECT bucket_hash
662 cffe5b99 Andreas
             FROM nephthys_buckets
663 cffe5b99 Andreas
             WHERE bucket_idx LIKE '". $idx ."'
664 cffe5b99 Andreas
          ")) {
665 cffe5b99 Andreas
666 cffe5b99 Andreas
          if(isset($row->bucket_hash))
667 cffe5b99 Andreas
             return $row->bucket_hash;
668 cffe5b99 Andreas
669 cffe5b99 Andreas
       }
670 cffe5b99 Andreas
671 cffe5b99 Andreas
       return 0;
672 cffe5b99 Andreas
673 cffe5b99 Andreas
    } // get_bucket_hash();
674 cffe5b99 Andreas
675 fff2a093 Andreas
    public function del_data_directory($hash)
676 cffe5b99 Andreas
    {
677 385f188a Andreas
       /* if something went wrong before, do not delete anything */
678 385f188a Andreas
       if(!is_string($hash) || empty($hash))
679 385f188a Andreas
          return false;
680 385f188a Andreas
681 385f188a Andreas
       $invalid_path = Array(
682 385f188a Andreas
          "/",
683 385f188a Andreas
          "/usr",
684 385f188a Andreas
          "/var",
685 385f188a Andreas
          "/home",
686 385f188a Andreas
          "/boot",
687 385f188a Andreas
          $this->parent->cfg->base_path);
688 385f188a Andreas
689 cffe5b99 Andreas
       /*
690 cffe5b99 Andreas
        * ensure that this function can not malfunction
691 cffe5b99 Andreas
        */
692 cffe5b99 Andreas
       if(in_array($this->parent->cfg->data_path, $invalid_path))
693 385f188a Andreas
          return false;
694 cffe5b99 Andreas
695 cffe5b99 Andreas
       if($this->data_directory_exists($hash))
696 27af6e13 Andreas
          return $this->parent->deltree($this->parent->cfg->data_path ."/". $hash);
697 cffe5b99 Andreas
698 cffe5b99 Andreas
       return false;
699 cffe5b99 Andreas
700 cffe5b99 Andreas
    } // del_data_directory()
701 cffe5b99 Andreas
702 385f188a Andreas
    /**
703 cffe5b99 Andreas
     * check if data directory exists
704 cffe5b99 Andreas
     *
705 cffe5b99 Andreas
     * returns true, if the specified data-directory + hash-named
706 cffe5b99 Andreas
     * directory really exists.
707 385f188a Andreas
     * @param string $hash
708 385f188a Andreas
     * @return bool
709 cffe5b99 Andreas
     */
710 cffe5b99 Andreas
    private function data_directory_exists($hash)
711 cffe5b99 Andreas
    {
712 cffe5b99 Andreas
       if(file_exists($this->parent->cfg->data_path ."/". $hash))
713 cffe5b99 Andreas
          return true;
714 cffe5b99 Andreas
715 cffe5b99 Andreas
       return false;
716 cffe5b99 Andreas
717 cffe5b99 Andreas
    } // data_directory_exists()
718 cffe5b99 Andreas
719 28fad955 Andreas
    /**
720 28fad955 Andreas
     * display interface to create or edit users
721 385f188a Andreas
     * @param int $idx
722 28fad955 Andreas
     */
723 28fad955 Andreas
    private function showEdit($idx)
724 28fad955 Andreas
    {
725 28fad955 Andreas
       /* If authentication is enabled, check permissions */
726 28fad955 Andreas
       if(!$this->parent->is_logged_in()) {
727 b340940a Andreas
          $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##"));
728 28fad955 Andreas
          return 0;
729 28fad955 Andreas
       }
730 28fad955 Andreas
731 28fad955 Andreas
       if($idx != 0) {
732 28fad955 Andreas
          $bucket = $this->db->db_fetchSingleRow("
733 28fad955 Andreas
             SELECT *
734 28fad955 Andreas
             FROM nephthys_buckets
735 28fad955 Andreas
             WHERE
736 28fad955 Andreas
                bucket_idx LIKE '". $idx ."'
737 28fad955 Andreas
          ");
738 28fad955 Andreas
739 28fad955 Andreas
          $this->tmpl->assign('bucket_idx', $idx);
740 ccc35b9d Andreas
          $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name));
741 ccc35b9d Andreas
          $this->tmpl->assign('bucket_sender', $this->parent->unescape($bucket->bucket_sender));
742 ccc35b9d Andreas
          $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver));
743 28fad955 Andreas
          $this->tmpl->assign('bucket_expire', $bucket->bucket_expire);
744 ccc35b9d Andreas
          $this->tmpl->assign('bucket_note', $this->parent->unescape($bucket->bucket_note));
745 ccc35b9d Andreas
          $this->tmpl->assign('bucket_owner', $this->parent->unescape($bucket->bucket_owner));
746 28fad955 Andreas
          $this->tmpl->assign('bucket_active', $bucket->bucket_active);
747 385f188a Andreas
          $this->tmpl->assign('bucket_notify_on_expire', $bucket->bucket_notify_on_expire);
748 28fad955 Andreas
749 28fad955 Andreas
       }
750 28fad955 Andreas
751 bc003de0 Andreas
       return $this->tmpl->fetch("bucket_edit.tpl");
752 cffe5b99 Andreas
753 28fad955 Andreas
    } // showEdit()
754 f49348b2 Andreas
755 385f188a Andreas
    /**
756 385f188a Andreas
     * get bucket details
757 385f188a Andreas
     *
758 385f188a Andreas
     * this function returns a object containing all
759 385f188a Andreas
     * informations about a bucket-object in database.
760 385f188a Andreas
     * @param int $idx
761 385f188a Andreas
     * @return object
762 385f188a Andreas
     */
763 385f188a Andreas
    public function get_bucket_details($idx)
764 385f188a Andreas
    {
765 385f188a Andreas
       if($bucket = $this->db->db_fetchSingleRow("
766 385f188a Andreas
          SELECT *
767 385f188a Andreas
          FROM
768 385f188a Andreas
             nephthys_buckets
769 385f188a Andreas
          WHERE
770 385f188a Andreas
             bucket_idx='". $idx ."'")) {
771 385f188a Andreas
772 385f188a Andreas
          return $bucket;
773 385f188a Andreas
774 385f188a Andreas
       }
775 385f188a Andreas
776 385f188a Andreas
       return NULL;
777 385f188a Andreas
778 385f188a Andreas
    } // get_bucket_details()
779 385f188a Andreas
780 385f188a Andreas
    /**
781 385f188a Andreas
     * get expired buckets
782 385f188a Andreas
     *
783 385f188a Andreas
     * this function will return an array consiting the row id's of all
784 385f188a Andreas
     * expired buckets.
785 385f188a Andreas
     * @return array
786 385f188a Andreas
     */
787 385f188a Andreas
    public function get_expired_buckets()
788 385f188a Andreas
    {
789 385f188a Andreas
790 385f188a Andreas
       $expired_buckets = Array();
791 385f188a Andreas
792 385f188a Andreas
       /* get all buckets */
793 385f188a Andreas
       $buckets = $this->db->db_query("
794 385f188a Andreas
          SELECT
795 385f188a Andreas
             b.bucket_idx as bucket_idx,
796 385f188a Andreas
             b.bucket_expire as bucket_expire,
797 385f188a Andreas
             b.bucket_created as bucket_created
798 385f188a Andreas
          FROM
799 385f188a Andreas
             nephthys_buckets b
800 385f188a Andreas
          INNER JOIN
801 385f188a Andreas
             nephthys_users u
802 385f188a Andreas
          ON
803 385f188a Andreas
             b.bucket_owner=u.user_idx
804 385f188a Andreas
       ");
805 385f188a Andreas
806 385f188a Andreas
       while($bucket = $buckets->fetchRow()) {
807 385f188a Andreas
808 385f188a Andreas
          /* don't care about never-expiring buckets */
809 385f188a Andreas
          if($bucket->bucket_expire == -1)
810 385f188a Andreas
             continue;
811 385f188a Andreas
812 385f188a Andreas
          /* check if the bucket has expired */
813 385f188a Andreas
          if(($bucket->bucket_created + ($bucket->bucket_expire * 86400)) <= mktime()) {
814 385f188a Andreas
             array_push($expired_buckets, $bucket->bucket_idx);
815 385f188a Andreas
          }
816 385f188a Andreas
       }
817 385f188a Andreas
818 385f188a Andreas
       return $expired_buckets;
819 385f188a Andreas
820 385f188a Andreas
    } // get_expired_buckets()
821 385f188a Andreas
822 385f188a Andreas
    /**
823 385f188a Andreas
     * delete bucket
824 385f188a Andreas
     *
825 385f188a Andreas
     * this function deletes a bucket ONLY from the database identified
826 385f188a Andreas
     * by its row id.
827 385f188a Andreas
     * @param int $idx
828 385f188a Andreas
     * @return bool
829 385f188a Andreas
     */
830 385f188a Andreas
    public function delete_bucket($idx)
831 385f188a Andreas
    {
832 385f188a Andreas
       if($this->db->db_query("
833 385f188a Andreas
          DELETE FROM
834 385f188a Andreas
             nephthys_buckets
835 385f188a Andreas
          WHERE
836 385f188a Andreas
             bucket_idx LIKE '". $idx ."'")) {
837 385f188a Andreas
838 385f188a Andreas
          return true;
839 385f188a Andreas
840 385f188a Andreas
       }
841 385f188a Andreas
842 385f188a Andreas
       return false;
843 385f188a Andreas
844 385f188a Andreas
    } // delete_bucket()
845 385f188a Andreas
846 f49348b2 Andreas
 } // class NEPHTHYS_BUCKETS
847 f49348b2 Andreas
848 b392cb9b Andreas
 // vim: set filetype=php expandtab softtabstop=3 tabstop=3 shiftwidth=3 autoindent smartindent:
849 f49348b2 Andreas
 ?>