Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

header.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Header Template
  4. *
  5. * Uses HTML5, but all template HTML is (should be) xHTML 1.1 compatable
  6. */
  7. class Header{
  8. private $title = "Template";
  9. private $scripts = array();
  10. private $stylesheets = array(
  11. "https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;600;800&display=swap"
  12. );
  13. /*
  14. * The Attributes array. Holds data for the page.
  15. */
  16. private $attributes = array(
  17. "title" => "Template",
  18. "tagline" => "A Tyzoid Production",
  19. "showbar" => true,
  20. "loginbar" => ""
  21. );
  22. /**
  23. * Constructor
  24. *
  25. * @param string $title - the title of the page
  26. * @param mixed $scripts - the url (or array of urls) of the script(s) to include
  27. * @param mixed $stylesheets - the url (or array of urls) of the stylesheet(s) to include
  28. */
  29. public function __construct($title = null, $scripts = null, $stylesheets = null){
  30. // Page Title
  31. if (! empty($title)) $this->title = $title;
  32. if (! empty($scripts) && is_array($scripts)) $this->scripts = array_merge($scripts, $this->scripts);
  33. else if (! empty($scripts)) $this->addScript($scripts);
  34. if (! empty($stylesheets) && is_array($stylesheets)) $this->stylesheets = array_merge($stylesheets, $this->stylesheets);
  35. else if (! empty($stylesheets)) $this->addStyle($stylesheets);
  36. }
  37. public function setTitle($title){
  38. $this->title = $title;
  39. }
  40. public function addScript($script){
  41. if (empty($script) || strncmp($script, '/', 1) !== 0) return false;
  42. $this->scripts[] = $script;
  43. return true;
  44. }
  45. public function addStyle($stylesheet){
  46. if (empty($stylesheet) || strncmp($stylesheet, '/', 1) !== 0) return false;
  47. $this->stylesheets[] = $stylesheet;
  48. return true;
  49. }
  50. public function setAttribute($attribute, $value){
  51. $this->attributes[$attribute] = $value;
  52. }
  53. public function output($return = false){
  54. global $user;
  55. // Doctype
  56. $html = "<!doctype html>\n";
  57. $html .= "<html>\n";
  58. $html .= "\t<head>\n";
  59. // Page Attributes/Head information
  60. $html .= "\t\t<title>" . $this->title . "</title>";
  61. // Set mobile-friendly
  62. $html .= '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />';
  63. // Stylesheet import
  64. foreach ($this->stylesheets as $style){
  65. $html .= "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"$style\" />\n";
  66. }
  67. // Script import
  68. foreach ($this->scripts as $script){
  69. $html .= "\t\t<script type=\"text/javascript\" src=\"$script\"></script>\n";
  70. }
  71. // Start Body of the page
  72. $html .= "\t</head>\n";
  73. $html .= "\t<body>\n";
  74. // Page layout
  75. $html .= "\t\t<div id=\"container\">\n";
  76. // Login/Statusbar
  77. $html .= "\t\t\t<div class=\"loginbar\">\n";
  78. if ($user->loggedin()) {
  79. $html .= "\t\t\t\t" . $user->name() . "\n";
  80. $html .= "\t\t\t\t" . " <a href=\"/login.php?logout\">Log Out</a>\n";
  81. if ($user->getRole() === "admin")
  82. $html .= "\t\t\t\t" . " <a href=\"/admin/checkin.php\">Poll Worker</a>\n";
  83. $html .= "\t\t\t\t<a href=\"/index.php\">Home</a>\n";
  84. } else if (basename($_SERVER['PHP_SELF']) != 'login.php') {
  85. $html .= "\t\t\t\t<a href=\"/login.php\">Log In</a>\n";
  86. } else {
  87. $html .= "\t\t\t\t<a href=\"/index.php\">Home</a>\n";
  88. }
  89. $html .= "\t\t\t</div>\n";
  90. $html .= "\t\t\t<div class=\"header\">\n";
  91. $html .= "\t\t\t\t<h1>{$this->attributes['title']}</h1>\n";
  92. $html .= "\t\t\t\t<h2>{$this->attributes['tagline']}</h2>\n";
  93. $html .= "\t\t\t</div>\n";
  94. $html .= "\t\t\t<div class=\"content\">\n";
  95. $html .= "\t\t\t\t<div class=\"page\">\n";
  96. //End divs should be closed in the footer template
  97. if($return === true) return $html;
  98. echo $html;
  99. }
  100. }