diff --git a/include/api.tickets.php b/include/api.tickets.php index 81dac7a927134e11e090cc1e356b42e82064b915..25cc9c4d1333f3a78b53e393ddd3afe9a86a6a38 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -18,15 +18,16 @@ class TicketApiController extends ApiController { ); # Fetch dynamic form field names for the given help topic and add # the names to the supported request structure - if (isset($data['topicId'])) { - $topic=Topic::lookup($data['topicId']); - $form=DynamicForm::lookup($topic->ht['form_id']); + if (isset($data['topicId']) + && ($topic = Topic::lookup($data['topicId'])) + && ($form = $topic->getForm())) { foreach ($form->getDynamicFields() as $field) $supported[] = $field->get('name'); } - $form = TicketForm::lookup()->instanciate(); - foreach ($form->getDynamicFields() as $field) - $supported[] = $field->get('name'); + + if(($form = TicketForm::lookup()->instanciate())) + foreach ($form->getDynamicFields() as $field) + $supported[] = $field->get('name'); if(!strcasecmp($format, 'email')) { $supported = array_merge($supported, array('header', 'mid', diff --git a/include/class.topic.php b/include/class.topic.php index 688cb7aaa2715d8e68b6ebfc03f2dc5148175ea6..140e44e6bb1c847fc9dec26e20cfc1f1e0cc0d58 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -21,6 +21,7 @@ class Topic { var $parent; var $page; + var $form; function Topic($id) { $this->id=0; @@ -44,7 +45,7 @@ class Topic { $this->ht = db_fetch_array($res); $this->id = $this->ht['topic_id']; - $this->page = null; + $this->page = $this->form = null; return true; @@ -108,6 +109,17 @@ class Topic { return $this->page; } + function getFormId() { + return $this->ht['form_id']; + } + + function getForm() { + if(!$this->form && $this->getFormId()) + $this->form = DynamicForm::lookup($this->getFormId()); + + return $this->form; + } + function autoRespond() { return (!$this->ht['noautoresp']); }