/include/admin/moduls/contact.modul.php

https://github.com/pschichtel/Infected-CMS · PHP · 302 lines · 275 code · 27 blank · 0 comment · 37 complexity · bf248fe0e5d8b8e89ebeb11a78f8a71c 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. define('PAGELEN', 20);
  8. $lang = new Lang($info->modul);
  9. $design = new Design();
  10. $design->printBegin();
  11. if (!is_null($info->modulParams('add')))
  12. {
  13. user::hasRight('contact_add') or headerTo($info->modulSelf . '&status=access_denied');
  14. $msg = '';
  15. $name = '';
  16. $email = '';
  17. if (isset($_POST['post']))
  18. {
  19. if (trim($_POST['name']) === '')
  20. {
  21. $msg .= ' - ' . $lang->err_name . '<br />';
  22. }
  23. elseif (mb_strlen(trim($_POST['name']), 'UTF-8') > 70)
  24. {
  25. $msg .= ' - ' . $lang->err_name2long . '<br />';
  26. }
  27. if (trim($_POST['email']) === '' || !Text::is_email($_POST['email']))
  28. {
  29. $msg .= ' - ' . $lang->err_email . '<br />';
  30. }
  31. elseif (mb_strlen(trim($_POST['email']), 'UTF-8') > 100)
  32. {
  33. $msg .= ' - ' . $lang->err_email2long . '<br />';
  34. }
  35. if ($msg == '')
  36. {
  37. $name = htmlspecialchars($_POST['name']);
  38. $email = htmlspecialchars($_POST['email']);
  39. $msg = $lang->added;
  40. $query = 'INSERT INTO `PREFIX_contact` (`name`, `email`) VALUES (?, ?)';
  41. $types = 'ss';
  42. $param_arr = array($name, $email);
  43. $db->PushData($query, $types, $param_arr);
  44. headerTo($info->modulSelf . '&status=added');
  45. }
  46. else
  47. {
  48. $msg = $lang->err . ':<br />' . $msg;
  49. $name = ($_POST['name']) ? $_POST['name'] : '';
  50. $email = ($_POST['email']) ? $_POST['email'] : '';
  51. }
  52. }
  53. $tpl = new Template('contact_new', $lang);
  54. $params = array(
  55. 'MSG' => $msg,
  56. 'NAME' => $name,
  57. 'EMAIL' => $email,
  58. 'THIS' => $info->modulSelf
  59. );
  60. $tpl->setParams($params);
  61. $tpl->printPart(0, true);
  62. }
  63. elseif (!is_null($info->modulParams('edit')))
  64. {
  65. user::hasRight('contact_edit') or headerTo($info->modulSelf . '&status=access_denied');
  66. $msg = '';
  67. $name = '';
  68. $email = '';
  69. if (isset($_POST['edit']))
  70. {
  71. if (trim($_POST['name']) === '')
  72. {
  73. $msg .= ' - ' . $lang->err_name . '<br />';
  74. }
  75. elseif (mb_strlen(trim($_POST['name']), 'UTF-8') > 70)
  76. {
  77. $msg .= ' - ' . $lang->err_name2long . '<br />';
  78. }
  79. if (trim($_POST['email']) === '' || !Text::is_email($_POST['email']))
  80. {
  81. $msg .= ' - ' . $lang->err_email . '<br />';
  82. }
  83. elseif (mb_strlen(trim($_POST['email']), 'UTF-8') > 100)
  84. {
  85. $msg .= ' - ' . $lang->err_email2long . '<br />';
  86. }
  87. if ($msg === '')
  88. {
  89. $name = htmlspecialchars($_POST['name']);
  90. $email = htmlspecialchars($_POST['email']);
  91. $query = 'UPDATE `PREFIX_contact` SET `name`=?,`email`=? WHERE `id`=? LIMIT 1';
  92. $types = 'ssi';
  93. $param_arr = array($name, $email, (int) $info->modulParams('edit'));
  94. $db->PushData($query, $types, $param_arr);
  95. headerTo($info->modulSelf . '&status=updated&page=' . (int) $info->modulParams('page'));
  96. }
  97. else
  98. {
  99. $msg = $lang->err . ':<br />' . $msg;
  100. $name = (trim($_POST['name']) !== '' ? trim($_POST['name']) : '');
  101. $email = (trim($_POST['email']) !== '' ? trim($_POST['email']) : '');
  102. }
  103. }
  104. $tpl = new Template('contact_edit', $lang);
  105. $query = 'SELECT `id`,`name`,`email` FROM `PREFIX_contact` WHERE `id`=' . (int) $info->modulParams('edit');
  106. $result = $db->getData($query);
  107. if ($db->affected_rows == 0)
  108. {
  109. headerTo($info->modulSelf);
  110. }
  111. $result = &$result[0];
  112. $params = array(
  113. 'PAGE' => (int) $info->modulParams('page'),
  114. 'MSG' => $msg,
  115. 'NAME' => ($msg ? $name : $result->name),
  116. 'EMAIL' => ($msg ? $email : $result->email),
  117. 'THIS' => $info->modulSelf,
  118. 'ID' => $result->id
  119. );
  120. $tpl->setParams($params);
  121. $tpl->printPart(0, true);
  122. }
  123. elseif (!is_null($info->modulParams('del')))
  124. {
  125. user::hasRight('contact_del') or headerTo($info->modulSelf . '&status=access_denied');
  126. if (isset($_POST['confirmation']))
  127. {
  128. if ($_POST['confirm'] == 'no')
  129. {
  130. headerTo($info->modulSelf);
  131. }
  132. elseif ($_POST['confirm'] == 'yes')
  133. {
  134. $query = 'DELETE FROM `PREFIX_contact` WHERE `id`=? LIMIT 1';
  135. $types = 'i';
  136. $param_arr = array(
  137. (int) $info->modulParams('del')
  138. );
  139. $db->PushData($query, $types, $param_arr);
  140. headerTo($info->modulSelf . '&status=deleted');
  141. }
  142. }
  143. $params = array(
  144. 'THIS' => $info->modulSelf . '&amp;del=' . $info->modulParams('del'),
  145. 'LEGEND' => $lang->sure2delete
  146. );
  147. $tpl = new Template('confirm', $lang);
  148. $tpl->setParams($params);
  149. $tpl->printPart(0, true);
  150. }
  151. elseif (!is_null($info->modulParams('delpage')))
  152. {
  153. user::hasRight('contact_del') or headerTo($info->modulSelf . '&status=access_denied');
  154. if (isset($_POST['confirmation']))
  155. {
  156. if ($_POST['confirm'] == 'no')
  157. {
  158. headerTo($info->modulSelf);
  159. }
  160. elseif ($_POST['confirm'] == 'yes')
  161. {
  162. $delindex = $info->modulParams('delpage');
  163. if ($delindex !== '0' && !is_numeric($delindex))
  164. {
  165. headerTo($info->modulSelf);
  166. }
  167. $query = 'SELECT `id` FROM `PREFIX_contact` ORDER BY `id` LIMIT ' . $delindex . ', ' . PAGELEN;
  168. $result = $db->getData($query);
  169. foreach ($result as $row)
  170. {
  171. $query = 'DELETE FROM `PREFIX_contact` WHERE `id`=' . $row->id . ' LIMIT 1';
  172. $db->PushData($query);
  173. }
  174. headerTo($info->modulSelf . '&status=deleted_page');
  175. }
  176. }
  177. $params = array(
  178. 'THIS' => $info->modulSelf . '&amp;delpage=' . $info->modulParams('delpage'),
  179. 'LEGEND' => $lang->sure2delete_page
  180. );
  181. $tpl = new Template('confirm', $lang);
  182. $tpl->setParams($params);
  183. $tpl->printPart(0, true);
  184. }
  185. elseif (!is_null($info->modulParams('delall')))
  186. {
  187. user::hasRight('contact_del') or headerTo($info->modulSelf . '&status=access_denied');
  188. if (isset($_POST['confirmation']))
  189. {
  190. if ($_POST['confirm'] == 'no')
  191. {
  192. headerTo($info->modulSelf);
  193. }
  194. elseif ($_POST['confirm'] == 'yes')
  195. {
  196. $query = 'DELETE FROM `PREFIX_contact`';
  197. $db->PushData($query);
  198. headerTo($info->modulSelf . '&status=deleted_all');
  199. }
  200. }
  201. $params = array(
  202. 'THIS' => $info->modulSelf . '&amp;delall=true',
  203. 'LEGEND' => $lang->sure2delete_all
  204. );
  205. $tpl = new Template('confirm', $lang);
  206. $tpl->setParams($params);
  207. $tpl->printPart(0, true);
  208. }
  209. else
  210. {
  211. $tpl = new Template('contact', $lang);
  212. $page = (int) $info->modulParams('page');
  213. $page = ($page > 0 ? $page : 1);
  214. $offset = ($page - 1) * PAGELEN;
  215. $params = array(
  216. 'THIS' => $info->modulSelf,
  217. 'MSG' => $info->statusMessage($lang),
  218. 'DELINDEX' => $offset
  219. );
  220. $tpl->setParams($params);
  221. $tpl->printPart(0, true);
  222. $query = 'SELECT * FROM `PREFIX_contact` ORDER BY `id` DESC LIMIT ' . $offset . ', ' . PAGELEN;
  223. $result = $db->GetData($query);
  224. $rows = $db->CountTable('contact');
  225. $pages_count = ceil($rows / PAGELEN);
  226. $pages_count = ($pages_count == 0 ? 1 : $pages_count);
  227. if ($result)
  228. {
  229. foreach ($result as $index => $row)
  230. {
  231. $fullName = $row->name;
  232. $fullEmail = $row->email;
  233. if (mb_strlen($fullName) > 20)
  234. {
  235. $row->name = mb_substr($row->name, 0, 20) . '...';
  236. }
  237. if (mb_strlen($fullEmail) > 20)
  238. {
  239. $row->email = mb_substr($row->email, 0, 30) . '...';
  240. }
  241. $params = array(
  242. 'PAGE' => (int) $info->modulParams('page'),
  243. 'NAME' => $row->name,
  244. 'FULLNAME' => $fullName,
  245. 'EMAIL' => $row->email,
  246. 'FULLEMAIL' => $fullEmail,
  247. 'ID' => $row->id,
  248. 'THIS' => $info->modulSelf,
  249. 'STYLE' => 'tablerow' . ($index % 2 == 0 ? '1' : '2')
  250. );
  251. $tpl->setParams($params);
  252. $tpl->printPart(1, true);
  253. }
  254. }
  255. $next_page = '&nbsp;';
  256. if ($page < $pages_count)
  257. {
  258. $next_page = '<a href="' . $info->modulSelf . '&amp;page=' . ($page + 1) . '">' . $lang->next_page . '</a>';
  259. }
  260. $prev_page = '&nbsp';
  261. if ($page > 1)
  262. {
  263. $prev_page = '<a href="' . $info->modulSelf . '&amp;page=' . ($page - 1) . '">' . $lang->prev_page . '</a>';
  264. }
  265. $params = array(
  266. 'PAGE-B' => $prev_page,
  267. 'PAGE-F' => $next_page,
  268. 'PAGE' => $page,
  269. 'PAGES-C' => $pages_count
  270. );
  271. $tpl->setParams($params);
  272. $tpl->printPart(2, true);
  273. }
  274. $design->printEnd();
  275. ?>