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 
00031 class widget {
00052   var $type;
00053   var $name;
00054   var $value;
00055   var $readonly;
00056   var $size;
00057   var $selected;
00058   var $table;
00059   var $label;
00060   var $disabled;
00061   var $extra;
00062   var $extra2;
00063   var $tabindex;
00064   function widget($p_type="") {
00065     $this->type=$p_type;
00066     $this->readonly=false;
00067     $this->size=20;
00068     $this->width=50;
00069     $this->heigh=20;
00070     $this->value="";
00071     $this->selected="";
00072     $this->table=0;
00073     $this->label="";
00074     $this->disabled=false;
00075     $this->tabindex=32767;
00076   }
00077   function SetReadOnly($p_read) {
00078     $this->readonly=$p_read;
00079   }
00089   function IOValue($p_name=null,$p_value=null,$p_label="") {
00090     
00091     if ( $p_name != null)
00092       $this->name=$p_name;
00093     $this->value=($p_value===null)?$this->value:$p_value;
00094     $this->label=($p_label == "")?$this->label:$p_label;
00095     
00096     // Input text type
00097     $disabled = $this->disabled ? "DISABLED" : "";
00098     if (strtoupper($this->type)=="TEXT") {
00099       if ( $this->readonly==false) {
00100         $r="<INPUT style=\"border:solid 1px blue;\" TYPE=\"TEXT\" NAME=\"$this->name\" VALUE=\"$this->value\" TABINDEX=\"$this->tabindex\" SIZE=\"$this->size\" ".$disabled.">";} else {
00101             $r=sprintf('<span>%s</span><input type="hidden" name="%s" value="%s">', $this->value,$this->name,$this->value);
00102         }
00103         
00104       if ($this->table==1) {
00105         if ( $this->label != "") {
00106           $r="<TD  style=\"border:groove 1px blue;\">".$this->label."</TD><TD>".$r."</TD>";
00107         }else {
00108           $r="<TD>".$r."</TD>";
00109         }
00110       }
00111       return $r;
00112     }
00113     // Hidden field
00114     if (strtoupper($this->type)=="HIDDEN") {
00115       $r='<INPUT TYPE="HIDDEN" name="'.$this->name.'" value="'.$this->value.'">';
00116       if ( $this->readonly==true) return "";
00117       return $r;
00118     }
00119     // Select value
00120     if ( strtoupper($this->type) == "SELECT") {
00121       if ($this->readonly==false )
00122         {
00123           //echo "<b>Selected <b>".$this->selected;
00124           $r="<SELECT  NAME=\"$this->name\">";
00125           for ( $i=0;$i<sizeof($this->value);$i++) 
00126             {
00127               $checked=($this->selected==$this->value[$i]['value'])?"SELECTED":"";
00128               $r.='<OPTION VALUE="'.$this->value[$i]['value'].'" '.$checked.'>';
00129               $r.=$this->value[$i]['label'];
00130             }
00131           $r.="</SELECT>";
00132         } else 
00133           {
00134             $r="";
00135             echo_debug('class_widget.php',__LINE__,"this->selected = ".$this->selected); 
00136             for ( $i=0;$i<sizeof($this->value);$i++) 
00137               {
00138                 echo_debug('class_widget.php',__LINE__,"check for ".$this->value[$i]['value']);
00139                 if ($this->selected==$this->value[$i]['value'] ) 
00140                   {
00141                     $r=$this->value[$i]['label'];
00142         
00143                   }
00144               }
00145           }
00146       if ( $this->table==1) {
00147         $r="<TD> $r </TD>";
00148         if ( $this->label != "") $r="<TD> $this->label</TD>".$r;
00149       }
00150       return $r;
00151     }
00152     // Password
00153     if (strtoupper($this->type)=="PASSWORD") {
00154       if ( $this->readonly==true) return "";
00155       $r='<input type="password" name="'.$this->name;
00156       $r.='">';
00157       if ($this->table==1) {
00158         $r="<TD> $this->label </TD><TD> $r </TD>";
00159       }
00160       return $r;
00161     }
00162 
00163     // Checkbox
00164     if (strtoupper($this->type)=="CHECKBOX") {
00165       if ( $this->readonly == true) {
00166         $check=( $this->selected==true )?"checked":"unchecked";
00167         $r='<input type="CHECKBOX" name="'.$this->name.'"';
00168         $r.="  $check";
00169         $r.=' disabled>';
00170 
00171       } else {
00172         $check=( $this->selected==true )?"checked":"unchecked";
00173         $r='<input type="CHECKBOX" name="'.$this->name.'"';
00174         $r.="  $check";
00175         $r.=' '.$disabled.'>';
00176       }
00177       if ($this->table==1) {
00178         $r="<TD> $this->label </TD><TD> $r </TD>";
00179       } else {
00180         $r=$r." $this->label";
00181       }
00182       return $r;
00183     }
00184 
00185     //radio
00186     if (strtoupper($this->type)=="RADIO") {
00187       if ( $this->readonly == true) {
00188         $check=( $this->selected==true || $this->selected=='t' )?"Yes":"no";
00189         $r=$check;
00190       } else {
00191         $check=( $this->selected==true||$this->selected=='t' )?"checked":"unchecked";
00192         $r='<input type="RADIO" name="'.$this->name.'"';
00193         $r.=" VALUE=\"$this->value\"";
00194         $r.="  $check";
00195         $r.=' '.$disabled.'>';
00196       }
00197       if ($this->table==1) {
00198         $r="<TD> $this->label </TD><TD> $r </TD>";
00199       } else {
00200         $r=$this->label.$r;
00201       }
00202       return $r;
00203     }
00204 
00205     //textarea
00206     if (strtoupper($this->type)=="TEXTAREA") {
00207       if ( $this->readonly == false ) {
00208         $r="";
00209         $r.='<TEXTAREA name="'.$this->name.'"';
00210         $r.=" rows=\"$this->heigh\" ";
00211         $r.=" cols=\"$this->width\" ";
00212         $r.=' '.$disabled.'>';
00213         $r.=$this->value;
00214 
00215         $r.="</TEXTAREA>";
00216       } else {
00217         $r='<p>';
00218         $r.=$this->value;
00219         $r.=sprintf('<input type="hidden" name="%s" value="%s">',
00220                     $this->name,urlencode($this->value));
00221         $r.='</p>';
00222 
00223       }
00224       if ($this->table==1) {
00225         $r="<TD> $this->label </TD><TD> $r </TD>";
00226       }
00227       return $r;
00228     }
00229 
00230     //----------------------------------------------------------------------
00231 
00232     //----------------------------------------------------------------------
00233     // Rich Text
00239     if ( strtoupper($this->type)=='RICHTEXT')
00240       {
00241             $r= ' <script language="JavaScript" type="text/javascript"> '.
00242               '<!-- '."\n".
00243               "\nfunction submitForm() {\n".
00244               " updateRTE('".$this->name."');\n ".
00245               " return true; \n".
00246               "} \n".
00247               'initRTE("images/", "", "");'."\n".
00248               '//-->'."\n".
00249               '</script>'.
00250               '<noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>'.
00251               'Note Interne : '.
00252               '<script language="JavaScript" type="text/javascript">'."\n".
00253               '<!--'."\n";
00254               //Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
00255 
00256             echo_debug('class_widget',__LINE__,'to write is '.$this->name);
00257             /*\! brief 
00258              *\note the value must be urlencoded
00259              */
00260             //  Removing new line
00261             
00262             //      $msg=urlencode($this->value);
00263             $msg=$this->value;
00264             $msg=str_replace("%OA","",$msg);
00265             $msg=str_replace("%OD","",$msg);
00266             $msg=str_replace("\n","",$msg);
00267             $msg=str_replace("\r","",$msg);
00268 
00269             $read=($this->readonly==false)?"false":"true";          
00270 
00271 
00272             $r.=sprintf(" writeRichText('%s','%s',%d,%d,true,%s);\n",
00273                         $this->name,
00274                         $msg,
00275                         $this->width,
00276                         $this->heigh, 
00277                         $read);
00278             $r.= "\n//-->".
00279               "</script>";
00280             echo_debug ('class_widget',__LINE__,"writeRichText '$r'");
00281 
00282             return $r;
00283           
00284       }
00285 
00286     //----------------------------------------------------------------------
00287     //file
00288     if (strtoupper($this->type)=="FILE") {
00289       if ( $this->readonly == false ) {
00290         $r='<INPUT TYPE="file" name="'.$this->name.'" VALUE="'.$this->value.'">';
00291 
00292       }
00293       if ( $this->table==1) $r="<TD>$this->label</TD><TD>$r</TD>"; 
00294       return $r;
00295     }
00296   // input type == js_search_poste => button search for the account
00297     if ( strtolower($this->type)=="js_search_poste") {
00298      
00299       $l_sessid=$_REQUEST['PHPSESSID'];
00300       if ( $this->readonly == false ) {
00301       // Do we need to filter ??
00302       if ( $this->extra2 == null ) {
00303       $r=sprintf('<TD>
00304          <INPUT TYPE="button" onClick=SearchPoste(\'%s\',\'%s\',\'%s\') value="Search">
00305             %s</TD><TD> 
00306 
00307              <INPUT   TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00308                  </TD>',
00309                  $l_sessid,
00310                  $this->name,
00311                  $this->extra,
00312                  $this->label,
00313                  $this->name,
00314                  $this->value 
00315                  );
00316 
00317     } else { // $p_list is not null, so we have a filter
00318       $r=sprintf('<TD>
00319          <INPUT TYPE="button" onClick=SearchPosteFilter(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00320             %s</TD><TD> 
00321 
00322              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00323                  </TD>',
00324                  $l_sessid,
00325                  $this->name,
00326                  $this->extra2,
00327                  $this->extra,
00328                  $this->label,
00329                  $this->name,
00330                  $this->value 
00331                  );
00332 
00333       } //else
00334       } else {
00335       $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
00336                   %s
00337 
00338                  </TD>',
00339                  $this->name, 
00340                  $this->value ,
00341                  $this->value 
00342                  );
00343 
00344       } //else if readonly == true
00345       return $r;
00346 
00347     } // end js_search_poste
00348 
00349   // input type == js_search => button search for card
00350   if ( strtolower($this->type)=="js_search") {
00351     $l_sessid=$_REQUEST['PHPSESSID'];
00352     if  ( $this->readonly == false ) {
00353       $r=sprintf('<TD>
00354          <INPUT TYPE="button" onClick=NewCard(\'%s\',\'%s\',\'%s\',\'%s\') value="New">
00355          </TD><TD>
00356          <INPUT TYPE="button" onClick=SearchCard(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00357             %s <INPUT TYPE="Text"    NAME="%s" VALUE="%s" SIZE="8" TABINDEX="%s">
00358                  ',
00359                $l_sessid,
00360                $this->extra, // deb or cred
00361                $this->name,
00362                $this->extra2, //jrn
00363                $l_sessid,
00364                $this->extra,
00365                $this->name,
00366                $this->extra2,
00367                $this->label,
00368                $this->name,
00369                $this->value, 
00370          $this->tabindex
00371                );
00372     } else {
00373       // readonly == true
00374       $r=sprintf('<TD>            %s</TD>
00375                  <TD> 
00376                  <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">
00377                  </TD>',
00378                $this->label,
00379                $this->name,
00380                $this->value 
00381                  );
00382 
00383     }
00384     return $r;
00385   }// poste==js_search
00386 
00387 
00388   // input type == js_search => button search for card
00391   if ( strtolower($this->type)=="js_search_only") {
00392     $l_sessid=$_REQUEST['PHPSESSID'];
00393     if  ( $this->readonly == false ) {
00394       if ( $this->table==1)
00395         {
00396           $r=sprintf('<TD>
00397          <INPUT TYPE="button" onClick=SearchCard(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00398             %s</TD><TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8" TABINDEX="%s">
00399                  ',
00400                $l_sessid,
00401                $this->extra,
00402                $this->name,
00403                $this->extra2,
00404                $this->label,
00405                $this->name,
00406                $this->value, 
00407          $this->tabindex
00408                );
00409         }
00410       else
00411         {
00412           $r=sprintf('
00413          <INPUT TYPE="button" onClick=SearchCard(\'%s\',\'%s\',\'%s\',\'%s\') value="Search">
00414             %s <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8" TABINDEX="%s">           ',
00415                $l_sessid,
00416                $this->extra,
00417                $this->name,
00418                $this->extra2,
00419                $this->label,
00420                $this->name,
00421                $this->value, 
00422                $this->tabindex
00423                );
00424         }
00425     } else {
00426       // readonly == true
00427       $r=sprintf('<TD>            %s</TD>
00428                  <TD> 
00429                  <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">
00430                  </TD>',
00431                $this->label,
00432                $this->name,
00433                $this->value 
00434                  );
00435 
00436     }
00437     return $r;
00438   }// poste==js_search_only
00439 
00440 
00441 
00442 
00443 
00444   // type=span
00445   if ( strtolower($this->type)=="span") {
00446     $r=sprintf('<span id="%s"  >%s </span>',
00447                $this->name,
00448                $this->value
00449                );
00450 
00451     return $r;
00452   }// end type = span
00453 
00454    // input type == js_tva
00455    if ( strtolower($this->type)=="js_tva") {
00456      $id=sprintf("<span id=%s></span>",$this->label);
00457         $r=sprintf('%s<TD> <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="3" onChange="ChangeTVA(\'%s\',\'%s\');">',
00458                   $id,
00459                $this->name,
00460                $this->value,
00461                $this->label,
00462                $this->name);
00463      $l_sessid=$_REQUEST['PHPSESSID'];
00464      $r.=sprintf("<input type=\"button\" value=\"Tva\" 
00465         onClick=\"
00466                            ShowTva('%s','%s');\"></TD>",
00467                 $l_sessid,$this->name);
00468      return $r;
00469    }
00470 
00471   // input type == js_concerned => button search for the concerned operations
00472   if ( strtolower($this->type)=="js_concerned") {
00473     if ( $this->readonly == false) {
00474       $l_sessid=$_REQUEST['PHPSESSID'];
00475       $r=sprintf('<TD>
00476          <INPUT TYPE="button" onClick=SearchJrn(\'%s\',\'%s\') value="Search">
00477             %s</TD><TD> 
00478 
00479              <INPUT TYPE="Text" NAME="%s" VALUE="%s" SIZE="8">
00480                  </TD>',
00481                  $l_sessid,
00482                  $this->name,
00483                  $this->label,
00484                  $this->name,
00485                  $this->value 
00486                  );
00487     } else {
00488       $r=sprintf("<TD><span>%s</span>",$this->value);
00489       $r.=sprintf('<input type="hidden" name="%s" value="%s"></TD>', $this->name,$this->value);
00490     }
00491 
00492     return $r;
00493   }// end js_concerned
00494   return "INVALID WIDGET $this->type ";
00495   } //end function
00496   /* Debug
00497    */
00498   function debug() {
00499     echo "Type ".$this->type."<br>";
00500     echo "name ".$this->name."<br>";
00501     echo "value". $this->value."<br>";
00502     $readonly=($this->readonly==false)?"false":"true";
00503     echo "read only".$readonly."<br>";
00504   }
00505   function Submit ($p_name,$p_value) {
00506     return '<INPUT TYPE="SUBMIT" NAME="'.$p_name.'" VALUE="'.$p_value.'">';
00507   }
00508   function Reset ($p_value) {
00509     return '<INPUT TYPE="SUBMIT"  VALUE="'.$p_value.'">';
00510   }
00511 
00512 }

Generated on Wed Jun 28 02:07:23 2006 for phpcompta by  doxygen 1.4.4