config = &$CONF; $this->exercise = &$EXERCISE; $this->lng = &$LNG; $this->fields = array( '1' => 'a.id', '2' => 'a.id_grupo', '3' => 'a.fecha', '4' => 'a.estado', '5' => 'a.descripcion'); $this->query_order = array( 'a' => 'ASC', 'd' => 'DESC' ); $this->records_view = array('order' => array('1','3','4','5'), 'width' => array('25', '90', '90', '300'), 'orderby' => array(true, true, true, false) ); } //----------------------------------------------------------------------------------- // getRecordList // Obtiene un listado de registros de la BBDD. function getRecordList(&$page, $order_field = 3, $order_type = 'a', $SQL_records_filter = '' ) { $records_list = array(); if ( !isset( $this->fields[$order_field] ) ) $order_field = 3; if ( !isset( $this->query_order[$order_type] ) ) $order_type = 'a'; $SQL_records_query = db_query('SELECT COUNT(*) AS total FROM alertas a' . $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]; $SQL_records_limit = ' LIMIT ' . ( ( $page - 1 ) * $this->config['max_num_regs_list'] ) . ', ' . $this->config['max_num_regs_list']; $SQL_query = db_query('SELECT a.id, a.id_grupo, DATE_FORMAT(a.fecha, "%d/%m/%Y") AS fecha, a.estado, a.descripcion, ( TO_DAYS(a.fecha) - TO_DAYS(CURDATE()) ) AS dias FROM alertas a' . $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'] = $SQL_record['id_grupo']; $records_list[$SQL_record['id']]['3'] = $SQL_record['fecha']; $records_list[$SQL_record['id']]['4'] = $this->lng['form_status_' . $SQL_record['estado']]; $records_list[$SQL_record['id']]['5'] = stripslashes($SQL_record['descripcion']); $records_list[$SQL_record['id']]['6'] = $SQL_record['dias']; $records_list[$SQL_record['id']]['7'] = $SQL_record['estado']; } } return $records_list; } //----------------------------------------------------------------------------------- // generateFilterQuery function generateFilterQuery( $filter_field = '', $filter_values = '', $exactSearch = false ) { $filterQuery = ' WHERE 1'; if ( is_array($filter_values) ) { if ( count($filter_values) > 0 ) { while ( list($id) = each($filter_values) ) { $filter_values[$id] = ( $exactSearch ? addslashes($filter_values[$id]) : '%' . addslashes($filter_values[$id]) . '%' ); if ( isset( $this->fields[$id]) && trim($filter_values[$id]) != '' ) $filterQuery .= ' AND ' . $this->fields[$id] . ' LIKE \'' . $filter_values[$id] . '\''; } } } elseif ( trim($filter_values) != '' && isset( $this->fields[$filter_field] ) ) { $filter_values = ( $exactSearch ? '\'' . addslashes($filter_values) . '\'' : '\'%' . addslashes($filter_values) . '%\'' ); $filterQuery .= ' AND ' . $this->fields[$filter_field] . ' LIKE ' . $filter_values; } return $filterQuery; } //----------------------------------------------------------------------------------- // deleteRecord // Elimina un registro de la BBDD. function deleteRecord($record) { if ( $this->checkRecord($record) ) { if ( db_query('DELETE FROM alertas WHERE id = \'' . $record . '\'') ) return '0'; else return '2'; } else return '1'; } //----------------------------------------------------------------------------------- // checkRecord // Comprueba si existe o no un registro function checkRecord(&$record) { settype($record, "integer"); $SQL_check_record = db_query('SELECT count(*) AS total FROM alertas 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 a.id, a.id_grupo AS group_id, DATE_FORMAT(a.fecha, "%d/%m/%Y") AS alert_date, a.estado AS alert_status, a.descripcion AS alert_description FROM alertas a WHERE a.id = \'' . $record . '\''); if ( db_num_rows($SQL_check_record) == 1 ) { $SQL_values = db_fetch_array($SQL_check_record); return $SQL_values; } 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. // // [1] > Tipo de accion // [2] > Campo nombre // [3] > Campo Fecha Inicio // [4] > Campo Fecha Fin // [5] > Campo Nivel // [6] > Chequeo antes de realizar una accion sobre la BBDD // [7] > Resultado de la accion sobre la BBDD. 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 ( ereg("^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$", $params['alert_date'], $date ) && checkdate($date[2], $date[1], $date[3]) ) $alert_date = mktime(0,0,0,$date[2],$date[1],$date[3]); // Generacion del codigo de error $error .= ( $action == '' ? 1 : 0 ); $error .= ( empty($params['alert_description']) ? 1 : 0 ); $error .= ( !$alert_date ? 1 : 0 ); // Acciones sobre la BBDD if ( ereg("^0+$", $error) ) { format_record($params); if ( $action == 'insert' ) { if ( db_query('INSERT INTO alertas (id_grupo, fecha, estado, descripcion) VALUES (\'' . $params['group_id'] . '\', \'' . date('Y-m-d', $alert_date) . '\', \'' . $params['alert_status'] . '\', \'' . $params['alert_description'] . '\')' ) ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE alertas SET id_grupo = \'' . $params['group_id'] . '\', fecha = "' . date('Y-m-d', $alert_date) . '", estado = \'' . $params['alert_status'] . '\', descripcion = \'' . $params['alert_description'] . '\' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= 0; else $error .= 1; } } strip_slashes($params); return $error; } } ?>