root/admin/admin_release_groups.php

Revision 317, 14.5 kB (checked in by Nafania, 2 years ago)

Изменена функция pager немного, для удобного построения LIMIT запросов.
Мелкие фиксы.
Обновлен jquery до последней версии.
Фикс ошибки, вызывающей sql ошибку Duplicate entry 'n' for key 'PRIMARY' occured in sql query UPDATE forum_search_results SET search_id = n, search_time = t, search_array = WHERE session_id = 'x', для этого апдейт базы.

Line 
1 <?php
2 /***************************************************************************</span>
3 <span class="code-comment">*                               admin_smilies.php
4 *                              -------------------
5 *     begin                : Thu May 31, 2001
6 *     copyright            : (C) 2001 The phpBB Group
7 *     email                : support@phpbb.com
8 *
9 *     $Id: admin_smilies.php,v 1.22.2.16 2005/10/30 15:17:13 acydburn Exp $
10 *
11 ****************************************************************************/
12
13 /***************************************************************************
14  *
15  *   This program is free software; you can redistribute it and/or modify
16  *   it under the terms of the GNU General Public License as published by
17  *   the Free Software Foundation; either version 2 of the License, or
18  *   (at your option) any later version.
19  *
20  ***************************************************************************/
21
22 /**************************************************************************
23 *        This file will be used for modifying the smiley settings for a board.
24 **************************************************************************/
25
26 //
27 // First we do the setmodules stuff for the admin cp.
28 //
29 if( !empty($setmodules) )</span>
30 <span class="code-keyword">{
31         $filename = basename(__FILE__);
32         $module['general']['release_groups'] = $filename;
33
34         return;
35 }
36
37 define('IN_PHPBB', 1);
38
39 $root_path = './../';</span>
40 <span class="code-lang">require($root_path . 'extension.inc');
41 require($root_path . 'include/functions_check.' . $phpEx);
42 require('./pagestart.' . $phpEx);
43 $cancel = ( isset($_POST['cancel']) ) ? true : false;
44 $no_page_header = $cancel;</span>
45 <span class="code-lang">
46 include($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_release_groups.' . $phpEx);
47 include($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_smilies_upload.' . $phpEx);
48
49 if ($cancel)
50 {
51         redirect('admin/' . append_sid("admin_release_groups.$phpEx"));
52 }
53
54 //</span>
55 <span class="code-comment">// Check to see what mode we should operate in.
56 //
57 if( isset($_POST['mode']) || isset($_GET['mode']) )</span>
58 <span class="code-keyword">{
59         $mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode'];
60         $mode = htmlspecialchars($mode);
61 }
62 else
63 {
64         $mode = "";
65 }
66
67 $delimeter  = '=+:';
68
69 //</span>
70 <span class="code-comment">// Read a listing of uploaded smilies for use in the add or edit smliey code...
71 //
72 $dir = @opendir($root_path . 'pic/groups/');</span>
73 <span class="code-lang">
74 while($file = @readdir($dir))
75 {
76         if( !@is_dir(phpbb_realpath($root_path . 'pic/groups/' . $file)) )
77         {
78                 $img_size = @getimagesize($root_path . 'pic/groups/' . $file);
79
80                 if( $img_size[0] && $img_size[1] )
81                 {
82                         $group_images[] = $file;
83                 }
84         }
85 }
86
87 @closedir($dir);
88
89
90 if( isset($_POST['add']) || isset($_GET['add']) )
91 {
92         //
93         // Admin has selected to add a smiley.
94         //
95
96         $template->set_filenames(array(
97                 "body" => "../admin/release_group_upload_body.tpl")
98         );
99
100         $ini_val = ( phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
101         $form_enctype = ( @$ini_val('file_uploads') == '0' || strtolower(@$ini_val('file_uploads') == 'off') || phpversion() == '4.0.4pl1' || ( phpversion() < '4.0.3' && @$ini_val('open_basedir') != '' ) ) ? '' : 'enctype="multipart/form-data"';
102
103         if( !empty($form_enctype) ) {
104             $template->assign_block_vars('switch_uploads', array());
105         }
106         else {
107             $template->assign_block_vars('switch_no_uploads', array(
108                      'L_SORRY' => $lang['su_sorry'] )
109             );
110         }
111
112         $s_hidden_fields = '<input type="hidden" name="mode" value="addnew" />';
113
114         $template->assign_vars(array(
115                 "S_FORM_ENCTYPE" => $form_enctype,
116                 'S_PROFILE_ACTION' => append_sid('admin_release_groups.' . $phpEx),
117                 'L_UPLOAD_FILE' => $lang['su_file'],
118                 'L_UPLOAD_NAME' => $lang['su_upload_name'],
119                 'L_DEFAULT_NAME' => $lang['su_default_name'],
120                 'L_NAME_EXPLAIN' => $lang['su_name_explain'],
121                 'L_UPLOADED_SMILIES' => $lang['su_uploaded'],
122                 'L_AUTO_ADD' => $lang['su_auto_add'],
123
124
125                 "S_SMILEY_ACTION" => append_sid("admin_release_groups.$phpEx"),
126                 "S_HIDDEN_FIELDS" => $s_hidden_fields)
127         );
128
129         $template->display("body");
130 }
131 else if ( $mode != "" )
132 {
133         switch( $mode )
134         {
135                 case 'delete':
136                         //
137                         // Admin has selected to delete a smiley.
138                         //
139
140                         $group_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id'];
141                         $group_id = intval($group_id);
142
143                         $confirm = isset($_POST['confirm']);
144
145                         if( $confirm )
146                         {
147                             $sql = "SELECT * FROM " . RELEASE_GROUPS_TABLE . " WHERE group_id = " . $group_id;
148                             $result = $db->sql_query($sql);
149                             $group_data = $db->sql_fetchrow($result);
150                                 @unlink($root_path . 'pic/groups/' . $group_data['pic_url']);
151                                 $sql = 'DELETE FROM ' . RELEASE_GROUPS_TABLE . ' WHERE group_id = ' . $group_id;
152                                 $db->sql_query($sql);
153                                 $numrows = $db->sql_affectedrows();
154                                 if( !$numrows ) {
155                                     trigger_error("Couldn't delete smiley");
156                                 }
157                                 else {
158                                     $message = $lang['release_groups_del_success'] . "<br /><br />" . sprintf($lang['click_return_release_groups'], "<a href=\"" . append_sid("admin_release_groups.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
159                                                 trigger_error($message);
160                                 }
161
162                         }
163                         else
164                         {
165                                 // Present the confirmation screen to the user
166                                 $template->set_filenames(array(
167                                         'body' => '../admin/confirm_body.tpl')
168                                 );
169
170                                 $hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $group_id . '" />';
171
172                                 $template->assign_vars(array(
173                                         'MESSAGE_TITLE' => $lang['confirm'],
174                                         'MESSAGE_TEXT' => $lang['confirm_delete_release_group'],
175
176                                         'S_CONFIRM_ACTION' => append_sid("admin_release_groups.$phpEx"),
177                                         'S_HIDDEN_FIELDS' => $hidden_fields)
178                                 );
179                                 $template->display('body');
180                         }
181                         return;
182                         break;
183
184                 case 'edit':
185
186                         $group_id = ( !empty($_POST['id']) ) ? intval($_POST['id']) : intval($_GET['id']);
187                         $group_edit_img = '';
188
189                         $sql = 'SELECT *
190                                 FROM ' . RELEASE_GROUPS_TABLE . '
191                                 WHERE group_id = ' . $group_id;
192                         $result = $db->sql_query($sql);
193                         $group_data = $db->sql_fetchrow($result);
194
195                         $filename_list = "";
196                         for( $i = 0; $i < sizeof($group_images); $i++ )
197                         {
198                                 if( $group_images[$i] == $group_data['pic_url'] )
199                                 {
200                                         $group_selected = "selected=\"selected\"";
201                                         $group_edit_img = $group_images[$i];
202                                 }
203                                 else
204                                 {
205                                         $group_selected = "";
206                                 }
207
208                                 $filename_list .= '<option value="' . $group_images[$i] . '"' . $group_selected . '>' . $group_images[$i] . '</option>';
209                         }
210
211                         $template->set_filenames(array(
212                                 "body" => "../admin/release_group_edit_body.tpl")
213                         );
214
215                         $s_hidden_fields = '<input type="hidden" name="mode" value="save" /><input type="hidden" name="group_id" value="' . $group_data['group_id'] . '" />';
216
217                         $template->assign_vars(array(
218                                 "GROUP_NAME" => $group_data['group_name'],
219
220                                 "GROUP_IMG" => $root_path . 'pic/groups/' . $group_edit_img,
221
222                                 "S_GROUP_ACTION" => append_sid("admin_release_groups.$phpEx"),
223                                 "S_HIDDEN_FIELDS" => $s_hidden_fields,
224                                 "S_FILENAME_OPTIONS" => $filename_list,
225                                 "S_GROUP_BASEDIR" =>  $root_path . 'pic/groups' )
226                         );
227
228                         $template->display("body");
229                         break;
230
231                 case "save":
232                         $group_name = ( isset($_POST['group_name']) ) ? trim($_POST['group_name']) : '';
233                         $pic_url = ( isset($_POST['pic_url']) ) ? trim($_POST['pic_url']) : '';
234                         $pic_url = phpbb_ltrim(basename($pic_url), "'");
235                         $group_id = ( isset($_POST['group_id']) ) ? intval($_POST['group_id']) : 0;
236                         $group_name = trim($group_name);
237                         $pic_url = trim($pic_url);
238
239                         // If no code was entered complain ...
240                         if ($group_name == '' || $pic_url == '')
241                         {
242                                 trigger_error($lang['fields_empty']);
243                                 return;
244                         }
245
246                         //
247                         // Convert < and > to proper htmlentities for parsing.
248                         //
249                         $group_name = str_replace('<', '&lt;', $group_name);
250                         $group_name = str_replace('>', '&gt;', $group_name);
251
252                         //
253                         // Proceed with updating the smiley table.
254                         //
255                         $sql = "UPDATE " . RELEASE_GROUPS_TABLE . "
256                                 SET group_name = '" . str_replace("\'", "''", $group_name) . "', pic_url = '" . str_replace("\'", "''", $pic_url) . "'
257                                 WHERE group_id = $group_id";
258                         $result = $db->sql_query($sql);
259
260                         $message = $lang['release_group_edit_success'] . "<br /><br />" . sprintf($lang['click_return_release_groups'], "<a href=\"" . append_sid("admin_release_groups.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
261
262                         trigger_error($message);
263                         return;
264                         break;
265                 case "addnew":
266
267                     $group_name = ( isset($_POST['group_name']) ? trim(htmlspecialchars($_POST['group_name'])) : '' );
268                     $group_name = str_replace(array('<', '>'), array('&lt;', '&gt;'), $group_name);
269
270                     if ( !$group_name ) {
271                         trigger_error($lang['su_cc_fail']);
272                     }
273
274                     $image_file = ( isset($_FILES['imagefile']) ? $_FILES['imagefile'] : '' );
275                     $uploaded_filename = check_upload_image($image_file, 'pic/groups/');
276                     $uploaded_filename = $uploaded_filename['filename'];
277
278                     $sql = 'SELECT COUNT(*) AS count FROM ' . RELEASE_GROUPS_TABLE . ' WHERE group_name = \'' . str_replace("\'", "''", $group_name) . '\'';
279                     $result = $db->sql_query($sql);
280                     $row = $db->sql_fetchrow($result);
281                     if( $row['count'] ) {
282                         trigger_error($lang['su_cc_found']);
283                     }
284
285                      $sql = "INSERT INTO " . RELEASE_GROUPS_TABLE . " (pic_url , group_name) VALUES ('" . str_replace("\'", "''", $uploaded_filename) . "', '" . str_replace("\'", "''", $group_name) . "')";
286
287                         $db->sql_query($sql);
288
289                     $message = $lang['release_group_add_success'] . "<br /><br />" . sprintf($lang['click_return_release_groups'], "<a href=\"" . append_sid("admin_release_groups.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
290                     trigger_error($message);
291                         return;
292
293                         break;
294         }
295 }
296 else
297 {
298
299         //
300         // This is the main display of the page before the admin has selected
301         // any options.
302         //
303         $sql = 'SELECT *
304                 FROM ' . RELEASE_GROUPS_TABLE . ' ORDER by group_name ASC';
305         $result = $db->sql_query($sql);
306
307         $groups = $db->sql_fetchrowset($result);
308
309         $template->set_filenames(array(
310                 "body" => "../admin/release_group_list_body.tpl")
311         );
312
313         $template->assign_vars(array(
314                 "S_SMILEY_ACTION" => append_sid("admin_release_groups.$phpEx"))
315         );
316
317         //
318         // Loop throuh the rows of smilies setting block vars for the template.
319         //
320         for($i = 0; $i < sizeof($groups); $i++)
321         {
322
323                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
324                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
325
326                 $template->assign_block_vars("groups", array(
327                         "ROW_COLOR" => "#" . $row_color,
328                         "ROW_CLASS" => $row_class,
329
330                         "GROUP_IMG" =>  $root_path . 'pic/groups/' . $groups[$i]['pic_url'],
331                         "GROUP_NAME" => $groups[$i]['group_name'],
332
333                         "U_GROUP_EDIT" => append_sid("admin_release_groups.$phpEx?mode=edit&amp;id=" . $groups[$i]['group_id']),
334                         "U_GROUP_DELETE" => append_sid("admin_release_groups.$phpEx?mode=delete&amp;id=" . $groups[$i]['group_id']))
335                 );
336         }
337
338         //
339         // Spit out the page.
340         //
341         $template->display("body");
342 }
343
344 //</span>
345 <span class="code-comment">// Page Footer
346 //
347 include('./page_footer_admin.'.$phpEx);
348
349 ?>
Note: See TracBrowser for help on using the browser.