swad-core/swad_connected.c

1125 lines
42 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_connected.c: connected users
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
#include <limits.h> // For maximum values
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
2019-02-18 14:41:46 +01:00
#include <stdio.h> // For fprintf
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2017-01-17 03:10:43 +01:00
#include "swad_hierarchy.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2019-12-14 14:30:34 +01:00
#include "swad_log.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_photo.h"
2019-09-28 15:03:22 +02:00
#include "swad_role.h"
2014-12-01 23:55:08 +01:00
#include "swad_string.h"
#include "swad_user.h"
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/*************************** Private constants *******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/**************************** Private prototypes *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-24 13:50:57 +01:00
static void Con_PutIconToUpdateConnected (void);
2017-01-30 17:45:16 +01:00
static void Con_ShowGlobalConnectedUsrsRole (Rol_Role_t Role,unsigned UsrsTotal);
2015-12-20 01:41:07 +01:00
static void Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_Role_t Role);
2016-03-15 19:41:01 +01:00
static void Con_ShowConnectedUsrsBelongingToLocation (void);
2015-12-20 01:41:07 +01:00
2014-12-01 23:55:08 +01:00
static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_Role_t Role);
2016-03-15 22:15:25 +01:00
static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_Role_t Role);
2017-01-30 17:45:16 +01:00
static unsigned Con_GetConnectedUsrsTotal (Rol_Role_t Role);
2015-12-20 01:41:07 +01:00
static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t Role,struct ConnectedUsrs *Usrs);
2014-12-01 23:55:08 +01:00
static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role);
static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Role);
static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role);
static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t Role);
/*****************************************************************************/
/************************** Show connected users *****************************/
/*****************************************************************************/
void Con_ShowConnectedUsrs (void)
{
2016-11-21 18:12:23 +01:00
extern const char *Hlp_USERS_Connected;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Connected_users;
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
2015-09-22 23:58:18 +02:00
if (Gbl.Usrs.Me.Logged)
{
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuBegin ();
2019-12-14 14:30:34 +01:00
Log_PutLinkToLastClicks (); // Show last clicks in real time
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2015-09-22 23:58:18 +02:00
}
2016-03-15 19:41:01 +01:00
/***** Get scope *****/
Sco_SetScopesForListingStudents ();
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeCon");
2015-03-24 19:41:54 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2015-03-24 19:41:54 +01:00
/* Current time */
2018-10-17 10:32:18 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"%s"
"<div id=\"connected_current_time\"></div>",
Txt_Connected_users);
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Gbl.Title,Con_PutIconToUpdateConnected,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Connected,Box_NOT_CLOSABLE);
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC ("connected_current_time",Gbl.StartExecutionTimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA,
2019-11-02 11:45:41 +01:00
false,false,true,0x7);
2015-12-30 18:52:45 +01:00
2016-03-15 19:41:01 +01:00
/***** Number of connected users in the whole platform *****/
2014-12-01 23:55:08 +01:00
Con_ShowGlobalConnectedUsrs ();
2016-03-15 19:41:01 +01:00
/***** Show connected users in the current location *****/
2019-04-03 20:57:04 +02:00
if (Gbl.Scope.Current != Hie_UNK)
2017-03-14 10:04:35 +01:00
Con_ShowConnectedUsrsBelongingToLocation ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
2016-03-24 13:50:57 +01:00
/*****************************************************************************/
/******************** Put icon to update connected users *********************/
/*****************************************************************************/
static void Con_PutIconToUpdateConnected (void)
{
extern const char *Txt_Update;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActLstCon);
2016-06-24 20:34:58 +02:00
Sco_PutParamScope ("ScopeCon",Gbl.Scope.Current);
2019-11-19 00:17:23 +01:00
HTM_BUTTON_Animated_Begin (Txt_Update,"BT_LINK",NULL);
2017-06-11 19:13:28 +02:00
Ico_PutCalculateIcon (Txt_Update);
2019-11-19 00:17:23 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-24 13:50:57 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Show total number of connected users *******************/
/*****************************************************************************/
void Con_ShowGlobalConnectedUsrs (void)
{
2016-03-15 10:21:56 +01:00
extern const char *Txt_Connected_users;
2014-12-01 23:55:08 +01:00
extern const char *Txt_session;
extern const char *Txt_sessions;
extern const char *Txt_user[Usr_NUM_SEXS];
2016-06-27 12:35:15 +02:00
extern const char *Txt_users[Usr_NUM_SEXS];
2017-01-30 19:02:13 +01:00
Rol_Role_t Role;
unsigned NumUsrs[Rol_NUM_ROLES];
unsigned NumUsrsTotal;
/***** Get number of connected users *****/
2017-05-18 19:13:41 +02:00
for (Role = Rol_GST, NumUsrsTotal = 0;
2017-01-30 19:02:13 +01:00
Role <= Rol_SYS_ADM;
Role++)
{
NumUsrs[Role] = Con_GetConnectedUsrsTotal (Role);
NumUsrsTotal += NumUsrs[Role];
}
2014-12-01 23:55:08 +01:00
2015-11-25 21:07:50 +01:00
/***** Container start *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CONNECTED\"");
2014-12-01 23:55:08 +01:00
2016-03-15 22:15:25 +01:00
/***** Number of sessions *****/
/* Link to view more details about connected users */
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActLstCon); // Must be unique because
2016-03-16 01:44:51 +01:00
// the list of connected users
// is dynamically updated via AJAX
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_Connected_users,"BT_LINK CONNECTED_TXT",NULL);
2016-03-15 10:21:56 +01:00
2016-03-15 22:15:25 +01:00
/* Write total number of sessions */
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%u&nbsp;%s",Gbl.Session.NumSessions,
Gbl.Session.NumSessions == 1 ? Txt_session :
Txt_sessions);
2017-06-12 14:16:33 +02:00
/* End link to view more details about connected users */
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
2017-01-30 19:02:13 +01:00
if (NumUsrsTotal)
2016-03-15 19:41:01 +01:00
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CONNECTED_LIST\"");
2016-03-15 22:15:25 +01:00
2016-03-15 19:41:01 +01:00
/***** Write total number of users *****/
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%u&nbsp;%s:",NumUsrsTotal,
NumUsrsTotal == 1 ? Txt_user[Usr_SEX_UNKNOWN] :
Txt_users[Usr_SEX_UNKNOWN]);
2016-03-15 19:41:01 +01:00
2017-01-30 19:02:13 +01:00
/***** Write total number of users with each role *****/
2017-05-18 19:13:41 +02:00
for (Role = Rol_GST, NumUsrsTotal = 0;
2017-01-30 19:02:13 +01:00
Role <= Rol_SYS_ADM;
Role++)
Con_ShowGlobalConnectedUsrsRole (Role,NumUsrs[Role]);
2014-12-01 23:55:08 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-03-15 22:15:25 +01:00
}
2016-03-15 10:21:56 +01:00
2015-11-25 21:07:50 +01:00
/***** Container end *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2017-01-30 17:45:16 +01:00
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)
2019-11-09 21:03:02 +01:00
{
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%u&nbsp;%s",UsrsTotal,
UsrsTotal == 1 ? Txt_ROLES_SINGUL_abc[Role][Usr_SEX_UNKNOWN] :
Txt_ROLES_PLURAL_abc[Role][Usr_SEX_UNKNOWN]);
2019-11-09 21:03:02 +01:00
}
2017-01-30 17:45:16 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********** Compute connected users who belong to current course ************/
/*****************************************************************************/
void Con_ComputeConnectedUsrsBelongingToCurrentCrs (void)
{
2015-12-20 01:41:07 +01:00
if ((Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN) && // Right column visible
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Level == Hie_CRS && // Course selected
2015-12-20 01:41:07 +01:00
(Gbl.Usrs.Me.IBelongToCurrentCrs || // I can view users
2017-06-04 18:18:54 +02:00
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM))
2015-12-20 01:41:07 +01:00
{
Gbl.Usrs.Connected.NumUsrs = 0;
Gbl.Usrs.Connected.NumUsrsToList = 0;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Current = Hie_CRS;
2015-12-20 01:41:07 +01:00
/***** Number of teachers *****/
2017-05-18 19:13:41 +02:00
Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_TCH);
2015-12-20 01:41:07 +01:00
2017-05-20 12:04:12 +02:00
/***** Number of non-editing teachers *****/
2017-05-21 21:23:13 +02:00
Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_NET);
2017-05-20 12:04:12 +02:00
2015-12-20 01:41:07 +01:00
/***** Number of students *****/
2017-05-18 19:13:41 +02:00
Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_STD);
2015-12-20 01:41:07 +01:00
}
}
/*****************************************************************************/
/** Compute number of connected users of a type who belong to current course */
/*****************************************************************************/
2014-12-01 23:55:08 +01:00
2015-12-20 01:41:07 +01:00
static void Con_ComputeConnectedUsrsWithARoleBelongingToCurrentCrs (Rol_Role_t Role)
{
/***** Get number of connected users who belong to current course *****/
Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Role,&Gbl.Usrs.Connected.Usrs[Role]);
2014-12-01 23:55:08 +01:00
2015-12-20 01:41:07 +01:00
/***** Get list connected users belonging to this course *****/
Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Role);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2015-12-20 01:41:07 +01:00
/****** Show number of connected users who belong to current location ********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-15 19:41:01 +01:00
static void Con_ShowConnectedUsrsBelongingToLocation (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_from;
2015-12-20 01:41:07 +01:00
struct ConnectedUsrs Usrs;
2014-12-01 23:55:08 +01:00
2016-03-15 19:41:01 +01:00
/***** Start container *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CONNECTED\"");
2016-03-15 19:41:01 +01:00
2015-12-20 01:41:07 +01:00
/***** Number of connected users who belong to scope *****/
2017-05-18 19:13:41 +02:00
Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_UNK,&Usrs);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CONNECTED_TXT\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%u %s ",Usrs.NumUsrs,Txt_from);
2017-03-04 20:23:45 +01:00
/* Put form to change scope */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActLstCon);
2017-03-04 20:23:45 +01:00
Sco_PutSelectorScope ("ScopeCon",true);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-03-04 20:23:45 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-03-15 19:41:01 +01:00
/***** Number of teachers and students *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_Begin ("CONNECTED_LIST");
2017-05-18 19:13:41 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_TCH);
2017-05-21 21:23:13 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_NET);
2017-05-18 19:13:41 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_STD);
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2017-05-18 19:13:41 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_GST);
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2016-03-15 19:41:01 +01:00
2017-05-29 15:00:23 +02:00
/***** Put link to register students *****/
2017-05-29 21:34:43 +02:00
Enr_CheckStdsAndPutButtonToRegisterStdsInCurrentCrs ();
2017-05-29 15:00:23 +02:00
2016-03-15 19:41:01 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-03-15 19:41:01 +01:00
}
/*****************************************************************************/
/* Show number of connected users who belong to current course on right col. */
/*****************************************************************************/
2016-03-15 22:15:25 +01:00
void Con_ShowConnectedUsrsBelongingToCurrentCrs (void)
2016-03-15 19:41:01 +01:00
{
2016-03-15 22:15:25 +01:00
extern const char *Txt_Connected_users;
2016-03-15 19:41:01 +01:00
extern const char *Txt_from;
2017-03-08 14:12:33 +01:00
char CourseName[Hie_MAX_BYTES_SHRT_NAME + 1];
2016-03-15 19:41:01 +01:00
struct ConnectedUsrs Usrs;
2019-04-03 20:57:04 +02:00
/***** Trivial check *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Crs.CrsCod <= 0) // No course selected
2016-03-15 19:41:01 +01:00
return;
/***** Start container *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CONNECTED\"");
2016-03-15 19:41:01 +01:00
/***** Number of connected users who belong to course *****/
2016-03-15 22:15:25 +01:00
/* Link to view more details about connected users */
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActLstCon); // Must be unique because
2016-03-16 01:44:51 +01:00
// the list of connected users
// is dynamically updated via AJAX
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_Connected_users,"BT_LINK CONNECTED_TXT",NULL);
2019-04-04 10:45:15 +02:00
Str_Copy (CourseName,Gbl.Hierarchy.Crs.ShrtName,
2017-03-08 14:12:33 +01:00
Hie_MAX_BYTES_SHRT_NAME);
2017-05-18 19:13:41 +02:00
Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_UNK,&Usrs);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%u %s %s",Usrs.NumUsrs,Txt_from,CourseName);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-15 19:41:01 +01:00
/***** Number of teachers and students *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_Begin ("CONNECTED_LIST");
2016-03-15 19:41:01 +01:00
Gbl.Usrs.Connected.NumUsr = 0;
Gbl.Usrs.Connected.NumUsrs = 0;
Gbl.Usrs.Connected.NumUsrsToList = 0;
2017-05-18 19:13:41 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_TCH);
2017-05-21 21:23:13 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_NET);
2017-05-18 19:13:41 +02:00
Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_STD);
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
2016-03-15 19:41:01 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/* Show number of connected users with a role who belong to current location */
/*****************************************************************************/
static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentLocationOnMainZone (Rol_Role_t Role)
{
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2015-12-20 01:41:07 +01:00
struct ConnectedUsrs Usrs;
2014-12-01 23:55:08 +01:00
/***** Write number of connected users who belong to current course *****/
2015-12-20 01:41:07 +01:00
Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Role,&Usrs);
2016-03-15 19:41:01 +01:00
if (Usrs.NumUsrs)
2014-12-01 23:55:08 +01:00
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"3\" class=\"CT\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%u&nbsp;%s",Usrs.NumUsrs,
Usrs.NumUsrs == 1 ? Txt_ROLES_SINGUL_abc[Role][Usrs.Sex] :
Txt_ROLES_PLURAL_abc[Role][Usrs.Sex]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2016-03-15 19:41:01 +01:00
/***** I can see connected users *****/
Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Role);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2016-03-15 22:15:25 +01:00
/** Show number of connected users with a role who belong to current course **/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-15 22:15:25 +01:00
static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
2015-03-12 14:45:40 +01:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_Connected_users;
2015-12-20 01:41:07 +01:00
unsigned NumUsrsThisRole = Gbl.Usrs.Connected.Usrs[Role].NumUsrs;
Usr_Sex_t UsrSex = Gbl.Usrs.Connected.Usrs[Role].Sex;
2014-12-01 23:55:08 +01:00
2016-03-15 19:41:01 +01:00
if (NumUsrsThisRole)
2014-12-01 23:55:08 +01:00
{
2016-03-15 19:41:01 +01:00
/***** Write number of connected users who belong to current course *****/
Gbl.Usrs.Connected.NumUsrs += NumUsrsThisRole;
Gbl.Usrs.Connected.NumUsrsToList += NumUsrsThisRole;
if (Gbl.Usrs.Connected.NumUsrsToList > Cfg_MAX_CONNECTED_SHOWN)
Gbl.Usrs.Connected.NumUsrsToList = Cfg_MAX_CONNECTED_SHOWN;
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 00:26:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"3\" class=\"CON_USR_NARROW_TIT\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%u&nbsp;%s",NumUsrsThisRole,
NumUsrsThisRole == 1 ? Txt_ROLES_SINGUL_abc[Role][UsrSex] :
Txt_ROLES_PLURAL_abc[Role][UsrSex]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-08 00:26:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-03-15 19:41:01 +01:00
/***** I can see connected users *****/
Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Role);
/***** Write message with number of users not listed *****/
if (Gbl.Usrs.Connected.NumUsrsToList < Gbl.Usrs.Connected.NumUsrs)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 00:26:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"3\" class=\"CT\"");
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActLstCon); // Must be unique because
2016-03-15 19:41:01 +01:00
// the list of connected users
// is dynamically updated via AJAX
2019-04-03 20:57:04 +02:00
Sco_PutParamScope ("ScopeCon",Hie_CRS);
2019-11-20 15:23:52 +01:00
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"ellipsis-h.svg",
Txt_Connected_users,"ICO16x16");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-08 00:26:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-03-15 19:41:01 +01:00
}
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************* Modify my entry in connected list *********************/
/*****************************************************************************/
void Con_UpdateMeInConnectedList (void)
{
2017-01-30 19:02:13 +01:00
/***** Update my entry in connected list.
The role which is stored is the role of the last click *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not update list of connected users",
"REPLACE INTO connected"
" (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)"
" VALUES"
" (%ld,%u,%ld,NOW())",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Gbl.Usrs.Me.Role.Logged,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Remove old connected uses ************************/
/*****************************************************************************/
void Con_RemoveOldConnected (void)
{
/***** Remove old users from connected list *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove old users from list of connected users",
"DELETE FROM connected WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod) FROM sessions)");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-01-30 17:45:16 +01:00
/********************* Get connected users with a role ***********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-01-30 17:45:16 +01:00
static unsigned Con_GetConnectedUsrsTotal (Rol_Role_t Role)
2014-12-01 23:55:08 +01:00
{
if (!Gbl.DB.DatabaseIsOpen)
return 0;
2017-01-30 17:45:16 +01:00
/***** Get number of connected users with a role from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of connected users",
"SELECT COUNT(*) FROM connected"
" WHERE RoleInLastCrs=%u",
(unsigned) Role);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get connected users belonging to current course **************/
/*****************************************************************************/
// Return user's sex in UsrSex
2015-12-20 01:41:07 +01:00
static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t Role,struct ConnectedUsrs *Usrs)
2014-12-01 23:55:08 +01:00
{
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumSexs;
Usr_Sex_t Sex;
/***** Get number of connected users who belong to current course from database *****/
2015-12-20 01:41:07 +01:00
switch (Role)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_UNK: // Here Rol_UNK means "any role"
2015-12-20 01:41:07 +01:00
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS: // Show connected users in the whole platform
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM connected,usr_data"
" WHERE connected.UsrCod=usr_data.UsrCod");
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY: // Show connected users in the current country
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM institutions,centres,degrees,courses,crs_usr,connected,usr_data"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS: // Show connected users in the current institution
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM centres,degrees,courses,crs_usr,connected,usr_data"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR: // Show connected users in the current centre
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM degrees,courses,crs_usr,connected,usr_data"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG: // Show connected users in the current degree
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM courses,crs_usr,connected,usr_data"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS: // Show connected users in the current course
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM crs_usr,connected,usr_data"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2015-12-20 01:41:07 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2015-12-20 01:41:07 +01:00
break;
}
break;
2017-05-18 19:13:41 +02:00
case Rol_GST:
2018-10-31 13:00:40 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM connected,usr_data"
" WHERE connected.UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" AND connected.UsrCod=usr_data.UsrCod");
2015-12-20 01:41:07 +01:00
break;
2017-05-18 19:13:41 +02:00
case Rol_STD:
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2015-12-20 01:41:07 +01:00
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS: // Show connected users in the whole platform
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM connected,crs_usr,usr_data"
" WHERE connected.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role=%u"
" AND connected.UsrCod=usr_data.UsrCod",
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY: // Show connected users in the current country
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM institutions,centres,degrees,courses,crs_usr,connected,usr_data"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS: // Show connected users in the current institution
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM centres,degrees,courses,crs_usr,connected,usr_data"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR: // Show connected users in the current centre
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM degrees,courses,crs_usr,connected,usr_data"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG: // Show connected users in the current degree
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM courses,crs_usr,connected,usr_data"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS: // Show connected users in the current course
2018-10-30 14:47:31 +01:00
DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users"
" who belong to this location",
"SELECT COUNT(DISTINCT connected.UsrCod),"
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
" FROM crs_usr,connected,usr_data"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" AND connected.UsrCod=usr_data.UsrCod",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-20 01:41:07 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2015-12-20 01:41:07 +01:00
break;
}
break;
2014-12-01 23:55:08 +01:00
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2014-12-01 23:55:08 +01:00
break;
}
row = mysql_fetch_row (mysql_res);
/***** Get number of users (row[0]) *****/
2015-12-20 01:41:07 +01:00
if (sscanf (row[0],"%u",&(Usrs->NumUsrs)) != 1)
Lay_ShowErrorAndExit ("Error when getting number of connected users who belong to this location.");
2014-12-01 23:55:08 +01:00
/***** Get number of distinct sexs (row[1]) *****/
if (sscanf (row[1],"%u",&NumSexs) != 1)
2015-12-20 01:41:07 +01:00
Lay_ShowErrorAndExit ("Error when getting number of sexs in connected users who belong to this location.");
2014-12-01 23:55:08 +01:00
/***** Get users' sex (row[2]) *****/
2015-12-20 01:41:07 +01:00
Usrs->Sex = Usr_SEX_UNKNOWN;
2014-12-01 23:55:08 +01:00
if (NumSexs == 1)
2019-12-15 01:10:36 +01:00
for (Sex = (Usr_Sex_t) 0;
Sex <= (Usr_Sex_t) (Usr_NUM_SEXS - 1);
2014-12-01 23:55:08 +01:00
Sex++)
if (!strcasecmp (row[2],Usr_StringsSexDB[Sex]))
{
2015-12-20 01:41:07 +01:00
Usrs->Sex = Sex;
2014-12-01 23:55:08 +01:00
break;
}
/***** Free structure that stores the query result *****/
mysql_free_result (mysql_res);
}
/*****************************************************************************/
/******************* Compute connected users one by one **********************/
/*****************************************************************************/
static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2018-10-19 13:55:02 +02:00
unsigned NumUsr = Gbl.Usrs.Connected.NumUsrs; // Save current number of users
2014-12-01 23:55:08 +01:00
/***** Get connected users who belong to current course from database *****/
2018-10-30 14:47:31 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this course",
"SELECT connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM connected,crs_usr"
" WHERE crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Connected.NumUsrs += (unsigned) NumRows;
Gbl.Usrs.Connected.NumUsrsToList += (unsigned) NumRows;
if (Gbl.Usrs.Connected.NumUsrsToList > Cfg_MAX_CONNECTED_SHOWN)
Gbl.Usrs.Connected.NumUsrsToList = Cfg_MAX_CONNECTED_SHOWN;
/***** Write list of connected users *****/
for (;
NumUsr < Gbl.Usrs.Connected.NumUsrsToList;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get user code (row[0]) */
Gbl.Usrs.Connected.Lst[NumUsr].UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get course code (row[1]) */
2019-04-03 20:57:04 +02:00
Gbl.Usrs.Connected.Lst[NumUsr].ThisCrs = (Str_ConvertStrCodToLongCod (row[1]) ==
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
2015-10-26 22:34:29 +01:00
/* Compute elapsed time from last access */
if (sscanf (row[2],"%ld",&Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff) != 1)
Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff = (time_t) 0;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
mysql_free_result (mysql_res);
}
/*****************************************************************************/
/******************* Show connected users one by one *************************/
/*****************************************************************************/
static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Role)
{
/***** Write list of connected users *****/
for (;
Gbl.Usrs.Connected.NumUsr < Gbl.Usrs.Connected.NumUsrsToList;
Gbl.Usrs.Connected.NumUsr++)
/* Write row in screen */
Con_WriteRowConnectedUsrOnRightColumn (Role);
}
/*****************************************************************************/
/********************* Write the name of a connected user ********************/
/*****************************************************************************/
static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role)
{
2015-03-30 14:37:44 +02:00
extern const char *Txt_View_record_for_this_course;
2014-12-01 23:55:08 +01:00
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2019-11-18 20:12:10 +01:00
const char *ClassTxt;
const char *ClassLink;
2017-02-17 01:59:58 +01:00
long UsrCod;
bool ItsMe;
2018-10-10 23:56:42 +02:00
struct UsrData *UsrDat;
struct UsrData OtherUsrDat;
2017-02-17 01:59:58 +01:00
/***** Get user's code from list *****/
UsrCod = Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].UsrCod;
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (UsrCod);
2017-02-17 01:59:58 +01:00
if (ItsMe)
UsrDat = &Gbl.Usrs.Me.UsrDat;
else
{
/***** Initialize structure with user's data *****/
OtherUsrDat.UsrCod = UsrCod;
Usr_UsrDataConstructor (&OtherUsrDat);
2014-12-01 23:55:08 +01:00
2017-02-17 01:59:58 +01:00
/***** Get user's data *****/
2019-03-19 13:22:14 +01:00
Usr_GetAllUsrDataFromUsrCod (&OtherUsrDat,Usr_DONT_GET_PREFS);
2014-12-01 23:55:08 +01:00
2017-02-17 01:59:58 +01:00
UsrDat = &OtherUsrDat;
}
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 00:26:14 +02:00
/***** Show photo *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CON_PHOTO COLOR%u\"",Gbl.RowEvenOdd);
2017-02-17 01:59:58 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO21x28",Pho_ZOOM,true);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write full name and link *****/
2019-11-18 20:12:10 +01:00
if (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].ThisCrs)
{
ClassTxt = "CON_NAME_NARROW CON_CRS";
ClassLink = "BT_LINK CON_NAME_NARROW CON_CRS";
}
else
{
ClassTxt = "CON_NAME_NARROW CON_NO_CRS";
ClassLink = "BT_LINK CON_NAME_NARROW CON_NO_CRS";
}
HTM_TD_Begin ("class=\"%s COLOR%u\"",ClassTxt,Gbl.RowEvenOdd);
2017-05-20 12:04:12 +02:00
// The form must be unique because
// the list of connected users
// is dynamically updated via AJAX
switch (Role)
{
case Rol_STD:
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeRecOneStd);
2017-05-20 12:04:12 +02:00
break;
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-20 12:04:12 +02:00
case Rol_TCH:
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeRecOneTch);
2017-05-20 12:04:12 +02:00
break;
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2017-05-31 10:51:29 +02:00
break;
2017-05-20 12:04:12 +02:00
}
2017-02-17 01:59:58 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CON_NAME_NARROW\""); // Limited width
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_View_record_for_this_course,ClassLink,NULL);
2017-03-05 15:12:48 +01:00
Usr_WriteFirstNameBRSurnames (UsrDat);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 21:37:01 +02:00
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write time from last access *****/
2019-11-18 20:12:10 +01:00
ClassTxt = (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].ThisCrs ? "CON_SINCE CON_CRS" :
"CON_SINCE CON_NO_CRS");
HTM_TD_Begin ("class=\"%s COLOR%u\"",ClassTxt,Gbl.RowEvenOdd);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("id=\"hm%u\"",Gbl.Usrs.Connected.NumUsr); // Used for automatic update, only when displayed on right column
2019-01-11 12:32:41 +01:00
Dat_WriteHoursMinutesSecondsFromSeconds (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].TimeDiff);
2019-10-23 21:37:01 +02:00
HTM_DIV_End (); // Used for automatic update, only when displayed on right column
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-08 15:49:01 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-02-17 01:59:58 +01:00
if (!ItsMe)
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&OtherUsrDat);
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
/******************** Show connected users one by one ************************/
/*****************************************************************************/
static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t Role)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-10-30 14:47:31 +01:00
unsigned NumUsrs = 0; // Initialized to avoid warning
2014-12-01 23:55:08 +01:00
unsigned NumUsr;
bool ThisCrs;
time_t TimeDiff;
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2019-11-19 00:17:23 +01:00
const char *ClassTxt;
const char *ClassLink;
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
2019-04-03 20:57:04 +02:00
bool PutLinkToRecord = (Gbl.Hierarchy.Level == Hie_CRS && // Course selected
Gbl.Scope.Current == Hie_CRS && // Scope is current course
(Role == Rol_STD || // Role is student,...
Role == Rol_NET || // ...non-editing teacher...
Role == Rol_TCH)); // ...or teacher
2014-12-01 23:55:08 +01:00
/***** Get connected users who belong to current location from database *****/
2015-12-19 18:25:44 +01:00
switch (Role)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_GST:
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT UsrCod,LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(LastTime) AS Dif"
" FROM connected"
" WHERE UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY Dif");
2015-12-19 18:25:44 +01:00
break;
2017-05-18 19:13:41 +02:00
case Rol_STD:
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2015-12-19 18:25:44 +01:00
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS: // Show connected users in the whole platform
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM connected,crs_usr"
" WHERE connected.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role=%u"
" ORDER BY Dif",
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY: // Show connected users in the current country
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM institutions,centres,degrees,courses,crs_usr,connected"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS: // Show connected users in the current institution
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM centres,degrees,courses,crs_usr,connected"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR: // Show connected users in the current centre
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM degrees,courses,crs_usr,connected"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG: // Show connected users in the current degree
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM courses,crs_usr,connected"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS: // Show connected users in the current course
2018-10-30 14:47:31 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT connected.UsrCod,connected.LastCrsCod,"
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
" FROM crs_usr,connected"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=connected.UsrCod"
" ORDER BY Dif",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-10-30 14:47:31 +01:00
(unsigned) Role);
2015-12-19 18:25:44 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2015-12-19 18:25:44 +01:00
break;
}
break;
2014-12-01 23:55:08 +01:00
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2014-12-01 23:55:08 +01:00
break;
}
if (NumUsrs)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write list of connected users *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get user's data */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Existing user
2015-03-13 00:16:02 +01:00
{
2015-12-19 18:25:44 +01:00
/* Get course code (row[1]) */
2019-04-03 20:57:04 +02:00
ThisCrs = (Str_ConvertStrCodToLongCod (row[1]) ==
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2015-12-19 18:25:44 +01:00
/* Compute time from last access */
if (sscanf (row[2],"%ld",&TimeDiff) != 1)
TimeDiff = (time_t) 0;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 00:26:14 +02:00
/***** Show photo *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CON_PHOTO COLOR%u\"",Gbl.RowEvenOdd);
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2015-12-19 18:25:44 +01:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO21x28",Pho_ZOOM,false);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-19 18:25:44 +01:00
/***** Write full name and link *****/
2019-11-19 00:17:23 +01:00
if (ThisCrs)
{
ClassTxt = "CON_NAME_WIDE CON_CRS";
ClassLink = "BT_LINK CON_NAME_WIDE CON_CRS";
}
else
{
ClassTxt = "CON_NAME_WIDE CON_NO_CRS";
ClassLink = "BT_LINK CON_NAME_WIDE CON_NO_CRS";
}
HTM_TD_Begin ("class=\"%s COLOR%u\"",ClassTxt,Gbl.RowEvenOdd);
2015-12-19 18:25:44 +01:00
if (PutLinkToRecord)
{
2017-05-20 12:04:12 +02:00
switch (Role)
{
case Rol_STD:
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeRecOneStd);
2017-05-20 12:04:12 +02:00
break;
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-20 12:04:12 +02:00
case Rol_TCH:
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeRecOneTch);
2017-05-20 12:04:12 +02:00
break;
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2017-05-20 12:04:12 +02:00
}
2015-12-19 18:25:44 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
}
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CON_NAME_WIDE\""); // Limited width
2017-03-05 14:46:56 +01:00
if (PutLinkToRecord)
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (UsrDat.FullName,ClassLink,NULL);
2017-03-05 15:12:48 +01:00
Usr_WriteFirstNameBRSurnames (&UsrDat);
2015-12-19 18:25:44 +01:00
if (PutLinkToRecord)
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 21:37:01 +02:00
2017-03-05 14:46:56 +01:00
if (PutLinkToRecord)
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-12-19 18:25:44 +01:00
/***** Write time from last access *****/
2019-11-19 00:17:23 +01:00
ClassTxt = ThisCrs ? "CON_SINCE CON_CRS" :
"CON_SINCE CON_NO_CRS";
HTM_TD_Begin ("class=\"%s COLOR%u\"",ClassTxt,Gbl.RowEvenOdd);
2019-01-11 12:32:41 +01:00
Dat_WriteHoursMinutesSecondsFromSeconds (TimeDiff);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-08 00:26:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2015-12-19 18:25:44 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2014-12-01 23:55:08 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/***** Free structure that stores the query result *****/
2015-03-16 14:05:16 +01:00
DB_FreeMySQLResult (&mysql_res);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****** Write script to automatically update clocks of connected users *******/
/*****************************************************************************/
void Con_WriteScriptClockConnected (void)
{
unsigned NumUsr;
2019-11-11 00:15:44 +01:00
HTM_TxtF ("\tNumUsrsCon = %u;\n",Gbl.Usrs.Connected.NumUsrsToList);
2014-12-01 23:55:08 +01:00
for (NumUsr = 0;
NumUsr < Gbl.Usrs.Connected.NumUsrsToList;
NumUsr++)
2019-11-11 00:15:44 +01:00
HTM_TxtF ("\tListSeconds[%u] = %ld;\n",
NumUsr,Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff);
HTM_Txt ("\twriteClockConnected();\n");
2014-12-01 23:55:08 +01:00
}