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->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     /*!\brief set the javascript callback function
00137      * by default it is update_value called BEFORE the querystring is send
00138      *
00139      *\param $p_name callback function name
00140      */
00141     function set_callback($p_name)
00142     {
00143         $this->callback=$p_name;
00144     }
00145 
00146     /*!\brief set the javascript callback function
00147      * by default it is update_value called AFTER an item has been selected
00148      *\param $p_name callback function name
00149      */
00150     function set_function($p_name)
00151     {
00152         $this->fct=$p_name;
00153     }
00154     /*!\brief return the html string for creating the ipopup, this ipopup
00155      * can be used for adding, modifying or display a card
00156      *@note ipopup is obsolete, the popin is created by javascript
00157      *\param $p_name name of the ipopup, must be set after with set_attribute
00158     \code
00159       $f_add_button=new IButton('add_card');
00160       $f_add_button->label='Créer une nouvelle fiche';
00161       $f_add_button->set_attribute('ipopup','ipop_newcard');
00162       $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
00163       $f_add_button->javascript=" select_card_type(this);";
00164       $str_add_button=$f_add_button->input();
00165 
00166     \endcode
00167      *\return html string
00168      *\note must be one of first instruction on a new page, to avoid problem
00169      * of position with IE
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     /*!\brief set the extra javascript property for a double click on
00182      *  INPUT field
00183      *\param $p_action action when a double click happens
00184      *\note the $p_action cannot contain a double quote
00185      */
00186     function set_dblclick($p_action)
00187     {
00188         $this->dblclick=$p_action;
00189     }
00190     /*!\brief show the html  input of the widget*/
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     /*!\brief print in html the readonly value of the widget*/
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      *@brief return a string containing the button for displaying
00270      * a search form. When clicking on the result, update the input text file
00271      * the common used attribute as
00272      *   - jrn   the ledger
00273      *   - label the field to update
00274      *   - name name of the input text
00275      *   - price amount
00276      *   - tvaid
00277      *   - typecard (deb, cred, filter or list of value)
00278      * will be set
00279      * if ICard is in readOnly, the button disappears, so the return string is empty
00280     \code
00281       // search ipopup
00282     $search_card=new IPopup('ipop_card');
00283     $search_card->title=_('Recherche de fiche');
00284     $search_card->value='';
00285     echo $search_card->input();
00286 
00287     $a=new ICard('test');
00288     $a->search();
00289 
00290     \endcode
00291      *\see ajax_card.php
00292      *\note the ipopup id is hard coded : ipop_card
00293      *@return HTML string with the button
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             // $('debug').innerHTML=str;
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 }
 All Data Structures Namespaces Files Functions Variables Enumerations