diff --git a/Makefile b/Makefile index d983a14c..8ec3e415 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \ swad_connected.o swad_connected_database.o swad_cookie.o \ swad_cookie_database.o swad_country.o swad_country_config.o \ swad_country_database.o swad_course.o swad_course_config.o \ - swad_cryptography.o \ + swad_course_database.o swad_cryptography.o \ swad_database.o swad_date.o swad_degree.o swad_degree_config.o \ swad_degree_type.o swad_department.o swad_duplicate.o \ swad_enrolment.o swad_error.o swad_exam.o swad_exam_log.o \ diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index 767e1bdd..70fd075a 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -1174,470 +1174,470 @@ static void Cfe_ShowCallForExam (struct Cfe_CallsForExams *CallsForExams, Cfe_PutHiddenParamExaCod (ExaCod); } - /***** Begin table *****/ - HTM_TABLE_Begin ("%s CELLS_PAD_2", - ClassCallForExam[TypeViewCallForExam][CallsForExams->CallForExam.Status]); + /***** Begin table *****/ + HTM_TABLE_Begin ("%s CELLS_PAD_2", + ClassCallForExam[TypeViewCallForExam][CallsForExams->CallForExam.Status]); - /***** Institution logo *****/ - HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"2\" class=\"CM\""); - if (TypeViewCallForExam == Cfe_PRINT_VIEW) - HTM_SPAN_Begin ("class=\"EXAM_TIT\""); - else - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"EXAM_TIT\"", - Ins.WWW); - Lgo_DrawLogo (Hie_Lvl_INS,Ins.InsCod,Ins.FullName,64,NULL,true); - HTM_BR (); - HTM_Txt (Ins.FullName); - if (TypeViewCallForExam == Cfe_PRINT_VIEW) - HTM_SPAN_End (); - else - HTM_A_End (); - HTM_TD_End (); - HTM_TR_End (); + /***** Institution logo *****/ + HTM_TR_Begin (NULL); + HTM_TD_Begin ("colspan=\"2\" class=\"CM\""); + if (TypeViewCallForExam == Cfe_PRINT_VIEW) + HTM_SPAN_Begin ("class=\"EXAM_TIT\""); + else + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"EXAM_TIT\"", + Ins.WWW); + Lgo_DrawLogo (Hie_Lvl_INS,Ins.InsCod,Ins.FullName,64,NULL,true); + HTM_BR (); + HTM_Txt (Ins.FullName); + if (TypeViewCallForExam == Cfe_PRINT_VIEW) + HTM_SPAN_End (); + else + HTM_A_End (); + HTM_TD_End (); + HTM_TR_End (); - /***** Degree *****/ - HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"2\" class=\"EXAM_TIT CM\""); - if (TypeViewCallForExam == Cfe_NORMAL_VIEW) - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"EXAM_TIT\"", - Gbl.Hierarchy.Deg.WWW); - HTM_Txt (Gbl.Hierarchy.Deg.FullName); - if (TypeViewCallForExam == Cfe_NORMAL_VIEW) - HTM_A_End (); - HTM_TD_End (); - HTM_TR_End (); + /***** Degree *****/ + HTM_TR_Begin (NULL); + HTM_TD_Begin ("colspan=\"2\" class=\"EXAM_TIT CM\""); + if (TypeViewCallForExam == Cfe_NORMAL_VIEW) + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"EXAM_TIT\"", + Gbl.Hierarchy.Deg.WWW); + HTM_Txt (Gbl.Hierarchy.Deg.FullName); + if (TypeViewCallForExam == Cfe_NORMAL_VIEW) + HTM_A_End (); + HTM_TD_End (); + HTM_TR_End (); - /***** Title *****/ - HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"2\" class=\"EXAM CM\""); - HTM_NBSP (); - HTM_BR (); - HTM_STRONG_Begin (); - HTM_Txt (Txt_CALL_FOR_EXAM); - HTM_STRONG_End (); - HTM_TD_End (); - HTM_TR_End (); + /***** Title *****/ + HTM_TR_Begin (NULL); + HTM_TD_Begin ("colspan=\"2\" class=\"EXAM CM\""); + HTM_NBSP (); + HTM_BR (); + HTM_STRONG_Begin (); + HTM_Txt (Txt_CALL_FOR_EXAM); + HTM_STRONG_End (); + HTM_TD_End (); + HTM_TR_End (); - HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"2\" class=\"EXAM LM\""); - HTM_NBSP (); - HTM_TD_End (); - HTM_TR_End (); + HTM_TR_Begin (NULL); + HTM_TD_Begin ("colspan=\"2\" class=\"EXAM LM\""); + HTM_NBSP (); + HTM_TD_End (); + HTM_TR_End (); - /***** Name of the course *****/ - HTM_TR_Begin (NULL); + /***** Name of the course *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "CrsName" : - NULL, - Txt_CALL_FOR_EXAM_Course); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "CrsName" : + NULL, + Txt_CALL_FOR_EXAM_Course); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - HTM_INPUT_TEXT ("CrsName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,CallsForExams->CallForExam.CrsFullName, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"CrsName\" size=\"30\""); - else - { - HTM_STRONG_Begin (); - HTM_Txt (CallsForExams->CallForExam.CrsFullName); - HTM_STRONG_End (); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + HTM_INPUT_TEXT ("CrsName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,CallsForExams->CallForExam.CrsFullName, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"CrsName\" size=\"30\""); + else + { + HTM_STRONG_Begin (); + HTM_Txt (CallsForExams->CallForExam.CrsFullName); + HTM_STRONG_End (); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Year/semester (N.A., 1º, 2º, 3º, 4º, 5º...) *****/ - HTM_TR_Begin (NULL); + /***** Year/semester (N.A., 1º, 2º, 3º, 4º, 5º...) *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "Year" : - NULL, - Txt_CALL_FOR_EXAM_Year_or_semester); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "Year" : + NULL, + Txt_CALL_FOR_EXAM_Year_or_semester); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"Year\" name=\"Year\""); - for (Year = 0; - Year <= Deg_MAX_YEARS_PER_DEGREE; - Year++) - HTM_OPTION (HTM_Type_UNSIGNED,&Year, - CallsForExams->CallForExam.Year == Year,false, - "%s",Txt_YEAR_OF_DEGREE[Year]); - HTM_SELECT_End (); - } - else - HTM_Txt (Txt_YEAR_OF_DEGREE[CallsForExams->CallForExam.Year]); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"Year\" name=\"Year\""); + for (Year = 0; + Year <= Deg_MAX_YEARS_PER_DEGREE; + Year++) + HTM_OPTION (HTM_Type_UNSIGNED,&Year, + CallsForExams->CallForExam.Year == Year,false, + "%s",Txt_YEAR_OF_DEGREE[Year]); + HTM_SELECT_End (); + } + else + HTM_Txt (Txt_YEAR_OF_DEGREE[CallsForExams->CallForExam.Year]); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Exam session *****/ - HTM_TR_Begin (NULL); + /***** Exam session *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamSession" : - NULL, - Txt_CALL_FOR_EXAM_Session); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamSession" : + NULL, + Txt_CALL_FOR_EXAM_Session); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - HTM_INPUT_TEXT ("ExamSession",Cfe_MAX_CHARS_SESSION,CallsForExams->CallForExam.Session, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"ExamSession\" size=\"30\""); - else - HTM_Txt (CallsForExams->CallForExam.Session); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + HTM_INPUT_TEXT ("ExamSession",Cfe_MAX_CHARS_SESSION,CallsForExams->CallForExam.Session, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"ExamSession\" size=\"30\""); + else + HTM_Txt (CallsForExams->CallForExam.Session); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Date of the exam *****/ - HTM_TR_Begin (NULL); + /***** Date of the exam *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamYear" : - NULL, - Txt_CALL_FOR_EXAM_Exam_date); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamYear" : + NULL, + Txt_CALL_FOR_EXAM_Exam_date); - /* Data */ - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TD_Begin ("class=\"LB\""); - Dat_WriteFormDate (CallsForExams->CallForExam.ExamDate.Year < Gbl.Now.Date.Year ? CallsForExams->CallForExam.ExamDate.Year : - Gbl.Now.Date.Year, - Gbl.Now.Date.Year + 1,"Exam", - &(CallsForExams->CallForExam.ExamDate), - false,false); - HTM_TD_End (); - } - else - { - Dat_ConvDateToDateStr (&CallsForExams->CallForExam.ExamDate, - StrExamDate); - HTM_TD_Begin ("class=\"EXAM LB\""); - HTM_Txt (StrExamDate); - HTM_TD_End (); - } - HTM_TR_End (); + /* Data */ + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TD_Begin ("class=\"LB\""); + Dat_WriteFormDate (CallsForExams->CallForExam.ExamDate.Year < Gbl.Now.Date.Year ? CallsForExams->CallForExam.ExamDate.Year : + Gbl.Now.Date.Year, + Gbl.Now.Date.Year + 1,"Exam", + &(CallsForExams->CallForExam.ExamDate), + false,false); + HTM_TD_End (); + } + else + { + Dat_ConvDateToDateStr (&CallsForExams->CallForExam.ExamDate, + StrExamDate); + HTM_TD_Begin ("class=\"EXAM LB\""); + HTM_Txt (StrExamDate); + HTM_TD_End (); + } + HTM_TR_End (); - /***** Start time *****/ - HTM_TR_Begin (NULL); + /***** Start time *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamHour" : - NULL, - Txt_CALL_FOR_EXAM_Start_time); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamHour" : + NULL, + Txt_CALL_FOR_EXAM_Start_time); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"ExamHour\" name=\"ExamHour\""); - HTM_OPTION (HTM_Type_STRING,"0", - CallsForExams->CallForExam.StartTime.Hour == 0,false, - "-"); - for (Hour = 7; - Hour <= 22; - Hour++) - HTM_OPTION (HTM_Type_UNSIGNED,&Hour, - CallsForExams->CallForExam.StartTime.Hour == Hour,false, - "%02u %s",Hour,Txt_hours_ABBREVIATION); - HTM_SELECT_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"ExamHour\" name=\"ExamHour\""); + HTM_OPTION (HTM_Type_STRING,"0", + CallsForExams->CallForExam.StartTime.Hour == 0,false, + "-"); + for (Hour = 7; + Hour <= 22; + Hour++) + HTM_OPTION (HTM_Type_UNSIGNED,&Hour, + CallsForExams->CallForExam.StartTime.Hour == Hour,false, + "%02u %s",Hour,Txt_hours_ABBREVIATION); + HTM_SELECT_End (); - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "name=\"ExamMinute\""); - for (Minute = 0; - Minute <= 59; - Minute++) - HTM_OPTION (HTM_Type_UNSIGNED,&Minute, - CallsForExams->CallForExam.StartTime.Minute == Minute,false, - "%02u ′",Minute); - HTM_SELECT_End (); - } - else if (CallsForExams->CallForExam.StartTime.Hour) - HTM_TxtF ("%2u:%02u",CallsForExams->CallForExam.StartTime.Hour, - CallsForExams->CallForExam.StartTime.Minute); - HTM_TD_End (); + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "name=\"ExamMinute\""); + for (Minute = 0; + Minute <= 59; + Minute++) + HTM_OPTION (HTM_Type_UNSIGNED,&Minute, + CallsForExams->CallForExam.StartTime.Minute == Minute,false, + "%02u ′",Minute); + HTM_SELECT_End (); + } + else if (CallsForExams->CallForExam.StartTime.Hour) + HTM_TxtF ("%2u:%02u",CallsForExams->CallForExam.StartTime.Hour, + CallsForExams->CallForExam.StartTime.Minute); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Approximate duration of the exam *****/ - HTM_TR_Begin (NULL); + /***** Approximate duration of the exam *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "DurationHour" : - NULL, - Txt_CALL_FOR_EXAM_Approximate_duration); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "DurationHour" : + NULL, + Txt_CALL_FOR_EXAM_Approximate_duration); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"DurationHour\" name=\"DurationHour\""); - for (Hour = 0; - Hour <= 8; - Hour++) - HTM_OPTION (HTM_Type_UNSIGNED,&Hour, - CallsForExams->CallForExam.Duration.Hour == Hour,false, - "%02u %s",Hour,Txt_hours_ABBREVIATION); - HTM_SELECT_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"DurationHour\" name=\"DurationHour\""); + for (Hour = 0; + Hour <= 8; + Hour++) + HTM_OPTION (HTM_Type_UNSIGNED,&Hour, + CallsForExams->CallForExam.Duration.Hour == Hour,false, + "%02u %s",Hour,Txt_hours_ABBREVIATION); + HTM_SELECT_End (); - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "name=\"DurationMinute\""); - for (Minute = 0; - Minute <= 59; - Minute++) - HTM_OPTION (HTM_Type_UNSIGNED,&Minute, - CallsForExams->CallForExam.Duration.Minute == Minute,false, - "%02u ′",Minute); - HTM_SELECT_End (); - } - else if (CallsForExams->CallForExam.Duration.Hour || - CallsForExams->CallForExam.Duration.Minute) - { - if (CallsForExams->CallForExam.Duration.Hour) - { - if (CallsForExams->CallForExam.Duration.Minute) - HTM_TxtF ("%u%s %u′",CallsForExams->CallForExam.Duration.Hour, - Txt_hours_ABBREVIATION, - CallsForExams->CallForExam.Duration.Minute); - else - HTM_TxtF ("%u %s",CallsForExams->CallForExam.Duration.Hour, - CallsForExams->CallForExam.Duration.Hour == 1 ? Txt_hour : - Txt_hours); - } - else if (CallsForExams->CallForExam.Duration.Minute) - { - HTM_TxtF ("%u %s",CallsForExams->CallForExam.Duration.Minute, - CallsForExams->CallForExam.Duration.Minute == 1 ? Txt_minute : - Txt_minutes); - } - } - HTM_TD_End (); + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "name=\"DurationMinute\""); + for (Minute = 0; + Minute <= 59; + Minute++) + HTM_OPTION (HTM_Type_UNSIGNED,&Minute, + CallsForExams->CallForExam.Duration.Minute == Minute,false, + "%02u ′",Minute); + HTM_SELECT_End (); + } + else if (CallsForExams->CallForExam.Duration.Hour || + CallsForExams->CallForExam.Duration.Minute) + { + if (CallsForExams->CallForExam.Duration.Hour) + { + if (CallsForExams->CallForExam.Duration.Minute) + HTM_TxtF ("%u%s %u′",CallsForExams->CallForExam.Duration.Hour, + Txt_hours_ABBREVIATION, + CallsForExams->CallForExam.Duration.Minute); + else + HTM_TxtF ("%u %s",CallsForExams->CallForExam.Duration.Hour, + CallsForExams->CallForExam.Duration.Hour == 1 ? Txt_hour : + Txt_hours); + } + else if (CallsForExams->CallForExam.Duration.Minute) + { + HTM_TxtF ("%u %s",CallsForExams->CallForExam.Duration.Minute, + CallsForExams->CallForExam.Duration.Minute == 1 ? Txt_minute : + Txt_minutes); + } + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Place where the exam will be made *****/ - HTM_TR_Begin (NULL); + /***** Place where the exam will be made *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "Place" : - NULL, - Txt_CALL_FOR_EXAM_Place_of_exam); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "Place" : + NULL, + Txt_CALL_FOR_EXAM_Place_of_exam); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"Place\" name=\"Place\" cols=\"40\" rows=\"4\""); - HTM_Txt (CallsForExams->CallForExam.Place); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.Place, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.Place); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"Place\" name=\"Place\" cols=\"40\" rows=\"4\""); + HTM_Txt (CallsForExams->CallForExam.Place); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.Place, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.Place); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Exam mode *****/ - HTM_TR_Begin (NULL); + /***** Exam mode *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamMode" : - NULL, - Txt_CALL_FOR_EXAM_Mode); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "ExamMode" : + NULL, + Txt_CALL_FOR_EXAM_Mode); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"ExamMode\" name=\"ExamMode\" cols=\"40\" rows=\"2\""); - HTM_Txt (CallsForExams->CallForExam.Mode); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.Mode, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.Mode); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"ExamMode\" name=\"ExamMode\" cols=\"40\" rows=\"2\""); + HTM_Txt (CallsForExams->CallForExam.Mode); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.Mode, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.Mode); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Structure of the exam *****/ - HTM_TR_Begin (NULL); + /***** Structure of the exam *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "Structure" : - NULL, - Txt_CALL_FOR_EXAM_Structure_of_the_exam); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "Structure" : + NULL, + Txt_CALL_FOR_EXAM_Structure_of_the_exam); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"Structure\" name=\"Structure\" cols=\"40\" rows=\"8\""); - HTM_Txt (CallsForExams->CallForExam.Structure); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.Structure, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.Structure); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"Structure\" name=\"Structure\" cols=\"40\" rows=\"8\""); + HTM_Txt (CallsForExams->CallForExam.Structure); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.Structure, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.Structure); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Documentation required *****/ - HTM_TR_Begin (NULL); + /***** Documentation required *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "DocRequired" : - NULL, - Txt_CALL_FOR_EXAM_Documentation_required); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "DocRequired" : + NULL, + Txt_CALL_FOR_EXAM_Documentation_required); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"DocRequired\" name=\"DocRequired\" cols=\"40\" rows=\"2\""); - HTM_Txt (CallsForExams->CallForExam.DocRequired); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.DocRequired, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.DocRequired); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"DocRequired\" name=\"DocRequired\" cols=\"40\" rows=\"2\""); + HTM_Txt (CallsForExams->CallForExam.DocRequired); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.DocRequired, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.DocRequired); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Material required *****/ - HTM_TR_Begin (NULL); + /***** Material required *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "MatRequired" : - NULL, - Txt_CALL_FOR_EXAM_Material_required); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "MatRequired" : + NULL, + Txt_CALL_FOR_EXAM_Material_required); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"MatRequired\" name=\"MatRequired\" cols=\"40\" rows=\"4\""); - HTM_Txt (CallsForExams->CallForExam.MatRequired); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.MatRequired, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.MatRequired); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"MatRequired\" name=\"MatRequired\" cols=\"40\" rows=\"4\""); + HTM_Txt (CallsForExams->CallForExam.MatRequired); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.MatRequired, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.MatRequired); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Material allowed *****/ - HTM_TR_Begin (NULL); + /***** Material allowed *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "MatAllowed" : - NULL, - Txt_CALL_FOR_EXAM_Material_allowed); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "MatAllowed" : + NULL, + Txt_CALL_FOR_EXAM_Material_allowed); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"MatAllowed\" name=\"MatAllowed\" cols=\"40\" rows=\"4\""); - HTM_Txt (CallsForExams->CallForExam.MatAllowed); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.MatAllowed, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.MatAllowed); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"MatAllowed\" name=\"MatAllowed\" cols=\"40\" rows=\"4\""); + HTM_Txt (CallsForExams->CallForExam.MatAllowed); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.MatAllowed, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.MatAllowed); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Other information to students *****/ - HTM_TR_Begin (NULL); + /***** Other information to students *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT", - TypeViewCallForExam == Cfe_FORM_VIEW ? "OtherInfo" : - NULL, - Txt_CALL_FOR_EXAM_Other_information); + /* Label */ + Frm_LabelColumn ("RT", + TypeViewCallForExam == Cfe_FORM_VIEW ? "OtherInfo" : + NULL, + Txt_CALL_FOR_EXAM_Other_information); - /* Data */ - HTM_TD_Begin ("class=\"EXAM LB\""); - if (TypeViewCallForExam == Cfe_FORM_VIEW) - { - HTM_TEXTAREA_Begin ("id=\"OtherInfo\" name=\"OtherInfo\" cols=\"40\" rows=\"5\""); - HTM_Txt (CallsForExams->CallForExam.OtherInfo); - HTM_TEXTAREA_End (); - } - else - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - CallsForExams->CallForExam.OtherInfo, - Cns_MAX_BYTES_TEXT,false); - HTM_Txt (CallsForExams->CallForExam.OtherInfo); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"EXAM LB\""); + if (TypeViewCallForExam == Cfe_FORM_VIEW) + { + HTM_TEXTAREA_Begin ("id=\"OtherInfo\" name=\"OtherInfo\" cols=\"40\" rows=\"5\""); + HTM_Txt (CallsForExams->CallForExam.OtherInfo); + HTM_TEXTAREA_End (); + } + else + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + CallsForExams->CallForExam.OtherInfo, + Cns_MAX_BYTES_TEXT,false); + HTM_Txt (CallsForExams->CallForExam.OtherInfo); + } + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** End table, send button and end box *****/ - if (TypeViewCallForExam == Cfe_FORM_VIEW) - Box_BoxTableWithButtonEnd ((ExaCod > 0) ? Btn_CONFIRM_BUTTON : - Btn_CREATE_BUTTON, - Txt_Publish_call_FOR_EXAM); - else - Box_BoxTableEnd (); + /***** End table, send button and end box *****/ + if (TypeViewCallForExam == Cfe_FORM_VIEW) + Box_BoxTableWithButtonEnd ((ExaCod > 0) ? Btn_CONFIRM_BUTTON : + Btn_CREATE_BUTTON, + Txt_Publish_call_FOR_EXAM); + else + Box_BoxTableEnd (); - /***** Show QR code *****/ - if (TypeViewCallForExam == Cfe_PRINT_VIEW) - QR_ExamAnnnouncement (); + /***** Show QR code *****/ + if (TypeViewCallForExam == Cfe_PRINT_VIEW) + QR_ExamAnnnouncement (); /***** End article *****/ if (TypeViewCallForExam == Cfe_NORMAL_VIEW) @@ -1840,3 +1840,17 @@ static void Cfe_GetNotifContentCallForExam (const struct Cfe_CallsForExams *Call Txt_CALL_FOR_EXAM_Other_information,CallsForExams->CallForExam.OtherInfo) < 0) Err_NotEnoughMemoryExit (); } + +/*****************************************************************************/ +/*********** Mark all exam announcements in the course as deleted ************/ +/*****************************************************************************/ + +void Cfe_DB_MarkCallForExamsInCrsAsDeleted (long CrsCod) + { + DB_QueryUPDATE ("can not remove calls for exams of a course", + "UPDATE cfe_exams" + " SET Status=%u" + " WHERE CrsCod=%ld", + (unsigned) Cfe_DELETED_CALL_FOR_EXAM, + CrsCod); + } diff --git a/swad_call_for_exam.h b/swad_call_for_exam.h index 0d90e926..9d1a957e 100644 --- a/swad_call_for_exam.h +++ b/swad_call_for_exam.h @@ -126,4 +126,6 @@ void Cfe_GetSummaryAndContentCallForExam (char SummaryStr[Ntf_MAX_BYTES_SUMMARY char **ContentStr, long ExaCod,bool GetContent); +void Cfe_DB_MarkCallForExamsInCrsAsDeleted (long CrsCod); + #endif diff --git a/swad_center.c b/swad_center.c index d8ee046d..ea679e16 100644 --- a/swad_center.c +++ b/swad_center.c @@ -1232,7 +1232,7 @@ void Ctr_RemoveCenter (void) Svy_RemoveSurveys (Hie_Lvl_CTR,Ctr_EditingCtr->CtrCod); /***** Remove information related to files in center *****/ - Brw_RemoveCtrFilesFromDB (Ctr_EditingCtr->CtrCod); + Brw_DB_RemoveCtrFiles (Ctr_EditingCtr->CtrCod); /***** Remove all rooms in center *****/ Roo_RemoveAllRoomsInCtr (Ctr_EditingCtr->CtrCod); diff --git a/swad_changelog.h b/swad_changelog.h index 79ef954c..94022f47 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,14 +602,15 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 20.82 (2021-05-23)" +#define Log_PLATFORM_VERSION "SWAD 20.83 (2021-05-27)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams - Version 20.82: May 22, 2021 Queries moved to module swad_country_database. (311702 lines) + Version 20.83: May 27, 2021 New module swad_course_database for database queries related to courses. (311982 lines) + Version 20.82: May 23, 2021 Queries moved to module swad_country_database. (311702 lines) Version 20.81: May 22, 2021 New module swad_country_database for database queries related to countries. (311632 lines) Version 20.80: May 20, 2021 New module swad_cookie_database for database queries related to cookies. (311497 lines) Version 20.79: May 20, 2021 New module swad_connected_database for database queries related to connected users. (311415 lines) diff --git a/swad_country.c b/swad_country.c index b68d1e91..b05ef2d7 100644 --- a/swad_country.c +++ b/swad_country.c @@ -126,7 +126,7 @@ void Cty_SeeCtyWithPendingInss (void) } /***** Get countries with pending institutions *****/ - if ((NumCtys = Cty_DB_GetListOfCountriesWithPendingInss (&mysql_res))) + if ((NumCtys = Cty_DB_GetCtysWithPendingInss (&mysql_res))) { /***** Begin box and table *****/ Box_BoxTableBegin (NULL,Txt_Countries_with_pending_institutions, @@ -748,7 +748,7 @@ void Cty_GetBasicListOfCountries (void) return; /***** Get countries from database *****/ - if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetBasicListOfCountries (&mysql_res))) // Countries found... + if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetCtysBasic (&mysql_res))) // Countries found... { /***** Create list with countries *****/ if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, @@ -809,7 +809,7 @@ void Cty_GetFullListOfCountries (void) return; /***** Get countries from database *****/ - if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetFullListOfCountries (&mysql_res))) // Countries found... + if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetCtysFull (&mysql_res))) // Countries found... { /***** Create list with countries *****/ if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, @@ -871,15 +871,15 @@ void Cty_WriteSelectorOfCountry (void) /***** Begin form *****/ Frm_BeginFormGoTo (ActSeeIns); - /* Begin selector of country */ + /***** Begin selector of country *****/ HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, "id=\"cty\" name=\"cty\" class=\"HIE_SEL\""); - /* Initial disabled option */ + /***** Initial disabled option *****/ HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Cty.CtyCod < 0,true, "[%s]",Txt_Country); - /* List countries */ + /***** List countries *****/ for (NumCty = 0; NumCty < Gbl.Hierarchy.Ctys.Num; NumCty++) @@ -887,7 +887,7 @@ void Cty_WriteSelectorOfCountry (void) Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Hierarchy.Cty.CtyCod,false, "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); - /* End selector of country */ + /***** End selector of country *****/ HTM_SELECT_End (); /***** End form *****/ diff --git a/swad_country_database.c b/swad_country_database.c index 5271d0aa..84176734 100644 --- a/swad_country_database.c +++ b/swad_country_database.c @@ -113,7 +113,7 @@ void Cty_DB_CreateCountry (const struct Cty_Countr *Cty) /********** Get basic list of countries ordered by name of country ***********/ /*****************************************************************************/ -unsigned Cty_DB_GetBasicListOfCountries (MYSQL_RES **mysql_res) +unsigned Cty_DB_GetCtysBasic (MYSQL_RES **mysql_res) { extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; @@ -131,7 +131,7 @@ unsigned Cty_DB_GetBasicListOfCountries (MYSQL_RES **mysql_res) /******************* Get countries with pending institutions *****************/ /*****************************************************************************/ -unsigned Cty_DB_GetListOfCountriesWithPendingInss (MYSQL_RES **mysql_res) +unsigned Cty_DB_GetCtysWithPendingInss (MYSQL_RES **mysql_res) { extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; @@ -155,7 +155,7 @@ unsigned Cty_DB_GetListOfCountriesWithPendingInss (MYSQL_RES **mysql_res) /********** and number of users who claim to belong to them ***********/ /*****************************************************************************/ -unsigned Cty_DB_GetFullListOfCountries (MYSQL_RES **mysql_res) +unsigned Cty_DB_GetCtysFull (MYSQL_RES **mysql_res) { extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; char StrField[32]; diff --git a/swad_country_database.h b/swad_country_database.h index 1402bbb3..4c826737 100644 --- a/swad_country_database.h +++ b/swad_country_database.h @@ -43,9 +43,9 @@ void Cty_DB_CreateCountry (const struct Cty_Countr *Cty); -unsigned Cty_DB_GetBasicListOfCountries (MYSQL_RES **mysql_res); -unsigned Cty_DB_GetListOfCountriesWithPendingInss (MYSQL_RES **mysql_res); -unsigned Cty_DB_GetFullListOfCountries (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetCtysBasic (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetCtysWithPendingInss (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetCtysFull (MYSQL_RES **mysql_res); unsigned Cty_DB_GetDataOfCountryByCod (MYSQL_RES **mysql_res,long CtyCod); void Cty_DB_GetCountryName (long CtyCod,Lan_Language_t Language, char CtyName[Cty_MAX_BYTES_NAME + 1]); diff --git a/swad_course.c b/swad_course.c index 9486dfd8..3f1ef021 100644 --- a/swad_course.c +++ b/swad_course.c @@ -35,6 +35,7 @@ #include "swad_call_for_exam.h" #include "swad_course.h" #include "swad_course_config.h" +#include "swad_course_database.h" #include "swad_database.h" #include "swad_error.h" #include "swad_figure.h" @@ -49,6 +50,7 @@ #include "swad_info.h" #include "swad_logo.h" #include "swad_message.h" +#include "swad_notice.h" #include "swad_project.h" #include "swad_search.h" #include "swad_survey.h" @@ -80,7 +82,7 @@ static struct Crs_Course *Crs_EditingCrs = NULL; // Static variable to keep the static void Crs_WriteListMyCoursesToSelectOne (void); -static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses); +static void Crs_GetListCrssInCurrentDeg (void); static void Crs_ListCourses (void); static bool Crs_CheckIfICanCreateCourses (void); static void Crs_PutIconsListCourses (__attribute__((unused)) void *Args); @@ -101,16 +103,11 @@ static void Crs_PutHeadCoursesForEdition (void); static void Crs_ReceiveFormRequestOrCreateCrs (unsigned Status); static void Crs_GetParamsNewCourse (struct Crs_Course *Crs); -static void Crs_CreateCourse (unsigned Status); static void Crs_GetDataOfCourseFromRow (struct Crs_Course *Crs,MYSQL_ROW row); -static void Crs_GetShortNamesByCod (long CrsCod, - char CrsShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1], - char DegShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]); - static void Crs_EmptyCourseCompletely (long CrsCod); -static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName); +static void Crs_UpdateCrsStatus (struct Crs_Course *Crs,Crs_Status_t Status); static void Crs_PutButtonToGoToCrs (void); static void Crs_PutButtonToRegisterInCrs (void); @@ -133,7 +130,7 @@ void Crs_ShowIntroduction (void) { /***** Course configuration *****/ HTM_DIV_Begin ("class=\"CM\""); - CrsCfg_Configuration (false); + CrsCfg_Configuration (false); HTM_DIV_End (); /***** Course introduction *****/ @@ -186,220 +183,224 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Box_BoxBegin (NULL,Txt_My_courses, Crs_PutIconToSearchCourses,NULL, Hlp_PROFILE_Courses,Box_NOT_CLOSABLE); - HTM_UL_Begin ("class=\"LIST_TREE\""); - /***** Write link to platform *****/ - Highlight = (Gbl.Hierarchy.Cty.CtyCod <= 0); - HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - Frm_BeginForm (ActMyCrs); - Cty_PutParamCtyCod (-1L); - HTM_BUTTON_SUBMIT_Begin (Txt_System, - Highlight ? ClassHighlight : - ClassNormal, - NULL); - Ico_PutIcon ("sitemap.svg",Txt_System,"ICO16x16"); - HTM_TxtF (" %s",Txt_System); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_LI_End (); + /***** Begin list *****/ + HTM_UL_Begin ("class=\"LIST_TREE\""); - /***** Get my countries *****/ - NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_resCty); - for (NumCty = 0; - NumCty < NumCtys; - NumCty++) - { - /***** Get next institution *****/ - row = mysql_fetch_row (mysql_resCty); - - /***** Get data of this institution *****/ - Hie.Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Cty_GetDataOfCountryByCod (&Hie.Cty)) - Err_WrongCountrExit (); - - /***** Write link to country *****/ - Highlight = (Gbl.Hierarchy.Ins.InsCod <= 0 && - Gbl.Hierarchy.Cty.CtyCod == Hie.Cty.CtyCod); - HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - IsLastItemInLevel[1] = (NumCty == NumCtys - 1); - Lay_IndentDependingOnLevel (1,IsLastItemInLevel); - Frm_BeginForm (ActMyCrs); - Cty_PutParamCtyCod (Hie.Cty.CtyCod); - HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf), - Highlight ? ClassHighlight : - ClassNormal, - NULL); - Cty_DrawCountryMap (&Hie.Cty,"ICO16x16"); - HTM_TxtF (" %s",Hie.Cty.Name[Gbl.Prefs.Language]); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_LI_End (); - - /***** Get my institutions in this country *****/ - NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Cty.CtyCod,&mysql_resIns); - for (NumIns = 0; - NumIns < NumInss; - NumIns++) - { - /***** Get next institution *****/ - row = mysql_fetch_row (mysql_resIns); - - /***** Get data of this institution *****/ - Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Ins_GetDataOfInstitutionByCod (&Hie.Ins)) - Err_WrongInstitExit (); - - /***** Write link to institution *****/ - Highlight = (Gbl.Hierarchy.Ctr.CtrCod <= 0 && - Gbl.Hierarchy.Ins.InsCod == Hie.Ins.InsCod); + /***** Write link to platform *****/ + Highlight = (Gbl.Hierarchy.Cty.CtyCod <= 0); HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - IsLastItemInLevel[2] = (NumIns == NumInss - 1); - Lay_IndentDependingOnLevel (2,IsLastItemInLevel); - Frm_BeginForm (ActMyCrs); - Ins_PutParamInsCod (Hie.Ins.InsCod); - HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeInsInf), - Highlight ? ClassHighlight : - ClassNormal, - NULL); - Lgo_DrawLogo (Hie_Lvl_INS,Hie.Ins.InsCod,Hie.Ins.ShrtName,16,NULL,true); - HTM_TxtF (" %s",Hie.Ins.ShrtName); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_LI_End (); - - /***** Get my centers in this institution *****/ - NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Ins.InsCod,&mysql_resCtr); - for (NumCtr = 0; - NumCtr < NumCtrs; - NumCtr++) - { - /***** Get next center *****/ - row = mysql_fetch_row (mysql_resCtr); - - /***** Get data of this center *****/ - Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Ctr_GetDataOfCenterByCod (&Hie.Ctr)) - Err_WrongCenterExit (); - - /***** Write link to center *****/ - Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_CTR && - Gbl.Hierarchy.Ctr.CtrCod == Hie.Ctr.CtrCod); - HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - IsLastItemInLevel[3] = (NumCtr == NumCtrs - 1); - Lay_IndentDependingOnLevel (3,IsLastItemInLevel); - Frm_BeginForm (ActMyCrs); - Ctr_PutParamCtrCod (Hie.Ctr.CtrCod); - HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtrInf), - Highlight ? ClassHighlight : - ClassNormal, - NULL); - Lgo_DrawLogo (Hie_Lvl_CTR,Hie.Ctr.CtrCod,Hie.Ctr.ShrtName,16,NULL,true); - HTM_TxtF (" %s",Hie.Ctr.ShrtName); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_LI_End (); - - /***** Get my degrees in this center *****/ - NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Ctr.CtrCod,&mysql_resDeg); - for (NumDeg = 0; - NumDeg < NumDegs; - NumDeg++) - { - /***** Get next degree *****/ - row = mysql_fetch_row (mysql_resDeg); - - /***** Get data of this degree *****/ - Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Deg_GetDataOfDegreeByCod (&Hie.Deg)) - Err_WrongDegreeExit (); - - /***** Write link to degree *****/ - Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_DEG && - Gbl.Hierarchy.Deg.DegCod == Hie.Deg.DegCod); - HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - IsLastItemInLevel[4] = (NumDeg == NumDegs - 1); - Lay_IndentDependingOnLevel (4,IsLastItemInLevel); - Frm_BeginForm (ActMyCrs); - Deg_PutParamDegCod (Hie.Deg.DegCod); - HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeDegInf), + ClassNormal); + Frm_BeginForm (ActMyCrs); + Cty_PutParamCtyCod (-1L); + HTM_BUTTON_SUBMIT_Begin (Txt_System, Highlight ? ClassHighlight : ClassNormal, NULL); - Lgo_DrawLogo (Hie_Lvl_DEG,Hie.Deg.DegCod,Hie.Deg.ShrtName,16,NULL,true); - HTM_TxtF (" %s",Hie.Deg.ShrtName); + Ico_PutIcon ("sitemap.svg",Txt_System,"ICO16x16"); + HTM_TxtF (" %s",Txt_System); HTM_BUTTON_End (); - Frm_EndForm (); - HTM_LI_End (); + Frm_EndForm (); + HTM_LI_End (); - /***** Get my courses in this degree *****/ - NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Deg.DegCod,&mysql_resCrs); - for (NumCrs = 0; - NumCrs < NumCrss; - NumCrs++) - { - /***** Get next course *****/ - row = mysql_fetch_row (mysql_resCrs); + /***** Get my countries *****/ + NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_resCty); + for (NumCty = 0; + NumCty < NumCtys; + NumCty++) + { + /***** Get next institution *****/ + row = mysql_fetch_row (mysql_resCty); - /***** Get data of this course *****/ - Hie.Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Crs_GetDataOfCourseByCod (&Hie.Crs)) - Err_WrongCourseExit (); + /***** Get data of this institution *****/ + Hie.Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); + if (!Cty_GetDataOfCountryByCod (&Hie.Cty)) + Err_WrongCountrExit (); - /***** Write link to course *****/ - Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_CRS && - Gbl.Hierarchy.Crs.CrsCod == Hie.Crs.CrsCod); - HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : - ClassNormal); - IsLastItemInLevel[5] = (NumCrs == NumCrss - 1); - Lay_IndentDependingOnLevel (5,IsLastItemInLevel); - Frm_BeginForm (ActMyCrs); - Crs_PutParamCrsCod (Hie.Crs.CrsCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Hie.Crs.ShrtName), + /***** Write link to country *****/ + Highlight = (Gbl.Hierarchy.Ins.InsCod <= 0 && + Gbl.Hierarchy.Cty.CtyCod == Hie.Cty.CtyCod); + HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : + ClassNormal); + IsLastItemInLevel[1] = (NumCty == NumCtys - 1); + Lay_IndentDependingOnLevel (1,IsLastItemInLevel); + Frm_BeginForm (ActMyCrs); + Cty_PutParamCtyCod (Hie.Cty.CtyCod); + HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf), Highlight ? ClassHighlight : ClassNormal, NULL); - Hie_FreeGoToMsg (); - Ico_PutIcon ("chalkboard-teacher.svg",Hie.Crs.FullName,"ICO16x16"); - HTM_TxtF (" %s",Hie.Crs.ShrtName); + Cty_DrawCountryMap (&Hie.Cty,"ICO16x16"); + HTM_TxtF (" %s",Hie.Cty.Name[Gbl.Prefs.Language]); HTM_BUTTON_End (); + Frm_EndForm (); + HTM_LI_End (); + + /***** Get my institutions in this country *****/ + NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Cty.CtyCod,&mysql_resIns); + for (NumIns = 0; + NumIns < NumInss; + NumIns++) + { + /***** Get next institution *****/ + row = mysql_fetch_row (mysql_resIns); + + /***** Get data of this institution *****/ + Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]); + if (!Ins_GetDataOfInstitutionByCod (&Hie.Ins)) + Err_WrongInstitExit (); + + /***** Write link to institution *****/ + Highlight = (Gbl.Hierarchy.Ctr.CtrCod <= 0 && + Gbl.Hierarchy.Ins.InsCod == Hie.Ins.InsCod); + HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : + ClassNormal); + IsLastItemInLevel[2] = (NumIns == NumInss - 1); + Lay_IndentDependingOnLevel (2,IsLastItemInLevel); + Frm_BeginForm (ActMyCrs); + Ins_PutParamInsCod (Hie.Ins.InsCod); + HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeInsInf), + Highlight ? ClassHighlight : + ClassNormal, + NULL); + Lgo_DrawLogo (Hie_Lvl_INS,Hie.Ins.InsCod,Hie.Ins.ShrtName,16,NULL,true); + HTM_TxtF (" %s",Hie.Ins.ShrtName); + HTM_BUTTON_End (); Frm_EndForm (); + HTM_LI_End (); - /***** Put link to register students *****/ - Enr_PutButtonInlineToRegisterStds (Hie.Crs.CrsCod); + /***** Get my centers in this institution *****/ + NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Ins.InsCod,&mysql_resCtr); + for (NumCtr = 0; + NumCtr < NumCtrs; + NumCtr++) + { + /***** Get next center *****/ + row = mysql_fetch_row (mysql_resCtr); + /***** Get data of this center *****/ + Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]); + if (!Ctr_GetDataOfCenterByCod (&Hie.Ctr)) + Err_WrongCenterExit (); + + /***** Write link to center *****/ + Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_CTR && + Gbl.Hierarchy.Ctr.CtrCod == Hie.Ctr.CtrCod); + HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : + ClassNormal); + IsLastItemInLevel[3] = (NumCtr == NumCtrs - 1); + Lay_IndentDependingOnLevel (3,IsLastItemInLevel); + Frm_BeginForm (ActMyCrs); + Ctr_PutParamCtrCod (Hie.Ctr.CtrCod); + HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtrInf), + Highlight ? ClassHighlight : + ClassNormal, + NULL); + Lgo_DrawLogo (Hie_Lvl_CTR,Hie.Ctr.CtrCod,Hie.Ctr.ShrtName,16,NULL,true); + HTM_TxtF (" %s",Hie.Ctr.ShrtName); + HTM_BUTTON_End (); + Frm_EndForm (); HTM_LI_End (); + + /***** Get my degrees in this center *****/ + NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Ctr.CtrCod,&mysql_resDeg); + for (NumDeg = 0; + NumDeg < NumDegs; + NumDeg++) + { + /***** Get next degree *****/ + row = mysql_fetch_row (mysql_resDeg); + + /***** Get data of this degree *****/ + Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]); + if (!Deg_GetDataOfDegreeByCod (&Hie.Deg)) + Err_WrongDegreeExit (); + + /***** Write link to degree *****/ + Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_DEG && + Gbl.Hierarchy.Deg.DegCod == Hie.Deg.DegCod); + HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : + ClassNormal); + IsLastItemInLevel[4] = (NumDeg == NumDegs - 1); + Lay_IndentDependingOnLevel (4,IsLastItemInLevel); + Frm_BeginForm (ActMyCrs); + Deg_PutParamDegCod (Hie.Deg.DegCod); + HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeDegInf), + Highlight ? ClassHighlight : + ClassNormal, + NULL); + Lgo_DrawLogo (Hie_Lvl_DEG,Hie.Deg.DegCod,Hie.Deg.ShrtName,16,NULL,true); + HTM_TxtF (" %s",Hie.Deg.ShrtName); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_LI_End (); + + /***** Get my courses in this degree *****/ + NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Deg.DegCod,&mysql_resCrs); + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) + { + /***** Get next course *****/ + row = mysql_fetch_row (mysql_resCrs); + + /***** Get data of this course *****/ + Hie.Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0]); + if (!Crs_GetDataOfCourseByCod (&Hie.Crs)) + Err_WrongCourseExit (); + + /***** Write link to course *****/ + Highlight = (Gbl.Hierarchy.Level == Hie_Lvl_CRS && + Gbl.Hierarchy.Crs.CrsCod == Hie.Crs.CrsCod); + HTM_LI_Begin ("class=\"%s\"",Highlight ? ClassHighlight : + ClassNormal); + IsLastItemInLevel[5] = (NumCrs == NumCrss - 1); + Lay_IndentDependingOnLevel (5,IsLastItemInLevel); + Frm_BeginForm (ActMyCrs); + Crs_PutParamCrsCod (Hie.Crs.CrsCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Hie.Crs.ShrtName), + Highlight ? ClassHighlight : + ClassNormal, + NULL); + Hie_FreeGoToMsg (); + Ico_PutIcon ("chalkboard-teacher.svg",Hie.Crs.FullName,"ICO16x16"); + HTM_TxtF (" %s",Hie.Crs.ShrtName); + HTM_BUTTON_End (); + Frm_EndForm (); + + /***** Put link to register students *****/ + Enr_PutButtonInlineToRegisterStds (Hie.Crs.CrsCod); + + HTM_LI_End (); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_resCrs); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_resDeg); } /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resCrs); + DB_FreeMySQLResult (&mysql_resCtr); } /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resDeg); + DB_FreeMySQLResult (&mysql_resIns); } /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resCtr); - } + DB_FreeMySQLResult (&mysql_resCty); - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resIns); - } - - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resCty); + /***** End list *****/ + HTM_UL_End (); /***** End box *****/ - HTM_UL_End (); Box_BoxEnd (); } @@ -446,18 +447,7 @@ unsigned Crs_GetNumCrssInCty (long CtyCod) /***** 3. Slow: number of courses in a country from database *****/ Gbl.Cache.NumCrssInCty.CtyCod = CtyCod; - Gbl.Cache.NumCrssInCty.NumCrss = (unsigned) - DB_QueryCOUNT ("can not get the number of courses in a country", - "SELECT COUNT(*)" - " FROM ins_instits," - "ctr_centers," - "deg_degrees," - "crs_courses" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod", - CtyCod); + Gbl.Cache.NumCrssInCty.NumCrss = Crs_DB_GetNumCrssInCty (CtyCod); FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_Lvl_CTY,Gbl.Cache.NumCrssInCty.CtyCod, FigCch_UNSIGNED,&Gbl.Cache.NumCrssInCty.NumCrss); return Gbl.Cache.NumCrssInCty.NumCrss; @@ -498,16 +488,7 @@ unsigned Crs_GetNumCrssInIns (long InsCod) /***** 3. Slow: number of courses in an institution from database *****/ Gbl.Cache.NumCrssInIns.InsCod = InsCod; - Gbl.Cache.NumCrssInIns.NumCrss = (unsigned) - DB_QueryCOUNT ("can not get the number of courses in an institution", - "SELECT COUNT(*)" - " FROM ctr_centers," - "deg_degrees," - "crs_courses" - " WHERE ctr_centers.InsCod=%ld" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod", - InsCod); + Gbl.Cache.NumCrssInIns.NumCrss = Crs_DB_GetNumCrssInIns (InsCod); FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_Lvl_INS,Gbl.Cache.NumCrssInIns.InsCod, FigCch_UNSIGNED,&Gbl.Cache.NumCrssInIns.NumCrss); return Gbl.Cache.NumCrssInIns.NumCrss; @@ -548,14 +529,7 @@ unsigned Crs_GetNumCrssInCtr (long CtrCod) /***** 3. Slow: number of courses in a center from database *****/ Gbl.Cache.NumCrssInCtr.CtrCod = CtrCod; - Gbl.Cache.NumCrssInCtr.NumCrss = (unsigned) - DB_QueryCOUNT ("can not get the number of courses in a center", - "SELECT COUNT(*)" - " FROM deg_degrees," - "crs_courses" - " WHERE deg_degrees.CtrCod=%ld" - " AND deg_degrees.DegCod=crs_courses.DegCod", - CtrCod); + Gbl.Cache.NumCrssInCtr.NumCrss = Crs_DB_GetNumCrssInCtr (CtrCod); return Gbl.Cache.NumCrssInCtr.NumCrss; } @@ -598,12 +572,7 @@ unsigned Crs_GetNumCrssInDeg (long DegCod) /***** 3. Slow: number of courses in a degree from database *****/ Gbl.Cache.NumCrssInDeg.DegCod = DegCod; - Gbl.Cache.NumCrssInDeg.NumCrss = (unsigned) - DB_QueryCOUNT ("can not get the number of courses in a degree", - "SELECT COUNT(*)" - " FROM crs_courses" - " WHERE DegCod=%ld", - DegCod); + Gbl.Cache.NumCrssInDeg.NumCrss = Crs_DB_GetNumCrssInDeg (DegCod); FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_Lvl_DEG,Gbl.Cache.NumCrssInDeg.DegCod, FigCch_UNSIGNED,&Gbl.Cache.NumCrssInDeg.NumCrss); return Gbl.Cache.NumCrssInDeg.NumCrss; @@ -642,22 +611,7 @@ unsigned Crs_GetCachedNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery, FigCch_UNSIGNED,&NumCrssWithUsrs)) { /***** Get current number of courses with users from database and update cache *****/ - NumCrssWithUsrs = (unsigned) - DB_QueryCOUNT ("can not get number of courses with users", - "SELECT COUNT(DISTINCT crs_courses.CrsCod)" - " FROM ins_instits," - "ctr_centers," - "deg_degrees," - "crs_courses," - "crs_users" - " WHERE %s" - "institutions.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod" - " AND crs_users.Role=%u", - SubQuery, - (unsigned) Role); + NumCrssWithUsrs = Crs_DB_GetNumCrssWithUsrs (Role,SubQuery); FigCch_UpdateFigureIntoCache (FigureCrss[Role],Scope,Cod, FigCch_UNSIGNED,&NumCrssWithUsrs); } @@ -680,53 +634,50 @@ void Crs_WriteSelectorOfCourse (void) /***** Begin form *****/ Frm_BeginFormGoTo (ActSeeCrsInf); - if (Gbl.Hierarchy.Deg.DegCod > 0) - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"crs\" name=\"crs\" class=\"HIE_SEL\""); - else - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"crs\" name=\"crs\" class=\"HIE_SEL\"" - " disabled=\"disabled\""); - HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Crs.CrsCod < 0,true, - "[%s]",Txt_Course); - if (Gbl.Hierarchy.Deg.DegCod > 0) - { - /***** Get courses belonging to the current degree from database *****/ - NumCrss = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get courses of a degree", - "SELECT CrsCod," // row[0] - "ShortName" // row[1] - " FROM crs_courses" - " WHERE DegCod=%ld" - " ORDER BY ShortName", - Gbl.Hierarchy.Deg.DegCod); + /***** Begin selector of course *****/ + if (Gbl.Hierarchy.Deg.DegCod > 0) + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"crs\" name=\"crs\" class=\"HIE_SEL\""); + else + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"crs\" name=\"crs\" class=\"HIE_SEL\"" + " disabled=\"disabled\""); - /***** Get courses of this degree *****/ - for (NumCrs = 0; - NumCrs < NumCrss; - NumCrs++) - { - /* Get next course */ - row = mysql_fetch_row (mysql_res); + /***** Initial disabled option *****/ + HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Crs.CrsCod < 0,true, + "[%s]",Txt_Course); - /* Get course code (row[0]) */ - if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) - Err_WrongCourseExit (); + if (Gbl.Hierarchy.Deg.DegCod > 0) + { + /***** Get courses belonging to the current degree from database *****/ + NumCrss = Crs_DB_GetCrssInCurrentDegBasic (&mysql_res); + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) + { + /* Get next course */ + row = mysql_fetch_row (mysql_res); - /* Write option */ - HTM_OPTION (HTM_Type_LONG,&CrsCod, - Gbl.Hierarchy.Level == Hie_Lvl_CRS && // Course selected - CrsCod == Gbl.Hierarchy.Crs.CrsCod,false, - "%s",row[1]); - } + /* Get course code (row[0]) */ + if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) + Err_WrongCourseExit (); - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } + /* Write option */ + HTM_OPTION (HTM_Type_LONG,&CrsCod, + Gbl.Hierarchy.Level == Hie_Lvl_CRS && // Course selected + CrsCod == Gbl.Hierarchy.Crs.CrsCod,false, + "%s",row[1]); // Short name (row[1]) + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + + /***** End selector of course *****/ + HTM_SELECT_End (); /***** End form *****/ - HTM_SELECT_End (); Frm_EndForm (); } @@ -741,7 +692,7 @@ void Crs_ShowCrssOfCurrentDeg (void) return; /***** Get list of courses in this degree *****/ - Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED); + Crs_GetListCrssInCurrentDeg (); /***** Write menu to select country, institution, center and degree *****/ Hie_WriteMenuHierarchy (); @@ -757,7 +708,7 @@ void Crs_ShowCrssOfCurrentDeg (void) /*************** Create a list with courses in current degree ****************/ /*****************************************************************************/ -static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses) +static void Crs_GetListCrssInCurrentDeg (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -766,49 +717,7 @@ static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses) struct Crs_Course *Crs; /***** Get courses of a degree from database *****/ - switch (WhatCourses) - { - case Crs_ACTIVE_COURSES: - NumCrss = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get courses of a degree", - "SELECT CrsCod," // row[0] - "DegCod," // row[1] - "Year," // row[2] - "InsCrsCod," // row[3] - "Status," // row[4] - "RequesterUsrCod," // row[5] - "ShortName," // row[6] - "FullName" // row[7] - " FROM crs_courses" - " WHERE DegCod=%ld" - " AND Status=0" - " ORDER BY Year," - "ShortName", - Gbl.Hierarchy.Deg.DegCod); - break; - case Crs_ALL_COURSES_EXCEPT_REMOVED: - NumCrss = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get courses of a degree", - "SELECT CrsCod," // row[0] - "DegCod," // row[1] - "Year," // row[2] - "InsCrsCod," // row[3] - "Status," // row[4] - "RequesterUsrCod," // row[5] - "ShortName," // row[6] - "FullName" // row[7] - " FROM crs_courses" - " WHERE DegCod=%ld" - " AND (Status & %u)=0" - " ORDER BY Year," - "ShortName", - Gbl.Hierarchy.Deg.DegCod, - (unsigned) Crs_STATUS_BIT_REMOVED); - break; - default: - break; - } - if (NumCrss) // Courses found... + if ((NumCrss = Crs_DB_GetCrssInCurrentDegFull (&mysql_res))) // Courses found... { /***** Create list with courses in degree *****/ if ((Gbl.Hierarchy.Crss.Lst = calloc (NumCrss, @@ -870,53 +779,55 @@ void Crs_WriteSelectorMyCoursesInBreadcrumb (void) Frm_BeginFormGoTo (Gbl.Usrs.Me.MyCrss.Num ? ActSeeCrsInf : ActReqSch); - /***** Start selector of courses *****/ - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"my_courses\" name=\"crs\""); + /***** Begin selector of courses *****/ + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"my_courses\" name=\"crs\""); - /***** Write an option when no course selected *****/ - if (Gbl.Hierarchy.Crs.CrsCod <= 0) // No course selected - HTM_OPTION (HTM_Type_STRING,"-1",true,true, - "%s",Txt_Course); + /***** Write an option when no course selected *****/ + if (Gbl.Hierarchy.Crs.CrsCod <= 0) // No course selected + HTM_OPTION (HTM_Type_STRING,"-1",true,true, + "%s",Txt_Course); - if (Gbl.Usrs.Me.MyCrss.Num) - { - /***** Write an option for each of my courses *****/ - for (NumMyCrs = 0, LastDegCod = -1L; - NumMyCrs < Gbl.Usrs.Me.MyCrss.Num; - NumMyCrs++) - { - CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod; - DegCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].DegCod; - - Crs_GetShortNamesByCod (CrsCod,CrsShortName,DegShortName); - - if (DegCod != LastDegCod) + if (Gbl.Usrs.Me.MyCrss.Num) { + /***** Write an option for each of my courses *****/ + for (NumMyCrs = 0, LastDegCod = -1L; + NumMyCrs < Gbl.Usrs.Me.MyCrss.Num; + NumMyCrs++) + { + CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod; + DegCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].DegCod; + + Crs_DB_GetShortNamesByCod (CrsCod,CrsShortName,DegShortName); + + if (DegCod != LastDegCod) + { + if (LastDegCod > 0) + HTM_OPTGROUP_End (); + HTM_OPTGROUP_Begin (DegShortName); + LastDegCod = DegCod; + } + + HTM_OPTION (HTM_Type_LONG,&Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod, + CrsCod == Gbl.Hierarchy.Crs.CrsCod,false, // Course selected + "%s",CrsShortName); + } + if (LastDegCod > 0) HTM_OPTGROUP_End (); - HTM_OPTGROUP_Begin (DegShortName); - LastDegCod = DegCod; } - HTM_OPTION (HTM_Type_LONG,&Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod, - CrsCod == Gbl.Hierarchy.Crs.CrsCod,false, // Course selected - "%s",CrsShortName); - } + /***** Write an option with the current course + when I don't belong to it *****/ + if (Gbl.Hierarchy.Level == Hie_Lvl_CRS && // Course selected + !Gbl.Usrs.Me.IBelongToCurrentCrs) // I do not belong to it + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Crs.CrsCod,true,true, + "%s",Gbl.Hierarchy.Crs.ShrtName); - if (LastDegCod > 0) - HTM_OPTGROUP_End (); - } - - /***** Write an option with the current course - when I don't belong to it *****/ - if (Gbl.Hierarchy.Level == Hie_Lvl_CRS && // Course selected - !Gbl.Usrs.Me.IBelongToCurrentCrs) // I do not belong to it - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Crs.CrsCod,true,true, - "%s",Gbl.Hierarchy.Crs.ShrtName); + /***** End selector of courses *****/ + HTM_SELECT_End (); /***** End form *****/ - HTM_SELECT_End (); Frm_EndForm (); } @@ -940,34 +851,36 @@ static void Crs_ListCourses (void) Hlp_DEGREE_Courses,Box_NOT_CLOSABLE); Str_FreeString (); - if (Gbl.Hierarchy.Crss.Num) // There are courses in the current degree - { - /***** Begin table *****/ - HTM_TABLE_BeginWideMarginPadding (2); - Crs_PutHeadCoursesForSeeing (); + if (Gbl.Hierarchy.Crss.Num) // There are courses in the current degree + { + /***** Begin table *****/ + HTM_TABLE_BeginWideMarginPadding (2); - /***** List the courses *****/ - for (Year = 1; - Year <= Deg_MAX_YEARS_PER_DEGREE; - Year++) - if (Crs_ListCoursesOfAYearForSeeing (Year)) // If this year has courses ==> - Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; // ==> change color for the next year - Crs_ListCoursesOfAYearForSeeing (0); // Courses without a year selected + /* Heading */ + Crs_PutHeadCoursesForSeeing (); - /***** End table *****/ - HTM_TABLE_End (); - } - else // No courses created in the current degree - Ale_ShowAlert (Ale_INFO,Txt_No_courses); + /* List the courses */ + for (Year = 1; + Year <= Deg_MAX_YEARS_PER_DEGREE; + Year++) + if (Crs_ListCoursesOfAYearForSeeing (Year)) // If this year has courses ==> + Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; // ==> change color for the next year + Crs_ListCoursesOfAYearForSeeing (0); // Courses without a year selected - /***** Button to create course *****/ - if (Crs_CheckIfICanCreateCourses ()) - { - Frm_BeginForm (ActEdiCrs); - Btn_PutConfirmButton (Gbl.Hierarchy.Crss.Num ? Txt_Create_another_course : - Txt_Create_course); - Frm_EndForm (); - } + /***** End table *****/ + HTM_TABLE_End (); + } + else // No courses created in the current degree + Ale_ShowAlert (Ale_INFO,Txt_No_courses); + + /***** Button to create course *****/ + if (Crs_CheckIfICanCreateCourses ()) + { + Frm_BeginForm (ActEdiCrs); + Btn_PutConfirmButton (Gbl.Hierarchy.Crss.Num ? Txt_Create_another_course : + Txt_Create_course); + Frm_EndForm (); + } /***** End box *****/ Box_BoxEnd (); @@ -1052,62 +965,62 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) HTM_TR_Begin (NULL); - /* Get number of users */ - NumUsrs[Rol_STD] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_STD); - NumUsrs[Rol_NET] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_NET); - NumUsrs[Rol_TCH] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_TCH); - NumUsrs[Rol_UNK] = NumUsrs[Rol_STD] + - NumUsrs[Rol_NET] + - NumUsrs[Rol_TCH]; + /* Get number of users */ + NumUsrs[Rol_STD] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_STD); + NumUsrs[Rol_NET] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_NET); + NumUsrs[Rol_TCH] = Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CRS,Crs->CrsCod,1 << Rol_TCH); + NumUsrs[Rol_UNK] = NumUsrs[Rol_STD] + + NumUsrs[Rol_NET] + + NumUsrs[Rol_TCH]; - /* Put green tip if course has users */ - HTM_TD_Begin ("class=\"%s CM %s\" title=\"%s\"", - TxtClassNormal,BgColor, - NumUsrs[Rol_UNK] ? Txt_COURSE_With_users : - Txt_COURSE_Without_users); - HTM_Txt (NumUsrs[Rol_UNK] ? "✓" : - " "); - HTM_TD_End (); + /* Put green tip if course has users */ + HTM_TD_Begin ("class=\"%s CM %s\" title=\"%s\"", + TxtClassNormal,BgColor, + NumUsrs[Rol_UNK] ? Txt_COURSE_With_users : + Txt_COURSE_Without_users); + HTM_Txt (NumUsrs[Rol_UNK] ? "✓" : + " "); + HTM_TD_End (); - /* Institutional code of the course */ - HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); - HTM_Txt (Crs->InstitutionalCrsCod); - HTM_TD_End (); + /* Institutional code of the course */ + HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); + HTM_Txt (Crs->InstitutionalCrsCod); + HTM_TD_End (); - /* Course year */ - HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); - HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]); - HTM_TD_End (); + /* Course year */ + HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); + HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]); + HTM_TD_End (); - /* Course full name */ - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassStrong,BgColor); - Frm_BeginFormGoTo (ActSeeCrsInf); - Crs_PutParamCrsCod (Crs->CrsCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs->FullName), - TxtClassStrong,NULL); - Hie_FreeGoToMsg (); - HTM_Txt (Crs->FullName); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_TD_End (); + /* Course full name */ + HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassStrong,BgColor); + Frm_BeginFormGoTo (ActSeeCrsInf); + Crs_PutParamCrsCod (Crs->CrsCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs->FullName), + TxtClassStrong,NULL); + Hie_FreeGoToMsg (); + HTM_Txt (Crs->FullName); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_TD_End (); - /* Number of teachers in this course */ - HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (NumUsrs[Rol_TCH] + - NumUsrs[Rol_NET]); - HTM_TD_End (); + /* Number of teachers in this course */ + HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); + HTM_Unsigned (NumUsrs[Rol_TCH] + + NumUsrs[Rol_NET]); + HTM_TD_End (); - /* Number of students in this course */ - HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (NumUsrs[Rol_STD]); - HTM_TD_End (); + /* Number of students in this course */ + HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); + HTM_Unsigned (NumUsrs[Rol_STD]); + HTM_TD_End (); - /* Course status */ - StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); - if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); - HTM_TD_End (); + /* Course status */ + StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); + HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); + if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything + HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); + HTM_TD_End (); HTM_TR_End (); } @@ -1141,7 +1054,7 @@ static void Crs_EditCoursesInternal (void) Deg_GetListDegsInCurrentCtr (); /***** Get list of courses in this degree *****/ - Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED); + Crs_GetListCrssInCurrentDeg (); /***** Write menu to select country, institution, center and degree *****/ Hie_WriteMenuHierarchy (); @@ -1153,12 +1066,12 @@ static void Crs_EditCoursesInternal (void) Hlp_DEGREE_Courses,Box_NOT_CLOSABLE); Str_FreeString (); - /***** Put a form to create or request a new course *****/ - Crs_PutFormToCreateCourse (); + /***** Put a form to create or request a new course *****/ + Crs_PutFormToCreateCourse (); - /***** Forms to edit current courses *****/ - if (Gbl.Hierarchy.Crss.Num) - Crs_ListCoursesForEdition (); + /***** Forms to edit current courses *****/ + if (Gbl.Hierarchy.Crss.Num) + Crs_ListCoursesForEdition (); /***** End box *****/ Box_BoxEnd (); @@ -1205,16 +1118,18 @@ static void Crs_ListCoursesForEdition (void) { unsigned Year; - /***** Write heading *****/ + /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); - Crs_PutHeadCoursesForEdition (); - /***** List the courses *****/ - for (Year = 1; - Year <= Deg_MAX_YEARS_PER_DEGREE; - Year++) - Crs_ListCoursesOfAYearForEdition (Year); - Crs_ListCoursesOfAYearForEdition (0); + /***** Write heading *****/ + Crs_PutHeadCoursesForEdition (); + + /***** List the courses *****/ + for (Year = 1; + Year <= Deg_MAX_YEARS_PER_DEGREE; + Year++) + Crs_ListCoursesOfAYearForEdition (Year); + Crs_ListCoursesOfAYearForEdition (0); /***** End table *****/ HTM_TABLE_End (); @@ -1260,132 +1175,134 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) HTM_TR_Begin (NULL); - /* Put icon to remove course */ - HTM_TD_Begin ("class=\"BM\""); - if (NumUsrs[Rol_UNK] || // Course has users ==> deletion forbidden - !ICanEdit) - Ico_PutIconRemovalNotAllowed (); - else // Crs->NumUsrs == 0 && ICanEdit - Ico_PutContextualIconToRemove (ActRemCrs,NULL, - Crs_PutParamOtherCrsCod,&Crs->CrsCod); - HTM_TD_End (); + /* Put icon to remove course */ + HTM_TD_Begin ("class=\"BM\""); + if (NumUsrs[Rol_UNK] || // Course has users ==> deletion forbidden + !ICanEdit) + Ico_PutIconRemovalNotAllowed (); + else // Crs->NumUsrs == 0 && ICanEdit + Ico_PutContextualIconToRemove (ActRemCrs,NULL, + Crs_PutParamOtherCrsCod,&Crs->CrsCod); + HTM_TD_End (); - /* Course code */ - HTM_TD_Begin ("class=\"DAT CODE\""); - HTM_Long (Crs->CrsCod); - HTM_TD_End (); + /* Course code */ + HTM_TD_Begin ("class=\"DAT CODE\""); + HTM_Long (Crs->CrsCod); + HTM_TD_End (); - /* Institutional code of the course */ - HTM_TD_Begin ("class=\"DAT CM\""); - if (ICanEdit) - { - Frm_BeginForm (ActChgInsCrsCod); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, - Crs->InstitutionalCrsCod,HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_INS_CODE\""); - Frm_EndForm (); - } - else - HTM_Txt (Crs->InstitutionalCrsCod); - HTM_TD_End (); + /* Institutional code of the course */ + HTM_TD_Begin ("class=\"DAT CM\""); + if (ICanEdit) + { + Frm_BeginForm (ActChgInsCrsCod); + Crs_PutParamOtherCrsCod (&Crs->CrsCod); + HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, + Crs->InstitutionalCrsCod,HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_INS_CODE\""); + Frm_EndForm (); + } + else + HTM_Txt (Crs->InstitutionalCrsCod); + HTM_TD_End (); - /* Course year */ - HTM_TD_Begin ("class=\"DAT CM\""); - if (ICanEdit) - { - Frm_BeginForm (ActChgCrsYea); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\""); - for (YearAux = 0; - YearAux <= Deg_MAX_YEARS_PER_DEGREE; - YearAux++) // All the years are permitted because it's possible to move this course to another degree (with other active years) - HTM_OPTION (HTM_Type_UNSIGNED,&YearAux, - YearAux == Crs->Year,false, - "%s",Txt_YEAR_OF_DEGREE[YearAux]); - HTM_SELECT_End (); - Frm_EndForm (); - } - else - HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]); - HTM_TD_End (); + /* Course year */ + HTM_TD_Begin ("class=\"DAT CM\""); + if (ICanEdit) + { + Frm_BeginForm (ActChgCrsYea); + Crs_PutParamOtherCrsCod (&Crs->CrsCod); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\""); + for (YearAux = 0; + YearAux <= Deg_MAX_YEARS_PER_DEGREE; + YearAux++) // All the years are permitted + // because it's possible to move this course + // to another degree (with other active years) + HTM_OPTION (HTM_Type_UNSIGNED,&YearAux, + YearAux == Crs->Year,false, + "%s",Txt_YEAR_OF_DEGREE[YearAux]); + HTM_SELECT_End (); + Frm_EndForm (); + } + else + HTM_Txt (Txt_YEAR_OF_DEGREE[Crs->Year]); + HTM_TD_End (); - /* Course short name */ - HTM_TD_Begin ("class=\"DAT LM\""); - if (ICanEdit) - { - Frm_BeginForm (ActRenCrsSho); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Crs->ShrtName, - HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_SHORT_NAME\""); - Frm_EndForm (); - } - else - HTM_Txt (Crs->ShrtName); - HTM_TD_End (); + /* Course short name */ + HTM_TD_Begin ("class=\"DAT LM\""); + if (ICanEdit) + { + Frm_BeginForm (ActRenCrsSho); + Crs_PutParamOtherCrsCod (&Crs->CrsCod); + HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Crs->ShrtName, + HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_SHORT_NAME\""); + Frm_EndForm (); + } + else + HTM_Txt (Crs->ShrtName); + HTM_TD_End (); - /* Course full name */ - HTM_TD_Begin ("class=\"DAT LM\""); - if (ICanEdit) - { - Frm_BeginForm (ActRenCrsFul); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Crs->FullName, - HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_FULL_NAME\""); - Frm_EndForm (); - } - else - HTM_Txt (Crs->FullName); - HTM_TD_End (); + /* Course full name */ + HTM_TD_Begin ("class=\"DAT LM\""); + if (ICanEdit) + { + Frm_BeginForm (ActRenCrsFul); + Crs_PutParamOtherCrsCod (&Crs->CrsCod); + HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Crs->FullName, + HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_FULL_NAME\""); + Frm_EndForm (); + } + else + HTM_Txt (Crs->FullName); + HTM_TD_End (); - /* Current number of teachers in this course */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (NumUsrs[Rol_TCH] + - NumUsrs[Rol_NET]); - HTM_TD_End (); + /* Current number of teachers in this course */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (NumUsrs[Rol_TCH] + + NumUsrs[Rol_NET]); + HTM_TD_End (); - /* Current number of students in this course */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (NumUsrs[Rol_STD]); - HTM_TD_End (); + /* Current number of students in this course */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (NumUsrs[Rol_STD]); + HTM_TD_End (); - /* Course requester */ - UsrDat.UsrCod = Crs->RequesterUsrCod; - Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, - Usr_DONT_GET_PREFS, - Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\""); - Msg_WriteMsgAuthor (&UsrDat,true,NULL); - HTM_TD_End (); + /* Course requester */ + UsrDat.UsrCod = Crs->RequesterUsrCod; + Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, + Usr_DONT_GET_PREFS, + Usr_DONT_GET_ROLE_IN_CURRENT_CRS); + HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\""); + Msg_WriteMsgAuthor (&UsrDat,true,NULL); + HTM_TD_End (); - /* Course status */ - StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); - HTM_TD_Begin ("class=\"DAT LM\""); - if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM && - StatusTxt == Crs_STATUS_PENDING) - { - Frm_BeginForm (ActChgCrsSta); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"Status\" class=\"INPUT_STATUS\""); + /* Course status */ + StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); + HTM_TD_Begin ("class=\"DAT LM\""); + if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM && + StatusTxt == Crs_STATUS_PENDING) + { + Frm_BeginForm (ActChgCrsSta); + Crs_PutParamOtherCrsCod (&Crs->CrsCod); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "name=\"Status\" class=\"INPUT_STATUS\""); - StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_PENDING); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, - "%s",Txt_COURSE_STATUS[Crs_STATUS_PENDING]); + StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_PENDING); + HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, + "%s",Txt_COURSE_STATUS[Crs_STATUS_PENDING]); - StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_ACTIVE); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, - "%s",Txt_COURSE_STATUS[Crs_STATUS_ACTIVE]); + StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_ACTIVE); + HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, + "%s",Txt_COURSE_STATUS[Crs_STATUS_ACTIVE]); - HTM_SELECT_End (); - Frm_EndForm (); - } - else if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); - HTM_TD_End (); + HTM_SELECT_End (); + Frm_EndForm (); + } + else if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything + HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); + HTM_TD_End (); HTM_TR_End (); } @@ -1472,77 +1389,77 @@ static void Crs_PutFormToCreateCourse (void) NULL,NULL, NULL,Box_NOT_CLOSABLE,2); - /***** Write heading *****/ - Crs_PutHeadCoursesForEdition (); + /***** Write heading *****/ + Crs_PutHeadCoursesForEdition (); - HTM_TR_Begin (NULL); + HTM_TR_Begin (NULL); - /***** Column to remove course, disabled here *****/ - HTM_TD_Begin ("class=\"BM\""); - HTM_TD_End (); + /***** Column to remove course, disabled here *****/ + HTM_TD_Begin ("class=\"BM\""); + HTM_TD_End (); - /***** Course code *****/ - HTM_TD_Begin ("class=\"CODE\""); - HTM_TD_End (); + /***** Course code *****/ + HTM_TD_Begin ("class=\"CODE\""); + HTM_TD_End (); - /***** Institutional code of the course *****/ - HTM_TD_Begin ("class=\"CM\""); - HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, - Crs_EditingCrs->InstitutionalCrsCod, - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"INPUT_INS_CODE\""); - HTM_TD_End (); + /***** Institutional code of the course *****/ + HTM_TD_Begin ("class=\"CM\""); + HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, + Crs_EditingCrs->InstitutionalCrsCod, + HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"INPUT_INS_CODE\""); + HTM_TD_End (); - /***** Year *****/ - HTM_TD_Begin ("class=\"CM\""); - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\""); - for (Year = 0; - Year <= Deg_MAX_YEARS_PER_DEGREE; - Year++) - HTM_OPTION (HTM_Type_UNSIGNED,&Year, - Year == Crs_EditingCrs->Year,false, - "%s",Txt_YEAR_OF_DEGREE[Year]); - HTM_SELECT_End (); - HTM_TD_End (); + /***** Year *****/ + HTM_TD_Begin ("class=\"CM\""); + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\""); + for (Year = 0; + Year <= Deg_MAX_YEARS_PER_DEGREE; + Year++) + HTM_OPTION (HTM_Type_UNSIGNED,&Year, + Year == Crs_EditingCrs->Year,false, + "%s",Txt_YEAR_OF_DEGREE[Year]); + HTM_SELECT_End (); + HTM_TD_End (); - /***** Course short name *****/ - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Crs_EditingCrs->ShrtName, - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"INPUT_SHORT_NAME\" required=\"required\""); - HTM_TD_End (); + /***** Course short name *****/ + HTM_TD_Begin ("class=\"LM\""); + HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Crs_EditingCrs->ShrtName, + HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"INPUT_SHORT_NAME\" required=\"required\""); + HTM_TD_End (); - /***** Course full name *****/ - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Crs_EditingCrs->FullName, - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"INPUT_FULL_NAME\" required=\"required\""); - HTM_TD_End (); + /***** Course full name *****/ + HTM_TD_Begin ("class=\"LM\""); + HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Crs_EditingCrs->FullName, + HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"INPUT_FULL_NAME\" required=\"required\""); + HTM_TD_End (); - /***** Current number of teachers in this course *****/ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (0); - HTM_TD_End (); + /***** Current number of teachers in this course *****/ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (0); + HTM_TD_End (); - /***** Current number of students in this course *****/ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (0); - HTM_TD_End (); + /***** Current number of students in this course *****/ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (0); + HTM_TD_End (); - /***** Course requester *****/ - HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\""); - Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL); - HTM_TD_End (); + /***** Course requester *****/ + HTM_TD_Begin ("class=\"DAT INPUT_REQUESTER LT\""); + Msg_WriteMsgAuthor (&Gbl.Usrs.Me.UsrDat,true,NULL); + HTM_TD_End (); - /***** Course status *****/ - HTM_TD_Begin ("class=\"DAT LM\""); - HTM_TD_End (); + /***** Course status *****/ + HTM_TD_Begin ("class=\"DAT LM\""); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** End table, send button and end box *****/ - Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_course); + /***** End table, send button and end box *****/ + Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_course); /***** End form *****/ Frm_EndForm (); @@ -1561,13 +1478,13 @@ static void Crs_PutHeadCoursesForSeeing (void) HTM_TR_Begin (NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"CM",Txt_Institutional_BR_code); - HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); - HTM_TH (1,1,"LM",Txt_Course); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); - HTM_TH_Empty (1); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"CM",Txt_Institutional_BR_code); + HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); + HTM_TH (1,1,"LM",Txt_Course); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); + HTM_TH_Empty (1); HTM_TR_End (); } @@ -1589,18 +1506,18 @@ static void Crs_PutHeadCoursesForEdition (void) HTM_TR_Begin (NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"RM",Txt_Code); - HTM_TH_Begin (1,1,"CM"); - HTM_TxtF ("%s (%s)",Txt_Institutional_code,Txt_optional); - HTM_TH_End (); - HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); - HTM_TH (1,1,"LM",Txt_Short_name_of_the_course); - HTM_TH (1,1,"LM",Txt_Full_name_of_the_course); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); - HTM_TH (1,1,"LM",Txt_Requester); - HTM_TH_Empty (1); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"RM",Txt_Code); + HTM_TH_Begin (1,1,"CM"); + HTM_TxtF ("%s (%s)",Txt_Institutional_code,Txt_optional); + HTM_TH_End (); + HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); + HTM_TH (1,1,"LM",Txt_Short_name_of_the_course); + HTM_TH (1,1,"LM",Txt_Full_name_of_the_course); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); + HTM_TH (1,1,"LM",Txt_Requester); + HTM_TH_Empty (1); HTM_TR_End (); } @@ -1658,19 +1575,19 @@ static void Crs_ReceiveFormRequestOrCreateCrs (unsigned Status) Crs_EditingCrs->FullName[0]) // If there's a course name { /***** If name of course was in database... *****/ - if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName, + if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName, -1L,Crs_EditingCrs->DegCod,Crs_EditingCrs->Year)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists, Crs_EditingCrs->ShrtName); - else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName, + else if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName, -1L,Crs_EditingCrs->DegCod,Crs_EditingCrs->Year)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists, Crs_EditingCrs->FullName); else // Add new requested course to database { - Crs_CreateCourse (Status); + Crs_DB_CreateCourse (Crs_EditingCrs,Status); Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_Created_new_course_X, Crs_EditingCrs->FullName); @@ -1709,30 +1626,6 @@ static void Crs_GetParamsNewCourse (struct Crs_Course *Crs) Par_GetParToText ("FullName",Crs->FullName,Cns_HIERARCHY_MAX_BYTES_FULL_NAME); } -/*****************************************************************************/ -/************* Add a new requested course to pending requests ****************/ -/*****************************************************************************/ - -static void Crs_CreateCourse (unsigned Status) - { - /***** Insert new course into pending requests *****/ - Crs_EditingCrs->CrsCod = - DB_QueryINSERTandReturnCode ("can not create a new course", - "INSERT INTO crs_courses" - " (DegCod,Year,InsCrsCod,Status,RequesterUsrCod," - "ShortName,FullName)" - " VALUES" - " (%ld,%u,'%s',%u,%ld," - "'%s','%s')", - Crs_EditingCrs->DegCod, - Crs_EditingCrs->Year, - Crs_EditingCrs->InstitutionalCrsCod, - Status, - Gbl.Usrs.Me.UsrDat.UsrCod, - Crs_EditingCrs->ShrtName, - Crs_EditingCrs->FullName); - } - /*****************************************************************************/ /****************************** Remove a course ******************************/ /*****************************************************************************/ @@ -1798,18 +1691,7 @@ bool Crs_GetDataOfCourseByCod (struct Crs_Course *Crs) if (Crs->CrsCod > 0) { /***** Get data of a course from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get data of a course", - "SELECT CrsCod," // row[0] - "DegCod," // row[1] - "Year," // row[2] - "InsCrsCod," // row[3] - "Status," // row[4] - "RequesterUsrCod," // row[5] - "ShortName," // row[6] - "FullName" // row[7] - " FROM crs_courses" - " WHERE CrsCod=%ld", - Crs->CrsCod)) // Course found... + if (Crs_DB_GetDataOfCourseByCod (&mysql_res,Crs->CrsCod)) // Course found... { /***** Get data of the course *****/ row = mysql_fetch_row (mysql_res); @@ -1857,42 +1739,6 @@ static void Crs_GetDataOfCourseFromRow (struct Crs_Course *Crs,MYSQL_ROW row) Str_Copy (Crs->FullName,row[7],sizeof (Crs->FullName) - 1); } -/*****************************************************************************/ -/******* Get the short names of degree and course from a course code *********/ -/*****************************************************************************/ - -static void Crs_GetShortNamesByCod (long CrsCod, - char CrsShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1], - char DegShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - - DegShortName[0] = CrsShortName[0] = '\0'; - - if (CrsCod > 0) - { - /***** Get the short name of a degree from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get the short name of a course", - "SELECT crs_courses.ShortName," // row[0] - "deg_degrees.ShortName" // row[1] - " FROM crs_courses," - "deg_degrees" - " WHERE crs_courses.CrsCod=%ld" - " AND crs_courses.DegCod=deg_degrees.DegCod", - CrsCod) == 1) - { - /***** Get the course short name and degree short name *****/ - row = mysql_fetch_row (mysql_res); - Str_Copy (CrsShortName,row[0],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME); - Str_Copy (DegShortName,row[1],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - } - /*****************************************************************************/ /****************************** Remove a course ******************************/ /*****************************************************************************/ @@ -1905,16 +1751,10 @@ void Crs_RemoveCourseCompletely (long CrsCod) Crs_EmptyCourseCompletely (CrsCod); /***** Remove course from table of last accesses to courses in database *****/ - DB_QueryDELETE ("can not remove a course", - "DELETE FROM crs_last" - " WHERE CrsCod=%ld", - CrsCod); + Crs_DB_RemoveCrsLast (CrsCod); /***** Remove course from table of courses in database *****/ - DB_QueryDELETE ("can not remove a course", - "DELETE FROM crs_courses" - " WHERE CrsCod=%ld", - CrsCod); + Crs_DB_RemoveCrs (CrsCod); } } @@ -1943,53 +1783,28 @@ static void Crs_EmptyCourseCompletely (long CrsCod) Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod); /***** Remove information of the course ****/ + /* Remove information of the course */ + Crs_DB_RemoveCrsInfo (CrsCod); + /* Remove timetable of the course */ - DB_QueryDELETE ("can not remove the timetable of a course", - "DELETE FROM tmt_courses" - " WHERE CrsCod=%ld", - CrsCod); - - /* Remove other information of the course */ - DB_QueryDELETE ("can not remove info sources of a course", - "DELETE FROM crs_info_src" - " WHERE CrsCod=%ld", - CrsCod); - - DB_QueryDELETE ("can not remove info of a course", - "DELETE FROM crs_info_txt" - " WHERE CrsCod=%ld", - CrsCod); + Crs_DB_RemoveCrsTimetable (CrsCod); /***** Remove exam announcements in the course *****/ /* Mark all exam announcements in the course as deleted */ - DB_QueryUPDATE ("can not remove exam announcements of a course", - "UPDATE cfe_exams" - " SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Cfe_DELETED_CALL_FOR_EXAM, - CrsCod); + Cfe_DB_MarkCallForExamsInCrsAsDeleted (CrsCod); /***** Remove course cards of the course *****/ /* Remove content of course cards */ - DB_QueryDELETE ("can not remove content of cards in a course", - "DELETE FROM crs_records" - " USING crs_record_fields," - "crs_records" - " WHERE crs_record_fields.CrsCod=%ld" - " AND crs_record_fields.FieldCod=crs_records.FieldCod", - CrsCod); + Rec_DB_RemoveCrsRecordContents (CrsCod); /* Remove definition of fields in course cards */ - DB_QueryDELETE ("can not remove fields of cards in a course", - "DELETE FROM crs_record_fields" - " WHERE CrsCod=%ld", - CrsCod); + Rec_DB_RemoveCrsRecordFields (CrsCod); /***** Remove information related to files in course, including groups and projects, so this function must be called before removing groups and projects *****/ - Brw_RemoveCrsFilesFromDB (CrsCod); + Brw_DB_RemoveCrsFiles (CrsCod); /***** Remove assignments of the course *****/ Asg_RemoveCrsAssignments (CrsCod); @@ -2001,25 +1816,7 @@ static void Crs_EmptyCourseCompletely (long CrsCod) Att_RemoveCrsAttEvents (CrsCod); /***** Remove notices in the course *****/ - /* Copy all notices from the course to table of deleted notices */ - DB_QueryINSERT ("can not remove notices in a course", - "INSERT INTO not_deleted" - " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" - " SELECT NotCod," - "CrsCod," - "UsrCod," - "CreatTime," - "Content," - "NumNotif" - " FROM not_notices" - " WHERE CrsCod=%ld", - CrsCod); - - /* Remove all notices from the course */ - DB_QueryDELETE ("can not remove notices in a course", - "DELETE FROM not_notices" - " WHERE CrsCod=%ld", - CrsCod); + Not_DB_RemoveCrsNotices (CrsCod); /***** Remove all the threads and posts in forums of the course *****/ For_RemoveForums (Hie_Lvl_CRS,CrsCod); @@ -2037,47 +1834,14 @@ static void Crs_EmptyCourseCompletely (long CrsCod) Tst_RemoveCrsTests (CrsCod); /***** Remove groups in the course *****/ - /* Remove all the users in groups in the course */ - DB_QueryDELETE ("can not remove users from groups of a course", - "DELETE FROM grp_users" - " USING grp_types," - "grp_groups," - "grp_users" - " WHERE grp_types.CrsCod=%ld" - " AND grp_types.GrpTypCod=grp_groups.GrpTypCod" - " AND grp_groups.GrpCod=grp_users.GrpCod", - CrsCod); - - /* Remove all the groups in the course */ - DB_QueryDELETE ("can not remove groups of a course", - "DELETE FROM grp_groups" - " USING grp_types," - "grp_groups" - " WHERE grp_types.CrsCod=%ld" - " AND grp_types.GrpTypCod=grp_groups.GrpTypCod", - CrsCod); - - /* Remove all the group types in the course */ - DB_QueryDELETE ("can not remove types of group of a course", - "DELETE FROM grp_types" - " WHERE CrsCod=%ld", - CrsCod); + Grp_DB_RemoveCrsGrps (CrsCod); /***** Remove users' requests for inscription in the course *****/ - DB_QueryDELETE ("can not remove requests for inscription to a course", - "DELETE FROM crs_requests" - " WHERE CrsCod=%ld", - CrsCod); + Enr_DB_RemCrsRequests (CrsCod); /***** Remove possible users remaining in the course (teachers) *****/ - DB_QueryDELETE ("can not remove users from a course", - "DELETE FROM crs_user_settings" - " WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE ("can not remove users from a course", - "DELETE FROM crs_users" - " WHERE CrsCod=%ld", - CrsCod); + Enr_DB_RemAllUsrsFromCrsSettings (CrsCod); + Enr_DB_RemAllUsrsFromCrs (CrsCod); /***** Remove directories of the course *****/ snprintf (PathRelCrs,sizeof (PathRelCrs),"%s/%ld", @@ -2163,13 +1927,13 @@ void Crs_ChangeCrsYear (void) if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid { /***** If name of course was in database in the new year... *****/ - if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName, + if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Crs_EditingCrs->ShrtName, -1L,Crs_EditingCrs->DegCod,NewYear)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists_in_year_Y, Crs_EditingCrs->ShrtName, Txt_YEAR_OF_DEGREE[NewYear]); - else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName, + else if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("FullName",Crs_EditingCrs->FullName, -1L,Crs_EditingCrs->DegCod,NewYear)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists_in_year_Y, @@ -2195,6 +1959,21 @@ void Crs_ChangeCrsYear (void) Err_NoPermissionExit (); } +/*****************************************************************************/ +/************* Change the institutional course code of a course **************/ +/*****************************************************************************/ + +void Crs_UpdateInstitutionalCrsCod (struct Crs_Course *Crs, + const char *NewInstitutionalCrsCod) + { + /***** Update institutional course code in table of courses *****/ + Crs_DB_UpdateInstitutionalCrsCod (Crs->CrsCod,NewInstitutionalCrsCod); + + /***** Copy institutional course code *****/ + Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod, + sizeof (Crs->InstitutionalCrsCod) - 1); + } + /*****************************************************************************/ /****************** Change the year/semester of a course *********************/ /*****************************************************************************/ @@ -2202,35 +1981,23 @@ void Crs_ChangeCrsYear (void) void Crs_UpdateCrsYear (struct Crs_Course *Crs,unsigned NewYear) { /***** Update year/semester in table of courses *****/ - DB_QueryUPDATE ("can not update the year of a course", - "UPDATE crs_courses" - " SET Year=%u" - " WHERE CrsCod=%ld", - NewYear, - Crs->CrsCod); + Crs_DB_UpdateCrsYear (Crs->CrsCod,NewYear); /***** Copy course year/semester *****/ Crs->Year = NewYear; } /*****************************************************************************/ -/************* Change the institutional course code of a course **************/ +/********************** Change the status of a course ************************/ /*****************************************************************************/ -void Crs_UpdateInstitutionalCrsCod (struct Crs_Course *Crs,const char *NewInstitutionalCrsCod) +static void Crs_UpdateCrsStatus (struct Crs_Course *Crs,Crs_Status_t Status) { - /***** Update institutional course code in table of courses *****/ - DB_QueryUPDATE ("can not update the institutional code" - " of the current course", - "UPDATE crs_courses" - " SET InsCrsCod='%s'" - " WHERE CrsCod=%ld", - NewInstitutionalCrsCod, - Crs->CrsCod); + /***** Update status in table of courses *****/ + Crs_DB_UpdateCrsStatus (Crs->CrsCod,Status); - /***** Copy institutional course code *****/ - Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod, - sizeof (Crs->InstitutionalCrsCod) - 1); + /***** Copy course status *****/ + Crs->Status = Status; } /*****************************************************************************/ @@ -2305,7 +2072,7 @@ void Crs_RenameCourse (struct Crs_Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullNam if (strcmp (CurrentCrsName,NewCrsName)) // Different names { /***** If course was in database... *****/ - if (Crs_CheckIfCrsNameExistsInYearOfDeg (ParamName,NewCrsName,Crs->CrsCod, + if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (ParamName,NewCrsName,Crs->CrsCod, Crs->DegCod,Crs->Year)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists, @@ -2313,7 +2080,7 @@ void Crs_RenameCourse (struct Crs_Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullNam else { /* Update the table changing old name by new name */ - Crs_UpdateCrsNameDB (Crs->CrsCod,FieldName,NewCrsName); + Crs_DB_UpdateCrsName (Crs->CrsCod,FieldName,NewCrsName); /* Create alert to show the change made */ Ale_CreateAlert (Ale_SUCCESS,NULL, @@ -2336,44 +2103,6 @@ void Crs_RenameCourse (struct Crs_Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullNam Err_NoPermissionExit (); } -/*****************************************************************************/ -/********** Check if the name of course exists in existing courses ***********/ -/*****************************************************************************/ - -bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod, - long DegCod,unsigned Year) - { - /***** Get number of courses in a year of a degree and with a name from database *****/ - return (DB_QueryCOUNT ("can not check if the name" - " of a course already existed", - "SELECT COUNT(*)" - " FROM crs_courses" - " WHERE DegCod=%ld" - " AND Year=%u" - " AND %s='%s'" - " AND CrsCod<>%ld", - DegCod, - Year, - FieldName, - Name, - CrsCod) != 0); - } - -/*****************************************************************************/ -/***************** Update course name in table of courses ********************/ -/*****************************************************************************/ - -static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName) - { - /***** Update course changing old name by new name *****/ - DB_QueryUPDATE ("can not update the name of a course", - "UPDATE crs_courses" - " SET %s='%s'" - " WHERE CrsCod=%ld", - FieldName,NewCrsName, - CrsCod); - } - /*****************************************************************************/ /*********************** Change the status of a course ***********************/ /*****************************************************************************/ @@ -2405,14 +2134,8 @@ void Crs_ChangeCrsStatus (void) /***** Get data of course *****/ Crs_GetDataOfCourseByCod (Crs_EditingCrs); - /***** Update status in table of courses *****/ - DB_QueryUPDATE ("can not update the status of a course", - "UPDATE crs_courses" - " SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Status, - Crs_EditingCrs->CrsCod); - Crs_EditingCrs->Status = Status; + /***** Update status *****/ + Crs_UpdateCrsStatus (Crs_EditingCrs,Status); /***** Create alert to show the change made *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, @@ -2490,8 +2213,8 @@ static void Crs_PutButtonToGoToCrs (void) { Frm_BeginForm (ActSeeCrsInf); Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod); - Btn_PutConfirmButton (Hie_BuildGoToMsg (Crs_EditingCrs->ShrtName)); - Hie_FreeGoToMsg (); + Btn_PutConfirmButton (Hie_BuildGoToMsg (Crs_EditingCrs->ShrtName)); + Hie_FreeGoToMsg (); Frm_EndForm (); } } @@ -2508,9 +2231,11 @@ static void Crs_PutButtonToRegisterInCrs (void) // If the course being edited is different to the current one... if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod) Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod); + Btn_PutCreateButton (Str_BuildStringStr (Txt_Register_me_in_X, Crs_EditingCrs->ShrtName)); Str_FreeString (); + Frm_EndForm (); } @@ -2560,15 +2285,9 @@ void Crs_PutIconToSelectMyCoursesInBreadcrumb (void) /***** Begin form *****/ Frm_BeginForm (ActMyCrs); - /***** Put icon with link *****/ - HTM_INPUT_IMAGE (Gbl.Prefs.URLTheme,"sitemap.svg",Txt_My_courses, - "BC_ICON ICO_HIGHLIGHT"); - /* - HTM_BUTTON_Begin (Txt_My_courses,NULL,NULL); - HTM_IMG (Gbl.Prefs.URLTheme,"sitemap.svg",Txt_My_courses, - "class=\"BC_ICON ICO_HIGHLIGHT\""); - HTM_BUTTON_End (); - */ + /***** Put icon with link *****/ + HTM_INPUT_IMAGE (Gbl.Prefs.URLTheme,"sitemap.svg",Txt_My_courses, + "BC_ICON ICO_HIGHLIGHT"); /***** End form *****/ Frm_EndForm (); @@ -2638,48 +2357,13 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role) extern const char *Txt_Year_OF_A_DEGREE; extern const char *Txt_Course; extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES]; - char *SubQuery; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumCrss; unsigned NumCrs; /***** Get courses of a user from database *****/ - if (Role == Rol_UNK) // Role == Rol_UNK ==> any role - { - if (asprintf (&SubQuery,"%s","") < 0) - Err_NotEnoughMemoryExit (); - } - else - { - if (asprintf (&SubQuery," AND crs_users.Role=%u",(unsigned) Role) < 0) - Err_NotEnoughMemoryExit (); - } - NumCrss = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get courses of a user", - "SELECT deg_degrees.DegCod," // row[0] - "crs_courses.CrsCod," // row[1] - "deg_degrees.ShortName," // row[2] - "deg_degrees.FullName," // row[3] - "crs_courses.Year," // row[4] - "crs_courses.FullName," // row[5] - "ctr_centers.ShortName," // row[6] - "crs_users.Accepted" // row[7] - " FROM crs_users," - "crs_courses," - "deg_degrees," - "ctr_centers" - " WHERE crs_users.UsrCod=%ld%s" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " ORDER BY deg_degrees.FullName," - "crs_courses.Year," - "crs_courses.FullName", - UsrDat->UsrCod,SubQuery); - - /***** Free allocated memory for subquery *****/ - free (SubQuery); + NumCrss = Crs_DB_GetCrssOfAUsr (&mysql_res,UsrDat->UsrCod,Role); /***** List the courses (one row per course) *****/ if (NumCrss) @@ -2689,42 +2373,42 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role) NULL,NULL, NULL,Box_NOT_CLOSABLE,2); - /* Heading row */ - HTM_TR_Begin (NULL); + /* Heading row */ + HTM_TR_Begin (NULL); - HTM_TH_Begin (1,7,"LM"); - HTM_TxtColon (Str_BuildStringStr (Txt_USER_in_COURSE, - Role == Rol_UNK ? Txt_User[Usr_SEX_UNKNOWN] : // Role == Rol_UNK ==> any role - Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex])); - Str_FreeString (); - HTM_TH_End (); + HTM_TH_Begin (1,7,"LM"); + HTM_TxtColon (Str_BuildStringStr (Txt_USER_in_COURSE, + Role == Rol_UNK ? Txt_User[Usr_SEX_UNKNOWN] : // Role == Rol_UNK ==> any role + Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex])); + Str_FreeString (); + HTM_TH_End (); - HTM_TR_End (); + HTM_TR_End (); - HTM_TR_Begin (NULL); + HTM_TR_Begin (NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"LM",Txt_Degree); - HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); - HTM_TH (1,1,"LM",Txt_Course); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NET]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"LM",Txt_Degree); + HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); + HTM_TH (1,1,"LM",Txt_Course); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NET]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); - HTM_TR_End (); + HTM_TR_End (); - /* Write courses */ - for (NumCrs = 1; - NumCrs <= NumCrss; - NumCrs++) - { - /* Get next course */ - row = mysql_fetch_row (mysql_res); + /* Write courses */ + for (NumCrs = 1; + NumCrs <= NumCrss; + NumCrs++) + { + /* Get next course */ + row = mysql_fetch_row (mysql_res); - /* Write data of this course */ - Crs_WriteRowCrsData (NumCrs,row,true); - } + /* Write data of this course */ + Crs_WriteRowCrsData (NumCrs,row,true); + } /* End table and box */ Box_BoxTableEnd (); @@ -2761,30 +2445,30 @@ void Crs_ListCrssFound (MYSQL_RES **mysql_res,unsigned NumCrss) NULL,Box_NOT_CLOSABLE,2); Str_FreeString (); - /***** Heading row *****/ - HTM_TR_Begin (NULL); + /***** Heading row *****/ + HTM_TR_Begin (NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"LM",Txt_Degree); - HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); - HTM_TH (1,1,"LM",Txt_Course); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NET]); - HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"LM",Txt_Degree); + HTM_TH (1,1,"CM",Txt_Year_OF_A_DEGREE); + HTM_TH (1,1,"LM",Txt_Course); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NET]); + HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); - HTM_TR_End (); + HTM_TR_End (); - /***** Write courses *****/ - for (NumCrs = 1; - NumCrs <= NumCrss; - NumCrs++) - { - /* Get next course */ - row = mysql_fetch_row (*mysql_res); + /***** Write courses *****/ + for (NumCrs = 1; + NumCrs <= NumCrss; + NumCrs++) + { + /* Get next course */ + row = mysql_fetch_row (*mysql_res); - /* Write data of this course */ - Crs_WriteRowCrsData (NumCrs,row,false); - } + /* Write data of this course */ + Crs_WriteRowCrsData (NumCrs,row,false); + } /***** End table and box *****/ Box_BoxTableEnd (); @@ -2856,67 +2540,67 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA /***** Start row *****/ HTM_TR_Begin (NULL); - /***** User has accepted joining to this course/to any course in degree/to any course? *****/ - if (WriteColumnAccepted) - { - Accepted = (row[7][0] == 'Y'); - HTM_TD_Begin ("class=\"BT %s\" title=\"%s\"", - BgColor, - Accepted ? Txt_Enrolment_confirmed : - Txt_Enrolment_not_confirmed); - HTM_Txt (Accepted ? "✓" : - "✗"); + /***** User has accepted joining to this course/to any course in degree/to any course? *****/ + if (WriteColumnAccepted) + { + Accepted = (row[7][0] == 'Y'); + HTM_TD_Begin ("class=\"BT %s\" title=\"%s\"", + BgColor, + Accepted ? Txt_Enrolment_confirmed : + Txt_Enrolment_not_confirmed); + HTM_Txt (Accepted ? "✓" : + "✗"); + HTM_TD_End (); + } + + /***** Write number of course in this search *****/ + HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); + HTM_Unsigned (NumCrs); HTM_TD_End (); - } - /***** Write number of course in this search *****/ - HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); - HTM_Unsigned (NumCrs); - HTM_TD_End (); + /***** Write degree logo, degree short name (row[2]) + and center short name (row[6]) *****/ + HTM_TD_Begin ("class=\"LT %s\"",BgColor); + Frm_BeginFormGoTo (ActSeeDegInf); + Deg_PutParamDegCod (Deg.DegCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[2]),ClassLink,NULL); + Hie_FreeGoToMsg (); + Lgo_DrawLogo (Hie_Lvl_DEG,Deg.DegCod,Deg.ShrtName,20,"CT",true); + HTM_TxtF (" %s (%s)",row[2],row[6]); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_TD_End (); - /***** Write degree logo, degree short name (row[2]) - and center short name (row[6]) *****/ - HTM_TD_Begin ("class=\"LT %s\"",BgColor); - Frm_BeginFormGoTo (ActSeeDegInf); - Deg_PutParamDegCod (Deg.DegCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[2]),ClassLink,NULL); - Hie_FreeGoToMsg (); - Lgo_DrawLogo (Hie_Lvl_DEG,Deg.DegCod,Deg.ShrtName,20,"CT",true); - HTM_TxtF (" %s (%s)",row[2],row[6]); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_TD_End (); + /***** Write year (row[4]) *****/ + HTM_TD_Begin ("class=\"%s CT %s\"",ClassTxt,BgColor); + HTM_Txt (Txt_YEAR_OF_DEGREE[Deg_ConvStrToYear (row[4])]); + HTM_TD_End (); - /***** Write year (row[4]) *****/ - HTM_TD_Begin ("class=\"%s CT %s\"",ClassTxt,BgColor); - HTM_Txt (Txt_YEAR_OF_DEGREE[Deg_ConvStrToYear (row[4])]); - HTM_TD_End (); + /***** Write course full name (row[5]) *****/ + HTM_TD_Begin ("class=\"LT %s\"",BgColor); + Frm_BeginFormGoTo (ActSeeCrsInf); + Crs_PutParamCrsCod (CrsCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[5]),ClassLink,NULL); + Hie_FreeGoToMsg (); + HTM_Txt (row[5]); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_TD_End (); - /***** Write course full name (row[5]) *****/ - HTM_TD_Begin ("class=\"LT %s\"",BgColor); - Frm_BeginFormGoTo (ActSeeCrsInf); - Crs_PutParamCrsCod (CrsCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[5]),ClassLink,NULL); - Hie_FreeGoToMsg (); - HTM_Txt (row[5]); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_TD_End (); + /***** Write number of teachers in course *****/ + HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); + HTM_Unsigned (NumTchs); + HTM_TD_End (); - /***** Write number of teachers in course *****/ - HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); - HTM_Unsigned (NumTchs); - HTM_TD_End (); + /***** Write number of non-editing teachers in course *****/ + HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); + HTM_Unsigned (NumNETs); + HTM_TD_End (); - /***** Write number of non-editing teachers in course *****/ - HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); - HTM_Unsigned (NumNETs); - HTM_TD_End (); - - /***** Write number of students in course *****/ - HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); - HTM_Unsigned (NumStds); - HTM_TD_End (); + /***** Write number of students in course *****/ + HTM_TD_Begin ("class=\"%s RT %s\"",ClassTxt,BgColor); + HTM_Unsigned (NumStds); + HTM_TD_End (); HTM_TR_End (); @@ -2924,20 +2608,15 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA } /*****************************************************************************/ -/***************** Update my last click in current course ********************/ +/******************* Update last click in current course *********************/ /*****************************************************************************/ void Crs_UpdateCrsLast (void) { if (Gbl.Hierarchy.Level == Hie_Lvl_CRS && // Course selected Gbl.Usrs.Me.Role.Logged >= Rol_STD) - /***** Update my last access to current course *****/ - DB_QueryREPLACE ("can not update last access to current course", - "REPLACE INTO crs_last" - " (CrsCod,LastTime)" - " VALUES" - " (%ld,NOW())", - Gbl.Hierarchy.Crs.CrsCod); + /***** Update last access to current course *****/ + Crs_DB_UpdateCrsLastClick (); } /*****************************************************************************/ @@ -2973,30 +2652,30 @@ void Crs_AskRemoveOldCrss (void) /***** Begin form *****/ Frm_BeginForm (ActRemOldCrs); - /***** Begin box *****/ - Box_BoxBegin (NULL,Txt_Eliminate_old_courses, - NULL,NULL, - Hlp_SYSTEM_Maintenance_eliminate_old_courses,Box_NOT_CLOSABLE); + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Eliminate_old_courses, + NULL,NULL, + Hlp_SYSTEM_Maintenance_eliminate_old_courses,Box_NOT_CLOSABLE); - /***** Form to request number of months without clicks *****/ - HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); - HTM_TxtF ("%s ",Txt_Eliminate_all_courses_whithout_users_PART_1_OF_2); - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "name=\"Months\""); - for (i = Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS; - i <= Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS; - i++) - HTM_OPTION (HTM_Type_UNSIGNED,&i, - i == MonthsWithoutAccess,false, - "%u",i); - HTM_SELECT_End (); - HTM_NBSP (); - HTM_TxtF (Txt_Eliminate_all_courses_whithout_users_PART_2_OF_2, - Cfg_PLATFORM_SHORT_NAME); - HTM_LABEL_End (); + /***** Form to request number of months without clicks *****/ + HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); + HTM_TxtF ("%s ",Txt_Eliminate_all_courses_whithout_users_PART_1_OF_2); + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "name=\"Months\""); + for (i = Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS; + i <= Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS; + i++) + HTM_OPTION (HTM_Type_UNSIGNED,&i, + i == MonthsWithoutAccess,false, + "%u",i); + HTM_SELECT_End (); + HTM_NBSP (); + HTM_TxtF (Txt_Eliminate_all_courses_whithout_users_PART_2_OF_2, + Cfg_PLATFORM_SHORT_NAME); + HTM_LABEL_End (); - /***** Send button and end box *****/ - Box_BoxWithButtonEnd (Btn_REMOVE_BUTTON,Txt_Eliminate); + /***** Send button and end box *****/ + Box_BoxWithButtonEnd (Btn_REMOVE_BUTTON,Txt_Eliminate); /***** End form *****/ Frm_EndForm (); @@ -3029,17 +2708,9 @@ void Crs_RemoveOldCrss (void) SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; /***** Get old courses from database *****/ - NumCrss = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get old courses", - "SELECT CrsCod" - " FROM crs_last" - " WHERE LastTime // For free #include // For string functions +#include "swad_course_database.h" #include "swad_database.h" #include "swad_error.h" #include "swad_form.h" @@ -77,8 +78,6 @@ static void CrsCfg_Shortcut (bool PrintView); static void CrsCfg_QR (void); static void CrsCfg_Indicators (void); -static void CrsCfg_UpdateCrsDegDB (long CrsCod,long DegCod); - /*****************************************************************************/ /***************** Configuration of the current course ***********************/ /*****************************************************************************/ @@ -129,48 +128,48 @@ void CrsCfg_Configuration (bool PrintView) /**************************** Left part ***********************************/ HTM_DIV_Begin ("class=\"HIE_CFG_LEFT HIE_CFG_WIDTH\""); - /***** Begin table *****/ - HTM_TABLE_BeginWidePadding (2); + /***** Begin table *****/ + HTM_TABLE_BeginWidePadding (2); - /***** Degree *****/ - CrsCfg_Degree (PrintView,PutFormDeg); + /***** Degree *****/ + CrsCfg_Degree (PrintView,PutFormDeg); - /***** Course name *****/ - CrsCfg_FullName (PutFormName); - CrsCfg_ShrtName (PutFormName); + /***** Course name *****/ + CrsCfg_FullName (PutFormName); + CrsCfg_ShrtName (PutFormName); - /***** Course year *****/ - CrsCfg_Year (PutFormYear); + /***** Course year *****/ + CrsCfg_Year (PutFormYear); - if (!PrintView) - { - /***** Institutional code of the course *****/ - CrsCfg_InstitutionalCode (PutFormInsCod); + if (!PrintView) + { + /***** Institutional code of the course *****/ + CrsCfg_InstitutionalCode (PutFormInsCod); - /***** Internal code of the course *****/ - CrsCfg_InternalCode (); - } + /***** Internal code of the course *****/ + CrsCfg_InternalCode (); + } - /***** Shortcut to the couse *****/ - CrsCfg_Shortcut (PrintView); + /***** Shortcut to the couse *****/ + CrsCfg_Shortcut (PrintView); - if (PrintView) - /***** QR code with link to the course *****/ - CrsCfg_QR (); - else - { - /***** Number of users *****/ - HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_TCH); - HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_NET); - HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_STD); - HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_UNK); + if (PrintView) + /***** QR code with link to the course *****/ + CrsCfg_QR (); + else + { + /***** Number of users *****/ + HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_TCH); + HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_NET); + HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_STD); + HieCfg_NumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,Rol_UNK); - /***** Indicators *****/ - CrsCfg_Indicators (); - } + /***** Indicators *****/ + CrsCfg_Indicators (); + } - /***** End table *****/ - HTM_TABLE_End (); + /***** End table *****/ + HTM_TABLE_End (); /***** End of left part *****/ HTM_DIV_End (); @@ -205,12 +204,12 @@ void CrsCfg_PrintConfiguration (void) static void CrsCfg_Title (bool PutLink) { HieCfg_Title (PutLink, - Hie_Lvl_DEG, // Logo scope - Gbl.Hierarchy.Deg.DegCod, // Logo code - Gbl.Hierarchy.Deg.ShrtName, // Logo short name - Gbl.Hierarchy.Deg.FullName, // Logo full name - Gbl.Hierarchy.Deg.WWW, // Logo www - Gbl.Hierarchy.Crs.FullName); // Text full name + Hie_Lvl_DEG, // Logo scope + Gbl.Hierarchy.Deg.DegCod, // Logo code + Gbl.Hierarchy.Deg.ShrtName, // Logo short name + Gbl.Hierarchy.Deg.FullName, // Logo full name + Gbl.Hierarchy.Deg.WWW, // Logo www + Gbl.Hierarchy.Crs.FullName); // Text full name } /*****************************************************************************/ @@ -225,56 +224,56 @@ static void CrsCfg_Degree (bool PrintView,bool PutForm) /***** Degree *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "OthDegCod" : - NULL, - Txt_Degree); + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "OthDegCod" : + NULL, + Txt_Degree); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - /* Get list of degrees of the current center */ - Deg_GetListDegsInCurrentCtr (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + /* Get list of degrees of the current center */ + Deg_GetListDegsInCurrentCtr (); - /* Put form to select degree */ - Frm_BeginForm (ActChgCrsDegCfg); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"OthDegCod\" name=\"OthDegCod\"" - " class=\"INPUT_SHORT_NAME\""); - for (NumDeg = 0; - NumDeg < Gbl.Hierarchy.Degs.Num; - NumDeg++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Degs.Lst[NumDeg].DegCod, - Gbl.Hierarchy.Degs.Lst[NumDeg].DegCod == Gbl.Hierarchy.Deg.DegCod,false, - "%s",Gbl.Hierarchy.Degs.Lst[NumDeg].ShrtName); - HTM_SELECT_End (); - Frm_EndForm (); + /* Put form to select degree */ + Frm_BeginForm (ActChgCrsDegCfg); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"OthDegCod\" name=\"OthDegCod\"" + " class=\"INPUT_SHORT_NAME\""); + for (NumDeg = 0; + NumDeg < Gbl.Hierarchy.Degs.Num; + NumDeg++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Degs.Lst[NumDeg].DegCod, + Gbl.Hierarchy.Degs.Lst[NumDeg].DegCod == Gbl.Hierarchy.Deg.DegCod,false, + "%s",Gbl.Hierarchy.Degs.Lst[NumDeg].ShrtName); + HTM_SELECT_End (); + Frm_EndForm (); - /* Free list of degrees of the current center */ - Deg_FreeListDegs (&Gbl.Hierarchy.Degs); - } - else // I can not move course to another degree - { - if (!PrintView) - { - Frm_BeginFormGoTo (ActSeeDegInf); - Deg_PutParamDegCod (Gbl.Hierarchy.Deg.DegCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Deg.ShrtName), - "BT_LINK LT DAT",NULL); - Hie_FreeGoToMsg (); - } - Lgo_DrawLogo (Hie_Lvl_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.ShrtName, - 20,"LM",true); - HTM_NBSP (); - HTM_Txt (Gbl.Hierarchy.Deg.FullName); - if (!PrintView) - { - HTM_BUTTON_End (); - Frm_EndForm (); - } - } - HTM_TD_End (); + /* Free list of degrees of the current center */ + Deg_FreeListDegs (&Gbl.Hierarchy.Degs); + } + else // I can not move course to another degree + { + if (!PrintView) + { + Frm_BeginFormGoTo (ActSeeDegInf); + Deg_PutParamDegCod (Gbl.Hierarchy.Deg.DegCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Deg.ShrtName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); + } + Lgo_DrawLogo (Hie_Lvl_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.ShrtName, + 20,"LM",true); + HTM_NBSP (); + HTM_Txt (Gbl.Hierarchy.Deg.FullName); + if (!PrintView) + { + HTM_BUTTON_End (); + Frm_EndForm (); + } + } + HTM_TD_End (); HTM_TR_End (); } @@ -314,31 +313,31 @@ static void CrsCfg_Year (bool PutForm) /***** Academic year *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "OthCrsYear" : - NULL, - Txt_Year_OF_A_DEGREE); + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "OthCrsYear" : + NULL, + Txt_Year_OF_A_DEGREE); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - Frm_BeginForm (ActChgCrsYeaCfg); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"OthCrsYear\" name=\"OthCrsYear\""); - for (Year = 0; - Year <= Deg_MAX_YEARS_PER_DEGREE; - Year++) - HTM_OPTION (HTM_Type_UNSIGNED,&Year, - Year == Gbl.Hierarchy.Crs.Year,false, - "%s",Txt_YEAR_OF_DEGREE[Year]); - HTM_SELECT_End (); - Frm_EndForm (); - } - else - HTM_Txt (Gbl.Hierarchy.Crs.Year ? Txt_YEAR_OF_DEGREE[Gbl.Hierarchy.Crs.Year] : - Txt_Not_applicable); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + Frm_BeginForm (ActChgCrsYeaCfg); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"OthCrsYear\" name=\"OthCrsYear\""); + for (Year = 0; + Year <= Deg_MAX_YEARS_PER_DEGREE; + Year++) + HTM_OPTION (HTM_Type_UNSIGNED,&Year, + Year == Gbl.Hierarchy.Crs.Year,false, + "%s",Txt_YEAR_OF_DEGREE[Year]); + HTM_SELECT_End (); + Frm_EndForm (); + } + else + HTM_Txt (Gbl.Hierarchy.Crs.Year ? Txt_YEAR_OF_DEGREE[Gbl.Hierarchy.Crs.Year] : + Txt_Not_applicable); + HTM_TD_End (); HTM_TR_End (); } @@ -354,26 +353,26 @@ static void CrsCfg_InstitutionalCode (bool PutForm) /***** Institutional course code *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "InsCrsCod" : - NULL, - Txt_Institutional_code); + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "InsCrsCod" : + NULL, + Txt_Institutional_code); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - Frm_BeginForm (ActChgInsCrsCodCfg); - HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, - Gbl.Hierarchy.Crs.InstitutionalCrsCod, - HTM_SUBMIT_ON_CHANGE, - "id=\"InsCrsCod\" size=\"%u\" class=\"INPUT_INS_CODE\"", - Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD); - Frm_EndForm (); - } - else - HTM_Txt (Gbl.Hierarchy.Crs.InstitutionalCrsCod); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + Frm_BeginForm (ActChgInsCrsCodCfg); + HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, + Gbl.Hierarchy.Crs.InstitutionalCrsCod, + HTM_SUBMIT_ON_CHANGE, + "id=\"InsCrsCod\" size=\"%u\" class=\"INPUT_INS_CODE\"", + Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD); + Frm_EndForm (); + } + else + HTM_Txt (Gbl.Hierarchy.Crs.InstitutionalCrsCod); + HTM_TD_End (); HTM_TR_End (); } @@ -389,13 +388,13 @@ static void CrsCfg_InternalCode (void) /***** Internal course code *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Internal_code); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Internal_code); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Long (Gbl.Hierarchy.Crs.CrsCod); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Long (Gbl.Hierarchy.Crs.CrsCod); + HTM_TD_End (); HTM_TR_End (); } @@ -437,25 +436,25 @@ static void CrsCfg_Indicators (void) /***** Number of indicators *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Indicators); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Indicators); - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_BeginForm (ActReqStaCrs); - if (asprintf (&Title,"%u %s %u", - IndicatorsCrs.NumIndicators, - Txt_of_PART_OF_A_TOTAL,Ind_NUM_INDICATORS) < 0) - Err_NotEnoughMemoryExit (); - HTM_BUTTON_SUBMIT_Begin (Title,"BT_LINK DAT",NULL); - HTM_TxtF ("%s ",Title); - Ico_PutIcon ((IndicatorsCrs.NumIndicators == Ind_NUM_INDICATORS) ? "check-circle.svg" : - "exclamation-triangle.svg", - Title,"ICO16x16"); - HTM_BUTTON_End (); - free (Title); - Frm_EndForm (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_BeginForm (ActReqStaCrs); + if (asprintf (&Title,"%u %s %u", + IndicatorsCrs.NumIndicators, + Txt_of_PART_OF_A_TOTAL,Ind_NUM_INDICATORS) < 0) + Err_NotEnoughMemoryExit (); + HTM_BUTTON_SUBMIT_Begin (Title,"BT_LINK DAT",NULL); + HTM_TxtF ("%s ",Title); + Ico_PutIcon ((IndicatorsCrs.NumIndicators == Ind_NUM_INDICATORS) ? "check-circle.svg" : + "exclamation-triangle.svg", + Title,"ICO16x16"); + HTM_BUTTON_End (); + free (Title); + Frm_EndForm (); + HTM_TD_End (); HTM_TR_End (); } @@ -481,15 +480,15 @@ void CrsCfg_ChangeCrsDeg (void) Deg_GetDataOfDegreeByCod (&NewDeg); /***** If name of course was in database in the new degree... *****/ - if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Hierarchy.Crs.ShrtName,-1L, - NewDeg.DegCod,Gbl.Hierarchy.Crs.Year)) + if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Hierarchy.Crs.ShrtName,-1L, + NewDeg.DegCod,Gbl.Hierarchy.Crs.Year)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z, Txt_YEAR_OF_DEGREE[Gbl.Hierarchy.Crs.Year], NewDeg.FullName, Gbl.Hierarchy.Crs.ShrtName); - else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Hierarchy.Crs.FullName,-1L, - NewDeg.DegCod,Gbl.Hierarchy.Crs.Year)) + else if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Hierarchy.Crs.FullName,-1L, + NewDeg.DegCod,Gbl.Hierarchy.Crs.Year)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z, Txt_YEAR_OF_DEGREE[Gbl.Hierarchy.Crs.Year], @@ -498,7 +497,7 @@ void CrsCfg_ChangeCrsDeg (void) else // Update degree in database { /***** Update degree in table of courses *****/ - CrsCfg_UpdateCrsDegDB (Gbl.Hierarchy.Crs.CrsCod,NewDeg.DegCod); + Crs_DB_UpdateCrsDeg (Gbl.Hierarchy.Crs.CrsCod,NewDeg.DegCod); Gbl.Hierarchy.Crs.DegCod = Gbl.Hierarchy.Deg.DegCod = NewDeg.DegCod; @@ -514,21 +513,6 @@ void CrsCfg_ChangeCrsDeg (void) } } -/*****************************************************************************/ -/********************** Update degree in table of courses ********************/ -/*****************************************************************************/ - -static void CrsCfg_UpdateCrsDegDB (long CrsCod,long DegCod) - { - /***** Update degree in table of courses *****/ - DB_QueryUPDATE ("can not move course to another degree", - "UPDATE crs_courses" - " SET DegCod=%ld" - " WHERE CrsCod=%ld", - DegCod, - CrsCod); - } - /*****************************************************************************/ /*************** Change the name of a course in configuration ****************/ /*****************************************************************************/ @@ -563,14 +547,14 @@ void CrsCfg_ChangeCrsYear (void) if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid { /***** If name of course was in database in the new year... *****/ - if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Hierarchy.Crs.ShrtName,-1L, - Gbl.Hierarchy.Crs.DegCod,NewYear)) + if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Hierarchy.Crs.ShrtName,-1L, + Gbl.Hierarchy.Crs.DegCod,NewYear)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists_in_year_Y, Gbl.Hierarchy.Crs.ShrtName, Txt_YEAR_OF_DEGREE[NewYear]); - else if (Crs_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Hierarchy.Crs.FullName,-1L, - Gbl.Hierarchy.Crs.DegCod,NewYear)) + else if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg ("FullName",Gbl.Hierarchy.Crs.FullName,-1L, + Gbl.Hierarchy.Crs.DegCod,NewYear)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_course_X_already_exists_in_year_Y, Gbl.Hierarchy.Crs.FullName, diff --git a/swad_course_database.c b/swad_course_database.c new file mode 100644 index 00000000..12e81a66 --- /dev/null +++ b/swad_course_database.c @@ -0,0 +1,501 @@ +// swad_course_database.c: edition of courses operations with database + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +#include // For asprintf + +#include "swad_course.h" +#include "swad_course_config.h" +#include "swad_database.h" +#include "swad_error.h" +#include "swad_global.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/*************************** Public constants ********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private types *********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/**************************** Private variables ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/**************************** Private prototypes *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************* Add a new requested course to pending requests ****************/ +/*****************************************************************************/ + +void Crs_DB_CreateCourse (struct Crs_Course *Crs,unsigned Status) + { + /***** Insert new course into pending requests *****/ + Crs->CrsCod = + DB_QueryINSERTandReturnCode ("can not create a new course", + "INSERT INTO crs_courses" + " (DegCod,Year,InsCrsCod,Status,RequesterUsrCod," + "ShortName,FullName)" + " VALUES" + " (%ld,%u,'%s',%u,%ld," + "'%s','%s')", + Crs->DegCod, + Crs->Year, + Crs->InstitutionalCrsCod, + Status, + Gbl.Usrs.Me.UsrDat.UsrCod, + Crs->ShrtName, + Crs->FullName); + } + +/*****************************************************************************/ +/******************** Get courses in current degree *********************/ +/*****************************************************************************/ + +unsigned Crs_DB_GetCrssInCurrentDegBasic (MYSQL_RES **mysql_res) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get courses of a degree", + "SELECT CrsCod," // row[0] + "ShortName" // row[1] + " FROM crs_courses" + " WHERE DegCod=%ld" + " ORDER BY ShortName", + Gbl.Hierarchy.Deg.DegCod); + } + +/*****************************************************************************/ +/******************** Get courses in current degree *********************/ +/*****************************************************************************/ + +unsigned Crs_DB_GetCrssInCurrentDegFull (MYSQL_RES **mysql_res) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get courses of a degree", + "SELECT CrsCod," // row[0] + "DegCod," // row[1] + "Year," // row[2] + "InsCrsCod," // row[3] + "Status," // row[4] + "RequesterUsrCod," // row[5] + "ShortName," // row[6] + "FullName" // row[7] + " FROM crs_courses" + " WHERE DegCod=%ld" + " AND (Status & %u)=0" + " ORDER BY Year," + "ShortName", + Gbl.Hierarchy.Deg.DegCod, + (unsigned) Crs_STATUS_BIT_REMOVED); // All courses except those removed + } + +/*****************************************************************************/ +/********************* Get data of a course from its code ********************/ +/*****************************************************************************/ + +unsigned Crs_DB_GetDataOfCourseByCod (MYSQL_RES **mysql_res,long CrsCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get data of a course", + "SELECT CrsCod," // row[0] + "DegCod," // row[1] + "Year," // row[2] + "InsCrsCod," // row[3] + "Status," // row[4] + "RequesterUsrCod," // row[5] + "ShortName," // row[6] + "FullName" // row[7] + " FROM crs_courses" + " WHERE CrsCod=%ld", + CrsCod); + } + +/*****************************************************************************/ +/******* Get the short names of degree and course from a course code *********/ +/*****************************************************************************/ + +void Crs_DB_GetShortNamesByCod (long CrsCod, + char CrsShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1], + char DegShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + + DegShortName[0] = CrsShortName[0] = '\0'; + + /***** Trivial check: course code should be > 0 *****/ + if (CrsCod <= 0) + return; + + /***** Get the short name of a degree from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get the short name of a course", + "SELECT crs_courses.ShortName," // row[0] + "deg_degrees.ShortName" // row[1] + " FROM crs_courses," + "deg_degrees" + " WHERE crs_courses.CrsCod=%ld" + " AND crs_courses.DegCod=deg_degrees.DegCod", + CrsCod) == 1) + { + /***** Get the course short name and degree short name *****/ + row = mysql_fetch_row (mysql_res); + Str_Copy (CrsShortName,row[0],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME); + Str_Copy (DegShortName,row[1],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/********** Check if the name of course exists in existing courses ***********/ +/*****************************************************************************/ + +bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod, + long DegCod,unsigned Year) + { + /***** Get number of courses in a year of a degree and with a name from database *****/ + return (DB_QueryCOUNT ("can not check if the name" + " of a course already existed", + "SELECT COUNT(*)" + " FROM crs_courses" + " WHERE DegCod=%ld" + " AND Year=%u" + " AND %s='%s'" + " AND CrsCod<>%ld", + DegCod, + Year, + FieldName, + Name, + CrsCod) != 0); + } + +/*****************************************************************************/ +/************************** Write courses of a user **************************/ +/*****************************************************************************/ + +unsigned Crs_DB_GetCrssOfAUsr (MYSQL_RES **mysql_res,long UsrCod,Rol_Role_t Role) + { + char *SubQuery; + unsigned NumCrss; + + /***** Get courses of a user from database *****/ + if (Role == Rol_UNK) // Role == Rol_UNK ==> any role + { + if (asprintf (&SubQuery,"%s","") < 0) + Err_NotEnoughMemoryExit (); + } + else + { + if (asprintf (&SubQuery," AND crs_users.Role=%u",(unsigned) Role) < 0) + Err_NotEnoughMemoryExit (); + } + NumCrss = (unsigned) + DB_QuerySELECT (mysql_res,"can not get courses of a user", + "SELECT deg_degrees.DegCod," // row[0] + "crs_courses.CrsCod," // row[1] + "deg_degrees.ShortName," // row[2] + "deg_degrees.FullName," // row[3] + "crs_courses.Year," // row[4] + "crs_courses.FullName," // row[5] + "ctr_centers.ShortName," // row[6] + "crs_users.Accepted" // row[7] + " FROM crs_users," + "crs_courses," + "deg_degrees," + "ctr_centers" + " WHERE crs_users.UsrCod=%ld%s" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " ORDER BY deg_degrees.FullName," + "crs_courses.Year," + "crs_courses.FullName", + UsrCod,SubQuery); + + /***** Free allocated memory for subquery *****/ + free (SubQuery); + + return NumCrss; + } + +/*****************************************************************************/ +/************************** Get old courses from database ********************/ +/*****************************************************************************/ + +unsigned Crs_DB_GetOldCrss (MYSQL_RES **mysql_res,unsigned long SecondsWithoutAccess) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get old courses", + "SELECT CrsCod" + " FROM crs_last" + " WHERE LastTime. +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_constant.h" +#include "swad_course.h" +#include "swad_role.h" + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Public types ********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +void Crs_DB_CreateCourse (struct Crs_Course *Crs,unsigned Status); + +unsigned Crs_DB_GetCrssInCurrentDegBasic (MYSQL_RES **mysql_res); +unsigned Crs_DB_GetCrssInCurrentDegFull (MYSQL_RES **mysql_res); +unsigned Crs_DB_GetDataOfCourseByCod (MYSQL_RES **mysql_res,long CrsCod); +void Crs_DB_GetShortNamesByCod (long CrsCod, + char CrsShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1], + char DegShortName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]); +bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod, + long DegCod,unsigned Year); +unsigned Crs_DB_GetCrssOfAUsr (MYSQL_RES **mysql_res,long UsrCod,Rol_Role_t Role); +unsigned Crs_DB_GetOldCrss (MYSQL_RES **mysql_res,unsigned long SecondsWithoutAccess); + +unsigned Crs_DB_GetNumCrssInCty (long CtyCod); +unsigned Crs_DB_GetNumCrssInIns (long InsCod); +unsigned Crs_DB_GetNumCrssInCtr (long CtrCod); +unsigned Crs_DB_GetNumCrssInDeg (long DegCod); +unsigned Crs_DB_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery); + +void Crs_DB_UpdateInstitutionalCrsCod (long CrsCod,const char *NewInstitutionalCrsCod); +void Crs_DB_UpdateCrsStatus (long CrsCod,Crs_Status_t Status); +void Crs_DB_UpdateCrsYear (long CrsCod,unsigned NewYear); +void Crs_DB_UpdateCrsName (long CrsCod,const char *FieldName,const char *NewCrsName); +void Crs_DB_UpdateCrsDeg (long CrsCod,long DegCod); + +void Crs_DB_UpdateCrsLastClick (void); + +void Crs_DB_RemoveCrsInfo (long CrsCod); +void Crs_DB_RemoveCrsTimetable (long CrsCod); +void Crs_DB_RemoveCrsLast (long CrsCod); +void Crs_DB_RemoveCrs (long CrsCod); + +#endif diff --git a/swad_degree.c b/swad_degree.c index 08a5ed97..a716d1ef 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1529,7 +1529,7 @@ void Deg_RemoveDegreeCompletely (long DegCod) Svy_RemoveSurveys (Hie_Lvl_DEG,DegCod); /***** Remove information related to files in degree *****/ - Brw_RemoveDegFilesFromDB (DegCod); + Brw_DB_RemoveDegFiles (DegCod); /***** Remove directories of the degree *****/ snprintf (PathDeg,sizeof (PathDeg),"%s/%02u/%u", diff --git a/swad_enrolment.c b/swad_enrolment.c index 657350d8..11593ab9 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -4309,7 +4309,19 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, } /*****************************************************************************/ -/************************ Remove a user from a course ************************/ +/*********** Remove all users' requests for inscription in a course **********/ +/*****************************************************************************/ + +void Enr_DB_RemCrsRequests (long CrsCod) + { + DB_QueryDELETE ("can not remove requests for inscription to a course", + "DELETE FROM crs_requests" + " WHERE CrsCod=%ld", + CrsCod); + } + +/*****************************************************************************/ +/************ Remove user's requests for inscription from a course ***********/ /*****************************************************************************/ void Enr_DB_RemUsrRequests (long UsrCod) @@ -4320,6 +4332,30 @@ void Enr_DB_RemUsrRequests (long UsrCod) UsrCod); } +/*****************************************************************************/ +/*************** Remove all users from settings in a course ******************/ +/*****************************************************************************/ + +void Enr_DB_RemAllUsrsFromCrsSettings (long CrsCod) + { + DB_QueryDELETE ("can not remove users from a course settings", + "DELETE FROM crs_user_settings" + " WHERE CrsCod=%ld", + CrsCod); + } + +/*****************************************************************************/ +/*************** Remove all users from settings in a course ******************/ +/*****************************************************************************/ + +void Enr_DB_RemAllUsrsFromCrs (long CrsCod) + { + DB_QueryDELETE ("can not remove users from a course", + "DELETE FROM crs_users" + " WHERE CrsCod=%ld", + CrsCod); + } + /*****************************************************************************/ /************************ Remove a user from a course ************************/ /*****************************************************************************/ diff --git a/swad_enrolment.h b/swad_enrolment.h index 3860907e..efa8e478 100644 --- a/swad_enrolment.h +++ b/swad_enrolment.h @@ -145,7 +145,10 @@ void Enr_ModifyUsr2 (void); void Enr_AcceptUsrInCrs (long UsrCod); +void Enr_DB_RemCrsRequests (long CrsCod); void Enr_DB_RemUsrRequests (long UsrCod); +void Enr_DB_RemAllUsrsFromCrsSettings (long CrsCod); +void Enr_DB_RemAllUsrsFromCrs (long CrsCod); void Enr_DB_RemUsrFromAllCrss (long UsrCod); void Enr_DB_RemUsrAsAdmin (long UsrCod); diff --git a/swad_file_browser.c b/swad_file_browser.c index 345e6e02..8beb8337 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -4173,7 +4173,7 @@ static void Brw_StoreSizeOfFileTreeInDB (void) /******** Remove files related to an institution from the database ***********/ /*****************************************************************************/ -void Brw_RemoveInsFilesFromDB (long InsCod) +void Brw_DB_RemoveInsFiles (long InsCod) { /***** Remove from database the entries that store the file views *****/ DB_QueryDELETE ("can not remove file views to files of an institution", @@ -4241,7 +4241,7 @@ void Brw_RemoveInsFilesFromDB (long InsCod) /************ Remove files related to a center from the database *************/ /*****************************************************************************/ -void Brw_RemoveCtrFilesFromDB (long CtrCod) +void Brw_DB_RemoveCtrFiles (long CtrCod) { /***** Remove from database the entries that store the file views *****/ DB_QueryDELETE ("can not remove file views to files of a center", @@ -4305,7 +4305,7 @@ void Brw_RemoveCtrFilesFromDB (long CtrCod) /************ Remove files related to a degree from the database *************/ /*****************************************************************************/ -void Brw_RemoveDegFilesFromDB (long DegCod) +void Brw_DB_RemoveDegFiles (long DegCod) { /***** Remove from database the entries that store the file views *****/ DB_QueryDELETE ("can not remove file views to files of a degree", @@ -4373,7 +4373,7 @@ void Brw_RemoveDegFilesFromDB (long DegCod) so this function must be called before removing groups and projects */ -void Brw_RemoveCrsFilesFromDB (long CrsCod) +void Brw_DB_RemoveCrsFiles (long CrsCod) { char SubqueryGrp[256]; char SubqueryPrj[128]; diff --git a/swad_file_browser.h b/swad_file_browser.h index 1604c6f6..e8d76ee5 100644 --- a/swad_file_browser.h +++ b/swad_file_browser.h @@ -185,10 +185,10 @@ void Brw_GetSelectedUsrsAndShowWorks (void); void Brw_ShowFileBrowserOrWorks (void); void Brw_ShowAgainFileBrowserOrWorks (void); -void Brw_RemoveInsFilesFromDB (long InsCod); -void Brw_RemoveCtrFilesFromDB (long CtrCod); -void Brw_RemoveDegFilesFromDB (long DegCod); -void Brw_RemoveCrsFilesFromDB (long CrsCod); +void Brw_DB_RemoveInsFiles (long InsCod); +void Brw_DB_RemoveCtrFiles (long CtrCod); +void Brw_DB_RemoveDegFiles (long DegCod); +void Brw_DB_RemoveCrsFiles (long CrsCod); void Brw_RemoveGrpFilesFromDB (long GrpCod); void Brw_RemovePrjFilesFromDB (long PrjCod); void Brw_RemoveSomeInfoAboutCrsUsrFilesFromDB (long UsrCod,long CrsCod); diff --git a/swad_group.c b/swad_group.c index 06f1321a..add74995 100644 --- a/swad_group.c +++ b/swad_group.c @@ -5147,3 +5147,36 @@ Grp_WhichGroups_t Grp_GetParamWhichGroups (void) return Gbl.Crs.Grps.WhichGrps; } + +/*****************************************************************************/ +/************************** Remove groups in a course ************************/ +/*****************************************************************************/ + +void Grp_DB_RemoveCrsGrps (long CrsCod) + { + /***** Remove all the users in groups in the course *****/ + DB_QueryDELETE ("can not remove users from groups of a course", + "DELETE FROM grp_users" + " USING grp_types," + "grp_groups," + "grp_users" + " WHERE grp_types.CrsCod=%ld" + " AND grp_types.GrpTypCod=grp_groups.GrpTypCod" + " AND grp_groups.GrpCod=grp_users.GrpCod", + CrsCod); + + /***** Remove all the groups in the course *****/ + DB_QueryDELETE ("can not remove groups of a course", + "DELETE FROM grp_groups" + " USING grp_types," + "grp_groups" + " WHERE grp_types.CrsCod=%ld" + " AND grp_types.GrpTypCod=grp_groups.GrpTypCod", + CrsCod); + + /***** Remove all the group types in the course *****/ + DB_QueryDELETE ("can not remove types of group of a course", + "DELETE FROM grp_types" + " WHERE CrsCod=%ld", + CrsCod); + } diff --git a/swad_group.h b/swad_group.h index 38b6707e..718bec5d 100644 --- a/swad_group.h +++ b/swad_group.h @@ -242,4 +242,6 @@ void Grp_ShowFormToSelWhichGrps (Act_Action_t Action, void (*FuncParams) (void *Args),void *Args); Grp_WhichGroups_t Grp_GetParamWhichGroups (void); +void Grp_DB_RemoveCrsGrps (long CrsCod); + #endif diff --git a/swad_institution.c b/swad_institution.c index cc5bc006..d8524b77 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1372,7 +1372,7 @@ void Ins_RemoveInstitution (void) Svy_RemoveSurveys (Hie_Lvl_INS,Ins_EditingIns->InsCod); /***** Remove information related to files in institution *****/ - Brw_RemoveInsFilesFromDB (Ins_EditingIns->InsCod); + Brw_DB_RemoveInsFiles (Ins_EditingIns->InsCod); /***** Remove directories of the institution *****/ snprintf (PathIns,sizeof (PathIns),"%s/%02u/%u", diff --git a/swad_notice.c b/swad_notice.c index b9429f94..01df8c44 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -1087,3 +1087,30 @@ static long Not_GetParamNotCod (void) /***** Get notice code *****/ return Par_GetParToLong ("NotCod"); } + +/*****************************************************************************/ +/************************* Remove notices in a course ************************/ +/*****************************************************************************/ + +void Not_DB_RemoveCrsNotices (long CrsCod) + { + /***** Copy all notices from the course to table of deleted notices *****/ + DB_QueryINSERT ("can not remove notices in a course", + "INSERT INTO not_deleted" + " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" + " SELECT NotCod," + "CrsCod," + "UsrCod," + "CreatTime," + "Content," + "NumNotif" + " FROM not_notices" + " WHERE CrsCod=%ld", + CrsCod); + + /***** Remove all notices from the course *****/ + DB_QueryDELETE ("can not remove notices in a course", + "DELETE FROM not_notices" + " WHERE CrsCod=%ld", + CrsCod); + } diff --git a/swad_notice.h b/swad_notice.h index bcb279e1..3c041a4f 100644 --- a/swad_notice.h +++ b/swad_notice.h @@ -77,4 +77,6 @@ unsigned Not_GetNumNoticesDeleted (Hie_Lvl_Level_t Scope,unsigned *NumNotif); void Not_PutHiddenParamNotCod (long NotCod); +void Not_DB_RemoveCrsNotices (long CrsCod); + #endif diff --git a/swad_record.c b/swad_record.c index 0ffc9198..cd4fc60e 100644 --- a/swad_record.c +++ b/swad_record.c @@ -4236,3 +4236,30 @@ void Rec_UpdateMyOfficePhone (void) /***** Show form again *****/ Rec_ShowMySharedRecordAndMore (); } + +/*****************************************************************************/ +/******************** Remove content of course record cards ******************/ +/*****************************************************************************/ + +void Rec_DB_RemoveCrsRecordContents (long CrsCod) + { + DB_QueryDELETE ("can not remove content of cards in a course", + "DELETE FROM crs_records" + " USING crs_record_fields," + "crs_records" + " WHERE crs_record_fields.CrsCod=%ld" + " AND crs_record_fields.FieldCod=crs_records.FieldCod", + CrsCod); + } + +/*****************************************************************************/ +/************ Remove definition of fields in course record cards *************/ +/*****************************************************************************/ + +void Rec_DB_RemoveCrsRecordFields (long CrsCod) + { + DB_QueryDELETE ("can not remove fields of cards in a course", + "DELETE FROM crs_record_fields" + " WHERE CrsCod=%ld", + CrsCod); + } diff --git a/swad_record.h b/swad_record.h index 49d0d6f7..cf6cc2cf 100644 --- a/swad_record.h +++ b/swad_record.h @@ -180,4 +180,7 @@ void Rec_UpdateMyDepartment (void); void Rec_UpdateMyOffice (void); void Rec_UpdateMyOfficePhone (void); +void Rec_DB_RemoveCrsRecordContents (long CrsCod); +void Rec_DB_RemoveCrsRecordFields (long CrsCod); + #endif