PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/notepad/index.php

https://github.com/michaelmwu/saratogahigh.com
PHP | 219 lines | 187 code | 31 blank | 1 comment | 25 complexity | 9edbcb8f108bbbfbdf7aa78f231041ff MD5 | raw file
  1. <?
  2. include '../db.php';
  3. include 'notepad.php';
  4. if($_GET['charset'] == '')
  5. $charset = 'utf-8';
  6. else
  7. $charset = htmlentities($_GET['charset']);
  8. if($loggedin)
  9. {
  10. $toomanynotes = TooManyNotes($userid);
  11. if(is_numeric($_GET['delete']))
  12. mysql_query('DELETE FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' AND NOTEPAGE_ID=' . $_GET['delete']) or die("Delete failed.");
  13. if($_POST['go'] == 'Save')
  14. {
  15. if(strlen(stripslashes($_POST['entrytext'])) > 65530)
  16. $errorm = '<p style="font-size: medium">Your note was too long. Notes are limited to 65530 characters.</p>.';
  17. else if($toomanynotes)
  18. $errorm = '<p style="font-size: medium">Sorry, you\'re limited to 60 notes.</p>';
  19. else
  20. mysql_query('INSERT INTO NOTEPAGE_LIST (NOTEPAGE_OWNER, NOTEPAGE_CREATED, NOTEPAGE_MODIFIED, NOTEPAGE_VALUE, NOTEPAGE_DIGEST) VALUES (' . $userid . ', "' . date(TIME_FORMAT_SQL, CURRENT_TIME) . '", NOTEPAGE_CREATED, \'' . $_POST['entrytext'] . '\', \'' . makedigest($_POST['entrytext']) . '\')') or die("Insert failed.");
  21. }
  22. else if($_POST['go'] == 'Edit')
  23. {
  24. mysql_query('UPDATE NOTEPAGE_LIST SET NOTEPAGE_MODIFIED="' . date(TIME_FORMAT_SQL, CURRENT_TIME) . '", NOTEPAGE_VALUE=\'' . $_POST['entrytext'] . '\', NOTEPAGE_DIGEST=\'' . makedigest($_POST['entrytext']) . '\' WHERE NOTEPAGE_OWNER=' . $userid . ' AND NOTEPAGE_ID=' . $_GET['id']) or die("Insert failed.");
  25. }
  26. }
  27. else
  28. forceLogin();
  29. $xml->handle_request();
  30. ?>
  31. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  32. <html>
  33. <head>
  34. <title>Notepad</title>
  35. <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
  36. <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  37. <link rel="stylesheet" type="text/css" href="../shs.css">
  38. <meta http-equiv="Content-Type" content="text/html; charset=<?= $charset ?>">
  39. <style type="text/css">
  40. a.linkh { font-weight: bold }
  41. .headed { background-color: #f0f0f0; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #666; padding: 3px; }
  42. </style>
  43. </head>
  44. <body>
  45. <? include "../inc-header.php"; ?>
  46. <h1>Notepad</h1>
  47. <?= htmlentities($errorm) ?>
  48. <p>Notepad is the easy way to save information you've found on the web. You can use it to store links and text you've found at school and access them at home, or vice versa.</p>
  49. <? if(strlen($_GET['query']) > 0) { ?>
  50. <form method="get" action="./">
  51. <p>Search my pages: <input type="text" name="query" value="<?= htmlentities(stripslashes($_GET['query'])) ?>"> <input type="submit" name="go" value="Search"><!-- <a href="search.php">Search Tips</a>--></p>
  52. </form>
  53. <h2>Pages matching '<?= htmlentities(stripslashes($_GET['query'])) ?>'</h2>
  54. <p><a href="./">Cancel search</a></p>
  55. <?
  56. print 'SELECT NOTEPAGE_ID, NOTEPAGE_DIGEST, UNIX_TIMESTAMP(NOTEPAGE_CREATED) as TS FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' AND MATCH(NOTEPAGE_VALUE) AGAINST (\'' . $_GET['query'] . '\')';
  57. $entries = mysql_query('SELECT NOTEPAGE_ID, NOTEPAGE_DIGEST, UNIX_TIMESTAMP(NOTEPAGE_CREATED) as TS FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' AND MATCH(NOTEPAGE_VALUE) AGAINST (\'' . $_GET['query'] . '\')') or die('Query failed.');
  58. print '<p>' . mysql_num_rows($entries) . ' page(s), sorted by relevance.</p>';
  59. while($l = mysql_fetch_array($entries, MYSQL_ASSOC))
  60. print '<p><a href="page.php?id=' . $l['NOTEPAGE_ID'] . '">' . date(TIME_FORMAT, $l['TS']) . '</a>: ' . htmlentities($l['NOTEPAGE_DIGEST']) . ' <a href="./?go=Search?&amp;query=' . $_GET['query'] . '&amp;delete=' . $l['NOTEPAGE_ID'] . '">Delete</a></p>';
  61. ?>
  62. <? } else { ?>
  63. <table>
  64. <tr>
  65. <td id="noteview_box" style="vertical-align: top; width: 500px;">
  66. <? if($_GET['mode'] == 'view')
  67. view_box($userid,$_GET['id']);
  68. else if($_GET['mode'] == 'edit')
  69. edit_box($userid,$_GET['id']);
  70. else
  71. new_box($userid); ?>
  72. </td>
  73. <td style="vertical-align: top; padding-left: 20px;">
  74. <h2>All Pages</h2>
  75. <div class="headed">
  76. <form method="get" action="./">
  77. <p>Search my pages: <input type="text" name="query" value=""> <input type="submit" name="go" value="Search"><!-- <a href="search.php">Search Tips</a>--></p>
  78. </form>
  79. <div id="allpages_box">
  80. <? allpages_box($userid); ?>
  81. </div>
  82. <a href="/notepad" onClick="return new_page();">New Page</a>
  83. </div>
  84. </td>
  85. </tr>
  86. </table>
  87. <? include '../inc-footer.php'; ?>
  88. <script type="text/javascript">
  89. <!--
  90. function view_page(id)
  91. {
  92. <? print $xml->make_request("'index.php'",'POST','noteview_box','view_box', "a:2:{i:0;i:$userid;i:1;i:' + id + ';}"); ?>
  93. return false;
  94. }
  95. function edit_page(id)
  96. {
  97. <? print $xml->make_request("'index.php'",'POST','noteview_box','edit_box',"a:2:{i:0;i:$userid;i:1;i:' + id + ';}"); ?>
  98. return false;
  99. }
  100. function save_page(id,text)
  101. {
  102. xmlhttp.open("POST", 'index.php?id=',true);
  103. xmlhttp.onreadystatechange=function()
  104. {
  105. if (xmlhttp.readyState==4)
  106. {
  107. document.getElementById("noteview_box").innerHTML = xmlhttp.responseText;
  108. }
  109. }
  110. xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.send('go=Edit&entrytext=' + text + '&XMLRequest=1&XMLFunction=view_box&XMLArgs=a:2:{i:0;i:32;i:1;i:' + id + ';}'); return false;
  111. }
  112. function delete_page(id, redirect)
  113. {
  114. xmlhttp.open("POST", 'index.php?delete=' + id,true);
  115. xmlhttp.onreadystatechange=function()
  116. {
  117. if (xmlhttp.readyState==4)
  118. {
  119. document.getElementById("allpages_box").innerHTML = xmlhttp.responseText;
  120. document.getElementById("noteview_box").innerHTML = ' <h2>New Page</h2>'
  121. + '<form method="post" action="./">'
  122. + '<p><textarea name="entrytext" rows="12" cols="60" wrap="virtual"></textarea></p>'
  123. + '<p><input type="submit" name="go" value="Save"></p>'
  124. + '</form>';
  125. }
  126. }
  127. xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.send('XMLRequest=1&XMLFunction=allpages_box&XMLArgs=a:1:{i:0;i:<?=$userid?>;}');
  128. return false;
  129. }
  130. function new_page()
  131. {
  132. <? print $xml->make_request("'index.php'",'POST','noteview_box','new_box',"a:1:{i:0;i:$userid;}"); ?>
  133. return false;
  134. }
  135. // -->
  136. </script>
  137. </body>
  138. </html>
  139. <?
  140. }
  141. function new_box($userid)
  142. {
  143. $toomanynotes = TooManyNotes($userid);
  144. print '<h2>New Page</h2>';
  145. if(!$toomanynotes) { ?>
  146. <form method="post" action="./">
  147. <p><textarea name="entrytext" rows="12" cols="60" wrap="virtual"></textarea></p>
  148. <p><input type="submit" name="go" value="Save"></p>
  149. </form>
  150. <? } else {
  151. print "<p>You can't save any more notes at this time, because you've exceeded your limit.</p>";
  152. }
  153. }
  154. function view_box($userid,$id)
  155. {
  156. print '<h2>View Page</h2>';
  157. $entries = mysql_query('SELECT NOTEPAGE_LIST.*, NOTEPAGE_CREATED as CR, NOTEPAGE_MODIFIED as MO FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' AND NOTEPAGE_ID=' . $id) or die('Query failed.');
  158. if($l = mysql_fetch_array($entries, MYSQL_ASSOC))
  159. {
  160. print '<table>';
  161. print '<tr><td>Created</td><td>' . date(TIME_FORMAT, strtotime($l['CR'])) . '</td></tr>';
  162. print '<tr><td>Modified</td><td>' . date(TIME_FORMAT, strtotime($l['MO'])) . '</td></tr>';
  163. print '</table>';
  164. print '<p><span class="toolbar"><a href="./?mode=edit&amp;id=' . $id . '" onClick="return edit_page(' . $id . ');">Modify</a></span>&nbsp;<span class="toolbar"><a href="/mail/compose.php?fwnote=' . $id . '">Forward</a></span>&nbsp;<span class="toolbar"><a href="./?delete=' . $id . '" onClick="return delete_page(' . $l['NOTEPAGE_ID'] . ',true);">Delete</a></span></p>';
  165. print '<p style="font-family: monospace; background-color: #eeeeee; padding: 5px;">' . printable($l['NOTEPAGE_VALUE']) . '</p>';
  166. }
  167. }
  168. function edit_box($userid,$id)
  169. {
  170. print '<h2>Modify Page</h2>';
  171. $entries = mysql_query('SELECT NOTEPAGE_LIST.*, NOTEPAGE_CREATED as CR, NOTEPAGE_MODIFIED as MO FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' AND NOTEPAGE_ID=' . $id) or die('Query failed.');
  172. if($l = mysql_fetch_array($entries, MYSQL_ASSOC))
  173. {
  174. ?>
  175. <form method="post" action="./?id=<?= $id ?>">
  176. <p><textarea name="entrytext" rows="12" cols="60" wrap="virtual"><?= htmlspecialchars($l['NOTEPAGE_VALUE']) ?></textarea></p>
  177. <p><input type="submit" name="go" value="Edit"></p>
  178. </form>
  179. <? }
  180. }
  181. function allpages_box($userid)
  182. {
  183. $entries = mysql_query('SELECT NOTEPAGE_ID, NOTEPAGE_DIGEST, NOTEPAGE_CREATED as TS FROM NOTEPAGE_LIST WHERE NOTEPAGE_OWNER=' . $userid . ' ORDER BY NOTEPAGE_CREATED DESC') or die('Query failed.');
  184. print '<p>' . mysql_num_rows($entries) . ' page(s).</p>';
  185. while($l = mysql_fetch_array($entries, MYSQL_ASSOC))
  186. print '<p><a href="./?mode=view&amp;id=' . $l['NOTEPAGE_ID'] . '" onClick="return view_page(' . $l['NOTEPAGE_ID'] . ');">' . date(TIME_FORMAT, strtotime($l['TS'])) . '</a>: ' . htmlentities($l['NOTEPAGE_DIGEST']) . ' <a href="./?delete=' . $l['NOTEPAGE_ID'] . '" onClick="return delete_page(' . $l['NOTEPAGE_ID'] . ',false);">Delete</a></p>';
  187. }
  188. ?>