mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-16 09:04:11 +03:00
Create "BanController"
This commit is contained in:
parent
8969b71613
commit
3ea2da1ad2
@ -8,5 +8,5 @@
|
||||
(function(d,e){d.Views.QueuedThread=d.Views.CompositeBase.extend({template:e.templates.queued_thread,itemView:d.Views.Control,itemViewContainer:".thread-controls",className:"thread",modelEvents:{change:"render"},events:{"click .open-dialog":"openDialog","click .view-control":"viewDialog","click .track-control":"showTrack","click .ban-control":"showBan","click .geo-link":"showGeoInfo","click .first-message a":"showFirstMessage"},initialize:function(){this.lastStyles=[]},serializeData:function(){var a=
|
||||
this.model,b=d.Objects.Models.page,c=a.toJSON();c.stateDesc=this.stateToDesc(a.get("state"));c.chatting=a.get("state")==a.STATE_CHATTING;c.tracked=b.get("showVisitors");c.firstMessage&&(c.firstMessagePreview=30<c.firstMessage.length?c.firstMessage.substring(0,30)+"...":c.firstMessage);return c},stateToDesc:function(a){var b=d.Localization;return a==this.model.STATE_QUEUE?b.get("chat.thread.state_wait"):a==this.model.STATE_WAITING?b.get("chat.thread.state_wait_for_another_agent"):a==this.model.STATE_CHATTING?
|
||||
b.get("chat.thread.state_chatting_with_agent"):a==this.model.STATE_CLOSED?b.get("chat.thread.state_closed"):a==this.model.STATE_LOADING?b.get("chat.thread.state_loading"):""},showGeoInfo:function(){var a=this.model.get("userIp");if(a){var b=d.Objects.Models.page,c=b.get("geoLink").replace("{ip}",a);d.Popup.open(c,"ip"+a,b.get("geoWindowParams"))}},openDialog:function(){var a=this.model;if(a.get("canOpen")||a.get("canView"))a=!a.get("canOpen"),this.showDialogWindow(a)},viewDialog:function(){this.showDialogWindow(!0)},
|
||||
showDialogWindow:function(a){var b=this.model.id,c=d.Objects.Models.page;d.Popup.open(c.get("agentLink")+"?thread="+b+(a?"&viewonly=true":""),"ImCenter"+b,c.get("chatWindowParams"))},showTrack:function(){var a=this.model.id,b=d.Objects.Models.page;d.Popup.open(b.get("trackedLink")+"?thread="+a,"ImTracked"+a,b.get("trackedUserWindowParams"))},showBan:function(){var a=this.model,b=a.get("ban"),c=d.Objects.Models.page;d.Popup.open(c.get("banLink")+"?"+(!1!==b?"id="+b.id:"thread="+a.id),"ImBan"+b.id,
|
||||
c.get("banWindowParams"))},showFirstMessage:function(){var a=this.model.get("firstMessage");a&&alert(a)}})})(Mibew,Handlebars);
|
||||
showDialogWindow:function(a){var b=this.model.id,c=d.Objects.Models.page;d.Popup.open(c.get("agentLink")+"?thread="+b+(a?"&viewonly=true":""),"ImCenter"+b,c.get("chatWindowParams"))},showTrack:function(){var a=this.model.id,b=d.Objects.Models.page;d.Popup.open(b.get("trackedLink")+"?thread="+a,"ImTracked"+a,b.get("trackedUserWindowParams"))},showBan:function(){var a=this.model,b=a.get("ban"),c=d.Objects.Models.page;d.Popup.open(c.get("banLink")+"/"+(!1!==b?b.id+"/edit":"add?thread="+a.id),"ImBan"+
|
||||
b.id,c.get("banWindowParams"))},showFirstMessage:function(){var a=this.model.get("firstMessage");a&&alert(a)}})})(Mibew,Handlebars);
|
||||
|
@ -95,8 +95,8 @@ a,c);return c.field},updateVisitors:function(a){if(0==a.errorCode){var c;c=a.cur
|
||||
(function(d,e){d.Views.QueuedThread=d.Views.CompositeBase.extend({template:e.templates.queued_thread,itemView:d.Views.Control,itemViewContainer:".thread-controls",className:"thread",modelEvents:{change:"render"},events:{"click .open-dialog":"openDialog","click .view-control":"viewDialog","click .track-control":"showTrack","click .ban-control":"showBan","click .geo-link":"showGeoInfo","click .first-message a":"showFirstMessage"},initialize:function(){this.lastStyles=[]},serializeData:function(){var a=
|
||||
this.model,b=d.Objects.Models.page,c=a.toJSON();c.stateDesc=this.stateToDesc(a.get("state"));c.chatting=a.get("state")==a.STATE_CHATTING;c.tracked=b.get("showVisitors");c.firstMessage&&(c.firstMessagePreview=30<c.firstMessage.length?c.firstMessage.substring(0,30)+"...":c.firstMessage);return c},stateToDesc:function(a){var b=d.Localization;return a==this.model.STATE_QUEUE?b.get("chat.thread.state_wait"):a==this.model.STATE_WAITING?b.get("chat.thread.state_wait_for_another_agent"):a==this.model.STATE_CHATTING?
|
||||
b.get("chat.thread.state_chatting_with_agent"):a==this.model.STATE_CLOSED?b.get("chat.thread.state_closed"):a==this.model.STATE_LOADING?b.get("chat.thread.state_loading"):""},showGeoInfo:function(){var a=this.model.get("userIp");if(a){var b=d.Objects.Models.page,c=b.get("geoLink").replace("{ip}",a);d.Popup.open(c,"ip"+a,b.get("geoWindowParams"))}},openDialog:function(){var a=this.model;if(a.get("canOpen")||a.get("canView"))a=!a.get("canOpen"),this.showDialogWindow(a)},viewDialog:function(){this.showDialogWindow(!0)},
|
||||
showDialogWindow:function(a){var b=this.model.id,c=d.Objects.Models.page;d.Popup.open(c.get("agentLink")+"?thread="+b+(a?"&viewonly=true":""),"ImCenter"+b,c.get("chatWindowParams"))},showTrack:function(){var a=this.model.id,b=d.Objects.Models.page;d.Popup.open(b.get("trackedLink")+"?thread="+a,"ImTracked"+a,b.get("trackedUserWindowParams"))},showBan:function(){var a=this.model,b=a.get("ban"),c=d.Objects.Models.page;d.Popup.open(c.get("banLink")+"?"+(!1!==b?"id="+b.id:"thread="+a.id),"ImBan"+b.id,
|
||||
c.get("banWindowParams"))},showFirstMessage:function(){var a=this.model.get("firstMessage");a&&alert(a)}})})(Mibew,Handlebars);
|
||||
showDialogWindow:function(a){var b=this.model.id,c=d.Objects.Models.page;d.Popup.open(c.get("agentLink")+"?thread="+b+(a?"&viewonly=true":""),"ImCenter"+b,c.get("chatWindowParams"))},showTrack:function(){var a=this.model.id,b=d.Objects.Models.page;d.Popup.open(b.get("trackedLink")+"?thread="+a,"ImTracked"+a,b.get("trackedUserWindowParams"))},showBan:function(){var a=this.model,b=a.get("ban"),c=d.Objects.Models.page;d.Popup.open(c.get("banLink")+"/"+(!1!==b?b.id+"/edit":"add?thread="+a.id),"ImBan"+
|
||||
b.id,c.get("banWindowParams"))},showFirstMessage:function(){var a=this.model.get("firstMessage");a&&alert(a)}})})(Mibew,Handlebars);
|
||||
/*
|
||||
Copyright 2005-2014 the original author or authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License").
|
||||
|
@ -218,10 +218,10 @@
|
||||
// Open ban window
|
||||
Mibew.Popup.open(
|
||||
page.get('banLink')
|
||||
+ '?'
|
||||
+ '/'
|
||||
+ (ban !== false
|
||||
? 'id='+ban.id
|
||||
: 'thread='+ thread.id),
|
||||
? ban.id + '/edit'
|
||||
: 'add?thread='+ thread.id),
|
||||
'ImBan' + ban.id,
|
||||
page.get('banWindowParams')
|
||||
);
|
||||
|
263
src/mibew/libs/classes/Mibew/Controller/BanController.php
Normal file
263
src/mibew/libs/classes/Mibew/Controller/BanController.php
Normal file
@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\Controller;
|
||||
|
||||
use Mibew\Database;
|
||||
use Mibew\Http\Exception\BadRequestException;
|
||||
use Mibew\Http\Exception\NotFoundException;
|
||||
use Mibew\Thread;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Contains all actions which are related with banned visitors.
|
||||
*/
|
||||
class BanController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Generates list of all banned visitors in the system.
|
||||
*
|
||||
* @param Request $request Incoming request.
|
||||
* @return string Rendered page content.
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
set_csrf_token();
|
||||
setlocale(LC_TIME, getstring('time.locale'));
|
||||
|
||||
$operator = $request->attributes->get('_operator');
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
// Prepare list of all banned visitors
|
||||
$db = Database::getInstance();
|
||||
$blocked_list = $db->query(
|
||||
"SELECT banid, dtmtill AS till, address, comment FROM {chatban}",
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
foreach ($blocked_list as &$item) {
|
||||
$item['comment'] = $item['comment'];
|
||||
}
|
||||
unset($item);
|
||||
|
||||
$page['title'] = getlocal('page_bans.title');
|
||||
$page['menuid'] = 'bans';
|
||||
$pagination = setup_pagination($blocked_list);
|
||||
$page['pagination'] = $pagination['info'];
|
||||
$page['pagination.items'] = $pagination['items'];
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
return $this->render('bans', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a ban from the database.
|
||||
*
|
||||
* @param Request $request Incoming request.
|
||||
* @return string Rendered page content.
|
||||
*/
|
||||
public function deleteAction(Request $request)
|
||||
{
|
||||
csrf_check_token($request);
|
||||
|
||||
$ban_id = $request->attributes->getInt('ban_id');
|
||||
|
||||
// Remove ban from database
|
||||
$db = Database::getInstance();
|
||||
$db->query("DELETE FROM {chatban} WHERE banid = ?", array($ban_id));
|
||||
|
||||
// Redirect the current operator to page with bans list
|
||||
return $this->redirect($this->generateUrl('bans'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a page with form for add/edit ban.
|
||||
*
|
||||
* @param Request $request Incoming request.
|
||||
* @return string Rendered page content.
|
||||
* @throws NotFoundException If the ban with specified ID is not found in
|
||||
* the system.
|
||||
* @throws BadRequestException If "thread" GET param is specified but has a
|
||||
* wrong format.
|
||||
*/
|
||||
public function showEditFormAction(Request $request)
|
||||
{
|
||||
set_csrf_token();
|
||||
|
||||
$operator = $request->attributes->get('_operator');
|
||||
|
||||
$page = array(
|
||||
'banId' => '',
|
||||
'saved' => false,
|
||||
'thread' => '',
|
||||
'threadid' => '',
|
||||
// Use errors list stored in the request. We need to do so to have
|
||||
// an ability to pass the request from the "submitEditForm" action.
|
||||
'errors' => $request->attributes->get('errors', array()),
|
||||
);
|
||||
|
||||
if ($request->attributes->has('ban_id')) {
|
||||
$ban_id = $request->attributes->getInt('ban_id');
|
||||
|
||||
// Retrieve ban information from the database
|
||||
$db = Database::getInstance();
|
||||
$ban = $db->query(
|
||||
("SELECT banid, (dtmtill - :now) AS days, address, comment "
|
||||
. "FROM {chatban} WHERE banid = :banid"),
|
||||
array(
|
||||
':banid' => $ban_id,
|
||||
':now' => time(),
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
if (!$ban) {
|
||||
throw new NotFoundException('The ban is not found.');
|
||||
}
|
||||
|
||||
$page['banId'] = $ban['banid'];
|
||||
$page['formaddress'] = $ban['address'];
|
||||
$page['formdays'] = round($ban['days'] / 86400);
|
||||
$page['formcomment'] = $ban['comment'];
|
||||
} elseif ($request->query->has('thread')) {
|
||||
// Prepopulate form using thread data
|
||||
$thread_id = $request->query->has('thread');
|
||||
if (!preg_match("/^\d{1,10}$/", $thread_id)) {
|
||||
throw new BadRequestException('Wrong value of "thread" argument.');
|
||||
}
|
||||
|
||||
$thread = Thread::load($thread_id);
|
||||
if ($thread) {
|
||||
$page['thread'] = htmlspecialchars($thread->userName);
|
||||
$page['threadid'] = $thread_id;
|
||||
$page['formaddress'] = $thread->remote;
|
||||
$page['formdays'] = 15;
|
||||
}
|
||||
}
|
||||
|
||||
// Override form fields from the request if it is needed
|
||||
if ($request->isMethod('POST')) {
|
||||
$page['formaddress'] = $request->request->get('address');
|
||||
$page['formdays'] = $request->request->get('days');
|
||||
$page['formcomment'] = $request->request->get('comment');
|
||||
$page['threadid'] = $request->request->get('threadid');
|
||||
}
|
||||
|
||||
$page['title'] = getlocal('page_ban.title');
|
||||
$page['formaction'] = $request->getBaseUrl() . $request->getPathInfo();
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
return $this->render('ban', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes submitting of the form which is generated in
|
||||
* {@link \Mibew\Controller\BanController::showEditFormAction()} method.
|
||||
*
|
||||
* @param Request $request Incoming request.
|
||||
* @return string Rendered page content.
|
||||
*/
|
||||
public function submitEditFormAction(Request $request)
|
||||
{
|
||||
csrf_check_token($request);
|
||||
|
||||
$operator = $request->attributes->get('_operator');
|
||||
$errors = array();
|
||||
|
||||
$page = array(
|
||||
'banId' => '',
|
||||
'saved' => false,
|
||||
);
|
||||
|
||||
// Get form fields and validate them
|
||||
$ban_id = $request->attributes->getInt('ban_id');
|
||||
$address = $request->request->get('address');
|
||||
$days = $request->request->get('days');
|
||||
$comment = $request->request->get('comment');
|
||||
|
||||
if (!$address) {
|
||||
$errors[] = no_field('form.field.address');
|
||||
}
|
||||
|
||||
if (!preg_match("/^\d+$/", $days)) {
|
||||
$errors[] = wrong_field('form.field.ban_days');
|
||||
}
|
||||
|
||||
if (!$comment) {
|
||||
$errors[] = no_field('form.field.ban_comment');
|
||||
}
|
||||
|
||||
// Check if the ban already exists in the database
|
||||
$existing_ban = ban_for_addr($address);
|
||||
$ban_duplicate = (!$ban_id && $existing_ban)
|
||||
|| ($ban_id && $existing_ban && $ban_id != $existing_ban['banid']);
|
||||
|
||||
if ($ban_duplicate) {
|
||||
$ban_url = $this->generateUrl(
|
||||
'ban_edit',
|
||||
array('ban_id' => $existing_ban['banid'])
|
||||
);
|
||||
$errors[] = getlocal2('ban.error.duplicate', array($address, $ban_url));
|
||||
}
|
||||
|
||||
if (count($errors) != 0) {
|
||||
$request->attributes->set('errors', $errors);
|
||||
|
||||
// The form should be rebuild. Invoke appropriate action.
|
||||
return $this->showEditFormAction($request);
|
||||
}
|
||||
|
||||
// Save ban into the database
|
||||
$db = Database::getInstance();
|
||||
$now = time();
|
||||
$till_time = $now + $days * 24 * 60 * 60;
|
||||
if (!$ban_id) {
|
||||
$db->query(
|
||||
("INSERT INTO {chatban} (dtmcreated, dtmtill, address, comment) "
|
||||
. "VALUES (:now,:till,:address,:comment)"),
|
||||
array(
|
||||
':now' => $now,
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$db->query(
|
||||
("UPDATE {chatban} SET dtmtill = :till, address = :address, "
|
||||
. "comment = :comment WHERE banid = :banid"),
|
||||
array(
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
':banid' => $ban_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Rerender the form page
|
||||
$page['saved'] = true;
|
||||
$page['address'] = $address;
|
||||
$page['title'] = getlocal('page_ban.title');
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
return $this->render('ban', $page);
|
||||
}
|
||||
}
|
@ -13,6 +13,53 @@ widget_gateway:
|
||||
|
||||
# Operators' pages
|
||||
|
||||
## Banned visitors
|
||||
ban_add:
|
||||
path: /operator/ban/add
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::showEditFormAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
methods: [GET]
|
||||
|
||||
ban_add_save:
|
||||
path: /operator/ban/add
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::submitEditFormAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
methods: [POST]
|
||||
|
||||
ban_delete:
|
||||
path: /operator/ban/{ban_id}/delete
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::deleteAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
requirements:
|
||||
ban_id: \d{1,10}
|
||||
|
||||
ban_edit:
|
||||
path: /operator/ban/{ban_id}/edit
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::showEditFormAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
requirements:
|
||||
ban_id: \d{1,10}
|
||||
methods: [GET]
|
||||
|
||||
ban_edit_save:
|
||||
path: /operator/ban/{ban_id}/edit
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::submitEditFormAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
requirements:
|
||||
ban_id: \d{1,10}
|
||||
methods: [POST]
|
||||
|
||||
bans:
|
||||
path: /operator/ban
|
||||
defaults:
|
||||
_controller: Mibew\Controller\BanController::indexAction
|
||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||
|
||||
## Canned messages
|
||||
canned_message_add:
|
||||
path: /operator/canned-message/add
|
||||
|
@ -5,7 +5,7 @@ admin.content.description=Functions available for site operators.
|
||||
agent.not_logged_in=Your session has expired. Please login again
|
||||
app.descr=Mibew Messenger is an open-source live support application.
|
||||
app.title=Mibew Messenger
|
||||
ban.error.duplicate=The specified address is already in use. Click <a href="ban.php?id={1}">here</a> if you want to edit it.
|
||||
ban.error.duplicate=The specified address is already in use. Click <a href="{1}">here</a> if you want to edit it.
|
||||
button.delete=Delete
|
||||
button.enter=Enter
|
||||
button.offline.bottom=Leave your message
|
||||
|
@ -1,134 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Database;
|
||||
use Mibew\Thread;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrf_check_token();
|
||||
$page = array('banId' => '');
|
||||
$page['saved'] = false;
|
||||
$page['thread'] = '';
|
||||
$page['threadid'] = '';
|
||||
$page['errors'] = array();
|
||||
|
||||
if (isset($_POST['address'])) {
|
||||
$ban_id = verify_param("banId", "/^(\d{1,9})?$/", "");
|
||||
$address = get_param("address");
|
||||
$days = get_param("days");
|
||||
$comment = get_param('comment');
|
||||
$thread_id = isset($_POST['threadid']) ? get_param('threadid') : "";
|
||||
|
||||
if (!$address) {
|
||||
$page['errors'][] = no_field("form.field.address");
|
||||
}
|
||||
|
||||
if (!preg_match("/^\d+$/", $days)) {
|
||||
$page['errors'][] = wrong_field("form.field.ban_days");
|
||||
}
|
||||
|
||||
if (!$comment) {
|
||||
$page['errors'][] = no_field("form.field.ban_comment");
|
||||
}
|
||||
|
||||
$existing_ban = ban_for_addr($address);
|
||||
|
||||
if ((!$ban_id && $existing_ban) ||
|
||||
($ban_id && $existing_ban && $ban_id != $existing_ban['banid'])) {
|
||||
$page['errors'][] = getlocal2("ban.error.duplicate", array($address, $existing_ban['banid']));
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$now = time();
|
||||
$till_time = $now + $days * 24 * 60 * 60;
|
||||
if (!$ban_id) {
|
||||
$db->query(
|
||||
("INSERT INTO {chatban} (dtmcreated, dtmtill, address, comment) "
|
||||
. "VALUES (:now,:till,:address,:comment)"),
|
||||
array(
|
||||
':now' => $now,
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$db->query(
|
||||
("UPDATE {chatban} SET dtmtill = :till, address = :address, "
|
||||
. "comment = :comment WHERE banid = :banid"),
|
||||
array(
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
':banid' => $ban_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$page['saved'] = true;
|
||||
$page['address'] = $address;
|
||||
} else {
|
||||
$page['banId'] = $ban_id;
|
||||
$page['formaddress'] = $address;
|
||||
$page['formdays'] = $days;
|
||||
$page['formcomment'] = $comment;
|
||||
$page['threadid'] = $thread_id;
|
||||
}
|
||||
} elseif (isset($_GET['id'])) {
|
||||
$ban_id = verify_param('id', "/^\d{1,9}$/");
|
||||
$db = Database::getInstance();
|
||||
$ban = $db->query(
|
||||
("SELECT banid, (dtmtill - :now) AS days, address, comment "
|
||||
. "FROM {chatban} WHERE banid = :banid"),
|
||||
array(
|
||||
':banid' => $ban_id,
|
||||
':now' => time(),
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
if ($ban) {
|
||||
$page['banId'] = $ban['banid'];
|
||||
$page['formaddress'] = $ban['address'];
|
||||
$page['formdays'] = round($ban['days'] / 86400);
|
||||
$page['formcomment'] = $ban['comment'];
|
||||
} else {
|
||||
$page['errors'][] = "Wrong id";
|
||||
}
|
||||
} elseif (isset($_GET['thread'])) {
|
||||
$thread_id = verify_param('thread', "/^\d{1,9}$/");
|
||||
$thread = Thread::load($thread_id);
|
||||
if ($thread) {
|
||||
$page['thread'] = htmlspecialchars($thread->userName);
|
||||
$page['threadid'] = $thread_id;
|
||||
$page['formaddress'] = $thread->remote;
|
||||
$page['formdays'] = 15;
|
||||
}
|
||||
}
|
||||
|
||||
$page['title'] = getlocal("page_ban.title");
|
||||
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::getCurrentStyle());
|
||||
$page_style->render('ban', $page);
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
setlocale(LC_TIME, getstring("time.locale"));
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
if (isset($_GET['act']) && $_GET['act'] == 'del') {
|
||||
$ban_id = isset($_GET['id']) ? $_GET['id'] : "";
|
||||
|
||||
if (!preg_match("/^\d+$/", $ban_id)) {
|
||||
$page['errors'][] = "Cannot delete: wrong argument";
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db->query("DELETE FROM {chatban} WHERE banid = ?", array($ban_id));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/blocked.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$blocked_list = $db->query(
|
||||
"SELECT banid, dtmtill AS till,address,comment FROM {chatban}",
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
foreach ($blocked_list as &$item) {
|
||||
$item['comment'] = $item['comment'];
|
||||
}
|
||||
unset($item);
|
||||
|
||||
$page['title'] = getlocal("page_bans.title");
|
||||
$page['menuid'] = "blocked";
|
||||
|
||||
$pagination = setup_pagination($blocked_list);
|
||||
$page['pagination'] = $pagination['info'];
|
||||
$page['pagination.items'] = $pagination['items'];
|
||||
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::getCurrentStyle());
|
||||
$page_style->render('blocked_visitors', $page);
|
@ -19,7 +19,7 @@
|
||||
<li{{#ifEqual menuid "statistics"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/statistics">{{l10n "statistics.title"}}</a></li>
|
||||
{{/if}}
|
||||
{{#if showban}}
|
||||
<li{{#ifEqual menuid "blocked"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/blocked.php">{{l10n "menu.blocked"}}</a></li>
|
||||
<li{{#ifEqual menuid "bans"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/ban">{{l10n "menu.blocked"}}</a></li>
|
||||
{{/if}}
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -22,9 +22,8 @@
|
||||
<br/>
|
||||
{{/if}}
|
||||
|
||||
<form name="banForm" method="post" action="{{mibewRoot}}/operator/ban.php">
|
||||
<form name="banForm" method="post" action="{{formaction}}">
|
||||
{{csrfTokenInput}}
|
||||
<input type="hidden" name="banId" value="{{banId}}"/>
|
||||
|
||||
{{#if threadid}}
|
||||
<input type="hidden" name="threadid" value="{{threadid}}"/>
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
<div class="tabletool">
|
||||
<img src="{{stylePath}}/images/buttons/createban.gif" border="0" alt=""/>
|
||||
<a href="{{mibewRoot}}/operator/ban.php" title="{{l10n "page_bans.add"}}"
|
||||
onclick="this.newWindow = window.open('{{mibewRoot}}/operator/ban.php', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">{{l10n "page_bans.add"}}</a>
|
||||
<a href="{{mibewRoot}}/operator/ban/add" title="{{l10n "page_bans.add"}}"
|
||||
onclick="this.newWindow = window.open('{{mibewRoot}}/operator/ban/add', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">{{l10n "page_bans.add"}}</a>
|
||||
</div>
|
||||
<br clear="all"/>
|
||||
|
||||
@ -56,11 +56,11 @@
|
||||
<td>{{cutString comment "30"}}</td>
|
||||
|
||||
<td>
|
||||
<a class="removelink" id="i{{banid}}" href="{{../mibewRoot}}/operator/blocked.php?act=del&id={{banid}}&{{csrfTokenInUrl}}">
|
||||
<a class="removelink" id="i{{banid}}" href="{{../mibewRoot}}/operator/ban/{{banid}}/delete?{{csrfTokenInUrl}}">
|
||||
{{l10n "remove.item"}}
|
||||
</a>,
|
||||
<a href="{{../mibewRoot}}/operator/ban.php?id={{banid}}"
|
||||
onclick="this.newWindow = window.open('{{../mibewRoot}}/operator/ban.php?id={{banid}}', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">{{l10n "edit.item"}}</a>
|
||||
<a href="{{../mibewRoot}}/operator/ban/{{banid}}/edit"
|
||||
onclick="this.newWindow = window.open('{{../mibewRoot}}/operator/ban/{{banid}}/edit', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">{{l10n "edit.item"}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
@ -62,7 +62,7 @@
|
||||
<div class="dashitem">
|
||||
<div class="dashitem-content">
|
||||
<img src="{{stylePath}}/images/dash/blocked.gif" alt=""/>
|
||||
<a href="{{mibewRoot}}/operator/blocked.php">
|
||||
<a href="{{mibewRoot}}/operator/ban">
|
||||
{{l10n "menu.blocked"}}
|
||||
</a>
|
||||
{{l10n "content.blocked"}}
|
||||
|
@ -101,7 +101,7 @@
|
||||
agentLink: "{{mibewRoot}}/operator/agent.php",
|
||||
geoLink: "{{geoLink}}",
|
||||
trackedLink: "{{mibewRoot}}/operator/history/user-track",
|
||||
banLink: "{{mibewRoot}}/operator/ban.php",
|
||||
banLink: "{{mibewRoot}}/operator/ban",
|
||||
inviteLink: "{{mibewRoot}}/operator/invite",
|
||||
|
||||
chatWindowParams: "{{[chatStyles.chatWindowParams]}}",
|
||||
|
Loading…
Reference in New Issue
Block a user