diff --git a/include/class.topic.php b/include/class.topic.php index 9f02858efe744889eef7d9fae6707f142791a105..eda6a2a69b3c9e59af82745855cf30ef5d62c8d4 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -449,12 +449,14 @@ class Topic extends VerySimpleModel { }; // Consider all the forms in the request + $current = array(); if (is_array($form_ids = $vars['forms'])) { $forms = TopicFormModel::objects() ->select_related('form') ->filter(array('topic_id' => $this->getId())); foreach ($forms as $F) { if (false !== ($idx = array_search($F->form_id, $form_ids))) { + $current[] = $F->form_id; $F->sort = $idx + 1; $F->extra = JsonDataEncoder::encode( array('disable' => $find_disabled($F->form)) @@ -470,6 +472,10 @@ class Topic extends VerySimpleModel { if (!($form = DynamicForm::lookup($id))) { continue; } + elseif (in_array($id, $current)) { + // Don't add a form more than once + continue; + } TopicFormModel::create(array( 'topic_id' => $this->getId(), 'form_id' => $id, diff --git a/include/client/templates/dynamic-form.tmpl.php b/include/client/templates/dynamic-form.tmpl.php index a333ac2eef0d7aff31ee0a35d7cc18f4717c3bc5..6cf54466b08a0622693126a915ed503cf9dbba86 100644 --- a/include/client/templates/dynamic-form.tmpl.php +++ b/include/client/templates/dynamic-form.tmpl.php @@ -8,7 +8,7 @@ <?php print ($form instanceof DynamicFormEntry) ? $form->getForm()->getMedia() : $form->getMedia(); ?> <h3><?php echo Format::htmlchars($form->getTitle()); ?></h3> - <em><?php echo Format::htmlchars($form->getInstructions()); ?></em> + <div><?php echo Format::display($form->getInstructions()); ?></div> </div> </td></tr> <?php diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index c9702d2105347d3e47835ac1acc9cd1952c18b8e..cf43338fa5abf33fc15477418cc5d485d6a48653 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -337,13 +337,16 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <div class="hidden tab_content" id="forms"> <table id="topic-forms" class="table" border="0" cellspacing="0" cellpadding="2"> -<?php foreach ($forms as $F) { ?> +<?php +$current_forms = array(); +foreach ($forms as $F) { + $current_forms[] = $F->id; ?> <tbody data-form-id="<?php echo $F->get('id'); ?>"> <tr> <td class="handle" colspan="6"> <input type="hidden" name="forms[]" value="<?php echo $F->get('id'); ?>" /> <div class="pull-right"> - <i class="icon-2x icon-move icon-muted"></i> + <i class="icon-large icon-move icon-muted"></i> <?php if ($F->get('type') != 'T') { ?> <a href="#" title="<?php echo __('Delete'); ?>" onclick="javascript: if (confirm(__('You sure?'))) @@ -352,11 +355,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); $(this).closest('form') .find('[name=form_id] [value=' + tbody.data('formId') + ']') .prop('disabled', false); - return false;"><i class="icon-2x icon-trash"></i></a> + return false;"><i class="icon-large icon-trash"></i></a> <?php } ?> </div> - <div><strong><?php echo $F->getLocal('title'); ?></strong></div> - <div><?php echo $F->getLocal('instructions'); ?></div> + <div><strong><?php echo Format::htmlchars($F->getLocal('title')); ?></strong></div> + <div><?php echo Format::display($F->getLocal('instructions')); ?></div> </td> </tr> <tr> @@ -402,6 +405,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <option value=""><?php echo '— '.__('Add a custom form') . ' —'; ?></option> <?php foreach (DynamicForm::objects()->filter(array('type'=>'G')) as $F) { ?> <option value="<?php echo $F->get('id'); ?>" + <?php if (in_array($F->id, $current_forms)) + echo 'disabled="disabled"'; ?> <?php if ($F->get('id') == $info['form_id']) echo 'selected="selected"'; ?>> <?php echo $F->getLocal('title'); ?> @@ -448,5 +453,5 @@ $('table#topic-forms').sortable({ ui=ui.clone().css({'background-color':'white', 'opacity':0.8}); return ui; } -}); +}).disableSelection(); </script> diff --git a/include/staff/templates/dynamic-form.tmpl.php b/include/staff/templates/dynamic-form.tmpl.php index 6fc7b8978faea9b538a80e55acc6db3b503a0434..5002700fce79396f2f86098a030ac1c061cdb357 100644 --- a/include/staff/templates/dynamic-form.tmpl.php +++ b/include/staff/templates/dynamic-form.tmpl.php @@ -20,8 +20,7 @@ if (isset($options['entry']) && $options['mode'] == 'edit') { ?> <?php } ?> <?php if ($form->getTitle()) { ?> <tr><th colspan="2"> - <em><strong><?php echo Format::htmlchars($form->getTitle()); ?></strong>: - <?php echo Format::htmlchars($form->getInstructions()); ?> + <em> <?php if ($options['mode'] == 'edit') { ?> <div class="pull-right"> <?php if ($options['entry'] @@ -32,7 +31,10 @@ if (isset($options['entry']) && $options['mode'] == 'edit') { ?> <?php } ?> <i class="icon-sort" title="Drag to Sort"></i> </div> -<?php } ?></em> +<?php } ?> + <strong><?php echo Format::htmlchars($form->getTitle()); ?></strong>: + <div><?php echo Format::display($form->getInstructions()); ?></div> + </em> </th></tr> <?php }