$data = null; if ($data = get_record_select('collection', 'id = ?', array($id))) { $collection = new Collection($id, (array) $data); if (!$USER->can_edit_collection($collection)) { $SESSION->add_error_msg(get_string('canteditdontown')); redirect('/collection/'); } } // if not a new collection if (!$new) { define('COLLECTION', $id); define('TITLE', $collection->get('name') . ': ' . get_string('edittitleanddesc', 'collection')); } else { define('TITLE', get_string('edittitleanddesc', 'collection')); } $elements = Collection::get_collectionform_elements($data); $submitstr = $new ? array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection')) : array(get_string('save'), get_string('cancel')); $confirm = $new ? array('cancel' => get_string('confirmcancelcreatingcollection', 'collection')) : null; $elements['submit'] = array('type' => 'submitcancel', 'value' => $submitstr, 'confirm' => $confirm); $form = pieform(array('name' => 'edit', 'plugintype' => 'core', 'pluginname' => 'collection', 'successcallback' => 'submit', 'elements' => $elements)); $smarty = smarty(); $smarty->assign('PAGEHEADING', TITLE); $smarty->assign_by_ref('form', $form); $smarty->display('collection/edit.tpl'); function submit(Pieform $form, $values) { global $SESSION, $new; $collection = Collection::save($values); if (!$new) { $SESSION->add_ok_msg(get_string('collectionsaved', 'collection')); }