semanas == 0) ? 7 : $weeks->semanas) : $_POST['weeksNumber']; $weeksCount = Database::escape_string($weeksCount); Database::query("REPLACE INTO $table_semanas_curso (course_code , semanas) VALUES ('$course_code','$weeksCount')"); if (intval($obj->cant) != $weeksCount) { if (intval($obj->cant) > $weeksCount) { $sql = "DELETE FROM $table_reporte_semanas WHERE week_id > $weeksCount AND course_code = '$course_code'"; Database::query($sql); } else { for ($i = $obj->cant + 1; $i <= $weeksCount; $i++) { if (!Database::query("INSERT INTO $table_reporte_semanas (week_id, course_code, forum_id, work_id, quiz_id, pc_id) VALUES ($i, '$course_code', '0', '0', '0', '0' )")) { return false; } } } } $sql = "REPLACE INTO $table_students_report (user_id, week_report_id, work_ok , thread_ok , quiz_ok , pc_ok) SELECT cu.user_id, rs.id, 0, 0, 0, 0 FROM $table_course_rel_user cu INNER JOIN $courseTable c ON (c.id = cu.c_id) LEFT JOIN $table_reporte_semanas rs ON c.code = rs.course_code WHERE cu.status = 5 AND rs.course_code = '$course_code' ORDER BY cu.user_id, rs.id"; if (!Database::query($sql)) { return false; } else { $page = (!isset($_GET['page'])) ? 1 : $_GET['page']; Database::query("UPDATE $table_students_report sr SET sr.work_ok = 1 WHERE CONCAT (sr.user_id,',',sr.week_report_id) IN (SELECT DISTINCT CONCAT(w.user_id,',',rs.id) FROM $table_work w JOIN $table_reporte_semanas rs ON w.parent_id = rs.work_id)"); Database::query("UPDATE $table_students_report sr SET sr.thread_ok = 1 WHERE CONCAT (sr.user_id,',',sr.week_report_id) IN (SELECT DISTINCT CONCAT(f.poster_id,',',rs.id) FROM $table_post f JOIN $table_reporte_semanas rs ON f.thread_id = rs.forum_id)"); return showResults($course_info, $weeksCount, $page); } } /** * @param $courseInfo * @param $weeksCount * @param $page * @return array */ function showResults($courseInfo, $weeksCount, $page) { $course_code = $courseInfo['code']; $page = intval($page); $weeksCount = intval($weeksCount); $tableWeeklyReport = Database::get_main_table('rp_reporte_semanas'); $tableStudentsReport = Database::get_main_table('rp_students_report'); //$table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tableUser = Database::get_main_table(TABLE_MAIN_USER); $tableThread = Database::get_course_table(TABLE_FORUM_THREAD); $tableWork = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $results = array(); $tableExport = array(); $sqlHeader = "SELECT rs.id as id,rs.week_id, w.title AS work_title, t.thread_title ,'EVALUATION' as eval_title ,'QUIZ' as pc_title FROM $tableWeeklyReport rs LEFT JOIN $tableThread t ON t.thread_id = rs.forum_id LEFT JOIN $tableWork w ON w.id = rs.work_id WHERE rs.course_code = '$course_code' ORDER BY rs.week_id"; $resultHeader = Database::query($sqlHeader); $ids = array(); $line = '