From 51138d1c41d9be15d64d42bd25a46758d360ae4e Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Fri, 11 Feb 2011 00:55:42 +0000 Subject: improved actions history --- .../Application/Controllers/LastController.php | 65 ++++++++++++++++++++ h-source/Application/Include/languages.php | 14 +++++ h-source/Application/Include/myFunctions.php | 69 +++++++++++----------- h-source/Application/Models/HardwareModel.php | 40 ++++++++++++- h-source/Application/Views/Last/modifications.php | 47 +++++++++++++++ 5 files changed, 201 insertions(+), 34 deletions(-) create mode 100644 h-source/Application/Controllers/LastController.php create mode 100644 h-source/Application/Views/Last/modifications.php (limited to 'h-source/Application') diff --git a/h-source/Application/Controllers/LastController.php b/h-source/Application/Controllers/LastController.php new file mode 100644 index 0000000..0791ccb --- /dev/null +++ b/h-source/Application/Controllers/LastController.php @@ -0,0 +1,65 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class LastController extends BaseController +{ + + public function __construct($model, $controller, $queryString) + { + parent::__construct($model, $controller, $queryString); + + $this->model('HistoryModel'); + + $data['title'] = 'last - '.Website::$generalName; + $this->append($data); + + $this->setArgKeys(array('page:forceNat'=>1)); + } + + public function modifications($lang = 'en') + { + $this->shift(1); + + $whereClauseArray = array( + 'gr' => 'registered', + 'type' => 'wiki', + ); + + $this->helper('Pages','last/modifications/'.$this->lang,'page'); + + $this->m['HistoryModel']->clear()->select()->where($whereClauseArray)->orderBy('id_history desc'); + + $recordNumber = $this->m['HistoryModel']->rowNumber(); + $page = $this->viewArgs['page']; + + $this->m['HistoryModel']->limit = $this->h['Pages']->getLimit($page,$recordNumber,30); + + $data['table'] = $this->m['HistoryModel']->send(); + + $data['pageList'] = $this->h['Pages']->render($page-5,11); + + $this->append($data); + $this->load('modifications'); + $this->right(); + } + +} \ No newline at end of file diff --git a/h-source/Application/Include/languages.php b/h-source/Application/Include/languages.php index 0e0959a..40014b0 100644 --- a/h-source/Application/Include/languages.php +++ b/h-source/Application/Include/languages.php @@ -167,6 +167,12 @@ class Lang "Download the xml file of all the webcams in the database" => "Scarica il file xml di tutte le webcams presenti nel database", "You can download all the h-node database in one unique xml file in order to parse its contents by means of some proper script (for example a Python or Perl or PHP script)" => "Puoi scaricare l'intero database di h-node in un unico file xml per analizzarne i contenuti utilizzando uno script appropriato (ad esempio uno script Python o Perl o PHP)", "Download the h-node hardware database in xml format" => "Scarica il database dell'hardware di h-node in formato xml", + "Database modifications" => "Modifiche al database", + "List of the database modifications carried out by users" => "Lista delle modifiche apportate al database dagli utenti", + "the model" => "il modello", + "has been inserted by" => "è stato inserito da", + "has been updated by" => "è stato modificato da", + "at" => "alle ore", ), 'es' => array ( @@ -460,6 +466,14 @@ class Go { return "http://".DOMAIN_NAME."/".Hardware::getControllerFromType($type)."/insert/".Lang::$current; } + + //go to the page of one device from the id of that device + public static function toHardwarePage($idHard = 0) + { + $clean['idHard'] = (int)$idHard; + $urls = getUrlsFromIdHard($clean['idHard']); + return $urls['urlView']; + } } class MyStrings diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index 483a85f..daefb59 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -95,40 +95,40 @@ function getOrderByClause($string) function diff($old, $new){ - $maxlen = 0; - foreach($old as $oindex => $ovalue){ + $maxlen = 0; + foreach($old as $oindex => $ovalue){ // $nkeys = getNewKeys($new,$ovalue); - $nkeys = array_keys($new, $ovalue); - foreach($nkeys as $nindex){ - $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? - $matrix[$oindex - 1][$nindex - 1] + 1 : 1; - if($matrix[$oindex][$nindex] > $maxlen){ - $maxlen = $matrix[$oindex][$nindex]; - $omax = $oindex + 1 - $maxlen; - $nmax = $nindex + 1 - $maxlen; - } - } - } - if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); - return array_merge( - diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), - array_slice($new, $nmax, $maxlen), - diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); + $nkeys = array_keys($new, $ovalue); + foreach($nkeys as $nindex){ + $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? + $matrix[$oindex - 1][$nindex - 1] + 1 : 1; + if($matrix[$oindex][$nindex] > $maxlen){ + $maxlen = $matrix[$oindex][$nindex]; + $omax = $oindex + 1 - $maxlen; + $nmax = $nindex + 1 - $maxlen; + } + } + } + if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); + return array_merge( + diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), + array_slice($new, $nmax, $maxlen), + diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } function htmlDiff($old, $new){ - $old = str_replace("\r\n"," \r\n ",$old); - $new = str_replace("\r\n"," \r\n ",$new); - - $ret = null; - $diff = diff(explode(' ', $old), explode(' ', $new)); - foreach($diff as $k){ - if(is_array($k)) - $ret .= (!empty($k['d'])?"".implode(' ',$k['d'])." ":''). - (!empty($k['i'])?"".implode(' ',$k['i'])." ":''); - else $ret .= $k . ' '; - } - return $ret; + $old = str_replace("\r\n"," \r\n ",$old); + $new = str_replace("\r\n"," \r\n ",$new); + + $ret = null; + $diff = diff(explode(' ', $old), explode(' ', $new)); + foreach($diff as $k){ + if(is_array($k)) + $ret .= (!empty($k['d'])?"".implode(' ',$k['d'])." ":''). + (!empty($k['i'])?"".implode(' ',$k['i'])." ":''); + else $ret .= $k . ' '; + } + return $ret; } @@ -457,16 +457,19 @@ function getUrlsFromIdHard($id_hard) $urlView = "http://".DOMAIN_NAME; $urlTalk = "http://".DOMAIN_NAME; + $deviceName = null; $hard = new HardwareModel(); $res = $hard->select('type,model')->where(array('id_hard'=>$clean['id_hard']))->send(); if (count($res) > 0) { - $urlView = "http://".DOMAIN_NAME."/".MyStrings::$reverse[$res[0]['hardware']['type']]."/view/".Lang::$current."/".$clean['id_hard']."/".encodeUrl($res[0]['hardware']['model']); + $urlView = "http://".DOMAIN_NAME."/".Hardware::$typeToController[$res[0]['hardware']['type']]."/view/".Lang::$current."/".$clean['id_hard']."/".encodeUrl($res[0]['hardware']['model']); - $urlTalk = "http://".DOMAIN_NAME."/".MyStrings::$reverse[$res[0]['hardware']['type']]."/talk/".Lang::$current."/".$clean['id_hard']; + $urlTalk = "http://".DOMAIN_NAME."/".Hardware::$typeToController[$res[0]['hardware']['type']]."/talk/".Lang::$current."/".$clean['id_hard']; + + $deviceName = $res[0]['hardware']['model']; } - return array('urlView'=>$urlView,'urlTalk'=>$urlTalk); + return array('urlView'=>$urlView,'urlTalk'=>$urlTalk,'modelName'=>$deviceName); } \ No newline at end of file diff --git a/h-source/Application/Models/HardwareModel.php b/h-source/Application/Models/HardwareModel.php index d4c9a47..150abc8 100644 --- a/h-source/Application/Models/HardwareModel.php +++ b/h-source/Application/Models/HardwareModel.php @@ -92,6 +92,9 @@ class HardwareModel extends Model_Map { $this->lastId = $clean['id']; $this->db->update('hardware','type',array($this->type),'id_hard='.$clean['id']); + //update the history table + $this->updateHistory('insert'); + $this->associate($clean['id']); } @@ -122,6 +125,10 @@ class HardwareModel extends Model_Map { if ($this->queryResult) { $this->lastId = $clean['id']; + + //update the history table + $this->updateHistory('update'); + if (!$this->checkAssociation($clean['id'],(int)$this->id_user)) { $this->associate($clean['id']); @@ -165,6 +172,10 @@ class HardwareModel extends Model_Map { if (parent::update($clean['id_hard'])) { $this->lastId = $clean['id_hard']; + + //update the history table + $this->updateHistory('update'); + if (!$this->checkAssociation($clean['id_hard'],(int)$this->id_user)) { $this->associate($clean['id_hard']); @@ -196,6 +207,33 @@ class HardwareModel extends Model_Map { return $name; } - + //save in the history all the action carried out by users + protected function updateHistory($action) + { + $translations = array( + 'insert' => 'inserted', + 'update' => 'updated', + ); + + $allowedActions = array('insert','update'); + + if (in_array($action,$allowedActions)) + { + $users = new UsersModel(); + + $clean['user'] = sanitizeAll($users->getUser($this->id_user)); + + $history = new HistoryModel(); + $history->values = array( + 'created_by' => $this->id_user, + 'type' => 'wiki', + 'action' => $action, + 'id' => $this->lastId, + 'message' => 'The device having id='.$this->lastId.' has been '.$translations[$action].' by the user ' . $clean['user'] . ' (id_user='.$this->id_user.') ', + 'gr' => 'registered', + ); + $history->insert(); + } + } } \ No newline at end of file diff --git a/h-source/Application/Views/Last/modifications.php b/h-source/Application/Views/Last/modifications.php new file mode 100644 index 0000000..1c8e8ea --- /dev/null +++ b/h-source/Application/Views/Last/modifications.php @@ -0,0 +1,47 @@ + + +. +?> + +
+ +
+ ">Home » +
+ +
+ +
+ +
+ +
+ +
+ : +
+ +
-- cgit v1.2.3