diff --git a/ajax/form_duplicate_target.php b/ajax/form_duplicate_target.php new file mode 100644 index 000000000..964bb61ae --- /dev/null +++ b/ajax/form_duplicate_target.php @@ -0,0 +1,48 @@ +. + * --------------------------------------------------------------------- + * @copyright Copyright © 2011 - 2021 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +include ('../../../inc/includes.php'); + +// Check if plugin is activated... +if (!(new Plugin())->isActivated('formcreator')) { + http_response_code(404); + die(); +} + +if (!isset($_REQUEST['itemtype']) || !isset($_REQUEST['items_id']) || !isset($_REQUEST['action'])) { + http_response_code(500); + die(); +} + +Session::checkRight('entity', UPDATE); +if (!PluginFormcreatorCommon::getForm()->duplicateTarget($_REQUEST)) { + http_response_code(500); +} \ No newline at end of file diff --git a/inc/abstractitiltarget.class.php b/inc/abstractitiltarget.class.php index 90bc24e07..050d34d2e 100644 --- a/inc/abstractitiltarget.class.php +++ b/inc/abstractitiltarget.class.php @@ -2493,4 +2493,17 @@ public static function getMailImage() { public static function getNoMailImage() { return ''; } + + public function getCloneRelations(): array { + return [ + PluginFormcreatorTarget_Actor::class, + PluginFormcreatorCondition::class, + ]; + } + + public function prepareInputForClone($input) { + $input = parent::prepareInputForClone($input); + $input['_skip_create_actors'] = true; + return $input; + } } diff --git a/inc/abstracttarget.class.php b/inc/abstracttarget.class.php index c7962ac33..8c9be59c3 100644 --- a/inc/abstracttarget.class.php +++ b/inc/abstracttarget.class.php @@ -31,7 +31,7 @@ */ use Glpi\Application\View\TemplateRenderer; -use Glpi\Toolbox\Sanitizer; +use \Glpi\Features\Clonable; if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); @@ -43,6 +43,7 @@ abstract class PluginFormcreatorAbstractTarget extends CommonDBChild implements PluginFormcreatorConditionnableInterface, PluginFormcreatorTranslatableInterface { + use Clonable; use PluginFormcreatorConditionnableTrait; use PluginFormcreatorExportableTrait; use PluginFormcreatorTranslatable; @@ -553,4 +554,9 @@ protected function showDestinationEntitySetings($rand) { echo ''; echo ''; } + + public function prepareInputForClone($input) { + unset($input['uuid']); + return $input; + } } diff --git a/inc/condition.class.php b/inc/condition.class.php index c11644228..e2b5db8ad 100644 --- a/inc/condition.class.php +++ b/inc/condition.class.php @@ -374,4 +374,9 @@ public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : boo } return $this->deleteByCriteria($keepCriteria); } + + public function prepareInputForClone($input) { + unset($input['uuid']); + return $input; + } } diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 4197efb84..7a1ae5ed1 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -311,4 +311,6 @@ public function show(string $domain, bool $canEdit = true): string; * @return void */ public function setFormAnswer(PluginFormcreatorFormAnswer $form_answer): void; + + public function getRawValue(); } diff --git a/inc/form.class.php b/inc/form.class.php index c5132b639..7d0dd26e2 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -522,7 +522,17 @@ public function showTargets($ID, $options = []) { echo '