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

/module/forum/admin/index.php

https://bitbucket.org/rafalwolak/cms2u
PHP | 199 lines | 154 code | 30 blank | 15 comment | 17 complexity | 6b1b8b4507c07904e61de3f580d98428 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /**
  3. * Module Forum
  4. *
  5. * @link http://www.cms.woli.pl/ CMS WOLI
  6. * @author Rafal Wolak <rafal.wolak@woli.pl>
  7. * @license http://creativecommons.org/licenses/by/2.5/pl/
  8. Creative Commons Uznanie autorstwa 2.5
  9. * @package module
  10. */
  11. /**
  12. */
  13. define('IN_SITE', true);
  14. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  15. // Za?adowanie pliku konfiguracyjnego
  16. if (!defined('IS_INSTALLED'))
  17. {
  18. require_once '../../inc/config.' . $phpEx;
  19. }
  20. require_once ROOT_DIR . 'inc/common.' . $phpEx;
  21. require_once ROOT_DIR . 'inc/init.' . $phpEx;
  22. /**
  23. * Komentarze
  24. */
  25. if (!isset($_GET['o']))
  26. {
  27. if (request_var('go', 'false') == 'true')
  28. {
  29. $postid = $_POST['postid'];
  30. $rate = $_POST['rate'];
  31. for ($i = 0, $end = count($postid); $i < $end; $i++)
  32. {
  33. $sql = 'UPDATE ' . $prefix . '_forum_post
  34. SET post_active="' . request_var('active-' . $postid[$i], 0) . '",
  35. post_rate="' . $rate[$i]. '"
  36. WHERE post_id="' . (int) $postid[$i] . '"';
  37. $db->sql_query($sql);
  38. }
  39. header('Location: ' . request_url());
  40. exit;
  41. }
  42. else
  43. {
  44. $pag['onsite'] = 20;
  45. $userid = request_var('userid', 0);
  46. $sql = 'SELECT post_id
  47. FROM ' . $prefix . '_forum_post';
  48. $result = $db->sql_query($sql);
  49. $pag['num'] = $db->sql_numrows($result);
  50. $db->sql_freeresult($result);
  51. $smarty->assign('num', $pag['num']);
  52. $sql = 'SELECT *
  53. FROM ' . $prefix . '_forum_post
  54. ORDER BY post_adddate DESC
  55. LIMIT ' . (int) $pag['start'] . ', ' . (int) $pag['onsite'];
  56. $result = $db->sql_query($sql);
  57. $lp = $pag['start'] + 1;
  58. while ($row = $db->sql_fetchrow($result))
  59. {
  60. $value[] = array(
  61. 'id' => $row['post_id'],
  62. 'url' => $mod_forum->_url($row['post_id']),
  63. 'title' => $row['post_title'],
  64. 'text' => htmlspecialchars_decode($row['post_text'], ENT_QUOTES),
  65. 'userid' => $row['post_userid'],
  66. 'username' => ($row['post_userid'] > 0) ? $user->username($row['post_userid']) : $row['post_username'],
  67. 'email' => $row['post_useremail'],
  68. 'ip' => $row['post_userip'],
  69. 'host' => $row['post_userhost'],
  70. 'adddate' => $date->view($row['post_adddate'], '|d.m.Y \o H:i|', false),
  71. 'active' => $row['post_active'],
  72. 'rate' => $row['post_rate'],
  73. 'isbanuserid' => $core->is_ban($row['post_userid'], 'userid', 'text'),
  74. 'isbanip' => $core->is_ban($row['post_userip'], 'ip', 'text'),
  75. 'isbanemail' => $core->is_ban($row['post_useremail'], 'email', 'text'),
  76. 'baniduserid' => $core->is_ban($row['post_userid'], 'userid', 'id'),
  77. 'banidip' => $core->is_ban($row['post_userip'], 'ip', 'id'),
  78. 'banidemail' => $core->is_ban($row['post_useremail'], 'email', 'id'),
  79. 'lp' => $lp
  80. );
  81. $lp++;
  82. }
  83. $db->sql_freeresult($result);
  84. $smarty->assign('value', $value);
  85. if ($pag['num'] > 0)
  86. $smarty->assign('pagination', ($pag['num'] > 0) ? pag(append_sid(SITE_URL . 'admin/?q=' . request_var('q', '') . '&p=#')) : '');
  87. }
  88. }
  89. else
  90. {
  91. switch (request_var('w', 'error'))
  92. {
  93. case 'edit':
  94. if (request_var('go', 'false') == 'true')
  95. {
  96. $sql = 'UPDATE ' . $prefix . '_forum_post
  97. SET post_title="' . request_var('title', '') . '",
  98. post_text="' . request_var('text', '') . '",
  99. post_moddate="' . time() . '",
  100. post_active="' . request_var('active', 0) . '"
  101. WHERE ad_id="' . (int) request_var('id', 0) . '"';
  102. if ($db->sql_query($sql))
  103. {
  104. $msg = array(
  105. 'text' => '<strong>' . lang('GLOBAL: CONGRATULATIONS') . '</strong> ' . lang('GLOBAL: OPTIONS HAVE BEEN SAVED'),
  106. 'url' => SITE_URL . '?q=' . request_var('q', '') . '&o=ad',
  107. 'time' => 2
  108. );
  109. }
  110. else
  111. {
  112. $msg = array(
  113. 'text' => '<strong>' . lang('GLOBAL: ATTENTION') . '</strong> ' . lang('GLOBAL: FAILED TO SAVE OPTIONS'),
  114. 'url' => request_url(),
  115. 'time' => 5
  116. );
  117. }
  118. $smarty->assign('msg', $msg);
  119. }
  120. else
  121. {
  122. $sql = 'SELECT post_id, post_title, post_text, post_active
  123. FROM ' . $prefix . '_forum_post
  124. WHERE post_id="' . (int) request_var('id', 0) . '"';
  125. $result = $db->sql_query($sql);
  126. while ($row = $db->sql_fetchrow($result))
  127. {
  128. $edit = array(
  129. 'id' => $row['post_id'],
  130. 'title' => $row['post_title'],
  131. 'text' => $row['post_text'],
  132. 'active' => $row['post_active']
  133. );
  134. }
  135. $db->sql_freeresult($result);
  136. $smarty->assign('edit', $edit);
  137. }
  138. break;
  139. case 'del':
  140. if (request_var('go', 'false') == 'true')
  141. {
  142. $sql = 'DELETE
  143. FROM ' . $prefix . '_forum_post
  144. WHERE post_id="' . (int) request_var('id', 0) . '"';
  145. if ($db->sql_query($sql))
  146. {
  147. $msg = array(
  148. 'text' => '<strong>Gratulacje!</strong> Dane zosta?y usuni?te.' . $msetext,
  149. 'url' => SITE_URL . '?q=' . request_var('q', ''),
  150. 'time' => 5
  151. );
  152. }
  153. else
  154. {
  155. $msg = array(
  156. 'text' => '<strong>Uwaga!</strong> Dane nie zosta3y usuni?te.',
  157. 'url' => request_url(),
  158. 'time' => 5
  159. );
  160. }
  161. $smarty->assign('msg', $msg);
  162. }
  163. break;
  164. }
  165. }
  166. $smarty->caching = 0;
  167. $cache_lifetime = 0;
  168. $smarty->display(template('admin/index', 'mod', 'forum'), $my_cache_id);
  169. ?>