Changeset 15149 for extensions/typetags/admin.php
- Timestamp:
- May 20, 2012, 12:38:07 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/typetags/admin.php
r12483 r15149 26 26 // +-----------------------------------------------------------------------+ 27 27 28 if ( isset($_POST['edittypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])))28 if ( isset($_POST['edittypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])) ) 29 29 { 30 30 $edited_typetag = array( … … 33 33 'color' => $_POST['typetag_color'], 34 34 ); 35 $page['errors'][] = l10n('typetag_error'); 35 36 array_push($page['errors'], l10n('typetag_error')); 36 37 } 37 38 else if (isset($_POST['edittypetag'])) 38 39 { 39 $typetag = mysql_escape_string($_POST['edited_typetag']);40 $typetag_name = mysql_escape_string($_POST['typetag_name']);41 $typetag_color = mysql_escape_string($_POST['typetag_color']);42 43 $all_typetags = pwg_query("44 SELECT45 id,46 name,47 color48 FROM `". typetags_TABLE ."`;49 ");50 51 while ($row = mysql_fetch_array($all_typetags))52 {53 $existing_names[] = $row['name'];54 if ($typetag == $row['id'])55 {56 $current_name = $row['name'];57 $current_color = $row['color'];58 }59 }60 61 40 // we must not rename typetag with an already existing name 62 if ($typetag_name != $current_name AND in_array($typetag_name, $existing_names)) 41 $query = ' 42 SELECT id 43 FROM '.typetags_TABLE.' 44 WHERE 45 name = "'.$_POST['typetag_name'].'" 46 AND id != '.$_POST['edited_typetag'].' 47 ;'; 48 49 if ( pwg_db_num_rows(pwg_query($query)) ) 63 50 { 64 51 $edited_typetag = array( 65 'id' => $ typetag,66 'name' => $ typetag_name,67 'color' => $ typetag_color,52 'id' => $_POST['edited_typetag'], 53 'name' => $_POST['typetag_name'], 54 'color' => $_POST['typetag_color'], 68 55 ); 69 56 70 $page['errors'][] = l10n('typetag_already_exists');57 array_push($page['errors'], l10n('typetag_already_exists')); 71 58 } 72 59 else 73 60 { 74 pwg_query(" 75 UPDATE `". typetags_TABLE ."` SET 76 `name` = '". $typetag_name ."', 77 `color` = '". $typetag_color ."' 78 WHERE `id` = ". $typetag ."; 79 "); 80 81 $page['infos'][] = l10n('typetag_saved'); 61 $query = ' 62 UPDATE '.typetags_TABLE.' 63 SET 64 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')); 82 71 } 83 72 } … … 89 78 if (isset($_GET['deletetypetag'])) 90 79 { 91 $query = " 92 SELECT name 93 FROM `". typetags_TABLE ."` 94 WHERE id = ". $_GET['deletetypetag'] ."; 95 "; 96 $typetag_name = array_from_query($query, 'name'); 97 98 if (count($typetag_name) != 0) 99 { 100 pwg_query(" 101 UPDATE `". TAGS_TABLE ."` 102 SET id_typetags = NULL 103 WHERE id_typetags = ". $_GET['deletetypetag'] ."; 104 "); 105 106 pwg_query(" 107 DELETE FROM `". typetags_TABLE ."` 108 WHERE id = ". $_GET['deletetypetag'] ."; 109 "); 110 111 $page['infos'][] = l10n('typetag_suppr').' : '.$typetag_name[0]; 80 $query = ' 81 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')); 112 102 } 113 103 else 114 104 { 115 $page['errors'][] = l10n('typetag_unknown').' : '.$_GET['deletetypetag'];105 array_push($page['errors'], l10n('typetag_unknown')); 116 106 } 117 107 } … … 121 111 // +-----------------------------------------------------------------------+ 122 112 123 if ( isset($_POST['addtypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])))113 if ( isset($_POST['addtypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])) ) 124 114 { 125 115 $template->assign('typetag', array( 126 'NAME' => isset($_POST['typetag_name']) ? $_POST['typetag_name'] : '',127 'COLOR' => isset($_POST['typetag_color']) ? $_POST['typetag_color'] : '',116 'NAME' => $_POST['typetag_name'], 117 'COLOR' => $_POST['typetag_color'], 128 118 )); 129 119 130 $page['errors'][] = l10n('typetag_error');120 array_push($page['errors'], l10n('typetag_error')); 131 121 } 132 122 else if (isset($_POST['addtypetag'])) … … 136 126 137 127 // does the tag already exists? 138 $query = " 139 SELECT id 140 FROM `". typetags_TABLE ."` 141 WHERE name = '". $typetag_name ."'; 142 "; 143 $existing_tags = array_from_query($query, 'id'); 144 145 if (count($existing_tags) == 0) 146 { 147 pwg_query(" 148 INSERT INTO `". typetags_TABLE ."`( 149 `name`, 150 `color` 151 ) 152 VALUES( 153 '". $typetag_name ."', 154 '". $typetag_color ."' 155 ); 156 "); 157 158 $page['infos'][] = l10n('typetag_saved'); 128 $query = ' 129 SELECT id 130 FROM '.typetags_TABLE.' 131 WHERE name = "'.$_POST['typetag_name'].'" 132 '; 133 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')); 159 142 } 160 143 else 161 144 { 162 $template->assign('typetag', array( 163 'NAME' => $typetag_name, 164 'COLOR' => $typetag_color, 165 )); 166 167 $page['errors'][] = l10n('typetag_already_exists'); 145 $query = ' 146 INSERT INTO '.typetags_TABLE.'( 147 name, 148 color 149 ) 150 VALUES( 151 "'.$_POST['typetag_name'].'", 152 "'.$_POST['typetag_color'].'" 153 ) 154 ;'; 155 pwg_query($query); 156 157 array_push($page['infos'], l10n('typetag_saved')); 168 158 } 169 159 } … … 175 165 if (isset($_POST['delete_all_assoc'])) 176 166 { 177 pwg_query("UPDATE `". TAGS_TABLE ."` SET id_typetags = NULL;"); 178 $page['infos'][] = l10n('All associations have been removed'); 179 167 pwg_query('UPDATE '.TAGS_TABLE.' SET id_typetags = NULL;'); 168 array_push($page['infos'], l10n('All associations have been removed')); 180 169 } 181 170 else if (isset($_POST['associations'])) 182 171 { 183 // beautify the parameters array 184 $string = preg_replace('#[;]$#', '', $_POST['associations']); 185 $associations = array(); 186 $a = explode(';', $string); 187 188 foreach ($a as $s) 189 { 190 $v = explode(':', $s); 191 $associations[ltrim($v[0],'t-')] = ltrim($v[1],'tt-'); 192 } 193 194 // save associations 195 foreach ($associations AS $tag => $typetag) 196 { 197 pwg_query(" 198 UPDATE `". TAGS_TABLE ."` 199 SET id_typetags = ". $typetag ." 200 WHERE id = ". $tag ."; 201 "); 202 } 203 204 $page['infos'][] = l10n('typetags_associated'); 205 } 206 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, 190 )); 191 } 192 193 mass_updates( 194 TAGS_TABLE, 195 array('primary' => array('id'), 'update' => array('id_typetags')), 196 $updates 197 ); 198 199 array_push($page['infos'], l10n('typetags_associated')); 200 } 201 202 // +-----------------------------------------------------------------------+ 203 // | Configuration | 204 // +-----------------------------------------------------------------------+ 205 if (isset($_POST['save_config'])) 206 { 207 $conf['TypeTags'] = array( 208 'show_all' => $_POST['show_all'] == 'true', 209 ); 210 211 conf_update_param('TypeTags', serialize($conf['TypeTags'])); 212 } 213 214 $template->assign('SHOW_ALL', $conf['TypeTags']['show_all']); 207 215 208 216 // +-----------------------------------------------------------------------+ … … 212 220 $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin/typetags_admin.tpl')); 213 221 214 // Récupère tous les tags 215 $all_tags = pwg_query(" 216 SELECT 217 t.id as tagid, 218 t.name as tagname, 219 tt.id as typetagid, 220 tt.name as typetagname 221 FROM `". TAGS_TABLE ."` as t 222 LEFT JOIN `". typetags_TABLE ."` as tt 223 ON t.id_typetags = tt.id 224 ORDER BY t.name ASC; 225 "); 226 227 while ($row = pwg_db_fetch_assoc($all_tags)) { 228 if ($row['typetagname'] == null) $row['typetagid'] = 'NULL'; 229 $row['tagname'] = trigger_event('render_tag_name', $row['tagname']); 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'])); 230 237 $template->append('typetags_association', $row); 231 238 } 232 239 233 // Récupère tous les typetags 234 $all_typetags = pwg_query("SELECT * FROM `". typetags_TABLE ."` ORDER BY `name`;"); 240 // get all typetags 241 $query = 'SELECT * FROM '.typetags_TABLE.' ORDER BY name;'; 242 $all_typetags = pwg_query($query); 235 243 236 244 while ($row = mysql_fetch_assoc($all_typetags)) … … 243 251 } 244 252 245 // formualire d'édition 246 if (isset($_GET['edittypetag'])) { 253 // edit form 254 if (isset($_GET['edittypetag'])) 255 { 247 256 $edited_typetag['id'] = $_GET['edittypetag']; 248 257 } … … 251 260 { 252 261 $template->assign('edited_typetag', $edited_typetag['id']); 253 254 $tag = pwg_query(" 255 256 257 258 259 FROM `". typetags_TABLE ."`260 WHERE id = ".$edited_typetag['id'].";261 ");262 $row = pwg_db_fetch_assoc( $tag);262 263 $query = ' 264 SELECT 265 id, 266 name, 267 color 268 FROM '.typetags_TABLE.' 269 WHERE id = '.$edited_typetag['id'].' 270 ;'; 271 $row = pwg_db_fetch_assoc(pwg_query($query)); 263 272 264 273 $template->assign('typetag', array(
Note: See TracChangeset
for help on using the changeset viewer.