diff --git a/swad_action.h b/swad_action.h index 7da169d5..c4be238a 100644 --- a/swad_action.h +++ b/swad_action.h @@ -53,7 +53,7 @@ typedef enum Act_DOWNLD_FILE, // Download a file in a new window. Do not write HTML content. } Act_BrowserWindow_t; -typedef int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action +typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action #define Act_NUM_ACTIONS (1 + 9 + 51 + 14 + 93 + 73 + 70 + 249 + 189 + 159 + 172 + 36 + 31 + 97) diff --git a/swad_agenda.c b/swad_agenda.c index 0ffceab7..d456ed9a 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -697,10 +697,11 @@ static void Agd_GetParamEventOrder (void) if (!AlreadyGot) { - Gbl.Agenda.SelectedOrder = (Agd_Order_t) Par_GetParToUnsigned ("Order", - (unsigned) Agd_ORDER_BY_START_DATE, - (unsigned) Agd_ORDER_BY_END_DATE, - (unsigned) Agd_ORDER_DEFAULT); + Gbl.Agenda.SelectedOrder = (Agd_Order_t) + Par_GetParToUnsignedLong ("Order", + 0, + Agd_NUM_ORDERS - 1, + (unsigned long) Agd_ORDER_DEFAULT); AlreadyGot = true; } } diff --git a/swad_agenda.h b/swad_agenda.h index 1112e33b..3d0f7750 100644 --- a/swad_agenda.h +++ b/swad_agenda.h @@ -62,6 +62,7 @@ typedef enum Agd_ONLY_PUBLIC_EVENTS, } Agd_WhichEvents_t; +#define Agd_NUM_ORDERS 2 typedef enum { Agd_ORDER_BY_START_DATE = 0, diff --git a/swad_assignment.c b/swad_assignment.c index e72c5aea..918986f1 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -523,10 +523,11 @@ static void Asg_WriteAssignmentFolder (struct Assignment *Asg) static void Asg_GetParamAsgOrder (void) { - Gbl.Asgs.SelectedOrder = (Dat_StartEndTime_t) Par_GetParToUnsigned ("Order", - (unsigned) Dat_START_TIME, - (unsigned) Dat_END_TIME, - (unsigned) Asg_ORDER_DEFAULT); + Gbl.Asgs.SelectedOrder = (Dat_StartEndTime_t) + Par_GetParToUnsignedLong ("Order", + 0, + Dat_NUM_START_END_TIME - 1, + (unsigned long) Asg_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_attendance.c b/swad_attendance.c index 0409a06e..817e7a07 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -522,10 +522,11 @@ static void Att_WriteAttEventAuthor (struct AttendanceEvent *Att) static void Att_GetParamAttOrder (void) { - Gbl.AttEvents.SelectedOrder = (Dat_StartEndTime_t) Par_GetParToUnsigned ("Order", - (unsigned) Dat_START_TIME, - (unsigned) Dat_END_TIME, - (unsigned) Att_ORDER_DEFAULT); + Gbl.AttEvents.SelectedOrder = (Dat_StartEndTime_t) + Par_GetParToUnsignedLong ("Order", + 0, + Dat_NUM_START_END_TIME - 1, + (unsigned long) Att_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_calendar.c b/swad_calendar.c index b76d1637..c325c120 100644 --- a/swad_calendar.c +++ b/swad_calendar.c @@ -162,8 +162,11 @@ static unsigned Cal_GetParamFirstDayOfWeek (void) { unsigned FirstDayOfWeek; - FirstDayOfWeek = Par_GetParToUnsigned ("FirstDayOfWeek",0,6, - Cal_FIRST_DAY_OF_WEEK_DEFAULT); + FirstDayOfWeek = (unsigned) + Par_GetParToUnsignedLong ("FirstDayOfWeek", + 0, + 6, + Cal_FIRST_DAY_OF_WEEK_DEFAULT); if (!Cal_DayIsValidAsFirstDayOfWeek[FirstDayOfWeek]) FirstDayOfWeek = Cal_FIRST_DAY_OF_WEEK_DEFAULT; diff --git a/swad_centre.c b/swad_centre.c index c8d9ba51..e9e3e092 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -918,10 +918,11 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr) static void Ctr_GetParamCtrOrder (void) { - Gbl.Ctrs.SelectedOrder = (Ctr_Order_t) Par_GetParToUnsigned ("Order", - (unsigned) Ctr_ORDER_BY_CENTRE, - (unsigned) Ctr_ORDER_BY_NUM_TCHS, - (unsigned) Ctr_ORDER_DEFAULT); + Gbl.Ctrs.SelectedOrder = (Ctr_Order_t) + Par_GetParToUnsignedLong ("Order", + 0, + Ctr_NUM_ORDERS - 1, + (unsigned long) Ctr_ORDER_DEFAULT); } /*****************************************************************************/ @@ -2079,8 +2080,11 @@ void Ctr_ChangeCtrStatus (void) Ctr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (); /* Get parameter with status */ - Status = (Ctr_Status_t) Par_GetParToUnsigned ("Status",0,UINT_MAX, - (unsigned) Ctr_WRONG_STATUS); + Status = (Ctr_Status_t) + Par_GetParToUnsignedLong ("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); diff --git a/swad_centre.h b/swad_centre.h index 38e27e5f..e779e011 100644 --- a/swad_centre.h +++ b/swad_centre.h @@ -43,7 +43,8 @@ typedef enum } Ctr_Status_Bits_t; typedef unsigned Ctr_Status_t; -#define Ctr_WRONG_STATUS ((Ctr_Status_t) UINT_MAX) +#define Ctr_MAX_STATUS ((Ctr_Status_t) 3) +#define Ctr_WRONG_STATUS ((Ctr_Status_t) (Ctr_MAX_STATUS + 1)) #define Ctr_NUM_STATUS_TXT 4 typedef enum @@ -76,12 +77,12 @@ struct Centre unsigned NumUsrs; // Number of users in courses of this centre }; +#define Ctr_NUM_ORDERS 2 typedef enum { Ctr_ORDER_BY_CENTRE = 0, Ctr_ORDER_BY_NUM_TCHS = 1, } Ctr_Order_t; - #define Ctr_ORDER_DEFAULT Ctr_ORDER_BY_CENTRE /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 5ca4e504..a277caae 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -191,13 +191,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.131 (2017-01-29)" +#define Log_PLATFORM_VERSION "SWAD 16.132 (2017-01-29)" #define CSS_FILE "swad16.123.css" #define JS_FILE "swad16.123.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.132: Jan 29, 2017 Code refactoring in unsigned parameters. (211915 lines) Version 16.131: Jan 29, 2017 Code refactoring in unsigned parameters. Not finished. (211856 lines) Version 16.130: Jan 29, 2017 Code refactoring in unsigned parameters. Not finished. (211843 lines) Version 16.129: Jan 28, 2017 Code refactoring in Y/N parameters. (211974 lines) diff --git a/swad_country.c b/swad_country.c index 8ad8e0ef..4707fd79 100644 --- a/swad_country.c +++ b/swad_country.c @@ -889,10 +889,11 @@ void Cty_WriteScriptGoogleGeochart (void) static void Cty_GetParamCtyOrder (void) { - Gbl.Ctys.SelectedOrder = (Cty_Order_t) Par_GetParToUnsigned ("Order", - (unsigned) Cty_ORDER_BY_COUNTRY, - (unsigned) Cty_ORDER_BY_NUM_USRS, - (unsigned) Cty_ORDER_DEFAULT); + Gbl.Ctys.SelectedOrder = (Cty_Order_t) + Par_GetParToUnsignedLong ("Order", + 0, + Cty_NUM_ORDERS - 1, + (unsigned long) Cty_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_country.h b/swad_country.h index 52888412..9f00207b 100644 --- a/swad_country.h +++ b/swad_country.h @@ -56,12 +56,12 @@ struct Country unsigned NumUsrs; // Number of users in courses of the institution }; +#define Cty_NUM_ORDERS 2 typedef enum { Cty_ORDER_BY_COUNTRY = 0, Cty_ORDER_BY_NUM_USRS = 1, } Cty_Order_t; - #define Cty_ORDER_DEFAULT Cty_ORDER_BY_NUM_USRS typedef enum diff --git a/swad_course.c b/swad_course.c index 83441490..5625c8ae 100644 --- a/swad_course.c +++ b/swad_course.c @@ -2773,8 +2773,11 @@ void Crs_ChangeCrsStatus (void) Crs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (); /* Get parameter with status */ - Status = (Crs_Status_t) Par_GetParToUnsigned ("Status",0,UINT_MAX, - (unsigned) Crs_WRONG_STATUS); + Status = (Crs_Status_t) + Par_GetParToUnsignedLong ("Status", + 0, + (unsigned long) Crs_MAX_STATUS, + (unsigned long) Crs_WRONG_STATUS); if (Status == Crs_WRONG_STATUS) Lay_ShowErrorAndExit ("Wrong status."); StatusTxt = Crs_GetStatusTxtFromStatusBits (Status); @@ -3374,10 +3377,11 @@ void Crs_RemoveOldCrss (void) long CrsCod; /***** Get parameter with number of months without access *****/ - MonthsWithoutAccess = Par_GetParToUnsigned ("Months", - Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS, - Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS, - UINT_MAX); + MonthsWithoutAccess = (unsigned) + Par_GetParToUnsignedLong ("Months", + Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS, + Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS, + UINT_MAX); if (MonthsWithoutAccess == UINT_MAX) Lay_ShowErrorAndExit ("Wrong number of months without clicks."); SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; diff --git a/swad_course.h b/swad_course.h index 95d77a64..83d569fd 100644 --- a/swad_course.h +++ b/swad_course.h @@ -58,7 +58,8 @@ typedef enum } Crs_Status_Bits_t; typedef unsigned Crs_Status_t; -#define Crs_WRONG_STATUS ((Crs_Status_t) UINT_MAX) +#define Crs_MAX_STATUS ((Crs_Status_t) 3) +#define Crs_WRONG_STATUS ((Crs_Status_t) (Crs_MAX_STATUS + 1)) #define Crs_NUM_STATUS_TXT 4 typedef enum diff --git a/swad_date.c b/swad_date.c index 54e7bc52..0468fe9c 100644 --- a/swad_date.c +++ b/swad_date.c @@ -724,13 +724,13 @@ void Dat_GetDateFromForm (const char *ParamNameDay,const char *ParamNameMonth,co unsigned *Day,unsigned *Month,unsigned *Year) { /**** Get day ****/ - *Day = Par_GetParToUnsigned (ParamNameDay ,1,31,0); + *Day = (unsigned) Par_GetParToUnsignedLong (ParamNameDay ,1,31,0); /**** Get month ****/ - *Month = Par_GetParToUnsigned (ParamNameMonth,1,12,0); + *Month = (unsigned) Par_GetParToUnsignedLong (ParamNameMonth,1,12,0); /**** Get year ****/ - *Year = Par_GetParToUnsigned (ParamNameYear ,0,UINT_MAX,0); + *Year = (unsigned) Par_GetParToUnsignedLong (ParamNameYear ,0,UINT_MAX,0); } /*****************************************************************************/ diff --git a/swad_degree.c b/swad_degree.c index 0067a0b4..4b205fe7 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -2212,8 +2212,11 @@ void Deg_ChangeDegStatus (void) Deg->DegCod = Deg_GetAndCheckParamOtherDegCod (); /* Get parameter with status */ - Status = (Deg_Status_t) Par_GetParToUnsigned ("Status",0,UINT_MAX, - (unsigned) Deg_WRONG_STATUS); + Status = (Deg_Status_t) + Par_GetParToUnsignedLong ("Status", + 0, + (unsigned long) Deg_MAX_STATUS, + (unsigned long) Deg_WRONG_STATUS); if (Status == Deg_WRONG_STATUS) Lay_ShowErrorAndExit ("Wrong status."); StatusTxt = Deg_GetStatusTxtFromStatusBits (Status); diff --git a/swad_degree.h b/swad_degree.h index a4d68d16..fe326420 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -54,7 +54,8 @@ typedef enum } Deg_Status_Bits_t; typedef unsigned Deg_Status_t; -#define Deg_WRONG_STATUS ((Deg_Status_t) UINT_MAX) +#define Deg_MAX_STATUS ((Deg_Status_t) 3) +#define Deg_WRONG_STATUS ((Deg_Status_t) (Deg_MAX_STATUS + 1)) #define Deg_NUM_STATUS_TXT 4 typedef enum diff --git a/swad_department.c b/swad_department.c index ac9f5a55..a193ed6b 100644 --- a/swad_department.c +++ b/swad_department.c @@ -193,10 +193,11 @@ void Dpt_SeeDepts (void) static void Dpt_GetParamDptOrder (void) { - Gbl.Dpts.SelectedOrder = (Dpt_Order_t) Par_GetParToUnsigned ("Order", - (unsigned) Dpt_ORDER_BY_DEPARTMENT, - (unsigned) Dpt_ORDER_BY_NUM_TCHS, - (unsigned) Dpt_ORDER_DEFAULT); + Gbl.Dpts.SelectedOrder = (Dpt_Order_t) + Par_GetParToUnsignedLong ("Order", + 0, + Dpt_NUM_ORDERS - 1, + (unsigned long) Dpt_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_department.h b/swad_department.h index a5ba5da1..d7f2ea2c 100644 --- a/swad_department.h +++ b/swad_department.h @@ -44,12 +44,12 @@ struct Department unsigned NumTchs; }; +#define Dpt_NUM_ORDERS 2 typedef enum { Dpt_ORDER_BY_DEPARTMENT = 0, Dpt_ORDER_BY_NUM_TCHS = 1, } Dpt_Order_t; - #define Dpt_ORDER_DEFAULT Dpt_ORDER_BY_DEPARTMENT /*****************************************************************************/ diff --git a/swad_enrollment.c b/swad_enrollment.c index 26d6f041..0e715a1b 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -52,9 +52,10 @@ /****************************** Internal types *******************************/ /*****************************************************************************/ +#define Enr_NUM_REG_REM_USRS_ACTIONS 6 typedef enum { - Enr_USRS_UNKNOWN_ACTION = 0, + Enr_REG_REM_USRS_UNKNOWN_ACTION = 0, Enr_REGISTER_SPECIFIED_USRS_IN_CRS = 1, Enr_REMOVE_SPECIFIED_USRS_FROM_CRS = 2, Enr_REMOVE_NOT_SPECIFIED_USRS_FROM_CRS = 3, @@ -722,10 +723,11 @@ void Enr_RemoveOldUsrs (void) struct UsrData UsrDat; /***** Get parameter with number of months without access *****/ - MonthsWithoutAccess = Par_GetParToUnsigned ("Months", - Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS, - Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS, - UINT_MAX); + MonthsWithoutAccess = (unsigned) + Par_GetParToUnsignedLong ("Months", + Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS, + Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS, + (unsigned long) UINT_MAX); if (MonthsWithoutAccess == UINT_MAX) Lay_ShowErrorAndExit ("Wrong number of months."); SecondsWithoutAccess = (time_t) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; @@ -1289,10 +1291,11 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role) WhatToDo.EliminateUsrs = false; WhatToDo.RegisterUsrs = false; - RegRemUsrsAction = (Enr_RegRemUsrsAction_t) Par_GetParToUnsigned ("RegRemAction", - (unsigned) Enr_REGISTER_SPECIFIED_USRS_IN_CRS, - (unsigned) Enr_ELIMINATE_USRS_FROM_PLATFORM, - (unsigned) Enr_USRS_UNKNOWN_ACTION); + RegRemUsrsAction = (Enr_RegRemUsrsAction_t) + Par_GetParToUnsignedLong ("RegRemAction", + 0, + Enr_NUM_REG_REM_USRS_ACTIONS - 1, + (unsigned long) Enr_REG_REM_USRS_UNKNOWN_ACTION); switch (RegRemUsrsAction) { case Enr_REGISTER_SPECIFIED_USRS_IN_CRS: @@ -1852,10 +1855,11 @@ void Enr_SignUpInCrs (void) else { /***** Get new role from record form *****/ - RoleFromForm = (Rol_Role_t) Par_GetParToUnsigned ("Role", - 0, - Rol_NUM_ROLES - 1, - (unsigned) Rol_UNKNOWN); + RoleFromForm = (Rol_Role_t) + Par_GetParToUnsignedLong ("Role", + 0, + Rol_NUM_ROLES - 1, + (unsigned long) Rol_UNKNOWN); /* Check if role is correct */ if (!(RoleFromForm == Rol_STUDENT || @@ -3641,10 +3645,10 @@ void Enr_ModifyUsr1 (void) /***** Get the action to do *****/ Gbl.Usrs.RegRemAction = (Enr_RegRemOneUsrAction_t) - Par_GetParToUnsigned ("RegRemAction", - (unsigned) Enr_REGISTER_MODIFY_ONE_USR_IN_CRS, - (unsigned) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM, - (unsigned) Enr_ONE_USR_UNKNOWN_ACTION); + Par_GetParToUnsignedLong ("RegRemAction", + 0, + Enr_REG_REM_ONE_USR_NUM_ACTIONS - 1, + (unsigned long) Enr_REG_REM_ONE_USR_UNKNOWN_ACTION); switch (Gbl.Usrs.RegRemAction) { case Enr_REGISTER_MODIFY_ONE_USR_IN_CRS: diff --git a/swad_enrollment.h b/swad_enrollment.h index 7d8d63c1..8b4594d6 100644 --- a/swad_enrollment.h +++ b/swad_enrollment.h @@ -49,9 +49,10 @@ typedef enum Enr_SET_ACCEPTED_TO_TRUE, } Enr_KeepOrSetAccepted_t; +#define Enr_REG_REM_ONE_USR_NUM_ACTIONS 11 typedef enum { - Enr_ONE_USR_UNKNOWN_ACTION = 0, + Enr_REG_REM_ONE_USR_UNKNOWN_ACTION = 0, Enr_REGISTER_MODIFY_ONE_USR_IN_CRS = 1, Enr_REGISTER_ONE_DEGREE_ADMIN = 2, Enr_REGISTER_ONE_CENTRE_ADMIN = 3, diff --git a/swad_exam.c b/swad_exam.c index fcb13e92..19ca1d7f 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -129,10 +129,11 @@ static long Exa_GetParamsExamAnnouncement (void) Crs_MAX_LENGTH_COURSE_FULL_NAME); /***** Get the year *****/ - Gbl.ExamAnns.ExaDat.Year = Par_GetParToUnsigned ("Year", - 0, // N.A. - Deg_MAX_YEARS_PER_DEGREE, - Gbl.CurrentCrs.Crs.Year); + Gbl.ExamAnns.ExaDat.Year = (unsigned) + Par_GetParToUnsignedLong ("Year", + 0, // N.A. + Deg_MAX_YEARS_PER_DEGREE, + (unsigned long) Gbl.CurrentCrs.Crs.Year); /***** Get the type of exam announcement *****/ Par_GetParToText ("ExamSession",Gbl.ExamAnns.ExaDat.Session,Cns_MAX_BYTES_STRING); @@ -152,16 +153,16 @@ static long Exa_GetParamsExamAnnouncement (void) } /***** Get the hour of the exam *****/ - Gbl.ExamAnns.ExaDat.StartTime.Hour = Par_GetParToUnsigned ("ExamHour", - 0,23,0); - Gbl.ExamAnns.ExaDat.StartTime.Minute = Par_GetParToUnsigned ("ExamMinute", - 0,59,0); + Gbl.ExamAnns.ExaDat.StartTime.Hour = (unsigned) Par_GetParToUnsignedLong ("ExamHour", + 0,23,0); + Gbl.ExamAnns.ExaDat.StartTime.Minute = (unsigned) Par_GetParToUnsignedLong ("ExamMinute", + 0,59,0); /***** Get the duration of the exam *****/ - Gbl.ExamAnns.ExaDat.Duration.Hour = Par_GetParToUnsigned ("DurationHour", - 0,23,0); - Gbl.ExamAnns.ExaDat.Duration.Minute = Par_GetParToUnsigned ("DurationMinute", - 0,59,0); + Gbl.ExamAnns.ExaDat.Duration.Hour = (unsigned) Par_GetParToUnsignedLong ("DurationHour", + 0,23,0); + Gbl.ExamAnns.ExaDat.Duration.Minute = (unsigned) Par_GetParToUnsignedLong ("DurationMinute", + 0,59,0); /***** Get the place where the exam will happen *****/ Par_GetParToHTML ("Place",Gbl.ExamAnns.ExaDat.Place,Cns_MAX_BYTES_TEXT); diff --git a/swad_file_browser.c b/swad_file_browser.c index f0ce3e85..18c66adf 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -9864,10 +9864,11 @@ static bool Brw_GetParamPublicFile (void) static Brw_License_t Brw_GetParLicense (void) { - return (Brw_License_t) Par_GetParToUnsigned ("License", - (unsigned) Brw_LICENSE_UNKNOWN, - (unsigned) Brw_LICENSE_CC_BY_NC_ND, - (unsigned) Brw_LICENSE_UNKNOWN); + return (Brw_License_t) + Par_GetParToUnsignedLong ("License", + 0, + Brw_NUM_LICENSES - 1, + (unsigned long) Brw_LICENSE_UNKNOWN); } /*****************************************************************************/ @@ -11630,10 +11631,11 @@ void Brw_RemoveOldFilesBriefcase (void) if (Brw_GetIfCrsAssigWorksFileBrowser ()) { /***** Get parameter with number of months without access *****/ - Months = Par_GetParToUnsigned ("Months", - Brw_MIN_MONTHS_TO_REMOVE_OLD_FILES, - Brw_MAX_MONTHS_IN_BRIEFCASE, - Brw_DEF_MONTHS_TO_REMOVE_OLD_FILES); + Months = (unsigned) + Par_GetParToUnsignedLong ("Months", + Brw_MIN_MONTHS_TO_REMOVE_OLD_FILES, + Brw_MAX_MONTHS_IN_BRIEFCASE, + Brw_DEF_MONTHS_TO_REMOVE_OLD_FILES); /***** Remove old files *****/ Brw_RemoveOldFilesInBrowser (Months,&Removed); diff --git a/swad_forum.c b/swad_forum.c index fbc71a00..d3fd6374 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -3729,17 +3729,17 @@ void For_GetParamsForum (void) { /***** Get which forums I want to see *****/ Gbl.Forum.WhichForums = (For_WhichForums_t) - Par_GetParToUnsigned ("WhichForum", - (unsigned) For_ONLY_CURRENT_FORUMS, - (unsigned) For_ALL_MY_FORUMS, - (unsigned) For_DEFAULT_WHICH_FORUMS); + Par_GetParToUnsignedLong ("WhichForum", + 0, + For_NUM_WHICH_FORUMS - 1, + (unsigned long) For_DEFAULT_WHICH_FORUMS); /***** Get order type *****/ Gbl.Forum.SelectedOrder = (For_Order_t) - Par_GetParToUnsigned ("Order", - (unsigned) For_FIRST_MSG, - (unsigned) For_LAST_MSG, - (unsigned) For_DEFAULT_ORDER); + Par_GetParToUnsignedLong ("Order", + 0, + For_NUM_ORDERS - 1, + (unsigned long) For_DEFAULT_ORDER); /***** Get parameter with code of institution *****/ Gbl.Forum.Ins.InsCod = Par_GetParToLong ("ForInsCod"); diff --git a/swad_forum.h b/swad_forum.h index e00ea4fe..006543a7 100644 --- a/swad_forum.h +++ b/swad_forum.h @@ -77,6 +77,8 @@ struct ForumThread unsigned NumWriters; unsigned NumReaders; }; + +#define For_NUM_ORDERS 2 typedef enum { For_FIRST_MSG = 0, diff --git a/swad_global.c b/swad_global.c index b82950bb..810fa3d8 100644 --- a/swad_global.c +++ b/swad_global.c @@ -380,12 +380,12 @@ void Gbl_InitializeGlobals (void) Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF; /* Statistics */ - Gbl.Stat.ClicksGroupedBy = Sta_CLICKS_CRS_PER_USR; - Gbl.Stat.CountType = Sta_TOTAL_CLICKS; - Gbl.Stat.Role = Sta_IDENTIFIED_USRS; - Gbl.Stat.NumAction = ActAll; - Gbl.Stat.RowsPerPage = 50; - Gbl.Stat.FigureType = Sta_USERS; + Gbl.Stat.ClicksGroupedBy = Sta_CLICKS_GROUPED_BY_DEFAULT; + Gbl.Stat.CountType = Sta_COUNT_TYPE_DEFAULT; + Gbl.Stat.Role = Sta_ROLE_DEFAULT; + Gbl.Stat.NumAction = Sta_NUM_ACTION_DEFAULT; + Gbl.Stat.RowsPerPage = Sta_DEF_ROWS_PER_PAGE; + Gbl.Stat.FigureType = Sta_FIGURE_TYPE_DEF; Gbl.Scope.Current = Sco_SCOPE_CRS; diff --git a/swad_group.c b/swad_group.c index c2065bf9..e6639b8d 100644 --- a/swad_group.c +++ b/swad_group.c @@ -3150,10 +3150,11 @@ void Grp_RecFormNewGrp (void) Grp_MAX_LENGTH_GROUP_NAME); /* Get maximum number of students */ - Gbl.CurrentCrs.Grps.MaxStudents = Par_GetParToUnsigned ("MaxStudents", - 0, - Grp_MAX_STUDENTS_IN_A_GROUP, - Grp_NUM_STUDENTS_NOT_LIMITED); + Gbl.CurrentCrs.Grps.MaxStudents = (unsigned) + Par_GetParToUnsignedLong ("MaxStudents", + 0, + Grp_MAX_STUDENTS_IN_A_GROUP, + Grp_NUM_STUDENTS_NOT_LIMITED); if (Gbl.CurrentCrs.Grps.GrpName[0]) // If there's a group name { @@ -3844,10 +3845,11 @@ void Grp_ChangeMaxStdsGrp (void) Lay_ShowErrorAndExit ("Code of group is missing."); /* Get the new maximum number of students of the group */ - NewMaxStds = Par_GetParToUnsigned ("MaxStudents", - 0, - Grp_MAX_STUDENTS_IN_A_GROUP, - Grp_NUM_STUDENTS_NOT_LIMITED); + NewMaxStds = (unsigned) + Par_GetParToUnsignedLong ("MaxStudents", + 0, + Grp_MAX_STUDENTS_IN_A_GROUP, + Grp_NUM_STUDENTS_NOT_LIMITED); /* Get from the database the type, name, and antiguo maximum of students of the group */ GrpDat.GrpCod = Gbl.CurrentCrs.Grps.GrpCod; @@ -4281,9 +4283,9 @@ void Grp_GetParamWhichGrps (void) /* Get parameter */ Gbl.CurrentCrs.Grps.WhichGrps = (Grp_WhichGroups_t) - Par_GetParToUnsigned ("WhichGrps", - (unsigned) Grp_ONLY_MY_GROUPS, - (unsigned) Grp_ALL_GROUPS, - (unsigned) WhichGroupsDefault); + Par_GetParToUnsignedLong ("WhichGrps", + 0, + Grp_NUM_WHICH_GROUPS - 1, + (unsigned long) WhichGroupsDefault); } } diff --git a/swad_group.h b/swad_group.h index 74c6fb35..77994eff 100644 --- a/swad_group.h +++ b/swad_group.h @@ -38,7 +38,8 @@ #define Grp_MAX_LENGTH_GROUP_NAME (256 - 1) #define Grp_MAX_STUDENTS_IN_A_GROUP 10000 // If max of students in a group is greater than this, it is considered infinite -#define Grp_NUM_STUDENTS_NOT_LIMITED INT_MAX // This number can be stored in database and means that a group has no limit of students +#define Grp_NUM_STUDENTS_NOT_LIMITED INT_MAX // This number can be stored in database as an integer... + // ...and means that a group has no limit of students /*****************************************************************************/ /******************************* Public types ********************************/ @@ -109,6 +110,7 @@ struct ListGrpsAlreadySelec bool AlreadySelected; }; +#define Grp_NUM_WHICH_GROUPS 2 typedef enum { Grp_ONLY_MY_GROUPS, diff --git a/swad_holiday.c b/swad_holiday.c index 4361ab61..9a183d59 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -182,10 +182,10 @@ void Hld_SeeHolidays (void) static void Hld_GetParamHldOrder (void) { Gbl.Hlds.SelectedOrder = (Hld_Order_t) - Par_GetParToUnsigned ("Order", - (unsigned) Hld_ORDER_BY_PLACE, - (unsigned) Hld_ORDER_BY_START_DATE, - (unsigned) Hld_DEFAULT_ORDER_TYPE); + Par_GetParToUnsignedLong ("Order", + 0, + Hld_NUM_ORDERS - 1, + (unsigned long) Hld_DEFAULT_ORDER_TYPE); } /*****************************************************************************/ @@ -440,10 +440,11 @@ static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld) static Hld_HolidayType_t Hld_GetParamHldType (void) { - return (Hld_HolidayType_t) Par_GetParToUnsigned ("HldTyp", - (unsigned) Hld_HOLIDAY, - (unsigned) Hld_NON_SCHOOL_PERIOD, - (unsigned) Hld_HOLIDAY_TYPE_DEFAULT); + return (Hld_HolidayType_t) + Par_GetParToUnsignedLong ("HldTyp", + 0, + Hld_NUM_TYPES_HOLIDAY - 1, + (unsigned long) Hld_HOLIDAY_TYPE_DEFAULT); } /*****************************************************************************/ diff --git a/swad_holiday.h b/swad_holiday.h index d765abe7..4e86d958 100644 --- a/swad_holiday.h +++ b/swad_holiday.h @@ -61,12 +61,12 @@ struct Holiday char Name[Hld_MAX_LENGTH_HOLIDAY_NAME + 1]; }; +#define Hld_NUM_ORDERS 2 typedef enum { Hld_ORDER_BY_PLACE = 0, Hld_ORDER_BY_START_DATE = 1, } Hld_Order_t; - #define Hld_DEFAULT_ORDER_TYPE Hld_ORDER_BY_START_DATE /*****************************************************************************/ diff --git a/swad_image.c b/swad_image.c index 194d3258..8f67ba94 100644 --- a/swad_image.c +++ b/swad_image.c @@ -375,10 +375,11 @@ void Img_SetParamNames (struct ParamUploadImg *ParamUploadImg,int NumImgInForm) Img_Action_t Img_GetImageActionFromForm (const char *ParamAction) { /***** Get parameter with the action to perform on image *****/ - return (Img_Action_t) Par_GetParToUnsigned (ParamAction, - (unsigned) Img_ACTION_NEW_IMAGE, - (unsigned) Img_ACTION_NO_IMAGE, - (unsigned) Img_ACTION_NO_IMAGE); // Default action if none supplied + return (Img_Action_t) + Par_GetParToUnsignedLong (ParamAction, + 0, + Img_NUM_ACTIONS - 1, + (unsigned long) Img_ACTION_DEFAULT); } /*****************************************************************************/ diff --git a/swad_image.h b/swad_image.h index 4ba4db15..685f0236 100644 --- a/swad_image.h +++ b/swad_image.h @@ -47,6 +47,7 @@ typedef enum Img_ACTION_CHANGE_IMAGE, // Change existing image by a new image Img_ACTION_NO_IMAGE, // Do not use image (remove current image if exists) } Img_Action_t; +#define Img_ACTION_DEFAULT Img_ACTION_NO_IMAGE /***** Status of an image file *****/ /* diff --git a/swad_info.c b/swad_info.c index 36e77530..a533ad21 100644 --- a/swad_info.c +++ b/swad_info.c @@ -1442,10 +1442,11 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromForm (void) { /***** Get info source for a specific type of course information (introduction, teaching guide, bibliography, FAQ, links or evaluation) *****/ - return (Inf_InfoSrc_t) Par_GetParToUnsigned ("InfoSrc", - (unsigned) Inf_INFO_SRC_NONE, - (unsigned) Inf_INFO_SRC_URL, - (unsigned) Inf_INFO_SRC_NONE); + return (Inf_InfoSrc_t) + Par_GetParToUnsignedLong ("InfoSrc", + 0, + Inf_NUM_INFO_SOURCES - 1, + (unsigned long) Inf_INFO_SRC_NONE); } /*****************************************************************************/ diff --git a/swad_institution.c b/swad_institution.c index 00f358d6..a020987b 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -909,10 +909,10 @@ static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable) static void Ins_GetParamInsOrder (void) { Gbl.Inss.SelectedOrder = (Ins_Order_t) - Par_GetParToUnsigned ("Order", - (unsigned) Ins_ORDER_BY_INSTITUTION, - (unsigned) Ins_ORDER_BY_NUM_USRS, - (unsigned) Ins_ORDER_DEFAULT); + Par_GetParToUnsignedLong ("Order", + 0, + Ins_NUM_ORDERS - 1, + (unsigned long) Ins_ORDER_DEFAULT); } /*****************************************************************************/ @@ -1935,9 +1935,12 @@ void Ins_ChangeInsStatus (void) Ins->InsCod = Ins_GetAndCheckParamOtherInsCod (); /* Get parameter with status */ - Status = (Ins_Status_t) Par_GetParToUnsigned ("Status",0,UINT_MAX, - (unsigned) Ins_WRONG_STATUS); - if (Status == Ctr_WRONG_STATUS) + Status = (Ins_Status_t) + Par_GetParToUnsignedLong ("Status", + 0, + (unsigned long) Ins_MAX_STATUS, + (unsigned long) Ins_WRONG_STATUS); + if (Status == Ins_WRONG_STATUS) Lay_ShowErrorAndExit ("Wrong status."); StatusTxt = Ins_GetStatusTxtFromStatusBits (Status); Status = Ins_GetStatusBitsFromStatusTxt (StatusTxt); // New status diff --git a/swad_institution.h b/swad_institution.h index be29d76a..6aa56695 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -41,7 +41,8 @@ typedef enum } Ins_Status_Bits_t; typedef unsigned Ins_Status_t; -#define Ins_WRONG_STATUS ((Ins_Status_t) UINT_MAX) +#define Ins_MAX_STATUS ((Ins_Status_t) 3) +#define Ins_WRONG_STATUS ((Ins_Status_t) (Ins_MAX_STATUS + 1)) #define Ins_NUM_STATUS_TXT 4 typedef enum @@ -74,12 +75,12 @@ struct Instit unsigned NumUsrs; // Number of users in courses of this institution }; +#define Ins_NUM_ORDERS 2 typedef enum { Ins_ORDER_BY_INSTITUTION = 0, Ins_ORDER_BY_NUM_USRS = 1, } Ins_Order_t; - #define Ins_ORDER_DEFAULT Ins_ORDER_BY_NUM_USRS typedef enum diff --git a/swad_mail.c b/swad_mail.c index 440269aa..50b7cdc4 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -162,10 +162,10 @@ void Mai_SeeMailDomains (void) static void Mai_GetParamMaiOrder (void) { Gbl.Mails.SelectedOrder = (Mai_DomainsOrder_t) - Par_GetParToUnsigned ("Order", - (unsigned) Mai_ORDER_BY_DOMAIN, - (unsigned) Mai_ORDER_BY_INFO, - (unsigned) Mai_ORDER_DEFAULT); + Par_GetParToUnsignedLong ("Order", + 0, + Mai_NUM_ORDERS - 1, + (unsigned long) Mai_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_mail.h b/swad_mail.h index 3ab0b3c4..1ec72c06 100644 --- a/swad_mail.h +++ b/swad_mail.h @@ -36,13 +36,13 @@ #define Mai_MAX_LENGTH_MAIL_DOMAIN (128 - 1) #define Mai_MAX_LENGTH_MAIL_INFO (128 - 1) +#define Mai_NUM_ORDERS 3 typedef enum { Mai_ORDER_BY_DOMAIN = 0, Mai_ORDER_BY_INFO = 1, Mai_ORDER_BY_USERS = 2, } Mai_DomainsOrder_t; - #define Mai_ORDER_DEFAULT Mai_ORDER_BY_USERS struct Mail diff --git a/swad_menu.c b/swad_menu.c index 32d2007a..ddce7680 100644 --- a/swad_menu.c +++ b/swad_menu.c @@ -435,8 +435,9 @@ void Mnu_ChangeMenu (void) Mnu_Menu_t Mnu_GetParamMenu (void) { - return (Mnu_Menu_t) Par_GetParToUnsigned ("Menu", - (unsigned) Mnu_MENU_HORIZONTAL, - (unsigned) Mnu_MENU_VERTICAL, - (unsigned) Mnu_MENU_DEFAULT); + return (Mnu_Menu_t) + Par_GetParToUnsignedLong ("Menu", + 0, + Mnu_NUM_MENUS - 1, + (unsigned long) Mnu_MENU_DEFAULT); } diff --git a/swad_network.c b/swad_network.c index ba0ccf80..bc050a10 100644 --- a/swad_network.c +++ b/swad_network.c @@ -77,6 +77,7 @@ typedef enum Net_WIKIPEDIA, Net_YOUTUBE, } Net_WebsAndSocialNetworks_t; +#define Net_WEB_SOCIAL_NET_DEFAULT Net_WWW #define Net_MAX_LENGTH_NETWORK_NAME 32 @@ -397,10 +398,11 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void) char URL[Cns_MAX_LENGTH_WWW + 1]; /***** Get parameter with the type of web / social network *****/ - Web = (Net_WebsAndSocialNetworks_t) Par_GetParToUnsigned ("Web", - (unsigned) Net_WWW, - (unsigned) Net_YOUTUBE, - (unsigned) Net_WWW); + Web = (Net_WebsAndSocialNetworks_t) + Par_GetParToUnsignedLong ("Web", + 0, + Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1, + (unsigned long) Net_WEB_SOCIAL_NET_DEFAULT); /***** Get URL *****/ Par_GetParToText ("URL",URL,Cns_MAX_LENGTH_WWW); diff --git a/swad_notification.c b/swad_notification.c index d3618d4f..160205df 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -823,10 +823,11 @@ static void Ntf_PutHiddenParamNotifyEvent (Ntf_NotifyEvent_t NotifyEvent) Ntf_NotifyEvent_t Ntf_GetParamNotifyEvent (void) { - return (Ntf_NotifyEvent_t) Par_GetParToUnsigned ("NotifyEvent", - (unsigned) Ntf_EVENT_UNKNOWN, - (unsigned) Ntf_EVENT_SURVEY, - (unsigned) Ntf_EVENT_UNKNOWN); + return (Ntf_NotifyEvent_t) + Par_GetParToUnsignedLong ("NotifyEvent", + 0, + Ntf_NUM_NOTIFY_EVENTS - 1, + (unsigned long) Ntf_EVENT_UNKNOWN); } /*****************************************************************************/ diff --git a/swad_pagination.c b/swad_pagination.c index b91e39ed..09a1cfcd 100644 --- a/swad_pagination.c +++ b/swad_pagination.c @@ -622,8 +622,11 @@ void Pag_GetParamPagNum (Pag_WhatPaginate_t WhatPaginate) FirstCall = false; /***** Try to get parameter with the number of page *****/ - Gbl.Pag.CurrentPage = Par_GetParToUnsigned ("NumPage", - 1,UINT_MAX,0); + Gbl.Pag.CurrentPage = (unsigned) + Par_GetParToUnsignedLong ("NumPage", + 1, + UINT_MAX, + 0); if (Gbl.Pag.CurrentPage == 0) /***** If there's no parameter page, return a default value *****/ switch (WhatPaginate) diff --git a/swad_parameter.c b/swad_parameter.c index cb1696e2..2e53e287 100644 --- a/swad_parameter.c +++ b/swad_parameter.c @@ -712,15 +712,15 @@ void Par_GetMainParameters (void) } /***** Get action to perform *****/ - ActCod = Par_GetParToUnsigned ("act", - ActUnk, - Act_MAX_ACTION_COD, - ActUnk); + ActCod = (unsigned) Par_GetParToUnsignedLong ("act", + ActUnk, + Act_MAX_ACTION_COD, + ActUnk); if (ActCod == ActUnk) - ActCod = Par_GetParToUnsigned ("ActCod", - ActUnk, - Act_MAX_ACTION_COD, - ActUnk); + ActCod = (unsigned) Par_GetParToUnsignedLong ("ActCod", + ActUnk, + Act_MAX_ACTION_COD, + ActUnk); if (ActCod != ActUnk) Gbl.Action.Act = Act_FromActCodToAction[ActCod]; @@ -842,10 +842,11 @@ void Par_GetMainParameters (void) Gbl.Action.Tab = TabUnk; if (Gbl.Action.Act == ActMnu) { - Gbl.Action.Tab = (Tab_Tab_t) Par_GetParToUnsigned ("NxtTab", - (unsigned) TabUnk, - Tab_NUM_TABS - 1, - (unsigned) TabUnk); + Gbl.Action.Tab = (Tab_Tab_t) + Par_GetParToUnsignedLong ("NxtTab", + (unsigned long) TabUnk, + Tab_NUM_TABS - 1, + (unsigned long) TabUnk); Tab_DisableIncompatibleTabs (); } else // Set tab depending on current action @@ -867,19 +868,19 @@ unsigned Par_GetParToText (const char *ParamName,char *ParamValue,size_t MaxByte /****************** Get the unsigned value of a parameter ********************/ /*****************************************************************************/ -unsigned Par_GetParToUnsigned (const char *ParamName, - unsigned Min, - unsigned Max, - unsigned Default) +unsigned long Par_GetParToUnsignedLong (const char *ParamName, + unsigned long Min, + unsigned long Max, + unsigned long Default) { - char UnsignedStr[10 + 1]; - unsigned UnsignedNum; + char UnsignedLongStr[20 + 1]; + unsigned long UnsignedLongNum; /***** Get parameter with unsigned number *****/ - Par_GetParToText (ParamName,UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) - if (UnsignedNum >= Min && UnsignedNum <= Max) - return UnsignedNum; + Par_GetParToText (ParamName,UnsignedLongStr,10); + if (sscanf (UnsignedLongStr,"%lu",&UnsignedLongNum) == 1) + if (UnsignedLongNum >= Min && UnsignedLongNum <= Max) + return UnsignedLongNum; return Default; } diff --git a/swad_parameter.h b/swad_parameter.h index 63150c0c..bfe31e88 100644 --- a/swad_parameter.h +++ b/swad_parameter.h @@ -72,10 +72,10 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, void Par_GetMainParameters (void); unsigned Par_GetParToText (const char *ParamName,char *ParamValue,size_t MaxBytes); -unsigned Par_GetParToUnsigned (const char *ParamName, - unsigned Min, - unsigned Max, - unsigned Default); +unsigned long Par_GetParToUnsignedLong (const char *ParamName, + unsigned long Min, + unsigned long Max, + unsigned long Default); long Par_GetParToLong (const char *ParamName); bool Par_GetParToBool (const char *ParamName); unsigned Par_GetParToHTML (const char *ParamName,char *ParamValue,size_t MaxBytes); diff --git a/swad_photo.c b/swad_photo.c index dae9762b..d5ecee0d 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -1643,12 +1643,14 @@ void Pho_ShowOrPrintPhotoDegree (Pho_AvgPhotoSeeOrPrint_t SeeOrPrint) /***** Draw the classphoto/list *****/ switch (Gbl.Usrs.Me.ListType) { - case Usr_CLASS_PHOTO: + case Usr_LIST_AS_CLASS_PHOTO: Pho_ShowOrPrintClassPhotoDegrees (SeeOrPrint); break; - case Usr_LIST: + case Usr_LIST_AS_LISTING: Pho_ShowOrPrintListDegrees (SeeOrPrint); break; + default: + break; } } @@ -1707,10 +1709,10 @@ void Pho_PutHiddenParamTypeOfAvg (void) static Pho_AvgPhotoTypeOfAverage_t Pho_GetPhotoAvgTypeFromForm (void) { return (Pho_AvgPhotoTypeOfAverage_t) - Par_GetParToUnsigned ("AvgType", - (unsigned) Pho_PHOTO_MEDIAN_ALL, - (unsigned) Pho_PHOTO_AVERAGE_ALL, - (unsigned) Pho_PHOTO_AVG_DEFAULT); + Par_GetParToUnsignedLong ("AvgType", + 0, + Pho_NUM_AVERAGE_PHOTO_TYPES - 1, + (unsigned long) Pho_PHOTO_AVG_DEFAULT); } /*****************************************************************************/ @@ -1768,10 +1770,10 @@ void Pho_PutHiddenParamPhotoSize (void) static Pho_HowComputePhotoSize_t Pho_GetHowComputePhotoSizeFromForm (void) { return (Pho_HowComputePhotoSize_t) - Par_GetParToUnsigned ("PhotoSize", - (unsigned) Pho_PROPORTIONAL_TO_NUMBER_OF_STUDENTS, - (unsigned) Pho_UNIQUE_SIZE, - (unsigned) Pho_PHOTO_SIZE_DEFAULT); + Par_GetParToUnsignedLong ("PhotoSize", + 0, + Pho_NUM_HOW_COMPUTE_PHOTO_SIZES - 1, + (unsigned long) Pho_PHOTO_SIZE_DEFAULT); } /*****************************************************************************/ @@ -1829,10 +1831,10 @@ void Pho_PutHiddenParamOrderDegrees (void) static Pho_HowOrderDegrees_t Pho_GetHowOrderDegreesFromForm (void) { return (Pho_HowOrderDegrees_t) - Par_GetParToUnsigned ("Order", - (unsigned) Pho_NUMBER_OF_STUDENTS, - (unsigned) Pho_DEGREE_NAME, - (unsigned) Pho_ORDER_DEFAULT); + Par_GetParToUnsignedLong ("Order", + 0, + Pho_NUM_HOW_ORDER_DEGREES - 1, + (unsigned long) Pho_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_place.c b/swad_place.c index 7992fc6c..402ddd4b 100644 --- a/swad_place.c +++ b/swad_place.c @@ -185,10 +185,10 @@ void Plc_SeePlaces (void) static void Plc_GetParamPlcOrder (void) { Gbl.Plcs.SelectedOrder = (Plc_Order_t) - Par_GetParToUnsigned ("Order", - (unsigned) Plc_ORDER_BY_PLACE, - (unsigned) Plc_ORDER_BY_NUM_CTRS, - (unsigned) Plc_ORDER_DEFAULT); + Par_GetParToUnsignedLong ("Order", + 0, + Plc_NUM_ORDERS - 1, + (unsigned long) Plc_ORDER_DEFAULT); } /*****************************************************************************/ diff --git a/swad_place.h b/swad_place.h index 0ac6c747..90d7c4ad 100644 --- a/swad_place.h +++ b/swad_place.h @@ -43,12 +43,12 @@ struct Place unsigned NumCtrs; }; +#define Plc_NUM_ORDERS 2 typedef enum { Plc_ORDER_BY_PLACE = 0, Plc_ORDER_BY_NUM_CTRS = 1, } Plc_Order_t; - #define Plc_ORDER_DEFAULT Plc_ORDER_BY_NUM_CTRS /*****************************************************************************/ diff --git a/swad_preference.c b/swad_preference.c index 08127b2e..a382568e 100644 --- a/swad_preference.c +++ b/swad_preference.c @@ -352,10 +352,11 @@ Txt_Language_t Pre_GetParamLanguage (void) { extern const unsigned Txt_Current_CGI_SWAD_Language; - return (Txt_Language_t) Par_GetParToUnsigned ("Lan", - 1, - Txt_NUM_LANGUAGES, - Txt_Current_CGI_SWAD_Language); + return (Txt_Language_t) + Par_GetParToUnsignedLong ("Lan", + 1, + Txt_NUM_LANGUAGES, + (unsigned long) Txt_Current_CGI_SWAD_Language); } /*****************************************************************************/ @@ -499,8 +500,8 @@ static void Pre_UpdateSideColsOnUsrDataTable (void) unsigned Pre_GetParamSideCols (void) { - return Par_GetParToUnsigned ("SideCols", - 0, - Lay_SHOW_BOTH_COLUMNS, - Cfg_DEFAULT_COLUMNS); + return (unsigned) Par_GetParToUnsignedLong ("SideCols", + 0, + Lay_SHOW_BOTH_COLUMNS, + Cfg_DEFAULT_COLUMNS); } diff --git a/swad_privacy.c b/swad_privacy.c index 833c63a5..820a0681 100644 --- a/swad_privacy.c +++ b/swad_privacy.c @@ -228,10 +228,10 @@ Pri_Visibility_t Pri_GetVisibilityFromStr (const char *Str) Pri_Visibility_t Pri_GetParamVisibility (const char *ParamName) { return (Pri_Visibility_t) - Par_GetParToUnsigned (ParamName, - 0, - Pri_NUM_OPTIONS_PRIVACY - 1, - (unsigned) Pri_VISIBILITY_UNKNOWN); + Par_GetParToUnsignedLong (ParamName, + 0, + Pri_NUM_OPTIONS_PRIVACY - 1, + (unsigned long) Pri_VISIBILITY_UNKNOWN); } /*****************************************************************************/ diff --git a/swad_record.c b/swad_record.c index 1bf12f34..9dec99d3 100644 --- a/swad_record.c +++ b/swad_record.c @@ -438,17 +438,18 @@ void Rec_ReceiveFormField (void) Par_GetParToText ("FieldName",Gbl.CurrentCrs.Records.Field.Name,Rec_MAX_LENGTH_NAME_FIELD); /* Get the number of lines */ - Gbl.CurrentCrs.Records.Field.NumLines = Par_GetParToUnsigned ("NumLines", - Rec_MIN_LINES_IN_EDITION_FIELD, - Rec_MAX_LINES_IN_EDITION_FIELD, - Rec_DEF_LINES_IN_EDITION_FIELD); + Gbl.CurrentCrs.Records.Field.NumLines = (unsigned) + Par_GetParToUnsignedLong ("NumLines", + Rec_MIN_LINES_IN_EDITION_FIELD, + Rec_MAX_LINES_IN_EDITION_FIELD, + Rec_DEF_LINES_IN_EDITION_FIELD); /* Get the field visibility by students */ Gbl.CurrentCrs.Records.Field.Visibility = (Rec_VisibilityRecordFields_t) - Par_GetParToUnsigned ("Visibility", - 0, - Rec_NUM_TYPES_VISIBILITY - 1, - Rec_VISIBILITY_DEFAULT); + Par_GetParToUnsignedLong ("Visibility", + 0, + Rec_NUM_TYPES_VISIBILITY - 1, + (unsigned long) Rec_VISIBILITY_DEFAULT); if (Gbl.CurrentCrs.Records.Field.Name[0]) // If there's a name { @@ -823,10 +824,11 @@ void Rec_ChangeLinesField (void) Lay_ShowErrorAndExit ("Code of field is missing."); /* Get the new number of lines */ - NewNumLines = Par_GetParToUnsigned ("NumLines", - Rec_MIN_LINES_IN_EDITION_FIELD, - Rec_MAX_LINES_IN_EDITION_FIELD, - Rec_DEF_LINES_IN_EDITION_FIELD); + NewNumLines = (unsigned) + Par_GetParToUnsignedLong ("NumLines", + Rec_MIN_LINES_IN_EDITION_FIELD, + Rec_MAX_LINES_IN_EDITION_FIELD, + Rec_DEF_LINES_IN_EDITION_FIELD); /* Get from the database the number of lines of the field */ Rec_GetFieldByCod (Gbl.CurrentCrs.Records.Field.FieldCod,Gbl.CurrentCrs.Records.Field.Name,&Gbl.CurrentCrs.Records.Field.NumLines,&Gbl.CurrentCrs.Records.Field.Visibility); @@ -875,10 +877,10 @@ void Rec_ChangeVisibilityField (void) /* Get the new visibility of the field */ NewVisibility = (Rec_VisibilityRecordFields_t) - Par_GetParToUnsigned ("Visibility", - 0, - Rec_NUM_TYPES_VISIBILITY - 1, - Rec_VISIBILITY_DEFAULT); + Par_GetParToUnsignedLong ("Visibility", + 0, + Rec_NUM_TYPES_VISIBILITY - 1, + (unsigned long) Rec_VISIBILITY_DEFAULT); /* Get from the database the visibility of the field */ Rec_GetFieldByCod (Gbl.CurrentCrs.Records.Field.FieldCod,Gbl.CurrentCrs.Records.Field.Name,&Gbl.CurrentCrs.Records.Field.NumLines,&Gbl.CurrentCrs.Records.Field.Visibility); @@ -1434,10 +1436,11 @@ static void Rec_ShowLinkToPrintPreviewOfRecords (void) static void Rec_GetParamRecordsPerPage (void) { - Gbl.Usrs.Listing.RecsPerPag = Par_GetParToUnsigned ("RecsPerPag", - Rec_MIN_RECORDS_PER_PAGE, - Rec_MAX_RECORDS_PER_PAGE, - Rec_DEF_RECORDS_PER_PAGE); + Gbl.Usrs.Listing.RecsPerPag = (unsigned) + Par_GetParToUnsignedLong ("RecsPerPag", + Rec_MIN_RECORDS_PER_PAGE, + Rec_MAX_RECORDS_PER_PAGE, + Rec_DEF_RECORDS_PER_PAGE); } /*****************************************************************************/ @@ -3517,10 +3520,11 @@ Rol_Role_t Rec_GetRoleFromRecordForm (void) bool RoleOK = false; /***** Get role as a parameter from form *****/ - Role = (Rol_Role_t) Par_GetParToUnsigned ("Role", - 0, - Rol_NUM_ROLES - 1, - (unsigned) Rol_UNKNOWN); + Role = (Rol_Role_t) + Par_GetParToUnsignedLong ("Role", + 0, + Rol_NUM_ROLES - 1, + (unsigned long) Rol_UNKNOWN); /***** Check if I can register a user with the received role in current course *****/ @@ -3601,10 +3605,11 @@ void Rec_GetUsrNameFromRecordForm (struct UsrData *UsrDat) static void Rec_GetUsrExtraDataFromRecordForm (struct UsrData *UsrDat) { /***** Get sex from form *****/ - UsrDat->Sex = (Usr_Sex_t) Par_GetParToUnsigned ("Sex", - (unsigned) Usr_SEX_FEMALE, - (unsigned) Usr_SEX_MALE, - (unsigned) Usr_SEX_UNKNOWN); + UsrDat->Sex = (Usr_Sex_t) + Par_GetParToUnsignedLong ("Sex", + (unsigned long) Usr_SEX_FEMALE, + (unsigned long) Usr_SEX_MALE, + (unsigned long) Usr_SEX_UNKNOWN); /***** Get country code *****/ UsrDat->CtyCod = Par_GetParToLong ("OthCtyCod"); diff --git a/swad_role.c b/swad_role.c index 87d034f3..78832a53 100644 --- a/swad_role.c +++ b/swad_role.c @@ -319,10 +319,11 @@ void Rol_ChangeMyRole (void) Rol_Role_t NewRole; /***** Get parameter with the new logged role ******/ - NewRole = (Rol_Role_t) Par_GetParToUnsigned ("MyRole", - 0, - Rol_NUM_ROLES - 1, - (unsigned) Rol_UNKNOWN); + NewRole = (Rol_Role_t) + Par_GetParToUnsignedLong ("MyRole", + 0, + Rol_NUM_ROLES - 1, + (unsigned long) Rol_UNKNOWN); if (NewRole != Rol_UNKNOWN) { /* Check if new role is allowed for me */ @@ -403,10 +404,11 @@ unsigned Rol_GetSelectedRoles (void) unsigned Roles; /***** Try to get param "Roles" with multiple roles *****/ - Roles = Par_GetParToUnsigned ("Roles", - 0, // 000...000 - (1 << Rol_NUM_ROLES) - 1, // 111...111 - 0); // 000...000 + Roles = (unsigned) + Par_GetParToUnsignedLong ("Roles", + 0, // 000...000 + (1 << Rol_NUM_ROLES) - 1, // 111...111 + 0); // 000...000 /***** Try to get multiple param "Role" *****/ Par_GetParMultiToText ("Role",StrRoles,Rol_NUM_ROLES * (10 + 1)); diff --git a/swad_scope.c b/swad_scope.c index 69913765..50660c75 100644 --- a/swad_scope.c +++ b/swad_scope.c @@ -193,10 +193,10 @@ void Sco_GetScope (const char *ParamName) { /***** Get parameter with scope *****/ Gbl.Scope.Current = (Sco_Scope_t) - Par_GetParToUnsigned (ParamName, - 0, - Sco_NUM_SCOPES - 1, - (Sco_Scope_t) Sco_SCOPE_UNK); + Par_GetParToUnsignedLong (ParamName, + 0, + Sco_NUM_SCOPES - 1, + (unsigned long) Sco_SCOPE_UNK); /***** Adjust scope avoiding impossible or forbidden scopes *****/ Sco_AdjustScope (); diff --git a/swad_search.c b/swad_search.c index a27cbd9e..62b2355a 100644 --- a/swad_search.c +++ b/swad_search.c @@ -418,10 +418,10 @@ void Sch_GetParamWhatToSearch (void) /***** Get what to search from form *****/ WhatToSearch = (Sch_WhatToSearch_t) - Par_GetParToUnsigned ("WhatToSearch", - 0, - Sch_NUM_WHAT_TO_SEARCH - 1, - (unsigned) Sch_SEARCH_UNKNOWN); + Par_GetParToUnsignedLong ("WhatToSearch", + 0, + Sch_NUM_WHAT_TO_SEARCH - 1, + (unsigned long) Sch_SEARCH_UNKNOWN); // If parameter WhatToSearch is not present, use parameter from session if (WhatToSearch != Sch_SEARCH_UNKNOWN) diff --git a/swad_statistic.c b/swad_statistic.c index 76b0c0b5..8b760553 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -403,11 +403,18 @@ void Sta_AskShowCrsHits (void) extern const char *Txt_No_teachers_or_students_found; static unsigned long RowsPerPage[] = { - 10,20,30,40,50, - 100,500, - 1000,5000, - 10000,50000, - 100000 + Sta_MIN_ROWS_PER_PAGE * 1, + Sta_MIN_ROWS_PER_PAGE * 2, + Sta_MIN_ROWS_PER_PAGE * 3, + Sta_MIN_ROWS_PER_PAGE * 4, + Sta_MIN_ROWS_PER_PAGE * 5, + Sta_MIN_ROWS_PER_PAGE * 10, + Sta_MIN_ROWS_PER_PAGE * 50, + Sta_MIN_ROWS_PER_PAGE * 100, + Sta_MIN_ROWS_PER_PAGE * 500, + Sta_MIN_ROWS_PER_PAGE * 1000, + Sta_MIN_ROWS_PER_PAGE * 5000, + Sta_MAX_ROWS_PER_PAGE, }; #define NUM_OPTIONS_ROWS_PER_PAGE (sizeof (RowsPerPage) / sizeof (RowsPerPage[0])) unsigned NumTotalUsrs; @@ -484,7 +491,7 @@ void Sta_AskShowCrsHits (void) if ((Gbl.Stat.ClicksGroupedBy < Sta_CLICKS_CRS_PER_USR || Gbl.Stat.ClicksGroupedBy > Sta_CLICKS_CRS_PER_ACTION) && Gbl.Stat.ClicksGroupedBy != Sta_CLICKS_CRS_DETAILED_LIST) - Gbl.Stat.ClicksGroupedBy = Sta_CLICKS_CRS_PER_USR; + Gbl.Stat.ClicksGroupedBy = Sta_CLICKS_GROUPED_BY_DEFAULT; fprintf (Gbl.F.Out,"= Sta_NUM_CLICKS_GROUPED_BY) - Lay_ShowErrorAndExit ("Type of grouping is missing."); - Gbl.Stat.ClicksGroupedBy = (Sta_ClicksGroupedBy_t) UnsignedNum; - } + Gbl.Stat.ClicksGroupedBy = (Sta_ClicksGroupedBy_t) + Par_GetParToUnsignedLong ("GroupedBy", + 0, + Sta_NUM_CLICKS_GROUPED_BY - 1, + (unsigned long) Sta_CLICKS_GROUPED_BY_DEFAULT); /***** Get the type of count of clicks *****/ if (Gbl.Stat.ClicksGroupedBy != Sta_CLICKS_CRS_DETAILED_LIST) - { - Par_GetParToText ("CountType",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1) - Lay_ShowErrorAndExit ("Type of count is missing."); - if (UnsignedNum >= Sta_NUM_COUNT_TYPES) - Lay_ShowErrorAndExit ("Type of count is missing."); - Gbl.Stat.CountType = (Sta_CountType_t) UnsignedNum; - } + Gbl.Stat.CountType = (Sta_CountType_t) + Par_GetParToUnsignedLong ("CountType", + 0, + Sta_NUM_COUNT_TYPES - 1, + (unsigned long) Sta_COUNT_TYPE_DEFAULT); /***** Get action *****/ - Par_GetParToText ("StatAct",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1) - Lay_ShowErrorAndExit ("Action is missing."); - if (UnsignedNum >= Act_NUM_ACTIONS) - Lay_ShowErrorAndExit ("Action is missing."); - Gbl.Stat.NumAction = (Act_Action_t) UnsignedNum; + Gbl.Stat.NumAction = (Act_Action_t) + Par_GetParToUnsignedLong ("StatAct", + 0, + Act_NUM_ACTIONS - 1, + (unsigned long) Sta_NUM_ACTION_DEFAULT); switch (GlobalOrCourse) { case Sta_SHOW_GLOBAL_ACCESSES: /***** Get the type of user of clicks *****/ - Par_GetParToText ("Role",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1) - Lay_ShowErrorAndExit ("Type of users is missing."); - if (UnsignedNum >= Sta_NUM_ROLES_STAT) - Lay_ShowErrorAndExit ("Type of users is missing."); - Gbl.Stat.Role = (Sta_Role_t) UnsignedNum; + Gbl.Stat.Role = (Sta_Role_t) + Par_GetParToUnsignedLong ("Role", + 0, + Sta_NUM_ROLES_STAT - 1, + (unsigned long) Sta_ROLE_DEFAULT); /***** Get users range for access statistics *****/ Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS | @@ -929,19 +928,22 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse) if (Gbl.Stat.ClicksGroupedBy == Sta_CLICKS_CRS_DETAILED_LIST) { /****** Get the number of the first row to show ******/ - Par_GetParToText ("FirstRow",UnsignedStr,10); - if (sscanf (UnsignedStr,"%lu",&Gbl.Stat.FirstRow) != 1) - Lay_ShowErrorAndExit ("Number of start row is missing."); + Gbl.Stat.FirstRow = Par_GetParToUnsignedLong ("FirstRow", + 1, + ULONG_MAX, + 0); /****** Get the number of the last row to show ******/ - Par_GetParToText ("LastRow",UnsignedStr,10); - if (sscanf (UnsignedStr,"%lu",&Gbl.Stat.LastRow) != 1) - Lay_ShowErrorAndExit ("Number of end row is missing."); + Gbl.Stat.LastRow = Par_GetParToUnsignedLong ("LastRow", + 1, + ULONG_MAX, + 0); /****** Get the number of rows per page ******/ - Par_GetParToText ("RowsPage",UnsignedStr,10); - if (sscanf (UnsignedStr,"%lu",&Gbl.Stat.RowsPerPage) != 1) - Lay_ShowErrorAndExit ("Number of rows per page is missing."); + Gbl.Stat.RowsPerPage = Par_GetParToUnsignedLong ("RowsPage", + Sta_MIN_ROWS_PER_PAGE, + Sta_MAX_ROWS_PER_PAGE, + Sta_DEF_ROWS_PER_PAGE); } /***** Show form again *****/ @@ -1592,9 +1594,9 @@ static void Sta_ShowDetailedAccessesList (unsigned long NumRows,MYSQL_RES *mysql Act_FormStartAnchor (ActSeeAccCrs,"stat_results"); Sta_WriteParamsDatesSeeAccesses (); Par_PutHiddenParamUnsigned ("GroupedBy",(unsigned) Sta_CLICKS_CRS_DETAILED_LIST); - Par_PutHiddenParamUnsigned ("StatAct",(unsigned) Gbl.Stat.NumAction); - Par_PutHiddenParamLong ("FirstRow",FirstRow-Gbl.Stat.RowsPerPage); - Par_PutHiddenParamLong ("LastRow",FirstRow-1); + Par_PutHiddenParamUnsigned ("StatAct" ,(unsigned) Gbl.Stat.NumAction); + Par_PutHiddenParamLong ("FirstRow",FirstRow - Gbl.Stat.RowsPerPage); + Par_PutHiddenParamLong ("LastRow" ,FirstRow - 1); Par_PutHiddenParamLong ("RowsPage",Gbl.Stat.RowsPerPage); Usr_PutHiddenParUsrCodAll (ActSeeAccCrs,Gbl.Usrs.Select.All); } @@ -2100,7 +2102,7 @@ static void Sta_ShowDistrAccessesPerDaysAndHour (unsigned long NumRows,MYSQL_RES Sta_WriteParamsDatesSeeAccesses (); Par_PutHiddenParamUnsigned ("GroupedBy",(unsigned) Gbl.Stat.ClicksGroupedBy); Par_PutHiddenParamUnsigned ("CountType",(unsigned) Gbl.Stat.CountType); - Par_PutHiddenParamUnsigned ("StatAct",(unsigned) Gbl.Stat.NumAction); + Par_PutHiddenParamUnsigned ("StatAct" ,(unsigned) Gbl.Stat.NumAction); if (Gbl.Action.Act == ActSeeAccCrs) Usr_PutHiddenParUsrCodAll (ActSeeAccCrs,Gbl.Usrs.Select.All); else // Gbl.Action.Act == ActSeeAccGbl @@ -2335,19 +2337,11 @@ static void Sta_ShowDistrAccessesPerDaysAndHour (unsigned long NumRows,MYSQL_RES static Sta_ColorType_t Sta_GetStatColorType (void) { - char UnsignedStr[10 + 1]; - unsigned UnsignedNum; - - Par_GetParToText ("ColorType",UnsignedStr,10); - if (UnsignedStr[0]) - { - if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1) - Lay_ShowErrorAndExit ("Type of color is missing."); - if (UnsignedNum >= Sta_NUM_COLOR_TYPES) - Lay_ShowErrorAndExit ("Type of color is missing."); - return (Sta_ColorType_t) UnsignedNum; - } - return (Sta_ColorType_t) 0; + return (Sta_ColorType_t) + Par_GetParToUnsignedLong ("ColorType", + 0, + Sta_NUM_COLOR_TYPES - 1, + (unsigned long) Sta_COLOR_TYPE_DEF); } /*****************************************************************************/ @@ -3976,16 +3970,13 @@ void Sta_ShowFigures (void) Sta_GetAndShowNumUsrsPerSideColumns, // Sta_SIDE_COLUMNS Sta_GetAndShowNumUsrsPerPrivacy, // Sta_PRIVACY }; - char UnsignedStr[10 + 1]; - unsigned UnsignedNum; /***** Get the type of figure ******/ - Par_GetParToText ("FigureType",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1) - Lay_ShowErrorAndExit ("Type of stat is missing."); - if (UnsignedNum >= Sta_NUM_FIGURES) - Lay_ShowErrorAndExit ("Type of stat is missing."); - Gbl.Stat.FigureType = (Sta_FigureType_t) UnsignedNum; + Gbl.Stat.FigureType = (Sta_FigureType_t) + Par_GetParToUnsignedLong ("FigureType", + 0, + Sta_NUM_FIGURES - 1, + (unsigned long) Sta_FIGURE_TYPE_DEF); /***** Show again the form to see use of the platform *****/ Sta_ReqShowFigures (); @@ -5079,7 +5070,7 @@ static void Sta_GetAndShowInss (const char *Query,const char *TxtFigure) /* Draw the classphoto/list */ switch (Gbl.Usrs.Me.ListType) { - case Usr_CLASS_PHOTO: + case Usr_LIST_AS_CLASS_PHOTO: /***** Draw institutions as a class photo *****/ for (NumIns = 0; NumIns < NumInss;) @@ -5113,7 +5104,7 @@ static void Sta_GetAndShowInss (const char *Query,const char *TxtFigure) fprintf (Gbl.F.Out,""); break; - case Usr_LIST: + case Usr_LIST_AS_LISTING: /***** Draw institutions as a list *****/ fprintf (Gbl.F.Out,"