From 9bce0286467117a4140064445c8ea8a36946e1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 30 Jan 2017 17:45:16 +0100 Subject: [PATCH] Version 16.132.3 --- swad_changelog.h | 3 +- swad_connected.c | 105 ++++++++++++++++------------------------------- 2 files changed, 37 insertions(+), 71 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 55bd72013..e24fbeed5 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -191,13 +191,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.132.2 (2017-01-30)" +#define Log_PLATFORM_VERSION "SWAD 16.132.3 (2017-01-30)" #define CSS_FILE "swad16.123.css" #define JS_FILE "swad16.123.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.132.3: Jan 30, 2017 Code refactoring in connected users. (211881 lines) Version 16.132.2: Jan 30, 2017 Fixed bug in file browser. (211911 lines) Version 16.132.1: Jan 29, 2017 Fixed bug in listing of users. (211916 lines) Version 16.132: Jan 29, 2017 Code refactoring in unsigned parameters. (211915 lines) diff --git a/swad_connected.c b/swad_connected.c index a396681fb..88bb7b4bc 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -56,14 +56,15 @@ extern struct Globals Gbl; static void Con_PutIconToUpdateConnected (void); +static void Con_ShowGlobalConnectedUsrsRole (Rol_Role_t Role,unsigned UsrsTotal); + static void Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_Role_t Role); static void Con_ShowConnectedUsrsBelongingToLocation (void); static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_Role_t Role); static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_Role_t Role); -static unsigned Con_GetConnectedGuestsTotal (void); -static unsigned Con_GetConnectedStdsTotal (void); -static unsigned Con_GetConnectedTchsTotal (void); +static unsigned Con_GetConnectedUsrsTotal (Rol_Role_t Role); + static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t Role,struct ConnectedUsrs *Usrs); static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role); static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Role); @@ -347,12 +348,10 @@ void Con_ShowGlobalConnectedUsrs (void) extern const char *Txt_sessions; extern const char *Txt_user[Usr_NUM_SEXS]; extern const char *Txt_users[Usr_NUM_SEXS]; - extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; - extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; - unsigned StdsTotal = Con_GetConnectedStdsTotal (); - unsigned TchsTotal = Con_GetConnectedTchsTotal (); - unsigned WithoutCoursesTotal = Con_GetConnectedGuestsTotal (); - unsigned UsrsTotal = StdsTotal + TchsTotal + WithoutCoursesTotal; + unsigned StdsTotal = Con_GetConnectedUsrsTotal (Rol_STUDENT); + unsigned TchsTotal = Con_GetConnectedUsrsTotal (Rol_TEACHER); + unsigned GstsTotal = Con_GetConnectedUsrsTotal (Rol__GUEST_); + unsigned UsrsTotal = StdsTotal + TchsTotal + GstsTotal; /***** Container start *****/ fprintf (Gbl.F.Out,"
"); @@ -384,28 +383,13 @@ void Con_ShowGlobalConnectedUsrs (void) Txt_users[Usr_SEX_UNKNOWN]); /***** Write total number of students *****/ - if (StdsTotal) - fprintf (Gbl.F.Out,"
" - "%u %s", - StdsTotal, - (StdsTotal == 1) ? Txt_ROLES_SINGUL_abc[Rol_STUDENT][Usr_SEX_UNKNOWN] : - Txt_ROLES_PLURAL_abc[Rol_STUDENT][Usr_SEX_UNKNOWN]); + Con_ShowGlobalConnectedUsrsRole (Rol_STUDENT,StdsTotal); /***** Write total number of teachers *****/ - if (TchsTotal) - fprintf (Gbl.F.Out,"
" - "%u %s", - TchsTotal, - (TchsTotal == 1) ? Txt_ROLES_SINGUL_abc[Rol_TEACHER][Usr_SEX_UNKNOWN] : - Txt_ROLES_PLURAL_abc[Rol_TEACHER][Usr_SEX_UNKNOWN]); + Con_ShowGlobalConnectedUsrsRole (Rol_TEACHER,TchsTotal); /***** Write total number of users who do not belong to any course *****/ - if (WithoutCoursesTotal) - fprintf (Gbl.F.Out,"
" - "%u %s", - WithoutCoursesTotal, - (WithoutCoursesTotal == 1) ? Txt_ROLES_SINGUL_abc[Rol__GUEST_][Usr_SEX_UNKNOWN] : - Txt_ROLES_PLURAL_abc[Rol__GUEST_][Usr_SEX_UNKNOWN]); + Con_ShowGlobalConnectedUsrsRole (Rol__GUEST_,GstsTotal); fprintf (Gbl.F.Out,"
"); } @@ -414,6 +398,19 @@ void Con_ShowGlobalConnectedUsrs (void) fprintf (Gbl.F.Out,""); } +static void Con_ShowGlobalConnectedUsrsRole (Rol_Role_t Role,unsigned UsrsTotal) + { + extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; + extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; + + if (UsrsTotal) + fprintf (Gbl.F.Out,"
" + "%u %s", + UsrsTotal, + (UsrsTotal == 1) ? Txt_ROLES_SINGUL_abc[Role][Usr_SEX_UNKNOWN] : + Txt_ROLES_PLURAL_abc[Role][Usr_SEX_UNKNOWN]); + } + /*****************************************************************************/ /*********** Compute connected users who belong to current course ************/ /*****************************************************************************/ @@ -718,12 +715,15 @@ void Con_UpdateMeInConnectedList (void) /***** Which role will be stored in connected table? *****/ MyRoleInConnected = (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT || Gbl.Usrs.Me.LoggedRole == Rol_TEACHER) ? Gbl.Usrs.Me.LoggedRole : - Gbl.Usrs.Me.MaxRole; + Gbl.Usrs.Me.MaxRole; /***** Update my entry in connected list. The role which is stored is the role of the last click *****/ - sprintf (Query,"REPLACE INTO connected (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)" + sprintf (Query,"REPLACE INTO connected" + " (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)" " VALUES ('%ld','%u','%ld',NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) MyRoleInConnected,Gbl.CurrentCrs.Crs.CrsCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) MyRoleInConnected, + Gbl.CurrentCrs.Crs.CrsCod); DB_QueryREPLACE (Query,"can not update list of connected users"); } @@ -742,55 +742,20 @@ void Con_RemoveOldConnected (void) } /*****************************************************************************/ -/*************************** Get connected guests ***************************/ +/********************* Get connected users with a role ***********************/ /*****************************************************************************/ -static unsigned Con_GetConnectedGuestsTotal (void) +static unsigned Con_GetConnectedUsrsTotal (Rol_Role_t Role) { char Query[128]; if (!Gbl.DB.DatabaseIsOpen) return 0; - /***** Get number of connected users not belonging to any course *****/ - sprintf (Query,"SELECT COUNT(*) FROM connected" - " WHERE RoleInLastCrs='%u'", - (unsigned) Rol__GUEST_); - return (unsigned) DB_QueryCOUNT (Query,"can not get number of connected users who not belong to any course"); - } - -/*****************************************************************************/ -/*************************** Get connected students **************************/ -/*****************************************************************************/ - -static unsigned Con_GetConnectedStdsTotal (void) - { - char Query[128]; - - if (!Gbl.DB.DatabaseIsOpen) - return 0; - - /***** Get number of connected students from database *****/ + /***** Get number of connected users with a role from database *****/ sprintf (Query,"SELECT COUNT(*) FROM connected WHERE RoleInLastCrs='%u'", - (unsigned) Rol_STUDENT); - return (unsigned) DB_QueryCOUNT (Query,"can not get number of connected students"); - } - -/*****************************************************************************/ -/*************************** Get connected teachers **************************/ -/*****************************************************************************/ - -static unsigned Con_GetConnectedTchsTotal (void) - { - char Query[256]; - - if (!Gbl.DB.DatabaseIsOpen) - return 0; - - /***** Get number of connected teachers from database *****/ - sprintf (Query,"SELECT COUNT(*) FROM connected WHERE RoleInLastCrs='%u'", - (unsigned) Rol_TEACHER); - return (unsigned) DB_QueryCOUNT (Query,"can not get number of connected teachers"); + (unsigned) Role); + return (unsigned) DB_QueryCOUNT (Query,"can not get number of connected users"); } /*****************************************************************************/