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.='<TEXTAREA name="'.$this->name.'"';
00198         $r.=" rows=\"$this->heigh\" ";
00199         $r.=" cols=\"$this->width\" ";
00200         $r.=' '.$disabled.'>';
00201         $r.=$this->value;
00202 
00203         $r.="</TEXTAREA>";
00204       } else {
00205         $r='<p>';
00206         $r.=$this->value;
00207         $r.=sprintf('<input type="hidden" name="%s" value="%s">',
00208                     $this->name,urlencode($this->value));
00209         $r.='</p>';
00210 
00211       }
00212       if ($this->table==1) {
00213         $r="<TD> $this->label </TD><TD> $r </TD>";
00214       }
00215       return $r;
00216     }
00217 
00218     //file
00219     if (strtoupper($this->type)=="FILE") {
00220       if ( $this->readonly == false ) {
00221         $r='<INPUT TYPE="file" name="'.$this->name.'" VALUE="'.$this->value.'">';
00222 
00223       }
00224       if ( $this->table==1) $r="<TD>$this->label</TD><TD>$r</TD>"; 
00225       return $r;
00226     }
00227   // input type == js_search_poste => button search for the account
00228     if ( strtolower($this->type)=="js_search_poste") {
00229      
00230       $l_sessid=$_REQUEST['PHPSESSID'];
00231       if ( $this->readonly == false ) {
00232       // Do we need to filter ??
00233       if ( $this->extra2 == null ) {
00234       $r=sprintf('<TD>
00235          <INPUT TYPE="button" onClick=SearchPoste(\'%s\',\'%s\',\'%s\') value="Search">
00236             %s</TD><TD> 
00237 
00238              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00239                  </TD>',
00240                  $l_sessid,
00241                  $this->name,
00242                  $this->extra,
00243                  $this->label,
00244                  $this->name,
00245                  $this->value 
00246                  );
00247 
00248     } else { // $p_list is not null, so we have a filter
00249       $r=sprintf('<TD>
00250          <INPUT TYPE="button" onClick=SearchPosteFilter(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00251             %s</TD><TD> 
00252 
00253              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00254                  </TD>',
00255                  $l_sessid,
00256                  $this->name,
00257                  $this->extra2,
00258                  $this->extra,
00259                  $this->label,
00260                  $this->name,
00261                  $this->value 
00262                  );
00263 
00264       } //else
00265       } else {
00266       $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
00267                   %s
00268 
00269                  </TD>',
00270                  $this->name, 
00271                  $this->value ,
00272                  $this->value 
00273                  );
00274 
00275       } //else if readonly == true
00276       return $r;
00277 
00278     } // end js_search_poste
00279 
00280   // input type == js_search => button search for card
00281   if ( strtolower($this->type)=="js_search") {
00282     $l_sessid=$_REQUEST['PHPSESSID'];
00283     if  ( $this->readonly == false ) {
00284       $r=sprintf('<TD>
00285          <INPUT TYPE="button" onClick=NewCard(\'%s\',\'%s\',\'%s\',\'%s\') value="New">
00286          <INPUT TYPE="button" onClick=SearchCard(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00287             %s</TD><TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8" TABINDEX="%s">
00288                  ',
00289                $l_sessid,
00290                $this->extra, // deb or cred
00291                $this->name,
00292                $this->extra2, //jrn
00293                $l_sessid,
00294                $this->extra,
00295                $this->name,
00296                $this->extra2,
00297                $this->label,
00298                $this->name,
00299                $this->value, 
00300          $this->tabindex
00301                );
00302     } else {
00303       // readonly == true
00304       $r=sprintf('<TD>            %s</TD>
00305                  <TD> 
00306                  <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">
00307                  </TD>',
00308                $this->label,
00309                $this->name,
00310                $this->value 
00311                  );
00312 
00313     }
00314     return $r;
00315   }// poste==js_search
00316 
00317 
00318   // type=span
00319   if ( strtolower($this->type)=="span") {
00320     $r=sprintf('<span id="%s"  >%s</span>',
00321                $this->name,
00322                $this->value);
00323     return $r;
00324   }// end type = span
00325 
00326    // input type == js_tva
00327    if ( strtolower($this->type)=="js_tva") {
00328      $id=sprintf("<span id=%s></span>",$this->label);
00329         $r=sprintf('%s<TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="3" onChange="ChangeTVA(\'%s\',\'%s\');">',
00330                   $id,
00331                $this->name,
00332                $this->value,
00333                $this->label,
00334                $this->name);
00335      $l_sessid=$_REQUEST['PHPSESSID'];
00336      $r.=sprintf("<input type=\"button\" value=\"Tva\" 
00337         onClick=\"
00338                            ShowTva('%s','%s');\"></TD>",
00339                 $l_sessid,$this->name);
00340      return $r;
00341    }
00342 
00343   // input type == js_concerned => button search for the concerned operations
00344   if ( strtolower($this->type)=="js_concerned") {
00345     if ( $this->readonly == false) {
00346       $l_sessid=$_REQUEST['PHPSESSID'];
00347       $r=sprintf('<TD>
00348          <INPUT TYPE="button" onClick=SearchJrn(\'%s\',\'%s\') value="Search">
00349             %s</TD><TD> 
00350 
00351              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00352                  </TD>',
00353                  $l_sessid,
00354                  $this->name,
00355                  $this->label,
00356                  $this->name,
00357                  $this->value 
00358                  );
00359     } else {
00360       $r=sprintf("<TD><span>%s</span>",$this->value);
00361       $r.=sprintf('<input type="hidden" name="%s" value="%s"></TD>', $this->name,$this->value);
00362     }
00363 
00364     return $r;
00365   }// end js_concerned
00366   return "INVALID WIDGET ";
00367   } //end function
00368   /* Debug
00369    */
00370   function debug() {
00371     echo "Type ".$this->type."<br>";
00372     echo "name ".$this->name."<br>";
00373     echo "value". $this->value."<br>";
00374     $readonly=($this->readonly==false)?"false":"true";
00375     echo "read only".$readonly."<br>";
00376   }
00377   function Submit ($p_name,$p_value) {
00378     return '<INPUT TYPE="SUBMIT" NAME="'.$p_name.'" VALUE="'.$p_value.'">';
00379   }
00380   function Reset ($p_value) {
00381     return '<INPUT TYPE="SUBMIT"  VALUE="'.$p_value.'">';
00382   }
00383 
00384 }

Generated on Fri Jun 23 00:12:45 2006 for phpcompta by  doxygen 1.4.4