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

/www/admin/admin_snippets_edit.php

https://github.com/Sweil/Frogsystem-2
PHP | 326 lines | 241 code | 36 blank | 49 comment | 44 complexity | 8fca65e323c934895e057e8e0905d355 MD5 | raw file
  1. <?php if (!defined('ACP_GO')) die('Unauthorized access!');
  2. /////////////////////////////
  3. //// DB: Update Snippets ////
  4. /////////////////////////////
  5. if (
  6. isset ( $_POST['sended'] ) && $_POST['sended'] == 'edit'
  7. && isset ( $_POST['snippet_action'] ) && $_POST['snippet_action'] == 'edit'
  8. && isset ( $_POST['snippet_id'] )
  9. )
  10. {
  11. // Security-Functions
  12. settype ( $_POST['snippet_id'], 'integer' );
  13. settype ( $_POST['snippet_active'], 'integer' );
  14. // SQL-Queries
  15. $stmt = $FD->db()->conn()->prepare('
  16. UPDATE `'.$FD->env('DB_PREFIX')."snippets`
  17. SET
  18. `snippet_text` = ?,
  19. `snippet_active` = '".$_POST['snippet_active']."'
  20. WHERE `snippet_id` = '".$_POST['snippet_id']."'");
  21. $stmt->execute(array($_POST['snippet_text']));
  22. // Display Message
  23. systext ( $FD->text("admin", "changes_saved"),
  24. $FD->text("admin", "info"), FALSE, $FD->text("admin", "icon_save_ok") );
  25. // Unset Vars
  26. unset ( $_POST );
  27. }
  28. /////////////////////////////
  29. //// DB: Delete Snippets ////
  30. /////////////////////////////
  31. elseif (
  32. $_SESSION['snippets_delete']
  33. && isset ( $_POST['sended'] ) && $_POST['sended'] == 'delete'
  34. && isset ( $_POST['snippet_action'] ) && $_POST['snippet_action'] == 'delete'
  35. && isset ( $_POST['snippet_id'] )
  36. && isset ( $_POST['snippet_delete'] )
  37. )
  38. {
  39. if ( $_POST['snippet_delete'] == 1 ) {
  40. // Security-Functions
  41. $_POST['snippet_id'] = array_map ( 'intval', explode ( ',', $_POST['snippet_id'] ) );
  42. // SQL-Delete-Query
  43. $FD->db()->conn()->exec ('
  44. DELETE
  45. FROM `'.$FD->env('DB_PREFIX').'snippets`
  46. WHERE `snippet_id` IN ('.implode ( ',', $_POST['snippet_id'] ).')');
  47. systext ( $FD->text("admin", "snippets_deleted"),
  48. $FD->text("admin", "info"), FALSE, $FD->text("admin", "icon_trash_ok") );
  49. } else {
  50. systext ( $FD->text("admin", "snippets_not_deleted"),
  51. $FD->text("admin", "info"), FALSE, $FD->text("admin", "icon_trash_error") );
  52. }
  53. // Unset Vars
  54. unset ( $_POST );
  55. }
  56. ///////////////////////
  57. //// Display Forms ////
  58. ///////////////////////
  59. if ( isset ( $_POST['snippet_id'] ) && is_array ( $_POST['snippet_id'] ) && $_POST['snippet_action'] )
  60. {
  61. // Security Function
  62. $_POST['snippet_id'] = array_map ( 'intval', $_POST['snippet_id'] );
  63. ///////////////////////////
  64. //// Edit Snippet Form ////
  65. ///////////////////////////
  66. if ( $_POST['snippet_action'] == 'edit' && count ( $_POST['snippet_id'] ) == 1 )
  67. {
  68. $_POST['snippet_id'] = $_POST['snippet_id'][0];
  69. // Display Error Messages
  70. if ( isset($_POST['sended']) && ($_POST['sended'] == 'edit') ) {
  71. // Shouldn't happen
  72. // Get Data from DB
  73. } else {
  74. $index = $FD->db()->conn()->query ( '
  75. SELECT *
  76. FROM `'.$FD->env('DB_PREFIX')."snippets`
  77. WHERE `snippet_id` = '".$_POST['snippet_id']."'
  78. LIMIT 0,1" );
  79. $data_arr = $index->fetch(PDO::FETCH_ASSOC);
  80. putintopost ( $data_arr );
  81. }
  82. // Security Functions
  83. $_POST['snippet_tag'] = killhtml ( $_POST['snippet_tag'] );
  84. $_POST['snippet_text'] = killhtml ( $_POST['snippet_text'] );
  85. settype ( $_POST['snippet_id'], 'integer' );
  86. settype ( $_POST['snippet_active'], 'integer' );
  87. // Display Form
  88. echo '
  89. <form action="" method="post">
  90. <input type="hidden" name="go" value="snippets_edit">
  91. <input type="hidden" name="snippet_action" value="edit">
  92. <input type="hidden" name="sended" value="edit">
  93. <input type="hidden" name="snippet_id" value="'.$_POST['snippet_id'].'">
  94. <table class="configtable" cellpadding="4" cellspacing="0">
  95. <tr><td class="line" colspan="2">'.$FD->text("admin", "snippet_edit_title").'</td></tr>
  96. <tr>
  97. <td class="config" width="50%">
  98. '.$FD->text("admin", "snippet_tag_title").':<br>
  99. <span class="small">'.$FD->text("admin", "snippet_tag_desc").'</span>
  100. </td>
  101. <td class="config" width="50%">
  102. '.$_POST['snippet_tag'].'
  103. </td>
  104. </tr>
  105. <tr>
  106. <td class="config">
  107. '.$FD->text("admin", "snippet_active_title").':<br>
  108. <span class="small">'.$FD->text("admin", "snippet_active_desc").'</span>
  109. </td>
  110. <td class="config">
  111. <input class="pointer" type="checkbox" name="snippet_active" value="1" '.getchecked ( 1, $_POST['snippet_active'] ).'>
  112. </td>
  113. </tr>
  114. <tr>
  115. <td class="config">
  116. '.$FD->text("admin", "snippet_text_title").':<br>
  117. <span class="small">'.$FD->text("admin", "snippet_text_desc").'</span>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td class="config" colspan="2">
  122. <textarea style="width:100%;" name="snippet_text" rows="20" wrap="virtual">'.$_POST['snippet_text'].'</textarea>
  123. </td>
  124. </tr>
  125. <tr><td class="space"></td></tr>
  126. <tr>
  127. <td colspan="2" class="buttontd">
  128. <button class="button_new" type="submit">
  129. '.$FD->text("admin", "button_arrow").' '.$FD->text("admin", "save_changes_button").'
  130. </button>
  131. </td>
  132. </tr>
  133. </table>
  134. </form>
  135. ';
  136. }
  137. ///////////////////////////////////////////////////////////////
  138. //// Show too much selected Error & Go back to Select Form ////
  139. ///////////////////////////////////////////////////////////////
  140. elseif ( $_POST['snippet_action'] == 'edit' && count ( $_POST['snippet_id'] ) > 1 ) {
  141. // Display Error
  142. systext ( $FD->text("admin", "select_only_one_to_edit"),
  143. $FD->text("admin", "error"), TRUE, $FD->text("admin", "icon_error") );
  144. unset ( $_POST['snippet_id'] );
  145. }
  146. /////////////////////////////
  147. //// Delete Snippet Form ////
  148. /////////////////////////////
  149. elseif ( $_SESSION['snippets_delete'] && $_POST['snippet_action'] == 'delete' && count ( $_POST['snippet_id'] ) >= 1 )
  150. {
  151. // Display Head of Table
  152. echo '
  153. <form action="" method="post">
  154. <input type="hidden" name="go" value="snippets_edit">
  155. <input type="hidden" name="snippet_action" value="delete">
  156. <input type="hidden" name="sended" value="delete">
  157. <input type="hidden" name="snippet_id" value="'.implode ( ',', $_POST['snippet_id'] ).'">
  158. <table class="configtable" cellpadding="4" cellspacing="0">
  159. <tr><td class="line" colspan="2">'.$FD->text("admin", "snippets_delete_title").'</td></tr>
  160. <tr>
  161. <td class="configthin">
  162. '.$FD->text("admin", "snippets_delete_question").'
  163. <br><br>
  164. ';
  165. // get snippets from db
  166. $index = $FD->db()->conn()->query ( '
  167. SELECT COUNT(*)
  168. FROM `'.$FD->env('DB_PREFIX').'snippets`
  169. WHERE `snippet_id` IN ('.implode ( ',', $_POST['snippet_id'] ).')' );
  170. // snippets found
  171. if ( $index->fetchColumn() > 0 ) {
  172. // display snippets
  173. $index = $FD->db()->conn()->query ( '
  174. SELECT *
  175. FROM `'.$FD->env('DB_PREFIX').'snippets`
  176. WHERE `snippet_id` IN ('.implode ( ',', $_POST['snippet_id'] ).')
  177. ORDER BY `snippet_tag`' );
  178. while ( $data_arr = $index->fetch(PDO::FETCH_ASSOC) ) {
  179. // get other data
  180. $data_arr['active_text'] = ( $data_arr['snippet_active'] == 1 ) ? $FD->text("admin", "snippet_active") : $FD->text("admin", "snippet_not_active");
  181. echo '
  182. <b>'.killhtml ( $data_arr['snippet_tag'] ).'</b> ('.$data_arr['active_text'].')<br>
  183. ';
  184. }
  185. }
  186. // Display End of Table
  187. echo '
  188. </td>
  189. <td class="config right top" style="padding: 0px;">
  190. '.get_yesno_table ( 'snippet_delete' ).'
  191. </td>
  192. </tr>
  193. <tr><td class="space"></td></tr>
  194. <tr>
  195. <td class="buttontd" colspan="2">
  196. <button class="button_new" type="submit">
  197. '.$FD->text("admin", "button_arrow").' '.$FD->text("admin", "do_action_button_long").'
  198. </button>
  199. </td>
  200. </tr>
  201. </table>
  202. </form>
  203. ';
  204. }
  205. }
  206. /////////////////////////////
  207. //// Select Snippet Form ////
  208. /////////////////////////////
  209. if ( !isset ( $_POST['snippet_id'] ) )
  210. {
  211. // start display
  212. echo '
  213. <form action="" method="post">
  214. <input type="hidden" name="go" value="snippets_edit">
  215. <table class="configtable select_list" cellpadding="4" cellspacing="0">
  216. <tr><td class="line" colspan="3">'.$FD->text("admin", "snippet_select_title").'</td></tr>
  217. ';
  218. // get snippets from db
  219. $index = $FD->db()->conn()->query ( '
  220. SELECT COUNT(*)
  221. FROM `'.$FD->env('DB_PREFIX').'snippets`' );
  222. // snippets found
  223. if ( $index->fetchColumn() > 0 ) {
  224. // display table head
  225. echo '
  226. <tr>
  227. <td class="config">'.$FD->text("admin", "snippet_tag_title").'</td>
  228. <td class="config" width="20">&nbsp;&nbsp;'.$FD->text("admin", "active").'&nbsp;&nbsp;</td>
  229. <td class="config" width="20"></td>
  230. </tr>
  231. ';
  232. // display Snippets
  233. $index = $FD->db()->conn()->query ( '
  234. SELECT *
  235. FROM `'.$FD->env('DB_PREFIX').'snippets`
  236. ORDER BY `snippet_tag`' );
  237. while ( $data_arr = $index->fetch(PDO::FETCH_ASSOC) ) {
  238. // get other data
  239. $data_arr['active_text'] = ( $data_arr['snippet_active'] == 1 ) ? $FD->text("admin", "yes") : $FD->text("admin", "no");
  240. echo '
  241. <tr class="select_entry">
  242. <td class="configthin middle">'.killhtml ( $data_arr['snippet_tag'] ).'</td>
  243. <td class="configthin middle center">'.$data_arr['active_text'].'</td>
  244. <td class="config top center">
  245. <input class="pointer select_box" type="checkbox" name="snippet_id[]" value="'.$data_arr['snippet_id'].'">
  246. </td>
  247. </tr>
  248. ';
  249. }
  250. if (!isset($_POST['snippet_action']))
  251. $_POST['snippet_action'] = '';
  252. // display footer with button
  253. echo'
  254. <tr><td class="space"></td></tr>
  255. <tr>
  256. <td class="right" colspan="4">
  257. <select class="select_type" name="snippet_action" size="1">
  258. <option class="select_one" value="edit" '.getselected( 'edit', $_POST['snippet_action'] ).'>'.$FD->text("admin", "selection_edit").'</option>
  259. ';
  260. echo ( $_SESSION['snippets_delete'] ) ? '<option class="select_red" value="delete" '.getselected ( 'delete', $_POST['snippet_action'] ).'>'.$FD->text("admin", "selection_delete").'</option>' : '';
  261. echo'
  262. </select>
  263. </td>
  264. </tr>
  265. <tr><td class="space"></td></tr>
  266. <tr>
  267. <td class="buttontd" colspan="4">
  268. <button class="button_new" type="submit">
  269. '.$FD->text("admin", "button_arrow").' '.$FD->text("admin", "do_action_button_long").'
  270. </button>
  271. </td>
  272. </tr>
  273. ';
  274. // no Snippets found
  275. } else {
  276. echo'
  277. <tr><td class="space"></td></tr>
  278. <tr>
  279. <td class="config center" colspan="4">'.$FD->text("admin", "snippets_not_found").'</td>
  280. </tr>
  281. <tr><td class="space"></td></tr>
  282. ';
  283. }
  284. echo '
  285. </table>
  286. </form>
  287. ';
  288. }
  289. ?>