source: alternc/trunk/bureau/class/m_trash.php @ 2905

Revision 2905, 3.4 KB checked in by benjamin, 2 years ago (diff)

trash ok for yes/no (was buggy)

Line 
1<?php
2/*
3 $Id: m_trash.php,v 0.1 2010/11/17 15:51:00 fufroma Exp $
4 ----------------------------------------------------------------------
5 LICENSE
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License (GPL)
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 To read the license please visit http://www.gnu.org/copyleft/gpl.html
18 ----------------------------------------------------------------------
19 Original Author of file: Alan Garcia
20 Purpose of file: Manage trash class
21 ----------------------------------------------------------------------
22*/
23
24class m_trash {
25
26  var $is_trash=false;
27  var $expiration_date=null;
28  var $expiration_date_db=null;
29
30  /* ----------------------------------------------------------------- */
31  /**
32   * Constructeur
33   */
34  function m_trash() {
35  }
36 
37  function set_from_db($expiration_date_db) {
38    $this->expiration_date_db=$expiration_date_db;
39    $this->expiration_date=strtotime($this->expiration_date_db);
40    if ($this->expiration_date_db) $this->is_trash=true;
41  }
42
43  function human_display() {
44    return strftime("%d/%m/%Y",$this->expiration_date);
45  }
46
47  function getfromform() {
48    $fields = array (
49                     "istrash"                => array ("request", "boolean", false),
50                     "trash_type_expiration"  => array ("request", "string", ""),
51                     "trash_exp_in_value"     => array ("request", "string", ""),
52                     "trash_exp_in_unit"      => array ("request", "string", ""),
53                     "trash_datepicker"       => array ("request", "string", ""),
54    );
55    $champs=getFields($fields);
56    foreach($champs as $k=>$v) $$k = $v; 
57
58    if (!$istrash) $trash_type_expiration="no_exp";
59
60    switch($trash_type_expiration) {
61        case "trash_at_x":
62            // We can use date_parse_from_format if we have php 5.3
63            //$this->expiration_date=date_parse_from_format("%d/%m/%Y",$trash_datepicker);
64            $mydate=strptime($trash_datepicker, "%d/%m/%Y");
65            if ($mydate){
66                $this->expiration_date=new DateTime("@".mktime( 0, 0, 0, $mydate['tm_mon']+1, $mydate['tm_mday']+1, 1900+$mydate['tm_year']));
67            } else {
68                $this->expiration_date=new DateTime("@".(time() + (7*24*3600)));
69            }
70            $this->is_trash=true;
71            break;
72        case "trash_in_x":
73            $this->is_trash=true;
74            switch ($trash_exp_in_unit) {
75                case "weeks":
76                    $trash_unit = 7*24*3600;
77                    break;
78                case "days":
79                    $trash_unit = 24*3600;
80                    break;
81                case "hours":
82                    $trash_unit = 3600;
83                    break;
84            }
85            $this->expiration_date= new DateTime("@".(time() + ($trash_exp_in_value*$trash_unit)) );
86            break;
87        case "no_exp":
88            $this->is_trash=false;
89            break;
90        default:
91            $this->is_trash=false;
92    } // switch
93
94    if (!is_null($this->expiration_date)) $this->expiration_date_db=$this->expiration_date->format('Y-m-d H:i:s');
95  }
96
97}
Note: See TracBrowser for help on using the repository browser.