PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/modules/news/news.Manage.php

https://github.com/KenBoyer/CompactCMS
PHP | 324 lines | 267 code | 16 blank | 41 comment | 19 complexity | 20fc195fedfffd05f8229fe25bd61a04 MD5 | raw file
  1. <?php
  2. /* ************************************************************
  3. Copyright (C) 2008 - 2010 by Xander Groesbeek (CompactCMS.nl)
  4. Revision: CompactCMS - v 1.4.2
  5. This file is part of CompactCMS.
  6. CompactCMS is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. CompactCMS is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. A reference to the original author of CompactCMS and its copyright
  15. should be clearly visible AT ALL TIMES for the user of the back-
  16. end. You are NOT allowed to remove any references to the original
  17. author, communicating the product to be your own, without written
  18. permission of the original copyright owner.
  19. You should have received a copy of the GNU General Public License
  20. along with CompactCMS. If not, see <http://www.gnu.org/licenses/>.
  21. > Contact me for any inquiries.
  22. > E: Xander@CompactCMS.nl
  23. > W: http://community.CompactCMS.nl/forum
  24. ************************************************************ */
  25. /* make sure no-one can run anything here if they didn't arrive through 'proper channels' */
  26. if(!defined("COMPACTCMS_CODE")) { define("COMPACTCMS_CODE", 1); } /*MARKER*/
  27. /*
  28. We're only processing form requests / actions here, no need to load the page content in sitemap.php, etc.
  29. */
  30. if (!defined('CCMS_PERFORM_MINIMAL_INIT')) { define('CCMS_PERFORM_MINIMAL_INIT', true); }
  31. // Define default location
  32. if (!defined('BASE_PATH'))
  33. {
  34. $base = str_replace('\\','/',dirname(dirname(dirname(dirname(__FILE__)))));
  35. define('BASE_PATH', $base);
  36. }
  37. // Include general configuration
  38. /*MARKER*/require_once(BASE_PATH . '/admin/includes/security.inc.php'); // when session expires or is overridden, the login page won't show if we don't include this one, but a cryptic error will be printed.
  39. if (!checkAuth() || empty($_SESSION['rc1']) || empty($_SESSION['rc2']))
  40. {
  41. die("No external access to file");
  42. }
  43. $do = getGETparam4IdOrNumber('do');
  44. $status = getGETparam4IdOrNumber('status');
  45. $status_message = getGETparam4DisplayHTML('msg');
  46. $page_id = getGETparam4IdOrNumber('page_id');
  47. $pagerow = $db->SelectSingleRow($cfg['db_prefix'].'pages', array('page_id' => MySQL::SQLValue($page_id, MySQL::SQLVALUE_NUMBER)));
  48. if (!$pagerow) $db->Kill();
  49. $pageName = $pagerow->urlpage;
  50. if (empty($pageName) || empty($page_id))
  51. {
  52. die($ccms['lang']['system']['error_forged'] . ' (' . __FILE__ . ', ' . __LINE__ . ')' );
  53. }
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  56. <html>
  57. <head>
  58. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  59. <title>News module</title>
  60. <link rel="stylesheet" type="text/css" href="../../../admin/img/styles/base.css,liquid.css,layout.css,sprite.css,last_minute_fixes.css" />
  61. <!--[if IE]>
  62. <link rel="stylesheet" type="text/css" href="../../../admin/img/styles/ie.css" />
  63. <![endif]-->
  64. </head>
  65. <body>
  66. <div class="module" id="news-manager">
  67. <div class="center-text <?php echo $status; ?>">
  68. <?php
  69. if(!empty($status_message))
  70. {
  71. echo '<p class="ss_has_sprite"><span class="ss_sprite_16 '.($status == 'notice' ? 'ss_accept' : 'ss_error').'">&#160;</span>'.$status_message.'</p>';
  72. }
  73. ?>
  74. </div>
  75. <div class="span-18 colborder">
  76. <h2><?php echo $ccms['lang']['news']['manage']; ?></h2>
  77. <?php
  78. // Load recordset
  79. $i=0;
  80. $newsitems = $db->QueryObjects("SELECT * FROM `".$cfg['db_prefix']."modnews` n LEFT JOIN `".$cfg['db_prefix']."users` u ON n.userID=u.userID WHERE page_id=".MySQL::SQLValue($page_id, MySQL::SQLVALUE_NUMBER));
  81. if ($newsitems === false)
  82. $db->Kill();
  83. // Start switch for news, select all the right details
  84. if(count($newsitems) > 0)
  85. {
  86. $preview_checkcode = GenerateNewPreviewCode($page_id);
  87. ?>
  88. <form action="news.Process.php?action=del-news" method="post" accept-charset="utf-8">
  89. <div class="table_inside">
  90. <table cellspacing="0" cellpadding="0">
  91. <tr>
  92. <th class="span-1">&#160;</th>
  93. <th class="span-1">&#160;</th>
  94. <th class="span-14"><?php echo $ccms['lang']['news']['title']; ?></th>
  95. <th class="span-5"><?php echo $ccms['lang']['news']['author']; ?></th>
  96. <th class="span-4 last"><?php echo $ccms['lang']['news']['date']; ?></th>
  97. </tr>
  98. <?php
  99. foreach($newsitems as $rsNews)
  100. {
  101. // Alternate rows
  102. if($i%2 != 1)
  103. {
  104. echo '<tr class="altrgb"><td>';
  105. }
  106. else
  107. {
  108. echo '<tr><td>';
  109. }
  110. if($perm->is_level_okay('manageModNews', $_SESSION['ccms_userLevel']))
  111. {
  112. ?>
  113. <label>
  114. <input type="checkbox" name="newsID[]" value="<?php echo rm0lead($rsNews->newsID); ?>">
  115. </label>
  116. <?php
  117. }
  118. ?>
  119. </td>
  120. <td>
  121. <?php
  122. echo "<span class='ss_sprite_16 ".($rsNews->newsPublished != 0 ? "ss_bullet_green'>" : "ss_bullet_red'>") . "&#160;</span>";
  123. // Filter spaces, non-file characters and account for UTF-8
  124. $newsTitle = cvt_text2legibleURL($rsNews->newsTitle);
  125. echo '<a href="' . $cfg['rootdir'].$pageName.'/'.rm0lead($rsNews->newsID).'-'.$newsTitle . '.html?preview=' . $preview_checkcode . '" ' .
  126. 'title="' . $ccms['lang']['backend']['previewpage'] . '"><span class="ss_sprite_16 ss_eye">&#160;</span></a>';
  127. ?>
  128. </td>
  129. <td>
  130. <?php
  131. if($perm->is_level_okay('manageModNews', $_SESSION['ccms_userLevel']))
  132. {
  133. ?>
  134. <a href="news.Write.php?page_id=<?php echo $page_id; ?>&amp;newsID=<?php echo rm0lead($rsNews->newsID); ?>"><span class="ss_sprite_16 ss_pencil">&#160;</span><?php echo substr($rsNews->newsTitle,0,20); echo (strlen($rsNews->newsTitle)>20 ? '...' : null); ?></a>
  135. <?php
  136. }
  137. else
  138. {
  139. ?>
  140. <?php echo $rsNews->newsTitle; ?>
  141. <?php
  142. }
  143. ?>
  144. </td>
  145. <td class="nowrap"><a href="mailto:<?php echo $rsNews->userEmail; ?>"><span class="ss_sprite_16 ss_email">&#160;</span><?php echo substr(ucfirst($rsNews->userFirst),0,1).'. '.ucfirst($rsNews->userLast); ?></a></td>
  146. <td class="nowrap"><span class="ss_sprite_16 ss_calendar">&#160;</span><?php echo date('Y-m-d G:i', strtotime($rsNews->newsModified)); ?></td>
  147. </tr>
  148. <?php
  149. $i++;
  150. }
  151. ?>
  152. </table>
  153. </div>
  154. <?php
  155. if($perm->is_level_okay('manageModNews', $_SESSION['ccms_userLevel']))
  156. {
  157. ?>
  158. <input type="hidden" name="page_id" value="<?php echo $page_id; ?>" id="page_id">
  159. <div class="right">
  160. <button type="submit" onclick="return confirmation_delete();" name="deleteNews"><span class="ss_sprite_16 ss_newspaper_delete">&#160;</span><?php echo $ccms['lang']['backend']['delete']; ?></button>
  161. </div>
  162. <?php
  163. }
  164. ?>
  165. </form>
  166. <?php
  167. }
  168. else
  169. {
  170. echo $ccms['lang']['system']['noresults']; // [i_a] moved OUTSIDE the <form><table> : correct HTML
  171. }
  172. ?>
  173. </div>
  174. <div class="span-6 last">
  175. <h2><?php echo $ccms['lang']['news']['addnews']; ?></h2>
  176. <?php
  177. if($perm->is_level_okay('manageModNews', $_SESSION['ccms_userLevel']))
  178. {
  179. ?>
  180. <p class="ss_has_sprite"><a href="news.Write.php?page_id=<?php echo $page_id; ?>"><span class="ss_sprite_16 ss_newspaper_add">&#160;</span><?php echo $ccms['lang']['news']['addnewslink']; ?></a></p>
  181. <h2><?php echo $ccms['lang']['news']['settings']; ?></h2>
  182. <?php
  183. $rsCfg = $db->SelectSingleRow($cfg['db_prefix'].'cfgnews', array('page_id' => MySQL::SQLValue($page_id,MySQL::SQLVALUE_NUMBER)));
  184. if ($db->ErrorNumber() != 0) $db->Kill();
  185. if ($rsCfg !== false)
  186. {
  187. $showmsg = max(1,intval($rsCfg->showMessage)); // always show at least 1 news item on a news page!
  188. $locale = $rsCfg->showLocale;
  189. $showauth = intval($rsCfg->showAuthor);
  190. $showdate = intval($rsCfg->showDate);
  191. $showteaser = intval($rsCfg->showTeaser);
  192. //$newscfgid = $rsCfg->cfgID;
  193. }
  194. else // set defaults
  195. {
  196. // [i_a] when no cfg record, fill in the defaults as were also set in the database
  197. $showmsg = 3;
  198. $locale = $cfg['locale'];
  199. $showauth = 1;
  200. $showdate = 1;
  201. $showteaser = 0;
  202. //$newscfgid = null;
  203. }
  204. ?>
  205. <form action="news.Process.php?action=cfg-news" method="post" accept-charset="utf-8">
  206. <label for="messages"><?php echo $ccms['lang']['news']['numbermess']; ?></label>
  207. <input type="text" class="text span-25 last" name="messages" value="<?php echo $showmsg; ?>" id="messages" />
  208. <label for="locale"><?php echo $ccms['lang']['forms']['setlocale']; ?></label>
  209. <select name="locale" class="title span-25 last" id="locale" size="1">
  210. <?php
  211. // Get current languages
  212. $s = (isset($_SESSION['variables']['language']) ? $_SESSION['variables']['language'] : 'en');
  213. $lcoll = GetAvailableLanguages();
  214. foreach($lcoll as $lcode => $ldesc)
  215. {
  216. $c = ($lcode == $s ? 'selected="selected"' : null);
  217. echo '<option value="'.$ldesc['locale'].'" '.$c.'>'.$ldesc['name'].'</option>';
  218. }
  219. ?>
  220. </select>
  221. <label><?php echo $ccms['lang']['news']['showauthor']; ?></label>
  222. <div id="show-author" class="span-25">
  223. <label><?php echo $ccms['lang']['backend']['yes']; ?>
  224. <input type="radio" name="author" <?php echo ($showauth!=0?'checked="checked"':null); ?> value="1" id="author1" />
  225. </label>
  226. <label><?php echo $ccms['lang']['backend']['no']; ?>
  227. <input type="radio" name="author" <?php echo ($showauth==0?'checked="checked"':null); ?> value="0" id="author0" />
  228. </label>
  229. </div>
  230. <label><?php echo $ccms['lang']['news']['showdate']; ?></label>
  231. <div id="show-date" class="span-25">
  232. <label><?php echo $ccms['lang']['backend']['yes']; ?>
  233. <input type="radio" name="show_modified" <?php echo ($showdate!=0?'checked="checked"':null); ?> value="1" id="show_modified1" />
  234. </label>
  235. <label><?php echo $ccms['lang']['backend']['no']; ?>
  236. <input type="radio" name="show_modified" <?php echo ($showdate==0?'checked="checked"':null); ?> value="0" id="show_modified0" />
  237. </label>
  238. </div>
  239. <label><?php echo $ccms['lang']['news']['showteaser']; ?></label>
  240. <div id="show-teaser" class="span-25">
  241. <label><?php echo $ccms['lang']['backend']['yes']; ?>
  242. <input type="radio" name="show_teaser" <?php echo ($showteaser!=0?'checked="checked"':null); ?> value="1" id="show_teaser1" />
  243. </label>
  244. <label><?php echo $ccms['lang']['backend']['no']; ?>
  245. <input type="radio" name="show_teaser" <?php echo ($showteaser==0?'checked="checked"':null); ?> value="0" id="show_teaser0" />
  246. </label>
  247. </div>
  248. <?php
  249. if ($rsCfg !== false)
  250. {
  251. echo '<input type="hidden" name="cfgID" value="' . rm0lead($rsCfg->cfgID) . '" id="cfgID" />';
  252. }
  253. ?>
  254. <input type="hidden" name="page_id" value="<?php echo $page_id; ?>" id="page_id" />
  255. <div class="right">
  256. <button type="submit"><span class="ss_sprite_16 ss_disk">&#160;</span><?php echo $ccms['lang']['forms']['savebutton']; ?></button>
  257. <a class="button" href="../../../admin/index.php" onClick="return confirmation();" title="<?php echo $ccms['lang']['editor']['cancelbtn']; ?>"><span class="ss_sprite_16 ss_cross">&#160;</span><?php echo $ccms['lang']['editor']['cancelbtn']; ?></a>
  258. </div>
  259. </form>
  260. <?php
  261. }
  262. else
  263. {
  264. echo $ccms['lang']['auth']['featnotallowed'];
  265. }
  266. ?>
  267. </div>
  268. </div>
  269. <script type="text/javascript" src="../../includes/js/the_goto_guy.js" charset="utf-8"></script>
  270. <script type="text/javascript" charset="utf-8">
  271. function confirmation_delete()
  272. {
  273. var answer = <?php echo (strpos($cfg['verify_alert'], 'D') !== false ? 'confirm("'.$ccms['lang']['backend']['confirmdelete'].'")' : 'true'); ?>;
  274. return !!answer;
  275. }
  276. function confirmation()
  277. {
  278. var answer = <?php echo (strpos($cfg['verify_alert'], 'X') !== false ? 'confirm("'.$ccms['lang']['editor']['confirmclose'].'")' : 'true'); ?>;
  279. if(answer)
  280. {
  281. return !close_mochaUI_window_or_goto_url("<?php echo makeAbsoluteURI($cfg['rootdir'] . 'admin/index.php'); ?>", '<?php echo $pageName; ?>_ccms');
  282. }
  283. return false;
  284. }
  285. </script>
  286. </body>
  287. </html>