>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
include_once('db.php');
include_once('nonce.php');
include_once('rpc.php');
if(!isset($_SESSION['id'])){die(_('Insufficient privileges'));}
if(!($privileges&PRIV_TAGS)){die(_('Insufficient privileges'));}
$error='';
if(checknonce()) // Save changes
{
if(isset($_POST['options']))
{
setoption('usertags', isset($_POST['usertags']));
}
if(isset($_POST['addtag']) || isset($_POST['blacklisttag']))
{
$tag=mysqli_real_escape_string($db, $_POST['newtag']);
$blacklist='0';
if(isset($_POST['blacklisttag']))
{
$blacklist='1';
$res=mysqli_query($db, 'select id from tags where name="'.$tag.'"');
if($res=mysqli_fetch_row($res))
{
mysqli_query($db, 'delete from tagmaps where tag="'.(int)$res[0].'"');
}
}
mysqli_query($db, 'delete from tags where name="'.$tag.'"');
mysqli_query($db, 'insert into tags(name, blacklist, optin) values("'.$tag.'", '.$blacklist.', "")');
}
if(isset($_POST['deletetag']))
{
$tag=(int)$_POST['deletetag'];
mysqli_query($db, 'delete from tagmaps where tag="'.$tag.'"');
mysqli_query($db, 'delete from tags where id="'.$tag.'"');
}
if(isset($_POST['tag_optin']))
{
$id=(int)$path[3];
$optin=mysqli_real_escape_string($db, $_POST['tag_optin']);
mysqli_query($db, 'update tags set optin="'.$optin.'" where id='.$id);
header('Location: '.BASEURL.'/admin/tags');
}
}
if($error!=''){$error=''.$error.'';}
// Load current
if(!isset($path[3]))
{
$tags='';
$res=mysqli_query($db, 'select name, blacklist, id from tags order by name asc');
while($row=mysqli_fetch_assoc($res))
{
$name=htmlentities($row['name']);
if($row['blacklist']){$name=''.$name.'';}
$tags.=''.$name.' ';
}
$usertagscheck=(getoption('usertags', true)?' checked':'');
}else{ // Individual tag
$id=(int)$path[3];
$res=mysqli_query($db, 'select name, blacklist, optin from tags where id='.$id);
$res=mysqli_fetch_assoc($res);
$name=$res['name'];
if($res['blacklist'])
{
$optin='';
$placeholder='"'._('Blacklisted').'" disabled';
}else{
$optin=htmlentities($res['optin']);
$placeholder='"'._('No opt-in required').'"';
}
$res=mysqli_query($db, 'select count(*) from tagmaps where tag='.$id);
$numtags=mysqli_fetch_row($res)[0];
}
if(!isset($path[3]))
{
?>
=$error?>
Tag '=$name?>'
=sprintf(_('%s things tagged on this node.'), $numtags)?>