diff --git a/swad_centre.c b/swad_centre.c index 5d562bbe..56982da8 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -205,17 +205,13 @@ void Ctr_SeeCtrWithPendingDegs (void) void Ctr_DrawCentreLogoAndNameWithLink (struct Centre *Ctr,Act_Action_t Action, const char *ClassLink,const char *ClassLogo) { - extern const char *Txt_Go_to_X; - /***** Begin form *****/ Frm_StartFormGoTo (Action); Ctr_PutParamCtrCod (Ctr->CtrCod); /***** Link to action *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Ctr->FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Ctr->FullName),ClassLink,NULL); + Hie_FreeGoToMsg (); /***** Centre logo and name *****/ Lgo_DrawLogo (Hie_CTR,Ctr->CtrCod,Ctr->ShrtName,16,ClassLogo,true); @@ -1550,17 +1546,14 @@ void Ctr_ContEditAfterChgCtr (void) static void Ctr_ShowAlertAndButtonToGoToCtr (void) { - extern const char *Txt_Go_to_X; - // If the centre being edited is different to the current one... if (Ctr_EditingCtr->CtrCod != Gbl.Hierarchy.Ctr.CtrCod) { /***** Alert with button to go to centre *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Ctr_EditingCtr->ShrtName); Ale_ShowLastAlertAndButton (ActSeeDeg,NULL,NULL,Ctr_PutParamGoToCtr, - Btn_CONFIRM_BUTTON,Gbl.Title); + Btn_CONFIRM_BUTTON, + Hie_BuildGoToMsg (Ctr_EditingCtr->ShrtName)); + Hie_FreeGoToMsg (); } else /***** Alert *****/ diff --git a/swad_centre_config.c b/swad_centre_config.c index 52fa3a47..e7c81858 100644 --- a/swad_centre_config.c +++ b/swad_centre_config.c @@ -592,7 +592,6 @@ static void CtrCfg_FreePhotoAttr (char **PhotoAttribution) static void CtrCfg_Institution (bool PrintView,bool PutForm) { extern const char *Txt_Institution; - extern const char *Txt_Go_to_X; unsigned NumIns; /***** Institution *****/ @@ -633,10 +632,9 @@ static void CtrCfg_Institution (bool PrintView,bool PutForm) { Frm_StartFormGoTo (ActSeeInsInf); Ins_PutParamInsCod (Gbl.Hierarchy.Ins.InsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Gbl.Hierarchy.Ins.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Ins.ShrtName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); } Lgo_DrawLogo (Hie_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.ShrtName, 20,"LM",true); diff --git a/swad_changelog.h b/swad_changelog.h index 78646171..949eb963 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.107 (2019-12-29)" +#define Log_PLATFORM_VERSION "SWAD 19.108 (2019-12-30)" #define CSS_FILE "swad19.101.5.css" #define JS_FILE "swad19.91.1.js" /* @@ -502,6 +502,7 @@ ps2pdf source.ps destination.pdf Version 19.10x: Dec 30, 2019 Map in country information. (? lines) Version 19.10x: Dec 30, 2019 Map in institution information. (? lines) + Version 19.108: Dec 30, 2019 Code refactoring related to hierarchy. (249730 lines) Version 19.107: Dec 29, 2019 New module swad_hierarchy_config for common hierarchy configuration functions. (249760 lines) Version 19.106: Dec 29, 2019 New module swad_country_config for country configuration. (249683 lines) Version 19.105: Dec 29, 2019 New module swad_institution_config for institution configuration. (249614 lines) diff --git a/swad_country.c b/swad_country.c index 7a9e1235..dc81218a 100644 --- a/swad_country.c +++ b/swad_country.c @@ -501,7 +501,6 @@ void Cty_DrawCountryMapAndNameWithLink (struct Country *Cty,Act_Action_t Action, const char *ClassMap, const char *ClassLink) { - extern const char *Txt_Go_to_X; char CountryName[Cty_MAX_BYTES_NAME + 1]; /***** Begin form *****/ @@ -510,10 +509,9 @@ void Cty_DrawCountryMapAndNameWithLink (struct Country *Cty,Act_Action_t Action, HTM_DIV_Begin ("class=\"%s\"",ClassContainer); /***** Link to action *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Cty->Name[Gbl.Prefs.Language]); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cty->Name[Gbl.Prefs.Language]), + ClassLink,NULL); + Hie_FreeGoToMsg (); /***** Draw country map *****/ Cty_DrawCountryMap (Cty,ClassMap); @@ -1610,17 +1608,14 @@ void Cty_ContEditAfterChgCty (void) static void Cty_ShowAlertAndButtonToGoToCty (void) { - extern const char *Txt_Go_to_X; - // If the country being edited is different to the current one... if (Cty_EditingCty->CtyCod != Gbl.Hierarchy.Cty.CtyCod) { /***** Alert with button to go to couuntry *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Cty_EditingCty->Name[Gbl.Prefs.Language]); Ale_ShowLastAlertAndButton (ActSeeIns,NULL,NULL,Cty_PutParamGoToCty, - Btn_CONFIRM_BUTTON,Gbl.Title); + Btn_CONFIRM_BUTTON, + Hie_BuildGoToMsg (Cty_EditingCty->Name[Gbl.Prefs.Language])); + Hie_FreeGoToMsg (); } else /***** Alert *****/ diff --git a/swad_course.c b/swad_course.c index 498c54f2..bdbc78d7 100644 --- a/swad_course.c +++ b/swad_course.c @@ -143,7 +143,6 @@ static void Crs_WriteListMyCoursesToSelectOne (void) extern const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES]; extern const char *Txt_My_courses; extern const char *Txt_System; - extern const char *Txt_Go_to_X; struct Country Cty; struct Instit Ins; struct Centre Ctr; @@ -356,13 +355,11 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Lay_IndentDependingOnLevel (5,IsLastItemInLevel); Frm_StartForm (ActMyCrs); Crs_PutParamCrsCod (Crs.CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title, + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs.ShrtName), Highlight ? ClassHighlight : ClassNormal, NULL); + Hie_FreeGoToMsg (); Ico_PutIcon ("list-ol.svg",Crs.FullName,"ICO16x16"); HTM_TxtF (" %s",Crs.ShrtName); HTM_BUTTON_End (); @@ -828,7 +825,6 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) extern const char *Txt_COURSE_With_users; extern const char *Txt_COURSE_Without_users; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; - extern const char *Txt_Go_to_X; extern const char *Txt_COURSE_STATUS[Crs_NUM_STATUS_TXT]; unsigned NumCrs; struct Course *Crs; @@ -887,10 +883,9 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) HTM_TD_Begin ("class=\"%s LM %s\"",TxtClassStrong,BgColor); Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (Crs->CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs->FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,TxtClassStrong,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs->FullName), + TxtClassStrong,NULL); + Hie_FreeGoToMsg (); HTM_Txt (Crs->FullName); HTM_BUTTON_End (); Frm_EndForm (); @@ -2251,17 +2246,13 @@ void Crs_ContEditAfterChgCrs (void) static void Crs_PutButtonToGoToCrs (void) { - extern const char *Txt_Go_to_X; - // If the course being edited is different to the current one... if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod) { Frm_StartForm (ActSeeCrsInf); Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs_EditingCrs->ShrtName); - Btn_PutConfirmButton (Gbl.Title); + Btn_PutConfirmButton (Hie_BuildGoToMsg (Crs_EditingCrs->ShrtName)); + Hie_FreeGoToMsg (); Frm_EndForm (); } } @@ -2564,7 +2555,6 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA { extern const char *Txt_Enrolment_confirmed; extern const char *Txt_Enrolment_not_confirmed; - extern const char *Txt_Go_to_X; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; struct Degree Deg; long CrsCod; @@ -2640,10 +2630,8 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA HTM_TD_Begin ("class=\"LT %s\"",BgColor); Frm_StartFormGoTo (ActSeeDegInf); Deg_PutParamDegCod (Deg.DegCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - row[2]); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[2]),ClassLink,NULL); + Hie_FreeGoToMsg (); Lgo_DrawLogo (Hie_DEG,Deg.DegCod,Deg.ShrtName,20,"CT",true); HTM_TxtF (" %s (%s)",row[2],row[6]); HTM_BUTTON_End (); @@ -2659,10 +2647,8 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA HTM_TD_Begin ("class=\"LT %s\"",BgColor); Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - row[5]); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (row[5]),ClassLink,NULL); + Hie_FreeGoToMsg (); HTM_Txt (row[5]); HTM_BUTTON_End (); Frm_EndForm (); diff --git a/swad_course_config.c b/swad_course_config.c index c0034fab..c1f3b2b5 100644 --- a/swad_course_config.c +++ b/swad_course_config.c @@ -211,7 +211,6 @@ static void CrsCfg_Title (bool PutLink) static void CrsCfg_Degree (bool PrintView,bool PutForm) { extern const char *Txt_Degree; - extern const char *Txt_Go_to_X; unsigned NumDeg; /***** Degree *****/ @@ -252,10 +251,9 @@ static void CrsCfg_Degree (bool PrintView,bool PutForm) { Frm_StartFormGoTo (ActSeeDegInf); Deg_PutParamDegCod (Gbl.Hierarchy.Deg.DegCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Gbl.Hierarchy.Deg.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Deg.ShrtName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); } Lgo_DrawLogo (Hie_DEG,Gbl.Hierarchy.Deg.DegCod,Gbl.Hierarchy.Deg.ShrtName, 20,"LM",true); diff --git a/swad_degree.c b/swad_degree.c index 4b9d009b..67b76fc9 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -213,17 +213,13 @@ void Deg_SeeDegWithPendingCrss (void) void Deg_DrawDegreeLogoAndNameWithLink (struct Degree *Deg,Act_Action_t Action, const char *ClassLink,const char *ClassLogo) { - extern const char *Txt_Go_to_X; - /***** Begin form *****/ Frm_StartFormGoTo (Action); Deg_PutParamDegCod (Deg->DegCod); /***** Link to action *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Deg->FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Deg->FullName),ClassLink,NULL); + Hie_FreeGoToMsg (); /***** Degree logo and name *****/ Lgo_DrawLogo (Hie_DEG,Deg->DegCod,Deg->ShrtName,16,ClassLogo,true); @@ -1806,17 +1802,14 @@ void Deg_ContEditAfterChgDeg (void) static void Deg_ShowAlertAndButtonToGoToDeg (void) { - extern const char *Txt_Go_to_X; - // If the degree being edited is different to the current one... if (Deg_EditingDeg->DegCod != Gbl.Hierarchy.Deg.DegCod) { /***** Alert with button to go to degree *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Deg_EditingDeg->ShrtName); Ale_ShowLastAlertAndButton (ActSeeCrs,NULL,NULL,Deg_PutParamGoToDeg, - Btn_CONFIRM_BUTTON,Gbl.Title); + Btn_CONFIRM_BUTTON, + Hie_BuildGoToMsg (Deg_EditingDeg->ShrtName)); + Hie_FreeGoToMsg (); } else /***** Alert *****/ @@ -1947,130 +1940,6 @@ unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery) SubQuery,(unsigned) Role); } -/*****************************************************************************/ -/***** Write institutions, centres and degrees administrated by an admin *****/ -/*****************************************************************************/ - -void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) - { - extern const char *Txt_all_degrees; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumRow; - unsigned NumRows; - struct Instit Ins; - struct Centre Ctr; - struct Degree Deg; - - /***** Get institutions, centres, degrees admin by user from database *****/ - NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions," - " centres, degrees" - " admin by a user", - "(SELECT %u AS S,-1 AS Cod,'' AS FullName" - " FROM admin" - " WHERE UsrCod=%ld" - " AND Scope='%s')" - " UNION " - "(SELECT %u AS S,admin.Cod,institutions.FullName" - " FROM admin,institutions" - " WHERE admin.UsrCod=%ld" - " AND admin.Scope='%s'" - " AND admin.Cod=institutions.InsCod)" - " UNION " - "(SELECT %u AS S,admin.Cod,centres.FullName" - " FROM admin,centres" - " WHERE admin.UsrCod=%ld" - " AND admin.Scope='%s'" - " AND admin.Cod=centres.CtrCod)" - " UNION " - "(SELECT %u AS S,admin.Cod,degrees.FullName" - " FROM admin,degrees" - " WHERE admin.UsrCod=%ld" - " AND admin.Scope='%s'" - " AND admin.Cod=degrees.DegCod)" - " ORDER BY S,FullName", - (unsigned) Hie_SYS,UsrCod,Sco_GetDBStrFromScope (Hie_SYS), - (unsigned) Hie_INS,UsrCod,Sco_GetDBStrFromScope (Hie_INS), - (unsigned) Hie_CTR,UsrCod,Sco_GetDBStrFromScope (Hie_CTR), - (unsigned) Hie_DEG,UsrCod,Sco_GetDBStrFromScope (Hie_DEG)); - if (NumRows) - /***** Get the list of degrees *****/ - for (NumRow = 1; - NumRow <= NumRows; - NumRow++) - { - HTM_TR_Begin (NULL); - - /***** Indent *****/ - HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); - Ico_PutIcon (NumRow == NumRows ? "subend20x20.gif" : - "submid20x20.gif", - "","ICO25x25"); - HTM_TD_End (); - - /***** Write institution, centre, degree *****/ - HTM_TD_Begin ("colspan=\"%u\" class=\"DAT_SMALL_NOBR LT COLOR%u\"", - ColSpan - 1,Gbl.RowEvenOdd); - - /* Get next institution, centre, degree */ - row = mysql_fetch_row (mysql_res); - - /* Get scope */ - switch (Sco_GetScopeFromUnsignedStr (row[0])) - { - case Hie_SYS: // System - Ico_PutIcon ("swad64x64.png",Txt_all_degrees,"ICO16x16"); - HTM_TxtF (" %s",Txt_all_degrees); - break; - case Hie_INS: // Institution - Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]); - if (Ins.InsCod > 0) - { - /* Get data of institution */ - Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA); - - /* Write institution logo and name */ - Ins_DrawInstitutionLogoAndNameWithLink (&Ins,ActSeeInsInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - case Hie_CTR: // Centre - Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]); - if (Ctr.CtrCod > 0) - { - /* Get data of centre */ - Ctr_GetDataOfCentreByCod (&Ctr,Ctr_GET_BASIC_DATA); - - /* Write centre logo and name */ - Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeCtrInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - case Hie_DEG: // Degree - Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); - if (Deg.DegCod > 0) - { - /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); - - /* Write degree logo and name */ - Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - default: // There are no administrators in other scopes - Lay_WrongScopeExit (); - break; - } - HTM_TD_End (); - - HTM_TR_End (); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - /*****************************************************************************/ /**************************** List degrees found *****************************/ /*****************************************************************************/ diff --git a/swad_degree_config.c b/swad_degree_config.c index 24f99207..9c686366 100644 --- a/swad_degree_config.c +++ b/swad_degree_config.c @@ -208,7 +208,6 @@ static void DegCfg_Title (bool PutLink) static void DegCfg_Centre (bool PrintView,bool PutForm) { extern const char *Txt_Centre; - extern const char *Txt_Go_to_X; unsigned NumCtr; /***** Centre *****/ @@ -249,10 +248,9 @@ static void DegCfg_Centre (bool PrintView,bool PutForm) { Frm_StartFormGoTo (ActSeeCtrInf); Ctr_PutParamCtrCod (Gbl.Hierarchy.Ctr.CtrCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Gbl.Hierarchy.Ctr.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Ctr.ShrtName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); } Lgo_DrawLogo (Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod,Gbl.Hierarchy.Ctr.ShrtName, 20,"LM",true); diff --git a/swad_enrolment.c b/swad_enrolment.c index 90c4cfd4..dfc6ec2e 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -2214,7 +2214,6 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) extern const char *Txt_Requester; extern const char *Txt_Role; extern const char *Txt_Date; - extern const char *Txt_Go_to_X; extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_Register; extern const char *Txt_Reject; @@ -2827,10 +2826,9 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) HTM_TD_Begin ("class=\"DAT LT\""); Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (Crs.CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs.FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs.FullName), + "BT_LINK DAT",NULL); + Hie_FreeGoToMsg (); HTM_TxtF ("%s > %s",Deg.ShrtName,Crs.ShrtName); HTM_BUTTON_End (); Frm_EndForm (); diff --git a/swad_file_browser.c b/swad_file_browser.c index 9d66642f..2aadab83 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -11876,7 +11876,6 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) extern const char *Txt_Project_assessment; extern const char *Txt_Marks_area; extern const char *Txt_Temporary_private_storage_area; - extern const char *Txt_Go_to_X; extern const char *Txt_Folder; struct FileMetadata FileMetadata; long InsCod; @@ -11948,10 +11947,9 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) { Frm_StartFormGoTo (ActSeeInsInf); Deg_PutParamDegCod (InsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - InsShortName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (InsShortName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); Lgo_DrawLogo (Hie_INS,InsCod,InsShortName,20,"BT_LINK LT",true); HTM_TxtF (" %s",InsShortName); HTM_BUTTON_End (); @@ -11965,10 +11963,9 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) { Frm_StartFormGoTo (ActSeeCtrInf); Deg_PutParamDegCod (CtrCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - CtrShortName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (CtrShortName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); Lgo_DrawLogo (Hie_CTR,CtrCod,CtrShortName,20,"LT",true); HTM_TxtF (" %s",CtrShortName); HTM_BUTTON_End (); @@ -11982,10 +11979,9 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) { Frm_StartFormGoTo (ActSeeDegInf); Deg_PutParamDegCod (DegCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - DegShortName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (DegShortName), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); Lgo_DrawLogo (Hie_DEG,DegCod,DegShortName,20,"LT",true); HTM_TxtF (" %s",DegShortName); HTM_BUTTON_End (); @@ -11999,10 +11995,8 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) { Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - CrsShortName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (CrsShortName),"BT_LINK DAT",NULL); + Hie_FreeGoToMsg (); HTM_Txt (CrsShortName); HTM_BUTTON_End (); Frm_EndForm (); diff --git a/swad_hierarchy.c b/swad_hierarchy.c index c0c4edf5..a9a41e47 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -28,6 +28,7 @@ #define _GNU_SOURCE // For asprintf #include // For asprintf +#include "swad_database.h" #include "swad_form.h" #include "swad_global.h" #include "swad_HTML.h" @@ -48,11 +49,17 @@ extern struct Globals Gbl; /*****************************************************************************/ /*****************************************************************************/ -/**************************** Private constants ******************************/ +/*************************** Private variables *******************************/ +/*****************************************************************************/ + +char *Hie_GoToMsg = NULL; + +/*****************************************************************************/ +/*************************** Private constants *******************************/ /*****************************************************************************/ /*****************************************************************************/ -/**************************** Private prototypes *****************************/ +/*************************** Private prototypes ******************************/ /*****************************************************************************/ /*****************************************************************************/ @@ -652,3 +659,150 @@ void Hie_ResetHierarchy (void) Gbl.Hierarchy.Level = Hie_UNK; Gbl.Hierarchy.Cod = -1L; } + +/*****************************************************************************/ +/***** Write institutions, centres and degrees administrated by an admin *****/ +/*****************************************************************************/ + +void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) + { + extern const char *Txt_all_degrees; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumRow; + unsigned NumRows; + struct Instit Ins; + struct Centre Ctr; + struct Degree Deg; + + /***** Get institutions, centres, degrees admin by user from database *****/ + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions," + " centres, degrees" + " admin by a user", + "(SELECT %u AS S,-1 AS Cod,'' AS FullName" + " FROM admin" + " WHERE UsrCod=%ld" + " AND Scope='%s')" + " UNION " + "(SELECT %u AS S,admin.Cod,institutions.FullName" + " FROM admin,institutions" + " WHERE admin.UsrCod=%ld" + " AND admin.Scope='%s'" + " AND admin.Cod=institutions.InsCod)" + " UNION " + "(SELECT %u AS S,admin.Cod,centres.FullName" + " FROM admin,centres" + " WHERE admin.UsrCod=%ld" + " AND admin.Scope='%s'" + " AND admin.Cod=centres.CtrCod)" + " UNION " + "(SELECT %u AS S,admin.Cod,degrees.FullName" + " FROM admin,degrees" + " WHERE admin.UsrCod=%ld" + " AND admin.Scope='%s'" + " AND admin.Cod=degrees.DegCod)" + " ORDER BY S,FullName", + (unsigned) Hie_SYS,UsrCod,Sco_GetDBStrFromScope (Hie_SYS), + (unsigned) Hie_INS,UsrCod,Sco_GetDBStrFromScope (Hie_INS), + (unsigned) Hie_CTR,UsrCod,Sco_GetDBStrFromScope (Hie_CTR), + (unsigned) Hie_DEG,UsrCod,Sco_GetDBStrFromScope (Hie_DEG)); + if (NumRows) + /***** Get the list of degrees *****/ + for (NumRow = 1; + NumRow <= NumRows; + NumRow++) + { + HTM_TR_Begin (NULL); + + /***** Indent *****/ + HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); + Ico_PutIcon (NumRow == NumRows ? "subend20x20.gif" : + "submid20x20.gif", + "","ICO25x25"); + HTM_TD_End (); + + /***** Write institution, centre, degree *****/ + HTM_TD_Begin ("colspan=\"%u\" class=\"DAT_SMALL_NOBR LT COLOR%u\"", + ColSpan - 1,Gbl.RowEvenOdd); + + /* Get next institution, centre, degree */ + row = mysql_fetch_row (mysql_res); + + /* Get scope */ + switch (Sco_GetScopeFromUnsignedStr (row[0])) + { + case Hie_SYS: // System + Ico_PutIcon ("swad64x64.png",Txt_all_degrees,"ICO16x16"); + HTM_TxtF (" %s",Txt_all_degrees); + break; + case Hie_INS: // Institution + Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]); + if (Ins.InsCod > 0) + { + /* Get data of institution */ + Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA); + + /* Write institution logo and name */ + Ins_DrawInstitutionLogoAndNameWithLink (&Ins,ActSeeInsInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + case Hie_CTR: // Centre + Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]); + if (Ctr.CtrCod > 0) + { + /* Get data of centre */ + Ctr_GetDataOfCentreByCod (&Ctr,Ctr_GET_BASIC_DATA); + + /* Write centre logo and name */ + Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeCtrInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + case Hie_DEG: // Degree + Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); + if (Deg.DegCod > 0) + { + /* Get data of degree */ + Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + + /* Write degree logo and name */ + Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + default: // There are no administrators in other scopes + Lay_WrongScopeExit (); + break; + } + HTM_TD_End (); + + HTM_TR_End (); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/********************* Build a "Go to " message ***********************/ +/*****************************************************************************/ +// Where is a hierarchy member (country, institution, centre, degree or course +// Hie_FreeGoToMsg() must be called after calling this function + +char *Hie_BuildGoToMsg (const char *Where) + { + extern const char *Txt_Go_to_X; + + Hie_FreeGoToMsg (); + if (asprintf (&Hie_GoToMsg,Txt_Go_to_X,Where) < 0) + Lay_NotEnoughMemoryExit (); + + return Hie_GoToMsg; + } + +void Hie_FreeGoToMsg (void) + { + if (Hie_GoToMsg != NULL) + free (Hie_GoToMsg); + } diff --git a/swad_hierarchy.h b/swad_hierarchy.h index 4fcd4829..53e345a2 100644 --- a/swad_hierarchy.h +++ b/swad_hierarchy.h @@ -72,4 +72,7 @@ void Hie_ResetHierarchy (void); void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan); +char *Hie_BuildGoToMsg (const char *Where); +void Hie_FreeGoToMsg (void); + #endif diff --git a/swad_institution.c b/swad_institution.c index db5f6afa..a34f3d9a 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -233,17 +233,13 @@ void Ins_DrawInstitutionLogoWithLink (struct Instit *Ins,unsigned Size) void Ins_DrawInstitutionLogoAndNameWithLink (struct Instit *Ins,Act_Action_t Action, const char *ClassLink,const char *ClassLogo) { - extern const char *Txt_Go_to_X; - /***** Begin form *****/ Frm_StartFormGoTo (Action); Ins_PutParamInsCod (Ins->InsCod); /***** Link to action *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Ins->FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Ins->FullName),ClassLink,NULL); + Hie_FreeGoToMsg (); /***** Institution logo and name *****/ Lgo_DrawLogo (Hie_INS,Ins->InsCod,Ins->ShrtName,16,ClassLogo,true); @@ -1613,17 +1609,14 @@ void Ins_ContEditAfterChgIns (void) static void Ins_ShowAlertAndButtonToGoToIns (void) { - extern const char *Txt_Go_to_X; - // If the institution being edited is different to the current one... if (Ins_EditingIns->InsCod != Gbl.Hierarchy.Ins.InsCod) { /***** Alert with button to go to institution *****/ - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Ins_EditingIns->ShrtName); Ale_ShowLastAlertAndButton (ActSeeCtr,NULL,NULL,Ins_PutParamGoToIns, - Btn_CONFIRM_BUTTON,Gbl.Title); + Btn_CONFIRM_BUTTON, + Hie_BuildGoToMsg (Ins_EditingIns->ShrtName)); + Hie_FreeGoToMsg (); } else /***** Alert *****/ diff --git a/swad_institution_config.c b/swad_institution_config.c index 8554380f..d0826418 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -320,7 +320,6 @@ static void InsCfg_Map (void) static void InsCfg_Country (bool PrintView,bool PutForm) { extern const char *Txt_Country; - extern const char *Txt_Go_to_X; unsigned NumCty; /***** Country *****/ @@ -361,10 +360,9 @@ static void InsCfg_Country (bool PrintView,bool PutForm) { Frm_StartFormGoTo (ActSeeCtyInf); Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); } Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,"COUNTRY_MAP_TINY"); HTM_NBSP (); diff --git a/swad_message.c b/swad_message.c index 741dc84f..72e09bb1 100644 --- a/swad_message.c +++ b/swad_message.c @@ -3255,7 +3255,6 @@ void Msg_WriteMsgAuthor (struct UsrData *UsrDat,bool Enabled,const char *BgColor bool Msg_WriteCrsOrgMsg (long CrsCod) { extern const char *Txt_from_this_course; - extern const char *Txt_Go_to_X; extern const char *Txt_no_course_of_origin; struct Course Crs; bool FromThisCrs = true; @@ -3283,10 +3282,9 @@ bool Msg_WriteCrsOrgMsg (long CrsCod) Crs_PutParamCrsCod (Crs.CrsCod); HTM_DIV_Begin ("class=\"AUTHOR_TXT\""); HTM_Txt ("("); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs.FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK AUTHOR_TXT",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs.FullName), + "BT_LINK AUTHOR_TXT",NULL); + Hie_FreeGoToMsg (); HTM_Txt (Crs.ShrtName); HTM_BUTTON_End (); HTM_Txt (")"); diff --git a/swad_photo.c b/swad_photo.c index 7e60d40b..65f24970 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -2435,7 +2435,6 @@ static void Pho_ShowDegreeAvgPhotoAndStat (struct Degree *Deg, int NumStds,int NumStdsWithPhoto) { extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; - extern const char *Txt_Go_to_X; extern const char *Txt_students_ABBREVIATION; extern const char *Txt_SEX_PLURAL_abc[Usr_NUM_SEXS]; extern const char *Txt_photos; @@ -2460,10 +2459,8 @@ static void Pho_ShowDegreeAvgPhotoAndStat (struct Degree *Deg, { Frm_StartFormGoTo (ActSeeDegInf); Deg_PutParamDegCod (Deg->DegCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Deg->FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Deg->FullName),"BT_LINK",NULL); + Hie_FreeGoToMsg (); } /***** Check if photo of degree can be shown *****/ diff --git a/swad_statistic.c b/swad_statistic.c index a053e8af..83f0f5c2 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -3592,7 +3592,6 @@ static void Sta_ShowNumHitsPerCourse (unsigned long NumRows, extern const char *Txt_Year_OF_A_DEGREE; extern const char *Txt_Course; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; - extern const char *Txt_Go_to_X; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; // Declaration in swad_degree.c unsigned long NumRow; unsigned long Ranking; @@ -3657,10 +3656,8 @@ static void Sta_ShowNumHitsPerCourse (unsigned long NumRows, { Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (Crs.CrsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Crs.FullName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT LOG",NULL); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Crs.FullName),"BT_LINK LT LOG",NULL); + Hie_FreeGoToMsg (); HTM_Txt (Crs.ShrtName); HTM_BUTTON_End (); }