swad-core/swad_project.c

1696 lines
60 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_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;
/*****************************************************************************/
2017-09-19 16:45:42 +02:00
/************************* Public constants and types ************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-19 16:45:42 +02:00
// Related with user's roles in a project
/*
Don't change these numbers! They are used in database
*/
2017-09-15 13:19:27 +02:00
2017-09-19 16:45:42 +02:00
#define Prj_NUM_ROLES_IN_PROJECT 4
typedef enum
{
Prj_ROLE_UNK = 0, // Unknown
Prj_ROLE_STD = 1, // Student
Prj_ROLE_TUT = 2, // Tutor
Prj_ROLE_REV = 3, // Reviewer
} Prj_RoleInProject_t;
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
/***************************** 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);
2017-09-19 01:12:05 +02:00
static void Prj_ShowOneProject (struct Project *Prj,bool PrintView);
2017-09-20 14:06:24 +02:00
static void Prj_ShowOneProjectTxtRow (struct Project *Prj,bool PrintView,
const char *Label,char *TxtField);
2017-09-19 16:45:42 +02:00
static void Prj_WriteUsrs (long PrjCod,Prj_RoleInProject_t RoleInProject);
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
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_PutParamPrjCod (long PrjCod);
static bool Prj_CheckIfSimilarProjectsExists (const char *Field,const char *Value,long PrjCod);
2017-09-19 01:12:05 +02:00
static void Prj_AllocMemProject (struct Project *Prj);
static void Prj_FreeMemProject (struct Project *Prj);
static void Prj_CreateProject (struct Project *Prj);
static void Prj_UpdateProject (struct Project *Prj);
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_SeeProjects (void)
{
/***** Get parameters *****/
2017-09-17 16:58:09 +02:00
Prj_GetParamPrjOrder ();
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-19 01:12:05 +02:00
struct Project Prj;
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
2017-09-17 16:58:09 +02:00
if (Gbl.Prjs.Num)
2017-09-15 13:19:27 +02:00
{
2017-09-19 01:12:05 +02:00
/***** Allocate memory for the project *****/
Prj_AllocMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** Table head *****/
2017-09-19 14:33:57 +02:00
Tbl_StartTableWideMargin (5);
2017-09-15 13:19:27 +02:00
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++)
2017-09-19 01:12:05 +02:00
{
Prj.PrjCod = Gbl.Prjs.LstPrjCods[NumPrj - 1];
Prj_ShowOneProject (&Prj,
2017-09-18 17:26:20 +02:00
false); // Not print view
2017-09-19 01:12:05 +02:00
}
2017-09-15 13:19:27 +02:00
/***** End table *****/
Tbl_EndTable ();
2017-09-19 01:12:05 +02:00
/***** Free memory of the project *****/
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
}
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);
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 ();
}
/*****************************************************************************/
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)
{
2017-09-19 01:12:05 +02:00
struct Project Prj;
/***** Allocate memory for the project *****/
Prj_AllocMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** Get the code of the project *****/
2017-09-19 01:12:05 +02:00
Prj.PrjCod = Prj_GetParamPrjCod ();
2017-09-15 13:19:27 +02:00
/***** 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 *****/
2017-09-19 01:12:05 +02:00
Prj_ShowOneProject (&Prj,
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-19 01:12:05 +02:00
/***** Free memory of the project *****/
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/***************************** Show one project ******************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-19 01:12:05 +02:00
static void Prj_ShowOneProject (struct Project *Prj,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;
2017-09-19 09:55:09 +02:00
extern const char *Txt_Description;
extern const char *Txt_Required_knowledge;
extern const char *Txt_Required_materials;
2017-09-19 15:06:19 +02:00
extern const char *Txt_Tutors;
2017-09-20 13:56:48 +02:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2017-09-15 13:19:27 +02:00
static unsigned UniqueId = 0;
/***** Get data of this project *****/
2017-09-19 01:12:05 +02:00
Prj_GetDataOfProjectByCod (Prj);
2017-09-15 13:19:27 +02:00
/***** Write first row of data of this project *****/
/* Forms to remove/edit this project */
fprintf (Gbl.F.Out,"<tr>"
2017-09-20 13:56:48 +02:00
"<td rowspan=\"6\" class=\"CONTEXT_COL");
2017-09-15 13:19:27 +02:00
if (PrintView)
fprintf (Gbl.F.Out,"\">");
else
{
fprintf (Gbl.F.Out," COLOR%u\">",Gbl.RowEvenOdd);
2017-09-19 01:12:05 +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,
2017-09-19 01:12:05 +02:00
Prj->Hidden ? (Prj->Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Prj->Open ? "DATE_GREEN" :
"DATE_RED"));
2017-09-15 13:19:27 +02:00
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>",
2017-09-19 01:12:05 +02:00
UniqueId,Prj->TimeUTC[Dat_START_TIME],
2017-09-15 13:19:27 +02:00
(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,
2017-09-19 01:12:05 +02:00
Prj->Hidden ? (Prj->Open ? "DATE_GREEN_LIGHT" :
"DATE_RED_LIGHT") :
(Prj->Open ? "DATE_GREEN" :
"DATE_RED"));
2017-09-15 13:19:27 +02:00
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>",
2017-09-19 01:12:05 +02:00
UniqueId,Prj->TimeUTC[Dat_END_TIME],
2017-09-15 13:19:27 +02:00
(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>",
2017-09-19 01:12:05 +02:00
Prj->Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
Prj->Title);
2017-09-15 13:19:27 +02:00
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-19 01:12:05 +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-19 01:12:05 +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
2017-09-20 14:06:24 +02:00
/***** Write rows of data of this project *****/
2017-09-19 09:55:09 +02:00
/* Description of the project */
2017-09-20 14:06:24 +02:00
Prj_ShowOneProjectTxtRow (Prj,PrintView,
Txt_Description,Prj->Description);
2017-09-15 13:19:27 +02:00
2017-09-19 09:55:09 +02:00
/* Required knowledge to carry out the project */
2017-09-20 14:06:24 +02:00
Prj_ShowOneProjectTxtRow (Prj,PrintView,
Txt_Required_knowledge,Prj->Knowledge);
2017-09-19 09:55:09 +02:00
/* Required materials to carry out the project */
2017-09-20 14:06:24 +02:00
Prj_ShowOneProjectTxtRow (Prj,PrintView,
Txt_Required_materials,Prj->Materials);
2017-09-19 09:55:09 +02:00
2017-09-20 14:06:24 +02:00
/* Project tutors */
2017-09-19 09:55:09 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"RIGHT_TOP");
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
2017-09-19 14:33:57 +02:00
fprintf (Gbl.F.Out," %s\">"
2017-09-19 09:55:09 +02:00
"%s:"
"</td>"
"<td colspan=\"2\" class=\"LEFT_TOP",
2017-09-19 14:33:57 +02:00
Prj->Hidden ? "ASG_LABEL_LIGHT" :
"ASG_LABEL",
2017-09-20 14:06:24 +02:00
Txt_Tutors);
2017-09-19 09:55:09 +02:00
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
2017-09-20 14:06:24 +02:00
fprintf (Gbl.F.Out," %s\">",
2017-09-19 09:55:09 +02:00
Prj->Hidden ? "DAT_LIGHT" :
2017-09-20 14:06:24 +02:00
"DAT");
Prj_WriteUsrs (Prj->PrjCod,Prj_ROLE_TUT);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2017-09-19 09:55:09 +02:00
2017-09-20 14:06:24 +02:00
/* Project students */
2017-09-19 15:06:19 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"RIGHT_TOP");
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out," %s\">"
"%s:"
"</td>"
"<td colspan=\"2\" class=\"LEFT_TOP",
Prj->Hidden ? "ASG_LABEL_LIGHT" :
"ASG_LABEL",
2017-09-20 14:06:24 +02:00
Txt_ROLES_PLURAL_Abc[Rol_STD][Usr_SEX_UNKNOWN]);
2017-09-19 15:06:19 +02:00
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out," %s\">",
Prj->Hidden ? "DAT_LIGHT" :
"DAT");
2017-09-20 14:06:24 +02:00
Prj_WriteUsrs (Prj->PrjCod,Prj_ROLE_STD);
2017-09-19 15:06:19 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2017-09-20 14:06:24 +02:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
/*********************** Show test info about a project **********************/
/*****************************************************************************/
static void Prj_ShowOneProjectTxtRow (struct Project *Prj,bool PrintView,
const char *Label,char *TxtField)
{
/***** Change format *****/
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
TxtField,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML
Str_InsertLinks (TxtField,Cns_MAX_BYTES_TEXT,60); // Insert links
/***** Row with label and text *****/
2017-09-20 13:56:48 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"RIGHT_TOP");
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out," %s\">"
"%s:"
"</td>"
"<td colspan=\"2\" class=\"LEFT_TOP",
Prj->Hidden ? "ASG_LABEL_LIGHT" :
"ASG_LABEL",
2017-09-20 14:06:24 +02:00
Label);
2017-09-20 13:56:48 +02:00
if (!PrintView)
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
2017-09-20 14:06:24 +02:00
fprintf (Gbl.F.Out," %s\">"
"%s"
"</td>"
"</tr>",
2017-09-20 13:56:48 +02:00
Prj->Hidden ? "DAT_LIGHT" :
2017-09-20 14:06:24 +02:00
"DAT",
TxtField);
2017-09-15 13:19:27 +02:00
}
2017-09-19 15:06:19 +02:00
/*****************************************************************************/
2017-09-19 16:45:42 +02:00
/*************** Write list of users with a role in a project ****************/
2017-09-19 15:06:19 +02:00
/*****************************************************************************/
2017-09-19 16:45:42 +02:00
static void Prj_WriteUsrs (long PrjCod,Prj_RoleInProject_t RoleInProject)
2017-09-19 15:06:19 +02:00
{
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char Query[2048];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsr;
unsigned NumUsrs;
unsigned NumUsrsKnown;
unsigned NumUsrsUnknown;
unsigned NumUsrsToShow;
struct UsrData UsrDat;
bool UsrValid;
bool ShowPhoto;
char PhotoURL[PATH_MAX + 1];
2017-09-19 16:45:42 +02:00
/***** Get number of users in project from database *****/
sprintf (Query,"SELECT COUNT(*) FROM prj_usr"
" WHERE PrjCod=%ld AND RoleInProject=%u",
PrjCod,(unsigned) RoleInProject);
NumUsrs = (unsigned) DB_QueryCOUNT (Query,"can not get users in project");
2017-09-19 15:06:19 +02:00
2017-09-19 16:45:42 +02:00
/***** Get users in project from database *****/
2017-09-19 15:06:19 +02:00
sprintf (Query,"SELECT prj_usr.UsrCod,"
"usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN"
" FROM prj_usr,usr_data"
2017-09-19 16:45:42 +02:00
" WHERE prj_usr.PrjCod=%ld AND RoleInProject=%u"
2017-09-19 15:06:19 +02:00
" AND prj_usr.UsrCod=usr_data.UsrCod"
" ORDER BY S1,S2,FN",
2017-09-19 16:45:42 +02:00
PrjCod,(unsigned) RoleInProject);
NumUsrsKnown = (unsigned) DB_QuerySELECT (Query,&mysql_res,
"can not get users in project");
2017-09-19 15:06:19 +02:00
/***** Check number of users *****/
if (NumUsrs)
{
/***** Start table *****/
fprintf (Gbl.F.Out,"<table>");
/***** How many users will be shown? *****/
NumUsrsToShow = NumUsrsKnown;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write known users *****/
for (NumUsr = 0;
NumUsr < NumUsrsToShow;
NumUsr++)
{
/* Get user's code */
row = mysql_fetch_row (mysql_res);
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get user's data */
UsrValid = Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
/* Put user's photo */
fprintf (Gbl.F.Out,"<td class=\"CENTER_TOP\" style=\"width:30px;\">");
ShowPhoto = (UsrValid ? Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL) :
false);
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO21x28",Pho_ZOOM,false);
/* Write user's name */
fprintf (Gbl.F.Out,"</td>"
"<td class=\"AUTHOR_TXT LEFT_MIDDLE\">");
if (UsrValid)
fprintf (Gbl.F.Out,"%s",UsrDat.FullName);
else
fprintf (Gbl.F.Out,"[%s]",
Txt_ROLES_SINGUL_abc[Rol_UNK][Usr_SEX_UNKNOWN]); // User not found, likely a user who has been removed
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/***** If any users are unknown *****/
if ((NumUsrsUnknown = NumUsrs - NumUsrsKnown))
/***** Start form to show all the users *****/
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"3\" class=\"AUTHOR_TXT LEFT_MIDDLE\">"
"[%u %s]"
"</td>"
"</tr>",
NumUsrsUnknown,
(NumUsrsUnknown == 1) ?
Txt_ROLES_SINGUL_abc[Rol_UNK][Usr_SEX_UNKNOWN] :
Txt_ROLES_PLURAL_abc[Rol_UNK][Usr_SEX_UNKNOWN]);
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** End table *****/
fprintf (Gbl.F.Out,"</table>");
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
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 ();
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;
}
2017-09-19 14:20:49 +02:00
sprintf (Query,"SELECT PrjCod"
" FROM projects"
" WHERE CrsCod=%ld%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery);
2017-09-15 13:19:27 +02:00
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 *****/
2017-09-19 18:13:52 +02:00
sprintf (Query,"SELECT PrjCod,Hidden,Preassigned,"
2017-09-15 13:19:27 +02:00
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
2017-09-19 01:12:05 +02:00
"Title,Description,Knowledge,Materials,URL"
2017-09-15 13:19:27 +02:00
" FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj->PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
2017-09-19 01:12:05 +02:00
/*
row[ 0]: PrjCod
row[ 1]: Hidden
row[ 2]: Preassigned
2017-09-19 18:13:52 +02:00
row[ 3]: UNIX_TIMESTAMP(StartTime)
row[ 4]: UNIX_TIMESTAMP(EndTime)
row[ 5]: NOW() BETWEEN StartTime AND EndTime
row[ 6]: Title
row[ 7]: Description
row[ 8]: Knowledge
row[ 9]: Materials
row[10]: URL
2017-09-19 01:12:05 +02:00
*/
2017-09-15 13:19:27 +02:00
/***** 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);
2017-09-19 01:12:05 +02:00
/*
row[ 0]: PrjCod
row[ 1]: Hidden
row[ 2]: Preassigned
2017-09-19 18:13:52 +02:00
row[ 3]: UNIX_TIMESTAMP(StartTime)
row[ 4]: UNIX_TIMESTAMP(EndTime)
row[ 5]: NOW() BETWEEN StartTime AND EndTime
row[ 6]: Title
row[ 7]: Description
row[ 8]: Knowledge
row[ 9]: Materials
row[10]: URL
2017-09-19 01:12:05 +02:00
*/
2017-09-15 13:19:27 +02:00
/* 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');
2017-09-19 01:12:05 +02:00
/* Get the folder for the project files (row[2]) */
Prj->Preassigned = (row[2][0] == 'Y') ? Prj_PREASSIGNED :
Prj_NOT_PREASSIGNED;
2017-09-19 18:13:52 +02:00
/* Get start date (row[3] holds the start UTC time) */
Prj->TimeUTC[Dat_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
2017-09-15 13:19:27 +02:00
2017-09-19 18:13:52 +02:00
/* Get end date (row[4] holds the end UTC time) */
Prj->TimeUTC[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]);
2017-09-15 13:19:27 +02:00
2017-09-19 18:13:52 +02:00
/* Get whether the project is open or closed (row[5]) */
Prj->Open = (row[5][0] == '1');
2017-09-15 13:19:27 +02:00
2017-09-19 18:13:52 +02:00
/* 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
2017-09-19 18:13:52 +02:00
/* Get the description of the project (row[7]) */
Str_Copy (Prj->Description,row[7],
2017-09-19 01:12:05 +02:00
Cns_MAX_BYTES_TEXT);
2017-09-19 18:13:52 +02:00
/* Get the required knowledge for the project (row[8]) */
Str_Copy (Prj->Knowledge,row[8],
2017-09-19 01:12:05 +02:00
Cns_MAX_BYTES_TEXT);
2017-09-15 13:19:27 +02:00
2017-09-19 18:13:52 +02:00
/* Get the required materials for the project (row[9]) */
Str_Copy (Prj->Materials,row[9],
2017-09-19 01:12:05 +02:00
Cns_MAX_BYTES_TEXT);
2017-09-19 18:13:52 +02:00
/* Get the URL of the project (row[10]) */
Str_Copy (Prj->URL,row[10],
2017-09-18 17:26:20 +02:00
Cns_MAX_BYTES_WWW);
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
/************************** 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->Hidden = false;
2017-09-19 01:12:05 +02:00
Prj->Preassigned = Prj_NOT_PREASSIGNED;
2017-09-15 13:19:27 +02:00
Prj->TimeUTC[Dat_START_TIME] =
Prj->TimeUTC[Dat_END_TIME ] = (time_t) 0;
Prj->Open = false;
Prj->Title[0] = '\0';
2017-09-19 01:12:05 +02:00
Prj->Description[0] = '\0';
Prj->Knowledge[0] = '\0';
Prj->Materials[0] = '\0';
Prj->URL[0] = '\0';
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
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
/******************* 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 ();
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 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;
2017-09-19 09:35:36 +02:00
/***** Allocate memory for the project *****/
Prj_AllocMemProject (&Prj);
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);
/***** 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);
2017-09-19 09:35:36 +02:00
/***** Free memory of the project *****/
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** 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;
2017-09-19 09:35:36 +02:00
/***** Allocate memory for the project *****/
Prj_AllocMemProject (&Prj);
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);
/***** 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);
2017-09-19 09:35:36 +02:00
/***** Free memory of the project *****/
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** 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_No;
extern const char *Txt_Yes;
2017-09-15 13:19:27 +02:00
extern const char *Txt_Description;
2017-09-19 01:12:05 +02:00
extern const char *Txt_Required_knowledge;
extern const char *Txt_Required_materials;
2017-09-18 01:06:51 +02:00
extern const char *Txt_URL;
2017-09-19 14:05:02 +02:00
extern const char *Txt_Preassigned_QUESTION;
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-19 01:12:05 +02:00
/***** Allocate memory for the project *****/
Prj_AllocMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** Get parameters *****/
2017-09-17 16:58:09 +02:00
Prj_GetParamPrjOrder ();
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 */
2017-09-19 01:12:05 +02:00
Prj_ResetProject (&Prj);
2017-09-15 13:19:27 +02:00
Prj.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
Prj.TimeUTC[Dat_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours
Prj.Open = true;
}
else
/* Get data of the project from database */
Prj_GetDataOfProjectByCod (&Prj);
/***** 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-19 01:12:05 +02:00
/***** Description of the project *****/
2017-09-15 13:19:27 +02:00
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_TOP\">"
2017-09-19 01:12:05 +02:00
"<label for=\"Description\" class=\"%s\">%s:</label>"
2017-09-15 13:19:27 +02:00
"</td>"
"<td class=\"LEFT_TOP\">"
2017-09-19 01:12:05 +02:00
"<textarea id=\"Description\" name=\"Description\""
2017-09-15 13:19:27 +02:00
" cols=\"60\" rows=\"10\">",
The_ClassForm[Gbl.Prefs.Theme],Txt_Description);
2017-09-17 18:55:02 +02:00
if (!ItsANewProject)
2017-09-19 01:12:05 +02:00
fprintf (Gbl.F.Out,"%s",Prj.Description);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
/***** Required knowledge to carry out the project *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_TOP\">"
"<label for=\"Knowledge\" class=\"%s\">%s:</label>"
"</td>"
"<td class=\"LEFT_TOP\">"
"<textarea id=\"Knowledge\" name=\"Knowledge\""
" cols=\"60\" rows=\"5\">",
The_ClassForm[Gbl.Prefs.Theme],Txt_Required_knowledge);
if (!ItsANewProject)
fprintf (Gbl.F.Out,"%s",Prj.Knowledge);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
/***** Required materials to carry out the project *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"RIGHT_TOP\">"
"<label for=\"Materials\" class=\"%s\">%s:</label>"
"</td>"
"<td class=\"LEFT_TOP\">"
"<textarea id=\"Materials\" name=\"Materials\""
" cols=\"60\" rows=\"5\">",
The_ClassForm[Gbl.Prefs.Theme],Txt_Required_materials);
if (!ItsANewProject)
fprintf (Gbl.F.Out,"%s",Prj.Materials);
2017-09-15 13:19:27 +02:00
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-19 14:05:02 +02:00
/***** Preassigned? *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">"
"<select name=\"Preassigned\">",
The_ClassForm[Gbl.Prefs.Theme],
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
/***** 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 ();
2017-09-19 01:12:05 +02:00
/***** Free memory of the project *****/
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
/***** Show current projects, if any *****/
Prj_ShowAllProjects ();
}
2017-09-19 01:12:05 +02:00
/*****************************************************************************/
/*** Allocate memory for those parameters of a project with a lot of text ****/
/*****************************************************************************/
static void Prj_AllocMemProject (struct Project *Prj)
{
if ((Prj->Description = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store project.");
if ((Prj->Knowledge = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store project.");
if ((Prj->Materials = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store project.");
}
/*****************************************************************************/
/****** Free memory of those parameters of a project with a lot of text ******/
/*****************************************************************************/
static void Prj_FreeMemProject (struct Project *Prj)
{
if (Prj->Description)
{
free ((void *) Prj->Description);
Prj->Description = NULL;
}
if (Prj->Knowledge)
{
free ((void *) Prj->Knowledge);
Prj->Knowledge = NULL;
}
if (Prj->Materials)
{
free ((void *) Prj->Materials);
Prj->Materials = NULL;
}
}
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
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;
2017-09-19 09:35:36 +02:00
struct Project Prj; // Project data received from form
2017-09-17 18:55:02 +02:00
bool ItsANewProject;
bool NewProjectIsCorrect = true;
2017-09-19 01:12:05 +02:00
/***** Allocate memory for the project *****/
2017-09-19 09:35:36 +02:00
Prj_AllocMemProject (&Prj);
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/***** Get parameters from form *****/
/* Get the code of the project */
2017-09-19 09:35:36 +02:00
Prj.PrjCod = Prj_GetParamPrjCod ();
ItsANewProject = (Prj.PrjCod < 0);
2017-09-15 13:19:27 +02:00
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-19 09:35:36 +02:00
/* Reset project data */
Prj_ResetProject (&Prj);
2017-09-15 13:19:27 +02:00
else
2017-09-19 09:35:36 +02:00
/* Get data of the project from database */
Prj_GetDataOfProjectByCod (&Prj);
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get start/end date-times */
2017-09-19 09:35:36 +02:00
Prj.TimeUTC[Dat_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
Prj.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-19 09:35:36 +02:00
Par_GetParToText ("Title",Prj.Title,Prj_MAX_BYTES_PROJECT_TITLE);
2017-09-15 13:19:27 +02:00
2017-09-19 01:12:05 +02:00
/* Get project description, required knowledge and required materials */
2017-09-19 09:35:36 +02:00
Par_GetParToHTML ("Description",Prj.Description,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
Par_GetParToHTML ("Knowledge" ,Prj.Knowledge ,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
Par_GetParToHTML ("Materials" ,Prj.Materials ,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
2017-09-15 13:19:27 +02:00
2017-09-18 17:26:20 +02:00
/* Get degree WWW */
2017-09-19 09:35:36 +02:00
Par_GetParToText ("URL",Prj.URL,Cns_MAX_BYTES_WWW);
2017-09-18 17:26:20 +02:00
2017-09-19 14:05:02 +02:00
/* Get whether the project is preassigned */
Prj.Preassigned = (Par_GetParToBool ("Preassigned")) ? Prj_PREASSIGNED :
Prj_NOT_PREASSIGNED;
2017-09-15 13:19:27 +02:00
/***** Adjust dates *****/
2017-09-19 09:35:36 +02:00
if (Prj.TimeUTC[Dat_START_TIME] == 0)
Prj.TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC;
if (Prj.TimeUTC[Dat_END_TIME] == 0)
Prj.TimeUTC[Dat_END_TIME] = Prj.TimeUTC[Dat_START_TIME] + 2 * 60 * 60; // +2 hours
2017-09-15 13:19:27 +02:00
/***** Check if title is correct *****/
2017-09-19 09:35:36 +02:00
if (Prj.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-19 09:35:36 +02:00
if (Prj_CheckIfSimilarProjectsExists ("Title",Prj.Title,Prj.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,
2017-09-19 09:35:36 +02:00
Prj.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
{
2017-09-17 18:55:02 +02:00
if (ItsANewProject)
2017-09-15 13:19:27 +02:00
{
2017-09-19 09:35:36 +02:00
Prj_CreateProject (&Prj); // Add new project to database
2017-09-15 13:19:27 +02:00
/***** Write success message *****/
2017-09-19 09:35:36 +02:00
sprintf (Gbl.Alert.Txt,Txt_Created_new_project_X,Prj.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)
{
2017-09-19 09:35:36 +02:00
Prj_UpdateProject (&Prj);
2017-09-17 23:37:03 +02:00
/***** Write success message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_project_has_been_modified);
}
2017-09-15 13:19:27 +02:00
/***** Show projects again *****/
Prj_SeeProjects ();
}
else
// TODO: The form should be filled with partial data, now is always empty
Prj_RequestCreatOrEditPrj ();
2017-09-19 01:12:05 +02:00
/***** Free memory of the project *****/
2017-09-19 09:35:36 +02:00
Prj_FreeMemProject (&Prj);
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/************************** Create a new project *****************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-19 01:12:05 +02:00
static void Prj_CreateProject (struct Project *Prj)
2017-09-15 13:19:27 +02:00
{
char Query[1024 +
2017-09-17 23:37:03 +02:00
Prj_MAX_BYTES_PROJECT_TITLE +
2017-09-19 01:12:05 +02:00
Cns_MAX_BYTES_TEXT*3 +
2017-09-18 17:26:20 +02:00
Cns_MAX_BYTES_WWW];
2017-09-15 13:19:27 +02:00
/***** Create a new project *****/
sprintf (Query,"INSERT INTO projects"
2017-09-19 18:13:52 +02:00
" (CrsCod,Hidden,Preassigned,StartTime,EndTime,"
2017-09-19 01:12:05 +02:00
"Title,Description,Knowledge,Materials,URL)"
2017-09-15 13:19:27 +02:00
" VALUES"
2017-09-19 18:13:52 +02:00
" (%ld,'%c','%c',FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
2017-09-19 01:12:05 +02:00
"'%s','%s','%s','%s','%s')",
2017-09-15 13:19:27 +02:00
Gbl.CurrentCrs.Crs.CrsCod,
2017-09-19 01:12:05 +02:00
Prj->Hidden ? 'Y' :
'N',
Prj->Preassigned == Prj_PREASSIGNED ? 'Y' :
'N',
2017-09-15 13:19:27 +02:00
Prj->TimeUTC[Dat_START_TIME],
Prj->TimeUTC[Dat_END_TIME ],
Prj->Title,
2017-09-19 01:12:05 +02:00
Prj->Description,
Prj->Knowledge,
Prj->Materials,
2017-09-18 17:26:20 +02:00
Prj->URL);
2017-09-15 13:19:27 +02:00
Prj->PrjCod = DB_QueryINSERTandReturnCode (Query,"can not create new project");
2017-09-19 18:13:52 +02:00
/***** Insert creator as first tutor *****/
sprintf (Query,"INSERT INTO prj_usr"
" (PrjCod,RoleInProject,UsrCod)"
" VALUES"
" (%ld,%u,%ld)",
Prj->PrjCod,
(unsigned) Prj_ROLE_TUT,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not add tutor");
2017-09-15 13:19:27 +02:00
}
/*****************************************************************************/
2017-09-17 16:58:09 +02:00
/*********************** Update an existing project **************************/
2017-09-15 13:19:27 +02:00
/*****************************************************************************/
2017-09-19 01:12:05 +02:00
static void Prj_UpdateProject (struct Project *Prj)
2017-09-15 13:19:27 +02:00
{
char Query[1024 +
2017-09-17 23:37:03 +02:00
Prj_MAX_BYTES_PROJECT_TITLE +
2017-09-19 01:12:05 +02:00
Cns_MAX_BYTES_TEXT*3 +
2017-09-18 17:26:20 +02:00
Cns_MAX_BYTES_WWW];
2017-09-15 13:19:27 +02:00
/***** Update the data of the project *****/
sprintf (Query,"UPDATE projects SET "
2017-09-19 09:35:36 +02:00
"Hidden='%c',Preassigned='%c',"
2017-09-15 13:19:27 +02:00
"StartTime=FROM_UNIXTIME(%ld),"
"EndTime=FROM_UNIXTIME(%ld),"
2017-09-19 01:12:05 +02:00
"Title='%s',"
"Description='%s',Knowledge='%s',Materials='%s',URL='%s'"
2017-09-15 13:19:27 +02:00
" WHERE PrjCod=%ld AND CrsCod=%ld",
2017-09-19 01:12:05 +02:00
Prj->Hidden ? 'Y' :
'N',
Prj->Preassigned == Prj_PREASSIGNED ? 'Y' :
'N',
2017-09-15 13:19:27 +02:00
Prj->TimeUTC[Dat_START_TIME],
Prj->TimeUTC[Dat_END_TIME ],
Prj->Title,
2017-09-19 01:12:05 +02:00
Prj->Description,
Prj->Knowledge,
Prj->Materials,
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");
}
/*****************************************************************************/
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 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
/******************** 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
}