選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AliasdomainHandler.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. # $Id$
  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])) {
  37. # don't allow chained domain aliases (domain1 -> domain2 -> domain3)
  38. unset($this->struct['alias_domain']['options'][$dom]);
  39. }
  40. }
  41. if (count($this->struct['alias_domain']['options']) == 1) { # only one alias_domain available - filter it out from target_domain list
  42. $keys = array_keys($this->struct['alias_domain']['options']);
  43. unset($this->struct['target_domain']['options'][$keys[0]]);
  44. }
  45. }
  46. public function init($id) {
  47. $success = parent::init($id);
  48. if ($success) {
  49. if (count($this->struct['alias_domain']['options']) == 0 && $this->new) {
  50. $this->errormsg[] = Config::lang('pCreate_alias_domain_error4');
  51. return false;
  52. }
  53. # TODO: check if target domains are available (in new and edit mode)
  54. }
  55. return $success;
  56. }
  57. protected function initMsg() {
  58. $this->msg['error_already_exists'] = 'alias_domain_already_exists';
  59. $this->msg['error_does_not_exist'] = 'alias_domain_does_not_exist';
  60. $this->msg['confirm_delete'] = 'confirm_delete_aliasdomain';
  61. if ($this->new) {
  62. $this->msg['logname'] = 'create_alias_domain';
  63. $this->msg['store_error'] = 'alias_domain_create_failed';
  64. $this->msg['successmessage'] = 'pCreate_alias_domain_success';
  65. } else {
  66. $this->msg['logname'] = 'edit_alias_domain';
  67. $this->msg['store_error'] = 'alias_domain_change_failed';
  68. $this->msg['successmessage'] = 'alias_domain_changed';
  69. }
  70. }
  71. public function webformConfig() {
  72. return array(
  73. # $PALANG labels
  74. 'formtitle_create' => 'pCreate_alias_domain_welcome',
  75. 'formtitle_edit' => 'pCreate_alias_domain_welcome',
  76. 'create_button' => 'add_alias_domain',
  77. # various settings
  78. 'required_role' => 'admin',
  79. 'listview' => 'list-virtual.php',
  80. 'early_init' => 1, # 0 for create-domain
  81. 'prefill' => array('alias_domain', 'target_domain'),
  82. );
  83. }
  84. protected function validate_new_id() {
  85. return true; # alias_domain is enum, so we don't need to check its syntax etc.
  86. }
  87. /**
  88. * @return true on success false on failure
  89. */
  90. public function delete() {
  91. if (! $this->view()) {
  92. $this->errormsg[] = 'An alias domain with that name does not exist!'; # TODO: make translatable? (will a user ever see this?)
  93. return false;
  94. }
  95. db_delete($this->db_table, $this->id_field, $this->id);
  96. db_log($this->id, 'delete_alias_domain', $this->result['target_domain']);
  97. $this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->result['alias_domain'] . ' -> ' . $this->result['target_domain']);
  98. return true;
  99. }
  100. /**
  101. * validate target_domain field - it must be != $this->id to avoid a loop
  102. */
  103. protected function _validate_target_domain($field, $val) {
  104. if ($val == $this->id) {
  105. $this->errormsg[$field] = Config::lang('alias_domain_to_itsself');
  106. return false;
  107. }
  108. return true;
  109. }
  110. }
  111. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */