<?php

//	NOTE - $row_config is defined in the common file
if (isset($_POST["mod"])) {
    $mod_item = mod_item(T_BOOKINGS_CONFIG, 1, $_POST["mod"], false);
    if ($mod_item == "OK") {
        //	reload to get fresh values and show message
        $url = "index.php?page=" . ADMIN_PAGE . "&msg=mod_OK";
        header("Location:" . $url . "");
    } else {
        $warning = $lang["msg_mod_KO"];
        //echo mysql_error();
    }
}
//	get possible themes
$list_themes = "";
$dir = AC_DIR_THEMES_ROOT;
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            //	define select list of themes
            if ($row_config["theme"] == $file) {
                $selected = ' selected="selected"';
            } else {
                $selected = "";
            }
            $list_themes .= "<option value='" . $file . "' " . $selected . ">" . $file . "</option>\n";
        }
    }
    closedir($handle);
} else {
//	define admin page table
$this_table = T_BOOKINGS_ITEMS;
//	delete item
if (isset($_POST["delete_it"])) {
    if (delete_item($this_table, $_POST["id"])) {
        //	delete bookings for this item
        $del = "DELETE FROM " . T_BOOKINGS . " WHERE id_item=" . $_POST["id"] . "";
        mysql_query($del) or die("Error deelting item bookings");
        header("Location:index.php?page=" . ADMIN_PAGE . "&msg=delete_OK");
    } else {
        $warning = $lang["msg_delete_KO"];
    }
}
//	modify item
if (isset($_POST["mod"])) {
    if (mod_item($this_table, $_POST["id"], $_POST["mod"])) {
        header("Location:index.php?page=" . ADMIN_PAGE . "&id_modified=" . $_POST["id"] . "&msg=mod_OK");
    } else {
        $warning = $lang["msg_mod_KO"];
    }
}
//	add new item
if (isset($_POST["add"])) {
    //	define next list order
    $_POST["add"]["list_order"] = get_next_order($this_table);
    $_POST["add"]["id_user"] = $_SESSION["admin_id"];
    if (add_item($this_table, $_POST["add"], false)) {
        header("Location:index.php?page=" . ADMIN_PAGE . "&id_added=" . mysql_insert_id() . "&msg=add_OK");
    } else {
        $warning = $lang["msg_add_KO"];
    }
<?php

/*
just for modifying current user - NOT active in superadmin account
*/
//	define admin page table
$this_table = T_BOOKINGS_ADMIN;
//	modify item
if (isset($_POST["mod"])) {
    //	add password to array - this is not in the array as it is need for formchecking
    if ($_POST["password"] != "") {
        $_POST["mod"]["password"] = $_POST["password"];
    }
    if (mod_item($this_table, $_SESSION["admin_id"], $_POST["mod"], false)) {
        header("Location:index.php?page=" . ADMIN_PAGE . "&msg=mod_OK");
    } else {
        $warning = $lang["msg_mod_KO"];
    }
}
$xtra_moo .= 'new FormCheck("item_form")';
//	get item data
$row = get_item($this_table, $_SESSION["admin_id"]);
$page_title_add = ' - ' . $lang["title_mod"] . '';
$contents .= '
<form method="post" id="item_form">
<table>
	<tr>
		<td class="side">' . $lang["username"] . '</td>
		<td><input type="text" name="mod[username]" value="' . $row["username"] . '" style="width:99%;" class="validate[\'required\',\'length[0,100]\'] text-input"></td>
	</tr>
	<tr>