static function forma($liga, $legend = false, $cols = false, $props = false, $completo = true, $vals = false) { if ($liga->numCol() > 0 || $cols) { echo $completo ? self::etiq_props($liga, 'form', $props) . self::etiq_props($liga, 'fieldset', $props) : ''; if ($legend && is_string($legend) && !empty($legend)) { echo self::etiq_props($liga, 'legend', $props); echo htmlentities($legend, ENT_NOQUOTES, 'UTF-8'); echo "</legend>\n"; } $cols = is_array($cols) && count($cols) > 0 ? $cols : (is_string($cols) ? array_map('trim', explode(',', $cols)) : array_keys($liga->meta())); $cols = self::todos($liga, $cols); if (count($cols) > 0) { foreach ($cols as $k => $v) { $col = is_string($k) ? trim($k) : trim($v); if (!$liga->p($col, 'ai')) { echo self::etiq_props($liga, 'div', $props); $label = is_string($k) && is_string($v) && $v != '' && strpos($v, '<') === false ? self::procesar($liga, $v) : self::mejorar($col); $pref = isset($props['prefid']) ? self::procesar($liga, $props['prefid']) : ''; if (strpos($label, '<label for') === false && $label != '') { $prop = isset($props["label[{$col}]"]) ? htmlentities(self::procesar($liga, self::array2props($props["label[{$col}]"])), ENT_NOQUOTES, 'UTF-8') : ''; $prop .= self::procesar($liga, self::prop_cond("label[{$col}]", $props)); $prop .= isset($props['label']) ? htmlentities(self::procesar($liga, self::array2props($props['label'])), ENT_NOQUOTES, 'UTF-8') : ''; $prop .= self::procesar($liga, self::prop_cond('label', $props)); $req = $liga->p($col, 'nulo') === false ? ' *' : ''; $label = "<label for=\"{$pref}{$col}\"{$prop}>{$label}{$req}</label> "; } echo $label; if (strpos($v, '<') !== false) { echo $v; } elseif ($liga->existe($col)) { $prop = isset($props["input[{$col}]"]) ? htmlentities(self::procesar($liga, self::array2props($props["input[{$col}]"])), ENT_NOQUOTES, 'UTF-8') : ''; $prop .= self::procesar($liga, self::prop_cond("input[{$col}]", $props)); $prop .= isset($props['input']) ? htmlentities(self::procesar($liga, self::array2props($props['input'])), ENT_NOQUOTES, 'UTF-8') : ''; $prop .= isset($props[$col]) ? htmlentities(self::procesar($liga, self::array2props($props[$col])), ENT_NOQUOTES, 'UTF-8') : ''; $prop .= self::procesar($liga, self::prop_cond('input', $props)); $max = $liga->p($col, 'max') ? ' maxlength="' . $liga->p($col, 'max') . '"' : ''; $com = $liga->p($col, 'com') ? ' title="' . $liga->p($col, 'com') . '"' : ''; if ($ref = $liga->p($col, 'referencia')) { $objRef = LIGA(substr($ref, 0, strpos($ref, '::'))); $colRef = substr($ref, strpos($ref, '::') + 2); $value = isset($vals[$col]) ? self::procesar($liga, $vals[$col]) : ''; $propRef = array('select' => "id='{$pref}{$col}' name='{$col}'{$com}{$prop}", 'option' => "value='@[{$colRef}]'", 'option@si("@[' . $colRef . ']"=="' . $value . '")' => 'selected="selected"'); echo self::selector($objRef, '1', $propRef); } elseif ($liga->p($col, 'blob')) { $value = isset($vals[$col]) ? self::procesar($liga, $vals[$col]) : ''; echo "<textarea id='{$pref}{$col}' name='{$col}'{$max}{$com}{$prop}>{$value}</textarea>"; } else { $value = isset($vals[$col]) ? ' value="' . self::procesar($liga, $vals[$col]) . '"' : ''; $fecha = strpos($liga->p($col, 'tipo'), 'date') === false ? '' : ' class="fecha"'; $fecha = strpos($liga->p($col, 'tipo'), 'stamp') === false ? $fecha : ' class="fecha"'; echo "<input id='{$pref}{$col}' name='{$col}'{$max}{$com}{$fecha}{$prop}{$value} />"; } } else { $value = isset($vals[$col]) ? ' value="' . self::procesar($liga, $vals[$col]) . '"' : ''; echo "<input id='{$pref}{$col}' name='{$col}'{$value} />"; } echo "</div>\n"; } } } echo '<div class="botones" style="clear:both">' . "\n"; echo isset($props['submit']) && is_string($props['submit']) ? $props['submit'] : '<input type="submit" value="Enviar" />'; echo isset($props['reset']) && is_string($props['reset']) ? $props['reset'] : '<input type="reset" value="Limpiar" />'; echo "</div>\n"; echo $completo ? "</fieldset>\n</form>\n" : ''; } else { echo '[LIGA] Parámetros incorrectos'; } }
<?php // Cargamos LIGA3 require_once 'LIGA3/LIGA.php'; // Personalizo una conexión a la base de datos (servidor, usuario, contraseña, schema) BD('localhost', 'root', '', 'base'); // Configuramos la entidad a usar $tabla = 'usuarios'; $liga = LIGA($tabla); // Controlador de acciones $resp = ''; if (isset($_GET['accion'])) { if ($_GET['accion'] == 'insertar') { $resp = $liga->insertar($_POST); } elseif ($_GET['accion'] == 'modificar') { $datos = array($_POST['cual'] => $_POST); $resp = $liga->modificar($datos); } } if (isset($_GET['borrar'])) { $resp = $liga->eliminar($_GET['borrar']); } // Si es una petición asíncrona sólo muestro la respuesta if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { echo $resp; exit(0); } // Imprimo las etiquetas HTML iniciales HTML::cabeceras(array('title' => 'Pruebas LIGA 3', 'description' => 'Página de pruebas para LIGA 3', 'css' => 'util/LIGA.css', 'style' => 'label { width:100px; }')); // Guardo el bufer para colocarlo en el layout ob_start();