root/admin/admin_categories.php

Revision 324, 41.2 kB (checked in by Nafania, 1 year ago)

Много мелких изменений. Если используется xbtt, то надо обязательно скачать новую версию на форуме.
Добавлен файл cron.php - если есть возможность, то пускайте cron таски через него. Особенно если используете массовую рассылку почты.

Line 
1 <?php
2
3 if( !empty($setmodules) )</span>
4 <span class="code-keyword">{
5         $file = basename(__FILE__);
6         $module['general']['tracker_categories'] = $file;
7         return;
8 }
9
10 define('IN_PHPBB', 1);
11
12 //</span>
13 <span class="code-comment">// Let's set the root dir for phpBB
14 //
15 $root_path = '../';</span>
16 <span class="code-lang">require($root_path . 'extension.inc');
17 require('./pagestart.' . $phpEx);
18 include($root_path . 'include/functions_check.'.$phpEx);
19 include($root_path . 'include/functions_selects.'.$phpEx);
20 include($root_path . 'include/functions_delete.'.$phpEx);
21
22 $mode = request_var('mode', '');
23
24 $cat_images_ary = array();</span>
25 <span class="code-lang">if( $dir = @opendir($root_path . 'pic/categories/') ) {
26     while( $file = @readdir($dir) ) {
27         if( is_file($root_path . 'pic/categories/' . $file) && !is_link($root_path . 'pic/categories/' .$file) && $file != "." && $file != ".." && preg_match('/\.(gif|jpg|jpeg|png|bmp)/', $file)  ) {
28             $cat_images_ary[] = $file;
29         }
30         }
31 }
32 else {
33        trigger_error($lang['cant_open_dir_with_cat_pics']);
34 }
35 sort($cat_images_ary);
36 $cat_images_ary_size = sizeof($cat_images_ary);
37
38 $dir_pics_warn = $dir_template_warn = '';</span>
39 <span class="code-lang">if ( !file_exists($root_path . 'pic/categories/') || !is_writable($root_path . 'pic/categories/') ) {
40     $dir_pics_warn = $lang['dir_with_cat_pics_not_writable'];
41 }
42
43 $templates_path = $root_path . 'templates/upload_templates/';</span>
44 <span class="code-lang">if ( !file_exists($templates_path) || !is_writable($templates_path) ) {
45     $dir_template_warn = $lang['dir_with_templates_not_writable'];
46 }
47
48 switch ( $mode ) {
49     case 'edit':
50         $cat_name = request_var('cat_name', array(0=>''));
51         $cat_image = request_var('cat_image', array(0=>''));
52         $allow_upload = request_var('allow_upload', array(0=>0));
53         $anonymous_view = request_var('anonymous_view', array(0=>0));
54         $torrent_limit = request_var('torrent_limit', array(0=>0));
55
56         foreach ( $cat_name AS $cat_id => $cat_new_name ) {
57             if ( !check_category_id($cat_id) ) {
58                 trigger_error(sprintf($lang['invalid_id'], $cat_id));
59             }
60             $allow_upload_val = ( isset($allow_upload[$cat_id]) ? 1 : 0 );
61             $anonymous_view_val = ( isset($anonymous_view[$cat_id]) ? 1 : 0 );
62             $torrent_limit_val = ( isset($torrent_limit[$cat_id]) ? $torrent_limit[$cat_id] : 0 );
63
64             $sql = 'UPDATE ' . CATEGORIES_TABLE . ' SET name = \'' . $db->sql_escape($cat_new_name) . '\', allow_upload = ' . $allow_upload_val . ', anonymous_view = ' . $anonymous_view_val . ', torrents_limit = ' . $torrent_limit_val . ' WHERE id = ' . $cat_id;
65             $db->sql_query($sql);
66         }
67
68         foreach ( $cat_image AS $cat_id => $cat_new_image ) {
69             $cat_new_image = ( in_array($cat_new_image, $cat_images_ary) ? $cat_new_image : '' );
70             $sql = 'UPDATE ' . CATEGORIES_TABLE . ' SET image = \'' . $db->sql_escape($cat_new_image) . '\' WHERE id = ' . $cat_id;
71             $db->sql_query($sql);
72         }
73
74         $cache->destroy('sql', CATEGORIES_TABLE);
75         $cache->destroy('_cats');
76
77         $message = $lang['categories_succefully_updated'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
78
79         trigger_error($message);
80     break;
81
82     case 'edit_template':
83         require ($root_path . 'include/bbcode/bbcode.lib.php');
84
85         $cats = $cache->obtain_cats();
86
87         $cat_id = request_var('cat_id', 0);
88         if ( !check_category_id($cat_id) ) {
89             trigger_error(sprintf($lang['invalid_id'], $cat_id));
90         }
91
92         if ( !file_exists($root_path . 'templates/upload_templates/' . $cat_id . '.html') || !is_writable($root_path . 'templates/upload_templates/' . $cat_id . '.html')  ) {
93             trigger_error($lang['file_not_exists_or_not_writable']);
94         }
95
96         $field_types_ary = array('input', 'select', 'textarea');
97         $template_file = file_get_contents($root_path . 'templates/upload_templates/' . $cat_id . '.html');
98
99         preg_match_all('/<!-- IF(.*?)>(.*?)<!-- ENDIF -->/si', $template_file, $tr_content);
100
101         preg_match('/d.descr.value( |)=( |)(.*?);/si', $template_file, $script_content);
102
103         preg_match('/var fields = new Array\((.*?)\);/si', $template_file, $fill_checked_ary);
104         $fill_checked_ary = ( isset($fill_checked_ary[1]) ? explode(', ', $fill_checked_ary[1]) : array() );
105
106         preg_match('/d.name.value = (.*?);/i', $template_file, $name_content);
107         $name_content = ( isset($name_content[1]) ? trim($name_content[1]) : '' );
108
109         $preview_view = ( isset($script_content[3]) ? trim($script_content[3]) : '' );
110
111         for ( $i = 0; $i < sizeof($tr_content[2]); ++$i ) {
112             preg_match_all('/<td(.*?)>(.*?)<\/td>/si', $tr_content[2][$i], $td_content);
113             for ( $j = 0; $j < sizeof($td_content[2]); $j = $j + 2 ) {
114                 $content = $td_content[2][$j+1];
115                 $name = $td_content[2][$j];
116                 $pos = strpos($content, '<br />');
117                 $note = ( $pos ? substr($content, $pos + 6) : '' );
118                 $content = ( $note ? str_replace($note, '', $content) : $content );
119                 $name = strip_tags($name);
120
121                 $tag_type = ( strstr($content, '<input') ? 'input' : ( strstr($content, '<select') ? 'select' : 'textarea' ) );
122
123                 switch ( $tag_type ) {
124                     case 'input':
125                         preg_match('/value="(.*?)"/', $content, $matches);
126                         $value = ( sizeof($matches) ? $matches[1] : '' );
127                     break;
128
129                     case 'textarea':
130                         preg_match('/>(.*?)<\//', $content, $matches);
131                         $value = ( sizeof($matches) ? $matches[1] : '' );
132                     break;
133
134                     case 'select':
135                         $content = preg_replace('/<(\/|)select(.*?)>/', '', $content);
136                         $len = strlen($content);
137                         if ( substr($content, 0,1) == '{' && substr($content, $len - 1, $len) == '}' ) {
138                             $value = $content;
139                         }
140                         else {
141                             preg_match_all('/<option value="(.*?)">(.*?)<\//', $content, $matches);
142                             $value = '';
143                             for ( $k = 0; $k < sizeof($matches[1]); ++$k ) {
144                                 $value2 = ( $matches[1][$k] <> $matches[2][$k] ? ' [' . trim($matches[2][$k]) . ']' : '' );
145                                 $value .= ( $value ? '; ' . $matches[1][$k] : $matches[1][$k] ) . $value2;
146                             }
147                         }
148                     break;
149                 }
150
151                 $field_types_select = '<select name="template_field_type[' .$i . ']">';
152
153                 foreach ( $field_types_ary AS $type ) {
154                     $field_types_select .= '<option value="' . $type . '"' . ( $type == $tag_type ? ' selected="selected" ' : '' ) . '>' . $type . '</option>';
155                 }
156
157                 $field_types_select .= '</select>';
158
159                 $fill_checked = ( isset($fill_checked_ary[$i]) ? intval($fill_checked_ary[$i]) : 0 );
160                 $fill_checked = ( $fill_checked ? 1 : 0 );
161
162                 $show_m_checked = $show_r_checked = $show_o_checked = '';
163                 $show_checked = array();
164
165                 //preg_match("/<!-- IF(.*?) -->/i", $tr_content[1][$i], $show_checked);
166                 //var_dump($tr_content[1][$i]);
167                 if ( $tr_content[1][$i] ) {
168                     $show_checked = $tr_content[1][$i];
169                     $show_m_checked = ( strpos($show_checked, 'main') ? ' checked="checked"' : '' );
170                     $show_r_checked = ( strpos($show_checked, 'request') ? ' checked="checked"' : '' );
171                     $show_o_checked = ( strpos($show_checked, 'offer') ? ' checked="checked"' : '' );
172                 }
173
174                 $template->assign_block_vars('template_row', array(
175                     'NAME' => htmlspecialchars($name),
176                     'VALUE' => $value,
177                     'NOTE' => htmlspecialchars($note),
178                     'FILL_CHECKED' => ( $fill_checked ? ' checked="checked"' : '' ),
179                     'ROW_COLOR' => ($i % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
180                     'COUNTER' => $i,
181                     'FIELD_TYPES_SELECT' => $field_types_select,
182                     'SHOW_M_CHECKED' => $show_m_checked,
183                     'SHOW_O_CHECKED' => $show_o_checked,
184                     'SHOW_R_CHECKED' => $show_r_checked,
185                 ));
186
187                 $find = array("( document.getElementById('u_t_" . $i . "') && return_field_val(document.getElementById('u_t_" . $i . "').value) != '' ? ", 'document.getElementById(\'u_t_' . $i . '\').value', 'document.getElementById(\'u_t_' . $i . '\').options[document.getElementById(\'u_t_' . $i . '\').selectedIndex].text', '( document.getElementById(\'u_t_' . $i . '\') ? ');
188                 $replace = array($name . '.start', $name . '.value', $name . '.value2', $name . '.start');
189                 $preview_view = str_replace($find, $replace, $preview_view);
190
191                 $preview_name = str_replace(array('/', '(', ')', '[', ']'), array('\/', '\(', '\)', '\[', '\]'), $name);
192
193                 $name_content = str_replace($find, $replace, $name_content);
194
195                 $preview_view = preg_replace('/(' . $preview_name . '.start(.*?)) : "" \)/si', '\\1' . $name . '.end', $preview_view, 1);
196
197                 $name_content = preg_replace('/(' . $preview_name . '.start(.*?)) : "" \)/si', '\\1' . $name . '.end', $name_content, 1);
198
199                 $pos_start = strpos($preview_view, $name . '.start');
200                 $pos_end = strpos($preview_view, $name . '.end');
201
202                 //ok, we have start && end tags for this string
203                 if ( $pos_start !== false && $pos_end !== false ) {
204                     $substr = substr($preview_view, $pos_start, $pos_end - $pos_start + strlen($name . '.end') );
205                     $pos = strpos($substr, '\n\\');
206
207                     if ( $pos === false ) {
208                         $preview_view = str_replace(array($name . '.start', $name . '.end'), '', $preview_view);
209                     }
210                 }
211
212             }
213         }
214         $find = array('\"', '"', ' + ', '\\' . "\n", '\n');
215         $replace = array('"', '', '', "\n", "");
216         $preview_view = str_replace($find, $replace, $preview_view);
217
218         $name_content = str_replace($find, $replace, $name_content);
219
220         $field_types_select = '';
221
222         foreach ( $field_types_ary AS $type ) {
223             $field_types_select .= '<option value="' . $type . '">' . $type . '</option>';
224         }
225         $field_types_select .= '</select>';
226
227         if ( $dir = opendir($root_path . 'templates/upload_templates/') ) {
228             $j = 0;
229             while ( ( $file = readdir($dir) ) !== false ) {
230                 ++$j;
231                 if ( strpos($file, $cat_id . '.html.') !== false ) {
232                     $time = str_replace($cat_id . '.html.', '', $file);
233                     $template->assign_block_vars('old_templates_row', array(
234                         'DATE' => create_date($time),
235                         'VIEW_LINK' => append_sid('admin_categories.php?mode=view_backup_template&amp;cat_id=' . $cat_id .'&amp;id=' . $time),
236                         'RESTORE_LINK' => append_sid('admin_categories.php?mode=restore_backup_template&amp;cat_id=' . $cat_id .'&amp;id=' . $time),
237                         'DELETE_LINK' => append_sid('admin_categories.php?mode=delete_backup_template&amp;cat_id=' . $cat_id .'&amp;id=' . $time),
238                         'ROW_COLOR' => ($j % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
239                     ));
240                 }
241             }
242         }
243         $cat_parent_name = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_name']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . ' -> ' : '' );
244
245         $template_edit_content = $preview_view;
246
247         $bb_code = new bbcode($preview_view);
248         $preview_view = $bb_code->get_html();
249
250         $template->assign_vars(array(
251                 'PREVIEW_VIEW' => $preview_view,
252                 'TEMPLATE_EDIT_CONTENT' => $template_edit_content,
253                 'CAT_ID' => $cat_id,
254                 'S_TRACKER_CATEGORY_EDITING' => sprintf($lang['tracker_category_editing'], $cat_parent_name . $cats[$cat_id]['cat_name']),
255                 'TEMPLATE_NAME_CREATOR_VALUE' => htmlspecialchars($name_content),
256                 'JS_COUNTER' => $i,
257                 'JS_TD_CLASS1' => $theme['td_class1'],
258                 'JS_TD_CLASS2' => $theme['td_class2'],
259                 'FIELD_TYPES_SELECT' => $field_types_select
260         ));
261
262         $template->set_filenames(array(
263                 'body' => '../admin/admin_categories_template_edit.html'
264         ));
265
266         $template->display('body');
267
268
269     break;
270
271     case 'save_template':
272             $cat_id = request_var('cat_id', 0);
273             $template_field_value = request_var('template_field_value', array(''=>''));
274             $template_field_name = request_var('template_field_name', array(''=>''));
275             $template_field_note = request_var('template_field_note', array(''=>''));
276             $template_field_type = request_var('template_field_type', array(''=>''));
277             $template_field_show = request_var('template_field_show', array(array(''=>'')));
278             $template_field_fill = request_var('template_field_fill', array(''=>''));
279             $template_edit_content = request_var('template_edit_content', '');
280             $template_name = request_var('template_name', '');
281
282             if ( !check_category_id($cat_id) ) {
283                 trigger_error(sprintf($lang['invalid_id'], $cat_id));
284             }
285             else {
286                 $fields = array();
287                 $find = array('"', "'", "\r\n", "\n");
288                 $replace = array('\"', "\'", '\n\\' . "\n", '\n\\' . "\n");
289                 $template_edit_content = str_replace($find, $replace, $template_edit_content);
290
291                 $fill_fields = "\n\tvar fields = new Array(";
292                 $fill_fields_ary = array();
293
294                 $fields_def_vals = "\n\tvar fields_def_vals = new Array(";
295                 $fields_def_vals_ary = array();
296
297                 foreach ( $template_field_name AS $key => $name ) {
298                     $show = ( isset($template_field_show[$key]) ? $template_field_show[$key] : array() );
299                     $value = ( isset($template_field_value[$key]) ? $template_field_value[$key] : '' );
300                     $note = ( isset($template_field_note[$key]) ? undo_htmlspecialchars($template_field_note[$key]) : '' );
301                     $type = ( isset($template_field_type[$key]) ? $template_field_type[$key] : '' );
302                     $fill = ( isset($template_field_fill[$key]) ? 1 : 0 );
303                     $fields[$template_field_name[$key]] = array('value' => $value, 'note' => $note, 'type' => $type, 'show' => $show, 'fill' => $fill );
304
305                     $fill_fields_ary[] = $fill;
306                     $fields_def_vals_ary[] = ( $type !== 'select' ? "'" . str_replace("'", "\'", $value) . "'" : "''" );
307                 }
308
309                 $fields_def_vals .= implode(', ', $fields_def_vals_ary);
310                 $fields_def_vals .= ');';
311
312                 $fill_fields .= implode(', ', $fill_fields_ary);
313                 $fill_fields .= ');';
314
315                 $new_template = "<script type=\"text/javascript\">\n\t<!--\n\tfunction CheckForm() {\n\td = document.form1;";
316                 $new_template .= "\n\tvar unfilled_fields = new Array();";
317                 $new_template .= "\n\tvar k = 0;";
318                 $new_template .= $fill_fields;
319                 $new_template .= $fields_def_vals;
320                 $new_template .= "\n\tfor (i = 0; i < fields.length; i++) {";
321                 $new_template .= "\n\t\tvar field_val = ( document.getElementById('u_t_' + i) ? document.getElementById('u_t_' + i).value : 'false' );";
322                 $new_template .= "\n\t\tfield_val = field_val.replace(/(^\s+)|(\s+$)/g, \"\");";
323                 $new_template .= "\n\t\tif ( ( !field_val || field_val == fields_def_vals[i] ) && fields[i] == 1 ) {";
324                 $new_template .= "\n\t\t\t++k;";
325                 $new_template .= "\n\t\t\tunfilled_fields[k] = document.getElementById('u_t_' + i + '_label').innerHTML;";
326                 $new_template .= "\n\t\t}";
327                 $new_template .= "\n\t}";
328                 $new_template .= "\n\tif ( unfilled_fields.length > 0 ) {";
329                 $new_template .= "\n\t\t" . 'alert(\'{L_JS_UNFILLED_FIELDS}:\' + unfilled_fields.join(\'\n\') );';
330                 $new_template .= "\n\t\treturn false;";
331                 $new_template .= "\n\t}";
332
333                 $new_template_add = '';;
334
335                 $i = 0;
336                 foreach ( $fields AS $name => $data_ary ) {
337                     $value = trim($data_ary['value']);
338                     $value = ( !empty($data_ary['value']) ? htmlspecialchars($data_ary['value']) : '' );
339                     switch ( $data_ary['type'] ) {
340                         case 'input':
341                             $size = 60;
342                             $tag = '<input type="text" name="' . $i . '" id="u_t_' . $i . '" value="' . $value . '" size="' . $size . '" />';
343                         break;
344
345                         case 'select':
346                             $tag = '<select name="' . $i . '" id="u_t_' . $i . '">';
347                             $select_values = ( strpos($value, ';') ? explode(';', $value) : ( trim($value) ? array($value) : array() ) );
348                             $find = array('[', ']');
349
350                             foreach ( $select_values AS $val ) {
351                                 $val = trim($val);
352                                 $len = strlen($val);
353                                 if ( substr($val, 0,1) == '{' && substr($val, $len - 1, $len) == '}' ) {
354                                     $tag .= $val;
355                                     continue;
356                                 }
357                                 $val2 = '';
358                                 preg_match('/\[(.*?)\]/', $val, $vals2);
359                                 if ( isset($vals2[1]) ) {
360                                     $val2 = trim($vals2[1]);
361                                 }
362                                 $val = str_replace('[' . $val2 . ']', '', $val);
363                                 $val = trim($val);
364                                 $val2 = ( $val2 ? $val2 : $val);
365                                 $tag .= '<option value="' . $val . '">' . $val2 . '</option>';
366                             }
367                             $tag .= '</select>';
368                         break;
369
370                         case 'textarea':
371                             $cols = 50;
372                             $rows = 10;
373                             $tag = '<textarea name="' . $i . '" id="u_t_' . $i . '" cols="' . $cols . '" rows="' . $rows . '">' . $value . '</textarea>';
374                         break;
375                     }
376                     $note = trim($data_ary['note']);
377                     $note = ( !empty($data_ary['note']) ? '<br />' . $data_ary['note'] : '' );
378
379                     $show = ( isset($data_ary['show']['M']) ? "TYPE == 'main'" : '' );
380                     $show .= ( isset($data_ary['show']['R']) ? ( $show ? ' || ' : '' ) . "TYPE == 'request'" : '' );
381                     $show .= ( isset($data_ary['show']['O']) ? ( $show ? ' || ' : '' ) . "TYPE == 'offer'" : '' );
382
383                     $show_fields = "\n<!-- IF ";
384                     $show_fields .= ( $show ? $show : "TYPE == ''" );
385                     $show_fields .= " -->\n";
386                     $fill = ( $data_ary['fill'] ? '' : " && return_field_val(document.getElementById('u_t_" . $i . "').value) != ''" );
387
388                     $pos_start = strpos($template_edit_content, $name . '.start');
389                     $pos_end = strpos($template_edit_content, $name . '.end');
390
391                     $find = array(
392                         $name . '.start',
393                         $name . '.end',
394                         $name . '.value2',
395                         $name . '.value'
396                     );
397                     $replace = array(
398                         '" + ( document.getElementById(\'u_t_' . $i . '\')' . $fill . ' ? "',
399                         '" : "" ) + "',
400                         '" + document.getElementById(\'u_t_' . $i . '\').options[document.getElementById(\'u_t_' . $i . '\').selectedIndex].text + "',
401                         '" + document.getElementById(\'u_t_' . $i . '\').value + "'
402                     );
403
404                     $template_name = str_replace($find, $replace, $template_name);
405                     $template_edit_content = str_replace($find, $replace, $template_edit_content);
406
407                     //ok, we have start && end tags for this string
408                     if ( $pos_start !== false && $pos_end !== false ) {
409                         $template_edit_content = str_replace($find, $replace, $template_edit_content);
410                     }
411                     else {
412                         $repl_name = str_replace(array('/', '"', '(', ')', '[', ']'), array('\/', '\"', '\(', '\)', '\[', '\]'), $name);
413                         //$template_edit_content = preg_replace("/(\"|)(.*?" . $repl_name  . ".value.*?)(\\\\\n|$)/i", '" + ( document.getElementById(\'u_t_' . $i . '\')' . $fill . ' ? "\\2" : "" ) + "' . "\\3", $template_edit_content);
414                         $template_edit_content = preg_replace("/(\"|)(.*?getElementById\('u_t_" . $i . "'\).*?)(\\\\\n|$)/i", '" + ( document.getElementById(\'u_t_' . $i . '\')' . $fill . ' ? "\\2" : "" ) + "' . "\\3", $template_edit_content);
415                     }
416
417                     $new_template_add .= $show_fields . "<tr id=\"u_t_" . $i  . "_tr\">\n\t<td><label id=\"u_t_" . $i  . "_label\" for=\"u_t_" . $i  . '">' . $name . "</label></td>\n\t<td>" . $tag . $note . "</td>\n</tr>\n<!-- ENDIF -->";
418
419                     ++$i;
420                 }
421
422                 $template_edit_content = '"' . str_replace( array('? " + document', ' ? " + ( document'), array('? document', ' ? ( document'), $template_edit_content );
423                 $new_template .= "\n\td.descr.value = " . $template_edit_content . '";';
424                 $new_template .= "\n\td.name.value = \"" . $template_name . '";';
425                 $new_template .= "\n\treturn true;\n}\n//-->\n</script>";
426                 $new_template .= $new_template_add;
427
428                 //we try to backup original template and delete old backups
429                 if ( $dir = opendir($root_path . 'templates/upload_templates/') ) {
430                     while ( ( $file = readdir($dir) ) !== false ) {
431                         if ( strpos($file, $cat_id . '.html.') !== false ) {
432                             $time = str_replace($cat_id . '.html.', '', $file);
433                             if ( $time < time() - 7 * 24 * 60 * 60 ) {
434                                 @unlink($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $time);
435                             }
436                         }
437                     }
438                 }
439                 @copy($root_path . 'templates/upload_templates/' . $cat_id . '.html', $root_path . 'templates/upload_templates/' . $cat_id . '.html.' . time());
440
441                 if ( $fp = @fopen($root_path . 'templates/upload_templates/' . $cat_id . '.html', 'wb') ) {
442                     fwrite($fp, $new_template);
443                     fclose($fp);
444                     @chmod($root_path . 'templates/upload_templates/' . $cat_id . '.html', 0777);
445                 }
446                 else {
447                     trigger_error($lang['file_not_exists_or_not_writable']);
448                 }
449                 $message = $lang['template_succefully_updated'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
450                 trigger_error($message);
451         }
452         break;
453
454         case 'delete':
455             $confirm = isset($_POST['confirm']);
456             $cancel = isset($_POST['cancel']);
457             $cats = $cache->obtain_cats();
458             if ( $confirm ) {
459                 $move_cat_id = request_var('category', 0);
460                 $cat_id = request_var('id', 0);
461
462                 if ( !isset($_POST['move_torrents']) ) {
463                     $sql = 'SELECT fid, info_hash FROM ' . TORRENTS_TABLE . ' WHERE category = ' . $cat_id;
464                     $result = $db->sql_query($sql);
465                     $ids = array();
466                     while ( $row = $db->sql_fetchrow($result) ) {
467                         $ids[$row['info_hash']] = $row['fid'];
468                     }
469                     deletetorrent($ids);
470                 }
471                 else {
472                     if ( !check_category_id( $move_cat_id ) || $move_cat_id == $cat_id ) {
473                         trigger_error( sprintf( $lang['invalid_id'], $move_cat_id ) );
474                     }
475                     else {
476                         $sql = 'UPDATE ' . TORRENTS_TABLE . ' SET category = ' . $move_cat_id . ' WHERE category = ' . $cat_id;
477                         $db->sql_query($sql);
478                     }
479                 }
480
481                 if ( !isset($_POST['move_subcats']) ) {
482                     $sql = 'DELETE FROM ' . CATEGORIES_TABLE . ' WHERE cat_parent_id = ' . $cat_id;
483                     $db->sql_query($sql);
484                 }
485                 else {
486                     if ( !check_category_id( $move_cat_id ) || $move_cat_id == $cat_id ) {
487                         trigger_error( sprintf( $lang['invalid_id'], $move_cat_id ) );
488                     }
489                     else {
490                         $sql = 'UPDATE ' . CATEGORIES_TABLE . ' SET cat_parent_id = ' . $move_cat_id . ' WHERE cat_parent_id = ' . $cat_id;
491                         $db->sql_query($sql);
492                     }
493                 }
494
495                     $sql = 'DELETE FROM ' . CATEGORIES_TABLE . ' WHERE id = ' . $cat_id;
496                     $db->sql_query($sql);
497
498                     @unlink($root_path . 'templates/upload_templates/' . $cat_id . '.html');
499                 @unlink($root_path . 'templates/upload_templates/' . $cat_id . '.html.old');
500
501                     $cache->destroy('sql', CATEGORIES_TABLE);
502                     $cache->destroy('_cats');
503
504                     $message = $lang['category_sucefully_deleted'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
505                     trigger_error($message);
506              }
507              elseif ( !$cancel ) {
508                 $cat_id = request_var('cat_id', 0);
509
510                 if ( !check_category_id( $cat_id ) ) {
511                     trigger_error( sprintf( $lang['invalid_id'], $cat_id ) );
512                 }
513                     $template->set_filenames(array(
514                       'body' => '../admin/confirm_body.tpl')
515                   );
516
517                 $hidden_fields = '<input type="hidden" name="action" value="delete" /><input type="hidden" name="id" value="' . $cat_id . '" />';
518
519                 $cat_select = categories_select('-', 'category', true, true);
520
521                 $cat_parent_name = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_name']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . ' -> ' : '' );
522
523                 $message_text = $lang['choose_category_to_move'] . '<br /><br />' . sprintf($lang['move_torrents_to_cat'], '<input type="checkbox" name="move_torrents" checked="checked" />', '<input type="checkbox" name="move_subcats" checked="checked" />') . ' ' . $cat_select . '<br /><br />' . sprintf($lang['confirm_delete_category'], $cat_parent_name . $cats[$cat_id]['cat_name']);
524
525                   $template->assign_vars(array(
526                       'MESSAGE_TITLE' => $lang['confirm'],
527                        'MESSAGE_TEXT' => $message_text,
528
529                        'S_CONFIRM_ACTION' => append_sid("admin_categories.$phpEx?mode=delete"),
530                        'S_HIDDEN_FIELDS' => $hidden_fields)
531                   );
532                   $template->display('body');
533                   include('./page_footer_admin.'.$phpEx);
534              }
535         break;
536
537         case 'add_new_cat':
538             if ( isset($_POST['submit']) ) {
539                 if ( $dir_template_warn ) {
540                     trigger_error($dir_template_warn);
541                 }
542                 $cat_picture = request_var('cat_picture', '');
543                 $cat_name = request_var('cat_name', '');
544                 $cat_parent = request_var('cat_parent', 0);
545                 $template_from = request_var('template_from', 0);
546                 $allow_upload = request_var('allow_upload', 0);
547                 $anonymous_view = request_var('anonymous_view', 0);
548                 $torrents_limit = request_var('torrents_limit', 0);
549
550                 if ( $cat_parent ) {
551                     if ( !check_category_id( $cat_parent ) ) {
552                         trigger_error( sprintf( $lang['invalid_id'], $cat_parent ) );
553                     }
554                 }
555
556                 if ( $template_from ) {
557                     if ( !check_category_id( $template_from ) ) {
558                         trigger_error( sprintf( $lang['invalid_id'], $template_from ) );
559                     }
560                 }
561
562                 if ( !$cat_picture ) {
563                     $image_file = ( isset($_FILES['imagefile']) ? $_FILES['imagefile'] : '' );
564                     $uploaded_filename = check_upload_image($image_file, 'pic/categories/');
565                     $cat_picture = $uploaded_filename['filename'];
566                 }
567
568                 if ( !$cat_name ) {
569                     trigger_error('please_enter_category_name');
570                 }
571
572                 $insert_ary = array(
573                     'name' => $cat_name,
574                     'image' => $cat_picture,
575                     'cat_parent_id' => $cat_parent,
576                     'allow_upload' => $allow_upload,
577                     'anonymous_view' => $anonymous_view,
578                     'torrents_limit' => $torrents_limit
579                 );
580
581                 $sql = 'INSERT INTO ' . CATEGORIES_TABLE . ' ' . $db->sql_build_array('INSERT', $insert_ary);
582                 $db->sql_query($sql);
583
584                 $id = $db->sql_nextid();
585
586                 if ( $template_from ) {
587                     if ( !copy($templates_path . "$template_from.html", $templates_path . "$id.html") ) {
588                         trigger_error('cant_copy_template_file');
589                     }
590                 }
591                 else {
592
593                     if ($fp = @fopen($templates_path . "$id.html", 'wb'))
594                     {
595                         $template_code = "<script type=\"text/javascript\">\n\tfunction CheckForm() {\n\t\td = document.form1;\n\t\td.descr.value = d.descr2.value;\n\t}\n</script>\n<tr>\n\t<td valign=\"top\">{L_DESCRIPTION}</td>\n\t<td><textarea id=\"descr2\" cols=\"50\" rows=\"10\"></textarea></td>\n</tr>";
596                         @flock($fp, LOCK_EX);
597                         fwrite($fp, $template_code);
598                         @flock($fp, LOCK_UN);
599                         fclose($fp);
600
601                         @chmod($templates_path . "$id.html", 0777);
602                     }
603                     else {
604                         $sql = 'DELETE FROM ' . CATEGORIES_TABLE . ' WHERE id = ' . $id;
605                         $db->sql_query($sql);
606                         trigger_error('cant_create_template_file');
607                     }
608                 }
609                 $cache->destroy('sql', CATEGORIES_TABLE);
610                 $cache->destroy('_cats');
611
612                 $message = $lang['category_added_sucefully'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
613                 trigger_error($message);
614                    return;
615             }
616             else {
617                 if ( $dir_template_warn ) {
618                     trigger_error($dir_template_warn);
619                 }
620                 $s_cat_images_select = '<option value="0">(' . $lang['none'] . ')</option>';
621                 for ( $j = 0; $j < $cat_images_ary_size; ++$j ) {
622                     $s_cat_images_select .= '<option>' . $cat_images_ary[$j] . '</option>';
623                 }
624
625                 $cats = $cache->obtain_cats();
626                 $cat_parent_options = '';
627                 foreach ( $cats AS $cat_id => $cats_ary ) {
628                     if ( $cats_ary['cat_parent'] ) {
629                         continue;
630                     }
631                     $cat_parent_options .= '<option value="' . $cat_id . '">' . $cats_ary['cat_name'] . '</option>';
632                 }
633
634                 $ini_val = ( phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
635                 $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"';
636
637                 $template->assign_vars(array(
638                     'DIR_PICS_WARN' => ( $dir_pics_warn ? '<span style="color:red;font-weight:bold;">' . $dir_pics_warn . '</span>' : '' ),
639                     'S_CAT_IMAGE_SELECT' => $s_cat_images_select,
640                     'S_FORM_ACTION' => append_sid('admin_categories.php?mode=add_new_cat'),
641                     'S_FORM_ENCTYPE' => $form_enctype,
642                     'CAT_PARENT_OPTIONS' => $cat_parent_options
643
644                 ));
645
646                 $template->set_filenames(array(
647                     'body' => '../admin/admin_categories_add_new_cat.html')
648                  );
649
650                 $template->display('body');
651             }
652         break;
653
654         case 'view_backup_template':
655             $no_page_header = true;
656
657             require ($root_path . 'include/bbcode/bbcode.lib.php');
658
659             $cat_id = request_var('cat_id', 0);
660             $id = request_var('id', 0);
661             if ( !check_category_id($cat_id) ) {
662                     trigger_error(sprintf($lang['invalid_id'], $cat_id));
663             }
664
665             if ( !file_exists($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id)  ) {
666                     trigger_error($lang['file_not_exists_or_not_writable']);
667             }
668             $field_types_ary = array('input', 'select', 'textarea');
669             $template_file = file_get_contents($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id);
670             $template_file = preg_replace('#\{L_([a-z0-9\-_]*)\}#ise', "isset(\$lang[utf_strtolower('\\1')]) ? \$lang[utf_strtolower('\\1')] : '{ ' . ucfirst(utf_strtolower(str_replace('_', ' ', '\\1'))) . ' }'", $template_file );
671             preg_match_all('/<tr(.*?)>(.*?)<\/tr>/si', $template_file, $tr_content);
672
673             preg_match('/d.descr.value( |)=( |)(.*?);/si', $template_file, $script_content);
674             $preview_view = ( isset($script_content[3]) ? trim($script_content[3]) : '' );
675
676             preg_match('/d.name.value = (.*?);/i', $template_file, $name_content);
677             $name_content = ( isset($name_content[1]) ? trim($name_content[1]) : '' );
678
679             for ( $i = 0; $i < sizeof($tr_content[2]); ++$i ) {
680                 preg_match_all('/<td(.*?)>(.*?)<\/td>/si', $tr_content[2][$i], $td_content);
681                 for ( $j = 0; $j < sizeof($td_content[2]); $j = $j + 2 ) {
682                     $content = $td_content[2][$j+1];
683                     $name = $td_content[2][$j];
684                     $pos = strpos($content, '<br />');
685                     $note = ( $pos ? substr($content, $pos + 6) : '' );
686                     $content = ( $note ? str_replace($note, '', $content) : $content );
687                     $name = strip_tags($name);
688
689                     $tag_type = ( strstr($content, '<input') ? 'input' : ( strstr($content, '<select') ? 'select' : 'textarea' ) );
690
691                     switch ( $tag_type ) {
692                         case 'input':
693                             preg_match('/value="(.*?)"/', $content, $matches);
694                             $value = ( sizeof($matches) ? $matches[1] : '' );
695                         break;
696
697                         case 'textarea':
698                             preg_match('/>(.*?)<\//', $content, $matches);
699                             $value = ( sizeof($matches) ? $matches[1] : '' );
700                         break;
701
702                         case 'select':
703                             preg_match_all('/<option value="(.*?)">(.*?)<\//', $content, $matches);
704                             $value = '';
705                             for ( $k = 0; $k < sizeof($matches[1]); ++$k ) {
706                                 $value2 = ( $matches[1][$k] <> $matches[2][$k] ? ' {' . trim($matches[2][$k]) . '}' : '' );
707                                 $value .= ( $value ? '; ' . $matches[1][$k] : $matches[1][$k] ) . $value2;
708                             }
709                         break;
710                     }
711
712                     $template->assign_block_vars('template_row', array(
713                         'NAME' => htmlspecialchars($name),
714                         'VALUE' => htmlspecialchars($value),
715                         'NOTE' => htmlspecialchars($note),
716                         'ROW_COLOR' => ($i % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
717                         'TAG_TYPE' => $tag_type
718                     ));
719
720                     $find = array("( document.getElementById('u_t_" . $i . "') && return_field_val(document.getElementById('u_t_" . $i . "').value) != '' ?", 'document.getElementById(\'u_t_' . $i . '\').value', 'document.getElementById(\'u_t_' . $i . '\').options[document.getElementById(\'u_t_' . $i . '\').selectedIndex].text', '( document.getElementById(\'u_t_' . $i . '\') ? ');
721                     $replace = array($name . '.start', $name . '.value', $name . '.value2', $name . '.start');
722                     $preview_view = str_replace($find, $replace, $preview_view);
723                     $preview_name = str_replace(array('/', '(', ')', '[', ']'), array('\/', '\(', '\)', '\[', '\]'), $name);
724
725                     $name_content = str_replace($find, $replace, $name_content);
726
727                     $preview_view = preg_replace('/(' . $preview_name . '.start(.*?)) : "" \)/si', '\\1' . $name . '.end', $preview_view, 1);
728
729                     $pos_start = strpos($preview_view, $name . '.start');
730                     $pos_end = strpos($preview_view, $name . '.end');
731
732                     //ok, we have start && end tags for this string
733                     if ( $pos_start !== false && $pos_end !== false ) {
734                         $substr = substr($preview_view, $pos_start, $pos_end - $pos_start + strlen($name . '.end') );
735                         $pos = strpos($substr, '\n\\');
736                         if ( !$pos ) {
737                             $preview_view = str_replace(array($name . '.start', $name . '.end'), '', $preview_view);
738                         }
739                     }
740
741                 }
742             }
743             $find = array('\"', '"', ' + ', '\\' . "\n", '\n');
744             $replace = array('"', '', '', "\n", "");
745             $preview_view = str_replace($find, $replace, trim($preview_view));
746
747             $name_content = str_replace($find, $replace, trim($name_content));
748
749             $bb_code = new bbcode($preview_view);
750             $preview_view = $bb_code->get_html();
751
752             $template->assign_vars(array(
753                     'PREVIEW_VIEW' => $preview_view,
754                     'TEMPLATE_EDIT_CONTENT' => $preview_view,
755                     'TEMPLATE_NAME_CREATOR_VALUE' => $name_content
756             ));
757
758             $template->set_filenames(array(
759                 'body' => '../admin/admin_categories_view_backup_template.html')
760             );
761
762             $template->display('body');
763         break;
764
765         case 'restore_backup_template':
766             $confirm = isset($_POST['confirm']);
767             $cancel = isset($_POST['cancel']);
768             $cat_id = request_var('cat_id', 0);
769             $id = request_var('id', 0);
770
771             if ( !check_category_id( $cat_id ) ) {
772                 trigger_error( sprintf( $lang['invalid_id'], $cat_id ) );
773             }
774             if ( $confirm ) {
775                 if ( !file_exists($root_path . 'templates/upload_templates/' . $cat_id . '.html')  ) {
776                     trigger_error($lang['file_not_exists_or_not_writable']);
777                 }
778                 if ( !file_exists($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id)  ) {
779                     trigger_error($lang['file_not_exists_or_not_writable']);
780                 }
781                 @unlink($root_path . 'templates/upload_templates/' . $cat_id . '.html');
782                 @rename($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id, $root_path . 'templates/upload_templates/' . $cat_id . '.html');
783
784                 $message = $lang['template_backup_succefully_restored'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
785
786                 trigger_error($message);
787
788             }
789             elseif ( $cancel ) {
790                 $message = $lang['template_backup_restore_canceled'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
791
792                 trigger_error($message);
793             }
794             else {
795                  $template->set_filenames(array(
796                      'body' => '../admin/confirm_body.tpl')
797                  );
798
799                 $hidden_fields = '<input type="hidden" name="mode" value="restore_backup_template" /><input type="hidden" name="cat_id" value="' . $cat_id . '" /><input type="hidden" name="id" value="' . $id . '" />';
800
801                   $template->assign_vars(array(
802                       'MESSAGE_TITLE' => $lang['confirm'],
803                        'MESSAGE_TEXT' => $lang['are_you_sure_restore_backup'],
804                        'S_CONFIRM_ACTION' => append_sid("admin_categories.$phpEx"),
805                        'S_HIDDEN_FIELDS' => $hidden_fields)
806                   );
807                   $template->display('body');
808                   include('./page_footer_admin.'.$phpEx);
809             }
810         break;
811
812         case 'delete_backup_template':
813             $confirm = isset($_POST['confirm']);
814             $cancel = isset($_POST['cancel']);
815             $cat_id = request_var('cat_id', 0);
816             $id = request_var('id', 0);
817
818             if ( !check_category_id( $cat_id ) ) {
819                 trigger_error( sprintf( $lang['invalid_id'], $cat_id ) );
820             }
821             if ( $confirm ) {
822                 if ( !file_exists($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id)  ) {
823                     trigger_error($lang['file_not_exists_or_not_writable']);
824                 }
825                 @unlink($root_path . 'templates/upload_templates/' . $cat_id . '.html.' . $id);
826
827                 $message = $lang['template_backup_succefully_deleted'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
828
829                 trigger_error($message);
830
831             }
832             elseif ( $cancel ) {
833                 $message = $lang['template_backup_delete_canceled'] . "<br /><br />" . sprintf($lang['click_return_categories_admin'], "<a href=\"" . append_sid("admin_categories.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
834
835                 trigger_error($message);
836             }
837             else {
838                  $template->set_filenames(array(
839                      'body' => '../admin/confirm_body.tpl')
840                  );
841
842                 $hidden_fields = '<input type="hidden" name="mode" value="delete_backup_template" /><input type="hidden" name="cat_id" value="' . $cat_id . '" /><input type="hidden" name="id" value="' . $id . '" />';
843
844                   $template->assign_vars(array(
845                       'MESSAGE_TITLE' => $lang['confirm'],
846                        'MESSAGE_TEXT' => $lang['are_you_sure_delete_backup'],
847                        'S_CONFIRM_ACTION' => append_sid("admin_categories.$phpEx"),
848                        'S_HIDDEN_FIELDS' => $hidden_fields)
849                   );
850                   $template->display('body');
851                   include('./page_footer_admin.'.$phpEx);
852             }
853         break;
854
855         default:
856
857             $template->assign_vars(array(
858                 'U_ADD_NEW_CATEGORY' => append_sid('admin_categories.php?mode=add_new_cat'),
859                 'S_FORM_ACTION' => append_sid('admin_categories.php')
860             ));
861
862             $cats = array();
863
864             $sql = 'SELECT * FROM ' . CATEGORIES_TABLE . ' ORDER BY cat_parent_id';
865             $result = $db->sql_query($sql);
866
867             while( $row = $db->sql_fetchrow($result) ){
868                 $parent_cat_id = ( $row['cat_parent_id'] ? $row['cat_parent_id'] : $row['id'] );
869                 $cats[$parent_cat_id][$row['id']] = $row;
870             } // while
871
872             $i = 0;
873
874             foreach ( $cats AS $cat_id => $ary ) {
875                 $row = $ary[$cat_id];
876                 $count = sizeof($ary) - 1;
877
878                 $s_cat_images_options = '';
879                 for ( $j = 0; $j < $cat_images_ary_size; ++$j ) {
880                     $s_cat_images_options .= '<option' . ( $cat_images_ary[$j] == $row['image'] ? ' selected="selected"' : '' ) . '>' . $cat_images_ary[$j] . '</option>';
881                 }
882
883                 $template->assign_block_vars('catrow', array(
884                     'CAT_ID' => $row['id'],
885                     'CAT_IMAGE' => ( !empty($row['image']) ? $row['image'] : '' ),
886                     'CAT_NAME' => $row['name'],
887                     'U_DELETE' => append_sid('admin_categories.php?mode=delete&amp;cat_id=' . $row['id']),
888                     'U_EDIT' => append_sid('admin_categories.php?mode=edit&amp;cat_id=' . $row['id']),
889                     'U_EDIT_TEMPLATE' => append_sid('admin_categories.php?mode=edit_template&amp;cat_id=' . $row['id']),
890                     'ROW_COLOR' => ($i % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
891                     'S_CAT_IMAGES_OPTIONS' => $s_cat_images_options,
892                     'ANONYMOUS_VIEW_CHECKED' => ( $row['anonymous_view'] ? ' checked="checked"' : '' ),
893                     'ALLOW_UPLOAD_CHECKED' => ( $row['allow_upload'] ? ' checked="checked"' : '' ),
894                     'TORRENTS_LIMIT' => $row['torrents_limit']
895                 ));
896
897                 unset($ary[$cat_id]);
898                 if ( $count ) {
899                     foreach( $ary AS $key => $sub_ary ) {
900                         $s_cat_images_options = '';
901                         for ( $j = 0; $j < $cat_images_ary_size; ++$j ) {
902                             $s_cat_images_options .= '<option' . ( $cat_images_ary[$j] == $sub_ary['image'] ? ' selected="selected"' : '' ) . '>' . $cat_images_ary[$j] . '</option>';
903                         }
904
905                         $template->assign_block_vars('catrow.subcats_row', array(
906                             'CAT_ID' => $sub_ary['id'],
907                             'CAT_IMAGE' => ( !empty($sub_ary['image']) ? $sub_ary['image'] : '' ),
908                             'CAT_NAME' => $sub_ary['name'],
909                             'U_DELETE' => append_sid('admin_categories.php?mode=delete&amp;cat_id=' . $sub_ary['id']),
910                             'U_EDIT' => append_sid('admin_categories.php?mode=edit&amp;cat_id=' . $sub_ary['id']),
911                             'U_EDIT_TEMPLATE' => append_sid('admin_categories.php?mode=edit_template&amp;cat_id=' . $sub_ary['id']),
912                             'ROW_COLOR' => ($i % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
913                             'S_CAT_IMAGES_OPTIONS' => $s_cat_images_options,
914                             'ANONYMOUS_VIEW_CHECKED' => ( $sub_ary['anonymous_view'] ? ' checked="checked"' : '' ),
915                             'ALLOW_UPLOAD_CHECKED' => ( $sub_ary['allow_upload'] ? ' checked="checked"' : '' ),
916                             'TORRENTS_LIMIT' => $sub_ary['torrents_limit']
917                         ));
918                     }
919                 }
920
921                 ++$i;
922
923             }
924
925
926
927             if ( $row = $db->sql_fetchrow($result) ) {
928                 $i = 0;
929                 do {
930
931                     $template->assign_block_vars('catrow', array(
932                         'CAT_ID' => $row['id'],
933                         'CAT_IMAGE' => ( !empty($row['image']) ? $row['image'] : '' ),
934                         'CAT_NAME' => $row['name'],
935                         'U_DELETE' => append_sid('admin_categories.php?mode=delete&amp;cat_id=' . $row['id']),
936                         'U_EDIT' => append_sid('admin_categories.php?mode=edit&amp;cat_id=' . $row['id']),
937                         'U_EDIT_TEMPLATE' => append_sid('admin_categories.php?mode=edit_template&amp;cat_id=' . $row['id']),
938                         'ROW_COLOR' => ($i % 2 ? $theme['td_class1'] : $theme['td_class2'] ),
939                         'S_CAT_IMAGES_OPTIONS' => $s_cat_images_options,
940                         'ANONYMOUS_VIEW_CHECKED' => ( $row['anonymous_view'] ? ' checked="checked"' : '' ),
941                         'TORRENTS_LIMIT' => $row['torrents_limit']
942                     ));
943                     ++$i;
944                 }
945                 while ( $row = $db->sql_fetchrow($result) );
946             }
947
948                $template->set_filenames(array(
949                 'body' => '../admin/admin_categories_view.html')
950             );
951
952             $template->display('body');
953
954         break;
955 }
956
957 include('./page_footer_admin.'.$phpEx);
958
959 ?>
Note: See TracBrowser for help on using the browser.