Version 15.25

This commit is contained in:
Antonio Cañas Vargas 2015-10-26 22:34:29 +01:00
parent 9ffcc6b19c
commit 26ba7642ef
4 changed files with 86 additions and 89 deletions

View File

@ -108,11 +108,12 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.24.2 (2015/10/26)" #define Log_PLATFORM_VERSION "SWAD 15.25 (2015/10/26)"
// Number of lines (includes comments but not blank lines) has been got with the following command: // 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 // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/* /*
Version 15.25: Oct 26, 2015 Clicks in real time are displayed as time ago. (186211 lines)
Version 15.24.2: Oct 26, 2015 Change in function that write clock. (186219 lines) Version 15.24.2: Oct 26, 2015 Change in function that write clock. (186219 lines)
Version 15.24.1: Oct 26, 2015 Remove unused code related to date-times. (186217 lines) Version 15.24.1: Oct 26, 2015 Remove unused code related to date-times. (186217 lines)
Version 15.24: Oct 26, 2015 Lot of changes in swad.js related to date-times. (186336 lines) Version 15.24: Oct 26, 2015 Lot of changes in swad.js related to date-times. (186336 lines)

View File

@ -63,6 +63,7 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role
static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Role); static void Con_ShowConnectedUsrsCurrentCrsOneByOneOnRightColumn (Rol_Role_t Role);
static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role); static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role);
static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t Role); static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t Role);
static void Con_WriteHoursMinutesSecondsFromSeconds (time_t Seconds);
/*****************************************************************************/ /*****************************************************************************/
/************************** Show connected users *****************************/ /************************** Show connected users *****************************/
@ -171,7 +172,7 @@ void Con_GetAndShowLastClicks (void)
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS]; extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
extern Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD]; extern Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD];
extern const char *Txt_Click; extern const char *Txt_Click;
extern const char *Txt_Hour; extern const char *Txt_ELAPSED_TIME;
extern const char *Txt_Role; extern const char *Txt_Role;
extern const char *Txt_Country; extern const char *Txt_Country;
extern const char *Txt_Institution; extern const char *Txt_Institution;
@ -186,6 +187,7 @@ void Con_GetAndShowLastClicks (void)
unsigned NumRows; unsigned NumRows;
long ActCod; long ActCod;
const char *ClassRow; const char *ClassRow;
time_t TimeDiff;
struct Country Cty; struct Country Cty;
struct Institution Ins; struct Institution Ins;
struct Centre Ctr; struct Centre Ctr;
@ -194,25 +196,25 @@ void Con_GetAndShowLastClicks (void)
/***** Get last clicks from database *****/ /***** Get last clicks from database *****/
/* Important for maximum performance: /* Important for maximum performance:
do the LIMIT in the big log table before the JOIN */ do the LIMIT in the big log table before the JOIN */
sprintf (Query,"SELECT last_logs.LogCod,last_logs.ActCod,last_logs.T,last_logs.Role," sprintf (Query,"SELECT last_logs.LogCod,last_logs.ActCod,last_logs.Dif,last_logs.Role,"
"last_logs.CtyCod,last_logs.InsCod,last_logs.CtrCod,last_logs.DegCod,actions.Txt" "last_logs.CtyCod,last_logs.InsCod,last_logs.CtrCod,last_logs.DegCod,actions.Txt"
" FROM" " FROM"
" (SELECT LogCod,ActCod,DATE_FORMAT(ClickTime,'%%H:%%i:%%S') AS T,Role,CtyCod,InsCod,CtrCod,DegCod" " (SELECT LogCod,ActCod,UNIX_TIMESTAMP()-UNIX_TIMESTAMP(ClickTime) AS Dif,Role,CtyCod,InsCod,CtrCod,DegCod"
" FROM log_recent ORDER BY LogCod DESC LIMIT 20)" " FROM log_recent ORDER BY LogCod DESC LIMIT 20)"
" AS last_logs,actions" " AS last_logs,actions"
" WHERE last_logs.ActCod=actions.ActCod AND actions.Language='es'"); " WHERE last_logs.ActCod=actions.ActCod AND actions.Language='es'");
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get last clicks"); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get last clicks");
/***** Write list of connected users *****/ /***** Write list of connected users *****/
fprintf (Gbl.F.Out,"<table class=\"TABLE10\">" fprintf (Gbl.F.Out,"<table class=\"CELLS_PAD_2\">"
"<tr>" "<tr>"
"<th class=\"LEFT_MIDDLE\"" "<th class=\"LEFT_MIDDLE\""
" style=\"width:85px;\">" " style=\"width:85px;\">"
"%s" // Click "%s" // Click
"</th>" "</th>"
"<th class=\"LEFT_MIDDLE\"" "<th class=\"RIGHT_MIDDLE\""
" style=\"width:70px;\">" " style=\"width:50px;\">"
"%s" // Hour "%s" // Elapsed time
"</th>" "</th>"
"<th class=\"LEFT_MIDDLE\"" "<th class=\"LEFT_MIDDLE\""
" style=\"width:100px;\">" " style=\"width:100px;\">"
@ -240,7 +242,7 @@ void Con_GetAndShowLastClicks (void)
"</th>" "</th>"
"</tr>", "</tr>",
Txt_Click, Txt_Click,
Txt_Hour, Txt_ELAPSED_TIME,
Txt_Role, Txt_Role,
Txt_Country, Txt_Country,
Txt_Institution, Txt_Institution,
@ -260,10 +262,15 @@ void Con_GetAndShowLastClicks (void)
/* Use a special color for this row depending on the action */ /* Use a special color for this row depending on the action */
ClassRow = (Act_Actions[Act_FromActCodToAction[ActCod]].BrowserWindow == Act_DOWNLD_FILE) ? "DAT_SMALL_YELLOW LEFT_MIDDLE" : ClassRow = (Act_Actions[Act_FromActCodToAction[ActCod]].BrowserWindow == Act_DOWNLD_FILE) ? "DAT_SMALL_YELLOW LEFT_MIDDLE" :
(ActCod == Act_Actions[ActAutUsrInt].ActCod || (ActCod == Act_Actions[ActAutUsrInt].ActCod ||
ActCod == Act_Actions[ActAutUsrExt].ActCod) ? "DAT_SMALL_GREEN LEFT_MIDDLE" : ActCod == Act_Actions[ActAutUsrExt].ActCod) ? "DAT_SMALL_GREEN" :
(ActCod == Act_Actions[ActLogOut].ActCod ) ? "DAT_SMALL_RED LEFT_MIDDLE" : (ActCod == Act_Actions[ActLogOut].ActCod ) ? "DAT_SMALL_RED" :
(ActCod == Act_Actions[ActWebSvc].ActCod ) ? "DAT_SMALL_BLUE LEFT_MIDDLE" : (ActCod == Act_Actions[ActWebSvc].ActCod ) ? "DAT_SMALL_BLUE" :
"DAT_SMALL_GREY LEFT_MIDDLE"; "DAT_SMALL_GREY";
/* Compute elapsed time from last access */
if (sscanf (row[2],"%ld",&TimeDiff) != 1)
TimeDiff = (time_t) 0;
/* Get degree code (row[4]) */ /* Get degree code (row[4]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[4]); Cty.CtyCod = Str_ConvertStrCodToLongCod (row[4]);
Cty_GetCountryName (Cty.CtyCod,Cty.Name[Gbl.Prefs.Language]); Cty_GetCountryName (Cty.CtyCod,Cty.Name[Gbl.Prefs.Language]);
@ -282,33 +289,34 @@ void Con_GetAndShowLastClicks (void)
/* Print table row */ /* Print table row */
fprintf (Gbl.F.Out,"<tr>" fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Click "%s" // Click
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s RIGHT_MIDDLE\">" // Elapsed time
"%s" // Hour "",
ClassRow,row[0],
ClassRow);
Con_WriteHoursMinutesSecondsFromSeconds (TimeDiff);
fprintf (Gbl.F.Out,"</td>"
"<td class=\"%s LEFT_MIDDLE\">"
"%s" // Role
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Role "%s" // Country
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Country "%s" // Institution
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Institution "%s" // Centre
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Centre "%s" // Degree
"</td>" "</td>"
"<td class=\"%s\">" "<td class=\"%s LEFT_MIDDLE\">"
"%s" // Degree "%s" // Action
"</td>"
"<td class=\"%s\">"
"%s" // Action
"</td>" "</td>"
"</tr>", "</tr>",
ClassRow,row[0],
ClassRow,row[2],
ClassRow,Txt_ROLES_SINGUL_Abc[Rol_ConvertUnsignedStrToRole (row[3])][Usr_SEX_UNKNOWN], ClassRow,Txt_ROLES_SINGUL_Abc[Rol_ConvertUnsignedStrToRole (row[3])][Usr_SEX_UNKNOWN],
ClassRow,Cty.Name[Gbl.Prefs.Language], ClassRow,Cty.Name[Gbl.Prefs.Language],
ClassRow,Ins.ShortName, ClassRow,Ins.ShortName,
@ -982,7 +990,6 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
time_t TimeDiff;
/***** Get connected users who belong to current course from database *****/ /***** Get connected users who belong to current course from database *****/
sprintf (Query,"SELECT connected.UsrCod,connected.LastCrsCod," sprintf (Query,"SELECT connected.UsrCod,connected.LastCrsCod,"
@ -1011,10 +1018,9 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role
/* Get course code (row[1]) */ /* Get course code (row[1]) */
Gbl.Usrs.Connected.Lst[NumUsr].ThisCrs = (Str_ConvertStrCodToLongCod (row[1]) == Gbl.CurrentCrs.Crs.CrsCod); Gbl.Usrs.Connected.Lst[NumUsr].ThisCrs = (Str_ConvertStrCodToLongCod (row[1]) == Gbl.CurrentCrs.Crs.CrsCod);
/* Compute time from last access */ /* Compute elapsed time from last access */
Gbl.Usrs.Connected.Lst[NumUsr].Seconds = 0; if (sscanf (row[2],"%ld",&Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff) != 1)
if (sscanf (row[2],"%ld",&TimeDiff) == 1) Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff = (time_t) 0;
Gbl.Usrs.Connected.Lst[NumUsr].Seconds = (unsigned) TimeDiff;
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -1047,9 +1053,6 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role)
const char *Font = (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].ThisCrs ? "CON_CRS" : const char *Font = (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].ThisCrs ? "CON_CRS" :
"CON"); "CON");
struct UsrData UsrDat; struct UsrData UsrDat;
unsigned Hours;
unsigned Minutes;
unsigned Seconds;
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
@ -1097,21 +1100,7 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role)
fprintf (Gbl.F.Out,"<div id=\"hm%u\">", fprintf (Gbl.F.Out,"<div id=\"hm%u\">",
Gbl.Usrs.Connected.NumUsr); // Used for automatic update, only when displayed on right column Gbl.Usrs.Connected.NumUsr); // Used for automatic update, only when displayed on right column
Hours = Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].Seconds / (60*60); Con_WriteHoursMinutesSecondsFromSeconds (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].TimeDiff);
Minutes = (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].Seconds / 60) % 60;
Seconds = Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].Seconds % 60;
if (Hours)
fprintf (Gbl.F.Out,"%u:%02u'%02u&quot;",
Hours,
Minutes,
Seconds);
else if (Minutes)
fprintf (Gbl.F.Out,"%u'%02u&quot;",
Minutes,
Seconds);
else
fprintf (Gbl.F.Out,"%u&quot;",
Seconds);
fprintf (Gbl.F.Out,"</div>"); // Used for automatic update, only when displayed on right column fprintf (Gbl.F.Out,"</div>"); // Used for automatic update, only when displayed on right column
fprintf (Gbl.F.Out,"</td>" fprintf (Gbl.F.Out,"</td>"
@ -1140,9 +1129,6 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
char PhotoURL[PATH_MAX+1]; char PhotoURL[PATH_MAX+1];
const char *Font; const char *Font;
struct UsrData UsrDat; struct UsrData UsrDat;
unsigned Hours;
unsigned Minutes;
unsigned Seconds;
bool PutLinkToRecord = (Gbl.CurrentCrs.Crs.CrsCod > 0 && bool PutLinkToRecord = (Gbl.CurrentCrs.Crs.CrsCod > 0 &&
Gbl.Scope.Current == Sco_SCOPE_CRS); Gbl.Scope.Current == Sco_SCOPE_CRS);
@ -1251,9 +1237,8 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
"CON"); "CON");
/* Compute time from last access */ /* Compute time from last access */
Seconds = 0; if (sscanf (row[2],"%ld",&TimeDiff) != 1)
if (sscanf (row[2],"%ld",&TimeDiff) == 1) TimeDiff = (time_t) 0;
Seconds = (unsigned) TimeDiff;
/***** Show photo *****/ /***** Show photo *****/
fprintf (Gbl.F.Out,"<tr>" fprintf (Gbl.F.Out,"<tr>"
@ -1289,21 +1274,7 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE COLOR%u\"" fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_MIDDLE COLOR%u\""
" style=\"width:48px;\">", " style=\"width:48px;\">",
Font,Gbl.RowEvenOdd); Font,Gbl.RowEvenOdd);
Hours = Seconds / (60 * 60); Con_WriteHoursMinutesSecondsFromSeconds (TimeDiff);
Minutes = (Seconds / 60) % 60;
Seconds %= 60;
if (Hours)
fprintf (Gbl.F.Out,"%u:%02u'%02u&quot;",
Hours,
Minutes,
Seconds);
else if (Minutes)
fprintf (Gbl.F.Out,"%u'%02u&quot;",
Minutes,
Seconds);
else
fprintf (Gbl.F.Out,"%u&quot;",
Seconds);
fprintf (Gbl.F.Out,"</td>" fprintf (Gbl.F.Out,"</td>"
"</tr>"); "</tr>");
@ -1318,6 +1289,31 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/
/********* Write time difference in seconds as hours:minutes:seconds *********/
/*****************************************************************************/
// TimeDiff must be in seconds
static void Con_WriteHoursMinutesSecondsFromSeconds (time_t Seconds)
{
time_t Hours = Seconds / (60*60);
time_t Minutes = (Seconds / 60) % 60;
Seconds %= 60;
if (Hours)
fprintf (Gbl.F.Out,"%ld:%02ld'%02ld&quot;",
(long) Hours,
(long) Minutes,
(long) Seconds);
else if (Minutes)
fprintf (Gbl.F.Out,"%ld'%02ld&quot;",
(long) Minutes,
(long) Seconds);
else
fprintf (Gbl.F.Out,"%ld&quot;",
(long) Seconds);
}
/*****************************************************************************/ /*****************************************************************************/
/****** Write script to automatically update clocks of connected users *******/ /****** Write script to automatically update clocks of connected users *******/
/*****************************************************************************/ /*****************************************************************************/
@ -1331,7 +1327,7 @@ void Con_WriteScriptClockConnected (void)
for (NumUsr = 0; for (NumUsr = 0;
NumUsr < Gbl.Usrs.Connected.NumUsrsToList; NumUsr < Gbl.Usrs.Connected.NumUsrsToList;
NumUsr++) NumUsr++)
fprintf (Gbl.F.Out," ListSeconds[%u] = %u;\n", fprintf (Gbl.F.Out," ListSeconds[%u] = %ld;\n",
NumUsr,Gbl.Usrs.Connected.Lst[NumUsr].Seconds); NumUsr,Gbl.Usrs.Connected.Lst[NumUsr].TimeDiff);
fprintf (Gbl.F.Out," writeClockConnected();\n"); fprintf (Gbl.F.Out," writeClockConnected();\n");
} }

View File

@ -376,7 +376,7 @@ struct Globals
{ {
long UsrCod; long UsrCod;
bool ThisCrs; bool ThisCrs;
unsigned Seconds; time_t TimeDiff;
} Lst[Cfg_MAX_CONNECTED_SHOWN]; } Lst[Cfg_MAX_CONNECTED_SHOWN];
} Connected; } Connected;
char FileNamePhoto[NAME_MAX+1]; // File name (with no path and no .jpg) of the temporary file with the selected face char FileNamePhoto[NAME_MAX+1]; // File name (with no path and no .jpg) of the temporary file with the selected face

View File

@ -13271,25 +13271,25 @@ const char *Txt_Home_PAGE =
"Home"; "Home";
#endif #endif
const char *Txt_Hour = const char *Txt_ELAPSED_TIME =
#if L==0 #if L==0
"Hora"; "Fa";
#elif L==1 #elif L==1
"Stunde"; "Vor";
#elif L==2 #elif L==2
"Hour"; "Ago";
#elif L==3 #elif L==3
"Hora"; "Hace";
#elif L==4 #elif L==4
"Heure"; "Y a";
#elif L==5 #elif L==5
"Aravo"; "Hace"; // Okoteve traducción
#elif L==6 #elif L==6
"Ora"; "Fa";
#elif L==7 #elif L==7
"Godzina"; "Temu";
#elif L==8 #elif L==8
"Hora"; "Atr&aacute;s";
#endif #endif
const char *Txt_hour = const char *Txt_hour =