FusionDirectory
class_ButtonAttribute.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 $buttonText = NULL;
27  protected $action;
28 
29  function __construct ($label, $description, $ldapName, $buttonText, $action = NULL, $defaultValue = "", $acl = "")
30  {
31  parent::__construct($label, $description, $ldapName, FALSE, $defaultValue, $acl);
32  $this->buttonText = $buttonText;
33  if ($action === NULL) {
34  $action = 'handle_'.$ldapName;
35  }
36  $this->action = $action;
37  }
38 
39  function renderFormInput (): string
40  {
41  $id = $this->getHtmlId();
42  $display = $this->renderInputField(
43  'submit', $id,
44  ['value' => $this->buttonText]
45  );
46  return $this->renderAcl($display);
47  }
48 
49  function loadPostValue ()
50  {
51  $this->postValue = FALSE;
52  if ($this->isVisible() && isset($_POST[$this->getHtmlId()])) {
53  $this->setPostValue(TRUE);
54  }
55  }
56 
57  function applyPostValue ()
58  {
59  if (!$this->disabled && $this->isVisible() && $this->postValue) {
60  $func = $this->action;
61  $this->plugin->$func();
62  }
63  }
64 }
Attribute showing a button.
renderAcl(string $display)
Add ACL information around display.
This class allow to handle easily any kind of LDAP attribute.