noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_icard.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Input HTML for the card show buttons
00024  *
00025  */
00026 
00027 /*!
00028  * \brief Input HTML for the card show buttons, in the file, you have to add card.js
00029  * How to use :
00030  * - label is the label in the button
00031  * - extra contents the type (all, deb or cred, a list of FD_ID between parent.  or a SQL clause
00032  * - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
00033  *  hidden field in the document, if none are set, there is no filter on the ledger
00034  *\note you must in a hidden field gDossier (dossier::hidden)
00035  *\see ajaxFid
00036  *\see card.js
00037  *\see fid.php
00038  *\see fid_card.php
00039  *\see ajax_card.php
00040  *
00041  * Set the hidden field or input field to be set by javascript with the function set_attribute
00042  * call the input method. After selecting a value the update_value function is called. If you need
00043  * to modify the queryString before the request is sent, you'll use the set_callback; the first
00044  * parameter is the INPUT field and the second the queryString, the function must returns a
00045  * queryString
00046  *\code
00047 // insert all the javascript files
00048   echo js_include('prototype.js');
00049   echo js_include('scriptaculous.js');
00050   echo js_include('effects.js');
00051   echo js_include('controls.js');
00052 
00053 //
00054   $W1=new ICard();
00055   $W1->label="Client ".HtmlInput::infobulle(0) ;
00056   $W1->name="e_client";
00057   $W1->tabindex=3;
00058   $W1->value=$e_client;
00059   $W1->table=0;
00060 // If double click call the javascript fill_ipopcard
00061   $W1->set_dblclick("fill_ipopcard(this);");
00062 
00063   // Type of card : deb, cred or all
00064   $W1->set_attribute('typecard','deb');
00065 
00066   $W1->extra='deb';
00067 
00068 // Add the callback function to filter the card on the jrn
00069   $W1->set_callback('filter_card');
00070 
00071 // when value selected in the autcomplete
00072   $W1->set_function('fill_data');
00073 
00074 // when the data change
00075   $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
00076             $W1->name);
00077 
00078  // name of the field to update with the name of the card
00079   $W1->set_attribute('label','e_client_label');
00080   $client_label=new ISpan();
00081   $client_label->table=0;
00082   $f_client=$client_label->input("e_client_label",$e_client_label);
00083 
00084   $f_client_qcode=$W1->input();
00085 
00086 // Search button for card
00087   $f_client_bt=$W1->search();
00088 * \endcode
00089 For searching a card, you need a popup, the script card.js and set
00090 the values for card, popup filter_card callback
00091 @code
00092 $card=new ICard('acc');
00093 $card->name="acc";
00094 $card->extra="all";
00095 $card->set_attribute('typecard','all');
00096 $card->set_callback('filter_card');
00097 
00098 echo $card->input();
00099 echo $card->search();
00100 // example 2
00101 $w=new ICard("av_text".$attr->ad_id);
00102 // filter on frd_id
00103 $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
00104 $filter=$this->cn->make_list($sql);
00105 $w->set_attribute('ipopup','ipopcard');
00106 $w->set_attribute('typecard',$filter);
00107 $w->set_attribute('inp',"av_text".$attr->ad_id);
00108 $w->set_attribute('label',"av_text".$attr->ad_id."_label");
00109 
00110 $w->extra=$filter;
00111 $w->extra2=0;
00112 $label=new ISpan();
00113 $label->name="av_text".$attr->ad_id."_label";
00114 $msg.=td($w->search().$label->input());
00115 @endcode
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->autocomplete=1;
00130                 $this->id=($p_id != "")?$p_id:$name;
00131     }
00132     /*!\brief set the javascript callback function
00133      * by default it is update_value called BEFORE the querystring is send
00134      *
00135      *\param $p_name callback function name
00136      */
00137     function set_callback($p_name)
00138     {
00139         $this->callback=$p_name;
00140     }
00141 
00142     /*!\brief set the javascript callback function
00143      * by default it is update_value called AFTER an item has been selected
00144      *\param $p_name callback function name
00145      */
00146     function set_function($p_name)
00147     {
00148         $this->fct=$p_name;
00149     }
00150     /*!\brief return the html string for creating the ipopup, this ipopup
00151      * can be used for adding, modifying or display a card
00152      *@note ipopup is obsolete, the popin is created by javascript
00153      *\param $p_name name of the ipopup, must be set after with set_attribute
00154     \code
00155       $f_add_button=new IButton('add_card');
00156       $f_add_button->label='Créer une nouvelle fiche';
00157       $f_add_button->set_attribute('ipopup','ipop_newcard');
00158       $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
00159       $f_add_button->javascript=" select_card_type(this);";
00160       $str_add_button=$f_add_button->input();
00161 
00162     \endcode
00163      *\return html string
00164      *\note must be one of first instruction on a new page, to avoid problem
00165      * of position with IE
00166      */
00167     static function ipopup($p_name)
00168     {
00169         $ip_card=new IPopup ($p_name);
00170         $ip_card->drag=true;
00171                 $ip_card->set_width('45%');
00172         $ip_card->title='Fiche ';
00173         $ip_card->value='';
00174         return $ip_card->input();
00175     }
00176     /*!\brief set the extra javascript property for a double click on
00177      *  INPUT field
00178      *\param $p_action action when a double click happens
00179      *\note the $p_action cannot contain a double quote
00180      */
00181     function set_dblclick($p_action)
00182     {
00183         $this->dblclick=$p_action;
00184     }
00185     /*!\brief show the html  input of the widget*/
00186     public function input($p_name=null,$p_value=null)
00187     {
00188         if ( $p_name == null && $this->name == "")
00189             throw (new Exception('Le nom d une icard doit être donne'));
00190 
00191         $this->value=($p_value==null)?$this->value:$p_value;
00192         if ( $this->readOnly==true) return $this->display();
00193 
00194                  $this->id=($this->id=="")?$this->name:$this->id;
00195 
00196         $attr=$this->get_js_attr();
00197 
00198         $label='';
00199         if ( $this->dblclick != '')
00200         {
00201             $e=sprintf(' ondblclick="%s" ',
00202                        $this->dblclick);
00203             $this->dblclick=$e;
00204         }
00205         $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
00206                        ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
00207                        $this->name,
00208                        $this->id,
00209                        $this->value,
00210                        $this->size,
00211                        $this->dblclick,
00212                        $this->javascript
00213                       );
00214                 if ( $this->autocomplete == 1)
00215                 {
00216                         $ind=sprintf('<span id="%s_ind" class="autocomplete" style="display:none">Un instant... <img src="image/loading.gif" alt="Chargement..."/>'.
00217                                                 '</span>',
00218                                                 $this->id);
00219 
00220                         $div=sprintf('<div id="%s_choices"  class="autocomplete"></div>',
00221                                                 $this->id);
00222 
00223                         $query=dossier::get().'&e='.urlencode($this->typecard);
00224 
00225                         $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","fid_card.php?%s",'.
00226                                                                 '{paramName:"FID",minChars:1,indicator:null, '.
00227                                                                 'callback:%s, '.
00228                                                                 ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
00229                                                                 $this->id,$this->id,$query,
00230                                                                 $this->callback,
00231                                                                 $this->fct);
00232 
00233                         $javascript=create_script($javascript.$this->dblclick);
00234 
00235                         $r=$label.$input.$attr.$ind.$div.$javascript;
00236                 }
00237                 else
00238                 {
00239                         $r=$label.$input;
00240                 }
00241         if ( $this->table == 1 )
00242             $r=td($r);
00243         return $r;
00244 
00245     }
00246     /*!\brief print in html the readonly value of the widget*/
00247     public function display()
00248     {
00249         $r=sprintf('         <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" SIZE="8">',
00250                    $this->name,
00251                    $this->name,
00252                    $this->value
00253                   );
00254         $r.='<span>'.$this->value.'</span>';
00255         return $r;
00256 
00257     }
00258     /**
00259      *@brief return a string containing the button for displaying
00260      * a search form. When clicking on the result, update the input text file
00261      * the common used attribute as
00262      *   - jrn   the ledger
00263      *   - label the field to update
00264      *   - name name of the input text
00265      *   - price amount
00266      *   - tvaid
00267      *   - typecard (deb, cred, filter or list of value)
00268      * will be set
00269      * if ICard is in readOnly, the button disappears, so the return string is empty
00270     \code
00271       // search ipopup
00272     $search_card=new IPopup('ipop_card');
00273     $search_card->title=_('Recherche de fiche');
00274     $search_card->value='';
00275     echo $search_card->input();
00276 
00277     $a=new ICard('test');
00278     $a->search();
00279 
00280     \endcode
00281      *\see ajax_card.php
00282      *\note the ipopup id is hard coded : ipop_card
00283      *@return HTML string with the button
00284      */
00285     function search()
00286     {
00287         if ( $this->readOnly==true) return '';
00288                 if ( ! isset($this->id )) $this->id=$this->name;
00289         $button=new ISmallButton($this->name.'_bt',"","","smallbutton");
00290         $button->label=_('Recherche');
00291         $a="";
00292         foreach (array('typecard','jrn','label','price','tvaid') as $att)
00293         {
00294             if (isset($this->$att) )
00295                 $a.="this.".$att."='".$this->$att."';";
00296         }
00297         if (isset($this->id) && $this->id != "")
00298             $a.="this.inp='".$this->id."';";
00299                 else
00300             $a.="this.inp='".$this->name."';";
00301         $a.="this.popup='ipop_card';";
00302                 $button->tabindex=-1;
00303         $button->javascript=$a.' search_card(this)';
00304         return $button->input();
00305     }
00306 
00307     static public function test_me()
00308     {
00309         require_once('class_itext.php');
00310         $_SESSION['isValid']=1;
00311         $a=new ICard('testme');
00312         $a->extra="all";
00313         $a->set_attribute('label','ctl_label');
00314         $a->set_attribute('tvaid','ctl_tvaid');
00315         $a->set_attribute('price','ctl_price');
00316         $a->set_attribute('purchase','ctl_purchase');
00317         $a->set_attribute('type','all');
00318         echo <<<EOF
00319           <div id="debug" style="border:solid 1px black;overflow:auto"></div>
00320           <script type="text/javascript" language="javascript"  src="js/prototype.js">
00321           </script>
00322           <script type="text/javascript" language="javascript"  src="js/scriptaculous.js">
00323           </script>
00324           <script type="text/javascript" language="javascript"  src="js/effects.js">
00325           </script>
00326           <script type="text/javascript" language="javascript"  src="js/controls.js">
00327           </script>
00328           <script type="text/javascript" language="javascript"  src="js/ajax_fid.js">
00329           </script>
00330           <script type="text/javascript" language="javascript"  >
00331           function test_value(text,li)
00332           {
00333             alert("premier"+li.id);
00334 
00335             str="";
00336             str=text.id+'<hr>';
00337             if ( text.js_attr1)
00338               {
00339                 str+=text.js_attr1;
00340                 str+='<hr>';
00341               }
00342             if ( text.js_attr2)
00343               {
00344                 str+=text.js_attr2;
00345                 str+='<hr>';
00346               }
00347             if ( text.js_attr3)
00348               {
00349                 str+=text.js_attr3;
00350                 str+='<hr>';
00351               }
00352             for (var i in text)
00353               {
00354                 str+=i+'<br>';
00355               }
00356 
00357             // $('debug').innerHTML=str;
00358             ajaxFid(text);
00359           }
00360         </script>
00361 
00362 EOF;
00363         echo "<form>";
00364         $l=new IText('ctl_label');
00365         $t=new IText('ctl_tvaid');
00366         $p=new IText('ctl_price');
00367         $b=new IText('ctl_purchase');
00368 
00369         echo "Label ".$l->input().'<br>';
00370         echo "Tva id  ".$t->input().'<br>';
00371         echo "Price ".$p->input().'<br>';
00372         echo "Purchase ".$b->input().'<br>';
00373 
00374         if ( isset($_REQUEST['test_select']) )
00375             echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
00376         $a->set_function('test_value');
00377         $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
00378         echo $a->input();
00379         echo dossier::hidden();
00380         echo HtmlInput::submit('Entree','entree');
00381         echo '</form>';
00382         echo <<<EOF
00383 EOF;
00384     }
00385 }
 All Data Structures Namespaces Files Functions Variables Enumerations