<?php

$property = $decoded['property'];
if ($property == 'title') {
    // section title
    $sectionsList = BertaEditor::getSections();
    $sName = $decoded['section'];
    $returnUpdate = $sNewTitle = $decoded['value'];
    $returnReal = $sNewName = BertaEditor::getUniqueSectionSlug($sName, $sNewTitle, $sectionsList);
    $fName = $options['XML_ROOT'] . str_replace('%', $sName, $options['blog.%.xml']);
    $fNewName = $options['XML_ROOT'] . str_replace('%', $sNewName, $options['blog.%.xml']);
    if (!file_exists($fName)) {
        $returnError = 'current section storage file does not exist! you\'ll have to delete this section!';
        $returnUpdate = !empty($sectionsList[$sName]['title']) ? $sectionsList[$sName]['title']['value'] : '';
        $returnReal = $sName;
    } elseif (empty($sNewName)) {
        $returnError = 'section name cannot be empty!';
        $returnUpdate = !empty($sectionsList[$sName]['title']) ? $sectionsList[$sName]['title']['value'] : '';
        $returnReal = $sName;
    } elseif (file_exists($fNewName) && $sNewName != $sName) {
        $returnError = 'section cannot be created! another section with the same (or too similar name) exists.';
        $returnUpdate = !empty($sectionsList[$sName]['title']) ? $sectionsList[$sName]['title']['value'] : '';
        $returnReal = $sName;
    } else {
        if (!@rename($fName, $fNewName)) {
            $returnError = 'section storage file cannot be renamed! check permissions and be sure the name of the section is not TOO fancy.';
        } else {
            @chmod($fNewName, 0666);
            // update title...
            $sectionsListNew = array();
            foreach ($sectionsList as $sN => $s) {