class_iposte.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta 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  *   PhpCompta 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 PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 4842 $ */
00020 
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00022 
00023 /*!\file
00024  * \brief Html Input
00025  *
00026  */
00027 require_once('class_html_input.php');
00028 require_once('class_itext.php');
00029 require_once('class_ibutton.php');
00030 require_once('class_ipopup.php');
00031 require_once('function_javascript.php');
00032 /**
00033  *@brief show a button, for selecting a account and a input text for manually inserting an account
00034  * the different value of table are
00035  * - 0 no table, it means no TD tags
00036  * - 1 the button and the text are separated by TD tags
00037  * - 2 the button and the text are in the same column (TD)
00038  * - 3 the button and the text are in the table (TD)
00039  *\note we use the set_attribute for giving parameter to search_account
00040  * attribute are
00041  *  - gDossier
00042  *  - jrn  if set there is a filter on a ledger, in  that case, contains the jrn_id (0 for no filter)
00043  *  - account field to update with the account_number,
00044  *  - label  field to update  control with account_label,
00045  *  - bracket if true return the account_number between bracket
00046  *  - noquery don't start a search with the content
00047  *  - no_overwrite do not overwrite the existant content
00048  *  - query value to seek
00049  *@note needed javascript are
00050  - echo js_include('prototype.js');
00051  - echo js_include('scriptaculous.js');
00052  - echo js_include('effects.js');
00053  - echo js_include('controls.js');
00054  - echo js_include('dragdrop.js');
00055  - echo js_include('accounting_item.js');
00056  *\see ajax_poste.php
00057  *\code
00058 // must be done BEFORE any FORM
00059  echo js_include('prototype.js');
00060  echo js_include('scriptaculous.js');
00061  echo js_include('effects.js');
00062  echo js_include('controls.js');
00063  echo js_include('dragdrop.js');
00064  echo js_include('accounting_item.js');
00065 
00066 
00067 require_once('class_iposte.php');
00068 
00069 // In the FORM
00070 $text=new IPoste();
00071 $text->name('field');
00072 $text->value=$p_res[$i]['pvalue'];
00073 $text->set_attribute('gDossier',Dossier::id());
00074 $text->set_attribute('jrn',0);
00075 $text->set_attribute('account','field');
00076 
00077 
00078 \endcode
00079  */
00080 class IPoste extends HtmlInput
00081 {
00082 
00083     function __construct($p_name="",$p_value="")
00084     {
00085         $this->name=$p_name;
00086         $this->readOnly=false;
00087         $this->size=10;
00088         $this->value=$p_value;
00089         $this->selected="";
00090         $this->table=0;
00091         $this->disabled=false;
00092         $this->javascript="";
00093         $this->extra2="all";
00094         $this->attribute=array();
00095 
00096     }
00097 
00098     static function ipopup($p_name)
00099     {
00100         $ip=new IPopup($p_name);
00101         $ip->title='Plan comptable';
00102         $ip->value='';
00103         $ip->set_height('80%');
00104         $ip->set_zindex(20);
00105         return $ip->input();
00106     }
00107     /*!\brief create the javascript for adding the javascript properties
00108      * onto the *button*
00109      *\return a javascript surrounded by the tag <SCRIPT>
00110      */
00111     public function get_js_attr()
00112     {
00113         $attr="";
00114         /* Add properties at the widget */
00115         for ($i=0;$i< count($this->attribute);$i++)
00116         {
00117             list($name,$value)=$this->attribute[$i];
00118             $tmp1=sprintf("$('%s_bt').%s='%s';",
00119                           $this->name,
00120                           $name,
00121                           $value);
00122             $attr.=$tmp1;
00123         }
00124         $attr=create_script($attr);
00125         return $attr;
00126     }
00127 
00128     public function dsp_button()
00129     {
00130         $ib=new IButton($this->name.'_bt');
00131         $ib->javascript='search_poste(this)';
00132 
00133         /*  add the property */
00134         $sc=$this->get_js_attr();
00135         return $ib->input().$sc;
00136     }
00137     /*!\brief show the html  input of the widget*/
00138     public function input($p_name=null,$p_value=null)
00139     {
00140         $this->name=($p_name==null)?$this->name:$p_name;
00141         $this->value=($p_value==null)?$this->value:$p_value;
00142         if ( $this->readOnly==true) return $this->display();
00143         //--
00144         if ( ! isset($this->ctrl) ) $this->ctrl='none';
00145 
00146         if ( ! isset($this->javascript)) $this->javascript="";
00147 
00148         /* create the text  */
00149         $itext=new IText($this->name,$this->value);
00150 
00151         if ( isset ($this->css_size))
00152              $itext->css_size=$this->css_size;
00153         else
00154              $itext->size=$this->size;
00155 
00156                  $itext->javascript=$this->javascript;
00157         /* create the button */
00158         $ibutton=$this->dsp_button();
00159         if ( $this->table==3)
00160         {
00161             $r='<table>'.tr(td($itext->input()).td($ibutton));
00162             $r.='</table>';
00163             return $r;
00164         }
00165         $r=$itext->input().$ibutton;
00166         if ( $this->table==1) $r=td($r);
00167 
00168         return $r;
00169 
00170 
00171         //--
00172 
00173     }
00174     /*!\brief print in html the readonly value of the widget*/
00175     public function display()
00176     {
00177         $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
00178                    %s
00179 
00180                    </TD>',
00181                    $this->name,
00182                    $this->value ,
00183                    $this->value
00184                   );
00185 
00186         return $r;
00187 
00188     }
00189         /**
00190          *add a double click to poste to see his history
00191          *@note change $this->javascript
00192          */
00193         public function dbl_click_history()
00194         {
00195                 $r=' ondblclick="get_history_account(\''.$this->name.'\',\''.dossier::id().'\')"';
00196                 $this->javascript=$r;
00197         }
00198     static public function test_me()
00199     {
00200     }
00201 }