diff --git a/swad_center.c b/swad_center.c index 80fcc8da..3f78bbcb 100644 --- a/swad_center.c +++ b/swad_center.c @@ -82,10 +82,6 @@ static void Ctr_GetDataOfCenterFromRow (struct Ctr_Center *Ctr,MYSQL_ROW row); static void Ctr_ListCentersForEdition (const struct Plc_Places *Places); static bool Ctr_CheckIfICanEditACenter (struct Ctr_Center *Ctr); -static Ctr_StatusTxt_t Ctr_GetStatusTxtFromStatusBits (Ctr_Status_t Status); -static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt); - -static void Ctr_PutParamOtherCtrCod (void *CtrCod); static void Ctr_ShowAlertAndButtonToGoToCtr (void); static void Ctr_PutParamGoToCtr (void *CtrCod); @@ -93,7 +89,7 @@ static void Ctr_PutParamGoToCtr (void *CtrCod); static void Ctr_PutFormToCreateCenter (const struct Plc_Places *Places); static void Ctr_PutHeadCentersForSeeing (bool OrderSelectable); static void Ctr_PutHeadCentersForEdition (void); -static void Ctr_ReceiveFormRequestOrCreateCtr (Ctr_Status_t Status); +static void Ctr_ReceiveFormRequestOrCreateCtr (Hie_Status_t Status); static unsigned Ctr_GetNumCtrsInCty (long CtyCod); @@ -329,18 +325,17 @@ static void Ctr_PutIconToEditCenters (void) static void Ctr_ListOneCenterForSeeing (struct Ctr_Center *Ctr,unsigned NumCtr) { - extern const char *Txt_CENTER_STATUS[Ctr_NUM_STATUS_TXT]; + extern const char *Txt_CENTER_STATUS[Hie_NUM_STATUS_TXT]; struct Plc_Place Plc; const char *TxtClassNormal; const char *TxtClassStrong; const char *BgColor; - Ctr_StatusTxt_t StatusTxt; /***** Get data of place of this center *****/ Plc.PlcCod = Ctr->PlcCod; Plc_GetDataOfPlaceByCod (&Plc); - if (Ctr->Status & Ctr_STATUS_BIT_PENDING) + if (Ctr->Status & Hie_STATUS_BIT_PENDING) { TxtClassNormal = "DAT_LIGHT"; TxtClassStrong = "BT_LINK LT DAT_LIGHT"; @@ -395,11 +390,7 @@ static void Ctr_ListOneCenterForSeeing (struct Ctr_Center *Ctr,unsigned NumCtr) HTM_TD_End (); /***** Center status *****/ - StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status); - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); - if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_CENTER_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCell (Ctr->Status,TxtClassNormal,BgColor,Txt_CENTER_STATUS); HTM_TR_End (); @@ -604,7 +595,7 @@ bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr) /***** Clear data *****/ Ctr->InsCod = -1L; Ctr->PlcCod = -1L; - Ctr->Status = (Ctr_Status_t) 0; + Ctr->Status = (Hie_Status_t) 0; Ctr->RequesterUsrCod = -1L; Ctr->ShrtName[0] = '\0'; Ctr->FullName[0] = '\0'; @@ -750,7 +741,7 @@ void Ctr_WriteSelectorOfCenter (void) static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) { extern const char *Txt_Another_place; - extern const char *Txt_CENTER_STATUS[Ctr_NUM_STATUS_TXT]; + extern const char *Txt_CENTER_STATUS[Hie_NUM_STATUS_TXT]; unsigned NumCtr; struct Ctr_Center *Ctr; unsigned NumPlc; @@ -760,8 +751,6 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) unsigned NumDegs; unsigned NumUsrsCtr; unsigned NumUsrsInCrssOfCtr; - Ctr_StatusTxt_t StatusTxt; - unsigned StatusUnsigned; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -798,7 +787,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) Ico_PutIconRemovalNotAllowed (); else // I can remove center Ico_PutContextualIconToRemove (ActRemCtr,NULL, - Ctr_PutParamOtherCtrCod,&Ctr->CtrCod); + Hie_PutParamOtherHieCod,&Ctr->CtrCod); HTM_TD_End (); /* Center code */ @@ -816,7 +805,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) if (ICanEdit) { Frm_BeginForm (ActChgCtrPlc); - Ctr_PutParamOtherCtrCod (&Ctr->CtrCod); + Hie_PutParamOtherHieCod (&Ctr->CtrCod); HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, "name=\"PlcCod\" class=\"PLC_SEL\""); HTM_OPTION (HTM_Type_STRING,"0", @@ -844,7 +833,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) if (ICanEdit) { Frm_BeginForm (ActRenCtrSho); - Ctr_PutParamOtherCtrCod (&Ctr->CtrCod); + Hie_PutParamOtherHieCod (&Ctr->CtrCod); HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Ctr->ShrtName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_SHORT_NAME\""); @@ -859,7 +848,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) if (ICanEdit) { Frm_BeginForm (ActRenCtrFul); - Ctr_PutParamOtherCtrCod (&Ctr->CtrCod); + Hie_PutParamOtherHieCod (&Ctr->CtrCod); HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Ctr->FullName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_FULL_NAME\""); @@ -874,7 +863,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) if (ICanEdit) { Frm_BeginForm (ActChgCtrWWW); - Ctr_PutParamOtherCtrCod (&Ctr->CtrCod); + Hie_PutParamOtherHieCod (&Ctr->CtrCod); HTM_INPUT_URL ("WWW",Ctr->WWW,HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_WWW_NARROW\" required=\"required\""); Frm_EndForm (); @@ -916,30 +905,9 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) HTM_TD_End (); /* Center status */ - StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status); - HTM_TD_Begin ("class=\"DAT LM\""); - if (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM && - StatusTxt == Ctr_STATUS_PENDING) - { - Frm_BeginForm (ActChgCtrSta); - Ctr_PutParamOtherCtrCod (&Ctr->CtrCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"Status\" class=\"INPUT_STATUS\""); - - StatusUnsigned = (unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_PENDING); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, - "%s",Txt_CENTER_STATUS[Ctr_STATUS_PENDING]); - - StatusUnsigned = (unsigned) Ctr_GetStatusBitsFromStatusTxt (Ctr_STATUS_ACTIVE); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, - "%s",Txt_CENTER_STATUS[Ctr_STATUS_ACTIVE]); - - HTM_SELECT_End (); - Frm_EndForm (); - } - else if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_CENTER_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCellEditable (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM, + Ctr->Status,ActChgCtrSta,Ctr->CtrCod, + Txt_CENTER_STATUS); HTM_TR_End (); } @@ -958,52 +926,10 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) static bool Ctr_CheckIfICanEditACenter (struct Ctr_Center *Ctr) { return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM || // I am an institution administrator or higher - ((Ctr->Status & Ctr_STATUS_BIT_PENDING) != 0 && // Center is not yet activated + ((Ctr->Status & Hie_STATUS_BIT_PENDING) != 0 && // Center is not yet activated Gbl.Usrs.Me.UsrDat.UsrCod == Ctr->RequesterUsrCod)); // I am the requester } -/*****************************************************************************/ -/******************* Set StatusTxt depending on status bits ******************/ -/*****************************************************************************/ -// Ctr_STATUS_UNKNOWN = 0 // Other -// Ctr_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Ctr_STATUS_PENDING = 2 // 01 (Status == Ctr_STATUS_BIT_PENDING) -// Ctr_STATUS_REMOVED = 3 // 1- (Status & Ctr_STATUS_BIT_REMOVED) - -static Ctr_StatusTxt_t Ctr_GetStatusTxtFromStatusBits (Ctr_Status_t Status) - { - if (Status == 0) - return Ctr_STATUS_ACTIVE; - if (Status == Ctr_STATUS_BIT_PENDING) - return Ctr_STATUS_PENDING; - if (Status & Ctr_STATUS_BIT_REMOVED) - return Ctr_STATUS_REMOVED; - return Ctr_STATUS_UNKNOWN; - } - -/*****************************************************************************/ -/******************* Set status bits depending on StatusTxt ******************/ -/*****************************************************************************/ -// Ctr_STATUS_UNKNOWN = 0 // Other -// Ctr_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Ctr_STATUS_PENDING = 2 // 01 (Status == Ctr_STATUS_BIT_PENDING) -// Ctr_STATUS_REMOVED = 3 // 1- (Status & Ctr_STATUS_BIT_REMOVED) - -static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt) - { - switch (StatusTxt) - { - case Ctr_STATUS_UNKNOWN: - case Ctr_STATUS_ACTIVE: - return (Ctr_Status_t) 0; - case Ctr_STATUS_PENDING: - return Ctr_STATUS_BIT_PENDING; - case Ctr_STATUS_REMOVED: - return Ctr_STATUS_BIT_REMOVED; - } - return (Ctr_Status_t) 0; - } - /*****************************************************************************/ /******************** Write parameter with code of center ********************/ /*****************************************************************************/ @@ -1013,16 +939,6 @@ void Ctr_PutParamCtrCod (long CtrCod) Par_PutHiddenParamLong (NULL,"ctr",CtrCod); } -/*****************************************************************************/ -/***************** Write parameter with code of other center *****************/ -/*****************************************************************************/ - -static void Ctr_PutParamOtherCtrCod (void *CtrCod) - { - if (CtrCod) - Par_PutHiddenParamLong (NULL,"OthCtrCod",*((long *) CtrCod)); - } - /*****************************************************************************/ /****************** Get parameter with code of other center ******************/ /*****************************************************************************/ @@ -1052,7 +968,7 @@ void Ctr_RemoveCenter (void) Ctr_EditingCenterConstructor (); /***** Get center code *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); /***** Get data of the center from database *****/ Ctr_GetDataOfCenterByCod (Ctr_EditingCtr); @@ -1124,7 +1040,7 @@ void Ctr_ChangeCtrPlc (void) Ctr_EditingCenterConstructor (); /***** Get center code *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); /***** Get parameter with place code *****/ NewPlcCod = Plc_GetParamPlcCod (); @@ -1152,7 +1068,7 @@ void Ctr_RenameCenterShort (void) Ctr_EditingCenterConstructor (); /***** Rename center *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); Ctr_RenameCenter (Ctr_EditingCtr,Cns_SHRT_NAME); } @@ -1162,7 +1078,7 @@ void Ctr_RenameCenterFull (void) Ctr_EditingCenterConstructor (); /***** Rename center *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); Ctr_RenameCenter (Ctr_EditingCtr,Cns_FULL_NAME); } @@ -1252,7 +1168,7 @@ void Ctr_ChangeCtrWWW (void) Ctr_EditingCenterConstructor (); /***** Get the code of the center *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); /***** Get the new WWW for the center *****/ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -1284,32 +1200,24 @@ void Ctr_ChangeCtrWWW (void) void Ctr_ChangeCtrStatus (void) { extern const char *Txt_The_status_of_the_center_X_has_changed; - Ctr_Status_t NewStatus; - Ctr_StatusTxt_t NewStatusTxt; + Hie_Status_t Status; /***** Center constructor *****/ Ctr_EditingCenterConstructor (); - /***** Get center code *****/ - Ctr_EditingCtr->CtrCod = Ctr_GetAndCheckParamOtherCtrCod (1); + /***** Get parameters from form *****/ + /* Get center code */ + Ctr_EditingCtr->CtrCod = Hie_GetAndCheckParamOtherHieCod (1); - /***** Get parameter with status *****/ - NewStatus = (Ctr_Status_t) - Par_GetParToUnsignedLong ("Status", - 0, - (unsigned long) Ctr_MAX_STATUS, - (unsigned long) Ctr_WRONG_STATUS); - if (NewStatus == Ctr_WRONG_STATUS) - Err_WrongStatusExit (); - NewStatusTxt = Ctr_GetStatusTxtFromStatusBits (NewStatus); - NewStatus = Ctr_GetStatusBitsFromStatusTxt (NewStatusTxt); // New status + /* Get parameter with status */ + Status = Hie_GetParamStatus (); // New status /***** Get data of center *****/ Ctr_GetDataOfCenterByCod (Ctr_EditingCtr); - /***** Update status in table of centers *****/ - Ctr_DB_UpdateCtrStatus (Ctr_EditingCtr->CtrCod,NewStatus); - Ctr_EditingCtr->Status = NewStatus; + /***** Update status *****/ + Ctr_DB_UpdateCtrStatus (Ctr_EditingCtr->CtrCod,Status); + Ctr_EditingCtr->Status = Status; /***** Write message to show the change made and put button to go to center changed *****/ @@ -1581,7 +1489,7 @@ void Ctr_ReceiveFormReqCtr (void) Ctr_EditingCenterConstructor (); /***** Receive form to request a new center *****/ - Ctr_ReceiveFormRequestOrCreateCtr ((Ctr_Status_t) Ctr_STATUS_BIT_PENDING); + Ctr_ReceiveFormRequestOrCreateCtr ((Hie_Status_t) Hie_STATUS_BIT_PENDING); } /*****************************************************************************/ @@ -1594,14 +1502,14 @@ void Ctr_ReceiveFormNewCtr (void) Ctr_EditingCenterConstructor (); /***** Receive form to create a new center *****/ - Ctr_ReceiveFormRequestOrCreateCtr ((Ctr_Status_t) 0); + Ctr_ReceiveFormRequestOrCreateCtr ((Hie_Status_t) 0); } /*****************************************************************************/ /************* Receive form to request or create a new center ****************/ /*****************************************************************************/ -static void Ctr_ReceiveFormRequestOrCreateCtr (Ctr_Status_t Status) +static void Ctr_ReceiveFormRequestOrCreateCtr (Hie_Status_t Status) { extern const char *Txt_The_center_X_already_exists; extern const char *Txt_Created_new_center_X; @@ -1962,7 +1870,7 @@ static void Ctr_EditingCenterConstructor (void) Ctr_EditingCtr->CtrCod = -1L; Ctr_EditingCtr->InsCod = -1L; Ctr_EditingCtr->PlcCod = -1L; - Ctr_EditingCtr->Status = (Ctr_Status_t) 0; + Ctr_EditingCtr->Status = (Hie_Status_t) 0; Ctr_EditingCtr->RequesterUsrCod = -1L; Ctr_EditingCtr->ShrtName[0] = '\0'; Ctr_EditingCtr->FullName[0] = '\0'; diff --git a/swad_center.h b/swad_center.h index f79b0575..bf380b6d 100644 --- a/swad_center.h +++ b/swad_center.h @@ -39,25 +39,6 @@ /************************** Public types and constants ***********************/ /*****************************************************************************/ -typedef enum - { - Ctr_STATUS_BIT_PENDING = (1 << 0), // Center is requested, but not yet activated - Ctr_STATUS_BIT_REMOVED = (1 << 1), // Center has been removed - } Ctr_Status_Bits_t; - -typedef unsigned Ctr_Status_t; -#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 - { - Ctr_STATUS_UNKNOWN = 0, // Other - Ctr_STATUS_ACTIVE = 1, // 00 (Status == 0) - Ctr_STATUS_PENDING = 2, // 01 (Status == Ctr_STATUS_BIT_PENDING) - Ctr_STATUS_REMOVED = 3, // 1- (Status & Ctr_STATUS_BIT_REMOVED) - } Ctr_StatusTxt_t; - #define Ctr_MAX_CENTERS_PER_USR 10 // Used in list of my centers struct Ctr_Center @@ -65,7 +46,7 @@ struct Ctr_Center long CtrCod; // Center code long InsCod; // Institution code long PlcCod; // Place code - Ctr_Status_t Status; // Center status + Hie_Status_t Status; // Center status long RequesterUsrCod; // User code of the person who requested the creation of this center struct Map_Coordinates Coord; // Geographical coordinates char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; diff --git a/swad_center_database.c b/swad_center_database.c index 071796ef..50c7022d 100644 --- a/swad_center_database.c +++ b/swad_center_database.c @@ -34,6 +34,7 @@ #include "swad_error.h" #include "swad_global.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" #include "swad_search.h" /*****************************************************************************/ @@ -46,7 +47,7 @@ extern struct Globals Gbl; /***************************** Create a new center ***************************/ /*****************************************************************************/ -long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,Ctr_Status_t Status) +long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,Hie_Status_t Status) { return DB_QueryINSERTandReturnCode ("can not create a new center", @@ -187,7 +188,7 @@ unsigned Ctr_DB_GetCtrsWithPendingDegs (MYSQL_RES **mysql_res) " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " GROUP BY deg_degrees.CtrCod" " ORDER BY ctr_centers.ShortName", - (unsigned) Deg_STATUS_BIT_PENDING, + (unsigned) Hie_STATUS_BIT_PENDING, Gbl.Usrs.Me.UsrDat.UsrCod); case Rol_SYS_ADM: return (unsigned) @@ -200,7 +201,7 @@ unsigned Ctr_DB_GetCtrsWithPendingDegs (MYSQL_RES **mysql_res) " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " GROUP BY deg_degrees.CtrCod" " ORDER BY ctr_centers.ShortName", - (unsigned) Deg_STATUS_BIT_PENDING); + (unsigned) Hie_STATUS_BIT_PENDING); default: // Forbidden for other users Err_WrongRoleExit (); return 0; // Not reached @@ -594,7 +595,7 @@ void Ctr_DB_UpdateCtrCoordinate (long CtrCod, /******************** Update status in table of centers **********************/ /*****************************************************************************/ -void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus) +void Ctr_DB_UpdateCtrStatus (long CtrCod,Hie_Status_t NewStatus) { DB_QueryUPDATE ("can not update the status of a center", "UPDATE ctr_centers" diff --git a/swad_center_database.h b/swad_center_database.h index b7500824..0707b108 100644 --- a/swad_center_database.h +++ b/swad_center_database.h @@ -38,7 +38,7 @@ /****************************** Public prototypes ****************************/ /*****************************************************************************/ -long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,Ctr_Status_t Status); +long Ctr_DB_CreateCenter (const struct Ctr_Center *Ctr,Hie_Status_t Status); unsigned Ctr_DB_GetListOfCtrsInCurrentIns (MYSQL_RES **mysql_res); unsigned Ctr_DB_GetListOfCtrsFull (MYSQL_RES **mysql_res,long InsCod); @@ -74,7 +74,7 @@ void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); void Ctr_DB_UpdateCtrPhotoAttribution (long CtrCod,const char NewPhotoAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]); void Ctr_DB_UpdateCtrCoordinate (long CtrCod, const char *CoordField,double NewCoord); -void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus); +void Ctr_DB_UpdateCtrStatus (long CtrCod,Hie_Status_t NewStatus); bool Ctr_DB_CheckIfMapIsAvailableInIns (long InsCod); diff --git a/swad_changelog.h b/swad_changelog.h index 3dc661e3..b90b55dd 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,14 +602,15 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.55.2 (2021-11-10)" +#define Log_PLATFORM_VERSION "SWAD 21.56 (2021-11-10)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams - Version 21.55.2: Nov 10, 2021 Code refactoring in switch statements (until swad_button.c). (? lines) + Version 21.56: Nov 10, 2021 Code refactoring in hierarchy. (319618 lines) + Version 21.55.2: Nov 10, 2021 Code refactoring in switch statements (until swad_button.c). (319875 lines) Version 21.55.1: Nov 09, 2021 Removed unused comments. (319893 lines) Version 21.55: Nov 09, 2021 New module swad_template. Removed unused comments. (320885 lines) Version 21.54.8: Nov 09, 2021 Queries moved from API module to database modules. (322179 lines) diff --git a/swad_connected.c b/swad_connected.c index fdcad566..9584821a 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -550,6 +550,19 @@ static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Rol static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) { extern const char *Txt_View_record_for_this_course; + static const Act_Action_t NextAction[Rol_NUM_ROLES] = + { + [Rol_UNK ] = ActUnk, + [Rol_GST ] = ActUnk, + [Rol_USR ] = ActUnk, + [Rol_STD ] = ActSeeRecOneStd, + [Rol_NET ] = ActSeeRecOneTch, + [Rol_TCH ] = ActSeeRecOneTch, + [Rol_DEG_ADM] = ActUnk, + [Rol_CTR_ADM] = ActUnk, + [Rol_INS_ADM] = ActUnk, + [Rol_SYS_ADM] = ActUnk, + }; const char *ClassTxt; const char *ClassLink; long UsrCod; @@ -599,19 +612,9 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) // The form must be unique because // the list of connected users // is dynamically updated via AJAX - switch (Role) - { - case Rol_STD: - Frm_BeginFormUnique (ActSeeRecOneStd); - break; - case Rol_NET: - case Rol_TCH: - Frm_BeginFormUnique (ActSeeRecOneTch); - break; - default: - Err_WrongRoleExit (); - break; - } + if (NextAction[Role] == ActUnk) + Err_WrongRoleExit (); + Frm_BeginFormUnique (NextAction[Role]); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); HTM_DIV_Begin ("class=\"CON_NAME_NARROW\""); // Limited width @@ -647,6 +650,19 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t Role) { + static const Act_Action_t NextAction[Rol_NUM_ROLES] = + { + [Rol_UNK ] = ActUnk, + [Rol_GST ] = ActUnk, + [Rol_USR ] = ActUnk, + [Rol_STD ] = ActSeeRecOneStd, + [Rol_NET ] = ActSeeRecOneTch, + [Rol_TCH ] = ActSeeRecOneTch, + [Rol_DEG_ADM] = ActUnk, + [Rol_CTR_ADM] = ActUnk, + [Rol_INS_ADM] = ActUnk, + [Rol_SYS_ADM] = ActUnk, + }; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumUsrs = 0; // Initialized to avoid warning @@ -708,20 +724,12 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R ClassLink = "BT_LINK CON_NAME_WIDE CON_NO_CRS"; } HTM_TD_Begin ("class=\"%s COLOR%u\"",ClassTxt,Gbl.RowEvenOdd); + if (PutLinkToRecord) { - switch (Role) - { - case Rol_STD: - Frm_BeginForm (ActSeeRecOneStd); - break; - case Rol_NET: - case Rol_TCH: - Frm_BeginForm (ActSeeRecOneTch); - break; - default: - Err_WrongRoleExit (); - } + if (NextAction[Role] == ActUnk) + Err_WrongRoleExit (); + Frm_BeginForm (NextAction[Role]); Usr_PutParamUsrCodEncrypted (UsrDat.EnUsrCod); } @@ -735,6 +743,7 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R if (PutLinkToRecord) Frm_EndForm (); + HTM_TD_End (); /***** Write time from last access *****/ diff --git a/swad_country_database.c b/swad_country_database.c index 9176aa56..24ee0d86 100644 --- a/swad_country_database.c +++ b/swad_country_database.c @@ -34,6 +34,7 @@ #include "swad_error.h" #include "swad_global.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" #include "swad_search.h" /*****************************************************************************/ @@ -137,7 +138,7 @@ unsigned Cty_DB_GetCtysWithPendingInss (MYSQL_RES **mysql_res) " AND ins_instits.CtyCod=cty_countrs.CtyCod" " GROUP BY ins_instits.CtyCod" " ORDER BY cty_countrs.Name_%s", - (unsigned) Ins_STATUS_BIT_PENDING, + (unsigned) Hie_STATUS_BIT_PENDING, Lan_STR_LANG_ID[Gbl.Prefs.Language]); } diff --git a/swad_course.c b/swad_course.c index 722c6938..2d25fbb1 100644 --- a/swad_course.c +++ b/swad_course.c @@ -100,28 +100,21 @@ static void Crs_PutIconToViewCourses (void); static void Crs_ListCoursesForEdition (void); static void Crs_ListCoursesOfAYearForEdition (unsigned Year); static bool Crs_CheckIfICanEdit (struct Crs_Course *Crs); -static Crs_StatusTxt_t Crs_GetStatusTxtFromStatusBits (Crs_Status_t Status); -static Crs_Status_t Crs_GetStatusBitsFromStatusTxt (Crs_StatusTxt_t StatusTxt); static void Crs_PutFormToCreateCourse (void); static void Crs_PutHeadCoursesForSeeing (void); static void Crs_PutHeadCoursesForEdition (void); -static void Crs_ReceiveFormRequestOrCreateCrs (unsigned Status); +static void Crs_ReceiveFormRequestOrCreateCrs (Hie_Status_t Status); static void Crs_GetParamsNewCourse (struct Crs_Course *Crs); static void Crs_GetDataOfCourseFromRow (struct Crs_Course *Crs,MYSQL_ROW row); static void Crs_EmptyCourseCompletely (long CrsCod); -static void Crs_UpdateCrsStatus (struct Crs_Course *Crs,Crs_Status_t Status); - static void Crs_PutButtonToGoToCrs (void); static void Crs_PutButtonToRegisterInCrs (void); static void Crs_PutIconToSearchCourses (__attribute__((unused)) void *Args); -static void Crs_PutParamOtherCrsCod (void *CrsCod); -static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed); - static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnAccepted); static void Crs_EditingCourseConstructor (void); @@ -938,13 +931,12 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) extern const char *Txt_COURSE_With_users; extern const char *Txt_COURSE_Without_users; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; - extern const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT]; + extern const char *Txt_COURSE_STATUS[Hie_NUM_STATUS_TXT]; unsigned NumCrs; struct Crs_Course *Crs; const char *TxtClassNormal; const char *TxtClassStrong; const char *BgColor; - Crs_StatusTxt_t StatusTxt; bool ThisYearHasCourses = false; unsigned NumUsrs[Rol_NUM_ROLES]; @@ -957,7 +949,7 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) if (Crs->Year == Year) // The year of the course is this? { ThisYearHasCourses = true; - if (Crs->Status & Crs_STATUS_BIT_PENDING) + if (Crs->Status & Hie_STATUS_BIT_PENDING) { TxtClassNormal = "DAT_LIGHT"; TxtClassStrong = "BT_LINK LT DAT_LIGHT"; @@ -1025,11 +1017,7 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) HTM_TD_End (); /* Course status */ - StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); - if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCell (Crs->Status,TxtClassNormal,BgColor,Txt_COURSE_STATUS); HTM_TR_End (); } @@ -1151,15 +1139,13 @@ static void Crs_ListCoursesForEdition (void) static void Crs_ListCoursesOfAYearForEdition (unsigned Year) { extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; - extern const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT]; + extern const char *Txt_COURSE_STATUS[Hie_NUM_STATUS_TXT]; struct Crs_Course *Crs; unsigned YearAux; unsigned NumCrs; struct UsrData UsrDat; bool ICanEdit; unsigned NumUsrs[Rol_NUM_ROLES]; - Crs_StatusTxt_t StatusTxt; - unsigned StatusUnsigned; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -1191,7 +1177,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) Ico_PutIconRemovalNotAllowed (); else // Crs->NumUsrs == 0 && ICanEdit Ico_PutContextualIconToRemove (ActRemCrs,NULL, - Crs_PutParamOtherCrsCod,&Crs->CrsCod); + Hie_PutParamOtherHieCod,&Crs->CrsCod); HTM_TD_End (); /* Course code */ @@ -1204,7 +1190,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) if (ICanEdit) { Frm_BeginForm (ActChgInsCrsCod); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); + Hie_PutParamOtherHieCod (&Crs->CrsCod); HTM_INPUT_TEXT ("InsCrsCod",Crs_MAX_CHARS_INSTITUTIONAL_CRS_COD, Crs->InstitutionalCrsCod,HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_INS_CODE\""); @@ -1219,7 +1205,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) if (ICanEdit) { Frm_BeginForm (ActChgCrsYea); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); + Hie_PutParamOtherHieCod (&Crs->CrsCod); HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, "name=\"OthCrsYear\" class=\"HIE_SEL_NARROW\""); for (YearAux = 0; @@ -1242,7 +1228,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) if (ICanEdit) { Frm_BeginForm (ActRenCrsSho); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); + Hie_PutParamOtherHieCod (&Crs->CrsCod); HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Crs->ShrtName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_SHORT_NAME\""); @@ -1257,7 +1243,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) if (ICanEdit) { Frm_BeginForm (ActRenCrsFul); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); + Hie_PutParamOtherHieCod (&Crs->CrsCod); HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Crs->FullName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_FULL_NAME\""); @@ -1288,30 +1274,9 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) HTM_TD_End (); /* Course status */ - StatusTxt = Crs_GetStatusTxtFromStatusBits (Crs->Status); - HTM_TD_Begin ("class=\"DAT LM\""); - if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM && - StatusTxt == Crs_STATUS_PENDING) - { - Frm_BeginForm (ActChgCrsSta); - Crs_PutParamOtherCrsCod (&Crs->CrsCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"Status\" class=\"INPUT_STATUS\""); - - StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_PENDING); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, - "%s",Txt_COURSE_STATUS[Crs_STATUS_PENDING]); - - StatusUnsigned = (unsigned) Crs_GetStatusBitsFromStatusTxt (Crs_STATUS_ACTIVE); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, - "%s",Txt_COURSE_STATUS[Crs_STATUS_ACTIVE]); - - HTM_SELECT_End (); - Frm_EndForm (); - } - else if (StatusTxt != Crs_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_COURSE_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCellEditable (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM, + Crs->Status,ActChgCrsSta,Crs->CrsCod, + Txt_COURSE_STATUS); HTM_TR_End (); } @@ -1328,52 +1293,10 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) static bool Crs_CheckIfICanEdit (struct Crs_Course *Crs) { return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM || // I am a degree administrator or higher - ((Crs->Status & Crs_STATUS_BIT_PENDING) != 0 && // Course is not yet activated + ((Crs->Status & Hie_STATUS_BIT_PENDING) != 0 && // Course is not yet activated Gbl.Usrs.Me.UsrDat.UsrCod == Crs->RequesterUsrCod)); // I am the requester } -/*****************************************************************************/ -/******************* Set StatusTxt depending on status bits ******************/ -/*****************************************************************************/ -// Crs_STATUS_UNKNOWN = 0 // Other -// Crs_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Crs_STATUS_PENDING = 2 // 01 (Status == Crs_STATUS_BIT_PENDING) -// Crs_STATUS_REMOVED = 3 // 1- (Status & Crs_STATUS_BIT_REMOVED) - -static Crs_StatusTxt_t Crs_GetStatusTxtFromStatusBits (Crs_Status_t Status) - { - if (Status == 0) - return Crs_STATUS_ACTIVE; - if (Status == Crs_STATUS_BIT_PENDING) - return Crs_STATUS_PENDING; - if (Status & Crs_STATUS_BIT_REMOVED) - return Crs_STATUS_REMOVED; - return Crs_STATUS_UNKNOWN; - } - -/*****************************************************************************/ -/******************* Set status bits depending on StatusTxt ******************/ -/*****************************************************************************/ -// Crs_STATUS_UNKNOWN = 0 // Other -// Crs_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Crs_STATUS_PENDING = 2 // 01 (Status == Crs_STATUS_BIT_PENDING) -// Crs_STATUS_REMOVED = 3 // 1- (Status & Crs_STATUS_BIT_REMOVED) - -static Crs_Status_t Crs_GetStatusBitsFromStatusTxt (Crs_StatusTxt_t StatusTxt) - { - switch (StatusTxt) - { - case Crs_STATUS_UNKNOWN: - case Crs_STATUS_ACTIVE: - return (Crs_Status_t) 0; - case Crs_STATUS_PENDING: - return Crs_STATUS_BIT_PENDING; - case Crs_STATUS_REMOVED: - return Crs_STATUS_BIT_REMOVED; - } - return (Crs_Status_t) 0; - } - /*****************************************************************************/ /*********************** Put a form to create a new course *******************/ /*****************************************************************************/ @@ -1541,7 +1464,7 @@ void Crs_ReceiveFormReqCrs (void) Crs_EditingCourseConstructor (); /***** Receive form to request a new course *****/ - Crs_ReceiveFormRequestOrCreateCrs ((unsigned) Crs_STATUS_BIT_PENDING); + Crs_ReceiveFormRequestOrCreateCrs ((Hie_Status_t) Hie_STATUS_BIT_PENDING); } /*****************************************************************************/ @@ -1554,14 +1477,14 @@ void Crs_ReceiveFormNewCrs (void) Crs_EditingCourseConstructor (); /***** Receive form to create a new course *****/ - Crs_ReceiveFormRequestOrCreateCrs (0); + Crs_ReceiveFormRequestOrCreateCrs ((Hie_Status_t) 0); } /*****************************************************************************/ /************* Receive form to request or create a new course ****************/ /*****************************************************************************/ -static void Crs_ReceiveFormRequestOrCreateCrs (unsigned Status) +static void Crs_ReceiveFormRequestOrCreateCrs (Hie_Status_t Status) { extern const char *Txt_The_course_X_already_exists; extern const char *Txt_Created_new_course_X; @@ -1648,7 +1571,7 @@ void Crs_RemoveCourse (void) Crs_EditingCourseConstructor (); /***** Get course code *****/ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); /***** Get data of the course from database *****/ Crs_GetDataOfCourseByCod (Crs_EditingCrs); @@ -1691,7 +1614,7 @@ bool Crs_GetDataOfCourseByCod (struct Crs_Course *Crs) /***** Clear data *****/ Crs->DegCod = -1L; Crs->Year = 0; - Crs->Status = (Crs_Status_t) 0; + Crs->Status = (Hie_Status_t) 0; Crs->RequesterUsrCod = -1L; Crs->ShrtName[0] = '\0'; Crs->FullName[0] = '\0'; @@ -1883,7 +1806,7 @@ void Crs_ChangeInsCrsCod (void) /***** Get parameters from form *****/ /* Get course code */ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); /* Get institutional code */ Par_GetParToText ("InsCrsCod",NewInstitutionalCrsCod,Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD); @@ -1929,7 +1852,7 @@ void Crs_ChangeCrsYear (void) /***** Get parameters from form *****/ /* Get course code */ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); /* Get parameter with year */ Par_GetParToText ("OthCrsYear",YearStr,2); @@ -2002,19 +1925,6 @@ void Crs_UpdateCrsYear (struct Crs_Course *Crs,unsigned NewYear) Crs->Year = NewYear; } -/*****************************************************************************/ -/********************** Change the status of a course ************************/ -/*****************************************************************************/ - -static void Crs_UpdateCrsStatus (struct Crs_Course *Crs,Crs_Status_t Status) - { - /***** Update status in table of courses *****/ - Crs_DB_UpdateCrsStatus (Crs->CrsCod,Status); - - /***** Copy course status *****/ - Crs->Status = Status; - } - /*****************************************************************************/ /************************ Change the name of a course ************************/ /*****************************************************************************/ @@ -2025,7 +1935,7 @@ void Crs_RenameCourseShort (void) Crs_EditingCourseConstructor (); /***** Rename course *****/ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); Crs_RenameCourse (Crs_EditingCrs,Cns_SHRT_NAME); } @@ -2035,7 +1945,7 @@ void Crs_RenameCourseFull (void) Crs_EditingCourseConstructor (); /***** Rename course *****/ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); Crs_RenameCourse (Crs_EditingCrs,Cns_FULL_NAME); } @@ -2125,32 +2035,24 @@ void Crs_RenameCourse (struct Crs_Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullNam void Crs_ChangeCrsStatus (void) { extern const char *Txt_The_status_of_the_course_X_has_changed; - Crs_Status_t Status; - Crs_StatusTxt_t StatusTxt; + Hie_Status_t Status; /***** Course constructor *****/ Crs_EditingCourseConstructor (); /***** Get parameters from form *****/ /* Get course code */ - Crs_EditingCrs->CrsCod = Crs_GetAndCheckParamOtherCrsCod (1); + Crs_EditingCrs->CrsCod = Hie_GetAndCheckParamOtherHieCod (1); /* Get parameter with status */ - Status = (Crs_Status_t) - Par_GetParToUnsignedLong ("Status", - 0, - (unsigned long) Crs_MAX_STATUS, - (unsigned long) Crs_WRONG_STATUS); - if (Status == Crs_WRONG_STATUS) - Err_WrongStatusExit (); - StatusTxt = Crs_GetStatusTxtFromStatusBits (Status); - Status = Crs_GetStatusBitsFromStatusTxt (StatusTxt); // New status + Status = Hie_GetParamStatus (); // New status /***** Get data of course *****/ Crs_GetDataOfCourseByCod (Crs_EditingCrs); /***** Update status *****/ - Crs_UpdateCrsStatus (Crs_EditingCrs,Status); + Crs_DB_UpdateCrsStatus (Crs_EditingCrs->CrsCod,Status); + Crs_EditingCrs->Status = Status; /***** Create alert to show the change made *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, @@ -2334,31 +2236,6 @@ void Crs_PutParamCrsCod (long CrsCod) Par_PutHiddenParamLong (NULL,"crs",CrsCod); } -/*****************************************************************************/ -/******************** Write parameter with code of course ********************/ -/*****************************************************************************/ - -static void Crs_PutParamOtherCrsCod (void *CrsCod) - { - if (CrsCod) - Par_PutHiddenParamLong (NULL,"OthCrsCod",*((long *) CrsCod)); - } - -/*****************************************************************************/ -/********************* Get parameter with code of course *********************/ -/*****************************************************************************/ - -static long Crs_GetAndCheckParamOtherCrsCod (long MinCodAllowed) - { - long CrsCod; - - /***** Get and check parameter with code of course *****/ - if ((CrsCod = Par_GetParToLong ("OthCrsCod")) < MinCodAllowed) - Err_WrongCourseExit (); - - return CrsCod; - } - /*****************************************************************************/ /************************** Write courses of a user **************************/ /*****************************************************************************/ diff --git a/swad_course.h b/swad_course.h index 0a63db61..23d3a4af 100644 --- a/swad_course.h +++ b/swad_course.h @@ -52,33 +52,14 @@ /******************************* Public types ********************************/ /*****************************************************************************/ -typedef enum - { - Crs_STATUS_BIT_PENDING = (1 << 0), // Course is requested, but not yet activated - Crs_STATUS_BIT_REMOVED = (1 << 1), // Course has been removed - } Crs_Status_Bits_t; - -typedef unsigned Crs_Status_t; -#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 - { - Crs_STATUS_UNKNOWN = 0, // Other - Crs_STATUS_ACTIVE = 1, // 00 (Status == 0) - Crs_STATUS_PENDING = 2, // 01 (Status == Crs_STATUS_BIT_PENDING) - Crs_STATUS_REMOVED = 3, // 1- (Status & Crs_STATUS_BIT_REMOVED) - } Crs_StatusTxt_t; - struct Crs_Course { long CrsCod; char InstitutionalCrsCod[Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD + 1]; // Institutional code of the course long DegCod; - unsigned Year; // Year: 0 (optatives), 1, 2, 3... - unsigned Status; // Course status - long RequesterUsrCod; // User code of the person who requested the creation of this course + unsigned Year; // Year: 0 (optatives), 1, 2, 3... + Hie_Status_t Status; // Course status + long RequesterUsrCod; // User code of the person who requested the creation of this course char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; // Short name of course char FullName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]; // Full name of course }; diff --git a/swad_course_database.c b/swad_course_database.c index 744dbd7c..2eafec1d 100644 --- a/swad_course_database.c +++ b/swad_course_database.c @@ -35,6 +35,7 @@ #include "swad_error.h" #include "swad_global.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -46,7 +47,7 @@ extern struct Globals Gbl; /************* Add a new requested course to pending requests ****************/ /*****************************************************************************/ -void Crs_DB_CreateCourse (struct Crs_Course *Crs,unsigned Status) +void Crs_DB_CreateCourse (struct Crs_Course *Crs,Hie_Status_t Status) { /***** Insert new course into pending requests *****/ Crs->CrsCod = @@ -60,7 +61,7 @@ void Crs_DB_CreateCourse (struct Crs_Course *Crs,unsigned Status) Crs->DegCod, Crs->Year, Crs->InstitutionalCrsCod, - Status, + (unsigned) Status, Gbl.Usrs.Me.UsrDat.UsrCod, Crs->ShrtName, Crs->FullName); @@ -118,7 +119,7 @@ unsigned Crs_DB_GetCrssInCurrentDegFull (MYSQL_RES **mysql_res) " ORDER BY Year," "ShortName", Gbl.Hierarchy.Deg.DegCod, - (unsigned) Crs_STATUS_BIT_REMOVED); // All courses except those removed + (unsigned) Hie_STATUS_BIT_REMOVED); // All courses except those removed } /*****************************************************************************/ @@ -497,20 +498,6 @@ void Crs_DB_UpdateCrsYear (long CrsCod,unsigned NewYear) CrsCod); } -/*****************************************************************************/ -/********************** Change the status of a course ************************/ -/*****************************************************************************/ - -void Crs_DB_UpdateCrsStatus (long CrsCod,Crs_Status_t Status) - { - DB_QueryUPDATE ("can not update the status of a course", - "UPDATE crs_courses" - " SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Status, - CrsCod); - } - /*****************************************************************************/ /***************** Update course name in table of courses ********************/ /*****************************************************************************/ @@ -539,6 +526,20 @@ void Crs_DB_UpdateCrsDeg (long CrsCod,long DegCod) CrsCod); } +/*****************************************************************************/ +/********************** Change the status of a course ************************/ +/*****************************************************************************/ + +void Crs_DB_UpdateCrsStatus (long CrsCod,Hie_Status_t Status) + { + DB_QueryUPDATE ("can not update the status of a course", + "UPDATE crs_courses" + " SET Status=%u" + " WHERE CrsCod=%ld", + (unsigned) Status, + CrsCod); + } + /*****************************************************************************/ /***************** Update my last click in current course ********************/ /*****************************************************************************/ diff --git a/swad_course_database.h b/swad_course_database.h index 12df80c2..72c2e486 100644 --- a/swad_course_database.h +++ b/swad_course_database.h @@ -35,7 +35,7 @@ /***************************** Public prototypes *****************************/ /*****************************************************************************/ -void Crs_DB_CreateCourse (struct Crs_Course *Crs,unsigned Status); +void Crs_DB_CreateCourse (struct Crs_Course *Crs,Hie_Status_t Status); unsigned Crs_DB_GetCrssInDeg (MYSQL_RES **mysql_res,long DegCod); unsigned Crs_DB_GetCrssInCurrentDegBasic (MYSQL_RES **mysql_res); @@ -65,10 +65,10 @@ unsigned Crs_DB_GetNumCrssWithUsrs (Rol_Role_t Role, unsigned Crs_DB_GetCrssFromUsr (MYSQL_RES **mysql_res,long UsrCod,long DegCod); void Crs_DB_UpdateInstitutionalCrsCod (long CrsCod,const char *NewInstitutionalCrsCod); -void Crs_DB_UpdateCrsStatus (long CrsCod,Crs_Status_t Status); void Crs_DB_UpdateCrsYear (long CrsCod,unsigned NewYear); void Crs_DB_UpdateCrsName (long CrsCod,const char *FieldName,const char *NewCrsName); void Crs_DB_UpdateCrsDeg (long CrsCod,long DegCod); +void Crs_DB_UpdateCrsStatus (long CrsCod,Hie_Status_t Status); void Crs_DB_UpdateCrsLastClick (void); diff --git a/swad_degree.c b/swad_degree.c index 8ad308cf..ff66a47a 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -79,8 +79,6 @@ static struct Deg_Degree *Deg_EditingDeg = NULL; // Static variable to keep the static void Deg_ListDegreesForEdition (void); static bool Deg_CheckIfICanEditADegree (struct Deg_Degree *Deg); -static Deg_StatusTxt_t Deg_GetStatusTxtFromStatusBits (Deg_Status_t Status); -static Deg_Status_t Deg_GetStatusBitsFromStatusTxt (Deg_StatusTxt_t StatusTxt); static void Deg_PutFormToCreateDegree (void); static void Deg_PutHeadDegreesForSeeing (void); static void Deg_PutHeadDegreesForEdition (void); @@ -94,8 +92,7 @@ static void Deg_ListOneDegreeForSeeing (struct Deg_Degree *Deg,unsigned NumDeg); static void Deg_EditDegreesInternal (void); static void Deg_PutIconsEditingDegrees (__attribute__((unused)) void *Args); -static void Deg_ReceiveFormRequestOrCreateDeg (unsigned Status); -static void Deg_PutParamOtherDegCod (void *DegCod); +static void Deg_ReceiveFormRequestOrCreateDeg (Hie_Status_t Status); static void Deg_GetDataOfDegreeFromRow (struct Deg_Degree *Deg,MYSQL_ROW row); @@ -303,7 +300,7 @@ void Deg_ShowDegsOfCurrentCtr (void) static void Deg_ListDegreesForEdition (void) { - extern const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT]; + extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT]; unsigned NumDeg; struct DegreeType *DegTyp; struct Deg_Degree *Deg; @@ -313,8 +310,6 @@ static void Deg_ListDegreesForEdition (void) bool ICanEdit; unsigned NumCrss; unsigned NumUsrsInCrssOfDeg; - Deg_StatusTxt_t StatusTxt; - unsigned StatusUnsigned; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -349,7 +344,7 @@ static void Deg_ListDegreesForEdition (void) Ico_PutIconRemovalNotAllowed (); else Ico_PutContextualIconToRemove (ActRemDeg,NULL, - Deg_PutParamOtherDegCod,&Deg->DegCod); + Hie_PutParamOtherHieCod,&Deg->DegCod); HTM_TD_End (); /* Degree code */ @@ -367,7 +362,7 @@ static void Deg_ListDegreesForEdition (void) if (ICanEdit) { Frm_BeginForm (ActRenDegSho); - Deg_PutParamOtherDegCod (&Deg->DegCod); + Hie_PutParamOtherHieCod (&Deg->DegCod); HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Deg->ShrtName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_SHORT_NAME\""); @@ -382,7 +377,7 @@ static void Deg_ListDegreesForEdition (void) if (ICanEdit) { Frm_BeginForm (ActRenDegFul); - Deg_PutParamOtherDegCod (&Deg->DegCod); + Hie_PutParamOtherHieCod (&Deg->DegCod); HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Deg->FullName, HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_FULL_NAME\""); @@ -397,7 +392,7 @@ static void Deg_ListDegreesForEdition (void) if (ICanEdit) { Frm_BeginForm (ActChgDegTyp); - Deg_PutParamOtherDegCod (&Deg->DegCod); + Hie_PutParamOtherHieCod (&Deg->DegCod); HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, "name=\"OthDegTypCod\" class=\"HIE_SEL_NARROW\""); for (NumDegTyp = 0; @@ -426,7 +421,7 @@ static void Deg_ListDegreesForEdition (void) if (ICanEdit) { Frm_BeginForm (ActChgDegWWW); - Deg_PutParamOtherDegCod (&Deg->DegCod); + Hie_PutParamOtherHieCod (&Deg->DegCod); HTM_INPUT_URL ("WWW",Deg->WWW,HTM_SUBMIT_ON_CHANGE, "class=\"INPUT_WWW_NARROW\" required=\"required\""); Frm_EndForm (); @@ -463,27 +458,10 @@ static void Deg_ListDegreesForEdition (void) HTM_TD_End (); /* Degree status */ - StatusTxt = Deg_GetStatusTxtFromStatusBits (Deg->Status); - HTM_TD_Begin ("class=\"DAT LM\""); - if (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM && - StatusTxt == Deg_STATUS_PENDING) - { - Frm_BeginForm (ActChgDegSta); - Deg_PutParamOtherDegCod (&Deg->DegCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"Status\" class=\"INPUT_STATUS\""); - StatusUnsigned = (unsigned) Deg_GetStatusBitsFromStatusTxt (Deg_STATUS_PENDING); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, - "%s",Txt_DEGREE_STATUS[Deg_STATUS_PENDING]); - StatusUnsigned = (unsigned) Deg_GetStatusBitsFromStatusTxt (Deg_STATUS_ACTIVE); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, - "%s",Txt_DEGREE_STATUS[Deg_STATUS_ACTIVE]); - HTM_SELECT_End (); - Frm_EndForm (); - } - else if (StatusTxt != Deg_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_DEGREE_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCellEditable (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM, + Deg->Status,ActChgDegSta,Deg->DegCod, + Txt_DEGREE_STATUS); + HTM_TR_End (); } @@ -501,52 +479,10 @@ static void Deg_ListDegreesForEdition (void) static bool Deg_CheckIfICanEditADegree (struct Deg_Degree *Deg) { return (bool) (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM || // I am a center administrator or higher - ((Deg->Status & Deg_STATUS_BIT_PENDING) != 0 && // Degree is not yet activated + ((Deg->Status & Hie_STATUS_BIT_PENDING) != 0 && // Degree is not yet activated Gbl.Usrs.Me.UsrDat.UsrCod == Deg->RequesterUsrCod)); // I am the requester } -/*****************************************************************************/ -/******************* Set StatusTxt depending on status bits ******************/ -/*****************************************************************************/ -// Deg_STATUS_UNKNOWN = 0 // Other -// Deg_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Deg_STATUS_PENDING = 2 // 01 (Status == Deg_STATUS_BIT_PENDING) -// Deg_STATUS_REMOVED = 3 // 1- (Status & Deg_STATUS_BIT_REMOVED) - -static Deg_StatusTxt_t Deg_GetStatusTxtFromStatusBits (Deg_Status_t Status) - { - if (Status == 0) - return Deg_STATUS_ACTIVE; - if (Status == Deg_STATUS_BIT_PENDING) - return Deg_STATUS_PENDING; - if (Status & Deg_STATUS_BIT_REMOVED) - return Deg_STATUS_REMOVED; - return Deg_STATUS_UNKNOWN; - } - -/*****************************************************************************/ -/******************* Set status bits depending on StatusTxt ******************/ -/*****************************************************************************/ -// Deg_STATUS_UNKNOWN = 0 // Other -// Deg_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Deg_STATUS_PENDING = 2 // 01 (Status == Deg_STATUS_BIT_PENDING) -// Deg_STATUS_REMOVED = 3 // 1- (Status & Deg_STATUS_BIT_REMOVED) - -static Deg_Status_t Deg_GetStatusBitsFromStatusTxt (Deg_StatusTxt_t StatusTxt) - { - switch (StatusTxt) - { - case Deg_STATUS_UNKNOWN: - case Deg_STATUS_ACTIVE: - return (Deg_Status_t) 0; - case Deg_STATUS_PENDING: - return Deg_STATUS_BIT_PENDING; - case Deg_STATUS_REMOVED: - return Deg_STATUS_BIT_REMOVED; - } - return (Deg_Status_t) 0; - } - /*****************************************************************************/ /*********************** Put a form to create a new degree *******************/ /*****************************************************************************/ @@ -831,20 +767,19 @@ static void Deg_ListOneDegreeForSeeing (struct Deg_Degree *Deg,unsigned NumDeg) { extern const char *Txt_DEGREE_With_courses; extern const char *Txt_DEGREE_Without_courses; - extern const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT]; + extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT]; struct DegreeType DegTyp; const char *TxtClassNormal; const char *TxtClassStrong; const char *BgColor; unsigned NumCrss = Crs_GetCachedNumCrssInDeg (Deg->DegCod); - Deg_StatusTxt_t StatusTxt; /***** Get data of type of degree of this degree *****/ DegTyp.DegTypCod = Deg->DegTypCod; if (!DegTyp_GetDataOfDegreeTypeByCod (&DegTyp)) Err_WrongDegTypExit (); - if (Deg->Status & Deg_STATUS_BIT_PENDING) + if (Deg->Status & Hie_STATUS_BIT_PENDING) { TxtClassNormal = "DAT_LIGHT"; TxtClassStrong = "BT_LINK LT DAT_LIGHT"; @@ -899,11 +834,7 @@ static void Deg_ListOneDegreeForSeeing (struct Deg_Degree *Deg,unsigned NumDeg) HTM_TD_End (); /***** Degree status *****/ - StatusTxt = Deg_GetStatusTxtFromStatusBits (Deg->Status); - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); - if (StatusTxt != Deg_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_DEGREE_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCell (Deg->Status,TxtClassNormal,BgColor,Txt_DEGREE_STATUS); /***** End table row *****/ HTM_TR_End (); @@ -1105,7 +1036,7 @@ void Deg_ReceiveFormReqDeg (void) Deg_EditingDegreeConstructor (); /***** Receive form to request a new degree *****/ - Deg_ReceiveFormRequestOrCreateDeg ((unsigned) Deg_STATUS_BIT_PENDING); + Deg_ReceiveFormRequestOrCreateDeg ((Hie_Status_t) Hie_STATUS_BIT_PENDING); } /*****************************************************************************/ @@ -1118,14 +1049,14 @@ void Deg_ReceiveFormNewDeg (void) Deg_EditingDegreeConstructor (); /***** Receive form to create a new degree *****/ - Deg_ReceiveFormRequestOrCreateDeg (0); + Deg_ReceiveFormRequestOrCreateDeg ((Hie_Status_t) 0); } /*****************************************************************************/ /******************* Receive form to create a new degree *********************/ /*****************************************************************************/ -static void Deg_ReceiveFormRequestOrCreateDeg (unsigned Status) +static void Deg_ReceiveFormRequestOrCreateDeg (Hie_Status_t Status) { extern const char *Txt_The_degree_X_already_exists; extern const char *Txt_Created_new_degree_X; @@ -1192,7 +1123,7 @@ void Deg_RemoveDegree (void) Deg_EditingDegreeConstructor (); /***** Get degree code *****/ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); /***** Get data of degree *****/ Deg_GetDataOfDegreeByCod (Deg_EditingDeg); @@ -1224,16 +1155,6 @@ void Deg_PutParamDegCod (long DegCod) Par_PutHiddenParamLong (NULL,"deg",DegCod); } -/*****************************************************************************/ -/******************** Write parameter with code of degree ********************/ -/*****************************************************************************/ - -static void Deg_PutParamOtherDegCod (void *DegCod) - { - if (DegCod) - Par_PutHiddenParamLong (NULL,"OthDegCod",*((long *) DegCod)); - } - /*****************************************************************************/ /********************* Get parameter with code of degree *********************/ /*****************************************************************************/ @@ -1263,7 +1184,7 @@ bool Deg_GetDataOfDegreeByCod (struct Deg_Degree *Deg) /***** Clear data *****/ Deg->CtrCod = -1L; Deg->DegTypCod = -1L; - Deg->Status = (Deg_Status_t) 0; + Deg->Status = (Hie_Status_t) 0; Deg->RequesterUsrCod = -1L; Deg->ShrtName[0] = '\0'; Deg->FullName[0] = '\0'; @@ -1385,7 +1306,7 @@ void Deg_RenameDegreeShort (void) Deg_EditingDegreeConstructor (); /***** Rename degree *****/ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); Deg_RenameDegree (Deg_EditingDeg,Cns_SHRT_NAME); } @@ -1395,7 +1316,7 @@ void Deg_RenameDegreeFull (void) Deg_EditingDegreeConstructor (); /***** Rename degree *****/ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); Deg_RenameDegree (Deg_EditingDeg,Cns_FULL_NAME); } @@ -1486,7 +1407,7 @@ void Deg_ChangeDegreeType (void) /***** Get parameters from form *****/ /* Get degree code */ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); /* Get the new degree type */ NewDegTypCod = DegTyp_GetAndCheckParamOtherDegTypCod (1); @@ -1519,7 +1440,7 @@ void Deg_ChangeDegWWW (void) /***** Get parameters from form *****/ /* Get the code of the degree */ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); /* Get the new WWW for the degree */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -1551,31 +1472,22 @@ void Deg_ChangeDegWWW (void) void Deg_ChangeDegStatus (void) { extern const char *Txt_The_status_of_the_degree_X_has_changed; - Deg_Status_t Status; - Deg_StatusTxt_t StatusTxt; + Hie_Status_t Status; /***** Degree constructor *****/ Deg_EditingDegreeConstructor (); /***** Get parameters from form *****/ /* Get degree code */ - Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1L); + Deg_EditingDeg->DegCod = Hie_GetAndCheckParamOtherHieCod (1L); /* Get parameter with status */ - Status = (Deg_Status_t) - Par_GetParToUnsignedLong ("Status", - 0, - (unsigned long) Deg_MAX_STATUS, - (unsigned long) Deg_WRONG_STATUS); - if (Status == Deg_WRONG_STATUS) - Err_WrongStatusExit (); - StatusTxt = Deg_GetStatusTxtFromStatusBits (Status); - Status = Deg_GetStatusBitsFromStatusTxt (StatusTxt); // New status + Status = Hie_GetParamStatus (); // New status /***** Get data of degree *****/ Deg_GetDataOfDegreeByCod (Deg_EditingDeg); - /***** Update status in table of degrees *****/ + /***** Update status *****/ Deg_DB_UpdateDegStatus (Deg_EditingDeg->DegCod,Status); Deg_EditingDeg->Status = Status; @@ -1919,7 +1831,7 @@ static void Deg_EditingDegreeConstructor (void) Deg_EditingDeg->DegCod = -1L; Deg_EditingDeg->DegTypCod = -1L; Deg_EditingDeg->CtrCod = -1L; - Deg_EditingDeg->Status = (Deg_Status_t) 0; + Deg_EditingDeg->Status = (Hie_Status_t) 0; Deg_EditingDeg->RequesterUsrCod = -1L; Deg_EditingDeg->ShrtName[0] = '\0'; Deg_EditingDeg->FullName[0] = '\0'; diff --git a/swad_degree.h b/swad_degree.h index 95b4a800..00f0b70c 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -47,31 +47,12 @@ /******************************* Public types ********************************/ /*****************************************************************************/ -typedef enum - { - Deg_STATUS_BIT_PENDING = (1 << 0), // Degree is requested, but not yet activated - Deg_STATUS_BIT_REMOVED = (1 << 1), // Degree has been removed - } Deg_Status_Bits_t; - -typedef unsigned Deg_Status_t; -#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 - { - Deg_STATUS_UNKNOWN = 0, // Other - Deg_STATUS_ACTIVE = 1, // 00 (Status == 0) - Deg_STATUS_PENDING = 2, // 01 (Status == Deg_STATUS_BIT_PENDING) - Deg_STATUS_REMOVED = 3, // 1- (Status & Deg_STATUS_BIT_REMOVED) - } Deg_StatusTxt_t; - struct Deg_Degree { long DegCod; // Degree code long DegTypCod; // Degree type code long CtrCod; // Center code - Deg_Status_t Status; // Degree status + Hie_Status_t Status; // Degree status long RequesterUsrCod; // User code of the person who requested the creation of this degree char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; // Short name of degree char FullName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]; // Full name of degree diff --git a/swad_degree_database.c b/swad_degree_database.c index 0717b96f..7441d052 100644 --- a/swad_degree_database.c +++ b/swad_degree_database.c @@ -30,6 +30,7 @@ #include "swad_error.h" #include "swad_global.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -53,7 +54,7 @@ void Deg_DB_CreateDegreeType (const char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE /***************************** Create a new degree ***************************/ /*****************************************************************************/ -void Deg_DB_CreateDegree (struct Deg_Degree *Deg,unsigned Status) +void Deg_DB_CreateDegree (struct Deg_Degree *Deg,Hie_Status_t Status) { Deg->DegCod = DB_QueryINSERTandReturnCode ("can not create a new degree", @@ -65,7 +66,7 @@ void Deg_DB_CreateDegree (struct Deg_Degree *Deg,unsigned Status) "%ld,'%s','%s','%s')", Deg->CtrCod, Deg->DegTypCod, - Status, + (unsigned) Status, Gbl.Usrs.Me.UsrDat.UsrCod, Deg->ShrtName, Deg->FullName, @@ -392,7 +393,7 @@ unsigned Deg_DB_GetDegsWithPendingCrss (MYSQL_RES **mysql_res) " ORDER BY deg_degrees.ShortName", Gbl.Usrs.Me.UsrDat.UsrCod, Sco_GetDBStrFromScope (HieLvl_DEG), - (unsigned) Crs_STATUS_BIT_PENDING); + (unsigned) Hie_STATUS_BIT_PENDING); case Rol_SYS_ADM: return (unsigned) DB_QuerySELECT (mysql_res,"can not get degrees with pending courses", @@ -404,7 +405,7 @@ unsigned Deg_DB_GetDegsWithPendingCrss (MYSQL_RES **mysql_res) " AND crs_courses.DegCod=deg_degrees.DegCod" " GROUP BY crs_courses.DegCod" " ORDER BY deg_degrees.ShortName", - (unsigned) Crs_STATUS_BIT_PENDING); + (unsigned) Hie_STATUS_BIT_PENDING); default: // Forbidden for other users Err_WrongRoleExit (); return 0; // Not reached @@ -663,7 +664,7 @@ void Deg_DB_UpdateDegWWW (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]) /*********************** Update the status of a degree ***********************/ /*****************************************************************************/ -void Deg_DB_UpdateDegStatus (long DegCod,Deg_Status_t NewStatus) +void Deg_DB_UpdateDegStatus (long DegCod,Hie_Status_t NewStatus) { DB_QueryUPDATE ("can not update the status of a degree", "UPDATE deg_degrees" diff --git a/swad_degree_database.h b/swad_degree_database.h index 72964a14..82e188dd 100644 --- a/swad_degree_database.h +++ b/swad_degree_database.h @@ -38,7 +38,7 @@ /*****************************************************************************/ void Deg_DB_CreateDegreeType (const char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1]); -void Deg_DB_CreateDegree (struct Deg_Degree *Deg,unsigned Status); +void Deg_DB_CreateDegree (struct Deg_Degree *Deg,Hie_Status_t Status); unsigned Deg_DB_GetDegreeTypes (MYSQL_RES **mysql_res, HieLvl_Level_t Scope,DegTyp_Order_t Order); @@ -76,7 +76,7 @@ void Deg_DB_UpdateDegNameDB (long DegCod,const char *FieldName, void Deg_DB_UpdateDegCtr (long DegCod,long NewCtrCod); void Deg_DB_UpdateDegTyp (long DegCod,long NewDegTypCod); void Deg_DB_UpdateDegWWW (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); -void Deg_DB_UpdateDegStatus (long DegCod,Deg_Status_t NewStatus); +void Deg_DB_UpdateDegStatus (long DegCod,Hie_Status_t NewStatus); unsigned Deg_DB_GetDegsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long CtrCod); unsigned Deg_DB_GetUsrMainDeg (MYSQL_RES **mysql_res,long UsrCod); diff --git a/swad_error.c b/swad_error.c index b270f883..4e7ac64f 100644 --- a/swad_error.c +++ b/swad_error.c @@ -81,6 +81,11 @@ void Err_WrongScopeExit (void) /********* when wrong country, institution, center, degree or course *********/ /*****************************************************************************/ +void Err_WrongHierarchyExit (void) + { + Err_ShowErrorAndExit ("Wrong hierarchy."); + } + void Err_WrongCountrExit (void) { Err_ShowErrorAndExit ("Wrong country."); diff --git a/swad_error.h b/swad_error.h index cf113a15..35c76f0b 100644 --- a/swad_error.h +++ b/swad_error.h @@ -31,6 +31,7 @@ void Err_NotEnoughMemoryExit (void); void Err_QuerySizeExceededExit (void); void Err_WrongActionExit (void); void Err_WrongScopeExit (void); +void Err_WrongHierarchyExit (void); void Err_WrongCountrExit (void); void Err_WrongInstitExit (void); void Err_WrongCenterExit (void); diff --git a/swad_hierarchy.c b/swad_hierarchy.c index 474c4b71..7b84f59d 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -47,6 +47,13 @@ extern struct Globals Gbl; +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +static Hie_StatusTxt_t Hie_GetStatusTxtFromStatusBits (Hie_Status_t Status); +static Hie_Status_t Hie_GetStatusBitsFromStatusTxt (Hie_StatusTxt_t StatusTxt); + /*****************************************************************************/ /********** List pending institutions, centers, degrees and courses **********/ /*****************************************************************************/ @@ -747,24 +754,145 @@ void Hie_FreeGoToMsg (void) } /*****************************************************************************/ -/******************* Get number of countries with users **********************/ +/*********************** Write status cell in table **************************/ /*****************************************************************************/ -void Hie_DB_BuildSubquery (char SubQuery[128],HieLvl_Level_t Scope,long Cod) +void Hie_WriteStatusCell (Hie_Status_t Status, + const char *Class,const char *BgColor, + const char *Txt[Hie_NUM_STATUS_TXT]) { - static const char *Format[HieLvl_NUM_LEVELS] = + Hie_StatusTxt_t StatusTxt = Hie_GetStatusTxtFromStatusBits (Status); + + HTM_TD_Begin ("class=\"%s LM %s\"",Class,BgColor); + if (StatusTxt != Hie_STATUS_ACTIVE) // If active ==> do not show anything + HTM_Txt (Txt[StatusTxt]); + HTM_TD_End (); + } + +void Hie_WriteStatusCellEditable (bool ICanEdit,Hie_Status_t Status, + Act_Action_t NextAction,long HieCod, + const char *Txt[Hie_NUM_STATUS_TXT]) + { + Hie_StatusTxt_t StatusTxt = Hie_GetStatusTxtFromStatusBits (Status); + unsigned StatusUnsigned; + + /***** Begin cell *****/ + HTM_TD_Begin ("class=\"DAT LM\""); + if (ICanEdit && StatusTxt == Hie_STATUS_PENDING) + { + /* Begin form */ + Frm_BeginForm (NextAction); + Hie_PutParamOtherHieCod (&HieCod); + + /* Selector */ + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "name=\"Status\" class=\"INPUT_STATUS\""); + + StatusUnsigned = (unsigned) Hie_GetStatusBitsFromStatusTxt (Hie_STATUS_PENDING); + HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, + "%s",Txt[Hie_STATUS_PENDING]); + + StatusUnsigned = (unsigned) Hie_GetStatusBitsFromStatusTxt (Hie_STATUS_ACTIVE); + HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, + "%s",Txt[Hie_STATUS_ACTIVE]); + + HTM_SELECT_End (); + + /* End form */ + Frm_EndForm (); + } + else if (StatusTxt != Hie_STATUS_ACTIVE) // If active ==> do not show anything + HTM_Txt (Txt[StatusTxt]); + + /***** End cell *****/ + HTM_TD_End (); + } + +/*****************************************************************************/ +/**************************** Get parameter status ***************************/ +/*****************************************************************************/ + +Hie_Status_t Hie_GetParamStatus (void) + { + Hie_Status_t Status; + Hie_StatusTxt_t StatusTxt; + + /***** Get parameter with status *****/ + Status = (Hie_Status_t) + Par_GetParToUnsignedLong ("Status", + 0, + (unsigned long) Hie_MAX_STATUS, + (unsigned long) Hie_WRONG_STATUS); + if (Status == Hie_WRONG_STATUS) + Err_WrongStatusExit (); + + StatusTxt = Hie_GetStatusTxtFromStatusBits (Status); + Status = Hie_GetStatusBitsFromStatusTxt (StatusTxt); // New status + + return Status; + } + +/*****************************************************************************/ +/******************* Set StatusTxt depending on status bits ******************/ +/*****************************************************************************/ +// Hie_STATUS_UNKNOWN = 0 // Other +// Hie_STATUS_ACTIVE = 1 // 00 (Status == 0) +// Hie_STATUS_PENDING = 2 // 01 (Status == Hie_STATUS_BIT_PENDING) +// Hie_STATUS_REMOVED = 3 // 1- (Status & Hie_STATUS_BIT_REMOVED) + +static Hie_StatusTxt_t Hie_GetStatusTxtFromStatusBits (Hie_Status_t Status) + { + if (Status == 0) + return Hie_STATUS_ACTIVE; + if (Status == Hie_STATUS_BIT_PENDING) + return Hie_STATUS_PENDING; + if (Status & Hie_STATUS_BIT_REMOVED) + return Hie_STATUS_REMOVED; + return Hie_STATUS_UNKNOWN; + } + +/*****************************************************************************/ +/******************* Set status bits depending on StatusTxt ******************/ +/*****************************************************************************/ +// Hie_STATUS_UNKNOWN = 0 // Other +// Hie_STATUS_ACTIVE = 1 // 00 (Status == 0) +// Hie_STATUS_PENDING = 2 // 01 (Status == Hie_STATUS_BIT_PENDING) +// Hie_STATUS_REMOVED = 3 // 1- (Status & Hie_STATUS_BIT_REMOVED) + +static Hie_Status_t Hie_GetStatusBitsFromStatusTxt (Hie_StatusTxt_t StatusTxt) + { + static const Hie_Status_t StatusBits[Hie_NUM_STATUS_TXT] = { - [HieLvl_UNK] = "", // Unknown - [HieLvl_SYS] = "", // System - [HieLvl_CTY] = "ins_instits.CtyCod=%ld AND ", // Country - [HieLvl_INS] = "ctr_centers.InsCod=%ld AND ", // Institution - [HieLvl_CTR] = "deg_degrees.CtrCod=%ld AND ", // Center - [HieLvl_DEG] = "crs_courses.DegCod=%ld AND ", // Degree - [HieLvl_CRS] = "crs_users.CrsCod=%ld AND ", // Course + [Hie_STATUS_UNKNOWN] = (Hie_Status_t) 0, + [Hie_STATUS_ACTIVE ] = (Hie_Status_t) 0, + [Hie_STATUS_PENDING] = Hie_STATUS_BIT_PENDING, + [Hie_STATUS_REMOVED] = Hie_STATUS_BIT_REMOVED, }; - if (Cod > 0) - sprintf (SubQuery,Format[Scope],Cod); - else - SubQuery[0] = '\0'; + return StatusBits[StatusTxt]; + } + +/*****************************************************************************/ +/**** Write parameter with code of other institution/center/degree/course ****/ +/*****************************************************************************/ + +void Hie_PutParamOtherHieCod (void *HieCod) + { + if (HieCod) + Par_PutHiddenParamLong (NULL,"OthHieCod",*((long *) HieCod)); + } + +/*****************************************************************************/ +/***** Get parameter with code of other institution/center/degree/course *****/ +/*****************************************************************************/ + +long Hie_GetAndCheckParamOtherHieCod (long MinCodAllowed) + { + long HieCod; + + /***** Get and check parameter with code *****/ + if ((HieCod = Par_GetParToLong ("OthHieCod")) < MinCodAllowed) + Err_WrongHierarchyExit (); + + return HieCod; } diff --git a/swad_hierarchy.h b/swad_hierarchy.h index b3f0c964..fba8e9e9 100644 --- a/swad_hierarchy.h +++ b/swad_hierarchy.h @@ -65,6 +65,14 @@ void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan); char *Hie_BuildGoToMsg (const char *Where); void Hie_FreeGoToMsg (void); -void Hie_DB_BuildSubquery (char SubQuery[128],HieLvl_Level_t Scope,long Cod); +void Hie_WriteStatusCell (Hie_Status_t Status, + const char *Class,const char *BgColor, + const char *Txt[Hie_NUM_STATUS_TXT]); +void Hie_WriteStatusCellEditable (bool ICanEdit,Hie_Status_t Status, + Act_Action_t NextAction,long HieCod, + const char *Txt[Hie_NUM_STATUS_TXT]); +Hie_Status_t Hie_GetParamStatus (void); +void Hie_PutParamOtherHieCod (void *HieCod); +long Hie_GetAndCheckParamOtherHieCod (long MinCodAllowed); #endif diff --git a/swad_hierarchy_database.c b/swad_hierarchy_database.c index 500857c7..bfc00ed3 100644 --- a/swad_hierarchy_database.c +++ b/swad_hierarchy_database.c @@ -30,6 +30,29 @@ #include "swad_hierarchy_level.h" #include "swad_scope.h" +/*****************************************************************************/ +/******************* Get number of countries with users **********************/ +/*****************************************************************************/ + +void Hie_DB_BuildSubquery (char SubQuery[128],HieLvl_Level_t Scope,long Cod) + { + static const char *Format[HieLvl_NUM_LEVELS] = + { + [HieLvl_UNK] = "", // Unknown + [HieLvl_SYS] = "", // System + [HieLvl_CTY] = "ins_instits.CtyCod=%ld AND ", // Country + [HieLvl_INS] = "ctr_centers.InsCod=%ld AND ", // Institution + [HieLvl_CTR] = "deg_degrees.CtrCod=%ld AND ", // Center + [HieLvl_DEG] = "crs_courses.DegCod=%ld AND ", // Degree + [HieLvl_CRS] = "crs_users.CrsCod=%ld AND ", // Course + }; + + if (Cod > 0) + sprintf (SubQuery,Format[Scope],Cod); + else + SubQuery[0] = '\0'; + } + /*****************************************************************************/ /****** Get institutions, centers and degrees administrated by an admin *****/ /*****************************************************************************/ diff --git a/swad_hierarchy_database.h b/swad_hierarchy_database.h index 77bd413a..9f79d634 100644 --- a/swad_hierarchy_database.h +++ b/swad_hierarchy_database.h @@ -33,6 +33,7 @@ /***************************** Public prototypes *****************************/ /*****************************************************************************/ +void Hie_DB_BuildSubquery (char SubQuery[128],HieLvl_Level_t Scope,long Cod); unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod); #endif diff --git a/swad_hierarchy_level.h b/swad_hierarchy_level.h index 06cf515d..f996d349 100644 --- a/swad_hierarchy_level.h +++ b/swad_hierarchy_level.h @@ -40,4 +40,23 @@ typedef enum HieLvl_CRS = 6, // Course } HieLvl_Level_t; +typedef enum + { + Hie_STATUS_BIT_PENDING = (1 << 0), // Requested, but not yet activated + Hie_STATUS_BIT_REMOVED = (1 << 1), // Removed + } Hie_Status_Bits_t; + +typedef unsigned Hie_Status_t; +#define Hie_MAX_STATUS ((Hie_Status_t) 3) +#define Hie_WRONG_STATUS ((Hie_Status_t) (Hie_MAX_STATUS + 1)) + +#define Hie_NUM_STATUS_TXT 4 +typedef enum + { + Hie_STATUS_UNKNOWN = 0, // Other + Hie_STATUS_ACTIVE = 1, // 00 (Status == 0) + Hie_STATUS_PENDING = 2, // 01 (Status == Hie_STATUS_BIT_PENDING) + Hie_STATUS_REMOVED = 3, // 1- (Status & Hie_STATUS_BIT_REMOVED) + } Hie_StatusTxt_t; + #endif diff --git a/swad_institution.c b/swad_institution.c index fd4cba29..9465a150 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -87,11 +87,6 @@ static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins, static void Ins_ListInstitutionsForEdition (void); static bool Ins_CheckIfICanEdit (struct Ins_Instit *Ins); -static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status); -static Ins_Status_t Ins_GetStatusBitsFromStatusTxt (Ins_StatusTxt_t StatusTxt); - -static void Ins_PutParamOtherInsCod (void *InsCod); -static long Ins_GetParamOtherInsCod (void); static void Ins_UpdateInsNameDB (long InsCod,const char *FieldName,const char *NewInsName); @@ -100,7 +95,7 @@ static void Ins_PutParamGoToIns (void *InsCod); static void Ins_PutFormToCreateInstitution (void); static void Ins_PutHeadInstitutionsForEdition (void); -static void Ins_ReceiveFormRequestOrCreateIns (unsigned Status); +static void Ins_ReceiveFormRequestOrCreateIns (Hie_Status_t Status); static void Ins_EditingInstitutionConstructor (); static void Ins_EditingInstitutionDestructor (); @@ -364,13 +359,12 @@ static void Ins_PutIconToEditInstitutions (void) static void Ins_ListOneInstitutionForSeeing (struct Ins_Instit *Ins,unsigned NumIns) { - extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT]; + extern const char *Txt_INSTITUTION_STATUS[Hie_NUM_STATUS_TXT]; const char *TxtClassNormal; const char *TxtClassStrong; const char *BgColor; - Ins_StatusTxt_t StatusTxt; - if (Ins->Status & Ins_STATUS_BIT_PENDING) + if (Ins->Status & Hie_STATUS_BIT_PENDING) { TxtClassNormal = "DAT_LIGHT"; TxtClassStrong = "BT_LINK LT DAT_LIGHT"; @@ -431,11 +425,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Ins_Instit *Ins,unsigned Num HTM_TD_End (); /***** Institution status *****/ - StatusTxt = Ins_GetStatusTxtFromStatusBits (Ins->Status); - HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassNormal,BgColor); - if (StatusTxt != Ins_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_INSTITUTION_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCell (Ins->Status,TxtClassNormal,BgColor,Txt_INSTITUTION_STATUS); HTM_TR_End (); @@ -709,12 +699,12 @@ bool Ins_GetDataOfInstitByCod (struct Ins_Instit *Ins) bool InsFound = false; /***** Clear data *****/ - Ins->CtyCod = -1L; - Ins->Status = (Ins_Status_t) 0; - Ins->RequesterUsrCod = -1L; - Ins->ShrtName[0] = - Ins->FullName[0] = - Ins->WWW[0] = '\0'; + Ins->CtyCod = -1L; + Ins->Status = (Hie_Status_t) 0; + Ins->RequesterUsrCod = -1L; + Ins->ShrtName[0] = + Ins->FullName[0] = + Ins->WWW[0] = '\0'; Ins->NumUsrsWhoClaimToBelongToIns.Valid = false; /***** Check if institution code is correct *****/ @@ -923,7 +913,7 @@ void Ins_WriteSelectorOfInstitution (void) static void Ins_ListInstitutionsForEdition (void) { - extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT]; + extern const char *Txt_INSTITUTION_STATUS[Hie_NUM_STATUS_TXT]; unsigned NumIns; struct Ins_Instit *Ins; char WWW[Cns_MAX_BYTES_WWW + 1]; @@ -932,8 +922,6 @@ static void Ins_ListInstitutionsForEdition (void) unsigned NumCtrs; unsigned NumUsrsIns; unsigned NumUsrsInCrssOfIns; - Ins_StatusTxt_t StatusTxt; - unsigned StatusUnsigned; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -971,7 +959,7 @@ static void Ins_ListInstitutionsForEdition (void) Ico_PutIconRemovalNotAllowed (); else Ico_PutContextualIconToRemove (ActRemIns,NULL, - Ins_PutParamOtherInsCod,&Ins->InsCod); + Hie_PutParamOtherHieCod,&Ins->InsCod); HTM_TD_End (); /* Institution code */ @@ -989,10 +977,10 @@ static void Ins_ListInstitutionsForEdition (void) if (ICanEdit) { Frm_BeginForm (ActRenInsSho); - Ins_PutParamOtherInsCod (&Ins->InsCod); - HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Ins->ShrtName, - HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_SHORT_NAME\""); + Hie_PutParamOtherHieCod (&Ins->InsCod); + HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Ins->ShrtName, + HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_SHORT_NAME\""); Frm_EndForm (); } else @@ -1004,10 +992,10 @@ static void Ins_ListInstitutionsForEdition (void) if (ICanEdit) { Frm_BeginForm (ActRenInsFul); - Ins_PutParamOtherInsCod (&Ins->InsCod); - HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Ins->FullName, - HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_FULL_NAME\""); + Hie_PutParamOtherHieCod (&Ins->InsCod); + HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Ins->FullName, + HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_FULL_NAME\""); Frm_EndForm (); } else @@ -1019,19 +1007,19 @@ static void Ins_ListInstitutionsForEdition (void) if (ICanEdit) { Frm_BeginForm (ActChgInsWWW); - Ins_PutParamOtherInsCod (&Ins->InsCod); - HTM_INPUT_URL ("WWW",Ins->WWW,HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_WWW_NARROW\" required=\"required\""); + Hie_PutParamOtherHieCod (&Ins->InsCod); + HTM_INPUT_URL ("WWW",Ins->WWW,HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_WWW_NARROW\" required=\"required\""); Frm_EndForm (); } else { Str_Copy (WWW,Ins->WWW,sizeof (WWW) - 1); HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHORT\""); - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\"", - Ins->WWW,Ins->WWW); - HTM_Txt (WWW); - HTM_A_End (); + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\"", + Ins->WWW,Ins->WWW); + HTM_Txt (WWW); + HTM_A_End (); HTM_DIV_End (); } HTM_TD_End (); @@ -1061,27 +1049,9 @@ static void Ins_ListInstitutionsForEdition (void) HTM_TD_End (); /* Institution status */ - HTM_TD_Begin ("class=\"DAT LM\""); - StatusTxt = Ins_GetStatusTxtFromStatusBits (Ins->Status); - if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM && - StatusTxt == Ins_STATUS_PENDING) - { - Frm_BeginForm (ActChgInsSta); - Ins_PutParamOtherInsCod (&Ins->InsCod); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "name=\"Status\" class=\"INPUT_STATUS\""); - StatusUnsigned = (unsigned) Ins_GetStatusBitsFromStatusTxt (Ins_STATUS_PENDING); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,true,false, - "%s",Txt_INSTITUTION_STATUS[Ins_STATUS_PENDING]); - StatusUnsigned = (unsigned) Ins_GetStatusBitsFromStatusTxt (Ins_STATUS_ACTIVE); - HTM_OPTION (HTM_Type_UNSIGNED,&StatusUnsigned,false,false, - "%s",Txt_INSTITUTION_STATUS[Ins_STATUS_ACTIVE]); - HTM_SELECT_End (); - Frm_EndForm (); - } - else if (StatusTxt != Ins_STATUS_ACTIVE) // If active ==> do not show anything - HTM_Txt (Txt_INSTITUTION_STATUS[StatusTxt]); - HTM_TD_End (); + Hie_WriteStatusCellEditable (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM, + Ins->Status,ActChgInsSta,Ins->InsCod, + Txt_INSTITUTION_STATUS); HTM_TR_End (); } @@ -1100,50 +1070,8 @@ static void Ins_ListInstitutionsForEdition (void) static bool Ins_CheckIfICanEdit (struct Ins_Instit *Ins) { return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || // I am a superuser - ((Ins->Status & Ins_STATUS_BIT_PENDING) != 0 && // Institution is not yet activated - Gbl.Usrs.Me.UsrDat.UsrCod == Ins->RequesterUsrCod)); // I am the requester - } - -/*****************************************************************************/ -/******************* Set StatusTxt depending on status bits ******************/ -/*****************************************************************************/ -// Ins_STATUS_UNKNOWN = 0 // Other -// Ins_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Ins_STATUS_PENDING = 2 // 01 (Status == Ins_STATUS_BIT_PENDING) -// Ins_STATUS_REMOVED = 3 // 1- (Status & Ins_STATUS_BIT_REMOVED) - -static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status) - { - if (Status == 0) - return Ins_STATUS_ACTIVE; - if (Status == Ins_STATUS_BIT_PENDING) - return Ins_STATUS_PENDING; - if (Status & Ins_STATUS_BIT_REMOVED) - return Ins_STATUS_REMOVED; - return Ins_STATUS_UNKNOWN; - } - -/*****************************************************************************/ -/******************* Set status bits depending on StatusTxt ******************/ -/*****************************************************************************/ -// Ins_STATUS_UNKNOWN = 0 // Other -// Ins_STATUS_ACTIVE = 1 // 00 (Status == 0) -// Ins_STATUS_PENDING = 2 // 01 (Status == Ins_STATUS_BIT_PENDING) -// Ins_STATUS_REMOVED = 3 // 1- (Status & Ins_STATUS_BIT_REMOVED) - -static Ins_Status_t Ins_GetStatusBitsFromStatusTxt (Ins_StatusTxt_t StatusTxt) - { - switch (StatusTxt) - { - case Ins_STATUS_UNKNOWN: - case Ins_STATUS_ACTIVE: - return (Ins_Status_t) 0; - case Ins_STATUS_PENDING: - return Ins_STATUS_BIT_PENDING; - case Ins_STATUS_REMOVED: - return Ins_STATUS_BIT_REMOVED; - } - return (Ins_Status_t) 0; + ((Ins->Status & Hie_STATUS_BIT_PENDING) != 0 && // Institution is not yet activated + Gbl.Usrs.Me.UsrDat.UsrCod == Ins->RequesterUsrCod)); // I am the requester } /*****************************************************************************/ @@ -1165,16 +1093,6 @@ void Ins_PutParamInsCod (long InsCod) Par_PutHiddenParamLong (NULL,"ins",InsCod); } -/*****************************************************************************/ -/***************** Write parameter with code of institution ******************/ -/*****************************************************************************/ - -static void Ins_PutParamOtherInsCod (void *InsCod) - { - if (InsCod) - Par_PutHiddenParamLong (NULL,"OthInsCod",*((long *) InsCod)); - } - /*****************************************************************************/ /******************* Get parameter with code of institution ******************/ /*****************************************************************************/ @@ -1184,18 +1102,12 @@ long Ins_GetAndCheckParamOtherInsCod (long MinCodAllowed) long InsCod; /***** Get and check parameter with code of institution *****/ - if ((InsCod = Ins_GetParamOtherInsCod ()) < MinCodAllowed) + if ((InsCod = Par_GetParToLong ("OthInsCod")) < MinCodAllowed) Err_WrongInstitExit (); return InsCod; } -static long Ins_GetParamOtherInsCod (void) - { - /***** Get code of institution *****/ - return Par_GetParToLong ("OthInsCod"); - } - /*****************************************************************************/ /**************************** Remove a institution ***************************/ /*****************************************************************************/ @@ -1210,7 +1122,7 @@ void Ins_RemoveInstitution (void) Ins_EditingInstitutionConstructor (); /***** Get institution code *****/ - Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Hie_GetAndCheckParamOtherHieCod (1); /***** Get data of the institution from database *****/ Ins_GetDataOfInstitByCod (Ins_EditingIns); @@ -1284,7 +1196,7 @@ void Ins_RenameInsShort (void) Ins_EditingInstitutionConstructor (); /***** Rename institution *****/ - Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Hie_GetAndCheckParamOtherHieCod (1); Ins_RenameInstitution (Ins_EditingIns,Cns_SHRT_NAME); } @@ -1294,7 +1206,7 @@ void Ins_RenameInsFull (void) Ins_EditingInstitutionConstructor (); /***** Rename institution *****/ - Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Hie_GetAndCheckParamOtherHieCod (1); Ins_RenameInstitution (Ins_EditingIns,Cns_FULL_NAME); } @@ -1398,7 +1310,7 @@ void Ins_ChangeInsWWW (void) /***** Get parameters from form *****/ /* Get the code of the institution */ - Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Hie_GetAndCheckParamOtherHieCod (1); /* Get the new WWW for the institution */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); @@ -1430,31 +1342,22 @@ void Ins_ChangeInsWWW (void) void Ins_ChangeInsStatus (void) { extern const char *Txt_The_status_of_the_institution_X_has_changed; - Ins_Status_t Status; - Ins_StatusTxt_t StatusTxt; + Hie_Status_t Status; /***** Institution constructor *****/ Ins_EditingInstitutionConstructor (); /***** Get parameters from form *****/ /* Get institution code */ - Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Hie_GetAndCheckParamOtherHieCod (1); /* Get parameter with status */ - Status = (Ins_Status_t) - Par_GetParToUnsignedLong ("Status", - 0, - (unsigned long) Ins_MAX_STATUS, - (unsigned long) Ins_WRONG_STATUS); - if (Status == Ins_WRONG_STATUS) - Err_WrongStatusExit (); - StatusTxt = Ins_GetStatusTxtFromStatusBits (Status); - Status = Ins_GetStatusBitsFromStatusTxt (StatusTxt); // New status + Status = Hie_GetParamStatus (); // New status /***** Get data of institution *****/ Ins_GetDataOfInstitByCod (Ins_EditingIns); - /***** Update status in table of institutions *****/ + /***** Update status *****/ Ins_DB_UpdateInsStatus (Status,Ins_EditingIns->InsCod); Ins_EditingIns->Status = Status; @@ -1650,7 +1553,7 @@ void Ins_ReceiveFormReqIns (void) Ins_EditingInstitutionConstructor (); /***** Receive form to request a new institution *****/ - Ins_ReceiveFormRequestOrCreateIns ((unsigned) Ins_STATUS_BIT_PENDING); + Ins_ReceiveFormRequestOrCreateIns ((Hie_Status_t) Hie_STATUS_BIT_PENDING); } /*****************************************************************************/ @@ -1663,14 +1566,14 @@ void Ins_ReceiveFormNewIns (void) Ins_EditingInstitutionConstructor (); /***** Receive form to create a new institution *****/ - Ins_ReceiveFormRequestOrCreateIns (0); + Ins_ReceiveFormRequestOrCreateIns ((Hie_Status_t) 0); } /*****************************************************************************/ /*********** Receive form to request or create a new institution *************/ /*****************************************************************************/ -static void Ins_ReceiveFormRequestOrCreateIns (unsigned Status) +static void Ins_ReceiveFormRequestOrCreateIns (Hie_Status_t Status) { extern const char *Txt_The_institution_X_already_exists; extern const char *Txt_Created_new_institution_X; diff --git a/swad_institution.h b/swad_institution.h index c257cde6..720f8295 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -35,32 +35,13 @@ /************************ Public types and constants *************************/ /*****************************************************************************/ -typedef enum - { - Ins_STATUS_BIT_PENDING = (1 << 0), // Institution is requested, but not yet activated - Ins_STATUS_BIT_REMOVED = (1 << 1), // Institution has been removed - } Ins_Status_Bits_t; - -typedef unsigned Ins_Status_t; -#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 - { - Ins_STATUS_UNKNOWN = 0, // Other - Ins_STATUS_ACTIVE = 1, // 00 (Status == 0) - Ins_STATUS_PENDING = 2, // 01 (Status == Ins_STATUS_BIT_PENDING) - Ins_STATUS_REMOVED = 3, // 1- (Status & Ins_STATUS_BIT_REMOVED) - } Ins_StatusTxt_t; - #define Ins_MAX_INSTITS_PER_USR 10 // Used in list of my institutions struct Ins_Instit { long InsCod; long CtyCod; - Ins_Status_t Status; // Institution status + Hie_Status_t Status; // Institution status long RequesterUsrCod; // User code of the person who requested the creation of this institution char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; char FullName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]; diff --git a/swad_institution_database.c b/swad_institution_database.c index 0947400b..e32864c9 100644 --- a/swad_institution_database.c +++ b/swad_institution_database.c @@ -33,6 +33,7 @@ #include "swad_error.h" #include "swad_global.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" #include "swad_institution.h" #include "swad_institution_database.h" @@ -46,7 +47,7 @@ extern struct Globals Gbl; /************************** Create a new institution *************************/ /*****************************************************************************/ -long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status) +long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,Hie_Status_t Status) { return DB_QueryINSERTandReturnCode ("can not create institution", @@ -57,7 +58,7 @@ long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status) " (%ld,%u,%ld," "'%s','%s','%s')", Ins->CtyCod, - Status, + (unsigned) Status, Gbl.Usrs.Me.UsrDat.UsrCod, Ins->ShrtName, Ins->FullName, @@ -82,7 +83,7 @@ void Ins_DB_UpdateInsCty (long InsCod,long CtyCod) /****************** Update status in table of institutions *******************/ /*****************************************************************************/ -void Ins_DB_UpdateInsStatus (long InsCod,Ins_Status_t Status) +void Ins_DB_UpdateInsStatus (long InsCod,Hie_Status_t Status) { DB_QueryUPDATE ("can not update the status of an institution", "UPDATE ins_instits" @@ -223,7 +224,7 @@ unsigned Ins_DB_GetAllInsWithPendingCtr (MYSQL_RES **mysql_res) " AND ctr_centers.InsCod=ins_instits.InsCod" " GROUP BY ctr_centers.InsCod" " ORDER BY ins_instits.ShortName", - (unsigned) Ctr_STATUS_BIT_PENDING); + (unsigned) Hie_STATUS_BIT_PENDING); } /*****************************************************************************/ @@ -245,7 +246,7 @@ unsigned Ins_DB_GetInsWithPendingCtrsAdminByMe (MYSQL_RES **mysql_res) " AND ctr_centers.InsCod=ins_instits.InsCod" " GROUP BY ctr_centers.InsCod" " ORDER BY ins_instits.ShortName", - (unsigned) Ctr_STATUS_BIT_PENDING, + (unsigned) Hie_STATUS_BIT_PENDING, Gbl.Usrs.Me.UsrDat.UsrCod); } diff --git a/swad_institution_database.h b/swad_institution_database.h index 2bf5ef2c..90b31e37 100644 --- a/swad_institution_database.h +++ b/swad_institution_database.h @@ -37,9 +37,9 @@ /***************************** Public prototypes *****************************/ /*****************************************************************************/ -long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,unsigned Status); +long Ins_DB_CreateInstitution (const struct Ins_Instit *Ins,Hie_Status_t Status); void Ins_DB_UpdateInsCty (long InsCod,long CtyCod); -void Ins_DB_UpdateInsStatus (long InsCod,Ins_Status_t Status); +void Ins_DB_UpdateInsStatus (long InsCod,Hie_Status_t Status); void Ins_DB_UpdateInsName (long InsCod,const char *FieldName,const char *NewInsName); void Ins_DB_UpdateInsWWW (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); diff --git a/swad_text.c b/swad_text.c index de0cf8f9..968761b4 100644 --- a/swad_text.c +++ b/swad_text.c @@ -71,6 +71,7 @@ #include "swad_exam_log.h" #include "swad_figure.h" #include "swad_forum.h" +#include "swad_hierarchy.h" #include "swad_holiday.h" #include "swad_info.h" #include "swad_institution.h" @@ -4033,9 +4034,9 @@ const char *Txt_Center_X_removed = // Warning: it is very important to include % "Centro %s removido."; #endif -const char *Txt_CENTER_STATUS[Crs_NUM_STATUS_TXT] = +const char *Txt_CENTER_STATUS[Hie_NUM_STATUS_TXT] = { - [Ctr_STATUS_UNKNOWN] = + [Hie_STATUS_UNKNOWN] = #if L==1 // ca "Desconegudo" #elif L==2 // de @@ -4056,7 +4057,7 @@ const char *Txt_CENTER_STATUS[Crs_NUM_STATUS_TXT] = "Desconhecido" #endif , - [Ctr_STATUS_ACTIVE] = + [Hie_STATUS_ACTIVE] = #if L==1 // ca "Activo" #elif L==2 // de @@ -4077,7 +4078,7 @@ const char *Txt_CENTER_STATUS[Crs_NUM_STATUS_TXT] = "Ativo" #endif , - [Ctr_STATUS_PENDING] = + [Hie_STATUS_PENDING] = #if L==1 // ca "Novo" #elif L==2 // de @@ -4098,7 +4099,7 @@ const char *Txt_CENTER_STATUS[Crs_NUM_STATUS_TXT] = "Novo" #endif , - [Ctr_STATUS_REMOVED] = + [Hie_STATUS_REMOVED] = #if L==1 // ca "Eliminado" #elif L==2 // de @@ -5710,9 +5711,9 @@ const char *Txt_Course_program = "Programa da disciplina"; #endif -const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT] = +const char *Txt_COURSE_STATUS[Hie_NUM_STATUS_TXT] = { - [Crs_STATUS_UNKNOWN] = + [Hie_STATUS_UNKNOWN] = #if L==1 // ca "Desconegudo" #elif L==2 // de @@ -5733,7 +5734,7 @@ const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT] = "Desconhecido" #endif , - [Crs_STATUS_ACTIVE] = + [Hie_STATUS_ACTIVE] = #if L==1 // ca "Activa" #elif L==2 // de @@ -5754,7 +5755,7 @@ const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT] = "Ativa" #endif , - [Crs_STATUS_PENDING] = + [Hie_STATUS_PENDING] = #if L==1 // ca "Nova" #elif L==2 // de @@ -5775,7 +5776,7 @@ const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT] = "Nova" #endif , - [Crs_STATUS_REMOVED] = + [Hie_STATUS_REMOVED] = #if L==1 // ca "Eliminada" #elif L==2 // de @@ -8120,9 +8121,9 @@ const char *Txt_degree = "grau"; #endif -const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT] = +const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT] = { - [Deg_STATUS_UNKNOWN] = + [Hie_STATUS_UNKNOWN] = #if L==1 // ca "Desconegudo" #elif L==2 // de @@ -8143,7 +8144,7 @@ const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT] = "Desconhecido" #endif , - [Deg_STATUS_ACTIVE] = + [Hie_STATUS_ACTIVE] = #if L==1 // ca "Activa" #elif L==2 // de @@ -8164,7 +8165,7 @@ const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT] = "Ativa" #endif , - [Deg_STATUS_PENDING] = + [Hie_STATUS_PENDING] = #if L==1 // ca "Nova" #elif L==2 // de @@ -8185,7 +8186,7 @@ const char *Txt_DEGREE_STATUS[Deg_NUM_STATUS_TXT] = "Nova" #endif , - [Deg_STATUS_REMOVED] = + [Hie_STATUS_REMOVED] = #if L==1 // ca "Eliminada" #elif L==2 // de @@ -17443,9 +17444,9 @@ const char *Txt_Institution_X_removed = // Warning: it is very important to incl #endif -const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT] = +const char *Txt_INSTITUTION_STATUS[Hie_NUM_STATUS_TXT] = { - [Ins_STATUS_UNKNOWN] = + [Hie_STATUS_UNKNOWN] = #if L==1 // ca "Desconegudo" #elif L==2 // de @@ -17466,7 +17467,7 @@ const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT] = "Desconhecido" #endif , - [Ins_STATUS_ACTIVE] = + [Hie_STATUS_ACTIVE] = #if L==1 // ca "Activa" #elif L==2 // de @@ -17487,7 +17488,7 @@ const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT] = "Ativa" #endif , - [Ins_STATUS_PENDING] = + [Hie_STATUS_PENDING] = #if L==1 // ca "Nova" #elif L==2 // de @@ -17508,7 +17509,7 @@ const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT] = "Nova" #endif , - [Ins_STATUS_REMOVED] = + [Hie_STATUS_REMOVED] = #if L==1 // ca "Eliminada" #elif L==2 // de