swad-core/swad_QR.c

164 lines
6.8 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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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"
#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 *******************/
/*****************************************************************************/
2017-03-01 18:53:51 +01:00
void QR_PutLinkToPrintQRCode (Act_Action_t Action)
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 *****/
2016-12-06 23:35:15 +01:00
Lay_PutContextualLink (Action,QR_PutParamQRString,
2016-07-01 16:32:42 +02:00
"qr64x64.gif",
2017-03-01 18:53:51 +01:00
Txt_QR_code,NULL,
2016-07-01 16:32:42 +02:00
NULL);
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-01-28 15:58:46 +01:00
char QRString[Cns_MAX_BYTES_STRING + 1];
2014-12-01 23:55:08 +01:00
/***** Get QR string *****/
Par_GetParToText ("QRString",QRString,Cns_MAX_BYTES_STRING);
/***** 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
{
2016-12-07 00:41:36 +01:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\""
" style=\"margin:0 auto; width:%upx;\">"
2014-12-01 23:55:08 +01:00
"<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;"
" border:1px dashed silver;\" />"
2014-12-01 23:55:08 +01:00
"</div>",
QR_CODE_SIZE,
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);
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;
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_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,
2015-12-07 23:13:08 +01:00
Txt_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)
{
2016-04-23 23:39:07 +02:00
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Link_to_announcement_of_exam;
/***** Show QR code with direct link to the exam announcement *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">"
2015-03-07 21:08:44 +01:00
"<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\""
2015-09-28 18:28:29 +02:00
" style=\"width:250px; height:250px;\" />"
2014-12-01 23:55:08 +01:00
"</div>",
2015-09-24 18:02:21 +02:00
300,300,
2016-07-08 12:43:48 +02:00
Cfg_URL_SWAD_CGI,Gbl.CurrentCrs.Crs.CrsCod,Act_Actions[ActSeeAllExaAnn].ActCod,
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);
}