From 232aa1924c8c0f10d87b210b46c9f061af5c844c Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Sun, 17 Oct 2010 13:29:57 +0000 Subject: added files --- .../Application/Controllers/HistoryController.php | 185 +++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 h-source/Application/Controllers/HistoryController.php (limited to 'h-source/Application/Controllers/HistoryController.php') diff --git a/h-source/Application/Controllers/HistoryController.php b/h-source/Application/Controllers/HistoryController.php new file mode 100644 index 0000000..2d965ac --- /dev/null +++ b/h-source/Application/Controllers/HistoryController.php @@ -0,0 +1,185 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class HistoryController extends BaseController +{ + + protected $strings = array( + + 'hide' => array( + + 'action' => 'hide', + 'check_status' => 'no', + 'to_status' => 'yes', + 'exec_string' => 'The message has been hidden. Just reload the page', + 'error_string' => 'Error: the message is already hidden', + + ), + + 'show' => array( + + 'action' => 'show', + 'check_status' => 'yes', + 'to_status' => 'no', + 'exec_string' => 'The message is no more hidden. Just reload the page', + 'error_string' => 'Error: the message is already visible', + + ), + + ); + + protected $types = array( + + 'message' => array( + + 'clean_type' => 'message', + 'model_name' => 'MessagesModel', + 'id_name' => 'id_mes', + + ), + + 'talk' => array( + + 'clean_type' => 'talk', + 'model_name' => 'TalkModel', + 'id_name' => 'id_talk', + + ), + + ); + + public function __construct($model, $controller, $queryString) + { + parent::__construct($model, $controller, $queryString); + + $this->model('HistoryModel'); + + } + + public function hide($lang = 'en', $token = '') + { + $this->generic($lang, $token, 'hide'); + } + + public function show($lang = 'en', $token = '') + { + $this->generic($lang, $token, 'show'); + } + + protected function generic($lang = 'en', $token = '', $action = 'hide') + { + header('Content-type: text/html; charset=UTF-8'); + + $this->shift(2); + + $this->clean(); + + $clean['token'] = sanitizeAlphanum($token); + + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->ismoderator) + { + if (!$this->s['registered']->checkCsrf($clean['token'])) die("wrong token"); + + $clean['id_user'] = (int)$this->s['registered']->status['id_user']; + $clean['id'] = $this->request->post('id',0,'forceInt'); + $type = $this->request->post('type',0,'sanitizeAll'); + $message = $this->request->post('message',''); + + $modelName = 'error'; + + 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]; + + $count = $model->select()->where(array($clean['id_name'] => $clean['id'],'deleted' => $this->strings[$action]['check_status']))->rowNumber(); + + if ($count > 0) + { + if (eg_strlen($message) < 500) + { + //hide the message + $model->values = array('deleted' => $this->strings[$action]['to_status']); + $model->update($clean['id']); + + 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: the message has too many characters or wrong type"; + } + } + else + { + echo $this->strings[$action]['error_string']; + } + } + } + } + } + + public function viewall($lang = 'en', $type = 'message', $id = 0) + { + header('Content-type: text/html; charset=UTF-8'); + + $this->shift(3); + + $this->clean(); + + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->ismoderator) + { + $clean['id'] = (int)$id; + if (array_key_exists($type,$this->types)) + { + $clean['type'] = $this->types[$type]['clean_type']; + + $data['res'] = $this->m['HistoryModel']->select()->where(array('id'=>$clean['id'],'type'=>$clean['type']))->send(); + + $data['md_action'] = array('hide'=>'hidden','show'=>'restored'); + + $this->append($data); + $this->load('viewall'); + } + } + } + } + +} \ No newline at end of file -- cgit v1.2.3