PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/news.php

https://github.com/ECP-Black/ECP
PHP | 334 lines | 333 code | 1 blank | 0 comment | 78 complexity | dd2338cea6405d0bf5451eb3cdd9943a MD5 | raw file
  1. <?php
  2. function admin_news() {
  3. global $db;
  4. $tpl = new smarty;
  5. if(@$_GET['func'] == 'pin') {
  6. ob_end_clean();
  7. if($db->result(DB_PRE.'ecp_news', 'sticky', 'newsID = '.(int)$_GET['id']) == 0) {
  8. $db->query('UPDATE '.DB_PRE.'ecp_news SET sticky = 1 WHERE newsID = '.(int)$_GET['id']);
  9. } else {
  10. $db->query('UPDATE '.DB_PRE.'ecp_news SET sticky = 0 WHERE newsID = '.(int)$_GET['id']);
  11. }
  12. $tpl->assign('ajax', 1);
  13. }
  14. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', 'datum > 0',0);
  15. if($anzahl) {
  16. $limits = get_sql_limit($anzahl, ADMIN_ENTRIES);
  17. $news = array();
  18. $db->query('SELECT `newsID`, `topicID`, `datum`, `headline`, `topicname`, sticky FROM `'.DB_PRE.'ecp_news` LEFT JOIN `'.DB_PRE.'ecp_topics` ON (`topicID` = `tID`) ORDER BY sticky DESC, `datum` DESC LIMIT '.$limits[1].', '.ADMIN_ENTRIES);
  19. while($row = $db->fetch_assoc()) {
  20. $row['datum'] = date(LONG_DATE, $row['datum']);
  21. $news[] = $row;
  22. }
  23. }
  24. $tpl->assign('seiten', makepagelink('?section=admin&site=news', (isset($_GET['page']) ? $_GET['page'] : 1), $limits[0]));
  25. $tpl->assign('news', @$news);
  26. ob_start();
  27. $tpl->display(DESIGN.'/tpl/admin/news.html');
  28. $content = ob_get_contents();
  29. ob_end_clean();
  30. if(@$_GET['func'] == 'pin') {
  31. echo html_ajax_convert($content);
  32. die();
  33. } else {
  34. main_content(ADMIN_NEWS, $content, '',1);
  35. }
  36. }
  37. function admin_news_add() {
  38. global $db,$groups, $language_array;
  39. if(isset($_POST['submit'])) {
  40. if($_POST['headline'] == '' OR (int)$_POST['topic'] == 0 OR $_POST['bodytext'] == '') {
  41. $tpl = new smarty;
  42. $links = array();
  43. foreach($_POST AS $key => $value) {
  44. if(strpos($key, 'ink_')) {
  45. $nr = substr($key,strpos($key, '_')+1);
  46. $links[$nr]['link'] = $value;
  47. } elseif (strpos($key, 'rl_')) {
  48. $nr = substr($key,strpos($key, '_')+1);
  49. $links[$nr]['url'] = check_url($value);
  50. }else {
  51. $tpl->assign($key, $value);
  52. }
  53. }
  54. $tpl->assign('links', $links);
  55. $db->query('SELECT tID, topicname FROM '.DB_PRE.'ecp_topics ORDER by topicname ASC');
  56. $topics = '';
  57. while($row = $db->fetch_assoc()) {
  58. ($_POST['topic'] == $row['tID'])? $sub = ' selected="selected"' : $sub = '';
  59. $topics .= '<option'.$sub.' value="'.$row['tID'].'">'.$row['topicname'].'</option>';
  60. }
  61. $tpl->assign('topics', $topics);
  62. $db->query('SELECT groupID, name FROM '.DB_PRE.'ecp_groups ORDER by name ASC');
  63. (in_array('all', $_POST['rights']))? $rights = '<option value="all" selected="selected">'.ALL.'</option>' : $rights = '<option value="all">'.ALL.'</option>';
  64. while($row = $db->fetch_assoc()) {
  65. (in_array($row['groupID'], $_POST['rights']))? $sub = ' selected="selected"' : $sub = '';
  66. if(isset($groups[$row['name']])) $row['name'] = $groups[$row['name']];
  67. $rights .= '<option'.$sub.' value="'.$row['groupID'].'">'.$row['name'].'</option>';
  68. }
  69. $files = scan_dir('inc/language', true);
  70. (in_array('all', $_POST['rights']))?$languages = '<option value="all" selected="selected">'.ALL.'</option>' : $languages = '<option value="all">'.ALL.'</option>';
  71. foreach($files AS $lang) {
  72. if(strpos($lang, '.php')) {
  73. $lang = substr($lang,0,strpos($lang, '.'));
  74. (in_array($lang, $_POST['languages']))? $sub = ' selected="selected"' : $sub = '';
  75. @$languages .= '<option'.$sub.' value="'.$lang.'">'.@$language_array[$lang].'</option>';
  76. }
  77. }
  78. $tpl->assign('rights', $rights);
  79. $tpl->assign('topics', $topics);
  80. $tpl->assign('languages', $languages);
  81. ob_start();
  82. $tpl->display(DESIGN.'/tpl/admin/news_add_edit.html');
  83. $content = ob_get_contents();
  84. ob_end_clean();
  85. main_content(ADMIN_NEWS_ADD, $content, '',1);
  86. } else {
  87. if(in_array('all', $_POST['rights']))
  88. $rights = '';
  89. else {
  90. $rights = ',';
  91. foreach($_POST['rights'] AS $key) {
  92. $rights .= (int)$key.',';
  93. }
  94. }
  95. if(in_array('all', $_POST['languages'])) $lang = ''; else $lang = ','.implode(',',$_POST['languages']).',';
  96. $zeit = strtotime($_POST['datum']);
  97. if($zeit == 0) $zeit = time();
  98. $i = 0;
  99. while(isset($_POST['link_'.$i])) {
  100. if($_POST['link_'.$i] != '' AND $_POST['url_'.$i] != '') {
  101. @$links .= '[URL='.check_url($_POST['url_'.$i].']'.$_POST['link_'.$i].'[/URL]');
  102. }
  103. $i++;
  104. }
  105. $sql = 'INSERT INTO '.DB_PRE.'ecp_news (`userID`, `topicID`, `access`, `lang`, `datum`, `headline`, `bodytext`, `extendtext`, `links`) VALUES (
  106. '.$_SESSION['userID'].', '.(int)$_POST['topic'].', \''.$rights.'\', \''.strsave($lang).'\', '.$zeit.',
  107. \''.strsave($_POST['headline']).'\', \''.strsave($_POST['bodytext']).'\', \''.strsave($_POST['extendtext']).'\',
  108. \''.strsave(@$links).'\');';
  109. if($db->query($sql)) {
  110. header1('?section=admin&site=news');
  111. }
  112. }
  113. } else {
  114. $tpl = new smarty;
  115. $links = array(0);
  116. $tpl->assign('links', $links);
  117. $db->query('SELECT tID, topicname FROM '.DB_PRE.'ecp_topics ORDER by topicname ASC');
  118. $topics = '';
  119. while($row = $db->fetch_assoc()) {
  120. $topics .= '<option value="'.$row['tID'].'">'.$row['topicname'].'</option>';
  121. }
  122. $tpl->assign('topics', $topics);
  123. $db->query('SELECT groupID, name FROM '.DB_PRE.'ecp_groups ORDER by name ASC');
  124. $rights = '<option value="all" selected="selected">'.ALL.'</option>';
  125. while($row = $db->fetch_assoc()) {
  126. if(isset($groups[$row['name']])) $row['name'] = $groups[$row['name']];
  127. $rights .= '<option value="'.$row['groupID'].'">'.$row['name'].'</option>';
  128. }
  129. $files = scan_dir('inc/language', true);
  130. $languages = '<option value="all" selected="selected">'.ALL.'</option>';
  131. foreach($files AS $lang) {
  132. if(strpos($lang, '.php')) {
  133. $lang = substr($lang,0,strpos($lang, '.'));
  134. @$languages .= '<option value="'.$lang.'">'.@$language_array[$lang].'</option>';
  135. }
  136. }
  137. $tpl->assign('rights', $rights);
  138. $tpl->assign('topics', $topics);
  139. $tpl->assign('languages', $languages);
  140. ob_start();
  141. $tpl->display(DESIGN.'/tpl/admin/news_add_edit.html');
  142. $content = ob_get_contents();
  143. ob_end_clean();
  144. main_content(ADMIN_NEWS_ADD, $content, '',1);
  145. }
  146. }
  147. function admin_news_edit($id) {
  148. global $db,$groups, $language_array;
  149. if(isset($_POST['submit'])) {
  150. if($_POST['headline'] == '' OR (int)$_POST['topic'] == 0 OR $_POST['bodytext'] == '') {
  151. $tpl = new smarty;
  152. $links = array();
  153. foreach($_POST AS $key => $value) {
  154. if(strpos($key, 'ink_')) {
  155. $nr = substr($key,strpos($key, '_')+1);
  156. $links[$nr]['link'] = $value;
  157. } elseif (strpos($key, 'rl_')) {
  158. $nr = substr($key,strpos($key, '_')+1);
  159. $links[$nr]['url'] = check_url($value);
  160. }else {
  161. $tpl->assign($key, $value);
  162. }
  163. }
  164. $tpl->assign('links', $links);
  165. $db->query('SELECT tID, topicname FROM '.DB_PRE.'ecp_topics ORDER by topicname ASC');
  166. $topics = '';
  167. while($row = $db->fetch_assoc()) {
  168. ($_POST['topic'] == $row['tID'])? $sub = ' selected="selected"' : $sub = '';
  169. $topics .= '<option'.$sub.' value="'.$row['tID'].'">'.$row['topicname'].'</option>';
  170. }
  171. $tpl->assign('topics', $topics);
  172. $db->query('SELECT groupID, name FROM '.DB_PRE.'ecp_groups ORDER by name ASC');
  173. (in_array('all', $_POST['rights']))? $rights = '<option value="all" selected="selected">'.ALL.'</option>' : $rights = '<option value="all">'.ALL.'</option>';
  174. while($row = $db->fetch_assoc()) {
  175. (in_array($row['groupID'], $_POST['rights']))? $sub = ' selected="selected"' : $sub = '';
  176. if(isset($groups[$row['name']])) $row['name'] = $groups[$row['name']];
  177. $rights .= '<option'.$sub.' value="'.$row['groupID'].'">'.$row['name'].'</option>';
  178. }
  179. $files = scan_dir('inc/language', true);
  180. (in_array('all', $_POST['rights']))?$languages = '<option value="all" selected="selected">'.ALL.'</option>' : $languages = '<option value="all">'.ALL.'</option>';
  181. foreach($files AS $lang) {
  182. if(strpos($lang, '.php')) {
  183. $lang = substr($lang,0,strpos($lang, '.'));
  184. (in_array($lang, $_POST['languages']))? $sub = ' selected="selected"' : $sub = '';
  185. @$languages .= '<option'.$sub.' value="'.$lang.'">'.@$language_array[$lang].'</option>';
  186. }
  187. }
  188. $tpl->assign('rights', $rights);
  189. $tpl->assign('topics', $topics);
  190. $tpl->assign('languages', $languages);
  191. ob_start();
  192. $tpl->display(DESIGN.'/tpl/admin/news_add_edit.html');
  193. $content = ob_get_contents();
  194. ob_end_clean();
  195. main_content(ADMIN_NEWS_ADD, $content, '',1);
  196. } else {
  197. if(in_array('all', $_POST['rights']))
  198. $rights = '';
  199. else {
  200. $rights = ',';
  201. foreach($_POST['rights'] AS $key) {
  202. $rights .= (int)$key.',';
  203. }
  204. }
  205. if(in_array('all', $_POST['languages'])) $lang = ''; else $lang = ','.implode(',',$_POST['languages']).',';
  206. $zeit = strtotime($_POST['datum']);
  207. if($zeit == 0) $zeit = time();
  208. $i = 0;
  209. while(isset($_POST['link_'.$i])) {
  210. if($_POST['link_'.$i] != '' AND $_POST['url_'.$i] != '') {
  211. @$links .= '[URL='.check_url($_POST['url_'.$i].']'.$_POST['link_'.$i].'[/URL]');
  212. }
  213. $i++;
  214. }
  215. $sql = 'UPDATE '.DB_PRE.'ecp_news SET `topicID` = '.(int)$_POST['topic'].',
  216. `access` = \''.$rights.'\',
  217. `lang` = \''.strsave($lang).'\',
  218. `datum` = '.$zeit.',
  219. `headline` = \''.strsave($_POST['headline']).'\',
  220. `bodytext` = \''.strsave($_POST['bodytext']).'\',
  221. `extendtext` = \''.strsave($_POST['extendtext']).'\',
  222. `links` = \''.strsave(@$links).'\'
  223. WHERE newsID = '.$id.';';
  224. if($db->query($sql)) {
  225. header1('?section=admin&site=news');
  226. }
  227. }
  228. } else {
  229. $news = $db->fetch_assoc('SELECT `topicID`, `access`, `lang`, `datum`, `headline`, `bodytext`, `extendtext`, `links` FROM `'.DB_PRE.'ecp_news` WHERE newsID = '.$id);
  230. if(is_array($news)) {
  231. $tpl = new smarty;
  232. $news['datum'] = date('Y-m-d H:i:s', $news['datum']);
  233. $db->query('SELECT tID, topicname FROM '.DB_PRE.'ecp_topics ORDER by topicname ASC');
  234. $topics = '';
  235. while($row = $db->fetch_assoc()) {
  236. ($news['topicID'] == $row['tID'])? $sub = ' selected="selected"' : $sub = '';
  237. $topics .= '<option'.$sub.' value="'.$row['tID'].'">'.$row['topicname'].'</option>';
  238. }
  239. $tpl->assign('topics', $topics);
  240. $db->query('SELECT groupID, name FROM '.DB_PRE.'ecp_groups ORDER by name ASC');
  241. if ($news['access'] == '') {
  242. $rights = '<option value="all" selected="selected">'.ALL.'</option>';
  243. $rechte = array();
  244. } else {
  245. $rechte = explode(',', substr($news['access'],1,strlen($news['access'])-1));
  246. $rights = '<option value="all">'.ALL.'</option>';
  247. }
  248. while($row = $db->fetch_assoc()) {
  249. (in_array($row['groupID'], $rechte))? $sub = ' selected="selected"' : $sub = '';
  250. if(isset($groups[$row['name']])) $row['name'] = $groups[$row['name']];
  251. $rights .= '<option'.$sub.' value="'.$row['groupID'].'">'.$row['name'].'</option>';
  252. }
  253. $files = scan_dir('inc/language', true);
  254. if ($news['lang'] == '') {
  255. $languages = '<option value="all" selected="selected">'.ALL.'</option>';
  256. $lang1 = array();
  257. } else {
  258. $lang1 = explode(',', substr($news['lang'],1,strlen($news['lang'])-1));
  259. $languages = '<option value="all">'.ALL.'</option>';
  260. }
  261. foreach($files AS $lang) {
  262. if(strpos($lang, '.php')) {
  263. $lang = substr($lang,0,strpos($lang, '.'));
  264. (in_array($lang, $lang1))? $sub = ' selected="selected"' : $sub = '';
  265. @$languages .= '<option'.$sub.' value="'.$lang.'">'.@$language_array[$lang].'</option>';
  266. }
  267. }
  268. if($news['links'] == '')
  269. $links = array(0);
  270. else {
  271. preg_match_all('#\[URL=(.*)\](.*)\[/URL\]#Uis', $news['links'], $spe);
  272. for($i = 0; $i<count($spe[1]); $i++) {
  273. $links[$i]['url'] = $spe[1][$i];
  274. $links[$i]['link'] = $spe[2][$i];
  275. }
  276. }
  277. foreach($news AS $key => $value) $tpl->assign($key, $value);
  278. $tpl->assign('links', $links);
  279. $tpl->assign('rights', $rights);
  280. $tpl->assign('topics', $topics);
  281. $tpl->assign('languages', $languages);
  282. ob_start();
  283. $tpl->display(DESIGN.'/tpl/admin/news_add_edit.html');
  284. $content = ob_get_contents();
  285. ob_end_clean();
  286. main_content(ADMIN_NEWS_ADD, $content, '',1);
  287. } else {
  288. table(ERROR, NO_ENTRIES);
  289. }
  290. }
  291. }
  292. function admin_news_del($id) {
  293. global $db;
  294. if(isset($_GET['agree'])) {
  295. $id = (int)$_GET['id'];
  296. if($db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', 'newsID = '.$id)) {
  297. if($db->query('DELETE FROM '.DB_PRE.'ecp_comments WHERE subID = '.$id.' AND bereich = "news"')){
  298. if($db->query('DELETE FROM '.DB_PRE.'ecp_news WHERE newsID = '.$id)) {
  299. header1('?section=admin&site=news');
  300. }
  301. }
  302. } else {
  303. echo NO_ENTRIES_ID;
  304. }
  305. } else {
  306. table(DELETE, '<center>'.DEL_NEWS.'<br /><a href="?section=admin&amp;site=news&amp;func=del&amp;id='.$id.'&amp;agree=1"><span class="error">'.YES.'</span></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?section=admin&amp;site=news">'.NO.'</a></center>');
  307. }
  308. }
  309. if (!isset($_SESSION['rights']['admin']['news']) AND !isset($_SESSION['rights']['superadmin'])) {
  310. table(ERROR, NO_ADMIN_RIGHTS);
  311. } else {
  312. if(isset($_GET['func'])) {
  313. switch($_GET['func']) {
  314. case 'add':
  315. admin_news_add();
  316. break;
  317. case 'edit':
  318. admin_news_edit((int)$_GET['id']);
  319. break;
  320. case 'del':
  321. admin_news_del((int)$_GET['id']);
  322. break;
  323. case 'pin':
  324. admin_news();
  325. break;
  326. default:
  327. admin_news();
  328. }
  329. } else {
  330. admin_news();
  331. }
  332. }
  333. ?>