@ -25,6 +25,10 @@ abstract class PFAHandler {
# field containing the ID
# field containing the ID
protected $id_field = null;
protected $id_field = null;
# field containing the label
# defaults to $id_field if not set
protected $label_field = null;
# column containing the domain
# column containing the domain
# if a table does not contain a domain column, leave empty and override no_domain_field())
# if a table does not contain a domain column, leave empty and override no_domain_field())
protected $domain_field = "";
protected $domain_field = "";
@ -66,6 +70,10 @@ abstract class PFAHandler {
# filled in domain_from_id() via init()
# filled in domain_from_id() via init()
protected $domain = null;
protected $domain = null;
# the label of the current item (for usage in error/info messages)
# filled in init() (only contains the "real" label in edit mode - in new mode, it will be the same as $id)
protected $label = null;
# can this item be edited?
# can this item be edited?
# filled in init() (only in edit mode)
# filled in init() (only in edit mode)
protected $can_edit = 1;
protected $can_edit = 1;
@ -111,6 +119,11 @@ abstract class PFAHandler {
* @param integer - 0 if logged in as user, 1 if logged in as admin or superadmin
* @param integer - 0 if logged in as user, 1 if logged in as admin or superadmin
*/
*/
public function __construct($new = 0, $username = "", $is_admin = 1) {
public function __construct($new = 0, $username = "", $is_admin = 1) {
# set label_field if not explicitely set
if (empty($this->label_field)) {
$this->label_field = $this->id_field;
}
if ($new) $this->new = 1;
if ($new) $this->new = 1;
if ($is_admin) {
if ($is_admin) {
@ -251,6 +264,7 @@ abstract class PFAHandler {
*/
*/
public function init($id) {
public function init($id) {
$this->id = strtolower($id);
$this->id = strtolower($id);
$this->label = $this->id;
$exists = $this->view(false);
$exists = $this->view(false);
@ -271,6 +285,7 @@ abstract class PFAHandler {
} else {
} else {
$this->can_edit = $this->result['_can_edit'];
$this->can_edit = $this->result['_can_edit'];
$this->can_delete = $this->result['_can_delete'];
$this->can_delete = $this->result['_can_delete'];
$this->label = $this->result[$this->label_field];
# return true;
# return true;
}
}
}
}
@ -326,7 +341,7 @@ abstract class PFAHandler {
*/
*/
public function set($values) {
public function set($values) {
if ( !$this->can_edit ) {
if ( !$this->can_edit ) {
$this->errormsg[] = Config::Lang_f('edit_not_allowed', $this->id );
$this->errormsg[] = Config::Lang_f('edit_not_allowed', $this->label );
return false;
return false;
}
}
@ -463,7 +478,7 @@ abstract class PFAHandler {
$result = db_update($this->db_table, $this->id_field, $this->id, $db_values);
$result = db_update($this->db_table, $this->id_field, $this->id, $db_values);
}
}
if ($result != 1) {
if ($result != 1) {
$this->errormsg[] = Config::lang_f($this->msg['store_error'], $this->id );
$this->errormsg[] = Config::lang_f($this->msg['store_error'], $this->label );
return false;
return false;
}
}
@ -475,7 +490,7 @@ abstract class PFAHandler {
if ($result) {
if ($result) {
# return success message
# return success message
# TODO: add option to override the success message (for example to include autogenerated passwords)
# TODO: add option to override the success message (for example to include autogenerated passwords)
$this->infomsg['success'] = Config::lang_f($this->msg['successmessage'], $this->id );
$this->infomsg['success'] = Config::lang_f($this->msg['successmessage'], $this->label );
}
}
return $result;
return $result;