jmyeom

staff connect, fixed

Dec 4th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 KB | None | 0 0
  1. please note was made by someone else, ive edited it to make it work and update it, the orginal was posted as a guest but under the title of "NightHawk"
  2. it has the same layout that "post by url" had, maybe by the same person, and i also updated that one and fixed that one... odd...
  3. here is the orginal:http://pastebin.com/esBp31vY
  4.  
  5. first thing, go to manage panel, and click "sql query"
  6.  
  7.  
  8. paste this and go :
  9.  
  10. CREATE TABLE `staffconnect` (`id` INT NOT NULL AUTO_INCREMENT, `news` TEXT NOT NULL, `postedby` TEXT NOT NULL, `postedat` INT NOT NULL, `subject` TEXT NOT NULL, `name` TEXT NOT NULL, `comments` TEXT NOT NULL, PRIMARY KEY (`id`));
  11.  
  12.  
  13. ############## Add this in *_manage.class.php.
  14.  
  15. function staffconnect() {
  16. global $tc_db, $dwoo, $tpl_page, $action;
  17. $this->ModeratorsOnly();
  18. $tpl_page .= '<h2>' . _gettext('Staff Connect') . '</h2><br>';
  19. if($_GET['add']) {
  20. $this->AdministratorsOnly();
  21. $tpl_page .= '<form action="?action=staffconnect" method="post">';
  22. $tpl_page .= '<b>Add item</b><br/>
  23. This message will be displayed to all staff members. Format your staffconnect with HTML code.<br/>
  24. <br/>
  25. <label for="subject">Subject:</label><input type="text" name="subject" length="50"/><br/><label for="news_item">News:</label><textarea name="news_item" rows="15" cols="50"></textarea><input type="submit" value="Add News"/></form><br/>';
  26. }
  27. if($_GET['delete']) {
  28. $this->AdministratorsOnly();
  29. if($_GET['delete'] != '') {
  30. if($tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "staffconnect` WHERE `id` = '" . mysql_real_escape_string($_GET['delete']) . "'")) {
  31. $tpl_page .= 'News post deleted<br/><br/>';
  32. management_addlogentry(_gettext('Deleted an staffconnect entry'), 9);
  33. }
  34. }
  35. }
  36. if(isset($_POST['news_item'])) {
  37. $this->AdministratorsOnly();
  38. if($_POST['news_item'] == '' || $_POST['subject'] == '') {
  39. exitWithErrorPage(_gettext('Please fill in all fields.'));
  40. }
  41.  
  42. if($tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "staffconnect` ( `name`, `subject` , `news` , `postedat` , `postedby`) VALUES ( '" . mysql_real_escape_string($_SESSION['manageusername']) . "' , '" . mysql_real_escape_string($_POST['subject']) . "' , '" . mysql_real_escape_string($_POST['news_item']) . "' , '" . time() . "' , '" . mysql_real_escape_string($_SESSION['manageusername']) . "')")) {
  43. management_addlogentry(_gettext('Added an staff connect entry'), 9);
  44. $tpl_page .= (_gettext('News item successfully added.')) . '<br/><br/>';
  45. }
  46. else {
  47. exitWithErrorPage(_gettext('Item was not added ' . mysql_error()));
  48. }
  49. }
  50. if($_GET['commentdelete']) {
  51. $this->AdministratorsOnly();
  52. $_GET['commentdelete'] = urldecode($_GET['commentdelete']);
  53. if(!is_numeric($_GET['id'])) {
  54. exitWithErrorPage(_gettext('Invalid ID'));
  55. }
  56. else {
  57. $results = $tc_db->GetAll ("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staffconnect` WHERE `id` = '". mysql_real_escape_string($_GET['id'])."'");
  58. if (count($results) > 0) {
  59. foreach ($results as $line) {
  60. $line['comments'] = str_replace($_GET['commentdelete'], "", $line['comments']);
  61. }
  62. if($tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staffconnect` SET `comments` = '".mysql_real_escape_string($line['comments'])."' WHERE `id` = '". mysql_real_escape_string($_GET['id'])."'")) {
  63. $tpl_page .= 'Comment deleted';
  64. }
  65. else {
  66. $tpl_page .= 'Failed to delete: ' . mysql_error();
  67. }
  68. }
  69. else {
  70. $tpl_page .= 'Invalid ID';
  71. }
  72. }
  73. }
  74. if($_GET['comment']) {
  75. if(isset($_POST['addcomment'])) {
  76. $_POST['addcomment'] = str_replace("|", "-", $_POST['addcomment']);
  77. $_POST['addcomment'] = str_replace(":", ";", $_POST['addcomment']);
  78. if($tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staffconnect` SET `comments` = CONCAT( `comments`, '". mysql_real_escape_string($_POST['addcomment']) . '|' . $_POST['commentid'] . '|' . $_SESSION['manageusername'] . '|' . time() . ':' . "') WHERE `id` = '". $_POST['commentid']."'")) {
  79. $tpl_page .= 'Comment added!<br/><br/>';
  80. management_addlogentry(_gettext('Added an staffconnect comment'), 9);
  81. }
  82. else {
  83. die(mysql_error());
  84. }
  85. }
  86. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staffconnect` WHERE `id` = '". mysql_real_escape_string($_GET['comment'])."' ORDER BY `id` DESC");
  87. if (count($results) > 0) {
  88. foreach ($results as $line) {
  89. $tpl_page .= '<div style="border: 1px solid #888"><div style="padding: 5px;background:#E0E0E0;"><b>'.$line['subject'].'</b> | '.date('F j, Y, g:i a', $line['postedat']).'';
  90. $tpl_page .= ' by '.$line['name'].' ';
  91. if($line['name'] == $_SESSION['manageusername']){
  92. $tpl_page .= '[<a href="manage_page.php?action=staffconnect&delete='.$line['id'].'">x</a>]</div>';
  93. }
  94. $tpl_page .= '<div style="padding: 5px;">'.$line['news'].'</div></div><br/>';
  95. if($line['comments'] == '') {
  96. $tpl_page .= 'No comments<br/>';
  97. }
  98. else {
  99. $comment = explode(":", $line['comments']);
  100. foreach($comment as $comment2) {
  101. if($comment2 != '') {
  102. $comment3 = explode("|", $comment2);
  103. $tpl_page .= '<div style="border: 1px solid #999;"><div style="background-color: #F0F0F0; padding: 4px;"><strong>'.$comment3[2] . '</strong> ('.date('F j, Y, g:i a', $comment3[3]).') [<a href="manage_page.php?action=staffconnect&commentdelete='.urlencode($comment2).'&id='.$line['id'].'">x</a>]</div><div style="padding: 4px;">' . htmlspecialchars($comment3[0]).'</div></div><br/>';
  104. }
  105. }
  106. }
  107. $tpl_page .= '<br/><form action="?action=staffconnect&comment='.$line['id'].'" method="post"><input type="hidden" value="'.$_GET['comment'].'" name="commentid"/><textarea name="addcomment" rows="4" cols="50"></textarea><input type="submit" name="submitcomment" value="Add"/></form><br/>';
  108. }
  109. }
  110. else {
  111. $tpl_page .= 'Invalid comment ID';
  112. }
  113. }
  114. if(!($_GET['add']) && !($_GET['comment']) && !($_GET['commentdelete'])) {
  115. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staffconnect` ORDER BY `id` DESC");
  116. if ($results !== false && count($results) > 0) {
  117. foreach ($results as $line) {
  118. $tpl_page .= '<div style="border: 1px solid #888"><div style="padding: 5px;background:#E0E0E0;"><b>'.$line['subject'].'</b> | '.date('F j, Y, g:i a', $line['postedat']).'';
  119. $tpl_page .= ' by '.$line['name'].' ';
  120. if($line['name'] == $_SESSION['manageusername']){
  121. $tpl_page .= '[<a href="manage_page.php?action=staffconnect&delete='.$line['id'].'">x</a>]</div>';
  122. }
  123. $tpl_page .= '<div style="padding: 5px;">'.$line['news'].'</div></div>';
  124. $comment = explode(":", $line['comments']);
  125. $i = 0;
  126. foreach($comment as $comment2) {
  127. if($comment2 != '') {
  128. $i++;
  129. }
  130. }
  131. if($i == 0) {
  132. $tpl_page .= '<div align="right" style="padding: 3px"><a href="manage_page.php?action=staffconnect&comment='.$line['id'].'" style="color: grey">No comments</a></div><br/><br/>';
  133. }
  134. else {
  135. $tpl_page .= '<div align="right" style="padding: 3px"><a href="manage_page.php?action=staffconnect&comment='.$line['id'].'">Comments ('.$i.')</a></div><br/><br/>';
  136. }
  137. }
  138. } else {
  139. $tpl_page .= 'No news feed.';
  140. }
  141. if($this->CurrentUserIsAdministrator()) {
  142. $tpl_page .= '<p style="text-align: right">[<a href="manage_page.php?action=staffconnect&add=1">Add item</a>]</p>';
  143. }
  144. }
  145. }
  146.  
  147. ############## Add this in *_manage_menu.php.
  148.  
  149. <li><a href="manage_page.php?action=staffconnect">'._gettext('Staff Connect').'</a></li>
  150.  
  151.  
  152.  
Advertisement
Add Comment
Please, Sign In to add comment