diff --git a/swad_browser.c b/swad_browser.c index e1c95bbc1..7014a1b1c 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -65,6 +65,7 @@ #include "swad_photo.h" #include "swad_profile.h" #include "swad_profile_database.h" +#include "swad_program_database.h" #include "swad_project.h" #include "swad_project_database.h" #include "swad_role.h" @@ -8325,7 +8326,7 @@ void Brw_GetLinkToFile (void) if (Found) { /***** Copy link to file into resource clipboard *****/ - // Prg_DB_CopyToClipboard (&FileMetadata); + Prg_DB_CopyToClipboard (PrgRsc_DOCUMENT,FileMetadata.FilCod); /***** Write sucess message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Link_to_resource_X_copied_into_clipboard, diff --git a/swad_changelog.h b/swad_changelog.h index 165bec6f5..bce9f7224 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -606,15 +606,16 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate TODO: Attach pdf files in multimedia. */ -#define Log_PLATFORM_VERSION "SWAD 21.117 (2022-09-12)" +#define Log_PLATFORM_VERSION "SWAD 21.117.1 (2022-09-12)" #define CSS_FILE "swad21.107.1.css" #define JS_FILE "swad21.100.js" /* + Version 21.117.1: Sep 12, 2022 Copy link to file into resource clipboard. (329561 lines) Version 21.117: Sep 12, 2022 New database table with clipboards for program resources. New actions to get link to file in course document area. (329514 lines) 1 change necessary in database: ALTER TABLE prg_resources ADD COLUMN Type ENUM('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') NOT NULL DEFAULT 'none' AFTER Hidden; -CREATE TABLE IF NOT EXISTS prg_clipboards (UsrCod INT NOT NULL,CrsCod INT NOT NULL,Type ENUM('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') NOT NULL DEFAULT 'none',Cod INT NOT NULL DEFAULT -1,CopyTime TIMESTAMP,INDEX(UsrCod,CrsCod,CopyTime),INDEX(CrsCod,Type,Cod),INDEX(CopyTime)); +CREATE TABLE IF NOT EXISTS prg_clipboards (UsrCod INT NOT NULL,CrsCod INT NOT NULL,Type ENUM('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') NOT NULL DEFAULT 'none',Cod INT NOT NULL DEFAULT -1,CopyTime TIMESTAMP,UNIQUE INDEX(UsrCod,CrsCod,Type,Cod),INDEX(CrsCod,Type,Cod),INDEX(CopyTime)); If you want to use MyISAM: ALTER TABLE prg_clipboards ENGINE=MyISAM; diff --git a/swad_database.c b/swad_database.c index 3ff7fc75f..d3cd53b9e 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2456,10 +2456,10 @@ mysql> DESCRIBE prg_clipboards; +----------+--------------------------------------------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------------------------------------------------------------+------+-----+---------+-------+ -| UsrCod | int | NO | MUL | NULL | | -| CrsCod | int | NO | MUL | NULL | | -| Type | enum('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') | NO | | none | | -| Cod | int | NO | | -1 | | +| UsrCod | int | NO | PRI | NULL | | +| CrsCod | int | NO | PRI | NULL | | +| Type | enum('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') | NO | PRI | none | | +| Cod | int | NO | PRI | -1 | | | CopyTime | timestamp | YES | MUL | NULL | | +----------+--------------------------------------------------------------------+------+-----+---------+-------+ 5 rows in set (0,00 sec) @@ -2480,7 +2480,7 @@ mysql> DESCRIBE prg_clipboards; "'for') NOT NULL DEFAULT 'none'," "Cod INT NOT NULL DEFAULT -1," "CopyTime TIMESTAMP," - "INDEX(UsrCod,CrsCod,CopyTime)," + "UNIQUE INDEX(UsrCod,CrsCod,Type,Cod)," "INDEX(CrsCod,Type,Cod)," "INDEX(CopyTime))"); diff --git a/swad_program_database.c b/swad_program_database.c index 4d9bc9082..749f106a0 100644 --- a/swad_program_database.c +++ b/swad_program_database.c @@ -30,6 +30,32 @@ #include "swad_program.h" #include "swad_program_resource.h" +/*****************************************************************************/ +/**************************** Private constants ******************************/ +/*****************************************************************************/ + +const char *Prg_ResourceTypesDB[PrgRsc_NUM_TYPES] = + { + [PrgRsc_NONE ] = "non", + // gui TEACHING_GUIDE // Link to teaching guide + // bib BIBLIOGRAPHY // Link to bibliography + // faq FAQ // Link to FAQ + // lnk LINKS // Link to links + // tmt TIMETABLE // Link to timetable + [PrgRsc_ASSIGNMENT ] = "asg", + // prj PROJECT // A project is only for some students + [PrgRsc_CALL_FOR_EXAM ] = "cfe", + // tst TEST // User selects tags, teacher should select + [PrgRsc_EXAM ] = "exa", + [PrgRsc_GAME ] = "gam", + [PrgRsc_SURVEY ] = "svy", + [PrgRsc_DOCUMENT ] = "doc", + [PrgRsc_MARKS ] = "mrk", + // grp GROUPS // ??? User select groups + [PrgRsc_ATTENDANCE_EVENT] = "att", + [PrgRsc_FORUM_THREAD ] = "for", + }; + /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ @@ -645,3 +671,45 @@ void Prg_DB_UpdateRscInd (long RscCod,int RscInd) RscInd, RscCod); } + +/*****************************************************************************/ +/**************** Get resources in the current course clipboard **************/ +/*****************************************************************************/ +/* +mysql> SELECT * FROM prg_clipboards; ++--------+--------+------+-----+---------------------+ +| UsrCod | CrsCod | Type | Cod | CopyTime | ++--------+--------+------+-----+---------------------+ +| 1 | 1 | doc | 33 | 2022-09-12 12:08:25 | +| 1 | 1 | doc | 28 | 2022-09-12 12:08:31 | ++--------+--------+------+-----+---------------------+ +2 rows in set (0,00 sec) +*/ +/*****************************************************************************/ +/********************** Copy link to resource into clipboard *****************/ +/*****************************************************************************/ +/* +mysql> DESCRIBE prg_clipboards; ++----------+--------------------------------------------------------------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------------------------------------------------------------+------+-----+---------+-------+ +| UsrCod | int | NO | PRI | NULL | | +| CrsCod | int | NO | PRI | NULL | | +| Type | enum('none','asg','cfe','exa','gam','svy','doc','mrk','att','for') | NO | PRI | none | | +| Cod | int | NO | PRI | -1 | | +| CopyTime | timestamp | YES | MUL | NULL | | ++----------+--------------------------------------------------------------------+------+-----+---------+-------+ +5 rows in set (0,00 sec) +*/ +void Prg_DB_CopyToClipboard (PrgRsc_Type_t Type,long Cod) + { + DB_QueryREPLACE ("can not copy link to resource clipboard", + "REPLACE INTO prg_clipboards" + " (UsrCod,CrsCod,Type,Cod,CopyTime)" + " VALUES" + " (%ld,%ld,'%s',%ld,NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod, + Prg_ResourceTypesDB[Type], + Cod); + } diff --git a/swad_program_database.h b/swad_program_database.h index 8e968960c..24ac105c3 100644 --- a/swad_program_database.h +++ b/swad_program_database.h @@ -77,4 +77,6 @@ void Prg_DB_HideOrUnhideResource (long RscCod,bool Hide); void Prg_DB_LockTableResources (void); void Prg_DB_UpdateRscInd (long RscCod,int RscInd); +void Prg_DB_CopyToClipboard (PrgRsc_Type_t Type,long Cod); + #endif diff --git a/swad_program_resource.c b/swad_program_resource.c index 8b807864c..c6f80a08d 100644 --- a/swad_program_resource.c +++ b/swad_program_resource.c @@ -49,51 +49,6 @@ typedef enum PrgRsc_MOVE_DOWN, } PrgRsc_MoveUpDown_t; -#define PrgRsc_NUM_TYPES 10 -typedef enum - { - PrgRsc_NONE, - // gui TEACHING_GUIDE // Link to teaching guide - // bib BIBLIOGRAPHY // Link to bibliography - // faq FAQ // Link to FAQ - // lnk LINKS // Link to links - // tmt TIMETABLE // Link to timetable - PrgRsc_ASSIGNMENT, - // prj PROJECT // A project is only for some students - PrgRsc_CALL_FOR_EXAM, - // tst TEST // User selects tags, teacher should select - PrgRsc_EXAM, - PrgRsc_GAME, - PrgRsc_SURVEY, - PrgRsc_DOCUMENT, - PrgRsc_MARKS, - // grp GROUPS // ??? User select groups - PrgRsc_ATTENDANCE_EVENT, - PrgRsc_FORUM_THREAD, - } PrgRsc_Type_t; - -const char *PrgRsc_TypesDB[PrgRsc_NUM_TYPES] = - { - [PrgRsc_NONE ] = "non", - // gui TEACHING_GUIDE // Link to teaching guide - // bib BIBLIOGRAPHY // Link to bibliography - // faq FAQ // Link to FAQ - // lnk LINKS // Link to links - // tmt TIMETABLE // Link to timetable - [PrgRsc_ASSIGNMENT ] = "asg", - // prj PROJECT // A project is only for some students - [PrgRsc_CALL_FOR_EXAM ] = "cfe", - // tst TEST // User selects tags, teacher should select - [PrgRsc_EXAM ] = "exa", - [PrgRsc_GAME ] = "gam", - [PrgRsc_SURVEY ] = "svy", - [PrgRsc_DOCUMENT ] = "doc", - [PrgRsc_MARKS ] = "mrk", - // grp GROUPS // ??? User select groups - [PrgRsc_ATTENDANCE_EVENT] = "att", - [PrgRsc_FORUM_THREAD ] = "for", - }; - /*****************************************************************************/ /***************************** Private variables *****************************/ /*****************************************************************************/ diff --git a/swad_program_resource.h b/swad_program_resource.h index a9f93b3f8..25a452fe5 100644 --- a/swad_program_resource.h +++ b/swad_program_resource.h @@ -48,6 +48,29 @@ struct PrgRsc_Resource char Title[PrgRsc_MAX_BYTES_PROGRAM_RESOURCE_TITLE + 1]; }; +#define PrgRsc_NUM_TYPES 10 +typedef enum + { + PrgRsc_NONE, + // gui TEACHING_GUIDE // Link to teaching guide + // bib BIBLIOGRAPHY // Link to bibliography + // faq FAQ // Link to FAQ + // lnk LINKS // Link to links + // tmt TIMETABLE // Link to timetable + PrgRsc_ASSIGNMENT, + // prj PROJECT // A project is only for some students + PrgRsc_CALL_FOR_EXAM, + // tst TEST // User selects tags, teacher should select + PrgRsc_EXAM, + PrgRsc_GAME, + PrgRsc_SURVEY, + PrgRsc_DOCUMENT, + PrgRsc_MARKS, + // grp GROUPS // ??? User select groups + PrgRsc_ATTENDANCE_EVENT, + PrgRsc_FORUM_THREAD, + } PrgRsc_Type_t; + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/