diff --git a/include/class.forms.php b/include/class.forms.php index 69c4ebbfee556ae3801710539e58310c0d8ff2bf..13d2c42a54680013edb5fe654442bf25b65fe1fe 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -320,6 +320,16 @@ class FormField { return true; } + /** + * FIXME: Temp + * + */ + + function isEditable() { + return (($this->get('edit_mask') & 32) == 0); + } + + /** * parse * diff --git a/include/class.list.php b/include/class.list.php index 009f88921e538e8e9a0c48e94bcc5b6f0d475f4b..dfee67d558d3ef2a56ac81f16e14fa8a090c82a7 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -554,7 +554,8 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { $this->_form = DynamicForm::lookup( array('type'=>'L'.$this->get('list_id')))->getForm($source); if (!$source && $config) { - foreach ($this->_form->getFields() as $f) { + $fields = $this->_form->getFields(); + foreach ($fields as $f) { $name = $f->get('id'); if (isset($config[$name])) $f->value = $f->to_php($config[$name]); @@ -563,6 +564,7 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { } } } + return $this->_form; } @@ -802,21 +804,81 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { return $this->_form; } + function getExtraConfigOptions($source=null) { + + + $status_choices = array( 0 => __('System Default')); + if (($statuses=TicketStatusList::getStatuses( + array( 'enabled' => true, 'states' => + array('open'))))) + foreach ($statuses as $s) + $status_choices[$s->getId()] = $s->getName(); + + + return array( + 'allowreopen' => new BooleanField(array( + 'label' =>__('Allow Reopen'), + 'default' => isset($source['allowreopen']) + ? $source['allowreopen']: true, + 'id' => 'allowreopen', + 'name' => 'allowreopen', + 'configuration' => array( + 'desc'=>__('Allow tickets on this status to be reopened by end users'), + ), + 'visibility' => new VisibilityConstraint( + new Q(array('state__eq'=>'closed')), + VisibilityConstraint::HIDDEN + ), + )), + 'reopenstatus' => new ChoiceField(array( + 'label' => __('Reopen Status'), + 'required' => false, + 'default' => isset($source['reopenstatus']) + ? $source['reopenstatus'] : 0, + 'id' => 'reopenstatus', + 'name' => 'reopenstatus', + 'choices' => $status_choices, + 'configuration' => array( + 'widget' => 'dropdown', + 'multiselect' =>false + ), + 'visibility' => new VisibilityConstraint( + new Q(array('allowreopen__eq'=> true)), + VisibilityConstraint::HIDDEN + ), + )) + ); + } + function getConfigurationForm($source=null) { - if ($form = $this->getForm()) { - $config = $this->getConfiguration(); - $form = $form->getForm($source); - if (!$source && $config) { - foreach ($form->getFields() as $f) { - $name = $f->get('id'); - if (isset($config[$name])) - $f->value = $f->to_php($config[$name]); - else if ($f->get('default')) - $f->value = $f->get('default'); + if (!($form = $this->getForm())) + return null; + + $config = $this->getConfiguration(); + $form = $form->getForm($source); + $fields = $form->getFields(); + foreach ($fields as $k => $f) { + if ($f->get('name') == 'state' //TODO: check if editable. + && ($extras=$this->getExtraConfigOptions($source))) { + foreach ($extras as $extra) { + $extra->setForm($form); + $fields->insert(++$k, $extra); } + break; } } + + if (!$source && $config) { + foreach ($fields as $f) { + $name = $f->get('id'); + if (isset($config[$name])) + $f->value = $f->to_php($config[$name]); + else if ($f->get('default')) + $f->value = $f->get('default'); + } + } + return $form; } @@ -824,6 +886,34 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { return $this->hasFlag('mode', self::ENABLED); } + function isReopenable() { + + if (strcasecmp($this->get('state'), 'closed')) + return true; + + if (($c=$this->getConfiguration()) + && $c['allowreopen'] + && isset($c['reopenstatus'])) + return true; + + return false; + } + + function getReopenStatus() { + global $cfg; + + $status = null; + if ($this->isReopenable() + && ($c = $this->getConfiguration()) + && isset($c['reopenstatus'])) + $status = TicketStatus::lookup( + $c['reopenstatus'] ?: $cfg->getDefaultTicketStatusId()); + + return ($status + && !strcasecmp($status->getState(), 'open')) + ? $status : null; + } + function enable() { // Ticket status without properties cannot be enabled! diff --git a/include/i18n/en_US/ticket_status.yaml b/include/i18n/en_US/ticket_status.yaml index d19b4c0d7fc8b652fb27c98962640586b36e22ab..3dc9b52669593dcaee93ccda318bdf1c63a0250b 100644 --- a/include/i18n/en_US/ticket_status.yaml +++ b/include/i18n/en_US/ticket_status.yaml @@ -29,6 +29,8 @@ sort: 2 flags: 0 properties: + allowreopen: true + reopenstatus: 0 description: > Closed tickets. Tickets will still be accessible on client and staff panels. diff --git a/include/staff/templates/list-item-properties.tmpl.php b/include/staff/templates/list-item-properties.tmpl.php index 51e26b65a55a3a205011cef58951d11280875619..a8d158f98e5641ade0376c8090fec148fe8ff62f 100644 --- a/include/staff/templates/list-item-properties.tmpl.php +++ b/include/staff/templates/list-item-properties.tmpl.php @@ -10,8 +10,12 @@ $internal = $item->isInternal(); $form = $item->getConfigurationForm(); echo $form->getMedia(); - foreach ($form->getFields() as $f) { ?> - <div class="custom-field"> + foreach ($form->getFields() as $f) { + ?> + <div class="custom-field" id="field<?php + echo $f->getWidget()->id; ?>" + <?php + if (!$f->isVisible()) echo 'style="display:none;"'; ?>> <div class="field-label"> <label for="<?php echo $f->getWidget()->name; ?>" style="vertical-align:top;padding-top:0.2em"> diff --git a/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql b/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql index 2e00737d85eb832e93a4cf9cf304afe152a758c4..3b117941e70a36c183b3ef9cfcce934d95ee532f 100644 --- a/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql +++ b/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql @@ -27,6 +27,10 @@ UPDATE `%TABLE_PREFIX%ticket_status` s ON(c.namespace = CONCAT('TS.', s.id) AND c.key='properties') SET s.properties = c.value; +-- add default reopen settings to existing closed state statuses +UPDATE `%TABLE_PREFIX%ticket_status` + SET `properties`= INSERT(`properties`, 2, 0, '"allowreopen":true,"reopenstatus":0,') + WHERE `state` = 'closed'; -- Set new schema signature UPDATE `%TABLE_PREFIX%config`