mirror of https://github.com/acanas/swad-core.git
Version 15.176
This commit is contained in:
parent
4354030acb
commit
4c2189921f
|
@ -2067,7 +2067,8 @@ void Ctr_ReceivePhoto (void)
|
|||
int ReturnCode;
|
||||
|
||||
/***** Copy in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNameImgSrc,MIMEType);
|
||||
|
||||
/* Check if the file type is image/ or application/octet-stream */
|
||||
if (strncmp (MIMEType,"image/",strlen ("image/")))
|
||||
|
|
|
@ -139,13 +139,14 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.175.11 (2016-04-04)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.176 (2016-04-04)"
|
||||
#define CSS_FILE "swad15.175.10.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.176: Apr 04, 2016 Code refactoring related to images. (198019 lines)
|
||||
Version 15.175.11:Apr 04, 2016 Code refactoring related to image associated to a test question.
|
||||
Forms to edit image in every unique/multiple answer. (197968 lines)
|
||||
Version 15.175.10:Apr 04, 2016 Changes in CSS. (197955 lines)
|
||||
|
|
|
@ -220,7 +220,8 @@ Content-Type: image/pjpeg
|
|||
000020 03030304 03030405 08050504 04050A07 ················
|
||||
etc, etc.
|
||||
*/
|
||||
struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
|
||||
struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
|
||||
char *FileName,char *MIMEType)
|
||||
{
|
||||
struct Param *Param;
|
||||
|
||||
|
@ -228,8 +229,7 @@ struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
|
|||
FileName[0] = 0;
|
||||
|
||||
/***** Get parameter *****/
|
||||
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,NULL,
|
||||
Fil_MAX_FILE_SIZE,&Param);
|
||||
Par_GetParameter (Par_PARAM_SINGLE,ParamFile,NULL,Fil_MAX_FILE_SIZE,&Param);
|
||||
|
||||
/***** Get filename *****/
|
||||
/* Check if filename exists */
|
||||
|
|
|
@ -60,7 +60,8 @@ void Fil_CreateFileForHTMLOutput (void);
|
|||
void Fil_CloseAndRemoveFileForHTMLOutput (void);
|
||||
bool Fil_ReadStdinIntoTmpFile (void);
|
||||
void Fil_EndOfReadingStdin (void);
|
||||
struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType);
|
||||
struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
|
||||
char *FileName,char *MIMEType);
|
||||
bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param);
|
||||
void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName,char *OldName,char *NewName,FILE **NewFile);
|
||||
void Fil_CloseUpdateFile (const char *CurrentName,const char *OldName,const char *NewName,FILE *NewFile);
|
||||
|
|
|
@ -8406,7 +8406,8 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
|||
if (Brw_CheckIfICanCreateIntoFolder (Gbl.FileBrowser.Level))
|
||||
{
|
||||
/***** First, we save in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
||||
Param = Fil_StartReceptionOfFile (SrcFileName,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
SrcFileName,MIMEType);
|
||||
|
||||
/***** Get filename from path *****/
|
||||
// Spaces at start or end are allowed
|
||||
|
|
64
swad_image.c
64
swad_image.c
|
@ -67,6 +67,52 @@ static void Img_ProcessImage (const char *FileNameImgOriginal,
|
|||
const char *FileNameImgProcessed,
|
||||
unsigned Width,unsigned Height,unsigned Quality);
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Get image from form ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Img_GetImageFromForm (char *ImageName,void (*GetImageName) (void),
|
||||
const char *ParamFile,
|
||||
unsigned Width,unsigned Height,unsigned Quality)
|
||||
{
|
||||
Gbl.Image.Action = Img_GetImageActionFromForm ("ImgAct");
|
||||
switch (Gbl.Image.Action)
|
||||
{
|
||||
case Img_ACTION_NO_IMAGE: // Do not use image (remove current image if exists)
|
||||
/***** Reset image name *****/
|
||||
ImageName[0] = '\0';
|
||||
Gbl.Image.Status = Img_FILE_NONE;
|
||||
break;
|
||||
case Img_ACTION_KEEP_IMAGE: // Keep current image unchanged
|
||||
/***** Get image name *****/
|
||||
GetImageName ();
|
||||
Gbl.Image.Status = (ImageName[0] ? Img_NAME_STORED_IN_DB :
|
||||
Img_FILE_NONE);
|
||||
break;
|
||||
case Img_ACTION_NEW_IMAGE: // Upload new image
|
||||
/***** Get new image (if present ==> process and create temporary file) *****/
|
||||
Img_GetAndProcessImageFileFromForm (ParamFile,Width,Height,Quality);
|
||||
if (Gbl.Image.Status != Img_FILE_PROCESSED) // No new image received-processed successfully
|
||||
{
|
||||
/* Reset image name */
|
||||
ImageName[0] = '\0';
|
||||
Gbl.Image.Status = Img_FILE_NONE;
|
||||
}
|
||||
break;
|
||||
case Img_ACTION_CHANGE_IMAGE: // Replace old image by new image
|
||||
/***** Get new image (if present ==> process and create temporary file) *****/
|
||||
Img_GetAndProcessImageFileFromForm (ParamFile,Width,Height,Quality);
|
||||
if (Gbl.Image.Status != Img_FILE_PROCESSED) // No new image received-processed successfully
|
||||
{
|
||||
/* Get image name */
|
||||
GetImageName ();
|
||||
Gbl.Image.Status = (ImageName[0] ? Img_NAME_STORED_IN_DB :
|
||||
Img_FILE_NONE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Get image action from form ************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -89,7 +135,9 @@ Img_Action_t Img_GetImageActionFromForm (const char *ParamRadio)
|
|||
/*****************************************************************************/
|
||||
// Return true if image is created
|
||||
|
||||
void Img_GetAndProcessImageFromForm (unsigned Width,unsigned Height,unsigned Quality)
|
||||
void Img_GetAndProcessImageFileFromForm (const char *ParamFile,
|
||||
unsigned Width,unsigned Height,
|
||||
unsigned Quality)
|
||||
{
|
||||
struct Param *Param;
|
||||
char FileNameImgSrc[PATH_MAX+1];
|
||||
|
@ -105,7 +153,7 @@ void Img_GetAndProcessImageFromForm (unsigned Width,unsigned Height,unsigned Qua
|
|||
Gbl.Image.Status = Img_FILE_NONE;
|
||||
|
||||
/***** Get filename and MIME type *****/
|
||||
Param = Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (ParamFile,FileNameImgSrc,MIMEType);
|
||||
if (!FileNameImgSrc[0]) // No file present
|
||||
return;
|
||||
|
||||
|
@ -234,16 +282,16 @@ void Img_MoveImageToDefinitiveDirectory (void)
|
|||
/******************** Write the image of a test question *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Img_ShowImage (const char *Image,const char *ClassImg)
|
||||
void Img_ShowImage (const char *ImageName,const char *ClassImg)
|
||||
{
|
||||
char FileNameImgPriv[PATH_MAX+1];
|
||||
char FullPathImgPriv[PATH_MAX+1];
|
||||
char URL[PATH_MAX+1];
|
||||
|
||||
/***** If no image to show ==> nothing to do *****/
|
||||
if (!Image)
|
||||
if (!ImageName)
|
||||
return;
|
||||
if (!Image[0])
|
||||
if (!ImageName[0])
|
||||
return;
|
||||
if (Gbl.Image.Status != Img_NAME_STORED_IN_DB)
|
||||
return;
|
||||
|
@ -253,11 +301,11 @@ void Img_ShowImage (const char *Image,const char *ClassImg)
|
|||
Brw_CreateDirDownloadTmp ();
|
||||
|
||||
/***** Build private path to image *****/
|
||||
sprintf (FileNameImgPriv,"%s.jpg",Image);
|
||||
sprintf (FileNameImgPriv,"%s.jpg",ImageName);
|
||||
sprintf (FullPathImgPriv,"%s/%s/%c%c/%s",
|
||||
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,
|
||||
Image[0],
|
||||
Image[1],
|
||||
ImageName[0],
|
||||
ImageName[1],
|
||||
FileNameImgPriv);
|
||||
|
||||
/***** Create symbolic link from temporary public directory to private file
|
||||
|
|
14
swad_image.h
14
swad_image.h
|
@ -68,23 +68,29 @@ typedef enum
|
|||
} Img_FileStatus_t;
|
||||
|
||||
/***** Action to perform when editing a form with an image *****/
|
||||
#define Img_NUM_ACTIONS 3
|
||||
#define Img_NUM_ACTIONS 4
|
||||
typedef enum
|
||||
{
|
||||
Img_ACTION_NO_IMAGE, // Do not use image (remove current image if exists)
|
||||
Img_ACTION_KEEP_IMAGE, // Keep current image unchanged
|
||||
Img_ACTION_CHANGE_IMAGE, // Upload new image (remove current image if exists)
|
||||
Img_ACTION_NEW_IMAGE, // Upload new image
|
||||
Img_ACTION_CHANGE_IMAGE, // Change existing image by a new image
|
||||
} Img_Action_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Img_GetImageFromForm (char *ImageName,void (*GetImageName) (void),
|
||||
const char *ParamFile,
|
||||
unsigned Width,unsigned Height,unsigned Quality);
|
||||
Img_Action_t Img_GetImageActionFromForm (const char *ParamRadio);
|
||||
void Img_GetAndProcessImageFromForm (unsigned Width,unsigned Height,unsigned Quality);
|
||||
void Img_GetAndProcessImageFileFromForm (const char *ParamFile,
|
||||
unsigned Width,unsigned Height,
|
||||
unsigned Quality);
|
||||
|
||||
void Img_MoveImageToDefinitiveDirectory (void);
|
||||
void Img_ShowImage (const char *Image,const char *ClassImg);
|
||||
void Img_ShowImage (const char *ImageName,const char *ClassImg);
|
||||
void Img_RemoveImageFile (const char *ImageName);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2021,7 +2021,8 @@ void Inf_ReceivePagInfo (void)
|
|||
Gbl.CurrentCrs.Info.Type = Inf_AsignInfoType ();
|
||||
|
||||
/***** First of all, store in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
||||
Param = Fil_StartReceptionOfFile (SourceFileName,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
SourceFileName,MIMEType);
|
||||
|
||||
/***** Check that MIME type is HTML or ZIP *****/
|
||||
if (strcmp (MIMEType,"text/html"))
|
||||
|
|
|
@ -366,7 +366,8 @@ void Log_ReceiveLogo (Sco_Scope_t Scope)
|
|||
Fil_CreateDirIfNotExists (Path);
|
||||
|
||||
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
Param = Fil_StartReceptionOfFile (FileNameLogoSrc,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNameLogoSrc,MIMEType);
|
||||
|
||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||
if (strcmp (MIMEType,"image/png"))
|
||||
|
|
|
@ -498,7 +498,8 @@ void Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *UsrDat)
|
|||
Fil_RemoveOldTmpFiles (PathPhotosPubl,Cfg_TIME_TO_DELETE_PHOTOS_TMP_FILES,false);
|
||||
|
||||
/***** First of all, copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
Param = Fil_StartReceptionOfFile (FileNamePhotoSrc,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNamePhotoSrc,MIMEType);
|
||||
|
||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||
if (strcmp (MIMEType,"image/jpeg"))
|
||||
|
|
86
swad_test.c
86
swad_test.c
|
@ -1065,22 +1065,36 @@ static void Tst_PutFormToEditQstImage (const char *ImageName,
|
|||
Img_ShowImage (ImageName,"TEST_IMG_EDIT_ONE");
|
||||
}
|
||||
|
||||
/***** New image *****/
|
||||
/***** Change/new image *****/
|
||||
UniqueId++;
|
||||
fprintf (Gbl.F.Out,"<input type=\"radio\" id=\"chg_img_%u\" name=\"%s\""
|
||||
" value=\"%u\">",
|
||||
UniqueId,ParamRadio,Img_ACTION_CHANGE_IMAGE);
|
||||
fprintf (Gbl.F.Out,"<label class=\"%s\">"
|
||||
"%s: "
|
||||
"</label>",
|
||||
The_ClassForm[Gbl.Prefs.Theme],
|
||||
ImageName[0] ? Txt_Change_image :
|
||||
Txt_New_image);
|
||||
if (ImageName[0]) // Image exists
|
||||
{
|
||||
/***** Change image *****/
|
||||
fprintf (Gbl.F.Out,"<input type=\"radio\" id=\"chg_img_%u\" name=\"%s\""
|
||||
" value=\"%u\">",
|
||||
UniqueId,ParamRadio,Img_ACTION_CHANGE_IMAGE); // Replace existing image by new image
|
||||
fprintf (Gbl.F.Out,"<label class=\"%s\">"
|
||||
"%s: "
|
||||
"</label>",
|
||||
The_ClassForm[Gbl.Prefs.Theme],Txt_Change_image);
|
||||
|
||||
}
|
||||
else // Image does not exist
|
||||
{
|
||||
/***** New image *****/
|
||||
fprintf (Gbl.F.Out,"<input type=\"radio\" id=\"chg_img_%u\" name=\"%s\""
|
||||
" value=\"%u\">",
|
||||
UniqueId,ParamRadio,Img_ACTION_NEW_IMAGE); // Upload new image
|
||||
fprintf (Gbl.F.Out,"<label class=\"%s\">"
|
||||
"%s: "
|
||||
"</label>",
|
||||
The_ClassForm[Gbl.Prefs.Theme],Txt_New_image);
|
||||
}
|
||||
fprintf (Gbl.F.Out,"<input type=\"file\" name=\"%s\""
|
||||
" size=\"40\" maxlength=\"100\" value=\"\""
|
||||
" onchange=\"document.getElementById('chg_img_%u').checked = true;\" />",
|
||||
ParamFile,
|
||||
UniqueId);
|
||||
" size=\"40\" maxlength=\"100\" value=\"\""
|
||||
" onchange=\"document.getElementById('chg_img_%u').checked = true;\" />",
|
||||
ParamFile,
|
||||
UniqueId);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4820,7 +4834,8 @@ void Tst_ReceiveQst (void)
|
|||
and moved to the definitive directory) */
|
||||
Tst_RemoveImageFilesFromQstsInCrs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod);
|
||||
|
||||
if (Gbl.Image.Action == Img_ACTION_CHANGE_IMAGE && // Upload new image (remove current image if exists)
|
||||
if ((Gbl.Image.Action == Img_ACTION_NEW_IMAGE || // Upload new image
|
||||
Gbl.Image.Action == Img_ACTION_CHANGE_IMAGE) && // Replace existing image by new image
|
||||
Gbl.Image.Status == Img_FILE_PROCESSED) // The new image received has been processed
|
||||
/* Move processed image to definitive directory */
|
||||
Img_MoveImageToDefinitiveDirectory ();
|
||||
|
@ -4899,40 +4914,16 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback)
|
|||
/***** Get question stem *****/
|
||||
Par_GetParToHTML ("Stem",Stem,Cns_MAX_BYTES_TEXT);
|
||||
|
||||
/***** Get image associated to stem *****/
|
||||
Img_GetImageFromForm (Gbl.Test.Image,Tst_GetImageNameFromDB,
|
||||
Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
Tst_PHOTO_SAVED_MAX_WIDTH,
|
||||
Tst_PHOTO_SAVED_MAX_HEIGHT,
|
||||
Tst_PHOTO_SAVED_QUALITY);
|
||||
|
||||
/***** Get question feedback *****/
|
||||
Par_GetParToHTML ("Feedback",Feedback,Cns_MAX_BYTES_TEXT);
|
||||
|
||||
/***** Get type of image *****/
|
||||
Gbl.Image.Action = Img_GetImageActionFromForm ("ImgAct");
|
||||
switch (Gbl.Image.Action)
|
||||
{
|
||||
case Img_ACTION_NO_IMAGE: // Do not use image (remove current image if exists)
|
||||
/***** Reset image name *****/
|
||||
Gbl.Test.Image[0] = '\0';
|
||||
Gbl.Image.Status = Img_FILE_NONE;
|
||||
break;
|
||||
case Img_ACTION_KEEP_IMAGE: // Keep current image unchanged
|
||||
/***** Get image from database *****/
|
||||
Tst_GetImageNameFromDB ();
|
||||
Gbl.Image.Status = (Gbl.Test.Image[0] ? Img_NAME_STORED_IN_DB :
|
||||
Img_FILE_NONE);
|
||||
break;
|
||||
case Img_ACTION_CHANGE_IMAGE: // Upload new image (remove current image if exists)
|
||||
/***** Get new image (if present ==> process and create temporary file) *****/
|
||||
Img_GetAndProcessImageFromForm (Tst_PHOTO_SAVED_MAX_WIDTH,
|
||||
Tst_PHOTO_SAVED_MAX_HEIGHT,
|
||||
Tst_PHOTO_SAVED_QUALITY);
|
||||
if (Gbl.Image.Status != Img_FILE_PROCESSED && // No new image received-processed successfully
|
||||
Gbl.Test.QstCod > 0) // Question exists
|
||||
{
|
||||
/* Get possible image from database */
|
||||
Tst_GetImageNameFromDB ();
|
||||
Gbl.Image.Status = (Gbl.Test.Image[0] ? Img_NAME_STORED_IN_DB :
|
||||
Img_FILE_NONE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/***** Get answers *****/
|
||||
Gbl.Test.Shuffle = false;
|
||||
switch (Gbl.Test.AnswerType)
|
||||
|
@ -5056,7 +5047,8 @@ bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (void)
|
|||
bool ThereIsEndOfAnswers;
|
||||
unsigned i;
|
||||
|
||||
if (Gbl.Image.Action == Img_ACTION_CHANGE_IMAGE &&
|
||||
if ((Gbl.Image.Action == Img_ACTION_NEW_IMAGE || // Upload new image
|
||||
Gbl.Image.Action == Img_ACTION_CHANGE_IMAGE) && // Replace existing image by new image
|
||||
Gbl.Image.Status != Img_FILE_PROCESSED)
|
||||
{
|
||||
Lay_ShowAlert (Lay_WARNING,Txt_Error_receiving_or_processing_image);
|
||||
|
|
|
@ -399,7 +399,8 @@ void TsI_ImportQstsFromXML (void)
|
|||
Fil_RemoveOldTmpFiles (PathTestPriv,Cfg_TIME_TO_DELETE_TEST_TMP_FILES,false);
|
||||
|
||||
/***** First of all, copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
Param = Fil_StartReceptionOfFile (FileNameXMLSrc,MIMEType);
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNameXMLSrc,MIMEType);
|
||||
|
||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||
if (strcmp (MIMEType,"text/xml"))
|
||||
|
|
Loading…
Reference in New Issue