diff --git a/swad_changelog.h b/swad_changelog.h index 8cbd623c..c3f2e87e 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -103,11 +103,12 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 14.93.1 (2015/03/16)" +#define Log_PLATFORM_VERSION "SWAD 14.93.2 (2015/03/16)" // 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 14.93.2: Mar 16, 2015 New rankings for downloads, forum posts and messages sent. (182628 lines) Version 14.93.1: Mar 16, 2015 Photos and links to users' profiles in users' ranking. (182560 lines) Version 14.93: Mar 16, 2015 Users' ranking. (182527 lines) Version 14.92.2: Mar 15, 2015 Fixed minor bug in photo edition. (182208 lines) diff --git a/swad_config.h b/swad_config.h index 9356e2c9..c76ec54f 100644 --- a/swad_config.h +++ b/swad_config.h @@ -28,8 +28,8 @@ /** Uncomment one of the following installations of SWAD or create your own **/ /*****************************************************************************/ -#define LOCALHOST_UBUNTU // Comment this line if not applicable -//#define OPENSWAD_ORG // Comment this line if not applicable +//#define LOCALHOST_UBUNTU // Comment this line if not applicable +#define OPENSWAD_ORG // Comment this line if not applicable //#define SWAD_UGR_ES // Comment this line if not applicable //#define WWW_CEVUNA_UNA_PY // Comment this line if not applicable diff --git a/swad_photo.c b/swad_photo.c index eeaf12a0..8203b0f3 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -775,7 +775,7 @@ void Pho_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod) // Returns true if the photo can be shown and false if not. // Public photo means two different things depending on the user's type -bool Pho_ShowUsrPhotoIsAllowed (struct UsrData *UsrDat,char *PhotoURL) +bool Pho_ShowUsrPhotoIsAllowed (const struct UsrData *UsrDat,char *PhotoURL) { bool ICanSeePhoto; diff --git a/swad_photo.h b/swad_photo.h index af7a516e..75a0a005 100644 --- a/swad_photo.h +++ b/swad_photo.h @@ -100,7 +100,7 @@ void Pho_UpdateUsrPhoto2 (void); unsigned Pho_UpdateMyClicksWithoutPhoto (void); void Pho_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod); -bool Pho_ShowUsrPhotoIsAllowed (struct UsrData *UsrDat,char *PhotoURL); +bool Pho_ShowUsrPhotoIsAllowed (const struct UsrData *UsrDat,char *PhotoURL); bool Pho_BuildLinkToPhoto (const struct UsrData *UsrDat,char *PhotoURL,bool HTTPS); bool Pho_CheckIfPrivPhotoExists (long UsrCod,char *PathPrivRelPhoto); bool Pho_RemovePhoto (struct UsrData *UsrDat); diff --git a/swad_profile.c b/swad_profile.c index 3d4c631e..0c1d8910 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -97,6 +97,9 @@ static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures); static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures); static bool Prf_CheckIfUsrFiguresExists (long UsrCod); +static void Prf_GetAndShowRankingFigure (const char *FieldName); +static void Prf_ShowUsrInRanking (const struct UsrData *UsrDat); + /*****************************************************************************/ /************************** Get public profile URL ***************************/ /*****************************************************************************/ @@ -1124,28 +1127,49 @@ void Prf_IncrementNumMsgSntUsr (long UsrCod) void Prf_GetAndShowRankingClicks (void) { - extern const char *Txt_View_public_profile; + Prf_GetAndShowRankingFigure ("NumClicks"); + } + +void Prf_GetAndShowRankingFileViews (void) + { + Prf_GetAndShowRankingFigure ("NumFileViews"); + } + +void Prf_GetAndShowRankingForPst (void) + { + Prf_GetAndShowRankingFigure ("NumForPst"); + } + +void Prf_GetAndShowRankingMsgSnt (void) + { + Prf_GetAndShowRankingFigure ("NumMsgSnt"); + } + +static void Prf_GetAndShowRankingFigure (const char *FieldName) + { char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumUsrs; unsigned NumUsr; + unsigned Rank; struct UsrData UsrDat; - unsigned long NumClicks; - bool ShowPhoto; - char PhotoURL[PATH_MAX+1]; + long FigureHigh = LONG_MAX; + long Figure; /***** Get ranking from database *****/ switch (Gbl.Scope.Current) { case Sco_SCOPE_SYS: - sprintf (Query,"SELECT UsrCod,NumClicks" + sprintf (Query,"SELECT UsrCod,%s" " FROM usr_figures" - " WHERE NumClicks>='0'" - " ORDER BY NumClicks DESC LIMIT 100"); + " WHERE %s>='0'" + " ORDER BY %s DESC LIMIT 100", + FieldName, + FieldName,FieldName); break; case Sco_SCOPE_CTY: - sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.NumClicks" + sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" " FROM institutions,centres,degrees,courses,crs_usr,usr_figures" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -1153,51 +1177,61 @@ void Prf_GetAndShowRankingClicks (void) " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_figures.UsrCod" - " AND usr_figures.NumClicks>='0'" - " ORDER BY usr_figures.NumClicks DESC LIMIT 100", - Gbl.CurrentCty.Cty.CtyCod); + " AND usr_figures.%s>='0'" + " ORDER BY usr_figures.%s DESC LIMIT 100", + FieldName, + Gbl.CurrentCty.Cty.CtyCod, + FieldName,FieldName); break; case Sco_SCOPE_INS: - sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.NumClicks" + sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" " FROM centres,degrees,courses,crs_usr,usr_figures" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_figures.UsrCod" - " AND usr_figures.NumClicks>='0'" - " ORDER BY usr_figures.NumClicks DESC LIMIT 100", - Gbl.CurrentIns.Ins.InsCod); + " AND usr_figures.%s>='0'" + " ORDER BY usr_figures.%s DESC LIMIT 100", + FieldName, + Gbl.CurrentIns.Ins.InsCod, + FieldName,FieldName); break; case Sco_SCOPE_CTR: - sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.NumClicks" + sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" " FROM degrees,courses,crs_usr,usr_figures" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_figures.UsrCod" - " AND usr_figures.NumClicks>='0'" - " ORDER BY usr_figures.NumClicks DESC LIMIT 100", - Gbl.CurrentCtr.Ctr.CtrCod); + " AND usr_figures.%s>='0'" + " ORDER BY usr_figures.%s DESC LIMIT 100", + FieldName, + Gbl.CurrentCtr.Ctr.CtrCod, + FieldName,FieldName); break; case Sco_SCOPE_DEG: - sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.NumClicks" + sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" " FROM courses,crs_usr,usr_figures" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_figures.UsrCod" - " AND usr_figures.NumClicks>='0'" - " ORDER BY usr_figures.NumClicks DESC LIMIT 100", - Gbl.CurrentDeg.Deg.DegCod); + " AND usr_figures.%s>='0'" + " ORDER BY usr_figures.%s DESC LIMIT 100", + FieldName, + Gbl.CurrentDeg.Deg.DegCod, + FieldName,FieldName); break; case Sco_SCOPE_CRS: - sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.NumClicks" + sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" " FROM crs_usr,usr_figures" " WHERE crs_usr.CrsCod='%ld'" " AND crs_usr.UsrCod=usr_figures.UsrCod" - " AND usr_figures.NumClicks>='0'" - " ORDER BY usr_figures.NumClicks DESC LIMIT 100", - Gbl.CurrentCrs.Crs.CrsCod); + " AND usr_figures.%s>='0'" + " ORDER BY usr_figures.%s DESC LIMIT 100", + FieldName, + Gbl.CurrentCrs.Crs.CrsCod, + FieldName,FieldName); break; default: Lay_ShowErrorAndExit ("Wrong scope."); @@ -1211,8 +1245,8 @@ void Prf_GetAndShowRankingClicks (void) fprintf (Gbl.F.Out,""); - for (NumUsr = 1; - NumUsr <= NumUsrs; + for (NumUsr = 0, Rank = 0; + NumUsr < NumUsrs; NumUsr++) { /***** Get user and number of clicks *****/ @@ -1222,9 +1256,15 @@ void Prf_GetAndShowRankingClicks (void) UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); Usr_GetAllUsrDataFromUsrCod (&UsrDat); - /* Get number of clicks (row[1]) */ - if (sscanf (row[1],"%ld",&NumClicks) != 1) - NumClicks = -1L; + /* Get figure (row[1]) */ + if (sscanf (row[1],"%ld",&Figure) != 1) + Lay_ShowErrorAndExit ("Error reading user's figure."); + + if (Figure < FigureHigh) + { + Rank++; + FigureHigh = Figure; + } /***** Show row *****/ if (UsrDat.Nickname[0]) @@ -1232,26 +1272,12 @@ void Prf_GetAndShowRankingClicks (void) fprintf (Gbl.F.Out,"" "" "" "" "", - NumClicks); + Figure); } } @@ -1271,16 +1297,15 @@ void Prf_GetAndShowRankingClicks (void) void Prf_GetAndShowRankingClicksPerDay (void) { - extern const char *Txt_View_public_profile; char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumUsrs; unsigned NumUsr; + unsigned Rank; struct UsrData UsrDat; + float NumClicksPerDayHigh = (float) LONG_MAX; float NumClicksPerDay; - bool ShowPhoto; - char PhotoURL[PATH_MAX+1]; /***** Get ranking from database *****/ switch (Gbl.Scope.Current) @@ -1364,8 +1389,8 @@ void Prf_GetAndShowRankingClicksPerDay (void) fprintf (Gbl.F.Out,"
#%u", - NumUsr); - - /* User's photo */ - ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL); - Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL : - NULL, - "PHOTO18x24",Pho_ZOOM); - - /* Put form to go to public profile */ - Act_FormStart (ActSeePubPrf); - Usr_PutParamOtherUsrCodEncrypted (UsrDat.EncryptedUsrCod); - Act_LinkFormSubmit (Txt_View_public_profile,"DAT"); - fprintf (Gbl.F.Out,"@%s",UsrDat.Nickname); - fprintf (Gbl.F.Out,""); - Act_FormEnd (); - + Rank); + Prf_ShowUsrInRanking (&UsrDat); fprintf (Gbl.F.Out,"%ld
"); - for (NumUsr = 1; - NumUsr <= NumUsrs; + for (NumUsr = 0, Rank = 0; + NumUsr < NumUsrs; NumUsr++) { /***** Get user and number of clicks *****/ @@ -1377,6 +1402,11 @@ void Prf_GetAndShowRankingClicksPerDay (void) /* Get number of clicks per day (row[1]) */ NumClicksPerDay = Str_GetFloatNumFromStr (row[1]); + if (NumClicksPerDay < NumClicksPerDayHigh) + { + Rank++; + NumClicksPerDayHigh = NumClicksPerDay; + } /***** Show row *****/ if (UsrDat.Nickname[0]) @@ -1384,22 +1414,8 @@ void Prf_GetAndShowRankingClicksPerDay (void) fprintf (Gbl.F.Out,"" "" "" "" + "" + "" + "" "" @@ -3819,7 +3831,10 @@ static void Sta_GetAndShowUsersRanking (void) "" "", Txt_Clicks, - Txt_Clicks_per_day); + Txt_Clicks_per_day, + Txt_Downloads, + Txt_Forums, + Txt_Messages); /***** Rankings *****/ fprintf (Gbl.F.Out,"" @@ -3830,6 +3845,18 @@ static void Sta_GetAndShowUsersRanking (void) "" + "" + "" + "" "");
#%u", - NumUsr); - - /* User's photo */ - ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL); - Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL : - NULL, - "PHOTO18x24",Pho_ZOOM); - - /* Put form to go to public profile */ - Act_FormStart (ActSeePubPrf); - Usr_PutParamOtherUsrCodEncrypted (UsrDat.EncryptedUsrCod); - Act_LinkFormSubmit (Txt_View_public_profile,"DAT"); - fprintf (Gbl.F.Out,"@%s",UsrDat.Nickname); - fprintf (Gbl.F.Out,""); - Act_FormEnd (); - + Rank); + Prf_ShowUsrInRanking (&UsrDat); fprintf (Gbl.F.Out,""); Str_WriteFloatNum (NumClicksPerDay); @@ -1417,3 +1433,28 @@ void Prf_GetAndShowRankingClicksPerDay (void) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } + +/*****************************************************************************/ +/************** Show user's photo and nickname in ranking list ***************/ +/*****************************************************************************/ + +static void Prf_ShowUsrInRanking (const struct UsrData *UsrDat) + { + extern const char *Txt_View_public_profile; + bool ShowPhoto; + char PhotoURL[PATH_MAX+1]; + + /***** User's photo *****/ + ShowPhoto = Pho_ShowUsrPhotoIsAllowed (UsrDat,PhotoURL); + Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL : + NULL, + "PHOTO18x24",Pho_ZOOM); + + /***** Put form to go to public profile *****/ + Act_FormStart (ActSeePubPrf); + Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod); + Act_LinkFormSubmit (Txt_View_public_profile,"DAT"); + fprintf (Gbl.F.Out,"@%s",UsrDat->Nickname); + fprintf (Gbl.F.Out,""); + Act_FormEnd (); + } diff --git a/swad_profile.h b/swad_profile.h index 5dd2cfae..6da4b3d7 100644 --- a/swad_profile.h +++ b/swad_profile.h @@ -55,6 +55,9 @@ void Prf_IncrementNumForPstUsr (long UsrCod); void Prf_IncrementNumMsgSntUsr (long UsrCod); void Prf_GetAndShowRankingClicks (void); +void Prf_GetAndShowRankingFileViews (void); +void Prf_GetAndShowRankingForPst (void); +void Prf_GetAndShowRankingMsgSnt (void); void Prf_GetAndShowRankingClicksPerDay (void); #endif diff --git a/swad_statistic.c b/swad_statistic.c index 7b82f55d..dbe3ff9a 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -3806,11 +3806,23 @@ static void Sta_GetAndShowUsersRanking (void) extern const char *Txt_STAT_USE_STAT_TYPES[Sta_NUM_TYPES_USE_STATS]; extern const char *Txt_Clicks; extern const char *Txt_Clicks_per_day; + extern const char *Txt_Downloads; + extern const char *Txt_Forums; + extern const char *Txt_Messages; Lay_StartRoundFrameTable10 (NULL,2,Txt_STAT_USE_STAT_TYPES[Sta_USRS_RANKING]); /***** Header *****/ fprintf (Gbl.F.Out,"
" + "%s" + "" + "%s" + "" + "%s" + "" "%s" "
"); Prf_GetAndShowRankingClicksPerDay (); + fprintf (Gbl.F.Out,""); + Prf_GetAndShowRankingFileViews (); + fprintf (Gbl.F.Out,""); + Prf_GetAndShowRankingForPst (); + fprintf (Gbl.F.Out,""); + Prf_GetAndShowRankingMsgSnt (); fprintf (Gbl.F.Out,"