Source for file htmllight.jformsbuilder.php

Documentation is available at htmllight.jformsbuilder.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  forms
  5. @author      Laurent Jouanneau
  6. @contributor Julien Issler, Dominique Papin
  7. @copyright   2006-2009 Laurent Jouanneau
  8. @copyright   2008 Julien Issler, 2008 Dominique Papin
  9. @link        http://www.jelix.org
  10. @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  11. */
  12.  
  13. /**
  14.  * HTML form builder
  15.  * @package     jelix
  16.  * @subpackage  jelix-plugins
  17.  */
  18. class htmllightJformsBuilder extends jFormsBuilderBase {
  19.  
  20.     protected $options;
  21.  
  22.     protected $isRootControl = true;
  23.  
  24.     public function outputAllControls({
  25.  
  26.         echo '<table class="jforms-table" border="0">';
  27.         foreach$this->_form->getRootControls(as $ctrlref=>$ctrl){
  28.             if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden'continue;
  29.             if(!$this->_form->isActivated($ctrlref)) continue;
  30.             if($ctrl->type == 'group'{
  31.                 echo '<tr><td colspan="2">';
  32.                 $this->outputControl($ctrl);
  33.                 echo '</td></tr>';
  34.             }else{
  35.                 echo '<tr><th scope="row">';
  36.                 $this->outputControlLabel($ctrl);
  37.                 echo '</th><td>';
  38.                 $this->outputControl($ctrl);
  39.                 echo '</td></tr>';
  40.             }
  41.         }
  42.         echo '</table> <div class="jforms-submit-buttons">';
  43.         if $ctrl $this->_form->getReset() ) {
  44.             if(!$this->_form->isActivated($ctrl->ref)) continue;
  45.             $this->outputControl($ctrl);
  46.             echo ' ';
  47.         }
  48.         foreach$this->_form->getSubmits(as $ctrlref=>$ctrl){
  49.             if(!$this->_form->isActivated($ctrlref)) continue;
  50.             $this->outputControl($ctrl);
  51.             echo ' ';
  52.         }
  53.         echo '</div>';
  54.     }
  55.  
  56.     public function outputMetaContent($t{
  57.         global $gJCoord$gJConfig;
  58.         $resp$gJCoord->response;
  59.         if($resp === null || $resp->getType(!='html'){
  60.             return;
  61.         }
  62.         $www =$gJConfig->urlengine['jelixWWWPath'];
  63.         $bp =$gJConfig->urlengine['basePath'];
  64.         $resp->addJSLink($www.'js/jforms_light.js');
  65.         $resp->addCSSLink($www.'design/jform.css');
  66.         foreach($t->_vars as $k=>$v){
  67.             if($v instanceof jFormsBase && count($edlist $v->getHtmlEditors())) {
  68.                 foreach($edlist as $ed{
  69.                     if(isset($gJConfig->htmleditors[$ed->config.'.engine.file'])){
  70.                         if(is_array($gJConfig->htmleditors[$ed->config.'.engine.file'])){
  71.                             foreach($gJConfig->htmleditors[$ed->config.'.engine.file'as $url{
  72.                                 $resp->addJSLink($bp.$url);
  73.                             }
  74.                         }else
  75.                             $resp->addJSLink($bp.$gJConfig->htmleditors[$ed->config.'.engine.file']);
  76.                     }
  77.                     if(isset($gJConfig->htmleditors[$ed->config.'.config']))
  78.                         $resp->addJSLink($bp.$gJConfig->htmleditors[$ed->config.'.config']);
  79.                     if(isset($gJConfig->htmleditors[$ed->config.'.skin.'.$ed->skin]))
  80.                         $resp->addCSSLink($bp.$gJConfig->htmleditors[$ed->config.'.skin.'.$ed->skin]);
  81.                 }
  82.             }
  83.         }
  84.     }
  85.  
  86.     /**
  87.      * output the header content of the form
  88.      * @param array $params some parameters <ul>
  89.      *       <li>"errDecorator"=>"name of your javascript object for error listener"</li>
  90.      *       <li>"helpDecorator"=>"name of your javascript object for help listener"</li>
  91.      *       <li>"method" => "post" or "get". default is "post"</li>
  92.      *       </ul>
  93.      */
  94.     public function outputHeader($params){
  95.         $this->options = array_merge(array('errorDecorator'=>'jFormsErrorDecoratorAlert',
  96.                  'helpDecorator'=>'jFormsHelpDecoratorAlert''method'=>'post')$params);
  97.  
  98.         if (preg_match('#^https?://#',$this->_action)) {
  99.             $urlParams $this->_actionParams;
  100.             echo '<form action="',$this->_action,'" method="'.$this->options['method'].'" id="'$this->_name,'"';
  101.         else {
  102.             $url jUrl::get($this->_action$this->_actionParams2)// retourne le jurl correspondant
  103.             $urlParams $url->params;
  104.             echo '<form action="',$url->getPath(),'" method="'.$this->options['method'].'" id="'$this->_name,'"';
  105.         }
  106.         if($this->_form->hasUpload())
  107.             echo ' enctype="multipart/form-data">';
  108.         else
  109.             echo '>';
  110.  
  111.         echo '<script type="text/javascript">
  112. //<![CDATA[
  113. jForms.tForm = new jFormsForm(\''.$this->_name.'\');
  114. jForms.tForm.setErrorDecorator(new '.$this->options['errorDecorator'].'());
  115. jForms.tForm.setHelpDecorator(new '.$this->options['helpDecorator'].'());
  116. jForms.declareForm(jForms.tForm);
  117. //]]>
  118. </script>';
  119.  
  120.         $hiddens '';
  121.         foreach ($urlParams as $p_name => $p_value{
  122.             $hiddens .= '<input type="hidden" name="'$p_name .'" value="'htmlspecialchars($p_value)'"'.$this->_endt"\n";
  123.         }
  124.  
  125.         foreach ($this->_form->getHiddens(as $ctrl{
  126.             if(!$this->_form->isActivated($ctrl->ref)) continue;
  127.             $hiddens .= '<input type="hidden" name="'$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'" value="'htmlspecialchars($this->_form->getData($ctrl->ref))'"'.$this->_endt"\n";
  128.         }
  129.  
  130.         if($this->_form->securityLevel){
  131.             $tok $this->_form->createNewToken();
  132.             $hiddens .= '<input type="hidden" name="__JFORMS_TOKEN__" value="'.$tok.'"'.$this->_endt"\n";
  133.         }
  134.  
  135.         if($hiddens){
  136.             echo '<div class="jforms-hiddens">',$hiddens,'</div>';
  137.         }
  138.  
  139.         $errors $this->_form->getContainer()->errors;
  140.         if(count($errors)){
  141.             $ctrls $this->_form->getControls();
  142.             echo '<ul class="jforms-error-list">';
  143.             $errRequired='';
  144.             foreach($errors as $cname => $err){
  145.                 if(!$this->_form->isActivated($ctrls[$cname]->ref)) continue;
  146.                 if($err == jForms::ERRDATA_REQUIRED{
  147.                     if($ctrls[$cname]->alertRequired){
  148.                         echo '<li>'$ctrls[$cname]->alertRequired,'</li>';
  149.                     }else{
  150.                         echo '<li>'jLocale::get('jelix~formserr.js.err.required'$ctrls[$cname]->label),'</li>';
  151.                     }
  152.                 }elseif ($err != '' && $err != jForms::ERRDATA_INVALID{
  153.                     echo '<li>'$err,'</li>';
  154.                 }else{
  155.                     if($ctrls[$cname]->alertInvalid){
  156.                         echo '<li>'$ctrls[$cname]->alertInvalid,'</li>';
  157.                     }else{
  158.                         echo '<li>'jLocale::get('jelix~formserr.js.err.invalid'$ctrls[$cname]->label),'</li>';
  159.                     }
  160.                 }
  161.  
  162.             }
  163.             echo '</ul>';
  164.         }
  165.     }
  166.  
  167.     protected $jsContent = '';
  168.  
  169.     public function outputFooter(){
  170.         echo '<script type="text/javascript">
  171. //<![CDATA[
  172. (function(){var c, c2;
  173. '.$this->jsContent.'
  174. })();
  175. //]]>
  176. </script>';
  177.         echo '</form>';
  178.     }
  179.  
  180.     public function outputControlLabel($ctrl){
  181.         if($ctrl->type == 'hidden' || $ctrl->type == 'group'return;
  182.         $required ($ctrl->required == false || $ctrl->isReadOnly()?'':' jforms-required');
  183.         $inError (isset($this->_form->getContainer()->errors[$ctrl->ref]?' jforms-error':'');
  184.         $hint ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"');
  185.         if($ctrl->type == 'output' || $ctrl->type == 'checkboxes' || $ctrl->type == 'radiobuttons' || $ctrl->type == 'date' || $ctrl->type == 'datetime'){
  186.             echo '<span class="jforms-label',$required,$inError,'"',$hint,'>',htmlspecialchars($ctrl->label),'</span>';
  187.         }else if($ctrl->type != 'submit' && $ctrl->type != 'reset'){
  188.             $id $this->_name.'_'.$ctrl->ref;
  189.             echo '<label class="jforms-label',$required,$inError,'" for="',$id,'"',$hint,'>',htmlspecialchars($ctrl->label),'</label>';
  190.         }
  191.     }
  192.  
  193.     public function outputControl($ctrl){
  194.         if($ctrl->type == 'hidden'return;
  195.         $ro $ctrl->isReadOnly();
  196.         $id ' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'"';
  197.         $class ($ctrl->required == false || $ro?'':' jforms-required');
  198.         $class.= (isset($this->_form->getContainer()->errors[$ctrl->ref]?' jforms-error':'');
  199.         $class.= ($ro && $ctrl->type != 'captcha'?' jforms-readonly':'');
  200.         $readonly ($ro?' readonly="readonly"':'');
  201.         if($class !=''$class ' class="'.$class.'"';
  202.         $hint ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"');
  203.         $this->{'output'.$ctrl->type}($ctrl$id$class$readonly$hint);
  204.         $this->{'js'.$ctrl->type}($ctrl);
  205.         $this->outputHelp($ctrl);
  206.     }
  207.  
  208.     protected function escJsStr($str{
  209.         return '\''.str_replace(array("'","\n"),array("\\'""\\n")$str).'\'';
  210.     }
  211.  
  212.     protected function commonJs($ctrl{
  213.         if($ctrl->help){
  214.             $this->jsContent .="c.help=".$this->escJsStr($ctrl->help).";\n";
  215.         }
  216.  
  217.         if($ctrl->required){
  218.             $this->jsContent .="c.required = true;\n";
  219.             if($ctrl->alertRequired){
  220.                 $this->jsContent .="c.errRequired=".$this->escJsStr($ctrl->alertRequired).";\n";
  221.             }
  222.             else {
  223.                 $this->jsContent .="c.errRequired=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.required'$ctrl->label)).";\n";
  224.             }
  225.         }
  226.  
  227.         if($ctrl->alertInvalid){
  228.             $this->jsContent .="c.errInvalid=".$this->escJsStr($ctrl->alertInvalid).";\n";
  229.         }
  230.         else {
  231.             $this->jsContent .="c.errInvalid=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.invalid'$ctrl->label)).";\n";
  232.         }
  233.  
  234.         if ($this->isRootControl$this->jsContent .="jForms.tForm.addControl(c);\n";
  235.     }
  236.  
  237.     protected function outputInput($ctrl$id$class$readonly$hint{
  238.         $value $this->_form->getData($ctrl->ref);
  239.         $size ($ctrl->size == 0?'' ' size="'.$ctrl->size.'"');
  240.         $maxl$ctrl->datatype->getFacet('maxLength');
  241.         if($maxl !== null)
  242.             $maxl=' maxlength="'.$maxl.'"';
  243.         else
  244.             $maxl='';
  245.         echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt;
  246.     }
  247.  
  248.     protected function jsInput($ctrl{
  249.  
  250.         $datatype array('jDatatypeBoolean'=>'Boolean','jDatatypeDecimal'=>'Decimal','jDatatypeInteger'=>'Integer','jDatatypeHexadecimal'=>'Hexadecimal',
  251.                         'jDatatypeDateTime'=>'Datetime','jDatatypeDate'=>'Date','jDatatypeTime'=>'Time',
  252.                         'jDatatypeUrl'=>'Url','jDatatypeEmail'=>'Email','jDatatypeIPv4'=>'Ipv4','jDatatypeIPv6'=>'Ipv6');
  253.         $isLocale false;
  254.         $data_type_class get_class($ctrl->datatype);
  255.         if(isset($datatype[$data_type_class]))
  256.             $dt $datatype[$data_type_class];
  257.         else if ($ctrl->datatype instanceof jDatatypeLocaleTime)
  258.             $dt 'Time'$isLocale true}
  259.         else if ($ctrl->datatype instanceof jDatatypeLocaleDate)
  260.             $dt 'LocaleDate'$isLocale true}
  261.         else if ($ctrl->datatype instanceof jDatatypeLocaleDateTime)
  262.             $dt 'LocaleDatetime'$isLocale true}
  263.         else
  264.             $dt 'String';
  265.  
  266.         $this->jsContent .="c = new jFormsControl".$dt."('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  267.         if ($isLocale)
  268.             $this->jsContent .="c.lang='".$GLOBALS['gJConfig']->locale."';\n";
  269.  
  270.         $maxl$ctrl->datatype->getFacet('maxLength');
  271.         if($maxl !== null)
  272.             $this->jsContent .="c.maxLength = '$maxl';\n";
  273.  
  274.         $minl$ctrl->datatype->getFacet('minLength');
  275.         if($minl !== null)
  276.             $this->jsContent .="c.minLength = '$minl';\n";
  277.  
  278.         $this->commonJs($ctrl);
  279.     }
  280.  
  281.     protected function _outputDateControlDay($ctrl$id$value$class$readonly$hint){
  282.         if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  283.             echo '<input type="text" size="2" maxlength="2" id="'.$id.'day" name="'.$ctrl->ref.'[day]"'.$readonly.$hint.$class.' value="'.$value.'"'.$this->_endt;
  284.         else{
  285.             echo '<select id="'.$id.'day" name="'.$ctrl->ref.'[day]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.date.day.label')).'</option>';
  286.             for($i=1;$i<32;$i++){
  287.                 $k ($i<10)?'0'.$i:$i;
  288.                 echo '<option value="'.$k.'"'.($k == $value?' selected="selected"':'').'>'.$k.'</option>';
  289.             }
  290.             echo '</select>';
  291.         }
  292.     }
  293.  
  294.     protected function _outputDateControlMonth($ctrl$id$value$class$readonly$hint){
  295.         if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  296.             echo '<input type="text" size="2" maxlength="2" id="'.$id.'month" name="'.$ctrl->ref.'[month]"'.$readonly.$hint.$class.' value="'.$value.'"'.$this->_endt;
  297.         else{
  298.             $monthLabels $GLOBALS['gJConfig']->forms['controls.datetime.months.labels'];
  299.             echo '<select id="'.$id.'month" name="'.$ctrl->ref.'[month]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.date.month.label')).'</option>';
  300.             for($i=1;$i<13;$i++){
  301.                 $k ($i<10)?'0'.$i:$i;
  302.                 if($monthLabels == 'names')
  303.                     $l htmlspecialchars(jLocale::get('jelix~date_time.month.'.$k.'.label'));
  304.                 else if($monthLabels == 'shortnames')
  305.                     $l htmlspecialchars(jLocale::get('jelix~date_time.month.'.$k.'.shortlabel'));
  306.                 else
  307.                     $l $k;
  308.                 echo '<option value="'.$k.'"'.($k == $value?' selected="selected"':'').'>'.$l.'</option>';
  309.             }
  310.             echo '</select>';
  311.         }
  312.     }
  313.  
  314.     protected function _outputDateControlYear($ctrl$id$value$class$readonly$hint){
  315.         if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  316.             echo '<input type="text" size="4" maxlength="4" id="'.$id.'year" name="'.$ctrl->ref.'[year]"'.$readonly.$hint.$class.' value="'.$value.'"'.$this->_endt;
  317.         else{
  318.             $minDate $ctrl->datatype->getFacet('minValue');
  319.             $maxDate $ctrl->datatype->getFacet('maxValue');
  320.             if($minDate && $maxDate){
  321.                 echo '<select id="'.$id.'year" name="'.$ctrl->ref.'[year]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.date.year.label')).'</option>';
  322.                 for($i=$minDate->year;$i<=$maxDate->year;$i++)
  323.                     echo '<option value="'.$i.'"'.($i == $value?' selected="selected"':'').'>'.$i.'</option>';
  324.                 echo '</select>';
  325.             }
  326.             else
  327.                 echo '<input type="text" size="4" maxlength="4" id="'.$id.'year" name="'.$ctrl->ref.'[year]"'.$readonly.$hint.$class.' value="'.$value.'"'.$this->_endt;
  328.         }
  329.     }
  330.  
  331.     protected function _outputDateControlHour($ctrl$id$value$class$readonly$hint){
  332.         if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  333.             echo '<input type="text" id="'.$id.'hour" name="'.$ctrl->ref.'[hour]" value="'.$value.'"'.$this->_endt;
  334.         else{
  335.             echo '<select id="'.$id.'hour" name="'.$ctrl->ref.'[hour]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.time.hour.label')).'</option>';
  336.             for($i=0;$i<24;$i++){
  337.                 $k ($i<10)?'0'.$i:$i;
  338.                 echo '<option value="'.$k.'"'.(string) $k === $value?' selected="selected"':'').'>'.$k.'</option>';
  339.             }
  340.             echo '</select>';
  341.         }
  342.     }
  343.  
  344.     protected function _outputDateControlMinutes($ctrl$id$value$class$readonly$hint){
  345.         if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  346.             echo '<input type="text" id="'.$id.'minutes" name="'.$ctrl->ref.'[minutes]" value="'.$value.'"'.$this->_endt;
  347.         else{
  348.             echo '<select id="'.$id.'minutes" name="'.$ctrl->ref.'[minutes]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.time.minutes.label')).'</option>';
  349.             for($i=0;$i<60;$i++){
  350.                 $k ($i<10)?'0'.$i:$i;
  351.                 echo '<option value="'.$k.'"'.(string) $k === $value?' selected="selected"':'').'>'.$k.'</option>';
  352.             }
  353.             echo '</select>';
  354.         }
  355.     }
  356.  
  357.     protected function _outputDateControlSeconds($ctrl$id$value$class$readonly$hint){
  358.         if(!$ctrl->enableSeconds)
  359.             echo '<input type="hidden" id="'.$id.'seconds" name="'.$ctrl->ref.'[seconds]" value="'.$value.'"'.$this->_endt;
  360.         else if($GLOBALS['gJConfig']->forms['controls.datetime.input'== 'textboxes')
  361.             echo '<input type="text" id="'.$id.'seconds" name="'.$ctrl->ref.'[seconds]" value="'.$value.'"'.$this->_endt;
  362.         else{
  363.             echo '<select id="'.$id.'seconds" name="'.$ctrl->ref.'[seconds]"'.$readonly.$hint.$class.'><option value="">'.htmlspecialchars(jLocale::get('jelix~jforms.time.seconds.label')).'</option>';
  364.             for($i=0;$i<60;$i++){
  365.                 $k ($i<10)?'0'.$i:$i;
  366.                 echo '<option value="'.$k.'"'.(string) $k === $value?' selected="selected"':'').'>'.$k.'</option>';
  367.             }
  368.             echo '</select>';
  369.         }
  370.     }
  371.  
  372.     protected function outputDate($ctrl$id$class$readonly$hint){
  373.         $id $this->_name.'_'.$ctrl->ref.'_';
  374.         $v array('year'=>'','month'=>'','day'=>'');
  375.         if(preg_match('#^(\d{4})?-(\d{2})?-(\d{2})?$#',$this->_form->getData($ctrl->ref),$matches)){
  376.             if(isset($matches[1]))
  377.                 $v['year'$matches[1];
  378.             if(isset($matches[2]))
  379.                 $v['month'$matches[2];
  380.             if(isset($matches[3]))
  381.                 $v['day'$matches[3];
  382.         }
  383.         $f jLocale::get('jelix~format.date');
  384.         for($i=0;$i<strlen($f);$i++){
  385.             if($f[$i== 'Y')
  386.                 $this->_outputDateControlYear($ctrl$id$v['year']$class$readonly$hint);
  387.             else if($f[$i== 'm')
  388.                 $this->_outputDateControlMonth($ctrl$id$v['month']$class$readonly$hint);
  389.             else if($f[$i== 'd')
  390.                 $this->_outputDateControlDay($ctrl$id$v['day']$class$readonly$hint);
  391.             else
  392.                 echo ' ';
  393.         }
  394.     }
  395.  
  396.     protected function jsDate($ctrl){
  397.         $this->jsContent .= "c = new jFormsControlDate('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  398.         $this->jsContent .= "c.multiFields = true;\n";
  399.         $minDate $ctrl->datatype->getFacet('minValue');
  400.         $maxDate $ctrl->datatype->getFacet('maxValue');
  401.         if($minDate)
  402.             $this->jsContent .= "c.minDate = '".$minDate->toString(jDateTime::BD_DFORMAT)."';\n";
  403.         if($maxDate)
  404.             $this->jsContent .= "c.maxDate = '".$maxDate->toString(jDateTime::BD_DFORMAT)."';\n";
  405.         $this->commonJs($ctrl);
  406.     }
  407.  
  408.     protected function outputDatetime($ctrl$id$class$readonly$hint){
  409.         $id $this->_name.'_'.$ctrl->ref.'_';
  410.         $v array('year'=>'','month'=>'','day'=>'','hour'=>'','minutes'=>'','seconds'=>'');
  411.         if(preg_match('#^(\d{4})?-(\d{2})?-(\d{2})? (\d{2})?:(\d{2})?(:(\d{2})?)?$#',$this->_form->getData($ctrl->ref),$matches)){
  412.             if(isset($matches[1]))
  413.                 $v['year'$matches[1];
  414.             if(isset($matches[2]))
  415.                 $v['month'$matches[2];
  416.             if(isset($matches[3]))
  417.                 $v['day'$matches[3];
  418.             if(isset($matches[4]))
  419.                 $v['hour'$matches[4];
  420.             if(isset($matches[5]))
  421.                 $v['minutes'$matches[5];
  422.             if(isset($matches[7]))
  423.                 $v['seconds'$matches[7];
  424.         }
  425.         $f jLocale::get('jelix~format.datetime');
  426.         for($i=0;$i<strlen($f);$i++){
  427.             if($f[$i== 'Y')
  428.                 $this->_outputDateControlYear($ctrl$id$v['year']$class$readonly$hint);
  429.             else if($f[$i== 'm')
  430.                 $this->_outputDateControlMonth($ctrl$id$v['month']$class$readonly$hint);
  431.             else if($f[$i== 'd')
  432.                 $this->_outputDateControlDay($ctrl$id$v['day']$class$readonly$hint);
  433.             else if($f[$i== 'H')
  434.                 $this->_outputDateControlHour($ctrl$id$v['hour']$class$readonly$hint);
  435.             else if($f[$i== 'i')
  436.                 $this->_outputDateControlMinutes($ctrl$id$v['minutes']$class$readonly$hint);
  437.             else if($f[$i== 's')
  438.                 $this->_outputDateControlSeconds($ctrl$id$v['seconds']$class$readonly$hint);
  439.             else
  440.                 echo ' ';
  441.         }
  442.     }
  443.  
  444.     protected function jsDatetime($ctrl){
  445.         $this->jsContent .= "c = new jFormsControlDatetime('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  446.         $this->jsContent .= "c.multiFields = true;\n";
  447.         $minDate $ctrl->datatype->getFacet('minValue');
  448.         $maxDate $ctrl->datatype->getFacet('maxValue');
  449.         if($minDate)
  450.             $this->jsContent .= "c.minDate = '".$minDate->toString(jDateTime::BD_DTFORMAT)."';\n";
  451.         if($maxDate)
  452.             $this->jsContent .= "c.maxDate = '".$maxDate->toString(jDateTime::BD_DTFORMAT)."';\n";
  453.         $this->commonJs($ctrl);
  454.     }
  455.  
  456.     protected function outputCheckbox($ctrl$id$class$readonly$hint{
  457.         $value $this->_form->getData($ctrl->ref);
  458.  
  459.         if($ctrl->valueOnCheck == $value){
  460.             $v=' checked="checked"';
  461.         }else{
  462.             $v='';
  463.         }
  464.         echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt;
  465.     }
  466.  
  467.     protected function jsCheckbox($ctrl{
  468.  
  469.         $this->jsContent .="c = new jFormsControlBoolean('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  470.  
  471.         $this->commonJs($ctrl);
  472.     }
  473.  
  474.     protected function outputCheckboxes($ctrl$id$class$readonly$hint{
  475.         $i=0;
  476.         $id=$this->_name.'_'.$ctrl->ref.'_';
  477.         $attrs=' name="'.$ctrl->ref.'[]" id="'.$id;
  478.         $value $this->_form->getData($ctrl->ref);
  479.  
  480.         if(is_array($value&& count($value== 1)
  481.             $value $value[0];
  482.         $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"';
  483.  
  484.         if(is_array($value)){
  485.             $value array_map(create_function('$v''return (string) $v;'),$value);
  486.             foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  487.                 echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"';
  488.                 if(in_array((string) $v,$value,true))
  489.                     echo ' checked="checked"';
  490.                 echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>';
  491.                 $i++;
  492.             }
  493.         }else{
  494.             $value = (string) $value;
  495.             foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  496.                 echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"';
  497.                 if((string) $v === $value)
  498.                     echo ' checked="checked"';
  499.                 echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>';
  500.                 $i++;
  501.             }
  502.         }
  503.     }
  504.  
  505.     protected function jsCheckboxes($ctrl{
  506.  
  507.         $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."[]', ".$this->escJsStr($ctrl->label).");\n";
  508.  
  509.         $this->commonJs($ctrl);
  510.     }
  511.  
  512.     protected function outputRadiobuttons($ctrl$id$class$readonly$hint{
  513.         $i=0;
  514.         $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_';
  515.         $value $this->_form->getData($ctrl->ref);
  516.         if(is_array($value)){
  517.             if(isset($value[0]))
  518.                 $value $value[0];
  519.             else
  520.                 $value='';
  521.         }
  522.         $value = (string) $value;
  523.         $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"';
  524.         foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  525.             echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',((string) $v===$value?' checked="checked"':''),$readonly,$class,$this->_endt;
  526.             echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>';
  527.             $i++;
  528.         }
  529.     }
  530.  
  531.     protected function jsRadiobuttons($ctrl{
  532.  
  533.         $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  534.  
  535.         $this->commonJs($ctrl);
  536.     }
  537.  
  538.     protected function outputMenulist($ctrl$id$class$readonly$hint{
  539.         echo '<select',$id,$hint,$class,' size="1">';
  540.         $value $this->_form->getData($ctrl->ref);
  541.         if(is_array($value)){
  542.             if(isset($value[0]))
  543.                 $value $value[0];
  544.             else
  545.                 $value='';
  546.         }
  547.         $value = (string) $value;
  548.         if (!$ctrl->required{
  549.             echo '<option value=""',($value===''?' selected="selected"':''),'>',htmlspecialchars($ctrl->emptyItemLabel),'</option>';
  550.         }
  551.         foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  552.             echo '<option value="',htmlspecialchars($v),'"',((string) $v===$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>';
  553.         }
  554.         echo '</select>';
  555.     }
  556.  
  557.     protected function jsMenulist($ctrl{
  558.  
  559.         $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  560.  
  561.         $this->commonJs($ctrl);
  562.     }
  563.  
  564.     protected function outputListbox($ctrl$id$class$readonly$hint{
  565.         if($ctrl->multiple){
  566.             echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">';
  567.             $value $this->_form->getData($ctrl->ref);
  568.  
  569.             if(is_array($value&& count($value== 1)
  570.                 $value $value[0];
  571.  
  572.             if(is_array($value)){
  573.                 $value array_map(create_function('$v''return (string) $v;'),$value);
  574.                 foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  575.                     echo '<option value="',htmlspecialchars($v),'"',(in_array((string) $v,$value,true)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>';
  576.                 }
  577.             }else{
  578.                 $value = (string) $value;
  579.                 foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  580.                     echo '<option value="',htmlspecialchars($v),'"',((string) $v===$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>';
  581.                 }
  582.             }
  583.             echo '</select>';
  584.         }else{
  585.             $value $this->_form->getData($ctrl->ref);
  586.  
  587.             if(is_array($value)){
  588.                 if(count($value>= 1)
  589.                     $value $value[0];
  590.                 else
  591.                     $value ='';
  592.             }
  593.  
  594.             $value = (string) $value;
  595.             echo '<select',$id,$hint,$class,' size="',$ctrl->size,'">';
  596.             foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  597.                 echo '<option value="',htmlspecialchars($v),'"',((string) $v===$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>';
  598.             }
  599.             echo '</select>';
  600.         }
  601.     }
  602.  
  603.     protected function jsListbox($ctrl{
  604.         if($ctrl->multiple){
  605.             $this->jsContent .= "c = new jFormsControlString('".$ctrl->ref."[]', ".$this->escJsStr($ctrl->label).");\n";
  606.             $this->jsContent .= "c.multiple = true;\n";
  607.         else {
  608.             $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  609.         }
  610.  
  611.         $this->commonJs($ctrl);
  612.     }
  613.  
  614.     protected function outputTextarea($ctrl$id$class$readonly$hint{
  615.         $value $this->_form->getData($ctrl->ref);
  616.         $rows ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"';
  617.         echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>';
  618.     }
  619.  
  620.     protected function jsTextarea($ctrl{
  621.         $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  622.  
  623.         $maxl$ctrl->datatype->getFacet('maxLength');
  624.         if($maxl !== null)
  625.             $this->jsContent .="c.maxLength = '$maxl';\n";
  626.  
  627.         $minl$ctrl->datatype->getFacet('minLength');
  628.         if($minl !== null)
  629.             $this->jsContent .="c.minLength = '$minl';\n";
  630.  
  631.         $this->commonJs($ctrl);
  632.     }
  633.  
  634.     protected function outputHtmleditor($ctrl$id$class$readonly$hint{
  635.         $value $this->_form->getData($ctrl->ref);
  636.         $rows ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"';
  637.         echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>';
  638.     }
  639.  
  640.     protected function jsHtmleditor($ctrl{
  641.         $this->jsTextarea($ctrl);
  642.         $engine $GLOBALS['gJConfig']->htmleditors[$ctrl->config.'.engine.name'];
  643.         $this->jsContent .= 'jelix_'.$engine.'_'.$ctrl->config.'("'.$this->_name.'_'.$ctrl->ref.'","'.$this->_name."\");\n";
  644.     }
  645.  
  646.     protected function outputSecret($ctrl$id$class$readonly$hint{
  647.         $size ($ctrl->size == 0?''' size="'.$ctrl->size.'"');
  648.         $maxl $ctrl->datatype->getFacet('maxLength');
  649.         if($maxl !== null)
  650.             $maxl ' maxlength="'.$maxl.'"';
  651.         else
  652.             $maxl '';
  653.         echo '<input type="password"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt;
  654.     }
  655.  
  656.     protected function jsSecret($ctrl{
  657.         $this->jsContent .="c = new jFormsControlSecret('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  658.  
  659.         $maxl$ctrl->datatype->getFacet('maxLength');
  660.         if($maxl !== null)
  661.             $this->jsContent .="c.maxLength = '$maxl';\n";
  662.  
  663.         $minl$ctrl->datatype->getFacet('minLength');
  664.         if($minl !== null)
  665.             $this->jsContent .="c.minLength = '$minl';\n";
  666.  
  667.         $this->commonJs($ctrl);
  668.     }
  669.  
  670.     protected function outputSecretconfirm($ctrl$id$class$readonly$hint{
  671.         $size ($ctrl->size == 0?''' size="'.$ctrl->size.'"');
  672.         echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt;
  673.     }
  674.  
  675.     protected function jsSecretconfirm($ctrl{
  676.         $this->jsContent .="c = new jFormsControlConfirm('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  677.         $this->commonJs($ctrl);
  678.     }
  679.  
  680.     protected function outputOutput($ctrl$id$class$readonly$hint{
  681.         $value $this->_form->getData($ctrl->ref);
  682.         echo '<input type="hidden"',$id,' value="',htmlspecialchars($value),'"',$this->_endt;
  683.         echo '<span class="jforms-value"',$hint,'>',htmlspecialchars($value),'</span>';
  684.     }
  685.  
  686.     protected function jsOutput($ctrl{
  687.     }
  688.  
  689.     protected function outputUpload($ctrl$id$class$readonly$hint{
  690.         if($ctrl->maxsize){
  691.             echo '<input type="hidden" name="MAX_FILE_SIZE" value="',$ctrl->maxsize,'"',$this->_endt;
  692.         }
  693.         echo '<input type="file"',$id,$readonly,$hint,$class,' value=""',$this->_endt// ',htmlspecialchars($this->_form->getData($ctrl->ref)),'
  694.  
  695.     }
  696.  
  697.     protected function jsUpload($ctrl{
  698.         $this->jsContent .="c = new jFormsControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  699.  
  700.         $this->commonJs($ctrl);
  701.     }
  702.  
  703.     protected function outputSubmit($ctrl$id$class$readonly$hint{
  704.         if($ctrl->standalone){
  705.             echo '<input type="submit"',$id,$hint,' class="jforms-submit" value="',htmlspecialchars($ctrl->label),'"/>';
  706.         }else{
  707.             foreach($ctrl->datasource->getData($this->_formas $v=>$label){
  708.                 // because IE6 sucks with <button type=submit> (see ticket #431), we must use input :-(
  709.                 echo '<input type="submit" name="',$ctrl->ref,'" id="',$this->_name,'_',$ctrl->ref,'_',htmlspecialchars($v),'"',
  710.                     $hint,' class="jforms-submit" value="',htmlspecialchars($label),'"/> ';
  711.             }
  712.         }
  713.     }
  714.  
  715.     protected function jsSubmit($ctrl{
  716.         // no javascript
  717.     }
  718.  
  719.     protected function outputReset($ctrl$id$class$readonly$hint{
  720.         echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>';
  721.     }
  722.  
  723.     protected function jsReset($ctrl{
  724.         // no javascript
  725.     }
  726.  
  727.     protected function outputCaptcha($ctrl$id$class$readonly$hint{
  728.         $ctrl->initExpectedValue();
  729.         echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> ';
  730.         echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt;
  731.     }
  732.  
  733.     protected function jsCaptcha($ctrl{
  734.         $this->jsTextarea($ctrl);
  735.     }
  736.  
  737.     protected function outputGroup($ctrl$id$class$readonly$hint{
  738.         echo '<fieldset><legend>',htmlspecialchars($ctrl->label),"</legend>\n";
  739.         echo '<table class="jforms-table-group" border="0">',"\n";
  740.         foreach$ctrl->getChildControls(as $ctrlref=>$c){
  741.             if($c->type == 'submit' || $c->type == 'reset' || $c->type == 'hidden'continue;
  742.             if(!$this->_form->isActivated($ctrlref)) continue;
  743.             echo '<tr><th scope="row">';
  744.             $this->outputControlLabel($c);
  745.             echo "</th>\n<td>";
  746.             $this->outputControl($c);
  747.             echo "</td></tr>\n";
  748.         }
  749.         echo "</table></fieldset>";
  750.     }
  751.  
  752.     protected function jsGroup($ctrl{
  753.         //no javacript
  754.     }
  755.  
  756.     protected function outputChoice($ctrl$id$class$readonly$hint{
  757.         echo '<ul class="jforms-choice jforms-ctl-'.$ctrl->ref.'" >',"\n";
  758.  
  759.         $value $this->_form->getData($ctrl->ref);
  760.         if(is_array($value)){
  761.             if(isset($value[0]))
  762.                 $value $value[0];
  763.             else
  764.                 $value='';
  765.         }
  766.  
  767.         $i=0;
  768.         $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_';
  769.         $this->jsChoiceInternal($ctrl);
  770.         $this->jsContent .="c2 = c;\n";
  771.         $this->isRootControl = false;
  772.         foreach$ctrl->items as $itemName=>$listctrl){
  773.             echo '<li><label><input type="radio"',$id,$i,'" value="',htmlspecialchars($itemName),'"';
  774.             echo ($itemName==$value?' checked="checked"':''),$readonly;
  775.             echo ' onclick="jForms.getForm(\'',$this->_name,'\').getControl(\'',$ctrl->ref,'\').activate(\'',$itemName,'\')"'$this->_endt;
  776.             echo htmlspecialchars($ctrl->itemsNames[$itemName]),'</label> ';
  777.  
  778.             $displayedControls false;
  779.             foreach($listctrl as $ref=>$c{
  780.                 if(!$this->_form->isActivated($ref|| $c->type == 'hidden'continue;
  781.                 $displayedControls true;
  782.                 echo ' <span class="jforms-item-controls">';
  783.                 // we remove readonly status so when a user change the choice and
  784.                 // javascript is deactivated, it can still change the value of the control
  785.                 $ro $c->isReadOnly();
  786.                 if($ro && $readonly == ''$c->setReadOnly(false);
  787.                 $this->outputControlLabel($c);
  788.                 echo ' ';
  789.                 $this->outputControl($c);
  790.                 if($ro$c->setReadOnly(true);
  791.                 echo "</span>\n";
  792.                 $this->jsContent .="c2.addControl(c, ".$this->escJsStr($itemName).");\n";
  793.             }
  794.             if(!$displayedControls{
  795.                 $this->jsContent .="c2.items[".$this->escJsStr($itemName)."]=[];\n";
  796.             }
  797.  
  798.             echo "</li>\n";
  799.             $i++;
  800.         }
  801.         echo "</ul>\n";
  802.         $this->isRootControl = true;
  803.     }
  804.  
  805.     protected function jsChoice($ctrl{
  806.         $value $this->_form->getData($ctrl->ref);
  807.         if(is_array($value)){
  808.             if(isset($value[0]))
  809.                 $value $value[0];
  810.             else
  811.                 $value='';
  812.         }
  813.         $this->jsContent .= "c2.activate('".$value."');\n";
  814.     }
  815.  
  816.     protected function jsChoiceInternal($ctrl{
  817.  
  818.         $this->jsContent .="c = new jFormsControlChoice('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  819.  
  820.         $this->commonJs($ctrl);
  821.     }
  822.  
  823.     protected function outputHelp($ctrl{
  824.         if ($ctrl->help{
  825.             if($ctrl->type == 'checkboxes' || ($ctrl->type == 'listbox' && $ctrl->multiple)){
  826.                 $name=$ctrl->ref.'[]';
  827.             }else{
  828.                 $name=$ctrl->ref;
  829.             }
  830.             echo '<span class="jforms-help"><a href="javascript:jForms.showHelp(\''$this->_name.'\',\''.$name.'\')">?</a></span>';
  831.         }
  832.     }
  833. }

Documentation generated on Thu, 22 Mar 2012 22:13:42 +0100 by phpDocumentor 1.4.3