Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

class_widget.php

Go to the documentation of this file.
00001 <?
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$ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 
00032 class widget {
00047   var $type;
00048   var $name;
00049   var $value;
00050   var $readonly;
00051   var $size;
00052   var $selected;
00053   var $table;
00054   var $label;
00055   var $disabled;
00056   var $extra;
00057   var $extra2;
00058   var $tabindex;
00059   function widget($p_type="") {
00060     $this->type=$p_type;
00061     $this->readonly=false;
00062     $this->size=20;
00063     $this->width=50;
00064     $this->heigh=20;
00065     $this->value="";
00066     $this->selected="";
00067     $this->table=0;
00068     $this->label="";
00069     $this->disabled=false;
00070     $this->tabindex=32767;
00071   }
00072   function SetReadOnly($p_read) {
00073     $this->readonly=$p_read;
00074   }
00084   function IOValue($p_name=null,$p_value=null,$p_label="") {
00085     
00086     if ( $p_name != null)
00087       $this->name=$p_name;
00088     $this->value=($p_value===null)?$this->value:$p_value;
00089     $this->label=($p_label == "")?$this->label:$p_label;
00090     
00091     // Input text type
00092     $disabled = $this->disabled ? "DISABLED" : "";
00093     if (strtoupper($this->type)=="TEXT") {
00094       if ( $this->readonly==false) {
00095         $r="<INPUT TYPE=\"TEXT\" NAME=\"$this->name\" VALUE=\"$this->value\" TABINDEX=\"$this->tabindex\" SIZE=\"$this->size\" ".$disabled.">";} else {
00096             $r=sprintf('<span>%s</span><input type="hidden" name="%s" value="%s">', $this->value,$this->name,$this->value);
00097         }
00098         
00099       if ($this->table==1) {
00100         if ( $this->label != "") {
00101           $r="<TD>".$this->label."</TD><TD>".$r."</TD>";
00102         }else {
00103           $r="<TD>".$r."</TD>";
00104         }
00105       }
00106       return $r;
00107     }
00108     // Hidden field
00109     if (strtoupper($this->type)=="HIDDEN") {
00110       $r='<INPUT TYPE="HIDDEN" name="'.$this->name.'" value="'.$this->value.'">';
00111       if ( $this->readonly==true) return "";
00112       return $r;
00113     }
00114     // Select value
00115     if ( strtoupper($this->type) == "SELECT") {
00116       if ($this->readonly==false ){
00117               //echo "<b>Selected <b>".$this->selected;
00118       $r="<SELECT NAME=\"$this->name\">";
00119       for ( $i=0;$i<sizeof($this->value);$i++) {
00120         $checked=($this->selected==$this->value[$i]['value'])?"SELECTED":"";
00121         $r.='<OPTION VALUE="'.$this->value[$i]['value'].'" '.$checked.'>';
00122         $r.=$this->value[$i]['label'];
00123       }
00124       $r.="</SELECT>";
00125       } else {
00126         echo_debug('class_widget.php',__LINE__,"this->selected = ".$this->selected); 
00127         for ( $i=0;$i<sizeof($this->value);$i++) {
00128           echo_debug('class_widget.php',__LINE__,"check for ".$this->value[$i]['value']);
00129           if ($this->selected==$this->value[$i]['value'] ) {
00130             $r=$this->value[$i]['label'];
00131         
00132           }
00133         }
00134       }
00135       if ( $this->table==1) {
00136         $r="<TD> $r </TD>";
00137         if ( $this->label != "") $r="<TD> $this->label</TD>".$r;
00138       }
00139       return $r;
00140     }
00141     // Password
00142     if (strtoupper($this->type)=="PASSWORD") {
00143       if ( $this->readonly==true) return "";
00144       $r='<input type="password" name="'.$this->name;
00145       $r.='">';
00146       if ($this->table==1) {
00147         $r="<TD> $this->label </TD><TD> $r </TD>";
00148       }
00149       return $r;
00150     }
00151 
00152     // Checkbox
00153     if (strtoupper($this->type)=="CHECKBOX") {
00154       if ( $this->readonly == true) {
00155         $check=( $this->selected==true )?"checked":"unchecked";
00156         $r='<input type="CHECKBOX" name="'.$this->name.'"';
00157         $r.="  $check";
00158         $r.=' disabled>';
00159 
00160       } else {
00161         $check=( $this->selected==true )?"checked":"unchecked";
00162         $r='<input type="CHECKBOX" name="'.$this->name.'"';
00163         $r.="  $check";
00164         $r.=' '.$disabled.'>';
00165       }
00166       if ($this->table==1) {
00167         $r="<TD> $this->label </TD><TD> $r </TD>";
00168       } else {
00169         $r=$r." $this->label";
00170       }
00171       return $r;
00172     }
00173 
00174     //radio
00175     if (strtoupper($this->type)=="RADIO") {
00176       if ( $this->readonly == true) {
00177         $check=( $this->selected==true || $this->selected=='t' )?"Yes":"no";
00178         $r=$check;
00179       } else {
00180         $check=( $this->selected==true||$this->selected=='t' )?"checked":"unchecked";
00181         $r='<input type="RADIO" name="'.$this->name.'"';
00182         $r.=" VALUE=\"$this->value\"";
00183         $r.="  $check";
00184         $r.=' '.$disabled.'>';
00185       }
00186       if ($this->table==1) {
00187         $r="<TD> $this->label </TD><TD> $r </TD>";
00188       } else {
00189         $r=$this->label.$r;
00190       }
00191       return $r;
00192     }
00193 
00194     //textarea
00195     if (strtoupper($this->type)=="TEXTAREA") {
00196       if ( $this->readonly == false ) {
00197         $r="";
00198         $r.='<TEXTAREA name="'.$this->name.'"';
00199         $r.=" rows=\"$this->heigh\" ";
00200         $r.=" cols=\"$this->width\" ";
00201         $r.=' '.$disabled.'>';
00202         $r.=$this->value;
00203 
00204         $r.="</TEXTAREA>";
00205       } else {
00206         $r='<p>';
00207         $r.=$this->value;
00208         $r.=sprintf('<input type="hidden" name="%s" value="%s">',
00209                     $this->name,urlencode($this->value));
00210         $r.='</p>';
00211 
00212       }
00213       if ($this->table==1) {
00214         $r="<TD> $this->label </TD><TD> $r </TD>";
00215       }
00216       return $r;
00217     }
00218 
00219     //file
00220     if (strtoupper($this->type)=="FILE") {
00221       if ( $this->readonly == false ) {
00222         $r='<INPUT TYPE="file" name="'.$this->name.'" VALUE="'.$this->value.'">';
00223 
00224       }
00225       if ( $this->table==1) $r="<TD>$this->label</TD><TD>$r</TD>"; 
00226       return $r;
00227     }
00228   // input type == js_search_poste => button search for the account
00229     if ( strtolower($this->type)=="js_search_poste") {
00230      
00231       $l_sessid=$_REQUEST['PHPSESSID'];
00232       if ( $this->readonly == false ) {
00233       // Do we need to filter ??
00234       if ( $this->extra2 == null ) {
00235       $r=sprintf('<TD>
00236          <INPUT TYPE="button" onClick=SearchPoste(\'%s\',\'%s\',\'%s\') value="Search">
00237             %s</TD><TD> 
00238 
00239              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00240                  </TD>',
00241                  $l_sessid,
00242                  $this->name,
00243                  $this->extra,
00244                  $this->label,
00245                  $this->name,
00246                  $this->value 
00247                  );
00248 
00249     } else { // $p_list is not null, so we have a filter
00250       $r=sprintf('<TD>
00251          <INPUT TYPE="button" onClick=SearchPosteFilter(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00252             %s</TD><TD> 
00253 
00254              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00255                  </TD>',
00256                  $l_sessid,
00257                  $this->name,
00258                  $this->extra2,
00259                  $this->extra,
00260                  $this->label,
00261                  $this->name,
00262                  $this->value 
00263                  );
00264 
00265       } //else
00266       } else {
00267       $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
00268                   %s
00269 
00270                  </TD>',
00271                  $this->name, 
00272                  $this->value ,
00273                  $this->value 
00274                  );
00275 
00276       } //else if readonly == true
00277       return $r;
00278 
00279     } // end js_search_poste
00280 
00281   // input type == js_search => button search for card
00282   if ( strtolower($this->type)=="js_search") {
00283     $l_sessid=$_REQUEST['PHPSESSID'];
00284     if  ( $this->readonly == false ) {
00285       $r=sprintf('<TD>
00286          <INPUT TYPE="button" onClick=NewCard(\'%s\',\'%s\',\'%s\',\'%s\') value="New">
00287          <INPUT TYPE="button" onClick=SearchCard(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00288             %s</TD><TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8" TABINDEX="%s">
00289                  ',
00290                $l_sessid,
00291                $this->extra, // deb or cred
00292                $this->name,
00293                $this->extra2, //jrn
00294                $l_sessid,
00295                $this->extra,
00296                $this->name,
00297                $this->extra2,
00298                $this->label,
00299                $this->name,
00300                $this->value, 
00301          $this->tabindex
00302                );
00303     } else {
00304       // readonly == true
00305       $r=sprintf('<TD>            %s</TD>
00306                  <TD> 
00307                  <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">
00308                  </TD>',
00309                $this->label,
00310                $this->name,
00311                $this->value 
00312                  );
00313 
00314     }
00315     return $r;
00316   }// poste==js_search
00317 
00318 
00319   // type=span
00320   if ( strtolower($this->type)=="span") {
00321     $r=sprintf('<span id="%s"  >%s</span>',
00322                $this->name,
00323                $this->value);
00324     return $r;
00325   }// end type = span
00326 
00327    // input type == js_tva
00328    if ( strtolower($this->type)=="js_tva") {
00329      $id=sprintf("<span id=%s></span>",$this->label);
00330         $r=sprintf('%s<TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="3" onChange="ChangeTVA(\'%s\',\'%s\');">',
00331                   $id,
00332                $this->name,
00333                $this->value,
00334                $this->label,
00335                $this->name);
00336      $l_sessid=$_REQUEST['PHPSESSID'];
00337      $r.=sprintf("<input type=\"button\" value=\"Tva\" 
00338         onClick=\"
00339                            ShowTva('%s','%s');\"></TD>",
00340                 $l_sessid,$this->name);
00341      return $r;
00342    }
00343 
00344   // input type == js_concerned => button search for the concerned operations
00345   if ( strtolower($this->type)=="js_concerned") {
00346     if ( $this->readonly == false) {
00347       $l_sessid=$_REQUEST['PHPSESSID'];
00348       $r=sprintf('<TD>
00349          <INPUT TYPE="button" onClick=SearchJrn(\'%s\',\'%s\') value="Search">
00350             %s</TD><TD> 
00351 
00352              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00353                  </TD>',
00354                  $l_sessid,
00355                  $this->name,
00356                  $this->label,
00357                  $this->name,
00358                  $this->value 
00359                  );
00360     } else {
00361       $r=sprintf("<TD><span>%s</span>",$this->value);
00362       $r.=sprintf('<input type="hidden" name="%s" value="%s"></TD>', $this->name,$this->value);
00363     }
00364 
00365     return $r;
00366   }// end js_concerned
00367   return "INVALID WIDGET ";
00368   } //end function
00369   /* Debug
00370    */
00371   function debug() {
00372     echo "Type ".$this->type."<br>";
00373     echo "name ".$this->name."<br>";
00374     echo "value". $this->value."<br>";
00375     $readonly=($this->readonly==false)?"false":"true";
00376     echo "read only".$readonly."<br>";
00377   }
00378   function Submit ($p_name,$p_value) {
00379     return '<INPUT TYPE="SUBMIT" NAME="'.$p_name.'" VALUE="'.$p_value.'">';
00380   }
00381   function Reset ($p_value) {
00382     return '<INPUT TYPE="SUBMIT"  VALUE="'.$p_value.'">';
00383   }
00384 
00385 }

Generated on Sat Jun 24 20:41:33 2006 for phpcompta by  doxygen 1.4.4