render/render_form.inc.php

00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php5 based project management system  (c) 2005-2007  / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004 
00030 #====================================================================================
00031 # PageFormElement
00032 #====================================================================================
00033 class PageFormElement extends PageElement{
00034     public  $name;
00035     public  $value;
00036     public  $type;
00037     public  $title;
00038     public  $tooltip;
00039     public  $required;
00040     public  $invalid;
00041     public  $id;
00042     public  $display;
00043     public  $func;
00044 
00045     PUBLIC function __construct() {
00046         return;
00047     }
00048 }
00049 
00050 
00051 
00052 class Form_Captcha extends PageFormElement
00053 {
00054     public $required=false;
00055 
00056     PUBLIC function __construct($key)
00057     {
00058         $this->type=    'input';
00059         parent::__construct();
00060 
00061         $this->name=    'captcha_input';
00062         $this->title=   __("Please copy the text");
00063         $this->value=   $key;
00064         $this->tooltip= __("Sorry. To reduce the efficiency of spam bots, guests have to copy the text");
00065 
00066     }
00067 
00068     PUBLIC function __toString()
00069     {
00070         global $PH;
00071 
00072         $url= $PH->getUrl('imageRenderCaptcha',array('key' => $this->value));
00073 
00074         $buffer= "<p title='$this->tooltip' $this->id $this->display>
00075             <label>$this->title</label>
00076             <img src='$url'>
00077 
00078                     <input class='inp captcha' name='$this->name' value=''>
00079                    </p>";
00080 
00081         return $buffer;
00082     }
00083 }
00084 
00085 /*
00086 */
00087 
00088 
00089 class Form_Input extends PageFormElement {
00090     public $required=false;
00091 
00092     PUBLIC function __construct($name=false, $title="", $value=false, $tooltip=NULL, $required=false, $id="", $display="")
00093     {
00094         $this->type='input';
00095         parent::__construct();
00096         $this->name=    $name;
00097         $this->title=   $title;
00098         $this->value=   $value;
00099         $this->tooltip= $tooltip;
00100         $this->required=$required;
00101         $this->id=      $id;
00102         $this->display= $display;
00103     }
00104 
00105     PUBLIC function __toString()
00106     {
00107         $str_tooltip= $this->tooltip
00108                   ? "title='$this->tooltip'"
00109                   : "";
00110         $str_required=$this->required
00111                       ? 'required'
00112                       : '';
00113         $str_invalid=$this->invalid
00114                       ? 'invalid'
00115                       : '';
00116         $buffer= "<p $str_tooltip $this->id $this->display><label>$this->title</label><input class='inp $str_required $str_invalid' name='$this->name' value='".htmlspecialchars($this->value, ENT_QUOTES)."'></p>";
00117         return $buffer;
00118     }
00119 }
00120 
00121 
00122 class Page_TabGroup extends PageElement {
00123 
00124     PUBLIC function __construct($name="", $title="")
00125     {
00126         parent::__construct();
00127         $this->name=    $name;
00128         $this->title=   $title;
00129     }
00130 
00131     PUBLIC function __toString()
00132     {
00133 
00134 
00135         $buffer='<div class="tabgroup">'
00136             .'<ul>';
00137 
00138         foreach($this->children as $name=>$c) {
00139             $buffer.= '<li class="tab_header" id="'. $name. '"><a href="#">'. $c->title.'</a></li>';
00140         }
00141         $buffer.='</ul>';
00142 
00143         foreach($this->children as $name=>$c) {
00144             $buffer.='<div class="tab_body" id="' . $name . '-body">'. $c->render() . '</div>';
00145         }
00146 
00147         $buffer.='</div>';
00148 
00149         return $buffer;
00150     }
00151 }
00152 
00153 
00154 class Page_Tab extends PageElement
00155 {
00156 
00157     PUBLIC function __construct($name="", $title="")
00158     {
00159         parent::__construct();
00160         $this->name=    $name;
00161         $this->title=   $title;
00162     }
00163 
00164     PUBLIC function __toString()
00165     {
00166 
00167         $buffer= '';
00168         foreach($this->children as $c) {
00169             $buffer.= $c->render();
00170         }
00171         return $buffer;
00172     }
00173 }
00174 
00175 
00176 
00177 
00178 
00179 #====================================================================================
00180 # Password
00181 #====================================================================================
00182 class Form_Password extends PageFormElement {
00183 
00184     PUBLIC function __construct($name=false, $title="", $value=false, $tooltip=NULL)
00185     {
00186         $this->type='input';
00187         parent::__construct();
00188         $this->name=    $name;
00189         $this->title=   $title;
00190         $this->value=   $value;
00191         $this->tooltip= $tooltip;
00192     }
00193 
00194     PUBLIC function __toString()
00195     {
00196         $str_tooltip= $this->tooltip
00197                   ? "title='$this->tooltip'"
00198                   : "";
00199 
00200         $style_required =$this->required
00201                         ? 'required'
00202                         : '';
00203 
00204         $buffer= "<p $str_tooltip><label>$this->title</label><input class='inp $style_required' type='password' name='$this->name' value='".htmlspecialchars($this->value, ENT_QUOTES)."'></p>";
00205         return $buffer;
00206     }
00207 }
00208 
00209 
00210 
00211 #====================================================================================
00212 # HiddenField
00213 #====================================================================================
00214 class Form_HiddenField extends PageFormElement {
00215 
00216     PUBLIC function __construct($name=false, $title="", $value=false, $tooltip=NULL)
00217     {
00218         $this->type='input';
00219         parent::__construct();
00220         $this->name=    $name;
00221         $this->title=   $title;
00222         $this->value=   $value;
00223     }
00224 
00225     PUBLIC function __toString()
00226     {
00227         $buffer= "<input type=hidden name='$this->name' value='$this->value'>";
00228         return $buffer;
00229     }
00230 }
00231 
00232 
00233 
00234 class Form_DateTime extends PageFormElement
00235 {
00236     PUBLIC function __construct($name=false, $title="", $value=false, $tooltip=NULL)
00237     {
00238         $this->type='datetime';
00239         parent::__construct();
00240         $this->name=    $name;
00241         $this->title=   $title;
00242         $this->value=   $value;
00243         $this->tooltip= $tooltip;
00244     }
00245 
00246     PUBLIC function __toString()
00247     {
00248 
00249         $value_date= "-";
00250         $value_time= "-";
00251 
00252 
00253 
00254         if($this->value != "0000-00-00 00:00:00" && $this->value != "0000-00-00" ) {
00255 
00256             $time= strToClientTime($this->value);
00257 
00261             if($time < 0 || $time==false) {
00262                 $str_array=mysqlDatetime2utc($this->value);
00263                 $str= $str_array['year']  ."-".
00264                         $str_array['mon'] .'-'.
00265                         $str_array['day'] ." ".
00266                         $str_array['hour'].":".
00267                         $str_array['min']  .":".
00268                         $str_array['sec'];
00269                 $time= strToClientTime($str);
00270             }
00271 
00275             if($time != -1) {
00276                 $value_date= gmdate("D, d.m.Y",$time);
00277                 $value_time= gmdate("H:i",$time);
00278             }
00279         }
00280         else {
00281             $time = 0;
00282         }
00283 
00284         $label=isset($this->title)
00285             ? $this->title
00286             : ucwords(str_replace('_',' ',$this->name));
00287         $tooltip= isset($this->tooltip)
00288             ? "title='$this->tooltip'"
00289             :  ucwords($this->name);
00290 
00291         $field_id= $this->name;
00292 
00293         $buffer= "<p $tooltip class=datetime>"
00294             ."<label>$label</label>"
00295             ."<input class=inp_date id='{$field_id}_date' name='{$field_id}_date' value='$value_date'>"
00296             ."<span class=button_calendar id='trigger_{$field_id}_date'>...</span>"
00297 
00298             ."<input class=inp_time id='{$field_id}_time' name='{$field_id}_time' value='$value_time'>"
00299             ."<span class=slider_time id='drag_{$field_id}' >&nbsp;&nbsp;</span>"
00300             ."</p>"
00301             ."<script>"
00302             ."DragSlider.init('drag_{$field_id}','{$field_id}_time','time');
00303               Calendar.setup({
00304                   inputField  : \"{$field_id}_date\",         // ID of the input field
00305                   ifFormat    : \"%a, %d.%m.%Y\",    // the date format
00306                   button      : \"trigger_{$field_id}_date\"       // ID of the button
00307                 }
00308               );"
00309             ."</script>";
00310 
00311         return $buffer;
00312     }
00313 }
00314 
00315 #====================================================================================
00316 # Date
00317 #====================================================================================
00318 class Form_Date extends PageFormElement {
00319 
00320     PUBLIC function __construct($name=false, $title="", $value=false)
00321     {
00322         $this->type='date';
00323         parent::__construct();
00324         $this->name=    $name;
00325         $this->title=   $title;
00326         $this->value=   $value;
00327     }
00328 
00329     PUBLIC function __toString()
00330     {
00331         $str_value=$this->value;
00332         if($str_value=="0000-00-00") {
00333             $str_value="-";
00334         }
00335 
00336 
00337         $buffer= "<p class=datetime >"
00338             ."<label>$this->title</label>"
00339             ."<input class=inp_date name='$this->name' id='$this->name' value='$str_value'>"
00340             ."<span class=button_calendar id='trigger_{$this->name}'>...</span>"
00341             ."</p>";
00342 
00343         $buffer.="<script type=\"text/javascript\">
00344           Calendar.setup(
00345             {
00346               inputField  : \"$this->name\",         // ID of the input field
00347               ifFormat    : \"%a, %d.%m.%Y\",    // the date format
00348               button      : \"trigger_{$this->name}\"       // ID of the button
00349             }
00350           );
00351           //DragSlider('drag_{$this->name}','{$this->name}');
00352         </script>" ;
00353         return $buffer;
00354     }
00355 }
00356 
00357 #====================================================================================
00358 # Time
00359 #====================================================================================
00360 class Form_Time extends PageFormElement {
00361 
00362     PUBLIC function __construct($name=false, $title="", $value=false)
00363     {
00364         $this->type='time';
00365         parent::__construct();
00366         $this->name=    $name;
00367         $this->title=   $title;
00368         $this->value=   $value;
00369     }
00370 
00371     PUBLIC function __toString()
00372     {
00373         $str_value=$this->value;
00374         if($str_value=="0000-00-00" || $str_value=="00-00-00") {
00375             $str_value="-";
00376         }
00377 
00378         $tooltip= isset($field->tooltip)
00379             ? "title='$this->tooltip'"
00380             :  ucwords($this->name);
00381 
00382         $buffer= "<p $tooltip class=datetime>"
00383             ."<label>$this->title</label>"
00384             ."<input class=inp_time id='{$this->name}' name='{$this->name}' value='$str_value'>"
00385             ."<span class=slider_time id='drag_{$this->name}' >%</span>"
00386             ."</p>"
00387             ."<script>"
00388             ."DragSlider.init('drag_{$this->name}','{$this->name}','time');
00389             </script>
00390             ";
00391 
00392 
00393         return $buffer;
00394     }
00395 }
00396 
00397 #====================================================================================
00398 # Form_Edit
00399 #====================================================================================
00400 class Form_Edit extends PageFormElement {
00401 
00402     public $rows;
00403     PUBLIC function __construct($name=false, $title="", $value=false, $tooltip=NULL, $rows=5)
00404     {
00405         $this->type='edit';
00406         parent::__construct();
00407         $this->name=    $name;
00408         $this->title=   $title;
00409         $this->value=   $value;
00410         $this->rows= $rows;
00411     }
00412 
00413     PUBLIC function __toString()
00414     {
00415         global $PH;
00416         $hint= "<span class=hint_wiki_syntax><br>(". $PH->getWikiLink('WikiSyntax', __('Wiki format')).")</span>";
00417 
00418         $buffer= "<p><label>$this->title $hint</label><textarea rows=$this->rows name='$this->name'>".htmlspecialchars($this->value, ENT_QUOTES)."</textarea></p>"
00419 
00420         ;
00421         return $buffer;
00422     }
00423 }
00424 
00425 #====================================================================================
00426 # Form_Dropdown
00427 #====================================================================================
00428 class Form_Dropdown extends PageFormElement {
00429 
00430     private $options;
00431 
00432     PUBLIC function __construct($name=false, $title="", $options=array(), $value=false, $id="", $display="")
00433     {
00434         $this->type='dropdown';
00435         parent::__construct();
00436         $this->name=    $name;
00437         $this->title=   $title;
00438         $this->value=   $value;
00439         $this->id=      $id;
00440         $this->display= $display;
00441         $this->options=$options;
00442         $this->options=$options
00443             ? $options
00444             :array();
00445     }
00446 
00447     PUBLIC function __toString()
00448     {
00449         $buffer= "<p $this->id $this->display><label>$this->title</label>";
00450         $buffer.="<select size=1 name='$this->name' id='$this->name'>";
00451         foreach($this->options as $key=>$value) {
00452             $str_selected= ($this->value==$value)
00453                  ? "selected='selected'"
00454                  :"";
00455 
00456             $buffer.='<option ' . $str_selected .' value="' . asHtml($value) . '" >' . asHtml($key) . '</option>';
00457         }
00458         $buffer.="</select></p>";
00459         return $buffer;
00460     }
00461 }
00462 
00463 #====================================================================================
00464 # Form_Checkbox
00465 #====================================================================================
00466 class Form_Checkbox extends PageFormElement {
00467 
00468     private $options;
00469     public  $checked;
00470 
00471     PUBLIC function __construct($name=false, $title="", $checked=0, $func="", $value=NULL)
00472     {
00473         $this->type='checkbox';
00474         parent::__construct();
00475         $this->name     = $name;
00476         $this->title    = $title;
00477         $this->value    = $value;                             # add additional value parameter
00478         $this->func     = $func;                              # to add javascript functions
00479         $this->checked  = $checked;
00480     }
00481 
00482     PUBLIC function __toString()
00483     {
00484         $checked = $this->checked
00485             ? 'checked'
00486             : '';
00487 
00488         $str_value= (!is_null($this->value))
00489                   ? "value='{$this->value}'"
00490                   : '';
00491 
00492         $buffer= "<p>";
00493         $buffer.="<span class=checker><input type='checkbox' id='$this->name' name='$this->name' $str_value $this->func $checked><label for='$this->name'>$this->title</label></span>";
00494         $buffer.="</p>";
00495         return $buffer;
00496     }
00497 }
00498 
00499 
00507 class Form_Text extends PageFormElement
00508 {
00509 
00510     private $html = '';
00511 
00512     PUBLIC function __construct($html, $name="")
00513     {
00514         $this->type     = 'html';
00515         $this->name     = $name;
00516         parent::__construct();
00517         $this->html     = $html;
00518     }
00519 
00520     PUBLIC function __toString()
00521     {
00522         return "<p class=text>" . $this->html . "</p>";
00523     }
00524 }
00525 
00526 
00527 class Form_CustomHTML extends PageFormElement {
00528 
00529     private $html = '';
00530 
00531     PUBLIC function __construct($html='',$name=false)
00532     {
00533         $this->type='html';
00534         $this->name=$name; ## changed ##
00535         parent::__construct();
00536         $this->html=  $html;
00537     }
00538 
00539     PUBLIC function __toString()
00540     {
00541         return $this->html;
00542     }
00543 }
00544 
00545 
00546 
00547 
00548 
00549 
00559 class PageForm extends PageElement
00560 {
00561     public  $button_cancel= false;    # set to true to render
00562     public  $button_apply= false;     # set to true to render
00563     public  $button_submit= "Submit";
00564 
00565     public  $form_options=array();  # currently a list of html-snips
00566 
00567     PUBLIC function __construct()
00568     {
00569         $this->children=array();
00570 
00577         echo "<input type=hidden name=edit_request_time value='" . time(). "'>";
00578         $this->button_submit= __("Submit");
00579         parent::__construct();
00580     }
00581 
00582     PUBLIC function __toString()
00583     {
00584         $buffer= "<div class=form>";
00585 
00586         $hidden= array();
00587         foreach($this->children as $key=>$field) {
00588             if($field instanceof Form_HiddenField) {
00589                 $hidden[$field->name]= $field->value;
00590             }
00591             $buffer.=$field->render();
00592         }
00593 
00594         ### if logged in, add crc-checksum for hidden fields ###
00595         global $auth;
00596         if(isset($auth->cur_user)) {
00597             global $PH;
00598             $handle_for_hidden_values= $PH->defineFromHandle($hidden);
00599             echo "<input type=hidden name=hidden_crc value='$handle_for_hidden_values'>";
00600         }
00601 
00602 
00603         $buffer.="<div class=formbuttons>";
00604 
00605         ### form options ###
00606         if($this->form_options) {
00607             $buffer .="<div class=formoptions>";
00608             foreach($this->form_options as $fo) {
00609                 $buffer.= $fo;
00610             }
00611             $buffer .="</div>";
00612         }
00613 
00614 
00615         ### form - buttons ###
00616         if($str= $this->button_cancel) {
00617             if(!is_string($str)) {
00618                 $str=__('Cancel');
00619             }
00620             $buffer.= "<input class='button cancel' tabindex='200' type=button value='$str' onclick=\"javascript:document.my_form.form_do_cancel.value='1';document.my_form.submit();\">";
00621             $buffer.= "<input type=hidden name=form_do_cancel value=0>";
00622 
00623 
00624         }
00625 
00626         if($str= $this->button_apply) {
00627             if(!is_string($str)) {
00628                 $str=__('Apply');
00629             }
00630             $buffer.= "<input class='button apply'  type=button value='$str' onclick=\"javascript:document.my_form.form_do_apply.value='1';document.my_form.submit();\">";
00631             $buffer.= "<input type=hidden name=form_do_apply value=0>";
00632         }
00633 
00634         if($str= $this->button_submit) {
00635             $buffer.= "<input class='button submit' type=submit value='$str'>";        #@@@ add correct style h
00636         }
00637 
00638         $buffer.="</div>";
00639 
00640         $buffer.="</div>";
00641         return $buffer;
00642     }
00643 
00644 
00645     PUBLIC function addCaptcha()
00646     {
00647         $key= substr( md5(microtime()), 0,5);
00648         $this->add(new Form_Captcha( $key ));
00649         $this->add(new Form_HiddenField('captcha_key', '', $key));
00650 
00651     }
00652 }
00653 
00654 ?>

Generated on Sun Mar 4 17:19:31 2007 for streber by  doxygen 1.5.1-p1