FusionDirectory
class_GenericDialog.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2012-2020 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
24 abstract class GenericDialog implements FusionDirectoryDialog
25 {
26  protected $dialogClass = '';
27  protected $dialog;
28  protected $attribute;
29 
30  protected $post_cancel = 'add_cancel';
31  protected $post_finish = 'add_finish';
32 
33  function __construct ($simplePlugin, $attribute)
34  {
35  $this->attribute = $attribute;
36  $this->dialog = new $this->dialogClass();
37  }
38 
39  public function readPost ()
40  {
41  if (isset($_POST[$this->post_cancel])) {
42  $this->handleCancel();
43  } else {
44  $this->dialog->readPost();
45  if (isset($_POST[$this->post_finish]) || isset($_GET[$this->post_finish])) {
46  $this->handleFinish();
47  }
48  }
49  }
50 
51  public function update (): bool
52  {
53  if (isset($this->dialog)) {
54  return $this->dialog->update();
55  } else {
56  return FALSE;
57  }
58  }
59 
60  public function render (): string
61  {
62  return $this->dialog->render();
63  }
64 
65  abstract protected function handleFinish ();
66 
67  protected function handleCancel ()
68  {
69  unset($this->dialog);
70  }
71 }
update()
Update state and return FALSE if the dialog was closed.
This interface should be implemented by all dialog classes in FusionDirectory.
readPost()
Interpret POST content.
render()
Render the dialog and returns the HTML code.
Generic dialog base class.