/include/admin/moduls/navi.modul.php

https://github.com/pschichtel/Infected-CMS · PHP · 511 lines · 485 code · 26 blank · 0 comment · 106 complexity · b4cfd6ff4fd94676b0af14f82b7d83e2 MD5 · raw file

  1. <?php
  2. realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']) and die('<strong>Access denied!</strong>');
  3. if (!user::loggedIn())
  4. {
  5. user::backToLogin();
  6. }
  7. $lang = new Lang($info->modul);
  8. $design = new Design();
  9. $design->printBegin();
  10. $pos = (int) $info->modulParams('pos');
  11. $id = (int) $info->modulParams('id');
  12. $menuid = (int) $info->modulParams('menuid');
  13. if (!is_null($info->modulParams('add')))
  14. {
  15. user::hasRight('navi_add') or headerTo($info->modulSelf . '&status=access_denied');
  16. if (isset($_POST['post']))
  17. {
  18. $name = htmlspecialchars(trim($_POST['name']));
  19. $addr = htmlspecialchars(trim($_POST['addr']));
  20. $type = (int) $_POST['type'];
  21. $position = (int) $_POST['pos'];
  22. $level = (int) $_POST['level'];
  23. $extern = (isset($_POST['extern']) ? 1 : 0);
  24. $menuid = (int) $_POST['menuid'];
  25. $visible = (isset($_POST['visible']) ? 1 : 0);
  26. if ($name === '')
  27. {
  28. $name = $lang->unnamed;
  29. }
  30. if ($addr === '')
  31. {
  32. headerTo($info->modulSelf . '&status=no_address');
  33. }
  34. if ($type < 1 || $type > 5)
  35. {
  36. headerTo($info->modulSelf);
  37. }
  38. $query = 'SELECT count(`id`) as \'count\' FROM `PREFIX_menus` WHERE `menuid`=' . $menuid;
  39. $result = $db->GetData($query);
  40. $count = $result[0]->count;
  41. if ($position < 1 || $position > $count)
  42. {
  43. $position = $count + 1;
  44. }
  45. if ($level < 0)
  46. {
  47. $level = 0;
  48. }
  49. $query = "SELECT count(*) as 'count' FROM `PREFIX_menus` WHERE `position`=$position AND `menuid`=$menuid";
  50. $result = $db->GetData($query);
  51. if ($result[0]->count > 0)
  52. {
  53. $query = "UPDATE `PREFIX_menus` SET `position`=`position`+1 WHERE `position`>=$position";
  54. $db->PushData($query);
  55. }
  56. $query = 'INSERT INTO `PREFIX_menus` (`menuid`,`type`,`name`,`address`,`position`,`level`,`visible`,`extern`) VALUES ';
  57. $query .= "($menuid, $type, ?, ?, $position, $level, $visible, $extern)";
  58. $types = 'ss';
  59. $param_arr = array(
  60. $name,
  61. $addr
  62. );
  63. $db->PushData($query, $types, $param_arr);
  64. headerTo($info->modulSelf . '&status=added&menuid=' . $menuid);
  65. }
  66. if (!isset($_POST['type']) || !Text::is_numeric($_POST['type']))
  67. {
  68. headerTo($info->modulSelf);
  69. }
  70. $type = (int) $_POST['type'];
  71. if ($type > 0 && $type <= 5)
  72. {
  73. $tpl = new Template('navi_type' . $type, $lang);
  74. $params = array(
  75. 'THIS' => $info->modulSelf,
  76. 'DO' => 'add=new',
  77. 'NAME' => '',
  78. 'ADDR' => '',
  79. 'VISIBLE-TRUE' => ' selected="selected"',
  80. 'VISIBLE-FALSE' => '',
  81. 'LEVEL' => '0',
  82. 'POS' => '',
  83. 'MENU1' => '',
  84. 'MENU2' => '',
  85. 'MENU3' => '',
  86. 'MENU4' => '',
  87. 'MENU5' => '',
  88. 'EXTERN' => '',
  89. 'LEGEND' => $lang->{'new' . $type}
  90. );
  91. if ($type == 2 || $type == 3 || $type == 4)
  92. {
  93. switch ($type)
  94. {
  95. case 2:
  96. $options = list_moduls();
  97. if (count($options) == 0)
  98. {
  99. headerTo($info->modulSelf . '&status=no_available');
  100. }
  101. break;
  102. case 3:
  103. $options = list_selfs();
  104. if (count($options) == 0)
  105. {
  106. headerTo($info->modulSelf . '&status=no_available');
  107. }
  108. break;
  109. case 4:
  110. $options = list_boxes();
  111. if (count($options) == 0)
  112. {
  113. headerTo($info->modulSelf . '&status=no_available');
  114. }
  115. break;
  116. }
  117. $modulsStr = '';
  118. foreach($options as $value => $option)
  119. {
  120. $modulsStr .= '<option value="' . $value . '">' . ucfirst($option) . '</option>';
  121. }
  122. $params['ADDR'] = $modulsStr;
  123. }
  124. $tpl->setParams($params);
  125. $tpl->printPart(0, true);
  126. }
  127. }
  128. elseif (!is_null($info->modulParams('del')))
  129. {
  130. user::hasRight('navi_del') or headerTo($info->modulSelf . '&status=access_denied');
  131. if (isset($_POST['confirmation']))
  132. {
  133. if ($_POST['confirm'] == 'no')
  134. {
  135. headerTo($info->modulSelf . '&menuid=' . $menuid);
  136. }
  137. elseif ($_POST['confirm'] == 'yes')
  138. {
  139. $query = 'SELECT `position` FROM `PREFIX_menus` WHERE `id`=' . (int) $info->modulParams('del') . ' LIMIT 1';
  140. $result = $db->GetData($query);
  141. $posi = $result[0]->position;
  142. $query = 'DELETE FROM `PREFIX_menus` WHERE `menuid`= ' . $menuid . ' AND `id`=' . (int) $info->modulParams('del');
  143. $db->PushData($query);
  144. $query = 'UPDATE `PREFIX_menus` SET `position`=`position`-1 WHERE `menuid`= ' . $menuid . ' AND `position` >=' . $posi;
  145. $db->PushData($query);
  146. headerTo($info->modulSelf . '&status=deleted&menuid=' . $menuid);
  147. }
  148. else
  149. {
  150. headerTo($info->modulSelf);
  151. }
  152. }
  153. $tpl = new Template('confirm', $lang);
  154. $params = array(
  155. 'THIS' => $info->modulSelf . '&amp;del=' . (int) $info->modulParams('del') . '&amp;menuid=' . $menuid,
  156. 'LEGEND' => $lang->sure2delete
  157. );
  158. $tpl->setParams($params);
  159. $tpl->printPart(0, true);
  160. }
  161. elseif (!is_null($info->modulParams('edit')) && !is_null($info->modulParams('id')) && !is_null($info->modulParams('menuid')))
  162. {
  163. if ($info->modulParams('edit') == 'visible')
  164. {
  165. user::hasRight('navi_edit') or headerTo($info->modulSelf . '&status=access_denied');
  166. $query = 'SELECT `visible` FROM `PREFIX_menus` WHERE `id`=' . $id;
  167. $result = $db->GetData($query);
  168. if ($db->affected_rows == 0)
  169. {
  170. headerTo($info->modulSelf . '&menuid=' . $menuid);
  171. }
  172. $query = 'UPDATE `PREFIX_menus` SET `visible`=';
  173. $query .= ($result[0]->visible == 1) ? '0' : '1';
  174. $query .= ' WHERE `id`=' . $id;
  175. $db->PushData($query);
  176. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=visible_updated');
  177. }
  178. elseif ($info->modulParams('edit') == 'extern')
  179. {
  180. user::hasRight('navi_edit') or headerTo($info->modulSelf . '&status=access_denied');
  181. $query = 'SELECT `type` FROM `PREFIX_menus` WHERE `id`=' . $id . ' LIMIT 1';
  182. $result = $db->GetData($query);
  183. if ($db->affected_rows == 0)
  184. {
  185. headerTo($info->modulSelf . '&menuid=' . $menuid);
  186. }
  187. $result = &$result[0];
  188. if ($result->type == 1 || $result->type == 4)
  189. {
  190. headerTo($info->modulSelf . '&menuid=' . $menuid);
  191. }
  192. $query = 'SELECT `extern` FROM `PREFIX_menus` WHERE `id`=' . $id;
  193. $result = $db->GetData($query);
  194. $query = 'UPDATE `PREFIX_menus` SET `extern`=';
  195. $query .= ($result->extern == 1 ? '0' : '1');
  196. $query .= ' WHERE `id`=' . $id;
  197. $db->PushData($query);
  198. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=extern_updated');
  199. }
  200. elseif ($info->modulParams('edit') == 'pos_up')
  201. {
  202. user::hasRight('navi_move') or headerTo($info->modulSelf . '&status=access_denied');
  203. $query = 'SELECT `position` FROM `PREFIX_menus` WHERE `id`=' . $id;
  204. $posi = $db->GetData($query);
  205. if ($db->affected_rows == 0)
  206. {
  207. headerTo($info->modulSelf . '&menuid=' . $menuid);
  208. }
  209. if ($posi[0]->position <= 1)
  210. {
  211. headerTo($info->modulSelf . '&menuid=' . $menuid);
  212. }
  213. $query = 'UPDATE `PREFIX_menus` SET `position`=0 WHERE `id`=' . $id;
  214. $db->PushData($query);
  215. $query = "UPDATE `PREFIX_menus` SET `position`=`position`+1 WHERE `menuid`=$menuid AND `position`=" . --$pos;
  216. $db->PushData($query);
  217. $query = "UPDATE `PREFIX_menus` SET `position`=$pos WHERE `id`=$id";
  218. $db->PushData($query);
  219. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=pos_upped');
  220. }
  221. elseif ($info->modulParams('edit') == 'pos_down')
  222. {
  223. user::hasRight('navi_move') or headerTo($info->modulSelf . '&status=access_denied');
  224. $query = 'SELECT count(*) AS \'count\' FROM `PREFIX_menus` WHERE `menuid`=' . $menuid;
  225. $count = $db->GetData($query);
  226. if ($db->affected_rows == 0)
  227. {
  228. headerTo($info->modulSelf);
  229. }
  230. if ($pos >= $count[0]->count)
  231. {
  232. headerTo($info->modulSelf . '&menuid=' . $menuid);
  233. }
  234. $query = 'UPDATE `PREFIX_menus` SET `position`=0 WHERE `id`=' . $id;
  235. $db->PushData($query);
  236. $query = "UPDATE `PREFIX_menus` SET `position`=`position`-1 WHERE `menuid`=$menuid AND `position`=" . ++$pos;
  237. $db->PushData($query);
  238. $query = "UPDATE `PREFIX_menus` SET `position`=$pos WHERE `id`=$id";
  239. $db->PushData($query);
  240. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=pos_downed');
  241. }
  242. elseif ($info->modulParams('edit') == 'level_up')
  243. {
  244. user::hasRight('navi_move') or headerTo($info->modulSelf . '&status=access_denied');
  245. $query = 'SELECT `type` FROM `PREFIX_menus` WHERE `id`=' . $id . ' LIMIT 1';
  246. $result = $db->GetData($query);
  247. if ($db->affected_rows == 0)
  248. {
  249. headerTo($info->modulSelf . '&menuid=' . $menuid);
  250. }
  251. $result = &$result[0];
  252. if ($result->type == 1 || $result->type == 4)
  253. {
  254. headerTo($info->modulSelf . '&menuid=' . $menuid);
  255. }
  256. $query = 'UPDATE `PREFIX_menus` SET `level`=`level`+1 WHERE `id`=' . $id . ' LIMIT 1';
  257. $db->PushData($query);
  258. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=level_upped');
  259. }
  260. elseif ($info->modulParams('edit') == 'level_down')
  261. {
  262. user::hasRight('navi_move') or headerTo($info->modulSelf . '&status=access_denied');
  263. $query = 'SELECT `level`,`type` FROM `PREFIX_menus` WHERE `id`=' . $id . ' LIMIT 1';
  264. $result = $db->GetData($query);
  265. if ($db->affected_rows == 0)
  266. {
  267. headerTo($info->modulSelf . '&menuid=' . $menuid);
  268. }
  269. $result = &$result[0];
  270. if ($result->type == 1 || $result->type == 4)
  271. {
  272. headerTo($info->modulSelf . '&menuid=' . $menuid);
  273. }
  274. if (((int) $result->level - 1) < 0)
  275. {
  276. headerTo($info->modulSelf . '&menuid=' . $menuid);
  277. }
  278. $query = 'UPDATE `PREFIX_menus` SET `level`=`level`-1 WHERE `id`=' . $id . ' LIMIT 1';
  279. $db->PushData($query);
  280. headerTo($info->modulSelf . '&menuid=' . $menuid . '&status=level_downed');
  281. }
  282. elseif ($info->modulParams('edit') == 'full')
  283. {
  284. user::hasRight('navi_edit') or headerTo($info->modulSelf . '&status=access_denied');
  285. if (isset($_POST['post']))
  286. {
  287. $name = htmlspecialchars(trim($_POST['name']));
  288. $addr = htmlspecialchars(trim($_POST['addr']));
  289. $type = (int) $_POST['type'];
  290. $position = (int) $_POST['pos'];
  291. $level = (int) $_POST['level'];
  292. $extern = (isset($_POST['extern']) ? 1 : 0);
  293. $menuid = (int) $_POST['menuid'];
  294. $visible = (isset($_POST['visible']) ? 1 : 0);
  295. if (trim($name) === '')
  296. {
  297. $name = $lang->unnamed;
  298. }
  299. if (trim($addr) === '')
  300. {
  301. headerTo($info->modulSelf . '&status=no_address&menuid=' . $menuid);
  302. }
  303. if ($type < 1 || $type > 5)
  304. {
  305. headerTo($info->modulSelf . '&menuid=' . $menuid);
  306. }
  307. $query = 'SELECT count(`id`) as \'count\' FROM `PREFIX_menus` WHERE `menuid`=' . $menuid;
  308. $result = $db->GetData($query);
  309. $count = $result[0]->count;
  310. if ($position < 1 || $position > $count)
  311. {
  312. $position = $count + 1;
  313. }
  314. if ($level < 0)
  315. {
  316. $level = 0;
  317. }
  318. $query = "SELECT count(*) as 'count' FROM `PREFIX_menus` WHERE `position`=$position AND `menuid`=$menuid";
  319. $result = $db->GetData($query);
  320. if ($result[0]->count > 0)
  321. {
  322. $query = 'SELECT `position` FROM `PREFIX_menus` WHERE `id`=' . $id . ' LIMIT 1';
  323. $result = $db->GetData($query);
  324. $posi = $result[0]->position;
  325. $op0 = ($position < $posi ? '+' : '-');
  326. $op1 = ($position < $posi ? '>=' : '<=');
  327. $op2 = ($position < $posi ? '<' : '>');
  328. $query = "UPDATE `PREFIX_menus` SET `position`=`position`{$op0}1 WHERE `position`{$op1}{$position} AND `position`{$op2}{$posi}";
  329. $db->PushData($query);
  330. }
  331. $query = 'UPDATE `PREFIX_menus` SET ';
  332. $query .= "`menuid`=$menuid, ";
  333. $query .= "`name`=?, ";
  334. $query .= "`address`=?, ";
  335. $query .= "`position`=$position, ";
  336. $query .= "`level`=$level, ";
  337. $query .= "`visible`=$visible, ";
  338. $query .= "`extern`=$extern ";
  339. $query .= 'WHERE `id`=' . $id . ' LIMIT 1';
  340. $types = 'ss';
  341. $param_arr = array(
  342. $name,
  343. $addr
  344. );
  345. $db->PushData($query, $types, $param_arr);
  346. headerTo($info->modulSelf . '&status=edited&menuid=' . $menuid);
  347. }
  348. $query = 'SELECT `name`,`address`,`menuid`,`type`,`level`,`position`,`visible`,`extern` FROM `PREFIX_menus` WHERE `id`=' . $id;
  349. $result = $db->GetData($query);
  350. if ($db->affected_rows == 0)
  351. {
  352. headerTo($info->modulSelf . '&menuid=' . $menuid);
  353. }
  354. $result = &$result[0];
  355. $type = &$result->type;
  356. $tpl = new Template('navi_type' . $type, $lang);
  357. $params = array(
  358. 'THIS' => $info->modulSelf,
  359. 'DO' => 'edit=full&amp;id=' . $id . '&amp;menuid=' . $menuid,
  360. 'NAME' => $result->name,
  361. 'VISIBLE-TRUE' => '',
  362. 'VISIBLE-FALSE' => '',
  363. 'LEVEL' => $result->level,
  364. 'POS' => $result->position,
  365. 'MENU1' => '',
  366. 'MENU2' => '',
  367. 'MENU3' => '',
  368. 'MENU4' => '',
  369. 'MENU5' => '',
  370. 'EXTERN' => $result->extern ? 'checked="checked"' : '',
  371. 'LEGEND' => $lang->{'edit' . $type}
  372. );
  373. $params['MENU' . $result->menuid] = 'selected="selected"';
  374. $params['VISIBLE-' . ($result->visible ? 'TRUE' : 'FALSE')] = 'selected="selected"';
  375. if ($type == 2 || $type == 3 || $type == 4)
  376. {
  377. switch ($type)
  378. {
  379. case 2:
  380. $options = list_moduls($result->address);
  381. if (count($options) == 0)
  382. {
  383. headerTo($info->modulSelf . '&status=no_available&menuid=' . $menuid);
  384. }
  385. break;
  386. case 3:
  387. $options = list_selfs($result->address);
  388. if (count($options) == 0)
  389. {
  390. headerTo($info->modulSelf . '&status=no_available&menuid=' . $menuid);
  391. }
  392. break;
  393. case 4:
  394. $options = list_boxes($result->address);
  395. if (count($options) == 0)
  396. {
  397. headerTo($info->modulSelf . '&status=no_available&menuid=' . $menuid);
  398. }
  399. break;
  400. }
  401. $modulsStr = '';
  402. foreach($options as $value => $option)
  403. {
  404. $modulsStr .= '<option value="' . $value . '">' . ucfirst($option) . '</option>';
  405. }
  406. $params['ADDR'] = $modulsStr;
  407. }
  408. else
  409. {
  410. $params['ADDR'] = $result->address;
  411. }
  412. $tpl->setParams($params);
  413. $tpl->printPart(0, true);
  414. }
  415. else
  416. {
  417. headerTo($info->modulSelf . '&menuid=' . $menuid);
  418. }
  419. }
  420. else
  421. {
  422. if ($menuid === 0)
  423. {
  424. $menuid = 1;
  425. }
  426. $tpl = new Template('navi', $lang);
  427. $params = array(
  428. 'STATUS' => $info->statusMessage($lang),
  429. 'THIS' => $info->modulSelf
  430. );
  431. $tpl->setParams($params);
  432. $tpl->printPart(0, true);
  433. $query = 'SELECT * FROM `PREFIX_menus` WHERE `menuid`=' . $menuid . ' ORDER BY `position`';
  434. $result = $db->GetData($query);
  435. foreach ($result as $index => &$row)
  436. {
  437. $params = array(
  438. 'ID' => $row->id,
  439. 'POS' => $row->position,
  440. 'MENUID' => $row->menuid,
  441. 'NAME' => $row->name,
  442. 'ADDR' => $row->address,
  443. 'LEVEL' => $row->level,
  444. 'VISIBLE' => ($row->visible == 1 ? $lang->Yes : $lang->No),
  445. 'EXTERN' => ($row->extern == 1 ? $lang->Yes : $lang->No),
  446. 'THIS' => $info->modulSelf
  447. );
  448. if ($row->type == 1)
  449. {
  450. $params['NAME'] = '<span style="font-weight:bolder;">' . $params['NAME'] . '</span>';
  451. $params['ADDR'] = '<span style="font-weight:bolder;">' . $lang->menu . '</span>';
  452. $params['LEVEL'] = '-';
  453. $params['EXTERN'] = '-';
  454. }
  455. elseif ($row->type == 2)
  456. {
  457. $params['ADDR'] = 'Modul:' . $params['ADDR'];
  458. }
  459. elseif ($row->type == 3)
  460. {
  461. $params['ADDR'] = 'Self:' . $params['ADDR'];
  462. }
  463. elseif ($row->type == 4)
  464. {
  465. $params['NAME'] = '<span style="font-weight:bolder;">' . $params['NAME'] . '</span>';
  466. $params['ADDR'] = '<span style="font-weight:bolder;">Box:' . $params['ADDR'] . '</span>';
  467. $params['LEVEL'] = '-';
  468. $params['EXTERN'] = '-';
  469. }
  470. elseif ($row->type == 5)
  471. {
  472. $trimmed = mb_substr($params['ADDR'], 0, 20);
  473. $trimmed = $trimmed . (mb_strlen($params['ADDR']) > mb_strlen($trimmed) ? '...' : '');
  474. $params['ADDR'] = '<span title="' . $params['ADDR'] . '">' . $trimmed . '</span>';
  475. }
  476. $params['STYLE'] = 'tablerow' . ($index % 2 == 0 ? '1' : '2');
  477. $tpl->setParams($params);
  478. $tpl->printPart(1, true);
  479. }
  480. $params['THIS'] = $info->modulSelf;
  481. $tpl->setParams($params);
  482. $tpl->printPart(2, true);
  483. }
  484. $design->printEnd();
  485. ?>