Skip to content
Snippets Groups Projects
Commit 28cd0b47 authored by Jared Hancock's avatar Jared Hancock
Browse files

Merge pull request #1779 from protich/issue/helptopics


bugs: Fix  help topic create + forms

Reviewed-By: default avatarJared Hancock <jared@osticket.com>
parents 7df3fced ef8acc8e
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@ class DynamicFormsAjaxAPI extends AjaxController {
}
foreach ($topic->getForms() as $form) {
if (!$form->hasAnyVisibleFields())
continue;
ob_start();
$form->getForm($_SESSION[':form-data'])->render(!$client);
$html .= ob_get_clean();
......
......@@ -125,6 +125,23 @@ class DynamicForm extends VerySimpleModel {
}
}
function hasAnyVisibleFields($user=false) {
global $thisstaff, $thisclient;
$user = $user ?: $thisstaff ?: $thisclient;
$visible = 0;
$isstaff = $user instanceof Staff;
foreach ($this->getFields() as $F) {
if ($isstaff) {
if ($F->isVisibleToStaff())
$visible++;
}
elseif ($F->isVisibleToUsers()) {
$visible++;
}
}
return $visible > 0;
}
function instanciate($sort=1) {
return DynamicFormEntry::create(array(
'form_id'=>$this->get('id'), 'sort'=>$sort));
......
......@@ -82,14 +82,7 @@ if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) {
</tbody>
<tbody id="dynamic-form">
<?php foreach ($forms as $form) {
$hasFields = false;
foreach ($form->getFields() as $f) {
if ($f->isVisibleToUsers()) {
$hasFields = true;
break;
}
}
if (!$hasFields)
if (!$form->hasAnyVisibleFields())
continue;
include(CLIENTINC_DIR . 'templates/dynamic-form.tmpl.php');
} ?>
......
<?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',
......
......@@ -263,14 +263,7 @@ if ($_POST)
<tbody id="dynamic-form">
<?php
foreach ($forms as $form) {
$hasFields = false;
foreach ($form->getFields() as $f) {
if ($f->isVisibleToStaff()) {
$hasFields = true;
break;
}
}
if (!$hasFields)
if (!$form->hasAnyVisibleFields())
continue;
print $form->getForm()->getMedia();
include(STAFFINC_DIR . 'templates/dynamic-form.tmpl.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']){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment