formulario = '
$extra) { $this->formulario .= $indice . '="' . $extra . '"'; } } $this->formulario .= ' >'; } $this->sinFormulario = $sinFormulario; $this->context = Context::getContext(); $this->_path = $modulePath; $this->_modulePath = $pathToModule; $this->ajax = $ajax; if (!$this->ajax) { if (version_compare(_PS_VERSION_, '1.6.0.0 ', '>=')) { $this->addCSS('forms.css'); } else { $this->addCSS('forms.15.css'); } $this->addJS('forms.js'); } $this->idLang = Configuration::getGlobalValue('PS_LANG_DEFAULT'); $this->idShop = Configuration::getGlobalValue('PS_SHOP_DEFAULT'); $this->modulo = $modulo; } /** * Agrega html al formulario. * @param string $html * @return $this */ public function addToForm($html) { $this->formulario .= $html; return $this; } /** * Devuelve el html del formulario. * @param boolean $vaciarFormulario Si es true se vacia el form despues de devolver el html. * @return string */ public function renderForm($vaciarFormulario = false) { if (!$this->sinFormulario) { $this->formulario .= '
'; } $formulario = $this->formulario; if ($vaciarFormulario) { $this->formulario = ''; } return $formulario; } /** * Crea un elemento informativo * @param string $text Texto a mostrar * @param string $class Clase del elemento (warning (defecto), confirm) * @return $this */ function createFormInfomationText($text, $class = 'warning') { switch ($class) { case 'warning': $class = ' warning warn alert alert-warning '; break; case 'confirm': $class = ' module_confirmation conf confirm alert alert-success '; break; default: break; } $html = ''; $html .= '
'; $html .= '
'; $html .= '

'; $html .= $text; $html .= '

'; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param string $title * @param array $checks * @param array $selectedValue * @return $this */ public function createFormCheckboxGroupList($name, $text, $title, $checks, $selectedValue = array(), $extras = array()) { $html = ''; $html .= '
addExtras($extras); $html .= '>'; $html .= ''; $html .= '
'; foreach ($checks as $check) { $marcado = ($selectedValue !== false && in_array($check['value'], $selectedValue) ? 'checked="checked"' : ''); $html .= '
'; $html .= ' ' . $check['text']; $html .= '
'; } $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * Crea un checkbox. * @param string $name Nombre del checkbox * @param string $text Texto informativo * @param boolean $checked Marcado(true) o no(false), por defecto false * @param string $title Titulo * @param string $value El valor del checkbox. * @return $this */ function createFormCheckboxGroup($name, $text, $checked = false, $title = '', $value = 1) { $marcado = ''; if ($checked == true) { $marcado = ' checked="checked"'; } $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param array $datos * @param string $text * @param array $extras * @return $this */ function createFormRadioButtonGroup($datos, $text, $extras = false) { $html = ''; $html .= '
'; $html .= ''; $html .= '
'; foreach ($datos AS $indice => $dato) { $checked = ''; if (isset($dato['checked']) && $dato['checked'] == 1) { $checked = ' checked="checked"'; } $html .= '
'; $html .= ''; $html .= '
'; } $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $contenido * @param string $text * @param string $title * @param boolean $multiLang * @param boolean $wysiwyg * @return $this */ public function generarTextArea($name, $contenido, $text, $title = '', $multiLang = 0, $wysiwyg = 1, $array=false) { $html = ''; $html .= '
'; $html .= ''; if ($multiLang) { $idiomas = $this->getLanguages(); $idiomasSelect = $idiomas; foreach ($idiomas AS $language) { $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; } $html .= '
'; if ($wysiwyg) { $html .= ''; } if($multiLang) { $html .= ''; } $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $value * @param string $text * @param string $title * @param boolean $multiLang * @param boolean $password * @param array $extras * @param boolean $autofocus * @return $this */ function createFormTextGroup($name, $value, $text, $title = '', $multiLang = 0, $password = 0, $extras = false, $autofocus = false) { $tipo = 'text'; if ($password == 1) { $tipo = 'password'; } $html = '
'; $html .= ''; if ($multiLang) { $idiomas = $this->getLanguages(); $idiomasSelect = $idiomas; foreach ($idiomas AS $language) { $html .= '
'; $html .= '
'; $html .= ""; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' '; $html .= '
'; $html .= '
'; } } else { $html .= '
'; $html .= ' $extra) { $html.= ' ' . $indice . '="' . $extra . '"'; } } if ($autofocus) { $html .= ' autofocus '; } $html .= '>'; $html .= '
'; } $html .= '
'; $html .= ''; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param string $title * @param array $extras * @return $this */ function createFormDate($name, $text, $title = '', $extras = false) { $tipo = 'text'; $html = '
'; $html .= ''; $html .= '
'; $html .= ' $extra) { $html.= ' ' . $indice . '="' . $extra . '"'; } } $html .= '>'; $html .= '
'; $html .= '
'; $html .= ''; $this->formulario .= $html; return $this; } /** * Permite crear un elemento de tipo color picker * @param string $name * @param string $value * @param string $text * @param string $title * @param array $extras * @param boolean $autofocus */ function createFormColorPicker($name, $value, $text, $title = '', $extras = false, $autofocus = false) { $html = '
'; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; $html .= ' $extra) { if ($indice == 'class') { $class .= ' ' . $extra; } else { $html.= ' ' . $indice . '="' . $extra . '"'; } } } $html .= ' class="color mColorPickerInput'; if ($class) { $html .= ' ' . $class . '"'; } else { $html .= '"'; } if ($autofocus) { $html .= ' autofocus '; } $html .= '>'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $this->formulario .= $html; } /** * * @param string $name * @param string $value * @param string $text * @param string $title * @param string $outputDelimiter * @param string $paceholder * @param array $options * @return $this */ function createFormTagTextGroup($name, $value, $text, $title = '', $outputDelimiter = ',', $paceholder = 'Añadir etiqueta', $options = array()) { $html = ''; $this->addJS('jquery.tagify.js'); $html .= '
'; $html .= ''; $html .= '
'; $html .= ' $valor) { if ($indice == 'class') { $valor .= ' tagify'; } $html .= $indice . '="' . $valor . '"'; } } $html .= '>'; $html .= '
'; $html .= '
'; $html .= ''; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param int $min * @param int $max * @param int $step * @param string $title * @return $this */ function createFormSelectNumerico($name, $text, $defaultValue, $min, $max, $step = 1, $title = '') { $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } function createHidden($name, $value) { $html = ''; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param array $extras * @return $this */ function createSubmitButton($name, $text, $extras = false) { $html = ''; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param array $extras * @param string $type * @param string $icon * @return $this */ public function createButton($name, $text, $extras = false, $type = 'button', $icon = 'plus') { $html = ''; $this->formulario .= $html; return $this; } /** * Crea un select. * @param string $name * @param array $text * @param string $datos valor => visible * @param string $defaultValue * @param string $title * @param array $extras * @return $this */ function createFormSelect($name, $text, $datos, $defaultValue, $title = '', $extras = null) { $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $label * @param string $title * @param string $url * @return $this */ public function createFormFileButton($name, $label, $title, $url) { $this->addJS('spin.js'); $this->addJS('ladda.js'); $this->addJS('jquery.iframe-transport.js'); $this->addJS('jquery.fileupload.js'); $this->addJS('jquery.fileupload-process.js'); $this->addJS('jquery.fileupload-validate.js'); //$this->addJS('jquery.fileupload-image.js'); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= '
'; $html .= "'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param mixed $defaultValue * @param string $title * @return $this */ public function generarSelectIdioma($name, $text, $defaultValue, $title) { $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; reset($idiomas); $html .= ''; $html .= ''; $this->formulario .= $html; return $this; } private function addCSS($css) { $tab = Tools::getValue('tab', 0); if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { if ($this->context->controller instanceof stdClass) { $this->context->controller = new AdminModulesController(); } if ($this->_modulePath) { $this->context->controller->addCss($this->_modulePath . '/forms/' . $css, 'all'); } else { $this->context->controller->addCss($this->_path . '/forms/' . $css, 'all'); } } return; } private function addJS($js) { $tab = Tools::getValue('tab', 0); if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { if ($this->context->controller instanceof stdClass) { $this->context->controller = new AdminModulesController(); } if ($this->_modulePath) { $this->context->controller->addJs($this->_modulePath . '/forms/' . $js); } else { $this->context->controller->addJs($this->_path . '/forms/' . $js); } } return; } public function getLanguages() { $languages = Language::getLanguages(); return $languages; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @return $this */ public function createSelectSupplier($name, $text, $defaultValue, $title = '') { $suppliers = Supplier::getSuppliers(); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @return $this */ public function createSelectManufacturer($name, $text, $defaultValue, $title = '') { $manufacturers = Manufacturer::getManufacturers(); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param int $id_lang * @param string $name * @param string $text * @param array $value * @param string $title * @return $this */ public function createSelectGroups($id_lang, $name, $text, $value, $title = '') { $groups = Group::getGroups($id_lang); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; foreach ($groups as $group) { $marcado = ''; foreach ($value as $v) { if ($group['id_group'] == $v) { $marcado = ' checked '; break; } } $html .= ' ' . $group['name'] . '
'; } $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param int $id_lang * @param string $name * @param string $text * @param array $value * @param string $title * @param boolean $referencia * @return $this */ public function createCheckBoxCarriers($id_lang, $name, $text, $value, $title = '', $referencia = false) { $carriers = Carrier::getCarriers($id_lang); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; foreach ($carriers as $carrier) { $idCarrier = $carrier['id_carrier']; if ($referencia) { $idCarrier = $carrier['id_reference']; } $marcado = ''; foreach ($value as $v) { if ($idCarrier == $v) { $marcado = ' checked '; break; } } $html .= ' ' . $carrier['name'] . '
'; } $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param int $id_lang * @param string $name * @param string $text * @param array $idDefault * @param string $title * @param boolean $referencia * @return $this */ public function createSelectCarriers($id_lang, $name, $text, $idDefault, $title = '', $referencia = false) { $carriers = Carrier::getCarriers($id_lang); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= ''; foreach ($images AS $image) { $selected = ''; if ($image['id_image_type'] == $defaultValue) { $selected = ' selected="selected"'; } $html .= ''; } $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } public function mostrarCategorias($name, $prefijo, $idParentCategoria = 2) { $sql = ' SELECT ' . ' c.id_category, c.id_parent, cl.name, s.id_category AS checked, s.margen ' . ' FROM ' . ' ' . _DB_PREFIX_ . 'category AS c ' . ' INNER JOIN ' . _DB_PREFIX_ . 'category_lang AS cl ' . ' ON ' . ' cl.id_category = c.id_category ' . ' AND cl.id_lang = ' . $this->idLang . '' . ' AND c.id_shop_default = cl.id_shop ' . ' AND c.id_shop_default = ' . $this->idShop . '' . ' LEFT JOIN ' . _DB_PREFIX_ . $prefijo . 'categorias AS s ' . ' ON s.id_category = c.id_category ' . ' WHERE ' . ' c.id_parent = ' . $idParentCategoria . ' ' . ' ORDER BY ' . ' c.id_parent, c.id_category '; $categorias = Db::getInstance()->executeS($sql); $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($categorias AS $categoria) { $num = 0; $html .= ''; $html .= ''; $checked = ""; $porcentaje = ""; if (!empty($categoria['checked'])) { $checked = ' checked="checked"'; $porcentaje = $categoria['margen']; } $html .= ''; $html .= ''; $html .= ''; $this->getHijosTable($categoria, $html, $num, $prefijo); } $html .= '
 ' . $this->modulo->l('Margen general') . ' 
' . $this->modulo->l('Categoria') . '' . $this->modulo->l('Marcar para Exportar') . '' . $this->modulo->l('Margen') . '
' . $categoria['name'] . '
'; $html .= ''; $html .= ''; $this->formulario .= $html; return $this; } private function getHijosTable($categoria, &$html, &$num, $prefijo) { $numInterno = $num; $sqlHijos = ' SELECT ' . ' c.id_category, c.id_parent, cl.name, s.id_category AS checked, s.margen ' . ' FROM ' . ' ' . _DB_PREFIX_ . 'category AS c ' . ' INNER JOIN ' . _DB_PREFIX_ . 'category_lang AS cl ' . ' ON ' . ' cl.id_category = c.id_category ' . ' AND cl.id_lang = ' . $this->idLang . ' ' . ' AND c.id_shop_default = cl.id_shop ' . ' AND c.id_shop_default = ' . $this->idShop . ' ' . ' LEFT JOIN ' . _DB_PREFIX_ . $prefijo . 'categorias AS s ' . ' ON s.id_category = c.id_category ' . ' WHERE ' . ' c.id_parent=' . $categoria['id_category']; $categoriasHijos = Db::getInstance()->executeS($sqlHijos); $num++; foreach ($categoriasHijos AS $categoriaHijo) { $checked = ""; $porcentaje = ""; if (!empty($categoriaHijo['checked']) && $categoriaHijo['checked'] != null) { $checked = ' checked="checked"'; $porcentaje = $categoriaHijo['margen']; } $numClase = $num; $html .= ''; $html .= '' . str_repeat(" ", $num * 2) . $categoriaHijo['name'] . ''; $html .= ''; $html .= ''; $html .= ''; $this->getHijos($categoriaHijo, $html, $num); } $num = $numInterno; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @param boolean $active * @param boolean $chosen * @return $this */ public function createSelectCategory($name, $text, $defaultValue, $title = '', $active = true, $chosen = false) { $categories = Category::getHomeCategories($this->idLang, $active); $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; if ($chosen) { $html .= ''; } $this->formulario .= $html; return $this; } private function getHijos($id_parent, $defaultValue, &$html, &$num, $active) { $numInterno = $num; $categories = Category::getChildren($id_parent, $this->idLang, $active); if (!$categories) { return; } $num++; foreach ($categories AS $category) { $selected = ''; if ($category['id_category'] == $defaultValue) { $selected = ' selected="selected"'; } $html .= ''; $this->getHijos($category['id_category'], $defaultValue, $html, $num, $active); } $num = $numInterno; return true; } /** * Crea un upload File. * @param string $name Nombre del boton * @param string $text Texto informativo * @param string $title Titulo * @return $this */ public function createFormUploadFile($name, $text, $title = '') { $html = ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * Crea una tabla dinamica. * @param string $name Identificador de la tabla. * @param string $table Nombre de la tabla en la base de datos. * @param string[] $campos Nombres de los campos en base de datos. * @param string[] $camposBusqueda Nombres de los campos en base de datos para las busquedas. * @param string $url Ruta base. * @param string $serverfile Archivo de destino en el servidor. * @param string $contenidoCabecera Los "tr" para la cabecera. * @param string[] $codigoFormateadores [id del formateador => Contenido de la funcion formateadora, recibe los parametros column y row]. * @param string $codigoEventoLoad Contenido de la funcion del evento load. La tabla viene en la variable grid. Tambien se dispone de e. * @return $this */ function createTableAjax($name, $table, $campos, $camposBusqueda, $url, $serverfile, $contenidoCabecera, $codigoFormateadores = array(), $codigoEventoLoad = '') { $html = '
'; $html .= '' . '' . ' ' . $contenidoCabecera . '
'; $campos = urlencode(serialize($campos)); $camposBusqueda = urlencode(serialize($camposBusqueda)); $table = urlencode(trim($table)); $codigoFormateadoresString = ''; foreach ($codigoFormateadores as $idFormateador => $codigoFormateador) { $codigoFormateadoresString .= <<'; $html .= << $(function() { var grid = $("#$name").bootgrid( { ajax:true, post: function() { return { id: "b0df282a-0d67-40e5-8558-c9e93b7befed" }; }, url: "{$url}bootgrid/php/$serverfile?tabla=$table&campos=$campos&camposBusqueda=$camposBusqueda", formatters: { $codigoFormateadoresString } }).on("loaded.rs.jquery.bootgrid", function(e) { $codigoEventoLoad }); }); EOT; $html .= '
'; $this->formulario .= $html; return $this; } private function addExtras($extras) { $html = ''; if ($extras && is_array($extras)) { foreach ($extras AS $indice => $valor) { $html .= $indice . '="' . $valor . '"'; } } return $html; } public function __toString() { return $this->renderForm(true); } public function createCheckBoxManufacturer($name, $defaultValue) { $manufacturers = Manufacturer::getManufacturers(); $html = ''; $numElementos = count($manufacturers); $elementos = ceil($numElementos / 3); $intercambio = array_flip($defaultValue); $i = 0; $html .= '
'; $html .= '
'; foreach ($manufacturers as $m) { $checked = ''; if ($i == 0) { $html .= '
    '; } $html .= '
  • '; $html .= ''; $html .= '
    '; if (array_key_exists($m['id_manufacturer'], $intercambio)) { $checked = "checked='checked'"; } $html .= ''; $html .= '
  • '; $i++; if ($i >= $elementos) { $html .= '
'; $i = 0; } } $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param int $id_lang * @param string $name * @param string $text * @param array $values * @param string $title * @return $this */ public function createOptionStatuses($id_lang, $name, $text, $values, $title = '') { $status = OrderState::getOrderStates($id_lang); $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @return $this */ public function createSelectStatuses($idLang, $name, $text, $defaultValue, $title = '') { $status = OrderState::getOrderStates($idLang); $html = '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @return $this */ public function createSelectFeatures($idLang, $name, $text, $defaultValue, $title = '') { $features = Feature::getFeatures($idLang); $html = '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * * @param string $name * @param string $text * @param int $defaultValue * @param string $title * @return $this */ public function createSelectFeaturesValues($idLang, $name, $text, $defaultValue, $value, $title = '') { $features = FeatureValueCore::getFeatureValuesWithLang($idLang, $value); $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $this->formulario .= $html; return $this; } /** * Genera un select a partir de un array asociativo. * @param string $name * @param string $text * @param array $datos * @param string $claveId * @param string $claveValores * @param mixed $selectedValue * @param string $title * @param array $extras * @return $this */ public function createFormSelectFromArray($name, $text, $datos, $claveId, $claveValores, $selectedValue, $title = '', $extras = null) { $datosFormateados = array(); foreach ($datos as $dato) { $datosFormateados[$dato[$claveId]] = $dato[$claveValores]; } return $this->createFormSelect($name, $text, $datosFormateados, $selectedValue, $title, $extras); } }