PageRenderTime 19ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/index/index.php

https://github.com/harriswong/ATutor
PHP | 164 lines | 137 code | 20 blank | 7 comment | 35 complexity | 65bd22508cedb885d782e4f9a333dc8e MD5 | raw file
  1. <?php
  2. require(dirname(__FILE__) .'/../common/vitals.inc.php');
  3. // using 401 authentication
  4. if (isset($_GET['login'])) {
  5. if (!isset($_SERVER['PHP_AUTH_USER'])) {
  6. header('WWW-Authenticate: Basic realm="Administrator Login"');
  7. header('HTTP/1.0 401 Unauthorized');
  8. echo 'Wrong username/password combination.';
  9. exit;
  10. } else {
  11. $_POST['username'] = $_SERVER['PHP_AUTH_USER'];
  12. $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
  13. $_POST['submit'] = true;
  14. }
  15. unset($_SERVER['PHP_AUTH_USER']);
  16. unset($_SERVER['PHP_AUTH_PW']);
  17. }
  18. $config_location = '../../include/config.inc.php';
  19. if (is_file($config_location) && is_readable($config_location)) {
  20. require($config_location);
  21. $db = mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);
  22. mysql_select_db(DB_NAME, $db);
  23. // check atutor config table to see if handbook notes is enabled.
  24. $sql = "SELECT value FROM ".TABLE_PREFIX."config WHERE name='user_notes'";
  25. $result = @mysql_query($sql, $db);
  26. if (($row = mysql_fetch_assoc($result)) && $row['value']) {
  27. define('AT_HANDBOOK_ENABLE', true);
  28. $enable_user_notes = true;
  29. }
  30. define('AT_HANDBOOK_DB_TABLE_PREFIX', TABLE_PREFIX);
  31. if (isset($_POST['submit'])) {
  32. // try to validate $_POST
  33. // authenticate against the ATutor database if a connection can be made
  34. $_POST['username'] = addslashes($_POST['username']);
  35. $_POST['password'] = addslashes($_POST['password']);
  36. if (!$db) {
  37. $db = @mysql_connect(AT_HANDBOOK_DB_HOST . ':' . AT_HANDBOOK_DB_PORT, AT_HANDBOOK_DB_USER, AT_HANDBOOK_DB_PASSWORD);
  38. if (@mysql_select_db(AT_HANDBOOK_DB_DATABASE, $db)) {
  39. $enable_user_notes = true;
  40. }
  41. }
  42. // check if it's an admin login.
  43. $sql = "SELECT login, `privileges` FROM ".TABLE_PREFIX."admins WHERE login='$_POST[username]' AND PASSWORD(password)=PASSWORD('$_POST[password]') AND `privileges`>0";
  44. $result = mysql_query($sql, $db);
  45. if ($row = mysql_fetch_assoc($result)) {
  46. $_SESSION['handbook_admin'] = true;
  47. header('Location: '.$_SERVER['PHP_SELF']);
  48. exit;
  49. }
  50. } else if (isset($_GET['logout'])) {
  51. header('WWW-Authenticate: Basic realm="Administrator Login"');
  52. header('HTTP/1.0 401 Unauthorized');
  53. unset($_SERVER['PHP_AUTH_USER']);
  54. unset($_SERVER['PHP_AUTH_PW']);
  55. unset($_SESSION['handbook_admin']);
  56. session_write_close();
  57. header('Location: '.$_SERVER['PHP_SELF']);
  58. exit;
  59. }
  60. }
  61. if (!defined('AT_HANDBOOK_ENABLE')) {
  62. // use local config file
  63. require('../config.inc.php');
  64. if (isset($_POST['submit'])) {
  65. // try to validate $_POST
  66. if (($_POST['username'] == AT_HANDBOOK_ADMIN_USERNAME) && ($_POST['password'] == AT_HANDBOOK_ADMIN_PASSWORD)) {
  67. $_SESSION['handbook_admin'] = true;
  68. header('Location: '.$_SERVER['PHP_SELF']);
  69. exit;
  70. }
  71. } else if (key($_GET) == 'logout') {
  72. header('WWW-Authenticate: Basic realm="Administrator Login"');
  73. header('HTTP/1.0 401 Unauthorized');
  74. unset($_SERVER['PHP_AUTH_USER']);
  75. unset($_SERVER['PHP_AUTH_PW']);
  76. unset($_SESSION['handbook_admin']);
  77. session_write_close();
  78. header('Location: '.$_SERVER['PHP_SELF']);
  79. exit;
  80. }
  81. }
  82. if (!$db && defined('AT_HANDBOOK_ENABLE') && AT_HANDBOOK_ENABLE) {
  83. $db = @mysql_connect(AT_HANDBOOK_DB_HOST . ':' . AT_HANDBOOK_DB_PORT, AT_HANDBOOK_DB_USER, AT_HANDBOOK_DB_PASSWORD);
  84. @mysql_select_db(AT_HANDBOOK_DB_DATABASE, $db);
  85. $enable_user_notes = true;
  86. }
  87. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  88. <html lang="<?php if ($req_lang) { echo $req_lang; } else { echo 'dp'; } ?>">
  89. <head>
  90. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  91. <title><?php get_text('doc_title'); ?></title>
  92. <link rel="stylesheet" href="../common/styles.css" type="text/css" />
  93. </head>
  94. <body>
  95. <?php if ($missing_lang): ?>
  96. <div style="margin: 20px auto; border: 1px solid #aaf; padding: 4px; text-align: center; background-color: #eef;">
  97. <?php get_text('page_not_translated'); ?>
  98. </div>
  99. <?php endif; ?>
  100. <h1><?php get_text('doc_title'); ?></h1>
  101. <p><?php get_text('doc_welcome'); ?></p>
  102. <ol>
  103. <li><a href="../general/index.php?<?php echo $req_lang; ?>"><?php get_text('doc_user'); ?></a></li>
  104. <li><a href="../admin/index.php?<?php echo $req_lang; ?>"><?php get_text('doc_admin'); ?></a></li>
  105. <li><a href="../instructor/index.php?<?php echo $req_lang; ?>"><?php get_text('doc_instructor'); ?></a></li>
  106. <li><a href="../developer/guidelines.html"><?php get_text('doc_dev'); ?></a></li>
  107. <li><a href="../developer/modules.html"><?php get_text('doc_mods'); ?></a></li>
  108. <li><a href="../developer/themes.html"><?php get_text('doc_themes'); ?></a></li>
  109. </ol>
  110. <ol>
  111. <li><a href="http://www.atutor.ca" target="new">atutor.ca</a></li>
  112. <li><a href="http://www.atutor.ca/forums/" target="new">atutor.ca/forums/</a></li>
  113. <li><a href="http://www.atutor.ca/atutor/docs/index.php" target="new">atutor.ca/atutor/docs/</a></li>
  114. </ol>
  115. <?php if ($enable_user_notes && (!isset($_SESSION['handbook_admin']) || (isset($_SESSION['handbook_admin']) && !$_SESSION['handbook_admin']))): ?>
  116. <div style="text-align: right;">
  117. <p><?php get_text('doc_notes_enabled'); ?></p>
  118. </div>
  119. <?php elseif ($enable_user_notes): ?>
  120. <p><?php get_text('doc_logged_in'); ?></p>
  121. <?php
  122. $sql = "SELECT note_id, date, section, page, email, note FROM ".AT_HANDBOOK_DB_TABLE_PREFIX."handbook_notes WHERE approved=0 ORDER BY date DESC";
  123. $result = mysql_query($sql, $db);
  124. ?>
  125. <div class="add-note">
  126. <h3><?php get_text('doc_unapproved_notes'); ?></h3>
  127. </div>
  128. <?php if ($result && (mysql_num_rows($result) > 0)): ?>
  129. <?php while ($row = mysql_fetch_assoc($result)): ?>
  130. <div class="note">
  131. <h5><?php echo $row['date']; ?>
  132. <a href="../approve_note.php?id=<?php echo $row['note_id']; ?>" onclick="return confirm('<?php echo get_text('doc_approved_confirm'); ?>');"><?php get_text('doc_approve'); ?></a> |
  133. <a href="../delete_note.php?id=<?php echo $row['note_id']; ?>" onclick="return confirm('<?php echo get_text('doc_delete_confirm'); ?>');"><?php get_text('doc_delete'); ?></a>
  134. </h5>
  135. <h4><?php echo $row['email'];?></h4>
  136. <p><?php echo nl2br($row['note']); ?></p>
  137. </div>
  138. <?php endwhile; ?>
  139. <?php else: ?>
  140. <div class="note"><?php get_text('doc_no_notes'); ?></div>
  141. <?php endif; ?>
  142. <?php endif; ?>
  143. </body>
  144. </html>