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

Add `flags` to %form

Also make forms deleteble by marking them as deleted and hiding them from
the form listing. This ensures that custom data always has a link back to
the form.
parent 20464812
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,9 @@ class DynamicForm extends VerySimpleModel {
'O' => 'Organization Information',
);
const FLAG_DELETABLE = 0x0001;
const FLAG_DELETED = 0x0002;
var $_form;
var $_fields;
var $_has_data = false;
......@@ -124,7 +127,11 @@ class DynamicForm extends VerySimpleModel {
}
function isDeletable() {
return $this->get('deletable');
return $this->flags & self::FLAG_DELETABLE;
}
function setFlag($flag) {
$this->flags |= $flag;
}
function hasAnyVisibleFields($user=false) {
......@@ -173,6 +180,7 @@ class DynamicForm extends VerySimpleModel {
function save($refetch=false) {
if (count($this->dirty))
$this->set('updated', new SqlFunction('NOW'));
// XXX: This should go to an update routine
if (isset($this->dirty['notes']))
$this->notes = Format::sanitize($this->notes);
if ($rv = parent::save($refetch | $this->dirty))
......@@ -183,8 +191,9 @@ class DynamicForm extends VerySimpleModel {
function delete() {
if (!$this->isDeletable())
return false;
else
return parent::delete();
$this->setFlag(self::FLAG_DELETED);
return $this->save();
}
function getExportableFields($exclude=array()) {
......
......@@ -7,7 +7,8 @@
# title: Bold section title of the form
# instructions: Title deck, detailed instructions on entering form data
# notes: Notes for the form, shown under the fields
# deletable: True if the form can be removed from the system
# flags:
# 0x0001 If the form can be removed from the system
# fields: List of fields for the form
# type: Field type (short name) (eg. 'text', 'memo', 'phone', ...)
# label: Field label shown to the user
......@@ -35,7 +36,7 @@
- id: 1
type: U # notrans
title: Contact Information
deletable: false
flags: 0
fields:
- type: text # notrans
name: email # notrans
......@@ -75,7 +76,7 @@
This form will be attached to every ticket, regardless of its source.
You can add any fields to this form and they will be available to all
tickets, and will be searchable with advanced search and filterable.
deletable: false
flags: 0
fields:
- id: 20
type: text # notrans
......@@ -102,7 +103,7 @@
- type: C # notrans
title: Company Information
instructions: Details available in email templates
deletable: false
flags: 0
fields:
- type: text # notrans
name: name # notrans
......@@ -140,7 +141,7 @@
- type: O # notrans
title: Organization Information
instructions: Details on user organization
deletable: false
flags: 0
fields:
- type: text # notrans
name: name # notrans
......@@ -186,7 +187,7 @@
instructions: Please Describe The Issue
notes: |
This form is used to create a task.
deletable: false
flags: 0
fields:
- type: text # notrans
name: title # notrans
......
......@@ -7,8 +7,12 @@
<div class="clear"></div>
<?php
$other_forms = DynamicForm::objects()
->filter(array('type'=>'G'))
->exclude(array('flags__hasbit' => DynamicForm::FLAG_DELETED));
$page = ($_GET['p'] && is_numeric($_GET['p'])) ? $_GET['p'] : 1;
$count = DynamicForm::objects()->filter(array('type__in'=>array('G')))->count();
$count = $other_forms->count();
$pageNav = new Pagenate($count, $page, PAGE_LIMIT);
$pageNav->setURL('forms.php');
$showing=$pageNav->showing().' '._N('form','forms',$count);
......@@ -56,8 +60,7 @@ $showing=$pageNav->showing().' '._N('form','forms',$count);
</tr>
</thead>
<tbody>
<?php foreach (DynamicForm::objects()->filter(array('type'=>'G'))
->order_by('title')
<?php foreach ($other_forms->order_by('title')
->limit($pageNav->getLimit())
->offset($pageNav->getStart()) as $form) {
$sel=false;
......
......@@ -40,6 +40,13 @@ ALTER TABLE `%TABLE_PREFIX%thread_entry`
ADD `editor` int(10) unsigned NULL AFTER `poster`,
ADD `editor_type` char(1) NULL AFTER `editor`;
ALTER TABLE `%TABLE_PREFIX%form`
CHANGE `deletable` `flags` int(10) unsigned NOT NULL DEFAULT 1;
-- Previous versions did not correctly mark the internal forms as NOT deletable
UPDATE `%TABLE_PREFIX%form`
SET `flags` = 0 WHERE `type` IN ('T','U','C','O','A');
-- Finished with patch
UPDATE `%TABLE_PREFIX%config`
SET `value` = '00000000000000000000000000000000'
......
......@@ -117,7 +117,7 @@ CREATE TABLE `%TABLE_PREFIX%form` (
`id` int(11) unsigned NOT NULL auto_increment,
`pid` int(10) unsigned DEFAULT NULL,
`type` varchar(8) NOT NULL DEFAULT 'G',
`deletable` tinyint(1) NOT NULL DEFAULT 1,
`flags` int(10) unsigned NOT NULL DEFAULT 1,
`title` varchar(255) NOT NULL,
`instructions` varchar(512),
`name` varchar(64) NOT NULL DEFAULT '',
......
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