diff --git a/sql/swad.sql b/sql/swad.sql index 649c98bbd..8ab01a502 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -634,18 +634,16 @@ CREATE TABLE IF NOT EXISTS gam_users ( -- CREATE TABLE IF NOT EXISTS games ( GamCod INT NOT NULL AUTO_INCREMENT, - Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys', - Cod INT NOT NULL DEFAULT -1, + CrsCod INT NOT NULL DEFAULT -1, Hidden ENUM('N','Y') NOT NULL DEFAULT 'N', NumNotif INT NOT NULL DEFAULT 0, - Roles INT NOT NULL DEFAULT 0, UsrCod INT NOT NULL, StartTime DATETIME NOT NULL, EndTime DATETIME NOT NULL, Title VARCHAR(2047) NOT NULL, Txt TEXT NOT NULL, UNIQUE INDEX(GamCod), - INDEX(Scope,Cod)); + INDEX(CrsCod)); -- -- Table hidden_params: stores some hidden parameters passed from a page to another using database instead of forms -- diff --git a/swad_action.c b/swad_action.c index c7e4e4dc7..c7a171e07 100644 --- a/swad_action.c +++ b/swad_action.c @@ -588,7 +588,7 @@ Assessment: 436. ActSeeOneTstResMe Show one test result of me as student 437. ActSeeOneTstResOth Show one test result of other user - 438. ActSeeOneSvy Show one survey + 438. ActSeeSvy Show one survey 439. ActAnsSvy Answer a survey 440. ActFrmNewSvy Form to create a new survey 441. ActEdiOneSvy Edit one survey @@ -605,7 +605,7 @@ Assessment: 452. ActReqRemSvyQst Request the removal of a question of a survey 453. ActRemSvyQst Confirm the removal of a question of a survey - 454. ActSeeOneGam Show one game + 454. ActSeeGam Show one game 455. ActPlyGam Start playing a game 456. ActPlyGam1stQst Show first question when playing a game 457. ActPlyGamNxtQst Show next question when playing a game @@ -2012,7 +2012,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActSeeAsg */{ 801, 1,TabAss,ActSeeAsg ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Asg_SeeAssignments ,"edit" }, /* ActSeePrj */{1674, 2,TabAss,ActSeePrj ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Prj_SeeProjects ,"file-alt" }, /* ActReqTst */{ 103, 3,TabAss,ActReqTst ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Tst_ShowFormAskTst ,"check" }, - /* ActSeeAllGam */{1649, 4,TabAss,ActSeeAllGam ,0x200,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_SeeAllGames ,"gamepad" }, + /* ActSeeAllGam */{1649, 4,TabAss,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_SeeAllGames ,"gamepad" }, /* ActSeeAllSvy */{ 966, 5,TabAss,ActSeeAllSvy ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_SeeAllSurveys ,"poll" }, /* ActSeeAllExaAnn */{ 85, 6,TabAss,ActSeeAllExaAnn ,0x3F8,0x3C7, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Exa_ListExamAnnouncementsSee ,"bullhorn" }, @@ -2134,31 +2134,31 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActSeeUsrTstRes */{1081,-1,TabUnk,ActReqTst ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Tst_ShowUsrsTestResults ,NULL}, /* ActSeeOneTstResOth*/{1082,-1,TabUnk,ActReqTst ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Tst_ShowOneTestResult ,NULL}, - /* ActSeeOneGam */{1650,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_SeeOneGame ,NULL}, - /* ActPlyGam */{1670,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_PlayGame ,NULL}, - /* ActPlyGam1stQst */{1671,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_NEW_TAB,NULL ,Gam_PlayGameNextQuestion ,NULL}, - /* ActPlyGamNxtQst */{1672,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_2ND_TAB,NULL ,Gam_PlayGameNextQuestion ,NULL}, - /* ActPlyGamAns */{1673,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_2ND_TAB,NULL ,Gam_PlayGameShowAnswers ,NULL}, - /* ActAnsGam */{1651,-1,TabUnk,ActSeeAllGam ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ReceiveGameAnswers ,NULL}, - /* ActFrmNewGam */{1652,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, - /* ActEdiOneGam */{1653,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, - /* ActNewGam */{1654,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RecFormGame ,NULL}, - /* ActChgGam */{1655,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RecFormGame ,NULL}, - /* ActReqRemGam */{1656,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AskRemGame ,NULL}, - /* ActRemGam */{1657,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RemoveGame ,NULL}, - /* ActReqRstGam */{1658,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AskResetGame ,NULL}, - /* ActRstGam */{1659,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ResetGame ,NULL}, - /* ActHidGam */{1660,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_HideGame ,NULL}, - /* ActShoGam */{1661,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_UnhideGame ,NULL}, - /* ActAddOneGamQst */{1662,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestNewQuestion ,NULL}, - /* ActGamLstTstQst */{1666,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Tst_ListQuestionsToSelect ,NULL}, - /* ActAddTstQstToGam */{1667,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AddTstQuestionsToGame ,NULL}, - /* ActReqRemGamQst */{1664,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestRemoveQst ,NULL}, - /* ActRemGamQst */{1665,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RemoveQst ,NULL}, - /* ActUp_GamQst */{1668,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_MoveUpQst ,NULL}, - /* ActDwnGamQst */{1669,-1,TabUnk,ActSeeAllGam ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_MoveDownQst ,NULL}, + /* ActSeeGam */{1650,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_SeeOneGame ,NULL}, + /* ActPlyGam */{1670,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_PlayGame ,NULL}, + /* ActPlyGam1stQst */{1671,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,NULL ,Gam_PlayGameNextQuestion ,NULL}, + /* ActPlyGamNxtQst */{1672,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,NULL ,Gam_PlayGameNextQuestion ,NULL}, + /* ActPlyGamAns */{1673,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,NULL ,Gam_PlayGameShowAnswers ,NULL}, + /* ActAnsGam */{1651,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ReceiveGameAnswers ,NULL}, + /* ActFrmNewGam */{1652,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, + /* ActEdiOneGam */{1653,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, + /* ActNewGam */{1654,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RecFormGame ,NULL}, + /* ActChgGam */{1655,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RecFormGame ,NULL}, + /* ActReqRemGam */{1656,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AskRemGame ,NULL}, + /* ActRemGam */{1657,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RemoveGame ,NULL}, + /* ActReqRstGam */{1658,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AskResetGame ,NULL}, + /* ActRstGam */{1659,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ResetGame ,NULL}, + /* ActHidGam */{1660,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_HideGame ,NULL}, + /* ActShoGam */{1661,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_UnhideGame ,NULL}, + /* ActAddOneGamQst */{1662,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestNewQuestion ,NULL}, + /* ActGamLstTstQst */{1666,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Tst_ListQuestionsToSelect ,NULL}, + /* ActAddTstQstToGam */{1667,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_AddTstQuestionsToGame ,NULL}, + /* ActReqRemGamQst */{1664,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestRemoveQst ,NULL}, + /* ActRemGamQst */{1665,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RemoveQst ,NULL}, + /* ActUp_GamQst */{1668,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_MoveUpQst ,NULL}, + /* ActDwnGamQst */{1669,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_MoveDownQst ,NULL}, - /* ActSeeOneSvy */{ 982,-1,TabUnk,ActSeeAllSvy ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_SeeOneSurvey ,NULL}, + /* ActSeeSvy */{ 982,-1,TabUnk,ActSeeAllSvy ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_SeeOneSurvey ,NULL}, /* ActAnsSvy */{ 983,-1,TabUnk,ActSeeAllSvy ,0x3F8,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_ReceiveSurveyAnswers ,NULL}, /* ActFrmNewSvy */{ 973,-1,TabUnk,ActSeeAllSvy ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_RequestCreatOrEditSvy ,NULL}, /* ActEdiOneSvy */{ 974,-1,TabUnk,ActSeeAllSvy ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Svy_RequestCreatOrEditSvy ,NULL}, @@ -4170,7 +4170,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActEdiOneSvyQst, // #979 ActRcvSvyQst, // #980 ActRemSvyQst, // #981 - ActSeeOneSvy, // #982 + ActSeeSvy, // #982 ActAnsSvy, // #983 ActReqRstSvy, // #984 ActRstSvy, // #985 @@ -4838,7 +4838,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActRemNETCrs, // #1647 ActChgCtrPlcCfg, // #1648 ActSeeAllGam, // #1649 - ActSeeOneGam, // #1650 + ActSeeGam, // #1650 ActAnsGam, // #1651 ActFrmNewGam, // #1652 ActEdiOneGam, // #1653 diff --git a/swad_action.h b/swad_action.h index 8e821e7af..ffca49bd1 100644 --- a/swad_action.h +++ b/swad_action.h @@ -608,7 +608,7 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActSeeUsrTstRes (ActChgCrsTT1stDay + 114) #define ActSeeOneTstResOth (ActChgCrsTT1stDay + 115) -#define ActSeeOneGam (ActChgCrsTT1stDay + 116) +#define ActSeeGam (ActChgCrsTT1stDay + 116) #define ActPlyGam (ActChgCrsTT1stDay + 117) #define ActPlyGam1stQst (ActChgCrsTT1stDay + 118) #define ActPlyGamNxtQst (ActChgCrsTT1stDay + 119) @@ -632,7 +632,7 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActUp_GamQst (ActChgCrsTT1stDay + 137) #define ActDwnGamQst (ActChgCrsTT1stDay + 138) -#define ActSeeOneSvy (ActChgCrsTT1stDay + 139) +#define ActSeeSvy (ActChgCrsTT1stDay + 139) #define ActAnsSvy (ActChgCrsTT1stDay + 140) #define ActFrmNewSvy (ActChgCrsTT1stDay + 141) #define ActEdiOneSvy (ActChgCrsTT1stDay + 142) diff --git a/swad_changelog.h b/swad_changelog.h index a322a026b..d29fd75bf 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -448,10 +448,17 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.121.2 (2019-05-17)" +#define Log_PLATFORM_VERSION "SWAD 18.122 (2019-05-18)" #define CSS_FILE "swad18.112.1.css" #define JS_FILE "swad18.116.5.js" /* + Version 18.122: May 18, 2019 Games available for students. + Scope and roles removed from games. (242145 lines) + 3 changes necessary in database: +ALTER TABLE games DROP INDEX Scope; +ALTER TABLE games DROP COLUMN Scope,DROP COLUMN Roles; +ALTER TABLE games CHANGE COLUMN Cod CrsCod INT NOT NULL DEFAULT -1,ADD INDEX (CrsCod); + Version 18.121.2: May 17, 2019 Fixed bug in exporting tests. (242700 lines) Version 18.121.1: May 16, 2019 Fixed bug in renaming of institution. (242697 lines) Version 18.121: May 13, 2019 Module swad_web_service is renamed as swad_API. diff --git a/swad_database.c b/swad_database.c index 0b479c5f0..45db45f3e 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1306,39 +1306,33 @@ mysql> DESCRIBE forum_thread; /***** Table games *****/ /* mysql> DESCRIBE games; -+-----------+-------------------------------------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+-----------+-------------------------------------------+------+-----+---------+----------------+ -| GamCod | int(11) | NO | PRI | NULL | auto_increment | -| Scope | enum('Sys','Cty','Ins','Ctr','Deg','Crs') | NO | MUL | Sys | | -| Cod | int(11) | NO | | -1 | | -| DegCod | int(11) | NO | | -1 | | -| CrsCod | int(11) | NO | | -1 | | -| Hidden | enum('N','Y') | NO | | N | | -| NumNotif | int(11) | NO | | 0 | | -| Roles | int(11) | NO | | 0 | | -| UsrCod | int(11) | NO | | NULL | | -| StartTime | datetime | NO | | NULL | | -| EndTime | datetime | NO | | NULL | | -| Title | varchar(2047) | NO | | NULL | | -| Txt | text | NO | | NULL | | -+-----------+-------------------------------------------+------+-----+---------+----------------+ -13 rows in set (0,00 sec) ++-----------+---------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-----------+---------------+------+-----+---------+----------------+ +| GamCod | int(11) | NO | PRI | NULL | auto_increment | +| CrsCod | int(11) | NO | MUL | -1 | | +| Hidden | enum('N','Y') | NO | | N | | +| NumNotif | int(11) | NO | | 0 | | +| UsrCod | int(11) | NO | | NULL | | +| StartTime | datetime | NO | | NULL | | +| EndTime | datetime | NO | | NULL | | +| Title | varchar(2047) | NO | | NULL | | +| Txt | text | NO | | NULL | | ++-----------+---------------+------+-----+---------+----------------+ +9 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS games (" "GamCod INT NOT NULL AUTO_INCREMENT," - "Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys'," - "Cod INT NOT NULL DEFAULT -1," + "CrsCod INT NOT NULL DEFAULT -1," "Hidden ENUM('N','Y') NOT NULL DEFAULT 'N'," "NumNotif INT NOT NULL DEFAULT 0," - "Roles INT NOT NULL DEFAULT 0," "UsrCod INT NOT NULL," "StartTime DATETIME NOT NULL," "EndTime DATETIME NOT NULL," - "Title VARCHAR(2047) NOT NULL," // Svy_MAX_BYTES_SURVEY_TITLE + "Title VARCHAR(2047) NOT NULL," // Gam_MAX_BYTES_SURVEY_TITLE "Txt TEXT NOT NULL," // Cns_MAX_BYTES_TEXT "UNIQUE INDEX(GamCod)," - "INDEX(Scope,Cod))"); + "INDEX(CrsCod))"); /***** Table gam_answers *****/ /* diff --git a/swad_game.c b/swad_game.c index 1553ef1c8..cf1154fc1 100644 --- a/swad_game.c +++ b/swad_game.c @@ -80,6 +80,9 @@ const char *Gam_StrAnswerTypesDB[Gam_NUM_ANS_TYPES] = /***************************** Private variables *****************************/ /*****************************************************************************/ +long Gam_CurrentGamCod; // Used as parameter in contextual links +long Gam_CurrentQstCod; // Used as parameter in contextual links + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ @@ -100,20 +103,13 @@ static void Gam_WriteStatus (struct Game *Game); static void Gam_GetParamGameOrder (void); static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, - const char *Anchor, - bool ShowOnlyThisGame); + const char *Anchor); static void Gam_PutParamsToPlayGame1stQst (void); static void Gam_PutParams (void); -static void Gam_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed, - unsigned *HiddenAllowed); - static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); -static void Gam_PutButtonToResetGame (void); - static bool Gam_CheckIfSimilarGameExists (struct Game *Game); -static void Gam_SetDefaultAndAllowedScope (struct Game *Game); static void Gam_ShowLstGrpsToEditGame (long GamCod); static void Gam_CreateGame (struct Game *Game,const char *Txt); @@ -422,13 +418,6 @@ static void Gam_ShowOneGame (long GamCod, extern const char *Txt_View_game; extern const char *Txt_No_of_questions; extern const char *Txt_No_of_users; - extern const char *Txt_Scope; - extern const char *Txt_Country; - extern const char *Txt_Institution; - extern const char *Txt_Centre; - extern const char *Txt_Degree; - extern const char *Txt_Course; - extern const char *Txt_Users; extern const char *Txt_Play; extern const char *Txt_View_game_results; char *Anchor = NULL; @@ -444,6 +433,7 @@ static void Gam_ShowOneGame (long GamCod, /***** Get data of this game *****/ Game.GamCod = GamCod; Gam_GetDataOfGameByCod (&Game); + Gam_CurrentGamCod = Game.GamCod; // Used as parameter in contextual links /***** Set anchor string *****/ Frm_SetAnchorStr (Game.GamCod,&Anchor); @@ -452,18 +442,34 @@ static void Gam_ShowOneGame (long GamCod, if (ShowOnlyThisGame) Tbl_StartTableWide (2); - /***** Write first row of data of this assignment *****/ - /* Forms to remove/edit this assignment */ - fprintf (Gbl.F.Out,"" - ""); + + /***** Icons related to this game *****/ + fprintf (Gbl.F.Out,""); + if (Game.Status.ICanEdit) - Gam_PutFormsToRemEditOneGame (&Game,Anchor,ShowOnlyThisGame); + /* Icons to remove/edit this game */ + Gam_PutFormsToRemEditOneGame (&Game,Anchor); + + if (ShowOnlyThisGame) + /* Icon to show first question */ + Lay_PutContextualLinkOnlyIcon (ActPlyGam1stQst,NULL, + Gam_PutParamsToPlayGame1stQst, + "play.svg", + Txt_Play); + else + /* Icon to play game */ + Lay_PutContextualLinkOnlyIcon (ActPlyGam,NULL,Gam_PutParams, + "play.svg", + Txt_Play); + fprintf (Gbl.F.Out,""); - /* Start date/time */ + /***** Start date/time *****/ UniqueId++; fprintf (Gbl.F.Out,""); + + /* Game title */ Lay_StartArticle (Anchor); - Frm_StartForm (ActSeeOneGam); + Frm_StartForm (ActSeeGam); Gam_PutParamGameCod (GamCod); - Gam_PutHiddenParamGameOrder (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); + // Gam_PutHiddenParamGameOrder (); + // Grp_PutParamWhichGrps (); + // Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); Frm_LinkFormSubmit (Txt_View_game, Game.Status.Visible ? "ASG_TITLE" : "ASG_TITLE_LIGHT",NULL); @@ -519,9 +527,8 @@ static void Gam_ShowOneGame (long GamCod, Frm_EndForm (); Lay_EndArticle (); - /* Number of questions and number of distinct users who have already answered this game */ - fprintf (Gbl.F.Out,"
%s: %u; %s: %u
" - "", + /* Number of questions and number of distinct students who have already answered */ + fprintf (Gbl.F.Out,"
%s: %u; %s: %u
", Game.Status.Visible ? "ASG_GRP" : "ASG_GRP_LIGHT", Txt_No_of_questions, @@ -529,7 +536,13 @@ static void Gam_ShowOneGame (long GamCod, Txt_No_of_users, Game.NumUsrs); - /* Status of the game */ + /* Groups whose students can answer this game */ + if (Gbl.Crs.Grps.NumGrps) + Gam_GetAndWriteNamesOfGrpsAssociatedToGame (&Game); + + fprintf (Gbl.F.Out,""); + + /***** Status of the game *****/ fprintf (Gbl.F.Out,""); - Frm_StartForm (ActPlyGam); - Gam_PutParamGameCod (Game.GamCod); - Gam_PutHiddenParamGameOrder (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); - Btn_PutCreateButtonInline (Txt_Play); - Frm_EndForm (); - - fprintf (Gbl.F.Out,""); - } - else // Show several games - { - /* Possible button to answer this game */ - if (Game.Status.ICanAnswer) + /* Possible button to play the game */ + if (Game.Status.Open) { - fprintf (Gbl.F.Out,"
"); - - Frm_StartForm (ActSeeOneGam); + Frm_StartForm (ActPlyGam); Gam_PutParamGameCod (Game.GamCod); Gam_PutHiddenParamGameOrder (); Grp_PutParamWhichGrps (); Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); Btn_PutCreateButtonInline (Txt_Play); Frm_EndForm (); - - fprintf (Gbl.F.Out,"
"); } - /* Possible button to see the result of the game */ - else if (Game.Status.ICanViewResults) - { - fprintf (Gbl.F.Out,"
"); - Frm_StartForm (ActSeeOneGam); + /* Possible button to see the result of the game */ + if (Game.Status.ICanViewResults) + { + Frm_StartForm (ActSeeGam); Gam_PutParamGameCod (Game.GamCod); Gam_PutHiddenParamGameOrder (); Grp_PutParamWhichGrps (); Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); Btn_PutConfirmButtonInline (Txt_View_game_results); Frm_EndForm (); - - fprintf (Gbl.F.Out,"
"); } + + fprintf (Gbl.F.Out,""); + } + else // Show several games + { + fprintf (Gbl.F.Out,"
"); + + /* Possible button to answer this game */ + if (Game.Status.ICanAnswer) + { + Frm_StartForm (ActPlyGam); + Gam_PutParamGameCod (Game.GamCod); + Gam_PutHiddenParamGameOrder (); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); + Btn_PutCreateButtonInline (Txt_Play); + Frm_EndForm (); + } + + fprintf (Gbl.F.Out,"
"); } - fprintf (Gbl.F.Out,"" - ""); + fprintf (Gbl.F.Out,""); - /***** Write second row of data of this game *****/ + /***** End 1st row of this game *****/ + fprintf (Gbl.F.Out,""); + + /***** Start 2nd row of this game *****/ fprintf (Gbl.F.Out,"" ""); - /* Scope of the game */ - fprintf (Gbl.F.Out,"
%s: ", - Game.Status.Visible ? "ASG_GRP" : - "ASG_GRP_LIGHT", - Txt_Scope); - switch (Game.Scope) - { - case Hie_UNK: // Unknown - Lay_ShowErrorAndExit ("Wrong game scope."); - break; - case Hie_SYS: // System - fprintf (Gbl.F.Out,"%s", - Cfg_PLATFORM_SHORT_NAME); - break; - case Hie_CTY: // Country - fprintf (Gbl.F.Out,"%s %s", - Txt_Country,Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - break; - case Hie_INS: // Institution - fprintf (Gbl.F.Out,"%s %s", - Txt_Institution,Gbl.Hierarchy.Ins.ShrtName); - break; - case Hie_CTR: // Centre - fprintf (Gbl.F.Out,"%s %s", - Txt_Centre,Gbl.Hierarchy.Ctr.ShrtName); - break; - case Hie_DEG: // Degree - fprintf (Gbl.F.Out,"%s %s", - Txt_Degree,Gbl.Hierarchy.Deg.ShrtName); - break; - case Hie_CRS: // Course - fprintf (Gbl.F.Out,"%s %s", - Txt_Course,Gbl.Hierarchy.Crs.ShrtName); - break; - } - fprintf (Gbl.F.Out,"
"); - - /* Users' roles who can answer the game */ - fprintf (Gbl.F.Out,"
%s:
", - Game.Status.Visible ? "ASG_GRP" : - "ASG_GRP_LIGHT", - Txt_Users); - Rol_WriteSelectorRoles (1 << Rol_STD | - 1 << Rol_NET | - 1 << Rol_TCH, - Game.Roles, - true,false); - fprintf (Gbl.F.Out,"
"); - - /* Groups whose users can answer this game */ - if (Game.Scope == Hie_CRS) - if (Gbl.Crs.Grps.NumGrps) - Gam_GetAndWriteNamesOfGrpsAssociatedToGame (&Game); - /* Text of the game */ Gam_GetGameTxtFromDB (Game.GamCod,Txt); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, @@ -716,8 +678,6 @@ static void Gam_WriteStatus (struct Game *Game) extern const char *Txt_Visible_game; extern const char *Txt_Closed_game; extern const char *Txt_Open_game; - extern const char *Txt_SURVEY_Type_of_user_not_allowed; - extern const char *Txt_SURVEY_Type_of_user_allowed; extern const char *Txt_GAME_You_belong_to_the_scope_of_the_game; extern const char *Txt_GAME_You_dont_belong_to_the_scope_of_the_game; extern const char *Txt_SURVEY_You_have_already_answered; @@ -746,18 +706,6 @@ static void Gam_WriteStatus (struct Game *Game) "STATUS_RED_LIGHT", Txt_Closed_game); - /* Write whether game can be answered by me or not depending on user type */ - if (Game->Status.IAmLoggedWithAValidRoleToAnswer) - fprintf (Gbl.F.Out,"
  • %s
  • ", - Game->Status.Visible ? "STATUS_GREEN" : - "STATUS_GREEN_LIGHT", - Txt_SURVEY_Type_of_user_allowed); - else - fprintf (Gbl.F.Out,"
  • %s
  • ", - Game->Status.Visible ? "STATUS_RED" : - "STATUS_RED_LIGHT", - Txt_SURVEY_Type_of_user_not_allowed); - /* Write whether game can be answered by me or not depending on groups */ if (Game->Status.IBelongToScope) fprintf (Gbl.F.Out,"
  • %s
  • ", @@ -813,14 +761,11 @@ void Gam_PutHiddenParamGameOrder (void) /*****************************************************************************/ static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, - const char *Anchor, - bool ShowOnlyThisGame) + const char *Anchor) { extern const char *Txt_Reset; extern const char *Txt_Play; - Gbl.Games.CurrentGamCod = Game->GamCod; // Used as parameter in contextual links - /***** Put icon to remove game *****/ Ico_PutContextualIconToRemove (ActReqRemGam,Gam_PutParams); @@ -837,18 +782,6 @@ static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, /***** Put icon to edit game *****/ Ico_PutContextualIconToEdit (ActEdiOneGam,Gam_PutParams); - - if (ShowOnlyThisGame) - /***** Put icon to show first question *****/ - Lay_PutContextualLinkOnlyIcon (ActPlyGam1stQst,NULL, - Gam_PutParamsToPlayGame1stQst, - "play.svg", - Txt_Play); - else - /***** Put icon to play game *****/ - Lay_PutContextualLinkOnlyIcon (ActPlyGam,NULL,Gam_PutParams, - "play.svg", - Txt_Play); } /*****************************************************************************/ @@ -867,8 +800,8 @@ static void Gam_PutParamsToPlayGame1stQst (void) static void Gam_PutParams (void) { - if (Gbl.Games.CurrentGamCod > 0) - Gam_PutParamGameCod (Gbl.Games.CurrentGamCod); + if (Gam_CurrentGamCod > 0) + Gam_PutParamGameCod (Gam_CurrentGamCod); Att_PutHiddenParamAttOrder (); Grp_PutParamWhichGrps (); @@ -881,7 +814,7 @@ static void Gam_PutParams (void) void Gam_GetListGames (void) { - char *SubQuery[Hie_NUM_LEVELS]; + char *SubQuery; static const char *OrderBySubQuery[Gam_NUM_ORDERS] = { "StartTime DESC,EndTime DESC,Title DESC", // Gam_ORDER_BY_START_DATE @@ -891,115 +824,46 @@ void Gam_GetListGames (void) MYSQL_ROW row; unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumGame; - unsigned ScopesAllowed = 0; - unsigned HiddenAllowed = 0; - long Cods[Hie_NUM_LEVELS]; - Hie_Level_t Scope; - bool SubQueryFilled = false; /***** Free list of games *****/ if (Gbl.Games.LstIsRead) Gam_FreeListGames (); - /***** Set allowed and hidden scopes to get list depending on my user's role *****/ - Gam_SetAllowedAndHiddenScopes (&ScopesAllowed,&HiddenAllowed); - /***** Get list of games from database *****/ - Cods[Hie_SYS] = -1L; // System - Cods[Hie_CTY] = Gbl.Hierarchy.Cty.CtyCod; // Country - Cods[Hie_INS] = Gbl.Hierarchy.Ins.InsCod; // Institution - Cods[Hie_CTR] = Gbl.Hierarchy.Ctr.CtrCod; // Centre - Cods[Hie_DEG] = Gbl.Hierarchy.Deg.DegCod; // Degree - Cods[Hie_CRS] = Gbl.Hierarchy.Crs.CrsCod; // Course - - /* Fill subqueries for system, country, institution, centre and degree */ - for (Scope = Hie_SYS; - Scope <= Hie_DEG; - Scope++) - if (ScopesAllowed & 1 << Scope) - { - if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)", - SubQueryFilled ? " OR " : - "", - Sco_GetDBStrFromScope (Scope),Cods[Scope], - (HiddenAllowed & 1 << Scope) ? "" : - " AND Hidden='N'") < 0) - Lay_NotEnoughMemoryExit (); - SubQueryFilled = true; - } - else - { - if (asprintf (&SubQuery[Scope],"%s","") < 0) - Lay_NotEnoughMemoryExit (); - } - /* Fill subquery for course */ - if (ScopesAllowed & 1 << Hie_CRS) + if (Gbl.Crs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS) { - if (Gbl.Crs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS) - { - if (asprintf (&SubQuery[Hie_CRS],"%s(" - "Scope='%s' AND Cod=%ld%s" - " AND " - "(GamCod NOT IN" - " (SELECT GamCod FROM gam_grp)" - " OR" - " GamCod IN" - " (SELECT gam_grp.GamCod" - " FROM gam_grp,crs_grp_usr" - " WHERE crs_grp_usr.UsrCod=%ld" - " AND gam_grp.GrpCod=crs_grp_usr.GrpCod))" - ")", - SubQueryFilled ? " OR " : - "", - Sco_GetDBStrFromScope (Hie_CRS),Cods[Hie_CRS], - (HiddenAllowed & 1 << Hie_CRS) ? "" : - " AND Hidden='N'", - Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - } - else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS - { - if (asprintf (&SubQuery[Hie_CRS],"%s(Scope='%s' AND Cod=%ld%s)", - SubQueryFilled ? " OR " : - "", - Sco_GetDBStrFromScope (Hie_CRS),Cods[Hie_CRS], - (HiddenAllowed & 1 << Hie_CRS) ? "" : - " AND Hidden='N'") < 0) - Lay_NotEnoughMemoryExit (); - } - SubQueryFilled = true; - } - else - { - if (asprintf (&SubQuery[Hie_CRS],"%s","") < 0) - Lay_NotEnoughMemoryExit (); - } + if (asprintf (&SubQuery,"CrsCod=%ld" + " AND" + "(GamCod NOT IN" + " (SELECT GamCod FROM gam_grp)" + " OR" + " GamCod IN" + " (SELECT gam_grp.GamCod" + " FROM gam_grp,crs_grp_usr" + " WHERE crs_grp_usr.UsrCod=%ld" + " AND gam_grp.GrpCod=crs_grp_usr.GrpCod))", + Gbl.Hierarchy.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + } + else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS + { + if (asprintf (&SubQuery,"CrsCod=%ld", + Gbl.Hierarchy.Crs.CrsCod) < 0) + Lay_NotEnoughMemoryExit (); + } /* Make query */ - if (SubQueryFilled) - { - /* Make query */ - NumRows = DB_QuerySELECT (&mysql_res,"can not get games", - "SELECT GamCod FROM games" - " WHERE %s%s%s%s%s%s" - " ORDER BY %s", - SubQuery[Hie_SYS], - SubQuery[Hie_CTY], - SubQuery[Hie_INS], - SubQuery[Hie_CTR], - SubQuery[Hie_DEG], - SubQuery[Hie_CRS], - OrderBySubQuery[Gbl.Games.SelectedOrder]); - } - else - Lay_ShowErrorAndExit ("Can not get list of games."); + NumRows = DB_QuerySELECT (&mysql_res,"can not get games", + "SELECT GamCod FROM games" + " WHERE %s" + " ORDER BY %s", + SubQuery, + OrderBySubQuery[Gbl.Games.SelectedOrder]); - /* Free allocated memory for subqueries */ - for (Scope = Hie_SYS; - Scope <= Hie_CRS; - Scope++) - free ((void *) SubQuery[Scope]); + /* Free allocated memory for subquery */ + free ((void *) SubQuery); if (NumRows) // Games found... { @@ -1029,173 +893,6 @@ void Gam_GetListGames (void) Gbl.Games.LstIsRead = true; } -/*****************************************************************************/ -/*** Set allowed and hidden scopes to get list depending on my user's role ***/ -/*****************************************************************************/ - -static void Gam_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed, - unsigned *HiddenAllowed) - { - switch (Gbl.Usrs.Me.Role.Logged) - { - case Rol_UNK: // User not logged in ********************************* - *ScopesAllowed = 0; - *HiddenAllowed = 0; - break; - case Rol_GST: // User not belonging to any course ******************* - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - break; - case Rol_USR: // Student or teacher in other courses... - // ...but not belonging to the current course ********* - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod)) - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod)) - { - *ScopesAllowed |= 1 << Hie_INS; - if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod)) - { - *ScopesAllowed |= 1 << Hie_CTR; - if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod)) - *ScopesAllowed |= 1 << Hie_DEG; - } - } - } - break; - case Rol_STD: // Student in current course ************************** - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod)) - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod)) - { - *ScopesAllowed |= 1 << Hie_INS; - if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod)) - { - *ScopesAllowed |= 1 << Hie_CTR; - if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod)) - { - *ScopesAllowed |= 1 << Hie_DEG; - if (Gbl.Usrs.Me.IBelongToCurrentCrs) - *ScopesAllowed |= 1 << Hie_CRS; - } - } - } - } - break; - case Rol_NET: // Non-editing teacher in current course ************** - case Rol_TCH: // Teacher in current course ************************** - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod)) - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod)) - { - *ScopesAllowed |= 1 << Hie_INS; - if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod)) - { - *ScopesAllowed |= 1 << Hie_CTR; - if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod)) - { - *ScopesAllowed |= 1 << Hie_DEG; - if (Gbl.Usrs.Me.IBelongToCurrentCrs) - { - *ScopesAllowed |= 1 << Hie_CRS; - *HiddenAllowed |= 1 << Hie_CRS; // A non-editing teacher or teacher can view hidden course games - } - } - } - } - } - break; - case Rol_DEG_ADM: // Degree administrator ******************************* - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected - { - *ScopesAllowed |= 1 << Hie_INS; - if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected - { - *ScopesAllowed |= 1 << Hie_CTR; - if (Gbl.Hierarchy.Deg.DegCod > 0) // Degree selected - { - *ScopesAllowed |= 1 << Hie_DEG; - *HiddenAllowed |= 1 << Hie_DEG; // A degree admin can view hidden degree games - } - } - } - } - break; - case Rol_CTR_ADM: // Centre administrator ******************************* - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected - { - *ScopesAllowed |= 1 << Hie_INS; - if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected - { - *ScopesAllowed |= 1 << Hie_CTR; - *HiddenAllowed |= 1 << Hie_CTR; // A centre admin can view hidden centre games - } - } - } - break; - case Rol_INS_ADM: // Institution administrator ************************** - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 0; - if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected - { - *ScopesAllowed |= 1 << Hie_CTY; - if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected - { - *ScopesAllowed |= 1 << Hie_INS; - *HiddenAllowed |= 1 << Hie_INS; // An institution admin can view hidden institution games - } - } - break; - case Rol_SYS_ADM: // System administrator (superuser) ******************* - *ScopesAllowed = 1 << Hie_SYS; - *HiddenAllowed = 1 << Hie_SYS; // A system admin can view hidden system games - if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected - { - *ScopesAllowed |= 1 << Hie_CTY; - *HiddenAllowed |= 1 << Hie_CTY; // A system admin can view hidden country games - if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected - { - *ScopesAllowed |= 1 << Hie_INS; - *HiddenAllowed |= 1 << Hie_INS; // A system admin can view hidden institution games - if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected - { - *ScopesAllowed |= 1 << Hie_CTR; - *HiddenAllowed |= 1 << Hie_CTR; // A system admin can view hidden centre games - if (Gbl.Hierarchy.Deg.DegCod > 0) // Degree selected - { - *ScopesAllowed |= 1 << Hie_DEG; - *HiddenAllowed |= 1 << Hie_DEG; // A system admin can view hidden degree games - if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected - { - *ScopesAllowed |= 1 << Hie_CRS; - *HiddenAllowed |= 1 << Hie_CRS; // A system admin can view hidden course games - } - } - } - } - } - break; - } - } - /*****************************************************************************/ /********************* Get game data using its code ************************/ /*****************************************************************************/ @@ -1208,11 +905,13 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /***** Get data of game from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", - "SELECT GamCod,Scope,Cod,Hidden,Roles,UsrCod," - "UNIX_TIMESTAMP(StartTime)," - "UNIX_TIMESTAMP(EndTime)," - "NOW() BETWEEN StartTime AND EndTime," - "Title" + "SELECT GamCod," // row[0] + "Hidden," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW() BETWEEN StartTime AND EndTime," // row[5] + "Title" // row[6] " FROM games" " WHERE GamCod=%ld", Game->GamCod); @@ -1224,79 +923,42 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /* Get code of the game (row[0]) */ Game->GamCod = Str_ConvertStrCodToLongCod (row[0]); - /* Get game scope (row[1]) */ - if ((Game->Scope = Sco_GetScopeFromDBStr (row[1])) == Hie_UNK) - Lay_ShowErrorAndExit ("Wrong game scope."); + /* Get whether the game is hidden (row[1]) */ + Game->Status.Visible = (row[1][0] == 'N'); - /* Get code of the country, institution, centre, degree or course (row[2]) */ - Game->Cod = Str_ConvertStrCodToLongCod (row[2]); + /* Get author of the game (row[2]) */ + Game->UsrCod = Str_ConvertStrCodToLongCod (row[2]); - /* Get whether the game is hidden (row[3]) */ - Game->Status.Visible = (row[3][0] == 'N'); + /* Get start date (row[3] holds the start UTC time) */ + Game->TimeUTC[Att_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]); - /* Get roles (row[4]) */ - if (sscanf (row[4],"%u",&Game->Roles) != 1) - Lay_ShowErrorAndExit ("Error when reading roles of game."); + /* Get end date (row[4] holds the end UTC time) */ + Game->TimeUTC[Att_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]); - /* Get author of the game (row[5]) */ - Game->UsrCod = Str_ConvertStrCodToLongCod (row[5]); + /* Get whether the game is open or closed (row(5)) */ + Game->Status.Open = (row[5][0] == '1'); - /* Get start date (row[6] holds the start UTC time) */ - Game->TimeUTC[Att_START_TIME] = Dat_GetUNIXTimeFromStr (row[6]); - - /* Get end date (row[7] holds the end UTC time) */ - Game->TimeUTC[Att_END_TIME ] = Dat_GetUNIXTimeFromStr (row[7]); - - /* Get whether the game is open or closed (row(8)) */ - Game->Status.Open = (row[8][0] == '1'); - - /* Get the title of the game (row[9]) */ - Str_Copy (Game->Title,row[9], + /* Get the title of the game (row[6]) */ + Str_Copy (Game->Title,row[6], Gam_MAX_BYTES_SURVEY_TITLE); /* Get number of questions and number of users who have already answer this game */ Game->NumQsts = Gam_GetNumQstsGame (Game->GamCod); Game->NumUsrs = Gam_GetNumUsrsWhoHaveAnsweredGame (Game->GamCod); - /* Am I logged with a valid role to answer this game? */ - Game->Status.IAmLoggedWithAValidRoleToAnswer = (Game->Roles & (1 << Gbl.Usrs.Me.Role.Logged)); - /* Do I belong to valid groups to answer this game? */ - switch (Game->Scope) - { - case Hie_UNK: // Unknown - Lay_ShowErrorAndExit ("Wrong game scope."); - break; - case Hie_SYS: // System - Game->Status.IBelongToScope = Gbl.Usrs.Me.Logged; - break; - case Hie_CTY: // Country - Game->Status.IBelongToScope = Usr_CheckIfIBelongToCty (Game->Cod); - break; - case Hie_INS: // Institution - Game->Status.IBelongToScope = Usr_CheckIfIBelongToIns (Game->Cod); - break; - case Hie_CTR: // Centre - Game->Status.IBelongToScope = Usr_CheckIfIBelongToCtr (Game->Cod); - break; - case Hie_DEG: // Degree - Game->Status.IBelongToScope = Usr_CheckIfIBelongToDeg (Game->Cod); - break; - case Hie_CRS: // Course - Game->Status.IBelongToScope = Usr_CheckIfIBelongToCrs (Game->Cod) && - Gam_CheckIfICanDoThisGameBasedOnGrps (Game->GamCod); - break; - } + Game->Status.IBelongToScope = Gbl.Usrs.Me.IBelongToCurrentCrs && + Gam_CheckIfICanDoThisGameBasedOnGrps (Game->GamCod); /* Have I answered this game? */ Game->Status.IHaveAnswered = Gam_CheckIfIHaveAnsweredGame (Game->GamCod); /* Can I answer game? */ - Game->Status.ICanAnswer = (Game->NumQsts != 0) && - Game->Status.Visible && - Game->Status.Open && - Game->Status.IAmLoggedWithAValidRoleToAnswer && - Game->Status.IBelongToScope && + Game->Status.ICanAnswer = Game->NumQsts != 0 && + Game->Status.Visible && + Game->Status.Open && + Gbl.Usrs.Me.Role.Logged == Rol_STD && + Game->Status.IBelongToScope && !Game->Status.IHaveAnswered; /* Can I view results of the game? @@ -1304,75 +966,40 @@ void Gam_GetDataOfGameByCod (struct Game *Game) switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - Game->Status.ICanViewResults = (Game->Scope == Hie_CRS || - Game->Scope == Hie_DEG || - Game->Scope == Hie_CTR || - Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - (Game->NumQsts != 0) && - Game->Status.Visible && - Game->Status.Open && - Game->Status.IAmLoggedWithAValidRoleToAnswer && - Game->Status.IBelongToScope && - Game->Status.IHaveAnswered; + Game->Status.ICanViewResults = Game->NumQsts != 0 && + Game->Status.Visible && + Game->Status.Open && + Game->Status.IBelongToScope && + Game->Status.IHaveAnswered; Game->Status.ICanEdit = false; break; case Rol_NET: - Game->Status.ICanViewResults = (Game->Scope == Hie_CRS || - Game->Scope == Hie_DEG || - Game->Scope == Hie_CTR || - Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - Game->NumQsts != 0 && + Game->Status.ICanViewResults = Game->NumQsts != 0 && !Game->Status.ICanAnswer; Game->Status.ICanEdit = false; break; case Rol_TCH: - Game->Status.ICanViewResults = (Game->Scope == Hie_CRS || - Game->Scope == Hie_DEG || - Game->Scope == Hie_CTR || - Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - Game->NumQsts != 0 && + Game->Status.ICanViewResults = Game->NumQsts != 0 && !Game->Status.ICanAnswer; - Game->Status.ICanEdit = Game->Scope == Hie_CRS && - Game->Status.IBelongToScope; + Game->Status.ICanEdit = Game->Status.IBelongToScope; break; case Rol_DEG_ADM: - Game->Status.ICanViewResults = (Game->Scope == Hie_DEG || - Game->Scope == Hie_CTR || - Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - (Game->NumQsts != 0) && + Game->Status.ICanViewResults = Game->NumQsts != 0 && !Game->Status.ICanAnswer; - Game->Status.ICanEdit = Game->Scope == Hie_DEG && - Game->Status.IBelongToScope; + Game->Status.ICanEdit = Game->Status.IBelongToScope; break; case Rol_CTR_ADM: - Game->Status.ICanViewResults = (Game->Scope == Hie_CTR || - Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - (Game->NumQsts != 0) && + Game->Status.ICanViewResults = Game->NumQsts != 0 && !Game->Status.ICanAnswer; - Game->Status.ICanEdit = Game->Scope == Hie_CTR && - Game->Status.IBelongToScope; + Game->Status.ICanEdit = Game->Status.IBelongToScope; break; case Rol_INS_ADM: - Game->Status.ICanViewResults = (Game->Scope == Hie_INS || - Game->Scope == Hie_CTY || - Game->Scope == Hie_SYS) && - (Game->NumQsts != 0) && + Game->Status.ICanViewResults = Game->NumQsts != 0 && !Game->Status.ICanAnswer; - Game->Status.ICanEdit = Game->Scope == Hie_INS && - Game->Status.IBelongToScope; + Game->Status.ICanEdit = Game->Status.IBelongToScope; break; case Rol_SYS_ADM: - Game->Status.ICanViewResults = (Game->NumQsts != 0); + Game->Status.ICanViewResults = Game->NumQsts != 0; Game->Status.ICanEdit = true; break; default: @@ -1385,22 +1012,18 @@ void Gam_GetDataOfGameByCod (struct Game *Game) { /* Initialize to empty game */ Game->GamCod = -1L; - Game->Scope = Hie_UNK; - Game->Roles = 0; Game->UsrCod = -1L; Game->TimeUTC[Gam_START_TIME] = Game->TimeUTC[Gam_END_TIME ] = (time_t) 0; Game->Title[0] = '\0'; Game->NumQsts = 0; Game->NumUsrs = 0; - Game->Status.Visible = true; - Game->Status.Open = false; - Game->Status.IAmLoggedWithAValidRoleToAnswer = false; - Game->Status.IBelongToScope = false; - Game->Status.IHaveAnswered = false; - Game->Status.ICanAnswer = false; - Game->Status.ICanViewResults = false; - Game->Status.ICanEdit = false; + Game->Status.Visible = true; + Game->Status.Open = false; + Game->Status.IHaveAnswered = false; + Game->Status.ICanAnswer = false; + Game->Status.ICanViewResults = false; + Game->Status.ICanEdit = false; } /***** Free structure that stores the query result *****/ @@ -1500,7 +1123,7 @@ void Gam_AskRemGame (void) Lay_ShowErrorAndExit ("You can not remove this game."); /***** Show question and button to remove game *****/ - Gbl.Games.CurrentGamCod = Game.GamCod; + Gam_CurrentGamCod = Game.GamCod; Ale_ShowAlertAndButton (ActRemGam,NULL,NULL,Gam_PutParams, Btn_REMOVE_BUTTON,Txt_Remove_game, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_game_X, @@ -1561,6 +1184,7 @@ void Gam_RemoveGame (void) void Gam_AskResetGame (void) { extern const char *Txt_Do_you_really_want_to_reset_the_game_X; + extern const char *Txt_Reset_game; struct Game Game; /***** Get parameters *****/ @@ -1578,31 +1202,18 @@ void Gam_AskResetGame (void) Lay_ShowErrorAndExit ("You can not reset this game."); /***** Ask for confirmation of reset *****/ - Ale_ShowAlert (Ale_WARNING,Txt_Do_you_really_want_to_reset_the_game_X, - Game.Title); - - /***** Button of confirmation of reset *****/ - Gbl.Games.CurrentGamCod = Game.GamCod; - Gam_PutButtonToResetGame (); + Gam_CurrentGamCod = Game.GamCod; + Ale_ShowAlertAndButton (ActRstGam,NULL,NULL, + Gam_PutParams, + Btn_REMOVE_BUTTON, + Txt_Reset_game, + Ale_QUESTION,Txt_Do_you_really_want_to_reset_the_game_X, + Game.Title); /***** Show games again *****/ Gam_ListAllGames (); } -/*****************************************************************************/ -/************************* Put button to reset game ************************/ -/*****************************************************************************/ - -static void Gam_PutButtonToResetGame (void) - { - extern const char *Txt_Reset_game; - - Frm_StartForm (ActRstGam); - Gam_PutParams (); - Btn_PutRemoveButton (Txt_Reset_game); - Frm_EndForm (); - } - /*****************************************************************************/ /******************************* Reset a game ******************************/ /*****************************************************************************/ @@ -1703,10 +1314,10 @@ static bool Gam_CheckIfSimilarGameExists (struct Game *Game) /***** Get number of games with a field value from database *****/ return (DB_QueryCOUNT ("can not get similar games", "SELECT COUNT(*) FROM games" - " WHERE Scope='%s' AND Cod=%ld" - " AND Title='%s' AND GamCod<>%ld", - Sco_GetDBStrFromScope (Game->Scope),Game->Cod, - Game->Title,Game->GamCod) != 0); + " WHERE CrsCod=%ld AND Title='%s'" + " AND GamCod<>%ld", + Gbl.Hierarchy.Crs.CrsCod,Game->Title, + Game->GamCod) != 0); } /*****************************************************************************/ @@ -1719,11 +1330,9 @@ void Gam_RequestCreatOrEditGame (void) extern const char *Hlp_ASSESSMENT_Games_edit_game; extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *Txt_New_game; - extern const char *Txt_Scope; extern const char *Txt_Edit_game; extern const char *Txt_Title; extern const char *Txt_Description; - extern const char *Txt_Users; extern const char *Txt_Create_game; extern const char *Txt_Save_changes; struct Game Game; @@ -1747,21 +1356,18 @@ void Gam_RequestCreatOrEditGame (void) /* Initialize to empty game */ Game.GamCod = -1L; - Game.Scope = Hie_UNK; - Game.Roles = (1 << Rol_STD); Game.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; Game.TimeUTC[Gam_START_TIME] = Gbl.StartExecutionTimeUTC; Game.TimeUTC[Gam_END_TIME ] = Gbl.StartExecutionTimeUTC + (24 * 60 * 60); // +24 hours - Game.Title[0] = '\0'; - Game.NumQsts = 0; - Game.NumUsrs = 0; - Game.Status.Visible = true; - Game.Status.Open = true; - Game.Status.IAmLoggedWithAValidRoleToAnswer = false; - Game.Status.IBelongToScope = false; - Game.Status.IHaveAnswered = false; - Game.Status.ICanAnswer = false; - Game.Status.ICanViewResults = false; + Game.Title[0] = '\0'; + Game.NumQsts = 0; + Game.NumUsrs = 0; + Game.Status.Visible = true; + Game.Status.Open = true; + Game.Status.IBelongToScope = false; + Game.Status.IHaveAnswered = false; + Game.Status.ICanAnswer = false; + Game.Status.ICanViewResults = false; } else { @@ -1775,7 +1381,7 @@ void Gam_RequestCreatOrEditGame (void) } /***** Start form *****/ - Gbl.Games.CurrentGamCod = Game.GamCod; + Gam_CurrentGamCod = Game.GamCod; Frm_StartForm (ItsANewGame ? ActNewGam : ActChgGam); Gam_PutParams (); @@ -1791,20 +1397,6 @@ void Gam_RequestCreatOrEditGame (void) NULL, Hlp_ASSESSMENT_Games_edit_game,Box_NOT_CLOSABLE,2); - /***** Scope of the game *****/ - fprintf (Gbl.F.Out,"" - "" - "" - "" - "", - The_ClassFormInBox[Gbl.Prefs.Theme], - Txt_Scope); - Gam_SetDefaultAndAllowedScope (&Game); - Sco_GetScope ("ScopeGame"); - Sco_PutSelectorScope ("ScopeGame",false); - fprintf (Gbl.F.Out,"" - ""); - /***** Game title *****/ fprintf (Gbl.F.Out,"" "" @@ -1839,21 +1431,6 @@ void Gam_RequestCreatOrEditGame (void) "" ""); - /***** Users' roles who can answer the game *****/ - fprintf (Gbl.F.Out,"" - "%s:" - "" - "", - The_ClassFormInBox[Gbl.Prefs.Theme], - Txt_Users); - Rol_WriteSelectorRoles (1 << Rol_STD | - 1 << Rol_NET | - 1 << Rol_TCH, - Game.Roles, - false,false); - fprintf (Gbl.F.Out,"" - ""); - /***** Groups *****/ Gam_ShowLstGrpsToEditGame (Game.GamCod); @@ -1871,93 +1448,6 @@ void Gam_RequestCreatOrEditGame (void) Gam_ListGameQuestions (&Game); } -/*****************************************************************************/ -/****** Set default and allowed scopes depending on logged user's role *******/ -/*****************************************************************************/ - -static void Gam_SetDefaultAndAllowedScope (struct Game *Game) - { - bool ICanEdit = false; - - /***** Set default scope *****/ - Gbl.Scope.Default = Hie_UNK; - Gbl.Scope.Allowed = 0; - - switch (Gbl.Usrs.Me.Role.Logged) - { - case Rol_TCH: // Teachers only can edit course games - if (Game->Scope == Hie_UNK) // Scope not defined - Game->Scope = Hie_CRS; - if (Game->Scope == Hie_CRS) - { - Gbl.Scope.Default = Game->Scope; - Gbl.Scope.Allowed = 1 << Hie_CRS; - ICanEdit = true; - } - break; - case Rol_DEG_ADM: // Degree admins only can edit degree games - if (Game->Scope == Hie_UNK) // Scope not defined - Game->Scope = Hie_DEG; - if (Game->Scope == Hie_DEG) - { - Gbl.Scope.Default = Game->Scope; - Gbl.Scope.Allowed = 1 << Hie_DEG; - ICanEdit = true; - } - break; - case Rol_CTR_ADM: // Centre admins only can edit centre games - if (Game->Scope == Hie_UNK) // Scope not defined - Game->Scope = Hie_CTR; - if (Game->Scope == Hie_CTR) - { - Gbl.Scope.Default = Game->Scope; - Gbl.Scope.Allowed = 1 << Hie_CTR; - ICanEdit = true; - } - break; - case Rol_INS_ADM: // Institution admins only can edit institution games - if (Game->Scope == Hie_UNK) // Scope not defined - Game->Scope = Hie_INS; - if (Game->Scope == Hie_INS) - { - Gbl.Scope.Default = Game->Scope; - Gbl.Scope.Allowed = 1 << Hie_INS; - ICanEdit = true; - } - break; - case Rol_SYS_ADM:// System admins can edit any game - if (Game->Scope == Hie_UNK) // Scope not defined - { - if (Gbl.Hierarchy.Level == Hie_CRS) - Game->Scope = Hie_CRS; - else if (Gbl.Hierarchy.Deg.DegCod > 0) - Game->Scope = Hie_DEG; - else if (Gbl.Hierarchy.Ctr.CtrCod > 0) - Game->Scope = Hie_CTR; - else if (Gbl.Hierarchy.Ins.InsCod > 0) - Game->Scope = Hie_INS; - else if (Gbl.Hierarchy.Cty.CtyCod > 0) - Game->Scope = Hie_CTY; - else - Game->Scope = Hie_SYS; - } - Gbl.Scope.Default = Game->Scope; - Gbl.Scope.Allowed = 1 << Hie_SYS | - 1 << Hie_CTY | - 1 << Hie_INS | - 1 << Hie_CTR | - 1 << Hie_DEG | - 1 << Hie_CRS; - ICanEdit = true; - break; - default: - break; - } - - if (!ICanEdit) - Lay_NoPermissionExit (); - } - /*****************************************************************************/ /******************** Show list of groups to edit a game *******************/ /*****************************************************************************/ @@ -2035,66 +1525,13 @@ void Gam_RecFormGame (void) /***** Get the code of the game *****/ ItsANewGame = ((NewGame.GamCod = Gam_GetParamGameCod ()) == -1L); - if (ItsANewGame) - NewGame.Scope = Hie_UNK; - else + if (!ItsANewGame) { /* Get data of the old (current) game from database */ OldGame.GamCod = NewGame.GamCod; Gam_GetDataOfGameByCod (&OldGame); if (!OldGame.Status.ICanEdit) Lay_ShowErrorAndExit ("You can not update this game."); - NewGame.Scope = OldGame.Scope; - } - - /***** Get scope *****/ - Gam_SetDefaultAndAllowedScope (&NewGame); - Sco_GetScope ("ScopeGame"); - switch (Gbl.Scope.Current) - { - case Hie_SYS: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_SYS; - NewGame.Cod = -1L; - break; - case Hie_CTY: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_CTY; - NewGame.Cod = Gbl.Hierarchy.Cty.CtyCod; - break; - case Hie_INS: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM && - Gbl.Usrs.Me.Role.Logged != Rol_INS_ADM) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_INS; - NewGame.Cod = Gbl.Hierarchy.Ins.InsCod; - break; - case Hie_CTR: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM && - Gbl.Usrs.Me.Role.Logged != Rol_CTR_ADM) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_CTR; - NewGame.Cod = Gbl.Hierarchy.Ctr.CtrCod; - break; - case Hie_DEG: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM && - Gbl.Usrs.Me.Role.Logged != Rol_DEG_ADM) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_DEG; - NewGame.Cod = Gbl.Hierarchy.Deg.DegCod; - break; - case Hie_CRS: - if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM && - Gbl.Usrs.Me.Role.Logged != Rol_TCH) - Lay_ShowErrorAndExit ("Wrong game scope."); - NewGame.Scope = Hie_CRS; - NewGame.Cod = Gbl.Hierarchy.Crs.CrsCod; - break; - default: - Lay_WrongScopeExit (); - break; } /***** Get start/end date-times *****/ @@ -2113,9 +1550,6 @@ void Gam_RecFormGame (void) if (NewGame.TimeUTC[Gam_END_TIME] == 0) NewGame.TimeUTC[Gam_END_TIME] = NewGame.TimeUTC[Gam_START_TIME] + 24 * 60 * 60; // +24 hours - /***** Get users who can answer this game *****/ - NewGame.Roles = Rol_GetSelectedRoles (); - /***** Check if title is correct *****/ if (NewGame.Title[0]) // If there's a game title { @@ -2166,13 +1600,10 @@ static void Gam_CreateGame (struct Game *Game,const char *Txt) Game->GamCod = DB_QueryINSERTandReturnCode ("can not create new game", "INSERT INTO games" - " (Scope,Cod,Hidden,Roles,UsrCod,StartTime,EndTime,Title,Txt)" + " (CrsCod,Hidden,UsrCod,StartTime,EndTime,Title,Txt)" " VALUES" - " ('%s',%ld,'N',%u,%ld," - "FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," - "'%s','%s')", - Sco_GetDBStrFromScope (Game->Scope),Game->Cod, - Game->Roles, + " (%ld,'N',%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),'%s','%s')", + Gbl.Hierarchy.Crs.CrsCod, Gbl.Usrs.Me.UsrDat.UsrCod, Game->TimeUTC[Gam_START_TIME], Game->TimeUTC[Gam_END_TIME ], @@ -2199,13 +1630,13 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt) /***** Update the data of the game *****/ DB_QueryUPDATE ("can not update game", "UPDATE games" - " SET Scope='%s',Cod=%ld,Roles=%u," - "StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "Title='%s',Txt='%s'" + " SET CrsCod=%ld," + "StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "Title='%s'," + "Txt='%s'" " WHERE GamCod=%ld", - Sco_GetDBStrFromScope (Game->Scope),Game->Cod, - Game->Roles, + Gbl.Hierarchy.Crs.CrsCod, Game->TimeUTC[Gam_START_TIME], Game->TimeUTC[Gam_END_TIME ], Game->Title, @@ -2726,7 +2157,7 @@ static void Gam_ListGameQuestions (struct Game *Game) Game->GamCod); /***** Start box *****/ - Gbl.Games.CurrentGamCod = Game->GamCod; + Gam_CurrentGamCod = Game->GamCod; Box_StartBox (NULL,Txt_Questions,Game->Status.ICanEdit ? Gam_PutIconToAddNewQuestions : NULL, Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE); @@ -2833,8 +2264,8 @@ static void Gam_ListOneOrMoreQuestionsForEdition (struct Game *Game, Lay_ShowErrorAndExit ("Wrong code of question."); /***** Icons *****/ - Gbl.Games.CurrentGamCod = Game->GamCod; - Gbl.Games.CurrentQstCod = QstCod; + Gam_CurrentGamCod = Game->GamCod; + Gam_CurrentQstCod = QstCod; fprintf (Gbl.F.Out,"" "",Gbl.RowEvenOdd); @@ -3181,8 +2612,8 @@ static void Gam_PutIconToRemoveOneQst (void) static void Gam_PutParamsOneQst (void) { - Gam_PutParamGameCod (Gbl.Games.CurrentGamCod); - Gam_PutParamQstCod (Gbl.Games.CurrentQstCod); + Gam_PutParamGameCod (Gam_CurrentGamCod); + Gam_PutParamQstCod (Gam_CurrentQstCod); } /*****************************************************************************/ @@ -3210,8 +2641,8 @@ void Gam_RequestRemoveQst (void) QstInd = (unsigned) Gam_GetQstIndFromQstCod (Game.GamCod,QstCod); // TODO: Remove this function because a question code can be repeated /***** Show question and button to remove question *****/ - Gbl.Games.CurrentGamCod = Game.GamCod; - Gbl.Games.CurrentQstCod = QstCod; + Gam_CurrentGamCod = Game.GamCod; + Gam_CurrentQstCod = QstCod; Ale_ShowAlertAndButton (ActRemGamQst,NULL,NULL,Gam_PutParamsOneQst, Btn_REMOVE_BUTTON,Txt_Remove_question, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_question_X, diff --git a/swad_game.h b/swad_game.h index 4e428dcab..9bbdaddb1 100644 --- a/swad_game.h +++ b/swad_game.h @@ -45,11 +45,8 @@ typedef enum struct Game { - long GamCod; - Hie_Level_t Scope; - long Cod; // Country, institution, centre, degree or course code - unsigned Roles; // Example: if game can be made by students, Roles == (1 << Rol_STD) - long UsrCod; + long GamCod; // Game code + long UsrCod; // Author code char Title[Gam_MAX_BYTES_SURVEY_TITLE + 1]; time_t TimeUTC[Gam_NUM_DATES]; unsigned NumQsts; // Number of questions in the game @@ -58,7 +55,6 @@ struct Game { bool Visible; // Game is not hidden bool Open; // Start date <= now <= end date - bool IAmLoggedWithAValidRoleToAnswer; // I am logged with a valid role to answer this game bool IBelongToScope; // I belong to the scope of this game bool IHaveAnswered; // I have already answered this game bool ICanAnswer; diff --git a/swad_global.h b/swad_global.h index 926a4e91a..c2d3555cd 100644 --- a/swad_global.h +++ b/swad_global.h @@ -702,8 +702,6 @@ struct Globals unsigned Num; // Number of surveys long *LstGamCods; // List of game codes Gam_Order_t SelectedOrder; - long CurrentGamCod; // Used as parameter in contextual links - long CurrentQstCod; // Used as parameter in contextual links unsigned CurrentPage; char *ListQuestions; } Games; @@ -713,8 +711,6 @@ struct Globals unsigned Num; // Number of surveys long *LstSvyCods; // List of survey codes Svy_Order_t SelectedOrder; - long SvyCodToEdit; // Used as parameter in contextual links - long SvyQstCodToEdit; // Used as parameter in contextual links unsigned CurrentPage; } Svys; struct diff --git a/swad_survey.c b/swad_survey.c index 016331dde..f11855ac8 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -89,6 +89,9 @@ struct SurveyQuestion // Must be initialized to 0 before using it /***************************** Private variables *****************************/ /*****************************************************************************/ +long Svy_CurrentSvyCod; // Used as parameter in contextual links +long Svy_CurrentQstCod; // Used as parameter in contextual links + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ @@ -507,7 +510,7 @@ static void Svy_ShowOneSurvey (long SvyCod,struct SurveyQuestion *SvyQst, fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd); fprintf (Gbl.F.Out,"\">"); Lay_StartArticle (Anchor); - Frm_StartForm (ActSeeOneSvy); + Frm_StartForm (ActSeeSvy); Svy_PutParamSvyCod (SvyCod); Svy_PutHiddenParamSvyOrder (); Grp_PutParamWhichGrps (); @@ -544,7 +547,7 @@ static void Svy_ShowOneSurvey (long SvyCod,struct SurveyQuestion *SvyQst, { fprintf (Gbl.F.Out,"
    "); - Frm_StartForm (ActSeeOneSvy); + Frm_StartForm (ActSeeSvy); Svy_PutParamSvyCod (Svy.SvyCod); Svy_PutHiddenParamSvyOrder (); Grp_PutParamWhichGrps (); @@ -559,7 +562,7 @@ static void Svy_ShowOneSurvey (long SvyCod,struct SurveyQuestion *SvyQst, { fprintf (Gbl.F.Out,"
    "); - Frm_StartForm (ActSeeOneSvy); + Frm_StartForm (ActSeeSvy); Svy_PutParamSvyCod (Svy.SvyCod); Svy_PutHiddenParamSvyOrder (); Grp_PutParamWhichGrps (); @@ -807,7 +810,7 @@ static void Svy_PutFormsToRemEditOneSvy (const struct Survey *Svy, { extern const char *Txt_Reset; - Gbl.Svys.SvyCodToEdit = Svy->SvyCod; // Used as parameters in contextual links + Svy_CurrentSvyCod = Svy->SvyCod; // Used as parameters in contextual links /***** Put form to remove survey *****/ Ico_PutContextualIconToRemove (ActReqRemSvy,Svy_PutParams); @@ -833,8 +836,8 @@ static void Svy_PutFormsToRemEditOneSvy (const struct Survey *Svy, static void Svy_PutParams (void) { - if (Gbl.Svys.SvyCodToEdit > 0) - Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit); + if (Svy_CurrentSvyCod > 0) + Svy_PutParamSvyCod (Svy_CurrentSvyCod); Att_PutHiddenParamAttOrder (); Grp_PutParamWhichGrps (); Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage); @@ -1516,7 +1519,7 @@ void Svy_AskRemSurvey (void) Lay_ShowErrorAndExit ("You can not remove this survey."); /***** Show question and button to remove survey *****/ - Gbl.Svys.SvyCodToEdit = Svy.SvyCod; + Svy_CurrentSvyCod = Svy.SvyCod; Ale_ShowAlertAndButton (ActRemSvy,NULL,NULL,Svy_PutParams, Btn_REMOVE_BUTTON,Txt_Remove_survey, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_survey_X, @@ -1617,7 +1620,7 @@ void Svy_AskResetSurvey (void) Svy.Title); /***** Button of confirmation of reset *****/ - Gbl.Svys.SvyCodToEdit = Svy.SvyCod; + Svy_CurrentSvyCod = Svy.SvyCod; Svy_PutButtonToResetSurvey (); /***** Show surveys again *****/ @@ -1825,7 +1828,7 @@ void Svy_RequestCreatOrEditSvy (void) } /***** Start form *****/ - Gbl.Svys.SvyCodToEdit = Svy.SvyCod; + Svy_CurrentSvyCod = Svy.SvyCod; Frm_StartForm (ItsANewSurvey ? ActNewSvy : ActChgSvy); Svy_PutParams (); @@ -2637,8 +2640,8 @@ static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst, if (SvyQst->QstCod > 0) // If the question already has assigned a code { /* Parameters for contextual icon */ - Gbl.Svys.SvyCodToEdit = SvyCod; - Gbl.Svys.SvyQstCodToEdit = SvyQst->QstCod; + Svy_CurrentSvyCod = SvyCod; + Svy_CurrentQstCod = SvyQst->QstCod; snprintf (Gbl.Title,sizeof (Gbl.Title), "%s %u", @@ -3155,7 +3158,7 @@ static void Svy_ListSvyQuestions (struct Survey *Svy, Svy->SvyCod); /***** Start box *****/ - Gbl.Svys.SvyCodToEdit = Svy->SvyCod; + Svy_CurrentSvyCod = Svy->SvyCod; Box_StartBox (NULL,Txt_Questions,Svy->Status.ICanEdit ? Svy_PutIconToAddNewQuestion : NULL, Hlp_ASSESSMENT_Surveys_questions,Box_NOT_CLOSABLE); @@ -3215,8 +3218,8 @@ static void Svy_ListSvyQuestions (struct Survey *Svy, Frm_EndForm (); /* Write icon to edit the question */ - Gbl.Svys.SvyCodToEdit = Svy->SvyCod; - Gbl.Svys.SvyQstCodToEdit = SvyQst->QstCod; + Svy_CurrentSvyCod = Svy->SvyCod; + Svy_CurrentQstCod = SvyQst->QstCod; Ico_PutContextualIconToEdit (ActEdiOneSvyQst,Svy_PutParamsToEditQuestion); fprintf (Gbl.F.Out,""); @@ -3280,8 +3283,8 @@ static void Svy_ListSvyQuestions (struct Survey *Svy, static void Svy_PutParamsToEditQuestion (void) { - Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit); - Svy_PutParamQstCod (Gbl.Svys.SvyQstCodToEdit); + Svy_PutParamSvyCod (Svy_CurrentSvyCod); + Svy_PutParamQstCod (Svy_CurrentQstCod); } /*****************************************************************************/ @@ -3496,8 +3499,8 @@ static void Svy_PutIconToRemoveOneQst (void) static void Svy_PutParamsRemoveOneQst (void) { - Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit); - Svy_PutParamQstCod (Gbl.Svys.SvyQstCodToEdit); + Svy_PutParamSvyCod (Svy_CurrentSvyCod); + Svy_PutParamQstCod (Svy_CurrentQstCod); } /*****************************************************************************/ @@ -3527,8 +3530,8 @@ void Svy_RequestRemoveQst (void) SvyQst.QstInd = Svy_GetQstIndFromQstCod (SvyQst.QstCod); /***** Show question and button to remove question *****/ - Gbl.Svys.SvyCodToEdit = SvyCod; - Gbl.Svys.SvyQstCodToEdit = SvyQst.QstCod; + Svy_CurrentSvyCod = SvyCod; + Svy_CurrentQstCod = SvyQst.QstCod; Ale_ShowAlertAndButton (ActRemSvyQst,NULL,NULL,Svy_PutParamsRemoveOneQst, Btn_REMOVE_BUTTON,Txt_Remove_question, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_question_X, diff --git a/swad_text.c b/swad_text.c index 7de1fb685..98e9c72e8 100644 --- a/swad_text.c +++ b/swad_text.c @@ -8462,7 +8462,7 @@ const char *Txt_Do_you_really_want_to_remove_the_assignment_X = // Warning: it i const char *Txt_Do_you_really_want_to_remove_the_entire_thread = #if L==1 // ca - "¿Realmente desea eliminar toda la discusión?"; // Necessita traduccio + "De veres voleu eliminar tota la discusió?"; #elif L==2 // de "Wollen Sie die gesamten Thread wirklich entfernen?"; #elif L==3 // en @@ -8483,7 +8483,7 @@ const char *Txt_Do_you_really_want_to_remove_the_entire_thread = const char *Txt_Do_you_really_want_to_remove_the_entire_thread_X = // Warning: it is very important to include %s in the following sentences #if L==1 // ca - "¿Realmente desea eliminar toda la discusión %s?"; // Necessita traduccio + "De veres voleu eliminar tota la discussió %s?"; #elif L==2 // de "Wollen Sie die gesamten Thread %s wirklich entfernen?"; #elif L==3 // en @@ -8504,7 +8504,7 @@ const char *Txt_Do_you_really_want_to_remove_the_entire_thread_X = // Warning: i const char *Txt_Do_you_really_want_to_remove_the_event_X = // Warning: it is very important to include %s in the following sentences #if L==1 // ca - "¿Realmente desea eliminar el evento %s?"; // Necessita traduccio + "De veres voleu eliminar l'esdevenimen %s?"; #elif L==2 // de "Wollen Sie der Ereignis %s wirklich entfernen?"; #elif L==3 // en @@ -8564,7 +8564,7 @@ const char *Txt_Do_you_really_want_to_remove_the_field_X_from_the_records_of_Y_Z const char *Txt_Do_you_really_want_to_remove_FILE_OR_LINK_X = // Warning: it is very important to include %s in the following sentences #if L==1 // ca - "¿Realmente desea eliminar %s?"; // Necessita traduccio + "De veres voleu eliminar %s?"; #elif L==2 // de "Wollen Sie %s wirklich entfernen?"; #elif L==3 // en