diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index d36a56aa4e8db580e24bcd8ea9a2a843ba6d2a15..452e22bf41653150a29354eec7b54f983f9cecd4 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -810,6 +810,9 @@ class DynamicFormEntry extends VerySimpleModel { && in_array($field->get('name'), array('name'))) continue; + // Set the entry ID here so that $field->getClean() can use the + // entry-id if necessary + $a->set('entry_id', $this->get('id')); $val = $field->to_database($field->getClean()); if (is_array($val)) { $a->set('value', $val[0]); @@ -817,7 +820,6 @@ class DynamicFormEntry extends VerySimpleModel { } else $a->set('value', $val); - $a->set('entry_id', $this->get('id')); // Don't save answers for presentation-only fields if ($field->hasData() && !$field->isPresentationOnly()) $a->save(); diff --git a/include/class.forms.php b/include/class.forms.php index 2f597eb0757008ade7abe3a7a624561db47dd420..a20b330929df8c4a38a972971c2ae2f2247d8f8d 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -107,6 +107,35 @@ class Form { else include(CLIENTINC_DIR . 'templates/dynamic-form.tmpl.php'); } + + function getMedia() { + static $dedup = array(); + + foreach ($this->getFields() as $f) { + if (($M = $f->getImpl()->getMedia()) && is_array($M)) { + foreach ($M as $type=>$files) { + foreach ($files as $url) { + $key = strtolower($type.$url); + if (isset($dedup[$key])) + continue; + if ($url[0] == '/') + $url = ROOT_PATH . $url; + + switch (strtolower($type)) { + case 'css': ?> + <link rel="stylesheet" type="text/css" href="<?php echo $url; ?>"/><?php + break; + case 'js': ?> + <script type="text/javascript" src="<?php echo $url; ?>"></script><?php + break; + } + + $dedup[$key] = true; + } + } + } + } + } } require_once(INCLUDE_DIR . "class.json.php"); @@ -410,13 +439,18 @@ class FormField { } function render($mode=null) { - $this->getWidget()->render($mode); + return $this->getWidget()->render($mode); } function renderExtras($mode=null) { return; } + function getMedia() { + $widget = $this->getWidget(); + return $widget::$media; + } + function getConfigurationOptions() { return array(); } @@ -1173,6 +1207,7 @@ FormField::addFieldTypes('Dynamic Fields', function() { }); class Widget { + static $media = null; function __construct($field) { $this->field = $field; diff --git a/include/client/templates/dynamic-form.tmpl.php b/include/client/templates/dynamic-form.tmpl.php index c8e7090ff7c6de45686ee27aa1095e9c440ec5cc..57f1aa2951aed93e9e50cf6d6868c7e9f7c15041 100644 --- a/include/client/templates/dynamic-form.tmpl.php +++ b/include/client/templates/dynamic-form.tmpl.php @@ -5,6 +5,8 @@ ?> <tr><td colspan="2"><hr /> <div class="form-header" style="margin-bottom:0.5em"> + <?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> diff --git a/include/staff/templates/dynamic-form.tmpl.php b/include/staff/templates/dynamic-form.tmpl.php index 98a2776742b6a51cf232f91e0456c1eea253b525..79ebe981bad0798a851d2e61285be0f38613c5d3 100644 --- a/include/staff/templates/dynamic-form.tmpl.php +++ b/include/staff/templates/dynamic-form.tmpl.php @@ -7,6 +7,8 @@ if (isset($options['entry']) && $options['mode'] == 'edit' ) return; +print $form->getMedia(); + if (isset($options['entry']) && $options['mode'] == 'edit') { ?> <tbody> <?php } ?>