class_simpleManagement.inc 41.19 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2013-2016  FusionDirectory
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
class templateDialog
  protected $simpleManagement;
  protected $type;
  protected $template = NULL;
  protected $templates;
  protected $target = NULL;
  protected $tabObject;
  protected $post_finish = 'template_continue';
  protected $post_cancel = 'template_cancel';
  function __construct($simpleManagement, $type, $dn = NULL, $target = NULL)
    $this->simpleManagement = $simpleManagement;
    $this->type             = $type;
    $this->templates        = objects::getTemplates($this->type);
    if ($dn !== NULL) {
      if (isset($this->templates[$dn])) {
        $this->template = new template($this->type, $dn);
      } else {
        trigger_error('Unknown template "'.$dn.'"');
    $this->target = $target;
  function save_object ()
    if (isset($_POST[$this->post_cancel])) {
      return $this->handle_cancel();
    if (($this->target === NULL) &&
        (isset($_POST[$this->post_finish]) || isset($_GET[$this->post_finish])) &&
        is_object($this->template)) {
      $this->template->save_object();
      return $this->handle_finish();
    if (
      isset($_POST['template']) &&
      isset($this->templates[$_POST['template']])
      ) {
      if (is_object($this->template)) {
        trigger_error('redefining template object');
      $this->template = new template($this->type, $_POST['template']);
      /* This method can loop if there are several targets */
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
unset($_POST['template']); } if (is_object($this->template)) { if ($this->target !== NULL) { $this->simpleManagement->openTabObject($this->template->apply($this->target), $this->template->getBase()); $this->simpleManagement->handleTemplateApply(); return FALSE; } else { $this->template->save_object(); } } return TRUE; } function setNextTarget ($target) { $this->target = $target; $this->template->reset(); } function execute () { $smarty = get_smarty(); if (is_object($this->template)) { $smarty->assign('template_dialog', $this->template->execute()); } else { $smarty->assign('templates', $this->templates); } $display = $smarty->fetch(get_template_path('template.tpl')); return $display; } function handle_finish () { $this->simpleManagement->closeDialogs(); $this->simpleManagement->openTabObject($this->template->apply(), $this->template->getBase()); return FALSE; } function handle_cancel () { $this->simpleManagement->closeDialogs(); return FALSE; } } class simpleManagement { // The currently used object(s) (e.g. in edit, removal) // $dn is public due to some compatibility problems with class plugin.. public $dn = ''; protected $dns = array(); // The last used object(s). protected $last_dn = ''; protected $last_dns = array(); // The common places the displayed objects are stored in. (e.g. array("ou=groups,","..")) protected $storagePoints = array(); // The opened object. protected $tabObject = NULL; protected $dialogObject = NULL; // The last opened object. protected $last_tabObject = NULL; protected $last_dialogObject = NULL; // Whether to display the apply button or not
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
protected $displayApplyBtn = FALSE; // Whether to display a header or not. protected $skipHeader = FALSE; // Whether to display a footer or not. protected $skipFooter = FALSE; // Copy&Paste handler protected $cpHandler = NULL; // Indicates that we want to paste objects right now. protected $cpPastingStarted = FALSE; // The Snapshot handler class. protected $snapHandler = NULL; // The listing handlers protected $headpage = NULL; protected $filter = NULL; // A list of configured actions/events protected $actions = array(); // Some management classes are used in tab groups and needs this public $is_template = FALSE; public $attributes = array(); /* Attributes that child classes should override */ protected $objectTypes = array(); /* Attributes that child classes can override */ protected $departmentBrowser = TRUE; protected $departmentRootVisible = TRUE; protected $baseMode = TRUE; protected $multiSelect = TRUE; protected $filterXMLPath = NULL; protected $listXMLPath = NULL; protected $autoFilter = TRUE; protected $autoActions = TRUE; protected $skipCpHandler = FALSE; protected $skipSnapHandler = FALSE; protected $autoFilterAttributes = array('dn', 'cn', 'description'); protected $headpageClass = "listing"; public static $skipTemplates = TRUE; function __construct() { global $config; if ($this->filterXMLPath === NULL) { $this->filterXMLPath = get_template_path('simple-filter.xml', TRUE, dirname(__FILE__)); } if ($this->listXMLPath === NULL) { $this->listXMLPath = get_template_path('simple-list.xml', TRUE, dirname(__FILE__)); } foreach ($this->objectTypes as &$object) { $object = strtoupper($object); } unset($object); $this->storagePoints = array(); foreach ($this->objectTypes as $key => $object) { try { $i = objects::infos($object);
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
} catch (NonExistingObjectTypeException $e) { /* Remove objectTypes which are not existing */ unset($this->objectTypes[$key]); continue; } if ($i['ou'] !== NULL) { $this->storagePoints[] = $i['ou']; } } $this->storagePoints = array_unique($this->storagePoints); if (count($this->storagePoints) == 0) { $this->storagePoints[] = ''; } // Build filter if (session::global_is_set(get_class($this).'_filter')) { $filter = session::global_get(get_class($this).'_filter'); } else { $filter = new filter($this->filterXMLPath); $filter->setObjectStorage($this->storagePoints); } $this->setFilter($filter); // Build headpage $this->headpage = new $this->headpageClass($this->parseXML($this->listXMLPath)); $this->headpage->setFilter($filter); // Add copy&paste and snapshot handler. if (!$this->skipCpHandler) { $this->cpHandler = new CopyPasteHandler(); $this->headpage->setCopyPasteHandler($this->cpHandler); $this->registerAction('copy', 'copyPasteHandler'); $this->registerAction('cut', 'copyPasteHandler'); $this->registerAction('paste', 'copyPasteHandler'); } if (!$this->skipSnapHandler && ($config->get_cfg_value('enableSnapshots') == 'TRUE')) { $this->snapHandler = new SnapshotHandler(); $this->headpage->setSnapshotHandler($this->snapHandler); $this->registerAction('snapshot', 'createSnapshotDialog'); $this->registerAction('restore', 'restoreSnapshotDialog'); } // Register default actions $this->registerAction('new', 'newEntry'); $this->registerAction('edit', 'editEntry'); $this->registerAction('apply', 'applyChanges'); $this->registerAction('save', 'saveChanges'); $this->registerAction('cancel', 'cancelEdit'); $this->registerAction('cancelDelete', 'cancelEdit'); $this->registerAction('remove', 'removeEntryRequested'); $this->registerAction('removeConfirmed', 'removeEntryConfirmed'); $this->configureHeadpage(); $this->configureFilter(); if ($this->baseMode === FALSE) { $this->headpage->setBase($config->current['BASE']); } } /* Build the action menu, fill the object definition, etc, based on objectTypes info */ function configureHeadpage () { if ($this->autoActions) { if (static::$skipTemplates) { $this->headpage->xmlData['actionmenu']['action'][0]['action'] = array(); } else { $this->headpage->xmlData['actionmenu']['action'][0]['action'] = array( array(
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
'type' => 'sub', 'image' => 'geticon.php?context=devices&icon=template&size=16', 'label' => _('Template'), 'action' => array(), ), array( 'type' => 'sub', 'image' => 'geticon.php?context=actions&icon=document-new&size=16', 'label' => _('From template'), 'action' => array(), ), ); } } $this->configureHeadline(); foreach ($this->objectTypes as $object) { $i = objects::infos($object); if (!isset($i['icon'])) { trigger_error('Missing icon for type '.$object); $i['icon'] = ''; } $filterObject = objects::getFilterObject($object); $this->headpage->objectTypes[$object] = array( 'label' => $i['name'], 'category' => $i['aclCategory'], 'class' => $i['mainTab'], 'image' => $i['icon'], 'filter' => $filterObject, 'nameAttr' => $i['nameAttr'], ); if (!static::$skipTemplates) { $this->headpage->objectTypes['template_'.$object] = array( 'label' => sprintf(_('%s template'), $i['name']), 'category' => $i['aclCategory'], 'class' => 'template', 'image' => 'geticon.php?context=devices&icon=template&size=16', 'filter' => new ldapFilter( '&', array( new ldapFilterLeaf('objectClass', '=', 'fdTemplate'), fdTemplateFilter($filterObject), ) ), 'nameAttr' => $i['nameAttr'], ); } $this->headpage->categories[] = $i['aclCategory']; if ($this->autoActions) { $this->registerAction('new_'.$object, 'newEntry'); $icon = 'geticon.php?context=actions&amp;icon=document-new&amp;size=16'; if (isset($i['icon'])) { $icon = $i['icon']; } else { $infos = pluglist::pluginInfos($i['mainTab']); if (isset($infos['plIcon'])) { $icon = $infos['plIcon']; } } $this->headpage->xmlData['actionmenu']['action'][0]['action'][] = array( 'name' => 'new_'.$object, 'type' => 'entry', 'image' => $icon, 'label' => $i['name'], 'acl' => $i['aclCategory'].'/'.$i['mainTab'].'[c]', );
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
if (!static::$skipTemplates) { $this->registerAction('new_template_'.$object, 'newEntryTemplate'); $this->registerAction('template_apply_'.$object, 'newEntryFromTemplate'); $this->headpage->xmlData['actionmenu']['action'][0]['action'][0]['action'][] = array( 'name' => 'new_template_'.$object, 'type' => 'entry', 'image' => $icon, 'label' => $i['name'], 'acl' => $i['aclCategory'].'/template[c]', ); $this->headpage->xmlData['actionmenu']['action'][0]['action'][1]['action'][] = array( 'name' => 'template_apply_'.$object, 'type' => 'entry', 'image' => $icon, 'label' => $i['name'], 'acl' => $i['aclCategory'].'/'.$i['mainTab'].'[c]', ); } } } if ($this->autoActions && !static::$skipTemplates) { $this->registerAction('template_apply', 'newEntryFromTemplate'); } $this->headpage->refreshBasesList(); } function configureHeadline () { $pInfos = pluglist::pluginInfos(get_class($this)); $this->headpage->headline = $pInfos['plShortName']; } function configureFilterCategory () { $pInfos = pluglist::pluginInfos(get_class($this)); $cat = NULL; if (isset($pInfos['plCategory'])) { $cat = key($pInfos['plCategory']); if (is_numeric($cat)) { $cat = $pInfos['plCategory'][$cat]; } } elseif (isset($pInfos['plObjectType'])) { $ot = key($pInfos['plObjectType']); if (is_numeric($ot)) { $ot = $pInfos['plObjectType'][$ot]; } $infos = objects::infos($ot); $cat = $infos['aclCategory']; } if ($cat === NULL) { trigger_error('Could not find a category for '.get_class($this)); } $this->filter->category = $cat; } /* Build the filter(s) based on objectTypes info */ function configureFilter () { if ($this->autoFilter) { $this->configureFilterCategory(); $attributes = $this->autoFilterAttributes; $filter = '(|'; foreach ($this->objectTypes as $object) { $tag = 'FILTER'.$object; $filter .= '$'.$tag; $i = objects::infos($object); $this->filter->elements[$tag] = array( 'type' => 'checkbox', 'tag' => $tag, 'default' => TRUE,