noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_html_input.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 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /*! \file
00024  * \brief This class is used to create all the HTML INPUT TYPE
00025  */
00026 
00027 /*!
00028  * \brief class widget This class is used to create all the HTML INPUT TYPE
00029  *        and some specials which works with javascript like
00030  *        js_search.
00031  *
00032  * special value
00033  *    js_search and js_search_only :you need to add a span widget the name
00034  *    of the js_* widget + '_label' , the member extra contains cred,deb to
00035  *    filter the search of cred of deb of a jrn or contains a string with
00036  *    a list of frd_id.
00037  *    Possible type
00038  *    $type
00039  *      - TEXT
00040  *      - HIDDEN
00041  *      - BUTTON in this->js you have the javascript code
00042  *      - SELECT the options are passed via this->value, this array is
00043  *        build thanks the make_array function, each array (of the
00044  *        array) aka row must contains a field value and a field label
00045  *      - PASSWORD
00046  *      - CHECKBOX
00047  *      - RADIO
00048  *      - TEXTAREA
00049  *      - RICHTEXT
00050  *      - FILE
00051  *      - SPAN
00052  */
00053 class HtmlInput
00054 {
00055 
00056     var $type;                      /*!<  $type type of the widget */
00057     var $name;                      /*!<  $name field NAME of the INPUT */
00058     var $value;                     /*!<  $value what the INPUT contains */
00059     var $readOnly;                  /*!<  $readonly true : we cannot change value */
00060     var $size;                      /*!<  $size size of the input */
00061     var $selected;                  /*!<  $selected for SELECT RADIO and CHECKBOX the selected value */
00062     var $table;                     /*!<  $table =1 add the table tag */
00063     var $label;                     /*!<  $label the question before the input */
00064     var $disabled;                  /*!<  $disabled poss. value == true or nothing, to disable INPUT*/
00065     var $extra;                     /*!<  $extra different usage, it depends of the $type */
00066     var $extra2;                    /*!<  $extra2 different usage,
00067                                                                                 it depends of the $type */
00068     var $javascript;                               /*!< $javascript  is the javascript to add to the widget */
00069     var $ctrl;                                          /*!<$ctrl is the control to update (see js_search_card_control) */
00070 
00071     var $tabindex;
00072     function __construct($p_name="",$p_value="",$p_id="")
00073     {
00074         $this->name=$p_name;
00075         $this->readOnly=false;
00076         $this->size=20;
00077         $this->width=50;
00078         $this->heigh=20;
00079         $this->value=$p_value;
00080         $this->selected="";
00081         $this->table=0;
00082         $this->disabled=false;
00083         $this->javascript="";
00084         $this->extra2="all";
00085         $this->attribute=array();
00086         $this->id=$p_id;
00087 
00088     }
00089     function setReadOnly($p_read)
00090     {
00091         $this->readOnly=$p_read;
00092     }
00093     /*!\brief set the extra javascript property for the INPUT field
00094      *\param $p_name name of the parameter
00095      *\param $p_value default value of this parameter
00096      */
00097     public function set_attribute($p_name,$p_value)
00098     {
00099         $this->attribute[]=array($p_name,$p_value);
00100         $this->$p_name=$p_value;
00101     }
00102     /**
00103      *@brief you can add attribute to this in javascript
00104      * this function is a wrapper and create a script (in js) to modify
00105      * "this" (in javascript) with the value of obj->attribute from PHP
00106      *@return return string with the javascript code
00107      */
00108     public function get_js_attr()
00109     {
00110         require_once('function_javascript.php');
00111         $attr="";
00112         if ( count($this->attribute) == 0) return "";
00113 
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').%s='%s';",
00119                           $this->name,
00120                           $name,
00121                           $value);
00122             $attr.=$tmp1;
00123         }
00124         $attr=create_script($attr);
00125         return $attr;
00126     }
00127     /**
00128      * Make a JSON object, this method create a javascript object
00129      * with the attribute set, it returns a javascript string with the object
00130      * @param $p_name : name of the object, can be null. If the name is not null, return
00131      * $p_name={} otherwise only the object {}
00132      * @return javascript string with the object
00133      * @note: there is not check on the key->value, so you could need to escape
00134      * special char as quote, single-quote...
00135      * @code
00136     $a=new IButton()
00137     $a->set_attribute('prop','1');
00138     $a->set_attribute('prop','2');
00139     $a->set_attribute('prop','3');
00140     $string = $a->make_object('property');
00141     echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
00142     $string = $a->make_object(null);
00143     echo $string => {'prop':'1','prop2':'2','prop3':'3'};
00144     @endcode
00145     */
00146     public function make_object($p_name=null)
00147     {
00148         $name=($p_name != null)?$p_name.'=':'';
00149         if ( count($this->attribute) == 0) return $name."{}";
00150         $ret=$name."{";
00151         $and='';
00152 
00153         for ($i=0;$i< count($this->attribute);$i++)
00154         {
00155             list($name,$value)=$this->attribute[$i];
00156             $tmp1=sprintf($and."'%s':'%s'",
00157                           $name,
00158                           $value);
00159             $ret.=$tmp1;
00160             $and=',';
00161         }
00162 
00163         $ret.='}';
00164         return $ret;
00165     }
00166     //#####################################################################
00167     /* Debug
00168      */
00169     function debug()
00170     {
00171         echo "Type ".$this->type."<br>";
00172         echo "name ".$this->name."<br>";
00173         echo "value". $this->value."<br>";
00174         $readonly=($this->readonly==false)?"false":"true";
00175         echo "read only".$readonly."<br>";
00176     }
00177     static   function submit ($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
00178     {
00179 
00180         return '<INPUT TYPE="SUBMIT" class="'.$p_class.'" NAME="'.$p_name.'" ID="'.$p_name.'_submit_id"  VALUE="'.$p_value.'" '.$p_javascript.'>';
00181     }
00182     static   function button ($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
00183     {
00184 
00185         return '<INPUT TYPE="button" class="'.$p_class.'" NAME="'.$p_name.'" ID="'.$p_name.'" VALUE="'.$p_value.'" '.$p_javascript.'>';
00186     }
00187 
00188     static function reset ($p_value)
00189     {
00190         return '<INPUT TYPE="RESET" class="smallbutton" VALUE="'.$p_value.'">';
00191     }
00192     static function hidden($p_name,$p_value,$p_id="")
00193     {
00194                 if ($p_id=="") $p_id=$p_name;
00195         return '<INPUT TYPE="hidden" id="'.$p_id.'" NAME="'.$p_name.'" VALUE="'.$p_value.'">';
00196     }
00197 
00198     static function extension()
00199     {
00200         return self::hidden('plugin_code',$_REQUEST['plugin_code']);
00201     }
00202 
00203     /*!\brief create a button with a ref
00204      *\param $p_label the text
00205      *\param $p_value the location of the window,
00206      *\param $p_name the id of the span
00207      *\param $p_javascript javascript for this button
00208      *\return string with htmlcode
00209      */
00210     static function button_anchor($p_label,$p_value,$p_name="",$p_javascript="",$p_class="button")
00211     {
00212         $r=sprintf('<span id="%s" > <A class="'.$p_class.'" style="display:inline;"  href="%s" %s >%s</A></span>',
00213                    $p_name,
00214                    $p_value,
00215                    $p_javascript,
00216                    $p_label);
00217         return $r;
00218     }
00219     static function infobulle($p_comment)
00220     {
00221         $r='<A HREF="#" tabindex="-1" style="display:inline;color:black;background-color:yellow;padding-left:4px;width:2em;padding-right:4px;text-decoration:none;" onmouseover="showBulle(\''.$p_comment.'\')"  onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">?</A>';
00222         return $r;
00223     }
00224     static function warnbulle($p_comment)
00225     {
00226         $r='<A HREF="#" tabindex="-1" style="display:inline;color:red;background-color:white;padding-left:4px;padding-right:4px;text-decoration:none;" onmouseover="showBulle(\''.$p_comment.'\')"  onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">&Delta;</A>';
00227         return $r;
00228     }
00229     /**
00230      * return a string containing the html code for calling the modifyOperation
00231      */
00232     static function detail_op($p_jr_id,$p_mesg)
00233     {
00234         return sprintf('<A class="detail" style="text-decoration:underline;display:inline" HREF="javascript:modifyOperation(%d,%d)">%s</A>',
00235                        $p_jr_id,dossier::id(),$p_mesg);
00236     }
00237         /**
00238          * @brief return an anchor to view the detail of an action
00239          * @param $ag_id
00240          * @param $p_mesg
00241          * @param $p_modify let you modify an operation
00242          *
00243          */
00244     static function detail_action($ag_id,$p_mesg,$p_modify=1)
00245     {
00246         return sprintf('<A class="detail" style="text-decoration:underline;display:inline" HREF="javascript:view_action(%d,%d,%d)">%s</A>',
00247                        $ag_id,dossier::id(),$p_modify,$p_mesg);
00248     }
00249     /**
00250      * return a string containing the html code for calling the modifyModeleDocument
00251      */
00252     static function detail_modele_document($p_id,$p_mesg)
00253     {
00254         return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyModeleDocument(%d,%d)">%s</A>',
00255                        $p_id,dossier::id(),$p_mesg);
00256     }
00257 
00258     /**
00259      * return a string containing the html code for calling the removeStock
00260      */
00261     static function remove_stock($p_id,$p_mesg)
00262     {
00263         return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:removeStock(%d,%d)">%s</A>',
00264                        $p_id,dossier::id(),$p_mesg);
00265     }
00266 
00267     /**
00268      * display a div with the history of the card
00269      */
00270     static function history_card($f_id,$p_mesg,$p_style="")
00271     {
00272         $view_history= sprintf('<A class="detail"  style="text-decoration:underline;%s" HREF="javascript:view_history_card(\'%s\',\'%s\')" >%s</A>',
00273                                $p_style,$f_id, dossier::id(), $p_mesg);
00274         return $view_history;
00275     }
00276     /**
00277      * display a div with the history of the card
00278      */
00279     static function history_card_button($f_id,$p_mesg)
00280     {
00281       static $e=0;
00282       $e++;
00283       $js= sprintf('onclick="view_history_card(\'%s\',\'%s\')"',
00284                                $f_id, dossier::id());
00285       $view_history=HtmlInput::button("hcb"+$e,$p_mesg,$js);
00286       return $view_history;
00287     }
00288 
00289     /**
00290      * display a div with the history of the account
00291      */
00292     static function history_account($p_account,$p_mesg,$p_style="")
00293     {
00294         $view_history= sprintf('<A class="detail" style="text-decoration:underline;%s" HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
00295                                $p_style,$p_account, dossier::id(), $p_mesg);
00296         return $view_history;
00297     }
00298 
00299     /**
00300      * return the html code to create an hidden div and a button
00301      * to show this DIV. This contains all the available ledgers
00302      * for the user in READ or RW
00303      *@param $selected is an array of checkbox
00304      *@param $div div suffix
00305      *@note the choosen ledger are stored in the array r_jrn (_GET)
00306      */
00307     static function select_ledger($p_type,$p_selected,$div='')
00308     {
00309         global $g_user;
00310         $r = '';
00311         /* security : filter ledger on user */
00312         $p_array = $g_user->get_ledger($p_type, 3);
00313         
00314         ob_start();
00315         
00316 
00317         /* create a hidden div for the ledger */
00318         echo '<div id="div_jrn'.$div.'" >';
00319         echo HtmlInput::title_box(_("Journaux"), $div."jrn_search");
00320         echo '<div style="padding:5px">';
00321         echo '<form method="GET" id="'.$div.'search_frm" onsubmit="return hide_ledger_choice(\''.$div.'search_frm\')">';
00322         echo HtmlInput::hidden('nb_jrn', count($p_array));
00323         echo _('Filtre ').HtmlInput::filter_table($div.'tb_jrn', '0,1,2', 1);
00324         echo '<table class="result" id="'.$div.'tb_jrn">';
00325         echo '<tr>';
00326         echo th(_('Nom'));
00327         echo th(_('Description'));
00328         echo th(_('Type'));
00329         echo '</tr>';
00330         
00331         for ($e=0;$e<count($p_array);$e++)
00332         {
00333             $row=$p_array[$e];
00334             $r=new ICheckBox($div.'r_jrn'.$e,$row['jrn_def_id']);
00335             $idx=$row['jrn_def_id'];
00336             if ( $p_selected != null &&  in_array($row['jrn_def_id'],$p_selected))
00337             {
00338                 $r->selected=true;
00339             }
00340             $class=($e%2==0)?' class="even" ':' class="odd" ';
00341             echo '<tr '.$class.'>';
00342             echo '<td style="white-space: nowrap">'.$r->input().$row['jrn_def_name'].'</td>';
00343             echo '<td >'.$row['jrn_def_description'].'</td>';
00344             echo '<td >'.$row['jrn_def_type'].'</td>';
00345             echo '</tr>';
00346 
00347         }
00348         echo '</table>';
00349         echo HtmlInput::hidden('div',$div);
00350         echo HtmlInput::submit('save',_('Valider'));
00351         echo HtmlInput::button_close($div."jrn_search");
00352         echo '</form>';
00353         echo '</div>';
00354         echo '</div>';
00355   
00356         $ret=ob_get_contents();
00357         ob_end_clean();
00358         return $ret;
00359     }
00360     /**
00361      *create a hidden plus button to select the cat of ledger
00362      *@note the selected value is stored in the array p_cat
00363      */
00364     static function select_cat($array_cat)
00365     {
00366         ob_start();
00367         $ledger=new ISmallButton('l');
00368         $ledger->label=_("Catégorie");
00369         $ledger->javascript=" show_cat_choice()";
00370         echo $ledger->input();
00371 
00372         /* create a hidden div for the ledger */
00373         echo '<div id="div_cat">';
00374         echo '<h2 class="info">'._('Choix des categories').'</h2>';
00375         $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
00376 
00377         echo '<ul>';
00378         for ($e=0;$e<count($array_cat);$e++)
00379         {
00380             $row=$array_cat[$e];
00381             $re=new ICheckBox('r_cat['.$e.']',$row['cat']);
00382 
00383             if ( $selected != null && isset($selected[$e]))
00384             {
00385                 $re->selected=true;
00386             }
00387             echo '<li style="list-style-type: none;">'.$re->input().$row['name'].'('.$row['cat'].')</li>';
00388 
00389         }
00390         echo '</ul>';
00391         $hide=new IButton('l');
00392         $hide->label=_("Valider");
00393         $hide->javascript=" hide_cat_choice() ";
00394         echo $hide->input();
00395 
00396         echo '</div>';
00397         $r=ob_get_contents();
00398         ob_end_clean();
00399         return $r;
00400     }
00401     static function display_periode($p_id)
00402     {
00403       $r=sprintf('<a href="javascript:void(0)" onclick="display_periode(%d,%d)">Modifier</a>',
00404                  dossier::id(),
00405                  $p_id);
00406       return $r;
00407     }
00408     /**
00409      *close button for the HTML popup
00410      *@see add_div modify_operation
00411      *@param $div_name is the name of the div to remove
00412      */
00413     static function button_close($div_name)
00414     {
00415       $a=new IButton('Fermer',_('Fermer'));
00416       $a->label=_("Fermer");
00417       $a->javascript="removeDiv('".$div_name."')";
00418       $html=$a->input();
00419 
00420       return $html;
00421 
00422     }
00423     /**
00424      * Return a html string with an anchor which close the inside popup. (top-right corner)
00425      *@param name of the DIV to close
00426      */
00427     static function anchor_close($div)
00428     {
00429         $r='';
00430         $r.='<div style="position:absolute;right:2px;margin:2px;padding:0px;">';
00431         $r.= '<A id="close_div" class="input_text" onclick="removeDiv(\''.$div.'\');">'._('Fermer').'</A>';
00432         $r.='</div>';
00433         return $r;
00434     }
00435     /**
00436      * button Html
00437      *@param $action action action to perform (message) without onclick
00438      *@param $javascript javascript to execute
00439      */
00440     static function button_action($action,$javascript,$id="xx",$p_class="button")
00441     {
00442         if ($id=="xx"){
00443             $id=HtmlInput::generate_id("xx");
00444         }
00445                 $r="";
00446                 $r.='<input type="button" id="'.$id.'" class="'.$p_class.'" onclick="'.$javascript.'" value="'.h($action).'">';
00447                 return $r;
00448 
00449     }
00450     /**
00451      * button Html image
00452      *@param $javascript javascript to execute
00453      * @param $id id of the button
00454      * @param  $class class of the button
00455      * @param $p_image image
00456      */
00457     static function button_image($javascript,$id="xx",$p_class='class="button"',$p_image="")
00458     {
00459         if ($id=="xx"){
00460             $id=HtmlInput::generate_id("xx");
00461         }
00462         $r="";
00463         $r.='<image id="'.$id.'" '.$p_class.' onclick="'.$javascript.'"  src="'.$p_image.'" />';
00464         return $r;
00465 
00466     }
00467     /**
00468      * Return a html string with an anchor to hide a div, put it in the right corner
00469      *@param $action action action to perform (message)
00470      *@param $javascript javascript
00471      *@note not protected against html
00472      *@see Acc_Ledger::display_search_form
00473      */
00474     static function anchor_hide($action,$javascript)
00475     {
00476         $r='';
00477         $r.='<div style="position:absolute;margin:2px;right:2px">';
00478         $r.= '<span id="close_div" class="input_text"  onclick="'.$javascript.'">'.$action.'</span>';
00479         $r.='</div>';
00480         return $r;
00481     }
00482 
00483     /**
00484      * Javascript to print the current window
00485      */
00486     static function print_window()
00487     {
00488         $r='';
00489         $r.=HtmlInput::button('print','Imprimer','onclick="window.print();"');
00490         return $r;
00491     }
00492     /**
00493      *show the detail of a card
00494      */
00495     static function card_detail($p_qcode,$pname='',$p_style="",$p_nohistory=false)
00496     {
00497       //if ($pname=='')$pname=$p_qcode;
00498       $r="";
00499       $histo=($p_nohistory==true)?' ,nohistory:1':"";
00500       $r.=sprintf('<a href="javascript:void(0)" %s onclick="fill_ipopcard({qcode:\'%s\' %s})">%s [%s]</a>',
00501                   $p_style,$p_qcode,$histo,$pname,$p_qcode);
00502       return $r;
00503     }
00504     /**
00505      *transform request data  to hidden
00506      *@param $array is an of indices
00507      *@param $request name of the superglobal $_POST $_GET $_REQUEST(default)
00508      *@return html string with the hidden data
00509      */
00510     static function array_to_hidden($array,$global_array )
00511     {
00512 
00513       $r="";
00514 
00515       if ( count($global_array )==0) return '';
00516       foreach ($array  as $a)
00517         {
00518           if (isset($global_array [$a])) 
00519           if (is_array($global_array[$a]) == false ) {
00520                 $r.=HtmlInput::hidden($a,$global_array [$a]);
00521               } else {
00522                   if (count($global_array[$a]) > 0)
00523                   {
00524                       foreach ($global_array[$a] as $value)
00525                       {
00526                           $r.=HtmlInput::hidden($a."[]",$value);
00527                     }
00528                   }
00529               }
00530         }
00531 
00532       return $r;
00533     }
00534     /**
00535      *transform $_GET   data  to hidden
00536      *@param $array is an of indices
00537      *@see HtmlInput::request_to_hidden
00538      *@return html string with the hidden data
00539      */
00540     static function get_to_hidden($array)
00541     {
00542       $r=self::array_to_hidden($array,$_GET );
00543       return $r;
00544     }
00545 
00546     /**
00547      *transform $_POST  data  to hidden
00548      *@param $array is an of indices
00549      *@see HtmlInput::request_to_hidden
00550      *@return html string with the hidden data
00551      */
00552     static function post_to_hidden($array)
00553     {
00554       $r=self::array_to_hidden($array,$_POST );
00555       return $r;
00556     }
00557 
00558     /**
00559      *transform $_REQUEST   data  to hidden
00560      *@param $array is an of indices
00561      *@see HtmlInput::request_to_hidden
00562      *@return html string with the hidden data
00563      */
00564     static function request_to_hidden($array)
00565     {
00566       $r=self::array_to_hidden($array,$_REQUEST  );
00567       return $r;
00568     }
00569 
00570     /**
00571      *transform request data  to string
00572      *@param $array is an of indices
00573      *@param $request name of the superglobal $_POST $_GET $_REQUEST(default)
00574      *@return html string with the string data
00575      */
00576     static function array_to_string($array,$global_array,$start="?" )
00577     {
00578 
00579       $r=$start;
00580 
00581       if ( count($global_array )==0) return '';
00582       $and="";
00583       foreach ($array  as $a)
00584         {
00585           if (isset($global_array [$a]))
00586           {
00587               if (is_array($global_array[$a]) == false ) {
00588                 $r.=$and."$a=".$global_array [$a];
00589               } else {
00590                   for ($i=0;$i<count($global_array[$a]);$i++) {
00591                       $r.=$and."$a"."[]=".$global_array[$a][$i];
00592                       $and="&amp;";
00593                   }
00594               }
00595           }
00596           $and="&amp;";
00597         }
00598 
00599       return $r;
00600     }
00601     /**
00602      *transform $_GET   data  to string
00603      *@param $array is an of indices
00604      *@see HtmlInput::request_to_string
00605      *@return html string with the string data
00606      */
00607     static function get_to_string($array,$start="?")
00608     {
00609       $r=self::array_to_string($array,$_GET ,$start);
00610       return $r;
00611     }
00612 
00613     /**
00614      *transform $_POST  data  to string
00615      *@param $array is an of indices
00616      *@see HtmlInput::request_to_string
00617      *@return html string with the string data
00618      */
00619     static function post_to_string($array)
00620     {
00621       $r=self::array_to_string($array,$_POST );
00622       return $r;
00623     }
00624 
00625     /**
00626      *transform $_REQUEST   data  to string
00627      *@param $array is an of indices
00628      *@see HtmlInput::request_to_string
00629      *@return html string with the string data
00630      */
00631     static function request_to_string($array,$start="?")
00632     {
00633       $r=self::array_to_string($array,$_REQUEST,$start  );
00634       return $r;
00635     }
00636 
00637     /**
00638      * generate an unique id for a widget,
00639      *@param $p_prefix prefix
00640      *@see HtmlInput::IDate
00641      *@return string with a unique id
00642      */
00643     static function generate_id($p_prefix)
00644     {
00645       $r=sprintf('%s_%d',$p_prefix,mt_rand(0,999999));
00646       return $r;
00647     }
00648     /**
00649      * return default if the value if the value doesn't exist in the array
00650      *@param $ind the index to check
00651      *@param $default the value to return
00652      *@param $array the array
00653      */
00654     static function default_value($ind,$default,$array)
00655     {
00656       if ( ! isset($array[$ind]))
00657         {
00658           return $default;
00659         }
00660       return $array[$ind];
00661     }
00662         /**
00663          *  return default if the value if the value doesn't exist in $_GET
00664          * @param  $ind name of the variable
00665          * @param type $default
00666          * @return type
00667          */
00668         static function default_value_get($ind, $default)
00669         {
00670                 if (!isset($_GET[$ind]))
00671                 {
00672                         return $default;
00673                 }
00674                 return $_GET[$ind];
00675         }
00676         /**
00677          *  return default if the value if the value doesn't exist in $_POST
00678          * @param  $ind name of the variable
00679          * @param type $default
00680          * @return type
00681          */
00682         static function default_value_post($ind, $default)
00683         {
00684                 if (!isset($_POST[$ind]))
00685                 {
00686                         return $default;
00687                 }
00688                 return $_POST[$ind];
00689         }
00690         /**
00691          *  return default if the value if the value doesn't exist in $_REQUEST
00692          * @param  $ind name of the variable
00693          * @param type $default
00694          * @return type
00695          */
00696         static function default_value_request($ind, $default)
00697         {
00698                 if (!isset($_REQUEST[$ind]))
00699                 {
00700                         return $default;
00701                 }
00702                 return $_REQUEST[$ind];
00703         }
00704         /**
00705          * Title for boxes
00706          * @param type $name Title
00707          * @param type $div element id
00708          * @param type $mod hide or close
00709          * @param type $p_js if $mod is hide then you can add a javascript
00710          * @return type
00711          */
00712         static function title_box($name,$div,$mod="close",$p_js="")
00713         {
00714                 if ($mod=='close')              $r=HtmlInput::anchor_close($div);
00715                 if ($mod=='hide')               $r=HtmlInput::anchor_hide(_('Fermer'),"$('$div').hide();$p_js");
00716                 if ( $mod == 'none')    $r="";
00717                 $r.=h2($name,' class="title" ');
00718                 return $r;
00719         }
00720         /**
00721          *Return a simple anchor with a url or a javascript
00722          * if $p_js is not null then p_url will be javascript:void(0)
00723          * we don't add the event onclick. You must give p_url OR p_js
00724          * default CSS class=line
00725          * @param string $p_text text of the anchor
00726          * @param string $p_url  url
00727          * @param string $p_js javascript
00728          * @param string $p_style is the visuable effect (class, style...)
00729          */
00730       static function anchor($p_text,$p_url="",$p_js="",$p_style=' class="line" ')
00731       {
00732           if ($p_js != "")
00733           {
00734               $p_url="javascript:void(0)";
00735           }
00736 
00737 
00738           $str=sprintf('<a %s href="%s" %s>%s</a>',
00739                   $p_style,$p_url,$p_js,$p_text);
00740           return $str;
00741       }
00742       /**
00743        *Create an ISelect object containing the available repository for reading
00744        * or writing
00745        * @global $g_user
00746        * @param $p_cn db object
00747        * @param $p_name name of the select
00748        * @param $p_mode is 'R' for reading, 'W' for writinh
00749        * @return ISelect
00750        * @throws Exception if p_mode is wrong
00751        */
00752       static function select_stock( $p_cn, $p_name,$p_mode)
00753       {
00754           global $g_user;
00755           if ( ! in_array($p_mode,array('R','W') ) )
00756           {
00757               throw  new Exception  (__FILE__.":".__LINE__." $p_mode invalide");
00758           }
00759           $profile=$g_user->get_profile();
00760           $sel=new ISelect($p_name);
00761 
00762                   if ($p_mode == 'W')
00763                         {
00764                           $sel->value=$p_cn->make_array("
00765                 select r_id,r_name
00766                                   from stock_repository join profile_sec_repository using (r_id)
00767                 where
00768                  ur_right='W' and  p_id=".sql_string($profile).
00769                 " order by 2" );
00770                       return $sel;
00771                         }
00772                           if ($p_mode == 'R')
00773                         {
00774                           $sel->value=$p_cn->make_array("
00775                 select r_id,r_name
00776                                   from stock_repository join profile_sec_repository using (r_id)
00777                 where
00778                   p_id=".sql_string($profile).
00779                 " order by 2" );
00780                       return $sel;
00781                         }
00782         }
00783         static function filter_table($p_table_id,$p_col,$start_row)
00784         {
00785                 $r= "
00786                         <span>
00787                         <input id=\"lk_".$p_table_id."\" autocomplete=\"off\" class=\"input_text\" name=\"filter\" onkeyup=\"filter_table(this, '$p_table_id','$p_col',$start_row )\" type=\"text\">
00788                         <input type=\"button\" class=\"smallbutton\" onclick=\"$('lk_".$p_table_id."').value='';filter_table($('lk_".$p_table_id."'), '$p_table_id','$p_col',$start_row );\" value=\"X\">
00789                         </span>
00790                         ";
00791                 $r.=' <span class="notice" id="info_'.$p_table_id.'"></span>';
00792                 return $r;
00793         }
00794 
00795         static function show_reconcile($p_div, $let,$span="")
00796         {
00797                 $r = '<A  style="color:red;text-decoration:underline" href="javascript:void(0)" onclick="show_reconcile(\'' . $p_div . '\',\'' . $let . '\')">' . $let.$span . '</A>';
00798                 return $r;
00799         }
00800         /**
00801          * Zoom the calendar
00802          * @param type $obj objet json for the javascript
00803          * @see calendar_zoom in scripts.js 
00804          */
00805         static function calendar_zoom($obj)
00806         {
00807             $button=new ISmallButton("calendar", _("Calendrier"));
00808             $button->javascript="calendar_zoom($obj)";
00809             return $button->input();
00810         }
00811         /**
00812          * 
00813          * @param type $p_array indice
00814          *   - div div name
00815          *   - type ALL, VEN, ACH or ODS
00816          *   - all_type 1 yes 0 no
00817          * 
00818          */
00819         static function button_choice_ledger($p_array)
00820         {
00821             extract ($p_array);
00822             $bledger_param = json_encode(array(
00823                 'dossier' => $_REQUEST['gDossier'],
00824                 'type' => $type,
00825                 'all_type' => $all_type,
00826                 'div' => $div,
00827                 'class'=>'inner_box'
00828             ));
00829 
00830             $bledger_param = str_replace('"', "'", $bledger_param);
00831             $bledger = new ISmallButton('l');
00832             $bledger->label = _("choix des journaux");
00833             $bledger->javascript = " show_ledger_choice($bledger_param)";
00834             $f_ledger = $bledger->input();
00835             $hid_jrn = "";
00836             if (isset($_REQUEST[$div . 'nb_jrn']))
00837             {
00838                 for ($i = 0; $i < $_REQUEST[$div . 'nb_jrn']; $i++)
00839                 {
00840                     if (isset($_REQUEST[$div . "r_jrn"][$i]))
00841                         $hid_jrn.=HtmlInput::hidden($div . 'r_jrn[' . $i . ']', $_REQUEST[$div . "r_jrn"][$i]);
00842                 }
00843                 $hid_jrn.=HtmlInput::hidden($div . 'nb_jrn', $_REQUEST[$div . 'nb_jrn']);
00844             } else
00845             {
00846                 $hid_jrn = HtmlInput::hidden($div . 'nb_jrn', 0);
00847             }
00848             echo $f_ledger;
00849             echo '<span id="ledger_id' . $div . '">';
00850             echo $hid_jrn;
00851             echo '</span>';
00852         }
00853         /**
00854          * Returns HTML code for displaying a icon with a link to a receipt document from
00855          * the ledger 
00856          * @global $cn database connx
00857          * @param $p_jr_id jrn.jr_id
00858          * @return nothing or HTML Code for a link to the document
00859          */
00860         static function show_receipt_document($p_jr_id)
00861         {
00862             global $cn;
00863             
00864             $array=$cn->get_array('select jr_def_id,jr_pj_name,jr_grpt_id from jrn where jr_id=$1',array($p_jr_id));
00865             if (count($array)==0) return "";
00866             if ($array[0]['jr_pj_name'] == "") return "";
00867             $str_dossier=Dossier::get();
00868             $image='<IMG style="width:24px;height:24px;border:0px" SRC="image/documents.png" title="' . $array[0]['jr_pj_name'] . '" >';
00869             $r=sprintf('<A class="detail" HREF="show_pj.php?jrn=%s&jr_grpt_id=%s&%s">%s</A>', $array[0]['jr_def_id'], $array[0]['jr_grpt_id'], $str_dossier, $image);
00870             return $r;
00871             
00872         }
00873         /**
00874          * 
00875          * @param type $p_operation_jr_id action_gestion_operation.ago_id
00876          */
00877         static function  button_action_remove_operation($p_operation) 
00878         {
00879             $rmOperation=sprintf("javascript:if ( confirm('"._('Voulez-vous effacer cette relation ')."')==true ) {remove_operation('%s','%s');}",
00880                                                         dossier::id(),
00881                                                         $p_operation);
00882             $js= '<a class="tinybutton" id="acop'.$p_operation.'" href="'.$rmOperation.'">'."&#x2D5D;".'</a>';
00883             return $js;
00884         }
00885         static function button_action_add_concerned_card($p_agid)
00886         {
00887             $dossier=Dossier::id();
00888             $javascript= <<<EOF
00889                     obj={dossier:$dossier,ag_id:$p_agid};action_add_concerned_card(obj);
00890 EOF;
00891             $js=HtmlInput::button_action(_('Ajout autres'), $javascript);
00892             return $js;
00893         }
00894 }
 All Data Structures Namespaces Files Functions Variables Enumerations