Version 15.172

This commit is contained in:
Antonio Cañas Vargas 2016-04-01 12:47:32 +02:00
parent 0e0359f10e
commit 9e9f93baea
4 changed files with 84 additions and 4 deletions

View File

@ -2066,7 +2066,7 @@ void Ctr_ReceivePhoto (void)
char Command[1024+PATH_MAX*2];
int ReturnCode;
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
/***** Copy in disk the file received *****/
Param = Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
/* Check if the file type is image/ or application/octet-stream */

View File

@ -138,13 +138,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.171.2 (2016-04-01)"
#define Log_PLATFORM_VERSION "SWAD 15.172 (2016-04-01)"
#define CSS_FILE "swad15.165.5.css"
#define JS_FILE "swad15.131.3.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
Version 15.172: Apr 01, 2016 Reception of test image. Not finished. (197339 lines)
Version 15.171.2: Apr 01, 2016 Change in message related to user photo. (197272 lines)
Version 15.171.1: Apr 01, 2016 Code refactoring in functions to get a parameter and to receive file. (197271 lines)
Version 15.171: Apr 01, 2016 Code refactoring in function to get a parameter. (197259 lines)

View File

@ -224,6 +224,9 @@ struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
{
struct Param *Param;
/***** Set default values *****/
FileName[0] = 0;
/***** Get parameter *****/
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,NULL,
Fil_MAX_FILE_SIZE,&Param);
@ -231,8 +234,12 @@ struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
/***** Get filename *****/
/* Check if filename exists */
if (Param->FileName.Start == 0 ||
Param->FileName.Length == 0 ||
Param->FileName.Length > PATH_MAX)
Param->FileName.Length == 0)
{
FileName[0] = MIMEType[0] = '\0';
return Param;
}
if (Param->FileName.Length > PATH_MAX)
Lay_ShowErrorAndExit ("Error while getting filename.");
/* Copy filename */

View File

@ -36,6 +36,7 @@
#include <string.h> // For string functions
#include <sys/stat.h> // For mkdir
#include <sys/types.h> // For mkdir
#include <unistd.h> // For unlink
#include "swad_action.h"
#include "swad_database.h"
@ -206,6 +207,7 @@ static int Tst_CountNumAnswerTypesInList (void);
static void Tst_PutFormEditOneQst (char *Stem,char *Feedback);
static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *UnsignedStr);
static void Tst_GetQstFromForm (char *Stem,char *Feedback);
static bool Tst_GetImageFromForm (void);
static long Tst_GetTagCodFromTagTxt (const char *TagTxt);
static long Tst_CreateNewTag (long CrsCod,const char *TagTxt);
static void Tst_EnableOrDisableTag (long TagCod,bool TagHidden);
@ -4641,6 +4643,7 @@ void Tst_InitQst (void)
Gbl.Test.Stem.Length = 0;
Gbl.Test.Feedback.Text = NULL;
Gbl.Test.Feedback.Length = 0;
Gbl.Test.Image[0] = '\0';
Gbl.Test.AnswerType = Tst_ANS_UNIQUE_CHOICE;
Gbl.Test.Answer.NumOptions = 0;
Gbl.Test.Answer.TF = ' ';
@ -4778,6 +4781,10 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback)
/***** Get question feedback *****/
Par_GetParToHTML ("Feedback",Feedback,Cns_MAX_BYTES_TEXT);
/***** Get image *****/
if (Tst_GetImageFromForm ())
Lay_ShowAlert (Lay_INFO,"Image present.");
/***** Get answers *****/
Gbl.Test.Shuffle = false;
switch (Gbl.Test.AnswerType)
@ -4876,6 +4883,71 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback)
Gbl.Test.Feedback.Length = strlen (Gbl.Test.Feedback.Text);
}
/*****************************************************************************/
/****************** Get image of a test question from form *******************/
/*****************************************************************************/
// Return true if image is created
static bool Tst_GetImageFromForm (void)
{
struct Param *Param;
char FileNameImgSrc[PATH_MAX+1];
char *PtrExtension;
size_t LengthExtension;
char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1];
char PathImgPriv[PATH_MAX+1];
char FileNameImgTmp[PATH_MAX+1]; // Full name (including path and .jpg) of the destination temporary file
bool WrongType = false;
/***** Get filename and MIME type *****/
Param = Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
if (!FileNameImgSrc[0]) // No file present
return false;
/* Check if the file type is image/ or application/octet-stream */
if (strncmp (MIMEType,"image/",strlen ("image/")))
if (strcmp (MIMEType,"application/octet-stream"))
if (strcmp (MIMEType,"application/octetstream"))
if (strcmp (MIMEType,"application/octet"))
WrongType = true;
if (WrongType)
return false;
/***** Create private directories if not exist *****/
/* Create private directory for images if it does not exist */
sprintf (PathImgPriv,"%s/%s",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG);
Fil_CreateDirIfNotExists (PathImgPriv);
/* Create temporary private directory for images if it does not exist */
sprintf (PathImgPriv,"%s/%s/%s",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP);
Fil_CreateDirIfNotExists (PathImgPriv);
/* Get filename extension */
if ((PtrExtension = strrchr (FileNameImgSrc,(int) '.')) == NULL)
return false;
LengthExtension = strlen (PtrExtension);
if (LengthExtension < Fil_MIN_LENGTH_FILE_EXTENSION ||
LengthExtension > Fil_MAX_LENGTH_FILE_EXTENSION)
return false;
/* End the reception of image in a temporary file */
strcpy (Gbl.Test.Image,Gbl.UniqueNameEncrypted);
sprintf (FileNameImgTmp,"%s/%s/%s/%s.%s",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP,
Gbl.Test.Image,PtrExtension);
if (!Fil_EndReceptionOfFile (FileNameImgTmp,Param))
return false;
/***** TODO: Copy and process the file *****/
/***** Remove temporary file *****/
unlink (FileNameImgTmp);
return true;
}
/*****************************************************************************/
/*********************** Check if a question is correct **********************/
/*****************************************************************************/