noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
iperiod.class.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*/
34class IPeriod extends HtmlInput
35{
36 var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL */
37 var $cn; /*!< $cn is the database connection */
38 var $show_end_date; /*!< $show_end_date is not set or false, do not show the end date */
39 var $show_start_date; /*!< $show_start_date is not set or false, do not show the start date */
40 var $filter_year; /*!< $filter_year make a filter on the default exercice by default yes */
41 var $user; /*! $user if a filter is required then we need who is the user (object User)*/
42 function __construct($p_name="",$p_value="",$p_exercice='')
43 {
44 $this->name=$p_name;
45 $this->readOnly=false;
46 $this->size=20;
47 $this->width=50;
48 $this->heigh=20;
49 $this->value=$p_value;
50 $this->selected="";
51 $this->table=0;
52 $this->disabled=false;
53 $this->javascript="";
54 $this->extra2="all";
55 $this->show_start_date=true;
56 $this->show_end_date=true;
57 $this->exercice=$p_exercice;
58 $this->id=$p_name;
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=sprintf('<SELECT NAME="%s" id="%s" %s>',
125 $this->name,
126 $this->id,
127 $this->javascript)
128 ;
129 for ( $i = 0; $i < $Max;$i++)
130 {
131 $l_line=$this->cn->fetch($i);
132 if ( $this->value==$l_line['p_id'] )
133 $sel="SELECTED";
134 else
135 $sel="";
136
137 if ( $this->show_start_date == true && $this->show_end_date==true )
138 {
139 $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
140 ,$sel
141 ,$l_line['p_start_string']
142 ,$l_line['p_end_string']);
143 }
144 else if ($this->show_start_date == true )
145 {
146 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
147 ,$sel
148 ,$l_line['p_start_string']
149 );
150 }
151 else if ( $this->show_end_date == true )
152 {
153 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
154 ,$sel
155 ,$l_line['p_end_string']
156 );
157 }
158
159 }
160 $ret.="</SELECT>";
161 return $ret;
162
163
164 }
165 /*!\brief print in html the readonly value of the widget*/
166 public function display()
167 {
168 $r="not implemented ".__FILE__.":".__LINE__;
169 return $r;
170
171 }
172 static public function test_me()
173 {
174 }
175}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$select selected
$ret javascript
$name size
$input_from filter_year
$input_from user
$input_from show_end_date
$input_from cn
$from_poste name
$input_to show_start_date
_("actif, passif,charge,...")
$input_from type
Generate the form for the periode Data Members.
display()
print in html the readonly value of the widget
__construct($p_name="", $p_value="", $p_exercice='')
input($p_name=null, $p_value=null)
show the input html for a periode
static test_me()
$all table
const OPEN
Definition constant.php:201
const NOTCENTRALIZED
Definition constant.php:203
const CLOSED
Definition constant.php:202
const ALL
Definition constant.php:204
$icard readOnly
$all disabled
$p_exercice
$desc heigh
$desc width