diff --git a/frontend_routes.pm b/frontend_routes.pm index 326af97..269bcba 100644 --- a/frontend_routes.pm +++ b/frontend_routes.pm @@ -85,6 +85,22 @@ sub verifyChannelAccess { return 1; } +sub enumerateChannels { + my $aConnection = $_[0]; + + my $output = ""; + return $output; +} + sub handlePath { my $aClient = $_[0]; my $aPath = $_[1]; @@ -238,16 +254,7 @@ sub handlePath { $manageChannelAccess.=""; } $manageChannelAccess.=""; - $manageChannelAccess.="
"; + $manageChannelAccess.=enumerateChannels($aConnection)."
"; $manageChannelAccess.=" "; $manageChannelAccess.=""; $manageChannelAccess.=""; @@ -274,6 +281,7 @@ sub handlePath { } my $addChannel = ""; + my $updateChannel = ""; if($privileges==2) { $addChannel.="

Add channel

"; $addChannel.="
"; @@ -290,9 +298,16 @@ sub handlePath { $addChannel.="Public
"; $addChannel.=""; $addChannel.="
"; + + $updateChannel.="

Update channel

"; + $updateChannel.="
"; + $updateChannel.=enumerateChannels($aConnection)."
"; + $updateChannel.="Public
"; + $updateChannel.=""; + $updateChannel.="
"; } - frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "addUser"=>$addUser, "addServer"=>$addServer, "addChannel"=>$addChannel}); + frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "addUser"=>$addUser, "addServer"=>$addServer, "addChannel"=>$addChannel, "updateChannel"=>$updateChannel}); return 1; } when("/change_password_action") { @@ -498,10 +513,6 @@ sub handlePath { frontend::sendBadRequest($aClient, "Server ID required"); return 1; } - if(!defined($parameters{"public"}) || length($parameters{"public"})==0) { - frontend::sendBadRequest($aClient, "Public required"); - return 1; - } my $query = $aConnection->prepare(qq(select name from servers where id=?;)); $query->execute($parameters{"server"}); @@ -530,13 +541,34 @@ sub handlePath { } $query = $aConnection->prepare(qq(insert into channels values($lastID, ?, ?, ?);)); - $query->execute($parameters{"server"}, $parameters{"channel"}, $parameters{"public"}); + $query->execute($parameters{"server"}, $parameters{"channel"}, defined($parameters{"public"})?1:0); my $actionQueue = logger::getActionQueueByServerName($serverName); push(@$actionQueue, "JOIN", $parameters{"channel"}); frontend::redirect($aClient, "/channel_added.html"); return 1; } + when("/update_channel_action") { + if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) { + return 1; + } + my %parameters = frontend::parsePathParameters($aRequest->{"content"}); + if(!defined($parameters{"channel"}) || length($parameters{"channel"})==0) { + frontend::sendBadRequest($aClient, "Channel required"); + return 1; + } + my $query = $aConnection->prepare(qq(select id from channels where id=?;)); + $query->execute($parameters{"channel"}); + my @row = $query->fetchrow_array(); + if(scalar(@row)==0) { + frontend::sendBadRequest($aClient, "Channel with ID $parameters{'channel'} doesn't exist"); + return 1; + } + $query = $aConnection->prepare(qq(update channels set public=? where id=?;)); + $query->execute(defined($parameters{"public"})?1:0, $parameters{"channel"}); + frontend::redirect($aClient, "/channel_updated.html"); + return 1; + } when("/view_logs") { my $channelID = $aRequest->{"path"}{"parameters"}{"channel"}; if(!defined($channelID)) { diff --git a/static/channel_updated.html b/static/channel_updated.html new file mode 100644 index 0000000..eabc2c8 --- /dev/null +++ b/static/channel_updated.html @@ -0,0 +1,10 @@ + + + + Channel updated + + +

Channel successfully updated

+ Return to user panel + + diff --git a/templates/panel.html b/templates/panel.html index cec7d74..f5c1337 100644 --- a/templates/panel.html +++ b/templates/panel.html @@ -16,5 +16,6 @@ {{addUser}} {{addServer}} {{addChannel}} + {{updateChannel}}