swad-core/swad_project.c

1752 lines
62 KiB
C
Raw Normal View History

2017-09-15 13:19:27 +02:00
// swad_project.c: projects (final degree projects, thesis)
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_box.h"
#include "swad_database.h"
#include "swad_global.h"
#include "swad_group.h"
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_project.h"
#include "swad_string.h"
#include "swad_table.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Prj_ShowAllProjects (void);
static void Prj_PutHeadForSeeing (bool PrintView);
static bool Prj_CheckIfICanCreateProjects (void);
static void Prj_PutIconsListProjects (void);
static void Prj_PutIconToCreateNewPrj (void);
static void Prj_PutButtonToCreateNewPrj (void);
static void Prj_PutFormToSelectWhichGroupsToShow (void);
static void Prj_ParamsWhichGroupsToShow (void);
static void Prj_ShowOneProject (long PrjCod,bool PrintView);
2017-09-17 16:58:09 +02:00
static void Prj_WritePrjAuthor (struct Project *Prj);
static void Prj_GetParamPrjOrder (void);
2017-09-15 13:19:27 +02:00
2017-09-17 16:58:09 +02:00
static void Prj_PutFormsToRemEditOnePrj (long PrjCod,bool Hidden);
2017-09-15 13:19:27 +02:00
static void Prj_PutParams (void);
static void Prj_GetDataOfProject (struct Project *Prj,const char *Query);
static void Prj_ResetProject (struct Project *Prj);
static void Prj_GetProjectTxtFromDB (long PrjCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
static void Prj_PutParamPrjCod (long PrjCod);
static bool Prj_CheckIfSimilarProjectsExists (const char *Field,const char *Value,long PrjCod);
static void Prj_ShowLstGrpsToEditProject (long PrjCod);
static void Prj_CreateProject (struct Project *Prj,const char *Txt);
static void Prj_UpdateProject (struct Project *Prj,const char *Txt);
static bool Prj_CheckIfPrjIsAssociatedToGrps (long PrjCod);
static void Prj_RemoveAllTheGrpsAssociatedToAProject (long PrjCod);
static void Prj_CreateGrps (long PrjCod);
static void Prj_GetAndWriteNamesOfGrpsAssociatedToPrj (struct Project *Prj);
static bool Prj_CheckIfIBelongToCrsOrGrpsThisProject (long PrjCod);
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** List all the projects ****************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_SeeProjects (void)
{
/***** Get parameters *****/
2017-09-17 16:58:09 +02:00
Prj_GetParamPrjOrder ();
2017-09-15 13:19:27 +02:00
Grp_GetParamWhichGrps ();
2017-09-17 16:58:09 +02:00
Gbl.Prjs.CurrentPage = Pag_GetParamPagNum (Pag_PROJECTS);
2017-09-15 13:19:27 +02:00
/***** Show all the projects *****/
Prj_ShowAllProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** Show all the projects ****************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_ShowAllProjects (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Hlp_ASSESSMENT_Projects;
extern const char *Txt_Projects;
extern const char *Txt_No_projects;
2017-09-15 13:19:27 +02:00
struct Pagination Pagination;
2017-09-17 16:58:09 +02:00
unsigned NumPrj;
2017-09-15 13:19:27 +02:00
/***** Get list of projects *****/
Prj_GetListProjects ();
/***** Compute variables related to pagination *****/
2017-09-17 16:58:09 +02:00
Pagination.NumItems = Gbl.Prjs.Num;
Pagination.CurrentPage = (int) Gbl.Prjs.CurrentPage;
2017-09-15 13:19:27 +02:00
Pag_CalculatePagination (&Pagination);
2017-09-17 16:58:09 +02:00
Gbl.Prjs.CurrentPage = (unsigned) Pagination.CurrentPage;
2017-09-15 13:19:27 +02:00
/***** Write links to pages *****/
if (Pagination.MoreThanOnePage)
Pag_WriteLinksToPagesCentered (Pag_PROJECTS,
0,
&Pagination);
/***** Start box *****/
2017-09-17 16:58:09 +02:00
Box_StartBox ("100%",Txt_Projects,Prj_PutIconsListProjects,
Hlp_ASSESSMENT_Projects,Box_NOT_CLOSABLE);
2017-09-15 13:19:27 +02:00
/***** Select whether show only my groups or all groups *****/
if (Gbl.CurrentCrs.Grps.NumGrps)
Prj_PutFormToSelectWhichGroupsToShow ();
2017-09-17 16:58:09 +02:00
if (Gbl.Prjs.Num)
2017-09-15 13:19:27 +02:00
{
/***** Table head *****/
Tbl_StartTableWideMargin (2);
Prj_PutHeadForSeeing (false); // Not print view
/***** Write all the projects *****/
2017-09-17 16:58:09 +02:00
for (NumPrj = Pagination.FirstItemVisible;
NumPrj <= Pagination.LastItemVisible;
NumPrj++)
Prj_ShowOneProject (Gbl.Prjs.LstPrjCods[NumPrj - 1],
2017-09-18 17:26:20 +02:00
false); // Not print view
2017-09-15 13:19:27 +02:00
/***** End table *****/
Tbl_EndTable ();
}
else // No projects created
2017-09-17 16:58:09 +02:00
Ale_ShowAlert (Ale_INFO,Txt_No_projects);
2017-09-15 13:19:27 +02:00
/***** Button to create a new project *****/
if (Prj_CheckIfICanCreateProjects ())
Prj_PutButtonToCreateNewPrj ();
/***** Put link to register students *****/
Enr_CheckStdsAndPutButtonToRegisterStdsInCurrentCrs ();
/***** End box *****/
Box_EndBox ();
/***** Write again links to pages *****/
if (Pagination.MoreThanOnePage)
Pag_WriteLinksToPagesCentered (Pag_PROJECTS,
0,
&Pagination);
/***** Free list of projects *****/
Prj_FreeListProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************* Write header with fields of a project *******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutHeadForSeeing (bool PrintView)
{
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];
2017-09-17 18:55:02 +02:00
extern const char *Txt_Project;
2017-09-17 23:37:03 +02:00
extern const char *Txt_Preassigned_QUESTION;
2017-09-15 13:19:27 +02:00
Dat_StartEndTime_t Order;
fprintf (Gbl.F.Out,"<tr>"
"<th class=\"CONTEXT_COL\"></th>"); // Column for contextual icons
for (Order = Dat_START_TIME;
Order <= Dat_END_TIME;
Order++)
{
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
if (!PrintView)
{
2017-09-17 16:58:09 +02:00
Act_FormStart (ActSeePrj);
2017-09-15 13:19:27 +02:00
Grp_PutParamWhichGrps ();
2017-09-17 16:58:09 +02:00
Pag_PutHiddenParamPagNum (Pag_PROJECTS,Gbl.Prjs.CurrentPage);
2017-09-15 13:19:27 +02:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
Act_LinkFormSubmit (Txt_START_END_TIME_HELP[Order],"TIT_TBL",NULL);
2017-09-17 16:58:09 +02:00
if (Order == Gbl.Prjs.SelectedOrder)
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"<u>");
}
fprintf (Gbl.F.Out,"%s",Txt_START_END_TIME[Order]);
if (!PrintView)
{
2017-09-17 16:58:09 +02:00
if (Order == Gbl.Prjs.SelectedOrder)
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
Act_FormEnd ();
}
fprintf (Gbl.F.Out,"</th>");
}
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"<th class=\"CENTER_MIDDLE\">"
"%s"
"</th>"
"</tr>",
2017-09-17 18:55:02 +02:00
Txt_Project,
2017-09-17 23:37:03 +02:00
Txt_Preassigned_QUESTION);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************** Check if I can create projects ***********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static bool Prj_CheckIfICanCreateProjects (void)
{
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/***************** Put contextual icons in list of projects ******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutIconsListProjects (void)
{
/***** Put icon to create a new project *****/
if (Prj_CheckIfICanCreateProjects ())
Prj_PutIconToCreateNewPrj ();
/***** Put icon to show a figure *****/
2017-09-17 18:22:36 +02:00
Gbl.Stat.FigureType = Sta_PROJECTS;
2017-09-15 13:19:27 +02:00
Sta_PutIconToShowFigure ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************* Put icon to create a new project **********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutIconToCreateNewPrj (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Txt_New_project;
2017-09-15 13:19:27 +02:00
/***** Put form to create a new project *****/
2017-09-17 16:58:09 +02:00
Gbl.Prjs.PrjCodToEdit = -1L;
Lay_PutContextualLink (ActFrmNewPrj,NULL,Prj_PutParams,
2017-09-15 13:19:27 +02:00
"plus64x64.png",
2017-09-17 16:58:09 +02:00
Txt_New_project,NULL,
2017-09-15 13:19:27 +02:00
NULL);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Put button to create a new project *********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutButtonToCreateNewPrj (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Txt_New_project;
2017-09-15 13:19:27 +02:00
2017-09-17 16:58:09 +02:00
Gbl.Prjs.PrjCodToEdit = -1L;
Act_FormStart (ActFrmNewPrj);
2017-09-15 13:19:27 +02:00
Prj_PutParams ();
2017-09-17 16:58:09 +02:00
Btn_PutConfirmButton (Txt_New_project);
2017-09-15 13:19:27 +02:00
Act_FormEnd ();
}
/*****************************************************************************/
/***************** Put form to select which groups to show *******************/
/*****************************************************************************/
static void Prj_PutFormToSelectWhichGroupsToShow (void)
{
fprintf (Gbl.F.Out,"<div style=\"display:table; margin:0 auto;\">");
2017-09-17 16:58:09 +02:00
Grp_ShowFormToSelWhichGrps (ActSeePrj,Prj_ParamsWhichGroupsToShow);
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"</div>");
}
static void Prj_ParamsWhichGroupsToShow (void)
{
Prj_PutHiddenParamPrjOrder ();
2017-09-17 16:58:09 +02:00
Pag_PutHiddenParamPagNum (Pag_PROJECTS,Gbl.Prjs.CurrentPage);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************** Show print view of one project ***********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_PrintOneProject (void)
{
long PrjCod;
/***** Get the code of the project *****/
PrjCod = Prj_GetParamPrjCod ();
/***** Write header *****/
Lay_WriteHeaderClassPhoto (true,false,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentDeg.Deg.DegCod,
Gbl.CurrentCrs.Crs.CrsCod);
/***** Table head *****/
Tbl_StartTableWideMargin (2);
2017-09-17 23:37:03 +02:00
Prj_PutHeadForSeeing (true); // Print view
2017-09-15 13:19:27 +02:00
/***** Write project *****/
Prj_ShowOneProject (PrjCod,
2017-09-17 23:37:03 +02:00
true); // Print view
2017-09-15 13:19:27 +02:00
/***** End table *****/
Tbl_EndTable ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/***************************** Show one project ******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
static void Prj_ShowOneProject (long PrjCod,bool PrintView)
2017-09-15 13:19:27 +02:00
{
extern const char *Txt_Today;
2017-09-17 23:37:03 +02:00
extern const char *Txt_PREASSIGNED_TYPES[Prj_NUM_TYPES_PREASSIGNED];
2017-09-15 13:19:27 +02:00
extern const char *Txt_Yes;
extern const char *Txt_No;
static unsigned UniqueId = 0;
struct Project Prj;
char Txt[Cns_MAX_BYTES_TEXT + 1];
/***** Get data of this project *****/
2017-09-17 16:58:09 +02:00
Prj.PrjCod = PrjCod;
2017-09-15 13:19:27 +02:00
Prj_GetDataOfProjectByCod (&Prj);
/***** Write first row of data of this project *****/
/* Forms to remove/edit this project */
fprintf (Gbl.F.Out,"<tr>"
"<td rowspan=\"2\" class=\"CONTEXT_COL");
if (PrintView)
fprintf (Gbl.F.Out,"\">");
else
{
fprintf (Gbl.F.Out," COLOR%u\">",Gbl.RowEvenOdd);
2017-09-17 16:58:09 +02:00
Prj_PutFormsToRemEditOnePrj (Prj.PrjCod,Prj.Hidden);
2017-09-15 13:19:27 +02:00
}
fprintf (Gbl.F.Out,"</td>");
/* Start date/time */
UniqueId++;
fprintf (Gbl.F.Out,"<td id=\"asg_date_start_%u\" class=\"%s LEFT_BOTTOM",
UniqueId,
Prj.Hidden ? (Prj.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Prj.Open ? "DATE_GREEN" :
"DATE_RED"));
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
"<script type=\"text/javascript\">"
"writeLocalDateHMSFromUTC('asg_date_start_%u',%ld,"
"%u,'<br />','%s',true,true,0x7);"
"</script>"
"</td>",
UniqueId,Prj.TimeUTC[Dat_START_TIME],
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
/* End date/time */
UniqueId++;
fprintf (Gbl.F.Out,"<td id=\"asg_date_end_%u\" class=\"%s LEFT_BOTTOM",
UniqueId,
Prj.Hidden ? (Prj.Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Prj.Open ? "DATE_GREEN" :
"DATE_RED"));
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
"<script type=\"text/javascript\">"
"writeLocalDateHMSFromUTC('asg_date_end_%u',%ld,"
"%u,'<br />','%s',false,true,0x7);"
"</script>"
"</td>",
UniqueId,Prj.TimeUTC[Dat_END_TIME],
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
/* Project title */
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP");
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
"<div class=\"%s\">%s</div>",
Prj.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
Prj.Title);
fprintf (Gbl.F.Out,"</td>");
2017-09-17 23:37:03 +02:00
/* Preassigned? */
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"<td class=\"%s CENTER_TOP",
2017-09-17 23:37:03 +02:00
(Prj.Preassigned == Prj_PREASSIGNED) ? "DAT_N" :
"DAT");
2017-09-15 13:19:27 +02:00
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">"
2017-09-17 23:37:03 +02:00
"<img src=\"%s/%s64x64.png\""
2017-09-15 13:19:27 +02:00
" alt=\"%s\" title=\"%s\" class=\"ICO20x20\" />"
"<br />%s"
2017-09-17 23:37:03 +02:00
"</td>"
"</tr>",
2017-09-15 13:19:27 +02:00
Gbl.Prefs.IconsURL,
2017-09-17 23:37:03 +02:00
(Prj.Preassigned == Prj_PREASSIGNED) ? "usr" :
"usr_off",
Txt_PREASSIGNED_TYPES[Prj.Preassigned],
Txt_PREASSIGNED_TYPES[Prj.Preassigned],
(Prj.Preassigned == Prj_PREASSIGNED) ? Txt_Yes :
Txt_No);
2017-09-15 13:19:27 +02:00
/***** Write second row of data of this project *****/
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"LEFT_TOP");
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
/* Author of the project */
2017-09-17 16:58:09 +02:00
Prj_WritePrjAuthor (&Prj);
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"</td>");
/* Text of the project */
Prj_GetProjectTxtFromDB (Prj.PrjCod,Txt);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML
Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
2017-09-17 23:37:03 +02:00
fprintf (Gbl.F.Out,"<td colspan=\"2\" class=\"LEFT_TOP");
2017-09-15 13:19:27 +02:00
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
if (Gbl.CurrentCrs.Grps.NumGrps)
Prj_GetAndWriteNamesOfGrpsAssociatedToPrj (&Prj);
fprintf (Gbl.F.Out,"<p class=\"%s\">"
"%s"
"</p>"
"</td>"
"</tr>",
Prj.Hidden ? "DAT_LIGHT" :
"DAT",
Txt);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********************** Write the author of a project ***********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
static void Prj_WritePrjAuthor (struct Project *Prj)
2017-09-15 13:19:27 +02:00
{
Usr_WriteAuthor1Line (Prj->UsrCod,Prj->Hidden);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********* Get parameter with the type or order in list of projects **********/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
static void Prj_GetParamPrjOrder (void)
2017-09-15 13:19:27 +02:00
{
2017-09-17 16:58:09 +02:00
Gbl.Prjs.SelectedOrder = (Dat_StartEndTime_t)
2017-09-15 13:19:27 +02:00
Par_GetParToUnsignedLong ("Order",
0,
Dat_NUM_START_END_TIME - 1,
(unsigned long) Prj_ORDER_DEFAULT);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/***** Put a hidden parameter with the type of order in list of projects *****/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_PutHiddenParamPrjOrder (void)
{
2017-09-17 16:58:09 +02:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Prjs.SelectedOrder);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/****************** Put a link (form) to edit one project ********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
static void Prj_PutFormsToRemEditOnePrj (long PrjCod,bool Hidden)
2017-09-15 13:19:27 +02:00
{
2017-09-17 16:58:09 +02:00
Gbl.Prjs.PrjCodToEdit = PrjCod; // Used as parameter in contextual links
2017-09-15 13:19:27 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_TCH:
case Rol_SYS_ADM:
/***** Put form to remove project *****/
2017-09-17 16:58:09 +02:00
Ico_PutContextualIconToRemove (ActReqRemPrj,Prj_PutParams);
2017-09-15 13:19:27 +02:00
/***** Put form to hide/show project *****/
if (Hidden)
2017-09-17 16:58:09 +02:00
Ico_PutContextualIconToUnhide (ActShoPrj,Prj_PutParams);
2017-09-15 13:19:27 +02:00
else
2017-09-17 16:58:09 +02:00
Ico_PutContextualIconToHide (ActHidPrj,Prj_PutParams);
2017-09-15 13:19:27 +02:00
/***** Put form to edit project *****/
2017-09-17 16:58:09 +02:00
Ico_PutContextualIconToEdit (ActEdiOnePrj,Prj_PutParams);
2017-09-15 13:19:27 +02:00
// no break
case Rol_STD:
case Rol_NET:
/***** Put form to print project *****/
2017-09-17 16:58:09 +02:00
Ico_PutContextualIconToPrint (ActPrnOnePrj,Prj_PutParams);
2017-09-15 13:19:27 +02:00
break;
default:
break;
}
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************** Params used to edit a project ************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutParams (void)
{
2017-09-17 16:58:09 +02:00
if (Gbl.Prjs.PrjCodToEdit > 0)
Prj_PutParamPrjCod (Gbl.Prjs.PrjCodToEdit);
2017-09-15 13:19:27 +02:00
Prj_PutHiddenParamPrjOrder ();
Grp_PutParamWhichGrps ();
2017-09-17 16:58:09 +02:00
Pag_PutHiddenParamPagNum (Pag_PROJECTS,Gbl.Prjs.CurrentPage);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** List all the projects ****************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_GetListProjects (void)
{
char HiddenSubQuery[256];
char OrderBySubQuery[256];
char Query[2048];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2017-09-17 16:58:09 +02:00
unsigned NumPrj;
2017-09-15 13:19:27 +02:00
2017-09-17 16:58:09 +02:00
if (Gbl.Prjs.LstIsRead)
2017-09-15 13:19:27 +02:00
Prj_FreeListProjects ();
/***** Get list of projects from database *****/
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_TCH:
case Rol_SYS_ADM:
HiddenSubQuery[0] = '\0';
break;
default:
sprintf (HiddenSubQuery," AND Hidden='N'");
break;
}
2017-09-17 16:58:09 +02:00
switch (Gbl.Prjs.SelectedOrder)
2017-09-15 13:19:27 +02:00
{
case Dat_START_TIME:
sprintf (OrderBySubQuery,"StartTime DESC,EndTime DESC,Title DESC");
break;
case Dat_END_TIME:
sprintf (OrderBySubQuery,"EndTime DESC,StartTime DESC,Title DESC");
break;
}
if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS)
sprintf (Query,"SELECT PrjCod"
" FROM projects"
" WHERE CrsCod=%ld%s"
2017-09-17 16:58:09 +02:00
" AND (PrjCod NOT IN (SELECT PrjCod FROM prj_grp) OR"
" PrjCod IN (SELECT prj_grp.PrjCod FROM prj_grp,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld AND prj_grp.GrpCod=crs_grp_usr.GrpCod))"
2017-09-15 13:19:27 +02:00
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
HiddenSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
else // Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS
sprintf (Query,"SELECT PrjCod"
" FROM projects"
" WHERE CrsCod=%ld%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get projects");
2017-09-17 16:58:09 +02:00
if (NumRows) // Projects found...
2017-09-15 13:19:27 +02:00
{
2017-09-17 16:58:09 +02:00
Gbl.Prjs.Num = (unsigned) NumRows;
2017-09-15 13:19:27 +02:00
/***** Create list of projects *****/
2017-09-17 16:58:09 +02:00
if ((Gbl.Prjs.LstPrjCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
2017-09-15 13:19:27 +02:00
Lay_ShowErrorAndExit ("Not enough memory to store list of projects.");
/***** Get the projects codes *****/
2017-09-17 16:58:09 +02:00
for (NumPrj = 0;
NumPrj < Gbl.Prjs.Num;
NumPrj++)
2017-09-15 13:19:27 +02:00
{
/* Get next project code */
row = mysql_fetch_row (mysql_res);
2017-09-17 16:58:09 +02:00
if ((Gbl.Prjs.LstPrjCods[NumPrj] = Str_ConvertStrCodToLongCod (row[0])) < 0)
2017-09-15 13:19:27 +02:00
Lay_ShowErrorAndExit ("Error: wrong project code.");
}
}
else
2017-09-17 16:58:09 +02:00
Gbl.Prjs.Num = 0;
2017-09-15 13:19:27 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2017-09-17 16:58:09 +02:00
Gbl.Prjs.LstIsRead = true;
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************* Get project data using its code ***********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_GetDataOfProjectByCod (struct Project *Prj)
{
char Query[1024];
if (Prj->PrjCod > 0)
{
/***** Build query *****/
sprintf (Query,"SELECT PrjCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
2017-09-18 17:26:20 +02:00
"Title,Preassigned,URL"
2017-09-15 13:19:27 +02:00
" FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj->PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
/***** Get data of project *****/
Prj_GetDataOfProject (Prj,Query);
}
else
{
/***** Clear all project data *****/
Prj->PrjCod = -1L;
Prj_ResetProject (Prj);
}
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/**************************** Get project data *******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_GetDataOfProject (struct Project *Prj,const char *Query)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear all project data *****/
Prj_ResetProject (Prj);
/***** Get data of project from database *****/
if (DB_QuerySELECT (Query,&mysql_res,"can not get project data")) // Project found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of the project (row[0]) */
Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get whether the project is hidden or not (row[1]) */
Prj->Hidden = (row[1][0] == 'Y');
/* Get author of the project (row[2]) */
Prj->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get start date (row[3] holds the start UTC time) */
Prj->TimeUTC[Dat_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
/* Get end date (row[4] holds the end UTC time) */
Prj->TimeUTC[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]);
/* Get whether the project is open or closed (row(5)) */
Prj->Open = (row[5][0] == '1');
/* Get the title of the project (row[6]) */
Str_Copy (Prj->Title,row[6],
2017-09-17 23:37:03 +02:00
Prj_MAX_BYTES_PROJECT_TITLE);
2017-09-15 13:19:27 +02:00
/* Get the folder for the project files (row[7]) */
2017-09-17 23:37:03 +02:00
Prj->Preassigned = (row[7][0] == 'Y') ? Prj_PREASSIGNED :
Prj_NOT_PREASSIGNED;
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get the title of the project (row[8]) */
Str_Copy (Prj->URL,row[8],
Cns_MAX_BYTES_WWW);
2017-09-15 13:19:27 +02:00
/* Can I do this project? */
Prj->IBelongToCrsOrGrps = Prj_CheckIfIBelongToCrsOrGrpsThisProject (Prj->PrjCod);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** Clear all project data ***************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_ResetProject (struct Project *Prj)
{
if (Prj->PrjCod <= 0) // If > 0 ==> keep value
Prj->PrjCod = -1L;
Prj->PrjCod = -1L;
Prj->Hidden = false;
Prj->UsrCod = -1L;
Prj->TimeUTC[Dat_START_TIME] =
Prj->TimeUTC[Dat_END_TIME ] = (time_t) 0;
Prj->Open = false;
Prj->Title[0] = '\0';
2017-09-17 23:37:03 +02:00
Prj->Preassigned = Prj_NOT_PREASSIGNED;
2017-09-15 13:19:27 +02:00
Prj->IBelongToCrsOrGrps = false;
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*************************** Free list of projects ***************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_FreeListProjects (void)
{
2017-09-17 16:58:09 +02:00
if (Gbl.Prjs.LstIsRead && Gbl.Prjs.LstPrjCods)
2017-09-15 13:19:27 +02:00
{
/***** Free memory used by the list of projects *****/
2017-09-17 16:58:09 +02:00
free ((void *) Gbl.Prjs.LstPrjCods);
Gbl.Prjs.LstPrjCods = NULL;
Gbl.Prjs.Num = 0;
Gbl.Prjs.LstIsRead = false;
2017-09-15 13:19:27 +02:00
}
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********************** Get project text from database ***********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_GetProjectTxtFromDB (long PrjCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get text of project from database *****/
sprintf (Query,"SELECT Txt FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get project text");
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
Str_Copy (Txt,row[0],
Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumRows > 1)
Lay_ShowErrorAndExit ("Error when getting project text.");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************* Write parameter with code of project ********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_PutParamPrjCod (long PrjCod)
{
Par_PutHiddenParamLong ("PrjCod",PrjCod);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Get parameter with code of project *********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
long Prj_GetParamPrjCod (void)
{
/***** Get code of project *****/
return Par_GetParToLong ("PrjCod");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*************** Ask for confirmation of removing a project ******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_ReqRemProject (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Txt_Do_you_really_want_to_remove_the_project_X;
extern const char *Txt_Remove_project;
2017-09-15 13:19:27 +02:00
struct Project Prj;
/***** Get parameters *****/
2017-09-17 16:58:09 +02:00
Prj_GetParamPrjOrder ();
2017-09-15 13:19:27 +02:00
Grp_GetParamWhichGrps ();
2017-09-17 16:58:09 +02:00
Gbl.Prjs.CurrentPage = Pag_GetParamPagNum (Pag_PROJECTS);
2017-09-15 13:19:27 +02:00
/***** Get project code *****/
if ((Prj.PrjCod = Prj_GetParamPrjCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of project is missing.");
/***** Get data of the project from database *****/
Prj_GetDataOfProjectByCod (&Prj);
/***** Show question and button to remove the project *****/
2017-09-17 16:58:09 +02:00
Gbl.Prjs.PrjCodToEdit = Prj.PrjCod;
sprintf (Gbl.Alert.Txt,Txt_Do_you_really_want_to_remove_the_project_X,
2017-09-15 13:19:27 +02:00
Prj.Title);
Ale_ShowAlertAndButton (Ale_QUESTION,Gbl.Alert.Txt,
2017-09-17 16:58:09 +02:00
ActRemPrj,NULL,NULL,Prj_PutParams,
Btn_REMOVE_BUTTON,Txt_Remove_project);
2017-09-15 13:19:27 +02:00
/***** Show projects again *****/
Prj_SeeProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/***************************** Remove a project ******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RemoveProject (void)
{
2017-09-17 18:55:02 +02:00
extern const char *Txt_Project_X_removed;
2017-09-15 13:19:27 +02:00
char Query[512];
struct Project Prj;
/***** Get project code *****/
if ((Prj.PrjCod = Prj_GetParamPrjCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of project is missing.");
/***** Get data of the project from database *****/
Prj_GetDataOfProjectByCod (&Prj); // Inside this function, the course is checked to be the current one
/***** Remove all the groups of this project *****/
Prj_RemoveAllTheGrpsAssociatedToAProject (Prj.PrjCod);
/***** Remove project *****/
sprintf (Query,"DELETE FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryDELETE (Query,"can not remove project");
/***** Write message to show the change made *****/
2017-09-17 18:55:02 +02:00
sprintf (Gbl.Alert.Txt,Txt_Project_X_removed,
2017-09-15 13:19:27 +02:00
Prj.Title);
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
/***** Show projects again *****/
Prj_SeeProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/****************************** Hide a project *******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_HideProject (void)
{
2017-09-17 18:55:02 +02:00
extern const char *Txt_Project_X_is_now_hidden;
2017-09-15 13:19:27 +02:00
char Query[512];
struct Project Prj;
/***** Get project code *****/
if ((Prj.PrjCod = Prj_GetParamPrjCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of project is missing.");
/***** Get data of the project from database *****/
Prj_GetDataOfProjectByCod (&Prj);
/***** Hide project *****/
sprintf (Query,"UPDATE projects SET Hidden='Y'"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryUPDATE (Query,"can not hide project");
/***** Write message to show the change made *****/
2017-09-17 18:55:02 +02:00
sprintf (Gbl.Alert.Txt,Txt_Project_X_is_now_hidden,
2017-09-15 13:19:27 +02:00
Prj.Title);
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
/***** Show projects again *****/
Prj_SeeProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/****************************** Show a project *******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_ShowProject (void)
{
2017-09-17 18:55:02 +02:00
extern const char *Txt_Project_X_is_now_visible;
2017-09-15 13:19:27 +02:00
char Query[512];
struct Project Prj;
/***** Get project code *****/
if ((Prj.PrjCod = Prj_GetParamPrjCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of project is missing.");
/***** Get data of the project from database *****/
Prj_GetDataOfProjectByCod (&Prj);
/***** Hide project *****/
sprintf (Query,"UPDATE projects SET Hidden='N'"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj.PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryUPDATE (Query,"can not show project");
/***** Write message to show the change made *****/
2017-09-17 18:55:02 +02:00
sprintf (Gbl.Alert.Txt,Txt_Project_X_is_now_visible,
2017-09-15 13:19:27 +02:00
Prj.Title);
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
/***** Show projects again *****/
Prj_SeeProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/********** Check if the title or the folder of a project exists *************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static bool Prj_CheckIfSimilarProjectsExists (const char *Field,const char *Value,long PrjCod)
{
2017-09-17 23:37:03 +02:00
char Query[256 + Prj_MAX_BYTES_PROJECT_TITLE];
2017-09-15 13:19:27 +02:00
/***** Get number of projects with a field value from database *****/
sprintf (Query,"SELECT COUNT(*) FROM projects"
" WHERE CrsCod=%ld AND %s='%s' AND PrjCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod,Field,Value,PrjCod);
return (DB_QueryCOUNT (Query,"can not get similar projects") != 0);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Put a form to create a new project *********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RequestCreatOrEditPrj (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Hlp_ASSESSMENT_Projects_new_project;
extern const char *Hlp_ASSESSMENT_Projects_edit_project;
2017-09-15 13:19:27 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2017-09-17 16:58:09 +02:00
extern const char *Txt_New_project;
extern const char *Txt_Edit_project;
2017-09-15 13:19:27 +02:00
extern const char *Txt_Title;
2017-09-17 23:37:03 +02:00
extern const char *Txt_Preassigned_QUESTION;
extern const char *Txt_No;
extern const char *Txt_Yes;
2017-09-15 13:19:27 +02:00
extern const char *Txt_Description;
2017-09-18 01:06:51 +02:00
extern const char *Txt_URL;
2017-09-17 16:58:09 +02:00
extern const char *Txt_Create_project;
2017-09-15 13:19:27 +02:00
extern const char *Txt_Save;
struct Project Prj;
2017-09-17 18:55:02 +02:00
bool ItsANewProject;
2017-09-15 13:19:27 +02:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
/***** Get parameters *****/
2017-09-17 16:58:09 +02:00
Prj_GetParamPrjOrder ();
2017-09-15 13:19:27 +02:00
Grp_GetParamWhichGrps ();
2017-09-17 16:58:09 +02:00
Gbl.Prjs.CurrentPage = Pag_GetParamPagNum (Pag_PROJECTS);
2017-09-15 13:19:27 +02:00
/***** Get the code of the project *****/
2017-09-17 18:55:02 +02:00
ItsANewProject = ((Prj.PrjCod = Prj_GetParamPrjCod ()) == -1L);
2017-09-15 13:19:27 +02:00
/***** Get from the database the data of the project *****/
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-15 13:19:27 +02:00
{
/* Initialize to empty project */
Prj.PrjCod = -1L;
Prj.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
Prj.TimeUTC[Dat_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours
Prj.Open = true;
Prj.Title[0] = '\0';
2017-09-17 23:37:03 +02:00
Prj.Preassigned = Prj_NOT_PREASSIGNED;
2017-09-18 01:06:51 +02:00
Prj.URL[0] = '\0';
2017-09-15 13:19:27 +02:00
Prj.IBelongToCrsOrGrps = false;
}
else
{
/* Get data of the project from database */
Prj_GetDataOfProjectByCod (&Prj);
/* Get text of the project from database */
Prj_GetProjectTxtFromDB (Prj.PrjCod,Txt);
}
/***** Start form *****/
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-15 13:19:27 +02:00
{
2017-09-17 16:58:09 +02:00
Act_FormStart (ActNewPrj);
Gbl.Prjs.PrjCodToEdit = -1L;
2017-09-15 13:19:27 +02:00
}
else
{
2017-09-17 16:58:09 +02:00
Act_FormStart (ActChgPrj);
Gbl.Prjs.PrjCodToEdit = Prj.PrjCod;
2017-09-15 13:19:27 +02:00
}
Prj_PutParams ();
/***** Start box and table *****/
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-17 16:58:09 +02:00
Box_StartBoxTable (NULL,Txt_New_project,NULL,
Hlp_ASSESSMENT_Projects_new_project,Box_NOT_CLOSABLE,2);
2017-09-15 13:19:27 +02:00
else
2017-09-17 16:58:09 +02:00
Box_StartBoxTable (NULL,Txt_Edit_project,NULL,
Hlp_ASSESSMENT_Projects_edit_project,Box_NOT_CLOSABLE,2);
2017-09-15 13:19:27 +02:00
/***** Project title *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"Title\" class=\"%s\">%s:</label>"
"</td>"
"<td class=\"LEFT_MIDDLE\">"
"<input type=\"text\" id=\"Title\" name=\"Title\""
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],Txt_Title,
2017-09-17 23:37:03 +02:00
Prj_MAX_CHARS_PROJECT_TITLE,Prj.Title);
2017-09-15 13:19:27 +02:00
/***** Project start and end dates *****/
Dat_PutFormStartEndClientLocalDateTimes (Prj.TimeUTC,Dat_FORM_SECONDS_ON);
2017-09-17 23:37:03 +02:00
/***** Preassigned? *****/
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">"
2017-09-17 23:37:03 +02:00
"<select name=\"Preassigned\">",
2017-09-15 13:19:27 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2017-09-17 23:37:03 +02:00
Txt_Preassigned_QUESTION);
fprintf (Gbl.F.Out,"<option value=\"N\"");
if (Prj.Preassigned == Prj_NOT_PREASSIGNED)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_No);
fprintf (Gbl.F.Out,"<option value=\"Y\"");
if (Prj.Preassigned == Prj_PREASSIGNED)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_Yes);
fprintf (Gbl.F.Out,"</select>"
"</td>"
"</tr>");
2017-09-15 13:19:27 +02:00
/***** Project text *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_TOP\">"
"<label for=\"Txt\" class=\"%s\">%s:</label>"
"</td>"
"<td class=\"LEFT_TOP\">"
"<textarea id=\"Txt\" name=\"Txt\""
" cols=\"60\" rows=\"10\">",
The_ClassForm[Gbl.Prefs.Theme],Txt_Description);
2017-09-17 18:55:02 +02:00
if (!ItsANewProject)
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"%s",Txt);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
2017-09-18 01:06:51 +02:00
/***** URL for additional info *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"WWW\" class=\"%s\">%s:</label>"
"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"<input type=\"url\" id=\"URL\" name=\"URL\""
" size=\"45\" maxlength=\"%u\" value=\"%s\" />"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],
Txt_URL,
Cns_MAX_CHARS_WWW,Prj.URL);
2017-09-15 13:19:27 +02:00
/***** Groups *****/
Prj_ShowLstGrpsToEditProject (Prj.PrjCod);
/***** End table, send button and end box *****/
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-17 16:58:09 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_project);
2017-09-15 13:19:27 +02:00
else
Box_EndBoxTableWithButton (Btn_CONFIRM_BUTTON,Txt_Save);
/***** End form *****/
Act_FormEnd ();
/***** Show current projects, if any *****/
Prj_ShowAllProjects ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/****************** Show list of groups to edit and project ******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_ShowLstGrpsToEditProject (long PrjCod)
{
extern const char *Hlp_USERS_Groups;
extern const char *The_ClassForm[The_NUM_THEMES];
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);
if (Gbl.CurrentCrs.Grps.GrpTypes.Num)
{
/***** Start box and table *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_TOP\">"
"%s:"
"</td>"
"<td class=\"LEFT_TOP\">",
The_ClassForm[Gbl.Prefs.Theme],
Txt_Groups);
Box_StartBoxTable ("100%",NULL,NULL,
Hlp_USERS_Groups,Box_NOT_CLOSABLE,0);
/***** First row: checkbox to select the whole course *****/
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"7\" class=\"DAT LEFT_MIDDLE\">"
"<label>"
"<input type=\"checkbox\" id=\"WholeCrs\" name=\"WholeCrs\" value=\"Y\"");
if (!Prj_CheckIfPrjIsAssociatedToGrps (PrjCod))
fprintf (Gbl.F.Out," checked=\"checked\"");
fprintf (Gbl.F.Out," onclick=\"uncheckChildren(this,'GrpCods')\" />"
"%s %s"
"</label>"
"</td>"
"</tr>",
Txt_The_whole_course,Gbl.CurrentCrs.Crs.ShrtName);
/***** List the groups for each group type *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
if (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps)
2017-09-17 16:58:09 +02:00
Grp_ListGrpsToEditAsgPrjAttSvyGam (&Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp],
PrjCod,Grp_PROJECT);
2017-09-15 13:19:27 +02:00
/***** End table and box *****/
Box_EndBoxTable ();
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** Free list of groups types and groups in this course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Receive form to create a new project *******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RecFormProject (void)
{
2017-09-17 16:58:09 +02:00
extern const char *Txt_Already_existed_a_project_with_the_title_X;
extern const char *Txt_You_must_specify_the_title_of_the_project;
extern const char *Txt_Created_new_project_X;
extern const char *Txt_The_project_has_been_modified;
struct Project OldPrj; // Current assigment data in database
struct Project NewPrj; // Project data received from form
2017-09-17 18:55:02 +02:00
bool ItsANewProject;
bool NewProjectIsCorrect = true;
2017-09-15 13:19:27 +02:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2017-09-18 17:26:20 +02:00
/***** Get parameters from form *****/
/* Get the code of the project */
2017-09-17 16:58:09 +02:00
NewPrj.PrjCod = Prj_GetParamPrjCod ();
2017-09-17 18:55:02 +02:00
ItsANewProject = (NewPrj.PrjCod < 0);
2017-09-15 13:19:27 +02:00
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-15 13:19:27 +02:00
{
2017-09-18 17:26:20 +02:00
/* Reset old (current, not existing) project data */
2017-09-17 16:58:09 +02:00
OldPrj.PrjCod = -1L;
Prj_ResetProject (&OldPrj);
2017-09-15 13:19:27 +02:00
}
else
{
2017-09-18 17:26:20 +02:00
/* Get data of the old (current) project from database */
2017-09-17 16:58:09 +02:00
OldPrj.PrjCod = NewPrj.PrjCod;
Prj_GetDataOfProjectByCod (&OldPrj);
2017-09-15 13:19:27 +02:00
}
2017-09-18 17:26:20 +02:00
/* Get start/end date-times */
2017-09-17 16:58:09 +02:00
NewPrj.TimeUTC[Dat_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
NewPrj.TimeUTC[Dat_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get project title */
2017-09-17 23:37:03 +02:00
Par_GetParToText ("Title",NewPrj.Title,Prj_MAX_BYTES_PROJECT_TITLE);
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get folder name where to send works of the project */
2017-09-17 23:37:03 +02:00
NewPrj.Preassigned = (Par_GetParToBool ("Preassigned")) ? Prj_PREASSIGNED :
Prj_NOT_PREASSIGNED;
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get project text */
2017-09-15 13:19:27 +02:00
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
2017-09-18 17:26:20 +02:00
/* Get degree WWW */
Par_GetParToText ("URL",NewPrj.URL,Cns_MAX_BYTES_WWW);
2017-09-15 13:19:27 +02:00
/***** Adjust dates *****/
2017-09-17 16:58:09 +02:00
if (NewPrj.TimeUTC[Dat_START_TIME] == 0)
NewPrj.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
if (NewPrj.TimeUTC[Dat_END_TIME] == 0)
NewPrj.TimeUTC[Dat_END_TIME] = NewPrj.TimeUTC[Dat_START_TIME] + 2 * 60 * 60; // +2 hours
2017-09-15 13:19:27 +02:00
/***** Check if title is correct *****/
2017-09-17 16:58:09 +02:00
if (NewPrj.Title[0]) // If there's a project title
2017-09-15 13:19:27 +02:00
{
/* If title of project was in database... */
2017-09-17 16:58:09 +02:00
if (Prj_CheckIfSimilarProjectsExists ("Title",NewPrj.Title,NewPrj.PrjCod))
2017-09-15 13:19:27 +02:00
{
2017-09-17 18:55:02 +02:00
NewProjectIsCorrect = false;
2017-09-17 16:58:09 +02:00
sprintf (Gbl.Alert.Txt,Txt_Already_existed_a_project_with_the_title_X,
NewPrj.Title);
2017-09-15 13:19:27 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
}
}
else // If there is not a project title
{
2017-09-17 18:55:02 +02:00
NewProjectIsCorrect = false;
2017-09-17 16:58:09 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_project);
2017-09-15 13:19:27 +02:00
}
/***** Create a new project or update an existing one *****/
2017-09-17 18:55:02 +02:00
if (NewProjectIsCorrect)
2017-09-15 13:19:27 +02:00
{
/* Get groups for this projects */
Grp_GetParCodsSeveralGrps ();
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-15 13:19:27 +02:00
{
2017-09-17 16:58:09 +02:00
Prj_CreateProject (&NewPrj,Txt); // Add new project to database
2017-09-15 13:19:27 +02:00
/***** Write success message *****/
2017-09-17 16:58:09 +02:00
sprintf (Gbl.Alert.Txt,Txt_Created_new_project_X,NewPrj.Title);
2017-09-15 13:19:27 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
}
2017-09-17 23:37:03 +02:00
else if (NewProjectIsCorrect)
{
Prj_UpdateProject (&NewPrj,Txt);
/***** Write success message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_project_has_been_modified);
}
2017-09-15 13:19:27 +02:00
/* Free memory for list of selected groups */
Grp_FreeListCodSelectedGrps ();
/***** Show projects again *****/
Prj_SeeProjects ();
}
else
// TODO: The form should be filled with partial data, now is always empty
Prj_RequestCreatOrEditPrj ();
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** Create a new project *****************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_CreateProject (struct Project *Prj,const char *Txt)
{
char Query[1024 +
2017-09-17 23:37:03 +02:00
Prj_MAX_BYTES_PROJECT_TITLE +
2017-09-18 17:26:20 +02:00
Cns_MAX_BYTES_TEXT +
Cns_MAX_BYTES_WWW];
2017-09-15 13:19:27 +02:00
/***** Create a new project *****/
sprintf (Query,"INSERT INTO projects"
2017-09-18 17:26:20 +02:00
" (CrsCod,UsrCod,StartTime,EndTime,Title,Preassigned,Txt,URL)"
2017-09-15 13:19:27 +02:00
" VALUES"
" (%ld,%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
2017-09-18 17:26:20 +02:00
"'%s','%c','%s','%s')",
2017-09-15 13:19:27 +02:00
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Prj->TimeUTC[Dat_START_TIME],
Prj->TimeUTC[Dat_END_TIME ],
Prj->Title,
2017-09-17 23:37:03 +02:00
Prj->Preassigned == Prj_PREASSIGNED ? 'Y' :
'N',
2017-09-18 17:26:20 +02:00
Txt,
Prj->URL);
2017-09-15 13:19:27 +02:00
Prj->PrjCod = DB_QueryINSERTandReturnCode (Query,"can not create new project");
/***** Create groups *****/
if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps)
Prj_CreateGrps (Prj->PrjCod);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********************** Update an existing project **************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_UpdateProject (struct Project *Prj,const char *Txt)
{
char Query[1024 +
2017-09-17 23:37:03 +02:00
Prj_MAX_BYTES_PROJECT_TITLE +
2017-09-18 17:26:20 +02:00
Cns_MAX_BYTES_TEXT +
Cns_MAX_BYTES_WWW];
2017-09-15 13:19:27 +02:00
/***** Update the data of the project *****/
sprintf (Query,"UPDATE projects SET "
"StartTime=FROM_UNIXTIME(%ld),"
"EndTime=FROM_UNIXTIME(%ld),"
2017-09-18 17:26:20 +02:00
"Title='%s',Preassigned='%c',Txt='%s',URL='%s'"
2017-09-15 13:19:27 +02:00
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj->TimeUTC[Dat_START_TIME],
Prj->TimeUTC[Dat_END_TIME ],
Prj->Title,
2017-09-17 23:37:03 +02:00
Prj->Preassigned == Prj_PREASSIGNED ? 'Y' :
'N',
2017-09-15 13:19:27 +02:00
Txt,
2017-09-18 17:26:20 +02:00
Prj->URL,
2017-09-15 13:19:27 +02:00
Prj->PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
DB_QueryUPDATE (Query,"can not update project");
/***** Update groups *****/
/* Remove old groups */
Prj_RemoveAllTheGrpsAssociatedToAProject (Prj->PrjCod);
/* Create new groups */
if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps)
Prj_CreateGrps (Prj->PrjCod);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************* Check if a project is associated to any group *****************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static bool Prj_CheckIfPrjIsAssociatedToGrps (long PrjCod)
{
char Query[256];
/***** Get if a project is associated to a group from database *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*) FROM prj_grp WHERE PrjCod=%ld",
2017-09-15 13:19:27 +02:00
PrjCod);
return (DB_QueryCOUNT (Query,"can not check if a project is associated to groups") != 0);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************** Check if a project is associated to a group ******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
bool Prj_CheckIfPrjIsAssociatedToGrp (long PrjCod,long GrpCod)
{
char Query[256];
/***** Get if a project is associated to a group from database *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*) FROM prj_grp"
2017-09-15 13:19:27 +02:00
" WHERE PrjCod=%ld AND GrpCod=%ld",
PrjCod,GrpCod);
return (DB_QueryCOUNT (Query,"can not check if a project is associated to a group") != 0);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********************** Remove groups of a project **************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_RemoveAllTheGrpsAssociatedToAProject (long PrjCod)
{
char Query[256];
/***** Remove groups of the project *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"DELETE FROM prj_grp WHERE PrjCod=%ld",PrjCod);
2017-09-15 13:19:27 +02:00
DB_QueryDELETE (Query,"can not remove the groups associated to a project");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/****************** Remove one group from all the projects *******************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RemoveGroup (long GrpCod)
{
char Query[256];
/***** Remove group from all the projects *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"DELETE FROM prj_grp WHERE GrpCod=%ld",GrpCod);
2017-09-15 13:19:27 +02:00
DB_QueryDELETE (Query,"can not remove group from the associations between projects and groups");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************* Remove groups of one type from all the projects ***************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RemoveGroupsOfType (long GrpTypCod)
{
char Query[256];
/***** Remove group from all the projects *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"DELETE FROM prj_grp USING crs_grp,prj_grp"
2017-09-15 13:19:27 +02:00
" WHERE crs_grp.GrpTypCod=%ld"
2017-09-17 16:58:09 +02:00
" AND crs_grp.GrpCod=prj_grp.GrpCod",
2017-09-15 13:19:27 +02:00
GrpTypCod);
DB_QueryDELETE (Query,"can not remove groups of a type from the associations between projects and groups");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********************** Create groups of a project **************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_CreateGrps (long PrjCod)
{
unsigned NumGrpSel;
char Query[256];
/***** Create groups of the project *****/
for (NumGrpSel = 0;
NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps;
NumGrpSel++)
{
/* Create group */
2017-09-17 16:58:09 +02:00
sprintf (Query,"INSERT INTO prj_grp"
2017-09-15 13:19:27 +02:00
" (PrjCod,GrpCod)"
" VALUES"
" (%ld,%ld)",
PrjCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]);
DB_QueryINSERT (Query,"can not associate a group to a project");
}
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********** Get and write the names of the groups of a project **************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static void Prj_GetAndWriteNamesOfGrpsAssociatedToPrj (struct Project *Prj)
{
extern const char *Txt_Group;
extern const char *Txt_Groups;
extern const char *Txt_and;
extern const char *Txt_The_whole_course;
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow;
unsigned long NumRows;
/***** Get groups associated to a project from database *****/
sprintf (Query,"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
2017-09-17 16:58:09 +02:00
" FROM prj_grp,crs_grp,crs_grp_types"
" WHERE prj_grp.PrjCod=%ld"
" AND prj_grp.GrpCod=crs_grp.GrpCod"
2017-09-15 13:19:27 +02:00
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Prj->PrjCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get groups of a project");
/***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
Prj->Hidden ? "ASG_GRP_LIGHT" :
"ASG_GRP",
(NumRows == 1) ? Txt_Group :
Txt_Groups);
/***** Write groups *****/
if (NumRows) // Groups found...
{
/* Get and write the group types and names */
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Write group type name and group name */
fprintf (Gbl.F.Out,"%s %s",row[0],row[1]);
if (NumRows >= 2)
{
if (NumRow == NumRows-2)
fprintf (Gbl.F.Out," %s ",Txt_and);
if (NumRows >= 3)
if (NumRow < NumRows-2)
fprintf (Gbl.F.Out,", ");
}
}
}
else
fprintf (Gbl.F.Out,"%s %s",
Txt_The_whole_course,Gbl.CurrentCrs.Crs.ShrtName);
fprintf (Gbl.F.Out,"</div>");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Remove all the projects of a course ********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
void Prj_RemoveCrsProjects (long CrsCod)
{
char Query[512];
/***** Remove groups *****/
2017-09-17 16:58:09 +02:00
sprintf (Query,"DELETE FROM prj_grp USING projects,prj_grp"
2017-09-15 13:19:27 +02:00
" WHERE projects.CrsCod=%ld"
2017-09-17 16:58:09 +02:00
" AND projects.PrjCod=prj_grp.PrjCod",
2017-09-15 13:19:27 +02:00
CrsCod);
DB_QueryDELETE (Query,"can not remove all the groups associated to projects of a course");
/***** Remove projects *****/
sprintf (Query,"DELETE FROM projects WHERE CrsCod=%ld",CrsCod);
DB_QueryDELETE (Query,"can not remove all the projects of a course");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********** Check if I belong to any of the groups of a project *************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
static bool Prj_CheckIfIBelongToCrsOrGrpsThisProject (long PrjCod)
{
char Query[512];
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
case Rol_NET:
case Rol_TCH:
// Students and teachers can do projects depending on groups
/***** Get if I can do a project from database *****/
sprintf (Query,"SELECT COUNT(*) FROM projects"
" WHERE PrjCod=%ld"
" AND "
"("
2017-09-17 16:58:09 +02:00
"PrjCod NOT IN (SELECT PrjCod FROM prj_grp)" // Project is for the whole course
2017-09-15 13:19:27 +02:00
" OR "
"PrjCod IN" // Project is for specific groups
2017-09-17 16:58:09 +02:00
" (SELECT prj_grp.PrjCod FROM prj_grp,crs_grp_usr"
2017-09-15 13:19:27 +02:00
" WHERE crs_grp_usr.UsrCod=%ld"
2017-09-17 16:58:09 +02:00
" AND prj_grp.GrpCod=crs_grp_usr.GrpCod)"
2017-09-15 13:19:27 +02:00
")",
PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod);
return (DB_QueryCOUNT (Query,"can not check if I can do a project") != 0);
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
// Admins can view projects
return true;
default:
return false;
}
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Get number of projects in a course *********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
unsigned Prj_GetNumProjectsInCrs (long CrsCod)
{
char Query[256];
/***** Get number of projects in a course from database *****/
sprintf (Query,"SELECT COUNT(*) FROM projects WHERE CrsCod=%ld",
CrsCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of projects in course");
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/******************** Get number of courses with projects ********************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
// Returns the number of courses with projects
// in this location (all the platform, current degree or current course)
unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with projects from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod>0");
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM institutions,centres,degrees,courses,projects"
" 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=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of courses with projects");
/***** 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 projects.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** Get number of projects ***************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-17 18:55:02 +02:00
// Returns the number of projects in this location
2017-09-15 13:19:27 +02:00
2017-09-17 16:58:09 +02:00
unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
2017-09-15 13:19:27 +02:00
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-09-17 16:58:09 +02:00
unsigned NumProjects;
2017-09-15 13:19:27 +02:00
/***** Get number of projects from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM projects"
" WHERE CrsCod>0");
break;
case Sco_SCOPE_CTY:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
2017-09-17 16:58:09 +02:00
sprintf (Query,"SELECT COUNT(*)"
2017-09-15 13:19:27 +02:00
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of projects");
/***** Get number of projects *****/
row = mysql_fetch_row (mysql_res);
2017-09-17 16:58:09 +02:00
if (sscanf (row[0],"%u",&NumProjects) != 1)
2017-09-15 13:19:27 +02:00
Lay_ShowErrorAndExit ("Error when getting number of projects.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2017-09-17 16:58:09 +02:00
return NumProjects;
2017-09-15 13:19:27 +02:00
}