From 049e37619a1ea7de4eed2695139645d6d6b9f397 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Mon, 1 Nov 2010 20:42:44 +0000 Subject: moderators can now block/unblock users - part 1 --- .../Application/Controllers/HistoryController.php | 117 ++++++++++++++++----- .../Application/Controllers/MeetController.php | 11 +- h-source/Application/Models/UsersModel.php | 16 ++- h-source/Application/Views/History/viewall.php | 8 +- h-source/Application/Views/Meet/meet.php | 25 ++++- h-source/Config/Route.php | 2 + h-source/Public/Css/website.css | 25 ++++- h-source/Public/Img/H2O/im-ban-user.png | Bin 0 -> 1258 bytes h-source/Public/Img/H2O/im-user.png | Bin 0 -> 1109 bytes h-source/tables.sql | 1 + 10 files changed, 166 insertions(+), 39 deletions(-) create mode 100755 h-source/Public/Img/H2O/im-ban-user.png create mode 100755 h-source/Public/Img/H2O/im-user.png diff --git a/h-source/Application/Controllers/HistoryController.php b/h-source/Application/Controllers/HistoryController.php index 7250fb0..7702ac9 100644 --- a/h-source/Application/Controllers/HistoryController.php +++ b/h-source/Application/Controllers/HistoryController.php @@ -45,6 +45,26 @@ class HistoryController extends BaseController ), + 'block' => array( + + 'action' => 'block', + 'check_status' => 'no', + 'to_status' => 'yes', + 'exec_string' => 'The user has been blocked. Just reload the page', + 'error_string' => 'Error: the user is already blocked', + + ), + + 'unblock' => array( + + 'action' => 'unblock', + 'check_status' => 'yes', + 'to_status' => 'no', + 'exec_string' => 'The user is no more blocked. Just reload the page', + 'error_string' => 'Error: the user is already un-blocked', + + ), + ); protected $types = array( @@ -54,6 +74,8 @@ class HistoryController extends BaseController 'clean_type' => 'message', 'model_name' => 'MessagesModel', 'id_name' => 'id_mes', + 'field_name' => 'deleted', + 'actions' => array('hide','show'), ), @@ -62,6 +84,18 @@ class HistoryController extends BaseController 'clean_type' => 'talk', 'model_name' => 'TalkModel', 'id_name' => 'id_talk', + 'field_name' => 'deleted', + 'actions' => array('hide','show'), + + ), + + 'user' => array( + + 'clean_type' => 'user', + 'model_name' => 'UsersModel', + 'id_name' => 'id_user', + 'field_name' => 'blocked', + 'actions' => array('block','unblock'), ), @@ -85,6 +119,16 @@ class HistoryController extends BaseController $this->generic($lang, $token, 'show'); } + public function block($lang = 'en', $token = '') + { + $this->generic($lang, $token, 'block'); + } + + public function unblock($lang = 'en', $token = '') + { + $this->generic($lang, $token, 'unblock'); + } + protected function generic($lang = 'en', $token = '', $action = 'hide') { header('Content-type: text/html; charset=UTF-8'); @@ -110,47 +154,51 @@ class HistoryController extends BaseController if (array_key_exists($type,$this->types)) { - $modelName = $this->types[$type]['model_name']; - $clean['type'] = $this->types[$type]['clean_type']; - $clean['id_name'] = $this->types[$type]['id_name']; - - //load the right model - $this->model($modelName); - $model = $this->m[$modelName]; + if (in_array($action,$this->types[$type]['actions'])) + { + $modelName = $this->types[$type]['model_name']; + $clean['type'] = $this->types[$type]['clean_type']; + $clean['id_name'] = $this->types[$type]['id_name']; + $clean['field_name'] = $this->types[$type]['field_name']; + + //load the right model + $this->model($modelName); + $model = $this->m[$modelName]; - $count = $model->select()->where(array($clean['id_name'] => $clean['id'],'deleted' => $this->strings[$action]['check_status']))->rowNumber(); + $count = $model->select()->where(array($clean['id_name'] => $clean['id'],$clean['field_name'] => $this->strings[$action]['check_status']))->rowNumber(); - if ($count > 0) - { - if (eg_strlen($message) < 500) + if ($count > 0) { - //hide the message - $model->values = array('deleted' => $this->strings[$action]['to_status']); - $model->update($clean['id']); - - if ($model->queryResult) + if (eg_strlen($message) < 500) { - $this->m['HistoryModel']->setFields('id:forceInt,type,message','sanitizeAll'); - $this->m['HistoryModel']->values['created_by'] = $clean['id_user']; - $this->m['HistoryModel']->values['action'] = $this->strings[$action]['action']; - $this->m['HistoryModel']->updateTable('insert'); + //hide the message + $model->values = array($clean['field_name'] => $this->strings[$action]['to_status']); + $model->update($clean['id']); - echo $this->strings[$action]['exec_string']; + if ($model->queryResult) + { + $this->m['HistoryModel']->setFields('id:forceInt,type,message','sanitizeAll'); + $this->m['HistoryModel']->values['created_by'] = $clean['id_user']; + $this->m['HistoryModel']->values['action'] = $this->strings[$action]['action']; + $this->m['HistoryModel']->updateTable('insert'); + + echo $this->strings[$action]['exec_string']; + } + else + { + echo "error: one error occurred, please retry later"; + } } else { - echo "error: one error occurred, please retry later"; + echo "error: the message has too many characters or wrong type"; } } else { - echo "error: the message has too many characters or wrong type"; + echo $this->strings[$action]['error_string']; } } - else - { - echo $this->strings[$action]['error_string']; - } } } } @@ -173,10 +221,21 @@ class HistoryController extends BaseController { $clean['type'] = $this->types[$type]['clean_type']; - $data['res'] = $this->m['HistoryModel']->select()->where(array('id'=>$clean['id'],'type'=>$clean['type']))->send(); + switch ($clean['type']) { + case 'user': + $data['object'] = 'user'; + $data['box_class'] = 'details_of_actions_inner_user'; + break; + default: + $data['object'] = 'message'; + $data['box_class'] = 'details_of_actions_inner'; + break; + } - $data['md_action'] = array('hide'=>'hidden','show'=>'restored'); + $data['res'] = $this->m['HistoryModel']->select()->where(array('id'=>$clean['id'],'type'=>$clean['type']))->send(); + $data['md_action'] = array('hide'=>'hidden','show'=>'restored','block'=>'blocked','unblock'=>'un-blocked'); + $this->append($data); $this->load('viewall'); } diff --git a/h-source/Application/Controllers/MeetController.php b/h-source/Application/Controllers/MeetController.php index 416b5dd..72e9006 100644 --- a/h-source/Application/Controllers/MeetController.php +++ b/h-source/Application/Controllers/MeetController.php @@ -75,14 +75,23 @@ class MeetController extends BaseController if ($this->userExists($clean['user'])) { + $clean['id_user'] = (int)$this->m['UsersModel']->getUserId($clean['user']); + $data['meet_id_user'] = $clean['id_user']; + + $data['isBlocked'] = $this->m['UsersModel']->isBlocked($clean['id_user']); + $this->whereArray['username'] = $clean['user']; $data['table'] = $this->m['ProfileModel']->select('regusers.e_mail,regusers.username,profile.*')->from('regusers inner join profile')->on('regusers.id_user = profile.created_by')->where($this->whereArray)->send(); $data['meet_username'] = $clean['user']; - + +// javascript for moderator + $data['md_javascript'] = "moderator_dialog(\"block\",\"user\");moderator_dialog(\"unblock\",\"user\");"; + $this->append($data); $this->load('meet'); + $this->load('moderator_dialog'); $this->right(); } diff --git a/h-source/Application/Models/UsersModel.php b/h-source/Application/Models/UsersModel.php index 27fc02a..a7c3845 100755 --- a/h-source/Application/Models/UsersModel.php +++ b/h-source/Application/Models/UsersModel.php @@ -89,7 +89,7 @@ class UsersModel extends Model_Map } //get the user id from the username - public function getUserId($username) + public function getUserId($username = '') { $clean['username'] = ctype_alnum($username) ? sanitizeAll($username) : ''; @@ -104,6 +104,20 @@ class UsersModel extends Model_Map } } + public function isBlocked($idUser) + { + $clean['id_user'] = (int)$idUser; + + $res = $this->select('blocked')->where(array('id_user'=>$clean['id_user'],'has_confirmed'=>0,'deleted'=>'no'))->toList('blocked')->send(); + + if (count($res) > 0) + { + return strcmp($res[0],'yes') === 0 ? true : false; + } + + return true; + } + public function insert() { //create the token diff --git a/h-source/Application/Views/History/viewall.php b/h-source/Application/Views/History/viewall.php index 948a63d..9dc27c6 100644 --- a/h-source/Application/Views/History/viewall.php +++ b/h-source/Application/Views/History/viewall.php @@ -26,15 +26,15 @@ foreach ($res as $row) { $mess_count++; ?> -
-
this message has been by getUser($row['history']['created_by']));?> at with the following motivation: +
+
this has been by getUser($row['history']['created_by']));?> at with the following motivation:
-
+
-
+
there are no details..
\ No newline at end of file diff --git a/h-source/Application/Views/Meet/meet.php b/h-source/Application/Views/Meet/meet.php index 127fe86..82b3d90 100644 --- a/h-source/Application/Views/Meet/meet.php +++ b/h-source/Application/Views/Meet/meet.php @@ -25,7 +25,30 @@
">Home » meet
- + + +
+ + This user has been blocked + + ">unblock the user + + + + ">block the user + + + + +
+
user
+ ">view details +
+
+ +
+ + diff --git a/h-source/Config/Route.php b/h-source/Config/Route.php index 3cde053..145947e 100644 --- a/h-source/Config/Route.php +++ b/h-source/Config/Route.php @@ -97,6 +97,8 @@ class Route 'download,threegcards', 'history,hide', 'history,show', + 'history,block', + 'history,unblock', 'history,viewall', 'threegcards,catalogue', 'threegcards,view', diff --git a/h-source/Public/Css/website.css b/h-source/Public/Css/website.css index 01e35c9..0f50c7d 100755 --- a/h-source/Public/Css/website.css +++ b/h-source/Public/Css/website.css @@ -1325,7 +1325,7 @@ ins width:500px; } -.hide_general +.hide_general, .block_general { float:right; margin-left:10px; @@ -1338,6 +1338,11 @@ ins margin-right:5px; margin-bottom:-2px; } +.block_general img +{ + margin-right:5px; + margin-bottom:-5px; +} .language_links_box ul { overflow:hidden; @@ -1394,7 +1399,7 @@ ins { display:none; } -.details_of_hidden_message_inner, .details_of_actions_inner +.details_of_hidden_message_inner, .details_of_actions_inner, .details_of_actions_inner_user { margin:10px 0px; background:#fbfbfb; @@ -1406,7 +1411,11 @@ ins background:#ecfffe; border:1px solid #7ed0cb; } - +.details_of_actions_inner_user +{ +/* background:#F6EA99; */ +/* border:1px solid #F65637; */ +} .md_type { display:none; @@ -1445,4 +1454,14 @@ ins background:#F1D8D8; border-bottom:1px solid #DC143C; border-top:1px solid #DC143C; +} + +.moderator_box +{ + overflow:hidden; +/* height:20px; */ + padding:10px; + margin:5px 5px 25px 5px; + background:#fbd59a; + border:1px solid #f65637; } \ No newline at end of file diff --git a/h-source/Public/Img/H2O/im-ban-user.png b/h-source/Public/Img/H2O/im-ban-user.png new file mode 100755 index 0000000..3771291 Binary files /dev/null and b/h-source/Public/Img/H2O/im-ban-user.png differ diff --git a/h-source/Public/Img/H2O/im-user.png b/h-source/Public/Img/H2O/im-user.png new file mode 100755 index 0000000..69de2e4 Binary files /dev/null and b/h-source/Public/Img/H2O/im-user.png differ diff --git a/h-source/tables.sql b/h-source/tables.sql index 4489477..ae0d1c1 100644 --- a/h-source/tables.sql +++ b/h-source/tables.sql @@ -28,6 +28,7 @@ create table regusers ( creation_time INT UNSIGNED NOT NULL, temp_field CHAR(32) NOT NULL, deleted CHAR(4) NOT NULL default 'no', + blocked CHAR(4) NOT NULL default 'no', forgot_token CHAR(32) NOT NULL, forgot_time INT UNSIGNED NOT NULL, unique(username), -- cgit v1.2.3