conf = &$CONF; $this->lng = &$LNG; $this->fields = array( '1' => 's.id', '2' => 's.nombre', '3' => 's.estado', '4' => 's.id_oa' ); $this->query_order = array( 'a' => 'ASC', 'd' => 'DESC' ); $this->records_view = array('order' => array('1','2','3'), 'width' => array('25', '500', '80'), 'orderby' => array(true, true, true), 'search' => array(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_secciones s ' . $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 s.id, s.id_oa, s.nombre, s.estado FROM oas_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'] = $SQL_record['id_oa']; } } 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_secciones s WHERE s.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_secciones 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 s.id, s.id_oa, s.visualizar, s.nombre, s.imagen, s.estado FROM oas_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) { $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_oa'] = eregi_replace("[^0-9]", '', $params['id_oa']); $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_secciones (id_oa, visualizar, nombre, imagen, estado) VALUES (\'' . $params['id_oa'] . '\', \'' . implode(',', $params['visualizar']) . '\', \'' . $params['nombre'] . '\', \'' . $params['imagen'] . '\', \'' . $params['estado'] . '\')') ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE oas_secciones SET nombre = \'' . $params['nombre'] . '\', imagen = \'' . $params['imagen'] . '\', visualizar = \'' . implode(',', $params['visualizar']) . '\', estado = \'' . $params['estado'] . '\' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= 0; else $error .= 2; } } strip_slashes($params); return $error; } /* function getCategoriesList( $cats = array() ) { $categories = array(); $SQL_query = db_query('SELECT id, nombre FROM secciones WHERE id_oa = '' ORDER BY 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 generateCategoriesTree(&$categories, &$list, $start = '0', $separator = ' ') { if ( is_array($categories) ) { 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 ); } } } */ } ?>