PhoenixLecture  2.0.0
Set of tools to make lectures
redirect_html.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 
8 #include "redirect_html.h"
9 
11 
15 bool redirect_html(const PPath & fileName, const PMapLabel & mapLabel){
16  PString body("<!DOCTYPE html>\n");
17  body += "<html lang=\"fr\">\n";
18  body += "\t<head>\n";
19  body += "\t\t<meta charset=\"utf-8\" />\n";
20  body += "\t\t<title>Page redirection</title>\n";
21  body += "\t\t<link rel=\"stylesheet\" href=\"style.css\" />\n";
22  body += "\t\t<script type=\"text/javascript\">\n";
23  body += "\t\t\tfunction redirectionWithLabelReference(){\n";
24 
25  body += "\t\t\t\tvar parameters = location.search.substring(1).split(\"?\");\n";
26  body += "\t\t\t\tvar tmp = parameters[0].split(\"=\");\n";
27  body += "\t\t\t\treferenceName = unescape(tmp[1]);\n";
28 
29  body += "\t\t\t\tvar dictReference = {";
30  bool isComma(false);
31  for(PMapLabel::const_iterator it(mapLabel.begin()); it != mapLabel.end(); ++it){
32  if(isComma){body += ",";}
33  body += "\n\t\t\t\t\t\""+it->first+"\": \""+it->second.first+"\"";
34  isComma = true;
35  }
36  body += "\n\t\t\t\t};\n";
37  body += "\t\t\t\tif(referenceName in dictReference){\n";
38  body += "\t\t\t\t\tdocument.location.href=dictReference[referenceName];\n";
39  body += "\t\t\t\t}else{\n";
40  body += "\t\t\t\t\tdocument.location.href=\"index.html\";\n";
41  body += "\t\t\t\t}\n";
42  body += "\t\t\t}\n";
43  body += "\t\t</script>\n";
44  body += "\t</head>\n";
45  body += "\t<body onLoad=\"setTimeout('redirectionWithLabelReference()', 1000)\">\n";
46  body += "\t\t<div>Dans 2 secondes vous allez être redirigé vers la page que vous avez demandée... normalement</div>\n";
47  body += "\t</body>\n";
48  body += "</html>\n\n";
49  return fileName.saveFileContent(body);
50 }
51 
52 
53 
Path of a directory or a file.
Definition: PPath.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
Extends the std::string.
Definition: PString.h:16
bool redirect_html(const PPath &fileName, const PMapLabel &mapLabel)
Create the redirection page to get page with label name as reference.
std::map< PString, std::pair< PString, PString > > PMapLabel
Map of the label (name, link)