config = &$CONF; $this->exercise = &$EXERCISE; $this->fields = array( '1' => 'a.id', '2' => 'a.nombre', '3' => 'a.apellidos', '4' => 'a.nif', '5' => 'a.telefono', '6' => 'a.email', '7' => 'a.id_empresa', '8' => 'e.nombre' ); $this->query_order = array( 'a' => 'ASC', 'd' => 'DESC' ); $this->records_view = array('order' => array('1','3','2', '8','4','5','6'), 'width' => array('25', '180', '90', '130', '70', '70', '150'), 'orderby' => array(true, true, true, true, true, true, true), 'search' => array(true, true, true, true, true, true, false) ); $this->ref_tables = array( 'student_role' => 'ref_colectivos' ); $this->getReferenceValues(); } //----------------------------------------------------------------------------------- // getReferenceValues // Obtiene el listado de los datos de las tablas de referencia. function getReferenceValues() { if ( count($this->ref_tables) > 0 ) { while ( list($field) = each($this->ref_tables) ) { $SQL_query = db_query('SELECT id, nombre FROM ' . $this->ref_tables[$field] . ' ORDER BY nombre'); if ( db_num_rows($SQL_query) > 0 ) { while ( $SQL_values = db_fetch_array($SQL_query) ) $this->ref[$field][$SQL_values['id']] = $SQL_values['nombre']; } } reset($this->ref_tables); } } //----------------------------------------------------------------------------------- // 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 alumnos a LEFT JOIN empresas e ON a.id_empresa = e.id ' . $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->config['max_num_regs_list'] ) . ', ' . $this->config['max_num_regs_list']; $SQL_query = db_query('SELECT a.id, a.id_empresa, e.nombre AS nombre_empresa, a.nombre, a.apellidos, a.nif, a.telefono, a.email FROM alumnos a LEFT JOIN empresas e ON a.id_empresa = e.id ' . $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'] = stripslashes($SQL_record['apellidos']); $records_list[$SQL_record['id']]['4'] = $SQL_record['nif']; $records_list[$SQL_record['id']]['5'] = ( !empty($SQL_record['telefono']) ? $SQL_record['telefono'] : ''); $records_list[$SQL_record['id']]['6'] = stripslashes($SQL_record['email']); $records_list[$SQL_record['id']]['8'] = stripslashes($SQL_record['nombre_empresa']); } } return $records_list; } //----------------------------------------------------------------------------------- // generateFilterQuery function generateFilterQuery( $filter_field = '', $filter_values = '', $exactSearch = false ) { $filterQuery = ' WHERE 1 AND a.estado != \'2\''; $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) ) { $SQL_query = db_query('SELECT count(*) AS total FROM alumnos_grupos WHERE id_alumno = \'' . $record . '\''); $SQL_values = db_fetch_array($SQL_query); if ( $SQL_values['total'] > 0 ) { if ( @db_query('UPDATE alumnos SET estado = \'2\', apellidos = \'\', nif = \'\', email = \'\', telefono = \'\', telefono_2 = \'\' WHERE id = \'' . $record . '\'') ) $error .= 0; else $error .= 2; } else { if ( @db_query('DELETE FROM alumnos 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 alumnos 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 id, id_empresa AS company_id, nombre AS student_name, apellidos AS student_surname, nif AS student_nif, email AS student_email, IF(telefono, telefono, \'\') AS student_phone, IF(telefono_2, telefono_2, \'\') AS student_phone_2, observaciones AS student_comments, id_colectivo AS student_role FROM alumnos WHERE id = \'' . $record . '\''); if ( db_num_rows($SQL_check_record) == 1 ) { $this->student = db_fetch_array($SQL_check_record); return $this->student; } 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] > Codigo Empresa // [4] > Campo NIF // [5] > 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'; $params['student_nif'] = eregi_replace("[^0-9a-z]", '', $params['student_nif']); // Generacion del codigo de error $error = ( $action == '' ? 1 : 0 ); $error .= ( empty($params['student_name']) ? 1 : 0 ); $error .= ( !$this->checkCompany($params['company_id']) ? 1 : 0 ); $error .= ( !empty($params['student_nif']) && !$this->checkNif($params['student_nif'], $params['record_id']) ? 1 : 0 ); // Acciones sobre la BBDD if ( ereg("^0+$", $error) ) { format_record($params); if ( $action == 'insert' ) { if ( db_query('INSERT INTO alumnos (id_empresa, nombre, apellidos, nif, email, telefono, telefono_2, observaciones, id_colectivo) VALUES (\'' . $params['company_id'] . '\', \'' . $params['student_name'] . '\', \'' . $params['student_surname'] . '\', \'' . $params['student_nif'] . '\', \'' . $params['student_email'] . '\', \'' . $params['student_phone'] . '\', \'' . $params['student_phone_2'] . '\', \'' . $params['student_comments'] . '\', \'' . $params['student_role'] . '\')') ) { $params['record_id'] = db_insert_id(); $error .= 0; } else $error .= 1; } elseif ( $action == 'update' ) { if ( db_query('UPDATE alumnos SET nombre = \'' . $params['student_name'] . '\', apellidos = \'' . $params['student_surname'] . '\', nif = \'' . $params['student_nif'] . '\', email = \'' . $params['student_email'] . '\', telefono = \'' . $params['student_phone'] . '\', telefono_2 = \'' . $params['student_phone_2'] . '\', observaciones = \'' . $params['student_comments'] . '\', id_colectivo = \'' . $params['student_role'] . '\' WHERE id = \'' . $params['record_id'] . '\'') ) $error .= 0; else $error .= 2; } } strip_slashes($params); return $error; } //----------------------------------------------------------------------------------- // manageStudentsToGroup function manageStudentsToGroup( $group_id, $params, $group_level = '0' ) { $error = ''; if ( is_array($params['students']) && count($params['students']) > 0 ) { $error .= 0; $reg_errors = array(); $students = array(); $studentsToGroup = array(); $studentsInGroup = array(); // Comprobacion alumnos que ya estan asignados al grupo while ( list($id) = each($params['students']) ) { if ( ereg("^([0-9]+)$", $params['students'][$id]) ) $studentsToGroup[] = $params['students'][$id]; } reset($params['students']); $SQL_query = db_query('SELECT ag.id_alumno, CONCAT(a.apellidos, \' \', a.nombre) AS nombre FROM alumnos_grupos ag LEFT JOIN alumnos a ON ag.id_alumno = a.id WHERE ag.id_grupo = \'' . $group_id . '\' AND ag.id_alumno IN (' . implode(',', $studentsToGroup) . ')'); if ( db_num_rows($SQL_query) ) { while ( $SQL_values = db_fetch_array($SQL_query) ) $studentsInGroup[$SQL_values['id_alumno']] = $SQL_values['nombre']; } // Asignacion alumnos a grupo while ( list($id) = each($params['students']) ) { if ( ereg("^([0-9]+)$", $params['students'][$id]) ) { if ( $studentsInGroup[$params['students'][$id]] ) $reg_errors[] = array( 'name' => $studentsInGroup[$params['students'][$id]], 'code' => 1 ); elseif ( $this->checkRecord($params['students'][$id]) ) { @db_query('INSERT INTO alumnos_grupos (id_alumno, id_grupo, id_nivel) VALUES (\'' . $params['students'][$id] . '\', \'' . $group_id . '\', \'' . $group_level . '\')'); $students[] = $params['students'][$id]; } } } $error .= ( count($studentsInGroup) ? 1 : 0 ); if ( count($students) > 0 ) { $SQL_query = db_query('SELECT id, id_colectivo FROM alumnos WHERE id IN (' . implode(',', $students) . ')'); if ( db_num_rows($SQL_query) ) { while ( $SQL_record = db_fetch_array($SQL_query) ) @db_query('UPDATE alumnos_grupos SET id_colectivo = \'' . $SQL_record['id_colectivo'] . '\' WHERE id_grupo = \'' . $group_id . '\' AND id_alumno = \'' . $SQL_record['id'] . '\''); } } } else $error .= 1; return array( $error, $reg_errors ); } //----------------------------------------------------------------------------------- // checkCompany function checkCompany( $record ) { settype($record, "integer"); $SQL_query = db_query('SELECT count(*) AS total FROM empresas WHERE id = \'' . $record . '\''); $SQL_values = db_fetch_array($SQL_query); if ( $SQL_values['total'] == 1 ) return true; else return false; } //----------------------------------------------------------------------------------- // checkNif function checkNif( $nif, $record = '' ) { $SQL_query = db_query('SELECT count(*) AS total FROM alumnos WHERE nif = \'' . $nif . '\'' . ( !empty($record) ? ' AND id != \'' . $record . '\'' : '' ) ); $SQL_values = db_fetch_array($SQL_query); if ( $SQL_values['total'] > 0 ) return false; else return true; } //----------------------------------------------------------------------------------- // getStudentsNoGroup function getStudentsNoGroup( $company_id ) { $SQL_query = db_query('SELECT count(*) AS total FROM alumnos a LEFT JOIN alumnos_grupos ag ON a.id = ag.id_alumno LEFT JOIN grupos g ON ag.id_grupo = g.id WHERE a.id_empresa = \'' . $company_id . '\' AND a.estado != \'2\' AND ag.id_grupo IS NULL AND ( g.id_periodo != \'' . $this->exercise->exercise['id'] . '\' OR g.id_periodo IS NULL )'); $SQL_values = db_fetch_array($SQL_query); if ( $SQL_values['total'] > 0 ) return true; else return false; } //----------------------------------------------------------------------------------- // getCompanyStudents function getCompanyStudents( $company ) { $SQL_query = db_query('SELECT id, CONCAT(apellidos, \' \', nombre) AS alumno FROM alumnos WHERE id_empresa = \'' . $company . '\' AND estado != \'2\' ORDER BY alumno' ); if ( db_num_rows($SQL_query) > 0 ) { $company_students = array(); while ( $SQL_values = db_fetch_array($SQL_query) ) $company_students[$SQL_values['id']] = stripslashes($SQL_values['alumno']); return $company_students; } else return false; } //----------------------------------------------------------------------------------- // checkStudentToGroup function checkStudentToGroup( &$record, $group ) { settype($record, "integer"); $SQL_query = db_query('SELECT count(*) AS total FROM alumnos_grupos WHERE id = \'' . $record . '\' AND id_grupo = \'' . $group . '\''); $SQL_values = db_fetch_array($SQL_query); if ( $SQL_values['total'] > 0 ) return true; else return false; } //----------------------------------------------------------------------------------- // getStudentToGroupValues function getStudentToGroupValues( $record ) { $SQL_query = db_query('SELECT ag.id, id_alumno AS student_id, ag.id_grupo AS group_id, IF( ag.id_nivel > 0, ag.id_nivel, \'\' ) AS student_level, ag.id_colectivo AS student_role, ag.observaciones AS student_comments, IF( ag.fecha_inicio, UNIX_TIMESTAMP(ag.fecha_inicio), UNIX_TIMESTAMP(g.fecha_inicio) ) AS date_start, IF( ag.fecha_fin, UNIX_TIMESTAMP(ag.fecha_fin), IF(g.fecha_fin, UNIX_TIMESTAMP(g.fecha_fin), UNIX_TIMESTAMP(e.fecha_fin) ) ) AS date_end, CONCAT(a.apellidos, \' \', a.nombre) AS student_name, estado as student_status FROM alumnos_grupos ag LEFT JOIN grupos g ON ag.id_grupo = g.id LEFT JOIN ejercicios_lectivos e ON g.id_periodo = e.id LEFT JOIN alumnos a ON ag.id_alumno = a.id WHERE ag.id = \'' . $record . '\''); if ( db_num_rows($SQL_query) == 1 ) { $SQL_values = db_fetch_array($SQL_query); strip_slashes($SQL_values); $SQL_values['student_date_start'] = date('d/m/Y', $SQL_values['date_start']); $SQL_values['student_date_end'] = date('d/m/Y', $SQL_values['date_end']); return $SQL_values; } else return false; } //----------------------------------------------------------------------------------- // manageStudentToGroup function manageStudentToGroup(&$params, $groupValues, &$record) { $error = ''; // Chequeo y tratamiento de los valores recibidos $error .= ( !is_array($groupValues) || count($groupValues) == 0 ? 1 : 0 ); if ( empty($record) && empty($params['search_student_id']) ) $error .= 6; elseif ( !empty($record) && !$this->checkStudentToGroup( $record, $groupValues['id']) ) $error .= 1; elseif ( !empty($params['search_student_id']) && !$this->checkRecord($params['search_student_id']) ) $error .= 4; elseif ( !empty($params['search_student_id']) ) { $recordValues = $this->getRecordValues($params['search_student_id']); $error .= ( $recordValues['company_id'] == $groupValues['company_id'] ? 0 : 2 ); } else $error .= 0; if ( !$this->ref['student_role'][$params['student_role']] ) $params['student_role'] = '0'; if ( empty($params['search_student_id']) && !empty($record) ) $action = 'update'; elseif ( !empty($params['search_student_id']) && empty($record) ) $action = 'insert'; $error .= ( !$action ? 1 : 0 ); // Fechas recibidas if ( ereg("^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$", $params['student_date_start'], $s_date ) && checkdate($s_date[2], $s_date[1], $s_date[3]) ) $student_date_start = mktime(0,0,0,$s_date[2], $s_date[1], $s_date[3]); if ( !empty($params['student_date_end']) ) { if ( ereg("^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$", $params['student_date_end'], $e_date ) && checkdate($e_date[2], $e_date[1], $e_date[3]) ) $student_date_end = mktime(0,0,0,$e_date[2], $e_date[1], $e_date[3]); } else $student_date_end = $groupValues['date_end']; // Codigo error fechas if ( empty($student_date_start) ) $error .= 1; elseif ( empty($student_date_end) ) $error .= 2; elseif ( ( $student_date_start < $groupValues['date_start'] ) || ( $student_date_start >= $groupValues['date_end'] ) || ( $student_date_start >= $student_date_end ) ) $error .= 3; elseif ( ( $student_date_end <= $groupValues['date_start'] ) || ( $student_date_end > $groupValues['date_end'] ) || ( $student_date_end < $student_date_start ) ) $error .= 4; else $error .= 0; // Nivel del alumno $params['student_level'] = ereg_replace("[^0-9\.,]", '', $params['student_level']); $params['student_level'] = ereg_replace(',', '.', $params['student_level']); $error .= ( $params['student_level'] < '0' || $params['student_level'] > '10' ? '1' : '0' ); // Preparacion de los datos if ( ereg("^0+$", $error) ) { if ( $action == 'insert' ) { // INSERTAR ALUMNO // * Se comprueba que no se repita el alumno en el grupo if ( $this->checkStudentNoGroup( $params['search_student_id'], $groupValues['id'], $student_date_start, $student_date_end) ) { if ( empty($params['student_role']) && $params['student_automatic_role'] == '1' ) $params['student_role'] = $recordValues['student_role']; if ( @db_query('INSERT INTO alumnos_grupos (id_alumno, id_grupo, id_nivel, id_colectivo, observaciones, fecha_inicio, fecha_fin) VALUES (\'' . $params['search_student_id'] . '\', \'' . $groupValues['id'] . '\', \'' . $params['student_level'] . '\', \'' . $params['student_role'] . '\', \'' . addslashes($params['student_comments']) . '\', ' . ( $student_date_start > $groupValues['date_start'] ? '\'' . date('Y-m-d', $student_date_start) . '\'' : 'NULL' ) . ', ' . ( $student_date_end < $groupValues['date_end'] ? '\'' . date('Y-m-d', $student_date_end) . '\'' : 'NULL' ) . ')' ) ) { $error .= 0; $record = db_insert_id(); $SQL_query = db_query('SELECT id_nivel, id_colectivo FROM alumnos_grupos WHERE id_alumno = \'' . $params['search_student_id'] . '\' AND id_grupo = \'' . $groupValues['id'] . '\' LIMIT 1'); if ( db_num_rows($SQL_query) ) { $student = db_fetch_array($SQL_query); if ( empty( $params['student_role'] ) && !empty($student['id_colectivo']) ) { db_query('UPDATE alumnos_grupos SET id_colectivo = \'' . $student['id_colectivo'] . '\' WHERE id = \'' . $record . '\''); $params['student_role'] = $student['id_colectivo']; } else db_query('UPDATE alumnos_grupos SET id_colectivo = \'' . $params['student_role'] . '\' WHERE id_alumno = \'' . $params['search_student_id'] . '\' AND id_grupo = \'' . $groupValues['id'] . '\' AND id != \'' . $record . '\''); if ( $student['id_nivel'] != $params['student_level'] ) db_query('UPDATE alumnos_grupos SET id_nivel = \'' . $params['student_level'] . '\' WHERE id_alumno = \'' . $params['search_student_id'] . '\' AND id_grupo = \'' . $groupValues['id'] . '\' AND id != \'' . $record . '\''); } } else $error .= 1; } else $error .= 9; } elseif ( $action == 'update' ) { // ACTUALIZAR ALUMNO $SQL_query = @db_query('SELECT id_alumno FROM alumnos_grupos WHERE id = \'' . $record . '\''); if ( db_num_rows($SQL_query) ) { $student = db_fetch_array($SQL_query); if ($this->checkStudentNoGroup( $student['id_alumno'], $groupValues['id'], $student_date_start, $student_date_end, $record) ) { if ( @db_query('UPDATE alumnos_grupos SET fecha_inicio = ' . ( $groupValues['date_start'] == $student_date_start ? 'NULL' : '\'' . date('Y-m-d', $student_date_start) . '\'' ) . ', fecha_fin = ' . ( $groupValues['date_end'] != $student_date_end ? '\'' . date('Y-m-d', $student_date_end) . '\'' : 'NULL' ) . ', id_nivel = \'' . $params['student_level'] . '\', id_colectivo = \'' . $params['student_role'] . '\', observaciones = \'' . addslashes($params['student_comments']) . '\' WHERE id = \'' . $record . '\'') ) { $error .= 0; @db_query('UPDATE alumnos_grupos SET id_nivel = \'' . $params['student_level'] . '\' WHERE id_alumno = \'' . $student['id_alumno'] . '\' AND id_grupo = \'' . $groupValues['id'] . '\''); @db_query('UPDATE alumnos_grupos SET id_colectivo = \'' . $params['student_role'] . '\' WHERE id_alumno = \'' . $student['id_alumno'] . '\' AND id_grupo = \'' . $groupValues['id'] . '\''); } else $error .= 1; } else $error .= 9; } else $error .= 9; } return $error; } else return $error; } function checkStudentNoGroup( $student_id, $group_id, $student_date_start, $student_date_end, $record = '' ) { $SQL_student_date_start = date('Y-m-d', $student_date_start); $SQL_student_date_end = date('Y-m-d', $student_date_end); $SQL_query = db_query('SELECT IF( ag.fecha_inicio, ag.fecha_inicio, g.fecha_inicio ) AS fecha_inicio, IF( ag.fecha_fin, ag.fecha_fin, IF( g.fecha_fin, g.fecha_fin, e.fecha_fin ) ) AS fecha_fin FROM alumnos_grupos ag LEFT JOIN grupos g ON ag.id_grupo = g.id LEFT JOIN ejercicios_lectivos e ON g.id_periodo = e.id WHERE ag.id_alumno = \'' . $student_id . '\' AND ag.id_grupo = \'' . $group_id . '\'' . ( !empty($record) ? ' AND ag.id != \'' . $record . '\'' : '' ) . ' HAVING ( ( fecha_inicio <= "' . $SQL_student_date_end . '" AND fecha_fin >= "' . $SQL_student_date_end . '" ) OR ( fecha_inicio <= "' . $SQL_student_date_start . '" AND fecha_fin >= "' . $SQL_student_date_start . '" ) OR ( fecha_inicio = "' . $SQL_student_date_start . '" AND fecha_fin = "' . $SQL_student_date_end . '" ) )'); if ( db_num_rows($SQL_query) == 0 ) return true; else return false; } //----------------------------------------------------------------------------------- // deleteStudentToGroup function deleteStudentToGroup( $record, $group = '' ) { $error = ''; if ( !empty($group) ) $error .= ( $this->checkStudentToGroup($record, $group) ? 0 : 1 ); else $error .= 0; if ( ereg("^0+$", $error) ) { $recordValues = $this->getStudentToGroupValues($record); if ( @db_query('DELETE FROM alumnos_grupos WHERE id = \'' . $record . '\'') ) { $delDateStart = ''; $delDateStop = ''; // INFORMES // Registros anteriores $SQL_query_start_date = db_query('SELECT UNIX_TIMESTAMP(fecha_fin) AS fecha_fin FROM alumnos_grupos WHERE id_grupo = \'' . $recordValues['group_id'] .'\' AND id_alumno = \'' . $recordValues['student_id'] . '\' AND fecha_fin IS NOT NULL AND fecha_fin < "' . date('Y-m-d', $recordValues['date_start']) . '" ORDER BY fecha_fin DESC LIMIT 1'); if ( db_num_rows($SQL_query_start_date) ) { $startDate = db_fech_array($SQL_query_start_date); $delDateStart = date('Y-m-d', $startDate['fecha_fin']); } else $delDateStart = date('Y-m-d', mktime(0, 0, 0, date('m', $recordValues['date_start']), -1, date('Y', $recordValues['date_start']) ) ); // Registros anteriores $SQL_query_end_date = db_query('SELECT fecha_inicio FROM alumnos_grupos WHERE id_grupo = \'' . $recordValues['group_id'] .'\' AND id_alumno = \'' . $recordValues['student_id'] . '\' AND fecha_inicio IS NOT NULL AND fecha_inicio > "' . $recordValues['date_end'] . '" ORDER BY fecha_inicio ASC LIMIT 1'); if ( db_num_rows($SQL_query_end_date) ) { $endDate = db_fetch_array($SQL_query_end_date); $delDateStop = date('Y-m-d', mktime(0, 0, 0, date('m', $endDate['fecha_inicio']), -1, date('Y', $endDate['fecha_inicio']) )); } else $delDateStop = ( date('j', $recordValues['date_end'] ) > 1 ? date('Y-m-d', $recordValues['date_end']) : date('Y-m-', $recordValues['date_end']) . '02'); @db_query('DELETE FROM informe_global WHERE id_grupo = \'' . $recordValues['group_id'] . '\' AND id_alumno = \'' . $recordValues['student_id'] . '\' AND ( fecha > "' . $delDateStart . '" AND fecha < "' . $delDateStop . '" )'); if ( $recordValues['student_status'] == '2' ) $this->deleteRecord($recordValues['student_id']); $error .= 0; } else $error .= 1; } else return $error; } } ?>