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.php185
1 files changed, 185 insertions, 0 deletions
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 @@
+<?php
+
+// h-source, a web software to build a community of people that want to share their hardware information.
+// Copyright (C) 2010 Antonio Gallo (h-source-copyright.txt)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+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