swad-core/swad_QR.c

162 lines
6.6 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_QR.c: QR codes
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +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 "swad_action.h"
#include "swad_global.h"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_ID.h"
#include "swad_parameter.h"
#include "swad_QR.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal constants ****************************/
/*****************************************************************************/
2017-01-28 15:58:46 +01:00
#define QR_CODE_SIZE ((6 + 25 + 6) * 8)
2014-12-01 23:55:08 +01:00
#define QR_DEFAULT_TYPE QR_ID
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal prototypes ***************************/
/*****************************************************************************/
/*****************************************************************************/
/***************** Put a link to a print view of a QR code *******************/
/*****************************************************************************/
2019-04-11 14:45:31 +02:00
void QR_PutLinkToPrintQRCode (Act_Action_t Action,void (*FuncParams) (void))
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_QR_code;
2015-12-13 20:46:46 +01:00
/***** Link to print QR *****/
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (Action,NULL,FuncParams,
"qrcode.svg",
Txt_QR_code);
2015-12-13 20:46:46 +01:00
}
/*****************************************************************************/
/************************* Put parameter QR string ***************************/
/*****************************************************************************/
2017-03-01 12:59:49 +01:00
void QR_PutParamQRString (void)
2015-12-13 20:46:46 +01:00
{
2016-12-05 09:38:34 +01:00
Par_PutHiddenParamString ("QRString",Gbl.QR.Str);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Show a QR code ******************************/
/*****************************************************************************/
void QR_PrintQRCode (void)
{
2017-03-08 14:12:33 +01:00
char QRString[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
/***** Get QR string *****/
2017-03-08 14:12:33 +01:00
Par_GetParToText ("QRString",QRString,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/***** Show QR code *****/
QR_ImageQRCode (QRString);
}
/*****************************************************************************/
/******************** Write an QR (image) based on a string ******************/
/*****************************************************************************/
2017-03-01 18:53:51 +01:00
void QR_ImageQRCode (const char *QRString)
2014-12-01 23:55:08 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CM\" style=\"margin:0 auto; width:%upx;\"",
QR_CODE_SIZE);
2019-10-23 21:12:40 +02:00
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s\""
2015-07-22 13:49:39 +02:00
" alt=\"%s\" title=\"%s\""
2015-09-24 18:02:21 +02:00
" style=\"width:%upx; height:%upx;"
2019-10-23 20:07:56 +02:00
" border:1px dashed silver;\" />",
2014-12-01 23:55:08 +01:00
QR_CODE_SIZE,QR_CODE_SIZE,
QRString,
QRString,
2015-07-22 13:49:39 +02:00
QRString,
2016-12-07 00:41:36 +01:00
QR_CODE_SIZE,QR_CODE_SIZE);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2015-03-07 18:09:42 +01:00
/*************** Show QR code with direct link (shortcut URL) ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-03-07 18:09:42 +01:00
void QR_LinkTo (unsigned Size,const char *ParamStr,long Cod)
2014-12-01 23:55:08 +01:00
{
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
/***** Show QR code with direct link to the current centre *****/
2015-09-24 18:02:21 +02:00
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/%s?%s=%ld\""
2015-07-22 13:49:39 +02:00
" alt=\"%s\" title=\"%s\""
2015-09-24 18:02:21 +02:00
" style=\"width:%upx; height:%upx;\" />",
Size,Size,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],ParamStr,Cod,
2015-03-07 18:09:42 +01:00
Txt_Shortcut,
2015-07-22 13:49:39 +02:00
Txt_Shortcut,
2014-12-29 21:35:12 +01:00
Size,Size);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Show QR code with direct link to an exam announcement ***********/
/*****************************************************************************/
void QR_ExamAnnnouncement (void)
{
extern const char *Txt_Link_to_announcement_of_exam;
/***** Show QR code with direct link to the exam announcement *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2019-10-23 21:12:40 +02:00
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?crs=%ld%%26act=%ld\""
2015-07-22 13:49:39 +02:00
" alt=\"%s\" title=\"%s\""
2019-10-23 20:07:56 +02:00
" style=\"width:250px; height:250px;\" />",
2015-09-24 18:02:21 +02:00
300,300,
2019-04-04 10:45:15 +02:00
Cfg_URL_SWAD_CGI,Gbl.Hierarchy.Crs.CrsCod,Act_GetActCod (ActSeeAllExaAnn),
2015-07-22 13:49:39 +02:00
Txt_Link_to_announcement_of_exam,
2014-12-01 23:55:08 +01:00
Txt_Link_to_announcement_of_exam);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}