// 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. Copyright (C) 1999-2015 Antonio Caņas Vargas 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 . */ /*****************************************************************************/ /*********************************** Headers *********************************/ /*****************************************************************************/ #include // 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,"\"%s\""", Gbl.Prefs.IconsURL, Txt_QR_code); if (PrintText) fprintf (Gbl.F.Out," %s",Txt_QR_code); fprintf (Gbl.F.Out,"" ""); } /*****************************************************************************/ /******************************* 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) { fprintf (Gbl.F.Out,"
" "\"%s\"
" "%s" "
", QR_CODE_SIZE, QR_CODE_SIZE,QR_CODE_SIZE, QRString, QRString, QR_CODE_SIZE,QR_CODE_SIZE, 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,"\"%s\"", Size,Size, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCty.Cty.CtyCod, Txt_Shortcut_to_this_country, Size,Size); } /*****************************************************************************/ /********* 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,"\"%s\"", Size,Size, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentIns.Ins.InsCod, Txt_Shortcut_to_this_institution, Size,Size); } /*****************************************************************************/ /************ 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,"\"%s\"", Size,Size, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCtr.Ctr.CtrCod, Txt_Shortcut_to_this_centre, Size,Size); } /*****************************************************************************/ /************ 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,"\"%s\"", Size,Size, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentDeg.Deg.DegCod, Txt_Shortcut_to_this_degree, Size,Size); } /*****************************************************************************/ /************ 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,"\"%s\"", Size,Size, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCrs.Crs.CrsCod, Txt_Shortcut_to_this_course, Size,Size); } /*****************************************************************************/ /*********** 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 *****/ fprintf (Gbl.F.Out,"
" "\"%s\"" "
", 200,200, Cfg_HTTPS_URL_SWAD_CGI,Gbl.CurrentCrs.Crs.CrsCod,Act_Actions[ActSeeExaAnn].ActCod, Txt_Link_to_announcement_of_exam); }