Version 15.218.3

This commit is contained in:
Antonio Cañas Vargas 2016-06-04 14:21:01 +02:00
parent 83288f99bc
commit 148d359b6a
7 changed files with 56 additions and 54 deletions

View File

@ -26,7 +26,6 @@
/*****************************************************************************/ /*****************************************************************************/
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale
#include <stdio.h> // For fprintf #include <stdio.h> // For fprintf
#include <stdlib.h> // For malloc and free #include <stdlib.h> // For malloc and free
#include <string.h> // For string functions #include <string.h> // For string functions

View File

@ -133,13 +133,14 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.218.2 (2016-06-04)" #define Log_PLATFORM_VERSION "SWAD 15.218.3 (2016-06-04)"
#define CSS_FILE "swad15.218.css" #define CSS_FILE "swad15.218.css"
#define JS_FILE "swad15.216.js" #define JS_FILE "swad15.216.js"
// 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.218.3: Jun 04, 2016 Code refactoring related to setlocale. (201952 lines)
Version 15.218.2: Jun 04, 2016 Checked value returned by setlocale in all calls. (201957 lines) Version 15.218.2: Jun 04, 2016 Checked value returned by setlocale in all calls. (201957 lines)
Version 15.218.1: Jun 04, 2016 Change in listing of courses. (201934 lines) Version 15.218.1: Jun 04, 2016 Change in listing of courses. (201934 lines)
Version 15.218: Jun 03, 2016 New module swad_MFU for most frequently used actions. Version 15.218: Jun 03, 2016 New module swad_MFU for most frequently used actions.

View File

@ -25,9 +25,9 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#include <locale.h> // For setlocale
#include <limits.h> // For INT_MAX, LONG_MAX #include <limits.h> // For INT_MAX, LONG_MAX
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale
#include <stdlib.h> // For exit, system, malloc, calloc, free, etc #include <stdlib.h> // For exit, system, malloc, calloc, free, etc
#include <string.h> // For string functions #include <string.h> // For string functions
#include <sys/time.h> // For gettimeofday #include <sys/time.h> // For gettimeofday
@ -83,7 +83,12 @@ void Gbl_InitializeGlobals (void)
extern const unsigned Txt_Current_CGI_SWAD_Language; extern const unsigned Txt_Current_CGI_SWAD_Language;
Txt_Language_t Lan; Txt_Language_t Lan;
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) Gbl.Layout.WritingHTMLStart =
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = false;
if (!setlocale (LC_ALL,"es_ES.utf8")) // TODO: this should be internationalized!!!!!!!
exit (1); exit (1);
gettimeofday (&Gbl.tvStart, &Gbl.tz); gettimeofday (&Gbl.tvStart, &Gbl.tz);
@ -116,11 +121,6 @@ void Gbl_InitializeGlobals (void)
Gbl.Error = false; Gbl.Error = false;
Gbl.Layout.WritingHTMLStart =
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = false;
Gbl.DB.DatabaseIsOpen = false; Gbl.DB.DatabaseIsOpen = false;
Gbl.DB.LockedTables = false; Gbl.DB.LockedTables = false;

View File

@ -867,12 +867,10 @@ float Str_GetFloatNumFromStr (const char *Str)
if (Str) if (Str)
{ {
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (Str,"%f",&Num) != 1) if (sscanf (Str,"%f",&Num) != 1)
Lay_ShowErrorAndExit ("Bad floating point format."); Lay_ShowErrorAndExit ("Bad floating point format.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
} }
else // Str == NULL else // Str == NULL
Num = 0.0; Num = 0.0;
@ -880,6 +878,29 @@ float Str_GetFloatNumFromStr (const char *Str)
return Num; return Num;
} }
/*****************************************************************************/
/**** Change decimal point to US system in order to get/print it as a dot ****/
/*****************************************************************************/
void Str_SetDecimalPointToUS (void)
{
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get/print the floating point as a dot
if (Gbl.Layout.HTMLStartWritten)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
}
/*****************************************************************************/
/****************** Change decimal point to local system *********************/
/*****************************************************************************/
void Str_SetDecimalPointToLocal (void)
{
// TODO: this should be internationalized!!!!!!!
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to local system
if (Gbl.Layout.HTMLStartWritten)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
}
/*****************************************************************************/ /*****************************************************************************/
/*************** Add a string to a Query, changing ' for &#39; ***************/ /*************** Add a string to a Query, changing ' for &#39; ***************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -79,6 +79,8 @@ char Str_ConvertToLowerLetter (char Ch);
void Str_WriteFloatNum (float Number); void Str_WriteFloatNum (float Number);
void Str_ConvertStrFloatCommaToStrFloatPoint (char *Str); void Str_ConvertStrFloatCommaToStrFloatPoint (char *Str);
float Str_GetFloatNumFromStr (const char *Str); float Str_GetFloatNumFromStr (const char *Str);
void Str_SetDecimalPointToUS (void);
void Str_SetDecimalPointToLocal (void);
void Str_AddStrToQuery (char *Query,const char *Str,size_t SizeOfQuery); void Str_AddStrToQuery (char *Query,const char *Str,size_t SizeOfQuery);
void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo, void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,

View File

@ -28,7 +28,6 @@
#include <limits.h> // For UINT_MAX #include <limits.h> // For UINT_MAX
#include <linux/limits.h> // For PATH_MAX #include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale, LC_NUMERIC...
#include <mysql/mysql.h> // To access MySQL databases #include <mysql/mysql.h> // To access MySQL databases
#include <stdbool.h> // For boolean type #include <stdbool.h> // For boolean type
#include <stdio.h> // For fprintf, etc. #include <stdio.h> // For fprintf, etc.
@ -1172,7 +1171,7 @@ static void Tst_UpdateScoreQst (long QstCod,float ScoreThisQst,bool AnswerIsNotB
char Query[512]; char Query[512];
/***** Update number of clicks and score of the question *****/ /***** Update number of clicks and score of the question *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US."); Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (AnswerIsNotBlank) if (AnswerIsNotBlank)
sprintf (Query,"UPDATE tst_questions" sprintf (Query,"UPDATE tst_questions"
@ -1184,8 +1183,7 @@ static void Tst_UpdateScoreQst (long QstCod,float ScoreThisQst,bool AnswerIsNotB
" SET NumHits=NumHits+1" " SET NumHits=NumHits+1"
" WHERE QstCod='%ld'", " WHERE QstCod='%ld'",
QstCod); QstCod);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
DB_QueryUPDATE (Query,"can not update the score of a question"); DB_QueryUPDATE (Query,"can not update the score of a question");
} }
@ -2844,12 +2842,10 @@ static void Tst_ListOneOrMoreQuestionsToEdit (unsigned long NumRows,MYSQL_RES *m
Lay_ShowErrorAndExit ("Wrong number of hits not blank to a question."); Lay_ShowErrorAndExit ("Wrong number of hits not blank to a question.");
/* Get the acumulated score of the question (row[11]) */ /* Get the acumulated score of the question (row[11]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (row[11],"%lf",&TotalScoreThisQst) != 1) if (sscanf (row[11],"%lf",&TotalScoreThisQst) != 1)
Lay_ShowErrorAndExit ("Wrong score of a question."); Lay_ShowErrorAndExit ("Wrong score of a question.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
/* Write number of times this question has been answered */ /* Write number of times this question has been answered */
fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL CENTER_TOP COLOR%u\">" fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL CENTER_TOP COLOR%u\">"
@ -5626,15 +5622,13 @@ double Tst_GetFloatAnsFromStr (char *Str)
Str_ConvertStrFloatCommaToStrFloatPoint (Str); Str_ConvertStrFloatCommaToStrFloatPoint (Str);
/***** The string is "scanned" in floating point (it must have a point, not a colon as decimal separator) *****/ /***** The string is "scanned" in floating point (it must have a point, not a colon as decimal separator) *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (Str,"%lg",&DoubleNum) != 1) // If the string does not hold a valid floating point number... if (sscanf (Str,"%lg",&DoubleNum) != 1) // If the string does not hold a valid floating point number...
{ {
DoubleNum = 0.0; // ...the number is reset to 0 DoubleNum = 0.0; // ...the number is reset to 0
Str[0] = '\0'; // ...and the string is reset to "" Str[0] = '\0'; // ...and the string is reset to ""
} }
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
return DoubleNum; return DoubleNum;
} }
@ -6052,8 +6046,7 @@ static void Tst_InsertAnswersIntoDB (void)
DB_QueryINSERT (Query,"can not create answer"); DB_QueryINSERT (Query,"can not create answer");
break; break;
case Tst_ANS_FLOAT: case Tst_ANS_FLOAT:
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
for (i = 0; for (i = 0;
i < 2; i < 2;
i++) i++)
@ -6066,8 +6059,7 @@ static void Tst_InsertAnswersIntoDB (void)
Gbl.Test.Answer.FloatingPoint[i]); Gbl.Test.Answer.FloatingPoint[i]);
DB_QueryINSERT (Query,"can not create answer"); DB_QueryINSERT (Query,"can not create answer");
} }
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
break; break;
case Tst_ANS_TRUE_FALSE: case Tst_ANS_TRUE_FALSE:
sprintf (Query,"INSERT INTO tst_answers" sprintf (Query,"INSERT INTO tst_answers"
@ -6490,12 +6482,10 @@ static unsigned Tst_GetNumTstQuestions (Sco_Scope_t Scope,Tst_AnswerType_t AnsTy
if (sscanf (row[1],"%lu",&(Stats->NumHits)) != 1) if (sscanf (row[1],"%lu",&(Stats->NumHits)) != 1)
Lay_ShowErrorAndExit ("Error when getting total number of hits in test questions."); Lay_ShowErrorAndExit ("Error when getting total number of hits in test questions.");
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (row[2],"%lf",&(Stats->TotalScore)) != 1) if (sscanf (row[2],"%lf",&(Stats->TotalScore)) != 1)
Lay_ShowErrorAndExit ("Error when getting total score in test questions."); Lay_ShowErrorAndExit ("Error when getting total score in test questions.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
} }
else else
{ {
@ -6948,15 +6938,13 @@ static void Tst_StoreScoreOfTestExamInDB (long TstCod,
char Query[256]; char Query[256];
/***** Update score in test exam *****/ /***** Update score in test exam *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
sprintf (Query,"UPDATE tst_exams" sprintf (Query,"UPDATE tst_exams"
" SET NumQstsNotBlank='%u',Score='%lf'" " SET NumQstsNotBlank='%u',Score='%lf'"
" WHERE TstCod='%ld'", " WHERE TstCod='%ld'",
NumQstsNotBlank,Score, NumQstsNotBlank,Score,
TstCod); TstCod);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
DB_QueryUPDATE (Query,"can not update result of test exam"); DB_QueryUPDATE (Query,"can not update result of test exam");
} }
@ -7186,8 +7174,7 @@ static void Tst_ShowResultsOfTestExams (struct UsrData *UsrDat)
NumQstsNotBlankInThisExam = 0; NumQstsNotBlankInThisExam = 0;
/* Get score (row[5]) */ /* Get score (row[5]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (row[5],"%lf",&ScoreInThisExam) == 1) if (sscanf (row[5],"%lf",&ScoreInThisExam) == 1)
{ {
if (Gbl.Test.AllowTeachers) if (Gbl.Test.AllowTeachers)
@ -7195,8 +7182,7 @@ static void Tst_ShowResultsOfTestExams (struct UsrData *UsrDat)
} }
else else
ScoreInThisExam = 0.0; ScoreInThisExam = 0.0;
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
/* Write number of questions */ /* Write number of questions */
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP COLOR%u\">", fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP COLOR%u\">",
@ -7701,12 +7687,10 @@ static void Tst_GetExamDataByTstCod (long TstCod,time_t *TstTimeUTC,
*NumQstsNotBlank = 0; *NumQstsNotBlank = 0;
/* Get score (row[5]) */ /* Get score (row[5]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point Str_SetDecimalPointToUS (); // To get the decimal point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (sscanf (row[5],"%lf",Score) != 1) if (sscanf (row[5],"%lf",Score) != 1)
*Score = 0.0; *Score = 0.0;
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -7729,8 +7713,7 @@ static void Tst_StoreOneExamQstInDB (long TstCod,long QstCod,unsigned NumQst,dou
Par_ReplaceSeparatorMultipleByComma (Gbl.Test.StrAnswersOneQst[NumQst],Answers); Par_ReplaceSeparatorMultipleByComma (Gbl.Test.StrAnswersOneQst[NumQst],Answers);
/***** Insert question and user's answers into database *****/ /***** Insert question and user's answers into database *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
sprintf (Query,"INSERT INTO tst_exam_questions" sprintf (Query,"INSERT INTO tst_exam_questions"
" (TstCod,QstCod,QstInd,Score,Indexes,Answers)" " (TstCod,QstCod,QstInd,Score,Indexes,Answers)"
" VALUES ('%ld','%ld','%u','%lf','%s','%s')", " VALUES ('%ld','%ld','%u','%lf','%s','%s')",
@ -7739,8 +7722,7 @@ static void Tst_StoreOneExamQstInDB (long TstCod,long QstCod,unsigned NumQst,dou
Score, Score,
Indexes, Indexes,
Answers); Answers);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
DB_QueryINSERT (Query,"can not insert a question of an exam"); DB_QueryINSERT (Query,"can not insert a question of an exam");
} }

View File

@ -94,7 +94,6 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/
#include <dirent.h> // For scandir, etc. #include <dirent.h> // For scandir, etc.
#include <linux/limits.h> // For PATH_MAX #include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale, LC_NUMERIC...
#include <sys/stat.h> // For lstat #include <sys/stat.h> // For lstat
#include <string.h> #include <string.h>
#include <stdsoap2.h> #include <stdsoap2.h>
@ -3736,8 +3735,7 @@ int swad__getTrivialQuestion (struct soap *soap,
"lowerScore or upperScore values not valid"); "lowerScore or upperScore values not valid");
/***** Start query *****/ /***** Start query *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
sprintf (Query,"SELECT DISTINCTROW tst_questions.QstCod," sprintf (Query,"SELECT DISTINCTROW tst_questions.QstCod,"
"tst_questions.AnsType,tst_questions.Shuffle," "tst_questions.AnsType,tst_questions.Shuffle,"
"tst_questions.Stem,tst_questions.Feedback," "tst_questions.Stem,tst_questions.Feedback,"
@ -3758,8 +3756,7 @@ int swad__getTrivialQuestion (struct soap *soap,
" ORDER BY RAND(NOW()) LIMIT 1", " ORDER BY RAND(NOW()) LIMIT 1",
DegreesStr,DegreesStr, DegreesStr,DegreesStr,
lowerScore,upperScore); lowerScore,upperScore);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!) Str_SetDecimalPointToLocal (); // Return to local system
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test questions"); NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test questions");