1<?php 2/** 3 * provides the TAGS tab of admin 4 * @package admin 5 */ 6define('OFFSET_PATH', 1); 7require_once(dirname(__FILE__) . '/admin-globals.php'); 8require_once(dirname(__FILE__) . '/template-functions.php'); 9 10admin_securityChecks(TAGS_RIGHTS, currentRelativeURL()); 11 12$_GET['page'] = 'tags'; 13 14if (isset($_REQUEST['tagsort'])) { 15 $tagsort = sanitize($_REQUEST['tagsort']); 16 setOption('tagsort', ($tagsort && true)); 17} else { 18 $tagsort = getOption('tagsort'); 19} 20$action = ''; 21if (count($_POST) > 0) { 22 if (isset($_GET['newtags'])) { 23 XSRFdefender('new_tags'); 24 foreach ($_POST as $value) { 25 if (!empty($value)) { 26 $value = html_decode(sanitize($value, 3)); 27 $result = query_single_row('SELECT `id` FROM ' . prefix('tags') . ' WHERE `name`=' . db_quote($value)); 28 if (!is_array($result)) { // it really is a new tag 29 query('INSERT INTO ' . prefix('tags') . ' (`name`) VALUES (' . db_quote($value) . ')'); 30 } 31 } 32 } 33 $action = gettext('New tags added'); 34 } // newtags 35 if (isset($_GET['delete'])) { 36 XSRFdefender('tag_delete'); 37 $kill = array(); 38 foreach ($_POST as $key => $value) { 39 $key = str_replace('tags_', '', postIndexDecode($key)); 40 $kill[] = mb_strtolower($key); 41 } 42 if (count($kill) > 0) { 43 $sql = "SELECT `id` FROM " . prefix('tags') . " WHERE "; 44 foreach ($kill as $tag) { 45 $sql .= "`name`=" . (db_quote($tag)) . " OR "; 46 } 47 $sql = substr($sql, 0, strlen($sql) - 4); 48 $dbtags = query_full_array($sql); 49 if (is_array($dbtags) && count($dbtags) > 0) { 50 $sqltags = "DELETE FROM " . prefix('tags') . " WHERE "; 51 $sqlobjects = "DELETE FROM " . prefix('obj_to_tag') . " WHERE "; 52 foreach ($dbtags as $tag) { 53 $sqltags .= "`id`='" . $tag['id'] . "' OR "; 54 $sqlobjects .= "`tagid`='" . $tag['id'] . "' OR "; 55 } 56 $sqltags = substr($sqltags, 0, strlen($sqltags) - 4); 57 query($sqltags); 58 $sqlobjects = substr($sqlobjects, 0, strlen($sqlobjects) - 4); 59 query($sqlobjects); 60 } 61 } 62 $action = gettext('Checked tags deleted'); 63 } // delete 64 if (isset($_GET['rename'])) { 65 XSRFdefender('tag_rename'); 66 unset($_POST['XSRFToken']); 67 foreach ($_POST as $key => $newName) { 68 if (!empty($newName)) { 69 $newName = sanitize($newName, 3); 70 $key = postIndexDecode($key); 71 $key = substr($key, 2); // strip off the 'R_' 72 $newtag = query_single_row('SELECT `id` FROM ' . prefix('tags') . ' WHERE `name`=' . db_quote($newName)); 73 $oldtag = query_single_row('SELECT `id` FROM ' . prefix('tags') . ' WHERE `name`=' . db_quote($key)); 74 if (is_array($newtag)) { // there is an existing tag of the same name 75 $existing = $newtag['id'] != $oldtag['id']; // but maybe it is actually the original in a different case. 76 } else { 77 $existing = false; 78 } 79 if ($existing) { 80 query('DELETE FROM ' . prefix('tags') . ' WHERE `id`=' . $oldtag['id']); 81 query('UPDATE ' . prefix('obj_to_tag') . ' SET `tagid`=' . $newtag['id'] . ' WHERE `tagid`=' . $oldtag['id']); 82 } else { 83 query('UPDATE ' . prefix('tags') . ' SET `name`=' . db_quote($newName) . ' WHERE `id`=' . $oldtag['id']); 84 } 85 } 86 } 87 $action = gettext('Tags renamed'); 88 } // rename 89} 90 91printAdminHeader('tags'); 92?> 93</head> 94<body> 95 <?php 96 printLogoAndLinks(); 97 ?> 98 <div id="main"> 99 <?php 100 printTabs(); 101 ?> 102 <div id="content"> 103 <?php 104 if (!empty($action)) { 105 ?> 106 <div class="messagebox fade-message"> 107 <h2><?php echo $action; ?></h2> 108 </div> 109 <?php 110 } 111 112 113 echo "<h1>" . gettext("Tag Management") . "</h1>"; 114 if ($tagsort == 1) { 115 ?> 116 <p class="buttons"> 117 <a class="tagsort" href="?tagsort=0"> 118 <img src="images/sortorder.png" alt="" /> <?php echo gettext('Order alphabetically'); ?> 119 </a> 120 </p> 121 <br /> 122 <br /> 123 <br class="clearall" /> 124 <?php 125 } else { 126 ?> 127 <p class="buttons"> 128 <a class="tagsort" href="?tagsort=1"> 129 <img src="images/sortorder.png" alt="" /> <?php echo gettext('Order by most used'); ?> 130 </a> 131 </p> 132 <br /> 133 <br /> 134 <br class="clearall" /> 135 <?php 136 } 137 ?> 138 <table class="bordered"> 139 <tr> 140 <td valign='top'> 141 <h2 class="h2_bordered_edit"><?php echo gettext("Delete tags from the gallery"); ?></h2> 142 <form class="dirty-check" name="tag_delete" id="form_tagdelete" action="?delete=true&tagsort=<?php echo html_encode($tagsort); ?>" method="post" autocomplete="off"> 143 <?php XSRFToken('tag_delete'); ?> 144 <div class="box-tags-unpadded"> 145 <?php 146 tagSelector(NULL, 'tags_', true, $tagsort, false); 147 ?> 148 </div> 149 150 <p class="buttons"> 151 <button type="submit" id='delete_tags' value="<?php echo gettext("Delete checked tags"); ?>"> 152 <img src="images/fail.png" alt="" /><?php echo gettext("Delete checked tags"); ?> 153 </button> 154 </p> 155 <label id="autocheck"> 156 <input type="checkbox" name="checkAllAuto" id="checkAllAuto" onclick="$('.checkTagsAuto').prop('checked', $('#checkAllAuto').prop('checked'));"/> 157 <span id="autotext"><?php echo gettext('all'); ?></span> 158 </label> 159 <br class="clearall" /> 160 <br /> 161 <br /> 162 163 </form> 164 <div class="tagtext"> 165 <p><?php echo gettext('Place a checkmark in the box for each tag you wish to delete then press the <em>Delete checked tags</em> button. The brackets contain the number of times the tag appears.'); ?></p> 166 </div> 167 </td> 168 169 <td valign='top'> 170 <h2 class="h2_bordered_edit"><?php echo gettext("Rename tags"); ?></h2> 171 <form class="dirty-check" name="tag_rename" id="form_tagrename" action="?rename=true&tagsort=<?php echo html_encode($tagsort); ?>" method="post" autocomplete="off"> 172 <?php XSRFToken('tag_rename'); ?> 173 <div class="box-tags-unpadded"> 174 <ul class="tagrenamelist"> 175 <?php 176 $list = $_zp_admin_ordered_taglist; 177 foreach ($list as $item) { 178 $listitem = 'R_' . postIndexEncode($item); 179 ?> 180 <li> 181 <label> 182 <?php echo $item; ?> 183 <br /> 184 <input id="<?php echo $listitem; ?>" name="<?php echo $listitem; ?>" type="text" size='33' /> 185 </label> 186 </li> 187 <?php 188 } 189 ?> 190 </ul> 191 </div> 192 <p class="buttons"> 193 <button type="submit" id='rename_tags' value="<?php echo gettext("Rename tags"); ?>"> 194 <img src="images/pass.png" alt="" /><?php echo gettext("Rename tags"); ?> 195 </button> 196 </p> 197 <br class="clearall" /> 198 <br /> 199 <br /> 200 </form> 201 <div class="tagtext"> 202 <p><?php echo gettext('To change the value of a tag enter a new value in the text box below the tag. Then press the <em>Rename tags</em> button'); ?></p> 203 </div> 204 </td> 205 206 <td valign='top'> 207 <h2 class="h2_bordered_edit"><?php echo gettext("New tags"); ?></h2> 208 <form class="dirty-check" name="new_tags" id="form_newtags" action="?newtags=true&tagsort=<?php echo html_encode($tagsort); ?>" method="post" autocomplete="off"> 209 <?php XSRFToken('new_tags'); ?> 210 <div class="box-tags-unpadded"> 211 <ul class="tagnewlist"> 212 <?php 213 for ($i = 0; $i < 40; $i++) { 214 ?> 215 <li> 216 <input id="new_tag_<?php echo $i; ?>" name="new_tag_<?php echo $i; ?>" type="text" size='33'/> 217 </li> 218 <?php 219 } 220 ?> 221 </ul> 222 </div> 223 <p class="buttons"> 224 <button type="submit" id='save_tags' value="<?php echo gettext("Add tags"); ?>"> 225 <img src="images/add.png" alt="" /><?php echo gettext("Add tags"); ?> 226 </button> 227 </p> 228 <br class="clearall" /> 229 <br /> 230 <br /> 231 232 </form> 233 <div class="tagtext"> 234 <p><?php echo gettext("Add tags to the list by entering their names in the input fields of the <em>New tags</em> list. Then press the <em>Add tags</em> button"); ?></p> 235 </div> 236 </td> 237 </tr> 238 </table> 239 240 </div> 241 <?php 242 printAdminFooter(); 243 ?> 244 </div> 245</body> 246</html> 247 248 249 250 251