noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_iperiod.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief Html Input
24  */
25 /*! \brief Generate the form for the periode
26 * Data Members
27  * - $cn connexion to the current folder
28  * - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST BE SET
29  * - $filter_year make a filter on the default exercice by default true
30  * - $user if a filter_year is required then we need who is the user (object User)
31  * - $show_end_date; $show_end_date is not set or false, do not show the end date default = true
32  * - $show_start_date; $show_start_date is not set or false, do not show the start date default=true
33 */
34 require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
35 class IPeriod extends HtmlInput
36 {
37  var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL */
38  var $cn; /*!< $cn is the database connection */
39  var $show_end_date; /*!< $show_end_date is not set or false, do not show the end date */
40  var $show_start_date; /*!< $show_start_date is not set or false, do not show the start date */
41  var $filter_year; /*!< $filter_year make a filter on the default exercice by default yes */
42  var $user; /*! $user if a filter is required then we need who is the user (object User)*/
43  function __construct($p_name="",$p_value="",$p_exercice='')
44  {
45  $this->name=$p_name;
46  $this->readOnly=false;
47  $this->size=20;
48  $this->width=50;
49  $this->heigh=20;
50  $this->value=$p_value;
51  $this->selected="";
52  $this->table=0;
53  $this->disabled=false;
54  $this->javascript="";
55  $this->extra2="all";
56  $this->show_start_date=true;
57  $this->show_end_date=true;
58  $this->exercice=$p_exercice;
59  }
60  /*!
61  * \brief show the input html for a periode
62  *\param $p_name is the name of the widget
63  *\param $p_value is the default value
64  *\param $p_exercice is the exercice, if not set then the user preference is used
65  * \return string containing html code for the HTML
66  *
67  *
68  */
69  public function input($p_name=null,$p_value=null)
70  {
71  foreach (array('type','cn') as $a)
72  {
73  if ( ! isset ($this->$a) ) throw new Exception('Variable non définie [ '.$a.']');
74  }
75  $this->name=($p_name==null)?$this->name:$p_name;
76  $this->value=($p_value==null)?$this->value:$p_value;
77  if ( $this->readOnly==true) return $this->display();
78 
79  switch ($this->type)
80  {
81  case CLOSED:
82  $sql_closed="where p_closed=true and p_central = false ";
83  break;
84  case OPEN:
85  $sql_closed="where p_closed=false";
86  break;
87  case NOTCENTRALIZED:
88  $sql_closed="where p_closed=true and p_central = false ";
89  break;
90  case ALL:
91  $sql_closed="";
92  break;
93  default:
94  throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
95  }
96  $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
97  to_char(p_end,'DD.MM.YYYY') as p_end_string
98  from parm_periode
99  $sql_closed ";
100 
101  $cond="";
102 
103 
104  /* Create a filter on the current exercice */
105  if ( ! isset($this->filter_year) || (isset($this->filter_year) && $this->filter_year==true))
106  {
107  if ( $this->exercice=='')
108  {
109  if (! isset($this->user) ) throw new Exception (__FILE__.':'.__LINE__.' user is not set');
110  $this->exercice=$this->user->get_exercice();
111  }
112 
113  $cond='';
114  if ( $sql_closed=="") $and=" where " ; else $and=" and ";
115  if ($this->type == 'all' ) $cond=$and.' true ';
116  $cond.=" $and p_exercice='".sql_string($this->exercice)."'";
117  }
118 
119  $sql.=$cond." order by p_start,p_end";
120 
121  $Res=$this->cn->exec_sql($sql);
122  $Max=$this->cn->size($Res);
123  if ( $Max == 0 ) throw new Exception(_('Aucune periode trouvée'),1);
124  $ret='<SELECT NAME="'.$this->name.'" '.$this->javascript.'>';
125  for ( $i = 0; $i < $Max;$i++)
126  {
127  $l_line=$this->cn->fetch($i);
128  if ( $this->value==$l_line['p_id'] )
129  $sel="SELECTED";
130  else
131  $sel="";
132 
133  if ( $this->show_start_date == true && $this->show_end_date==true )
134  {
135  $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
136  ,$sel
137  ,$l_line['p_start_string']
138  ,$l_line['p_end_string']);
139  }
140  else if ($this->show_start_date == true )
141  {
142  $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
143  ,$sel
144  ,$l_line['p_start_string']
145  );
146  }
147  else if ( $this->show_end_date == true )
148  {
149  $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
150  ,$sel
151  ,$l_line['p_end_string']
152  );
153  }
154 
155  }
156  $ret.="</SELECT>";
157  return $ret;
158 
159 
160  }
161  /*!\brief print in html the readonly value of the widget*/
162  public function display()
163  {
164  $r="not implemented ".__FILE__.":".__LINE__;
165  return $r;
166 
167  }
168  static public function test_me()
169  {
170  }
171 }
const ALL
Definition: constant.php:173
static test_me()
Generate the form for the periode Data Members.
$input_from filter_year
Definition: balance.inc.php:72
__construct($p_name="", $p_value="", $p_exercice='')
input($p_name=null, $p_value=null)
show the input html for a periode
$all disabled
$ret javascript
display()
print in html the readonly value of the widget
for($e=0;$e< count($array);$e++) $desc readOnly
const OPEN
Definition: constant.php:170
$input_from show_end_date
Definition: balance.inc.php:69
$name size
$desc heigh
$from_poste name
$input_from user
Definition: balance.inc.php:73
$input_to show_start_date
Definition: balance.inc.php:85
$input_from cn
Definition: balance.inc.php:71
$input_from type
Definition: balance.inc.php:70
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
const CLOSED
Definition: constant.php:171
$select_type table
$me_code selected
const NOTCENTRALIZED
Definition: constant.php:172
$desc width