Exemple #1
0
 /**
  * Create form fieldset, called internal by {@link renderCreateForm())
  *
  * @param string $id field id
  * @param array $fdata fieldset data
  * @param e_admin_model $model
  * @return string
  */
 function renderCreateFieldset($id, $fdata, $model, $tab = 0)
 {
     $text = vartrue($fdata['fieldset_pre']) . "\r\n\t\t\t<fieldset id='{$id}'>\r\n\t\t\t\t<legend>" . vartrue($fdata['legend']) . "</legend>\r\n\t\t\t\t" . vartrue($fdata['table_pre']) . "\r\n\t\t\t\t<table class='table adminform'>\r\n\t\t\t\t\t<colgroup>\r\n\t\t\t\t\t\t<col class='col-label' />\r\n\t\t\t\t\t\t<col class='col-control' />\r\n\t\t\t\t\t</colgroup>\r\n\t\t\t\t\t<tbody>\r\n\t\t";
     // required fields - model definition
     $model_required = $model->getValidationRules();
     $required_help = false;
     $hidden_fields = array();
     foreach ($fdata['fields'] as $key => $att) {
         if ($tab !== false && varset($att['tab'], 0) !== $tab) {
             continue;
         }
         // convert aliases - not supported in edit mod
         if (vartrue($att['alias']) && !$model->hasData($key)) {
             $key = $att['field'];
         }
         if ($key == 'checkboxes' || $key == 'options' || $att['type'] === null || $att['type'] === false) {
             continue;
         }
         $parms = vartrue($att['formparms'], array());
         if (!is_array($parms)) {
             parse_str($parms, $parms);
         }
         $label = vartrue($att['note']) ? '<div class="label-note">' . deftrue($att['note'], $att['note']) . '</div>' : '';
         $help = vartrue($att['help']) ? '<div class="field-help">' . deftrue($att['help'], $att['help']) . '</div>' : '';
         $valPath = trim(vartrue($att['dataPath'], $key), '/');
         $keyName = $key;
         if (strpos($valPath, '/')) {
             $tmp = explode('/', $valPath);
             $keyName = array_shift($tmp);
             foreach ($tmp as $path) {
                 $keyName .= '[' . $path . ']';
             }
         }
         if (!empty($att['writeParms']) && !is_array($att['writeParms'])) {
             parse_str(varset($att['writeParms']), $writeParms);
         } else {
             $writeParms = varset($att['writeParms']);
         }
         if ('hidden' === $att['type']) {
             if (!vartrue($writeParms['show'])) {
                 $hidden_fields[] = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()));
                 continue;
             }
             unset($tmp);
         }
         // type null - system (special) fields
         if (vartrue($att['type']) !== null && !vartrue($att['noedit']) && $key != $model->getFieldIdName()) {
             $required = '';
             $required_class = '';
             if (isset($model_required[$key]) || vartrue($att['validate'])) {
                 $required = $this->getRequiredString();
                 $required_class = ' class="required-label"';
                 // TODO - add 'required-label' to the core CSS definitions
                 $required_help = true;
                 if (vartrue($att['validate'])) {
                     // override
                     $model_required[$key] = array();
                     $model_required[$key][] = true === $att['validate'] ? 'required' : $att['validate'];
                     $model_required[$key][] = varset($att['rule']);
                     $model_required[$key][] = $att['title'];
                     $model_required[$key][] = varset($att['error']);
                 }
             }
             /*
             if('hidden' === $att['type'])
             {
             	parse_str(varset($att['writeParms']), $tmp);
             	if(!vartrue($tmp['show']))
             	{
             		$hidden_fields[] = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()));
             		unset($tmp);
             		continue;
             	}
             	unset($tmp);
             }
             */
             $leftCell = $required . "<span{$required_class}>" . defset(vartrue($att['title']), vartrue($att['title'])) . "</span>" . $label;
             $rightCell = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()), $model->getId()) . " {$help}";
             if (vartrue($att['type']) == 'bbarea' || varset($writeParms['nolabel']) == true) {
                 $text .= "\r\n\t\t\t\t\t<tr><td colspan='2'>";
                 $text .= "<div style='padding-bottom:8px'>" . $leftCell . "</div>";
                 $text .= $rightCell . "\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t";
             } else {
                 // rightCellClass
                 //			leftCellClass
                 $leftCellClass = !empty($writeParms['tdClassLeft']) ? " class='" . $writeParms['tdClassLeft'] . "'" : "";
                 $rightCellClass = !empty($writeParms['tdClassRight']) ? " class='" . $writeParms['tdClassRight'] . "'" : "";
                 $trClass = !empty($writeParms['trClass']) ? " class='" . $writeParms['trClass'] . "'" : "";
                 $text .= "\r\n\t\t\t\t\t<tr{$trClass}>\r\n\t\t\t\t\t\t<td{$leftCellClass}>\r\n\t\t\t\t\t\t\t" . $leftCell . "\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t<td{$rightCellClass}>\r\n\t\t\t\t\t\t\t" . $rightCell . "\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t";
             }
         }
         //if($bckp) $model->remove($bckp);
     }
     //print_a($fdata);
     if ($required_help) {
         $required_help = '<div class="form-note">' . $this->getRequiredString() . ' - required fields</div>';
         //TODO - lans
     }
     $text .= "\r\n\t\t\t\t\t</tbody>\r\n\t\t\t\t</table>";
     $text .= implode("\n", $hidden_fields);
     $text .= "</fieldset>";
     $text .= vartrue($fdata['fieldset_post']);
     return $text;
     /*		
     		$text .= "
     				".implode("\n", $hidden_fields)."
     				".$required_help."
     				".vartrue($fdata['table_post'])."
     				<div class='buttons-bar center'>
     		";
     					// After submit options
     					$defsubmitopt = array('list' => 'go to list', 'create' => 'create another', 'edit' => 'edit current');
     					$submitopt = isset($fdata['after_submit_options']) ? $fdata['after_submit_options'] : true;
     					if(true === $submitopt)
     					{
     						$submitopt = $defsubmitopt;
     					}
     
     					if($submitopt)
     					{
     						$selected = isset($fdata['after_submit_default']) && array_key_exists($fdata['after_submit_default'], $submitopt) ? $fdata['after_submit_default'] : '';
     						
     					}
     
     					$triggers = vartrue($fdata['triggers'], 'auto');
     					if(is_string($triggers) && 'auto' === $triggers)
     					{
     						$triggers = array();
     						if($model->getId())
     						{
     							$triggers['submit'] = array(LAN_UPDATE, 'update', $model->getId());
     						}
     						else
     						{
     							$triggers['submit'] = array(LAN_CREATE, 'create', 0);
     						}
     						$triggers['cancel'] = array(LAN_CANCEL, 'cancel');
     					}
     
     					foreach ($triggers as $trigger => $tdata)
     					{
     						$text .= ($trigger == 'submit') ? "<div class=' btn-group'>" : "";
     						$text .= $this->admin_button('etrigger_'.$trigger, $tdata[0], $tdata[1]);
     						
     						if($trigger == 'submit' && $submitopt)
     						{
     						
     							$text .= 
     							'<button class="btn btn-success dropdown-toggle left" data-toggle="dropdown">
     									<span class="caret"></span>
     									</button>
     									<ul class="dropdown-menu col-selection">
     									<li class="nav-header">After submit:</li>
     							';
     							
     							foreach($defsubmitopt as $k=>$v)
     							{
     								$text .= "<li><a href='#' class='e-noclick'>".$this->radio('__after_submit_action', $k, $selected,"label=".$v)."</a></li>";	
     							}
     							
     							//$text .= '
     							//		<li role="menuitem">
     							//			<div class="options left" style="padding:5px">
     							//			'.$this->radio_multi('__after_submit_action', $submitopt, $selected, true).'
     							//			</div></li>';
     										
     									
     							$text .= '</ul>';
     						} 
     								
     						$text .= ($trigger == 'submit') ?"</div>" : "";
     						
     						if(isset($tdata[2]))
     						{
     							$text .= $this->hidden($trigger.'_value', $tdata[2]);
     						}
     					}
     
     		$text .= "
     				</div>
     			
     			".vartrue($fdata['fieldset_post'])."
     		";
     		return $text;
     */
 }
Exemple #2
0
    /**
     * Create form fieldset, called internal by {@link renderCreateForm())
     *
     * @param string $id field id
     * @param array $fdata fieldset data
     * @param e_admin_model $model
     */
    function renderCreateFieldset($id, $fdata, $model)
    {
        $text = vartrue($fdata['fieldset_pre']) . "\r\n\t\t\t<fieldset id='{$id}'>\r\n\t\t\t\t<legend>" . vartrue($fdata['legend']) . "</legend>\r\n\t\t\t\t" . vartrue($fdata['table_pre']) . "\r\n\t\t\t\t<table class='table adminform'>\r\n\t\t\t\t\t<colgroup>\r\n\t\t\t\t\t\t<col class='col-label' />\r\n\t\t\t\t\t\t<col class='col-control' />\r\n\t\t\t\t\t</colgroup>\r\n\t\t\t\t\t<tbody>\r\n\t\t";
        // required fields - model definition
        $model_required = $model->getValidationRules();
        $required_help = false;
        $hidden_fields = array();
        foreach ($fdata['fields'] as $key => $att) {
            // convert aliases - not supported in edit mod
            if ($att['alias'] && !$model->hasData($key)) {
                $key = $att['field'];
            }
            $parms = vartrue($att['formparms'], array());
            if (!is_array($parms)) {
                parse_str($parms, $parms);
            }
            $label = vartrue($att['note']) ? '<div class="label-note">' . deftrue($att['note'], $att['note']) . '</div>' : '';
            $help = vartrue($att['help']) ? '<div class="field-help">' . deftrue($att['help'], $att['help']) . '</div>' : '';
            $valPath = trim(vartrue($att['dataPath'], $key), '/');
            $keyName = $key;
            if (strpos($valPath, '/')) {
                $tmp = explode('/', $valPath);
                $keyName = array_shift($tmp);
                foreach ($tmp as $path) {
                    $keyName .= '[' . $path . ']';
                }
            }
            // type null - system (special) fields
            if ($att['type'] !== null && !vartrue($att['noedit']) && $key != $model->getFieldIdName()) {
                $required = '';
                $required_class = '';
                if (isset($model_required[$key]) || vartrue($att['validate'])) {
                    $required = $this->getRequiredString();
                    $required_class = ' class="required-label"';
                    // TODO - add 'required-label' to the core CSS definitions
                    $required_help = true;
                    if (vartrue($att['validate'])) {
                        // override
                        $model_required[$key] = array();
                        $model_required[$key][] = true === $att['validate'] ? 'required' : $att['validate'];
                        $model_required[$key][] = varset($att['rule']);
                        $model_required[$key][] = $att['title'];
                        $model_required[$key][] = varset($att['error']);
                    }
                }
                if ('hidden' === $att['type']) {
                    parse_str(varset($att['writeParms']), $tmp);
                    if (!vartrue($tmp['show'])) {
                        $hidden_fields[] = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()));
                        unset($tmp);
                        continue;
                    }
                    unset($tmp);
                }
                $text .= "\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t" . $required . "<span{$required_class}>" . defset($att['title'], $att['title']) . "</span>" . $label . "\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t" . $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array())) . "\r\n\t\t\t\t\t\t\t{$help}\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t";
            }
            //if($bckp) $model->remove($bckp);
        }
        if ($required_help) {
            $required_help = '<div class="form-note">' . $this->getRequiredString() . ' - required fields</div>';
            //TODO - lans
        }
        $text .= "\r\n\t\t\t\t\t</tbody>\r\n\t\t\t\t</table>\r\n\t\t\t\t" . implode("\n", $hidden_fields) . "\r\n\t\t\t\t" . $required_help . "\r\n\t\t\t\t" . vartrue($fdata['table_post']) . "\r\n\t\t\t\t<div class='buttons-bar center'>\r\n\t\t";
        // After submit options
        $defsubmitopt = array('list' => 'go to list', 'create' => 'create another', 'edit' => 'edit current');
        $submitopt = isset($fdata['after_submit_options']) ? $fdata['after_submit_options'] : true;
        if (true === $submitopt) {
            $submitopt = $defsubmitopt;
        }
        if ($submitopt) {
            $selected = isset($fdata['after_submit_default']) && array_key_exists($fdata['after_submit_default'], $submitopt) ? $fdata['after_submit_default'] : '';
            $text .= '
							<div class="options">
								After submit: ' . $this->radio_multi('__after_submit_action', $submitopt, $selected, false) . '
							</div>
						';
        }
        $triggers = vartrue($fdata['triggers'], 'auto');
        if (is_string($triggers) && 'auto' === $triggers) {
            $triggers = array();
            if ($model->getId()) {
                $triggers['submit'] = array(LAN_UPDATE, 'update', $model->getId());
            } else {
                $triggers['submit'] = array(LAN_CREATE, 'create', 0);
            }
            $triggers['cancel'] = array(LAN_CANCEL, 'cancel');
        }
        foreach ($triggers as $trigger => $tdata) {
            $text .= $this->admin_button('etrigger_' . $trigger, $tdata[0], $tdata[1]);
            if (isset($tdata[2])) {
                $text .= $this->hidden($trigger . '_value', $tdata[2]);
            }
        }
        $text .= "\r\n\t\t\t\t</div>\r\n\t\t\t</fieldset>\r\n\t\t\t" . vartrue($fdata['fieldset_post']) . "\r\n\t\t";
        return $text;
    }