2021-10-26 09:23:06 +02:00
|
|
|
|
// swad_test_visibility.c: visibility of test prints
|
2020-02-18 09:19:33 +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.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2020-02-18 09:19:33 +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 *********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
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
|
|
|
|
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.h"
|
2021-12-15 00:47:29 +01:00
|
|
|
|
#include "swad_global.h"
|
2023-06-06 22:18:31 +02:00
|
|
|
|
#include "swad_hidden_visible.h"
|
2020-02-18 09:19:33 +01:00
|
|
|
|
#include "swad_HTML.h"
|
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_test_visibility.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2020-02-19 01:55:32 +01:00
|
|
|
|
/******************************* Show visibility *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-06-06 15:16:57 +02:00
|
|
|
|
void TstVis_ShowVisibilityIcons (unsigned SelectedVisibility,
|
2023-06-06 22:18:31 +02:00
|
|
|
|
HidVis_HiddenOrVisible_t HiddenOrVisible)
|
2020-02-19 01:55:32 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
extern const char *Txt_TST_STR_VISIBILITY[TstVis_NUM_ITEMS_VISIBILITY];
|
2023-06-07 00:51:41 +02:00
|
|
|
|
extern const char *Txt_TST_HIDDEN_VISIBLE[HidVis_NUM_HIDDEN_VISIBLE];
|
2021-12-22 00:20:06 +01:00
|
|
|
|
static const char *Icons[TstVis_NUM_ITEMS_VISIBILITY] =
|
2020-02-19 09:40:28 +01:00
|
|
|
|
{
|
2021-12-22 00:20:06 +01:00
|
|
|
|
[TstVis_VISIBLE_QST_ANS_TXT ] = "file-alt.svg",
|
|
|
|
|
[TstVis_VISIBLE_FEEDBACK_TXT ] = "file-signature.svg",
|
|
|
|
|
[TstVis_VISIBLE_CORRECT_ANSWER] = "spell-check.svg",
|
|
|
|
|
[TstVis_VISIBLE_EACH_QST_SCORE] = "tasks.svg",
|
|
|
|
|
[TstVis_VISIBLE_TOTAL_SCORE ] = "check-circle-regular.svg",
|
2020-02-19 09:40:28 +01:00
|
|
|
|
};
|
2023-06-07 00:51:41 +02:00
|
|
|
|
static Ico_Color_t Color[HidVis_NUM_HIDDEN_VISIBLE] =
|
|
|
|
|
{
|
|
|
|
|
[HidVis_HIDDEN ] = Ico_RED,
|
|
|
|
|
[HidVis_VISIBLE] = Ico_GREEN,
|
|
|
|
|
};
|
2023-10-02 10:48:33 +02:00
|
|
|
|
static void (*Ico_PutIcon[HidVis_NUM_HIDDEN_VISIBLE]) (const char *Icon,
|
|
|
|
|
Ico_Color_t Color,
|
|
|
|
|
const char *Title) =
|
2023-06-07 01:12:21 +02:00
|
|
|
|
{
|
2023-10-02 10:48:33 +02:00
|
|
|
|
[HidVis_HIDDEN ] = Ico_PutIconOff,
|
|
|
|
|
[HidVis_VISIBLE] = Ico_PutIconOn,
|
2023-06-07 01:12:21 +02:00
|
|
|
|
};
|
2020-04-02 03:28:08 +02:00
|
|
|
|
TstVis_Visibility_t Visibility;
|
2023-06-07 00:51:41 +02:00
|
|
|
|
HidVis_HiddenOrVisible_t ItemHiddenOrVisible;
|
2020-02-19 01:55:32 +01:00
|
|
|
|
char *Title;
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
for (Visibility = (TstVis_Visibility_t) 0;
|
|
|
|
|
Visibility <= (TstVis_Visibility_t) (TstVis_NUM_ITEMS_VISIBILITY - 1);
|
2020-02-19 01:55:32 +01:00
|
|
|
|
Visibility++)
|
|
|
|
|
{
|
2023-06-07 00:51:41 +02:00
|
|
|
|
ItemHiddenOrVisible = ((SelectedVisibility & (1 << Visibility)) != 0) ? HidVis_VISIBLE :
|
|
|
|
|
HidVis_HIDDEN;
|
2020-02-19 01:55:32 +01:00
|
|
|
|
if (asprintf (&Title,"%s: %s",
|
|
|
|
|
Txt_TST_STR_VISIBILITY[Visibility],
|
2023-06-07 00:51:41 +02:00
|
|
|
|
Txt_TST_HIDDEN_VISIBLE[ItemHiddenOrVisible]) < 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2023-06-07 00:51:41 +02:00
|
|
|
|
Ico_PutIcon[HiddenOrVisible] (Icons[Visibility],Color[ItemHiddenOrVisible],Title);
|
2020-02-19 01:55:32 +01:00
|
|
|
|
free (Title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 15:40:04 +01:00
|
|
|
|
/*****************************************************************************/
|
2020-04-02 03:28:08 +02:00
|
|
|
|
/************* Put checkboxes in form to select exam visibility **************/
|
2020-02-18 15:40:04 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
void TstVis_PutVisibilityCheckboxes (unsigned SelectedVisibility)
|
2020-02-18 15:40:04 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
extern const char *Txt_TST_STR_VISIBILITY[TstVis_NUM_ITEMS_VISIBILITY];
|
|
|
|
|
static const char *Icons[TstVis_NUM_ITEMS_VISIBILITY] =
|
2020-02-19 09:40:28 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
[TstVis_VISIBLE_QST_ANS_TXT ] = "file-alt.svg",
|
|
|
|
|
[TstVis_VISIBLE_FEEDBACK_TXT ] = "file-signature.svg",
|
|
|
|
|
[TstVis_VISIBLE_CORRECT_ANSWER] = "spell-check.svg",
|
|
|
|
|
[TstVis_VISIBLE_EACH_QST_SCORE] = "tasks.svg",
|
|
|
|
|
[TstVis_VISIBLE_TOTAL_SCORE ] = "check-circle-regular.svg",
|
2020-02-19 09:40:28 +01:00
|
|
|
|
};
|
2020-04-02 03:28:08 +02:00
|
|
|
|
TstVis_Visibility_t Visibility;
|
2024-04-30 11:00:46 +02:00
|
|
|
|
Cns_Checked_t Checked;
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
2021-03-02 12:12:00 +01:00
|
|
|
|
/***** Write list of checkboxes for visibility *****/
|
2020-04-02 03:28:08 +02:00
|
|
|
|
for (Visibility = (TstVis_Visibility_t) 0;
|
|
|
|
|
Visibility <= (TstVis_Visibility_t) (TstVis_NUM_ITEMS_VISIBILITY - 1);
|
2020-02-18 15:40:04 +01:00
|
|
|
|
Visibility++)
|
|
|
|
|
{
|
2021-03-02 12:12:00 +01:00
|
|
|
|
/* Begin label */
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_LABEL_Begin ("class=\"DAT_%s\"",The_GetSuffix ());
|
2021-03-02 12:12:00 +01:00
|
|
|
|
|
|
|
|
|
/* Checkbox with icon and text */
|
2024-04-30 11:00:46 +02:00
|
|
|
|
Checked = ((SelectedVisibility & (1 << Visibility)) != 0) ? Cns_CHECKED :
|
|
|
|
|
Cns_UNCHECKED;
|
2024-05-09 19:11:16 +02:00
|
|
|
|
HTM_INPUT_CHECKBOX ("Visibility",Checked,HTM_ENABLED,
|
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2024-04-30 11:00:46 +02:00
|
|
|
|
"value=\"%u\"",(unsigned) Visibility);
|
2021-12-22 00:20:06 +01:00
|
|
|
|
Ico_PutIconOn (Icons[Visibility],Ico_BLACK,
|
|
|
|
|
Txt_TST_STR_VISIBILITY[Visibility]);
|
2021-03-02 12:12:00 +01:00
|
|
|
|
HTM_Txt (Txt_TST_STR_VISIBILITY[Visibility]);
|
|
|
|
|
|
|
|
|
|
/* End label */
|
2020-02-18 15:40:04 +01:00
|
|
|
|
HTM_LABEL_End ();
|
|
|
|
|
HTM_BR ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get visibility from form *************************/
|
2020-02-18 09:19:33 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
unsigned TstVis_GetVisibilityFromForm (void)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
|
|
|
|
size_t MaxSizeListVisibilitySelected;
|
|
|
|
|
char *StrVisibilitySelected;
|
|
|
|
|
const char *Ptr;
|
|
|
|
|
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
|
|
|
|
unsigned UnsignedNum;
|
2020-04-02 03:28:08 +02:00
|
|
|
|
TstVis_Visibility_t VisibilityItem;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
unsigned Visibility = 0; // Nothing selected
|
|
|
|
|
|
|
|
|
|
/***** Allocate memory for list of attendance events selected *****/
|
2020-04-02 03:28:08 +02:00
|
|
|
|
MaxSizeListVisibilitySelected = TstVis_NUM_ITEMS_VISIBILITY * (Cns_MAX_DECIMAL_DIGITS_UINT + 1);
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((StrVisibilitySelected = malloc (MaxSizeListVisibilitySelected + 1)) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2020-02-18 09:19:33 +01:00
|
|
|
|
|
|
|
|
|
/***** 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 */
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Par_GetNextStrUntilSeparParMult (&Ptr,UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
|
2020-02-18 09:19:33 +01:00
|
|
|
|
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
|
2020-04-02 03:28:08 +02:00
|
|
|
|
if (UnsignedNum < TstVis_NUM_ITEMS_VISIBILITY)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
VisibilityItem = (TstVis_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-04-02 03:28:08 +02:00
|
|
|
|
unsigned TstVis_GetVisibilityFromStr (const char *Str)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-02-18 15:40:04 +01:00
|
|
|
|
unsigned UnsignedNum;
|
2020-04-02 03:28:08 +02:00
|
|
|
|
unsigned Visibility = TstVis_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)
|
2020-04-02 03:28:08 +02:00
|
|
|
|
Visibility = UnsignedNum & TstVis_MAX_VISIBILITY;
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
|
|
|
|
return Visibility;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Get visibility items **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
bool TstVis_IsVisibleQstAndAnsTxt (unsigned Visibility)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
return (Visibility & (1 << TstVis_VISIBLE_QST_ANS_TXT)) != 0;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
bool TstVis_IsVisibleFeedbackTxt (unsigned Visibility)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
return (Visibility & (1 << TstVis_VISIBLE_FEEDBACK_TXT)) != 0;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
bool TstVis_IsVisibleCorrectAns (unsigned Visibility)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
return (Visibility & (1 << TstVis_VISIBLE_CORRECT_ANSWER)) != 0;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
bool TstVis_IsVisibleEachQstScore (unsigned Visibility)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
return (Visibility & (1 << TstVis_VISIBLE_EACH_QST_SCORE)) != 0;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 03:28:08 +02:00
|
|
|
|
bool TstVis_IsVisibleTotalScore (unsigned Visibility)
|
2020-02-18 09:19:33 +01:00
|
|
|
|
{
|
2020-04-02 03:28:08 +02:00
|
|
|
|
return (Visibility & (1 << TstVis_VISIBLE_TOTAL_SCORE)) != 0;
|
2020-02-18 09:19:33 +01:00
|
|
|
|
}
|