From 51abf377f8d3a2f774ebc12e56bcc43499db308e Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Fri, 27 Feb 2015 15:54:34 +0000
Subject: [PATCH] bugs: Fix  help topic create + forms

---
 include/staff/helptopic.inc.php | 37 ++++++++++++++++++---------------
 scp/helptopics.php              |  5 +++--
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php
index cf43338fa..7df72585c 100644
--- a/include/staff/helptopic.inc.php
+++ b/include/staff/helptopic.inc.php
@@ -1,6 +1,6 @@
 <?php
 if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
-$info = $qs = array();
+$info = $qs = $forms = array();
 if($topic && $_REQUEST['a']!='add') {
     $title=__('Update Help Topic');
     $action='update';
@@ -17,8 +17,8 @@ if($topic && $_REQUEST['a']!='add') {
     $submit_text=__('Add Topic');
     $info['isactive']=isset($info['isactive'])?$info['isactive']:1;
     $info['ispublic']=isset($info['ispublic'])?$info['ispublic']:1;
-    $info['form_id'] = Topic::FORM_USE_PARENT;
     $qs += array('a' => $_REQUEST['a']);
+    $forms = TicketForm::objects();
 }
 $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
 ?>
@@ -387,21 +387,7 @@ foreach ($forms as $F) {
 
    <br/>
    <strong><?php echo __('Add Custom Form'); ?></strong>:
-   <select name="form_id" onchange="javascript:
-    event.preventDefault();
-    var $this = $(this),
-        val = $this.val();
-    if (!val) return;
-    $.ajax({
-        url: 'ajax.php/form/' + val + '/fields/view',
-        dataType: 'json',
-        success: function(json) {
-            if (json.success) {
-                $(json.html).appendTo('#topic-forms').effect('highlight');
-                $this.find(':selected').prop('disabled', true);
-            }
-        }
-    });">
+   <select name="form_id" id="newform">
     <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'); ?>"
@@ -438,6 +424,23 @@ $(function() {
     };
     $('[name=sequence_id]').on('change', update_example);
     $('[name=number_format]').on('keyup', update_example);
+
+    $('form select#newform').change(function() {
+        var $this = $(this),
+            val = $this.val();
+        if (!val) return;
+        $.ajax({
+            url: 'ajax.php/form/' + val + '/fields/view',
+            dataType: 'json',
+            success: function(json) {
+                if (json.success) {
+                    $(json.html).appendTo('#topic-forms').effect('highlight');
+                    $this.find(':selected').prop('disabled', true);
+                }
+            }
+        });
+    });
+
 });
 $('table#topic-forms').sortable({
   items: 'tbody',
diff --git a/scp/helptopics.php b/scp/helptopics.php
index 01c01337b..adb1eb7c4 100644
--- a/scp/helptopics.php
+++ b/scp/helptopics.php
@@ -36,8 +36,9 @@ if($_POST){
             }
             break;
         case 'create':
-            $topic = Topic::create();
-            if ($topic->update($_POST, $errors)) {
+            $_topic = Topic::create();
+            if ($_topic->update($_POST, $errors)) {
+                $topic = $_topic;
                 $msg=sprintf(__('Successfully added %s'), Format::htmlchars($_POST['topic']));
                 $_REQUEST['a']=null;
             }elseif(!$errors['err']){
-- 
GitLab