<script type="text/javascript">
    //splx_drag and drop---------------->
    var isNav = (navigator.appName.indexOf('Netscape') != -1);
    var isIE = (navigator.appName.indexOf('Microsoft') != -1);

    var splx_dd_beforedrag_display_style = '';
    var splx_dd_drag_el = '';
    var splx_dd_ondrop = '';
    var splx_dd_mousedown = 0;
    var splx_eldrag = null;
    document.onmousedown = null;

    splx_start_drag = function(el, hide) {
        try {
            if (document.getElementById('splxdd') == undefined) {
                var splxddNode = document.createElement('div');
                splxddNode.setAttribute('id', 'splxdd');
                splxddNode.style.display = 'none';
                if (document.getElementsByTagName('body')[0] != undefined)
                    document.getElementsByTagName('body')[0]
                .appendChild(splxddNode);
            }
            document.getElementById('splxdd').style.position = 'absolute';
            document.getElementById('splxdd').innerHTML = '';
            document.getElementById('splxdd').style.border = '1px dotted';
            document.getElementById('splxdd').style.backgroundColor = 
                'transparent';
            // ---duplicazione--->
            if (el.clientWidth != undefined && el.clientWidth != 0) {
                document.getElementById('splxdd').style.width = el.clientWidth 
                    + 'px';
                document.getElementById('splxdd').style.height = 
                    el.clientHeight + 'px';
            } else {
                document.getElementById('splxdd').style.width = null;
                document.getElementById('splxdd').style.height = null;
            }
            if (el.innerHTML != '') {
                document.getElementById('splxdd').innerHTML = el.innerHTML;
            } else
                document.getElementById('splxdd').innerHTML = 'DRAG';
            // ---duplicazione---<
            if (hide == true && el.style != undefined) {
                splx_dd_beforedrag_display_style = el.style.display;
                splx_dd_drag_el = el;
            } else {
                splx_dd_drag_el = '';
            }
            splx_eldrag = el;
            // alert('z');

        } catch (e) {
            alert(e)
        }
        document.onmouseup = splx_end_drag;
        document.onmousedown = function() {
            return false
        };
        splx_dd_ondrop = '';
        document.onmousemove = splx_dd_onmousemove;
        return false;
    }

    splx_end_drag = function() {

        //alert('splx_end_drag:'+splx_dd_ondrop+ 'mousedown='+splx_dd_mousedown);
        document.getElementById('splxdd').style.display = 'none';
        document.getElementById('splxdd').innerHTML = '';
        if (splx_dd_drag_el != '' && splx_dd_drag_el.style.display != undefined) 
        {
            splx_dd_drag_el.style.display = splx_dd_beforedrag_display_style;
        }
        splx_dd_drag_el = '';
        document.onmousedown = null;
        var t = splx_dd_ondrop;
        splx_dd_ondrop = '';
        splx_dd_mousedown = 0;

        eval(t);
        return false;
    }

    splx_dd_onmousemove = function(e) {
        try {

            var tmp;
            if (splx_eldrag != null) {
                tmp = splx_eldrag.innerHTML;
                splx_eldrag.innerHTML = '';
                splx_eldrag.innerHTML = tmp;
                splx_eldrag = null;
            }

            var Xpos = (isIE) ? event.clientX : e.pageX;
            var Ypos = (isNav) ? e.pageY : event.clientY;
            Xpos += 12;
            Ypos += 12;
            splx_dd_mousedown = 0;
            var ddnode = document.getElementById('splxdd');
            if (document.getElementById('splxdd').innerHTML != '') {
                splx_dd_mousedown = 1;
                ddnode.style.display = 'none';
                ddnode.style.position = 'absolute';
                ddnode.style.left = Xpos.toString() + 'px';
                ddnode.style.top = Ypos.toString() + 'px';
                ddnode.style.display = 'block';
                ddnode.style.zIndex = '7';
            }
            if (splx_dd_drag_el != '' && splx_dd_drag_el.style.display != 
                undefined) {
                splx_dd_drag_el.style.display = 'none';
            }
        } catch (e) {
            alert(e)
        }

        return false;
    }

    splx_dd_setondrop = function(str) {
        if (splx_dd_mousedown == 1)
            splx_dd_ondrop = str;
        else
            splx_dd_ondrop = '';
    }

    if (isNav) {
        if (document.addEventListener)
        {
            document.addEventListener(Event.CLICK);
            document.addEventListener(Event.DBLCLICK);
            document.addEventListener(Event.ONMOUSEUP);
            document.addEventListener(Event.MOUSEMOVE);	
        }
        else
        {
            document.captureEvents(Event.CLICK);
            document.captureEvents(Event.DBLCLICK);
            document.captureEvents(Event.ONMOUSEUP);
            document.captureEvents(Event.MOUSEMOVE);
        }
    }

    // splx_drag and drop----------------<
</script>
<?php
/**
 * @package Flatnux_controlcenter
 * @author Alessandro Vernassa <speleoalex@gmail.com>
 * @copyright Copyright (c) 2003-2005
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
 *
 */
defined('_FNEXEC') or die('Restricted access');


//echo FN_HtmlSectionEditor();

global $_FN;
$opt = FN_GetParam("opt", $_GET);
$modcont = FN_GetParam("edit", $_GET);

echo "<br />";
FN_FixSections();

if ($modcont)
{
    $filename = basename($modcont);
    $filedir = dirname($modcont);
    $lang = str_replace(".html", "", str_replace("section.", "", $filename));

    $editor_params = false;
    if (file_exists(dirname($modcont) . "/style.css"))
    {
        $editor_params['css_file'] = dirname($modcont) . "/style.css";
    }
    if (!file_exists($modcont))
    {
        if (isset($_GET['create']))
        {
            //---from default language ---------------------------------------->
            if (!file_exists($modcont))
            {
                if (isset($_GET['copy']))
                {
                    $text = file_get_contents("$filedir/section.{$_FN['lang_default']}.html");
                    FN_Write($text, $modcont);
                }
            }
            //---from default language ----------------------------------------<
            FN_EditContent($modcont, "controlcenter.php?opt=$opt&edit=$modcont", "?opt=$opt", $editor_params);
        }
        else
        {
            echo "$modcont " . FN_i18n("does not exist") . "<br /><br />";
            echo FN_i18n("you want to create the file?");
            echo "<br /><br />";
            echo "<button onclick=\"window.location='controlcenter.php?opt=$opt'\" >" . FN_Translate("no") . "</button> ";
            echo "<button onclick=\"window.location='controlcenter.php?opt=$opt&amp;edit=$modcont&amp;create'\" >" . FN_Translate("yes") . "</button> ";

            if ($lang != $_FN['lang_default'] && file_exists("$filedir/section.{$_FN['lang_default']}.html"))
            {
                echo " <a href=\"controlcenter.php?opt=$opt&amp;edit=$modcont&amp;create&amp;copy\" >[" . FN_Translate("copy contents from the default translation and edit it") . "]</a> ";
            }
        }
    }
    else
    {
        $_FN['editor_folder'] = dirname($modcont);
        FN_EditContent($modcont, "controlcenter.php?opt=$opt&edit=$modcont", "?opt=$opt", $editor_params);
    }
}
else
{

    $newsection = FN_GetParam("newsection", $_GET);

//-------sitemap--------------------------------------------------------------->
    if (!$newsection)
    {
        $img = "<img title=\"\" alt=\"\" src=\"" . FN_FromTheme("images/add.png") . "\" />";
        echo "$img <a href=\"?mod={$_FN['mod']}&amp;opt=$opt&amp;newsection=1\">" . FN_i18n("create a new page") . "</a>";
        $htmlgrid = "";
//          dprint_r("qui 0a:" . FN_GetExecuteTimer());  //1 sec
        FNCC_UpdateSections();
//          dprint_r("qui 0b:" . FN_GetExecuteTimer()); //8sec
        $table = FN_XmlForm("fn_sections");
//($section="", $recursive=false, $onlyreadable = true, $hidden = false, $onlyenabled=true)
        $sections = FN_GetSections("", true, false, true, false, true);
        $sections = FN_ArraySortByKey($sections, "position");
        $sections = FN_ArraySortByKey($sections, "parent");
//---script---->
        $htmlgrid .= "<br /><br />
<script language=\"javascript\">
var moveup = function (node)
{
	var nodetomove = node;
	var list_child = new Array();
	nodetomove_level = getlevel (node);
	var i = 0;
	var tmp_nearnode = node.nextSibling;
	//lista nodi da spostare ----->
	while (tmp_nearnode != null && getlevel (node) < getlevel (tmp_nearnode) )
	{
		list_child[i] = tmp_nearnode;
		i++;
		tmp_nearnode = tmp_nearnode.nextSibling;
	}
	//lista nodi da spostare -----<
	var newnode;
	var parent;
	var nextnode;
	//dove spostare ----->
	var target  = findprev(nodetomove);
	if (target == null)
	{
		return;
	}
	//dove spostare -----<
	var id_node_main = nodetomove.id;
	movenode (nodetomove,target);
	target = document.getElementById(id_node_main);


	for (var j = 0 ;j <= i; j++)
	{
	try{
		movenode (list_child[j],target.nextSibling);
		target = document.getElementById(list_child[j].id);
	}catch (e){}
	}
	syncdiv('sectionsdiv');
}


var movedown = function (node)
{
	var nodetomove = node;
	var list_child = new Array();
	nodetomove_level = getlevel (node);
	var i = 0;
	var tmp_nearnode = node.nextSibling;
	//lista nodi da spostare ----->
	while (tmp_nearnode != null && getlevel (node) < getlevel (tmp_nearnode) )
	{
		list_child[i] = tmp_nearnode;
		i++;
		tmp_nearnode = tmp_nearnode.nextSibling;
	}
	//lista nodi da spostare -----<
	var newnode;
	var parent;
	var nextnode;
	//dove spostare -----<
	var target  = findnext(nodetomove);
	if (target == null)
	{
	
		return;
	}
	//dove spostare ----->
	var id_node_main = nodetomove.id;
	movenode (nodetomove,target.nextSibling);
	target = document.getElementById(id_node_main);
	for (var j = 0 ;j <= i; j++)
	{
	try{
		movenode (list_child[j],target.nextSibling);
		target = document.getElementById(list_child[j].id);
		}catch(e){}
	}
	syncdiv('sectionsdiv');
}
var movenode = function(node,before)
{
	var tmpnode = node;
	var parent = before.parentNode;
	//parent.removeChild(node);
	parent.insertBefore(tmpnode,before);
}

var getlevel = function (node)
{
	try{
	var span = document.getElementById('span_'+node.id);
	var px = parseInt(span.style.paddingLeft.replace('px',''));
	}catch (e){
	return 0;
	}
	return px;
}
//ritorna lultimo
var findnext = function (node)
{
	var start = getlevel(node)
	var nextnode = node.nextSibling;
	var retnode = nextnode;
	if (getlevel(nextnode) < start)
	{
		return null;
	}
	have_child = false;
	while (getlevel(nextnode) > start )
	{
		nextnode = nextnode.nextSibling;
		retnode =  nextnode;
		have_child = true;
	}
	if (have_child)
	{
		nextnode = retnode;
		
	}
	while (getlevel(nextnode.nextSibling) != start )
	{
		if (getlevel(nextnode.nextSibling) < start)
			break;
		nextnode = nextnode.nextSibling;
		retnode =  nextnode;
	}
	//alert (nextnode.id);
	return retnode;
}
//torna qulello successivo
var findprev = function (node)
{
	var start = getlevel(node)
	var prevnode = node.previousSibling;
	var retnode = prevnode;
	if (getlevel(prevnode) < start)
	{
		return null;
	}
	have_child = false;
	while (getlevel(prevnode) > start )
	{
		retnode =  prevnode;
		prevnode = prevnode.previousSibling;
		have_child = true;
	}
	
	if (have_child)
	{
		prevnode = retnode;
		//alert (nextnode.id);
	}
	
	while (getlevel(prevnode) != start )
	{
		prevnode = prevnode.previousSibling;
		retnode =  prevnode;
	}
	//alert ('cur = '+node.id+ ' prev = '+ prevnode.id);
	
	return prevnode;
}
var moveleft = function (node)
{
	var span = document.getElementById('span_'+node.id);
	var m = parseInt(span.style.paddingLeft.replace('px',''));
	m-=30;
	if (m<0)
		m=0;
	span.style.paddingLeft = m+'px';
	syncdiv('sectionsdiv');
}
var moveright = function (node)
{
	var span = document.getElementById('span_'+node.id);
	var m = parseInt(span.style.paddingLeft.replace('px',''));
	m+=30;
	span.style.paddingLeft = m+'px';
	syncdiv('sectionsdiv');
}
var syncdiv = function (id)
{
	var divitems = document.getElementById( id ).childNodes;
	var sep='';
	var str='';
	var lastdiv = null;
	for (var i in divitems)
	{
		if (divitems[i].id && document.getElementById('span_'+divitems[i].id ))
		{
			var span = document.getElementById('span_'+divitems[i].id );
			var left = parseInt(  span.style.paddingLeft.replace('px',''))/30;
			str = str + sep + divitems[i].id+':'+left;
			var ck = '0';
			if ( document.getElementById('hide_'+divitems[i].id ).checked)
			{
				ck = '1';
				divitems[i].style.color='#bbbbbb';
				divitems[i].style.fontStyle='italic';
				//divitems[i].style.textDecoration='line-through';
			}
			else
			{
				divitems[i].style.color='black';
				divitems[i].style.fontStyle='normal';
				//divitems[i].style.textDecoration='none';
			}
			str +=':' + ck;
			sep=',';
			//------------------images----------------------------------------->
			try{
			var image = document.getElementById('imageup_'+divitems[i].id );
			if (i == 0)
			{
				image.style.opacity='.2';
			}
			else
			{
				image.style.opacity='1';
			}
			image = document.getElementById('imagedown_'+divitems[i].id );
			image.style.opacity='1';
			image = document.getElementById('imageleft_'+divitems[i].id );
			if (left==0)
			{
				image.style.opacity='.2';
			}
			else
			{
				image.style.opacity='1';
			}
			}
			catch(e){
			}
			//------------------images-----------------------------------------<
			lastdiv = divitems[i];
		}
	}
	
	document.getElementById('sectionstring').value=str;
	if (lastdiv)
	{
		var image = document.getElementById('imagedown_'+lastdiv.id );
		try{image.style.opacity='.2';}catch(e){}
	}
	
//	//alert (str);
}
</script>
";
//---script----<

        $htmlgrid .="<form stile=\"clear:both;\" method=\"post\" op=\"?opt={$opt}\">";
        $htmlgrid .="<div style=\"padding:5px;font-size:12px;line-height:20px;background-color:#ffffff;color:#000000;border:1px inset;width:auto;white-space: nowrap\" id=\"sectionsdiv\">";
        $tmp = false;
        $htmlgrid .=FNCC_print_node("", $sections, $tmp);
        $htmlgrid .= "<div id=\"__last\" ><span></span></div>";
        $htmlgrid .="</div>";
        $htmlgrid .="<input type=\"hidden\" id=\"sectionstring\" name=\"sectionstring\" size=\"200\"  value=\"\"/>";
        $htmlgrid .="<button type=\"submit\">" . FN_i18n("save") . "</button>";
        $htmlgrid .="</form>";
        $htmlgrid .="
<script language=\"javascript\">
	syncdiv('sectionsdiv');
</script>

";
        $htmlgrid .= "<br /><br />";
    }
//-------sitemap---------------------------------------------------------------<
//-------section grid---------------------------------------------------------->
    if (!$newsection)
    {
        // dprint_r("qui 1:" . FN_GetExecuteTimer());
        $params = false;
        $params['enablenew'] = false;
        $table = FN_XmlForm("fn_sections");
        $table->formvals['id']['frm_show'] = 1;
        $table->formvals['position']['frm_show'] = 0;

        $params['table'] = $table;
        //$params['textmodify']=FN_i18n("settings",false,"Aa");
        //$params['fields']="id|title|status";
        $params['htmlgrid'] = $htmlgrid;
        $params['list_onupdate'] = false;

        //dprint_r($_POST);
        //dprint_r($_GET);

        $pk___xdb_fn_sections = FN_GetParam("pk___xdb_fn_sections", $_GET, "html");
        $id = FN_GetParam("id", $_POST, "html");
        $error = false;
        if ($id != "" && $pk___xdb_fn_sections != "" && $id != $pk___xdb_fn_sections)
        {
            //echo "rename sections/$pk___xdb_fn_sections to sections/$id";
            if (file_exists("sections/$id"))
            {
                echo "<div>";
                echo FN_Translate("a file already exists with this name");
                echo "</div>";
                $error = true;
            }
            else
            {
                if (false === FN_Rename("sections/$pk___xdb_fn_sections", "sections/$id"))
                {
                    echo FN_Translate("error");
                    $error = true;
                }
                else
                {
                    //rename parents ----->
                    $sectionstorenameparent = FN_XMLQuery("SELECT * FROM fn_sections WHERE parent LIKE '$pk___xdb_fn_sections'");
                    if (is_array($sectionstorenameparent))
                    {
                        $tb = FN_XmlTable("fn_sections");
                        foreach ($sectionstorenameparent as $sectiontorenameparent)
                        {
                            $sectiontorenameparent['parent'] = $id;
                            $table->UpdateRecord($sectiontorenameparent);
                        }
                    }
                    //rename parents -----<
                }
            }
            if (!$error)
            {
                //FN_JsRedirect("?mod{$_FN['mod']}&amp;opt=$opt");
            }
        }
        if (!$error)
        {
            $params['textviewlist'] = "";
            $params['textcancel'] = FN_Translate("back");
			
            if (empty($_POST['savefileconfig']))
            {
				
                FN_xmltableeditor("fn_sections", $params); //editor
            }
            else
            {
                echo "<br /><br />";
            }
            $sectiontype = FN_GetParam("type", $_POST, "html");
            $mod = FN_GetParam("pk___xdb_fn_sections", $_GET, "html");
            $block = "";
            if (!empty($mod))
            {
                $sectionvalues = FN_GetSectionValues($mod, false);
                $sectiontype = $sectionvalues['type'];
                if (file_exists("modules/$sectiontype/config.php"))
                {
					$t = FN_XmlForm("fn_sectionstypes");
					$values = $t->GetRecordTranslatedByPrimarykey("$sectiontype");
					$title = isset($values['title'])?$values['title']:$sectiontype;
                    echo "<fieldset>";
                    echo "<legend>" . FN_Translate("module options that is loaded in this page") . "</legend>";
					echo "<h3>".FN_Translate("configure")." ".$title.":</h3>";
                    $formaction = "controlcenter.php?opt=$opt&amp;op___xdb_fn_sections=insnew&amp;pk___xdb_fn_sections=$mod";
                    $formexit = "controlcenter.php?opt=$opt";
                    echo FN_HtmlEditConfFile("modules/$sectiontype/config.php", $formaction, $formexit, false, false, $mod, $block);
                    echo "</fieldset>";
                }
            }
        }
        else
        {
            echo "<div><a href=\"?opt=$opt\">" . FN_Translate("next") . " &gt;&gt;</a></div>";
        }


//------del section----------------------------------------------------->
        if (!empty($_GET['op___xdb_fn_sections']) && $_GET['op___xdb_fn_sections'] == "del")
        {
            $sid = FN_GetParam("pk___xdb_fn_sections", $_GET);
            if ($sid != "" && file_exists("sections/$sid"))
            {
                FN_RemoveDir("sections/$sid");
            }
            FN_JsRedirect("?mod{$_FN['mod']}&amp;opt=$opt");
            FN_Log("section deleted:$sid");
            FN_OnSitemapChange();
        }
        //------del section-----------------------------------------------------<
    }
    else
    {
        if (!FN_IsWritable("sections"))
        {
            echo "sections " . FN_i18n("is read-only");
        }
        else
        {
            $forminsert = FN_XmlForm("fn_sections");
            $newvalues = isset($_POST['newsection']) ? $forminsert->GetByPost() : false;
            $errors = array();
            $forminsert->formvals['id']['frm_show'] = "0";
            $forminsert->formvals['title']['frm_required'] = "1";
            $forminsert->formvals['parent']['frm_show'] = "0";
            $forminsert->formvals['position']['frm_show'] = "0";
            $sections = FN_GetSections("sections", true);
            if (!isset($newvalues['status']))
                $newvalues['status'] = "1";
            if (isset($_POST['newsection']))
            {
                if (isset($newvalues['title']))
                    $newvalues['id'] = FN_MakeSectionId($newvalues['title']);
                $before_after = FN_GetParam("before_after", $_POST);
                $before_after_section = FN_GetParam("before_after_section", $_POST);
                $newvalues['parent'] = isset($sections[$before_after_section]['parent']) ? $sections[$before_after_section]['parent'] : "";
                $newvalues['sectionpath'] = "sections";

                $errors = $forminsert->VerifyInsert($newvalues);
                if (count($errors) == 0)
                {
                    if (FN_MkDir("sections/{$newvalues['id']}"))
                    {
                        //fix position --------->
                        $i = 1;
                        $newsections = array();
                        foreach ($sections as $k => $section)
                        {
                            $newsections[$k] = $section;
                            $newsections[$k]['position'] = $i;
                            if ($k == $before_after_section)
                            {
                                if ($before_after == "before")
                                {
                                    $newvalues['position'] = $i;
                                    $i++;
                                    $newsections[$k]['position'] = $i;
                                }
                                else
                                {
                                    $i++;
                                    $newvalues['position'] = $i;
                                }
                            }
                            $i++;
                        }
                        if ($before_after == "inside")
                            $newvalues['parent'] = $before_after_section;
                        foreach ($newsections as $k => $newsection)
                        {
                            if ($newsections[$k]['position'] != $sections[$k]['position'])
                            {
                                // dprint_r("update {$newsections[$k]['position']} != {$sections[$k]['position']}");
                                $forminsert->UpdateRecord(array("id" => $newsections[$k]['id'], "position" => $newsections[$k]['position']));
                            }
                        }
                        //fix position ---------<
                        $forminsert->InsertRecord($newvalues);
                        echo FN_i18n("the page has been created");
                        echo "<br />";

                        echo "<br /><a href=\"controlcenter.php?mod={$_FN['mod']}&amp;opt=$opt\">" . FN_Translate("next") . "</a> <img style=\"vertical-align:middle\" src=\"images/right.png\" alt=\"\"/>";
                        if ($newvalues['type'] != "" && file_exists("modules/{$newvalues['type']}/config.php"))
                        {
                            echo "<br /><a href=\"controlcenter.php?mod={$_FN['mod']}&amp;opt=$opt&amp;op___xdb_fn_sections=insnew&amp;pk___xdb_fn_sections={$newvalues['id']}\">" . FN_Translate("module options that is loaded in this page") . "</a> <img style=\"vertical-align:middle\" src=\"images/right.png\" alt=\"\"/>";
                        }
                        FN_Log("created new section:{$newvalues['id']}");
                        FN_OnSitemapChange();
                        return;
                    }
                    else
                    {
                        echo FN_i18n("error");
                    }
                }
            }
            $html = "";
            $html .= "<form method=\"post\" action=\"" . "controlcenter.php?mod={$_FN['mod']}&amp;opt=$opt&amp;newsection=1" . "\">";
            $html .= "<input type=\"hidden\" name=\"newsection\" value=\"1\"/>";
            $html .=FNADMIN_HtmlSectionsTree();
            $html .= $forminsert->HtmlShowInsertForm(false, $newvalues, $errors);
            $html .= "<button type=\"submit\">" . FN_i18n("save") . "</button>";
            $html .= "<button onclick=\"window.location='controlcenter.php?mod={$_FN['mod']}&opt=$opt';return false;\" >" . FN_i18n("cancel") . "</button>";
            $html .= "</form>";
            echo $html . "";
        }
    }
//-------section grid----------------------------------------------------------<
}
/**
 *
 * @staticvar array $list
 * @staticvar int $level
 * @param string $parent
 * @param string $sections
 * @return array 
 */
function FNCC_print_node($parent, $sections, &$list)
{
    static $list = array();
    static $level = 0;
    $html = "";
    $level++;
    foreach ($sections as $section)
    {
        if ($section['parent'] == $parent)
        {
            if (in_array($section['id'], $list))
                return;
            $list[] = $section['id'];
            $html .= FNCC_print_section($section, $level);
            $tmp = false;
            $html .= FNCC_print_node($section['id'], $sections, $list);
        }
    }
    $level--;

    return $html;
}
/**
 *
 * @staticvar int $id
 * @param <type> $section
 * @param <type> $level
 */
function FNCC_print_section($section, $level)
{
    static $id = 0;
    global $_FN;
    $opt = FN_GetParam("opt", $_GET);
    $html = "";
    $id++;
    $left = ($level - 1) * 30;
    $linkdelete = 'controlcenter.php?page___xdb_fn_sections=1&order___xdb_fn_sections=id&op___xdb_fn_sections=del&pk___xdb_fn_sections=' . $section['id'] . '&opt=' . $opt;
    $linkedit = 'controlcenter.php?page___xdb_fn_sections=1&order___xdb_fn_sections=id&op___xdb_fn_sections=insnew&pk___xdb_fn_sections=' . $section['id'] . '&opt=' . $opt;
    $html .= "<div onmouseover=\"this.style.backgroundColor='#ffffaa'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" style=\"border:0px solid #000000;line-height:18px;padding:0px;margin:0px;font-size:12px;height:18px\" id=\"{$section['id']}\" >";
    
	
	if ($section['level'] != "" || $section['group_view'] != "")
    {
		$t = "";
		if ($section['level']!=="")
			$t .= FN_Translate("level").":".$section['level']." ";
		if ($section['group_view']!=="")
			$t .= FN_Translate("groups").":".$section['group_view'];
		$html .= "<img title=\"$t \" alt=\"\" src=\"images/locked.png\" style=\"vertical-align:middle\" />";
    }
	else
        $html .= "<img alt=\"\" src=\"images/unlocked.png\" style=\"vertical-align:middle\" />";

    //pagine --->
    $link = "controlcenter.php?mod={$section['id']}&edit=sections/{$section['id']}/section.php&opt=$opt";
    //   window.open("mioFile.htm","","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
    $html .= "<img style=\"cursor:pointer;vertical-align:middle\" alt=\"" . FN_i18n("preview") . "\" onclick=\"preview=window.open('" . FN_RewriteLink("index.php?mod={$section['id']}") . "','preview','top=10,left=10,scrollbars=yes');preview.focus();\" src=\"images/mime/web.png\" title=\"" . FN_i18n("preview") . "\" />";
    $border = "border:1px solid #ffffff";
    if (file_exists("sections/{$section['id']}/section.php"))
        $border = "border:1px solid #00ff00";
    $html .= "<img style=\"cursor:pointer;vertical-align:middle;$border\" alt=\"\" onclick=\"window.location='$link'\" src=\"images/mime/php.png\" />";
    foreach ($_FN['listlanguages'] as $l)
    {
        $border = "border:1px solid #ffffff";
        if (file_exists("sections/{$section['id']}/section.$l.html"))
            $border = "border:1px solid #00ff00";
        $link = "controlcenter.php?mod={$section['id']}&edit=sections/{$section['id']}/section.$l.html&opt=$opt";
        $html .= " <img style=\"cursor:pointer;vertical-align:middle;$border\" onclick=\"window.location='$link'\" src=\"images/flags/$l.png\" />";
    }
    //pagine ---<
    //controlcenter.php?page___xdb_fn_sections=1&order___xdb_fn_sections=id&op___xdb_fn_sections=insnew&pk___xdb_fn_sections=managers&mod=news&opt=contents/sitemap
    $html .= "<img style=\"vertical-align:middle;cursor:pointer\" onclick=\"window.location='$linkedit';return false;\" src=\"images/configure.png\" />";

    $ck = empty($section['hidden']) ? "" : "checked=checked";
    $html .= "<input style=\"vertical-align:middle\" title=\"" . FN_i18n("hidden") . "\" onchange=\"syncdiv('sectionsdiv');\" $ck type=\"checkbox\" id=\"hide_{$section['id']}\" />";
    //up --->
    $html .= "<a href=\"javascript:;\" onclick=\"moveup(this.parentNode);\">";
    $html .= "<img id=\"imageup_{$section['id']}\" style=\"height:9px;width:13px;vertical-align:middle;border:0px;\" src=\"" . FN_FromTheme("images/fn_up.png") . "\" title=\"" . FN_i18n("move up") . "\" /></a>";
    //up ---<
    //down --->
    $html .= "<a href=\"javascript:;\" onclick=\"movedown(this.parentNode);\">";
    $html .= "<img id=\"imagedown_{$section['id']}\" style=\"height:9px;width:13px;vertical-align:middle;border:0px;\" src=\"" . FN_FromTheme("images/fn_down.png") . "\" title=\"" . FN_i18n("move down") . "\" /></a>";
    //down --->
    //left --->
    $html .= "<a href=\"javascript:;\" onclick=\"moveleft(this.parentNode);\">";
    $html .= "<img id=\"imageleft_{$section['id']}\" style=\"height:9px;width:13px;vertical-align:middle;border:0px;\" src=\"" . FN_FromTheme("images/fn_left.png") . "\" title=\"" . FN_i18n("move left") . "\" /></a>";
    //left ---<
    //right --->
    $html .= "<a href=\"javascript:;\" onclick=\"moveright(this.parentNode);\">";
    $html .= "<img id=\"imageright_{$section['id']}\"  style=\"height:9px;width:13px;vertical-align:middle;border:0px;\" src=\"" . FN_FromTheme("images/fn_right.png") . "\" title=\"" . FN_i18n("move right") . "\" /></a>";
    //right ---<
    $html .= "<span id=\"span_{$section['id']}\"  style=\"background-position: bottom right;background-image:url(controlcenter/sections/contents/sitemap/node.png);background-repeat:no-repeat;padding-left:{$left}px\"></span>";
    //icon --->
    $html .= "<span onmouseout=\"splx_dd_setondrop('')\" onmouseover=\"splx_dd_setondrop('')\" onmousedown=\"splx_start_drag (this, true);\"><img style=\"vertical-align:middle;border:0px;\" src=\"" . FN_FromTheme("images/mime/dir.png") . "\" />&nbsp;{$section['title']}";
    //icon ---<
    $html .= "<img style=\"vertical-align:middle;cursor:pointer\" onclick=\"if(confirm ('" . FN_i18n("you want to permanently delete this page?") . "')){window.location='$linkdelete'} else {return false;}\" src=\"images/delete.png\" /></span>";
    $html .= "</div>";
    return $html;
}
/**
 *
 * @global array $_FN
 */
function FNCC_UpdateSections()
{
    global $_FN;
    $table = FN_XmlForm("fn_sections");
    $sectionstring = FN_GetParam("sectionstring", $_POST);
    $i = 1;
    $sects = array();
    if ($sectionstring != "")
    {
        $str_sectionsvalues = explode(",", $sectionstring);
        {
            foreach ($str_sectionsvalues as $str_section)
            {
                $tmp = explode(":", $str_section);
                if (isset($tmp[2]))
                {
                    $sec['id'] = $tmp[0];
                    $sec['position'] = $i;
                    $sec['leveltree'] = $tmp[1];
                    $sec['hidden'] = $tmp[2];
                    $sects[] = $sec;
                    $i++;
                }
            }
        }
        $errors = false;
        $idtree = 0;
        $curparent = "";
        $tree[$idtree] = "";
        $newvalues = array();
        for ($i = 0; isset($sects[$i]); $i++)
        {
            $oldvalues = FN_GetSectionValues($sects[$i]['id']);
            $newvalues['id'] = $sects[$i]['id'];
            $newvalues['hidden'] = $sects[$i]['hidden'];
            $newvalues['position'] = $sects[$i]['position'] * 10;

            if ($i == 0)
            {
                $newvalues['parent'] = "";
            }
            else
            {
                if ($sects[$i]['leveltree'] > $sects[$i - 1]['leveltree'])
                {
                    $curparent = $newvalues['parent'] = $sects[$i - 1]['id'];
                    $idtree = $idtree + ($sects[$i]['leveltree'] - $sects[$i - 1]['leveltree'] );
                    $tree[$idtree] = $curparent;
                }
                elseif ($sects[$i]['leveltree'] < $sects[$i - 1]['leveltree'])
                {
                    $idtree = $idtree - ($sects[$i - 1]['leveltree'] - $sects[$i]['leveltree']);
                    if (isset($tree[$idtree]))
                        $curparent = $newvalues['parent'] = $tree[$idtree];
                }
                else
                {
                    $newvalues['parent'] = $curparent;
                }
            }
            if ($newvalues['hidden'] != $oldvalues['hidden'] || $newvalues['position'] != $oldvalues['position'] || $newvalues['parent'] != $oldvalues['parent'])
            {
                //dprint_r($newvalues);
                if (!$table->xmltable->UpdateRecord($newvalues))
                {
                    $errors.=1;
                }
            }
        }

        if (!$errors)
        {
            FN_Alert("the data were successfully updated");
            FN_Log("sitemap changed");
            FN_OnSitemapChange();
        }
    }
}
?>