diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 7d7c73aa6a9482e42240b2581ea78f44d0157e68..7ac0995281e83f5bfb91510236141843eddf000d 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -948,6 +948,13 @@ class SelectionField extends FormField { } return $this->_choices; } + + function export($value) { + if ($value && is_numeric($value) + && ($item = DynamicListItem::lookup($value))) + return $item->toString(); + return $value; + } } class SelectionWidget extends ChoicesWidget { diff --git a/include/class.orm.php b/include/class.orm.php index 17f37679dca6726c3cbc86816401d3d4d4030541..b9bda6a1176ac4beea1aee9301360e50328a315b 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -162,7 +162,7 @@ class VerySimpleModel { $sql = 'UPDATE '.static::$meta['table']; $filter = $fields = array(); if (count($this->dirty) === 0) - return; + return true; foreach ($this->dirty as $field=>$old) { if ($this->__new__ or !in_array($field, $pk)) { if (@get_class($this->get($field)) == 'SqlFunction') diff --git a/include/staff/dynamic-list.inc.php b/include/staff/dynamic-list.inc.php index fffe5d9b2ad549a8ebe34deb9c57167bac7dd04a..4beb705768cf298e1d62255a4bdc16334066642b 100644 --- a/include/staff/dynamic-list.inc.php +++ b/include/staff/dynamic-list.inc.php @@ -1,7 +1,7 @@ <?php $info=array(); -if($list && $_REQUEST['a']!='add') { +if($list && !$errors) { $title = 'Update custom list'; $action = 'update'; $submit_text='Save Changes'; @@ -19,6 +19,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <form action="?" method="post" id="save"> <?php csrf_token(); ?> <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']; ?>"> <h2>Custom List</h2> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> @@ -33,7 +34,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <tbody> <tr> <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> <td width="180">Plural Name:</td> diff --git a/scp/lists.php b/scp/lists.php index 3fa3e3565b0643b5e123d5d8baff2f5593e5cff5..a68267703661f332df7f8b5f4ad4d973b59f60cd 100644 --- a/scp/lists.php +++ b/scp/lists.php @@ -8,12 +8,22 @@ if($_REQUEST['id'] && !($list=DynamicList::lookup($_REQUEST['id']))) if($_POST) { $fields = array('name', 'name_plural', 'sort_mode', 'notes'); + $required = array('name'); switch(strtolower($_POST['do'])) { case 'update': 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->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) { $id = $item->get('id'); if ($_POST["delete-$id"] == 'on') { @@ -27,12 +37,23 @@ if($_POST) { } break; 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( 'name'=>$_POST['name'], 'name_plural'=>$_POST['name_plural'], 'sort_mode'=>$_POST['sort_mode'], '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; case 'mass_process':