swad-core/swad_logo.c

431 lines
14 KiB
C
Raw Normal View History

2015-01-17 20:07:13 +01:00
// swad_logo.c: logo of institution, centre or degree
/*
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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
2015-01-17 20:07:13 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 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 <string.h> // For string functions
#include "swad_action.h"
#include "swad_global.h"
#include "swad_scope.h"
#include "swad_theme.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal constants ****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal prototypes ***************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Draw degree logo *****************************/
/*****************************************************************************/
void Log_DrawLogo (Sco_Scope_t Scope,long Cod,const char *AltText,
2015-08-06 12:31:05 +02:00
unsigned Size,const char *Class,bool PutIconIfNotExists)
2015-01-17 20:07:13 +01:00
{
2015-02-03 11:34:59 +01:00
static const char *Icon[Sco_NUM_SCOPES] =
{
NULL, // Sco_SCOPE_UNK
NULL, // Sco_SCOPE_SYS
NULL, // Sco_SCOPE_CTY
Cfg_FOLDER_INS, // Sco_SCOPE_INS
Cfg_FOLDER_CTR, // Sco_SCOPE_CTR
Cfg_FOLDER_DEG, // Sco_SCOPE_DEG
NULL, // Sco_SCOPE_CRS
};
2015-02-03 18:43:55 +01:00
const char *Folder = NULL; // To avoid warning
2017-01-28 15:58:46 +01:00
char PathLogo[PATH_MAX + 1];
2015-02-03 11:34:59 +01:00
bool LogoFound = false;
2015-02-10 14:58:50 +01:00
long InsCod;
long CtrCod;
long DegCod;
2015-01-17 20:07:13 +01:00
/***** Path to logo *****/
2015-02-10 14:58:50 +01:00
if (Icon[Scope]) // Scope is correct
2015-01-17 20:07:13 +01:00
{
2015-02-10 14:58:50 +01:00
if (Cod > 0) // Institution, centre or degree exists
2015-02-03 11:34:59 +01:00
{
2015-02-10 14:58:50 +01:00
/* Degree */
2015-02-03 11:34:59 +01:00
if (Scope == Sco_SCOPE_DEG)
2015-02-10 14:58:50 +01:00
{
Folder = Cfg_FOLDER_DEG;
DegCod = Cod;
sprintf (PathLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (DegCod % 100),
(unsigned) DegCod,
(unsigned) DegCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
2015-02-10 15:07:28 +01:00
if (LogoFound)
Cod = DegCod;
2015-02-10 14:58:50 +01:00
}
/* Centre */
if (!LogoFound && Scope != Sco_SCOPE_INS)
{
Folder = Cfg_FOLDER_CTR;
if (Scope == Sco_SCOPE_DEG) // && !LogoFound
CtrCod = Deg_GetCtrCodOfDegreeByCod (Cod);
else
CtrCod = Cod;
sprintf (PathLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (CtrCod % 100),
(unsigned) CtrCod,
(unsigned) CtrCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
2015-02-10 15:07:28 +01:00
if (LogoFound)
Cod = CtrCod;
2015-02-10 14:58:50 +01:00
}
/* Institution */
if (!LogoFound)
{
Folder = Cfg_FOLDER_INS;
if (Scope == Sco_SCOPE_DEG) // && !LogoFound
InsCod = Deg_GetInsCodOfDegreeByCod (Cod);
else if (Scope == Sco_SCOPE_CTR) // && !LogoFound
InsCod = Ctr_GetInsCodOfCentreByCod (Cod);
else
InsCod = Cod;
sprintf (PathLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (InsCod % 100),
(unsigned) InsCod,
(unsigned) InsCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
2015-02-10 15:07:28 +01:00
if (LogoFound)
Cod = InsCod;
2015-02-10 14:58:50 +01:00
}
2015-02-03 11:34:59 +01:00
2016-07-27 14:58:26 +02:00
if (LogoFound || PutIconIfNotExists)
{
/***** Draw logo *****/
fprintf (Gbl.F.Out,"<img src=\"");
if (LogoFound)
fprintf (Gbl.F.Out,"%s/%s/%02u/%u/logo/%u.png",
Cfg_URL_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
else if (Icon[Scope])
fprintf (Gbl.F.Out,"%s/%s64x64.gif",
Gbl.Prefs.IconsURL,Icon[Scope]);
fprintf (Gbl.F.Out,"\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO%ux%u",
2016-07-27 14:58:26 +02:00
AltText,AltText,
Size,Size);
if (Class)
if (Class[0])
fprintf (Gbl.F.Out," %s",Class);
fprintf (Gbl.F.Out,"\" />");
}
2015-02-03 11:34:59 +01:00
}
2015-01-17 20:07:13 +01:00
}
}
/*****************************************************************************/
2016-05-05 20:16:28 +02:00
/************* Put an icon to go to the action used to request ***************/
/************* the logo of institution, centre or degree ***************/
2015-01-17 20:07:13 +01:00
/*****************************************************************************/
2016-05-05 20:16:28 +02:00
void Log_PutIconToChangeLogo (Sco_Scope_t Scope)
2015-01-17 20:07:13 +01:00
{
extern const char *Txt_Change_logo;
extern const char *Txt_Upload_logo;
Act_Action_t Action;
long Cod;
const char *Folder;
2017-01-28 15:58:46 +01:00
char PathLogo[PATH_MAX + 1];
2015-01-17 20:07:13 +01:00
bool LogoExists;
/***** Set variables depending on scope *****/
switch (Scope)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2015-01-17 20:07:13 +01:00
Action = ActReqInsLog;
Cod = Gbl.CurrentIns.Ins.InsCod;
Folder = Cfg_FOLDER_INS;
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2015-01-17 20:07:13 +01:00
Action = ActReqCtrLog;
Cod = Gbl.CurrentCtr.Ctr.CtrCod;
Folder = Cfg_FOLDER_CTR;
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2015-01-17 20:07:13 +01:00
Action = ActReqDegLog;
Cod = Gbl.CurrentDeg.Deg.DegCod;
Folder = Cfg_FOLDER_DEG;
break;
default:
return; // Nothing to do
}
/***** Check if logo exists *****/
sprintf (PathLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
LogoExists = Fil_CheckIfPathExists (PathLogo);
/***** Link for changing / uploading the logo *****/
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (Action,NULL,NULL,
2016-07-01 16:32:42 +02:00
"logo64x64.png",
2015-12-13 19:02:06 +01:00
LogoExists ? Txt_Change_logo :
2016-07-01 16:32:42 +02:00
Txt_Upload_logo,NULL,
2016-05-05 20:16:28 +02:00
NULL);
2015-01-17 20:07:13 +01:00
}
/*****************************************************************************/
/**** Show a form for sending a logo of the institution, centre or degree ****/
/*****************************************************************************/
void Log_RequestLogo (Sco_Scope_t Scope)
{
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2015-12-13 20:24:39 +01:00
extern const char *Txt_Remove_logo;
2015-04-12 01:40:51 +02:00
extern const char *Txt_Logo;
2016-11-10 12:38:41 +01:00
extern const char *Txt_You_can_send_a_file_with_an_image_in_PNG_format_transparent_background_and_size_X_Y;
2015-01-17 20:07:13 +01:00
extern const char *Txt_File_with_the_logo;
2015-02-03 18:43:55 +01:00
long Cod;
const char *Folder;
Act_Action_t ActionRec;
Act_Action_t ActionRem;
2017-01-28 15:58:46 +01:00
char PathLogo[PATH_MAX + 1];
2015-01-17 20:07:13 +01:00
/***** Set action depending on scope *****/
switch (Scope)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2015-02-03 18:43:55 +01:00
Cod = Gbl.CurrentIns.Ins.InsCod;
Folder = Cfg_FOLDER_INS;
ActionRec = ActRecInsLog;
ActionRem = ActRemInsLog;
2015-01-17 20:07:13 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2015-02-03 18:43:55 +01:00
Cod = Gbl.CurrentCtr.Ctr.CtrCod;
Folder = Cfg_FOLDER_CTR;
ActionRec = ActRecCtrLog;
ActionRem = ActRemCtrLog;
2015-01-17 20:07:13 +01:00
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2015-02-03 18:43:55 +01:00
Cod = Gbl.CurrentDeg.Deg.DegCod;
Folder = Cfg_FOLDER_DEG;
ActionRec = ActRecDegLog;
ActionRem = ActRemDegLog;
2015-01-17 20:07:13 +01:00
break;
default:
return; // Nothing to do
}
2015-02-03 18:43:55 +01:00
/***** Check if logo exists *****/
sprintf (PathLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
if (Fil_CheckIfPathExists (PathLogo))
{
/***** Form to remove photo *****/
2015-08-06 13:18:36 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2017-04-17 19:03:21 +02:00
Lay_PutContextualLink (ActionRem,NULL,NULL,
2016-07-01 16:32:42 +02:00
"remove-on64x64.png",
Txt_Remove_logo,Txt_Remove_logo,
NULL);
2015-02-03 18:43:55 +01:00
fprintf (Gbl.F.Out,"</div>");
}
2015-04-12 01:40:51 +02:00
/***** Start form to upload logo *****/
Act_FormStart (ActionRec);
/***** Start frame *****/
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (NULL,Txt_Logo,NULL,NULL);
2015-04-12 01:40:51 +02:00
2015-01-17 20:07:13 +01:00
/***** Write help message *****/
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_You_can_send_a_file_with_an_image_in_PNG_format_transparent_background_and_size_X_Y,
2015-01-17 20:07:13 +01:00
64,64);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt);
2015-01-17 20:07:13 +01:00
2015-04-12 01:40:51 +02:00
/***** Upload logo *****/
fprintf (Gbl.F.Out,"<label class=\"%s\">"
2016-12-20 02:18:50 +01:00
"%s:&nbsp;"
2015-04-12 18:01:06 +02:00
"<input type=\"file\" name=\"%s\""
2016-12-20 02:18:50 +01:00
" onchange=\"document.getElementById('%s').submit();\" />"
"</label>",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],
2015-01-17 20:07:13 +01:00
Txt_File_with_the_logo,
2016-03-29 00:55:25 +02:00
Fil_NAME_OF_PARAM_FILENAME_ORG,
Gbl.Form.Id);
2015-04-12 01:40:51 +02:00
2016-03-29 00:55:25 +02:00
/***** End frame *****/
Lay_EndRoundFrame ();
2015-04-12 01:40:51 +02:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2015-01-17 20:07:13 +01:00
}
/*****************************************************************************/
/******* Receive the logo of the current institution, centre or degree *******/
/*****************************************************************************/
void Log_ReceiveLogo (Sco_Scope_t Scope)
{
extern const char *Txt_The_file_is_not_X;
long Cod;
const char *Folder;
2017-01-28 15:58:46 +01:00
char Path[PATH_MAX + 1];
2016-04-01 01:59:27 +02:00
struct Param *Param;
2017-01-28 15:58:46 +01:00
char FileNameLogoSrc[PATH_MAX + 1];
2017-01-15 18:02:52 +01:00
char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1];
2017-01-28 15:58:46 +01:00
char FileNameLogo[PATH_MAX + 1]; // Full name (including path and .png) of the destination file
2015-01-17 20:07:13 +01:00
bool WrongType = false;
/***** Set variables depending on scope *****/
switch (Scope)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2015-01-17 20:07:13 +01:00
Cod = Gbl.CurrentIns.Ins.InsCod;
Folder = Cfg_FOLDER_INS;
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2015-01-17 20:07:13 +01:00
Cod = Gbl.CurrentCtr.Ctr.CtrCod;
Folder = Cfg_FOLDER_CTR;
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2015-01-17 20:07:13 +01:00
Cod = Gbl.CurrentDeg.Deg.DegCod;
Folder = Cfg_FOLDER_DEG;
break;
default:
return; // Nothing to do
}
/***** Creates directories if not exist *****/
sprintf (Path,"%s/%s",
Cfg_PATH_SWAD_PUBLIC,Folder);
Fil_CreateDirIfNotExists (Path);
sprintf (Path,"%s/%s/%02u",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100));
Fil_CreateDirIfNotExists (Path);
sprintf (Path,"%s/%s/%02u/%u",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod);
Fil_CreateDirIfNotExists (Path);
sprintf (Path,"%s/%s/%02u/%u/logo",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod);
Fil_CreateDirIfNotExists (Path);
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
2016-04-04 12:13:37 +02:00
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
FileNameLogoSrc,MIMEType);
2015-01-17 20:07:13 +01:00
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
if (strcmp (MIMEType,"image/png"))
if (strcmp (MIMEType,"image/x-png"))
if (strcmp (MIMEType,"application/octet-stream"))
if (strcmp (MIMEType,"application/octetstream"))
if (strcmp (MIMEType,"application/octet"))
WrongType = true;
if (WrongType)
{
2017-05-10 10:25:01 +02:00
sprintf (Gbl.Alert.Txt,Txt_The_file_is_not_X,"png");
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2015-01-17 20:07:13 +01:00
}
2015-02-03 18:43:55 +01:00
else
{
/* End the reception of logo in a temporary file */
sprintf (FileNameLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
2016-04-01 01:59:27 +02:00
if (!Fil_EndReceptionOfFile (FileNameLogo,Param))
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,"Error copying file.");
2015-02-03 18:43:55 +01:00
}
}
2015-01-17 20:07:13 +01:00
2015-02-03 18:43:55 +01:00
/*****************************************************************************/
/******* Remove the logo of the current institution, centre or degree ********/
/*****************************************************************************/
void Log_RemoveLogo (Sco_Scope_t Scope)
{
long Cod;
const char *Folder;
2017-01-28 15:58:46 +01:00
char FileNameLogo[PATH_MAX + 1]; // Full name (including path and .png) of the destination file
2015-02-03 18:43:55 +01:00
/***** Set variables depending on scope *****/
switch (Scope)
{
case Sco_SCOPE_INS:
Cod = Gbl.CurrentIns.Ins.InsCod;
Folder = Cfg_FOLDER_INS;
break;
case Sco_SCOPE_CTR:
Cod = Gbl.CurrentCtr.Ctr.CtrCod;
Folder = Cfg_FOLDER_CTR;
break;
case Sco_SCOPE_DEG:
Cod = Gbl.CurrentDeg.Deg.DegCod;
Folder = Cfg_FOLDER_DEG;
break;
default:
return; // Nothing to do
}
/***** Remove logo *****/
2015-01-17 20:07:13 +01:00
sprintf (FileNameLogo,"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (FileNameLogo);
2015-01-17 20:07:13 +01:00
}