diff --git a/ihtml/themes/breezy/islocked.tpl b/ihtml/themes/breezy/islocked.tpl index 1f5544c9dab042ef25c3e45c0673d6c88e71a7ab..b2e6e89212b44041438d955ab209a03ef834549b 100644 --- a/ihtml/themes/breezy/islocked.tpl +++ b/ihtml/themes/breezy/islocked.tpl @@ -6,7 +6,7 @@ </div> <div> <p> - <b>{t}Warning{/t}:</b> {$message|escape} + <b>{t}Warning{/t}:</b> {t}The following entries are locked:{/t} <ul> {foreach from=$locks item=lock} <li>{t 1=$lock.object 2=$lock.user 3=$lock.timestamp|date_format:"%Y-%m-%d, %H:%M:%S"}"%1" has been locked by "%2" since %3{/t}</li> @@ -26,8 +26,6 @@ <input type="submit" formnovalidate="formnovalidate" name="cancel_lock" value="{t}Cancel{/t}"/> </p> - - <input type="hidden" name="dn" value="{$dn|escape}"/> </div> </div> diff --git a/ihtml/themes/breezy/simple-archive.tpl b/ihtml/themes/breezy/simple-archive.tpl new file mode 100644 index 0000000000000000000000000000000000000000..85b077bbe5e6957e094ad2d021a4886e33429ec3 --- /dev/null +++ b/ihtml/themes/breezy/simple-archive.tpl @@ -0,0 +1,28 @@ +<div class="notice"> + <div class="msgtitle"> + <h2> + <img alt="" src="geticon.php?context=status&icon=dialog-warning&size=32" class="center"/> {t}Warning: you are about to archive the following objects{/t} + </h2> + </div> + <div> + <p> + <ul> + {foreach from=$objects item=object} + <li style="list-style-image:url('{$object.icon|escape}');" title="{$object.type|escape}"> + {$object.name|escape} (<i>{$object.dn|escape}</i>) + </li> + {/foreach} + </ul> + {t}Please double check if you really want to do this since there is no way for FusionDirectory to get your data back.{/t} + </p> + + <p> + {t}So - if you're sure - press 'Archive' to continue or 'Cancel' to abort.{/t} + </p> + + <p class="plugbottom"> + <input type="submit" name="archive_confirmed" value="{t}Archive{/t}"/> + <input type="submit" formnovalidate="formnovalidate" name="archive_cancel" value="{msgPool type=cancelButton}"/> + </p> + </div> +</div> diff --git a/include/functions.inc b/include/functions.inc index 70160cf947dd734658914034e74fc09ed0c94972..d3469719f5bdb3b6a16bff6186df94ac4ad07ffd 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -824,92 +824,6 @@ function strict_uid_mode () return TRUE; } -/*! - * \brief Generate a lock message - * - * This message shows a warning to the user, that a certain object is locked - * and presents some choices how the user can proceed. By default this - * is 'Cancel' or 'Edit anyway', but depending on the function call - * its possible to allow readonly access, too. - * - * Example usage: - * \code - * if ($locks = get_locks($this->dn)) { - * return gen_locked_message($locks, $this->dn, TRUE); - * } - * \endcode - * - * \param string $locks the locks as returned by get_locks - * - * \param string $dn the locked DN - * - * \param boolean $allow_readonly TRUE if readonly access should be permitted, - * FALSE if not (default). - * - * - */ -function gen_locked_message (array $locks, $dn, $allow_readonly = FALSE) -{ - session::set('dn', $dn); - - /* Save variables from LOCK_VARS_TO_USE in session - for further editing */ - if (session::is_set('LOCK_VARS_TO_USE') && count(session::get('LOCK_VARS_TO_USE'))) { - $LOCK_VARS_USED_GET = []; - $LOCK_VARS_USED_POST = []; - $LOCK_VARS_USED_REQUEST = []; - $LOCK_VARS_TO_USE = session::get('LOCK_VARS_TO_USE'); - - foreach ($LOCK_VARS_TO_USE as $name) { - if (empty($name)) { - continue; - } - - foreach ($_POST as $Pname => $Pvalue) { - if (preg_match($name, $Pname)) { - $LOCK_VARS_USED_POST[$Pname] = $_POST[$Pname]; - } - } - - foreach ($_GET as $Pname => $Pvalue) { - if (preg_match($name, $Pname)) { - $LOCK_VARS_USED_GET[$Pname] = $_GET[$Pname]; - } - } - - foreach ($_REQUEST as $Pname => $Pvalue) { - if (preg_match($name, $Pname)) { - $LOCK_VARS_USED_REQUEST[$Pname] = $_REQUEST[$Pname]; - } - } - } - session::set('LOCK_VARS_TO_USE', []); - session::set('LOCK_VARS_USED_GET', $LOCK_VARS_USED_GET); - session::set('LOCK_VARS_USED_POST', $LOCK_VARS_USED_POST); - session::set('LOCK_VARS_USED_REQUEST', $LOCK_VARS_USED_REQUEST); - } - - /* Prepare and show template */ - $smarty = get_smarty(); - $smarty->assign('allow_readonly', $allow_readonly); - if (is_array($dn)) { - $msg = '<pre>'; - foreach ($dn as $sub_dn) { - $msg .= "\n".$sub_dn.', '; - } - $msg = preg_replace("/, $/", "</pre>", $msg); - } else { - $msg = $dn; - } - - $smarty->assign('dn', $msg); - $smarty->assign('action', _('Edit anyway')); - $smarty->assign('message', sprintf(_("You're going to edit the LDAP entry/entries %s"), "<b>".$msg."</b>", "")); - $smarty->assign('locks', $locks); - - return $smarty->fetch(get_template_path('islocked.tpl')); -} - - /*! * \brief Return a string/HTML representation of an array * diff --git a/include/management/class_ManagementDialog.inc b/include/management/class_ManagementDialog.inc index e1c44bd8cff493bafff5cd19c715ef56bc1ede25..a6414653c2a7400c518df7c151b49d824077976c 100644 --- a/include/management/class_ManagementDialog.inc +++ b/include/management/class_ManagementDialog.inc @@ -54,7 +54,7 @@ class ManagementDialog extends simplePlugin msg_dialog::displayChecks($errors); return; } else { - $this->parent->remove_lock(); + $this->parent->removeLocks(); $this->parent->closeDialogs(); } } @@ -62,7 +62,7 @@ class ManagementDialog extends simplePlugin protected function handleCancel () { - $this->parent->remove_lock(); + $this->parent->removeLocks(); $this->parent->closeDialogs(); } diff --git a/include/management/class_management.inc b/include/management/class_management.inc index 2f011da0d5c4be545a790a19115209907fd11964..0ef3b4ab94bef474bbae81675e40cdf0e390763d 100644 --- a/include/management/class_management.inc +++ b/include/management/class_management.inc @@ -1,7 +1,7 @@ <?php /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) - Copyright (C) 2017-2018 FusionDirectory + Copyright (C) 2017-2020 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 @@ -281,9 +281,11 @@ class management implements FusionDirectoryDialog } if (class_available('archivedObject')) { - $action = archivedObject::getManagementAction($this->objectTypes, 'archiveEntry'); + $action = archivedObject::getManagementAction($this->objectTypes, 'archiveRequested'); if ($action !== NULL) { $this->registerAction($action); + $this->registerAction(new HiddenAction('archiveConfirmed', 'archiveConfirmed')); + $this->registerAction(new HiddenAction('archiveCancel', 'cancelEdit')); } } @@ -397,6 +399,10 @@ class management implements FusionDirectoryDialog $action['action'] = 'removeConfirmed'; } elseif (isset($_POST['delete_cancel'])) { $action['action'] = 'cancelDelete'; + } elseif (isset($_POST['archive_confirmed'])) { + $action['action'] = 'archiveConfirmed'; + } elseif (isset($_POST['archive_cancel'])) { + $action['action'] = 'archiveCancel'; } else { $action = $this->listing->getAction(); } @@ -597,7 +603,7 @@ class management implements FusionDirectoryDialog * concurrent modifications. * This locks will automatically removed here. */ - function remove_lock () + public function removeLocks () { if (!empty($this->currentDn) && ($this->currentDn != 'new')) { del_lock($this->currentDn); @@ -802,7 +808,7 @@ class management implements FusionDirectoryDialog // check locks if ($locks = get_locks($this->currentDns)) { - return gen_locked_message($locks, $this->currentDns); + return static::genLockedMessage($locks, FALSE, _('Apply anyway')); } // Add locks @@ -841,7 +847,10 @@ class management implements FusionDirectoryDialog $this->dialogObject = new templateDialog($this, $type, NULL, $this->currentDn); } - public function archiveEntry (array $action) + /*! \brief Queue selected objects to be archived. + * Checks Locks and ask for confirmation. + */ + public function archiveRequested (array $action) { global $ui; @@ -850,33 +859,47 @@ class management implements FusionDirectoryDialog } $this->currentDns = $action['targets']; - logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Archiving'); + logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Entry archive requested'); - // check locks + // Check locks if ($locks = get_locks($this->currentDns)) { - return gen_locked_message($locks, $this->currentDns); + return static::genLockedMessage($locks, FALSE, _('Archive anyway')); } // Add locks add_lock($this->currentDns, $ui->dn); - $success = 0; + $objects = []; foreach ($this->currentDns as $dn) { - $entry = $this->listing->getEntry($dn); - if ($entry === NULL) { - trigger_error('Could not find '.$dn.', action canceled'); - $this->remove_lock(); - $this->currentDns = []; - return; - } - + $entry = $this->listing->getEntry($dn); if ($entry->isTemplate()) { $error = new FusionDirectoryError(htmlescape(_('Archiving a template is not possible'))); $error->display(); - $this->remove_lock(); + $this->removeLocks(); $this->currentDns = []; return; } + $infos = objects::infos($entry->getTemplatedType()); + $objects[] = [ + 'name' => $entry[$infos['nameAttr']][0], + 'dn' => $dn, + 'icon' => $infos['icon'], + 'type' => $infos['name'] + ]; + } + + $smarty = get_smarty(); + $smarty->assign('objects', $objects); + return $smarty->fetch(get_template_path('simple-archive.tpl')); + } + + public function archiveConfirmed (array $action) + { + logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Archiving'); + + $success = 0; + foreach ($this->currentDns as $dn) { + $entry = $this->listing->getEntry($dn); $errors = archivedObject::archiveObject($entry->type, $dn); if (empty($errors)) { @@ -898,7 +921,6 @@ class management implements FusionDirectoryDialog $this->currentDns = []; } - /*! * \brief This method opens an existing object to be edited. * @@ -927,7 +949,7 @@ class management implements FusionDirectoryDialog // Get the dn of the object and create lock $this->currentDn = $target; if ($locks = get_locks($this->currentDn, TRUE)) { - return gen_locked_message($locks, $this->currentDn, TRUE); + return static::genLockedMessage($locks, TRUE); } add_lock($this->currentDn, $ui->dn); @@ -950,7 +972,7 @@ class management implements FusionDirectoryDialog $this->handleTemplateApply(TRUE); return; } - $this->remove_lock(); + $this->removeLocks(); $this->closeDialogs(); } @@ -972,7 +994,7 @@ class management implements FusionDirectoryDialog msg_dialog::displayChecks($msgs); } else { logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry saved'); - $this->remove_lock(); + $this->removeLocks(); $this->closeDialogs(); } } @@ -1032,7 +1054,7 @@ class management implements FusionDirectoryDialog if (count($this->currentDns)) { // Check locks if ($locks = get_locks($this->currentDns)) { - return gen_locked_message($locks, $this->currentDns); + return static::genLockedMessage($locks, FALSE, _('Delete anyway')); } // Add locks @@ -1097,7 +1119,7 @@ class management implements FusionDirectoryDialog } // Cleanup - $this->remove_lock(); + $this->removeLocks(); $this->closeDialogs(); } @@ -1357,6 +1379,75 @@ class management implements FusionDirectoryDialog } } + /*! + * \brief Generate a lock message + * + * This message shows a warning to the user, that a certain object is locked + * and presents some choices how the user can proceed. By default this + * is 'Cancel' or 'Edit anyway', but depending on the function call + * its possible to allow readonly access, too. + * + * Example usage: + * \code + * if ($locks = get_locks($this->dn)) { + * return management::genLockedMessage($locks, TRUE); + * } + * \endcode + * + * \param string $locks the locks as returned by get_locks + * + * \param boolean $allowReadonly TRUE if readonly access should be permitted, + * FALSE if not (default). + * + * \param string $action Label of the action button, "Edit anyway" by default. Will be escaped. + * + */ + function genLockedMessage (array $locks, bool $allowReadonly = FALSE, string $action = NULL): string + { + /* Save variables from LOCK_VARS_TO_USE in session - for further editing */ + if (session::is_set('LOCK_VARS_TO_USE') && count(session::get('LOCK_VARS_TO_USE'))) { + $LOCK_VARS_USED_GET = []; + $LOCK_VARS_USED_POST = []; + $LOCK_VARS_USED_REQUEST = []; + $LOCK_VARS_TO_USE = session::get('LOCK_VARS_TO_USE'); + + foreach ($LOCK_VARS_TO_USE as $name) { + if (empty($name)) { + continue; + } + + foreach ($_POST as $Pname => $Pvalue) { + if (preg_match($name, $Pname)) { + $LOCK_VARS_USED_POST[$Pname] = $_POST[$Pname]; + } + } + + foreach ($_GET as $Pname => $Pvalue) { + if (preg_match($name, $Pname)) { + $LOCK_VARS_USED_GET[$Pname] = $_GET[$Pname]; + } + } + + foreach ($_REQUEST as $Pname => $Pvalue) { + if (preg_match($name, $Pname)) { + $LOCK_VARS_USED_REQUEST[$Pname] = $_REQUEST[$Pname]; + } + } + } + session::set('LOCK_VARS_TO_USE', []); + session::set('LOCK_VARS_USED_GET', $LOCK_VARS_USED_GET); + session::set('LOCK_VARS_USED_POST', $LOCK_VARS_USED_POST); + session::set('LOCK_VARS_USED_REQUEST', $LOCK_VARS_USED_REQUEST); + } + + /* Prepare and show template */ + $smarty = get_smarty(); + $smarty->assign('allow_readonly', $allowReadonly); + $smarty->assign('action', ($action ?? _('Edit anyway'))); + $smarty->assign('locks', $locks); + + return $smarty->fetch(get_template_path('islocked.tpl')); + } static function mainInc ($classname = NULL, $objectTypes = FALSE) { @@ -1369,7 +1460,7 @@ class management implements FusionDirectoryDialog /* Remove locks */ if ($remove_lock && session::is_set($classname)) { $macl = session::get($classname); - $macl->remove_lock(); + $macl->removeLocks(); } if ($cleanup) { diff --git a/include/management/class_templateDialog.inc b/include/management/class_templateDialog.inc index 06b153f2a330bc2d98654ee2a7fbb666ab0ec287..1ac23736401f3bde43b44a233408f2d1412df741 100644 --- a/include/management/class_templateDialog.inc +++ b/include/management/class_templateDialog.inc @@ -130,7 +130,7 @@ class templateDialog implements FusionDirectoryDialog protected function handleCancel () { - $this->management->remove_lock(); + $this->management->removeLocks(); $this->closed = TRUE; } } diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 09ca1bbb59cfdc329ec59d38755b0fb34972a07b..988d86084de6eb5b8b15c1a6d6e19e584aa509e6 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -2251,7 +2251,7 @@ class simplePlugin implements SimpleTab /* Check locking */ if ($locks = get_locks($entry_dn)) { session::set('LOCK_VARS_TO_USE', ["/^edit$/", "/^plug$/"]); - $lock_msg = gen_locked_message($locks, $entry_dn); + $lock_msg = management::genLockedMessage($locks); } else { /* Lock the current entry */ add_lock($entry_dn, $ui->dn);