diff --git a/swad_centre.c b/swad_centre.c index 6d06cbd8..a26ab77d 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -1674,13 +1674,13 @@ static void Ctr_PutParamOtherCtrCod (long CtrCod) /****************** Get parameter with code of other centre ******************/ /*****************************************************************************/ -long Ctr_GetAndCheckParamOtherCtrCod (void) +long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed) { long CtrCod; /***** Get and check parameter with code of centre *****/ - if ((CtrCod = Par_GetParToLong ("OthCtrCod")) <= 0) - Lay_ShowErrorAndExit ("Code of centre is missing."); + if ((CtrCod = Par_GetParToLong ("OthCtrCod")) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of centre is missing or invalid."); return CtrCod; } @@ -1698,7 +1698,7 @@ void Ctr_RemoveCentre (void) char PathCtr[PATH_MAX + 1]; /***** Get centre code *****/ - Ctr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + Ctr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); /***** Get data of the centre from database *****/ Ctr_GetDataOfCentreByCod (&Ctr); @@ -1728,12 +1728,12 @@ void Ctr_RemoveCentre (void) /***** Remove centre *****/ sprintf (Query,"DELETE FROM centres WHERE CtrCod=%ld", - Ctr.CtrCod); + Ctr.CtrCod); DB_QueryDELETE (Query,"can not remove a centre"); /***** Write message to show the change made *****/ sprintf (Gbl.Alert.Txt,Txt_Centre_X_removed, - Ctr.FullName); + Ctr.FullName); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); } @@ -1752,7 +1752,7 @@ void Ctr_ChangeCtrInsInConfig (void) struct Instit NewIns; /***** Get parameter with institution code *****/ - NewIns.InsCod = Ins_GetAndCheckParamOtherInsCod (); + NewIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Check if institution has changed *****/ if (NewIns.InsCod != Gbl.CurrentCtr.Ctr.InsCod) @@ -1834,11 +1834,10 @@ void Ctr_ChangeCentrePlace (void) long NewPlcCod; char Query[512]; - /***** Get parameters from form *****/ - /* Get centre code */ - Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + /***** Get centre code *****/ + Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); - /* Get parameter with centre code */ + /***** Get parameter with place code *****/ NewPlcCod = Plc_GetParamPlcCod (); /***** Get data of centre from database *****/ @@ -1846,12 +1845,12 @@ void Ctr_ChangeCentrePlace (void) /***** Update place in table of centres *****/ sprintf (Query,"UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", - NewPlcCod,Gbl.Ctrs.EditingCtr.CtrCod); + NewPlcCod,Gbl.Ctrs.EditingCtr.CtrCod); DB_QueryUPDATE (Query,"can not update the place of a centre"); Gbl.Ctrs.EditingCtr.PlcCod = NewPlcCod; /***** Write message to show the change made - and put button to go to centre changed *****/ + and put button to go to centre changed *****/ Gbl.Alert.Type = Ale_SUCCESS; sprintf (Gbl.Alert.Txt,"%s",Txt_The_place_of_the_centre_has_changed); Ctr_ShowAlertAndButtonToGoToCtr (); @@ -1866,7 +1865,7 @@ void Ctr_ChangeCentrePlace (void) void Ctr_RenameCentreShort (void) { - Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); Ctr_RenameCentre (&Gbl.Ctrs.EditingCtr,Cns_SHRT_NAME); } @@ -1881,7 +1880,7 @@ void Ctr_RenameCentreShortInConfig (void) void Ctr_RenameCentreFull (void) { - Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); Ctr_RenameCentre (&Gbl.Ctrs.EditingCtr,Cns_FULL_NAME); } @@ -2010,11 +2009,10 @@ void Ctr_ChangeCtrWWW (void) extern const char *Txt_You_can_not_leave_the_web_address_empty; char NewWWW[Cns_MAX_BYTES_WWW + 1]; - /***** Get parameters from form *****/ - /* Get the code of the centre */ - Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + /***** Get the code of the centre *****/ + Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); - /* Get the new WWW for the centre */ + /***** Get the new WWW for the centre *****/ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get data of centre *****/ @@ -2026,7 +2024,7 @@ void Ctr_ChangeCtrWWW (void) /***** Update database changing old WWW by new WWW *****/ Ctr_UpdateCtrWWWDB (Gbl.Ctrs.EditingCtr.CtrCod,NewWWW); Str_Copy (Gbl.Ctrs.EditingCtr.WWW,NewWWW, - Cns_MAX_BYTES_WWW); + Cns_MAX_BYTES_WWW); /***** Write message to show the change made and put button to go to centre changed *****/ @@ -2096,16 +2094,15 @@ void Ctr_ChangeCtrStatus (void) Ctr_Status_t Status; Ctr_StatusTxt_t StatusTxt; - /***** Get parameters from form *****/ - /* Get centre code */ - Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + /***** Get centre code *****/ + Gbl.Ctrs.EditingCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); - /* Get parameter with status */ + /***** Get parameter with status *****/ Status = (Ctr_Status_t) Par_GetParToUnsignedLong ("Status", - 0, - (unsigned long) Ctr_MAX_STATUS, - (unsigned long) Ctr_WRONG_STATUS); + 0, + (unsigned long) Ctr_MAX_STATUS, + (unsigned long) Ctr_WRONG_STATUS); if (Status == Ctr_WRONG_STATUS) Lay_ShowErrorAndExit ("Wrong status."); StatusTxt = Ctr_GetStatusTxtFromStatusBits (Status); @@ -2116,7 +2113,7 @@ void Ctr_ChangeCtrStatus (void) /***** Update status in table of centres *****/ sprintf (Query,"UPDATE centres SET Status=%u WHERE CtrCod=%ld", - (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod); + (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod); DB_QueryUPDATE (Query,"can not update the status of a centre"); Gbl.Ctrs.EditingCtr.Status = Status; @@ -2124,7 +2121,7 @@ void Ctr_ChangeCtrStatus (void) and put button to go to centre changed *****/ Gbl.Alert.Type = Ale_SUCCESS; sprintf (Gbl.Alert.Txt,Txt_The_status_of_the_centre_X_has_changed, - Gbl.Ctrs.EditingCtr.ShrtName); + Gbl.Ctrs.EditingCtr.ShrtName); Ctr_ShowAlertAndButtonToGoToCtr (); /***** Show the form again *****/ diff --git a/swad_centre.h b/swad_centre.h index 57a7fed7..28e4751c 100644 --- a/swad_centre.h +++ b/swad_centre.h @@ -102,7 +102,7 @@ void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr); void Ctr_FreeListCentres (void); void Ctr_WriteSelectorOfCentre (void); void Ctr_PutParamCtrCod (long CtrCod); -long Ctr_GetAndCheckParamOtherCtrCod (void); +long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed); void Ctr_RemoveCentre (void); void Ctr_ChangeCtrInsInConfig (void); void Ctr_ContEditAfterChgCtrInConfig (void); diff --git a/swad_changelog.h b/swad_changelog.h index 2d25534c..7ac0b815 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -227,17 +227,20 @@ // TODO: Fix bug: An URL like https://openswad.org/es?a gives Internal Server Error +// TODO: Limit lenght of very big institution name in record card + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.231.4 (2017-05-31)" +#define Log_PLATFORM_VERSION "SWAD 16.232 (2017-05-31)" #define CSS_FILE "swad16.226.css" #define JS_FILE "swad16.206.3.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.232: May 31, 2017 Fix bug in selection of user's centre. (221042 lines) Version 16.231.4: May 31, 2017 Changes in layout of statistics about institutions. Fixed bug in search. (221039 lines) Version 16.231.3: May 31, 2017 Changes in layout of statistics about institutions. (221037 lines) diff --git a/swad_country.c b/swad_country.c index 47805c1c..89b8404c 100644 --- a/swad_country.c +++ b/swad_country.c @@ -1647,13 +1647,13 @@ static void Cty_PutParamOtherCtyCod (long CtyCod) /******************* Get parameter with code of country **********************/ /*****************************************************************************/ -long Cty_GetAndCheckParamOtherCtyCod (void) +long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed) { long CtyCod; /***** Get and check parameter with code of country *****/ - if ((CtyCod = Cty_GetParamOtherCtyCod ()) < 0) - Lay_ShowErrorAndExit ("Code of country is missing."); + if ((CtyCod = Cty_GetParamOtherCtyCod ()) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of country is missing or invalid."); return CtyCod; } @@ -1676,7 +1676,7 @@ void Cty_RemoveCountry (void) struct Country Cty; /***** Get country code *****/ - Cty.CtyCod = Cty_GetAndCheckParamOtherCtyCod (); + Cty.CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Get data of the country from database *****/ Cty_GetDataOfCountryByCod (&Cty,Cty_GET_EXTRA_DATA); @@ -1693,12 +1693,12 @@ void Cty_RemoveCountry (void) /***** Remove country *****/ sprintf (Query,"DELETE FROM countries WHERE CtyCod='%03ld'", - Cty.CtyCod); + Cty.CtyCod); DB_QueryDELETE (Query,"can not remove a country"); /***** Write message to show the change made *****/ sprintf (Gbl.Alert.Txt,Txt_Country_X_removed, - Cty.Name[Gbl.Prefs.Language]); + Cty.Name[Gbl.Prefs.Language]); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); } @@ -1724,14 +1724,13 @@ void Cty_RenameCountry (void) Cty = &Gbl.Ctys.EditingCty; - /***** Get parameters from form *****/ - /* Get the code of the country */ - Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (); + /***** Get the code of the country *****/ + Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); - /* Get the lenguage */ + /***** Get the lenguage *****/ Language = Lan_GetParamLanguage (); - /* Get the new name for the country */ + /***** Get the new name for the country *****/ Par_GetParToText ("Name",NewCtyName,Cty_MAX_BYTES_NAME); /***** Get from the database the data of the country *****/ @@ -1741,44 +1740,46 @@ void Cty_RenameCountry (void) if (!NewCtyName[0]) { sprintf (Gbl.Alert.Txt,Txt_You_can_not_leave_the_name_of_the_country_X_empty, - Cty->Name[Language]); + Cty->Name[Language]); Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt); } else { /***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/ if (strcmp (Cty->Name[Language],NewCtyName)) // Different names - { - /***** If country was in database... *****/ - if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty->CtyCod)) - { - sprintf (Gbl.Alert.Txt,Txt_The_country_X_already_exists, - NewCtyName); - Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt); - } - else - { - /* Update the table changing old name by new name */ - sprintf (FieldName,"Name_%s",Txt_STR_LANG_ID[Language]); - Cty_UpdateCtyNameDB (Cty->CtyCod,FieldName,NewCtyName); + { + /***** If country was in database... *****/ + if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty->CtyCod)) + { + sprintf (Gbl.Alert.Txt,Txt_The_country_X_already_exists, + NewCtyName); + Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt); + } + else + { + /* Update the table changing old name by new name */ + sprintf (FieldName,"Name_%s",Txt_STR_LANG_ID[Language]); + Cty_UpdateCtyNameDB (Cty->CtyCod,FieldName,NewCtyName); - /* Write message to show the change made */ - sprintf (Gbl.Alert.Txt,Txt_The_country_X_has_been_renamed_as_Y, - Cty->Name[Language],NewCtyName); - Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); - } - } + /* Write message to show the change made */ + sprintf (Gbl.Alert.Txt,Txt_The_country_X_has_been_renamed_as_Y, + Cty->Name[Language],NewCtyName); + Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); + + /* Update country name */ + Str_Copy (Cty->Name[Language],NewCtyName, + Cty_MAX_BYTES_NAME); + } + } else // The same name - { - sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_country_X_has_not_changed, - Cty->Name[Language]); - Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt); - } + { + sprintf (Gbl.Alert.Txt,Txt_The_name_of_the_country_X_has_not_changed, + Cty->Name[Language]); + Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt); + } } /***** Show the form again *****/ - Str_Copy (Cty->Name[Language],NewCtyName, - Cty_MAX_BYTES_NAME); Cty_EditCountries (); } @@ -1855,14 +1856,13 @@ void Cty_ChangeCtyWWW (void) Cty = &Gbl.Ctys.EditingCty; - /***** Get parameters from form *****/ - /* Get the code of the country */ - Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (); + /***** Get the code of the country *****/ + Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); - /* Get the lenguage */ + /***** Get the lenguage *****/ Language = Lan_GetParamLanguage (); - /* Get the new WWW for the country */ + /***** Get the new WWW for the country *****/ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get from the database the data of the country *****/ @@ -1873,14 +1873,14 @@ void Cty_ChangeCtyWWW (void) " WHERE CtyCod='%03ld'", Txt_STR_LANG_ID[Language],NewWWW,Cty->CtyCod); DB_QueryUPDATE (Query,"can not update the web of a country"); + Str_Copy (Cty->WWW[Language],NewWWW, + Cns_MAX_BYTES_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Alert.Txt,Txt_The_new_web_address_is_X,NewWWW); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); /***** Show the form again *****/ - Str_Copy (Cty->WWW[Language],NewWWW, - Cns_MAX_BYTES_WWW); Cty_EditCountries (); } diff --git a/swad_country.h b/swad_country.h index c88b303a..01c89c6b 100644 --- a/swad_country.h +++ b/swad_country.h @@ -101,7 +101,7 @@ void Cty_WriteCountryName (long CtyCod,const char *ClassLink); bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraData); void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1]); void Cty_PutParamCtyCod (long CtyCod); -long Cty_GetAndCheckParamOtherCtyCod (void); +long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed); void Cty_RemoveCountry (void); void Cty_RenameCountry (void); void Cty_ChangeCtyWWW (void); diff --git a/swad_course.c b/swad_course.c index 5d753d9d..fd2d36c3 100644 --- a/swad_course.c +++ b/swad_course.c @@ -122,7 +122,7 @@ static void Crs_PutLinkToSearchCourses (void); static void Sch_PutLinkToSearchCoursesParams (void); static void Crs_PutParamOtherCrsCod (long CrsCod); -static long Crs_GetAndCheckParamOtherCrsCod (void); +static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed); static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnAccepted); @@ -1948,7 +1948,7 @@ void Crs_RemoveCourse (void) struct Course Crs; /***** Get course code *****/ - Crs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Crs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); /***** Get data of the course from database *****/ Crs_GetDataOfCourseByCod (&Crs); @@ -2113,16 +2113,19 @@ void Crs_RemoveCourseCompletely (long CrsCod) { char Query[128]; - /***** Empty course *****/ - Crs_EmptyCourseCompletely (CrsCod); + if (CrsCod > 0) + { + /***** Empty course *****/ + Crs_EmptyCourseCompletely (CrsCod); - /***** Remove course from table of last accesses to courses in database *****/ - sprintf (Query,"DELETE FROM crs_last WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove a course"); + /***** Remove course from table of last accesses to courses in database *****/ + sprintf (Query,"DELETE FROM crs_last WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove a course"); - /***** Remove course from table of courses in database *****/ - sprintf (Query,"DELETE FROM courses WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove a course"); + /***** Remove course from table of courses in database *****/ + sprintf (Query,"DELETE FROM courses WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove a course"); + } } /*****************************************************************************/ @@ -2137,122 +2140,125 @@ static void Crs_EmptyCourseCompletely (long CrsCod) char PathRelCrs[PATH_MAX + 1]; char Query[512]; - /***** Get course data *****/ - Crs.CrsCod = CrsCod; - Crs_GetDataOfCourseByCod (&Crs); + if (CrsCod > 0) + { + /***** Get course data *****/ + Crs.CrsCod = CrsCod; + Crs_GetDataOfCourseByCod (&Crs); - /***** Remove all the students in the course *****/ - Enr_RemAllStdsInCrs (&Crs); + /***** Remove all the students in the course *****/ + Enr_RemAllStdsInCrs (&Crs); - /***** Set all the notifications from the course as removed, - except notifications about new messages *****/ - Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod); + /***** Set all the notifications from the course as removed, + except notifications about new messages *****/ + Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod); - /***** Remove information of the course ****/ - /* Remove timetable of the course */ - sprintf (Query,"DELETE FROM timetable_crs WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove the timetable of a course"); + /***** Remove information of the course ****/ + /* Remove timetable of the course */ + sprintf (Query,"DELETE FROM timetable_crs WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove the timetable of a course"); - /* Remove other information of the course */ - sprintf (Query,"DELETE FROM crs_info_src WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove info sources of a course"); + /* Remove other information of the course */ + sprintf (Query,"DELETE FROM crs_info_src WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove info sources of a course"); - sprintf (Query,"DELETE FROM crs_info_txt WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove info of a course"); + sprintf (Query,"DELETE FROM crs_info_txt WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove info of a course"); - /***** Remove exam announcements in the course *****/ - /* Mark all exam announcements in the course as deleted */ - sprintf (Query,"UPDATE exam_announcements SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod); - DB_QueryUPDATE (Query,"can not remove exam announcements of a course"); + /***** Remove exam announcements in the course *****/ + /* Mark all exam announcements in the course as deleted */ + sprintf (Query,"UPDATE exam_announcements SET Status=%u" + " WHERE CrsCod=%ld", + (unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod); + DB_QueryUPDATE (Query,"can not remove exam announcements of a course"); - /***** Remove course cards of the course *****/ - /* Remove content of course cards */ - sprintf (Query,"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); - DB_QueryDELETE (Query,"can not remove content of cards in a course"); + /***** Remove course cards of the course *****/ + /* Remove content of course cards */ + sprintf (Query,"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); + DB_QueryDELETE (Query,"can not remove content of cards in a course"); - /* Remove definition of fields in course cards */ - sprintf (Query,"DELETE FROM crs_record_fields WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove fields of cards in a course"); + /* Remove definition of fields in course cards */ + sprintf (Query,"DELETE FROM crs_record_fields WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove fields of cards in a course"); - /***** Remove assignments of the course *****/ - Asg_RemoveCrsAssignments (CrsCod); + /***** Remove assignments of the course *****/ + Asg_RemoveCrsAssignments (CrsCod); - /***** Remove attendance events of the course *****/ - Att_RemoveCrsAttEvents (CrsCod); + /***** Remove attendance events of the course *****/ + Att_RemoveCrsAttEvents (CrsCod); - /***** Remove notices in the course *****/ - /* Copy all notices from the course to table of deleted notices */ - sprintf (Query,"INSERT INTO notices_deleted" - " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" - " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif FROM notices" - " WHERE CrsCod=%ld", - CrsCod); - DB_QueryINSERT (Query,"can not remove notices in a course"); - /* Remove all notices from the course */ - sprintf (Query,"DELETE FROM notices WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove notices in a course"); + /***** Remove notices in the course *****/ + /* Copy all notices from the course to table of deleted notices */ + sprintf (Query,"INSERT INTO notices_deleted" + " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" + " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif FROM notices" + " WHERE CrsCod=%ld", + CrsCod); + DB_QueryINSERT (Query,"can not remove notices in a course"); + /* Remove all notices from the course */ + sprintf (Query,"DELETE FROM notices WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE (Query,"can not remove notices in a course"); - /***** Remove all the threads and posts in forums of the course *****/ - For_RemoveForums (Sco_SCOPE_CRS,CrsCod); + /***** Remove all the threads and posts in forums of the course *****/ + For_RemoveForums (Sco_SCOPE_CRS,CrsCod); - /***** Remove surveys of the course *****/ - Svy_RemoveSurveys (Sco_SCOPE_CRS,CrsCod); + /***** Remove surveys of the course *****/ + Svy_RemoveSurveys (Sco_SCOPE_CRS,CrsCod); - /***** Remove all test exams made in the course *****/ - Tst_RemoveCrsTestResults (CrsCod); + /***** Remove all test exams made in the course *****/ + Tst_RemoveCrsTestResults (CrsCod); - /***** Remove all tests questions in the course *****/ - Tst_RemoveCrsTests (CrsCod); + /***** Remove all tests questions in the course *****/ + Tst_RemoveCrsTests (CrsCod); - /***** Remove groups in the course *****/ - /* Remove all the users in groups in the course */ - sprintf (Query,"DELETE FROM crs_grp_usr" - " USING crs_grp_types,crs_grp,crs_grp_usr" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.GrpCod=crs_grp_usr.GrpCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove users from groups of a course"); + /***** Remove groups in the course *****/ + /* Remove all the users in groups in the course */ + sprintf (Query,"DELETE FROM crs_grp_usr" + " USING crs_grp_types,crs_grp,crs_grp_usr" + " WHERE crs_grp_types.CrsCod=%ld" + " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" + " AND crs_grp.GrpCod=crs_grp_usr.GrpCod", + CrsCod); + DB_QueryDELETE (Query,"can not remove users from groups of a course"); - /* Remove all the groups in the course */ - sprintf (Query,"DELETE FROM crs_grp" - " USING crs_grp_types,crs_grp" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove groups of a course"); + /* Remove all the groups in the course */ + sprintf (Query,"DELETE FROM crs_grp" + " USING crs_grp_types,crs_grp" + " WHERE crs_grp_types.CrsCod=%ld" + " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod", + CrsCod); + DB_QueryDELETE (Query,"can not remove groups of a course"); - /* Remove all the group types in the course */ - sprintf (Query,"DELETE FROM crs_grp_types" - " WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove types of group of a course"); + /* Remove all the group types in the course */ + sprintf (Query,"DELETE FROM crs_grp_types" + " WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE (Query,"can not remove types of group of a course"); - /***** Remove users' requests for inscription in the course *****/ - sprintf (Query,"DELETE FROM crs_usr_requests WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove requests for inscription to a course"); + /***** Remove users' requests for inscription in the course *****/ + sprintf (Query,"DELETE FROM crs_usr_requests WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE (Query,"can not remove requests for inscription to a course"); - /***** Remove possible users remaining in the course (teachers) *****/ - sprintf (Query,"DELETE FROM crs_usr WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove users from a course"); + /***** Remove possible users remaining in the course (teachers) *****/ + sprintf (Query,"DELETE FROM crs_usr WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE (Query,"can not remove users from a course"); - /***** Remove information related to files in course *****/ - Brw_RemoveCrsFilesFromDB (CrsCod); + /***** Remove information related to files in course *****/ + Brw_RemoveCrsFilesFromDB (CrsCod); - /***** Remove directories of the course *****/ - sprintf (PathRelCrs,"%s/%s/%ld", - Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,CrsCod); - Fil_RemoveTree (PathRelCrs); - sprintf (PathRelCrs,"%s/%s/%ld", - Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,CrsCod); - Fil_RemoveTree (PathRelCrs); + /***** Remove directories of the course *****/ + sprintf (PathRelCrs,"%s/%s/%ld", + Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,CrsCod); + Fil_RemoveTree (PathRelCrs); + sprintf (PathRelCrs,"%s/%s/%ld", + Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,CrsCod); + Fil_RemoveTree (PathRelCrs); + } } /*****************************************************************************/ @@ -2295,7 +2301,7 @@ void Crs_ChangeInsCrsCod (void) /***** Get parameters from form *****/ /* Get course code */ - Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); /* Get institutional code */ Par_GetParToText ("InsCrsCod",NewInstitutionalCrsCod,Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD); @@ -2339,7 +2345,7 @@ void Crs_ChangeCrsDegInConfig (void) struct Degree NewDeg; /***** Get parameter with degree code *****/ - NewDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + NewDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); /***** Check if degree has changed *****/ if (NewDeg.DegCod != Gbl.CurrentCrs.Crs.DegCod) @@ -2477,7 +2483,7 @@ void Crs_ChangeCrsYear (void) /***** Get parameters from form *****/ /* Get course code */ - Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); /* Get parameter with year */ Par_GetParToText ("OthCrsYear",YearStr,2); @@ -2572,7 +2578,7 @@ void Crs_UpdateInstitutionalCrsCod (struct Course *Crs,const char *NewInstitutio void Crs_RenameCourseShort (void) { - Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); Crs_RenameCourse (&Gbl.Degs.EditingCrs,Cns_SHRT_NAME); } @@ -2587,7 +2593,7 @@ void Crs_RenameCourseShortInConfig (void) void Crs_RenameCourseFull (void) { - Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); Crs_RenameCourse (&Gbl.Degs.EditingCrs,Cns_FULL_NAME); } @@ -2732,7 +2738,7 @@ void Crs_ChangeCrsStatus (void) /***** Get parameters from form *****/ /* Get course code */ - Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (); + Gbl.Degs.EditingCrs.CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); /* Get parameter with status */ Status = (Crs_Status_t) @@ -2938,13 +2944,13 @@ static void Crs_PutParamOtherCrsCod (long CrsCod) /********************* Get parameter with code of course *********************/ /*****************************************************************************/ -static long Crs_GetAndCheckParamOtherCrsCod (void) +static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed) { long CrsCod; /***** Get and check parameter with code of course *****/ - if ((CrsCod = Par_GetParToLong ("OthCrsCod")) <= 0) - Lay_ShowErrorAndExit ("Code of course is missing."); + if ((CrsCod = Par_GetParToLong ("OthCrsCod")) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of course is missing or invalid."); return CrsCod; } diff --git a/swad_degree.c b/swad_degree.c index 98548d8f..8398000c 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1543,8 +1543,7 @@ static void Deg_RecFormRequestOrCreateDeg (unsigned Status) Par_GetParToText ("FullName",Gbl.Degs.EditingDeg.FullName,Hie_MAX_BYTES_FULL_NAME); /* Get degree type */ - if ((Gbl.Degs.EditingDeg.DegTypCod = DT_GetParamOtherDegTypCod ()) <= 0) - Ale_ShowAlert (Ale_ERROR,"Wrong type of degree."); + Gbl.Degs.EditingDeg.DegTypCod = DT_GetAndCheckParamOtherDegTypCod (1); /* Get degree WWW */ Par_GetParToText ("WWW",Gbl.Degs.EditingDeg.WWW,Cns_MAX_BYTES_WWW); @@ -1597,7 +1596,7 @@ void Deg_RemoveDegree (void) struct Degree Deg; /***** Get degree code *****/ - Deg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Deg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); /***** Get data of degree *****/ Deg_GetDataOfDegreeByCod (&Deg); @@ -1642,13 +1641,13 @@ static void Deg_PutParamOtherDegCod (long DegCod) /********************* Get parameter with code of degree *********************/ /*****************************************************************************/ -long Deg_GetAndCheckParamOtherDegCod (void) +long Deg_GetAndCheckParamOtherDegCod (long MinCodAllowed) { long DegCod; /***** Get and check parameter with code of degree *****/ - if ((DegCod = Par_GetParToLong ("OthDegCod")) <= 0) - Lay_ShowErrorAndExit ("Code of degree is missing."); + if ((DegCod = Par_GetParToLong ("OthDegCod")) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of degree is missing or invalid."); return DegCod; } @@ -1902,7 +1901,7 @@ void Deg_RemoveDegreeCompletely (long DegCod) void Deg_RenameDegreeShort (void) { - Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); Deg_RenameDegree (&Gbl.Degs.EditingDeg,Cns_SHRT_NAME); } @@ -1917,7 +1916,7 @@ void Deg_RenameDegreeShortInConfig (void) void Deg_RenameDegreeFull (void) { - Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); Deg_RenameDegree (&Gbl.Degs.EditingDeg,Cns_FULL_NAME); } @@ -2047,7 +2046,7 @@ void Deg_ChangeDegCtrInConfig (void) struct Centre NewCtr; /***** Get parameter with centre code *****/ - NewCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + NewCtr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); /***** Check if centre has changed *****/ if (NewCtr.CtrCod != Gbl.CurrentDeg.Deg.CtrCod) @@ -2126,7 +2125,7 @@ void Deg_ChangeDegWWW (void) /***** Get parameters from form *****/ /* Get the code of the degree */ - Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); /* Get the new WWW for the degree */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -2211,7 +2210,7 @@ void Deg_ChangeDegStatus (void) /***** Get parameters from form *****/ /* Get degree code */ - Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); /* Get parameter with status */ Status = (Deg_Status_t) diff --git a/swad_degree.h b/swad_degree.h index 0e02e09a..9b73fea5 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -112,7 +112,7 @@ void Deg_RecFormNewDeg (void); void Deg_RemoveDegree (void); void Deg_PutParamDegCod (long DegCod); -long Deg_GetAndCheckParamOtherDegCod (void); +long Deg_GetAndCheckParamOtherDegCod (long MinCodAllowed); bool Deg_GetDataOfDegreeByCod (struct Degree *Deg); void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg); diff --git a/swad_degree_type.c b/swad_degree_type.c index 5362d4f4..34244cec 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -746,8 +746,7 @@ void DT_RemoveDegreeType (void) struct DegreeType DegTyp; /***** Get the code of the degree type *****/ - if ((DegTyp.DegTypCod = DT_GetParamOtherDegTypCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of type of degree is missing."); + DegTyp.DegTypCod = DT_GetAndCheckParamOtherDegTypCod (1); /***** Get data of the degree type from database *****/ if (!DT_GetDataOfDegreeTypeByCod (&DegTyp)) @@ -784,10 +783,15 @@ static void DT_PutParamOtherDegTypCod (long DegTypCod) /******************* Get parameter with code of degree type ******************/ /*****************************************************************************/ -long DT_GetParamOtherDegTypCod (void) +long DT_GetAndCheckParamOtherDegTypCod (long MinCodAllowed) { - /***** Get code of degree type *****/ - return Par_GetParToLong ("OthDegTypCod"); + long DegTypCod; + + /***** Get and check parameter with code of degree type *****/ + if ((DegTypCod = Par_GetParToLong ("OthDegTypCod")) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of degree type is missing or invalid."); + + return DegTypCod; } /*****************************************************************************/ @@ -919,8 +923,7 @@ void DT_RenameDegreeType (void) /***** Get parameters from form *****/ /* Get the code of the degree type */ - if ((DegTyp->DegTypCod = DT_GetParamOtherDegTypCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of type of degree is missing."); + DegTyp->DegTypCod = DT_GetAndCheckParamOtherDegTypCod (1); /* Get the new name for the degree type */ Par_GetParToText ("DegTypName",NewNameDegTyp,Deg_MAX_BYTES_DEGREE_TYPE_NAME); @@ -1003,10 +1006,10 @@ void DT_ChangeDegreeType (void) /***** Get parameters from form *****/ /* Get degree code */ - Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (); + Gbl.Degs.EditingDeg.DegCod = Deg_GetAndCheckParamOtherDegCod (1); /* Get the new degree type */ - NewDegTypCod = DT_GetParamOtherDegTypCod (); + NewDegTypCod = DT_GetAndCheckParamOtherDegTypCod (1); /***** Get data of degree *****/ Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); diff --git a/swad_degree_type.h b/swad_degree_type.h index 8d8a4597..4bbf8b45 100644 --- a/swad_degree_type.h +++ b/swad_degree_type.h @@ -74,7 +74,7 @@ void DT_RecFormNewDegreeType (void); void DT_RemoveDegreeType (void); -long DT_GetParamOtherDegTypCod (void); +long DT_GetAndCheckParamOtherDegTypCod (long MinCodAllowed); bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp); void DT_RenameDegreeType (void); diff --git a/swad_department.c b/swad_department.c index b79875c6..d464d701 100644 --- a/swad_department.c +++ b/swad_department.c @@ -601,13 +601,18 @@ static void Dpt_PutParamDptCod (long DptCod) } /*****************************************************************************/ -/******************* Get parameter with code of degree type ******************/ +/******************* Get parameter with code of department *******************/ /*****************************************************************************/ -long Dpt_GetParamDptCod (void) +long Dpt_GetAndCheckParamDptCod (long MinCodAllowed) { - /***** Get code of department *****/ - return Par_GetParToLong ("DptCod"); + long DptCod; + + /***** Get and check parameter with code of department *****/ + if ((DptCod = Par_GetParToLong ("DptCod")) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of department is missing or invalid."); + + return DptCod; } /*****************************************************************************/ @@ -622,8 +627,7 @@ void Dpt_RemoveDepartment (void) struct Department Dpt; /***** Get department code *****/ - if ((Dpt.DptCod = Dpt_GetParamDptCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of department is missing."); + Dpt.DptCod = Dpt_GetAndCheckParamDptCod (1); /***** Get data of the department from database *****/ Dpt_GetDataOfDepartmentByCod (&Dpt); @@ -661,11 +665,10 @@ void Dpt_ChangeDepartIns (void) /***** Get parameters from form *****/ /* Get the code of the department */ - if ((Dpt->DptCod = Dpt_GetParamDptCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of department is missing."); + Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get parameter with institution code */ - Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (); + Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Update institution in table of departments *****/ sprintf (Query,"UPDATE departments SET InsCod=%ld WHERE DptCod=%ld", @@ -733,8 +736,7 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName) /***** Get parameters from form *****/ /* Get the code of the department */ - if ((Dpt->DptCod = Dpt_GetParamDptCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of department is missing."); + Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get the new name for the department */ Par_GetParToText (ParamName,NewDptName,MaxBytes); @@ -831,8 +833,7 @@ void Dpt_ChangeDptWWW (void) /***** Get parameters from form *****/ /* Get the code of the department */ - if ((Dpt->DptCod = Dpt_GetParamDptCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of department is missing."); + Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get the new WWW for the department */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -1020,7 +1021,7 @@ void Dpt_RecFormNewDpt (void) /***** Get parameters from form *****/ /* Get institution */ - Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (); + Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get department short name */ Par_GetParToText ("ShortName",Dpt->ShrtName,Hie_MAX_BYTES_SHRT_NAME); diff --git a/swad_department.h b/swad_department.h index 3edf6547..f315d8b1 100644 --- a/swad_department.h +++ b/swad_department.h @@ -61,7 +61,7 @@ void Dpt_GetListDepartments (long InsCod); void Dpt_FreeListDepartments (void); unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod); void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt); -long Dpt_GetParamDptCod (void); +long Dpt_GetAndCheckParamDptCod (long MinCodAllowed); void Dpt_RemoveDepartment (void); void Dpt_ChangeDepartIns (void); void Dpt_RenameDepartShort (void); diff --git a/swad_indicator.c b/swad_indicator.c index 8ee21d8b..7eed413f 100644 --- a/swad_indicator.c +++ b/swad_indicator.c @@ -222,11 +222,12 @@ static void Ind_GetParamsIndicators (void) Sco_GetScope ("ScopeInd"); /***** Get degree type code *****/ - Gbl.Stat.DegTypCod = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? DT_GetParamOtherDegTypCod () : - -1L; + Gbl.Stat.DegTypCod = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? + DT_GetAndCheckParamOtherDegTypCod (-1L) : // -1L (any degree type) is allowed here + -1L; /***** Get department code *****/ - Gbl.Stat.DptCod = Dpt_GetParamDptCod (); + Gbl.Stat.DptCod = Dpt_GetAndCheckParamDptCod (-1L); // -1L (any department) is allowed here /***** Get number of indicators *****/ Ind_GetParamNumIndicators (); diff --git a/swad_institution.c b/swad_institution.c index 9e5958e6..2e326bf4 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1641,13 +1641,13 @@ static void Ins_PutParamOtherInsCod (long InsCod) /******************* Get parameter with code of institution ******************/ /*****************************************************************************/ -long Ins_GetAndCheckParamOtherInsCod (void) +long Ins_GetAndCheckParamOtherInsCod (long MinCodAllowed) { long InsCod; /***** Get and check parameter with code of institution *****/ - if ((InsCod = Ins_GetParamOtherInsCod ()) < 0) - Lay_ShowErrorAndExit ("Code of institution is missing."); + if ((InsCod = Ins_GetParamOtherInsCod ()) < MinCodAllowed) + Lay_ShowErrorAndExit ("Code of institution is missing or invalid."); return InsCod; } @@ -1671,7 +1671,7 @@ void Ins_RemoveInstitution (void) char PathIns[PATH_MAX + 1]; /***** Get institution code *****/ - Ins.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Ins.InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Get data of the institution from database *****/ Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_EXTRA_DATA); @@ -1722,7 +1722,7 @@ void Ins_RemoveInstitution (void) void Ins_RenameInsShort (void) { - Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); Ins_RenameInstitution (&Gbl.Inss.EditingIns,Cns_SHRT_NAME); } @@ -1737,7 +1737,7 @@ void Ins_RenameInsShortInConfig (void) void Ins_RenameInsFull (void) { - Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); Ins_RenameInstitution (&Gbl.Inss.EditingIns,Cns_FULL_NAME); } @@ -1867,7 +1867,7 @@ void Ins_ChangeInsCtyInConfig (void) struct Country NewCty; /***** Get the new country code for the institution *****/ - NewCty.CtyCod = Cty_GetAndCheckParamOtherCtyCod (); + NewCty.CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Check if country has changed *****/ if (NewCty.CtyCod != Gbl.CurrentIns.Ins.CtyCod) @@ -1945,7 +1945,7 @@ void Ins_ChangeInsWWW (void) /***** Get parameters from form *****/ /* Get the code of the institution */ - Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get the new WWW for the institution */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -2030,7 +2030,7 @@ void Ins_ChangeInsStatus (void) /***** Get parameters from form *****/ /* Get institution code */ - Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Gbl.Inss.EditingIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get parameter with status */ Status = (Ins_Status_t) diff --git a/swad_institution.h b/swad_institution.h index 15609f45..70a3c719 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -111,7 +111,7 @@ void Ins_GetShortNameOfInstitutionByCod (struct Instit *Ins); void Ins_FreeListInstitutions (void); void Ins_WriteSelectorOfInstitution (void); void Ins_PutParamInsCod (long InsCod); -long Ins_GetAndCheckParamOtherInsCod (void); +long Ins_GetAndCheckParamOtherInsCod (long MinCodAllowed); void Ins_RemoveInstitution (void); void Ins_RenameInsShort (void); void Ins_RenameInsShortInConfig (void); diff --git a/swad_photo.c b/swad_photo.c index 8024066a..65cd8df1 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -1334,7 +1334,7 @@ void Pho_CalcPhotoDegree (void) Fil_RemoveOldTmpFiles (PathPhotosTmpPriv,Cfg_TIME_TO_DELETE_PHOTOS_TMP_FILES,false); /***** Get the degree which photo will be computed *****/ - DegCod = Deg_GetAndCheckParamOtherDegCod (); + DegCod = Deg_GetAndCheckParamOtherDegCod (1); /***** Prevent the computing of an average photo too recently updated *****/ if (Pho_GetTimeAvgPhotoWasComputed (DegCod) >= diff --git a/swad_record.c b/swad_record.c index 69acf5cb..2dbe7438 100644 --- a/swad_record.c +++ b/swad_record.c @@ -4249,7 +4249,7 @@ void Rec_ShowFormMyInsCtrDpt (void) void Rec_ChgCountryOfMyInstitution (void) { /***** Get country code of my institution *****/ - Gbl.Usrs.Me.UsrDat.InsCtyCod = Cty_GetAndCheckParamOtherCtyCod (); + Gbl.Usrs.Me.UsrDat.InsCtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Update institution, centre and department *****/ // When country changes, the institution, centre and department must be reset @@ -4272,7 +4272,7 @@ void Rec_UpdateMyInstitution (void) /***** Get my institution *****/ /* Get institution code */ - Ins.InsCod = Ins_GetAndCheckParamOtherInsCod (); + Ins.InsCod = Ins_GetAndCheckParamOtherInsCod (0); // 0 (another institution) is allowed here /* Get country of institution */ if (Ins.InsCod > 0) @@ -4302,7 +4302,7 @@ void Rec_UpdateMyCentre (void) /***** Get my centre *****/ /* Get centre code */ - Ctr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); + Ctr.CtrCod = Ctr_GetAndCheckParamOtherCtrCod (0); // 0 (another centre) is allowed here /* Get institution of centre */ if (Ctr.CtrCod > 0) @@ -4333,8 +4333,7 @@ void Rec_UpdateMyDepartment (void) /***** Get my department *****/ /* Get department code */ - if ((Dpt.DptCod = Dpt_GetParamDptCod ()) < 0) - Lay_ShowErrorAndExit ("Code of department is missing."); + Dpt.DptCod = Dpt_GetAndCheckParamDptCod (0); // 0 (another department) is allowed here /* Get institution of department */ if (Dpt.DptCod > 0)