Просмотр файла admin/admin_style_edit.php

Размер файла: 6.99Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', true);
  7.  
  8. if( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. $module['General']['Управление стилями'] = $filename;
  12. return;
  13. }
  14.  
  15. $phpbb_root_path = '../';
  16. require($phpbb_root_path . 'extension.inc');
  17. require('pagestart.' . $phpEx);
  18.  
  19. $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : FALSE;
  20.  
  21. if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
  22. {
  23. $mode = ( isset($HTTP_GET_VARS['mode']) ) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
  24. $mode = htmlspecialchars($mode);
  25. }
  26. else
  27. {
  28. $mode = "";
  29. }
  30.  
  31. switch( $mode )
  32. {
  33. case "delete":
  34. $style_id = ( isset($HTTP_GET_VARS['style_id']) ) ? intval($HTTP_GET_VARS['style_id']) : intval($HTTP_POST_VARS['style_id']);
  35.  
  36. if( !$style_id )
  37. {
  38. message_die(GENERAL_MESSAGE, "Не выбран ни один стиль");
  39. }
  40. if( !$confirm )
  41. {
  42. if($style_id == $board_config['default_style'])
  43. {
  44. message_die(GENERAL_MESSAGE, $lang['Cannot_remove_style']);
  45. }
  46. $hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'" /><input type="hidden" name="style_id" value="'.$style_id.'" />';
  47.  
  48. $template->set_filenames(array(
  49. "confirm" => "admin/confirm_body.tpl")
  50. );
  51.  
  52. $template->assign_vars(array(
  53. "MESSAGE_TITLE" => $lang['Confirm'],
  54. "MESSAGE_TEXT" => $lang['Confirm_delete_style'],
  55.  
  56. "L_YES" => $lang['Yes'],
  57. "L_NO" => $lang['No'],
  58.  
  59. "S_CONFIRM_ACTION" => append_sid("admin_style_edit.$phpEx"),
  60. "S_HIDDEN_FIELDS" => $hidden_fields)
  61. );
  62.  
  63. $template->pparse("confirm");
  64.  
  65. }
  66. else
  67. {
  68. $sql = "DELETE FROM " . STYLES_CSS . "
  69. WHERE style_id = $style_id";
  70. if(!$result = $db->sql_query($sql, BEGIN_TRANSACTION))
  71. {
  72. message_die(GENERAL_ERROR, "Could not remove style data!", "", __LINE__, __FILE__, $sql);
  73. }
  74. $message = $lang['Style_removed'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_style_edit.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  75.  
  76. message_die(GENERAL_MESSAGE, $message);
  77. }
  78. break;
  79. case "edit":
  80. $style_id = ( isset($HTTP_GET_VARS['style_id']) ) ? intval($HTTP_GET_VARS['style_id']) : intval($HTTP_POST_VARS['style_id']);
  81.  
  82. if( !$confirm )
  83. {
  84. $sql = "SELECT *
  85. FROM " . STYLES_CSS . "
  86. WHERE style_id = $style_id";
  87. if(!$result = $db->sql_query($sql))
  88. {
  89. message_die(GENERAL_ERROR, "Could not get data from styles table", "", __LINE__, __FILE__, $sql);
  90. }
  91. $row = $db->sql_fetchrow($result);
  92.  
  93. $hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'" /><input type="hidden" name="style_id" value="'.$style_id.'" /><input type="hidden" name="confirm" value="yes" />';
  94.  
  95. $template->set_filenames(array(
  96. "body" => "admin/style_edit.tpl")
  97. );
  98.  
  99. $template->assign_vars(array(
  100. "S_PROFILE_ACTION" => append_sid('admin_style_edit.'.$phpEx),
  101. "STYLE_NAME" => $row['style_name'],
  102. "STYLE_TEXT" => $row['style_text'],
  103. "L_SUBMIT" => $lang['Submit'],
  104. "S_HIDDEN_FIELDS" => $hidden_fields)
  105. );
  106.  
  107. $template->pparse("body");
  108. include('./page_footer_admin.'.$phpEx);
  109.  
  110. }
  111. else
  112. {
  113.  
  114. if ( empty($HTTP_POST_VARS['style_text']) || empty($HTTP_POST_VARS['style_name']) )
  115. {
  116. $message = "Заполните все поля!<br /><br /><a href=\"" . append_sid("admin_style_edit.$phpEx?mode=edit&amp;style_id=$style_id") . "\">Попробовать ещё</a>";
  117. message_die(GENERAL_ERROR, $message);
  118. }
  119. $style_text = htmlspecialchars(trim($HTTP_POST_VARS['style_text']));
  120. $style_name = htmlspecialchars(trim($HTTP_POST_VARS['style_name']));
  121.  
  122. $sql = "UPDATE " . STYLES_CSS . "
  123. SET style_name = '" . str_replace("\'", "''", $style_name) . "', style_text = '" . str_replace("\'", "''", $style_text) . "'
  124. WHERE style_id = $style_id";
  125. if(!$result = $db->sql_query($sql))
  126. {
  127. message_die(GENERAL_ERROR, "Could not update style information", "", __LINE__, __FILE__, $sql);
  128. }
  129.  
  130. $message = 'Стиль изменён<br/>- <a href="index.php?pane=left">настройки системы</a>';
  131. message_die(GENERAL_MESSAGE, $message);
  132.  
  133. }
  134. break;
  135. case "setup":
  136. if( !$confirm )
  137. {
  138. message_die(GENERAL_MESSAGE, "Ошибка! Не введены данные стиля!");
  139. }
  140. else
  141. {
  142.  
  143. if ( empty($HTTP_POST_VARS['style_text']) || empty($HTTP_POST_VARS['style_name']) )
  144. {
  145. $message = "Заполните все поля!<br /><br /><a href=\"" . append_sid("admin_style_edit.$phpEx") . "\">Попробовать ещё</a>";
  146. message_die(GENERAL_ERROR, $message);
  147. }
  148.  
  149. $style_text = htmlspecialchars(trim($HTTP_POST_VARS['style_text']));
  150. $style_name = htmlspecialchars(trim($HTTP_POST_VARS['style_name']));
  151.  
  152. $sql = "INSERT INTO " . STYLES_CSS . " (style_name, style_text)
  153. VALUES ('" . str_replace("\'", "''", $style_name) . "', '" . str_replace("\'", "''", $style_text) . "')";
  154. if ( !($result = $db->sql_query($sql)) )
  155. {
  156. message_die(GENERAL_ERROR, 'Could not insert data into styles table', '', __LINE__, __FILE__, $sql);
  157. }
  158. $message = "Стиль \"".$style_name."\" успешно добавлен.<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=left") . "\">", "</a>");
  159. message_die(GENERAL_MESSAGE, $message);
  160.  
  161. }
  162. break;
  163. default:
  164. $sql = "SELECT style_id, style_name
  165. FROM " . STYLES_CSS . " ORDER BY style_id ASC";
  166. if(!$result = $db->sql_query($sql))
  167. {
  168. message_die(GENERAL_ERROR, "Could not get style information!", "", __LINE__, __FILE__, $sql);
  169. }
  170. $style_rowset = $db->sql_fetchrowset($result);
  171. $template->set_filenames(array(
  172. "body" => "admin/styles_list_body.tpl")
  173. );
  174.  
  175. $hidden_fields = '<input type="hidden" name="mode" value="setup" /><input type="hidden" name="confirm" value="yes" />';
  176.  
  177. $template->assign_vars(array(
  178. "S_PROFILE_ACTION" => append_sid('admin_style_edit.'.$phpEx),
  179. "L_SUBMIT" => $lang['Submit'],
  180. "S_HIDDEN_FIELDS" => $hidden_fields)
  181. );
  182.  
  183. for($i = 0; $i < count($style_rowset); $i++)
  184. {
  185. $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
  186. $s_id = $i+1;
  187.  
  188. $template->assign_block_vars("styles", array(
  189. "ROW_CLASS" => $row_class,
  190. "STYLE_NAME" => $style_rowset[$i]['style_name'],
  191. "STYLE_ID" => $s_id,
  192. "U_STYLE_EDIT" => append_sid("admin_style_edit.$phpEx?mode=edit&amp;style_id=" . $style_rowset[$i]['style_id']),
  193. "U_STYLE_DELETE" => append_sid("admin_style_edit.$phpEx?mode=delete&amp;style_id=" . $style_rowset[$i]['style_id']))
  194. );
  195. }
  196. $template->pparse("body");
  197. include('./page_footer_admin.'.$phpEx);
  198.  
  199. }
  200.  
  201. ?>