00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 require_once('class_html_input.php');
00118 require_once('function_javascript.php');
00119
00120 class ICard extends HtmlInput
00121 {
00122 function __construct($name="",$value="",$p_id="")
00123 {
00124 parent::__construct($name,$value);
00125 $this->fct='update_value';
00126 $this->dblclick='';
00127 $this->callback='null';
00128 $this->javascript='';
00129 $this->id=($p_id != "")?$p_id:$name;
00130 $this->choice=null;
00131 $this->indicator=null;
00132 $this->choice_create=1;
00133 $this->autocomplete=1;
00134 $this->style=' style="vertical-align:50%"';
00135 }
00136
00137
00138
00139
00140
00141 function set_callback($p_name)
00142 {
00143 $this->callback=$p_name;
00144 }
00145
00146
00147
00148
00149
00150 function set_function($p_name)
00151 {
00152 $this->fct=$p_name;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 static function ipopup($p_name)
00172 {
00173 $ip_card=new IPopup ($p_name);
00174 $ip_card->drag=true;
00175 $ip_card->set_width('45%');
00176 $ip_card->title='Fiche ';
00177 $ip_card->value='';
00178
00179 return $ip_card->input();
00180 }
00181
00182
00183
00184
00185
00186 function set_dblclick($p_action)
00187 {
00188 $this->dblclick=$p_action;
00189 }
00190
00191 public function input($p_name=null,$p_value=null)
00192 {
00193 if ( $p_name == null && $this->name == "")
00194 throw (new Exception('Le nom d une icard doit être donne'));
00195
00196 $this->value=($p_value==null)?$this->value:$p_value;
00197 if ( $this->readOnly==true) return $this->display();
00198
00199 $this->id=($this->id=="")?$this->name:$this->id;
00200 $this->choice=($this->choice==null)?sprintf("%s_choices",$this->id):$this->choice;
00201 $this->indicator=($this->indicator==null)?sprintf("%s_ind",$this->id):$this->indicator;
00202 $attr=$this->get_js_attr();
00203
00204 $label='';
00205 if ( $this->dblclick != '')
00206 {
00207 $e=sprintf(' ondblclick="%s" ',
00208 $this->dblclick);
00209 $this->dblclick=$e;
00210 }
00211 $input=sprintf('<INPUT TYPE="Text" class="input_text" '.
00212 ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s %s>',
00213 $this->name,
00214 $this->id,
00215 $this->value,
00216 $this->size,
00217 $this->dblclick,
00218 $this->javascript,
00219 $this->style
00220 );
00221 if ( $this->autocomplete == 1)
00222 {
00223 $this->indicator="ind_".$this->id;
00224 $ind=sprintf('<span id="%s" class="autocomplete" style="position:absolute;display:none">Un instant... <img src="image/loading.gif" alt="Chargement..."/>'.
00225 '</span>',
00226 $this->indicator);
00227 $this->indicator="null";
00228 $div=($this->choice_create == 1) ? sprintf('<div id="%s" class="autocomplete"></div>',$this->choice):"";
00229
00230 $query=dossier::get().'&e='.urlencode($this->typecard);
00231
00232 $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s","fid_card.php?%s",'.
00233 '{paramName:"FID",minChars:1,indicator:%s, '.
00234 'callback:%s, '.
00235 ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
00236 $this->id,
00237 $this->choice,
00238 $query,
00239 $this->indicator,
00240 $this->callback,
00241 $this->fct);
00242
00243 $javascript=create_script($javascript.$this->dblclick);
00244
00245 $r=$label.$input.$attr.$ind.$div.$javascript;
00246 }
00247 else
00248 {
00249 $r=$label.$input;
00250 }
00251 if ( $this->table == 1 )
00252 $r=td($r);
00253 return $r;
00254
00255 }
00256
00257 public function display()
00258 {
00259 $r=sprintf(' <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" SIZE="8">',
00260 $this->name,
00261 $this->name,
00262 $this->value
00263 );
00264 $r.='<span>'.$this->value.'</span>';
00265 return $r;
00266
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 function search()
00296 {
00297 if ( $this->readOnly==true) return '';
00298 if ( ! isset($this->id )) $this->id=$this->name;
00299 $a="";
00300 foreach (array('typecard','jrn','label','price','tvaid') as $att)
00301 {
00302 if (isset($this->$att) )
00303 $a.="this.".$att."='".$this->$att."';";
00304 }
00305 if (isset($this->id) && $this->id != "")
00306 $a.="this.inp='".$this->id."';";
00307 else
00308 $a.="this.inp='".$this->name."';";
00309 $a.="this.popup='ipop_card';";
00310 $javascript=$a.' search_card(this);return false;';
00311
00312 $button=HtmlInput::button_image($javascript,$this->name."_bt", 'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
00313 return $button;
00314 }
00315
00316 static public function test_me()
00317 {
00318 require_once('class_itext.php');
00319 $_SESSION['isValid']=1;
00320 $a=new ICard('testme');
00321 $a->extra="all";
00322 $a->set_attribute('label','ctl_label');
00323 $a->set_attribute('tvaid','ctl_tvaid');
00324 $a->set_attribute('price','ctl_price');
00325 $a->set_attribute('purchase','ctl_purchase');
00326 $a->set_attribute('type','all');
00327 echo <<<EOF
00328 <div id="debug" style="border:solid 1px black;overflow:auto"></div>
00329 <script type="text/javascript" language="javascript" src="js/prototype.js">
00330 </script>
00331 <script type="text/javascript" language="javascript" src="js/scriptaculous.js">
00332 </script>
00333 <script type="text/javascript" language="javascript" src="js/effects.js">
00334 </script>
00335 <script type="text/javascript" language="javascript" src="js/controls.js">
00336 </script>
00337 <script type="text/javascript" language="javascript" src="js/ajax_fid.js">
00338 </script>
00339 <script type="text/javascript" language="javascript" >
00340 function test_value(text,li)
00341 {
00342 alert("premier"+li.id);
00343
00344 str="";
00345 str=text.id+'<hr>';
00346 if ( text.js_attr1)
00347 {
00348 str+=text.js_attr1;
00349 str+='<hr>';
00350 }
00351 if ( text.js_attr2)
00352 {
00353 str+=text.js_attr2;
00354 str+='<hr>';
00355 }
00356 if ( text.js_attr3)
00357 {
00358 str+=text.js_attr3;
00359 str+='<hr>';
00360 }
00361 for (var i in text)
00362 {
00363 str+=i+'<br>';
00364 }
00365
00366
00367 ajaxFid(text);
00368 }
00369 </script>
00370
00371 EOF;
00372 echo "<form>";
00373 $l=new IText('ctl_label');
00374 $t=new IText('ctl_tvaid');
00375 $p=new IText('ctl_price');
00376 $b=new IText('ctl_purchase');
00377
00378 echo "Label ".$l->input().'<br>';
00379 echo "Tva id ".$t->input().'<br>';
00380 echo "Price ".$p->input().'<br>';
00381 echo "Purchase ".$b->input().'<br>';
00382
00383 if ( isset($_REQUEST['test_select']) )
00384 echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
00385 $a->set_function('test_value');
00386 $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
00387 echo $a->input();
00388 echo dossier::hidden();
00389 echo HtmlInput::submit('Entree','entree');
00390 echo '</form>';
00391 echo <<<EOF
00392 EOF;
00393 }
00394 }