1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<?php
# $Id$
/**
* Handlers User level alias actions - e.g. add alias, get aliases, update etc.
*/
class AliasdomainHandler extends PFAHandler
{
protected $db_table = 'alias_domain';
protected $id_field = 'alias_domain';
protected $domain_field = 'alias_domain';
protected $searchfields = array('alias_domain', 'target_domain');
protected function initStruct()
{
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'alias_domain' => self::pacol($this->new, 1, 1, 'enum', 'pCreate_alias_domain_alias' , 'pCreate_alias_domain_alias_text' , '',
/*options, filled below*/ array(),
/* multiopt */ array('linkto' => 'list-virtual.php?domain=%s')),
'target_domain' => self::pacol(1, 1, 1, 'enum', 'pCreate_alias_domain_target' , 'pCreate_alias_domain_target_text', '',
/*options*/ array() /* filled below */),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
);
# check which domains are available as an alias- or target-domain
$this->getList("");
$used_targets = array();
foreach ($this->allowed_domains as $dom) {
if (isset($this->result[$dom])) { # already used as alias_domain
$used_targets[$this->result[$dom]['target_domain']] = $this->result[$dom]['target_domain'];
} else { # might be available
$this->struct['alias_domain']['options'][$dom] = $dom;
$this->struct['target_domain']['options'][$dom] = $dom;
}
}
foreach ($this->struct['alias_domain']['options'] as $dom) {
if (isset($used_targets[$dom])) {
# don't allow chained domain aliases (domain1 -> domain2 -> domain3)
unset($this->struct['alias_domain']['options'][$dom]);
}
}
if (count($this->struct['alias_domain']['options']) == 1) { # only one alias_domain available - filter it out from target_domain list
$keys = array_keys($this->struct['alias_domain']['options']);
unset($this->struct['target_domain']['options'][$keys[0]]);
}
}
public function init(string $id): bool
{
$success = parent::init($id);
if ($success) {
if (count($this->struct['alias_domain']['options']) == 0 && $this->new) {
$this->errormsg[] = Config::lang('pCreate_alias_domain_error4');
return false;
}
# TODO: check if target domains are available (in new and edit mode)
}
return $success;
}
protected function initMsg()
{
$this->msg['error_already_exists'] = 'alias_domain_already_exists';
$this->msg['error_does_not_exist'] = 'alias_domain_does_not_exist';
$this->msg['confirm_delete'] = 'confirm_delete_aliasdomain';
if ($this->new) {
$this->msg['logname'] = 'create_alias_domain';
$this->msg['store_error'] = 'alias_domain_create_failed';
$this->msg['successmessage'] = 'pCreate_alias_domain_success';
} else {
$this->msg['logname'] = 'edit_alias_domain';
$this->msg['store_error'] = 'alias_domain_change_failed';
$this->msg['successmessage'] = 'alias_domain_changed';
}
}
public function webformConfig()
{
return array(
# $PALANG labels
'formtitle_create' => 'pCreate_alias_domain_welcome',
'formtitle_edit' => 'pCreate_alias_domain_welcome',
'create_button' => 'add_alias_domain',
# various settings
'required_role' => 'admin',
'listview' => 'list-virtual.php',
'early_init' => 1, # 0 for create-domain
'prefill' => array('alias_domain', 'target_domain'),
);
}
protected function validate_new_id()
{
return true; # alias_domain is enum, so we don't need to check its syntax etc.
}
/**
* @return boolean
*/
public function delete()
{
if (! $this->view()) {
$this->errormsg[] = 'An alias domain with that name does not exist!'; # TODO: make translatable? (will a user ever see this?)
return false;
}
db_delete($this->db_table, $this->id_field, $this->id);
db_log($this->id, 'delete_alias_domain', $this->result['target_domain']);
$this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->result['alias_domain'] . ' -> ' . $this->result['target_domain']);
return true;
}
/**
* validate target_domain field - it must be != $this->id to avoid a loop
* @return boolean
*/
protected function _validate_target_domain($field, $val)
{
if ($val == $this->id) {
$this->errormsg[$field] = Config::lang('alias_domain_to_itsself');
return false;
}
return true;
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|