conf = &$CONF; $this->lng = &$LNG; $this->fields = array( '1' => 'f.id', '2' => 'f.nombre', '3' => 'f.estado', '4' => 'f.id_seccion', '5' => 'f.orden' ); $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) ); $this->tables = array( 'oa' => 'oas_documentos', 'section' => 'secciones_documentos' ); } //----------------------------------------------------------------------------------- // getRecordList // Obtiene un listado de registros de la BBDD. function getRecordList(&$page, $order_field = 1, $order_type = 'd', $SQL_records_filter = '', $section ) { $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 ' . $this->tables[$section] . ' f ' . $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 f.id, f.id_seccion, f.nombre, f.estado FROM ' . $this->tables[$section] . ' f ' . $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_seccion']; } } return $records_list; } //----------------------------------------------------------------------------------- // getRecordList // Obtiene un listado de registros de la BBDD. function getRecordListBySectionWithoutLimit($order_field = 1, $order_type = 'd', $SQL_records_filter = '') { $section = 'section'; $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 ' . $this->tables[$section] . ' f ' . $SQL_records_filter); $SQL_records = db_fetch_array($SQL_records_query); if ( $SQL_records['total'] > 0 ) { $this->num_records = $SQL_records['total']; $SQL_records_order = ' ORDER BY ' . $this->fields[$order_field] . ' ' . $this->query_order[$order_type] . ', ' . $this->fields[2]; $SQL_query = db_query('SELECT f.id, f.id_seccion, f.nombre, f.imagen, f.estado, f.orden FROM ' . $this->tables[$section] . ' f ' . $SQL_records_filter . $SQL_records_order); while ( $SQL_record = db_fetch_array($SQL_query) ) { $records_list['document_' . $SQL_record['id']]['id'] = $SQL_record['id']; $records_list['document_' . $SQL_record['id']]['nombre'] = stripslashes($SQL_record['nombre']); $records_list['document_' . $SQL_record['id']]['estado'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list['document_' . $SQL_record['id']]['id_seccion'] = $SQL_record['id_seccion']; $records_list['document_' . $SQL_record['id']]['imagen'] = $SQL_record['imagen']; $records_list['document_' . $SQL_record['id']]['orden'] = $SQL_record['orden']; } } return $records_list; } //----------------------------------------------------------------------------------- // generateFilterQuery function generateFilterQuery( $filter_field = '', $filter_values = '', $exactSearch = false, $sections = array() ) { $filterQuery = ' WHERE 1'; $filter_values = ( $exactSearch ? '\'' . addslashes($filter_values) . '\'' : '\'%' . addslashes($filter_values) . '%\'' ); $sections[] = $filter_values; if ( !empty($filter_values) && isset( $this->fields[$filter_field] ) ) { if ( $filter_field == '4' && count($sections) ) { $filterQuery .= ' AND ' . $this->fields[$filter_field] . ' IN (' . implode(',', $sections) . ')'; } else $filterQuery .= ' AND ' . $this->fields[$filter_field] . ' LIKE ' . $filter_values; } return $filterQuery; } //----------------------------------------------------------------------------------- // deleteRecord // Elimina un registro de la BBDD. function deleteRecord($record, $section) { $error .= ''; if ( $this->checkRecord($record, $section) ) { if ( @db_query('DELETE FROM ' . $this->tables[$section] . ' WHERE id = \'' . $record . '\'') ) $error .= '0'; else $error .= 3; } else $error .= 1; return $error; } //----------------------------------------------------------------------------------- // checkRecord // Comprueba si existe o no un registro function checkRecord(&$record, $section) { settype($record, "integer"); if ( $this->tables[$section] ) { $SQL_check_record = db_query('SELECT count(*) AS total FROM ' . $this->tables[$section] . ' WHERE id = \'' . $record . '\''); $SQL_num_records = db_fetch_array($SQL_check_record); if ( $SQL_num_records['total'] == 1 ) return true; else return false; } else return false; } //----------------------------------------------------------------------------------- // getRecordValues // Obtiene los valores para el registro indicado. function getRecordValues($record, $section) { if ( $this->tables[$section] && $this->checkRecord($record, $section) ) { $SQL_check_record = db_query('SELECT f.id, f.id_seccion, f.nombre, f.texto, f.imagen, f.estado, f.visualizar, f.orden FROM ' . $this->tables[$section] . ' f WHERE f.id = \'' . $record . '\''); if ( db_num_rows($SQL_check_record) == 1 ) { $this->doc = db_fetch_array($SQL_check_record); strip_slashes($this->doc); return $this->doc; } 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, $section) { $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'], $section) ) $action = 'update'; } } else $action = 'insert'; if ( $action == 'update' ) $old_record = $this->getRecordValues($params['record_id'], $section); $params['id_seccion'] = eregi_replace("[^0-9]", '', $params['id_seccion']); $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 ); $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 ' . $this->tables[$section] . ' (id_seccion, nombre, estado, visualizar, imagen, texto' . (!empty($params['orden'])?', orden':'') . ') VALUES (\'' . $params['id_seccion'] . '\', \'' . $params['nombre'] . '\', \'' . $params['estado'] . '\', \'' . implode(',', $params['visualizar']) . '\', \'' . $params['imagen'] . '\', \'' . $params['texto'] . '\'' . (!empty($params['orden'])?', \'' . $params['orden'] . '\'':'') . ')') ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE ' . $this->tables[$section] . ' SET id_seccion = \'' . $params['id_seccion'] . '\', nombre = \'' . $params['nombre'] . '\', visualizar = \'' . implode(',', $params['visualizar']) . '\', estado = \'' . $params['estado'] . '\', imagen = \'' . $params['imagen'] . '\', texto = \'' . $params['texto'] . '\', orden = ' . (!empty($params['orden'])?'\'' . $params['orden'] . '\'':'NULL') . ' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= 0; else $error .= 2; } } strip_slashes($params); return $error; } } ?>