fichero = new filename(); $this->documento = new doc(); $this->conf = &$CONF; $this->lng = &$LNG; $this->fields = array( '1' => 's.id', '2' => 's.nombre', '3' => 's.estado', '4' => 's.id_padre', '5' => 'visualizar', '6' => 'orden' ); $this->query_order = array( 'a' => 'ASC', 'd' => 'DESC' ); $this->records_view = array('order' => array('1','2','4','5','3','6'), 'width' => array('25', '150', '150', '150', '80', '80'), 'orderby' => array(true, true, true, true, true, true), 'search' => array(true, true, false, false, false, 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 secciones s ' . $SQL_records_filter); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $categories = $this->getExtendedCategoriesList(); $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 s.id, s.id_padre, s.nombre, s.estado, s.visualizar, s.orden FROM secciones s' . $SQL_records_filter . $SQL_records_order . $SQL_records_limit); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list[$SQL_record['id']]['1'] = $SQL_record['id']; $records_list[$SQL_record['id']]['2'] = stripslashes($SQL_record['nombre']); $records_list[$SQL_record['id']]['3'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list[$SQL_record['id']]['4'] = $this->generateSectionPath($categories, $SQL_record['id_padre']); $records_list[$SQL_record['id']]['5'] = $this->manageShowItem($SQL_record['visualizar']); $records_list[$SQL_record['id']]['6'] = stripslashes($SQL_record['orden']);; } } return $records_list; } function generateSectionPath(&$categories, $id_padre) { $path = ''; while ( $id_padre > 0 ) { $path .= $categories[$id_padre]['name'] . '\\'; $id_padre = $categories[$id_padre]['id_padre']; } if (!empty($path) && $path != '') { $arr_aux = explode('\\', ereg_replace('[\\]$','',$path)); $arr_aux = array_reverse($arr_aux); $path = implode('\\', $arr_aux); } return $path; } function manageShowItem( $show ) { $show = ereg_replace('1', $this->lng['site_zone_1'], $show); $show = ereg_replace('2', $this->lng['site_zone_2'], $show); $show = ereg_replace('3', $this->lng['site_zone_3'], $show); return $show; } //----------------------------------------------------------------------------------- // generateFilterQuery function generateFilterQuery( $filter_field = '', $filter_values = '', $exactSearch = false, $section = '' ) { $sections = array(); if ( $section > 0 ) { $sections[] = $section; $this->getSections($section, $sections); } $filterQuery = ' WHERE 1' . ( count($sections) ? ' AND s.id_padre IN (' . implode(',',$sections) . ')' : '' ); $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; } function getSections( $section, &$sections ) { $SQL_query = db_query('SELECT id FROM secciones WHERE id_padre IN (' . $section . ')'); if ( db_num_rows($SQL_query) ) { $cats = array(); while ( $SQL_record = mysql_fetch_array($SQL_query) ) { $cats[] = $SQL_record['id']; $sections[] = $SQL_record['id']; } $this->getSections(implode(',',$cats), $sections); } } //----------------------------------------------------------------------------------- // deleteRecord // Elimina un registro de la BBDD. function deleteRecord($record) { $error .= ''; if ( $this->checkRecord($record) ) { $SQL_check_record = db_query('SELECT count(*) AS total FROM secciones WHERE id_padre = \'' . $record . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] > 0 ) $error .= 4; else { $SQL_check_record = db_query('SELECT count(*) AS total FROM oas WHERE id_seccion = \'' . $record . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] > 0 ) $error .= 3; else { if ( @db_query('DELETE FROM secciones 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 secciones WHERE id = \'' . $record . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] == 1 ) return true; else return false; } //----------------------------------------------------------------------------------- // checkRecord // Comprueba si existe o no un registro function checkVisualizacionHijos(&$record_id, &$record_visualizacion) { //Esto lo podriamos tomar de una base de datos $exclude_values = array (1, 2, 3); //$arr_origen = split(",",$record_visualizacion); $visualizar = ''; for ($i = 0;$i < count($exclude_values);$i++) { if (empty($record_visualizacion) || !in_array($exclude_values[$i], $record_visualizacion)) { $visualizar .= (($visualizar != '')?' OR ':''). 'visualizar LIKE (\'%' . $exclude_values[$i] . '%\')'; } } $SQL_check_record = db_query('SELECT count(*) AS total FROM secciones WHERE ' . (($visualizar != '')?'(' . $visualizar . ') AND ':'1 = 0 AND ') . ' id_padre = \'' . $record_id . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] > 0 ) return false; else return true; } //----------------------------------------------------------------------------------- // getRecordValues // Obtiene los valores para el registro indicado. function getRecordValues($record) { if ( $this->checkRecord($record) ) { $SQL_check_record = db_query('SELECT s.id, s.id_padre, s.visualizar, s.nombre, s.imagen, s.rollover, s.rollover_prof_pub, s.imagen_peq_prof_pub, s.rollover_peq_prof_pub, s.descripcion, s.estado, s.orden FROM secciones s WHERE s.id = \'' . $record . '\''); if ( db_num_rows($SQL_check_record) == 1 ) { $this->section = db_fetch_array($SQL_check_record); strip_slashes($this->section); return $this->section; } 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_padre'] = eregi_replace("[^0-9]", '', $params['id_padre']); $params['estado'] = ereg_replace("^([^0-1])${1}", '', $params['estado']); $params['orden'] = eregi_replace("[^0-9]", '', $params['orden']); // Generacion del codigo de error $error = ( $action == '' ? 1 : 0 ); $error .= ( empty($params['nombre']) ? 1 : 0 ); if ( ( $params['record_id'] > '0' ) && ( $params['id_padre'] == $params['record_id'] ) ) $error .= 1; elseif ( $old_record && ( $old_record['id_padre'] == '0' ) && ( $params['id_padre'] > '0' ) ) $error .= 2; elseif ( $params['id_padre'] > '0' && !$this->checkRecord($params['id_padre']) ) $error .= 3; elseif ( $params['record_id'] > '0' && !$this->checkVisualizacionHijos($params['record_id'], $params['visualizar']) ) $error .= 4; else $error .= 0; $error .= (!empty($params['orden']) && !is_numeric($params['orden']) ? 1 : 0 ); // Acciones sobre la BBDD if ( ereg("^0+$", $error) ) { format_record($params); if ( $action == 'insert' ) { if ( db_query('INSERT INTO secciones (id_padre, visualizar, nombre, estado, descripcion' . (!empty($params['orden'])?', orden':'') . ') VALUES (\'' . $params['id_padre'] . '\', \'' . ( is_array($params['visualizar']) ? implode(',', $params['visualizar']) : '' ) . '\', \'' . $params['nombre'] . '\', \'' . $params['estado'] . '\', \'' . $params['descripcion'] . '\'' . (!empty($params['orden'])?', \'' . $params['orden'] . '\'':'') . ')') ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE secciones SET id_padre = \'' . $params['id_padre'] . '\', nombre = \'' . $params['nombre'] . '\', visualizar = \'' . ( is_array($params['visualizar']) ? implode(',', $params['visualizar']) : '' ) . '\', estado = \'' . $params['estado'] . '\', descripcion = \'' . $params['descripcion'] . '\', orden = ' . (!empty($params['orden'])?'\'' . $params['orden'] . '\'':'NULL') . ' WHERE id = \'' . $params['record_id'] . '\'') ) { $error .= 0; } else $error .= 2; } if ( count($files) > 0 ) { if ($this->manageImage($files['imagen'], $params['record_id'], $params, $error, $old_record['imagen']) ) { $params['imagen'] = $files['imagen']['name']; @db_query('UPDATE secciones SET imagen = \'' . $files['imagen']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } if ($this->manageImage($files['rollover'], $params['record_id'], $params, $error, $old_record['rollover']) ) { $params['rollover'] = $files['rollover']['name']; @db_query('UPDATE secciones SET rollover = \'' . $files['rollover']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } if ($this->manageImage($files['rollover_prof_pub'], $params['record_id'], $params, $error, $old_record['rollover_prof_pub']) ) { $params['rollover_prof_pub'] = $files['rollover_prof_pub']['name']; @db_query('UPDATE secciones SET rollover_prof_pub = \'' . $files['rollover_prof_pub']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } if ($this->manageImage($files['imagen_peq_prof_pub'], $params['record_id'], $params, $error, $old_record['imagen_peq_prof_pub']) ) { $params['imagen_peq_prof_pub'] = $files['imagen_peq_prof_pub']['name']; @db_query('UPDATE secciones SET imagen_peq_prof_pub = \'' . $files['imagen_peq_prof_pub']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } if ($this->manageImage($files['rollover_peq_prof_pub'], $params['record_id'], $params, $error, $old_record['rollover_peq_prof_pub']) ) { $params['rollover_peq_prof_pub'] = $files['rollover_peq_prof_pub']['name']; @db_query('UPDATE secciones SET rollover_peq_prof_pub = \'' . $files['rollover_peq_prof_pub']['name'] . '\' WHERE id = \'' . $params['record_id'] . '\''); } } else { if ( @db_query('UPDATE secciones SET imagen = \'' . $params['imagen'] . '\', rollover = \'' . $params['rollover'] . '\', rollover_prof_pub = \'' . $params['rollover_prof_pub'] . '\', imagen_peq_prof_pub = \'' . $params['imagen_peq_prof_pub'] . '\', rollover_peq_prof_pub = \'' . $params['rollover_peq_prof_pub'] . '\' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= '00'; else $error .= '11'; } } strip_slashes($params); return $error; } function manageImage( &$file, $id, &$params, &$error, $replace = '' ) { if ( is_array($file) && $file['error'] != '4' ) { if ( is_uploaded_file($file['tmp_name']) ) { if ( $this->checkRecord($id) ) { $location = $this->conf['fs_application'] . $this->conf['ws_img_sections']; 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 getExtendedCategoriesList() { $categories = array(); $SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones ORDER BY orden ASC, id_padre, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[$SQL_record['id']]['name'] = $SQL_record['nombre']; $categories[$SQL_record['id']]['id_padre'] = $SQL_record['id_padre']; } } return $categories; } function getCategoriesList( $cats = array() ) { $categories = array(); $SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones ' . ( count($cats) ? 'WHERE id_padre IN (' . implode(',',$cats) . ') ' : '' ) . 'ORDER BY orden ASC, id_padre, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[$SQL_record['id_padre']][$SQL_record['id']] = $SQL_record['nombre']; } } return $categories; } function getCategoriesSelectablesList( $visualizacion = '1,2,3' ) { $categories = array(); //$SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones ' . ( count($cats) ? 'WHERE id_padre IN (' . implode(',',$cats) . ') ' : '' ) . 'ORDER BY id_padre, nombre'); $SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones WHERE visualizar LIKE (\'%' . ereg_replace(",","%",$visualizacion) . '%\') ORDER BY orden ASC, id_padre, nombre'); if ( db_num_rows($SQL_query) ) { $padres = array('0'); while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[$SQL_record['id_padre']][$SQL_record['id']] = $SQL_record['nombre']; } } return $categories; } function getCategoriesSecondLevel( ) { $categories = array(); //$SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones ' . ( count($cats) ? 'WHERE id_padre IN (' . implode(',',$cats) . ') ' : '' ) . 'ORDER BY id_padre, nombre'); $SQL_query = db_query('SELECT id FROM secciones WHERE id_padre = \'0\' ORDER BY orden ASC, id_padre, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[] = $SQL_record['id']; } } return $categories; } function getCategoriesLevelList( $cats = array() , $levels = array() ) { $categories = array(); //$SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones ' . ( count($cats) ? 'WHERE id_padre IN (' . implode(',',$cats) . ') ' : '' ) . 'ORDER BY id_padre, nombre'); $SQL_query = db_query('SELECT id, id_padre, nombre FROM secciones WHERE ' . ( count($cats) ? 'id_padre IN (\'' . implode('\',\'',$cats) . '\') ' : '1 = 0' ) . ' ' . ( count($levels) ? 'AND (visualizar LIKE (\'%' . implode('%\') OR visualizar LIKE (\'%',$levels) . '%\')) ' : 'OR 1 = 0' ) . 'ORDER BY orden ASC, id_padre, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) $categories[$SQL_record['id_padre']][$SQL_record['id']] = $SQL_record['nombre']; } return $categories; } function getVisualizacionList( $id_padre = '0' , $form_zones = array() ) { $visualizar = array(); $SQL_query = db_query('SELECT visualizar FROM secciones WHERE id = ' . $id_padre . ' ORDER BY orden ASC, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $ver = split(",", $SQL_record['visualizar']); for ($i = 0;$i < count($ver);$i++) $visualizar[$ver[$i]] = $form_zones[$ver[$i]]; } } return $visualizar; } function generateCategoriesTreeExcluding(&$categories, &$list, $exclude, $start = '0', $separator = ' ') { if ( is_array($categories) ) { if ( is_array($categories[$start]) ) { while ( list($id,$value) = each($categories[$start]) ) { if ($id != $exclude) { $list[$id] = $separator . $value; if ( is_array($categories[$id]) ) $this->generateCategoriesTreeExcluding(&$categories, $list, $exclude, $id, (($separator == str_repeat($separator,3)) ? $separator : str_repeat($separator,3)) ); } } } } } function generateCategoriesTree(&$categories, &$list, $start = '0', $separator = ' ') { if ( is_array($categories) ) { if ( is_array($categories[$start]) ) { while ( list($id,$value) = each($categories[$start]) ) { $list[$id] = $separator . $value; if ( is_array($categories[$id]) ) $this->generateCategoriesTree(&$categories, $list, $id, str_repeat($separator,3)); } } } } 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 ); } } } function getActivesSectionsSubcats( $cat, $visualizar, &$list, $recursive = true ) { settype($cat, "integer"); $SQL_query = db_query('SELECT id FROM secciones WHERE estado = \'1\' AND visualizar LIKE \'%' . $visualizar . '%\' AND id_padre = \'' . $cat . '\''); //echo 'SELECT id FROM secciones WHERE estado = \'1\' AND visualizar LIKE \'%' . $visualizar . '%\' AND 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 ); } } } function getWebCategoriesList( $cat = 0, $section = '3' ) { $categories = array(); $SQL_query = db_query('SELECT id, nombre, imagen, rollover, rollover_prof_pub, imagen_peq_prof_pub, rollover_peq_prof_pub FROM secciones WHERE id_padre = \'' . $cat . '\' AND estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' ORDER BY orden ASC, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[$SQL_record['id']]['nombre'] = stripslashes($SQL_record['nombre']); $categories[$SQL_record['id']]['imagen'] = stripslashes($SQL_record['imagen']); $categories[$SQL_record['id']]['imagen'] = stripslashes($SQL_record['imagen']); $categories[$SQL_record['id']]['rollover'] = stripslashes($SQL_record['rollover']); $categories[$SQL_record['id']]['rollover_prof_pub'] = stripslashes($SQL_record['rollover_prof_pub']); $categories[$SQL_record['id']]['imagen_peq_prof_pub'] = stripslashes($SQL_record['imagen_peq_prof_pub']); $categories[$SQL_record['id']]['rollover_peq_prof_pub'] = stripslashes($SQL_record['rollover_peq_prof_pub']); } } return $categories; } function getAllCategoriesWebList( $section = '3' ) { $categories = array(); $SQL_query = db_query('SELECT id, nombre, imagen, rollover, rollover_prof_pub, imagen_peq_prof_pub, rollover_peq_prof_pub, descripcion, id_padre FROM secciones WHERE estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' ORDER BY orden ASC, nombre'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) { $categories[$SQL_record['id']]['nombre'] = stripslashes($SQL_record['nombre']); $categories[$SQL_record['id']]['imagen'] = stripslashes($SQL_record['imagen']); $categories[$SQL_record['id']]['imagen'] = stripslashes($SQL_record['imagen']); $categories[$SQL_record['id']]['rollover'] = stripslashes($SQL_record['rollover']); $categories[$SQL_record['id']]['rollover_prof_pub'] = stripslashes($SQL_record['rollover_prof_pub']); $categories[$SQL_record['id']]['imagen_peq_prof_pub'] = stripslashes($SQL_record['imagen_peq_prof_pub']); $categories[$SQL_record['id']]['rollover_peq_prof_pub'] = stripslashes($SQL_record['rollover_peq_prof_pub']); $categories[$SQL_record['id']]['descripcion'] = stripslashes($SQL_record['descripcion']); $categories[$SQL_record['id']]['id_padre'] = stripslashes($SQL_record['id_padre']); //$categories[$SQL_record['id']]['ficheros'] = $this->fichero->getRecordListBySectionWithoutLimit('1', 'd', ' WHERE estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' AND id_seccion = \'' . $SQL_record['id'] . '\''); //$categories[$SQL_record['id']]['documentos'] = $this->documento->getRecordListBySectionWithoutLimit('1', 'd', ' WHERE estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' AND id_seccion = \'' . $SQL_record['id'] . '\''); } } return $categories; } function getSectionFiles( $section = '3', $id_seccion){ $files = $this->fichero->getRecordListBySectionWithoutLimit('6', 'd', ' WHERE estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' AND id_seccion = \'' . $id_seccion . '\''); return $files; } function getSectionDocuments( $section = '3', $id_seccion){ $documents = $this->documento->getRecordListBySectionWithoutLimit('5', 'd', ' WHERE estado =\'1\' AND visualizar LIKE \'%' . $section . '%\' AND id_seccion = \'' . $id_seccion . '\''); return $documents; } function getNavigationList( $cat, &$values ) { $SQL_query = @db_query('SELECT id, id_padre, nombre, imagen, rollover FROM secciones WHERE id = \'' . $cat . '\' ORDER BY orden ASC'); if ( db_num_rows($SQL_query) ) { $SQL_record = db_fetch_array($SQL_query); array_unshift($values, $SQL_record); if ( $SQL_record['id_padre'] != '0' ) $this->getNavigationList($SQL_record['id_padre'], $values); } } } ?>