source: extensions/typetags/admin.php @ 27306

Last change on this file since 27306 was 26665, checked in by mistic100, 10 years ago

integrate in new tags manager + rename in Coloured Tags
(my apologies to translators :-) )

File size: 5.9 KB
Line 
1<?php
2defined('TYPETAGS_PATH') or die('Hacking attempt!');
3
4load_language('plugin.lang', TYPETAGS_PATH);
5
6include_once(TYPETAGS_PATH . 'include/functions.inc.php');
7
8
9// +-----------------------------------------------------------------------+
10// |                                edit typetags                          |
11// +-----------------------------------------------------------------------+
12if (isset($_POST['edittypetag']))
13{
14  if (empty($_POST['typetag_name']) or empty($_POST['typetag_color']))
15  {
16    $page['errors'][] = l10n('You must fill all fields (name and color)');
17  }
18  else
19  {
20    // we must not rename typetag with an already existing name
21    $query = '
22SELECT id
23  FROM ' . TYPETAGS_TABLE . '
24  WHERE
25    name = "' . pwg_db_real_escape_string($_POST['typetag_name']) . '"
26    AND id != ' . $_POST['edited_typetag'] . '
27;';
28
29    if (pwg_db_num_rows(pwg_query($query)))
30    {
31      $page['errors'][] = l10n('This name is already used');
32    }
33    else if ( ($color = check_color($_POST['typetag_color'])) === false )
34    {
35      $page['errors'][] = l10n('Invalid color');
36    }
37    else
38    {
39      $query = '
40UPDATE '.TYPETAGS_TABLE.'
41  SET
42    name = "' . pwg_db_real_escape_string($_POST['typetag_name']) . '",
43    color = "' . $color . '"
44  WHERE id = ' . $_POST['edited_typetag'] . '
45;';
46      pwg_query($query);
47
48      $page['infos'][] = l10n('Color saved');
49    }
50  }
51
52  if (count($page['errors']))
53  {
54    $edited_typetag = array(
55      'id' => $_POST['edited_typetag'],
56      'name' => $_POST['typetag_name'],
57      'color' => $_POST['typetag_color'],
58      );
59  }
60}
61
62// +-----------------------------------------------------------------------+
63// |                           delete typetags                             |
64// +-----------------------------------------------------------------------+
65if (isset($_GET['deletetypetag']))
66{
67  $query = '
68UPDATE ' . TAGS_TABLE . '
69  SET id_typetags = NULL
70  WHERE id_typetags = ' . intval($_GET['deletetypetag']) . '
71;';
72  pwg_query($query);
73
74  $query = '
75DELETE FROM ' . TYPETAGS_TABLE . '
76  WHERE id = ' . intval($_GET['deletetypetag']) . '
77;';
78  pwg_query($query);
79
80  if (pwg_db_changes())
81  {
82    $page['infos'][] = l10n('Color deleted');
83  }
84}
85
86// +-----------------------------------------------------------------------+
87// |                               add a typetag                           |
88// +-----------------------------------------------------------------------+
89if (isset($_POST['addtypetag']))
90{
91  if (empty($_POST['typetag_name']) or empty($_POST['typetag_color']))
92  {
93    $page['errors'][] = l10n('You must fill all fields (name and color)');
94  }
95  else
96  {
97    $typetag_name = $_POST['typetag_name'];
98    $typetag_color = $_POST['typetag_color'];
99
100    // does the tag already exists?
101    $query = '
102SELECT id
103  FROM ' . TYPETAGS_TABLE . '
104  WHERE name = "' . pwg_db_real_escape_string($_POST['typetag_name']) . '"
105';
106
107    if (pwg_db_num_rows(pwg_query($query)))
108    {
109      $page['errors'][] = l10n('This name is already used');
110    }
111    else if ( ($color = check_color($_POST['typetag_color'])) === false )
112    {
113      $page['errors'][] = l10n('Invalid color');
114    }
115    else
116    {
117      $query = '
118INSERT INTO ' . TYPETAGS_TABLE . '(
119    name,
120    color
121  )
122  VALUES(
123    "' . pwg_db_real_escape_string($_POST['typetag_name']) . '",
124    "' . $color . '"
125  )
126;';
127      pwg_query($query);
128
129      $page['infos'][] = l10n('Color added');
130    }
131  }
132
133  if (count($page['errors']))
134  {
135    $template->assign('typetag', array(
136      'NAME' => $_POST['typetag_name'],
137      'COLOR' => $_POST['typetag_color'],
138      ));
139  }
140}
141
142// +-----------------------------------------------------------------------+
143// |                          Configuration                                |
144// +-----------------------------------------------------------------------+
145if (isset($_POST['save_config']))
146{
147  $conf['TypeTags'] = array(
148    'show_all' => $_POST['show_all'] == 'true',
149    );
150
151  conf_update_param('TypeTags', serialize($conf['TypeTags']));
152  $page['infos'][] = l10n('Information data registered in database');
153}
154
155$template->assign('SHOW_ALL', $conf['TypeTags']['show_all']);
156
157// +-----------------------------------------------------------------------+
158// |                             template init                             |
159// +-----------------------------------------------------------------------+
160$template->assign('TYPETAGS_PATH', TYPETAGS_PATH);
161$template->assign('F_ACTION', TYPETAGS_ADMIN);
162
163// get all typetags
164$query = 'SELECT * FROM ' . TYPETAGS_TABLE . ' ORDER BY name;';
165$result = pwg_query($query);
166
167while ($row = pwg_db_fetch_assoc($result))
168{
169  $row['color_text'] = get_color_text($row['color']);
170  $row['u_edit'] = TYPETAGS_ADMIN . '&amp;edittypetag=' . $row['id'];
171  $row['u_delete'] = TYPETAGS_ADMIN . '&amp;deletetypetag=' . $row['id'];
172
173  $template->append('typetags', $row);
174}
175
176// edit form
177if (isset($_GET['edittypetag']))
178{
179  $edited_typetag['id'] = intval($_GET['edittypetag']);
180}
181
182if (isset($edited_typetag['id']) and $edited_typetag['id']>0)
183{
184  $template->assign('edited_typetag', $edited_typetag['id']);
185
186$query = '
187SELECT *
188  FROM ' . TYPETAGS_TABLE . '
189  WHERE id = ' . $edited_typetag['id'] . '
190;';
191  $row = pwg_db_fetch_assoc(pwg_query($query));
192
193  $template->assign('typetag', array(
194    'ID' => $row['id'],
195    'OLD_NAME' => $row['name'],
196    'OLD_COLOR' => $row['color'],
197    'COLOR_TEXT' => get_color_text($row['color']),
198    'NAME' => isset($edited_typetag['name']) ? $edited_typetag['name'] : $row['name'],
199    'COLOR'=> isset($edited_typetag['color']) ? $edited_typetag['color'] : $row['color'],
200    ));
201
202  $template->assign('IN_EDIT', true);
203}
204
205// +-----------------------------------------------------------------------+
206// |                           sending html code                           |
207// +-----------------------------------------------------------------------+
208$template->set_filename('typetags', realpath(TYPETAGS_PATH . 'template/admin.tpl'));
209$template->assign_var_from_handle('ADMIN_CONTENT', 'typetags');
Note: See TracBrowser for help on using the repository browser.