From a7d1885f0fcaf96d5f2cecb8550f6e858604ecdc Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 1 Sep 2014 15:23:18 -0500
Subject: [PATCH] forms: Fix multiselect widgets in advanced search

---
 include/class.forms.php                               | 8 ++++++--
 include/client/header.inc.php                         | 1 +
 include/staff/header.inc.php                          | 1 +
 include/staff/templates/dynamic-field-config.tmpl.php | 4 +++-
 include/staff/tickets.inc.php                         | 4 +++-
 5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/class.forms.php b/include/class.forms.php
index 4de84b36a..e2c8ff18f 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -1626,6 +1626,12 @@ class PhoneNumberWidget extends Widget {
 }
 
 class ChoicesWidget extends Widget {
+    static $media = array(
+        'css' => array(
+            '/css/jquery.multiselect.css',
+        ),
+    );
+
     function render($mode=false) {
 
         if ($mode && $mode == 'view') {
@@ -1683,8 +1689,6 @@ class ChoicesWidget extends Widget {
         <?php
         if ($config['multiselect']) {
          ?>
-        <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.multiselect.min.js"></script>
-        <link rel="stylesheet" href="<?php echo ROOT_PATH; ?>css/jquery.multiselect.css"/>
         <script type="text/javascript">
         $(function() {
             $("#<?php echo $this->name; ?>")
diff --git a/include/client/header.inc.php b/include/client/header.inc.php
index 97085a7cb..c0d0ec7c4 100644
--- a/include/client/header.inc.php
+++ b/include/client/header.inc.php
@@ -37,6 +37,7 @@ if (($lang = Internationalization::getCurrentLanguage())
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery-ui-1.10.3.custom.min.js"></script>
     <script src="<?php echo ROOT_PATH; ?>js/osticket.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/filedrop.field.js"></script>
+    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.multiselect.min.js"></script>
     <script src="<?php echo ROOT_PATH; ?>scp/js/bootstrap-typeahead.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor.min.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor-osticket.js"></script>
diff --git a/include/staff/header.inc.php b/include/staff/header.inc.php
index 238f65853..60079586d 100644
--- a/include/staff/header.inc.php
+++ b/include/staff/header.inc.php
@@ -23,6 +23,7 @@ if (($lang = Internationalization::getCurrentLanguage())
     <script type="text/javascript" src="./js/scp.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.pjax.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/filedrop.field.js"></script>
+    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.multiselect.min.js"></script>
     <script type="text/javascript" src="./js/tips.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor.min.js"></script>
     <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor-osticket.js"></script>
diff --git a/include/staff/templates/dynamic-field-config.tmpl.php b/include/staff/templates/dynamic-field-config.tmpl.php
index fe4116707..da2621b3f 100644
--- a/include/staff/templates/dynamic-field-config.tmpl.php
+++ b/include/staff/templates/dynamic-field-config.tmpl.php
@@ -6,7 +6,9 @@
         <?php
         echo csrf_token();
         $config = $field->getConfiguration();
-        foreach ($field->getConfigurationForm() as $name=>$f) {
+        $form = new Form($field->getConfigurationForm());
+        echo $form->getMedia();
+        foreach ($form->getFields() as $name=>$f) {
             if (isset($config[$name]))
                 $f->value = $config[$name];
             else if ($f->get('default'))
diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php
index 899f54e2a..8c3f4c5ed 100644
--- a/include/staff/tickets.inc.php
+++ b/include/staff/tickets.inc.php
@@ -639,7 +639,9 @@ if ($results) {
             <input class="dp" type="input" size="20" name="endDate">
         </fieldset>
         <?php
-        foreach (TicketForm::getInstance()->getFields() as $f) {
+        $tform = TicketForm::objects()->one();
+        echo $tform->getForm()->getMedia();
+        foreach ($tform->getInstance()->getFields() as $f) {
             if (in_array($f->get('type'), array('text', 'memo', 'phone', 'thread')))
                 continue;
             elseif (!$f->hasData())
-- 
GitLab