swad-core/swad_assignment.c

2010 lines
70 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_assignment.c: assignments
/*
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.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 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-11-01 22:53:39 +01:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/limits.h> // For PATH_MAX
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2019-11-01 22:53:39 +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
#include "swad_assignment.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2019-02-12 14:46:14 +01:00
#include "swad_figure.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"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
2019-09-28 15:03:22 +02: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_string.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
struct Asg_Assignments
{
bool LstIsRead; // Is the list already read from database...
// ...or it needs to be read?
unsigned Num; // Number of assignments
long *LstAsgCods; // List of assigment codes
Dat_StartEndTime_t SelectedOrder;
long AsgCodToEdit; // Used as parameter in contextual links
unsigned CurrentPage;
};
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_ResetAssignments (struct Asg_Assignments *Assignments);
static void Asg_ShowAllAssignments (struct Asg_Assignments *Assignments);
static void Asg_PutHeadForSeeing (struct Asg_Assignments *Assignments,
bool PrintView);
2016-11-07 01:44:50 +01:00
static bool Asg_CheckIfICanCreateAssignments (void);
2020-03-26 02:54:30 +01:00
static void Asg_PutIconsListAssignments (void *Args);
static void Asg_PutIconToCreateNewAsg (void *Assignments);
static void Asg_PutButtonToCreateNewAsg (void *Assignments);
static void Asg_ParamsWhichGroupsToShow (void *Args);
2017-05-02 10:24:47 +02:00
static void Asg_ShowOneAssignment (long AsgCod,bool PrintView);
2014-12-01 23:55:08 +01:00
static void Asg_WriteAsgAuthor (struct Assignment *Asg);
2017-05-02 10:24:47 +02:00
static void Asg_WriteAssignmentFolder (struct Assignment *Asg,bool PrintView);
2020-04-05 22:53:58 +02:00
static Dat_StartEndTime_t Asg_GetParamAsgOrder (void);
2015-04-02 18:39:49 +02:00
2019-04-20 22:06:18 +02:00
static void Asg_PutFormsToRemEditOneAsg (const struct Assignment *Asg,
const char *Anchor);
2020-03-26 02:54:30 +01:00
static void Asg_PutParams (void *Assignments);
2020-04-05 22:53:58 +02:00
static void Asg_GetListAssignments (struct Asg_Assignments *Assignments);
2018-10-30 09:02:14 +01:00
static void Asg_GetDataOfAssignment (struct Assignment *Asg,
MYSQL_RES **mysql_res,
unsigned long NumRows);
2016-12-28 17:45:53 +01:00
static void Asg_ResetAssignment (struct Assignment *Asg);
2020-04-05 22:53:58 +02:00
static void Asg_FreeListAssignments (struct Asg_Assignments *Assignments);
2017-01-13 01:51:23 +01:00
static void Asg_GetAssignmentTxtFromDB (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
2014-12-01 23:55:08 +01:00
static void Asg_PutParamAsgCod (long AsgCod);
static bool Asg_CheckIfSimilarAssignmentExists (const char *Field,const char *Value,long AsgCod);
static void Asg_ShowLstGrpsToEditAssignment (long AsgCod);
static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail);
static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt);
static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt);
static bool Asg_CheckIfAsgIsAssociatedToGrps (long AsgCod);
static void Asg_RemoveAllTheGrpsAssociatedToAnAssignment (long AsgCod);
static void Asg_CreateGrps (long AsgCod);
static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Assignment *Asg);
2015-11-10 02:23:55 +01:00
static bool Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (long AsgCod);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/*****************************************************************************/
/*************************** Reset assignments *******************************/
/*****************************************************************************/
static void Asg_ResetAssignments (struct Asg_Assignments *Assignments)
{
Assignments->LstIsRead = false; // List is not read
Assignments->Num = 0;
Assignments->LstAsgCods = NULL;
Assignments->SelectedOrder = Asg_ORDER_DEFAULT;
Assignments->AsgCodToEdit = -1L; // Used as parameter in contextual links
Assignments->CurrentPage = 0;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ List all the assignments ***************************/
/*****************************************************************************/
void Asg_SeeAssignments (void)
{
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2020-04-05 22:53:58 +02:00
Assignments.SelectedOrder = Asg_GetParamAsgOrder ();
Gbl.Crs.Grps.WhichGrps = Grp_GetParamWhichGroups ();
Assignments.CurrentPage = Pag_GetParamPagNum (Pag_ASSIGNMENTS);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Show all assignments *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Show all the assignments ***************************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_ShowAllAssignments (struct Asg_Assignments *Assignments)
2014-12-01 23:55:08 +01:00
{
2016-11-27 21:41:17 +01:00
extern const char *Hlp_ASSESSMENT_Assignments;
2015-01-02 12:57:26 +01:00
extern const char *Txt_Assignments;
2016-03-19 19:22:13 +01:00
extern const char *Txt_No_assignments;
2014-12-01 23:55:08 +01:00
struct Pagination Pagination;
unsigned NumAsg;
2016-03-19 19:34:22 +01:00
/***** Get list of assignments *****/
2020-04-05 22:53:58 +02:00
Asg_GetListAssignments (Assignments);
2016-03-19 19:34:22 +01:00
2015-01-02 12:57:26 +01:00
/***** Compute variables related to pagination *****/
2020-04-05 22:53:58 +02:00
Pagination.NumItems = Assignments->Num;
Pagination.CurrentPage = (int) Assignments->CurrentPage;
2015-01-02 12:57:26 +01:00
Pag_CalculatePagination (&Pagination);
2020-04-05 22:53:58 +02:00
Assignments->CurrentPage = (unsigned) Pagination.CurrentPage;
2015-01-02 12:57:26 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin ("100%",Txt_Assignments,
2020-04-05 22:53:58 +02:00
Asg_PutIconsListAssignments,Assignments,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Assignments,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 ();
2020-03-26 02:54:30 +01:00
Grp_ShowFormToSelWhichGrps (ActSeeAsg,
2020-04-05 22:53:58 +02:00
Asg_ParamsWhichGroupsToShow,Assignments);
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
2019-12-06 22:18:05 +01:00
/***** Write links to pages *****/
2019-12-11 00:13:09 +01:00
Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,
&Pagination,
2020-04-05 22:53:58 +02:00
(unsigned) Assignments->SelectedOrder,
2020-04-07 03:01:41 +02:00
NULL,0);
2019-12-06 22:18:05 +01:00
2020-04-05 22:53:58 +02:00
if (Assignments->Num)
2014-12-01 23:55:08 +01:00
{
2016-03-19 19:22:13 +01:00
/***** Table head *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
2020-04-05 22:53:58 +02:00
Asg_PutHeadForSeeing (Assignments,false); // Not print view
2016-03-19 19:22:13 +01:00
/***** Write all the assignments *****/
for (NumAsg = Pagination.FirstItemVisible;
NumAsg <= Pagination.LastItemVisible;
NumAsg++)
2020-04-05 22:53:58 +02:00
Asg_ShowOneAssignment (Assignments->LstAsgCods[NumAsg - 1],
2017-05-02 10:24:47 +02:00
false); // Not print view
2016-03-19 19:22:13 +01:00
2016-03-20 13:47:46 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
2016-03-19 19:22:13 +01:00
else // No assignments created
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_assignments);
2016-03-19 19:22:13 +01:00
2019-12-06 22:18:05 +01:00
/***** Write again links to pages *****/
2019-12-11 00:13:09 +01:00
Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,
&Pagination,
2020-04-05 22:53:58 +02:00
(unsigned) Assignments->SelectedOrder,
2020-04-07 03:01:41 +02:00
NULL,0);
2019-12-06 22:18:05 +01:00
2016-03-19 19:22:13 +01:00
/***** Button to create a new assignment *****/
2016-11-07 01:44:50 +01:00
if (Asg_CheckIfICanCreateAssignments ())
2020-04-05 22:53:58 +02:00
Asg_PutButtonToCreateNewAsg (Assignments);
2016-03-19 19:22:13 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2015-01-02 12:57:26 +01:00
2014-12-01 23:55:08 +01:00
/***** Free list of assignments *****/
2020-04-05 22:53:58 +02:00
Asg_FreeListAssignments (Assignments);
2014-12-01 23:55:08 +01:00
}
2017-05-02 10:24:47 +02:00
/*****************************************************************************/
/***************** Write header with fields of an assignment *****************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_PutHeadForSeeing (struct Asg_Assignments *Assignments,
bool PrintView)
2017-05-02 10:24:47 +02: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];
extern const char *Txt_Assignment;
extern const char *Txt_Folder;
Dat_StartEndTime_t Order;
2020-03-27 14:56:54 +01:00
Grp_WhichGroups_t WhichGroups;
2017-05-02 10:24:47 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"CONTEXT_COL",NULL); // Column for contextual icons
2020-03-30 13:21:11 +02:00
for (Order = Dat_START_TIME;
2017-05-02 10:24:47 +02:00
Order <= Dat_END_TIME;
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,"LM");
2017-05-02 13:02:43 +02:00
if (!PrintView)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeAsg);
2020-03-27 14:56:54 +01:00
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
2020-04-05 22:53:58 +02:00
Pag_PutHiddenParamPagNum (Pag_ASSIGNMENTS,Assignments->CurrentPage);
Dat_PutHiddenParamOrder (Order);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_START_END_TIME_HELP[Order],"BT_LINK TIT_TBL",NULL);
2020-04-05 22:53:58 +02:00
if (Order == Assignments->SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2017-05-02 13:02:43 +02:00
}
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_START_END_TIME[Order]);
2017-05-02 13:02:43 +02:00
if (!PrintView)
{
2020-04-05 22:53:58 +02:00
if (Order == Assignments->SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 09:35:23 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-05-02 13:02:43 +02:00
}
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2017-05-02 10:24:47 +02:00
}
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_Assignment);
HTM_TH (1,1,"LM",Txt_Folder);
2019-10-12 19:10:32 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-05-02 10:24:47 +02:00
}
2016-11-07 01:44:50 +01:00
/*****************************************************************************/
/******************** Check if I can create assignments **********************/
/*****************************************************************************/
static bool Asg_CheckIfICanCreateAssignments (void)
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
2016-11-07 01:44:50 +01:00
}
/*****************************************************************************/
/*************** Put contextual icons in list of assignments *****************/
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void Asg_PutIconsListAssignments (void *Assignments)
2016-11-07 01:44:50 +01:00
{
/***** Put icon to create a new assignment *****/
2020-03-26 02:54:30 +01:00
if (Assignments)
if (Asg_CheckIfICanCreateAssignments ())
Asg_PutIconToCreateNewAsg (Assignments);
2016-11-07 01:44:50 +01:00
/***** Put icon to show a figure *****/
2020-04-06 23:18:02 +02:00
Fig_PutIconToShowFigure (Fig_ASSIGNMENTS);
2016-11-07 01:44:50 +01:00
}
2016-03-19 19:22:13 +01:00
/*****************************************************************************/
/******************* Put icon to create a new assignment *********************/
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void Asg_PutIconToCreateNewAsg (void *Assignments)
2016-03-19 19:22:13 +01:00
{
extern const char *Txt_New_assignment;
2020-03-26 02:54:30 +01:00
if (Assignments)
{
/***** Put form to create a new assignment *****/
((struct Asg_Assignments *) Assignments)->AsgCodToEdit = -1L;
Ico_PutContextualIconToAdd (ActFrmNewAsg,NULL,
Asg_PutParams,Assignments,
Txt_New_assignment);
}
2016-03-19 19:22:13 +01:00
}
/*****************************************************************************/
2016-06-01 13:43:22 +02:00
/****************** Put button to create a new assignment ********************/
2016-03-19 19:22:13 +01:00
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void Asg_PutButtonToCreateNewAsg (void *Assignments)
2016-03-19 19:22:13 +01:00
{
extern const char *Txt_New_assignment;
2020-03-26 02:54:30 +01:00
if (Assignments)
{
((struct Asg_Assignments *) Assignments)->AsgCodToEdit = -1L;
Frm_StartForm (ActFrmNewAsg);
Asg_PutParams (Assignments);
Btn_PutConfirmButton (Txt_New_assignment);
Frm_EndForm ();
}
2016-03-19 19:22:13 +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
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_ParamsWhichGroupsToShow (void *Assignments)
2016-12-04 23:09:28 +01:00
{
2020-04-05 22:53:58 +02:00
if (Assignments)
2020-03-26 02:54:30 +01:00
{
2020-04-05 22:53:58 +02:00
Dat_PutHiddenParamOrder (((struct Asg_Assignments *) Assignments)->SelectedOrder);
Pag_PutHiddenParamPagNum (Pag_ASSIGNMENTS,
((struct Asg_Assignments *) Assignments)->CurrentPage);
2020-03-26 02:54:30 +01:00
}
2014-12-01 23:55:08 +01:00
}
2017-05-02 10:24:47 +02:00
/*****************************************************************************/
/******************** Show print view of one assignment **********************/
/*****************************************************************************/
void Asg_PrintOneAssignment (void)
{
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2017-05-02 10:24:47 +02:00
long AsgCod;
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2017-05-02 10:24:47 +02:00
/***** Get the code of the assignment *****/
AsgCod = Asg_GetParamAsgCod ();
2017-06-12 14:16:33 +02:00
/***** Write header *****/
2017-05-02 10:24:47 +02:00
Lay_WriteHeaderClassPhoto (true,false,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Deg.DegCod,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2017-05-02 10:24:47 +02:00
/***** Table head *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
2020-04-05 22:53:58 +02:00
Asg_PutHeadForSeeing (&Assignments,
true); // Print view
2017-05-02 10:24:47 +02:00
/***** Write assignment *****/
Asg_ShowOneAssignment (AsgCod,
true); // Print view
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-05-02 10:24:47 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************************** Show one assignment *****************************/
/*****************************************************************************/
2017-05-02 10:24:47 +02:00
static void Asg_ShowOneAssignment (long AsgCod,bool PrintView)
2014-12-01 23:55:08 +01:00
{
2019-04-20 22:06:18 +02:00
char *Anchor = NULL;
2015-10-22 01:24:43 +02:00
static unsigned UniqueId = 0;
2019-11-01 22:53:39 +01:00
char *Id;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
2019-09-27 00:46:02 +02:00
Dat_StartEndTime_t StartEndTime;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
/***** Get data of this assignment *****/
Asg.AsgCod = AsgCod;
Asg_GetDataOfAssignmentByCod (&Asg);
2019-04-20 22:06:18 +02:00
/***** Set anchor string *****/
Frm_SetAnchorStr (Asg.AsgCod,&Anchor);
2014-12-01 23:55:08 +01:00
/***** Write first row of data of this assignment *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-11-05 23:11:31 +01:00
/* Forms to remove/edit this assignment */
2017-05-02 13:02:43 +02:00
if (PrintView)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL\"");
2017-05-02 13:02:43 +02:00
else
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL COLOR%u\"",Gbl.RowEvenOdd);
2019-04-20 22:06:18 +02:00
Asg_PutFormsToRemEditOneAsg (&Asg,Anchor);
2017-05-02 13:02:43 +02:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-05-02 11:39:17 +02:00
2019-09-27 00:46:02 +02:00
/* Start/end date/time */
2015-10-22 01:24:43 +02:00
UniqueId++;
2019-09-27 00:46:02 +02:00
2019-12-15 01:10:36 +01:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
2019-09-27 00:46:02 +02:00
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"asg_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
2019-10-07 22:28:16 +02:00
if (PrintView)
2019-11-01 22:53:39 +01:00
HTM_TD_Begin ("id=\"%s\" class=\"%s LB\"",
Id,
2019-10-10 23:14:13 +02:00
Asg.Hidden ? (Asg.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Asg.Open ? "DATE_GREEN" :
"DATE_RED"));
2019-10-07 22:28:16 +02:00
else
2019-11-01 22:53:39 +01:00
HTM_TD_Begin ("id=\"%s\" class=\"%s LB COLOR%u\"",
Id,
2019-10-10 23:14:13 +02:00
Asg.Hidden ? (Asg.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Asg.Open ? "DATE_GREEN" :
"DATE_RED"),
Gbl.RowEvenOdd);
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (Id,Asg.TimeUTC[StartEndTime],
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
2019-11-02 11:45:41 +01:00
true,true,true,0x7);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-11-06 19:45:20 +01:00
free (Id);
2019-09-27 00:46:02 +02:00
}
2014-12-01 23:55:08 +01:00
/* Assignment title */
2019-10-07 22:28:16 +02:00
if (PrintView)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LT\"",
2019-10-10 23:14:13 +02:00
Asg.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE");
2019-10-07 22:28:16 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LT COLOR%u\"",
2019-10-10 23:14:13 +02:00
Asg.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
Gbl.RowEvenOdd);
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_Begin (Anchor);
2019-11-10 12:36:37 +01:00
HTM_Txt (Asg.Title);
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Assignment folder */
2019-11-04 21:00:57 +01:00
if (PrintView)
2019-11-05 23:11:31 +01:00
HTM_TD_Begin ("class=\"DAT LT\"");
2019-11-04 21:00:57 +01:00
else
2019-11-05 23:11:31 +01:00
HTM_TD_Begin ("class=\"DAT LT COLOR%u\"",Gbl.RowEvenOdd);
2017-05-02 10:24:47 +02:00
if (Asg.SendWork == Asg_SEND_WORK)
Asg_WriteAssignmentFolder (&Asg,PrintView);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Write second row of data of this assignment *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
/* Author of the assignment */
2019-10-07 22:28:16 +02:00
if (PrintView)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
2019-10-07 22:28:16 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
Asg_WriteAsgAuthor (&Asg);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Text of the assignment */
Asg_GetAssignmentTxtFromDB (Asg.AsgCod,Txt);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML
2016-01-25 00:19:21 +01:00
Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
2019-10-07 22:28:16 +02:00
if (PrintView)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
2019-10-07 22:28:16 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2019-04-04 10:45:15 +02:00
if (Gbl.Crs.Grps.NumGrps)
2014-12-01 23:55:08 +01:00
Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (&Asg);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"PAR %s\"",Asg.Hidden ? "DAT_LIGHT" :
"DAT");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-04-20 22:06:18 +02:00
/***** Free anchor string *****/
Frm_FreeAnchorStr (Anchor);
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
/***** Mark possible notification as seen *****/
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsSeen (Ntf_EVENT_ASSIGNMENT,
2019-04-04 10:45:15 +02:00
AsgCod,Gbl.Hierarchy.Crs.CrsCod,
2019-04-03 20:57:04 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Write the author of an assignment *********************/
/*****************************************************************************/
static void Asg_WriteAsgAuthor (struct Assignment *Asg)
{
2017-03-04 01:59:27 +01:00
Usr_WriteAuthor1Line (Asg->UsrCod,Asg->Hidden);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Write the folder of an assignment *********************/
/*****************************************************************************/
2017-05-02 10:24:47 +02:00
static void Asg_WriteAssignmentFolder (struct Assignment *Asg,bool PrintView)
2014-12-01 23:55:08 +01:00
{
2019-04-22 01:06:48 +02:00
extern const char *Txt_Upload_file_or_create_folder;
2015-07-21 17:24:52 +02:00
extern const char *Txt_Folder;
2019-12-19 14:47:14 +01:00
bool ICanSendFiles = !Asg->Hidden && // It's visible (not hidden)
Asg->Open && // It's open (inside dates)
Asg->IBelongToCrsOrGrps; // I belong to course or groups
2017-05-02 10:24:47 +02:00
/***** Folder icon *****/
if (!PrintView && // Not print view
ICanSendFiles) // I can send files to this assignment folder
2014-12-01 23:55:08 +01:00
{
2017-05-02 10:24:47 +02:00
/* Form to create a new file or folder */
2019-04-25 02:58:42 +02:00
Gbl.FileBrowser.FullTree = true; // By default, show all files
2019-12-19 14:47:14 +01:00
switch (Gbl.Usrs.Me.Role.Logged)
2019-04-25 02:58:42 +02:00
{
case Rol_STD:
Gbl.FileBrowser.Type = Brw_ADMI_ASG_USR; // User assignments
Frm_StartForm (ActFrmCreAsgUsr);
break;
case Rol_NET:
case Rol_TCH:
2019-12-19 14:47:14 +01:00
case Rol_SYS_ADM:
2019-04-25 02:58:42 +02:00
Gbl.FileBrowser.Type = Brw_ADMI_ASG_CRS; // Course assignments
Str_Copy (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
2019-12-19 14:47:14 +01:00
Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (&Gbl.Usrs.Selected);
2019-04-25 02:58:42 +02:00
Frm_StartForm (ActFrmCreAsgCrs);
break;
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2019-04-25 02:58:42 +02:00
break;
}
2019-04-25 14:39:51 +02:00
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,
PATH_MAX);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,Asg->Folder,
NAME_MAX);
Gbl.FileBrowser.FilFolLnk.Type = Brw_IS_FOLDER;
2020-04-05 22:53:58 +02:00
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
2019-04-25 02:58:42 +02:00
Ico_PutIconLink ("folder-open-yellow-plus.png",
Txt_Upload_file_or_create_folder);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-12-19 14:47:14 +01:00
switch (Gbl.Usrs.Me.Role.Logged)
2019-04-25 02:58:42 +02:00
{
case Rol_STD:
break;
case Rol_NET:
case Rol_TCH:
2019-12-19 14:47:14 +01:00
case Rol_SYS_ADM:
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-04-25 02:58:42 +02:00
break;
default:
break;
}
2014-12-01 23:55:08 +01:00
}
2019-01-12 03:00:59 +01:00
else // Sending of files disabled
Ico_PutIconOff (ICanSendFiles ? "folder-open-green.svg" :
"folder-red.svg",
Txt_Folder);
2017-05-02 10:24:47 +02:00
/***** Folder name *****/
2019-11-10 12:36:37 +01:00
HTM_Txt (Asg->Folder);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Get parameter with the type or order in list of assignments *********/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static Dat_StartEndTime_t Asg_GetParamAsgOrder (void)
2014-12-01 23:55:08 +01:00
{
2020-04-05 22:53:58 +02:00
return (Dat_StartEndTime_t)
Par_GetParToUnsignedLong ("Order",
0,
Dat_NUM_START_END_TIME - 1,
(unsigned long) Asg_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Put a link (form) to edit one assignment ******************/
/*****************************************************************************/
2019-04-20 22:06:18 +02:00
static void Asg_PutFormsToRemEditOneAsg (const struct Assignment *Asg,
const char *Anchor)
2014-12-01 23:55:08 +01:00
{
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
Assignments.AsgCodToEdit = Asg->AsgCod; // Used as parameter in contextual links
2015-12-13 19:17:09 +01:00
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2017-05-02 10:24:47 +02:00
{
2017-05-18 19:13:41 +02:00
case Rol_TCH:
2017-05-02 10:24:47 +02:00
case Rol_SYS_ADM:
/***** Put form to remove assignment *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToRemove (ActReqRemAsg,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments);
2017-05-02 10:24:47 +02:00
/***** Put form to hide/show assignment *****/
2019-04-20 22:06:18 +02:00
if (Asg->Hidden)
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToUnhide (ActShoAsg,Anchor,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments);
2017-05-02 10:24:47 +02:00
else
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToHide (ActHidAsg,Anchor,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments);
2017-05-02 10:24:47 +02:00
/***** Put form to edit assignment *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiOneAsg,NULL,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments);
2018-10-04 21:57:25 +02:00
/* falls through */
/* no break */
2017-05-18 19:13:41 +02:00
case Rol_STD:
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-02 10:24:47 +02:00
/***** Put form to print assignment *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToPrint (ActPrnOneAsg,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments);
2017-05-02 10:24:47 +02:00
break;
default:
break;
}
2015-12-13 19:17:09 +01:00
}
/*****************************************************************************/
2015-12-13 19:37:08 +01:00
/******************** Params used to edit an assignment **********************/
2015-12-13 19:17:09 +01:00
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void Asg_PutParams (void *Assignments)
2015-12-13 19:17:09 +01:00
{
2020-03-27 14:56:54 +01:00
Grp_WhichGroups_t WhichGroups;
2020-03-26 02:54:30 +01:00
if (Assignments)
{
if (((struct Asg_Assignments *) Assignments)->AsgCodToEdit > 0)
Asg_PutParamAsgCod (((struct Asg_Assignments *) Assignments)->AsgCodToEdit);
2020-04-05 22:53:58 +02:00
Dat_PutHiddenParamOrder (((struct Asg_Assignments *) Assignments)->SelectedOrder);
2020-03-27 14:56:54 +01:00
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
2020-03-26 02:54:30 +01:00
Pag_PutHiddenParamPagNum (Pag_ASSIGNMENTS,((struct Asg_Assignments *) Assignments)->CurrentPage);
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ List all the assignments ***************************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
2014-12-01 23:55:08 +01:00
{
2019-01-03 15:25:18 +01:00
static const char *HiddenSubQuery[Rol_NUM_ROLES] =
{
2019-11-21 00:40:35 +01:00
[Rol_UNK ] = " AND Hidden='N'",
[Rol_GST ] = " AND Hidden='N'",
[Rol_USR ] = " AND Hidden='N'",
[Rol_STD ] = " AND Hidden='N'",
[Rol_NET ] = " AND Hidden='N'",
[Rol_TCH ] = "",
[Rol_DEG_ADM] = " AND Hidden='N'",
[Rol_CTR_ADM] = " AND Hidden='N'",
[Rol_INS_ADM] = " AND Hidden='N'",
[Rol_SYS_ADM] = "",
2019-01-03 15:25:18 +01:00
};
static const char *OrderBySubQuery[Dat_NUM_START_END_TIME] =
{
2019-11-21 00:40:35 +01:00
[Dat_START_TIME] = "StartTime DESC,EndTime DESC,Title DESC",
[Dat_END_TIME ] = "EndTime DESC,StartTime DESC,Title DESC",
2019-01-03 15:25:18 +01:00
};
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumAsg;
2020-04-05 22:53:58 +02:00
if (Assignments->LstIsRead)
Asg_FreeListAssignments (Assignments);
2014-12-01 23:55:08 +01:00
/***** Get list of assignments from database *****/
2019-09-29 17:33:39 +02:00
if (Gbl.Crs.Grps.WhichGrps == Grp_MY_GROUPS)
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignments",
"SELECT AsgCod"
" FROM assignments"
" WHERE CrsCod=%ld%s"
" AND (AsgCod NOT IN (SELECT AsgCod FROM asg_grp) OR"
" AsgCod IN (SELECT asg_grp.AsgCod FROM asg_grp,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld AND asg_grp.GrpCod=crs_grp_usr.GrpCod))"
" ORDER BY %s",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2019-04-03 20:57:04 +02:00
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged],
2018-10-30 09:02:14 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2020-04-05 22:53:58 +02:00
OrderBySubQuery[Assignments->SelectedOrder]);
2019-04-04 10:45:15 +02:00
else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignments",
"SELECT AsgCod"
" FROM assignments"
" WHERE CrsCod=%ld%s"
" ORDER BY %s",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2019-04-03 20:57:04 +02:00
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged],
2020-04-05 22:53:58 +02:00
OrderBySubQuery[Assignments->SelectedOrder]);
2018-10-30 01:00:46 +01:00
2014-12-01 23:55:08 +01:00
if (NumRows) // Assignments found...
{
2020-04-05 22:53:58 +02:00
Assignments->Num = (unsigned) NumRows;
2014-12-01 23:55:08 +01:00
/***** Create list of assignments *****/
2020-04-05 22:53:58 +02:00
if ((Assignments->LstAsgCods = (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 assignments codes *****/
for (NumAsg = 0;
2020-04-05 22:53:58 +02:00
NumAsg < Assignments->Num;
2014-12-01 23:55:08 +01:00
NumAsg++)
{
/* Get next assignment code */
row = mysql_fetch_row (mysql_res);
2020-04-05 22:53:58 +02:00
if ((Assignments->LstAsgCods[NumAsg] = Str_ConvertStrCodToLongCod (row[0])) < 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Error: wrong assignment code.");
}
}
else
2020-04-05 22:53:58 +02:00
Assignments->Num = 0;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2020-04-05 22:53:58 +02:00
Assignments->LstIsRead = true;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get assignment data using its code **********************/
/*****************************************************************************/
void Asg_GetDataOfAssignmentByCod (struct Assignment *Asg)
{
2018-10-30 09:02:14 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
2016-12-28 17:45:53 +01:00
if (Asg->AsgCod > 0)
{
/***** Build query *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data",
"SELECT AsgCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title,Folder"
" FROM assignments"
" WHERE AsgCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Asg->AsgCod,Gbl.Hierarchy.Crs.CrsCod);
2016-12-28 17:45:53 +01:00
/***** Get data of assignment *****/
2018-10-30 09:02:14 +01:00
Asg_GetDataOfAssignment (Asg,&mysql_res,NumRows);
2016-12-28 17:45:53 +01:00
}
else
2016-12-29 23:33:01 +01:00
{
2016-12-28 17:45:53 +01:00
/***** Clear all assignment data *****/
2016-12-29 23:33:01 +01:00
Asg->AsgCod = -1L;
2016-12-28 17:45:53 +01:00
Asg_ResetAssignment (Asg);
2016-12-29 23:33:01 +01:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Get assignment data using its folder name *******************/
/*****************************************************************************/
void Asg_GetDataOfAssignmentByFolder (struct Assignment *Asg)
{
2018-10-30 09:02:14 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
2016-12-28 17:45:53 +01:00
if (Asg->Folder[0])
{
/***** Query database *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data",
"SELECT AsgCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title,Folder"
" FROM assignments"
" WHERE CrsCod=%ld AND Folder='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,Asg->Folder);
2016-12-28 17:45:53 +01:00
/***** Get data of assignment *****/
2018-10-30 09:02:14 +01:00
Asg_GetDataOfAssignment (Asg,&mysql_res,NumRows);
2016-12-28 17:45:53 +01:00
}
else
2016-12-29 23:33:01 +01:00
{
2016-12-28 17:45:53 +01:00
/***** Clear all assignment data *****/
2016-12-29 23:33:01 +01:00
Asg->AsgCod = -1L;
2016-12-28 17:45:53 +01:00
Asg_ResetAssignment (Asg);
2016-12-29 23:33:01 +01:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Get assignment data *******************************/
/*****************************************************************************/
2018-10-30 09:02:14 +01:00
static void Asg_GetDataOfAssignment (struct Assignment *Asg,
MYSQL_RES **mysql_res,
unsigned long NumRows)
2014-12-01 23:55:08 +01:00
{
MYSQL_ROW row;
2016-11-14 11:57:42 +01:00
/***** Clear all assignment data *****/
2016-12-28 17:45:53 +01:00
Asg_ResetAssignment (Asg);
2014-12-01 23:55:08 +01:00
/***** Get data of assignment from database *****/
2018-10-30 09:02:14 +01:00
if (NumRows) // Assignment found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
2018-10-30 09:02:14 +01:00
row = mysql_fetch_row (*mysql_res);
2014-12-01 23:55:08 +01:00
/* Get code of the assignment (row[0]) */
Asg->AsgCod = Str_ConvertStrCodToLongCod (row[0]);
2016-09-07 18:02:25 +02:00
/* Get whether the assignment is hidden or not (row[1]) */
2016-09-07 18:48:10 +02:00
Asg->Hidden = (row[1][0] == 'Y');
2014-12-01 23:55:08 +01:00
/* Get author of the assignment (row[2]) */
Asg->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
2015-10-23 13:20:42 +02:00
/* Get start date (row[3] holds the start UTC time) */
2016-12-15 00:39:52 +01:00
Asg->TimeUTC[Dat_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
2014-12-01 23:55:08 +01:00
2015-10-23 13:51:33 +02:00
/* Get end date (row[4] holds the end UTC time) */
2016-12-15 00:39:52 +01:00
Asg->TimeUTC[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]);
2014-12-01 23:55:08 +01:00
/* Get whether the assignment is open or closed (row(5)) */
Asg->Open = (row[5][0] == '1');
/* Get the title of the assignment (row[6]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Asg->Title,row[6],
2017-03-08 22:23:52 +01:00
Asg_MAX_BYTES_ASSIGNMENT_TITLE);
2014-12-01 23:55:08 +01:00
/* Get the folder for the assignment files (row[7]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Asg->Folder,row[7],
2017-03-08 22:23:52 +01:00
Brw_MAX_BYTES_FOLDER);
2014-12-01 23:55:08 +01:00
Asg->SendWork = (Asg->Folder[0] != '\0');
/* Can I do this assignment? */
2015-11-10 02:23:55 +01:00
Asg->IBelongToCrsOrGrps = Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (Asg->AsgCod);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
2018-10-30 09:02:14 +01:00
DB_FreeMySQLResult (mysql_res);
2014-12-01 23:55:08 +01:00
}
2016-12-28 17:45:53 +01:00
/*****************************************************************************/
/************************* Clear all assignment data **************************/
/*****************************************************************************/
static void Asg_ResetAssignment (struct Assignment *Asg)
{
2016-12-29 23:33:01 +01:00
if (Asg->AsgCod <= 0) // If > 0 ==> keep value
Asg->AsgCod = -1L;
2016-12-28 17:45:53 +01:00
Asg->AsgCod = -1L;
Asg->Hidden = false;
Asg->UsrCod = -1L;
Asg->TimeUTC[Dat_START_TIME] =
Asg->TimeUTC[Dat_END_TIME ] = (time_t) 0;
Asg->Open = false;
Asg->Title[0] = '\0';
2017-09-17 23:37:03 +02:00
Asg->SendWork = Asg_DO_NOT_SEND_WORK;
2016-12-28 17:45:53 +01:00
Asg->Folder[0] = '\0';
Asg->IBelongToCrsOrGrps = false;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************* Free list of assignments **************************/
/*****************************************************************************/
2020-04-05 22:53:58 +02:00
static void Asg_FreeListAssignments (struct Asg_Assignments *Assignments)
2014-12-01 23:55:08 +01:00
{
2020-04-05 22:53:58 +02:00
if (Assignments->LstIsRead &&
Assignments->LstAsgCods)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of assignments *****/
2020-04-05 22:53:58 +02:00
free (Assignments->LstAsgCods);
Assignments->LstAsgCods = NULL;
Assignments->Num = 0;
Assignments->LstIsRead = false;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/******************** Get assignment text from database **********************/
/*****************************************************************************/
2017-01-13 01:51:23 +01:00
static void Asg_GetAssignmentTxtFromDB (long AsgCod,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 assignment from database *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment text",
"SELECT Txt FROM assignments"
" WHERE AsgCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
AsgCod,Gbl.Hierarchy.Crs.CrsCod);
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 assignment text.");
}
/*****************************************************************************/
/***************** Get summary and content of an assignment *****************/
/*****************************************************************************/
2015-10-22 01:24:43 +02:00
// This function may be called inside a web service
2014-12-01 23:55:08 +01:00
2017-03-08 14:12:33 +01:00
void Asg_GetNotifAssignment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
2017-03-06 13:01:16 +01:00
char **ContentStr,
long AsgCod,bool GetContent)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-10-18 23:38:06 +02:00
unsigned long NumRows;
2017-01-17 03:10:43 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
/***** Build query *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment title and text",
"SELECT Title,Txt FROM assignments"
" WHERE AsgCod=%ld",
AsgCod);
2014-12-01 23:55:08 +01:00
2018-10-18 23:38:06 +02:00
/***** Result should have a unique row *****/
if (NumRows == 1)
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
2014-12-01 23:55:08 +01:00
2018-10-18 23:38:06 +02:00
/***** Get summary *****/
Str_Copy (SummaryStr,row[0],
Ntf_MAX_BYTES_SUMMARY);
/***** Get content *****/
if (GetContent)
{
Length = strlen (row[1]);
if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
Str_Copy (*ContentStr,row[1],
Length);
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Write parameter with code of assignment *******************/
/*****************************************************************************/
static void Asg_PutParamAsgCod (long AsgCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"AsgCod",AsgCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Get parameter with code of assignment ********************/
/*****************************************************************************/
long Asg_GetParamAsgCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of assignment *****/
return Par_GetParToLong ("AsgCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-12-11 21:02:22 +01:00
/************* Ask for confirmation of removing an assignment ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-12-11 21:02:22 +01:00
void Asg_ReqRemAssignment (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Do_you_really_want_to_remove_the_assignment_X;
extern const char *Txt_Remove_assignment;
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2020-04-05 22:53:58 +02:00
Assignments.SelectedOrder = Asg_GetParamAsgOrder ();
Gbl.Crs.Grps.WhichGrps = Grp_GetParamWhichGroups ();
Assignments.CurrentPage = Pag_GetParamPagNum (Pag_ASSIGNMENTS);
2014-12-01 23:55:08 +01:00
/***** Get assignment code *****/
if ((Asg.AsgCod = Asg_GetParamAsgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of assignment is missing.");
/***** Get data of the assignment from database *****/
Asg_GetDataOfAssignmentByCod (&Asg);
2017-04-28 10:20:29 +02:00
/***** Show question and button to remove the assignment *****/
2020-04-05 22:53:58 +02:00
Assignments.AsgCodToEdit = Asg.AsgCod;
2020-03-26 02:54:30 +01:00
Ale_ShowAlertAndButton (ActRemAsg,NULL,NULL,
2020-04-05 22:53:58 +02:00
Asg_PutParams,&Assignments,
2019-02-17 01:14:55 +01:00
Btn_REMOVE_BUTTON,Txt_Remove_assignment,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_assignment_X,
Asg.Title);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Show all assignments again *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Remove an assignment ****************************/
/*****************************************************************************/
void Asg_RemoveAssignment (void)
{
extern const char *Txt_Assignment_X_removed;
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get assignment code *****/
if ((Asg.AsgCod = Asg_GetParamAsgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of assignment is missing.");
/***** Get data of the assignment from database *****/
Asg_GetDataOfAssignmentByCod (&Asg); // Inside this function, the course is checked to be the current one
/***** Remove all the folders associated to this assignment *****/
if (Asg.Folder[0])
Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (Asg.Folder);
/***** Remove all the groups of this assignment *****/
Asg_RemoveAllTheGrpsAssociatedToAnAssignment (Asg.AsgCod);
/***** Remove assignment *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove assignment",
"DELETE FROM assignments WHERE AsgCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Asg.AsgCod,Gbl.Hierarchy.Crs.CrsCod);
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_ASSIGNMENT,Asg.AsgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Assignment_X_removed,
2019-02-15 23:38:44 +01:00
Asg.Title);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Show all assignments again *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Hide an assignment *****************************/
/*****************************************************************************/
void Asg_HideAssignment (void)
{
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get assignment code *****/
if ((Asg.AsgCod = Asg_GetParamAsgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of assignment is missing.");
/***** Get data of the assignment from database *****/
Asg_GetDataOfAssignmentByCod (&Asg);
/***** Hide assignment *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not hide assignment",
"UPDATE assignments SET Hidden='Y'"
" WHERE AsgCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Asg.AsgCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Show all assignments again *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Show an assignment *****************************/
/*****************************************************************************/
void Asg_ShowAssignment (void)
{
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get assignment code *****/
if ((Asg.AsgCod = Asg_GetParamAsgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of assignment is missing.");
/***** Get data of the assignment from database *****/
Asg_GetDataOfAssignmentByCod (&Asg);
/***** Hide assignment *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not show assignment",
"UPDATE assignments SET Hidden='N'"
" WHERE AsgCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Asg.AsgCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Show all assignments again *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Check if the title or the folder of an assignment exists ***********/
/*****************************************************************************/
static bool Asg_CheckIfSimilarAssignmentExists (const char *Field,const char *Value,long AsgCod)
{
/***** Get number of assignments with a field value from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not get similar assignments",
"SELECT COUNT(*) FROM assignments"
" WHERE CrsCod=%ld"
" AND %s='%s' AND AsgCod<>%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 13:13:11 +01:00
Field,Value,AsgCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Put a form to create a new assignment ********************/
/*****************************************************************************/
void Asg_RequestCreatOrEditAsg (void)
{
2016-11-27 21:41:17 +01:00
extern const char *Hlp_ASSESSMENT_Assignments_new_assignment;
extern const char *Hlp_ASSESSMENT_Assignments_edit_assignment;
2014-12-01 23:55:08 +01:00
extern const char *Txt_New_assignment;
extern const char *Txt_Edit_assignment;
extern const char *Txt_Title;
extern const char *Txt_Upload_files_QUESTION;
extern const char *Txt_Folder;
extern const char *Txt_Description;
extern const char *Txt_Create_assignment;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2014-12-01 23:55:08 +01:00
struct Assignment Asg;
bool ItsANewAssignment;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2020-02-26 19:35:33 +01:00
static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] =
{
Dat_HMS_TO_000000,
Dat_HMS_TO_235959
};
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get parameters *****/
2020-04-05 22:53:58 +02:00
Assignments.SelectedOrder = Asg_GetParamAsgOrder ();
2020-03-27 14:56:54 +01:00
Grp_GetParamWhichGroups ();
2020-04-05 22:53:58 +02:00
Assignments.CurrentPage = Pag_GetParamPagNum (Pag_ASSIGNMENTS);
2014-12-01 23:55:08 +01:00
/***** Get the code of the assignment *****/
ItsANewAssignment = ((Asg.AsgCod = Asg_GetParamAsgCod ()) == -1L);
/***** Get from the database the data of the assignment *****/
if (ItsANewAssignment)
{
/* Initialize to empty assignment */
Asg.AsgCod = -1L;
2016-12-15 00:39:52 +01:00
Asg.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
Asg.TimeUTC[Dat_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours
2014-12-01 23:55:08 +01:00
Asg.Open = true;
Asg.Title[0] = '\0';
2017-09-17 23:37:03 +02:00
Asg.SendWork = Asg_DO_NOT_SEND_WORK;
2014-12-01 23:55:08 +01:00
Asg.Folder[0] = '\0';
2015-11-10 02:23:55 +01:00
Asg.IBelongToCrsOrGrps = false;
2014-12-01 23:55:08 +01:00
}
else
{
/* Get data of the assignment from database */
Asg_GetDataOfAssignmentByCod (&Asg);
/* Get text of the assignment from database */
Asg_GetAssignmentTxtFromDB (Asg.AsgCod,Txt);
}
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2014-12-01 23:55:08 +01:00
if (ItsANewAssignment)
2017-04-28 10:20:29 +02:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewAsg);
2020-04-05 22:53:58 +02:00
Assignments.AsgCodToEdit = -1L;
2017-04-28 10:20:29 +02:00
}
2014-12-01 23:55:08 +01:00
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgAsg);
2020-04-05 22:53:58 +02:00
Assignments.AsgCodToEdit = Asg.AsgCod;
2014-12-01 23:55:08 +01:00
}
2020-04-05 22:53:58 +02:00
Asg_PutParams (&Assignments);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2017-06-11 22:26:40 +02:00
if (ItsANewAssignment)
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_New_assignment,
NULL,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Assignments_new_assignment,Box_NOT_CLOSABLE,2);
2017-06-11 22:26:40 +02:00
else
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,
2017-10-01 00:48:36 +02:00
Asg.Title[0] ? Asg.Title :
Txt_Edit_assignment,
2020-03-26 02:54:30 +01:00
NULL,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Assignments_edit_assignment,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2017-10-01 00:48:36 +02:00
2014-12-01 23:55:08 +01:00
/***** Assignment title *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RM","Title",Txt_Title);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-12-27 15:45:19 +01:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Title",Asg_MAX_CHARS_ASSIGNMENT_TITLE,Asg.Title,false,
2019-11-27 00:27:42 +01:00
"id=\"Title\" required=\"required\""
" class=\"TITLE_DESCRIPTION_WIDTH\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Assignment start and end dates *****/
2020-02-26 19:35:33 +01:00
Dat_PutFormStartEndClientLocalDateTimes (Asg.TimeUTC,
Dat_FORM_SECONDS_ON,
SetHMS);
2014-12-01 23:55:08 +01:00
/***** Send work? *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RM","Folder",Txt_Upload_files_QUESTION);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"DAT\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Folder);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Folder",Brw_MAX_CHARS_FOLDER,Asg.Folder,false,
2019-12-27 15:45:19 +01:00
"id=\"Folder\" size=\"30\"");
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Assignment text *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","Txt",Txt_Description);
2019-10-07 22:28:16 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-27 00:27:42 +01:00
HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" rows=\"10\""
" class=\"TITLE_DESCRIPTION_WIDTH\"");
2014-12-01 23:55:08 +01:00
if (!ItsANewAssignment)
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Groups *****/
Asg_ShowLstGrpsToEditAssignment (Asg.AsgCod);
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2015-03-24 17:47:26 +01:00
if (ItsANewAssignment)
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_assignment);
2015-03-24 17:47:26 +01:00
else
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CONFIRM_BUTTON,Txt_Save_changes);
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
2016-03-19 19:22:13 +01:00
/***** Show current assignments, if any *****/
2020-04-05 22:53:58 +02:00
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Show list of groups to edit and assignment *****************/
/*****************************************************************************/
static void Asg_ShowLstGrpsToEditAssignment (long AsgCod)
{
2016-11-27 21:41:17 +01:00
extern const char *Hlp_USERS_Groups;
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
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Groups);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin ("100%",NULL,
NULL,NULL,
2017-06-12 15:03:29 +02:00
Hlp_USERS_Groups,Box_NOT_CLOSABLE,0);
2014-12-01 23:55:08 +01:00
/***** First row: checkbox to select the whole course *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"7\" class=\"DAT LM\"");
2019-11-03 10:41:31 +01:00
HTM_LABEL_Begin (NULL);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"id=\"WholeCrs\" value=\"Y\"%s"
" onclick=\"uncheckChildren(this,'GrpCods')\"",
Asg_CheckIfAsgIsAssociatedToGrps (AsgCod) ? "" : " checked=\"checked\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;%s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
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)
2019-05-28 15:06:53 +02:00
Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp],
2019-04-03 20:57:04 +02:00
AsgCod,Grp_ASSIGNMENT);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/***** Free list of groups types and groups in this course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/*****************************************************************************/
/****************** Receive form to create a new assignment ******************/
/*****************************************************************************/
void Asg_RecFormAssignment (void)
{
extern const char *Txt_Already_existed_an_assignment_with_the_title_X;
extern const char *Txt_Already_existed_an_assignment_with_the_folder_X;
extern const char *Txt_You_must_specify_the_title_of_the_assignment;
2015-10-23 13:20:42 +02:00
extern const char *Txt_Created_new_assignment_X;
extern const char *Txt_The_assignment_has_been_modified;
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_can_not_disable_file_uploading_once_folders_have_been_created;
2020-04-05 22:53:58 +02:00
struct Asg_Assignments Assignments;
2016-12-28 17:45:53 +01:00
struct Assignment OldAsg; // Current assigment data in database
struct Assignment NewAsg; // Assignment data received from form
2014-12-01 23:55:08 +01:00
bool ItsANewAssignment;
bool NewAssignmentIsCorrect = true;
unsigned NumUsrsToBeNotifiedByEMail;
2019-02-15 21:09:18 +01:00
char Description[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2020-04-05 22:53:58 +02:00
/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
/***** Get the code of the assignment *****/
2016-12-28 17:45:53 +01:00
NewAsg.AsgCod = Asg_GetParamAsgCod ();
ItsANewAssignment = (NewAsg.AsgCod < 0);
2014-12-01 23:55:08 +01:00
2016-12-28 17:45:53 +01:00
if (ItsANewAssignment)
2016-12-29 23:33:01 +01:00
{
2016-12-28 17:45:53 +01:00
/***** Reset old (current, not existing) assignment data *****/
2016-12-29 23:33:01 +01:00
OldAsg.AsgCod = -1L;
2016-12-28 17:45:53 +01:00
Asg_ResetAssignment (&OldAsg);
2016-12-29 23:33:01 +01:00
}
2016-12-28 17:45:53 +01:00
else
2014-12-01 23:55:08 +01:00
{
2016-12-28 17:45:53 +01:00
/***** Get data of the old (current) assignment from database *****/
2014-12-01 23:55:08 +01:00
OldAsg.AsgCod = NewAsg.AsgCod;
Asg_GetDataOfAssignmentByCod (&OldAsg);
}
2015-10-22 14:49:48 +02:00
/***** Get start/end date-times *****/
2016-12-15 00:39:52 +01:00
NewAsg.TimeUTC[Dat_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
NewAsg.TimeUTC[Dat_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
2014-12-01 23:55:08 +01:00
/***** Get assignment title *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("Title",NewAsg.Title,Asg_MAX_BYTES_ASSIGNMENT_TITLE);
2014-12-01 23:55:08 +01:00
/***** Get folder name where to send works of the assignment *****/
2017-03-08 22:23:52 +01:00
Par_GetParToText ("Folder",NewAsg.Folder,Brw_MAX_BYTES_FOLDER);
2014-12-01 23:55:08 +01:00
NewAsg.SendWork = (NewAsg.Folder[0]) ? Asg_SEND_WORK :
Asg_DO_NOT_SEND_WORK;
/***** Get assignment text *****/
2019-02-15 21:09:18 +01:00
Par_GetParToHTML ("Txt",Description,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
2014-12-01 23:55:08 +01:00
/***** Adjust dates *****/
2016-12-15 00:39:52 +01:00
if (NewAsg.TimeUTC[Dat_START_TIME] == 0)
NewAsg.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
if (NewAsg.TimeUTC[Dat_END_TIME] == 0)
2017-01-28 15:58:46 +01:00
NewAsg.TimeUTC[Dat_END_TIME] = NewAsg.TimeUTC[Dat_START_TIME] + 2 * 60 * 60; // +2 hours
2014-12-01 23:55:08 +01:00
/***** Check if title is correct *****/
if (NewAsg.Title[0]) // If there's an assignment title
{
/* If title of assignment was in database... */
if (Asg_CheckIfSimilarAssignmentExists ("Title",NewAsg.Title,NewAsg.AsgCod))
{
NewAssignmentIsCorrect = false;
2019-02-15 21:09:18 +01:00
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_an_assignment_with_the_title_X,
2019-02-15 23:38:44 +01:00
NewAsg.Title);
2014-12-01 23:55:08 +01:00
}
else // Title is correct
{
if (NewAsg.SendWork == Asg_SEND_WORK)
{
if (Str_ConvertFilFolLnkNameToValid (NewAsg.Folder)) // If folder name is valid...
{
if (Asg_CheckIfSimilarAssignmentExists ("Folder",NewAsg.Folder,NewAsg.AsgCod)) // If folder of assignment was in database...
{
NewAssignmentIsCorrect = false;
2019-02-15 23:38:44 +01:00
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_an_assignment_with_the_folder_X,
2019-02-15 23:38:44 +01:00
NewAsg.Folder);
2014-12-01 23:55:08 +01:00
}
}
else // Folder name not valid
{
NewAssignmentIsCorrect = false;
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2014-12-01 23:55:08 +01:00
}
}
else // NewAsg.SendWork == Asg_DO_NOT_SEND_WORK
{
if (OldAsg.SendWork == Asg_SEND_WORK)
{
if (Brw_CheckIfExistsFolderAssigmentForAnyUsr (OldAsg.Folder))
{
NewAssignmentIsCorrect = false;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_disable_file_uploading_once_folders_have_been_created);
2014-12-01 23:55:08 +01:00
}
}
}
}
}
else // If there is not an assignment title
{
NewAssignmentIsCorrect = false;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_assignment);
2014-12-01 23:55:08 +01:00
}
/***** Create a new assignment or update an existing one *****/
if (NewAssignmentIsCorrect)
{
/* Get groups for this assignments */
2017-01-19 20:55:31 +01:00
Grp_GetParCodsSeveralGrps ();
2014-12-01 23:55:08 +01:00
if (ItsANewAssignment)
2015-10-23 13:20:42 +02:00
{
2019-02-15 21:09:18 +01:00
Asg_CreateAssignment (&NewAsg,Description); // Add new assignment to database
2015-10-23 13:20:42 +02:00
/***** Write success message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_assignment_X,
2019-02-15 23:38:44 +01:00
NewAsg.Title);
2015-10-23 13:20:42 +02:00
}
2014-12-01 23:55:08 +01:00
else
{
if (OldAsg.Folder[0] && NewAsg.Folder[0])
if (strcmp (OldAsg.Folder,NewAsg.Folder)) // Folder name has changed
NewAssignmentIsCorrect = Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (OldAsg.Folder,NewAsg.Folder);
if (NewAssignmentIsCorrect)
2015-10-23 13:20:42 +02:00
{
2019-02-15 21:09:18 +01:00
Asg_UpdateAssignment (&NewAsg,Description);
2015-10-23 13:20:42 +02:00
/***** Write success message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_assignment_has_been_modified);
2015-10-23 13:20:42 +02:00
}
2014-12-01 23:55:08 +01:00
}
/* Free memory for list of selected groups */
Grp_FreeListCodSelectedGrps ();
2016-03-19 19:34:22 +01:00
2016-11-16 23:19:52 +01:00
/***** Notify by email about the new assignment *****/
2016-03-19 19:34:22 +01:00
if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_ASSIGNMENT,NewAsg.AsgCod)))
Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (NewAsg.AsgCod,NumUsrsToBeNotifiedByEMail);
2020-04-05 22:53:58 +02:00
/***** Show all assignments again *****/
Asg_ShowAllAssignments (&Assignments);
2014-12-01 23:55:08 +01:00
}
else
2015-10-23 01:06:32 +02:00
// TODO: The form should be filled with partial data, now is always empty
2014-12-01 23:55:08 +01:00
Asg_RequestCreatOrEditAsg ();
}
/*****************************************************************************/
/******** Update number of users notified in table of assignments ************/
/*****************************************************************************/
static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail)
{
/***** Update number of users notified *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the number of notifications"
" of an assignment",
"UPDATE assignments SET NumNotif=NumNotif+%u"
" WHERE AsgCod=%ld",
NumUsrsToBeNotifiedByEMail,AsgCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Create a new assignment ****************************/
/*****************************************************************************/
static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt)
{
/***** Create a new assignment *****/
2018-11-03 01:45:36 +01:00
Asg->AsgCod =
DB_QueryINSERTandReturnCode ("can not create new assignment",
"INSERT INTO assignments"
" (CrsCod,UsrCod,StartTime,EndTime,Title,Folder,Txt)"
" VALUES"
" (%ld,%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
"'%s','%s','%s')",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 01:45:36 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
Asg->TimeUTC[Dat_START_TIME],
Asg->TimeUTC[Dat_END_TIME ],
Asg->Title,
Asg->Folder,
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
Asg_CreateGrps (Asg->AsgCod);
}
/*****************************************************************************/
/********************* Update an existing assignment *************************/
/*****************************************************************************/
static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt)
{
/***** Update the data of the assignment *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update assignment",
"UPDATE assignments SET "
"StartTime=FROM_UNIXTIME(%ld),"
"EndTime=FROM_UNIXTIME(%ld),"
"Title='%s',Folder='%s',Txt='%s'"
" WHERE AsgCod=%ld AND CrsCod=%ld",
Asg->TimeUTC[Dat_START_TIME],
Asg->TimeUTC[Dat_END_TIME ],
Asg->Title,
Asg->Folder,
Txt,
2019-04-04 10:45:15 +02:00
Asg->AsgCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/***** Update groups *****/
/* Remove old groups */
Asg_RemoveAllTheGrpsAssociatedToAnAssignment (Asg->AsgCod);
/* 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
Asg_CreateGrps (Asg->AsgCod);
}
/*****************************************************************************/
/*********** Check if an assignment is associated to any group ***************/
/*****************************************************************************/
static bool Asg_CheckIfAsgIsAssociatedToGrps (long AsgCod)
{
/***** Get if an assignment is associated to a group from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if an assignment"
" is associated to groups",
"SELECT COUNT(*) FROM asg_grp WHERE AsgCod=%ld",
AsgCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Check if an assignment is associated to a group ****************/
/*****************************************************************************/
bool Asg_CheckIfAsgIsAssociatedToGrp (long AsgCod,long GrpCod)
{
/***** Get if an assignment is associated to a group from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if an assignment"
" is associated to a group",
"SELECT COUNT(*) FROM asg_grp"
" WHERE AsgCod=%ld AND GrpCod=%ld",
AsgCod,GrpCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Remove groups of an assignment ************************/
/*****************************************************************************/
static void Asg_RemoveAllTheGrpsAssociatedToAnAssignment (long AsgCod)
{
/***** Remove groups of the assignment *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove the groups associated to an assignment",
"DELETE FROM asg_grp WHERE AsgCod=%ld",
AsgCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Remove one group from all the assignments ******************/
/*****************************************************************************/
void Asg_RemoveGroup (long GrpCod)
{
/***** Remove group from all the assignments *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove group from the associations"
" between assignments and groups",
"DELETE FROM asg_grp WHERE GrpCod=%ld",
GrpCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Remove groups of one type from all the assignments **************/
/*****************************************************************************/
void Asg_RemoveGroupsOfType (long GrpTypCod)
{
/***** Remove group from all the assignments *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove groups of a type from the associations"
" between assignments and groups",
"DELETE FROM asg_grp USING crs_grp,asg_grp"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=asg_grp.GrpCod",
GrpTypCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Create groups of an assignment ************************/
/*****************************************************************************/
static void Asg_CreateGrps (long AsgCod)
{
unsigned NumGrpSel;
/***** Create groups of the assignment *****/
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 an assignment",
"INSERT INTO asg_grp"
" (AsgCod,GrpCod)"
" VALUES"
" (%ld,%ld)",
AsgCod,
2019-04-04 10:45:15 +02:00
Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Get and write the names of the groups of an assignment ************/
/*****************************************************************************/
static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Assignment *Asg)
{
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 an assignment from database *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of an assignment",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM asg_grp,crs_grp,crs_grp_types"
" WHERE asg_grp.AsgCod=%ld"
" AND asg_grp.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Asg->AsgCod);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"%s\"",Asg->Hidden ? "ASG_GRP_LIGHT" :
"ASG_GRP");
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (NumRows == 1 ? Txt_Group :
Txt_Groups);
2014-12-01 23:55:08 +01:00
/***** 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 */
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;%s",row[0],row[1]);
2014-12-01 23:55:08 +01:00
if (NumRows >= 2)
{
if (NumRow == NumRows-2)
2019-11-11 00:15:44 +01:00
HTM_TxtF (" %s ",Txt_and);
2014-12-01 23:55:08 +01:00
if (NumRows >= 3)
if (NumRow < NumRows-2)
2019-11-10 13:51:07 +01:00
HTM_Txt (", ");
2014-12-01 23:55:08 +01:00
}
}
}
else
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;%s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
2014-12-01 23:55:08 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****************** Remove all the assignments of a course *******************/
/*****************************************************************************/
void Asg_RemoveCrsAssignments (long CrsCod)
{
/***** Remove groups *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove all the groups associated"
" to assignments of a course",
"DELETE FROM asg_grp USING assignments,asg_grp"
" WHERE assignments.CrsCod=%ld"
" AND assignments.AsgCod=asg_grp.AsgCod",
CrsCod);
2014-12-01 23:55:08 +01:00
/***** Remove assignments *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove all the assignments of a course",
"DELETE FROM assignments WHERE CrsCod=%ld",
CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Check if I belong to any of the groups of an assignment ***********/
/*****************************************************************************/
2015-11-10 02:23:55 +01:00
static bool Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (long AsgCod)
2014-12-01 23:55:08 +01:00
{
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2015-04-02 19:25:44 +02:00
{
2017-05-20 12:04:12 +02:00
case Rol_STD:
2017-05-21 21:23:13 +02:00
case Rol_NET:
2017-05-20 12:04:12 +02:00
case Rol_TCH:
// Students and teachers can do assignments depending on groups
/***** Get if I can do an assignment from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if I can do an assignment",
"SELECT COUNT(*) FROM assignments"
" WHERE AsgCod=%ld"
" AND "
"("
// Assignment is for the whole course
"AsgCod NOT IN (SELECT AsgCod FROM asg_grp)"
" OR "
// Assignment is for specific groups
"AsgCod IN"
" (SELECT asg_grp.AsgCod FROM asg_grp,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND asg_grp.GrpCod=crs_grp_usr.GrpCod)"
")",
AsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
2017-05-20 12:04:12 +02:00
case Rol_SYS_ADM:
return true;
default:
return false;
2015-04-02 19:25:44 +02:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Get number of courses with assignments *******************/
/*****************************************************************************/
// Returns the number of courses with assignments
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
unsigned Asg_GetNumCoursesWithAssignments (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 assignments from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM assignments"
" WHERE CrsCod>0");
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM institutions,centres,degrees,courses,assignments"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 11:13:35 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM centres,degrees,courses,assignments"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM degrees,courses,assignments"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM courses,assignments"
" WHERE courses.DegCod=%ld"
" AND courses.Status=0"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with assignments",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM assignments"
" WHERE CrsCod=%ld",
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 courses *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with assignments.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}
/*****************************************************************************/
/************************ Get number of assignments **************************/
/*****************************************************************************/
// Returns the number of assignments
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
unsigned Asg_GetNumAssignments (Hie_Level_t Scope,unsigned *NumNotif)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumAssignments;
/***** Get number of assignments from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM assignments"
" WHERE CrsCod>0");
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(assignments.NumNotif)"
" FROM institutions,centres,degrees,courses,assignments"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 11:13:35 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(assignments.NumNotif)"
" FROM centres,degrees,courses,assignments"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(assignments.NumNotif)"
" FROM degrees,courses,assignments"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(assignments.NumNotif)"
" FROM courses,assignments"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=assignments.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of assignments",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM assignments"
" WHERE CrsCod=%ld",
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 assignments *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumAssignments) != 1)
Lay_ShowErrorAndExit ("Error when getting number of assignments.");
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 assignments.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumAssignments;
}
2020-03-06 00:11:09 +01:00
/*****************************************************************************/
/****************** Get number of assignments in a course ********************/
/*****************************************************************************/
unsigned Asg_GetNumAssignmentsInCrs (long CrsCod)
{
/***** Get number of assignments in a course from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of assignments in course",
"SELECT COUNT(*) FROM assignments"
" WHERE CrsCod=%ld",
CrsCod);
}