conf = &$CONF; $this->lng = &$LNG; $this->fields = array( '1' => 'oa.id', '2' => 'oa.id_seccion', '3' => 'oa.nivel', '4' => 'oa.nombre', '5' => 'oa.descripcion', '6' => 'oa.estado', '7' => 's.nombre', '8' => 'oa.tipo', '9' => 'oa.destacado', '10' => 'oa.descargable', '11' => 'oa.imagen', '12' => 'oa.descripcion'); $this->query_order = array( 'a' => 'ASC', 'd' => 'DESC' ); $this->records_view = array('order' => array('1','4','3','7','6'), 'width' => array('25', '250', '80' , '250' , '80' ), 'orderby' => array(true, true, true, true, true, true), 'search' => array(true, true, true, true, true, false) ); } //----------------------------------------------------------------------------------- // getRecordList // Obtiene un listado de registros de la BBDD. function getRecordList(&$page, $order_field = 1, $order_type = 'd', $SQL_records_filter = '' ) { $records_list = array(); if ( !isset( $this->fields[$order_field] ) ) $order_field = 1; if ( !isset( $this->query_order[$order_type] ) ) $order_type = 'd'; if ( empty($SQL_records_filter) ) $this->generateFilterQuery(); $SQL_records_query = db_query('SELECT COUNT(*) AS total FROM oas oa ' . $SQL_records_filter); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $page = check_records_page($page, $SQL_records['total']); $this->num_records = $SQL_records['total']; $SQL_records_order = ' ORDER BY ' . $this->fields[$order_field] . ' ' . $this->query_order[$order_type] . ', ' . $this->fields[2]; $SQL_records_limit = ' LIMIT ' . ( ( $page - 1 ) * $this->conf['max_num_regs_list'] ) . ', ' . $this->conf['max_num_regs_list']; $SQL_query = db_query('SELECT oa.id, oa.id_seccion, oa.nivel, oa.nombre, oa.estado, oa.tipo, oa.destacado, oa.descargable, s.nombre AS seccion FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id' . $SQL_records_filter . $SQL_records_order . $SQL_records_limit); $section = new section(); $categories = $section->getExtendedCategoriesList(); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list[$SQL_record['id']]['1'] = $SQL_record['id']; $records_list[$SQL_record['id']]['2'] = $SQL_record['id_seccion']; $records_list[$SQL_record['id']]['3'] = $SQL_record['nivel']; $records_list[$SQL_record['id']]['4'] = htmlspecialchars($SQL_record['nombre']); $records_list[$SQL_record['id']]['6'] = $this->lng['form_status_' . $SQL_record['estado']]; //ESTO ES LO QUE ESTABA ANTES. AHORA SE GENERA EL PATH COMPLETO DE LA SECCION //$records_list[$SQL_record['id']]['7'] = $SQL_record['seccion']; $records_list[$SQL_record['id']]['7'] = $section->generateSectionPath($categories, $SQL_record['id_seccion']); $records_list[$SQL_record['id']]['8'] = $SQL_record['tipo']; $records_list[$SQL_record['id']]['9'] = $SQL_record['destacado']; $records_list[$SQL_record['id']]['10'] = $SQL_record['descargable']; } } return $records_list; } //----------------------------------------------------------------------------------- // generateFilterQuery function generateFilterQuery( $filter_field = '', $filter_values = '', $exactSearch = false ) { $filterQuery = ' WHERE 1'; $filter_values = ( $exactSearch ? '\'' . addslashes($filter_values) . '\'' : '\'%' . addslashes($filter_values) . '%\'' ); if ( !empty($filter_values) && isset( $this->fields[$filter_field] ) ) $filterQuery .= ' AND ' . $this->fields[$filter_field] . ' LIKE ' . $filter_values; return $filterQuery; } //----------------------------------------------------------------------------------- // deleteRecord // Elimina un registro de la BBDD. function deleteRecord($record) { $error .= ''; if ( $this->checkRecord($record) ) { if ( @db_query('DELETE FROM oas WHERE id = \'' . $record . '\'') ) $error .= '0'; else $error .= 2; } else $error .= 1; return $error; } //----------------------------------------------------------------------------------- // checkRecord // Comprueba si existe o no un registro function checkRecord(&$record) { settype($record, "integer"); $SQL_check_record = db_query('SELECT count(*) AS total FROM oas WHERE id = \'' . $record . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] == 1 ) return true; else return false; } //----------------------------------------------------------------------------------- // getRecordValues // Obtiene los valores para el registro indicado. function getRecordValues($record) { if ( $this->checkRecord($record) ) { $SQL_check_record = db_query('SELECT oa.id, oa.id_seccion, oa.nivel, oa.nombre, oa.descripcion, oa.estado, oa.imagen, oa.imagen_pro_pu, oa.pdf_file, oa.destacado, oa.descargable, oa.tipo, s.nombre AS seccion, oa.visualizar FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id WHERE oa.id = \'' . $record . '\''); if ( db_num_rows($SQL_check_record) == 1 ) { $this->oa = db_fetch_array($SQL_check_record); strip_slashes($this->oa); return $this->oa; } else return false; } else return false; } //----------------------------------------------------------------------------------- // manageRecord // - Recibe los parametros enviados desde el formulario mediante metodo POST. // - Determina el tipo de accion a realizar (INSERT o UPDATE). // - Trata los valores recibidos. // - Genera un codigo de error correspondiente a las acciones realizadas. // function manageRecord(&$params, &$files) { $action = ''; $error = ''; // Chequeo y tratamiento de los valores recibidos if ( isset($params['record_id']) ) { if ( ereg("^[0-9]+$", $params['record_id'] ) && $params['record_id'] > 0 ) { if ( $this->checkRecord($params['record_id']) ) $action = 'update'; } } else $action = 'insert'; if ( $action == 'update' ) $old_record = $this->getRecordValues($params['record_id']); $params['id_seccion'] = eregi_replace("[^0-9]", '', $params['id_seccion']); $params['nivel'] = ereg_replace("^([^1-3])${1}", '', $params['nivel']); $params['estado'] = ereg_replace("^([^0-1])${1}", '', $params['estado']); // Generacion del codigo de error $error = ( $action == '' ? 1 : 0 ); $error .= ( empty($params['nombre']) ? 1 : 0 ); // Acciones sobre la BBDD if ( ereg("^0+$", $error) ) { format_record($params); if ( $action == 'insert' ) { if ( db_query('INSERT INTO oas (id_seccion, nivel, nombre, descripcion, estado, destacado, descargable, tipo, visualizar) VALUES (\'' . $params['id_seccion'] . '\', \'' . $params['nivel'] . '\', \'' . $params['nombre'] . '\', \'' . $params['descripcion'] . '\', \'' . $params['estado'] . '\', \''. $params['destacado'] . '\', \'' . $params['descargable'] . '\', \'' . ( is_array($params['tipo']) ? implode(',', $params['tipo']) : '' ) . '\', \'' . ( is_array($params['visualizar']) ? implode(',', $params['visualizar']) : '' ) . '\')') ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE oas SET id_seccion = \'' . $params['id_seccion'] . '\', nivel = \'' . $params['nivel'] . '\', nombre = \'' . $params['nombre'] . '\', descripcion = \'' . $params['descripcion'] . '\', estado = \'' . $params['estado'] . '\', destacado = \'' . $params['destacado'] . '\', descargable = \'' . $params['descargable'] . '\', tipo = \'' . ( is_array($params['tipo']) ? implode(',', $params['tipo']) : '' ) . '\', visualizar = \'' . ( is_array($params['visualizar']) ? implode(',', $params['visualizar']) : '' ) . '\' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= 0; else $error .= 2; } } if ($this->manageImage($files['imagen'], $params['record_id'], $params, $error, $old_record['imagen']) ) { $params['imagen'] = $files['imagen']['name']; @db_query('UPDATE oas SET imagen = \'' . $files['imagen']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } else { if ($params['del_imagen']) {@db_query('UPDATE oas SET imagen = NULL WHERE id = \'' . $params['record_id'] . '\'');$this->deleteImage($old_record['imagen']);} } if ($this->manageImage($files['imagen_pro_pu'], $params['record_id'], $params, $error, $old_record['imagen_pro_pu']) ) { $params['imagen_pro_pu'] = $files['imagen_pro_pu']['name']; @db_query('UPDATE oas SET imagen_pro_pu = \'' . $files['imagen_pro_pu']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } else { if ($params['del_imagen_pro_pu']) {@db_query('UPDATE oas SET imagen_pro_pu = NULL WHERE id = \'' . $params['record_id'] . '\'');$this->deleteImage($old_record['imagen_pro_pu']);} } if ($this->managePdf($files['pdf_file'], $params['record_id'], $params, $error, $old_record['pdf_file']) ) { $params['pdf_file'] = $files['pdf_file']['name']; @db_query('UPDATE oas SET pdf_file = \'' . $files['pdf_file']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } else { if ($params['del_pdf_file']) {@db_query('UPDATE oas SET pdf_file = NULL WHERE id = \'' . $params['record_id'] . '\'');$this->deletePdf($old_record['pdf_file'],$params['record_id']);} } if ($this->manageZip($files['zip_pro_pu'], $params['record_id'], $params, $error) ) { } strip_slashes($params); return $error; } function deleteImage($replace) { $location = $this->conf['fs_application'] . $this->conf['ws_img_oas']; if ( !empty($replace) && file_exists($location . $replace) ) @unlink($location . $replace); } function deletePdf($replace,$id) { // TOCADO POR ANGEL $location = $this->conf['fs_document_root'] . $this->conf['ws_pdf_oas'] . $id . "/"; if ( !empty($replace) && file_exists($location . $replace) ) @unlink($location . $replace); } function manageImage( &$file, $id, &$params, &$error, $replace = '' ) { if ( is_array($file) && $file['error'] != '4' && $file['tmp_name'] != 'none' ) { if ( is_uploaded_file($file['tmp_name']) ) { if ( $this->checkRecord($id) ) { $location = $this->conf['fs_application'] . $this->conf['ws_img_oas']; if ( !empty($replace) && file_exists($location . $replace) ) @unlink($location . $replace); @unlink($location . $file['name']); if ( copy($file['tmp_name'], $location . $file['name']) ) { $error .= 0; return true; } else $error .= 3; } else $error .= 2; } else $error .= 1; } else $error .= 0; return false; } function managePdf( &$file, $id, &$params, &$error, $replace = '' ) { if ( is_array($file) && $file['error'] != '4' && $file['tmp_name'] != 'none' ) { if ( is_uploaded_file($file['tmp_name']) ) { if ( $this->checkRecord($id) ) { // TOCADO POR ANGEL $location = $this->conf['fs_document_root'] . $this->conf['ws_pdf_oas']. $id . "/"; if ( !empty($replace) && file_exists($location . $replace) ) @unlink($location . $replace); @unlink($location . $file['name']); if ( copy($file['tmp_name'], $location . $file['name']) ) { $error .= 0; return true; } else $error .= 3; } else $error .= 2; } else $error .= 1; } else $error .= 0; return false; } //ANYADIDO POR JOSE function manageZip( &$file, $id, &$params, &$error ) { if ( is_array($file) && $file['error'] != '4' ) { $nombreDocumento = $file['name']; $extension = ereg_replace(".*\.([^\.]*)$", "\\1", $nombreDocumento); $extension = strtolower($extension); if ($extension == "zip"){ $location = $this->conf['fs_document_root'] . $this->conf['ws_zip_oas'] . $id; if ( file_exists($location) || mkdir($location, 0777) ) { //TOCADO POR ANGEL if ( is_uploaded_file($file['tmp_name']) ) { if ( copy($file['tmp_name'], $location . "/" . $file['name']) ) { $error .= 0; } else $error .= 3; $zlib_prefix = $this->conf['fs_includes']."pcl/"; require_once( $zlib_prefix."pclzip.lib.php" ); $zipfile = new PclZip($file['tmp_name']); if((strtolower(PHP_OS) == 'winnt')) { define('OS_WINDOWS',1); } else { define('OS_WINDOWS',0); } $location_swf = $this->conf['fs_application'] . $this->conf['ws_swf_oas'] . $id; if ( file_exists($location_swf) || mkdir($location_swf, 0777) ) { $ret = $zipfile->extract(PCLZIP_OPT_PATH, $location_swf); if($ret <= 0){ $error .= 1; }else{ $error .= 0; } } else { $error .= 1; } } } } } } //ANYADIDO POR JOSE function getCategoriesList( $record ) { $categories = array(); if ( $this->checkRecord($record) ) { $SQL_query = db_query('SELECT id, nombre FROM oas_secciones WHERE id_oa = \'' . $record . '\' ORDER BY nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) $categories[$SQL_record['id']] = $SQL_record['nombre']; } } return $categories; } function getRecordListDestacados($nivel = '1') { $records_list = array(); $order_field = 1; $order_type = 'd'; $SQL_records_query = db_query('SELECT COUNT(*) AS total FROM oas oa WHERE oa.destacado = \'1\' AND oa.nivel = \''.$nivel.'\''); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $SQL_query = db_query('SELECT oa.id, oa.id_seccion, oa.nivel, oa.nombre, oa.estado, oa.tipo, oa.destacado, oa.descargable, oa.imagen, oa.pdf_file, oa.descripcion, s.nombre AS seccion FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id WHERE oa.destacado = \'1\' AND oa.estado=\'1\' AND s.visualizar LIKE \'%2%\' AND oa.nivel = \''.$nivel.'\''); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list[$SQL_record['id']]['1'] = $SQL_record['id']; $records_list[$SQL_record['id']]['2'] = $SQL_record['id_seccion']; $records_list[$SQL_record['id']]['3'] = $SQL_record['nivel']; $records_list[$SQL_record['id']]['4'] = htmlspecialchars($SQL_record['nombre']); $records_list[$SQL_record['id']]['6'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list[$SQL_record['id']]['7'] = $SQL_record['seccion']; $records_list[$SQL_record['id']]['8'] = $SQL_record['tipo']; $records_list[$SQL_record['id']]['9'] = $SQL_record['destacado']; $records_list[$SQL_record['id']]['10'] = $SQL_record['descargable']; $records_list[$SQL_record['id']]['11'] = $SQL_record['imagen']; $records_list[$SQL_record['id']]['12'] = $SQL_record['descripcion']; $records_list[$SQL_record['id']]['13'] = $SQL_record['pdf_file']; } } return $records_list; } function getRecordListBySectionAndLevel($seccion, $ids_seccion, $nivel = '1') { $records_list = array(); $order_field = 1; $order_type = 'd'; $SQL_records_query = db_query('SELECT COUNT(*) AS total FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id WHERE oa.estado=\'1\' AND s.visualizar LIKE \'%'.$seccion.'%\' AND oa.id_seccion IN (' . $ids_seccion . ') AND oa.nivel = \''.$nivel.'\''); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $SQL_query = db_query('SELECT oa.id, oa.id_seccion, oa.nivel, oa.nombre, oa.estado, oa.tipo, oa.destacado, oa.descargable, oa.imagen, oa.pdf_file, oa.descripcion, s.nombre AS seccion FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id WHERE oa.estado=\'1\' AND s.visualizar LIKE \'%'.$seccion.'%\' AND oa.id_seccion IN (' . $ids_seccion . ') AND oa.nivel = \''.$nivel.'\''); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list[$SQL_record['id']]['1'] = $SQL_record['id']; $records_list[$SQL_record['id']]['2'] = $SQL_record['id_seccion']; $records_list[$SQL_record['id']]['3'] = $SQL_record['nivel']; $records_list[$SQL_record['id']]['4'] = htmlspecialchars($SQL_record['nombre']); $records_list[$SQL_record['id']]['6'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list[$SQL_record['id']]['7'] = $SQL_record['seccion']; $records_list[$SQL_record['id']]['8'] = $SQL_record['tipo']; $records_list[$SQL_record['id']]['9'] = $SQL_record['destacado']; $records_list[$SQL_record['id']]['10'] = $SQL_record['descargable']; $records_list[$SQL_record['id']]['11'] = $SQL_record['imagen']; $records_list[$SQL_record['id']]['12'] = $SQL_record['descripcion']; $records_list[$SQL_record['id']]['13'] = $SQL_record['pdf_file']; } } return $records_list; } function getRecordListBySection($seccion, $id_seccion) { $records_list = array(); $order_field = 1; $order_type = 'd'; $SQL_records_query = db_query('SELECT COUNT(*) AS total FROM oas oa WHERE oa.id_seccion = \''.$id_seccion.'\''); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $SQL_query = db_query('SELECT oa.id, oa.id_seccion, oa.nivel, oa.nombre, oa.estado, oa.tipo, oa.destacado, oa.descargable, oa.imagen, oa.imagen_pro_pu, oa.pdf_file, oa.descripcion, s.nombre AS seccion FROM oas oa LEFT JOIN secciones s ON oa.id_seccion = s.id WHERE oa.estado=\'1\' AND s.visualizar LIKE \'%'.$seccion.'%\' AND oa.visualizar LIKE \'%'.$seccion.'%\' AND oa.id_seccion = \''.$id_seccion.'\''); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list[$SQL_record['id']]['id'] = $SQL_record['id']; $records_list[$SQL_record['id']]['id_seccion'] = $SQL_record['id_seccion']; $records_list[$SQL_record['id']]['nivel'] = $SQL_record['nivel']; $records_list[$SQL_record['id']]['nombre'] = htmlspecialchars($SQL_record['nombre']); $records_list[$SQL_record['id']]['estado'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list[$SQL_record['id']]['seccion'] = $SQL_record['seccion']; $records_list[$SQL_record['id']]['tipo'] = $SQL_record['tipo']; $records_list[$SQL_record['id']]['destacado'] = $SQL_record['destacado']; $records_list[$SQL_record['id']]['descargable'] = $SQL_record['descargable']; $records_list[$SQL_record['id']]['imagen'] = $SQL_record['imagen']; $records_list[$SQL_record['id']]['imagen_pro_pu'] = $SQL_record['imagen_pro_pu']; $records_list[$SQL_record['id']]['pdf_file'] = $SQL_record['pdf_file']; $records_list[$SQL_record['id']]['descripcion'] = $SQL_record['descripcion']; } } return $records_list; } function get_zip_file( $id_oa ) { $nombre_fichero = ''; $_path = $this->conf['fs_document_root'] . $this->conf['ws_zip_oas'] . $id_oa; if (file_exists($_path) && $handle = opendir($_path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && eregi(".zip$",$file)) { $nombre_fichero .= $file; } } closedir($handle); } return $nombre_fichero; } function get_flash_file( $id_oa ) { $nombre_fichero = ''; //$_path = $this->conf['fs_document_root'] . $this->conf['ws_zip_oas'] . $id_oa; $_path = $this->conf['fs_application'] . $this->conf['ws_swf_oas'] . $id_oa; if (file_exists($_path) && $handle = opendir($_path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && eregi(".swf$",$file)) { $nombre_fichero .= $file; } } closedir($handle); } return $nombre_fichero; } function get_html_file( $id_oa ) { $nombre_fichero = ''; //$_path = $this->conf['fs_document_root'] . $this->conf['ws_zip_oas'] . $id_oa; $_path = $this->conf['fs_application'] . $this->conf['ws_swf_oas'] . $id_oa; if (file_exists($_path) && $handle = opendir($_path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && eregi(".htm$|.html",$file)) { $nombre_fichero .= $file; } } closedir($handle); } return $nombre_fichero; } /* function getNumOfSubcats( $cat ) { $SQL_query = db_query('SELECT count(*) AS total FROM secciones WHERE id_padre = \'' . $cat . '\''); $SQL_record = db_fetch_array($SQL_query); return $SQL_record['total']; } function getSectionsSubcats( $cat, &$list, $recursive = true ) { settype($cat, "integer"); $SQL_query = db_query('SELECT id FROM secciones WHERE id_padre = \'' . $cat . '\''); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $list[] = $SQL_record['id']; if ( $recursive ) $this->getSectionsSubcats( $SQL_record['id'], $list ); } } } */ } ?>