openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

Form.class.php (3699B)


      1 <?php
      2 
      3 namespace template_engine\components;
      4 
      5 class FormComponent extends Component
      6 {
      7 
      8 	public $method = 'POST';
      9 
     10 	public $name = '';
     11 
     12 	public $action = null;
     13 
     14 	public $subaction = null;
     15 
     16 	public $id = '<?php echo OR_ID ?>';
     17 
     18 	public $languageid = null;
     19 	public $modelid    = null;
     20 
     21 	public $label;
     22 
     23 	public $apply  = false;
     24 	public $cancel = true;
     25 	public $readonly = false;
     26 
     27     /**
     28      * 'view' = Loads Action in the same view
     29      * 'top' = Replaces whole workbench.
     30      * @var string
     31      */
     32 	public $target = 'view';
     33 
     34 	public $enctype = 'application/x-www-form-urlencoded';
     35 
     36 	public $async = false;
     37 
     38 	public $autosave = false;
     39 
     40 	public $type = '';
     41 
     42 	public $afterSuccess;
     43 
     44 	protected function begin()
     45 	{
     46 		if ( ! $this->label )
     47 			$this->label = 'message:BUTTON_OK';
     48 		
     49 		if ($this->type == 'upload')
     50 			$this->submitFunction = '';
     51 
     52 		// Default: Target is the actual action/method-pair.
     53 		if(empty($this->action))
     54 		    $this->action = $this->request->action;
     55 		if(empty($this->subaction))
     56 		    $this->subaction = $this->request->method;
     57 
     58 		echo '<form';
     59 		echo ' name="' . $this->htmlvalue($this->name) . '"';
     60 
     61 		echo ' target="_self"';
     62 		echo ' data-target="' . $this->htmlvalue($this->target) . '"';
     63 		echo ' action="./"';
     64 		echo ' data-method="' . $this->htmlvalue($this->subaction) . '"';
     65 		echo ' data-action="' . $this->htmlvalue($this->action) . '"';
     66 		echo ' data-id="' . $this->htmlvalue($this->id) . '"';
     67 		echo ' method="' . $this->htmlvalue($this->method) . '"';
     68 		echo ' enctype="' . $this->htmlvalue($this->enctype) . '"';
     69 		echo ' class="or-form ' . $this->htmlvalue($this->action) . '"';
     70 		echo ' data-async="' . $this->htmlvalue($this->async) . '"';
     71 		echo ' data-autosave="' . $this->htmlvalue($this->autosave) . '"';
     72 
     73         if ( $this->afterSuccess )
     74             echo ' data-after-success="' . $this->htmlvalue($this->afterSuccess) . '"';
     75 
     76         echo '>';
     77 
     78         // Enable Submit on Enter - no need for...we have a submit button at the end.
     79 		// echo '<input type="submit" class="invisible" />';
     80 
     81         if ( !empty($this->languageid))
     82             echo '<input type="hidden" name="'.REQ_PARAM_LANGUAGE_ID.'" value="' . $this->htmlvalue($this->languageid) . '" />';
     83         if ( !empty($this->modelid))
     84             echo '<input type="hidden" name="'.REQ_PARAM_MODEL_ID.'" value="' . $this->htmlvalue($this->modelid) . '" />';
     85 		echo '<input type="hidden" name="<?php echo REQ_PARAM_TOKEN ?>" value="<?php echo token() ?>" />';
     86 		echo '<input type="hidden" name="<?php echo REQ_PARAM_ACTION ?>" value="' . $this->htmlvalue($this->action) . '" />';
     87 		echo '<input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="' . $this->htmlvalue($this->subaction) . '" />';
     88 		echo '<input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="' . $this->htmlvalue($this->id) . '" />';
     89 	}
     90 
     91 	protected function end()
     92 	{
     93 		$label = $this->htmlvalue($this->label);
     94 		
     95 		echo '<div class="or-form-actionbar">';
     96 		//echo "<div class=\"command {$this->visible}\">";
     97 
     98         // Cancel-Button nicht anzeigen, wenn cancel==false.
     99         if ($this->cancel)
    100         {
    101             echo '<input type="button" class="or-form-btn or-form-btn--secondary or-form-btn--cancel" value="<?php echo lang("CANCEL") ?>" />';
    102         }
    103 
    104         if ($this->apply && !$this->readonly)
    105         {
    106             echo '<input type="button" class="or-form-btn or-form-btn--primary or-form-btn--apply" value="<?php echo lang("APPLY") ?>" />';
    107         }
    108 
    109         if ( !$this->readonly )
    110             echo "<input type=\"submit\" class=\"or-form-btn or-form-btn--primary or-form-btn--save\" value=\"{$label}\" />";
    111 
    112         //echo '</div>';
    113         echo '</div>';
    114         echo '</form>';
    115 
    116     }
    117 }
    118 
    119 ?>