Esempio n. 1
0
 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'] . '&amp;action=create&amp;cat_id=' . $this->catId . '&amp;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'] . '&amp;action=edit&amp;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);
 }
 public function getListado()
 {
     // ADD CLASS TO SUPERCONTAINER FOR SORT
     $sortCls = '';
     if ($this->canSort) {
         $sortCls = 'sortListados';
     }
     $this->tableImg = $this->tableImg ? $this->tableImg : $this->table;
     // SUPERCONTAINER
     $out[] = '<div class="' . $sortCls . ' ' . $this->superContainerCls . '">';
     // LISTADOTABLA
     $out[] = '<div id="listadoTabla" class="' . $this->table . '"></div>';
     // ITERATE ITEMS
     foreach ($this->contents as $row) {
         // CANTIDAD ITEMS O SUBCATEGORIAS EN ESTE BLOQUE
         if ($this->countItems) {
             $cantidad = a("SELECT COUNT(" . $this->whereCountItems . ") AS cantidad FROM " . $this->tableCountItems . " WHERE " . $this->whereCountItems . " = '" . $row[$this->campo] . "'");
         }
         // ITEM
         $out[] = '<div id="listItem_' . $row['id'] . '" class="itemListado">';
         // DATA TITLES
         $out[] = '<div class="dataTitlesContainer">';
         // ITERA CAMPOS
         if ($this->campos) {
             $this->camposArray = explode(',', $this->campos);
             foreach ($this->camposArray as $c) {
                 if ($row[$c]) {
                     $out[] = '<div class="itemList line_' . $c . '">';
                     // ROW TITLE
                     $out[] = '<div class="rowTitle">' . lang($c) . '</div>';
                     // VALUE FOR FIELD DATE
                     if (stristr($c, 'date')) {
                         $out[] = '<div class="rowValue">' . date($this->config['dateFormat'], strtotime($row[$c])) . '</div>';
                     } else {
                         $out[] = '<div class="rowValue">' . lang(strip_tags(fop($row[$c])), true) . '</div>';
                     }
                     $out[] = '</div>';
                 }
             }
             // CONTEO DE ITEMS
             if ($this->countItems) {
                 $out[] = '<div class="itemList line_count">';
                 $out[] = '<div class="rowTitle">' . lang('cantidad') . '</div>';
                 $catId = false;
                 if (isset($_GET['cat_id'])) {
                     $catId = sprintf("%d", $_GET['cat_id']);
                 }
                 if (!$catId && $row[$this->campo]) {
                     $q = 'cat_id=' . $row['id'];
                 }
                 if ($catId && $row[$this->campo]) {
                     $q = 'cat_id=' . $catId . '&amp;subcat_id=' . $row['id'];
                 }
                 $this->nameCountItems = $this->nameCountItems ? $this->nameCountItems : $this->tableCountItems;
                 $out[] = '<div class="rowValue">';
                 $out[] = '<a href="?m=' . $_GET['m'] . '&amp;action=list&amp;' . $q . '">' . lang($this->nameCountItems) . ': ' . $cantidad['cantidad'] . '</a>';
                 $out[] = '</div>';
                 $out[] = '</div>';
             }
             // ACTIONS
             if ($this->canEdit || $this->canDelete || $this->linkToFront || $this->canSort) {
                 $out[] = '<div class="itemList line_actions">';
                 $out[] = '<div class="rowTitle">' . lang('acciones') . '</div>';
                 $catId = false;
                 if (isset($_GET['cat_id'])) {
                     $catId = sprintf("%d", $_GET['cat_id']);
                 }
                 $subcatId = false;
                 if (isset($_GET['subcat_id'])) {
                     $subcatId = sprintf("%d", $_GET['subcat_id']);
                 }
                 $q = '';
                 if ($catId && !$subcatId) {
                     $q = '&amp;cat_id=' . $catId;
                 }
                 if ($catId && $subcatId) {
                     $q = '&amp;cat_id=' . $catId . '&amp;subcat_id=' . $subcatId;
                 }
                 $out[] = '<div class="rowValue">';
                 // EDIT
                 if ($this->canEdit) {
                     $out[] = '<a href="?m=' . $_GET['m'] . '&amp;action=edit' . $q . '&amp;id=' . $row['id'] . '" rel="' . lang('editar') . ' ' . lang($this->itemText) . '" title="' . lang('editar') . ' ' . lang($this->itemText) . '">';
                     $out[] = '<img alt="' . lang('editar') . ' ' . lang($this->itemText) . '" title="' . lang('editar') . ' ' . lang($this->itemText) . '" src="' . ICONSPATH . 'pencil.png"/>';
                     $out[] = '</a>';
                 }
                 // DELETE
                 if ($this->canDelete) {
                     $out[] = '<a style="cursor: pointer;" onclick="borrar(\'' . $row['id'] . '\',\'' . $this->table . '\',\'delete_item\',0,0)" rel="' . lang('borrar') . ' ' . lang($this->itemText) . '" title="' . lang('borrar') . ' ' . lang($this->itemText) . '">';
                     $out[] = '<img alt="' . lang('borrar') . ' ' . lang($this->itemText) . '" title="' . lang('borrar') . ' ' . lang($this->itemText) . '" src="' . ICONSPATH . 'delete.png"/>';
                     $out[] = '</a>';
                 }
                 // SORT
                 if ($this->canSort) {
                     $out[] = '<a rel="' . lang('ordenar') . '" title="' . lang('ordenar') . '">';
                     $out[] = '<img alt="' . lang('ordenar') . '" title="' . lang('ordenar') . '" src="' . ICONSPATH . 'move.png"/>';
                     $out[] = '</a>';
                 }
                 // VER
                 if ($this->linkToFront) {
                     $out[] = '<a href="' . ROOT . $this->linkToFront . '?id=' . $row['id'] . '" rel="' . lang('ver') . ' ' . lang($this->itemText) . '" title="' . lang('ver') . ' ' . lang($this->itemText) . '" target="_blank">';
                     $out[] = '<img alt="' . lang('ver') . ' ' . lang($this->itemText) . '" title="' . lang('ver') . ' ' . lang($this->itemText) . '" src="' . ICONSPATH . 'eye.png"/>';
                     $out[] = '</a>';
                 }
                 $out[] = '</div>';
                 $out[] = '</div>';
             }
             // MEDIA
             if ($this->showImg) {
                 $ShowMedia = new ShowMedia();
                 $ShowMedia->itemId = $row['id'];
                 $ShowMedia->type = $this->mediaType;
                 $ShowMedia->table = $this->tableImg;
                 $ShowMedia->useColoursCloud = false;
                 foreach ($this->showMediaCfg as $paramK => $paramV) {
                     $ShowMedia->{$paramK} = $paramV;
                 }
                 if ($ShowMedia->getMediaOut()) {
                     $out[] = '<div class="itemList line_media">';
                     $out[] = '<div class="rowTitle">' . lang('media') . '</div>';
                     $out[] = '<div class="rowValue">';
                     $out[] = '<div class="imagesContainer">';
                     $out[] = $ShowMedia->getMediaOut();
                     $out[] = '</div>';
                     $out[] = '<div style="clear: both;"></div>';
                     $out[] = '</div>';
                     $out[] = '</div>';
                 }
             }
         }
         $out[] = '</div>';
         $out[] = '<div style="clear: both;"></div>';
         $out[] = '</div>';
         $out[] = '<div style="clear: both;"></div>';
     }
     $out[] = '</div>';
     return join("\n", $out);
 }