noalyss Version-9
ianccard.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 Input HTML for the card show buttons
24 *
25 */
26
27/*!
28* \class IAncCard
29 * \brief HtmlInput for card of analytic accountancy
30*/
31require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
32
33class IAncCard extends HtmlInput
34{
35 function __construct($name="",$value="",$p_id="")
36 {
37 parent::__construct($name,$value,$p_id);
38 $this->fct='update_value';
39 $this->dblclick='';
40 $this->callback='null';
41 $this->javascript='';
42 // the pa_id to filter
43 $this->plan=0;
44 // or the container of the Plan Analytic which contains the pa_id
45 $this->plan_ctl="";
46 }
47 /*!\brief set the javascript callback function
48 * by default it is update_value called BEFORE the querystring is send
49 * If you use the plan ctl must be set to filter_anc
50 *\param $p_name callback function name
51 */
52 function set_callback($p_name)
53 {
54 $this->callback=$p_name;
55 }
56
57 /*!\brief set the javascript callback function
58 * by default it is update_value called AFTER an item has been selected
59 *\param $p_name callback function name
60 */
61 function set_function($p_name)
62 {
63 $this->fct=$p_name;
64 }
65
66 /*!\brief set the extra javascript property for a double click on
67 * INPUT field
68 *\param $p_action action when a double click happens
69 *\note the $p_action cannot contain a double quote
70 */
72 {
73 $this->dblclick=$p_action;
74 }
75 /*!\brief show the html input of the widget*/
76 public function input($p_name=null,$p_value=null)
77 {
78 if ( $p_name == null && $this->name == "")
79 throw (new Exception(_('Le nom d une icard doit ĂȘtre donnĂ©')));
80
81 $this->value=($p_value==null)?$this->value:$p_value;
82 if ( $this->readOnly==true) return $this->display();
83
84 $this->id=($this->id=="")?$this->name:$this->id;
85
86
87
88 $label='';
89 if ( $this->dblclick != '')
90 {
91 $e=sprintf(' ondblclick="%s" ',
92 $this->dblclick);
93 $this->dblclick=$e;
94 }
95 $input=sprintf('<INPUT TYPE="Text" class="input_text" '.
96 ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
97 $this->name,
98 $this->name,
99 $this->value,
100 $this->size,
101 $this->dblclick,
102 $this->javascript
103 );
104
105
106 $div=sprintf('<div id="%s_choices" class="autocomplete"></div>',
107 $this->name);
108 $query="op=autoanc&".dossier::get();
109
110 // add parameter to search into a plan (pa_id) or get the value from
111 // a HtmlObject
112 if ($this->plan <> 0)
113 {
114 $query.="&pa_id=".$this->plan;
115 } elseif ( $this->plan_ctl <> '')
116 {
117 $this->set_attribute("plan_ctl", $this->plan_ctl);
118 }
119 $attr=$this->get_js_attr();
120 $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","ajax_misc.php?%s",'.
121 '{paramName:"anccard",minChars:1,indicator:null, '.
122 'callback:%s, '.
123 ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
124 $this->name,
125 $this->name,
126 $query,
127 $this->callback,
128 $this->fct);
129
130 $javascript=create_script($javascript.$this->dblclick);
131
132 $r=$label.$input.$attr.$div.$javascript;
133 if ( $this->table == 1 )
134 $r=td($r);
135 return $r;
136
137 }
138 /*!\brief print in html the readonly value of the widget*/
139 public function display()
140 {
141 $r=sprintf('
142 <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">',
143 $this->name,
144 $this->value
145 );
146 $r.='<span>'.$this->value.'</span>';
147 return $r;
148
149 }
150 /**
151 *@brief return a string containing the button for displaying
152 * a search form. When clicking on the result, update the input text file
153 * the common used attribute as
154 * - jrn the ledger
155 * - label the field to update
156 * - name name of the input text
157 * - price amount
158 * - tvaid
159 * - typecard (deb, cred, filter or list of value)
160 * will be set
161 * if ICard is in readOnly, the button disappears, so the return string is empty
162 \code
163 // search ipopup
164 $search_card=new IPopup('ipop_card');
165 $search_card->title=_('Recherche de fiche');
166 $search_card->value='';
167 echo $search_card->input();
168
169 $a=new ICard('test');
170 $a->search();
171
172 \endcode
173 *\see ajax_card.php
174 *\note the ipopup id is hard coded : ipop_card
175 *@return HTML string with the button
176 */
177 function search()
178 {
179 if ( $this->readOnly==true) return '';
180
181 $button=new IButton($this->name.'_bt');
182 $a="";
183 foreach (array('typecard','jrn','label','price','tvaid') as $att)
184 {
185 if (isset($this->$att) )
186 $a.="this.".$att."='".$this->$att."';";
187 }
188 if (isset($this->name))
189 $a.="this.inp='".$this->name."';";
190 $a.="this.popup='ipop_card';";
191
192 $button->javascript=$a.' search_card(this)';
193 return $button->input();
194 }
195
196 static public function test_me()
197 {
198
199 }
200}
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$input
$ret javascript
$div
$name size
$from_poste name
if(! isset($_GET['submit_query'])) $p_action
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
set_attribute($p_name, $p_value)
set the extra javascript property for the INPUT field
get_js_attr()
you can add attribute to this in javascript this function is a wrapper and create a script (in js) to...
HtmlInput for card of analytic accountancy.
set_function($p_name)
set the javascript callback function by default it is update_value called AFTER an item has been sele...
__construct($name="", $value="", $p_id="")
set_callback($p_name)
set the javascript callback function by default it is update_value called BEFORE the querystring is s...
static test_me()
set_dblclick($p_action)
set the extra javascript property for a double click on INPUT field
input($p_name=null, $p_value=null)
show the html input of the widget
display()
print in html the readonly value of the widget
search()
return a string containing the button for displaying a search form.
Html Input.
$all table
$icard readOnly
create_script($p_string)
create the HTML for adding the script tags around of the script
if( $delta< 0) elseif( $delta==0)