Changeset 26665 for extensions/typetags/admin.php
- Timestamp:
- Jan 12, 2014, 7:13:40 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/typetags/admin.php
r21361 r26665 1 1 <?php 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 4 load_language('plugin.lang', typetags_PATH); 5 6 function get_color_text($color) 7 { 8 if (strlen($color) == 7) 9 { 10 $rgb[] = hexdec(substr($color, 1, 2))/255; 11 $rgb[] = hexdec(substr($color, 3, 2))/255; 12 $rgb[] = hexdec(substr($color, 5, 2))/255; 13 } 14 else if (strlen($color) == 4) 15 { 16 $rgb[] = hexdec(substr($color, 1, 1))/15; 17 $rgb[] = hexdec(substr($color, 2, 1))/15; 18 $rgb[] = hexdec(substr($color, 3, 1))/15; 19 } 20 $l = (min($rgb) + max($rgb)) / 2; 21 return $l > 0.45 ? '#000' : '#fff'; 22 } 2 defined('TYPETAGS_PATH') or die('Hacking attempt!'); 3 4 load_language('plugin.lang', TYPETAGS_PATH); 5 6 include_once(TYPETAGS_PATH . 'include/functions.inc.php'); 7 23 8 24 9 // +-----------------------------------------------------------------------+ 25 10 // | edit typetags | 26 11 // +-----------------------------------------------------------------------+ 27 28 if ( isset($_POST['edittypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])) ) 29 { 30 $edited_typetag = array( 31 'id' => $_POST['edited_typetag'], 32 'name' => $_POST['typetag_name'], 33 'color' => $_POST['typetag_color'], 34 ); 35 36 array_push($page['errors'], l10n('typetag_error')); 37 } 38 else if (isset($_POST['edittypetag'])) 39 { 40 // we must not rename typetag with an already existing name 41 $query = ' 12 if (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 = ' 42 22 SELECT id 43 FROM ' .typetags_TABLE.'23 FROM ' . TYPETAGS_TABLE . ' 44 24 WHERE 45 name = "'.$_POST['typetag_name'].'" 46 AND id != '.$_POST['edited_typetag'].' 47 ;'; 48 49 if ( pwg_db_num_rows(pwg_query($query)) ) 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 = ' 40 UPDATE '.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'])) 50 53 { 51 54 $edited_typetag = array( … … 53 56 'name' => $_POST['typetag_name'], 54 57 'color' => $_POST['typetag_color'], 55 ); 56 57 array_push($page['errors'], l10n('typetag_already_exists')); 58 ); 59 } 60 } 61 62 // +-----------------------------------------------------------------------+ 63 // | delete typetags | 64 // +-----------------------------------------------------------------------+ 65 if (isset($_GET['deletetypetag'])) 66 { 67 $query = ' 68 UPDATE ' . TAGS_TABLE . ' 69 SET id_typetags = NULL 70 WHERE id_typetags = ' . intval($_GET['deletetypetag']) . ' 71 ;'; 72 pwg_query($query); 73 74 $query = ' 75 DELETE 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 // +-----------------------------------------------------------------------+ 89 if (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)'); 58 94 } 59 95 else 60 96 { 97 $typetag_name = $_POST['typetag_name']; 98 $typetag_color = $_POST['typetag_color']; 99 100 // does the tag already exists? 61 101 $query = ' 62 UPDATE '.typetags_TABLE.'63 SET64 name = "'.$_POST['typetag_name'].'",65 color = "'.$_POST['typetag_color'].'"66 WHERE id = '.$_POST['edited_typetag'].'67 ;';68 pwg_query($query);69 70 array_push($page['infos'], l10n('typetag_saved'));71 }72 }73 74 // +-----------------------------------------------------------------------+75 // | delete typetags |76 // +-----------------------------------------------------------------------+77 78 if (isset($_GET['deletetypetag']))79 {80 $query = '81 102 SELECT id 82 FROM '.typetags_TABLE.' 83 WHERE id = '.$_GET['deletetypetag'].' 84 ;'; 85 86 if ( pwg_db_num_rows(pwg_query($query)) ) 87 { 88 $query = ' 89 UPDATE '.TAGS_TABLE.' 90 SET id_typetags = NULL 91 WHERE id_typetags = '.$_GET['deletetypetag'].' 92 ;'; 93 pwg_query($query); 94 95 $query = ' 96 DELETE FROM '.typetags_TABLE.' 97 WHERE id = '.$_GET['deletetypetag'].' 98 ;'; 99 pwg_query($query); 100 101 array_push($page['infos'], l10n('typetag_suppr')); 102 } 103 else 104 { 105 array_push($page['errors'], l10n('typetag_unknown')); 106 } 107 } 108 109 // +-----------------------------------------------------------------------+ 110 // | add a typetag | 111 // +-----------------------------------------------------------------------+ 112 113 if ( isset($_POST['addtypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])) ) 114 { 115 $template->assign('typetag', array( 116 'NAME' => $_POST['typetag_name'], 117 'COLOR' => $_POST['typetag_color'], 118 )); 119 120 array_push($page['errors'], l10n('typetag_error')); 121 } 122 else if (isset($_POST['addtypetag'])) 123 { 124 $typetag_name = $_POST['typetag_name']; 125 $typetag_color = $_POST['typetag_color']; 126 127 // does the tag already exists? 128 $query = ' 129 SELECT id 130 FROM '.typetags_TABLE.' 131 WHERE name = "'.$_POST['typetag_name'].'" 103 FROM ' . TYPETAGS_TABLE . ' 104 WHERE name = "' . pwg_db_real_escape_string($_POST['typetag_name']) . '" 132 105 '; 133 106 134 if ( pwg_db_num_rows(pwg_query($query)) ) 135 { 136 $template->assign('typetag', array( 137 'NAME' => $_POST['typetag_name'], 138 'COLOR' => $_POST['typetag_color'], 139 )); 140 141 array_push($page['errors'], l10n('typetag_already_exists')); 142 } 143 else 144 { 145 $query = ' 146 INSERT INTO '.typetags_TABLE.'( 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 = ' 118 INSERT INTO ' . TYPETAGS_TABLE . '( 147 119 name, 148 120 color 149 121 ) 150 122 VALUES( 151 "' .$_POST['typetag_name'].'",152 "' .$_POST['typetag_color'].'"123 "' . pwg_db_real_escape_string($_POST['typetag_name']) . '", 124 "' . $color . '" 153 125 ) 154 126 ;'; 155 pwg_query($query); 156 157 array_push($page['infos'], l10n('typetag_saved')); 158 } 159 } 160 161 // +-----------------------------------------------------------------------+ 162 // | Associate Tag to Typetage | 163 // +-----------------------------------------------------------------------+ 164 165 if (isset($_POST['delete_all_assoc'])) 166 { 167 pwg_query('UPDATE '.TAGS_TABLE.' SET id_typetags = NULL;'); 168 array_push($page['infos'], l10n('All associations have been removed')); 169 } 170 else if (isset($_POST['associations'])) 171 { 172 // beautify the parameters array 173 $string = preg_replace('#[;]$#', null, $_POST['associations']); 174 $associations = array(); 175 $a = explode(';', $string); 176 177 foreach ($a as $s) 178 { 179 $v = explode(':', $s); 180 $associations[ltrim($v[0],'t-')] = ltrim($v[1],'tt-'); 181 } 182 183 // save associations 184 $updates = array(); 185 foreach ($associations as $tag => $typetag) 186 { 187 array_push($updates, array( 188 'id' => $tag, 189 'id_typetags' => $typetag, 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'], 190 138 )); 191 139 } 192 193 mass_updates(194 TAGS_TABLE,195 array('primary' => array('id'), 'update' => array('id_typetags')),196 $updates197 );198 199 array_push($page['infos'], l10n('typetags_associated'));200 140 } 201 141 … … 208 148 'show_all' => $_POST['show_all'] == 'true', 209 149 ); 210 150 211 151 conf_update_param('TypeTags', serialize($conf['TypeTags'])); 152 $page['infos'][] = l10n('Information data registered in database'); 212 153 } 213 154 … … 217 158 // | template init | 218 159 // +-----------------------------------------------------------------------+ 219 220 $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin/typetags_admin.tpl')); 221 222 // get all tags 223 $query = ' 224 SELECT 225 id as tagid, 226 name as tagname, 227 id_typetags as typetagid 228 FROM '.TAGS_TABLE.' 229 ORDER BY name ASC 230 ;'; 231 $all_tags = pwg_query($query); 232 233 while ($row = pwg_db_fetch_assoc($all_tags)) 234 { 235 if (!$row['typetagid']) $row['typetagid'] = 'NULL'; 236 $row['tagname'] = strip_tags(trigger_event('render_tag_name', $row['tagname'])); 237 $template->append('typetags_association', $row); 238 } 160 $template->assign('TYPETAGS_PATH', TYPETAGS_PATH); 161 $template->assign('F_ACTION', TYPETAGS_ADMIN); 239 162 240 163 // get all typetags 241 $query = 'SELECT * FROM ' .typetags_TABLE.' ORDER BY name;';242 $ all_typetags= pwg_query($query);243 244 while ($row = pwg_db_fetch_assoc($ all_typetags))164 $query = 'SELECT * FROM ' . TYPETAGS_TABLE . ' ORDER BY name;'; 165 $result = pwg_query($query); 166 167 while ($row = pwg_db_fetch_assoc($result)) 245 168 { 246 169 $row['color_text'] = get_color_text($row['color']); 247 $row['u_edit'] = typetags_ADMIN . '&edittypetag=' . $row['id'];248 $row['u_delete'] = typetags_ADMIN . '&deletetypetag=' . $row['id'];249 250 $template->append('typetags _selection', $row);170 $row['u_edit'] = TYPETAGS_ADMIN . '&edittypetag=' . $row['id']; 171 $row['u_delete'] = TYPETAGS_ADMIN . '&deletetypetag=' . $row['id']; 172 173 $template->append('typetags', $row); 251 174 } 252 175 … … 254 177 if (isset($_GET['edittypetag'])) 255 178 { 256 $edited_typetag['id'] = $_GET['edittypetag'];257 } 258 259 if (isset($edited_typetag['id']) )179 $edited_typetag['id'] = intval($_GET['edittypetag']); 180 } 181 182 if (isset($edited_typetag['id']) and $edited_typetag['id']>0) 260 183 { 261 184 $template->assign('edited_typetag', $edited_typetag['id']); 262 185 263 186 $query = ' 264 SELECT 265 id, 266 name, 267 color 268 FROM '.typetags_TABLE.' 269 WHERE id = '.$edited_typetag['id'].' 187 SELECT * 188 FROM ' . TYPETAGS_TABLE . ' 189 WHERE id = ' . $edited_typetag['id'] . ' 270 190 ;'; 271 191 $row = pwg_db_fetch_assoc(pwg_query($query)); … … 278 198 'NAME' => isset($edited_typetag['name']) ? $edited_typetag['name'] : $row['name'], 279 199 'COLOR'=> isset($edited_typetag['color']) ? $edited_typetag['color'] : $row['color'], 280 ));281 200 )); 201 282 202 $template->assign('IN_EDIT', true); 283 203 } … … 286 206 // | sending html code | 287 207 // +-----------------------------------------------------------------------+ 288 289 $template->assign('typetags_ADMIN', typetags_ADMIN); 290 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); 291 292 ?> 208 $template->set_filename('typetags', realpath(TYPETAGS_PATH . 'template/admin.tpl')); 209 $template->assign_var_from_handle('ADMIN_CONTENT', 'typetags');
Note: See TracChangeset
for help on using the changeset viewer.