swad-core/swad_test_visibility.c

231 lines
9.0 KiB
C
Raw Normal View History

2020-02-18 09:19:33 +01:00
// swad_test_visibility.c: visibility of test results
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2020 Antonio Ca<EFBFBD>as Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
2020-02-19 01:55:32 +01:00
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf
2020-02-19 21:54:23 +01:00
#include <stdlib.h> // For malloc, free
2020-02-19 01:55:32 +01:00
2020-02-18 09:19:33 +01:00
#include "swad_HTML.h"
#include "swad_parameter.h"
#include "swad_test_visibility.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Private constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Private global variables **************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
2020-02-19 01:55:32 +01:00
/******************************* Show visibility *****************************/
/*****************************************************************************/
2020-02-19 09:40:28 +01:00
void TsV_ShowVisibilityIcons (unsigned SelectedVisibility,bool Hidden)
2020-02-19 01:55:32 +01:00
{
extern const char *Txt_TST_STR_VISIBILITY[TsV_NUM_ITEMS_VISIBILITY];
2020-02-19 08:42:10 +01:00
extern const char *Txt_TST_HIDDEN_VISIBLE[2];
2020-02-19 09:40:28 +01:00
static const char *Icons[TsV_NUM_ITEMS_VISIBILITY][2] =
{
[TsV_VISIBLE_QST_ANS_TXT ][false] = "file-alt-red.svg",
[TsV_VISIBLE_QST_ANS_TXT ][true ] = "file-alt-green.svg",
[TsV_VISIBLE_FEEDBACK_TXT ][false] = "file-signature-red.svg",
[TsV_VISIBLE_FEEDBACK_TXT ][true ] = "file-signature-green.svg",
[TsV_VISIBLE_CORRECT_ANSWER][false] = "spell-check-red.svg",
[TsV_VISIBLE_CORRECT_ANSWER][true ] = "spell-check-green.svg",
[TsV_VISIBLE_EACH_QST_SCORE][false] = "tasks-red.svg",
[TsV_VISIBLE_EACH_QST_SCORE][true ] = "tasks-green.svg",
[TsV_VISIBLE_TOTAL_SCORE ][false] = "check-circle-regular-red.svg",
[TsV_VISIBLE_TOTAL_SCORE ][true ] = "check-circle-regular-green.svg",
};
2020-02-19 01:55:32 +01:00
TsV_Visibility_t Visibility;
2020-02-19 09:40:28 +01:00
bool ItemVisible;
2020-02-19 01:55:32 +01:00
char *Title;
for (Visibility = (TsV_Visibility_t) 0;
Visibility <= (TsV_Visibility_t) (TsV_NUM_ITEMS_VISIBILITY - 1);
Visibility++)
{
2020-02-19 09:40:28 +01:00
ItemVisible = (SelectedVisibility & (1 << Visibility)) != 0;
2020-02-19 01:55:32 +01:00
if (asprintf (&Title,"%s: %s",
Txt_TST_STR_VISIBILITY[Visibility],
2020-02-19 08:42:10 +01:00
Txt_TST_HIDDEN_VISIBLE[ItemVisible]) < 0)
2020-02-19 01:55:32 +01:00
Lay_NotEnoughMemoryExit ();
2020-02-19 09:40:28 +01:00
if (ItemVisible && !Hidden)
Ico_PutIconOn (Icons[Visibility][ItemVisible],Title);
else
Ico_PutIconOff (Icons[Visibility][ItemVisible],Title);
2020-02-19 01:55:32 +01:00
free (Title);
}
}
2020-02-18 15:40:04 +01:00
/*****************************************************************************/
/************ Put checkboxes in form to select result visibility *************/
/*****************************************************************************/
void TsV_PutVisibilityCheckboxes (unsigned SelectedVisibility)
{
extern const char *Txt_TST_STR_VISIBILITY[TsV_NUM_ITEMS_VISIBILITY];
2020-02-19 09:40:28 +01:00
static const char *Icons[TsV_NUM_ITEMS_VISIBILITY] =
{
[TsV_VISIBLE_QST_ANS_TXT ] = "file-alt.svg",
[TsV_VISIBLE_FEEDBACK_TXT ] = "file-signature.svg",
[TsV_VISIBLE_CORRECT_ANSWER] = "spell-check.svg",
[TsV_VISIBLE_EACH_QST_SCORE] = "tasks.svg",
[TsV_VISIBLE_TOTAL_SCORE ] = "check-circle-regular.svg",
};
2020-02-18 15:40:04 +01:00
TsV_Visibility_t Visibility;
2020-02-19 09:40:28 +01:00
bool ItemVisible;
2020-02-18 15:40:04 +01:00
for (Visibility = (TsV_Visibility_t) 0;
Visibility <= (TsV_Visibility_t) (TsV_NUM_ITEMS_VISIBILITY - 1);
Visibility++)
{
2020-02-19 09:40:28 +01:00
ItemVisible = (SelectedVisibility & (1 << Visibility)) != 0;
2020-02-18 15:40:04 +01:00
HTM_LABEL_Begin ("class=\"DAT\"");
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("Visibility",HTM_DONT_SUBMIT_ON_CHANGE,
2020-02-18 15:40:04 +01:00
"value=\"%u\"%s",
(unsigned) Visibility,
2020-02-19 09:40:28 +01:00
ItemVisible ? " checked=\"checked\"" :
"");
Ico_PutIconOn (Icons[Visibility],Txt_TST_STR_VISIBILITY[Visibility]);
2020-02-18 15:40:04 +01:00
HTM_Txt (Txt_TST_STR_VISIBILITY[Visibility]);
HTM_LABEL_End ();
HTM_BR ();
}
}
/*****************************************************************************/
/************************** Get visibility from form *************************/
2020-02-18 09:19:33 +01:00
/*****************************************************************************/
unsigned TsV_GetVisibilityFromForm (void)
{
size_t MaxSizeListVisibilitySelected;
char *StrVisibilitySelected;
const char *Ptr;
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
unsigned UnsignedNum;
2020-02-18 15:40:04 +01:00
TsV_Visibility_t VisibilityItem;
2020-02-18 09:19:33 +01:00
unsigned Visibility = 0; // Nothing selected
/***** Allocate memory for list of attendance events selected *****/
MaxSizeListVisibilitySelected = TsV_NUM_ITEMS_VISIBILITY * (Cns_MAX_DECIMAL_DIGITS_UINT + 1);
if ((StrVisibilitySelected = (char *) malloc (MaxSizeListVisibilitySelected + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of visibility items selected *****/
Par_GetParMultiToText ("Visibility",StrVisibilitySelected,MaxSizeListVisibilitySelected);
/***** Set which attendance events will be shown as selected (checkboxes on) *****/
if (StrVisibilitySelected[0]) // There are events selected
for (Ptr = StrVisibilitySelected;
*Ptr;
)
{
/* Get next visibility item selected */
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
if (UnsignedNum < TsV_NUM_ITEMS_VISIBILITY)
{
2020-02-18 15:40:04 +01:00
VisibilityItem = (TsV_Visibility_t) UnsignedNum;
2020-02-18 09:19:33 +01:00
Visibility |= (1 << VisibilityItem);
}
}
return Visibility;
}
/*****************************************************************************/
2020-02-18 15:40:04 +01:00
/************************** Get visibility from string *************************/
2020-02-18 09:19:33 +01:00
/*****************************************************************************/
2020-02-18 15:40:04 +01:00
unsigned TsV_GetVisibilityFromStr (const char *Str)
2020-02-18 09:19:33 +01:00
{
2020-02-18 15:40:04 +01:00
unsigned UnsignedNum;
unsigned Visibility = TsV_MIN_VISIBILITY; // In nothing is read, return minimum visibility
2020-02-18 09:19:33 +01:00
2020-02-18 15:40:04 +01:00
/***** Get visibility from string *****/
if (Str)
if (Str[0])
if (sscanf (Str,"%u",&UnsignedNum) == 1)
Visibility = UnsignedNum & TsV_MAX_VISIBILITY;
return Visibility;
2020-02-18 09:19:33 +01:00
}
/*****************************************************************************/
/***************************** Get visibility items **************************/
/*****************************************************************************/
bool TsV_IsVisibleQstAndAnsTxt (unsigned Visibility)
{
return (Visibility & (1 << TsV_VISIBLE_QST_ANS_TXT)) != 0;
}
bool TsV_IsVisibleFeedbackTxt (unsigned Visibility)
{
return (Visibility & (1 << TsV_VISIBLE_FEEDBACK_TXT)) != 0;
}
bool TsV_IsVisibleCorrectAns (unsigned Visibility)
{
return (Visibility & (1 << TsV_VISIBLE_CORRECT_ANSWER)) != 0;
}
bool TsV_IsVisibleEachQstScore (unsigned Visibility)
{
return (Visibility & (1 << TsV_VISIBLE_EACH_QST_SCORE)) != 0;
}
bool TsV_IsVisibleTotalScore (unsigned Visibility)
{
return (Visibility & (1 << TsV_VISIBLE_TOTAL_SCORE)) != 0;
}