]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/xs_edit_data.php
df1eb1e803193ec60e098204a67bc4396104cab8
[www.vanrenterghem.biz.git] / phpBB2_old / admin / xs_edit_data.php
1 <?php
3 /***************************************************************************
4  *                              xs_edit_data.php
5  *                              ----------------
6  *   copyright            : (C) 2003, 2004 CyberAlien
7  *   support              : http://www.phpbbstyles.com
8  *
9  *   version              : 2.0.1
10  *
11  *   file revision        : 50
12  *   project revision     : 51
13  *   last modified        : 25 Aug 2004  11:51:48
14  *
15  ***************************************************************************/
17 /***************************************************************************
18  *
19  *   This program is free software; you can redistribute it and/or modify
20  *   it under the terms of the GNU General Public License as published by
21  *   the Free Software Foundation; either version 2 of the License, or
22  *   (at your option) any later version.
23  *
24  ***************************************************************************/
26 define('IN_PHPBB', 1);
27 $phpbb_root_path = "./../";
28 $no_page_header = true;
29 require($phpbb_root_path . 'extension.inc');
30 require('./pagestart.' . $phpEx);
32 // check if mod is installed
33 if(empty($template->xs_version) || $template->xs_version !== 5)
34 {
35         message_die(GENERAL_ERROR, 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
36 }
38 define('IN_XS', true);
39 include_once('xs_include.' . $phpEx);
41 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_edit_data.'.$phpEx) . '">' . $lang['xs_edit_styles_data'] . '</a>'));
43 $lang['xs_edittpl_back_list'] = str_replace('{URL}', append_sid('xs_edit_data.'.$phpEx), $lang['xs_edittpl_back_list']);
45 function xs_empty_name()
46 {
47         global $db;
48         $sql = "SELECT * FROM " . THEMES_NAME_TABLE . " LIMIT 0, 1";
49         if(!$result = $db->sql_query($sql))
50         {
51                 $data = array();
52         }
53         $data = $db->sql_fetchrow($result);
54         if($data === false || !@count($data))
55         {
56                 $data = array(
57                         'themes_id'     => 0,
58                         'tr_color1_name'        => '',
59                         'tr_color2_name'        => '',
60                         'tr_color3_name'        => '',
61                         'tr_class1_name'        => '',
62                         'tr_class2_name'        => '',
63                         'tr_class3_name'        => '',
64                         'th_color1_name'        => '',
65                         'th_color2_name'        => '',
66                         'th_color3_name'        => '',
67                         'th_class1_name'        => '',
68                         'th_class2_name'        => '',
69                         'th_class3_name'        => '',
70                         'td_color1_name'        => '',
71                         'td_color2_name'        => '',
72                         'td_color3_name'        => '',
73                         'td_class1_name'        => '',
74                         'td_class2_name'        => '',
75                         'td_class3_name'        => '',
76                         'fontface1_name'        => '',
77                         'fontface2_name'        => '',
78                         'fontface3_name'        => '',
79                         'fontsize1_name'        => '',
80                         'fontsize2_name'        => '',
81                         'fontsize3_name'        => '',
82                         'fontcolor1_name'       => '',
83                         'fontcolor2_name'       => '',
84                         'fontcolor3_name'       => '',
85                         'span_class1_name'      => '',
86                         'span_class2_name'      => '',
87                         'span_class3_name'      => ''
88                 );
90         }
91         $arr = array();
92         foreach($data as $var => $value)
93         {
94                 if($var !== 'themes_id')
95                 {
96                         $arr[$var] = '';
97                 }
98         }
99         return $arr;
102 function xs_get_vars($theme)
104         $arr1 = array();
105         $arr2 = array();
106         $vars_100 = array('head_stylesheet', 'body_background');
107         $vars_50 = array('fontface');
108         $vars_30 = array('style_name');
109         $vars_25 = array('tr_class', 'th_class', 'td_class', 'span_class');
110         $vars_6 = array('body_bgcolor', 'body_text', 'body_link', 'body_vlink', 'body_alink', 'body_hlink', 'tr_color', 'th_color', 'td_color', 'fontcolor');
111         $vars_5 = array('img_size_poll', 'img_size_privmsg');
112         $vars_4 = array('fontsize', 'theme_public');
113         foreach($theme as $var => $value)
114         {
115                 if(!is_integer($var) && $var !== 'themes_id' && $var !== 'template_name')
116                 {
117                         // editable variable
118                         $len = 0;
119                         $sub = substr($var, 0, strlen($var) - 1);
120                         if(xs_in_array($var, $vars_100) || xs_in_array($sub, $vars_100))
121                         {
122                                 $len = 100;
123                         }
124                         elseif(xs_in_array($var, $vars_50) || xs_in_array($sub, $vars_50))
125                         {
126                                 $len = 50;
127                         }
128                         elseif(xs_in_array($var, $vars_30) || xs_in_array($sub, $vars_30))
129                         {
130                                 $len = 30;
131                         }
132                         elseif(xs_in_array($var, $vars_25) || xs_in_array($sub, $vars_25))
133                         {
134                                 $len = 25;
135                         }
136                         elseif(xs_in_array($var, $vars_6) || xs_in_array($sub, $vars_6))
137                         {
138                                 $len = 6;
139                         }
140                         elseif(xs_in_array($var, $vars_5) || xs_in_array($sub, $vars_5))
141                         {
142                                 $len = 5;
143                         }
144                         elseif(xs_in_array($var, $vrs_4) || xs_in_array($sub, $vars_4))
145                         {
146                                 $len = 4;
147                         }
148                         elseif(strpos($var, 'class'))
149                         {
150                                 $len = 25;
151                         }
152                         elseif(strpos($var, 'color'))
153                         {
154                                 $len = 6;
155                         }
156                         if($len)
157                         {
158                                 $item = array(
159                                         'var'           => $var,
160                                         'len'           => $len,
161                                         'color'         => $len == 6 ? true : false,
162                                         'font'          => $len == 25 ? true : false,
163                                         );
164                                 if($var === 'style_name' || $var === 'head_stylesheet' || $var === 'body_background')
165                                 {
166                                         $arr1[$var] = $item;
167                                 }
168                                 else
169                                 {
170                                         $arr2[$var] = $item;
171                                 }
172                         }
173                 }
174         }
175         krsort($arr1);
176         ksort($arr2);
177         return array_merge($arr1, $arr2);
180 //
181 // submit
182 //
183 if(!empty($HTTP_POST_VARS['edit']) && !defined('DEMO_MODE'))
185         $id = intval($HTTP_POST_VARS['edit']);
186         $lang['xs_edittpl_back_edit'] = str_replace('{URL}', append_sid('xs_edit_data.'.$phpEx.'?edit='.$id), $lang['xs_edittpl_back_edit']);
187         $data_item = array();
188         $data_item_update = array();
189         $data_name = array();
190         $data_name_insert_vars = array('themes_id');
191         $data_name_insert_values = array($id);
192         $data_name_update = array();
193         foreach($HTTP_POST_VARS as $var => $value)
194         {
195                 if(substr($var, 0, 5) === 'edit_')
196                 {
197                         $var = substr($var, 5);
198                         $value = stripslashes($value);
199                         $data_item[$var] = $value;
200                         $data_item_update[] = $var . "='" . xs_sql($value) . "'";
201                 }
202                 elseif(substr($var, 0, 5) === 'name_')
203                 {
204                         $var = substr($var, 5).'_name';
205                         $value = stripslashes($value);
206                         $data_name[$var] = $value;
207                         $data_name_update[] = $var . "='" . xs_sql($value) . "'";
208                         $data_name_insert_vars[] = $var;
209                         $data_name_insert_values[] = xs_sql($value);
210                 }
211         }
212         // update item
213         $sql = "UPDATE " . THEMES_TABLE . " SET " . implode(',', $data_item_update) . " WHERE themes_id='{$id}'";
214         if(!$result = $db->sql_query($sql))
215         {
216                 xs_error($lang['xs_edittpl_error_updating'] . '<br /><br />' . $lang['xs_edittpl_back_edit'] . '<br /><br />' . $lang['xs_edittpl_back_list'], __LINE__, __FILE__);
217         }
218         // check if there is name
219         $sql = "SELECT themes_id FROM " . THEMES_NAME_TABLE . " WHERE themes_id='{$id}'";
220         if(!$result = $db->sql_query($sql))
221         {
222                 $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (" . implode(',', $data_name_insert_vars) . ") VALUES ('" . implode("', '", $data_name_insert_values) . "')";
223         }
224         $item = $db->sql_fetchrow($result);
225         if(!is_array($item))
226         {
227                 $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (" . implode(',', $data_name_insert_vars) . ") VALUES ('" . implode("', '", $data_name_insert_values) . "')";
228         }
229         else
230         {
231                 $sql = "UPDATE " . THEMES_NAME_TABLE . " SET " . implode(',', $data_name_update) . " WHERE themes_id='{$id}'";
232         }
233         $db->sql_query($sql);
234         xs_message($lang['Information'], $lang['xs_edittpl_style_updated'] . '<br /><br />' . $lang['xs_edittpl_back_edit'] . '<br /><br />' . $lang['xs_edittpl_back_list']);
237 //
238 // edit style
239 //
240 if(!empty($HTTP_GET_VARS['edit']))
242         $id = intval($HTTP_GET_VARS['edit']);
243         $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$id}'";
244         if(!$result = $db->sql_query($sql))
245         {
246                 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
247         }
248         $item = $db->sql_fetchrow($result);
249         if(empty($item['themes_id']))
250         {
251                 xs_error($lang['xs_invalid_style_id'] . '<br /><br />' . $lang['xs_edittpl_back_list']);
252         }
253         $sql = "SELECT * FROM " . THEMES_NAME_TABLE . " WHERE themes_id='{$id}'";
254         if(!$result = $db->sql_query($sql))
255         {
256                 $item_name = array();
257         }
258         $item_name = $db->sql_fetchrow($result);
259         if($item_name === false || !@count($item_name))
260         {
261                 $item_name = xs_empty_name();
262         }
263         $vars = xs_get_vars($item);
264         // show variables
265         $template->assign_vars(array(
266                 'U_ACTION'      => append_sid('xs_edit_data.'.$phpEx),
267                 'TPL'           => htmlspecialchars($item['template-name']),
268                 'STYLE'         => htmlspecialchars($item['style_name']),
269                 'ID'            => $id
270                 )
271         );
272         // all variables
273         $i = 0;
274         foreach($vars as $var => $value)
275         {
276                 $row_class = $xs_row_class[$i % 2];
277                 $i++;
278                 if(isset($lang['xs_data_'.$var]))
279                 {
280                         $text = $lang['xs_data_'.$var];
281                 }
282                 else
283                 {
284                         $str = substr($var, 0, strlen($var) - 1);
285                         if(isset($lang['xs_data_'.$str]))
286                         {
287                                 $str1 = substr($var, strlen($var) - 1);
288                                 $text = sprintf($lang['xs_data_'.$str], $str1);
289                         }
290                         else
291                         {
292                                 $text = sprintf($lang['xs_data_unknown'], $var);
293                         }
294                 }
295                 $template->assign_block_vars('row', array(
296                         'ROW_CLASS'     => $row_class,
297                         'VAR'   => $var,
298                         'VALUE' => isset($item[$var]) ? htmlspecialchars($item[$var]) : '',
299                         'LEN'   => $value['len'],
300                         'SIZE'  => $value['len'] < 10 ? 10 : 30,
301                         'TEXT'  => htmlspecialchars($text),
302                         )
303                 );
304                 if($value['color'])
305                 {
306                         $template->assign_block_vars('row.color', array());
307                 }
308                 if($value['font'])
309                 {
310                         $template->assign_block_vars('row.font', array());
311                 }
312                 if(isset($item_name[$var.'_name']))
313                 {
314                         $template->assign_block_vars('row.name', array(
315                                 'DATA'  => $item_name[$var.'_name']
316                                 )
317                         );
318                 }
319                 else
320                 {
321                         $template->assign_block_vars('row.noname', array());
322                 }
323         }
324         $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_data.tpl'));
325         $template->pparse('body');
326         xs_exit();
330 //
331 // show list of installed styles
332 //
333 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY style_name';
334 if(!$result = $db->sql_query($sql))
336         xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
338 $style_rowset = $db->sql_fetchrowset($result);
340 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_data_list.tpl'));
341 for($i=0; $i<count($style_rowset); $i++)
343         $item = $style_rowset[$i];
344         $row_class = $xs_row_class[$i % 2];
345         $template->assign_block_vars('styles', array(
346                 'ROW_CLASS'             => $row_class,
347                 'TPL'                   => htmlspecialchars($item['template_name']),
348                 'STYLE'                 => htmlspecialchars($item['style_name']),
349                 'U_EDIT'                => append_sid('xs_edit_data.'.$phpEx.'?edit='.$item['themes_id'])
350                 )
351         );
354 $template->pparse('body');
355 xs_exit();
357 ?>