Exemplo n.º 1
0
function _mysqldump($mysql_database)
{
    $sql = "show tables where tables_in_{$mysql_database} not like 'COURSE_DETAILS%' and tables_in_{$mysql_database} not like 'ENROLL_GRADE%'\r\n               and tables_in_{$mysql_database} not like 'MARKING_PERIODS%' and tables_in_{$mysql_database} not like 'TRANSCRIPT_GRADES%' ;";
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_row($result)) {
            _mysqldump_table_structure($row[0]);
            _mysqldump_table_data($row[0]);
        }
        echo "--\r\n              --\r\n              --\r\n\r\n            CREATE VIEW MARKING_PERIODS AS\r\n            SELECT q.marking_period_id, 'openSIS' AS mp_source, q.syear,\r\n            q.school_id, 'quarter' AS mp_type, q.title, q.short_name,\r\n            q.sort_order, q.semester_id AS parent_id,\r\n            s.year_id AS grandparent_id, q.start_date,\r\n            q.end_date, q.post_start_date,\r\n            q.post_end_date, q.does_grades,\r\n            q.does_exam, q.does_comments\r\n           FROM SCHOOL_QUARTERS q\r\n           JOIN SCHOOL_SEMESTERS s ON q.semester_id = s.marking_period_id\r\n           UNION\r\n            SELECT marking_period_id, 'openSIS' AS mp_source, syear,\r\n            school_id, 'semester' AS mp_type, title, short_name,\r\n            sort_order, year_id AS parent_id,\r\n            -1 AS grandparent_id, start_date,\r\n            end_date, post_start_date,\r\n            post_end_date, does_grades,\r\n            does_exam, does_comments\r\n           FROM SCHOOL_SEMESTERS\r\n           UNION\r\n            SELECT marking_period_id, 'openSIS' AS mp_source, syear,\r\n            school_id, 'year' AS mp_type, title, short_name,\r\n            sort_order, -1 AS parent_id,\r\n            -1 AS grandparent_id, start_date,\r\n            end_date, post_start_date,\r\n            post_end_date, does_grades,\r\n            does_exam, does_comments\r\n            FROM SCHOOL_YEARS\r\n           UNION\r\n           SELECT marking_period_id, 'History' AS mp_source, syear,\r\n\t   school_id, mp_type, name AS title, NULL AS short_name,\r\n\t   NULL AS sort_order, parent_id,\r\n\t   -1 AS grandparent_id, NULL AS start_date,\r\n\t   post_end_date AS end_date, NULL AS post_start_date,\r\n\t   post_end_date, 'Y' AS does_grades,\r\n\t   NULL AS does_exam, NULL AS does_comments\r\n           FROM HISTORY_MARKING_PERIODS;\n\r\n\r\n          \r\n\r\n             CREATE VIEW COURSE_DETAILS AS\r\n             SELECT cp.school_id, cp.syear, cp.marking_period_id, cp.period_id, c.subject_id,\r\n\t     cp.course_id, cp.course_period_id, cp.teacher_id, cp.secondary_teacher_id, c.title AS course_title,\r\n\t     cp.title AS cp_title, cp.grade_scale_id, cp.mp, cp.credits\r\n             FROM COURSE_PERIODS cp, COURSES c WHERE (cp.course_id = c.course_id);\n\n\r\n\r\n            CREATE VIEW ENROLL_GRADE AS\r\n            SELECT e.id, e.syear, e.school_id, e.student_id, e.start_date, e.end_date, sg.short_name, sg.title\r\n            FROM STUDENT_ENROLLMENT e, SCHOOL_GRADELEVELS sg WHERE (e.grade_id = sg.id);\n\n\r\n\r\n            CREATE VIEW TRANSCRIPT_GRADES AS\r\n            SELECT s.id AS school_id, mp.mp_source, mp.marking_period_id AS mp_id,\r\n\t    mp.title AS mp_name, mp.syear, mp.end_date AS posted, rcg.student_id,\r\n\t    sms.grade_level_short AS gradelevel, rcg.grade_letter, rcg.weighted_gp AS gp_value,\r\n\t    rcg.unweighted_gp AS weighting, rcg.gp_scale, rcg.credit_attempted, rcg.credit_earned,\r\n\t    rcg.credit_category, rcg.course_title AS course_name,\r\n\t    sms.cum_weighted_factor AS cum_gp_factor,\r\n\t   (sms.cum_weighted_factor * s.reporting_gp_scale) AS cum_gpa,\r\n\t   ((sms.sum_weighted_factors / sms.count_weighted_factors) * s.reporting_gp_scale) AS gpa,\r\n\t   sms.cum_rank,mp.sort_order\r\n           FROM STUDENT_REPORT_CARD_GRADES rcg\r\n           INNER JOIN MARKING_PERIODS mp ON mp.marking_period_id = rcg.marking_period_id AND mp.mp_type IN ('year','semester','quarter')\r\n           INNER JOIN STUDENT_MP_STATS sms ON sms.student_id = rcg.student_id AND sms.marking_period_id = rcg.marking_period_id\r\n           INNER JOIN SCHOOLS s ON s.id = mp.school_id;\n\r\n            ";
    } else {
        echo "/* no tables in {$mysql_database} \n";
    }
    mysql_free_result($result);
}
Exemplo n.º 2
0
function _mysqldump($mysql_database)
{
    $sql = "show tables;";
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_row($result)) {
            _mysqldump_table_structure($row[0]);
            if (isset($_REQUEST['sql_table_data'])) {
                _mysqldump_table_data($row[0]);
            }
        }
    } else {
        print "/* no tables in {$mysql_database} */\n";
    }
    mysql_free_result($result);
}
Exemplo n.º 3
0
function _mysqldump($mysql_database)
{
    $sql = 'show tables where tables_in_' . $mysql_database . ' not like \'course_details%\' and tables_in_' . $mysql_database . ' not like \'enroll_grade%\'
               and tables_in_' . $mysql_database . ' not like \'marking_periods%\' and tables_in_' . $mysql_database . ' not like \'student_contacts%\' and tables_in_' . $mysql_database . ' not like \'transcript_grades%\' ;';
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_row($result)) {
            _mysqldump_table_structure($row[0]);
            _mysqldump_table_data($row[0]);
        }
        echo "--\r\n              --\r\n              --\r\n\r\n                    CREATE VIEW marking_periods AS\r\n    SELECT q.marking_period_id, 'openSIS' AS mp_source, q.syear,\r\n\tq.school_id, 'quarter' AS mp_type, q.title, q.short_name,\r\n\tq.sort_order, q.semester_id AS parent_id,\r\n\ts.year_id AS grandparent_id, q.start_date,\r\n\tq.end_date, q.post_start_date,\r\n\tq.post_end_date, q.does_grades,\r\n\tq.does_exam, q.does_comments\r\n    FROM school_quarters q\r\n    JOIN school_semesters s ON q.semester_id = s.marking_period_id\r\nUNION\r\n    SELECT marking_period_id, 'openSIS' AS mp_source, syear,\r\n\tschool_id, 'semester' AS mp_type, title, short_name,\r\n\tsort_order, year_id AS parent_id,\r\n\t-1 AS grandparent_id, start_date,\r\n\tend_date, post_start_date,\r\n\tpost_end_date, does_grades,\r\n\tdoes_exam, does_comments\r\n    FROM school_semesters\r\nUNION\r\n    SELECT marking_period_id, 'openSIS' AS mp_source, syear,\r\n\tschool_id, 'year' AS mp_type, title, short_name,\r\n\tsort_order, -1 AS parent_id,\r\n\t-1 AS grandparent_id, start_date,\r\n\tend_date, post_start_date,\r\n\tpost_end_date, does_grades,\r\n\tdoes_exam, does_comments\r\n    FROM school_years\r\nUNION\r\n    SELECT marking_period_id, 'History' AS mp_source, syear,\r\n\tschool_id, mp_type, name AS title, NULL AS short_name,\r\n\tNULL AS sort_order, parent_id,\r\n\t-1 AS grandparent_id, NULL AS start_date,\r\n\tpost_end_date AS end_date, NULL AS post_start_date,\r\n\tpost_end_date, 'Y' AS does_grades,\r\n\tNULL AS does_exam, NULL AS does_comments\r\n    FROM history_marking_periods;\n\r\n\r\n          \r\n\r\n             CREATE VIEW course_details AS\r\n  SELECT cp.school_id, cp.syear, cp.marking_period_id, c.subject_id,\r\n\t  cp.course_id, cp.course_period_id, cp.teacher_id,cp. secondary_teacher_id, c.title AS course_title,\r\n\t  cp.title AS cp_title, cp.grade_scale_id, cp.mp, cp.credits,cp.begin_date,cp.end_date\r\n  FROM course_periods cp, courses c WHERE (cp.course_id = c.course_id);\n\r\n\r\nCREATE VIEW enroll_grade AS\r\n  SELECT e.id, e.syear, e.school_id, e.student_id, e.start_date, e.end_date, sg.short_name, sg.title\r\n  FROM student_enrollment e, school_gradelevels sg WHERE (e.grade_id = sg.id);\n\r\n\r\nCREATE VIEW transcript_grades AS\r\n    SELECT s.id AS school_id, IF(mp.mp_source='history',(SELECT school_name FROM history_school WHERE student_id=rcg.student_id and marking_period_id=mp.marking_period_id),s.title) AS school_name,mp_source, mp.marking_period_id AS mp_id,\r\n mp.title AS mp_name, mp.syear, mp.end_date AS posted, rcg.student_id,\r\n sgc.grade_level_short AS gradelevel, rcg.grade_letter, rcg.unweighted_gp AS gp_value,\r\n rcg.weighted_gp AS weighting, rcg.gp_scale, rcg.credit_attempted, rcg.credit_earned,\r\n rcg.credit_category,rcg.course_period_id AS course_period_id, rcg.course_title AS course_name,\r\n        (SELECT courses.short_name FROM course_periods,courses  WHERE course_periods.course_id=courses.course_id and course_periods.course_period_id=rcg.course_period_id) AS course_short_name,rcg.gpa_cal AS gpa_cal,\r\n sgc.weighted_gpa,\r\n sgc.unweighted_gpa,\r\n                  sgc.gpa,\r\n sgc.class_rank,mp.sort_order\r\n    FROM student_report_card_grades rcg\r\n    INNER JOIN marking_periods mp ON mp.marking_period_id = rcg.marking_period_id AND mp.mp_type IN ('year','semester','quarter')\r\n    INNER JOIN student_gpa_calculated sgc ON sgc.student_id = rcg.student_id AND sgc.marking_period_id = rcg.marking_period_id\r\n    INNER JOIN schools s ON s.id = mp.school_id;\n\r\n            ";
        echo "DELIMITER \$\$\r\n--\r\n-- Procedures\r\n--\r\nCREATE PROCEDURE `ATTENDANCE_CALC`(IN cp_id INT)\r\nBEGIN\r\nDELETE FROM missing_attendance WHERE COURSE_PERIOD_ID=cp_id;\r\nINSERT INTO missing_attendance(SCHOOL_ID,SYEAR,SCHOOL_DATE,COURSE_PERIOD_ID,PERIOD_ID,TEACHER_ID,SECONDARY_TEACHER_ID) \r\n        SELECT s.ID AS SCHOOL_ID,acc.SYEAR,acc.SCHOOL_DATE,cp.COURSE_PERIOD_ID,cpv.PERIOD_ID, IF(tra.course_period_id=cp.course_period_id AND acc.school_date<tra.assign_date =true,tra.pre_teacher_id,cp.teacher_id) AS TEACHER_ID,\r\n        cp.SECONDARY_TEACHER_ID FROM attendance_calendar acc INNER JOIN course_periods cp ON cp.CALENDAR_ID=acc.CALENDAR_ID INNER JOIN course_period_var cpv ON cp.COURSE_PERIOD_ID=cpv.COURSE_PERIOD_ID \r\n        AND (cpv.COURSE_PERIOD_DATE IS NULL AND position(substring('UMTWHFS' FROM DAYOFWEEK(acc.SCHOOL_DATE) FOR 1) IN cpv.DAYS)>0 OR cpv.COURSE_PERIOD_DATE IS NOT NULL AND cpv.COURSE_PERIOD_DATE=acc.SCHOOL_DATE) \r\n        INNER JOIN schools s ON s.ID=acc.SCHOOL_ID LEFT JOIN teacher_reassignment tra ON (cp.course_period_id=tra.course_period_id) INNER JOIN schedule sch ON sch.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID \r\n        AND sch.student_id IN(SELECT student_id FROM student_enrollment se WHERE sch.school_id=se.school_id AND sch.syear=se.syear AND start_date<=acc.school_date AND (end_date IS NULL OR end_date>=acc.school_date))\r\n        AND (cp.MARKING_PERIOD_ID IS NOT NULL AND cp.MARKING_PERIOD_ID IN (SELECT MARKING_PERIOD_ID FROM school_years WHERE SCHOOL_ID=acc.SCHOOL_ID AND acc.SCHOOL_DATE BETWEEN START_DATE AND END_DATE UNION SELECT MARKING_PERIOD_ID FROM school_semesters WHERE SCHOOL_ID=acc.SCHOOL_ID AND acc.SCHOOL_DATE BETWEEN START_DATE AND END_DATE UNION SELECT MARKING_PERIOD_ID FROM school_quarters WHERE SCHOOL_ID=acc.SCHOOL_ID AND acc.SCHOOL_DATE BETWEEN START_DATE AND END_DATE) OR (cp.MARKING_PERIOD_ID IS NULL AND acc.school_date BETWEEN cp.begin_date AND cp.end_date))\r\n        AND sch.START_DATE<=acc.SCHOOL_DATE AND (sch.END_DATE IS NULL OR sch.END_DATE>=acc.SCHOOL_DATE ) AND cpv.DOES_ATTENDANCE='Y' AND acc.SCHOOL_DATE<=CURDATE() AND cp.course_period_id=cp_id \r\n        AND NOT EXISTS (SELECT '' FROM  attendance_completed ac WHERE ac.SCHOOL_DATE=acc.SCHOOL_DATE AND ac.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID AND ac.PERIOD_ID=cpv.PERIOD_ID \r\n        AND IF(tra.course_period_id=cp.course_period_id AND acc.school_date<=tra.assign_date =true,ac.staff_id=tra.pre_teacher_id,ac.staff_id=cp.teacher_id)) \r\n        GROUP BY acc.SCHOOL_DATE,cp.COURSE_PERIOD_ID,cp.TEACHER_ID,cpv.PERIOD_ID;\r\nEND\$\$\r\n\r\nCREATE PROCEDURE `ATTENDANCE_CALC_BY_DATE`(IN sch_dt DATE,IN year INT,IN school INT)\r\nBEGIN\r\n DELETE FROM missing_attendance WHERE SCHOOL_DATE=sch_dt AND SYEAR=year AND SCHOOL_ID=school;\r\n INSERT INTO missing_attendance(SCHOOL_ID,SYEAR,SCHOOL_DATE,COURSE_PERIOD_ID,PERIOD_ID,TEACHER_ID,SECONDARY_TEACHER_ID) SELECT s.ID AS SCHOOL_ID,acc.SYEAR,acc.SCHOOL_DATE,cp.COURSE_PERIOD_ID,cpv.PERIOD_ID, IF(tra.course_period_id=cp.course_period_id AND acc.school_date<tra.assign_date =true,tra.pre_teacher_id,cp.teacher_id) AS TEACHER_ID,cp.SECONDARY_TEACHER_ID FROM attendance_calendar acc INNER JOIN marking_periods mp ON mp.SYEAR=acc.SYEAR AND mp.SCHOOL_ID=acc.SCHOOL_ID AND acc.SCHOOL_DATE BETWEEN mp.START_DATE AND mp.END_DATE INNER JOIN course_periods cp ON cp.MARKING_PERIOD_ID=mp.MARKING_PERIOD_ID  AND cp.CALENDAR_ID=acc.CALENDAR_ID INNER JOIN course_period_var cpv ON cp.COURSE_PERIOD_ID=cpv.COURSE_PERIOD_ID AND cpv.DOES_ATTENDANCE='Y' LEFT JOIN teacher_reassignment tra ON (cp.course_period_id=tra.course_period_id) INNER JOIN school_periods sp ON sp.SYEAR=acc.SYEAR AND sp.SCHOOL_ID=acc.SCHOOL_ID AND sp.PERIOD_ID=cpv.PERIOD_ID AND (sp.BLOCK IS NULL AND position(substring('UMTWHFS' FROM DAYOFWEEK(acc.SCHOOL_DATE) FOR 1) IN cpv.DAYS)>0 OR sp.BLOCK IS NOT NULL AND acc.BLOCK IS NOT NULL AND sp.BLOCK=acc.BLOCK) INNER JOIN schools s ON s.ID=acc.SCHOOL_ID INNER JOIN schedule sch ON sch.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID AND sch.START_DATE<=acc.SCHOOL_DATE AND (sch.END_DATE IS NULL OR sch.END_DATE>=acc.SCHOOL_DATE )  LEFT JOIN attendance_completed ac ON ac.SCHOOL_DATE=acc.SCHOOL_DATE AND IF(tra.course_period_id=cp.course_period_id AND acc.school_date<tra.assign_date =true,ac.staff_id=tra.pre_teacher_id,ac.staff_id=cp.teacher_id) AND ac.PERIOD_ID=sp.PERIOD_ID WHERE acc.SYEAR=year AND acc.SCHOOL_ID=school AND (acc.MINUTES IS NOT NULL AND acc.MINUTES>0) AND acc.SCHOOL_DATE=sch_dt AND ac.STAFF_ID IS NULL GROUP BY s.TITLE,acc.SCHOOL_DATE,cp.TITLE,cp.COURSE_PERIOD_ID,cp.TEACHER_ID;\r\nEND\$\$\r\n\r\nCREATE PROCEDURE `SEAT_COUNT`() \r\nBEGIN\r\nUPDATE course_periods SET filled_seats=filled_seats-1 WHERE COURSE_PERIOD_ID IN (SELECT COURSE_PERIOD_ID FROM schedule WHERE end_date IS NOT NULL AND end_date < CURDATE() AND dropped='N');\r\nUPDATE schedule SET dropped='Y' WHERE end_date IS NOT NULL AND end_date < CURDATE() AND dropped='N';\r\nEND\$\$\r\n\r\nCREATE PROCEDURE `SEAT_FILL`() \r\nBEGIN\r\nUPDATE course_periods SET filled_seats=filled_seats+1 WHERE COURSE_PERIOD_ID IN (SELECT COURSE_PERIOD_ID FROM schedule WHERE dropped='Y' AND ( end_date IS NULL OR end_date >= CURDATE()));\r\nUPDATE schedule SET dropped='N' WHERE dropped='Y' AND ( end_date IS NULL OR end_date >= CURDATE()) ;\r\nEND\$\$\r\n\r\nCREATE PROCEDURE `TEACHER_REASSIGNMENT`()\r\nBEGIN\r\nUPDATE course_periods cp,course_period_var cpv,teacher_reassignment tr,school_periods sp,marking_periods mp,staff st SET cp.title=CONCAT(sp.title,IF(cp.mp<>'FY',CONCAT(' - ',mp.short_name),''),IF(CHAR_LENGTH(cpv.days)<5,CONCAT(' - ',cpv.days),''),' - ',cp.short_name,' - ',CONCAT_WS(' ',st.first_name,st.middle_name,st.last_name)), cp.teacher_id=tr.teacher_id WHERE cpv.period_id=sp.period_id and cp.marking_period_id=mp.marking_period_id and st.staff_id=tr.teacher_id and cp.course_period_id=tr.course_period_id AND assign_date <= CURDATE() AND updated='N' AND cp.COURSE_PERIOD_ID=cpv.COURSE_PERIOD_ID; \r\n UPDATE teacher_reassignment SET updated='Y' WHERE assign_date <=CURDATE() AND updated='N';\r\n END\$\$\r\n\r\n--\r\n-- functions\r\n--\r\nCREATE FUNCTION `CALC_CUM_GPA_MP`(\r\nmp_id int\r\n) RETURNS int(11)\r\nBEGIN\r\n\r\nDECLARE req_mp INT DEFAULT 0;\r\nDECLARE done INT DEFAULT 0;\r\nDECLARE gp_points DECIMAL(10,2);\r\nDECLARE student_id INT;\r\nDECLARE gp_points_weighted DECIMAL(10,2);\r\nDECLARE divisor DECIMAL(10,2);\r\nDECLARE credit_earned DECIMAL(10,2);\r\nDECLARE cgpa DECIMAL(10,2);\r\n\r\nDECLARE cur1 CURSOR FOR\r\n   SELECT srcg.student_id,\r\n                  IF(ISNULL(sum(srcg.unweighted_gp)),  (SUM(srcg.weighted_gp*srcg.credit_earned)),\r\n                      IF(ISNULL(sum(srcg.weighted_gp)), SUM(srcg.unweighted_gp*srcg.credit_earned),\r\n                         ( SUM(srcg.unweighted_gp*srcg.credit_attempted)+ SUM(srcg.weighted_gp*srcg.credit_earned))\r\n                        ))as gp_points,\r\n\r\n                      SUM(srcg.weighted_gp*srcg.credit_earned) as gp_points_weighted,\r\n                      SUM(srcg.credit_attempted) as divisor,\r\n                      SUM(srcg.credit_earned) as credit_earned,\r\n   \t\t      IF(ISNULL(sum(srcg.unweighted_gp)),  (SUM(srcg.weighted_gp*srcg.credit_earned))/ sum(srcg.credit_attempted),\r\n                          IF(ISNULL(sum(srcg.weighted_gp)), SUM(srcg.unweighted_gp*srcg.credit_earned)/sum(srcg.credit_attempted),\r\n                             ( SUM(srcg.unweighted_gp*srcg.credit_attempted)+ SUM(srcg.weighted_gp*srcg.credit_earned))/sum(srcg.credit_attempted)\r\n                            )\r\n                         ) as cgpa\r\n\r\n            FROM marking_periods mp,temp_cum_gpa srcg\r\n            INNER JOIN schools sc ON sc.id=srcg.school_id\r\n            WHERE srcg.marking_period_id= mp.marking_period_id AND srcg.gp_scale<>0 AND srcg.marking_period_id NOT LIKE 'E%'\r\n            AND mp.marking_period_id IN (SELECT marking_period_id  FROM marking_periods WHERE mp_type=req_mp )\r\n            GROUP BY srcg.student_id;\r\n DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;\r\n\r\n\r\n  CREATE TEMPORARY TABLE tmp(\r\n    student_id int,\r\n    sum_weighted_factors decimal(10,6),\r\n    count_weighted_factors int,\r\n    sum_unweighted_factors decimal(10,6),\r\n    count_unweighted_factors int,\r\n    grade_level_short varchar(10)\r\n  );\r\n\r\n  INSERT INTO tmp(student_id,sum_weighted_factors,count_weighted_factors,\r\n    sum_unweighted_factors, count_unweighted_factors,grade_level_short)\r\n  SELECT\r\n    srcg.student_id,\r\n    SUM(srcg.weighted_gp/s.reporting_gp_scale) AS sum_weighted_factors,\r\n    COUNT(*) AS count_weighted_factors,\r\n    SUM(srcg.unweighted_gp/srcg.gp_scale) AS sum_unweighted_factors,\r\n    COUNT(*) AS count_unweighted_factors,\r\n    eg.short_name\r\n  FROM student_report_card_grades srcg\r\n  INNER JOIN schools s ON s.id=srcg.school_id\r\n  LEFT JOIN enroll_grade eg on eg.student_id=srcg.student_id AND eg.syear=srcg.syear AND eg.school_id=srcg.school_id\r\n  WHERE srcg.marking_period_id=mp_id AND srcg.gp_scale<>0 AND srcg.marking_period_id NOT LIKE 'E%'\r\n  GROUP BY srcg.student_id,eg.short_name;\r\n\r\n  INSERT INTO student_gpa_calculated (student_id,marking_period_id)\r\n  SELECT\r\n      t.student_id,\r\n      mp_id\r\n    FROM tmp t\r\n    LEFT JOIN student_gpa_calculated sms ON sms.student_id=t.student_id AND sms.marking_period_id=mp_id\r\n    WHERE sms.student_id IS NULL;\r\n\r\n  UPDATE student_gpa_calculated g\r\n    INNER JOIN (\r\n\tSELECT s.student_id,\r\n\t\tSUM(s.weighted_gp/sc.reporting_gp_scale)/COUNT(*) AS cum_weighted_factor,\r\n\t\tSUM(s.unweighted_gp/s.gp_scale)/COUNT(*) AS cum_unweighted_factor\r\n\tFROM student_report_card_grades s\r\n\tINNER JOIN schools sc ON sc.id=s.school_id\r\n\tLEFT JOIN course_periods p ON p.course_period_id=s.course_period_id\r\n\tWHERE p.marking_period_id IS NULL OR p.marking_period_id=s.marking_period_id\r\n\tGROUP BY student_id) gg ON gg.student_id=g.student_id\r\n    SET g.cum_unweighted_factor=gg.cum_unweighted_factor;\r\n\r\n\r\n    SELECT mp_type INTO @mp_type FROM marking_periods WHERE marking_period_id=mp_id;\r\n\r\n \r\n    IF @mp_type = 'quarter'  THEN\r\n           set req_mp = 'quarter';\r\n    ELSEIF @mp_type = 'semester'  THEN\r\n        IF EXISTS(SELECT student_id FROM student_report_card_grades srcg WHERE srcg.marking_period_id IN (SELECT marking_period_id  FROM marking_periods WHERE mp_type=@mp_type)) THEN\r\n           set req_mp  = 'semester';\r\n       ELSE\r\n           set req_mp  = 'quarter';\r\n        END IF;\r\n   ELSEIF @mp_type = 'year'  THEN\r\n           IF EXISTS(SELECT student_id FROM student_report_card_grades srcg WHERE srcg.MARKING_PERIOD_ID IN (SELECT marking_period_id  FROM marking_periods WHERE mp_type='semester')\r\n                     UNION  SELECT student_id FROM student_report_card_grades srcg WHERE srcg.MARKING_PERIOD_ID IN (SELECT marking_period_id  FROM history_marking_periods WHERE mp_type='semester')\r\n                     ) THEN\r\n                 set req_mp  = 'semester';\r\n         \r\n          ELSE\r\n                  set req_mp  = 'quarter ';\r\n            END IF;\r\n   END IF;\r\n\r\n\r\n\r\nopen cur1;\r\nfetch cur1 into student_id, gp_points,gp_points_weighted,divisor,credit_earned,cgpa;\r\n\r\nwhile not done DO\r\n    IF EXISTS(SELECT student_id FROM student_gpa_calculated WHERE  student_gpa_calculated.student_id=student_id) THEN\r\n    UPDATE student_gpa_calculated gc\r\n               SET gc.cgpa=cgpa where gc.student_id=student_id and gc.marking_period_id=mp_id;\r\n    ELSE\r\n        INSERT INTO student_gpa_running(student_id,marking_period_id,mp,cgpa)\r\n          VALUES(student_id,mp_id,mp_id,cgpa);\r\n    END IF;\r\nfetch cur1 into student_id, gp_points,gp_points_weighted,divisor,credit_earned,cgpa;\r\nEND WHILE;\r\nCLOSE cur1;\r\n\r\n\r\nRETURN 1;\r\n\r\nEND\$\$\r\n\r\nCREATE FUNCTION `CALC_GPA_MP`(\r\n\ts_id int,\r\n\tmp_id int\r\n) RETURNS int(11)\r\nBEGIN\r\n  SELECT\r\n    SUM(srcg.weighted_gp/s.reporting_gp_scale) AS sum_weighted_factors, \r\n    COUNT(*) AS count_weighted_factors,                        \r\n    SUM(srcg.unweighted_gp/srcg.gp_scale) AS sum_unweighted_factors, \r\n    COUNT(*) AS count_unweighted_factors,\r\n   IF(ISNULL(sum(srcg.unweighted_gp)),  (SUM(srcg.weighted_gp*srcg.credit_earned))/ sum(srcg.credit_attempted),\r\n                      IF(ISNULL(sum(srcg.weighted_gp)), SUM(srcg.unweighted_gp*srcg.credit_earned)/sum(srcg.credit_attempted),\r\n                         ( SUM(srcg.unweighted_gp*srcg.credit_attempted)+ SUM(srcg.weighted_gp*srcg.credit_earned))/sum(srcg.credit_attempted)\r\n                        )\r\n      ),\r\n    \r\n    SUM(srcg.weighted_gp*srcg.credit_earned)/(select sum(sg.credit_attempted) from student_report_card_grades sg where sg.marking_period_id=mp_id AND sg.student_id=s_id\r\n                                                  AND sg.weighted_gp  IS NOT NULL  AND sg.unweighted_gp IS NULL AND sg.course_period_id IS NOT NULL GROUP BY sg.student_id, sg.marking_period_id) ,\r\n    SUM(srcg.unweighted_gp*srcg.credit_earned)/ (select sum(sg.credit_attempted) from student_report_card_grades sg where sg.marking_period_id=mp_id AND sg.student_id=s_id\r\n                                                     AND sg.unweighted_gp  IS NOT NULL  AND sg.weighted_gp IS NULL AND sg.course_period_id IS NOT NULL GROUP BY sg.student_id, sg.marking_period_id) ,\r\n    eg.short_name\r\n  INTO\r\n    @sum_weighted_factors,\r\n    @count_weighted_factors,\r\n    @sum_unweighted_factors,\r\n    @count_unweighted_factors,\r\n    @gpa,\r\n    @weighted_gpa,\r\n    @unweighted_gpa,\r\n    @grade_level_short\r\n  FROM student_report_card_grades srcg\r\n  INNER JOIN schools s ON s.id=srcg.school_id\r\nINNER JOIN course_periods cp ON cp.course_period_id=srcg.course_period_id\r\nINNER JOIN report_card_grade_scales rcgs ON rcgs.id=cp.grade_scale_id\r\n  LEFT JOIN enroll_grade eg on eg.student_id=srcg.student_id AND eg.syear=srcg.syear AND eg.school_id=srcg.school_id\r\n  WHERE srcg.marking_period_id=mp_id AND srcg.student_id=s_id AND srcg.gp_scale<>0 AND srcg.course_period_id IS NOT NULL AND (rcgs.gpa_cal='Y' OR cp.grade_scale_id IS NULL) AND srcg.marking_period_id NOT LIKE 'E%'\r\n  AND (eg.START_DATE IS NULL OR eg.START_DATE='0000-00-00'  OR eg.START_DATE<=CURDATE()) AND (eg.END_DATE IS NULL OR eg.END_DATE='0000-00-00'  OR eg.END_DATE>=CURDATE())  \r\n  GROUP BY srcg.student_id,eg.short_name;\r\n\r\n\r\n  IF NOT EXISTS(SELECT NULL FROM student_gpa_calculated WHERE marking_period_id=mp_id AND student_id=s_id) THEN\r\n    INSERT INTO student_gpa_calculated (student_id,marking_period_id)\r\n      VALUES(s_id,mp_id);\r\n  END IF;\r\n\r\n  UPDATE student_gpa_calculated g\r\n    INNER JOIN (\r\n\tSELECT s.student_id,\r\n\t\tSUM(s.unweighted_gp/s.gp_scale)/COUNT(*) AS cum_unweighted_factor\r\n\tFROM student_report_card_grades s\r\n\tINNER JOIN schools sc ON sc.id=s.school_id\r\n\tLEFT JOIN course_periods p ON p.course_period_id=s.course_period_id\r\n\tWHERE s.course_period_id IS NOT NULL AND p.marking_period_id IS NULL OR p.marking_period_id=s.marking_period_id\r\n\tGROUP BY student_id) gg ON gg.student_id=g.student_id\r\n    SET g.cum_unweighted_factor=gg.cum_unweighted_factor\r\n    WHERE g.student_id=s_id;\r\n\r\nIF EXISTS(SELECT student_id FROM student_gpa_calculated WHERE marking_period_id=mp_id AND student_id=s_id) THEN\r\n    UPDATE student_gpa_calculated\r\n    SET\r\n      gpa            = @gpa,\r\n      weighted_gpa   =@weighted_gpa,\r\n      unweighted_gpa =@unweighted_gpa\r\n\r\n    WHERE marking_period_id=mp_id AND student_id=s_id;\r\n  ELSE\r\n        INSERT INTO student_gpa_calculated(student_id,marking_period_id,mp,gpa,weighted_gpa,unweighted_gpa,grade_level_short)\r\n            VALUES(s_id,mp_id,mp_id,@gpa,@weighted_gpa,@unweighted_gpa,@grade_level_short  );\r\n                   \r\n\r\n   END IF;\r\n\r\n  RETURN 0;\r\n END\$\$\r\n\r\nCREATE FUNCTION `CREDIT`(\r\n \tcp_id int,\r\n \tmp_id int\r\n ) RETURNS decimal(10,3)\r\nBEGIN\r\n  SELECT credits,IF(ISNULL(marking_period_id),'Y',marking_period_id),mp INTO @credits,@marking_period_id,@mp FROM course_periods WHERE course_period_id=cp_id;\r\n   SELECT mp_type INTO @mp_type FROM marking_periods WHERE marking_period_id=mp_id;\r\n  \r\nIF @marking_period_id='Y' THEN \r\nRETURN @credits;\r\n   ELSEIF   @marking_period_id=mp_id THEN\r\n    RETURN @credits;\r\nELSEIF @mp = 'QTR' AND @mp_type = 'semester' THEN\r\n     RETURN @credits;\r\n   ELSEIF @mp='FY' AND @mp_type='semester' THEN\r\n     SELECT COUNT(*) INTO @val FROM marking_periods WHERE parent_id=@marking_period_id GROUP BY parent_id;\r\n   ELSEIF @mp = 'FY' AND @mp_type = 'quarter' THEN\r\n     SELECT count(*) into @val FROM marking_periods WHERE grandparent_id=@marking_period_id GROUP BY grandparent_id;\r\n   ELSEIF @mp = 'SEM' AND @mp_type = 'quarter' THEN\r\n     SELECT count(*) into @val FROM marking_periods WHERE parent_id=@marking_period_id GROUP BY parent_id;\r\n   ELSE\r\n     RETURN 0;\r\n   END IF;\r\n   IF @val > 0 THEN\r\n     RETURN @credits/@val;\r\n   END IF;\r\n   RETURN 0;\r\nEND\$\$\r\n\r\nCREATE FUNCTION fn_marking_period_seq () RETURNS INT\r\nBEGIN\r\n  INSERT INTO marking_period_id_generator VALUES(NULL);\r\nRETURN LAST_INSERT_ID();\r\nEND\$\$\r\n\r\nCREATE FUNCTION `SET_CLASS_RANK_MP`(\r\n\tmp_id int\r\n) RETURNS int(11)\r\nBEGIN\r\n\r\nDECLARE done INT DEFAULT 0;\r\nDECLARE marking_period_id INT;\r\nDECLARE student_id INT;\r\nDECLARE rank NUMERIC;\r\n\r\ndeclare cur1 cursor for\r\nselect\r\n  mp.marking_period_id,\r\n  sgc.student_id,\r\n (select count(*)+1 \r\n   from student_gpa_calculated sgc3\r\n   where sgc3.gpa > sgc.gpa\r\n     and sgc3.marking_period_id = mp.marking_period_id \r\n     and sgc3.student_id in (select distinct sgc2.student_id \r\n                                                from student_gpa_calculated sgc2, student_enrollment se2\r\n                                                where sgc2.student_id = se2.student_id \r\n                                                and sgc2.marking_period_id = mp.marking_period_id \r\n                                                and se2.grade_id = se.grade_id\r\n                                                and se2.syear = se.syear\r\n                                                group by gpa\r\n                                )\r\n  ) as rank\r\n  from student_enrollment se, student_gpa_calculated sgc, marking_periods mp\r\n  where se.student_id = sgc.student_id\r\n    and sgc.marking_period_id = mp.marking_period_id\r\n    and mp.marking_period_id = mp_id\r\n    and se.syear = mp.syear\r\n    and not sgc.gpa is null\r\n  order by grade_id, rank;\r\nDECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;\r\n\r\nopen cur1;\r\nfetch cur1 into marking_period_id,student_id,rank;\r\n\r\nwhile not done DO\r\n\tupdate student_gpa_calculated sgc\r\n\t  set\r\n\t    class_rank = rank\r\n\twhere sgc.marking_period_id = marking_period_id\r\n\t  and sgc.student_id = student_id;\r\n\tfetch cur1 into marking_period_id,student_id,rank;\r\nEND WHILE;\r\nCLOSE cur1;\r\n\r\nRETURN 1;\r\nEND\$\$\r\n\r\nCREATE FUNCTION `STUDENT_DISABLE`(\r\nstu_id int\r\n) RETURNS int(1)\r\nBEGIN\r\nUPDATE students set is_disable ='Y' where (select end_date from student_enrollment where  student_id=stu_id ORDER BY id DESC LIMIT 1) IS NOT NULL AND (select end_date from student_enrollment where  student_id=stu_id ORDER BY id DESC LIMIT 1)< CURDATE() AND  student_id=stu_id;\r\nRETURN 1;\r\nEND\$\$\r\n\r\nCREATE FUNCTION `RE_CALC_GPA_MP`(\r\n\ts_id int,\r\n\tmp_id int,\r\n        sy int,\r\n        sch_id int\r\n) RETURNS int(11)\r\nBEGIN\r\n  SELECT\r\n    SUM(srcg.weighted_gp/s.reporting_gp_scale) AS sum_weighted_factors, \r\n    COUNT(*) AS count_weighted_factors,                        \r\n    SUM(srcg.unweighted_gp/srcg.gp_scale) AS sum_unweighted_factors, \r\n    COUNT(*) AS count_unweighted_factors,\r\n   IF(ISNULL(sum(srcg.unweighted_gp)),  (SUM(srcg.weighted_gp*srcg.credit_earned))/ sum(srcg.credit_attempted),\r\n                      IF(ISNULL(sum(srcg.weighted_gp)), SUM(srcg.unweighted_gp*srcg.credit_earned)/sum(srcg.credit_attempted),\r\n                         ( SUM(srcg.unweighted_gp*srcg.credit_attempted)+ SUM(srcg.weighted_gp*srcg.credit_earned))/sum(srcg.credit_attempted)\r\n                        )\r\n      ),\r\n    \r\n    SUM(srcg.weighted_gp*srcg.credit_earned)/(select sum(sg.credit_attempted) from student_report_card_grades sg where sg.marking_period_id=mp_id AND sg.student_id=s_id\r\n                                                  AND sg.weighted_gp  IS NOT NULL  AND sg.unweighted_gp IS NULL GROUP BY sg.student_id, sg.marking_period_id) ,\r\n    SUM(srcg.unweighted_gp*srcg.credit_earned)/ (select sum(sg.credit_attempted) from student_report_card_grades sg where sg.marking_period_id=mp_id AND sg.student_id=s_id\r\n                                                     AND sg.unweighted_gp  IS NOT NULL  AND sg.weighted_gp IS NULL GROUP BY sg.student_id, sg.marking_period_id) ,\r\n    eg.short_name\r\n  INTO\r\n    @sum_weighted_factors,\r\n    @count_weighted_factors,\r\n    @sum_unweighted_factors,\r\n    @count_unweighted_factors,\r\n    @gpa,\r\n    @weighted_gpa,\r\n    @unweighted_gpa,\r\n    @grade_level_short\r\n  FROM student_report_card_grades srcg\r\n  INNER JOIN schools s ON s.id=srcg.school_id\r\n  LEFT JOIN enroll_grade eg on eg.student_id=srcg.student_id AND eg.syear=srcg.syear AND eg.school_id=srcg.school_id\r\n  WHERE srcg.marking_period_id=mp_id AND srcg.student_id=s_id AND srcg.gp_scale<>0 AND srcg.school_id=sch_id AND srcg.syear=sy AND srcg.marking_period_id NOT LIKE 'E%'\r\nAND (eg.START_DATE IS NULL OR eg.START_DATE='0000-00-00'  OR eg.START_DATE<=CURDATE()) AND (eg.END_DATE IS NULL OR eg.END_DATE='0000-00-00'  OR eg.END_DATE>=CURDATE())\r\n  GROUP BY srcg.student_id,eg.short_name;\r\n\r\n  \r\n\r\n  IF NOT EXISTS(SELECT NULL FROM student_gpa_calculated WHERE marking_period_id=mp_id AND student_id=s_id) THEN\r\n    INSERT INTO student_mp_stats(student_id,marking_period_id)\r\n      VALUES(s_id,mp_id);\r\n  END IF;\r\n\r\n  UPDATE student_gpa_calculated g\r\n    INNER JOIN (\r\n\tSELECT s.student_id,\r\n\t\tSUM(s.unweighted_gp/s.gp_scale)/COUNT(*) AS cum_unweighted_factor\r\n\tFROM student_report_card_grades s\r\n\tINNER JOIN schools sc ON sc.id=s.school_id\r\n\tLEFT JOIN course_periods p ON p.course_period_id=s.course_period_id\r\n\tWHERE p.marking_period_id IS NULL OR p.marking_period_id=s.marking_period_id\r\n\tGROUP BY student_id) gg ON gg.student_id=g.student_id\r\n    SET g.cum_unweighted_factor=gg.cum_unweighted_factor\r\n    WHERE g.student_id=s_id;\r\n\r\nIF EXISTS(SELECT student_id FROM student_gpa_calculated WHERE marking_period_id=mp_id AND student_id=s_id) THEN\r\n    UPDATE student_gpa_calculated\r\n    SET\r\n      gpa            = @gpa,\r\n      weighted_gpa   =@weighted_gpa,\r\n      unweighted_gpa =@unweighted_gpa\r\n\r\n    WHERE marking_period_id=mp_id AND student_id=s_id;\r\n  ELSE\r\n        INSERT INTO student_gpa_calculated(student_id,marking_period_id,mp,gpa,weighted_gpa,unweighted_gpa,grade_level_short)\r\n            VALUES(s_id,mp_id,mp_id,@gpa,@weighted_gpa,@unweighted_gpa,@grade_level_short  );\r\n                   \r\n\r\n   END IF;\r\n\r\n  RETURN 0;\r\nEND\$\$\r\nDELIMITER ;\r\n-- --------------------------------------------------------\n\r\n";
        echo "--\r\n-- Triggers `STUDENT_REPORT_CARD_GRADES`\r\n--\r\nDROP TRIGGER IF EXISTS `td_student_report_card_grades`;\r\nDELIMITER \$\$\r\nCREATE TRIGGER `td_student_report_card_grades`\r\n    AFTER DELETE ON student_report_card_grades\r\n    FOR EACH ROW\r\n\tSELECT CALC_GPA_MP(OLD.student_id, OLD.marking_period_id) INTO @return\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS `ti_student_report_card_grades`;\r\nDELIMITER \$\$\r\nCREATE TRIGGER `ti_student_report_card_grades`\r\n    AFTER INSERT ON student_report_card_grades\r\n    FOR EACH ROW\r\n\tSELECT CALC_GPA_MP(NEW.student_id, NEW.marking_period_id) INTO @return\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS `tu_student_report_card_grades`;\r\nDELIMITER \$\$\r\nCREATE TRIGGER `tu_student_report_card_grades`\r\n    AFTER UPDATE ON student_report_card_grades\r\n    FOR EACH ROW\r\n\tSELECT CALC_GPA_MP(NEW.student_id, NEW.marking_period_id) INTO @return\$\$\r\nDELIMITER ;\r\n\r\n\r\n\r\nDROP TRIGGER IF EXISTS tu_periods;\r\nCREATE TRIGGER tu_periods\r\n    AFTER UPDATE ON school_periods\r\n    FOR EACH ROW\r\n        UPDATE course_period_var SET start_time=NEW.start_time,end_time=NEW.end_time WHERE period_id=NEW.period_id;\r\n\r\nDROP TRIGGER IF EXISTS tu_school_years;\r\nCREATE TRIGGER tu_school_years\r\n    AFTER UPDATE ON school_years\r\n    FOR EACH ROW\r\n        UPDATE course_periods SET begin_date=NEW.start_date,end_date=NEW.end_date WHERE marking_period_id=NEW.marking_period_id;\r\n\r\nDROP TRIGGER IF EXISTS tu_school_semesters;\r\nCREATE TRIGGER tu_school_semesters\r\n    AFTER UPDATE ON school_semesters\r\n    FOR EACH ROW\r\n        UPDATE course_periods SET begin_date=NEW.start_date,end_date=NEW.end_date WHERE marking_period_id=NEW.marking_period_id;\r\n\r\nDROP TRIGGER IF EXISTS tu_school_quarters;\r\nCREATE TRIGGER tu_school_quarters\r\n    AFTER UPDATE ON school_quarters\r\n    FOR EACH ROW\r\n        UPDATE course_periods SET begin_date=NEW.start_date,end_date=NEW.end_date WHERE marking_period_id=NEW.marking_period_id;\r\n\r\nDROP TRIGGER IF EXISTS ti_course_period_var;\r\nCREATE TRIGGER ti_course_period_var\r\n    AFTER INSERT ON course_period_var\r\n    FOR EACH ROW\r\n\tCALL ATTENDANCE_CALC(NEW.course_period_id);\r\n\r\nDROP TRIGGER IF EXISTS tu_course_period_var;\r\nCREATE TRIGGER tu_course_period_var\r\n    AFTER UPDATE ON course_period_var\r\n    FOR EACH ROW\r\n\tCALL ATTENDANCE_CALC(NEW.course_period_id);\r\n\r\nDROP TRIGGER IF EXISTS td_course_period_var;\r\nCREATE TRIGGER td_course_period_var\r\n    AFTER DELETE ON course_period_var\r\n    FOR EACH ROW\r\n\tCALL ATTENDANCE_CALC(OLD.course_period_id);\r\n\r\nDROP TRIGGER IF EXISTS tu_course_periods;\r\nDELIMITER \$\$\r\nCREATE TRIGGER tu_course_periods\r\n    AFTER UPDATE ON course_periods\r\n    FOR EACH ROW\r\n    BEGIN\r\n\tCALL ATTENDANCE_CALC(NEW.course_period_id);\r\n    END\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS td_course_periods;\r\nDELIMITER \$\$\r\nCREATE TRIGGER td_course_periods\r\n    AFTER DELETE ON course_periods\r\n    FOR EACH ROW\r\n    BEGIN\r\n\tDELETE FROM course_period_var WHERE course_period_id=OLD.course_period_id;\r\n    END\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS ti_schdule;\r\nDELIMITER \$\$\r\nCREATE TRIGGER ti_schdule\r\n    AFTER INSERT ON schedule\r\n    FOR EACH ROW\r\n    BEGIN\r\n        UPDATE course_periods SET filled_seats=filled_seats+1 WHERE course_period_id=NEW.course_period_id;\r\n\tCALL ATTENDANCE_CALC(NEW.course_period_id);\r\n    END\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS tu_schedule;\r\nCREATE TRIGGER tu_schedule\r\n    AFTER UPDATE ON schedule\r\n    FOR EACH ROW\r\n\tCALL ATTENDANCE_CALC(NEW.course_period_id);\r\n\r\nDROP TRIGGER IF EXISTS td_schedule;\r\nDELIMITER \$\$\r\nCREATE TRIGGER td_schedule\r\n    AFTER DELETE ON schedule\r\n    FOR EACH ROW\r\n    BEGIN\r\n        UPDATE course_periods SET filled_seats=filled_seats-1 WHERE course_period_id=OLD.course_period_id AND OLD.dropped='N';\r\n\tCALL ATTENDANCE_CALC(OLD.course_period_id);\r\n    END\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS `ti_cal_missing_attendance`;\r\nDELIMITER \$\$\r\nCREATE TRIGGER `ti_cal_missing_attendance`\r\n    AFTER INSERT ON attendance_calendar\r\n    FOR EACH ROW\r\n    BEGIN\r\n    DECLARE associations INT;\r\n    SET associations = (SELECT COUNT(course_period_id) FROM `course_periods` WHERE calendar_id=NEW.calendar_id);\r\n    IF associations>0 THEN\r\n\tCALL ATTENDANCE_CALC_BY_DATE(NEW.school_date, NEW.syear,NEW.school_id);\r\n    END IF;\r\n    END\$\$\r\nDELIMITER ;\r\n\r\nDROP TRIGGER IF EXISTS `td_cal_missing_attendance`;\r\nCREATE TRIGGER `td_cal_missing_attendance`\r\n    AFTER DELETE ON attendance_calendar\r\n    FOR EACH ROW\r\n\tDELETE mi.* FROM missing_attendance mi,course_periods cp WHERE mi.course_period_id=cp.course_period_id and cp.calendar_id=OLD.calendar_id AND mi.SCHOOL_DATE=OLD.school_date;\r\n-- --------------------------------------------------------";
    } else {
        echo "/* no tables in {$mysql_database} \n";
    }
    mysql_free_result($result);
}
Exemplo n.º 4
0
function _mysqldump($mysql_database)
{
    $sonuc = "SET NAMES 'latin1';\n";
    $sonuc .= "SET CHARACTER SET latin1;\n";
    $sonuc .= "SET COLLATION_CONNECTION = 'latin1_swedish_ci';\n";
    $sonuc .= "/*For Turkish Settings*/\n\n";
    $sql = "SHOW TABLES IN {$mysql_database} LIKE 'eo_%'";
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_row($result)) {
            $sonuc .= _mysqldump_table_structure($row[0]);
            $sonuc .= _mysqldump_table_data($row[0]);
        }
    } else {
        $sonuc .= "/* no tables in {$mysql_database} */\n";
    }
    mysql_free_result($result);
    return $sonuc;
}
Exemplo n.º 5
0
function mysqldump($filename)
{
    $h = fopen($filename, 'w');
    $sql = "show tables;";
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_row($result)) {
            _mysqldump_table_structure($row[0], $h);
            _mysqldump_table_data($row[0], $h);
        }
    } else {
        echo "/* no tables in {$mysql_database} */\n";
    }
    mysql_free_result($result);
    fclose($h);
}