source: extensions/typetags/admin.php @ 26665

Last change on this file since 26665 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
RevLine 
[9829]1<?php
[26665]2defined('TYPETAGS_PATH') or die('Hacking attempt!');
[9829]3
[26665]4load_language('plugin.lang', TYPETAGS_PATH);
[9829]5
[26665]6include_once(TYPETAGS_PATH . 'include/functions.inc.php');
[9829]7
[26665]8
[9829]9// +-----------------------------------------------------------------------+
10// |                                edit typetags                          |
11// +-----------------------------------------------------------------------+
[26665]12if (isset($_POST['edittypetag']))
[9829]13{
[26665]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 = '
[15149]22SELECT id
[26665]23  FROM ' . TYPETAGS_TABLE . '
[15149]24  WHERE
[26665]25    name = "' . pwg_db_real_escape_string($_POST['typetag_name']) . '"
26    AND id != ' . $_POST['edited_typetag'] . '
[15149]27;';
[9829]28
[26665]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']))
[10987]53  {
54    $edited_typetag = array(
[15149]55      'id' => $_POST['edited_typetag'],
56      'name' => $_POST['typetag_name'],
57      'color' => $_POST['typetag_color'],
[26665]58      );
[10987]59  }
[9829]60}
61
62// +-----------------------------------------------------------------------+
[9863]63// |                           delete typetags                             |
[9829]64// +-----------------------------------------------------------------------+
[9863]65if (isset($_GET['deletetypetag']))
[9829]66{
[15149]67  $query = '
[26665]68UPDATE ' . TAGS_TABLE . '
[15149]69  SET id_typetags = NULL
[26665]70  WHERE id_typetags = ' . intval($_GET['deletetypetag']) . '
[15149]71;';
[26665]72  pwg_query($query);
73
74  $query = '
75DELETE FROM ' . TYPETAGS_TABLE . '
76  WHERE id = ' . intval($_GET['deletetypetag']) . '
[15149]77;';
[26665]78  pwg_query($query);
79
80  if (pwg_db_changes())
[10987]81  {
[26665]82    $page['infos'][] = l10n('Color deleted');
[10987]83  }
[9829]84}
85
86// +-----------------------------------------------------------------------+
87// |                               add a typetag                           |
88// +-----------------------------------------------------------------------+
[26665]89if (isset($_POST['addtypetag']))
[9829]90{
[26665]91  if (empty($_POST['typetag_name']) or empty($_POST['typetag_color']))
[10987]92  {
[26665]93    $page['errors'][] = l10n('You must fill all fields (name and color)');
[10987]94  }
[15149]95  else
96  {
[26665]97    $typetag_name = $_POST['typetag_name'];
98    $typetag_color = $_POST['typetag_color'];
99
100    // does the tag already exists?
[15149]101    $query = '
[26665]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 . '(
[15149]119    name,
120    color
121  )
122  VALUES(
[26665]123    "' . pwg_db_real_escape_string($_POST['typetag_name']) . '",
124    "' . $color . '"
[15149]125  )
126;';
[26665]127      pwg_query($query);
[15149]128
[26665]129      $page['infos'][] = l10n('Color added');
130    }
[15149]131  }
[9829]132
[26665]133  if (count($page['errors']))
[15149]134  {
[26665]135    $template->assign('typetag', array(
136      'NAME' => $_POST['typetag_name'],
137      'COLOR' => $_POST['typetag_color'],
[15149]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    );
[26665]150
[15149]151  conf_update_param('TypeTags', serialize($conf['TypeTags']));
[26665]152  $page['infos'][] = l10n('Information data registered in database');
[9829]153}
154
[15149]155$template->assign('SHOW_ALL', $conf['TypeTags']['show_all']);
[9863]156
[9829]157// +-----------------------------------------------------------------------+
158// |                             template init                             |
159// +-----------------------------------------------------------------------+
[26665]160$template->assign('TYPETAGS_PATH', TYPETAGS_PATH);
161$template->assign('F_ACTION', TYPETAGS_ADMIN);
[9829]162
[15149]163// get all typetags
[26665]164$query = 'SELECT * FROM ' . TYPETAGS_TABLE . ' ORDER BY name;';
165$result = pwg_query($query);
[9829]166
[26665]167while ($row = pwg_db_fetch_assoc($result))
[9829]168{
[10987]169  $row['color_text'] = get_color_text($row['color']);
[26665]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);
[9829]174}
175
[15149]176// edit form
177if (isset($_GET['edittypetag']))
178{
[26665]179  $edited_typetag['id'] = intval($_GET['edittypetag']);
[9863]180}
[9829]181
[26665]182if (isset($edited_typetag['id']) and $edited_typetag['id']>0)
[9829]183{
[10987]184  $template->assign('edited_typetag', $edited_typetag['id']);
[26665]185
[15149]186$query = '
[26665]187SELECT *
188  FROM ' . TYPETAGS_TABLE . '
189  WHERE id = ' . $edited_typetag['id'] . '
[15149]190;';
191  $row = pwg_db_fetch_assoc(pwg_query($query));
[9829]192
[10987]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'],
[26665]200    ));
201
[15477]202  $template->assign('IN_EDIT', true);
[9829]203}
204
205// +-----------------------------------------------------------------------+
206// |                           sending html code                           |
207// +-----------------------------------------------------------------------+
[26665]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.