remember($action, $_REQUEST))) {
$item = $_REQUEST;
$with_form = TRUE;
// else display the updated page
} else {
// cascade changes on access rights
if($_REQUEST['active'] != $item['active'])
Anchors::cascade('section:'.$item['id'], $_REQUEST['active']);
// touch the related anchor
if(is_object($anchor))
$anchor->touch('section:update', $item['id'],
isset($_REQUEST['silent']) && ($_REQUEST['silent'] == 'Y'),
isset($_REQUEST['notify_watchers']) && ($_REQUEST['notify_watchers'] == 'Y'),
isset($_REQUEST['notify_followers']) && ($_REQUEST['notify_followers'] == 'Y'));
// display the updated page
Safe::redirect($context['url_to_home'].$context['url_to_root'].Sections::get_permalink($item));
}
// create a new section
} elseif(!$_REQUEST['id'] = sections::post($_REQUEST)) {
$item = $_REQUEST;
$with_form = TRUE;
// successful post
} else {
// allow back-referencing from overlay
$_REQUEST['self_reference'] = 'section:'.$_REQUEST['id'];
$_REQUEST['self_url'] = $context['url_to_root'].Sections::get_permalink($_REQUEST);
// post an overlay, with the new section id --don't stop on error
if(is_object($overlay))
$overlay->remember('insert', $_REQUEST);
// touch the related anchor
if(is_object($anchor))
$anchor->touch('section:create', $_REQUEST['id'],
isset($_REQUEST['silent']) && ($_REQUEST['silent'] == 'Y'),
isset($_REQUEST['notify_watchers']) && ($_REQUEST['notify_watchers'] == 'Y'),
isset($_REQUEST['notify_followers']) && ($_REQUEST['notify_followers'] == 'Y'));
// increment the post counter of the surfer
Users::increment_posts(Surfer::get_id());
// get the new item
$section =& Anchors::get('section:'.$_REQUEST['id'], TRUE);
// reward the poster for new posts
$context['page_title'] = i18n::s('Thank you for your contribution');
$context['text'] .= '
'.i18n::s('Please review the new page carefully and fix possible errors rapidly.').'
';
// list persons that have been notified
$context['text'] .= Mailer::build_recipients(i18n::s('Persons that have been notified'));
// follow-up commands
$follow_up = i18n::s('What do you want to do now?');
$menu = array();
$menu = array_merge($menu, array($section->get_url() => i18n::s('View the section')));
if(Surfer::may_upload())
$menu = array_merge($menu, array('images/edit.php?anchor='.urlencode('section:'.$_REQUEST['id']) => i18n::s('Add an image')));
if(preg_match('/\bwith_files\b/i', $section->item['options']) && Surfer::may_upload())
$menu = array_merge($menu, array('files/edit.php?anchor='.urlencode('section:'.$_REQUEST['id']) => i18n::s('Upload a file')));
if(preg_match('/\bwith_links\b/i', $section->item['options']))
$menu = array_merge($menu, array('links/edit.php?anchor='.urlencode('section:'.$_REQUEST['id']) => i18n::s('Add a link')));
if(is_object($anchor))
$menu = array_merge($menu, array('sections/edit.php?anchor='.urlencode($anchor->get_reference()) => i18n::s('Add another section')));
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= Skin::build_block($follow_up, 'bottom');
// log the creation of a new section
$label = sprintf(i18n::c('New section: %s'), strip_tags($section->get_title()));
if(is_object($anchor))
$description = sprintf(i18n::s('Sent by %s in %s'), Surfer::get_name(), $anchor->get_title());
else
$description = sprintf(i18n::s('Sent by %s'), Surfer::get_name());
$description .= "\n\n".$section->get_teaser('basic')
."\n\n".$context['url_to_home'].$context['url_to_root'].$section->get_url();
Logger::notify('sections/edit.php', $label, $description);
}
// display the form on GET
} else
$with_form = TRUE;
// display the form
if($with_form) {
// the form to edit a section
$context['text'] .= '';
// append the script used for data checking on the browser
$context['page_footer'] .= JS_PREFIX
.'// check that main fields are not empty'."\n"
.'func'.'tion validateDocumentPost(container) {'."\n"
."\n"
.' // title is mandatory'."\n"
.' if(!container.index_title.value) {'."\n"
.' alert("'.i18n::s('Please provide a meaningful title.').'");'."\n"
.' Yacs.stopWorking();'."\n"
.' return false;'."\n"
.' }'."\n"
."\n"
.' // successful check'."\n"
.'// return true;'."\n"
.'}'."\n"
."\n"
.'// update title'."\n"
.'func'.'tion updateTitle() {'."\n"
."\n"
.' if(!$("title").value) {'."\n"
.' $("title").value = $("index_title").value;'."\n"
.' }'."\n"
.' if($("shadow_title").value == $("title").value) {'."\n"
.' $("title").value = $("index_title").value;'."\n"
.' }'."\n"
.' $("shadow_title").value = $("index_title").value;'."\n"
.'}'."\n"
."\n"
.'// observe changes in form'."\n"
.'Event.observe("index_title", "change", updateTitle);'."\n"
."\n"
.'// disable editor selection on change'."\n"
.'func'.'tion detectChanges() {'."\n"
."\n"
.' var nodes = $$("form#main_form input");'."\n"
.' for(var index = 0; index < nodes.length; index++) {'."\n"
.' var node = nodes[index];'."\n"
.' Event.observe(node, "change", function() { $("preferred_editor").disabled = true; });'."\n"
.' }'."\n"
."\n"
.' nodes = $$("form#main_form textarea");'."\n"
.' for(var index = 0; index < nodes.length; index++) {'."\n"
.' var node = nodes[index];'."\n"
.' Event.observe(node, "change", function() { $("preferred_editor").disabled = true; });'."\n"
.' }'."\n"
."\n"
.' nodes = $$("form#main_form select");'."\n"
.' for(var index = 0; index < nodes.length; index++) {'."\n"
.' var node = nodes[index];'."\n"
.' Event.observe(node, "change", function() { $("preferred_editor").disabled = true; });'."\n"
.' }'."\n"
.'}'."\n"
."\n"
.'// observe changes in form'."\n"
.'Event.observe(window, "load", detectChanges);'."\n"
."\n"
.'// set the focus on first form field'."\n"
.'$("index_title").focus();'."\n"
."\n"
.'// enable tags autocompletion'."\n"
.'Event.observe(window, "load", function() { new Ajax.Autocompleter("tags", "tags_choices", "'.$context['url_to_root'].'categories/complete.php", { paramName: "q", minChars: 1, frequency: 0.4, tokens: "," }); });'."\n"
.JS_SUFFIX."\n";
// content of the help box
$help = '';
// splash message for new pages
if(!isset($item['id']) && !count($context['error']))
$help .= '
'.i18n::s('Please describe the new section and hit the submit button. You will then be able to post images, files and links on subsequent forms.').'
';
// html and codes
$help .= '
'.sprintf(i18n::s('%s and %s are available to enhance text rendering.'), Skin::build_link('codes/', i18n::s('YACS codes'), 'help'), Skin::build_link('smileys/', i18n::s('smileys'), 'help')).'
';
// locate mandatory fields
$help .= '
'.i18n::s('Mandatory fields are marked with a *').'
';
// change to another editor
$help .= '';
// drive associates to the Content Assistant
if(Surfer::is_associate())
$help .= '
'.sprintf(i18n::s('Use the %s to populate this server.'), Skin::build_link('help/populate.php', i18n::s('Content Assistant'), 'shortcut')).'
'."\n";
// in a side box
$context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
}
// render the skin
render_skin();
?>