Skip to content
Snippets Groups Projects
Commit df83dc3a authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #610 from greezybacon/issue/list-field-export


Fix export of custom list fields

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 2f8a48f0 b94661de
No related branches found
No related tags found
No related merge requests found
...@@ -948,6 +948,13 @@ class SelectionField extends FormField { ...@@ -948,6 +948,13 @@ class SelectionField extends FormField {
} }
return $this->_choices; return $this->_choices;
} }
function export($value) {
if ($value && is_numeric($value)
&& ($item = DynamicListItem::lookup($value)))
return $item->toString();
return $value;
}
} }
class SelectionWidget extends ChoicesWidget { class SelectionWidget extends ChoicesWidget {
......
...@@ -162,7 +162,7 @@ class VerySimpleModel { ...@@ -162,7 +162,7 @@ class VerySimpleModel {
$sql = 'UPDATE '.static::$meta['table']; $sql = 'UPDATE '.static::$meta['table'];
$filter = $fields = array(); $filter = $fields = array();
if (count($this->dirty) === 0) if (count($this->dirty) === 0)
return; return true;
foreach ($this->dirty as $field=>$old) { foreach ($this->dirty as $field=>$old) {
if ($this->__new__ or !in_array($field, $pk)) { if ($this->__new__ or !in_array($field, $pk)) {
if (@get_class($this->get($field)) == 'SqlFunction') if (@get_class($this->get($field)) == 'SqlFunction')
......
<?php <?php
$info=array(); $info=array();
if($list && $_REQUEST['a']!='add') { if($list && !$errors) {
$title = 'Update custom list'; $title = 'Update custom list';
$action = 'update'; $action = 'update';
$submit_text='Save Changes'; $submit_text='Save Changes';
...@@ -19,6 +19,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -19,6 +19,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<form action="?" method="post" id="save"> <form action="?" method="post" id="save">
<?php csrf_token(); ?> <?php csrf_token(); ?>
<input type="hidden" name="do" value="<?php echo $action; ?>"> <input type="hidden" name="do" value="<?php echo $action; ?>">
<input type="hidden" name="a" value="<?php echo $_REQUEST['a']; ?>">
<input type="hidden" name="id" value="<?php echo $info['id']; ?>"> <input type="hidden" name="id" value="<?php echo $info['id']; ?>">
<h2>Custom List</h2> <h2>Custom List</h2>
<table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
...@@ -33,7 +34,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -33,7 +34,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<tbody> <tbody>
<tr> <tr>
<td width="180" class="required">Name:</td> <td width="180" class="required">Name:</td>
<td><input size="50" type="text" name="name" value="<?php echo $info['name']; ?>"/></td> <td><input size="50" type="text" name="name" value="<?php echo $info['name']; ?>"/>
<span class="error">*<br/><?php echo $errors['name']; ?></td>
</tr> </tr>
<tr> <tr>
<td width="180">Plural Name:</td> <td width="180">Plural Name:</td>
......
...@@ -8,12 +8,22 @@ if($_REQUEST['id'] && !($list=DynamicList::lookup($_REQUEST['id']))) ...@@ -8,12 +8,22 @@ if($_REQUEST['id'] && !($list=DynamicList::lookup($_REQUEST['id'])))
if($_POST) { if($_POST) {
$fields = array('name', 'name_plural', 'sort_mode', 'notes'); $fields = array('name', 'name_plural', 'sort_mode', 'notes');
$required = array('name');
switch(strtolower($_POST['do'])) { switch(strtolower($_POST['do'])) {
case 'update': case 'update':
foreach ($fields as $f) foreach ($fields as $f)
if (isset($_POST[$f])) if (in_array($f, $required) && !$_POST[$f])
$errors[$f] = sprintf('%s is required',
mb_convert_case($f, MB_CASE_TITLE));
elseif (isset($_POST[$f]))
$list->set($f, $_POST[$f]); $list->set($f, $_POST[$f]);
$list->save(true); if ($errors)
$errors['err'] = 'Unable to update custom list. Correct any error(s) below and try again.';
elseif ($list->save(true))
$msg = 'Custom list updated successfully';
else
$errors['err'] = 'Unable to update custom list. Unknown internal error';
foreach ($list->getItems() as $item) { foreach ($list->getItems() as $item) {
$id = $item->get('id'); $id = $item->get('id');
if ($_POST["delete-$id"] == 'on') { if ($_POST["delete-$id"] == 'on') {
...@@ -27,12 +37,23 @@ if($_POST) { ...@@ -27,12 +37,23 @@ if($_POST) {
} }
break; break;
case 'add': case 'add':
foreach ($fields as $f)
if (in_array($f, $required) && !$_POST[$f])
$errors[$f] = sprintf('%s is required',
mb_convert_case($f, MB_CASE_TITLE));
$list = DynamicList::create(array( $list = DynamicList::create(array(
'name'=>$_POST['name'], 'name'=>$_POST['name'],
'name_plural'=>$_POST['name_plural'], 'name_plural'=>$_POST['name_plural'],
'sort_mode'=>$_POST['sort_mode'], 'sort_mode'=>$_POST['sort_mode'],
'notes'=>$_POST['notes'])); 'notes'=>$_POST['notes']));
$list->save(true);
if ($errors)
$errors['err'] = 'Unable to create custom list. Correct any error(s) below and try again.';
elseif ($list->save(true))
$msg = 'Custom list added successfully';
else
$errors['err'] = 'Unable to create custom list. Unknown internal error';
break; break;
case 'mass_process': case 'mass_process':
......
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