array_push($errors, "Invalid slug!");
    }
    if ($p_slug == '') {
        $success = false;
        array_push($errors, "The slug field is required !");
    }
    if ($success) {
        $update = array('name' => $p_name, 'slug' => $p_slug);
        if ($region['parent'] > 0 && $p_parent > 0) {
            $update['parent'] = $p_parent;
        }
        Region::update($g_id, $update);
        $region = Region::get_one($g_id);
    }
}
$regions = Region::get_all(array('parent' => 0));
include "page-header.php";
?>

<div id="wrapper">

	<?php 
include "page-left.php";
?>

	<div id="content">
			
		<form name="form_region_edit" id="form_region_edit" method="post" enctype='application/x-www-form-urlencoded' accept-charset="UTF-8" class="form">

			<h2><?php 
print 'Edit ' . $current_group_page['name'] . ($exists ? "<span class='note'>( id: {$g_id} )</span>" : '');
if (isset($_GET['o'])) {
    $o = (int) $_GET['o'];
    $r = (int) $_GET['r'];
    if ($r != 0) {
        $r = 1;
    }
    Region::set_order($o, $parent, $r);
}
$tct = Region::count(array('parent' => $parent));
//total count
$rpp = 10;
//row per page
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct, 'urlVar' => "pageID{$parent}", 'excludeVars' => array('o', 'r', 'd', 't', 'e'));
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();
$regions = Region::get_all(array('r.parent' => $parent), '', $from - 1 . ", {$rpp}");
include "page-header.php";
?>

<div id="wrapper">
	
	<?php 
include "page-left.php";
?>

	<div id="content">

		<?php 
if ($tct > $rpp) {
    echo $pager->links . '<br /><br />';
}