noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_ianccard.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
00029 */
00030 require_once('class_html_input.php');
00031 require_once('function_javascript.php');
00032 
00033 class IAncCard extends HtmlInput
00034 {
00035     function __construct($name="",$value="",$p_id="")
00036     {
00037         parent::__construct($name,$value,$p_id);
00038         $this->fct='update_value';
00039         $this->dblclick='';
00040         $this->callback='null';
00041         $this->javascript='';
00042         // the pa_id to filter
00043         $this->plan=0;
00044         // or the container of the Plan Analytic which contains the pa_id
00045         $this->plan_ctl="";
00046     }
00047     /*!\brief set the javascript callback function
00048      * by default it is update_value called BEFORE the querystring is send
00049      * If you use the plan ctl must be set to filter_anc
00050      *\param $p_name callback function name
00051      */
00052     function set_callback($p_name)
00053     {
00054         $this->callback=$p_name;
00055     }
00056 
00057     /*!\brief set the javascript callback function
00058      * by default it is update_value called AFTER an item has been selected
00059      *\param $p_name callback function name
00060      */
00061     function set_function($p_name)
00062     {
00063         $this->fct=$p_name;
00064     }
00065 
00066     /*!\brief set the extra javascript property for a double click on
00067      *  INPUT field
00068      *\param $p_action action when a double click happens
00069      *\note the $p_action cannot contain a double quote
00070      */
00071     function set_dblclick($p_action)
00072     {
00073         $this->dblclick=$p_action;
00074     }
00075     /*!\brief show the html  input of the widget*/
00076     public function input($p_name=null,$p_value=null)
00077     {
00078         if ( $p_name == null && $this->name == "")
00079             throw (new Exception('Le nom d une icard doit ĂȘtre donne'));
00080 
00081         $this->value=($p_value==null)?$this->value:$p_value;
00082         if ( $this->readOnly==true) return $this->display();
00083 
00084         $this->id=($this->id=="")?$this->name:$this->id;
00085 
00086 
00087 
00088         $label='';
00089         if ( $this->dblclick != '')
00090         {
00091             $e=sprintf(' ondblclick="%s" ',
00092                        $this->dblclick);
00093             $this->dblclick=$e;
00094         }
00095         $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
00096                        ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
00097                        $this->name,
00098                        $this->name,
00099                        $this->value,
00100                        $this->size,
00101                        $this->dblclick,
00102                        $this->javascript
00103                       );
00104 
00105 
00106         $div=sprintf('<div id="%s_choices"  class="autocomplete"></div>',
00107                      $this->name);
00108         $query="op=autoanc&".dossier::get();
00109 
00110         // add parameter to search into a plan (pa_id) or get the value from
00111         // a HtmlObject
00112         if ($this->plan <> 0)
00113         {
00114             $query.="&pa_id=".$this->plan;
00115         } elseif ( $this->plan_ctl <> '')
00116         {
00117                $this->set_attribute("plan_ctl", $this->plan_ctl);
00118         }
00119         $attr=$this->get_js_attr();
00120         $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","ajax_misc.php?%s",'.
00121                             '{paramName:"anccard",minChars:1,indicator:null, '.
00122                             'callback:%s, '.
00123                             ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
00124                             $this->name,
00125                             $this->name,
00126                             $query,
00127                             $this->callback,
00128                             $this->fct);
00129 
00130         $javascript=create_script($javascript.$this->dblclick);
00131 
00132         $r=$label.$input.$attr.$div.$javascript;
00133         if ( $this->table == 1 )
00134             $r=td($r);
00135         return $r;
00136 
00137     }
00138     /*!\brief print in html the readonly value of the widget*/
00139     public function display()
00140     {
00141         $r=sprintf('
00142                     <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">',
00143                    $this->name,
00144                    $this->value
00145                   );
00146         $r.='<span>'.$this->value.'</span>';
00147         return $r;
00148 
00149     }
00150     /**
00151      *@brief return a string containing the button for displaying
00152      * a search form. When clicking on the result, update the input text file
00153      * the common used attribute as
00154      *   - jrn   the ledger
00155      *   - label the field to update
00156      *   - name name of the input text
00157      *   - price amount
00158      *   - tvaid
00159      *   - typecard (deb, cred, filter or list of value)
00160      * will be set
00161      * if ICard is in readOnly, the button disappears, so the return string is empty
00162     \code
00163       // search ipopup
00164     $search_card=new IPopup('ipop_card');
00165     $search_card->title=_('Recherche de fiche');
00166     $search_card->value='';
00167     echo $search_card->input();
00168 
00169     $a=new ICard('test');
00170     $a->search();
00171 
00172     \endcode
00173      *\see ajax_card.php
00174      *\note the ipopup id is hard coded : ipop_card
00175      *@return HTML string with the button
00176      */
00177     function search()
00178     {
00179         if ( $this->readOnly==true) return '';
00180 
00181         $button=new IButton($this->name.'_bt');
00182         $a="";
00183         foreach (array('typecard','jrn','label','price','tvaid') as $att)
00184         {
00185             if (isset($this->$att) )
00186                 $a.="this.".$att."='".$this->$att."';";
00187         }
00188         if (isset($this->name))
00189             $a.="this.inp='".$this->name."';";
00190         $a.="this.popup='ipop_card';";
00191 
00192         $button->javascript=$a.' search_card(this)';
00193         return $button->input();
00194     }
00195 
00196     static public function test_me()
00197     {
00198 
00199     }
00200 }
 All Data Structures Namespaces Files Functions Variables Enumerations