Version 21.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links.

This commit is contained in:
acanas 2021-09-22 13:20:57 +02:00
parent ddf9d0dfdc
commit ebc93b6c27
9 changed files with 624 additions and 457 deletions

View File

@ -59,7 +59,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_indicator_database.o swad_info.o swad_info_database.o \ swad_indicator_database.o swad_info.o swad_info_database.o \
swad_institution.o swad_institution_config.o \ swad_institution.o swad_institution_config.o \
swad_institution_database.o \ swad_institution_database.o \
swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \ swad_language.o swad_layout.o swad_link.o swad_link_database.o \
swad_log.o swad_logo.o \
swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \ swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \
swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \ swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \
swad_media.o swad_media_database.o swad_menu.o swad_message.o \ swad_media.o swad_media_database.o swad_menu.o swad_message.o \

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/ */
#define Log_PLATFORM_VERSION "SWAD 21.11.1 (2021-09-22)" #define Log_PLATFORM_VERSION "SWAD 21.12 (2021-09-22)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js" #define JS_FILE "swad20.69.1.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 21.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links. (316361 lines)
Version 21.11.1: Sep 22, 2021 Queries moved to module swad_info_database. (316237 lines) Version 21.11.1: Sep 22, 2021 Queries moved to module swad_info_database. (316237 lines)
Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information. (316228 lines) Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information. (316228 lines)
Version 21.10.1: Sep 21, 2021 Fixed bugs in roles. Reported by Javier Fernández Baldomero and Carmen García Miranda. (316111 lines) Version 21.10.1: Sep 21, 2021 Fixed bugs in roles. Reported by Javier Fernández Baldomero and Carmen García Miranda. (316111 lines)

View File

@ -196,18 +196,11 @@ void Lan_ChangeLanguage (void)
void Lan_UpdateMyLanguageToCurrentLanguage (void) void Lan_UpdateMyLanguageToCurrentLanguage (void)
{ {
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
/***** Set my language to the current language *****/ /***** Set my language to the current language *****/
Gbl.Usrs.Me.UsrDat.Prefs.Language = Gbl.Prefs.Language; Gbl.Usrs.Me.UsrDat.Prefs.Language = Gbl.Prefs.Language;
/***** Update my language in database *****/ /***** Update my language in database *****/
DB_QueryUPDATE ("can not update your language", Set_DB_UpdateMySettingsAboutLanguage ();
"UPDATE usr_data"
" SET Language='%s'"
" WHERE UsrCod=%ld",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -269,12 +269,12 @@ void Lay_WriteStartOfPage (void)
switch (BrowserTab) switch (BrowserTab)
{ {
case Act_BRW_1ST_TAB: case Act_BRW_1ST_TAB:
HTM_Txt ("<body onload=\"init();\">\n"); HTM_Txt ("<body onload=\"init();\">\n");
HTM_DIV_Begin ("id=\"zoomLyr\" class=\"ZOOM\""); HTM_DIV_Begin ("id=\"zoomLyr\" class=\"ZOOM\"");
HTM_IMG (Cfg_URL_ICON_PUBLIC,"usr_bl.jpg",NULL, HTM_IMG (Cfg_URL_ICON_PUBLIC,"usr_bl.jpg",NULL,
"class=\"IMG_USR\" id=\"zoomImg\""); "class=\"IMG_USR\" id=\"zoomImg\"");
HTM_DIV_Begin ("id=\"zoomTxt\" class=\"CM\""); HTM_DIV_Begin ("id=\"zoomTxt\" class=\"CM\"");
HTM_DIV_End (); HTM_DIV_End ();
HTM_DIV_End (); HTM_DIV_End ();
break; break;
case Act_BRW_NEW_TAB: case Act_BRW_NEW_TAB:
@ -311,77 +311,77 @@ void Lay_WriteStartOfPage (void)
/***** Begin box that contains the whole page except the foot *****/ /***** Begin box that contains the whole page except the foot *****/
HTM_DIV_Begin ("id=\"whole_page\""); HTM_DIV_Begin ("id=\"whole_page\"");
/***** Header of layout *****/ /***** Header of layout *****/
Lay_WritePageTopHeading (); Lay_WritePageTopHeading ();
/***** 3rd. row (tabs) *****/ /***** 3rd. row (tabs) *****/
Tab_DrawTabs (); Tab_DrawTabs ();
/***** 4th row: main zone *****/ /***** 4th row: main zone *****/
HTM_DIV_Begin ("id=\"main_zone\""); HTM_DIV_Begin ("id=\"main_zone\"");
/* Left column */ /* Left column */
if (Gbl.Prefs.SideCols & Lay_SHOW_LEFT_COLUMN) // Left column visible if (Gbl.Prefs.SideCols & Lay_SHOW_LEFT_COLUMN) // Left column visible
{ {
HTM_Txt ("<aside id=\"left_col\">"); HTM_Txt ("<aside id=\"left_col\">");
Lay_ShowLeftColumn (); Lay_ShowLeftColumn ();
HTM_Txt ("</aside>"); HTM_Txt ("</aside>");
} }
/* Right column */ /* Right column */
// Right column is written before central column // Right column is written before central column
// but it must be drawn at right using "position:absolute; right:0". // but it must be drawn at right using "position:absolute; right:0".
// The reason to write right column before central column // The reason to write right column before central column
// is that central column may hold a lot of content drawn slowly. // is that central column may hold a lot of content drawn slowly.
if (Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN) // Right column visible if (Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN) // Right column visible
{ {
HTM_Txt ("<aside id=\"right_col\">"); HTM_Txt ("<aside id=\"right_col\">");
Lay_ShowRightColumn (); Lay_ShowRightColumn ();
HTM_Txt ("</aside>"); HTM_Txt ("</aside>");
} }
/* Central (main) column */ /* Central (main) column */
switch (Gbl.Prefs.SideCols) switch (Gbl.Prefs.SideCols)
{ {
case 0: case 0:
HTM_DIV_Begin ("id=\"main_zone_central_none\""); HTM_DIV_Begin ("id=\"main_zone_central_none\"");
break; break;
case Lay_SHOW_LEFT_COLUMN: case Lay_SHOW_LEFT_COLUMN:
HTM_DIV_Begin ("id=\"main_zone_central_left\""); HTM_DIV_Begin ("id=\"main_zone_central_left\"");
break; break;
case Lay_SHOW_RIGHT_COLUMN: case Lay_SHOW_RIGHT_COLUMN:
HTM_DIV_Begin ("id=\"main_zone_central_right\""); HTM_DIV_Begin ("id=\"main_zone_central_right\"");
break; break;
case (Lay_SHOW_LEFT_COLUMN | Lay_SHOW_RIGHT_COLUMN): case (Lay_SHOW_LEFT_COLUMN | Lay_SHOW_RIGHT_COLUMN):
HTM_DIV_Begin ("id=\"main_zone_central_both\""); HTM_DIV_Begin ("id=\"main_zone_central_both\"");
break; break;
} }
HTM_DIV_Begin ("id=\"main_zone_central_container\" class=\"%s\"", HTM_DIV_Begin ("id=\"main_zone_central_container\" class=\"%s\"",
The_TabOnBgColors[Gbl.Prefs.Theme]); The_TabOnBgColors[Gbl.Prefs.Theme]);
/* Layout with horizontal or vertical menu */ /* Layout with horizontal or vertical menu */
HTM_DIV_Begin ("id=\"%s\"",LayoutMainZone[Gbl.Prefs.Menu]); HTM_DIV_Begin ("id=\"%s\"",LayoutMainZone[Gbl.Prefs.Menu]);
/* Menu */ /* Menu */
Mnu_WriteMenuThisTab (); Mnu_WriteMenuThisTab ();
/* Begin canvas: main zone for actions output */ /* Begin canvas: main zone for actions output */
HTM_MAIN_Begin ("MAIN_ZONE_CANVAS"); HTM_MAIN_Begin ("MAIN_ZONE_CANVAS");
/* If it is mandatory to read any information about course */ /* If it is mandatory to read any information about course */
if (Gbl.Crs.Info.ShowMsgMustBeRead) if (Gbl.Crs.Info.ShowMsgMustBeRead)
Inf_WriteMsgYouMustReadInfo (); Inf_WriteMsgYouMustReadInfo ();
/* Write title of the current action */ /* Write title of the current action */
if (Gbl.Prefs.Menu == Mnu_MENU_VERTICAL && if (Gbl.Prefs.Menu == Mnu_MENU_VERTICAL &&
Act_GetIndexInMenu (Gbl.Action.Act) >= 0) Act_GetIndexInMenu (Gbl.Action.Act) >= 0)
Lay_WriteTitleAction (); Lay_WriteTitleAction ();
Gbl.Layout.WritingHTMLStart = false; Gbl.Layout.WritingHTMLStart = false;
Gbl.Layout.HTMLStartWritten = true; Gbl.Layout.HTMLStartWritten = true;
/* Write message indicating number of clicks allowed before sending my photo */ /* Write message indicating number of clicks allowed before sending my photo */
Usr_InformAboutNumClicksBeforePhoto (); Usr_InformAboutNumClicksBeforePhoto ();
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1096,9 +1096,9 @@ static void Lay_WritePageTopHeading (void)
static void Lay_WriteBreadcrumb (void) static void Lay_WriteBreadcrumb (void)
{ {
HTM_Txt ("<nav id=\"breadcrumb\">"); HTM_Txt ("<nav id=\"breadcrumb\">");
Crs_PutIconToSelectMyCoursesInBreadcrumb (); Crs_PutIconToSelectMyCoursesInBreadcrumb ();
Hie_WriteHierarchyInBreadcrumb (); Hie_WriteHierarchyInBreadcrumb ();
Crs_WriteSelectorMyCoursesInBreadcrumb (); Crs_WriteSelectorMyCoursesInBreadcrumb ();
HTM_Txt ("</nav>"); HTM_Txt ("</nav>");
} }
@ -1117,16 +1117,16 @@ static void Lay_WriteTitleAction (void)
Gbl.Prefs.URLIconSet, Gbl.Prefs.URLIconSet,
Act_GetIcon (Act_GetSuperAction (Gbl.Action.Act))); Act_GetIcon (Act_GetSuperAction (Gbl.Action.Act)));
/***** Title *****/ /***** Title *****/
HTM_DIV_Begin ("class=\"%s\"",The_ClassTitleAction[Gbl.Prefs.Theme]); HTM_DIV_Begin ("class=\"%s\"",The_ClassTitleAction[Gbl.Prefs.Theme]);
HTM_TxtF ("%s &gt; %s",Txt_TABS_TXT[Act_GetTab (Gbl.Action.Act)], HTM_TxtF ("%s &gt; %s",Txt_TABS_TXT[Act_GetTab (Gbl.Action.Act)],
Act_GetTitleAction (Gbl.Action.Act)); Act_GetTitleAction (Gbl.Action.Act));
HTM_DIV_End (); HTM_DIV_End ();
/***** Subtitle *****/ /***** Subtitle *****/
HTM_DIV_Begin ("class=\"%s\"",The_ClassSubtitleAction[Gbl.Prefs.Theme]); HTM_DIV_Begin ("class=\"%s\"",The_ClassSubtitleAction[Gbl.Prefs.Theme]);
HTM_Txt (Act_GetSubtitleAction (Gbl.Action.Act)); HTM_Txt (Act_GetSubtitleAction (Gbl.Action.Act));
HTM_DIV_End (); HTM_DIV_End ();
/***** Container end *****/ /***** Container end *****/
HTM_DIV_End (); HTM_DIV_End ();
@ -1142,33 +1142,33 @@ static void Lay_ShowLeftColumn (void)
HTM_DIV_Begin ("style=\"width:160px;\""); HTM_DIV_Begin ("style=\"width:160px;\"");
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
if (Gbl.Usrs.Me.Logged)
{
/***** Most frequently used actions *****/
MFU_AllocateMFUActions (&ListMFUActions,6);
MFU_GetMFUActions (&ListMFUActions,6);
MFU_WriteSmallMFUActions (&ListMFUActions);
MFU_FreeMFUActions (&ListMFUActions);
}
else
/***** Institutional links *****/
Lnk_WriteMenuWithInstitutionalLinks ();
HTM_DIV_End ();
/***** Month *****/
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
Cal_DrawCurrentMonth ();
HTM_DIV_End ();
/***** Notices (yellow notes) *****/
if (Gbl.Hierarchy.Level == HieLvl_CRS)
{
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\""); HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
Not_ShowNotices (Not_LIST_BRIEF_NOTICES, if (Gbl.Usrs.Me.Logged)
-1L); // No notice highlighted {
/***** Most frequently used actions *****/
MFU_AllocateMFUActions (&ListMFUActions,6);
MFU_GetMFUActions (&ListMFUActions,6);
MFU_WriteSmallMFUActions (&ListMFUActions);
MFU_FreeMFUActions (&ListMFUActions);
}
else
/***** Institutional links *****/
Lnk_WriteMenuWithInstitutionalLinks ();
HTM_DIV_End (); HTM_DIV_End ();
}
/***** Month *****/
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
Cal_DrawCurrentMonth ();
HTM_DIV_End ();
/***** Notices (yellow notes) *****/
if (Gbl.Hierarchy.Level == HieLvl_CRS)
{
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
Not_ShowNotices (Not_LIST_BRIEF_NOTICES,
-1L); // No notice highlighted
HTM_DIV_End ();
}
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -1190,7 +1190,7 @@ static void Lay_ShowRightColumn (void)
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
{ {
HTM_DIV_Begin ("id=\"globalconnected\" class=\"LEFT_RIGHT_CELL\""); // Used for AJAX based refresh HTM_DIV_Begin ("id=\"globalconnected\" class=\"LEFT_RIGHT_CELL\""); // Used for AJAX based refresh
Con_ShowGlobalConnectedUsrs (); Con_ShowGlobalConnectedUsrs ();
HTM_DIV_End (); // Used for AJAX based refresh HTM_DIV_End (); // Used for AJAX based refresh
} }
@ -1198,15 +1198,15 @@ static void Lay_ShowRightColumn (void)
if (Gbl.Hierarchy.Level == HieLvl_CRS) // There is a course selected if (Gbl.Hierarchy.Level == HieLvl_CRS) // There is a course selected
{ {
HTM_DIV_Begin ("id=\"courseconnected\" class=\"LEFT_RIGHT_CELL\""); // Used for AJAX based refresh HTM_DIV_Begin ("id=\"courseconnected\" class=\"LEFT_RIGHT_CELL\""); // Used for AJAX based refresh
Gbl.Scope.Current = HieLvl_CRS; Gbl.Scope.Current = HieLvl_CRS;
Con_ShowConnectedUsrsBelongingToCurrentCrs (); Con_ShowConnectedUsrsBelongingToCurrentCrs ();
HTM_DIV_End (); // Used for AJAX based refresh HTM_DIV_End (); // Used for AJAX based refresh
} }
else if (Gbl.Usrs.Me.Logged) // I am logged else if (Gbl.Usrs.Me.Logged) // I am logged
{ {
/***** Suggest one user to follow *****/ /***** Suggest one user to follow *****/
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\""); HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
Fol_SuggestUsrsToFollowMainZoneOnRightColumn (); Fol_SuggestUsrsToFollowMainZoneOnRightColumn ();
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -1214,12 +1214,12 @@ static void Lay_ShowRightColumn (void)
{ {
/***** SWADroid advertisement *****/ /***** SWADroid advertisement *****/
HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\""); HTM_DIV_Begin ("class=\"LEFT_RIGHT_CELL\"");
HTM_A_Begin ("href=\"https://play.google.com/store/apps/details?id=es.ugr.swad.swadroid\"" HTM_A_Begin ("href=\"https://play.google.com/store/apps/details?id=es.ugr.swad.swadroid\""
" target=\"_blank\" title=\"%s\"", " target=\"_blank\" title=\"%s\"",
Txt_If_you_have_an_Android_device_try_SWADroid); Txt_If_you_have_an_Android_device_try_SWADroid);
HTM_IMG (Cfg_URL_ICON_PUBLIC,"SWADroid120x200.png","SWADroid", HTM_IMG (Cfg_URL_ICON_PUBLIC,"SWADroid120x200.png","SWADroid",
"style=\"width:150px; height:250px;\""); "style=\"width:150px; height:250px;\"");
HTM_A_End (); HTM_A_End ();
HTM_DIV_End (); HTM_DIV_End ();
} }
} }
@ -1267,7 +1267,7 @@ void Lay_PutContextualLinkIconText (Act_Action_t NextAction,const char *Anchor,
/***** Put icon and text with link *****/ /***** Put icon and text with link *****/
HTM_BUTTON_SUBMIT_Begin (Text,The_ClassFormLinkOutBoxBold[Gbl.Prefs.Theme],NULL); HTM_BUTTON_SUBMIT_Begin (Text,The_ClassFormLinkOutBoxBold[Gbl.Prefs.Theme],NULL);
Ico_PutIconTextLink (Icon,Text); Ico_PutIconTextLink (Icon,Text);
HTM_BUTTON_End (); HTM_BUTTON_End ();
/***** End form *****/ /***** End form *****/
@ -1301,7 +1301,7 @@ void Lay_PutContextualLinkIconTextOnSubmit (Act_Action_t NextAction,const char *
/***** Put icon with link *****/ /***** Put icon with link *****/
HTM_BUTTON_SUBMIT_Begin (Text,The_ClassFormLinkOutBoxBold[Gbl.Prefs.Theme],OnSubmit); HTM_BUTTON_SUBMIT_Begin (Text,The_ClassFormLinkOutBoxBold[Gbl.Prefs.Theme],OnSubmit);
Ico_PutIconTextLink (Icon,Text); Ico_PutIconTextLink (Icon,Text);
HTM_BUTTON_End (); HTM_BUTTON_End ();
/***** End form *****/ /***** End form *****/
@ -1334,29 +1334,33 @@ void Lay_PutContextualCheckbox (Act_Action_t NextAction,
if (FuncParams) if (FuncParams)
FuncParams (); FuncParams ();
/***** Begin container and label *****/ /***** Begin container *****/
HTM_DIV_Begin ("class=\"CONTEXT_OPT %s %s\" title=\"%s\"", HTM_DIV_Begin ("class=\"CONTEXT_OPT %s %s\" title=\"%s\"",
Checked ? "CHECKBOX_CHECKED" : Checked ? "CHECKBOX_CHECKED" :
"CHECKBOX_UNCHECKED", "CHECKBOX_UNCHECKED",
The_ClassFormOutBoxBold[Gbl.Prefs.Theme], The_ClassFormOutBoxBold[Gbl.Prefs.Theme],
Title); Title);
HTM_LABEL_Begin (NULL);
/****** Checkbox *****/ /***** Begin label *****/
HTM_INPUT_CHECKBOX (CheckboxName,HTM_SUBMIT_ON_CHANGE, HTM_LABEL_Begin (NULL);
"value=\"Y\"%s%s",
Checked ? " checked=\"checked\"" :
"",
Disabled ? " disabled=\"disabled\"" :
"");
/***** Text *****/ /****** Checkbox *****/
if (Text) HTM_INPUT_CHECKBOX (CheckboxName,HTM_SUBMIT_ON_CHANGE,
if (Text[0]) "value=\"Y\"%s%s",
HTM_TxtF ("&nbsp;%s",Text); Checked ? " checked=\"checked\"" :
"",
Disabled ? " disabled=\"disabled\"" :
"");
/***** End label and container *****/ /***** Text *****/
HTM_LABEL_End (); if (Text)
if (Text[0])
HTM_TxtF ("&nbsp;%s",Text);
/***** End label *****/
HTM_LABEL_End ();
/***** End container *****/
HTM_DIV_End (); HTM_DIV_End ();
/***** End form *****/ /***** End form *****/
@ -1513,9 +1517,9 @@ static void Lay_WriteFootFromHTMLFile (void)
{ {
HTM_Txt ("<footer id=\"foot_zone\">"); HTM_Txt ("<footer id=\"foot_zone\">");
/***** Copy HTML to output file *****/ /***** Copy HTML to output file *****/
Fil_FastCopyOfOpenFiles (FileHTML,Gbl.F.Out); Fil_FastCopyOfOpenFiles (FileHTML,Gbl.F.Out);
fclose (FileHTML); fclose (FileHTML);
HTM_Txt ("</footer>"); HTM_Txt ("</footer>");
} }
@ -1544,69 +1548,71 @@ void Lay_WriteHeaderClassPhoto (bool PrintView,bool DrawingClassPhoto,
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginWidePadding (10); HTM_TABLE_BeginWidePadding (10);
HTM_TR_Begin (NULL);
/***** First column: institution logo *****/ HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LT\" style=\"width:60px;\"");
if (InsCod > 0)
{
if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Hie.Ins.WWW);
Lgo_DrawLogo (HieLvl_INS,Hie.Ins.InsCod,Hie.Ins.ShrtName,40,NULL,true);
if (!PrintView)
HTM_A_End ();
}
HTM_TD_End ();
/***** Second column: class photo title *****/ /***** First column: institution logo *****/
HTM_TD_Begin ("class=\"CLASSPHOTO_TITLE CM\""); HTM_TD_Begin ("class=\"LT\" style=\"width:60px;\"");
if (InsCod > 0) if (InsCod > 0)
{ {
if (!PrintView) if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"", HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Hie.Ins.WWW);
Hie.Ins.WWW); Lgo_DrawLogo (HieLvl_INS,Hie.Ins.InsCod,Hie.Ins.ShrtName,40,NULL,true);
HTM_Txt (Hie.Ins.FullName); if (!PrintView)
if (!PrintView) HTM_A_End ();
HTM_A_End (); }
} HTM_TD_End ();
if (DegCod > 0)
{
if (Hie.Ins.InsCod > 0)
HTM_Txt (" - ");
if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"",
Hie.Deg.WWW);
HTM_Txt (Hie.Deg.FullName);
if (!PrintView)
HTM_A_End ();
}
HTM_BR ();
if (CrsCod > 0)
{
HTM_Txt (Hie.Crs.FullName);
if (DrawingClassPhoto && !Gbl.Usrs.ClassPhoto.AllGroups)
{
HTM_BR ();
Grp_WriteNamesOfSelectedGrps ();
}
}
HTM_TD_End ();
/***** Third column: degree logo *****/ /***** Second column: class photo title *****/
HTM_TD_Begin ("class=\"RT\" style=\"width:60px;\""); HTM_TD_Begin ("class=\"CLASSPHOTO_TITLE CM\"");
if (DegCod > 0) if (InsCod > 0)
{ {
if (!PrintView) if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"", HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"",
Hie.Deg.WWW); Hie.Ins.WWW);
Lgo_DrawLogo (HieLvl_DEG,Hie.Deg.DegCod,Hie.Deg.ShrtName,40,NULL,true); HTM_Txt (Hie.Ins.FullName);
if (!PrintView) if (!PrintView)
HTM_A_End (); HTM_A_End ();
} }
HTM_TD_End (); if (DegCod > 0)
{
if (Hie.Ins.InsCod > 0)
HTM_Txt (" - ");
if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"",
Hie.Deg.WWW);
HTM_Txt (Hie.Deg.FullName);
if (!PrintView)
HTM_A_End ();
}
HTM_BR ();
if (CrsCod > 0)
{
HTM_Txt (Hie.Crs.FullName);
if (DrawingClassPhoto && !Gbl.Usrs.ClassPhoto.AllGroups)
{
HTM_BR ();
Grp_WriteNamesOfSelectedGrps ();
}
}
HTM_TD_End ();
/***** Third column: degree logo *****/
HTM_TD_Begin ("class=\"RT\" style=\"width:60px;\"");
if (DegCod > 0)
{
if (!PrintView)
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"CLASSPHOTO_TITLE\"",
Hie.Deg.WWW);
Lgo_DrawLogo (HieLvl_DEG,Hie.Deg.DegCod,Hie.Deg.ShrtName,40,NULL,true);
if (!PrintView)
HTM_A_End ();
}
HTM_TD_End ();
HTM_TR_End ();
/***** End table *****/ /***** End table *****/
HTM_TR_End ();
HTM_TABLE_End (); HTM_TABLE_End ();
} }
@ -1629,19 +1635,19 @@ void Lay_AdvertisementMobile (void)
NULL,NULL, NULL,NULL,
NULL,Box_NOT_CLOSABLE,8); NULL,Box_NOT_CLOSABLE,8);
/***** Show advertisement *****/ /***** Show advertisement *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT CM\""); HTM_TD_Begin ("class=\"DAT CM\"");
HTM_A_Begin ("href=\"https://play.google.com/store/apps/details?id=es.ugr.swad.swadroid\"" HTM_A_Begin ("href=\"https://play.google.com/store/apps/details?id=es.ugr.swad.swadroid\""
" class=\"DAT\""); " class=\"DAT\"");
HTM_Txt (Txt_Stay_connected_with_SWADroid); HTM_Txt (Txt_Stay_connected_with_SWADroid);
HTM_BR (); HTM_BR ();
HTM_BR (); HTM_BR ();
HTM_IMG (Cfg_URL_ICON_PUBLIC,"SWADroid200x300.png",Txt_Stay_connected_with_SWADroid, HTM_IMG (Cfg_URL_ICON_PUBLIC,"SWADroid200x300.png",Txt_Stay_connected_with_SWADroid,
"style=\"width:250px; height:375px;\""); "style=\"width:250px; height:375px;\"");
HTM_A_End (); HTM_A_End ();
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
/***** End table and box *****/ /***** End table and box *****/
Box_BoxTableEnd (); Box_BoxTableEnd ();
@ -1702,14 +1708,14 @@ static void Lay_HelpTextEditor (const char *Text,const char *InlineMath,const ch
extern const char *Txt_Equation_centered; extern const char *Txt_Equation_centered;
HTM_DIV_Begin ("class=\"HELP_EDIT\""); HTM_DIV_Begin ("class=\"HELP_EDIT\"");
HTM_TxtF ("%s: %s" HTM_TxtF ("%s: %s"
" " " "
"%s: <code>%s</code>" "%s: <code>%s</code>"
" " " "
"%s: <code>%s</code>", "%s: <code>%s</code>",
Txt_Text,Text, Txt_Text,Text,
Txt_Inline_math,InlineMath, Txt_Inline_math,InlineMath,
Txt_Equation_centered,Equation); Txt_Equation_centered,Equation);
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -1723,11 +1729,13 @@ void Lay_BeginHTMLFile (FILE *File,const char *Title)
fprintf (File,"<!DOCTYPE html>\n" fprintf (File,"<!DOCTYPE html>\n"
"<html lang=\"%s\">\n" "<html lang=\"%s\">\n"
"<head>\n" "<head>\n"
"<meta http-equiv=\"Content-Type\"" "<meta http-equiv=\"Content-Type\""
" content=\"text/html;charset=windows-1252\" />\n" " content=\"text/html;charset=windows-1252\" />\n"
"<title>%s</title>\n" "<title>"
"</head>\n", "%s"
"</title>\n"
"</head>\n",
Lan_STR_LANG_ID[Gbl.Prefs.Language], // Language Lan_STR_LANG_ID[Gbl.Prefs.Language], // Language
Title); // Page title Title); // Page title
} }

View File

@ -39,6 +39,7 @@
#include "swad_HTML.h" #include "swad_HTML.h"
#include "swad_language.h" #include "swad_language.h"
#include "swad_link.h" #include "swad_link.h"
#include "swad_link_database.h"
#include "swad_parameter.h" #include "swad_parameter.h"
/*****************************************************************************/ /*****************************************************************************/
@ -72,16 +73,15 @@ static void Lnk_WriteListOfLinks (void);
static void Lnk_EditLinksInternal (void); static void Lnk_EditLinksInternal (void);
static void Lnk_PutIconsEditingLinks (__attribute__((unused)) void *Args); static void Lnk_PutIconsEditingLinks (__attribute__((unused)) void *Args);
static void Lnk_GetDataOfLink (MYSQL_RES *mysql_res,struct Link *Lnk);
static void Lnk_ListLinksForEdition (void); static void Lnk_ListLinksForEdition (void);
static void Lnk_PutParamLnkCod (void *LnkCod); static void Lnk_PutParamLnkCod (void *LnkCod);
static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName); static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName);
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod);
static void Lnk_UpdateLnkNameDB (long LnkCod,const char *FieldName,const char *NewLnkName);
static void Lnk_PutFormToCreateLink (void); static void Lnk_PutFormToCreateLink (void);
static void Lnk_PutHeadLinks (void); static void Lnk_PutHeadLinks (void);
static void Lnk_CreateLink (struct Link *Lnk);
static void Lnk_EditingLinkConstructor (void); static void Lnk_EditingLinkConstructor (void);
static void Lnk_EditingLinkDestructor (void); static void Lnk_EditingLinkDestructor (void);
@ -105,19 +105,19 @@ void Lnk_SeeLinks (void)
Lnk_PutIconsListingLinks,NULL, Lnk_PutIconsListingLinks,NULL,
Hlp_SYSTEM_Links,Box_NOT_CLOSABLE); Hlp_SYSTEM_Links,Box_NOT_CLOSABLE);
/***** Write all links *****/ /***** Write all links *****/
if (Gbl.Links.Num) // There are links if (Gbl.Links.Num) // There are links
Lnk_WriteListOfLinks (); Lnk_WriteListOfLinks ();
else // No links created else // No links created
Ale_ShowAlert (Ale_INFO,Txt_No_links); Ale_ShowAlert (Ale_INFO,Txt_No_links);
/***** Button to create link *****/ /***** Button to create link *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
{ {
Frm_BeginForm (ActEdiLnk); Frm_BeginForm (ActEdiLnk);
Btn_PutConfirmButton (Txt_New_link); Btn_PutConfirmButton (Txt_New_link);
Frm_EndForm (); Frm_EndForm ();
} }
/***** End box *****/ /***** End box *****/
Box_BoxEnd (); Box_BoxEnd ();
@ -166,13 +166,14 @@ void Lnk_WriteMenuWithInstitutionalLinks (void)
{ {
HTM_DIV_Begin ("id=\"institutional_links\""); HTM_DIV_Begin ("id=\"institutional_links\"");
Frm_BeginForm (ActSeeLnk); Frm_BeginForm (ActSeeLnk);
HTM_BUTTON_SUBMIT_Begin (Txt_Links,"BT_LINK LINK_TITLE",NULL); HTM_BUTTON_SUBMIT_Begin (Txt_Links,"BT_LINK LINK_TITLE",NULL);
HTM_TxtF ("%s",Txt_Links); HTM_TxtF ("%s",Txt_Links);
HTM_BUTTON_End (); HTM_BUTTON_End ();
Frm_EndForm (); Frm_EndForm ();
Lnk_WriteListOfLinks ();
Lnk_WriteListOfLinks ();
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -191,20 +192,20 @@ static void Lnk_WriteListOfLinks (void)
/***** List start *****/ /***** List start *****/
HTM_UL_Begin ("class=\"LIST_LEFT\""); HTM_UL_Begin ("class=\"LIST_LEFT\"");
/***** Write all links *****/ /***** Write all links *****/
for (NumLnk = 0; for (NumLnk = 0;
NumLnk < Gbl.Links.Num; NumLnk < Gbl.Links.Num;
NumLnk++) NumLnk++)
{ {
/* Write data of this link */ /* Write data of this link */
HTM_LI_Begin ("class=\"INS_LNK\""); HTM_LI_Begin ("class=\"INS_LNK\"");
HTM_A_Begin ("href=\"%s\" title=\"%s\" class=\"INS_LNK\" target=\"_blank\"", HTM_A_Begin ("href=\"%s\" title=\"%s\" class=\"INS_LNK\" target=\"_blank\"",
Gbl.Links.Lst[NumLnk].WWW, Gbl.Links.Lst[NumLnk].WWW,
Gbl.Links.Lst[NumLnk].FullName); Gbl.Links.Lst[NumLnk].FullName);
HTM_Txt (Gbl.Links.Lst[NumLnk].ShrtName); HTM_Txt (Gbl.Links.Lst[NumLnk].ShrtName);
HTM_A_End (); HTM_A_End ();
HTM_LI_End (); HTM_LI_End ();
} }
/***** List end *****/ /***** List end *****/
HTM_UL_End (); HTM_UL_End ();
@ -239,12 +240,12 @@ static void Lnk_EditLinksInternal (void)
Lnk_PutIconsEditingLinks,NULL, Lnk_PutIconsEditingLinks,NULL,
Hlp_SYSTEM_Links_edit,Box_NOT_CLOSABLE); Hlp_SYSTEM_Links_edit,Box_NOT_CLOSABLE);
/***** Put a form to create a new link *****/ /***** Put a form to create a new link *****/
Lnk_PutFormToCreateLink (); Lnk_PutFormToCreateLink ();
/***** Forms to edit current links *****/ /***** Forms to edit current links *****/
if (Gbl.Links.Num) if (Gbl.Links.Num)
Lnk_ListLinksForEdition (); Lnk_ListLinksForEdition ();
/***** End box *****/ /***** End box *****/
Box_BoxEnd (); Box_BoxEnd ();
@ -287,23 +288,12 @@ void Lnk_PutIconToViewLinks (void)
void Lnk_GetListLinks (void) void Lnk_GetListLinks (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumLnk; unsigned NumLnk;
struct Link *Lnk;
if (Gbl.DB.DatabaseIsOpen) if (Gbl.DB.DatabaseIsOpen)
{ {
/***** Get institutional links from database *****/ /***** Get institutional links from database *****/
Gbl.Links.Num = (unsigned) if ((Gbl.Links.Num = Lnk_DB_GetLinks (&mysql_res))) // Links found...
DB_QuerySELECT (&mysql_res,"can not get institutional links",
"SELECT LnkCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
"WWW" // row[3]
" FROM lnk_links"
" ORDER BY ShortName");
if (Gbl.Links.Num) // Places found...
{ {
/***** Create list with places *****/ /***** Create list with places *****/
if ((Gbl.Links.Lst = calloc ((size_t) Gbl.Links.Num, if ((Gbl.Links.Lst = calloc ((size_t) Gbl.Links.Num,
@ -314,22 +304,8 @@ void Lnk_GetListLinks (void)
for (NumLnk = 0; for (NumLnk = 0;
NumLnk < Gbl.Links.Num; NumLnk < Gbl.Links.Num;
NumLnk++) NumLnk++)
{
Lnk = &(Gbl.Links.Lst[NumLnk]);
/* Get next link */ /* Get next link */
row = mysql_fetch_row (mysql_res); Lnk_GetDataOfLink (mysql_res,&(Gbl.Links.Lst[NumLnk]));
/* Get link code (row[0]) */
if ((Lnk->LnkCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongLinkExit ();
/* Get the short name (row[0]), the full name (row[1])
and de URL (row[2]) of the link */
Str_Copy (Lnk->ShrtName,row[1],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[2],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[3],sizeof (Lnk->WWW ) - 1);
}
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -344,38 +320,43 @@ void Lnk_GetListLinks (void)
void Lnk_GetDataOfLinkByCod (struct Link *Lnk) void Lnk_GetDataOfLinkByCod (struct Link *Lnk)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/ /***** Clear data *****/
Lnk->ShrtName[0] = Lnk->FullName[0] = Lnk->WWW[0] = '\0'; Lnk->ShrtName[0] =
Lnk->FullName[0] =
Lnk->WWW[0] = '\0';
/***** Check if link code is correct *****/ /***** Check if link code is correct *****/
if (Lnk->LnkCod > 0) if (Lnk->LnkCod > 0)
{ {
/***** Get data of an institutional link from database *****/ /***** Get data of an institutional link from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of an institutional link", if (Lnk_DB_GetDataOfLinkByCod (&mysql_res,Lnk->LnkCod)) // Link found...
"SELECT ShortName," // row[0] Lnk_GetDataOfLink (mysql_res,Lnk);
"FullName," // row[1]
"WWW" // row[2]
" FROM lnk_links"
" WHERE LnkCod=%ld",
Lnk->LnkCod)) // Link found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the short name (row[0]), the full name (row[1])
and de URL (row[2]) of the link */
Str_Copy (Lnk->ShrtName,row[0],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[1],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[2],sizeof (Lnk->WWW ) - 1);
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
} }
/*****************************************************************************/
/**************************** Get data of link *******************************/
/*****************************************************************************/
static void Lnk_GetDataOfLink (MYSQL_RES *mysql_res,struct Link *Lnk)
{
MYSQL_ROW row;
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/***** Get the short name (row[0]),
the full name (row[1])
and the URL (row[2]) of the link *****/
Str_Copy (Lnk->ShrtName,row[0],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[1],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[2],sizeof (Lnk->WWW ) - 1);
}
/*****************************************************************************/ /*****************************************************************************/
/**************************** Free list of links *****************************/ /**************************** Free list of links *****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -403,60 +384,60 @@ static void Lnk_ListLinksForEdition (void)
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginWidePadding (2); HTM_TABLE_BeginWidePadding (2);
/***** Table head *****/ /***** Table head *****/
Lnk_PutHeadLinks (); Lnk_PutHeadLinks ();
/***** Write all the links *****/ /***** Write all the links *****/
for (NumLnk = 0; for (NumLnk = 0;
NumLnk < Gbl.Links.Num; NumLnk < Gbl.Links.Num;
NumLnk++) NumLnk++)
{ {
Lnk = &Gbl.Links.Lst[NumLnk]; Lnk = &Gbl.Links.Lst[NumLnk];
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
/* Put icon to remove link */ /* Put icon to remove link */
HTM_TD_Begin ("class=\"BM\""); HTM_TD_Begin ("class=\"BM\"");
Ico_PutContextualIconToRemove (ActRemLnk,NULL, Ico_PutContextualIconToRemove (ActRemLnk,NULL,
Lnk_PutParamLnkCod,&Lnk->LnkCod); Lnk_PutParamLnkCod,&Lnk->LnkCod);
HTM_TD_End (); HTM_TD_End ();
/* Link code */ /* Link code */
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Long (Lnk->LnkCod); HTM_Long (Lnk->LnkCod);
HTM_TD_End (); HTM_TD_End ();
/* Link short name */ /* Link short name */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenLnkSho); Frm_BeginForm (ActRenLnkSho);
Lnk_PutParamLnkCod (&Lnk->LnkCod); Lnk_PutParamLnkCod (&Lnk->LnkCod);
HTM_INPUT_TEXT ("ShortName",Lnk_MAX_CHARS_LINK_SHRT_NAME,Lnk->ShrtName, HTM_INPUT_TEXT ("ShortName",Lnk_MAX_CHARS_LINK_SHRT_NAME,Lnk->ShrtName,
HTM_SUBMIT_ON_CHANGE, HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME\" required=\"required\""); "class=\"INPUT_SHORT_NAME\" required=\"required\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Link full name */ /* Link full name */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenLnkFul); Frm_BeginForm (ActRenLnkFul);
Lnk_PutParamLnkCod (&Lnk->LnkCod); Lnk_PutParamLnkCod (&Lnk->LnkCod);
HTM_INPUT_TEXT ("FullName",Lnk_MAX_CHARS_LINK_FULL_NAME,Lnk->FullName, HTM_INPUT_TEXT ("FullName",Lnk_MAX_CHARS_LINK_FULL_NAME,Lnk->FullName,
HTM_SUBMIT_ON_CHANGE, HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME\" required=\"required\""); "class=\"INPUT_FULL_NAME\" required=\"required\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Link WWW */ /* Link WWW */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActChgLnkWWW); Frm_BeginForm (ActChgLnkWWW);
Lnk_PutParamLnkCod (&Lnk->LnkCod); Lnk_PutParamLnkCod (&Lnk->LnkCod);
HTM_INPUT_URL ("WWW",Lnk->WWW,HTM_SUBMIT_ON_CHANGE, HTM_INPUT_URL ("WWW",Lnk->WWW,HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\""); "class=\"INPUT_WWW_NARROW\" required=\"required\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
} }
/***** End table *****/ /***** End table *****/
HTM_TABLE_End (); HTM_TABLE_End ();
@ -501,10 +482,7 @@ void Lnk_RemoveLink (void)
Lnk_GetDataOfLinkByCod (Lnk_EditingLnk); Lnk_GetDataOfLinkByCod (Lnk_EditingLnk);
/***** Remove link *****/ /***** Remove link *****/
DB_QueryDELETE ("can not remove an institutional link", Lnk_DB_RemoveLink (Lnk_EditingLnk->LnkCod);
"DELETE FROM lnk_links"
" WHERE LnkCod=%ld",
Lnk_EditingLnk->LnkCod);
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -588,14 +566,14 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
if (strcmp (CurrentLnkName,NewLnkName)) // Different names if (strcmp (CurrentLnkName,NewLnkName)) // Different names
{ {
/***** If link was in database... *****/ /***** If link was in database... *****/
if (Lnk_CheckIfLinkNameExists (ParamName,NewLnkName,Lnk_EditingLnk->LnkCod)) if (Lnk_DB_CheckIfLinkNameExists (ParamName,NewLnkName,Lnk_EditingLnk->LnkCod))
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists, Txt_The_link_X_already_exists,
NewLnkName); NewLnkName);
else else
{ {
/* Update the table changing old name by new name */ /* Update the table changing old name by new name */
Lnk_UpdateLnkNameDB (Lnk_EditingLnk->LnkCod,FieldName,NewLnkName); Lnk_DB_UpdateLnkName (Lnk_EditingLnk->LnkCod,FieldName,NewLnkName);
/* Write message to show the change made */ /* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -615,37 +593,6 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
Str_Copy (CurrentLnkName,NewLnkName,MaxBytes); Str_Copy (CurrentLnkName,NewLnkName,MaxBytes);
} }
/*****************************************************************************/
/********************** Check if the name of link exists *********************/
/*****************************************************************************/
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{
/***** Get number of links with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of an institutional link"
" already existed",
"SELECT COUNT(*)"
" FROM lnk_links"
" WHERE %s='%s'"
" AND LnkCod<>%ld",
FieldName,Name,LnkCod) != 0);
}
/*****************************************************************************/
/************ Update link name in table of institutional links ***************/
/*****************************************************************************/
static void Lnk_UpdateLnkNameDB (long LnkCod,const char *FieldName,const char *NewLnkName)
{
/***** Update institutional link changing old name by new name */
DB_QueryUPDATE ("can not update the name of an institutional link",
"UPDATE lnk_links"
" SET %s='%s'"
" WHERE LnkCod=%ld",
FieldName,NewLnkName,
LnkCod);
}
/*****************************************************************************/ /*****************************************************************************/
/**************** Change the WWW of an institutional link ********************/ /**************** Change the WWW of an institutional link ********************/
/*****************************************************************************/ /*****************************************************************************/
@ -673,12 +620,7 @@ void Lnk_ChangeLinkWWW (void)
if (NewWWW[0]) if (NewWWW[0])
{ {
/***** Update the table changing old WWW by new WWW *****/ /***** Update the table changing old WWW by new WWW *****/
DB_QueryUPDATE ("can not update the web of an institutional link", Lnk_DB_UpdateLnkWWW (Lnk_EditingLnk->LnkCod,NewWWW);
"UPDATE lnk_links"
" SET WWW='%s'"
" WHERE LnkCod=%ld",
NewWWW,
Lnk_EditingLnk->LnkCod);
/***** Message to show the change made *****/ /***** Message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -721,46 +663,46 @@ static void Lnk_PutFormToCreateLink (void)
/***** Begin form *****/ /***** Begin form *****/
Frm_BeginForm (ActNewLnk); Frm_BeginForm (ActNewLnk);
/***** Begin box and table *****/ /***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_New_link, Box_BoxTableBegin (NULL,Txt_New_link,
NULL,NULL, NULL,NULL,
Hlp_SYSTEM_Links_edit,Box_NOT_CLOSABLE,2); Hlp_SYSTEM_Links_edit,Box_NOT_CLOSABLE,2);
/***** Write heading *****/ /***** Write heading *****/
Lnk_PutHeadLinks (); Lnk_PutHeadLinks ();
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
/***** Link code *****/ /***** Link code *****/
HTM_TD_Begin ("class=\"BM\""); HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Empty (1); HTM_TD_Empty (1);
/***** Link short name *****/ /***** Link short name *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("ShortName",Lnk_MAX_CHARS_LINK_SHRT_NAME,Lnk_EditingLnk->ShrtName, HTM_INPUT_TEXT ("ShortName",Lnk_MAX_CHARS_LINK_SHRT_NAME,Lnk_EditingLnk->ShrtName,
HTM_DONT_SUBMIT_ON_CHANGE, HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME\" required=\"required\""); "class=\"INPUT_SHORT_NAME\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
/***** Link full name *****/ /***** Link full name *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("FullName",Lnk_MAX_CHARS_LINK_FULL_NAME,Lnk_EditingLnk->FullName, HTM_INPUT_TEXT ("FullName",Lnk_MAX_CHARS_LINK_FULL_NAME,Lnk_EditingLnk->FullName,
HTM_DONT_SUBMIT_ON_CHANGE, HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME\" required=\"required\""); "class=\"INPUT_FULL_NAME\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
/***** Link WWW *****/ /***** Link WWW *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_URL ("WWW",Lnk_EditingLnk->WWW,HTM_DONT_SUBMIT_ON_CHANGE, HTM_INPUT_URL ("WWW",Lnk_EditingLnk->WWW,HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\""); "class=\"INPUT_WWW_NARROW\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
/***** End table, send button and end box *****/ /***** End table, send button and end box *****/
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_link); Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_link);
/***** End form *****/ /***** End form *****/
Frm_EndForm (); Frm_EndForm ();
@ -779,11 +721,11 @@ static void Lnk_PutHeadLinks (void)
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TH (1,1,"BM",NULL); HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"RM",Txt_Code); HTM_TH (1,1,"RM",Txt_Code);
HTM_TH (1,1,"LM",Txt_Short_name); HTM_TH (1,1,"LM",Txt_Short_name);
HTM_TH (1,1,"LM",Txt_Full_name); HTM_TH (1,1,"LM",Txt_Full_name);
HTM_TH (1,1,"LM",Txt_WWW); HTM_TH (1,1,"LM",Txt_WWW);
HTM_TR_End (); HTM_TR_End ();
} }
@ -816,11 +758,11 @@ void Lnk_ReceiveFormNewLink (void)
Lnk_EditingLnk->FullName[0]) // If there's a link name Lnk_EditingLnk->FullName[0]) // If there's a link name
{ {
/***** If name of link was in database... *****/ /***** If name of link was in database... *****/
if (Lnk_CheckIfLinkNameExists ("ShortName",Lnk_EditingLnk->ShrtName,-1L)) if (Lnk_DB_CheckIfLinkNameExists ("ShortName",Lnk_EditingLnk->ShrtName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists, Txt_The_link_X_already_exists,
Lnk_EditingLnk->ShrtName); Lnk_EditingLnk->ShrtName);
else if (Lnk_CheckIfLinkNameExists ("FullName",Lnk_EditingLnk->FullName,-1L)) else if (Lnk_DB_CheckIfLinkNameExists ("FullName",Lnk_EditingLnk->FullName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists, Txt_The_link_X_already_exists,
Lnk_EditingLnk->FullName); Lnk_EditingLnk->FullName);
@ -829,7 +771,7 @@ void Lnk_ReceiveFormNewLink (void)
Txt_You_must_specify_the_URL_of_the_new_link); Txt_You_must_specify_the_URL_of_the_new_link);
else // Add new link to database else // Add new link to database
{ {
Lnk_CreateLink (Lnk_EditingLnk); Lnk_DB_CreateLink (Lnk_EditingLnk);
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_link_X, Txt_Created_new_link_X,
Lnk_EditingLnk->ShrtName); Lnk_EditingLnk->ShrtName);
@ -840,23 +782,6 @@ void Lnk_ReceiveFormNewLink (void)
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_link); Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_link);
} }
/*****************************************************************************/
/**************************** Create a new link ******************************/
/*****************************************************************************/
static void Lnk_CreateLink (struct Link *Lnk)
{
/***** Create a new link *****/
DB_QueryINSERT ("can not create institutional link",
"INSERT INTO lnk_links"
" (ShortName,FullName,WWW)"
" VALUES"
" ('%s','%s','%s')",
Lnk->ShrtName,
Lnk->FullName,
Lnk->WWW);
}
/*****************************************************************************/ /*****************************************************************************/
/************************* Place constructor/destructor **********************/ /************************* Place constructor/destructor **********************/
/*****************************************************************************/ /*****************************************************************************/

170
swad_link_database.c Normal file
View File

@ -0,0 +1,170 @@
// swad_link_database.c: institutional links, operations with database
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2021 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <stddef.h> // For NULL
// #include <stdlib.h> // For calloc
// #include <string.h> // For string functions
// #include "swad_banner.h"
// #include "swad_box.h"
// #include "swad_constant.h"
#include "swad_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
// #include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_language.h"
// #include "swad_link.h"
#include "swad_link_database.h"
// #include "swad_parameter.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
// extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Create a new link ******************************/
/*****************************************************************************/
void Lnk_DB_CreateLink (const struct Link *Lnk)
{
DB_QueryINSERT ("can not create institutional link",
"INSERT INTO lnk_links"
" (ShortName,FullName,WWW)"
" VALUES"
" ('%s','%s','%s')",
Lnk->ShrtName,
Lnk->FullName,
Lnk->WWW);
}
/*****************************************************************************/
/************ Update link name in table of institutional links ***************/
/*****************************************************************************/
void Lnk_DB_UpdateLnkName (long LnkCod,const char *FieldName,const char *NewLnkName)
{
DB_QueryUPDATE ("can not update the name of an institutional link",
"UPDATE lnk_links"
" SET %s='%s'"
" WHERE LnkCod=%ld",
FieldName,NewLnkName,
LnkCod);
}
/*****************************************************************************/
/****************** Update link changing old WWW by new WWW ******************/
/*****************************************************************************/
void Lnk_DB_UpdateLnkWWW (long LnkCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
{
DB_QueryUPDATE ("can not update the web of an institutional link",
"UPDATE lnk_links"
" SET WWW='%s'"
" WHERE LnkCod=%ld",
NewWWW,
LnkCod);
}
/*****************************************************************************/
/************************** Get institutional links **************************/
/*****************************************************************************/
unsigned Lnk_DB_GetLinks (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get institutional links",
"SELECT LnkCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
"WWW" // row[3]
" FROM lnk_links"
" ORDER BY ShortName");
}
/*****************************************************************************/
/**************************** Get link full name *****************************/
/*****************************************************************************/
unsigned Lnk_DB_GetDataOfLinkByCod (MYSQL_RES **mysql_res,long LnkCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of an institutional link",
"SELECT ShortName," // row[0]
"FullName," // row[1]
"WWW" // row[2]
" FROM lnk_links"
" WHERE LnkCod=%ld",
LnkCod);
}
/*****************************************************************************/
/********************** Check if the name of link exists *********************/
/*****************************************************************************/
bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{
return (DB_QueryCOUNT ("can not check if the name of an institutional link"
" already existed",
"SELECT COUNT(*)"
" FROM lnk_links"
" WHERE %s='%s'"
" AND LnkCod<>%ld",
FieldName,Name,
LnkCod) != 0);
}
/*****************************************************************************/
/******************************* Remove a link *******************************/
/*****************************************************************************/
void Lnk_DB_RemoveLink (long LnkCod)
{
DB_QueryDELETE ("can not remove an institutional link",
"DELETE FROM lnk_links"
" WHERE LnkCod=%ld",
LnkCod);
}

52
swad_link_database.h Normal file
View File

@ -0,0 +1,52 @@
// swad_link_database.h: institutional links, operations with database
#ifndef _SWAD_LNK_DB
#define _SWAD_LNK_DB
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2021 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_link.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/
void Lnk_DB_CreateLink (const struct Link *Lnk);
void Lnk_DB_UpdateLnkName (long LnkCod,const char *FieldName,const char *NewLnkName);
void Lnk_DB_UpdateLnkWWW (long LnkCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
unsigned Lnk_DB_GetLinks (MYSQL_RES **mysql_res);
unsigned Lnk_DB_GetDataOfLinkByCod (MYSQL_RES **mysql_res,long LnkCod);
bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod);
void Lnk_DB_RemoveLink (long LnkCod);
#endif

View File

@ -313,6 +313,22 @@ void Set_ChangeSideCols (void)
Set_SetSettingsFromIP (); Set_SetSettingsFromIP ();
} }
/*****************************************************************************/
/**************** Update my language to the current language *****************/
/*****************************************************************************/
void Set_DB_UpdateMySettingsAboutLanguage (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
DB_QueryUPDATE ("can not update your language",
"UPDATE usr_data"
" SET Language='%s'"
" WHERE UsrCod=%ld",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/ /*****************************************************************************/
/************** Update layout of side colums on user data table **************/ /************** Update layout of side colums on user data table **************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -50,6 +50,7 @@ void Set_RemoveOldSettingsFromIP (void);
void Set_ChangeSideCols (void); void Set_ChangeSideCols (void);
unsigned Set_GetParamSideCols (void); unsigned Set_GetParamSideCols (void);
void Set_DB_UpdateMySettingsAboutLanguage (void);
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat); void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek); void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek);
void Set_DB_ChangeIconSet (const char *IconSetId); void Set_DB_ChangeIconSet (const char *IconSetId);