aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Controllers/HistoryController.php
diff options
context:
space:
mode:
Diffstat (limited to 'h-source/Application/Controllers/HistoryController.php')
-rw-r--r--h-source/Application/Controllers/HistoryController.php117
1 files changed, 88 insertions, 29 deletions
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');
}