From ed6b24d1e47cb8d53d1fb19a0bf7f39d86e6511b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 16 Jun 2016 19:30:29 +0200 Subject: [PATCH] Version 15.225.16 --- swad_account.c | 1 + swad_action.c | 4 ++ swad_action.h | 7 +-- swad_changelog.h | 6 ++- swad_duplicate.c | 129 +++++++++++++++++++++++++++++++++++++++++++--- swad_duplicate.h | 1 + swad_enrollment.c | 1 + swad_user.c | 1 + swad_user.h | 5 -- 9 files changed, 140 insertions(+), 15 deletions(-) diff --git a/swad_account.c b/swad_account.c index c4f4685d6..b652b16c2 100644 --- a/swad_account.c +++ b/swad_account.c @@ -31,6 +31,7 @@ #include "swad_announcement.h" #include "swad_calendar.h" #include "swad_database.h" +#include "swad_duplicate.h" #include "swad_enrollment.h" #include "swad_follow.h" #include "swad_global.h" diff --git a/swad_action.c b/swad_action.c index 2ef0e575a..0ad2e6d48 100644 --- a/swad_action.c +++ b/swad_action.c @@ -41,6 +41,7 @@ #include "swad_chat.h" #include "swad_database.h" #include "swad_degree_type.h" +#include "swad_duplicate.h" #include "swad_exam.h" #include "swad_enrollment.h" #include "swad_follow.h" @@ -1056,6 +1057,7 @@ Users: 883. ActRemOldUsr Eliminate completely old users NEW. ActLstDupUsr List possible duplicate users + NEW. ActLstSimUsr List users similar to a given one (possible duplicates) 884. ActLstClk List last clicks in real time Social: @@ -2452,6 +2454,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActRemOldUsr */{ 773,-1,TabUsr,ActLstOth ,0x100,0x100,0x100,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_RemoveOldUsrs ,NULL}, /* ActLstDupUsr */{1578,-1,TabUsr,ActLstOth ,0x100,0x100,0x100,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Dup_ListDuplicateUsrs ,NULL}, + /* ActLstSimUsr */{1579,-1,TabUsr,ActLstOth ,0x100,0x100,0x100,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Dup_ListSimilarUsrs ,NULL}, /* ActLstClk */{ 989,-1,TabUsr,ActLstCon ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Con_ShowLastClicks ,NULL}, @@ -4417,6 +4420,7 @@ Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD] = // Do not reuse uniq ActReqRemTchPho, // #1576 ActReqRemMyPho, // #1577 ActLstDupUsr, // #1578 + ActLstSimUsr, // #1579 }; /*****************************************************************************/ diff --git a/swad_action.h b/swad_action.h index 7e60252bd..8a23e8610 100644 --- a/swad_action.h +++ b/swad_action.h @@ -72,9 +72,9 @@ typedef enum typedef int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action -#define Act_NUM_ACTIONS (1+9+51+15+90+70+67+246+186+154+172+36+28+84) +#define Act_NUM_ACTIONS (1+9+51+15+90+70+67+246+186+155+172+36+28+84) -#define Act_MAX_ACTION_COD 1578 +#define Act_MAX_ACTION_COD 1579 #define Act_MAX_OPTIONS_IN_MENU_PER_TAB 20 @@ -1095,8 +1095,9 @@ typedef int Act_Action_t; // Must be a signed type, because -1 is used to indica #define ActRemOldUsr (ActChgNumRowFooGrp+152) #define ActLstDupUsr (ActChgNumRowFooGrp+153) +#define ActLstSimUsr (ActChgNumRowFooGrp+154) -#define ActLstClk (ActChgNumRowFooGrp+154) +#define ActLstClk (ActChgNumRowFooGrp+155) /*****************************************************************************/ /******************************** Social tab *********************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 644d2cb6b..b8ce3aa84 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -128,13 +128,17 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.225.15 (2016-06-16)" +#define Log_PLATFORM_VERSION "SWAD 15.225.16 (2016-06-16)" #define CSS_FILE "swad15.225.11.css" #define JS_FILE "swad15.216.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 15.225.16:Jun 16, 2016 New action to show similar users. Not finished. (202887 lines) + 1 change necessary in database: +INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1579','es','N','Listar usuarios similares'); + Version 15.225.15:Jun 16, 2016 Button in possible duplicate user to show similar users. (202781 lines) Version 15.225.14:Jun 16, 2016 Code refactoring in listing of users. (202741 lines) Version 15.225.13:Jun 16, 2016 Check if a user in listing of possible duplicate users has accepted all his/her courses. (202790 lines) diff --git a/swad_duplicate.c b/swad_duplicate.c index b151ef64d..e8df9c20e 100644 --- a/swad_duplicate.c +++ b/swad_duplicate.c @@ -25,16 +25,12 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -// #include // For isalnum, isdigit, etc. -// #include // For maximum values -// #include // For PATH_MAX // #include // For NULL // #include // For exit, system, malloc, free, rand, etc. // #include // For string functions -// #include // For the macro WEXITSTATUS -// #include // For access, lstat, getpid, chdir, symlink, unlink #include "swad_database.h" +#include "swad_duplicate.h" #include "swad_global.h" #include "swad_layout.h" #include "swad_role.h" @@ -202,7 +198,128 @@ void Dup_ListDuplicateUsrs (void) Gbl.RowEvenOdd, Usr_NUM_MAIN_FIELDS_DATA_USR-2, Gbl.RowEvenOdd); - Act_FormStart (ActLstDupUsr); // TODO: Change to new action + Act_FormStart (ActLstSimUsr); + Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod); + Lay_PutConfirmButtonInline (Txt_Similar_users); + Act_FormEnd (); + fprintf (Gbl.F.Out,"" + ""); + + /* Write all the courses this user belongs to */ + Crs_GetAndWriteCrssOfAUsr (&UsrDat,Rol_TEACHER); + Crs_GetAndWriteCrssOfAUsr (&UsrDat,Rol_STUDENT); + + Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; + } + else // User does not exists ==> + // remove user from table of possible duplicate users + Dup_RemoveUsrFromDuplicated (UsrDat.UsrCod); + } + + /***** End table *****/ + fprintf (Gbl.F.Out,""); + + /***** Free memory used for user's data *****/ + Usr_UsrDataDestructor (&UsrDat); + } + else // There are no users + Lay_ShowAlert (Lay_INFO,Txt_No_users_found[Rol_UNKNOWN]); + + /***** End frame *****/ + Lay_EndRoundFrame (); + } + +/*****************************************************************************/ +/********************* List similar users to a given one *********************/ +/*****************************************************************************/ + +// TODO: Write the code of this function + +void Dup_ListSimilarUsrs (void) + { + extern const char *Txt_Possibly_duplicate_users; + extern const char *Txt_Informants; + extern const char *Txt_Similar_users; + extern const char *Txt_No_users_found[Rol_NUM_ROLES]; + char Query[1024]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumUsrs; + unsigned NumUsr; + struct UsrData UsrDat; + unsigned NumInformants; + + /***** Start frame with list of possible duplicate users *****/ + Lay_StartRoundFrame (NULL,Txt_Possibly_duplicate_users,NULL); + + /***** Build query *****/ + sprintf (Query,"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T" + " FROM usr_duplicated" + " GROUP BY UsrCod" + " ORDER BY N DESC,T DESC"); + NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get requests for enrollment"); + + /***** List possible duplicated users *****/ + if (NumUsrs) + { + /***** Initialize field names *****/ + Usr_SetUsrDatMainFieldNames (); + + /***** Initialize structure with user's data *****/ + Usr_UsrDataConstructor (&UsrDat); + + /***** Start table *****/ + fprintf (Gbl.F.Out,""); + + /***** Heading row with column names *****/ + Gbl.Usrs.Listing.WithPhotos = true; + Usr_WriteHeaderFieldsUsrDat (false); // Columns for the data + + /***** List users *****/ + for (NumUsr = 0, Gbl.RowEvenOdd = 0; + NumUsr < NumUsrs; + NumUsr++) + { + row = mysql_fetch_row (mysql_res); + + /* Get user code (row[0]) */ + UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) + { + if (Usr_GetNumCrssOfUsr (UsrDat.UsrCod) != 0) + UsrDat.Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrDat.UsrCod) == 0); + else + UsrDat.Accepted = false; + + /* Write data of this user */ + Usr_WriteRowUsrMainData (NumUsrs - NumUsr,&UsrDat,false); + + /* Write number of informants (row[1]) if greater than 1 */ + if (sscanf (row[1],"%u",&NumInformants) != 1) + Lay_ShowErrorAndExit ("Wrong number of informers."); + if (NumInformants > 1) + fprintf (Gbl.F.Out,"" + "" + "" + "", + Gbl.RowEvenOdd, + Usr_NUM_MAIN_FIELDS_DATA_USR-2, + Gbl.RowEvenOdd, + Txt_Informants, + NumInformants); + + /* Write link to view users similar to this */ + fprintf (Gbl.F.Out,"" + "" + "
" + "%s: %u" + "
", + Gbl.RowEvenOdd, + Usr_NUM_MAIN_FIELDS_DATA_USR-2, + Gbl.RowEvenOdd); + Act_FormStart (ActLstSimUsr); Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod); Lay_PutConfirmButtonInline (Txt_Similar_users); Act_FormEnd (); diff --git a/swad_duplicate.h b/swad_duplicate.h index f14a1b7c5..9aecbcdd2 100644 --- a/swad_duplicate.h +++ b/swad_duplicate.h @@ -42,6 +42,7 @@ void Dup_ReportUsrAsPossibleDuplicate (void); void Dup_PutLinkToListDupUsrs (void); void Dup_ListDuplicateUsrs (void); +void Dup_ListSimilarUsrs (void); void Dup_RemoveUsrFromDuplicated (long UsrCod); #endif diff --git a/swad_enrollment.c b/swad_enrollment.c index 8392c6c94..64c70a564 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -31,6 +31,7 @@ #include "swad_account.h" #include "swad_announcement.h" #include "swad_database.h" +#include "swad_duplicate.h" #include "swad_enrollment.h" #include "swad_global.h" #include "swad_ID.h" diff --git a/swad_user.c b/swad_user.c index 8449679ab..fb106c12d 100644 --- a/swad_user.c +++ b/swad_user.c @@ -41,6 +41,7 @@ #include "swad_connected.h" #include "swad_course.h" #include "swad_database.h" +#include "swad_duplicate.h" #include "swad_enrollment.h" #include "swad_global.h" #include "swad_group.h" diff --git a/swad_user.h b/swad_user.h index e062f337e..52b56bda0 100644 --- a/swad_user.h +++ b/swad_user.h @@ -357,9 +357,4 @@ void Usr_GetAndShowNumUsrsInPlatform (Rol_Role_t Role); bool Usr_CheckIfUsrBanned (long UsrCod); void Usr_RemoveUsrFromUsrBanned (long UsrCod); -void Dup_ReportUsrAsPossibleDuplicate (void); -void Dup_PutLinkToListDupUsrs (void); -void Dup_ListDuplicateUsrs (void); -void Dup_RemoveUsrFromDuplicated (long UsrCod); - #endif