FusionDirectory
class_ManagementDialog.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2017-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 
26 {
27  protected $post_cancel = 'edit_cancel';
28  protected $post_finish = 'edit_finish';
29 
30  function __construct (string $dn = NULL, $object = NULL, management $parent = NULL, bool $mainTab = FALSE, array $attributesInfo = NULL)
31  {
32  parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
33  }
34 
35  public function readPost ()
36  {
37  parent::readPost();
38  if (isset($_POST[$this->post_cancel])) {
39  $this->handleCancel();
40  } elseif (isset($_POST[$this->post_finish])) {
41  $this->handleFinish();
42  }
43  }
44 
45  protected function handleFinish ()
46  {
47  $msgs = $this->check();
48  if (count($msgs)) {
49  msg_dialog::displayChecks($msgs);
50  return;
51  } else {
52  $errors = $this->save();
53  if (count($errors)) {
54  msg_dialog::displayChecks($errors);
55  return;
56  } else {
57  $this->parent->removeLocks();
58  $this->parent->closeDialogs();
59  }
60  }
61  }
62 
63  protected function handleCancel ()
64  {
65  $this->parent->removeLocks();
66  $this->parent->closeDialogs();
67  }
68 
69  public function render (): string
70  {
71  return parent::render().$this->getFooter();
72  }
73 
77  protected function getFooter (): string
78  {
79  if (!$this->displayPlugin) {
80  return '';
81  }
82  return '<p class="plugbottom">'.
83  ' <input type="submit" name="'.$this->post_finish.'" value="'.msgPool::saveButton().'"/>'.
84  ' <input type="submit" formnovalidate="formnovalidate" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'.
85  '</p>';
86  }
87 }
$parent
Reference to parent object.
This class is made for easy plugin creation for editing LDAP attributes.
$dn
dn of the opened object
save()
This function saves the object in the LDAP.
$mainTab
Is this plugin the main tab, the one that handle the object itself.
getFooter()
Returns the plugin footer (save cancel), displayed in the template.
render()
Render the dialog and returns the HTML code.
static cancelButton($escape=TRUE)
Text for a cancel button.
static saveButton($escape=TRUE)
Text for a save button.
$attributesInfo
This attribute store all information about attributes.
readPost()
Interpret POST content.
check()
This function checks the attributes values and yell if something is wrong.
Management base class.
Management dialog.