swad-core/swad_QR.c

242 lines
10 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.
2015-01-01 14:34:06 +01:00
Copyright (C) 1999-2015 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 <string.h> // For strncpy...
#include "swad_action.h"
#include "swad_global.h"
#include "swad_ID.h"
#include "swad_parameter.h"
#include "swad_QR.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal constants ****************************/
/*****************************************************************************/
//#define QR_CODE_SIZE ((6+21+6)*6)
#define QR_CODE_SIZE ((6+25+6)*6)
#define QR_DEFAULT_TYPE QR_ID
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal prototypes ***************************/
/*****************************************************************************/
static void QR_ImageQRCode (const char *QRString);
/*****************************************************************************/
/***************** Put a link to a print view of a QR code *******************/
/*****************************************************************************/
void QR_PutLinkToPrintQRCode (QR_QRType_t QRType,struct UsrData *UsrDat,bool PrintText)
{
extern const char *The_ClassFormul[The_NUM_THEMES];
extern const char *Txt_QR_code;
char NicknameWithArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA+1];
/***** Link to print view *****/
Act_FormStart (ActPrnUsrQR);
switch (QRType)
{
case QR_ID:
Par_PutHiddenParamString ("QRString",UsrDat->IDs.List[0].ID); // TODO: First ID?
break;
case QR_NICKNAME:
sprintf (NicknameWithArroba,"@%s",UsrDat->Nickname);
Par_PutHiddenParamString ("QRString",NicknameWithArroba);
break;
case QR_EMAIL:
Par_PutHiddenParamString ("QRString",UsrDat->Email);
break;
}
Act_LinkFormSubmit (Txt_QR_code,The_ClassFormul[Gbl.Prefs.Theme]);
fprintf (Gbl.F.Out,"<img src=\"%s/qr16x16.gif\" alt=\"%s\""
" class=\"ICON16x16\" style=\"margin-left:10px;\" />",
Gbl.Prefs.IconsURL,
Txt_QR_code);
if (PrintText)
fprintf (Gbl.F.Out," %s",Txt_QR_code);
fprintf (Gbl.F.Out,"</a>"
"</form>");
}
/*****************************************************************************/
/******************************* Show a QR code ******************************/
/*****************************************************************************/
void QR_PrintQRCode (void)
{
char QRString[Cns_MAX_BYTES_STRING+1];
/***** 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 ******************/
/*****************************************************************************/
static void QR_ImageQRCode (const char *QRString)
{
2014-12-26 17:55:42 +01:00
fprintf (Gbl.F.Out,"<div style=\"width:%upx; text-align:center;\">"
2014-12-01 23:55:08 +01:00
"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;"
" border:1px dashed silver;\" /><br />"
2014-12-01 23:55:08 +01:00
"<span class=\"DAT\">%s</span>"
"</div>",
QR_CODE_SIZE,
QR_CODE_SIZE,QR_CODE_SIZE,
QRString,
QRString,
2014-12-29 21:35:12 +01:00
QR_CODE_SIZE,QR_CODE_SIZE,
2014-12-01 23:55:08 +01:00
QRString);
}
/*****************************************************************************/
/*********** Show QR code with direct link to the current country ************/
/*****************************************************************************/
void QR_LinkToCountry (unsigned Size)
{
extern const char *Txt_Shortcut_to_this_country;
/***** Show QR code with direct link to the current centre *****/
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?CtyCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;\" />",
2014-12-01 23:55:08 +01:00
Size,Size,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCty.Cty.CtyCod,
2014-12-29 21:35:12 +01:00
Txt_Shortcut_to_this_country,
Size,Size);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Show QR code with direct link to the current institution **********/
/*****************************************************************************/
void QR_LinkToInstitution (unsigned Size)
{
extern const char *Txt_Shortcut_to_this_institution;
/***** Show QR code with direct link to the current institution *****/
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?InsCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;\" />",
2014-12-01 23:55:08 +01:00
Size,Size,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentIns.Ins.InsCod,
2014-12-29 21:35:12 +01:00
Txt_Shortcut_to_this_institution,
Size,Size);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Show QR code with direct link to the current centre ************/
/*****************************************************************************/
void QR_LinkToCentre (unsigned Size)
{
extern const char *Txt_Shortcut_to_this_centre;
/***** Show QR code with direct link to the current centre *****/
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?CtrCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;\" />",
2014-12-01 23:55:08 +01:00
Size,Size,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCtr.Ctr.CtrCod,
2014-12-29 21:35:12 +01:00
Txt_Shortcut_to_this_centre,
Size,Size);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Show QR code with direct link to the current degree ************/
/*****************************************************************************/
void QR_LinkToDegree (unsigned Size)
{
extern const char *Txt_Shortcut_to_this_degree;
/***** Show QR code with direct link to the current degree *****/
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?DegCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;\" />",
2014-12-01 23:55:08 +01:00
Size,Size,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentDeg.Deg.DegCod,
2014-12-29 21:35:12 +01:00
Txt_Shortcut_to_this_degree,
Size,Size);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Show QR code with direct link to the current course ************/
/*****************************************************************************/
void QR_LinkToCourse (unsigned Size)
{
extern const char *Txt_Shortcut_to_this_course;
/***** Show QR code with direct link to the current course *****/
fprintf (Gbl.F.Out,"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?CrsCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:%upx; height:%upx;\" />",
2014-12-01 23:55:08 +01:00
Size,Size,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCrs.Crs.CrsCod,
2014-12-29 21:35:12 +01:00
Txt_Shortcut_to_this_course,
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 *****/
2014-12-26 17:55:42 +01:00
fprintf (Gbl.F.Out,"<div style=\"text-align:center;\">"
2014-12-01 23:55:08 +01:00
"<img src=\"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?CrsCod=%ld%%26ActCod=%ld\""
2014-12-29 21:35:12 +01:00
" alt=\"%s\" style=\"width:200px; height:200px;\" />"
2014-12-01 23:55:08 +01:00
"</div>",
200,200,
Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCrs.Crs.CrsCod,Act_Actions[ActSeeExaAnn].ActCod,
Txt_Link_to_announcement_of_exam);
}