1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../../inc/common.php';
5 MTrackACL::requireAnyRights('Enumerations', 'modify');
7 $C = MTrackTicket_CustomFields::getInstance();
9 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
11 $name = $_POST['name'];
12 $type = $_POST['type'];
13 $group = $_POST['group'];
14 $label = $_POST['label'];
15 $options = $_POST['options'];
16 $default = $_POST['default'];
17 $order = (int)$_POST['order'];
19 if (!isset($C->field_types[$type])) {
20 throw new Exception("invalid type $type");
23 $name = MTrackTicket_CustomField::canonName($name);
24 if (!preg_match("/^x_[a-z_]+$/", $name)) {
25 throw new Exception("invalid field name $name");
28 $field = $C->fieldByName($name, true);
30 if (isset($_POST['delete'])) {
31 $C->deleteField($field);
33 $field->group = $group;
34 $field->label = $label;
36 $field->order = $order;
37 $field->options = $options;
38 $field->default = $default;
44 header("Location: ${ABSWEB}admin/customfield.php");
48 mtrack_head("Administration - Custom Fields");
49 echo "<h1>Custom Fields</h1>";
53 if (isset($_GET['add'])) {
54 $field = new MTrackTicket_CustomField;
55 $field->type = 'text';
56 $field->name = 'x_fieldname';
57 $field->label = 'The Label';
58 $field->group = 'Custom Fields';
59 } else if (isset($_GET['field'])) {
60 $field = $C->fieldByName($_GET['field']);
61 if ($field === null) {
62 throw new Exception("No such field " . $_GET['field']);
67 $type = mtrack_select_box('type', $C->field_types, $field->type);
68 $name = htmlentities($field->name, ENT_QUOTES, 'utf-8');
69 $label = htmlentities($field->label, ENT_QUOTES, 'utf-8');
70 $group = htmlentities($field->group, ENT_QUOTES, 'utf-8');
71 $options = htmlentities($field->options, ENT_QUOTES, 'utf-8');
72 $default = htmlentities($field->default, ENT_QUOTES, 'utf-8');
73 $order = $field->order;
75 <form method='post' id='editfield'>
77 <legend>Edit Custom Field</legend>
80 <td><label for='name'>Name</label></td>
81 <td><input type='text' name='name' value='<?php echo $name ?>'><br>
82 <em>The field name to use in the database. Must have a prefix
83 of 'x_' and must only contain characters a-z or underscore.
84 You cannot rename a field; once it is created, it stays
85 in the database. You can use the label field below if you
86 want to change the presentation.</em></td>
89 <td><label for='type'>Type</label></td>
90 <td><?php echo $type ?></td>
93 <td><label for='label'>Label</label></td>
94 <td><input type='text' name='label' value='<?php echo $label ?>'><br>
95 <em>The label to display on the ticket screen</em></td>
98 <td><label for='group'>Group</label></td>
99 <td><input type='text' name='group' value='<?php echo $group ?>'><br>
100 <em>Fields with the same group are grouped together on the ticket
101 editing screen</em></td>
104 <td><label for='default'>Default</label></td>
105 <td><input type='text' name='default' value='<?php echo $default ?>'><br>
106 <em>Enter the default value for this field</em></td>
110 <td><label for='options'>Options</label></td>
111 <td><input type='text' name='options' value='<?php echo $options ?>'><br>
112 <em>For Select and Multi-Select types, enter a list of possible
113 choices here, separated by a pipe character |</em></td>
116 <td><label for='order'>Sort Order</label></td>
118 <input type='text' name='order' value='<?php echo $order ?>'><br>
119 <em>Lower means show first. If two or more fields have same 'order',
120 then they are ordered by name</em>
124 <button type='submit'>Save</button>
125 <button type='submit' name='cancel'>Cancel</button>
126 <button type='submit' name='delete' id='delete-field'>Delete</button>
129 <div id="confirmDeleteDialog" style="display:none"
130 title="Are you sure?">
132 Deleting the field will hide it from the user interface; it will
133 not remove it from the database.
136 If you add the field back later on, the data previously entered
137 will be visible again.
142 $(document).ready(function () {
143 var delete_button = $('#delete-field');
144 var edit_form = $('#editfield');
146 $('#confirmDeleteDialog').dialog({
152 'Delete': function() {
153 $(this).dialog('close');
155 edit_form.append('<input type="hidden" name="delete" value="delete">');
156 delete_button.remove();
160 $(this).dialog('close');
164 $('#delete-field').click(
166 $('#confirmDeleteDialog').dialog('open');
175 $grouped = $C->getGroupedFields();
177 foreach ($grouped as $groupname => $group) {
178 $groupname = htmlentities($groupname, ENT_QUOTES, 'utf-8');
179 echo "<b>Group: $groupname</b><br>\n<table>\n";
180 foreach ($group as $field) {
181 $type = $field->type;
182 $label = htmlentities($field->label, ENT_QUOTES, 'utf-8');
183 $name = $field->name;
184 $name = "<a href=\"{$ABSWEB}admin/customfield.php?field=$name\">$name</a>";
185 echo "<tr><td>$name</td><td>$type</td><td>$label</td></tr>\n";
192 <input type='hidden' name='add' value='1'>
193 <button type='submit'>Add New Field</button>