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 +- 2 files changed, 98 insertions(+), 30 deletions(-) (limited to 'h-source/Application/Controllers') 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(); } -- cgit v1.2.3