public function getForm() { // VALUES FOR CREATE if (!$this->id) { if (isset($this->moduleCfg['lists']['categories'])) { $this->catId = $_GET['cat_id']; $this->values[$this->moduleCfg['lists']['items']['query']['campoCat']] = $this->catId; } if (isset($this->moduleCfg['lists']['subCategories'])) { $this->subcatId = $_GET['subcat_id']; $this->values[$this->moduleCfg['lists']['items']['query']['campoSubCat']] = $this->subcatId; } $this->mode = 'insert'; } // VALUES FOR UPDATE if ($this->id) { $this->values = a("SELECT * " . $this->moduleCfg['lists']['items']['query']['selectItem'] . " FROM " . $this->moduleCfg['general']['table'] . " WHERE id=" . $this->id); if (isset($this->moduleCfg['lists']['categories'])) { $this->catId = $this->values[$this->moduleCfg['lists']['items']['query']['campoCat']]; } if (isset($this->moduleCfg['lists']['subCategories'])) { $this->subcatId = $this->values[$this->moduleCfg['lists']['items']['query']['campoSubCat']]; } $this->mode = 'update'; } // IF FORM VALID AND POST SUBMITED PROCESS if ($this->formIsValid($this->moduleCfg['form']['fields']) && isset($_POST['submitted']) && $_POST['submitted'] == 1) { // SQL INSERT (NUEVO) if ($this->mode == 'insert') { if ($this->moduleCfg['general']['createTable'] && $this->config['createModuleTables']) { $createTable = makeCreateTableQuery($this->moduleCfg['form']['fields'], $this->moduleCfg['general']['executeQuerys'], $this->moduleCfg['general']['table']); } $creado = makeInsertQuery($this->moduleCfg['form']['fields'], $this->moduleCfg['general']['executeQuerys'], $this->moduleCfg['general']['table']); $this->id = mysql_insert_id(); if (isset($_POST['tags'])) { add_tags($_POST['tags'], $this->id, $this->moduleCfg['general']['table'], $this->moduleCfg['general']['table'], $this->moduleCfg['general']['table']); } } // SQL UPDATE (EDIT) if ($this->mode == 'update') { $editado = makeUpdateQuery($this->moduleCfg['form']['fields'], $this->id, $this->moduleCfg['general']['executeQuerys'], $this->moduleCfg['general']['table']); if (isset($_POST['tags'])) { add_tags($_POST['tags'], $this->id, $this->moduleCfg['general']['table'], $this->moduleCfg['general']['table'], $this->moduleCfg['general']['table']); } } // UPLOAD if (isset($this->moduleCfg['form']['uploads'])) { foreach ($this->moduleCfg['form']['uploads'] as $k => $v) { if (is_array($v) && !empty($v)) { $upload = new Upload(); $upload->campo = $k; $upload->id = $this->id; $upload->tabla = $this->moduleCfg['general']['table']; $upload->cat_id = $this->catId; $upload->subcat_id = $this->subcatId; $upload->titulo = $_POST[$this->moduleCfg['form']['uploads']['defaultUploadTitleField']]; foreach ($v as $paramK => $paramV) { $upload->{$paramK} = $paramV; } if (isset($this->moduleCfg['form']['uploads']['removeFilesBeforeUpload'])) { $upload->removeFilesBeforeUpload = $this->moduleCfg['form']['uploads']['removeFilesBeforeUpload']; } $upload->doUpload(); } } } // REDIRECT TO LIST if ($this->moduleCfg['form']['general']['redirectToList']) { $cat = 0; $subcat = 0; if (isset($this->moduleCfg['lists']['categories']['whereCountItems'])) { if (isset($_POST[$this->moduleCfg['lists']['categories']['whereCountItems']])) { $cat = $_POST[$this->moduleCfg['lists']['categories']['whereCountItems']]; } } if (isset($this->moduleCfg['lists']['subCategories']['whereCountItems'])) { if (isset($_POST[$this->moduleCfg['lists']['subCategories']['whereCountItems']])) { $subcat = $_POST[$this->moduleCfg['lists']['subCategories']['whereCountItems']]; } } if ($this->mode == 'insert' || $this->mode == 'update') { header('Location: ?m=' . $_GET['m'] . '&action=list&cat_id=' . $cat . '&subcat_id=' . $subcat); } } else { // REDIRECCION NUEVO if ($this->mode == 'insert') { header('Location: ?m=' . $_GET['m'] . '&action=edit&id=' . $this->id . '&created=' . $creado); } // REDIRECCION EDIT if ($this->mode == 'update') { header('Location: ?m=' . $_GET['m'] . '&action=edit&id=' . $this->id . '&edited=' . $editado); } } } $out[] = $this->mainBlocks->getHead(); $out[] = $this->mainBlocks->getMenu(); // RIGHT $wCls = isset($this->moduleCfg['form']['uploads']) ? '' : ''; // forceWidthTo40 $out[] = ' <div id="right" class="right_' . $this->moduleCfg['general']['table'] . ' ' . $wCls . '"> '; // rightPadding $out[] = ' <div class="rightPadding"> '; // BREAD $bread = new Bread(); $bread->catId = $this->catId; if (isset($this->moduleCfg['lists']['categories'])) { $bread->categories = $this->moduleCfg['lists']['categories']; } $bread->subcatId = $this->subcatId; if (isset($this->moduleCfg['lists']['subcategories'])) { $bread->subcategories = $this->moduleCfg['lists']['subcategories']; } $bread->showAll = $this->showAll; $out[] = $bread->getBread(); // ERRORS TBAR IF SUBMIT AND ERRORS FOUND $out[] = $this->getErrorsTbar(); // IF CREADO O EDITADO $out[] = $this->getStatusTbar(); // CREAR FORM if ($_GET['action'] == 'create') { $out[] = '<form action="?m=' . $_GET['m'] . '&action=create&cat_id=' . $this->catId . '&subcat_id=' . $this->subcatId . '" method="post" enctype="multipart/form-data" name="formulario" id="formulario">'; } // EDITAR FORM if ($_GET['action'] == 'edit') { $out[] = '<form action="?m=' . $_GET['m'] . '&action=edit&id=' . $this->id . '" method="post" enctype="multipart/form-data" name="formulario" id="formulario">'; } // COL-1 || MAIN if (isset($this->moduleCfg['form']['uploads'])) { $out[] = '<div id="col-1">'; } else { $out[] = '<div id="main">'; } $out[] = '<div class="boxContainer">'; // HIDDEN SUBMIT FIELD $out[] = '<input type="hidden" name="submitted" value="1" />'; // INSTANCIA FORM INPUTS SEGUN CONFIG DEL MODULO foreach ($this->moduleCfg['form']['fields'] as $campo) { $formInput = new formInputs(); $formInput->tabla = $this->moduleCfg['general']['table']; if ($this->id) { $formInput->item_id = $this->id; if ($this->values[$campo['name']]) { $formInput->value = $this->values[$campo['name']]; } } foreach ($campo as $k => $v) { if (isset($this->values[$campo['name']])) { $formInput->value = $this->values[$campo['name']]; } if ($v || $v === false) { $formInput->{$k} = $v; } } $out[] = $formInput->getFormInput(); } // SUBMIT BTN if ($this->moduleCfg['form']['general']['canSave']) { $f = new formInputs(); $f->fieldLabel = 'Guardar'; $f->inputType = 'submit'; $f->name = 'submit'; $f->submitFormId = 'formulario'; $out[] = $f->getFormInput(); } $out[] = '</div>'; $out[] = '</div>'; // COL-2 if (isset($this->moduleCfg['form']['uploads'])) { $out[] = '<div id="col-2">'; foreach ($this->moduleCfg['form']['uploads'] as $k => $v) { if (is_array($v['showMedia']) && !empty($v['showMedia'])) { $out[] = '<div class="boxContainer">'; if ($this->id) { $ShowMedia = new ShowMedia(); $ShowMedia->itemId = $this->id; $ShowMedia->type = $k; $ShowMedia->table = $this->moduleCfg['general']['table']; foreach ($v['showMedia'] as $paramK => $paramV) { $ShowMedia->{$paramK} = $paramV; } } $formInput = new formInputs(); $formInput->fieldLabel = $v['uploadLabel'] ? $v['uploadLabel'] : lang('adjuntar ' . $k); $formInput->name = $k; $formInput->inputType = 'file'; $formInput->maxFiles = $v['maxFiles'] ? $v['maxFiles'] : 0; $formInput->acceptedExtencions = isset($v['acceptedExtencions']) ? $v['acceptedExtencions'] : array('jpg', 'gif', 'png'); if ($this->id) { $formInput->afterFieldHtml = $ShowMedia->getMediaOut(); $formInput->disabled = $ShowMedia->getCant() == $v['maxFiles'] ? true : false; } if ($v['showMedia']['fileFieldCfg']) { foreach ($v['showMedia']['fileFieldCfg'] as $paramY => $paramZ) { $formInput->{$paramY} = $paramZ; } } $formInput->tabla = $this->moduleCfg['general']['table']; $out[] = $formInput->getFormInput(); $out[] = '</div>'; } } $out[] = '</div>'; } $out[] = '</form>'; // EO rightPadding $out[] = ' </div> '; // EO RIGHT $out[] = ' </div> '; $out[] = $this->mainBlocks->getFooter(); return join("\n", $out); }
<?php require_once '_init.php'; /*foreach($_POST as $key=>$value) { echo $key." = ".$value; }*/ $id = $_POST['id']; $tags = isset($_POST['tags' . '_' . $id]); $from = $_POST['from']; $tipo = $_POST['mediatype']; $arrayCampos = array('titulo' . '_' . $id, 'texto' . '_' . $id, 'fuente' . '_' . $id, 'preview' . '_' . $id); if (makeUpdateQuery($arrayCampos, $id, true, 'files', true)) { $out[] = array('mode' => 'update media info', 'success' => 'true', 'arrayCampos' => $arrayCampos); } else { $out[] = array('mode' => 'update media info', 'success' => 'false', 'arrayCampos' => $arrayCampos); } if ($tags && add_tags($tags, $id, $from, 'files', $tipo)) { $out[] = array('mode' => 'add tags to media', 'success' => 'true', 'tags' => $tags); } echo json_encode($out);