swad-core/swad_survey.c

4058 lines
144 KiB
C
Raw Normal View History

2016-10-27 15:06:11 +02:00
// swad_survey.c: surveys
2014-12-01 23:55:08 +01:00
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
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 ***********************************/
/*****************************************************************************/
2019-01-03 15:25:18 +01:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
2019-01-03 15:25:18 +01:00
#include <stdio.h> // For asprintf
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
#include "swad_group.h"
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
2016-12-13 13:32:19 +01:00
#include "swad_role.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2014-12-01 23:55:08 +01:00
#include "swad_survey.h"
2017-06-11 20:09:59 +02:00
#include "swad_table.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2017-03-08 14:12:33 +01:00
#define Svy_MAX_CHARS_ANSWER (1024 - 1) // 1023
#define Svy_MAX_BYTES_ANSWER ((Svy_MAX_CHARS_ANSWER + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 16383
2017-03-08 03:48:23 +01:00
#define Svy_MAX_BYTES_LIST_ANSWER_TYPES (10 + (Svy_NUM_ANS_TYPES - 1) * (1 + 10))
2014-12-01 23:55:08 +01:00
const char *Svy_StrAnswerTypesDB[Svy_NUM_ANS_TYPES] =
{
"unique_choice",
"multiple_choice",
};
#define Svy_MAX_ANSWERS_PER_QUESTION 10
2017-11-30 12:07:19 +01:00
struct SurveyQuestion // Must be initialized to 0 before using it
2014-12-01 23:55:08 +01:00
{
long QstCod;
unsigned QstInd;
Svy_AnswerType_t AnswerType;
struct
{
char *Text;
} AnsChoice[Svy_MAX_ANSWERS_PER_QUESTION];
bool AllAnsTypes;
2017-01-28 15:58:46 +01:00
char ListAnsTypes[Svy_MAX_BYTES_LIST_ANSWER_TYPES + 1];
2014-12-01 23:55:08 +01:00
};
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Svy_ListAllSurveys (struct SurveyQuestion *SvyQst);
static bool Svy_CheckIfICanCreateSvy (void);
2016-11-07 00:12:30 +01:00
static void Svy_PutIconsListSurveys (void);
2016-03-19 20:03:39 +01:00
static void Svy_PutIconToCreateNewSvy (void);
static void Svy_PutButtonToCreateNewSvy (void);
static void Svy_PutParamsToCreateNewSvy (void);
2016-12-04 23:09:28 +01:00
static void Svy_ParamsWhichGroupsToShow (void);
2016-10-26 01:23:02 +02:00
static void Svy_ShowOneSurvey (long SvyCod,struct SurveyQuestion *SvyQst,
bool ShowOnlyThisSvyComplete);
2014-12-01 23:55:08 +01:00
static void Svy_WriteAuthor (struct Survey *Svy);
static void Svy_WriteStatus (struct Survey *Svy);
2017-01-29 12:42:19 +01:00
static void Svy_GetParamSvyOrder (void);
2015-04-02 18:39:49 +02:00
2014-12-01 23:55:08 +01:00
static void Svy_PutFormsToRemEditOneSvy (long SvyCod,bool Visible);
2015-12-13 19:37:08 +01:00
static void Svy_PutParams (void);
2016-10-27 01:30:14 +02:00
static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
unsigned *HiddenAllowed);
2017-01-15 22:58:26 +01:00
static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
2014-12-01 23:55:08 +01:00
static void Svy_PutParamSvyCod (long SvyCod);
static long Svy_GetParamSvyCod (void);
2016-03-20 02:48:16 +01:00
static void Svy_PutButtonToResetSurvey (void);
2014-12-01 23:55:08 +01:00
static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy);
2016-10-26 01:23:02 +02:00
static void Svy_SetDefaultAndAllowedScope (struct Survey *Svy);
2014-12-01 23:55:08 +01:00
static void Svy_ShowLstGrpsToEditSurvey (long SvyCod);
2016-10-26 01:23:02 +02:00
static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
unsigned NumUsrsToBeNotifiedByEMail);
2014-12-01 23:55:08 +01:00
static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt);
static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt);
static bool Svy_CheckIfSvyIsAssociatedToGrps (long SvyCod);
static void Svy_RemoveAllTheGrpsAssociatedToAndSurvey (long SvyCod);
static void Svy_CreateGrps (long SvyCod);
static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy);
static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod);
static unsigned Svy_GetNumQstsSvy (long SvyCod);
2017-01-17 03:10:43 +01:00
static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,
char Txt[Cns_MAX_BYTES_TEXT + 1]);
2014-12-01 23:55:08 +01:00
static void Svy_InitQst (struct SurveyQuestion *SvyQst);
static void Svy_PutParamQstCod (long QstCod);
static long Svy_GetParamQstCod (void);
static void Svy_RemAnswersOfAQuestion (long QstCod);
static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD);
static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd);
static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res);
2017-07-02 19:46:53 +02:00
static bool Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns);
2014-12-01 23:55:08 +01:00
static void Svy_FreeTextChoiceAnswers (struct SurveyQuestion *SvyQst,unsigned NumAnswers);
static void Svy_FreeTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns);
static unsigned Svy_GetQstIndFromQstCod (long QstCod);
static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod);
2017-11-30 12:07:19 +01:00
static void Svy_ListSvyQuestions (struct Survey *Svy,
struct SurveyQuestion *SvyQst);
2017-09-08 01:18:20 +02:00
static void Svy_PutParamsToEditQuestion (void);
2016-03-20 02:48:16 +01:00
static void Svy_PutIconToAddNewQuestion (void);
static void Svy_PutButtonToCreateNewQuestion (void);
2015-09-06 11:36:34 +02:00
static void Svy_WriteQstStem (const char *Stem);
2017-11-30 12:07:19 +01:00
static void Svy_WriteAnswersOfAQst (struct Survey *Svy,
struct SurveyQuestion *SvyQst,
bool PutFormAnswerSurvey);
2014-12-01 23:55:08 +01:00
static void Svy_DrawBarNumUsrs (unsigned NumUsrs,unsigned MaxUsrs);
2016-04-05 13:07:33 +02:00
static void Svy_PutIconToRemoveOneQst (void);
static void Svy_PutParamsRemoveOneQst (void);
2014-12-01 23:55:08 +01:00
static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod);
static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd);
static void Svy_RegisterIHaveAnsweredSvy (long SvyCod);
static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod);
static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod);
/*****************************************************************************/
/************************** List all the surveys *****************************/
/*****************************************************************************/
void Svy_SeeAllSurveys (void)
{
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Show all the surveys *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/*************************** Show all the surveys ****************************/
/*****************************************************************************/
static void Svy_ListAllSurveys (struct SurveyQuestion *SvyQst)
{
2017-05-02 16:57:49 +02:00
extern const char *Hlp_ASSESSMENT_Surveys;
2015-01-02 12:57:26 +01:00
extern const char *Txt_Surveys;
2016-12-15 00:39:52 +01:00
extern const char *Txt_START_END_TIME_HELP[Dat_NUM_START_END_TIME];
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Survey;
extern const char *Txt_Status;
2016-03-19 20:03:39 +01:00
extern const char *Txt_No_surveys;
2017-01-29 12:42:19 +01:00
Svy_Order_t Order;
2014-12-01 23:55:08 +01:00
struct Pagination Pagination;
unsigned NumSvy;
2016-10-29 00:22:34 +02:00
/***** Get number of groups in current course *****/
2019-04-04 10:45:15 +02:00
if (!Gbl.Crs.Grps.NumGrps)
Gbl.Crs.Grps.WhichGrps = Grp_ALL_GROUPS;
2016-10-29 00:22:34 +02:00
2014-12-01 23:55:08 +01:00
/***** Get list of surveys *****/
Svy_GetListSurveys ();
2015-01-02 12:57:26 +01:00
/***** Compute variables related to pagination *****/
Pagination.NumItems = Gbl.Svys.Num;
2017-04-13 20:09:22 +02:00
Pagination.CurrentPage = (int) Gbl.Svys.CurrentPage;
2015-01-02 12:57:26 +01:00
Pag_CalculatePagination (&Pagination);
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = (unsigned) Pagination.CurrentPage;
2015-01-02 12:57:26 +01:00
/***** Write links to pages *****/
if (Pagination.MoreThanOnePage)
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered (Pag_SURVEYS,
0,
&Pagination);
2015-01-02 12:57:26 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ("100%",Txt_Surveys,Svy_PutIconsListSurveys,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys,Box_NOT_CLOSABLE);
2015-01-02 12:57:26 +01:00
2014-12-01 23:55:08 +01:00
/***** Select whether show only my groups or all groups *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.NumGrps)
2019-02-25 15:14:28 +01:00
{
2019-03-26 11:53:21 +01:00
Set_StartSettingsHead ();
2019-02-25 15:14:28 +01:00
Grp_ShowFormToSelWhichGrps (ActSeeAllSvy,Svy_ParamsWhichGroupsToShow);
2019-03-26 11:53:21 +01:00
Set_EndSettingsHead ();
2019-02-25 15:14:28 +01:00
}
2014-12-01 23:55:08 +01:00
2016-03-20 02:48:16 +01:00
if (Gbl.Svys.Num)
2014-12-01 23:55:08 +01:00
{
2016-03-19 20:03:39 +01:00
/***** Table head *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin (2);
2017-05-02 11:39:17 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"CONTEXT_COL\"></th>"); // Column for contextual icons
2016-03-19 20:03:39 +01:00
for (Order = Svy_ORDER_BY_START_DATE;
Order <= Svy_ORDER_BY_END_DATE;
Order++)
{
2016-12-13 01:36:23 +01:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
2016-10-26 01:23:02 +02:00
/* Form to change order */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeAllSvy);
2016-03-19 20:03:39 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2016-03-19 20:03:39 +01:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Txt_START_END_TIME_HELP[Order],"TIT_TBL",NULL);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Svys.SelectedOrder)
2016-03-19 20:03:39 +01:00
fprintf (Gbl.F.Out,"<u>");
2016-12-15 00:39:52 +01:00
fprintf (Gbl.F.Out,"%s",Txt_START_END_TIME[Order]);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Svys.SelectedOrder)
2016-03-19 20:03:39 +01:00
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-26 01:23:02 +02:00
2016-03-19 20:03:39 +01:00
fprintf (Gbl.F.Out,"</th>");
}
2016-12-13 01:36:23 +01:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
2016-03-19 20:03:39 +01:00
"%s"
"</th>"
"<th class=\"CENTER_MIDDLE\">"
"%s"
"</th>"
"</tr>",
Txt_Survey,
Txt_Status);
/***** Write all the surveys *****/
for (NumSvy = Pagination.FirstItemVisible;
NumSvy <= Pagination.LastItemVisible;
NumSvy++)
2016-10-26 01:23:02 +02:00
Svy_ShowOneSurvey (Gbl.Svys.LstSvyCods[NumSvy - 1],SvyQst,false);
2016-03-19 20:03:39 +01:00
2016-03-20 00:33:27 +01:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2015-01-02 12:57:26 +01:00
}
2016-03-20 00:33:27 +01:00
else // No surveys created
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_surveys);
2016-03-19 20:03:39 +01:00
/***** Button to create a new survey *****/
2016-11-07 00:12:30 +01:00
if (Svy_CheckIfICanCreateSvy ())
2016-03-20 02:08:13 +01:00
Svy_PutButtonToCreateNewSvy ();
2016-03-19 20:03:39 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2014-12-01 23:55:08 +01:00
2015-01-02 12:57:26 +01:00
/***** Write again links to pages *****/
if (Pagination.MoreThanOnePage)
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered (Pag_SURVEYS,
0,
&Pagination);
2014-12-01 23:55:08 +01:00
/***** Free list of surveys *****/
Svy_FreeListSurveys ();
}
/*****************************************************************************/
2016-11-07 00:12:30 +01:00
/******************* Check if I can create a new survey **********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static bool Svy_CheckIfICanCreateSvy (void)
{
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM:
2016-11-07 00:12:30 +01:00
case Rol_CTR_ADM:
case Rol_INS_ADM:
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2014-12-01 23:55:08 +01:00
return true;
default:
return false;
}
return false;
}
2016-11-07 00:12:30 +01:00
/*****************************************************************************/
/***************** Put contextual icons in list of surveys *******************/
/*****************************************************************************/
static void Svy_PutIconsListSurveys (void)
{
/***** Put icon to create a new survey *****/
if (Svy_CheckIfICanCreateSvy ())
Svy_PutIconToCreateNewSvy ();
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_SURVEYS;
Fig_PutIconToShowFigure ();
2016-11-07 00:12:30 +01:00
}
2016-03-19 20:03:39 +01:00
/*****************************************************************************/
/********************** Put icon to create a new survey **********************/
/*****************************************************************************/
static void Svy_PutIconToCreateNewSvy (void)
{
extern const char *Txt_New_survey;
2019-01-10 15:26:33 +01:00
Ico_PutContextualIconToAdd (ActFrmNewSvy,NULL,Svy_PutParamsToCreateNewSvy,
Txt_New_survey);
2016-03-19 20:03:39 +01:00
}
/*****************************************************************************/
/********************* Put button to create a new survey *********************/
/*****************************************************************************/
static void Svy_PutButtonToCreateNewSvy (void)
{
extern const char *Txt_New_survey;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActFrmNewSvy);
2016-03-19 20:03:39 +01:00
Svy_PutParamsToCreateNewSvy ();
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_survey);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-19 20:03:39 +01:00
}
/*****************************************************************************/
/******************* Put parameters to create a new survey *******************/
/*****************************************************************************/
static void Svy_PutParamsToCreateNewSvy (void)
{
2017-01-29 12:42:19 +01:00
Svy_PutHiddenParamSvyOrder ();
2016-03-19 20:03:39 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2016-03-19 20:03:39 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-02-25 15:14:28 +01:00
/**************** Put params to select which groups to show ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-12-04 23:09:28 +01:00
static void Svy_ParamsWhichGroupsToShow (void)
{
2017-01-29 12:42:19 +01:00
Svy_PutHiddenParamSvyOrder ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************************** Show one survey ******************************/
/*****************************************************************************/
void Svy_SeeOneSurvey (void)
{
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-07-02 19:46:53 +02:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Show survey *****/
Svy_ShowOneSurvey (Svy.SvyCod,&SvyQst,true);
}
/*****************************************************************************/
/****************************** Show one survey ******************************/
/*****************************************************************************/
2016-10-26 01:23:02 +02:00
static void Svy_ShowOneSurvey (long SvyCod,struct SurveyQuestion *SvyQst,
bool ShowOnlyThisSvyComplete)
2014-12-01 23:55:08 +01:00
{
2017-05-02 16:57:49 +02:00
extern const char *Hlp_ASSESSMENT_Surveys;
2015-04-12 18:01:06 +02:00
extern const char *Txt_Survey;
2015-12-29 11:35:01 +01:00
extern const char *Txt_Today;
2014-12-01 23:55:08 +01:00
extern const char *Txt_View_survey;
extern const char *Txt_No_of_questions;
extern const char *Txt_No_of_users;
extern const char *Txt_Scope;
2016-10-27 01:30:14 +02:00
extern const char *Txt_Country;
extern const char *Txt_Institution;
extern const char *Txt_Centre;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Degree;
extern const char *Txt_Course;
extern const char *Txt_Users;
extern const char *Txt_Answer_survey;
extern const char *Txt_View_survey_results;
2015-10-23 13:51:33 +02:00
static unsigned UniqueId = 0;
2014-12-01 23:55:08 +01:00
struct Survey Svy;
2017-01-15 22:58:26 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2015-04-12 18:01:06 +02:00
if (ShowOnlyThisSvyComplete)
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_Survey,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys,Box_NOT_CLOSABLE);
2015-04-12 18:01:06 +02:00
2014-12-01 23:55:08 +01:00
/***** Get data of this survey *****/
Svy.SvyCod = SvyCod;
Svy_GetDataOfSurveyByCod (&Svy);
2016-11-13 00:50:24 +01:00
/***** Start table *****/
if (ShowOnlyThisSvyComplete)
2017-06-11 20:09:59 +02:00
Tbl_StartTableWide (2);
2016-11-13 00:50:24 +01:00
2017-05-02 11:39:17 +02:00
/***** Write first row of data of this assignment *****/
/* Forms to remove/edit this assignment */
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2017-05-23 18:15:59 +02:00
"<td rowspan=\"2\" class=\"CONTEXT_COL");
if (!ShowOnlyThisSvyComplete)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
2017-05-02 11:39:17 +02:00
if (Svy.Status.ICanEdit)
Svy_PutFormsToRemEditOneSvy (Svy.SvyCod,Svy.Status.Visible);
fprintf (Gbl.F.Out,"</td>");
/* Start date/time */
UniqueId++;
fprintf (Gbl.F.Out,"<td id=\"svy_date_start_%u\" class=\"%s LEFT_TOP",
2015-10-23 13:51:33 +02:00
UniqueId,
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? (Svy.Status.Open ? "DATE_GREEN" :
"DATE_RED") :
(Svy.Status.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT"));
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
2015-10-23 13:51:33 +02:00
"<script type=\"text/javascript\">"
2017-05-04 17:06:26 +02:00
"writeLocalDateHMSFromUTC('svy_date_start_%u',%ld,"
2017-05-05 09:41:56 +02:00
"%u,'<br />','%s',true,true,0x7);"
2015-10-23 13:51:33 +02:00
"</script>"
2014-12-25 21:50:11 +01:00
"</td>",
2017-05-04 17:06:26 +02:00
UniqueId,Svy.TimeUTC[Svy_START_TIME],
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2014-12-01 23:55:08 +01:00
2017-05-02 11:39:17 +02:00
/* End date/time */
2017-04-27 10:54:45 +02:00
fprintf (Gbl.F.Out,"<td id=\"svy_date_end_%u\" class=\"%s LEFT_TOP",
2015-10-23 13:51:33 +02:00
UniqueId,
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? (Svy.Status.Open ? "DATE_GREEN" :
"DATE_RED") :
(Svy.Status.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT"));
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
2015-10-23 13:51:33 +02:00
"<script type=\"text/javascript\">"
2017-05-04 17:06:26 +02:00
"writeLocalDateHMSFromUTC('svy_date_end_%u',%ld,"
2017-05-05 09:41:56 +02:00
"%u,'<br />','%s',false,true,0x7);"
2015-10-23 13:51:33 +02:00
"</script>"
2014-12-25 21:50:11 +01:00
"</td>",
2017-05-04 17:06:26 +02:00
UniqueId,Svy.TimeUTC[Svy_END_TIME],
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2014-12-01 23:55:08 +01:00
2017-05-02 11:39:17 +02:00
/* Survey title */
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP");
2014-12-01 23:55:08 +01:00
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
2014-12-01 23:55:08 +01:00
/* Put form to view survey */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeOneSvy);
2014-12-01 23:55:08 +01:00
Svy_PutParamSvyCod (SvyCod);
2017-01-29 12:42:19 +01:00
Svy_PutHiddenParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Txt_View_survey,
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? "ASG_TITLE" :
2016-07-01 17:13:41 +02:00
"ASG_TITLE_LIGHT",NULL);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"%s</a>",
2014-12-01 23:55:08 +01:00
Svy.Title);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
/* Number of questions and number of distinct users who have already answered this survey */
2015-04-11 17:34:47 +02:00
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: %u; %s: %u</div>"
"</td>",
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? "ASG_GRP" :
"ASG_GRP_LIGHT",
Txt_No_of_questions,
Svy.NumQsts,
Txt_No_of_users,
Svy.NumUsrs);
2017-05-02 11:39:17 +02:00
/* Status of the survey */
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td rowspan=\"2\" class=\"LEFT_TOP");
2014-12-01 23:55:08 +01:00
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
2014-12-01 23:55:08 +01:00
Svy_WriteStatus (&Svy);
2016-03-24 22:03:24 +01:00
if (!ShowOnlyThisSvyComplete)
{
/* Possible button to answer this survey */
if (Svy.Status.ICanAnswer)
{
fprintf (Gbl.F.Out,"<div class=\"BUTTONS_AFTER_ALERT\">");
2016-10-26 01:23:02 +02:00
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeOneSvy);
2016-03-24 22:03:24 +01:00
Svy_PutParamSvyCod (Svy.SvyCod);
2017-01-29 12:42:19 +01:00
Svy_PutHiddenParamSvyOrder ();
2016-03-24 22:03:24 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline (Txt_Answer_survey);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-26 01:23:02 +02:00
2016-03-24 22:03:24 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/* Possible button to see the result of the survey */
else if (Svy.Status.ICanViewResults)
{
fprintf (Gbl.F.Out,"<div class=\"BUTTONS_AFTER_ALERT\">");
2016-10-26 01:23:02 +02:00
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeOneSvy);
2016-03-24 22:03:24 +01:00
Svy_PutParamSvyCod (Svy.SvyCod);
2017-01-29 12:42:19 +01:00
Svy_PutHiddenParamSvyOrder ();
2016-03-24 22:03:24 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButtonInline (Txt_View_survey_results);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-10-26 01:23:02 +02:00
2016-03-24 22:03:24 +01:00
fprintf (Gbl.F.Out,"</div>");
}
}
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Write second row of data of this survey *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-03 17:14:30 +02:00
"<td colspan=\"2\" class=\"LEFT_TOP");
2014-12-01 23:55:08 +01:00
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
2014-12-01 23:55:08 +01:00
/* Author of the survey */
Svy_WriteAuthor (&Svy);
fprintf (Gbl.F.Out,"</td>"
2015-09-03 17:14:30 +02:00
"<td class=\"LEFT_TOP");
2014-12-01 23:55:08 +01:00
if (!ShowOnlyThisSvyComplete)
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
2014-12-25 21:50:11 +01:00
fprintf (Gbl.F.Out,"\">");
2014-12-01 23:55:08 +01:00
/* Scope of the survey */
2015-04-11 20:18:30 +02:00
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? "ASG_GRP" :
"ASG_GRP_LIGHT",
Txt_Scope);
2016-10-27 01:30:14 +02:00
switch (Svy.Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_UNK: // Unknown
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
break;
2019-04-03 20:57:04 +02:00
case Hie_SYS: // System
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s",
Cfg_PLATFORM_SHORT_NAME);
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY: // Country
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s %s",
2019-04-03 20:57:04 +02:00
Txt_Country,Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS: // Institution
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s %s",
2019-04-03 20:57:04 +02:00
Txt_Institution,Gbl.Hierarchy.Ins.ShrtName);
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR: // Centre
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s %s",
2019-04-03 20:57:04 +02:00
Txt_Centre,Gbl.Hierarchy.Ctr.ShrtName);
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG: // Degree
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s %s",
2019-04-03 20:57:04 +02:00
Txt_Degree,Gbl.Hierarchy.Deg.ShrtName);
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS: // Course
2016-10-27 01:30:14 +02:00
fprintf (Gbl.F.Out,"%s %s",
2019-04-04 10:45:15 +02:00
Txt_Course,Gbl.Hierarchy.Crs.ShrtName);
2016-10-27 01:30:14 +02:00
break;
}
2015-04-11 20:18:30 +02:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/* Users' roles who can answer the survey */
2016-03-24 16:49:36 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">%s:<br />",
2014-12-01 23:55:08 +01:00
Svy.Status.Visible ? "ASG_GRP" :
"ASG_GRP_LIGHT",
Txt_Users);
2017-05-18 19:13:41 +02:00
Rol_WriteSelectorRoles (1 << Rol_STD |
2017-05-22 21:03:14 +02:00
1 << Rol_NET |
2017-05-18 19:13:41 +02:00
1 << Rol_TCH,
2016-03-24 16:49:36 +01:00
Svy.Roles,
true,false);
2015-04-11 20:18:30 +02:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/* Groups whose users can answer this survey */
2019-04-03 20:57:04 +02:00
if (Svy.Scope == Hie_CRS)
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.NumGrps)
2014-12-01 23:55:08 +01:00
Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (&Svy);
/* Text of the survey */
Svy_GetSurveyTxtFromDB (Svy.SvyCod,Txt);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
2016-10-26 01:23:02 +02:00
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to rigorous HTML
2016-01-25 00:19:21 +01:00
Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
2017-10-24 11:26:01 +02:00
fprintf (Gbl.F.Out,"<div class=\"PAR %s\">%s</div>"
2015-04-11 20:18:30 +02:00
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
Svy.Status.Visible ? "DAT" :
"DAT_LIGHT",
Txt);
/***** Write questions of this survey *****/
if (ShowOnlyThisSvyComplete)
{
2016-03-24 22:03:24 +01:00
fprintf (Gbl.F.Out,"<tr>"
2017-05-23 18:15:59 +02:00
"<td colspan=\"5\">");
2014-12-01 23:55:08 +01:00
Svy_ListSvyQuestions (&Svy,SvyQst);
2016-03-24 22:03:24 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
}
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
/***** Mark possible notification as seen *****/
2019-04-03 20:57:04 +02:00
if (Svy.Scope == Hie_CRS) // Only course surveys are notified
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsSeen (Ntf_EVENT_SURVEY,
2016-10-27 01:30:14 +02:00
SvyCod,Svy.Cod,
Gbl.Usrs.Me.UsrDat.UsrCod);
2015-04-12 18:01:06 +02:00
if (ShowOnlyThisSvyComplete)
2016-11-13 00:50:24 +01:00
{
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2016-11-13 00:50:24 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-11-13 00:50:24 +01:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Write the author of a survey ************************/
/*****************************************************************************/
static void Svy_WriteAuthor (struct Survey *Svy)
{
2017-03-04 01:59:27 +01:00
Usr_WriteAuthor1Line (Svy->UsrCod,!Svy->Status.Visible);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Write status of a survey ***************************/
/*****************************************************************************/
static void Svy_WriteStatus (struct Survey *Svy)
{
extern const char *Txt_Hidden_survey;
extern const char *Txt_Visible_survey;
extern const char *Txt_Closed_survey;
extern const char *Txt_Open_survey;
extern const char *Txt_SURVEY_Type_of_user_not_allowed;
extern const char *Txt_SURVEY_Type_of_user_allowed;
2016-10-28 10:36:14 +02:00
extern const char *Txt_SURVEY_You_belong_to_the_scope_of_the_survey;
extern const char *Txt_SURVEY_You_dont_belong_to_the_scope_of_the_survey;
2014-12-01 23:55:08 +01:00
extern const char *Txt_SURVEY_You_have_already_answered;
extern const char *Txt_SURVEY_You_have_not_answered;
/***** Start list with items of status *****/
fprintf (Gbl.F.Out,"<ul>");
/* Write whether survey is visible or hidden */
if (Svy->Status.Visible)
fprintf (Gbl.F.Out,"<li class=\"STATUS_GREEN\">%s</li>",
Txt_Visible_survey);
else
fprintf (Gbl.F.Out,"<li class=\"STATUS_RED_LIGHT\">%s</li>",
Txt_Hidden_survey);
/* Write whether survey is open or closed */
if (Svy->Status.Open)
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_GREEN" :
"STATUS_GREEN_LIGHT",
Txt_Open_survey);
else
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_RED" :
"STATUS_RED_LIGHT",
Txt_Closed_survey);
/* Write whether survey can be answered by me or not depending on user type */
if (Svy->Status.IAmLoggedWithAValidRoleToAnswer)
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_GREEN" :
"STATUS_GREEN_LIGHT",
Txt_SURVEY_Type_of_user_allowed);
else
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_RED" :
"STATUS_RED_LIGHT",
Txt_SURVEY_Type_of_user_not_allowed);
/* Write whether survey can be answered by me or not depending on groups */
2016-10-27 01:30:14 +02:00
if (Svy->Status.IBelongToScope)
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_GREEN" :
"STATUS_GREEN_LIGHT",
2016-10-28 10:36:14 +02:00
Txt_SURVEY_You_belong_to_the_scope_of_the_survey);
2014-12-01 23:55:08 +01:00
else
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_RED" :
"STATUS_RED_LIGHT",
2016-10-28 10:36:14 +02:00
Txt_SURVEY_You_dont_belong_to_the_scope_of_the_survey);
2014-12-01 23:55:08 +01:00
/* Write whether survey has been already answered by me or not */
if (Svy->Status.IHaveAnswered)
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_GREEN" :
"STATUS_GREEN_LIGHT",
Txt_SURVEY_You_have_already_answered);
else
fprintf (Gbl.F.Out,"<li class=\"%s\">%s</li>",
Svy->Status.Visible ? "STATUS_RED" :
"STATUS_RED_LIGHT",
Txt_SURVEY_You_have_not_answered);
/***** End list with items of status *****/
fprintf (Gbl.F.Out,"</ul>");
}
/*****************************************************************************/
/********* Get parameter with the type or order in list of surveys ***********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Svy_GetParamSvyOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 21:41:08 +01:00
Gbl.Svys.SelectedOrder = (Svy_Order_t)
Par_GetParToUnsignedLong ("Order",
0,
Svy_NUM_ORDERS - 1,
(unsigned long) Svy_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***** Put a hidden parameter with the type of order in list of surveys ******/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
void Svy_PutHiddenParamSvyOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 12:42:19 +01:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Svys.SelectedOrder);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Put a link (form) to edit one survey ********************/
/*****************************************************************************/
static void Svy_PutFormsToRemEditOneSvy (long SvyCod,bool Visible)
{
extern const char *Txt_Reset;
2015-12-13 19:37:08 +01:00
Gbl.Svys.SvyCodToEdit = SvyCod; // Used as parameters in contextual links
2014-12-01 23:55:08 +01:00
/***** Put form to remove survey *****/
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToRemove (ActReqRemSvy,Svy_PutParams);
2014-12-01 23:55:08 +01:00
/***** Put form to reset survey *****/
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActReqRstSvy,NULL,Svy_PutParams,
"recycle.svg",
Txt_Reset);
2014-12-01 23:55:08 +01:00
/***** Put form to hide/show survey *****/
if (Visible)
2019-03-25 19:05:10 +01:00
Ico_PutContextualIconToHide (ActHidSvy,NULL,Svy_PutParams);
2014-12-01 23:55:08 +01:00
else
2019-03-25 19:05:10 +01:00
Ico_PutContextualIconToUnhide (ActShoSvy,NULL,Svy_PutParams);
2014-12-01 23:55:08 +01:00
/***** Put form to edit survey *****/
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiOneSvy,Svy_PutParams);
2014-12-01 23:55:08 +01:00
}
2015-12-13 19:37:08 +01:00
/*****************************************************************************/
/********************** Params used to edit a survey *************************/
/*****************************************************************************/
static void Svy_PutParams (void)
{
2015-12-13 21:12:34 +01:00
if (Gbl.Svys.SvyCodToEdit > 0)
Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit);
2017-01-29 12:42:19 +01:00
Att_PutHiddenParamAttOrder ();
2015-12-13 19:37:08 +01:00
Grp_PutParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_SURVEYS,Gbl.Svys.CurrentPage);
2015-12-13 19:37:08 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********************** Get list of all the surveys *************************/
/*****************************************************************************/
void Svy_GetListSurveys (void)
{
2019-04-03 20:57:04 +02:00
char *SubQuery[Hie_NUM_LEVELS];
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Svy_NUM_ORDERS] =
{
"StartTime DESC,EndTime DESC,Title DESC", // Svy_ORDER_BY_START_DATE
"EndTime DESC,StartTime DESC,Title DESC", // Svy_ORDER_BY_END_DATE
};
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumSvy;
2016-10-27 01:30:14 +02:00
unsigned ScopesAllowed = 0;
unsigned HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
long Cods[Hie_NUM_LEVELS];
Hie_Level_t Scope;
2019-01-03 15:25:18 +01:00
bool SubQueryFilled = false;
2014-12-01 23:55:08 +01:00
2016-10-27 01:30:14 +02:00
/***** Free list of surveys *****/
2014-12-01 23:55:08 +01:00
if (Gbl.Svys.LstIsRead)
Svy_FreeListSurveys ();
2016-10-27 01:30:14 +02:00
/***** Set allowed and hidden scopes to get list depending on my user's role *****/
Svy_SetAllowedAndHiddenScopes (&ScopesAllowed,&HiddenAllowed);
2014-12-01 23:55:08 +01:00
/***** Get list of surveys from database *****/
2019-04-03 20:57:04 +02:00
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
2019-04-04 10:45:15 +02:00
Cods[Hie_CRS] = Gbl.Hierarchy.Crs.CrsCod; // Course
2016-10-27 01:30:14 +02:00
2016-10-29 00:22:34 +02:00
/* Fill subqueries for system, country, institution, centre and degree */
2019-04-03 20:57:04 +02:00
for (Scope = Hie_SYS;
Scope <= Hie_DEG;
2016-10-27 01:30:14 +02:00
Scope++)
if (ScopesAllowed & 1 << Scope)
{
2019-01-03 15:25:18 +01:00
if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)",
SubQueryFilled ? " OR " :
"",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cods[Scope],
2019-01-03 15:25:18 +01:00
(HiddenAllowed & 1 << Scope) ? "" :
" AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit ();
2016-10-27 01:30:14 +02:00
SubQueryFilled = true;
}
else
2019-01-03 15:25:18 +01:00
{
if (asprintf (&SubQuery[Scope],"%s","") < 0)
Lay_NotEnoughMemoryExit ();
}
2014-12-01 23:55:08 +01:00
2016-10-29 00:22:34 +02:00
/* Fill subquery for course */
2019-04-03 20:57:04 +02:00
if (ScopesAllowed & 1 << Hie_CRS)
2016-10-29 00:22:34 +02:00
{
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS)
2019-01-03 15:25:18 +01:00
{
2019-04-03 20:57:04 +02:00
if (asprintf (&SubQuery[Hie_CRS],"%s("
2019-01-03 15:25:18 +01:00
"Scope='%s' AND Cod=%ld%s"
" AND "
"(SvyCod NOT IN"
" (SELECT SvyCod FROM svy_grp)"
" OR"
" SvyCod IN"
" (SELECT svy_grp.SvyCod"
" FROM svy_grp,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND svy_grp.GrpCod=crs_grp_usr.GrpCod))"
")",
SubQueryFilled ? " OR " :
"",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS),Cods[Hie_CRS],
(HiddenAllowed & 1 << Hie_CRS) ? "" :
2019-01-03 15:25:18 +01:00
" AND Hidden='N'",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
}
2019-04-04 10:45:15 +02:00
else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS
2019-01-03 15:25:18 +01:00
{
2019-04-03 20:57:04 +02:00
if (asprintf (&SubQuery[Hie_CRS],"%s(Scope='%s' AND Cod=%ld%s)",
2019-01-03 15:25:18 +01:00
SubQueryFilled ? " OR " :
"",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS),Cods[Hie_CRS],
(HiddenAllowed & 1 << Hie_CRS) ? "" :
2019-01-03 15:25:18 +01:00
" AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit ();
}
2016-10-29 00:22:34 +02:00
SubQueryFilled = true;
}
2016-11-01 15:57:42 +01:00
else
2019-01-03 15:25:18 +01:00
{
2019-04-03 20:57:04 +02:00
if (asprintf (&SubQuery[Hie_CRS],"%s","") < 0)
2019-01-03 15:25:18 +01:00
Lay_NotEnoughMemoryExit ();
}
2016-10-29 00:22:34 +02:00
2018-11-02 01:23:05 +01:00
/* Make query */
2016-10-27 01:30:14 +02:00
if (SubQueryFilled)
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get surveys",
"SELECT SvyCod FROM surveys"
" WHERE %s%s%s%s%s%s"
" ORDER BY %s",
2019-04-03 20:57:04 +02:00
SubQuery[Hie_SYS],
SubQuery[Hie_CTY],
SubQuery[Hie_INS],
SubQuery[Hie_CTR],
SubQuery[Hie_DEG],
SubQuery[Hie_CRS],
2019-01-03 15:25:18 +01:00
OrderBySubQuery[Gbl.Svys.SelectedOrder]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 01:23:05 +01:00
{
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Can not get list of surveys.");
2018-11-02 01:23:05 +01:00
NumRows = 0; // Not reached. Initialized to avoid warning
}
2014-12-01 23:55:08 +01:00
2019-01-03 15:25:18 +01:00
/* Free allocated memory for subqueries */
2019-04-03 20:57:04 +02:00
for (Scope = Hie_SYS;
Scope <= Hie_CRS;
2019-01-03 15:25:18 +01:00
Scope++)
free ((void *) SubQuery[Scope]);
2014-12-01 23:55:08 +01:00
if (NumRows) // Surveys found...
{
Gbl.Svys.Num = (unsigned) NumRows;
/***** Create list of surveys *****/
if ((Gbl.Svys.LstSvyCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the surveys codes *****/
for (NumSvy = 0;
NumSvy < Gbl.Svys.Num;
NumSvy++)
{
/* Get next survey code */
row = mysql_fetch_row (mysql_res);
if ((Gbl.Svys.LstSvyCods[NumSvy] = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Error: wrong survey code.");
}
}
else
Gbl.Svys.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
Gbl.Svys.LstIsRead = true;
}
2016-10-27 01:30:14 +02:00
/*****************************************************************************/
/*** Set allowed and hidden scopes to get list depending on my user's role ***/
/*****************************************************************************/
static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
unsigned *HiddenAllowed)
{
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2016-10-27 01:30:14 +02:00
{
2017-05-18 19:13:41 +02:00
case Rol_UNK: // User not logged in *********************************
2016-10-27 01:30:14 +02:00
*ScopesAllowed = 0;
*HiddenAllowed = 0;
break;
2017-05-18 19:13:41 +02:00
case Rol_GST: // User not belonging to any course *******************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
break;
2017-05-18 19:13:41 +02:00
case Rol_USR: // Student or teacher in other courses...
2016-10-27 01:30:14 +02:00
// ...but not belonging to the current course *********
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod))
*ScopesAllowed |= 1 << Hie_DEG;
2016-10-27 01:30:14 +02:00
}
}
}
break;
2017-05-18 19:13:41 +02:00
case Rol_STD: // Student in current course **************************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_DEG;
2017-05-23 00:40:03 +02:00
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CRS;
2016-10-27 01:30:14 +02:00
}
}
}
}
break;
2017-05-21 21:23:13 +02:00
case Rol_NET: // Non-editing teacher in current course **************
2017-05-18 19:13:41 +02:00
case Rol_TCH: // Teacher in current course **************************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Usr_CheckIfIBelongToCty (Gbl.Hierarchy.Cty.CtyCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Usr_CheckIfIBelongToIns (Gbl.Hierarchy.Ins.InsCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
if (Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
if (Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod))
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_DEG;
2017-05-23 00:40:03 +02:00
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CRS;
*HiddenAllowed |= 1 << Hie_CRS; // A non-editing teacher or teacher can view hidden course surveys
2016-10-27 01:30:14 +02:00
}
}
}
}
}
break;
case Rol_DEG_ADM: // Degree administrator *******************************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
if (Gbl.Hierarchy.Deg.DegCod > 0) // Degree selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_DEG;
*HiddenAllowed |= 1 << Hie_DEG; // A degree admin can view hidden degree surveys
2016-10-27 01:30:14 +02:00
}
}
}
}
break;
case Rol_CTR_ADM: // Centre administrator *******************************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
*HiddenAllowed |= 1 << Hie_CTR; // A centre admin can view hidden centre surveys
2016-10-27 01:30:14 +02:00
}
}
}
break;
case Rol_INS_ADM: // Institution administrator **************************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
2016-10-27 01:30:14 +02:00
*HiddenAllowed = 0;
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
*HiddenAllowed |= 1 << Hie_INS; // An institution admin can view hidden institution surveys
2016-10-27 01:30:14 +02:00
}
}
break;
case Rol_SYS_ADM: // System administrator (superuser) *******************
2019-04-03 20:57:04 +02:00
*ScopesAllowed = 1 << Hie_SYS;
*HiddenAllowed = 1 << Hie_SYS; // A system admin can view hidden system surveys
if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTY;
*HiddenAllowed |= 1 << Hie_CTY; // A system admin can view hidden country surveys
if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_INS;
*HiddenAllowed |= 1 << Hie_INS; // A system admin can view hidden institution surveys
if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Centre selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CTR;
*HiddenAllowed |= 1 << Hie_CTR; // A system admin can view hidden centre surveys
if (Gbl.Hierarchy.Deg.DegCod > 0) // Degree selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_DEG;
*HiddenAllowed |= 1 << Hie_DEG; // A system admin can view hidden degree surveys
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
2016-10-27 01:30:14 +02:00
{
2019-04-03 20:57:04 +02:00
*ScopesAllowed |= 1 << Hie_CRS;
*HiddenAllowed |= 1 << Hie_CRS; // A system admin can view hidden course surveys
2016-10-27 01:30:14 +02:00
}
}
}
}
}
break;
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Get survey data using its code ************************/
/*****************************************************************************/
void Svy_GetDataOfSurveyByCod (struct Survey *Svy)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get data of survey from database *****/
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get survey data",
"SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title"
" FROM surveys"
" WHERE SvyCod=%ld",
Svy->SvyCod);
2014-12-01 23:55:08 +01:00
if (NumRows) // Survey found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of the survey (row[0]) */
Svy->SvyCod = Str_ConvertStrCodToLongCod (row[0]);
2016-10-27 01:30:14 +02:00
/* Get survey scope (row[1]) */
2019-04-03 20:57:04 +02:00
if ((Svy->Scope = Sco_GetScopeFromDBStr (row[1])) == Hie_UNK)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
/* Get code of the country, institution, centre, degree or course (row[2]) */
Svy->Cod = Str_ConvertStrCodToLongCod (row[2]);
2016-10-26 01:23:02 +02:00
2014-12-01 23:55:08 +01:00
/* Get whether the survey is hidden (row[3]) */
2016-09-07 18:48:10 +02:00
Svy->Status.Visible = (row[3][0] == 'N');
2014-12-01 23:55:08 +01:00
/* Get roles (row[4]) */
if (sscanf (row[4],"%u",&Svy->Roles) != 1)
Lay_ShowErrorAndExit ("Error when reading roles of survey.");
/* Get author of the survey (row[5]) */
Svy->UsrCod = Str_ConvertStrCodToLongCod (row[5]);
2015-10-23 13:51:33 +02:00
/* Get start date (row[6] holds the start UTC time) */
Svy->TimeUTC[Att_START_TIME] = Dat_GetUNIXTimeFromStr (row[6]);
2014-12-01 23:55:08 +01:00
2015-10-23 13:51:33 +02:00
/* Get end date (row[7] holds the end UTC time) */
Svy->TimeUTC[Att_END_TIME ] = Dat_GetUNIXTimeFromStr (row[7]);
2014-12-01 23:55:08 +01:00
/* Get whether the survey is open or closed (row(8)) */
Svy->Status.Open = (row[8][0] == '1');
/* Get the title of the survey (row[9]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Svy->Title,row[9],
2017-03-08 03:48:23 +01:00
Svy_MAX_BYTES_SURVEY_TITLE);
2014-12-01 23:55:08 +01:00
/* Get number of questions and number of users who have already answer this survey */
Svy->NumQsts = Svy_GetNumQstsSvy (Svy->SvyCod);
Svy->NumUsrs = Svy_GetNumUsrsWhoHaveAnsweredSvy (Svy->SvyCod);
/* Am I logged with a valid role to answer this survey? */
2017-06-04 18:18:54 +02:00
Svy->Status.IAmLoggedWithAValidRoleToAnswer = (Svy->Roles & (1 << Gbl.Usrs.Me.Role.Logged));
2014-12-01 23:55:08 +01:00
/* Do I belong to valid groups to answer this survey? */
2016-10-27 01:30:14 +02:00
switch (Svy->Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_UNK: // Unknown
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
break;
2019-04-03 20:57:04 +02:00
case Hie_SYS: // System
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Gbl.Usrs.Me.Logged;
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY: // Country
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Usr_CheckIfIBelongToCty (Svy->Cod);
break;
2019-04-03 20:57:04 +02:00
case Hie_INS: // Institution
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Usr_CheckIfIBelongToIns (Svy->Cod);
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR: // Centre
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Usr_CheckIfIBelongToCtr (Svy->Cod);
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG: // Degree
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Usr_CheckIfIBelongToDeg (Svy->Cod);
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS: // Course
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = Usr_CheckIfIBelongToCrs (Svy->Cod) &&
Svy_CheckIfICanDoThisSurveyBasedOnGrps (Svy->SvyCod);
break;
}
2014-12-01 23:55:08 +01:00
/* Have I answered this survey? */
Svy->Status.IHaveAnswered = Svy_CheckIfIHaveAnsweredSvy (Svy->SvyCod);
/* Can I answer survey? */
Svy->Status.ICanAnswer = (Svy->NumQsts != 0) &&
Svy->Status.Visible &&
Svy->Status.Open &&
Svy->Status.IAmLoggedWithAValidRoleToAnswer &&
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope &&
2014-12-01 23:55:08 +01:00
!Svy->Status.IHaveAnswered;
/* Can I view results of the survey?
Can I edit survey? */
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_STD:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_CRS ||
Svy->Scope == Hie_DEG ||
Svy->Scope == Hie_CTR ||
Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2016-10-27 01:30:14 +02:00
(Svy->NumQsts != 0) &&
Svy->Status.Visible &&
Svy->Status.Open &&
Svy->Status.IAmLoggedWithAValidRoleToAnswer &&
Svy->Status.IBelongToScope &&
Svy->Status.IHaveAnswered;
Svy->Status.ICanEdit = false;
2014-12-01 23:55:08 +01:00
break;
2017-05-22 21:03:14 +02:00
case Rol_NET:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_CRS ||
Svy->Scope == Hie_DEG ||
Svy->Scope == Hie_CTR ||
Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2017-05-22 21:03:14 +02:00
Svy->NumQsts != 0 &&
!Svy->Status.ICanAnswer;
Svy->Status.ICanEdit = false;
break;
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_CRS ||
Svy->Scope == Hie_DEG ||
Svy->Scope == Hie_CTR ||
Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2016-10-27 01:30:14 +02:00
Svy->NumQsts != 0 &&
2014-12-01 23:55:08 +01:00
!Svy->Status.ICanAnswer;
2019-04-03 20:57:04 +02:00
Svy->Status.ICanEdit = Svy->Scope == Hie_CRS &&
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope;
2014-12-01 23:55:08 +01:00
break;
2015-04-07 21:44:24 +02:00
case Rol_DEG_ADM:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_DEG ||
Svy->Scope == Hie_CTR ||
Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2016-10-27 01:30:14 +02:00
(Svy->NumQsts != 0) &&
!Svy->Status.ICanAnswer;
2019-04-03 20:57:04 +02:00
Svy->Status.ICanEdit = Svy->Scope == Hie_DEG &&
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope;
break;
case Rol_CTR_ADM:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_CTR ||
Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2016-10-27 01:30:14 +02:00
(Svy->NumQsts != 0) &&
!Svy->Status.ICanAnswer;
2019-04-03 20:57:04 +02:00
Svy->Status.ICanEdit = Svy->Scope == Hie_CTR &&
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope;
break;
case Rol_INS_ADM:
2019-04-03 20:57:04 +02:00
Svy->Status.ICanViewResults = (Svy->Scope == Hie_INS ||
Svy->Scope == Hie_CTY ||
Svy->Scope == Hie_SYS) &&
2016-10-27 01:30:14 +02:00
(Svy->NumQsts != 0) &&
!Svy->Status.ICanAnswer;
2019-04-03 20:57:04 +02:00
Svy->Status.ICanEdit = Svy->Scope == Hie_INS &&
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope;
2014-12-01 23:55:08 +01:00
break;
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2014-12-01 23:55:08 +01:00
Svy->Status.ICanViewResults = (Svy->NumQsts != 0);
2016-10-27 01:30:14 +02:00
Svy->Status.ICanEdit = true;
2014-12-01 23:55:08 +01:00
break;
default:
Svy->Status.ICanViewResults = false;
2016-10-27 01:30:14 +02:00
Svy->Status.ICanEdit = false;
2014-12-01 23:55:08 +01:00
break;
}
}
else
{
/* Initialize to empty survey */
2016-10-27 01:30:14 +02:00
Svy->SvyCod = -1L;
2019-04-03 20:57:04 +02:00
Svy->Scope = Hie_UNK;
2016-10-27 01:30:14 +02:00
Svy->Roles = 0;
Svy->UsrCod = -1L;
2015-10-23 13:51:33 +02:00
Svy->TimeUTC[Svy_START_TIME] =
Svy->TimeUTC[Svy_END_TIME ] = (time_t) 0;
2016-10-27 01:30:14 +02:00
Svy->Title[0] = '\0';
Svy->NumQsts = 0;
Svy->NumUsrs = 0;
Svy->Status.Visible = true;
Svy->Status.Open = false;
2014-12-01 23:55:08 +01:00
Svy->Status.IAmLoggedWithAValidRoleToAnswer = false;
2016-10-27 01:30:14 +02:00
Svy->Status.IBelongToScope = false;
Svy->Status.IHaveAnswered = false;
Svy->Status.ICanAnswer = false;
Svy->Status.ICanViewResults = false;
Svy->Status.ICanEdit = false;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/**************************** Free list of surveys ***************************/
/*****************************************************************************/
void Svy_FreeListSurveys (void)
{
if (Gbl.Svys.LstIsRead && Gbl.Svys.LstSvyCods)
{
/***** Free memory used by the list of surveys *****/
free ((void *) Gbl.Svys.LstSvyCods);
Gbl.Svys.LstSvyCods = NULL;
Gbl.Svys.Num = 0;
Gbl.Svys.LstIsRead = false;
}
}
/*****************************************************************************/
/********************** Get survey text from database ************************/
/*****************************************************************************/
2017-01-15 22:58:26 +01:00
static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get text of survey from database *****/
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text",
"SELECT Txt FROM surveys WHERE SvyCod=%ld",
SvyCod);
2014-12-01 23:55:08 +01:00
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
2017-01-17 03:10:43 +01:00
Str_Copy (Txt,row[0],
Cns_MAX_BYTES_TEXT);
2014-12-01 23:55:08 +01:00
}
else
Txt[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumRows > 1)
Lay_ShowErrorAndExit ("Error when getting survey text.");
}
/*****************************************************************************/
/******************** Get summary and content of a survey *******************/
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
2017-03-08 14:12:33 +01:00
void Svy_GetNotifSurvey (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
2017-03-06 13:01:16 +01:00
char **ContentStr,
long SvyCod,bool GetContent)
2014-12-01 23:55:08 +01:00
{
2017-03-13 14:45:05 +01:00
char Query[128];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-15 22:58:26 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
/***** Build query *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT Title,Txt FROM surveys WHERE SvyCod=%ld",
2014-12-01 23:55:08 +01:00
SvyCod);
if (!mysql_query (&Gbl.mysql,Query))
if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL)
{
/***** Result should have a unique row *****/
if (mysql_num_rows (mysql_res) == 1)
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/***** Get summary *****/
2017-01-17 03:10:43 +01:00
Str_Copy (SummaryStr,row[0],
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2014-12-01 23:55:08 +01:00
/***** Get content *****/
if (GetContent)
{
2017-01-15 22:58:26 +01:00
Length = strlen (row[1]);
if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
2017-01-17 03:10:43 +01:00
Str_Copy (*ContentStr,row[1],
Length);
2014-12-01 23:55:08 +01:00
}
}
mysql_free_result (mysql_res);
}
}
/*****************************************************************************/
/******************* Write parameter with code of survey *********************/
/*****************************************************************************/
static void Svy_PutParamSvyCod (long SvyCod)
{
Par_PutHiddenParamLong ("SvyCod",SvyCod);
}
/*****************************************************************************/
/******************** Get parameter with code of survey **********************/
/*****************************************************************************/
2016-03-20 02:48:16 +01:00
static long Svy_GetParamSvyCod (void)
2014-12-01 23:55:08 +01:00
{
2017-01-28 20:32:50 +01:00
/***** Get code of survey *****/
return Par_GetParToLong ("SvyCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Ask for confirmation of removing of a survey ****************/
/*****************************************************************************/
void Svy_AskRemSurvey (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_survey_X;
extern const char *Txt_Remove_survey;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not remove this survey.");
2017-04-28 14:05:30 +02:00
/***** Show question and button to remove survey *****/
2017-05-11 21:53:37 +02:00
Gbl.Svys.SvyCodToEdit = Svy.SvyCod;
2019-02-17 01:14:55 +01:00
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,
Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/****************************** Remove a survey ******************************/
/*****************************************************************************/
void Svy_RemoveSurvey (void)
{
extern const char *Txt_Survey_X_removed;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not remove this survey.");
/***** Remove all the users in this survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove users who are answered a survey",
"DELETE FROM svy_users WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Remove all the answers in this survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove answers of a survey",
"DELETE FROM svy_answers USING svy_questions,svy_answers"
" WHERE svy_questions.SvyCod=%ld"
" AND svy_questions.QstCod=svy_answers.QstCod",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Remove all the questions in this survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove questions of a survey",
"DELETE FROM svy_questions"
" WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Remove all the groups of this survey *****/
Svy_RemoveAllTheGrpsAssociatedToAndSurvey (Svy.SvyCod);
/***** Remove survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove survey",
"DELETE FROM surveys WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Mark possible notifications as removed *****/
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsRemoved (Ntf_EVENT_SURVEY,Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Survey_X_removed,
Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/***************** Ask for confirmation of reset of a survey *****************/
/*****************************************************************************/
void Svy_AskResetSurvey (void)
{
extern const char *Txt_Do_you_really_want_to_reset_the_survey_X;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not reset this survey.");
/***** Ask for confirmation of reset *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Do_you_really_want_to_reset_the_survey_X,
Svy.Title);
2015-12-13 21:12:34 +01:00
/***** Button of confirmation of reset *****/
Gbl.Svys.SvyCodToEdit = Svy.SvyCod;
2016-03-20 02:48:16 +01:00
Svy_PutButtonToResetSurvey ();
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/************************* Put button to reset survey ************************/
/*****************************************************************************/
static void Svy_PutButtonToResetSurvey (void)
{
extern const char *Txt_Reset_survey;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRstSvy);
2015-12-13 21:12:34 +01:00
Svy_PutParams ();
2017-06-11 19:02:40 +02:00
Btn_PutRemoveButton (Txt_Reset_survey);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Reset a survey ******************************/
/*****************************************************************************/
void Svy_ResetSurvey (void)
{
extern const char *Txt_Survey_X_reset;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not reset this survey.");
/***** Remove all the users in this survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove users who are answered a survey",
"DELETE FROM svy_users WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Reset all the answers in this survey *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not reset answers of a survey",
"UPDATE svy_answers,svy_questions SET svy_answers.NumUsrs=0"
" WHERE svy_questions.SvyCod=%ld"
" AND svy_questions.QstCod=svy_answers.QstCod",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Survey_X_reset,
Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/******************************** Hide a survey ******************************/
/*****************************************************************************/
void Svy_HideSurvey (void)
{
extern const char *Txt_Survey_X_is_now_hidden;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not hide this survey.");
/***** Hide survey *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not hide survey",
"UPDATE surveys SET Hidden='Y' WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Survey_X_is_now_hidden,
Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/******************************** Show a survey ******************************/
/*****************************************************************************/
void Svy_UnhideSurvey (void)
{
extern const char *Txt_Survey_X_is_now_visible;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not unhide this survey.");
/***** Show survey *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not show survey",
"UPDATE surveys SET Hidden='N' WHERE SvyCod=%ld",
Svy.SvyCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Survey_X_is_now_visible,
Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/******************* Check if the title of a survey exists *******************/
/*****************************************************************************/
static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy)
{
/***** Get number of surveys with a field value from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not get similar surveys",
"SELECT COUNT(*) FROM surveys"
" WHERE Scope='%s' AND Cod=%ld"
" AND Title='%s' AND SvyCod<>%ld",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
2018-11-03 22:08:45 +01:00
Svy->Title,Svy->SvyCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Put a form to create a new survey *********************/
/*****************************************************************************/
void Svy_RequestCreatOrEditSvy (void)
{
2017-05-02 16:57:49 +02:00
extern const char *Hlp_ASSESSMENT_Surveys_new_survey;
extern const char *Hlp_ASSESSMENT_Surveys_edit_survey;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_New_survey;
extern const char *Txt_Scope;
extern const char *Txt_Edit_survey;
extern const char *Txt_Title;
extern const char *Txt_Description;
extern const char *Txt_Users;
extern const char *Txt_Create_survey;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2014-12-01 23:55:08 +01:00
struct Survey Svy;
struct SurveyQuestion SvyQst;
bool ItsANewSurvey;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Get the code of the survey *****/
ItsANewSurvey = ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L);
/***** Get from the database the data of the survey *****/
if (ItsANewSurvey)
{
/***** Put link (form) to create new survey *****/
if (!Svy_CheckIfICanCreateSvy ())
Lay_ShowErrorAndExit ("You can not create a new survey here.");
/* Initialize to empty survey */
Svy.SvyCod = -1L;
2019-04-03 20:57:04 +02:00
Svy.Scope = Hie_UNK;
2017-05-18 19:13:41 +02:00
Svy.Roles = (1 << Rol_STD);
2016-10-26 01:23:02 +02:00
Svy.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2015-10-27 19:00:21 +01:00
Svy.TimeUTC[Svy_START_TIME] = Gbl.StartExecutionTimeUTC;
Svy.TimeUTC[Svy_END_TIME ] = Gbl.StartExecutionTimeUTC + (24 * 60 * 60); // +24 hours
2014-12-01 23:55:08 +01:00
Svy.Title[0] = '\0';
Svy.NumQsts = 0;
Svy.NumUsrs = 0;
Svy.Status.Visible = true;
Svy.Status.Open = true;
Svy.Status.IAmLoggedWithAValidRoleToAnswer = false;
2016-10-27 01:30:14 +02:00
Svy.Status.IBelongToScope = false;
2014-12-01 23:55:08 +01:00
Svy.Status.IHaveAnswered = false;
Svy.Status.ICanAnswer = false;
Svy.Status.ICanViewResults = false;
}
else
{
/* Get data of the survey from database */
Svy_GetDataOfSurveyByCod (&Svy);
if (!Svy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not update this survey.");
/* Get text of the survey from database */
Svy_GetSurveyTxtFromDB (Svy.SvyCod,Txt);
}
2015-04-11 17:33:14 +02:00
/***** Start form *****/
2016-04-05 13:07:33 +02:00
Gbl.Svys.SvyCodToEdit = Svy.SvyCod;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ItsANewSurvey ? ActNewSvy :
2015-12-13 21:12:34 +01:00
ActChgSvy);
Svy_PutParams ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-11 22:26:40 +02:00
if (ItsANewSurvey)
Box_StartBoxTable (NULL,Txt_New_survey,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys_new_survey,Box_NOT_CLOSABLE,2);
2017-06-11 22:26:40 +02:00
else
2017-10-01 00:48:36 +02:00
Box_StartBoxTable (NULL,
Svy.Title[0] ? Svy.Title :
Txt_Edit_survey,
NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys_edit_survey,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2016-10-26 01:23:02 +02:00
/***** Scope of the survey *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-03-27 21:36:52 +02:00
"<td class=\"RIGHT_MIDDLE\">"
2016-12-20 02:18:50 +01:00
"<label for=\"ScopeSvy\" class=\"%s\">%s:</label>"
2014-12-25 21:50:11 +01:00
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Scope);
2016-10-26 01:23:02 +02:00
Svy_SetDefaultAndAllowedScope (&Svy);
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeSvy");
Sco_PutSelectorScope ("ScopeSvy",false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Survey title *****/
fprintf (Gbl.F.Out,"<tr>"
2016-03-27 21:36:52 +02:00
"<td class=\"RIGHT_MIDDLE\">"
2016-12-20 02:18:50 +01:00
"<label for=\"Title\" class=\"%s\">%s:</label>"
2014-12-25 21:50:11 +01:00
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"LEFT_MIDDLE\">"
2016-12-20 02:18:50 +01:00
"<input type=\"text\" id=\"Title\" name=\"Title\""
2016-11-19 14:21:22 +01:00
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Title,
2017-03-08 03:48:23 +01:00
Svy_MAX_CHARS_SURVEY_TITLE,Svy.Title);
2014-12-01 23:55:08 +01:00
/***** Survey start and end dates *****/
2016-12-03 20:08:01 +01:00
Dat_PutFormStartEndClientLocalDateTimes (Svy.TimeUTC,Dat_FORM_SECONDS_ON);
2014-12-01 23:55:08 +01:00
/***** Survey text *****/
fprintf (Gbl.F.Out,"<tr>"
2016-03-27 21:36:52 +02:00
"<td class=\"RIGHT_TOP\">"
2016-12-20 02:18:50 +01:00
"<label for=\"Txt\" class=\"%s\">%s:</label>"
2014-12-25 21:50:11 +01:00
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"LEFT_TOP\">"
2016-12-20 02:18:50 +01:00
"<textarea id=\"Txt\" name=\"Txt\""
" cols=\"60\" rows=\"10\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Description);
if (!ItsANewSurvey)
fprintf (Gbl.F.Out,"%s",Txt);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
/***** Users' roles who can answer the survey *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 02:18:50 +01:00
"<td class=\"RIGHT_TOP %s\">%s:"
2014-12-25 21:50:11 +01:00
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"DAT LEFT_MIDDLE\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Users);
2017-05-18 19:13:41 +02:00
Rol_WriteSelectorRoles (1 << Rol_STD |
2017-05-22 21:03:14 +02:00
1 << Rol_NET |
2017-05-18 19:13:41 +02:00
1 << Rol_TCH,
2016-03-24 15:09:52 +01:00
Svy.Roles,
2016-03-24 16:49:36 +01:00
false,false);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Groups *****/
Svy_ShowLstGrpsToEditSurvey (Svy.SvyCod);
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2015-03-24 17:47:26 +01:00
if (ItsANewSurvey)
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_survey);
2015-03-24 17:47:26 +01:00
else
2019-02-18 18:27:45 +01:00
Box_EndBoxTableWithButton (Btn_CONFIRM_BUTTON,Txt_Save_changes);
2014-12-01 23:55:08 +01:00
2015-04-11 17:33:14 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
/***** Show questions of the survey ready to be edited *****/
if (!ItsANewSurvey)
Svy_ListSvyQuestions (&Svy,&SvyQst);
}
/*****************************************************************************/
2016-10-27 01:30:14 +02:00
/****** Set default and allowed scopes depending on logged user's role *******/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-10-26 01:23:02 +02:00
static void Svy_SetDefaultAndAllowedScope (struct Survey *Svy)
2014-12-01 23:55:08 +01:00
{
2016-10-26 01:23:02 +02:00
bool ICanEdit = false;
/***** Set default scope *****/
2019-04-03 20:57:04 +02:00
Gbl.Scope.Default = Hie_UNK;
2014-12-01 23:55:08 +01:00
Gbl.Scope.Allowed = 0;
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH: // Teachers only can edit course surveys
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
2016-10-26 01:23:02 +02:00
{
2019-04-03 20:57:04 +02:00
if (Svy->Scope == Hie_UNK) // Scope not defined
Svy->Scope = Hie_CRS;
if (Svy->Scope == Hie_CRS)
2016-10-26 01:23:02 +02:00
{
Gbl.Scope.Default = Svy->Scope;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Allowed = 1 << Hie_CRS;
2016-10-26 01:23:02 +02:00
ICanEdit = true;
}
}
break;
2016-10-27 01:30:14 +02:00
case Rol_DEG_ADM: // Degree admins only can edit degree surveys
2019-04-03 20:57:04 +02:00
if (Svy->Scope == Hie_UNK) // Scope not defined
Svy->Scope = Hie_DEG;
if (Svy->Scope == Hie_DEG)
2016-10-26 01:23:02 +02:00
{
Gbl.Scope.Default = Svy->Scope;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Allowed = 1 << Hie_DEG;
2016-10-26 01:23:02 +02:00
ICanEdit = true;
}
break;
2016-10-27 01:30:14 +02:00
case Rol_CTR_ADM: // Centre admins only can edit centre surveys
2019-04-03 20:57:04 +02:00
if (Svy->Scope == Hie_UNK) // Scope not defined
Svy->Scope = Hie_CTR;
if (Svy->Scope == Hie_CTR)
2016-10-27 01:30:14 +02:00
{
Gbl.Scope.Default = Svy->Scope;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Allowed = 1 << Hie_CTR;
2016-10-27 01:30:14 +02:00
ICanEdit = true;
}
break;
case Rol_INS_ADM: // Institution admins only can edit institution surveys
2019-04-03 20:57:04 +02:00
if (Svy->Scope == Hie_UNK) // Scope not defined
Svy->Scope = Hie_INS;
if (Svy->Scope == Hie_INS)
2016-10-26 01:23:02 +02:00
{
2016-10-27 01:30:14 +02:00
Gbl.Scope.Default = Svy->Scope;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Allowed = 1 << Hie_INS;
2016-10-27 01:30:14 +02:00
ICanEdit = true;
}
break;
case Rol_SYS_ADM:// System admins can edit any survey
2019-04-03 20:57:04 +02:00
if (Svy->Scope == Hie_UNK) // Scope not defined
Svy->Scope = (Gbl.Hierarchy.Level < Hie_NUM_LEVELS &&
Gbl.Hierarchy.Level != Hie_UNK) ? Gbl.Hierarchy.Level :
Hie_SYS;
2016-10-26 01:23:02 +02:00
Gbl.Scope.Default = Svy->Scope;
2019-04-03 20:57:04 +02:00
Gbl.Scope.Allowed = 1 << Hie_SYS |
1 << Hie_CTY |
1 << Hie_INS |
1 << Hie_CTR |
1 << Hie_DEG |
1 << Hie_CRS;
2016-10-26 01:23:02 +02:00
ICanEdit = true;
break;
2014-12-01 23:55:08 +01:00
default:
2016-10-26 01:23:02 +02:00
break;
2014-12-01 23:55:08 +01:00
}
2016-10-26 01:23:02 +02:00
if (!ICanEdit)
2019-02-16 20:44:31 +01:00
Lay_NoPermissionExit ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Show list of groups to edit a survey *******************/
/*****************************************************************************/
static void Svy_ShowLstGrpsToEditSurvey (long SvyCod)
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Groups;
extern const char *Txt_The_whole_course;
unsigned NumGrpTyp;
/***** Get list of groups types and groups in this course *****/
Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.GrpTypes.Num)
2014-12-01 23:55:08 +01:00
{
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_TOP\">"
2014-12-25 21:50:11 +01:00
"%s:"
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"LEFT_TOP\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-01 23:55:08 +01:00
Txt_Groups);
2017-06-10 21:38:10 +02:00
Box_StartBoxTable ("95%",NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,0);
2014-12-01 23:55:08 +01:00
/***** First row: checkbox to select the whole course *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-02 20:23:43 +02:00
"<td colspan=\"7\" class=\"DAT LEFT_MIDDLE\">"
2016-12-20 14:03:46 +01:00
"<label>"
2015-09-02 20:23:43 +02:00
"<input type=\"checkbox\""
" id=\"WholeCrs\" name=\"WholeCrs\" value=\"Y\"");
2014-12-01 23:55:08 +01:00
if (!Svy_CheckIfSvyIsAssociatedToGrps (SvyCod))
fprintf (Gbl.F.Out," checked=\"checked\"");
2016-12-20 14:03:46 +01:00
fprintf (Gbl.F.Out," onclick=\"uncheckChildren(this,'GrpCods')\" />"
"%s %s"
"</label>"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2019-04-04 10:45:15 +02:00
Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
2014-12-01 23:55:08 +01:00
/***** List the groups for each group type *****/
for (NumGrpTyp = 0;
2019-04-04 10:45:15 +02:00
NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num;
2014-12-01 23:55:08 +01:00
NumGrpTyp++)
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps)
Grp_ListGrpsToEditAsgAttSvyGam (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp],
2017-09-17 16:58:09 +02:00
SvyCod,Grp_SURVEY);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** Free list of groups types and groups in this course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/*****************************************************************************/
/********************* Receive form to create a new survey *******************/
/*****************************************************************************/
void Svy_RecFormSurvey (void)
{
extern const char *Txt_Already_existed_a_survey_with_the_title_X;
extern const char *Txt_You_must_specify_the_title_of_the_survey;
2016-10-27 01:30:14 +02:00
struct Survey OldSvy;
struct Survey NewSvy;
2014-12-01 23:55:08 +01:00
struct SurveyQuestion SvyQst;
bool ItsANewSurvey;
bool NewSurveyIsCorrect = true;
unsigned NumUsrsToBeNotifiedByEMail;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get the code of the survey *****/
ItsANewSurvey = ((NewSvy.SvyCod = Svy_GetParamSvyCod ()) == -1L);
2016-10-27 01:30:14 +02:00
if (ItsANewSurvey)
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_UNK;
2016-10-27 01:30:14 +02:00
else
2014-12-01 23:55:08 +01:00
{
/* Get data of the old (current) survey from database */
OldSvy.SvyCod = NewSvy.SvyCod;
Svy_GetDataOfSurveyByCod (&OldSvy);
if (!OldSvy.Status.ICanEdit)
Lay_ShowErrorAndExit ("You can not update this survey.");
2016-10-27 01:30:14 +02:00
NewSvy.Scope = OldSvy.Scope;
2014-12-01 23:55:08 +01:00
}
/***** Get scope *****/
2016-10-27 01:30:14 +02:00
Svy_SetDefaultAndAllowedScope (&NewSvy);
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeSvy");
2014-12-01 23:55:08 +01:00
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_SYS;
2016-10-27 01:30:14 +02:00
NewSvy.Cod = -1L;
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_CTY;
NewSvy.Cod = Gbl.Hierarchy.Cty.CtyCod;
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM &&
Gbl.Usrs.Me.Role.Logged != Rol_INS_ADM)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_INS;
NewSvy.Cod = Gbl.Hierarchy.Ins.InsCod;
2016-10-27 01:30:14 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM &&
Gbl.Usrs.Me.Role.Logged != Rol_CTR_ADM)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_CTR;
NewSvy.Cod = Gbl.Hierarchy.Ctr.CtrCod;
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM &&
Gbl.Usrs.Me.Role.Logged != Rol_DEG_ADM)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_DEG;
NewSvy.Cod = Gbl.Hierarchy.Deg.DegCod;
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM &&
Gbl.Usrs.Me.Role.Logged != Rol_TCH)
2016-10-27 01:30:14 +02:00
Lay_ShowErrorAndExit ("Wrong survey scope.");
2019-04-03 20:57:04 +02:00
NewSvy.Scope = Hie_CRS;
2019-04-04 10:45:15 +02:00
NewSvy.Cod = Gbl.Hierarchy.Crs.CrsCod;
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
2015-10-23 13:51:33 +02:00
/***** Get start/end date-times *****/
2016-12-15 00:39:52 +01:00
NewSvy.TimeUTC[Dat_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
NewSvy.TimeUTC[Dat_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
2014-12-01 23:55:08 +01:00
/***** Get survey title *****/
2017-03-08 03:48:23 +01:00
Par_GetParToText ("Title",NewSvy.Title,Svy_MAX_BYTES_SURVEY_TITLE);
2014-12-01 23:55:08 +01:00
/***** Get survey text and insert links *****/
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
/***** Adjust dates *****/
2015-10-23 13:51:33 +02:00
if (NewSvy.TimeUTC[Svy_START_TIME] == 0)
2015-10-27 19:00:21 +01:00
NewSvy.TimeUTC[Svy_START_TIME] = Gbl.StartExecutionTimeUTC;
2015-10-23 13:51:33 +02:00
if (NewSvy.TimeUTC[Svy_END_TIME] == 0)
2017-01-28 15:58:46 +01:00
NewSvy.TimeUTC[Svy_END_TIME] = NewSvy.TimeUTC[Svy_START_TIME] + 24 * 60 * 60; // +24 hours
2014-12-01 23:55:08 +01:00
/***** Get users who can answer this survey *****/
2016-03-24 16:49:36 +01:00
NewSvy.Roles = Rol_GetSelectedRoles ();
2014-12-01 23:55:08 +01:00
/***** Check if title is correct *****/
if (NewSvy.Title[0]) // If there's a survey title
{
/* If title of survey was in database... */
if (Svy_CheckIfSimilarSurveyExists (&NewSvy))
{
NewSurveyIsCorrect = false;
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_survey_with_the_title_X,
NewSvy.Title);
2014-12-01 23:55:08 +01:00
}
}
else // If there is not a survey title
{
NewSurveyIsCorrect = false;
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_survey);
2014-12-01 23:55:08 +01:00
}
/***** Create a new survey or update an existing one *****/
if (NewSurveyIsCorrect)
{
/* Get groups for this surveys */
2017-01-19 20:55:31 +01:00
Grp_GetParCodsSeveralGrps ();
2014-12-01 23:55:08 +01:00
if (ItsANewSurvey)
Svy_CreateSurvey (&NewSvy,Txt); // Add new survey to database
else
Svy_UpdateSurvey (&NewSvy,Txt);
/* Free memory for list of selected groups */
Grp_FreeListCodSelectedGrps ();
}
else
Svy_RequestCreatOrEditSvy ();
2016-11-16 23:19:52 +01:00
/***** Notify by email about the new survey *****/
2019-04-03 20:57:04 +02:00
if (NewSvy.Scope == Hie_CRS) // Notify only the surveys for a course, not for a degree or global
2014-12-01 23:55:08 +01:00
if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_SURVEY,NewSvy.SvyCod)))
Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (NewSvy.SvyCod,NumUsrsToBeNotifiedByEMail);
/***** Show surveys again *****/
Svy_ListAllSurveys (&SvyQst);
}
/*****************************************************************************/
/*********** Update number of users notified in table of surveys *************/
/*****************************************************************************/
2016-10-26 01:23:02 +02:00
static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
unsigned NumUsrsToBeNotifiedByEMail)
2014-12-01 23:55:08 +01:00
{
/***** Update number of users notified *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the number of notifications of a survey",
"UPDATE surveys SET NumNotif=NumNotif+%u"
" WHERE SvyCod=%ld",
NumUsrsToBeNotifiedByEMail,SvyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Create a new survey *****************************/
/*****************************************************************************/
static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt)
{
extern const char *Txt_Created_new_survey_X;
/***** Create a new survey *****/
2018-11-03 01:45:36 +01:00
Svy->SvyCod =
DB_QueryINSERTandReturnCode ("can not create new survey",
"INSERT INTO surveys"
" (Scope,Cod,Hidden,Roles,UsrCod,StartTime,EndTime,Title,Txt)"
" VALUES"
" ('%s',%ld,'N',%u,%ld,"
"FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
"'%s','%s')",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
2018-11-03 01:45:36 +01:00
Svy->Roles,
Gbl.Usrs.Me.UsrDat.UsrCod,
Svy->TimeUTC[Svy_START_TIME],
Svy->TimeUTC[Svy_END_TIME ],
Svy->Title,
Txt);
2014-12-01 23:55:08 +01:00
/***** Create groups *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
2014-12-01 23:55:08 +01:00
Svy_CreateGrps (Svy->SvyCod);
/***** Write success message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_survey_X,
Svy->Title);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Update an existing survey *************************/
/*****************************************************************************/
static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt)
{
extern const char *Txt_The_survey_has_been_modified;
/***** Update the data of the survey *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update survey",
"UPDATE surveys"
" SET Scope='%s',Cod=%ld,Roles=%u,"
"StartTime=FROM_UNIXTIME(%ld),"
"EndTime=FROM_UNIXTIME(%ld),"
"Title='%s',Txt='%s'"
" WHERE SvyCod=%ld",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
2018-11-03 12:16:40 +01:00
Svy->Roles,
Svy->TimeUTC[Svy_START_TIME],
Svy->TimeUTC[Svy_END_TIME ],
Svy->Title,
Txt,
Svy->SvyCod);
2014-12-01 23:55:08 +01:00
/***** Update groups *****/
/* Remove old groups */
Svy_RemoveAllTheGrpsAssociatedToAndSurvey (Svy->SvyCod);
/* Create new groups */
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
2014-12-01 23:55:08 +01:00
Svy_CreateGrps (Svy->SvyCod);
/***** Write success message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_survey_has_been_modified);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Check if a survey is associated to any group ****************/
/*****************************************************************************/
static bool Svy_CheckIfSvyIsAssociatedToGrps (long SvyCod)
{
/***** Get if a survey is associated to a group from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not check if a survey is associated to groups",
2018-11-04 20:51:38 +01:00
"SELECT COUNT(*) FROM svy_grp"
" WHERE SvyCod=%ld",
2018-11-03 22:08:45 +01:00
SvyCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Check if a survey is associated to a group *****************/
/*****************************************************************************/
bool Svy_CheckIfSvyIsAssociatedToGrp (long SvyCod,long GrpCod)
{
/***** Get if a survey is associated to a group from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not check if a survey is associated to a group",
"SELECT COUNT(*) FROM svy_grp"
" WHERE SvyCod=%ld AND GrpCod=%ld",
SvyCod,GrpCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Remove groups of a survey *************************/
/*****************************************************************************/
static void Svy_RemoveAllTheGrpsAssociatedToAndSurvey (long SvyCod)
{
/***** Remove groups of the survey *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove the groups associated to a survey",
"DELETE FROM svy_grp WHERE SvyCod=%ld",
SvyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Remove one group from all the surveys *******************/
/*****************************************************************************/
void Svy_RemoveGroup (long GrpCod)
{
/***** Remove group from all the surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove group from the associations"
" between surveys and groups",
"DELETE FROM svy_grp WHERE GrpCod=%ld",
GrpCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Remove groups of one type from all the surveys **************/
/*****************************************************************************/
void Svy_RemoveGroupsOfType (long GrpTypCod)
{
/***** Remove group from all the surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove groups of a type"
" from the associations between surveys and groups",
"DELETE FROM svy_grp USING crs_grp,svy_grp"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=svy_grp.GrpCod",
GrpTypCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Create groups of a survey **************************/
/*****************************************************************************/
static void Svy_CreateGrps (long SvyCod)
{
unsigned NumGrpSel;
/***** Create groups of the survey *****/
for (NumGrpSel = 0;
2019-04-04 10:45:15 +02:00
NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps;
2014-12-01 23:55:08 +01:00
NumGrpSel++)
/* Create group */
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not associate a group to a survey",
"INSERT INTO svy_grp"
" (SvyCod,GrpCod)"
" VALUES"
" (%ld,%ld)",
2019-04-04 10:45:15 +02:00
SvyCod,Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Get and write the names of the groups of a survey **************/
/*****************************************************************************/
static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy)
{
extern const char *Txt_Group;
extern const char *Txt_Groups;
extern const char *Txt_and;
extern const char *Txt_The_whole_course;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow;
unsigned long NumRows;
/***** Get groups associated to a survey from database *****/
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM svy_grp,crs_grp,crs_grp_types"
" WHERE svy_grp.SvyCod=%ld"
" AND svy_grp.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,"
"crs_grp.GrpName",
Svy->SvyCod);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
2015-04-11 20:18:30 +02:00
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
2014-12-01 23:55:08 +01:00
Svy->Status.Visible ? "ASG_GRP" :
"ASG_GRP_LIGHT",
NumRows == 1 ? Txt_Group :
Txt_Groups);
/***** Write groups *****/
if (NumRows) // Groups found...
{
/* Get and write the group types and names */
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Write group type name and group name */
fprintf (Gbl.F.Out,"%s %s",row[0],row[1]);
if (NumRows >= 2)
{
if (NumRow == NumRows-2)
fprintf (Gbl.F.Out," %s ",Txt_and);
if (NumRows >= 3)
if (NumRow < NumRows-2)
fprintf (Gbl.F.Out,", ");
}
}
}
else
fprintf (Gbl.F.Out,"%s %s",
2019-04-04 10:45:15 +02:00
Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
2014-12-01 23:55:08 +01:00
2015-04-11 20:18:30 +02:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2016-10-27 22:16:03 +02:00
/************ Remove all the surveys of a place on the hierarchy *************/
/************ (country, institution, centre, degree or course) *************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-04-03 20:57:04 +02:00
void Svy_RemoveSurveys (Hie_Level_t Scope,long Cod)
2014-12-01 23:55:08 +01:00
{
/***** Remove all the users in course surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove users"
" who had answered surveys in a place on the hierarchy",
"DELETE FROM svy_users"
" USING surveys,svy_users"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_users.SvyCod",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cod);
2014-12-01 23:55:08 +01:00
/***** Remove all the answers in course surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove answers of surveys"
" in a place on the hierarchy",
"DELETE FROM svy_answers"
" USING surveys,svy_questions,svy_answers"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod"
" AND svy_questions.QstCod=svy_answers.QstCod",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cod);
2014-12-01 23:55:08 +01:00
/***** Remove all the questions in course surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove questions of surveys"
" in a place on the hierarchy",
"DELETE FROM svy_questions"
" USING surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cod);
2014-12-01 23:55:08 +01:00
/***** Remove groups *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove all the groups"
" associated to surveys of a course",
"DELETE FROM svy_grp"
" USING surveys,svy_grp"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_grp.SvyCod",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cod);
2014-12-01 23:55:08 +01:00
/***** Remove course surveys *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove all the surveys"
" in a place on the hierarchy",
"DELETE FROM surveys"
" WHERE Scope='%s' AND Cod=%ld",
2019-04-01 23:15:17 +02:00
Sco_GetDBStrFromScope (Scope),Cod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Check if I belong to any of the groups of a survey *************/
/*****************************************************************************/
static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
{
/***** Get if I can do a survey from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not check if I can do a survey",
"SELECT COUNT(*) FROM surveys"
" WHERE SvyCod=%ld"
" AND (SvyCod NOT IN (SELECT SvyCod FROM svy_grp) OR"
" SvyCod IN (SELECT svy_grp.SvyCod FROM svy_grp,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND svy_grp.GrpCod=crs_grp_usr.GrpCod))",
SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of questions of a survey *********************/
/*****************************************************************************/
static unsigned Svy_GetNumQstsSvy (long SvyCod)
{
/***** Get data of questions from database *****/
2018-11-03 22:08:45 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of questions of a survey",
"SELECT COUNT(*) FROM svy_questions"
" WHERE SvyCod=%ld",
SvyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Put a form to edit/create a question in survey *****************/
/*****************************************************************************/
void Svy_RequestEditQuestion (void)
{
long SvyCod;
struct SurveyQuestion SvyQst;
2017-01-17 03:10:43 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2017-11-30 12:07:19 +01:00
/***** Initialize text to empty string *****/
2014-12-01 23:55:08 +01:00
Txt[0] = '\0';
/***** Get survey code *****/
if ((SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/* Get the question code */
SvyQst.QstCod = Svy_GetParamQstCod ();
/***** Get other parameters *****/
2017-01-29 12:42:19 +01:00
Svy_GetParamSvyOrder ();
2014-12-01 23:55:08 +01:00
Grp_GetParamWhichGrps ();
2017-04-13 20:09:22 +02:00
Gbl.Svys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS);
2014-12-01 23:55:08 +01:00
/***** Show form to create a new question in this survey *****/
Svy_ShowFormEditOneQst (SvyCod,&SvyQst,Txt);
/***** Show current survey *****/
Svy_ShowOneSurvey (SvyCod,&SvyQst,true);
}
/*****************************************************************************/
/******************* Show form to edit one survey question *******************/
/*****************************************************************************/
2017-01-17 03:10:43 +01:00
static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,
char Txt[Cns_MAX_BYTES_TEXT + 1])
2014-12-01 23:55:08 +01:00
{
2017-05-02 16:57:49 +02:00
extern const char *Hlp_ASSESSMENT_Surveys_questions;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Question;
extern const char *Txt_New_question;
extern const char *Txt_Stem;
extern const char *Txt_Type;
2015-01-02 12:57:26 +01:00
extern const char *Txt_SURVEY_STR_ANSWER_TYPES[Svy_NUM_ANS_TYPES];
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2015-04-11 20:18:30 +02:00
extern const char *Txt_Create_question;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-12-25 22:01:43 +01:00
unsigned NumAns;
unsigned NumAnswers = 0;
2014-12-01 23:55:08 +01:00
Svy_AnswerType_t AnsType;
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Act == ActEdiOneSvyQst) // If no receiving the question, but editing a new or existing question
2014-12-01 23:55:08 +01:00
{
if ((SvyQst->QstCod > 0)) // If parameter QstCod received ==> question already exists in the database
{
/***** Get the type of answer and the stem from the database *****/
/* Get the question from database */
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get a question",
"SELECT QstInd,AnsType,Stem FROM svy_questions"
" WHERE QstCod=%ld AND SvyCod=%ld",
SvyQst->QstCod,SvyCod);
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row (mysql_res);
/* Get question index inside survey (row[0]) */
if (sscanf (row[0],"%u",&(SvyQst->QstInd)) != 1)
Lay_ShowErrorAndExit ("Error: wrong question index.");
/* Get the type of answer (row[1]) */
SvyQst->AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[1]);
/* Get the stem of the question from the database (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Txt,row[2],
Cns_MAX_BYTES_TEXT);
2014-12-01 23:55:08 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Get the answers from the database *****/
NumAnswers = Svy_GetAnswersQst (SvyQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
for (NumAns = 0;
NumAns < NumAnswers;
NumAns++)
{
row = mysql_fetch_row (mysql_res);
if (NumAnswers > Svy_MAX_ANSWERS_PER_QUESTION)
Lay_ShowErrorAndExit ("Wrong answer.");
if (!Svy_AllocateTextChoiceAnswer (SvyQst,NumAns))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
2017-01-17 03:10:43 +01:00
Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],
Svy_MAX_BYTES_ANSWER);
2014-12-01 23:55:08 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
}
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2014-12-01 23:55:08 +01:00
if (SvyQst->QstCod > 0) // If the question already has assigned a code
{
2016-04-05 13:07:33 +02:00
/* Parameters for contextual icon */
2017-04-28 13:38:23 +02:00
Gbl.Svys.SvyCodToEdit = SvyCod;
2016-04-05 13:07:33 +02:00
Gbl.Svys.SvyQstCodToEdit = SvyQst->QstCod;
2018-10-18 02:02:32 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"%s %u",
Txt_Question,SvyQst->QstInd + 1); // Question index may be 0, 1, 2, 3,...
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Gbl.Title,Svy_PutIconToRemoveOneQst,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
}
else
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_New_question,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys_questions,Box_NOT_CLOSABLE);
2016-04-05 13:07:33 +02:00
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRcvSvyQst);
2016-04-05 13:07:33 +02:00
Svy_PutParamSvyCod (SvyCod);
if (SvyQst->QstCod > 0) // If the question already has assigned a code
Svy_PutParamQstCod (SvyQst->QstCod);
/***** Start table *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWide (2);
2014-12-01 23:55:08 +01:00
/***** Stem *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-25 22:01:43 +01:00
"<td class=\"RIGHT_TOP\">"
"<label for=\"Txt\" class=\"%s\">%s:</label>"
2014-12-25 21:50:11 +01:00
"</td>"
2015-09-02 20:23:43 +02:00
"<td class=\"LEFT_TOP\">"
2016-12-25 22:01:43 +01:00
"<textarea id=\"Txt\" name=\"Txt\""
" cols=\"60\" rows=\"4\">"
2014-12-01 23:55:08 +01:00
"%s"
"</textarea>"
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],Txt_Stem,
2014-12-01 23:55:08 +01:00
Txt);
/***** Type of answer *****/
fprintf (Gbl.F.Out,"<tr>"
2015-07-28 00:16:09 +02:00
"<td class=\"%s RIGHT_TOP\">"
2014-12-25 21:50:11 +01:00
"%s:"
2015-07-28 00:16:09 +02:00
"</td>"
"<td class=\"%s LEFT_TOP\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2015-07-28 00:16:09 +02:00
Txt_Type,
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme]);
2014-12-01 23:55:08 +01:00
for (AnsType = (Svy_AnswerType_t) 0;
AnsType < Svy_NUM_ANS_TYPES;
AnsType++)
{
2016-12-25 22:01:43 +01:00
fprintf (Gbl.F.Out,"<label>"
"<input type=\"radio\" name=\"AnswerType\""
" value=\"%u\"",
2014-12-01 23:55:08 +01:00
(unsigned) AnsType);
if (AnsType == SvyQst->AnswerType)
fprintf (Gbl.F.Out," checked=\"checked\"");
2016-12-25 22:01:43 +01:00
fprintf (Gbl.F.Out," />"
"%s"
"</label><br />",
2015-01-02 12:57:26 +01:00
Txt_SURVEY_STR_ANSWER_TYPES[AnsType]);
2014-12-01 23:55:08 +01:00
}
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Answers *****/
/* Unique or multiple choice answers */
fprintf (Gbl.F.Out,"<tr>"
2014-12-25 21:50:11 +01:00
"<td></td>"
2017-05-01 21:17:38 +02:00
"<td class=\"LEFT_TOP\">");
2017-06-11 20:09:59 +02:00
Tbl_StartTable (2);
2014-12-01 23:55:08 +01:00
for (NumAns = 0;
NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
{
/* Label with the number of the answer */
fprintf (Gbl.F.Out,"<tr>"
2016-12-25 22:01:43 +01:00
"<td class=\"RIGHT_TOP\">"
"<label for=\"AnsStr%u\" class=\"%s\">%u)</label>"
2014-12-25 21:50:11 +01:00
"</td>",
2019-02-22 21:47:50 +01:00
NumAns,The_ClassFormInBox[Gbl.Prefs.Theme],NumAns + 1);
2014-12-01 23:55:08 +01:00
/* Answer text */
2015-09-02 20:23:43 +02:00
fprintf (Gbl.F.Out,"<td class=\"RIGHT_TOP\">"
2016-12-25 22:01:43 +01:00
"<textarea id=\"AnsStr%u\" name=\"AnsStr%u\""
" cols=\"50\" rows=\"1\">",
NumAns,NumAns);
2014-12-01 23:55:08 +01:00
if (SvyQst->AnsChoice[NumAns].Text)
fprintf (Gbl.F.Out,"%s",SvyQst->AnsChoice[NumAns].Text);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
}
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2017-05-01 21:17:38 +02:00
fprintf (Gbl.F.Out,"</td>"
2015-03-24 17:47:26 +01:00
"</tr>");
2016-04-05 13:07:33 +02:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2016-04-05 13:07:33 +02:00
/***** Send button *****/
2015-03-24 17:47:26 +01:00
if (SvyQst->QstCod > 0) // If the question already has assigned a code
2019-02-18 18:27:45 +01:00
Btn_PutConfirmButton (Txt_Save_changes);
2015-03-24 17:47:26 +01:00
else
2017-06-11 19:02:40 +02:00
Btn_PutCreateButton (Txt_Create_question);
2015-03-24 17:47:26 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-04-05 13:07:33 +02:00
/***** Free memory for answers *****/
2014-12-01 23:55:08 +01:00
Svy_FreeTextChoiceAnswers (SvyQst,NumAnswers);
}
/*****************************************************************************/
/********************* Initialize a new question to zero *********************/
/*****************************************************************************/
static void Svy_InitQst (struct SurveyQuestion *SvyQst)
{
unsigned NumAns;
SvyQst->QstCod = -1L;
SvyQst->QstInd = 0;
SvyQst->AnswerType = Svy_ANS_UNIQUE_CHOICE;
for (NumAns = 0;
NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
SvyQst->AnsChoice[NumAns].Text = NULL;
}
/*****************************************************************************/
/****************** Write parameter with code of question ********************/
/*****************************************************************************/
static void Svy_PutParamQstCod (long QstCod)
{
Par_PutHiddenParamLong ("QstCod",QstCod);
}
/*****************************************************************************/
/******************* Get parameter with code of question *********************/
/*****************************************************************************/
static long Svy_GetParamQstCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of question *****/
return Par_GetParToLong ("QstCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Remove answers of a survey question *******************/
/*****************************************************************************/
static void Svy_RemAnswersOfAQuestion (long QstCod)
{
/***** Remove answers *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove the answers of a question",
"DELETE FROM svy_answers WHERE QstCod=%ld",
QstCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Convert a string with the answer type to answer type ************/
/*****************************************************************************/
static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD)
{
Svy_AnswerType_t AnsType;
for (AnsType = (Svy_AnswerType_t) 0;
AnsType < Svy_NUM_ANS_TYPES;
AnsType++)
if (!strcmp (StrAnsTypeBD,Svy_StrAnswerTypesDB[AnsType]))
return AnsType;
return (Svy_AnswerType_t) 0;
}
/*****************************************************************************/
/*********** Check if an answer of a question exists in database *************/
/*****************************************************************************/
static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
{
/***** Get answers of a question from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not check if an answer exists",
"SELECT COUNT(*) FROM svy_answers"
" WHERE QstCod=%ld AND AnsInd=%u",
QstCod,AnsInd) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get answers of a survey question from database ***************/
/*****************************************************************************/
static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
{
unsigned long NumRows;
/***** Get answers of a question from database *****/
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd,NumUsrs,Answer FROM svy_answers"
" WHERE QstCod=%ld ORDER BY AnsInd",
QstCod);
2014-12-01 23:55:08 +01:00
/***** Count number of rows of result *****/
if (NumRows == 0)
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_ERROR,"Error when getting answers of a question.");
2014-12-01 23:55:08 +01:00
return (unsigned) NumRows;
}
/*****************************************************************************/
/******************* Allocate memory for a choice answer *********************/
/*****************************************************************************/
2017-11-30 12:07:19 +01:00
static bool Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,
unsigned NumAns)
2014-12-01 23:55:08 +01:00
{
Svy_FreeTextChoiceAnswer (SvyQst,NumAns);
2018-10-08 12:37:29 +02:00
if ((SvyQst->AnsChoice[NumAns].Text = (char *) malloc (Svy_MAX_BYTES_ANSWER + 1)) == NULL)
2014-12-01 23:55:08 +01:00
{
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store answer.");
2017-07-02 19:46:53 +02:00
return false;
2014-12-01 23:55:08 +01:00
}
SvyQst->AnsChoice[NumAns].Text[0] = '\0';
2017-07-02 19:46:53 +02:00
return true;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Free memory of all choice answers **********************/
/*****************************************************************************/
static void Svy_FreeTextChoiceAnswers (struct SurveyQuestion *SvyQst,unsigned NumAnswers)
{
unsigned NumAns;
for (NumAns = 0;
NumAns < NumAnswers;
NumAns++)
Svy_FreeTextChoiceAnswer (SvyQst,NumAns);
}
/*****************************************************************************/
/********************** Free memory of a choice answer ***********************/
/*****************************************************************************/
static void Svy_FreeTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns)
{
if (SvyQst->AnsChoice[NumAns].Text)
{
free ((void *) SvyQst->AnsChoice[NumAns].Text);
SvyQst->AnsChoice[NumAns].Text = NULL;
}
}
/*****************************************************************************/
/*********************** Receive a question of a survey **********************/
/*****************************************************************************/
void Svy_ReceiveQst (void)
{
extern const char *Txt_You_must_type_the_stem_of_the_question;
extern const char *Txt_You_can_not_leave_empty_intermediate_answers;
extern const char *Txt_You_must_type_at_least_the_first_two_answers;
extern const char *Txt_The_survey_has_been_modified;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
long SvyCod;
struct SurveyQuestion SvyQst;
unsigned NumAns;
2017-01-28 15:58:46 +01:00
char AnsStr[8 + 10 + 1];
2014-12-01 23:55:08 +01:00
unsigned NumLastAns;
bool ThereIsEndOfAnswers;
bool Error = false;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
2014-12-01 23:55:08 +01:00
Svy_InitQst (&SvyQst);
/***** Get parameters from form *****/
/* Get survey code */
if ((SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/* Get question code */
SvyQst.QstCod = Svy_GetParamQstCod ();
/* Get answer type */
2017-01-29 21:41:08 +01:00
SvyQst.AnswerType = (Svy_AnswerType_t)
Par_GetParToUnsignedLong ("AnswerType",
0,
Svy_NUM_ANS_TYPES - 1,
(unsigned long) Svy_ANSWER_TYPE_DEFAULT);
2014-12-01 23:55:08 +01:00
/* Get question text */
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT);
/* Get the texts of the answers */
for (NumAns = 0;
NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
{
2017-07-02 19:46:53 +02:00
if (!Svy_AllocateTextChoiceAnswer (&SvyQst,NumAns))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2018-10-18 02:02:32 +02:00
snprintf (AnsStr,sizeof (AnsStr),
"AnsStr%u",
NumAns);
2014-12-01 23:55:08 +01:00
Par_GetParToHTML (AnsStr,SvyQst.AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER);
}
/***** Make sure that stem and answer are not empty *****/
if (Txt[0])
{
if (SvyQst.AnsChoice[0].Text[0]) // If the first answer has been filled
{
for (NumAns = 0, NumLastAns = 0, ThereIsEndOfAnswers = false;
!Error && NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
if (SvyQst.AnsChoice[NumAns].Text[0])
{
if (ThereIsEndOfAnswers)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_empty_intermediate_answers);
2014-12-01 23:55:08 +01:00
Error = true;
}
else
NumLastAns = NumAns;
}
else
ThereIsEndOfAnswers = true;
if (!Error)
{
if (NumLastAns < 1)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_the_first_two_answers);
2014-12-01 23:55:08 +01:00
Error = true;
}
}
}
else // If first answer is empty
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_the_first_two_answers);
2014-12-01 23:55:08 +01:00
Error = true;
}
}
else
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_the_stem_of_the_question);
2014-12-01 23:55:08 +01:00
Error = true;
}
if (Error)
Svy_ShowFormEditOneQst (SvyCod,&SvyQst,Txt);
else
{
/***** Form is received OK ==> insert question and answer in the database *****/
if (SvyQst.QstCod < 0) // It's a new question
{
SvyQst.QstInd = Svy_GetNextQuestionIndexInSvy (SvyCod);
/* Insert question in the table of questions */
2018-11-03 01:45:36 +01:00
SvyQst.QstCod =
DB_QueryINSERTandReturnCode ("can not create question",
"INSERT INTO svy_questions"
" (SvyCod,QstInd,AnsType,Stem)"
" VALUES"
" (%ld,%u,'%s','%s')",
SvyCod,SvyQst.QstInd,
Svy_StrAnswerTypesDB[SvyQst.AnswerType],Txt);
2014-12-01 23:55:08 +01:00
}
else // It's an existing question
/* Update question */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update question",
"UPDATE svy_questions SET Stem='%s',AnsType='%s'"
" WHERE QstCod=%ld AND SvyCod=%ld",
Txt,Svy_StrAnswerTypesDB[SvyQst.AnswerType],
SvyQst.QstCod,SvyCod);
2014-12-01 23:55:08 +01:00
/* Insert, update or delete answers in the answers table */
for (NumAns = 0;
NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
if (Svy_CheckIfAnswerExists (SvyQst.QstCod,NumAns)) // If this answer exists...
{
if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty
/* Update answer text */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update answer",
"UPDATE svy_answers SET Answer='%s'"
" WHERE QstCod=%ld AND AnsInd=%u",
SvyQst.AnsChoice[NumAns].Text,SvyQst.QstCod,NumAns);
2014-12-01 23:55:08 +01:00
else // Answer is empty
/* Delete answer from database */
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not delete answer",
"DELETE FROM svy_answers"
" WHERE QstCod=%ld AND AnsInd=%u",
SvyQst.QstCod,NumAns);
2014-12-01 23:55:08 +01:00
}
else // If this answer does not exist...
{
if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty
/* Create answer into database */
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create answer",
"INSERT INTO svy_answers"
" (QstCod,AnsInd,NumUsrs,Answer)"
" VALUES"
" (%ld,%u,0,'%s')",
SvyQst.QstCod,NumAns,SvyQst.AnsChoice[NumAns].Text);
2014-12-01 23:55:08 +01:00
}
/***** List the questions of this survey, including the new one just inserted into the database *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_survey_has_been_modified);
2014-12-01 23:55:08 +01:00
}
/***** Free answers *****/
Svy_FreeTextChoiceAnswers (&SvyQst,Svy_MAX_ANSWERS_PER_QUESTION);
/***** Show current survey *****/
Svy_ShowOneSurvey (SvyCod,&SvyQst,true);
}
/*****************************************************************************/
/******************* Get next question index in a survey *********************/
/*****************************************************************************/
static unsigned Svy_GetQstIndFromQstCod (long QstCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/
2018-11-02 01:23:05 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get question index",
"SELECT QstInd FROM svy_questions"
" WHERE QstCod=%ld",
QstCod);
2014-12-01 23:55:08 +01:00
/***** Get number of users *****/
if (NumRows)
{
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&QstInd) != 1)
Lay_ShowErrorAndExit ("Error when getting question index.");
}
else
Lay_ShowErrorAndExit ("Error when getting question index.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return QstInd;
}
/*****************************************************************************/
/******************* Get next question index in a survey *********************/
/*****************************************************************************/
static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(QstInd) FROM svy_questions WHERE SvyCod=%ld",
SvyCod);
2014-12-01 23:55:08 +01:00
/***** Get number of users *****/
row = mysql_fetch_row (mysql_res);
if (row[0]) // There are questions
{
if (sscanf (row[0],"%u",&QstInd) != 1)
Lay_ShowErrorAndExit ("Error when getting last question index.");
QstInd++;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return QstInd;
}
/*****************************************************************************/
/************************ List the questions of a survey *********************/
/*****************************************************************************/
2017-11-30 12:07:19 +01:00
static void Svy_ListSvyQuestions (struct Survey *Svy,
struct SurveyQuestion *SvyQst)
2014-12-01 23:55:08 +01:00
{
2017-05-02 16:57:49 +02:00
extern const char *Hlp_ASSESSMENT_Surveys_questions;
2015-04-12 18:01:06 +02:00
extern const char *Txt_Questions;
2014-12-01 23:55:08 +01:00
extern const char *Txt_No_INDEX;
extern const char *Txt_Type;
extern const char *Txt_Question;
2015-01-02 12:57:26 +01:00
extern const char *Txt_SURVEY_STR_ANSWER_TYPES[Svy_NUM_ANS_TYPES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_This_survey_has_no_questions;
2016-03-24 22:03:24 +01:00
extern const char *Txt_Done;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQsts;
unsigned NumQst;
2016-04-05 10:47:36 +02:00
bool Editing = (Gbl.Action.Act == ActEdiOneSvy ||
2016-01-17 15:10:54 +01:00
Gbl.Action.Act == ActEdiOneSvyQst ||
Gbl.Action.Act == ActRcvSvyQst);
2015-12-13 21:12:34 +01:00
bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing;
2014-12-01 23:55:08 +01:00
/***** Get data of questions from database *****/
2018-11-02 01:23:05 +01:00
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT QstCod,QstInd,AnsType,Stem"
" FROM svy_questions"
" WHERE SvyCod=%ld ORDER BY QstInd",
Svy->SvyCod);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2016-03-20 02:48:16 +01:00
Gbl.Svys.SvyCodToEdit = Svy->SvyCod;
2017-06-11 22:26:40 +02:00
Box_StartBox (NULL,Txt_Questions,Svy->Status.ICanEdit ? Svy_PutIconToAddNewQuestion :
NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Surveys_questions,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
if (NumQsts)
{
2016-03-20 02:48:16 +01:00
if (PutFormAnswerSurvey)
{
/***** Start form to send answers to survey *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActAnsSvy);
2016-03-20 02:48:16 +01:00
Svy_PutParamSvyCod (Svy->SvyCod);
}
2014-12-01 23:55:08 +01:00
/***** Write the heading *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin (2);
2017-05-01 12:36:24 +02:00
fprintf (Gbl.F.Out,"<tr>");
2014-12-01 23:55:08 +01:00
if (Svy->Status.ICanEdit)
2017-11-30 10:08:37 +01:00
fprintf (Gbl.F.Out,"<th></th>");
2015-09-06 20:02:14 +02:00
fprintf (Gbl.F.Out,"<th class=\"CENTER_TOP\">"
2014-12-25 21:50:11 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"CENTER_TOP\">"
2014-12-25 21:50:11 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_TOP\">"
2014-12-25 21:50:11 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_No_INDEX,
Txt_Type,
Txt_Question);
/***** Write questions one by one *****/
for (NumQst = 0;
NumQst < NumQsts;
NumQst++)
{
Gbl.RowEvenOdd = (int) (NumQst % 2);
row = mysql_fetch_row (mysql_res);
/* row[0] holds the code of the question */
if (sscanf (row[0],"%ld",&(SvyQst->QstCod)) != 1)
Lay_ShowErrorAndExit ("Wrong code of question.");
fprintf (Gbl.F.Out,"<tr>");
if (Svy->Status.ICanEdit)
{
2017-09-08 01:18:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"BT%u\">",Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
/* Write icon to remove the question */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActReqRemSvyQst);
2014-12-01 23:55:08 +01:00
Svy_PutParamSvyCod (Svy->SvyCod);
Svy_PutParamQstCod (SvyQst->QstCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
/* Write icon to edit the question */
2017-09-08 01:18:20 +02:00
Gbl.Svys.SvyCodToEdit = Svy->SvyCod;
Gbl.Svys.SvyQstCodToEdit = SvyQst->QstCod;
Ico_PutContextualIconToEdit (ActEdiOneSvyQst,Svy_PutParamsToEditQuestion);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
}
/* Write index of question inside survey (row[1]) */
if (sscanf (row[1],"%u",&(SvyQst->QstInd)) != 1)
Lay_ShowErrorAndExit ("Error: wrong question index.");
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL CENTER_TOP COLOR%u\">"
2014-12-25 21:50:11 +01:00
"%u"
"</td>",
2017-01-28 15:58:46 +01:00
Gbl.RowEvenOdd,SvyQst->QstInd + 1);
2014-12-01 23:55:08 +01:00
/* Write the question type (row[2]) */
SvyQst->AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
2015-09-03 17:14:30 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL CENTER_TOP COLOR%u\">"
2015-09-06 11:36:34 +02:00
"%s"
"</td>",
2015-09-03 17:14:30 +02:00
Gbl.RowEvenOdd,
2015-01-02 12:57:26 +01:00
Txt_SURVEY_STR_ANSWER_TYPES[SvyQst->AnswerType]);
2014-12-01 23:55:08 +01:00
2015-09-06 11:36:34 +02:00
/* Write the stem (row[3]) and the answers of this question */
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_TOP COLOR%u\">",
2015-09-06 11:36:34 +02:00
Gbl.RowEvenOdd);
Svy_WriteQstStem (row[3]);
2015-12-13 21:12:34 +01:00
Svy_WriteAnswersOfAQst (Svy,SvyQst,PutFormAnswerSurvey);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
2016-03-20 02:48:16 +01:00
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2016-03-20 02:48:16 +01:00
if (PutFormAnswerSurvey)
{
/***** Button to create/modify survey *****/
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_Done);
2016-03-20 02:48:16 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-20 02:48:16 +01:00
}
2014-12-01 23:55:08 +01:00
}
else // This survey has no questions
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_This_survey_has_no_questions);
2014-12-01 23:55:08 +01:00
2016-10-25 13:24:51 +02:00
if (Svy->Status.ICanEdit && // I can edit
(!NumQsts || // This survey has no questions
Editing)) // I am editing
2016-03-20 02:48:16 +01:00
/***** Put button to add a new question in this survey *****/
Svy_PutButtonToCreateNewQuestion ();
2015-04-11 20:18:30 +02:00
2016-10-25 13:24:51 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-03-20 02:48:16 +01:00
}
2017-09-08 01:18:20 +02:00
/*****************************************************************************/
/******************** Put parameters to edit a question **********************/
/*****************************************************************************/
static void Svy_PutParamsToEditQuestion (void)
{
Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit);
Svy_PutParamQstCod (Gbl.Svys.SvyQstCodToEdit);
}
2016-03-20 02:48:16 +01:00
/*****************************************************************************/
/***************** Put icon to add a new question to survey ******************/
/*****************************************************************************/
static void Svy_PutIconToAddNewQuestion (void)
{
extern const char *Txt_New_question;
/***** Put form to create a new question *****/
2019-01-10 15:26:33 +01:00
Ico_PutContextualIconToAdd (ActEdiOneSvyQst,NULL,Svy_PutParams,
Txt_New_question);
2016-03-20 02:48:16 +01:00
}
2015-04-11 20:18:30 +02:00
2016-03-20 02:48:16 +01:00
/*****************************************************************************/
/**************** Put button to add a new question to survey *****************/
/*****************************************************************************/
static void Svy_PutButtonToCreateNewQuestion (void)
{
extern const char *Txt_New_question;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEdiOneSvyQst);
2016-03-20 02:48:16 +01:00
Svy_PutParams ();
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_question);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Write the heading of a survey question *******************/
/*****************************************************************************/
2015-09-06 11:36:34 +02:00
static void Svy_WriteQstStem (const char *Stem)
2014-12-01 23:55:08 +01:00
{
char *HeadingRigorousHTML;
2017-01-15 22:58:26 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
/* Convert the stem, that is in HTML, to rigorous HTML */
2017-03-08 03:48:23 +01:00
Length = strlen (Stem) * Str_MAX_BYTES_PER_CHAR;
2018-10-08 12:37:29 +02:00
if ((HeadingRigorousHTML = (char *) malloc (Length + 1)) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-01-17 03:10:43 +01:00
Str_Copy (HeadingRigorousHTML,Stem,
Length);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
2017-01-15 22:58:26 +01:00
HeadingRigorousHTML,Length,false);
2014-12-01 23:55:08 +01:00
/* Write the stem */
2016-01-18 00:33:52 +01:00
fprintf (Gbl.F.Out,"%s",HeadingRigorousHTML);
2014-12-01 23:55:08 +01:00
/* Free memory allocated for the stem */
free ((void *) HeadingRigorousHTML);
}
/*****************************************************************************/
/************** Get and write the answers of a survey question ***************/
/*****************************************************************************/
2017-11-30 12:07:19 +01:00
static void Svy_WriteAnswersOfAQst (struct Survey *Svy,
struct SurveyQuestion *SvyQst,
bool PutFormAnswerSurvey)
2014-12-01 23:55:08 +01:00
{
2016-12-20 02:18:50 +01:00
unsigned NumAnswers;
unsigned NumAns;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrsThisAnswer;
2017-07-02 19:46:53 +02:00
/***** Get answers of this question *****/
2014-12-01 23:55:08 +01:00
NumAnswers = Svy_GetAnswersQst (SvyQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
/***** Write the answers *****/
2016-04-06 19:26:09 +02:00
if (NumAnswers)
2014-12-01 23:55:08 +01:00
{
2017-07-02 19:46:53 +02:00
/* Check number of answers */
if (NumAnswers > Svy_MAX_ANSWERS_PER_QUESTION)
Lay_ShowErrorAndExit ("Wrong number of answers.");
/* Write one row for each answer */
2017-06-11 20:09:59 +02:00
Tbl_StartTable (5);
2016-04-06 19:26:09 +02:00
for (NumAns = 0;
NumAns < NumAnswers;
NumAns++)
{
row = mysql_fetch_row (mysql_res);
/* Get number of users who have marked this answer (row[1]) */
if (sscanf (row[1],"%u",&NumUsrsThisAnswer) != 1)
Lay_ShowErrorAndExit ("Error when getting number of users who have marked an answer.");
/* Convert the answer (row[2]), that is in HTML, to rigorous HTML */
2017-07-02 19:46:53 +02:00
if (!Svy_AllocateTextChoiceAnswer (SvyQst,NumAns))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2017-07-02 19:46:53 +02:00
Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],
Svy_MAX_BYTES_ANSWER);
2016-04-06 19:26:09 +02:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
2017-07-02 19:46:53 +02:00
SvyQst->AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER,false);
2016-04-06 19:26:09 +02:00
/* Selectors and label with the letter of the answer */
fprintf (Gbl.F.Out,"<tr>");
if (PutFormAnswerSurvey)
{
/* Write selector to choice this answer */
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP\">"
"<input type=\"");
if (SvyQst->AnswerType == Svy_ANS_UNIQUE_CHOICE)
fprintf (Gbl.F.Out,"radio\""
" onclick=\"selectUnselectRadio(this,this.form.Ans%010u,%u)\"",
(unsigned) SvyQst->QstCod,NumAnswers);
else // SvyQst->AnswerType == Svy_ANS_MULTIPLE_CHOICE
fprintf (Gbl.F.Out,"checkbox\"");
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out," id=\"Ans%010u_%010u\" name=\"Ans%010u\""
" value=\"%u\" />"
2016-04-06 19:26:09 +02:00
"</td>",
2016-12-20 02:18:50 +01:00
(unsigned) SvyQst->QstCod,NumAns,(unsigned) SvyQst->QstCod,
NumAns);
2016-04-06 19:26:09 +02:00
}
/* Write the number of option */
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP\" style=\"width:50px;\">"
2016-12-25 22:01:43 +01:00
"<label for=\"Ans%010u_%010u\" class=\"DAT\">"
"%u)"
"</label>"
2016-04-06 19:26:09 +02:00
"</td>",
2016-12-20 02:18:50 +01:00
(unsigned) SvyQst->QstCod,NumAns,NumAns + 1);
2016-04-06 19:26:09 +02:00
/* Write the text of the answer */
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP\">"
"<label for=\"Ans%010u_%010u\" class=\"DAT\">%s</label>"
"</td>",
2017-07-02 19:46:53 +02:00
(unsigned) SvyQst->QstCod,NumAns,
SvyQst->AnsChoice[NumAns].Text);
2016-04-06 19:26:09 +02:00
/* Show stats of this answer */
if (Svy->Status.ICanViewResults)
Svy_DrawBarNumUsrs (NumUsrsThisAnswer,Svy->NumUsrs);
fprintf (Gbl.F.Out,"</tr>");
/* Free memory allocated for the answer */
2017-07-02 19:46:53 +02:00
Svy_FreeTextChoiceAnswer (SvyQst,NumAns);
2016-04-06 19:26:09 +02:00
}
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/***************** Draw a bar with the percentage of answers *****************/
/*****************************************************************************/
2015-09-28 18:28:29 +02:00
#define Svy_MAX_BAR_WIDTH 125
2014-12-01 23:55:08 +01:00
static void Svy_DrawBarNumUsrs (unsigned NumUsrs,unsigned MaxUsrs)
{
extern const char *Txt_of_PART_OF_A_TOTAL;
unsigned BarWidth = 0;
2015-07-22 18:59:44 +02:00
/***** String with the number of users *****/
if (MaxUsrs)
2018-10-18 02:02:32 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"%u&nbsp;(%u%%&nbsp;%s&nbsp;%u)",
NumUsrs,
(unsigned) ((((float) NumUsrs * 100.0) / (float) MaxUsrs) + 0.5),
Txt_of_PART_OF_A_TOTAL,MaxUsrs);
2015-07-22 18:59:44 +02:00
else
2018-10-18 02:02:32 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"0&nbsp;(0%%&nbsp;%s&nbsp;%u)",
Txt_of_PART_OF_A_TOTAL,MaxUsrs);
2015-07-22 18:59:44 +02:00
2014-12-01 23:55:08 +01:00
/***** Draw bar with a with proportional to the number of clicks *****/
2015-09-24 18:02:21 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_TOP\" style=\"width:%upx;\">",
2015-09-28 18:28:29 +02:00
Svy_MAX_BAR_WIDTH + 125);
2014-12-01 23:55:08 +01:00
if (NumUsrs && MaxUsrs)
2014-12-25 21:50:11 +01:00
BarWidth = (unsigned) ((((float) NumUsrs * (float) Svy_MAX_BAR_WIDTH) /
(float) MaxUsrs) + 0.5);
2014-12-01 23:55:08 +01:00
if (BarWidth < 2)
BarWidth = 2;
2015-07-22 18:59:44 +02:00
fprintf (Gbl.F.Out,"<img src=\"%s/c1x16.gif\""
" alt=\"%s\" title=\"%s\""
2015-09-05 11:48:44 +02:00
" class=\"LEFT_TOP\""
2015-09-28 18:28:29 +02:00
" style=\"width:%upx; height:20px;\" />"
2014-12-29 21:35:12 +01:00
"&nbsp;",
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,
2015-07-22 18:59:44 +02:00
Gbl.Title,
Gbl.Title,
BarWidth);
2014-12-01 23:55:08 +01:00
/***** Write the number of users *****/
2015-07-22 18:59:44 +02:00
fprintf (Gbl.F.Out,"%s</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
2015-07-22 18:59:44 +02:00
Gbl.Title);
2014-12-01 23:55:08 +01:00
}
2016-04-05 13:07:33 +02:00
/*****************************************************************************/
/********************* Put icon to remove one question ***********************/
/*****************************************************************************/
static void Svy_PutIconToRemoveOneQst (void)
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToRemove (ActReqRemSvyQst,Svy_PutParamsRemoveOneQst);
2016-04-05 13:07:33 +02:00
}
/*****************************************************************************/
/****************** Put parameter to remove one question *********************/
/*****************************************************************************/
static void Svy_PutParamsRemoveOneQst (void)
{
Svy_PutParamSvyCod (Gbl.Svys.SvyCodToEdit);
Svy_PutParamQstCod (Gbl.Svys.SvyQstCodToEdit);
}
2016-04-05 10:47:36 +02:00
/*****************************************************************************/
/********************** Request the removal of a question ********************/
/*****************************************************************************/
void Svy_RequestRemoveQst (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_question_X;
extern const char *Txt_Remove_question;
long SvyCod;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2016-04-05 10:47:36 +02:00
/***** Get parameters from form *****/
/* Get survey code */
if ((SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/* Get question code */
if ((SvyQst.QstCod = Svy_GetParamQstCod ()) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get question index */
SvyQst.QstInd = Svy_GetQstIndFromQstCod (SvyQst.QstCod);
2017-04-28 13:38:23 +02:00
/***** Show question and button to remove question *****/
Gbl.Svys.SvyCodToEdit = SvyCod;
Gbl.Svys.SvyQstCodToEdit = SvyQst.QstCod;
2019-02-17 01:14:55 +01:00
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,
(unsigned long) (SvyQst.QstInd + 1));
2016-04-05 10:47:36 +02:00
/***** Show current survey *****/
Svy_ShowOneSurvey (SvyCod,&SvyQst,true);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************************** Remove a question ****************************/
/*****************************************************************************/
void Svy_RemoveQst (void)
{
extern const char *Txt_Question_removed;
long SvyCod;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get survey code */
if ((SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/* Get question code */
if ((SvyQst.QstCod = Svy_GetParamQstCod ()) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get question index */
SvyQst.QstInd = Svy_GetQstIndFromQstCod (SvyQst.QstCod);
/***** Remove the question from all the tables *****/
/* Remove answers from this test question */
Svy_RemAnswersOfAQuestion (SvyQst.QstCod);
/* Remove the question itself */
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove a question",
"DELETE FROM svy_questions WHERE QstCod=%ld",
SvyQst.QstCod);
2014-12-01 23:55:08 +01:00
if (!mysql_affected_rows (&Gbl.mysql))
Lay_ShowErrorAndExit ("The question to be removed does not exist.");
/* Change index of questions greater than this */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update indexes of questions",
"UPDATE svy_questions SET QstInd=QstInd-1"
" WHERE SvyCod=%ld AND QstInd>%u",
SvyCod,SvyQst.QstInd);
2014-12-01 23:55:08 +01:00
/***** Write message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
2014-12-01 23:55:08 +01:00
/***** Show current survey *****/
Svy_ShowOneSurvey (SvyCod,&SvyQst,true);
}
/*****************************************************************************/
/************************ Receive answers of a survey ************************/
/*****************************************************************************/
void Svy_ReceiveSurveyAnswers (void)
{
extern const char *Txt_You_already_answered_this_survey_before;
extern const char *Txt_Thanks_for_answering_the_survey;
struct Survey Svy;
struct SurveyQuestion SvyQst;
2017-11-30 12:07:19 +01:00
/***** Initialize question to zero *****/
Svy_InitQst (&SvyQst);
2014-12-01 23:55:08 +01:00
/***** Get survey code *****/
if ((Svy.SvyCod = Svy_GetParamSvyCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of survey is missing.");
/***** Get data of the survey from database *****/
Svy_GetDataOfSurveyByCod (&Svy);
/***** Check if I have no answered this survey formerly *****/
if (Svy.Status.IHaveAnswered)
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_already_answered_this_survey_before);
2014-12-01 23:55:08 +01:00
else
{
/***** Receive and store user's answers *****/
Svy_ReceiveAndStoreUserAnswersToASurvey (Svy.SvyCod);
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Thanks_for_answering_the_survey);
2014-12-01 23:55:08 +01:00
}
/***** Show current survey *****/
Svy_ShowOneSurvey (Svy.SvyCod,&SvyQst,true);
}
/*****************************************************************************/
/**************** Get and store user's answers to a survey *******************/
/*****************************************************************************/
static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQst;
unsigned NumQsts;
long QstCod;
2017-01-28 15:58:46 +01:00
char ParamName[3 + 10 + 6 + 1];
char StrAnswersIndexes[Svy_MAX_ANSWERS_PER_QUESTION * (10 + 1)];
2014-12-01 23:55:08 +01:00
const char *Ptr;
2017-01-28 15:58:46 +01:00
char UnsignedStr[10 + 1];
2014-12-01 23:55:08 +01:00
unsigned AnsInd;
/***** Get questions of this survey from database *****/
2018-11-02 01:23:05 +01:00
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
" of a survey",
"SELECT QstCod FROM svy_questions"
" WHERE SvyCod=%ld ORDER BY QstCod",
SvyCod);
if (NumQsts)
2014-12-01 23:55:08 +01:00
{
2017-11-30 12:07:19 +01:00
// This survey has questions
2014-12-01 23:55:08 +01:00
/***** Get questions *****/
for (NumQst = 0;
NumQst < NumQsts;
NumQst++)
{
/* Get next answer */
row = mysql_fetch_row (mysql_res);
/* Get question code (row[0]) */
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Lay_ShowErrorAndExit ("Error: wrong question code.");
/* Get possible parameter with the user's answer */
2018-10-18 02:02:32 +02:00
snprintf (ParamName,sizeof (ParamName),
"Ans%010u",
(unsigned) QstCod);
2014-12-01 23:55:08 +01:00
// Lay_ShowAlert (Lay_INFO,ParamName);
2017-01-28 15:58:46 +01:00
Par_GetParMultiToText (ParamName,StrAnswersIndexes,
Svy_MAX_ANSWERS_PER_QUESTION * (10 + 1));
2014-12-01 23:55:08 +01:00
Ptr = StrAnswersIndexes;
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,10);
if (sscanf (UnsignedStr,"%u",&AnsInd) == 1)
2017-11-30 12:07:19 +01:00
// Parameter exists ==> user has checked this answer
// ==> store it in database
2014-12-01 23:55:08 +01:00
Svy_IncreaseAnswerInDB (QstCod,AnsInd);
}
}
}
2017-11-30 12:07:19 +01:00
else // This survey has no questions
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Error: this survey has no questions.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Register that you have answered this survey *****/
Svy_RegisterIHaveAnsweredSvy (SvyCod);
}
/*****************************************************************************/
/************ Increase number of users who have marked one answer ************/
/*****************************************************************************/
static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd)
{
/***** Increase number of users who have selected the answer AnsInd in the question QstCod *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not register your answer to the survey",
"UPDATE svy_answers SET NumUsrs=NumUsrs+1"
" WHERE QstCod=%ld AND AnsInd=%u",
QstCod,AnsInd);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Register that I have answered this survey *****************/
/*****************************************************************************/
static void Svy_RegisterIHaveAnsweredSvy (long SvyCod)
{
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not register that you have answered the survey",
"INSERT INTO svy_users"
" (SvyCod,UsrCod)"
" VALUES"
" (%ld,%ld)",
SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Register that you have answered this survey ******************/
/*****************************************************************************/
static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod)
{
/***** Get number of surveys with a field value from database *****/
2018-11-03 22:08:45 +01:00
return (DB_QueryCOUNT ("can not check if you have answered a survey",
"SELECT COUNT(*) FROM svy_users"
" WHERE SvyCod=%ld AND UsrCod=%ld",
SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Register that you have answered this survey *****************/
/*****************************************************************************/
static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
{
/***** Get number of surveys with a field value from database *****/
2018-11-03 22:08:45 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of users"
" who have answered a survey",
"SELECT COUNT(*) FROM svy_users"
" WHERE SvyCod=%ld",
SvyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get number of courses with surveys *********************/
/*****************************************************************************/
// Returns the number of courses with surveys for courses
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
unsigned Svy_GetNumCoursesWithCrsSurveys (Hie_Level_t Scope)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with surveys from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT Cod)"
" FROM surveys"
" WHERE Scope='%s'",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM institutions,centres,degrees,courses,surveys"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
2015-03-09 00:40:29 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM centres,degrees,courses,surveys"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM degrees,courses,surveys"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM courses,surveys"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT Cod)"
" FROM surveys"
" WHERE Scope='%s' AND Cod=%ld",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS),
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with surveys.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}
/*****************************************************************************/
2016-10-27 15:06:11 +02:00
/******************** Get number of surveys for courses **********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
// Returns the number of surveys for courses
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
unsigned Svy_GetNumCrsSurveys (Hie_Level_t Scope,unsigned *NumNotif)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumSurveys;
/***** Get number of surveys from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys"
" WHERE Scope='%s'",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM institutions,centres,degrees,courses,surveys"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_CRS));
2015-03-09 00:45:35 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM centres,degrees,courses,surveys"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM degrees,courses,surveys"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM courses,surveys"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys"
" WHERE surveys.Scope='%s'"
" AND CrsCod=%ld",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS),
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumSurveys) != 1)
Lay_ShowErrorAndExit ("Error when getting number of surveys.");
2016-11-16 23:19:52 +01:00
/***** Get number of notifications by email *****/
2014-12-01 23:55:08 +01:00
if (row[1])
{
if (sscanf (row[1],"%u",NumNotif) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notifications of surveys.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumSurveys;
}
/*****************************************************************************/
2016-10-27 15:06:11 +02:00
/************ Get average number of questions per course survey **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-04-03 20:57:04 +02:00
float Svy_GetNumQstsPerCrsSurvey (Hie_Level_t Scope)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
float NumQstsPerSurvey;
2016-10-27 15:06:11 +02:00
/***** Get number of questions per survey from database *****/
2014-12-01 23:55:08 +01:00
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions"
" WHERE surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-03 20:57:04 +02:00
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM institutions,centres,degrees,courses,surveys,svy_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_CRS));
2015-03-09 00:45:35 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM centres,degrees,courses,surveys,svy_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM degrees,courses,surveys,svy_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM courses,surveys,svy_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-11-02 01:23:05 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
2019-04-04 10:45:15 +02:00
Sco_GetDBStrFromScope (Hie_CRS),Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);
NumQstsPerSurvey = Str_GetFloatNumFromStr (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumQstsPerSurvey;
}