You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AliasdomainHandler.php 5.5KB

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