コード例 #1
0
 /**
  * 	Contruct a HTML From for a fields
  *
  * 	@param	array	$aRow		parameter of the field
  * 	@param	string	$key		Name of the field
  * 	@param	string	$cssClass	CSS Classe for the form
  * 	@return	string
  */
 public function form($aRow, $key, $cssClass)
 {
     global $langs, $conf;
     $form = new Form($this->db);
     $rtr = "";
     if ($aRow->enable) {
         $rtr .= '<div class="formRow elVal">' . "\n";
         $label = $langs->transcountry($key, $this->Country);
         if (!$label) {
             $label = $langs->trans($key);
         }
         $rtr .= '<label for="' . $key . '">' . $label . '</label>' . "\n";
         switch ($aRow->type) {
             case "textarea":
                 $rtr .= '<textarea maxlength="' . $aRow->length . '" class="' . $cssClass . '" id="' . $key . '" name="' . $key . '" cols="1" rows="4">' . $this->{$key} . '</textarea>';
                 $rtr .= '<script> $(document).ready(function() { $("#' . $key . '").counter({ goal: 120 });});	</script>';
                 break;
             case "select":
                 if ($cssClass == "small") {
                     $style = "width:200px;";
                 } else {
                     $style = "width:400px;";
                 }
                 $rtr .= '<select data-placeholder="' . $langs->trans($key) . '&hellip;" class="chzn-select expand" style="' . $style . '" id="' . $key . '" name="' . $key . '" >';
                 if (isset($aRow->dict)) {
                     require_once DOL_DOCUMENT_ROOT . "/admin/class/dict.class.php";
                     // load from dictionnary
                     try {
                         $dict = new Dict($this->db);
                         $values = $dict->load($aRow->dict, true);
                         //filter for country
                         foreach ($values->values as $idx => $row) {
                             if (empty($row->pays_code) || $this->Country == $row->pays_code) {
                                 $aRow->values[$idx] = $row;
                             }
                         }
                     } catch (Exception $e) {
                         dol_print_error('', $e->getMessage());
                     }
                 }
                 if (empty($this->{$key})) {
                     $this->{$key} = $aRow->default;
                 }
                 foreach ($aRow->values as $idx => $row) {
                     if ($row->enable) {
                         $rtr .= '<option value="' . $idx . '"';
                         if ($this->{$key} == $idx) {
                             $rtr .= ' selected="selected"';
                         }
                         $rtr .= '>';
                         if (isset($row->label)) {
                             $rtr .= $langs->trans($row->label);
                         } else {
                             $rtr .= $langs->trans($idx);
                         }
                         $rtr .= '</option>';
                     }
                 }
                 $rtr .= '</select>';
                 break;
             case "checkbox":
                 if (isset($this->{$key})) {
                     $value = $this->{$key};
                 } else {
                     $value = $aRow->default;
                 }
                 if ($value) {
                     $rtr .= '<input type="checkbox" id="' . $key . '" name="' . $key . '" checked="checked"/>';
                 } else {
                     $rtr .= '<input type="checkbox" id="' . $key . '" name="' . $key . '" />';
                 }
                 break;
             case "uploadfile":
                 $rtr .= '<input type="file" class="flat" name="' . $key . '" id="' . $key . '">';
                 break;
             default:
                 if (isset($aRow->mask)) {
                     $rtr .= '<input type="text" maxlength="' . $aRow->length . '" id="' . $key . '" name="' . $key . '" value="' . $this->{$key} . '" class="input-text ' . $aRow->css . " " . $cssClass . '" mask="' . $key . '"/>' . "\n";
                 } else {
                     $rtr .= '<input type="text" maxlength="' . $aRow->length . '" id="' . $key . '" name="' . $key . '" value="' . $this->{$key} . '" class="input-text ' . $aRow->css . " " . $cssClass . '"/>' . "\n";
                 }
         }
         $rtr .= '</div>' . "\n";
     }
     return $rtr;
 }