browse-notes.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. require_once('../include/prepend.php');
  3. require_once '../include/shared-manual.inc';
  4. require_once('../include/prepend.php');
  5. commonHeader("Browse Notes"); ?>
  6. <P>
  7. These notes are only visible at <A href="http://gtk.php.net/manual/">gtk.php.net</A>
  8. because that's where the database that stores them is located. If (when) the
  9. PHP-GTK website is mirrored in several locations, we'll work out a way of
  10. having the notes available across all the mirror sites.
  11. </P><?php
  12. commonFooter();
  13. die();
  14. if (isset($_POST['cancel'])) {
  15. header("Location: {$_SERVER['PHP_SELF']}".(isset($_POST['queue']) ? '?q' : ''));
  16. exit;
  17. }
  18. makeAdminOpts();
  19. $queue = null;
  20. if ($user = get_user()) {
  21. commonHeader("Manual Notes Administration");
  22. $order = isset($_POST['order']) ? $_POST['order'] : null;
  23. if ($order) {
  24. if (!isset($_COOKIE['order']) || (isset($_COOKIE['order']) && $order != $_COOKIE['order'])) {
  25. setcookie('order', $order, time()+(3600*24*7), '/');
  26. }
  27. } else {
  28. if (isset($_COOKIE['order'])) {
  29. $order = $_COOKIE['order'];
  30. } else {
  31. $order = 'page';
  32. }
  33. }
  34. if (isset($_POST['queue']) || array_key_exists('q', $_GET)) {
  35. echo "<h1>Manual Notes Queue Administration</h1>\n\n";
  36. $notesfile = $queuefile;
  37. $queue = '&q';
  38. } else {
  39. echo "<h1>Manual Notes Administration</h1>\n\n";
  40. }
  41. $admin = true;
  42. $id = null;
  43. if (isset($_GET['delete']) && is_numeric($_GET['delete'])) {
  44. $id = $_GET['delete'];
  45. }
  46. if (isset($_GET['reject']) && is_numeric($_GET['reject'])) {
  47. $id = $_GET['reject'];
  48. $reject_text = "If you are receiving this email, it is because a note you posted for the\n";
  49. $reject_text .= "on-line PHP-GTK manual has been rejected by one of the editors.\n\n";
  50. $reject_text .= "The user contributed notes are not an appropriate place to ask questions,\n";
  51. $reject_text .= "ask questions, report bugs or suggest new features.\n\n";
  52. $reject_text .= "Bug reports and feature requests should be entered as 'PHP-GTK related'\n";
  53. $reject_text .= "at <a href = 'http://bugs.php.net'>bugs.php.net</a>.\n";
  54. $reject_text .= "Support and ways to find answers to your questions can be found at\n";
  55. $reject_text .= "<a href='http://gtk.php.net/resources.php'>gtk.php.net/resources.php</a>.\n\n";
  56. $reject_text .= "Your note has been removed from the on-line manual.\n\n";
  57. }
  58. if ($id) {
  59. $db = sqlite_open($notesfile);
  60. $query = sqlite_query($db, "SELECT * FROM notes WHERE id = '$id'");
  61. $row = sqlite_fetch_array($query, SQLITE_ASSOC);
  62. if (sqlite_exec($db, "DELETE FROM notes WHERE id = '$id'")) {
  63. if (isset($_GET['reject'])) {
  64. if (!substr($row['email'], 0, 3) == 'GTK_') {
  65. /* email user */
  66. if (!isset($_COOKIE[$user])) { /* but only if we're not in test mode */
  67. $mailto = $row['email'];
  68. }
  69. if ($mail) mail($mailto, "note {$row['id']} rejected: {$row['page']}", $reject_text."----- Copy of your note below -----\n\n".stripslashes($row['comment']), "From: $user@php.net");
  70. }
  71. $actioned = 'rejected';
  72. } else {
  73. $actioned = 'deleted';
  74. }
  75. if ($mail) mail($mailto, "note $id $actioned: {$row['page']}", "Content of note:\n\n".stripslashes($row['comment']), "From: $user@php.net");
  76. print "<p><b>Note $id deleted successfully</b></p>";
  77. } else {
  78. print "<p><b>Unable to delete note $id</b></p>";
  79. }
  80. sqlite_close($db);
  81. }
  82. if (isset($_GET['edit']) && is_numeric($_GET['edit'])) {
  83. $db = sqlite_open($notesfile);
  84. $query = sqlite_query($db, "SELECT * FROM notes WHERE id = ".$_GET['edit']);
  85. $row = sqlite_fetch_array($query, SQLITE_ASSOC);
  86. $email = stripslashes($row['email']);
  87. $comment = stripslashes($row['comment']);
  88. if (substr($email, 0, 3) == 'GTK_') {
  89. $email = null;
  90. }
  91. $get = isset($_GET['let']) ? "?let={$_GET['let']}" : null;
  92. if (!$get) {
  93. $get = isset($_GET['y']) ? "?y={$_GET['y']}" : null;
  94. }
  95. if ($get) $get .= $queue ? '&q': null;
  96. else $get .= $queue ? '?q': null;
  97. echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].$get.'">';
  98. echo '<table border="0" cellpadding="5" width="80%" bgcolor="#e0e0e0">';
  99. echo '<tr><td align="right">E-mail:<br /></td>' .
  100. '<td><input type="text" size="40" name="email" value="'.$email.'" />&nbsp;&nbsp;ID: '.$_GET['edit'].'<br /></td></tr>';
  101. echo '<input type="hidden" name="id" value='.$_GET['edit'].' />';
  102. echo '<tr valign="top"><td align="right">Note:<br /></td>' .
  103. '<td><textarea name="note" rows="15" cols="70">'.$comment.'</textarea><br /></td></tr>';
  104. echo '<tr bgcolor="#cccccc"><td colspan="2"></td></tr>';
  105. echo '<tr><td colspan="2" align="right"><input type="submit" name="modify" value="Save changes">';
  106. echo '&nbsp;&nbsp;<input type="submit" name="cancel" value="Cancel" /></td></tr>';
  107. echo "</table>\n</form>\n";
  108. sqlite_close($db);
  109. commonFooter();
  110. exit;
  111. }
  112. if (isset($_POST['modify'])) {
  113. $db = sqlite_open($notesfile);
  114. $query = sqlite_query($db, "SELECT * FROM notes WHERE id = ".$_POST['id']);
  115. $row = sqlite_fetch_array($query, SQLITE_ASSOC);
  116. $add_url = "\n\nhttp://gtk.php.net/manual/{$row['lang']}/{$row['page']}\n";
  117. $note = htmlentities($_POST['note'], ENT_COMPAT, 'UTF-8');
  118. $note = sqlite_escape_string($note);
  119. $note = stripslashes($note); // get rid of double slashes
  120. $query = "UPDATE notes SET";
  121. if (!empty($_POST['email'])) $query .= " email='{$_POST['email']}',";
  122. $query .= " comment='$note' WHERE id='{$row['id']}'";
  123. if (sqlite_exec($db, $query)) {
  124. echo "<p><b>Record {$row['id']} modified successfully</b></p>";
  125. if ($mail) mail($mailto, "note {$row['id']} modified: {$row['page']}", $note.$add_url, "From: $user@php.net");
  126. } else {
  127. echo "<p><b>Record {$row['id']} not modified (query failed)</b></p>";
  128. }
  129. sqlite_close($db);
  130. }
  131. } else {
  132. commonHeader("Browse Manual Notes");
  133. $order = isset($_POST['order']) ? $_POST['order'] : null;
  134. if (isset($order)) {
  135. if (!isset($_COOKIE['order']) || (isset($_COOKIE['order']) && $order != $_COOKIE['order'])) {
  136. setcookie('order', $order, time()+(3600*24), '/');
  137. }
  138. } else {
  139. if (isset($_COOKIE['order'])) {
  140. $order = $_COOKIE['order'];
  141. } else {
  142. $order = 'page';
  143. }
  144. }
  145. echo '<h1>Browse Manual Notes</h1>';
  146. $admin = false;
  147. }
  148. ob_start();
  149. include('browse.php');
  150. commonFooter();
  151. ?>