FusionDirectory
class_GenericSimplePluginDialog.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2012-2020 FusionDirectory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
25 {
26  protected $initialDialogValue = NULL;
27 
28  public function __construct ($simplePlugin, $attribute, $value = [])
29  {
30  $this->attribute = $attribute;
31  $this->dialog = new $this->dialogClass('new');
32 
33  $base = $simplePlugin->dn;
34  if ($base == 'new') {
35  $base = $simplePlugin->base;
36  }
37  $this->dialog->base = $base;
38  $this->dialog->set_acl_category($simplePlugin->acl_category);
39  if (!empty($value)) {
40  $this->initialDialogValue = $value;
41  foreach ($this->dialog->attributes as $attr) {
42  if (isset($value[$attr])) {
43  $this->dialog->$attr = $value[$attr];
44  }
45  }
46  }
47  }
48 
49  public function render (): string
50  {
51  return parent::render().$this->buttons();
52  }
53 
54  protected function buttons ()
55  {
56  return '<div style="width:100%; text-align:right; clear:both; float:none;">'.
57  ' <input type="submit" name="'.$this->post_finish.'" value="'.msgPool::saveButton().'"/>&nbsp;'.
58  ' <input type="submit" formnovalidate="formnovalidate" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'.
59  '</div>';
60  }
61 
62  protected function handleFinish ()
63  {
64  $this->dialog->update();
65  $msgs = $this->dialog->check();
66  if (count($msgs)) {
67  msg_dialog::displayChecks($msgs);
68  return;
69  }
70 
71  $value = [];
72  foreach ($this->dialog->attributes as $attr) {
73  $value[$attr] = $this->dialog->$attr;
74  }
75 
76  $this->attribute->addValue('', $value);
77  unset($this->dialog);
78  }
79 
80  protected function handleCancel ()
81  {
82  if ($this->initialDialogValue !== NULL) {
83  $this->attribute->addValue('', $this->initialDialogValue);
84  }
85  unset($this->dialog);
86  }
87 }
render()
Render the dialog and returns the HTML code.
GenericDialog using a simplePlugin based class as dialog.
static cancelButton($escape=TRUE)
Text for a cancel button.
static saveButton($escape=TRUE)
Text for a save button.
Generic dialog base class.