ticket_fields.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:46k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: ticket_fields.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.26 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Custom ticket field maintenance (administration page)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- admin_header('Links', 'Ticket Fields');
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view";
- }
- // globalise variables
- $global = array (
- array('id', 'number'),
- array('type')
- );
- rg($global);
- language_check();
- ############################### CREATE INDEX ###############################
- if ($_REQUEST['do'] == 'createindex') {
- $db->query("SHOW INDEX FROM ticket");
- while ($index = $db->row_array()) {
- $indexed[$index['Column_name']] = 1;
- }
- $column = $db->query_return("SELECT name FROM ticket_def WHERE id = '$_REQUEST[id]'");
- $column = $column['name'];
- if (!$indexed[$column]) {
- $db->query("CREATE INDEX $column ON ticket ($column(20))");
- alert('Index created.');
- $_REQUEST['do'] = 'view';
- } else {
- alert('Index already present.');
- }
- }
- ############################### DELETE INDEX ###############################
- if ($_REQUEST['do'] == 'dropindex') {
- $db->query("SHOW INDEX FROM ticket");
- while ($index = $db->row_array()) {
- $indexed[$index['Column_name']] = 1;
- }
- $column = $db->query_return("SELECT name FROM ticket_def WHERE id = '$_REQUEST[id]'");
- $column = $column['name'];
- if ($indexed[$column]) {
- $db->query("DROP INDEX $column ON ticket");
- alert('Index removed.');
- $_REQUEST['do'] = 'view';
- } else {
- alert('No index present.');
- }
- }
- ############################### CREATE NEW PROFILE FIELDS ###############################
- if (($_REQUEST['do'] == "new3") OR ($_REQUEST['do'] == "update")) {
- if ($_REQUEST['regex'] != NULL) {
- $match = @preg_match($_REQUEST['regex'], '');
- if (!is_int($match)) { // It's invalid unless $match is an integer
- mistake('The regular expression you specified is invalid. Refer to
- PHP's manual
- for current information about PHP's implementation of Perl-compatible
- Regular Expressions. This may assist you in building a valid regular
- expression. Please go back and correct the regular expression.');
- exit;
- }
- }
- // code for creating a new field
- if ($_REQUEST['do'] == "new3") {
- $query = "INSERT INTO ticket_def SET ";
- // get max field number
- $db->query("SELECT name FROM ticket_def WHERE name LIKE 'custom%'");
- while ($results = $db->row_array()) {
- eregi("^custom([0-9]*)", $results[name], $value);
- if ($max < $value[1]) {
- $max = $value[1];
- }
- }
- $max++;
- $name = "custom" . $max;
- // create the column
- $db->query("ALTER TABLE ticket ADD $name MEDIUMTEXT");
- // sort out field
- $user_field[formtype] = $_REQUEST[formtype];
- // code for updating a field
- } elseif ($_REQUEST['do'] == "update") {
-
- $user_field = $db->query_return("SELECT * FROM ticket_def WHERE id = " . intval($id));
- $query = "UPDATE ticket_def SET ";
- $name = $user_field[name];
- }
- ############################### THE FIELD DATA ###############################
- if (($user_field[formtype] == "checkbox") OR
- ($user_field[formtype] == "radio") OR
- ($user_field[formtype] == "select")) {
- // build array of current data
- $temp_data = unserialize($user_field[data]);
- if (is_array($temp_data)) {
- foreach($temp_data AS $key => $var) {
- $with_content[] = $temp_data[$key][0];
- }
- }
-
- // build array of new data
- if (is_array($_REQUEST[elementid])) {
- foreach($_REQUEST[elementid] AS $key => $var) {
- if (!is_int($key)) {
- $key++;
- }
- if ($_REQUEST[name][$key] != "") {
- $data[] = array(
- $key,
- $_REQUEST[order][$key],
- $_REQUEST[name][$key],
- $_REQUEST[start][$key]
- );
- } else {
- // check if there used to be value
- if (is_array($with_content)) {
- if (in_array($key, $with_content)) {
- // row needs to be deleted from the database
- $db->query("
- UPDATE ticket SET $user_field[name] = REPLACE ($user_field[name], '$key|||', '')
- ");
- }
- }
- }
- }
- }
- // sort based on order
- if (is_array($data)) {
- usort($data, "array_order2");
- }
- // convert to data to store in database
- $data = serialize($data);
- }
- ############################### LANGUAGE BITS ###############################
- if ($settings[language_on]) {
- $_REQUEST[display_name] = serialize($_REQUEST[display_name]);
- $_REQUEST[description] = serialize($_REQUEST[description]);
- $_REQUEST[error_message] = serialize($_REQUEST[error_message]);
- } else {
- $display_name = unserialize($user_field[display_name]);
- $description = unserialize($user_field[description]);
- $error_message = unserialize($user_field[error_message]);
- $display_name[$settings[default_language]] = $_REQUEST['display_name'];
- $description[$settings[default_language]] = $_REQUEST['description'];
- $error_message[$settings[default_language]] = $_REQUEST['error_message'];
- $_REQUEST[display_name] = serialize($display_name);
- $_REQUEST[description] = serialize($description);
- $_REQUEST[error_message] = serialize($error_message);
- }
- ############################### INPUT ###############################
- if ($user_field[formtype] == "input") {
- $query .= "
- name = '$name',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- ticket_start = '".mysql_escape_string($_REQUEST['ticket_start'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
- default_value = '".mysql_escape_string($_REQUEST['default_value'])."',
- parsed_default_value = '".mysql_escape_string($_REQUEST['parsed_default_value'])."',
- minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
- maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
- displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
- regex = '".mysql_escape_string($_REQUEST['regex'])."',
- error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
- length = '".mysql_escape_string($_REQUEST['length'])."',
- formtype = 'input'
- ";
- ############################### TEXTAREA ###############################
- } elseif ($user_field[formtype] == "textarea") {
- $query .= "
- name = '$name',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- ticket_start = '".mysql_escape_string($_REQUEST['ticket_start'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
- default_value = '".mysql_escape_string($_REQUEST['default_value'])."',
- parsed_default_value = '".mysql_escape_string($_REQUEST['parsed_default_value'])."',
- minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
- maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
- displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
- regex = '".mysql_escape_string($_REQUEST['regex'])."',
- error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
- length = '".mysql_escape_string($_REQUEST['length'])."',
- height = '".mysql_escape_string($_REQUEST['height'])."',
- formtype = 'textarea'
- ";
- ############################### RADIO ###############################
- } elseif ($user_field[formtype] == "radio") {
- $query .= "
- name = '$name',
- data = '".mysql_escape_string($data)."',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- required = '".mysql_escape_string($_REQUEST['required'])."',
- ticket_start = '".mysql_escape_string($_REQUEST['ticket_start'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
- displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
- extrainput = '".mysql_escape_string($_REQUEST['extrainput'])."',
- perline = '".mysql_escape_string($_REQUEST['perline'])."',
- extrainput_location = '".mysql_escape_string($_REQUEST['extrainput_location'])."',
- extrainput_text = '".mysql_escape_string($_REQUEST['extrainput_text'])."',
- minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
- maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
- regex = '".mysql_escape_string($_REQUEST['regex'])."',
- error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
- length = '".mysql_escape_string($_REQUEST['length'])."',
- formtype = 'radio'
- ";
- ############################### SELECT ###############################
- } elseif ($user_field[formtype] == "select") {
- $query .= "
- name = '$name',
- data = '".mysql_escape_string($data)."',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- required = '".mysql_escape_string($_REQUEST['required'])."',
- ticket_start = '".mysql_escape_string($_REQUEST['ticket_start'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
- displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
- extrainput = '".mysql_escape_string($_REQUEST['extrainput'])."',
- extrainput_location = '".mysql_escape_string($_REQUEST['extrainput_location'])."',
- extrainput_text = '".mysql_escape_string($_REQUEST['extrainput_text'])."',
- minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
- maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
- maxoptions = '".mysql_escape_string($_REQUEST['maxoptions'])."',
- minoptions = '".mysql_escape_string($_REQUEST['minoptions'])."',
- multiselect = '".mysql_escape_string($_REQUEST['multiselect'])."',
- height = '".mysql_escape_string($_REQUEST['height'])."',
- regex = '".mysql_escape_string($_REQUEST['regex'])."',
- error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
- length = '".mysql_escape_string($_REQUEST['length'])."',
- formtype = 'select'
- ";
- ############################### CHECKBOX ###############################
- } elseif ($user_field[formtype] == "checkbox") {
- $query .= "
- name = '$name',
- data = '".mysql_escape_string($data)."',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- minoptions = '".mysql_escape_string($_REQUEST['minoptions'])."',
- maxoptions = '".mysql_escape_string($_REQUEST['maxoptions'])."',
- ticket_start = '".mysql_escape_string($_REQUEST['ticket_start'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
- displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
- extrainput = '".mysql_escape_string($_REQUEST['extrainput'])."',
- multiselect = '".mysql_escape_string($_REQUEST['multiselect'])."',
- minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
- maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
- perline = '".mysql_escape_string($_REQUEST['perline'])."',
- error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
- length = '".mysql_escape_string($_REQUEST['length'])."',
- formtype = 'checkbox'
- ";
- ############################### SYSTEM ###############################
- } elseif ($user_field[formtype] == "system") {
- unset($data);
- $data[when][reg1] = $_REQUEST['reg1'];
- $data[when][reg2] = $_REQUEST['reg2'];
- $data[when][usermod] = $_REQUEST['usermod'];
- $data[when][techmod] = $_REQUEST['techmod'];
- $data[when][technew] = $_REQUEST['technew'];
- $data[code][code] = $_REQUEST['code'];
- $data[code][variable] = $_REQUEST['variable'];
- $data = serialize($data);
- $query .= "
- name = '$name',
- data = '".mysql_escape_string($data)."',
- display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
- description = '".mysql_escape_string($_REQUEST['description'])."',
- user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
- tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
- formtype = 'system'
- ";
-
- }
- ############################### FINISH AND REDIRECT ###############################
- if ($_REQUEST['do'] == "new3") {
- $db->query($query);
- $id = $db->last_id();
- jump("ticket_fields.php?do=edit&id=$id", 'New field has been created<br />Redirecting you to your new field');
- } else {
- $db->query($query . "WHERE id = " . intval($id));
- jump("ticket_fields.php?do=edit&id=$id", 'Field has been updated<br />Redirecting you to the updated field');
- }
- }
- ############################### EDIT PROFILE FIELDS ###############################
- if (($_REQUEST['do'] == "edit") OR ($_REQUEST['do'] == "new2")) {
- // set form action for field editing
- if ($_REQUEST['do'] == "edit") {
-
- $user_field = $db->query_return("
- SELECT * FROM ticket_def
- WHERE id = '$id'
- ");
- echo "
- <form do="ticket_fields.php" method="post" name="fields">
- <input type="hidden" name="do" value="update">
- <input type="hidden" name="id" value="$user_field[id]">
- ";
- // set form action for new field creation
- } else {
- $user_field[formtype] = $type;
- echo "
- <form do="ticket_fields.php" method="post" name="fields">
- <input type="hidden" name="do" value="new3">
- <input type="hidden" name="type" value="$user_field[formtype]">
- ";
- }
- ############################### LANGUAGE BITS ###############################
- $user_field[display_name] = unserialize($user_field[display_name]);
- $user_field[description] = unserialize($user_field[description]);
- $user_field[error_message] = unserialize($user_field[error_message]);
- if ($settings[language_on]) {
-
- $name = "<div id="name"><table cellpadding="2" cellspacing="0">";
- $description = "<div id="description"><table cellpadding="2" cellspacing="0">";
- $error = "<div id="error"><table cellpadding="2" cellspacing="0">";
- $db->query("SELECT * FROM languages WHERE is_selectable = 1");
- while ($lang = $db->row_array()) {
- $name .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_input($lang[id], $user_field[display_name][$lang[id]], 30, 'display_name') . "</td></tr>";
- $description .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_textarea($lang[id], 40, 5, $user_field[description][$lang[id]], 'description') . "</td></tr>";
- $error .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_textarea($lang[id], 40, 5, $user_field[error_message][$lang[id]], 'error_message') . "</td></tr>";
- }
- $name .= "</table><input type="button" value="Hide Language Options" onclick="oc('name');oc('name2')"></div><div id="name2"><input type="button" value="View Language Options" onclick="oc('name');oc('name2');"><div><script>oc('name')</script>";
- $description .= "</table><input type="button" value="Hide Language Options" onclick="oc('description');oc('description2')"></div><div id="description2"><input type="button" value="View Language Options" onclick="oc('description');oc('description2');"><div><script>oc('description')</script>";
-
- $error .= "</table><input type="button" value="Hide Language Options" onclick="oc('error');oc('error2')"></div><div id="error2"><input type="button" value="View Language Options" onclick="oc('error');oc('error2');"><div><script>oc('error')</script>";
- } else {
- $name = form_input('display_name', $user_field[display_name][$settings[default_language]]);
- $description = form_textarea('description', 50, 5, $user_field[description][$settings[default_language]]);
- $error = form_textarea('error_message', 50, 5, $user_field[error_message][$settings[default_language]]);
- }
- ############################### STANDARD FOR ALL ###############################
- // display options
- $table[] = array('<b>Display Name</b><br />This is the name of the field that will be presented to technicians and users', $name);
- // show different message if new/edit
- if ($_REQUEST['do'] == "edit") {
- $table[] = array('<b>Database Name</b><br />This is the name of the field as it is in the database. This is the name you would use to call the value in your templates', $user_field[name]);
- } else {
- $table[] = array('<b>Database Name</b><br />This is the name of the field as it is in the database. This is the name you would use to call the value in your templates', '<I>Generated upon field creation</I>');
- }
- $table[] = array('<b>Description</b><br />The description that will be presented for this field to your users', $description);
- if ($user_field[formtype] != "system") {
- $table[] = array('<b>Display During Ticket Creation</b><br />Do you wish this field to be presented to the user during new ticket creation?', form_radio_yn('ticket_start', '', $user_field[ticket_start]));
- }
- $width = array('60%', '40%');
- table_header('Field Details');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // field permissions
- $table[] = array('<b>User Viewable</b><br />Do you wish to allow your users to view this field?', form_radio_yn('user_viewable', '', $user_field[user_viewable]));
- if ($user_field[formtype] != "system") {
- $table[] = array('<b>User Editable</b><br />Do you wish to allow your users to edit the data held in this field?', form_radio_yn('user_editable', '', $user_field[user_editable]));
- }
- $table[] = array('<b>Tech Viewable</b><br />Do you wish to allow your staff to view this field?', form_radio_yn('tech_viewable', '', $user_field[tech_viewable]));
- if ($user_field[formtype] != "system") {
- $table[] = array('<b>Tech Editable</b><br />Do you wish to allow your staff to edit this field?', form_radio_yn('tech_editable', '', $user_field[tech_editable]));
- }
- $width = array('60%', '40%');
- table_header('Field Permissions');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- ############################### INPUT ###############################
- if ($user_field[formtype] == "input") {
- echo form_hidden('formtype', 'input');
- // regex
- $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
- $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
- $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual. A custom regex overrides any stipulations on minimum or maximum field length', form_input('regex', $user_field[regex], '45'));
- $table[] = array('<b>Error Message</b><br />If the user enters text that fails the criteria you have specified above, this is the error that will be presented', $error);
- $width = array('60%', '40%');
- table_header('Field Criteria');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // default value
- $table[] = array('<b>Default Value</b><br />You may specify a default starting value here', form_input('default_value', $user_field[default_value], '45'));
- $table[] = array('<b>Parsed Default Value</b><br />You may specify a parsed default value. This overrides any default value you may have set.', form_input('parsed_default_value', $user_field[parsed_default_value], '45'));
- $width = array('60%', '40%');
- table_header('Default Value');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // display properties
- $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '4'));
- $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '4'));
- $width = array('60%', '40%');
- table_header('Field Display Properties');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- ############################### TEXTAREA ###############################
- } elseif ($user_field[formtype] == "textarea") {
- echo form_hidden('formtype', 'textarea');
- // regex
- $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
- $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
- $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual. A custom regex overrides any stipulations on minimum or maximum field length', form_input('regex', $user_field[regex], '45'));
- $table[] = array('<b>Error Message</b><br />If the user enters text that fails the criteria you have specified above, this is the error that will be presented', $error);
- $width = array('60%', '40%');
- table_header('Field Criteria');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // default value
- $table[] = array('<b>Default Value</b><br />You may specify a default starting value here', form_input('default_value', $user_field[default_value], '45'));
- $table[] = array('<b>Parsed Default Value</b><br />You may specify a parsed default value. This overrides any default value you may have set.', form_input('parsed_default_value', $user_field[parsed_default_value], '45'));
- $width = array('60%', '40%');
- table_header('Default Value');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // display properties
- $table[] = array('<b>Length</b><br />How long do you wish the TEXTAREA field to be?', form_input('length', $user_field[length], '4'));
- $table[] = array('<b>Height</b><br />How many lines do you wish the TEXTAREA field to have?', form_input('height', $user_field[height], '4'));
- $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '4'));
- $width = array('60%', '40%');
- table_header('Field Display Properties');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- ############################### RADIO ###############################
- } elseif ($user_field[formtype] == "radio") {
- echo form_hidden('formtype', 'radio');
- // regex
- $table[] = array('<b>Require a Selection</b><br />Set yes to require the selection of a radio element)', form_radio_yn('required', '', $user_field[required]));
- $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
- $width = array('60%', '40%');
- table_header('Field Criteria');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // display properties
- $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
- $table[] = array('<b>Radio Elements Per line</b><br />How many radio elements do you want to display per line?', form_input('perline', $user_field[perline], '3'));
- $width = array('60%', '40%');
- table_header('Field Display Properties');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // extra bit
- $table[] = array('<b>Allow Alternative Input</b><br />Selecting Yes will generate an alternative INPUT field that will allow your user to enter custom information if none of the SELECT options are suitable. If you enable this feature it will override the requirement of a selection you may have set earlier.', form_radio_yn('extrainput', '', $user_field[extrainput], '', 'onClick="extrainput2();"'));
- $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
- $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
- $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual.', form_input('regex', $user_field[regex], '45'));
- $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '3'));
- $table[] = array('<b>Extrainput Text</b><br />The text to display to explain the presence of the input box. For example <I>Or enter your own option</I>', form_input('extrainput_text', $user_field[extrainput_text], 45));
- $table[] = array('<b>Extrainput Location</b><br />Do you want the INPUT field to be displayed on a new line?', form_radio_yn('extrainput_location', '', $user_field[extrainput_location]));
- $width = array('60%', '40%');
- table_header('Extra Input');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- $field_data = unserialize($user_field[data]);
- // get max number for creating new fields
- if (is_array($field_data)) {
- while (list ($key, $val) = each ($field_data)) {
- $array_count[] = $field_data[$key][0];
- }
- $max = max($array_count);
- reset($field_data);
- }
- $field_data[] = array($max+1, '', '', '', '');
- $field_data[] = array($max+2, '', '', '', '');
- $field_data[] = array($max+3, '', '', '', '');
- $field_data[] = array($max+4, '', '', '', '');
- $field_data[] = array($max+5, '', '', '', '');
- while (list ($key, $val) = each ($field_data)) {
- $table[] = array(
- $val[0] . form_hidden($key, '1', $arrayto='elementid'),
- form_input($val[0], $val[1], '3', 'order'),
- iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
- form_input($val[0], $val[2], '45', 'name'),
- form_radio_yn($val[0], 'start', $val[3])
- );
- }
- $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
- table_header('Field Data');
- table_content($columns, $table);
- table_footer();
- unset($table);
- // javascript to control options
- ?>
- <SCRIPT>
- function extrainput2() {
- var value;
- for (value = 0; value < document.fields.extrainput.length; value++)
- {
- if (document.fields.extrainput[value].checked == true)
- {
- yesno = document.fields.extrainput[value].value;
- }
- }
- if (yesno == '1')
- {
- document.fields.minlength.disabled=false;
- document.fields.maxlength.disabled=false;
- document.fields.regex.disabled=false;
- document.fields.length.disabled=false;
- document.fields.extrainput_location[0].disabled=false;
- document.fields.extrainput_location[1].disabled=false;
- document.fields.extrainput_text.disabled=false;
- } else {
- document.fields.minlength.disabled=true;
- document.fields.maxlength.disabled=true;
- document.fields.regex.disabled=true;
- document.fields.length.disabled=true;
- document.fields.extrainput_location[0].disabled=true;
- document.fields.extrainput_location[1].disabled=true;
- document.fields.extrainput_text.disabled=true;
- }
- }
- extrainput2();
- </SCRIPT>
- <?
- // javascript to only allow one selected by default
- ############################### SELECT ###############################
- } elseif ($user_field[formtype] == "select") {
- echo form_hidden('formtype', 'select');
- // regex
- $table[] = array('<b>Require a Selection</b><br />Do you wish to require a selection. Note this field has no affect if you allow multiple selections, you should use the minimum option setting to control the amount of required information.', form_radio_yn('required', '', $user_field[required]));
- $table[] = array('<b>Allow multiple selections</b><br />By allowing multiple selections your users can pick a number of options from the select menu. In terms of HTML, the element becomes a multiselect field. <b>Note:</b> enabling multiselect disables the alternative input option', form_radio_yn('multiselect', '', $user_field[multiselect], '', 'onClick="multipleselect();"'));
- $table[] = array('<b>Maximum Options</b><br />The maximum number of options that can be selected. Set a 0 to have no maximum. (only applies if you are allowing multiple selections)', form_input('maxoptions', $user_field[maxoptions], '3'));
- $table[] = array('<b>Minimum Options</b><br />The minimum amount of options that must be selected. Set a 0 to have no minumum. (only applies if you are allowing multiple selections otherwise use the require a selection setting)', form_input('minoptions', $user_field[minoptions], '3'));
- $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
- $width = array('60%', '40%');
- table_header('Field Criteria');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // display properties
- $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
- $table[] = array('<b>Height</b><br />How many rows do you wish to display for the select menu', form_input('height', $user_field[height], '3'));
- $width = array('60%', '40%');
- table_header('Field Display Properties');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // extra bit
- $table[] = array('<b>Allow Alternative Input</b><br />Selecting Yes will generate an alternative INPUT field that will allow your user to enter custom information if none of the SELECT options are suitable. If you enable this feature it will override the requirement of a selection you may have set earlier.', form_radio_yn('extrainput', '', $user_field[extrainput], '', 'onClick="extrainput2();"'));
- $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
- $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
- $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual', form_input('regex', $user_field[regex], '45'));
- $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '3'));
- $table[] = array('<b>Extrainput Text</b><br />The text to display to explain the presence of the input box. For example <I>Or enter your own option</I>', form_input('extrainput_text', $user_field[extrainput_text], 45));
- $table[] = array('<b>Extrainput Location</b><br />Do you want the INPUT field to be displayed on a new line?', form_radio_yn('extrainput_location', '', $user_field[extrainput_location]));
- $width = array('60%', '40%');
- table_header('Extra Input');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- $field_data = unserialize($user_field[data]);
- // get max number for creating new fields
- if (is_array($field_data)) {
- while (list ($key, $val) = each ($field_data)) {
- $array_count[] = $field_data[$key][0];
- }
- $max = max($array_count);
- reset($field_data);
- }
- $field_data[] = array($max+1, '', '', '');
- $field_data[] = array($max+2, '', '', '');
- $field_data[] = array($max+3, '', '', '');
- $field_data[] = array($max+4, '', '', '');
- $field_data[] = array($max+5, '', '', '');
- while (list ($key, $val) = each ($field_data)) {
- $table[] = array(
- $val[0] . form_hidden($val[0], '1', $arrayto='elementid'),
- form_input($val[0], $val[1], '3', 'order'),
- iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
- form_input($val[0], $val[2], '45', 'name'),
- form_radio_yn($val[0], 'start', $val[3])
- );
- }
- $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
- table_header('Field Data');
- table_content($columns, $table);
- table_footer();
- unset($table);
- // javascript to control options
- ?>
- <SCRIPT>
- function extrainput2() {
- var value;
- for (value = 0; value < document.fields.extrainput.length; value++)
- {
- if (document.fields.extrainput[value].checked == true)
- {
- yesno = document.fields.extrainput[value].value;
- }
- }
- if (yesno == '1')
- {
- document.fields.minlength.disabled=false;
- document.fields.maxlength.disabled=false;
- document.fields.regex.disabled=false;
- document.fields.length.disabled=false;
- document.fields.extrainput_location[0].disabled=false;
- document.fields.extrainput_location[1].disabled=false;
- document.fields.extrainput_text.disabled=false;
- } else {
- document.fields.minlength.disabled=true;
- document.fields.maxlength.disabled=true;
- document.fields.regex.disabled=true;
- document.fields.length.disabled=true;
- document.fields.extrainput_location[0].disabled=true;
- document.fields.extrainput_location[1].disabled=true;
- document.fields.extrainput_text.disabled=true;
- }
- }
- function multipleselect() {
- var value;
- for (value = 0; value < document.fields.multiselect.length; value++)
- {
- if (document.fields.multiselect[value].checked == true)
- {
- yesno = document.fields.multiselect[value].value;
- }
- }
- if (yesno == '1') {
- document.fields.maxoptions.disabled=false;
- document.fields.minoptions.disabled=false;
- document.fields.required[0].disabled=true;
- document.fields.required[1].disabled=true;
- document.fields.extrainput[1].checked=true;
- extrainput2();
- document.fields.extrainput[0].disabled=true;
- } else {
- document.fields.maxoptions.disabled=true;
- document.fields.minoptions.disabled=true;
- document.fields.required[0].disabled=false;
- document.fields.required[1].disabled=false;
- document.fields.extrainput[0].disabled=false;
- }
- }
- extrainput2();
- multipleselect();
- </SCRIPT>
- <?
- ############################### CHECKBOX ###############################
- } elseif ($user_field[formtype] == "checkbox") {
- echo form_hidden('formtype', 'checkbox');
- // regex
- $table[] = array('<b>Maximum Options</b><br />The maximum amount of options that can be selected. (Set a 0 to have no maximum.)', form_input('maxoptions', $user_field[maxoptions], '3'));
- $table[] = array('<b>Minimum Options</b><br />The minimum amount of options that must be selected. (Set as 0 to require no minimum number of options.)', form_input('minoptions', $user_field[minoptions], '3'));
- $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
- $width = array('60%', '40%');
- table_header('Field Criteria');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- // display properties
- $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
- $table[] = array('<b>Checkboxes Per line</b><br />How many checkboxes do you want to display per line?', form_input('perline', $user_field[perline], '3'));
- $width = array('60%', '40%');
- table_header('Field Display Properties');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- $field_data = unserialize($user_field[data]);
- // get max number for creating new fields
- if (is_array($field_data)) {
- while (list ($key, $val) = each ($field_data)) {
- $array_count[] = $field_data[$key][0];
- }
- $max = max($array_count);
- reset($field_data);
- }
- $field_data[] = array($max+1, '', '', '', '');
- $field_data[] = array($max+2, '', '', '', '');
- $field_data[] = array($max+3, '', '', '', '');
- $field_data[] = array($max+4, '', '', '', '');
- $field_data[] = array($max+5, '', '', '', '');
- while (list ($key, $val) = each ($field_data)) {
- $table[] = array(
- $val[0] . form_hidden($key, '1', $arrayto='elementid'),
- form_input($val[0], $val[1], '3', 'order'),
- iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
- form_input($val[0], $val[2], '45', 'name'),
- form_radio_yn($val[0], 'start', $val[3])
- );
- }
- $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
- table_header('Field Data');
- table_content($columns, $table);
- table_footer();
- unset($table);
- ############################### SYSTEM ###############################
- } elseif ($user_field[formtype] == "system") {
- $field_data = unserialize($user_field[data]);
- echo form_hidden('formtype', 'system');
- // creation time
- $table[] = array('<b>Run during registration (page 1)</b><br />Do you wish the code to be executed during the 1st page of user regisration whereupon the variable will be passed as a hidden form element to the 2nd page and then saved?', form_radio_yn('reg1', '', $field_data[when][reg1]));
- $table[] = array('<b>Run during registration (page 2)</b><br />Do you wish the code to be executed during the 2nd page of registration?', form_radio_yn('reg2', '', $field_data[when][reg2]));
- $table[] = array('<b>Run during user profile modification</b><br />Do you wish the code to be executed when a user modifies their profile?', form_radio_yn('usermod', '', $field_data[when][usermod]));
- $table[] = array('<b>Run during tech profile modification</b><br />Do you wish the code to be executed when a tech modifies a users profile?', form_radio_yn('techmod', '', $field_data[when][techmod]));
- $table[] = array('<b>Run during tech user creation</b><br />Do you wish the code to be executed when a tech creates a user?', form_radio_yn('technew', '', $field_data[when][technew]));
- $width = array('60%', '40%');
- table_header('Run Time');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- $table[] = array('<b>Code</b><br />Any PHP code you wish to run (to manipulate a variable)', form_textarea('code', '70', '5', $field_data[code][code]));
- $table[] = array('<b>Variable</b><br />The variable you wish to store for this field', form_input('variable', $field_data[code][variable], '45'));
- $width = array('60%', '40%');
- table_header('Code');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table, $width);
- }
- // show different form button if new/edit
- if ($_REQUEST['do'] == "edit") {
- echo "<br /><center><input type="submit" name="submit" value="Update Field Options"></center></form>";
- } else {
- echo "<br /><center><input type="submit" name="submit" value="Create New Field"></center></form>";
- }
- }
- ############################### SELECT TYPE OF NEW FIELD TO CREATE ###############################
- if ($_REQUEST['do'] == "add") {
- $table[] = array('<b>INPUT</b>', 'This field allows the user to enter text on one line. Useful for words and short sentances', '<a href="ticket_fields.php?do=new2&type=input">create</a>');
- $table[] = array('<b>TEXTAREA</b>', 'Allows for text input across a number of lines. Useful for where more information is required.', '<a href="ticket_fields.php?do=new2&type=textarea">create</a>');
- $table[] = array('<b>SELECT</b>', 'This field allows the user to select from a number of options contained in a list', '<a href="ticket_fields.php?do=new2&type=select">create</a>');
- $table[] = array('<b>RADIO</b>', 'Allows the user from pick one from a number of options where the options are displayed as radio buttons', '<a href="ticket_fields.php?do=new2&type=radio">create</a>');
- $table[] = array('<b>CHECKBOX</b>', 'Allows the user to select a number of options where the options are displayed as checkboxes', '<a href="ticket_fields.php?do=new2&type=checkbox">create</a>');
- table_header('Create New Field');
- table_content('', $table);
- table_footer();
- unset($table, $width);
- }
- ############################### DELETE CUSTOM PROFILE FIELDS ###############################
- if ($_REQUEST['do'] == "delete") {
- $field = $db->query_return("SELECT name FROM ticket_def WHERE id = " . intval($id));
- // delete the field and column
- $db->query("DELETE FROM ticket_def WHERE id = " . intval($id));
- $db->query("ALTER TABLE ticket DROP $field[name]");
- // Update tech's field display preference; remove this deleted field from it.
- $techs = $db->query_return_array('SELECT id, fielddisplay FROM tech');
- if ($db->num_rows()) {
- foreach ($techs AS $tech) {
- $tech['fielddisplay'] = unserialize($tech['fielddisplay']);
- if (!@count($tech['fielddisplay']['custom'])) {
- // Tech has no preference here, move on.
- continue;
- }
- $tech['fielddisplay']['custom'] = array_diff($tech['fielddisplay']['custom'], array($id));
- $tech['fielddisplay'] = serialize($tech['fielddisplay']);
- $db->query("UPDATE tech SET fielddisplay = '" . mysql_escape_string($tech['fielddisplay']) . "' WHERE id = $tech[id]");
- }
- }
-
-
- jump('ticket_fields.php?action=view', 'Custom Profile Field Deleted');
- }
- ############################### LIST CUSTOM PROFILE FIELDS ###############################
- if ($_REQUEST['do'] == "view") {
- // Fetch indexes
- $db->query("SHOW INDEX FROM ticket");
- while ($index = $db->row_array()) {
- $indexed[$index['Column_name']] = 1;
- }
- // select the articles
- $db->query("
- SELECT * FROM ticket_def
- ORDER BY displayorder
- ");
-
- while ($ticket_fields = $db->row_array()) {
- $ticket_fields[display_name] = unserialize($ticket_fields[display_name]);
- $ticket_fields[display_name] = $ticket_fields[display_name][$settings[default_language]];
- if ($indexed[$ticket_fields['name']]) {
- $index = jprompt('This will remove the index for this field. Searches on this field may take longer, but changes to the tickets table that involve this field may be faster after this change. This operation may take some time if there are many tickets.',
- "ticket_fields.php?do=dropindex&id=$ticket_fields[id]",
- 'Remove Index');
- } else {
- $index = jprompt('This will create an index for this field. Searches on this field may be faster, but changes to the tickets table that involve this field may take longer after this change. This operation may take some time if there are many tickets.',
- "ticket_fields.php?do=createindex&id=$ticket_fields[id]",
- 'Create Index');
- }
- ${"table_$ticket_fields[formtype]"}[] = array(
- $ticket_fields[display_name],
- $ticket_fields[name],
- ifynb($ticket_fields[user_viewable]),
- ifynb($ticket_fields[user_editable]),
- ifynb($ticket_fields[tech_viewable]),
- ifynb($ticket_fields[tech_editable]),
- $index,
- $ticket_fields[displayorder],
- "<a href="ticket_fields.php?do=edit&id=$ticket_fields[id]">edit</a>",
- jprompt('Are you sure you want to delete this custom field?', "ticket_fields.php?do=delete&id=$ticket_fields[id]", 'Delete')
- );
- }
- // build the row headings
- $columns = array('Display name', 'SQL name', 'User Viewable', 'User Editable', 'Tech Viewable', 'Tech Editable', 'Index', 'Order', 'Edit', 'Delete');
- table_header('Input Fields');
- table_content($columns, $table_input);
- table_footer();
- table_header('Select Fields');
- table_content($columns, $table_select);
- table_footer();
- table_header('Textarea Fields');
- table_content($columns, $table_textarea);
- table_footer();
- table_header('Radio Fields');
- table_content($columns, $table_radio);
- table_footer();
- table_header('Checkbox Fields');
- table_content($columns, $table_checkbox);
- table_footer();
- $columns = array('Display name', 'SQL name', 'User Viewable', 'Tech Viewable', 'Order', 'Edit', 'Delete');
- /*
- table_header('System Fields');
- table_content($columns, $table_system);
- table_footer();
- */
- }