diff options
Diffstat (limited to 'h-source/Application')
| -rw-r--r-- | h-source/Application/Controllers/LastController.php | 65 | ||||
| -rw-r--r-- | h-source/Application/Include/languages.php | 14 | ||||
| -rw-r--r-- | h-source/Application/Include/myFunctions.php | 69 | ||||
| -rw-r--r-- | h-source/Application/Models/HardwareModel.php | 40 | ||||
| -rw-r--r-- | h-source/Application/Views/Last/modifications.php | 47 | 
5 files changed, 201 insertions, 34 deletions
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 @@ +<?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 file is part of h-source +// +// h-source 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. +//  +// h-source 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 h-source.  If not, see <http://www.gnu.org/licenses/>. + +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 <b>webcams</b> in the database"	=>	"Scarica il file xml di tutte le <b>webcams</b> 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'])?"<del>".implode(' ',$k['d'])."</del> ":''). -                                (!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":''); -                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'])?"<del>".implode(' ',$k['d'])."</del> ":''). +							(!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":''); +			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 @@ +<?php if (!defined('EG')) die('Direct access not allowed!'); ?> + +<?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 file is part of h-source +// +// h-source 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. +//  +// h-source 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 h-source.  If not, see <http://www.gnu.org/licenses/>. +?> + +	<div id="left"> +		 +		<div class="position_tree_box"> +			<a href="<?php echo $this->baseUrl."/home/index/$lang";?>">Home</a> » <?php echo gtext('Database modifications');?> +		</div> +		 +		<div class="contrib_explain_box"> +			<?php echo gtext('List of the database modifications carried out by users');?> +		</div> +		 +		<div class="notebooks_viewall"> +			<ul class="page_history"> +			<?php $hw = new HardwareModel(); ?> +			<?php $translations = array('insert'=>'inserted','update'=>'updated');?> +			<?php foreach ($table as $row) { ?> +				<li class="page_history_item"><?php echo gtext('the model');?> <a href="<?php echo Go::toHardwarePage($row['history']['id']);?>"><?php echo $hw->getTheModelName($row['history']['id']);?></a> <?php echo gtext('has been '.$translations[$row['history']['action']].' by');?> <?php echo getLinkToUser($u->getUser($row['history']['created_by']))?> <?php echo gtext('at');?> <?php echo smartDate($row['history']['creation_date']);?></li> +			<?php } ?> +			</ul> +		</div> + +		<div class="history_page_list"> +			<?php echo gtext("page list");?>: <?php echo $pageList;?> +		</div> +		 +	</div>  | 
