예제 #1
0
 function salvar()
 {
     require_once ECOMP_PATH_CLASS . DS . 'ebasic.util.php';
     require_once ECOMP_PATH_CLASS . DS . 'wideimage' . DS . 'lib' . DS . 'WideImage.inc.php';
     $idcomponente = JRequest::getVar('idcomponente', 0);
     $post = $_POST;
     $dados = array('id' => $post['id'], 'published' => $post['published'], 'ordering' => $post['ordering']);
     foreach ($post['dados'] as $idcampo => $v) {
         // abre o campo
         $campo = new JCRUD(ECOMP_TABLE_CAMPOS, array('id' => $idcampo));
         $coluna = key($v);
         $valor = str_replace('$id', $post['id'], stripslashes($v[$coluna]));
         $dados[$coluna] = $valor;
         //data
         if ($campo->idtipo == 6) {
             $dados[$coluna] = eUtil::converteData($valor);
         }
     }
     // abre o componente
     $componente = new JCRUD(ECOMP_TABLE_COMPONENTES, array('id' => $idcomponente));
     // abre o cadastro
     $cadastro = new JCRUD(ECOMP_TABLE_COMPONENTES . "_{$componente->alias}", $dados);
     // apaga o relacionamento antigo com as tags e categorias
     JCRUD::query("DELETE FROM " . ECOMP_TABLE_CADASTROS_TAGS . " WHERE idcomponente = '{$idcomponente}' AND idcadastro = {$cadastro->id}");
     JCRUD::query("DELETE FROM " . ECOMP_TABLE_CADASTROS_CATEGORIAS . " WHERE idcomponente = '{$idcomponente}' AND idcadastro = {$cadastro->id}");
     //
     if ($cadastro->id) {
         $cadastro->update();
     } else {
         $cadastro->insert();
     }
     // cadastra as tags
     $tags = new JCRUD(ECOMP_TABLE_CADASTROS_TAGS);
     if (isset($post['tags'])) {
         foreach ($post['tags'] as $tag) {
             $tags->id = null;
             $tags->idcomponente = $idcomponente;
             $tags->idcadastro = $cadastro->id;
             $tags->idtag = $tag;
             $tags->insert();
         }
     }
     // cadastra as categorias
     $categorias = new JCRUD(ECOMP_TABLE_CADASTROS_CATEGORIAS);
     if (isset($post['categorias'])) {
         foreach ($post['categorias'] as $cat) {
             $categorias->id = null;
             $categorias->idcomponente = $idcomponente;
             $categorias->idcadastro = $cadastro->id;
             $categorias->idcategoria = $cat;
             $categorias->insert();
         }
     }
     ////////////////////////////////////////////////////
     // uploads
     ////////////////////////////////////////////////////
     $uploads = count($_FILES['dados']) ? $_FILES['dados'] : array();
     foreach ($uploads['name'] as $idcampo => $coluna) {
         $campo = new JCRUD(ECOMP_TABLE_CAMPOS, array('id' => $idcampo));
         $coluna = key($coluna);
         $tipo = new JCRUD(ECOMP_TABLE_TIPOS, array('id' => $campo->idtipo));
         parse_str($tipo->params, $params1);
         parse_str($campo->params, $params2);
         $params = array_merge($params1, $params2);
         //upload de imagem
         if ($campo->idtipo == 11 && $uploads['error'][$idcampo][$coluna] != 4) {
             $path_dest = ECOMP_PATH_UPLOADS . DS . $idcomponente . DS . $cadastro->id;
             $file = $uploads;
             $file_ext = strtolower(JFile::getExt($file['name'][$idcampo][$coluna]));
             $file_name = $coluna . '.' . $file_ext;
             $file_tmp = $file['tmp_name'][$idcampo][$coluna];
             $file_dest = $path_dest . DS . $file_name;
             if (strpos($params['ext'], $file_ext) !== false) {
                 // eLoad - Salva o caminho da pasta cache atual
                 if (file_exists($file_dest)) {
                     $cache_dir = ECOMP_PATH_CACHE_ELOAD . DS . substr(sha1_file($file_dest), 0, 10);
                 }
                 if (JFile::upload($file_tmp, $file_dest)) {
                     // eLoad - Apaga a pasta cache anterior
                     if (isset($cache_dir) && is_dir($cache_dir)) {
                         JFolder::delete($cache_dir);
                     }
                     // apaga o arquivo
                     if ($cadastro->{$coluna} != $file_name) {
                         @unlink($path_dest . DS . $cadastro->{$coluna});
                     }
                     if ($params['resize'] == 1) {
                         if ($file_ext != 'gif' || $file_ext == 'gif' && $params['resize_gif'] == 1) {
                             $imagem = wiImage::load($file_dest);
                             if ($imagem->getWidth() > $params['width'] || $imagem->getHeight() > $params['height']) {
                                 wiImage::load($file_dest)->resize($params['width'], $params['height'], $params['fit'], $params['scale'])->saveToFile($file_dest, null, 90);
                             }
                             // Cria imagem 800x600
                             //$file_800 = $path_dest.DS.$coluna.'800x600.'.$file_ext;
                             //ecompHelper::redimensionaImg($file_dest, $file_800, 800, 600, $params['fit'], $params['scale'], 90);
                             // Cria imagem 640x480
                             //$file_640 = $path_dest.DS.$coluna.'640x480.'.$file_ext;
                             //ecompHelper::redimensionaImg($file_dest, $file_640, 640, 480, $params['fit'], $params['scale'], 90);
                             // Cria imagem 320x240
                             //$file_320 = $path_dest.DS.$coluna.'320x240.'.$file_ext;
                             //ecompHelper::redimensionaImg($file_dest, $file_320, 320, 240, $params['fit'], $params['scale'], 90);
                         }
                     }
                     // altera o nome da imagem
                     $cadastro->{$coluna} = $file_name;
                 }
             }
         }
         //upload
         if ($campo->idtipo == 4 && $uploads['error'][$idcampo][$coluna] != 4) {
             $path_dest = ECOMP_PATH_UPLOADS . DS . $idcomponente . DS . $cadastro->id;
             $file = $uploads;
             $file_ext = strtolower(JFile::getExt($file['name'][$idcampo][$coluna]));
             $file_name = $coluna . '.' . $file_ext;
             $file_tmp = $file['tmp_name'][$idcampo][$coluna];
             $file_dest = $path_dest . DS . $file_name;
             // apaga o arquivo
             @unlink($path_dest . DS . $cadastro->{$coluna});
             if (JFile::upload($file_tmp, $file_dest)) {
                 // altera o nome da imagem
                 $cadastro->{$coluna} = $file_name;
             }
         }
         // salva os dados
         $cadastro->update();
     }
     return true;
 }
예제 #2
0
     $value = @$this->row->{$alias};
     echo $editor->display($name, $value, $params['width'], $params['height'], '60', '20', false, $params_editor);
 }
 // Upload
 if ($campo->idtipo == 4) {
     echo sprintf('<input type="file" name="%s" /> Tamanho máximo: %s', $name, ini_get('upload_max_filesize'));
 }
 // Boolean
 if ($campo->idtipo == 5) {
     $value = @$this->row->{$alias};
     echo sprintf('<input type="radio" name="%s" value="0" %s />Não<input type="radio" name="%s" value="1" %s />Sim', $name, !$value ? 'checked="checked"' : '', $name, $value ? 'checked="checked"' : '');
 }
 // Data
 if ($campo->idtipo == 6) {
     $date_scripts[] = "myCal{$campo->id} = new Calendar({ date{$campo->id}: 'd/m/Y' });\n";
     echo sprintf('<input class="text_area datas" type="text" name="%s" size="12" maxlength="10" value="%s" />', $name, eUtil::converteData(htmlspecialchars(@$this->row->{$alias})));
 }
 // Data / Hora
 if ($campo->idtipo == 7) {
     echo sprintf('<input class="text_area" type="text" name="%s" size="100" maxlength="100" value="%s" />', $name, htmlspecialchars(@$this->row->{$alias}));
 }
 // Relacionamento
 if ($campo->idtipo == 8) {
     $campo = new JCRUD(ECOMP_TABLE_CAMPOS, array('id' => $params['idcampo']));
     $componente = new JCRUD(ECOMP_TABLE_COMPONENTES, array('id' => $params['idcomponente']));
     if ($campo->id && $componente->id) {
         echo '<select name="' . $name . '">';
         $rel = new JCRUD(ECOMP_TABLE_COMPONENTES . '_' . $componente->alias);
         $rels = $rel->busca("WHERE published = '1' ORDER BY ordering, {$campo->alias} ASC");
         foreach ($rels as $rel) {
             $campo_alias = $campo->alias;