SF.net SVN: postfixadmin:[1716] trunk/model/PFAHandler.php
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2014-11-01 19:51:31
|
Revision: 1716 http://sourceforge.net/p/postfixadmin/code/1716 Author: christian_boltz Date: 2014-11-01 19:51:25 +0000 (Sat, 01 Nov 2014) Log Message: ----------- PFAHandler: Add $can_edit and $can_delete flags. This makes it possible to make some, but not all items non-editable or non-deletable (based on a database column/query or read_from_db_postprocess()) - add $can_edit and $can_delete - after initStruct, check if $struct contains _can_edit and _can_delete. If not, fill with default values (allowed) - init(): set $this->can_edit and $this->can_delete (only in view/edit mode) - set(): abort if !$this->can_edit Modified Paths: -------------- trunk/model/PFAHandler.php Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2014-11-01 19:38:28 UTC (rev 1715) +++ trunk/model/PFAHandler.php 2014-11-01 19:51:25 UTC (rev 1716) @@ -66,6 +66,15 @@ # filled in domain_from_id() via init() protected $domain = null; + # can this item be edited? + # filled in init() (only in edit mode) + protected $can_edit = 1; + + # can this item be deleted? + # filled in init() (only in edit mode) + protected $can_delete = 1; + # TODO: needs to be implemented in delete() + # structure of the database table, list, edit form etc. # filled in initStruct() protected $struct = array(); @@ -132,6 +141,22 @@ $this->initStruct(); + if (!isset($this->struct['_can_edit'])) { + $this->struct['_can_edit'] = pacol( 0, 0, 1, 'vnum', '' , '' , '', '', + /*not_in_db*/ 0, + /*dont_write_to_db*/ 1, + /*select*/ '1 as _can_edit' + ); + } + + if (!isset($this->struct['_can_delete'])) { + $this->struct['_can_delete'] = pacol( 0, 0, 1, 'vnum', '' , '' , '', '', + /*not_in_db*/ 0, + /*dont_write_to_db*/ 1, + /*select*/ '1 as _can_delete' + ); + } + $struct_hook = Config::read($this->db_table . '_struct_hook'); if ( $struct_hook != 'NO' && function_exists($struct_hook) ) { $this->struct = $struct_hook($this->struct); @@ -239,11 +264,13 @@ # } else { # return true; } - } else { # edit mode + } else { # view or edit mode if (!$exists) { $this->errormsg[$this->id_field] = Config::lang($this->msg['error_does_not_exist']); return false; -# } else { + } else { + $this->can_edit = $this->result['_can_edit']; + $this->can_delete = $this->result['_can_delete']; # return true; } } @@ -298,6 +325,11 @@ * error messages (if any) are stored in $this->errormsg */ public function set($values) { + if ( !$this->can_edit ) { + $this->errormsg[] = Config::Lang_f('edit_not_allowed', $this->id); + return false; + } + if ($this->new == 1) { $values[$this->id_field] = $this->id; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |