Location: PHPKode > projects > Phpman > phpman-2.0a_RC2/admin/manuals.php
<?php
/**
* Manage languages
* @package phpman
* @copyright (c) 2004 Samuel Suter
* @author Samuel Suter <hide@address.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @version 1.0
**/
?>
<h1><?=$lang->manuals?></h1>
<?php
if($_REQUEST["edit_lang"]) {
	listManLang($_REQUEST["edit_lang"]);
} elseif($_REQUEST["list_pages"]) {
	listManPages($_REQUEST["list_pages"]);
} elseif($_REQUEST["edit_page"]) {
	editPage($_REQUEST["edit_page"]);
} elseif($_REQUEST["edit_page_lang"]) {
	listPageLang($_REQUEST["edit_page_lang"]);
} elseif($_REQUEST["edit_page_lang_content"]) {
	editPageLangContent($_REQUEST["data"]["page_lang_ID"]);
} elseif($_REQUEST["save_page_lang"]) {
	if($_REQUEST["content"]) {
		$_REQUEST["data"]["content"] = $_REQUEST["content"];
	}
	savePageLang($_REQUEST["data"]);
	listPageLang($_REQUEST["data"]["page_ID"]);
} elseif($_REQUEST["add_page"]) {
	addPage($_REQUEST["add_page"]);
} elseif($_REQUEST["save_page"]) {
	savePage($_REQUEST["data"]);
	listManPages($_REQUEST["manual_ID"]);
} elseif($_REQUEST["delete_page"]) {
	deletePage($_REQUEST["delete_page"]);
	listManPages($_REQUEST["manual_ID"]);
} elseif($_REQUEST["save_page_add"]) {
	if(!$data["name"]) {
		addPage($_REQUEST["data"]["root_ID"],$_REQUEST["data"]["parent_ID"]);
	} else {
		savePageAdd($_REQUEST["data"]);
		listManPages($_REQUEST["manual_ID"]);
	}
} elseif($_REQUEST["add"]) {
	editMan();
} elseif($_REQUEST["edit"]) {
	editMan($_REQUEST["edit"]);
} elseif($_REQUEST["delete"]) {
	$table = new mlsDBtable("#__manuals","manual_ID",$database);
	$table->delete($_REQUEST["data"]["manual_ID"]);
	listMan();
} elseif($_REQUEST["save"]) {
	saveMan($_REQUEST["data"]);
	listMan();
} elseif($_REQUEST["save_lang"]) {
	saveManLang($_REQUEST["data"]);
	listManLang($_REQUEST["data"]["manual_ID"]);
} elseif($_REQUEST["edit_authors"]) {
	editAuthors($_REQUEST["edit_authors"]);
} elseif($_REQUEST["add_author"]) {
	saveAuthor($_REQUEST["data"]);
	editAuthors($_REQUEST["data"]["manual_ID"]);
} elseif($_REQUEST["delete_author"]) {
	deleteAuthor($_REQUEST["data"]["manual_author_ID"]);
	editAuthors($_REQUEST["data"]["manual_ID"]);
} else {
	listMan();
}

function deleteAuthor($manual_author_ID) {
	global $database;
	$table = new mlsDBTable("#__manuals_authors","manual_author_ID",$database);
	$table->delete($manual_author_ID);
}

function saveAuthor($data) {
	global $database;
	$table = new mlsDBTable("#__manuals_authors","manual_author_ID",$database);
	$table->bind($data);
	$table->store();
}
function editAuthors($manual_ID) {
	global $database,$lang;
	$tbl_man = new mlsDBTable("#__manuals","manual_ID",$database);
	$data = $tbl_man->load($manual_ID);
	
	$tbl_aut = new mlsDBTable("#__users","user_ID",$database);
	$tbl_aut_man = new mlsDBTable("#__manuals_authors","manual_author_ID",$database);
	$query = "SELECT t1.manual_author_ID,t2.* FROM `#__manuals_authors` AS t1 INNER JOIN `#__users` AS t2 ON t1.user_ID=t2.user_ID WHERE t1.manual_ID='".$manual_ID."' ORDER BY t2.name ASC";
	$database->setQuery($query);
	$authors = $database->loadRowsAssoc();
	?>
	<h2><?=$lang->edit_authors?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>"><?=$lang->back?></a> ]<br>
	
	<input type="hidden" name="data[manual_ID]" value="<?=$data["manual_ID"] ?>">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->name?>:</th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$userselect = mlsHTML::userSelectList('data[user_ID]',0,'username','ASC','name');
		?>
		<form method="POST" action="index.php" name="adminForm">
		<input type="hidden" name="data[manual_ID]" value="<?=$data["manual_ID"] ?>">
		<tr class="row<?=$k?>">
			<td><?=$userselect?></td>
			<td><input type="submit" name="add_author" value="<?=$lang->add?>"></td>
		</tr>
		<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
		<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
		</form>
		<?php
		$k = 0;
		foreach($authors as $author) {
			$userselect = mlsHTML::userSelectList('data[user_ID]',$author["user_ID"],'username','ASC','name');
			?>
			<form method="POST" action="index.php" name="adminForm">
			<input type="hidden" name="data[manual_ID]" value="<?=$data["manual_ID"] ?>">
			<input type="hidden" name="data[manual_author_ID]" value="<?=$author["manual_author_ID"] ?>">
			<tr class="row<?=$k?>">
				<td><?=$userselect?></td>
				<td><input type="submit" name="delete_author" value="<?=$lang->delete?>"></td>
			</tr>
			<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
			<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
			</form>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	
	
	<?php
};

function deletePage($page_ID) {
	global $database;
	/** details of page to delete */
	$table = new mlsDBTable("#__pages","page_ID",$database);
	$data = $table->load($page_ID);
	
	/** number of children */
	if($data["page_ID"] != $data["root_ID"]) {
		$my_children = ($data["rgt"] - $data["lft"] - 1) / 2;
	}
	
	$numbers = 2 + ($my_children * 2);
	
	/** Update all pages to the right (lft) */
	$query = "UPDATE `#__pages` SET `lft`=`lft` - ".$numbers." WHERE `root_ID`='".$data["root_ID"]."' AND `lft`>'".$data["lft"]."' AND `rgt`>='".$data["rgt"]."'";
	$database->setQuery($query);
	$database->query();
	
	/** Update all pages to the right (rgt) */
	$query = "UPDATE `#__pages` SET `rgt`=`rgt` - ".$numbers." WHERE `root_ID`='".$data["root_ID"]."' AND `rgt`>='".$data["rgt"]."'";
	$database->setQuery($query);
	$database->query();
	
	/** Delete the page */
	$query = "DELETE FROM `#__pages` WHERE `page_ID`='".$page_ID."'";
	$database->setQuery($query);
	$database->query();
	
	/** Delete the notes */
	$query = "DELETE FROM `#__notes` WHERE `page_ID`='".$page_ID."'";
	$database->setQuery($query);
	$database->query();
	
	/** Delete the translations */
	$query = "DELETE FROM `#__pages_lang` WHERE `page_ID`='".$page_ID."'";
	$database->setQuery($query);
	$database->query();
	
	/** Delete the children */
	$query = "SELECT `page_ID` FROM `#__pages` WHERE `lft`>'".$data["lft"]."' AND `rgt`<'".$data["rgt"]."'";
	$database->setQuery($query);
	$children = $database->loadRowsAssoc();
	foreach($children as $child) {
		/** Delete the notes */
		$query = "DELETE FROM `#__notes` WHERE `page_ID`='".$child["page_ID"]."'";
		$database->setQuery($query);
		$database->query();
		
		/** Delete the translations */
		$query = "DELETE FROM `#__pages_lang` WHERE `page_ID`='".$child["page_ID"]."'";
		$database->setQuery($query);
		$database->query();
		
		/** Delete the page */
		$query = "DELETE FROM `#__pages` WHERE `page_ID`='".$child["page_ID"]."'";
		$database->setQuery($query);
		$database->query();
	}
};

function savePageAdd($data) {
	global $database;
	/** Get ID, lft and rft from parent */
	$database->setQuery("SELECT `page_ID`,`lft`,`rgt` FROM `#__pages` WHERE `page_ID`='".$data["parent_ID"]."'");
	$data_parent = $database->loadRowAssoc();
	if($data["insert_after"] == 'first') {
		/** new page comes to first position */
		$new_lft = $data_parent["lft"] + 1;
		$new_rgt = $new_lft + 1;
	} else {
		/** new page comes after page selected */
		$database->setQuery("SELECT `page_ID`,`lft`,`rgt` FROM `#__pages` WHERE `page_ID`='".$data["insert_after"]."'");
		$data_after = $database->loadRowAssoc();
		$new_lft = $data_after["rgt"] + 1;
		$new_rgt = $new_lft + 1;
	}
	
	/** Update all pages to the right (lft) */
	$query = "UPDATE `#__pages`"
	." SET `lft`=`lft` + 2"
	." WHERE `root_ID`='".$data["root_ID"]."'"
	." AND `lft`>='".$new_lft."'"
	." AND `rgt`>='".$new_rgt."'";
	$database->setQuery($query);
	$database->query();
	
	/** Update all pages to the right (rgt) */
	$query = "UPDATE `#__pages`"
	." SET `rgt`=`rgt` + 2"
	." WHERE `root_ID`='".$data["root_ID"]."'"
	." AND `rgt`>='".$new_lft."'";
	$database->setQuery($query);
	$database->query();
	
	/** Insert new page */
	$query = "INSERT INTO `#__pages` (`root_ID`,`name`,`lft`,`rgt`,`numbering`) VALUES ('".$data["root_ID"]."','".$data["name"]."','".$new_lft."','".$new_rgt."','".$data["numbering"]."')";
	$database->setQuery($query);
	$database->query();
};

function saveMan($data) {
	global $database,$lang;
	$table = new mlsDBtable("#__manuals","manual_ID",$database);
	$table->bind($data);
	$table->store();
	$manual_ID = $table->_data["manual_ID"];
	if(!$data["manual_ID"]) {
		/** Create root page */
		$database->setQuery("INSERT INTO `#__pages` (`page_ID`,`name`,`lft`,`rgt`) VALUES ('','".$table->_data["name"]."','1','2')");
		$database->query();
		$root_ID = mysql_insert_id();
		
		/** Update root_id */
		$table = $tbl_prefix . "pages";
		$database->setQuery("UPDATE `#__pages` SET `root_ID`='".$root_ID."' WHERE `page_ID`='".$root_ID."'");
		$database->query();
		
		/** Link manual and root page */
		$table = $tbl_prefix . "manuals";
		$database->setQuery("UPDATE `#__manuals` SET `root_ID`='".$root_ID."' WHERE `manual_ID`='".$manual_ID."'");
		$database->query();
	}
};

function savePage($data) {
	global $database,$lang;
	$table = new mlsDBtable("#__pages","page_ID",$database);
	$table->bind($data);
	$table->store();
};

function saveManLang($data) {
	global $database,$lang;
	$table = new mlsDBtable("#__manuals_lang","manual_lang_ID",$database);
	$table->bind($data);
	$table->store();
};

function savePageLang($data) {
	global $database,$lang;
	$table = new mlsDBtable("#__pages_lang","page_lang_ID",$database);
	$table->bind($data);
	$table->store();
};

function editMan($id = 0) {
	global $database,$lang;
	$table = new mlsDBtable("#__manuals","manual_ID",$database);
	$data = $table->load($id);
	?>
	<h2><?=$lang->edit_manual?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>"><?=$lang->back?></a> ]<br>
	<form method="POST" action="index.php" name="adminForm">
	<input type="hidden" name="data[manual_ID]" value="<?=$data["manual_ID"] ?>">
	<input type="hidden" name="data[root_ID]" value="<?=$data["root_ID"] ?>">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<td class="form"><?=$lang->pubdate?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[pubdate]" value="<?=$data["pubdate"] ?>"> (YYYY-MM-DD)</td>
		</tr>
		<tr>
			<td class="form"><?=$lang->name?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[name]" value="<?=$data["name"] ?>"></td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="submit" name="save" value="<?=$lang->save?>">
			<input type="submit" name="delete" value="<?=$lang->delete?>">
			</td>
		</tr>
	</table>
	<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
	<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
	</form>
	<?php
};

function listMan() {
	global $database,$lang;
	$table = new mlsDBtable("#__manuals","manual_ID",$database);
	$table->select('','pubdate','ASC');
	$rows = $table->_db->loadRowsAssoc();
	?>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&add=yes"><?=$lang->add?></a> ]<br>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->manual_ID?></th>
			<th><?=$lang->root_ID?></th>
			<th><?=$lang->pubdate?></th>
			<th><?=$lang->name?></th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		foreach($rows as $row) {
			?>
			<tr class="row<?=$k?>">
				<td><?=$row["manual_ID"]?></td>
				<td><?=$row["root_ID"]?></td>
				<td><?=$row["pubdate"]?></td>
				<td><?=$row["name"]?></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit=<?=$row["manual_ID"]?>"><?=$lang->edit?></a></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit_lang=<?=$row["manual_ID"]?>"><?=$lang->edit_lang?></a></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&list_pages=<?=$row["manual_ID"]?>"><?=$lang->list_pages?></a></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit_authors=<?=$row["manual_ID"]?>"><?=$lang->authors?></a></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	<?php
};

function listManLang($manual_ID) {
	global $database,$lang;
	$tbl_lang = new mlsDBtable("#__languages","language_ID",$database);
	$tbl_lang->select('','language_ID','ASC');
	$rows_lang = $tbl_lang->_db->loadRowsAssoc();
	
	
	$tbl_man = new mlsDBtable("#__manuals","manual_ID",$database);
	$tbl_man_lang = new mlsDBtable("#__manuals_lang","manual_lang_ID",$database);
	$tbl_man_lang->select('','language_ID','ASC');
	$rows_man_lang = $tbl_man_lang->_db->loadRowsCustom2('language_ID','manual_ID');
	?>
	<h2><?=$lang->manual_translations?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>"><?=$lang->back?></a> ]<br>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->language?></th>
			<th><?=$lang->title?></th>
			<th><?=$lang->subtitle?></th>
			<th><?=$lang->copyright?></th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		foreach($rows_lang as $row_lang) {
			$row_man_lang = $rows_man_lang[$row_lang["language_ID"]][$manual_ID];
			?>
			<form method="POST" action="index.php" name="adminForm">
			<input type="hidden" name="data[manual_lang_ID]" value="<?=$row_man_lang["manual_lang_ID"]?>">
			<input type="hidden" name="data[manual_ID]" value="<?=$manual_ID?>">
			<input type="hidden" name="data[language_ID]" value="<?=$row_lang["language_ID"]?>">
			<tr class="row<?=$k?>">
				<td><?=$row_lang["language"]?> (<?=$row_lang["isocode"]?>)</td>
				<td><input type="text" name="data[title]" size="20" value="<?=$row_man_lang["title"]?>"></td>
				<td><input type="text" name="data[subtitle]" size="20" value="<?=$row_man_lang["subtitle"]?>"></td>
				<td><input type="text" name="data[copyright]" size="20" value="<?=$row_man_lang["copyright"]?>"></td>
				<td><input type="submit" name="save_lang" value="<?=$lang->save?>"></td>
				<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
				<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
			</tr>
			</form>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	<?php
};

function editPageLangContent($page_lang_ID) {
	global $database,$lang;
	$table = new mlsDBtable("#__pages_lang","page_lang_ID",$database);
	$data = $table->load($page_lang_ID);
	?>
	<h2><?=$lang->page_translations?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit_page_lang=<?=$data["page_ID"]?>"><?=$lang->back?></a> ]<br>
	<form method="POST" action="index.php" name="adminForm">
	<input type="hidden" name="data[page_lang_ID]" value="<?=$data["page_lang_ID"]?>">
	<input type="hidden" name="data[page_ID]" value="<?=$data["page_ID"]?>">
	<input type="hidden" name="data[language_ID]" value="<?=$data["language_ID"]?>">
	<input type="text" name="data[title]" value="<?=$data["title"]?>">
	<?php
	$spaw_root = _mlsDocroot.'spaw/';
	include $spaw_root.'spaw_control.class.php';
	$sw = new SPAW_Wysiwyg('content',stripslashes($data["content"]),$my->_data["lang"],'full','default','750','350',_mlsWebdir."/style.css",$spaw_dropdown_data);
	$sw->show();
	?>
	<input type="submit" name="save_page_lang" value="<?=$lang->save?>">
	</form>
	<?php
};

function listPageLang($page_ID) {
	global $database,$lang;
	$tbl_lang = new mlsDBtable("#__languages","language_ID",$database);
	$tbl_lang->select('','language_ID','ASC');
	$rows_lang = $tbl_lang->_db->loadRowsAssoc();
	
	$tbl_page_lang = new mlsDBtable("#__pages_lang","page_lang_ID",$database);
	$tbl_page_lang->select('','language_ID','ASC');
	$rows_page_lang = $tbl_page_lang->_db->loadRowsCustom2('language_ID','page_ID');
	
	$database->setQuery("SELECT t2.manual_ID FROM `#__pages` AS t1 INNER JOIN `#__manuals` AS t2 ON t1.root_ID=t2.root_ID WHERE t1.page_ID='".$page_ID."'");
	$man_data = $database->loadRowAssoc();
	
	?>
	<h2><?=$lang->page_translations?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&list_pages=<?=$man_data["manual_ID"]?>"><?=$lang->back?></a> ]<br>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->language?></th>
			<th><?=$lang->title?></th>
			<th><?=$lang->content?></th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		foreach($rows_lang as $row_lang) {
			$row_page_lang = $rows_page_lang[$row_lang["language_ID"]][$page_ID];
			?>
			<form method="POST" action="index.php" name="adminForm">
			<input type="hidden" name="data[page_lang_ID]" value="<?=$row_page_lang["page_lang_ID"]?>">
			<input type="hidden" name="data[page_ID]" value="<?=$page_ID?>">
			<input type="hidden" name="data[language_ID]" value="<?=$row_lang["language_ID"]?>">
			<tr class="row<?=$k?>">
				<td><?=$row_lang["language"]?> (<?=$row_lang["isocode"]?>)</td>
				<td><input type="text" name="data[title]" size="20" value="<?=$row_page_lang["title"]?>"></td>
				<td><textarea rows="5" cols="40" name="data[content]"><?=$row_page_lang["content"]?></textarea></td>
				<td><input type="submit" name="save_page_lang" value="<?=$lang->save?>"></td>
				<td>
				<?php if($row_page_lang["page_lang_ID"]) { ?>
					<input type="submit" name="edit_page_lang_content" value="<?=$lang->html_editor?>">
				<? } else {?>
					&nbsp;
				<? } ?>
				</td>
				<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
				<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
			</tr>
			</form>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	<?php
};

function listManPages($manual_ID) {
	global $database,$lang;
	
	$tbl_man = new mlsDBtable("#__manuals","manual_ID",$database);
	$man_data = $tbl_man->load($manual_ID);
	
	$tbl_pages = new mlsDBtable("#__pages","page_ID",$database);
	$database->setQuery("SELECT a1.page_ID,a1.lft,a1.rgt,a1.name,a1.numbering,COUNT(*) AS `level` FROM `#__pages` AS a1, `#__pages` AS a2 WHERE a1.root_ID='".$man_data["root_ID"]."' AND a2.root_ID='".$man_data["root_ID"]."' AND a1.lft BETWEEN a2.lft AND a2.rgt GROUP BY a1.lft");
	$rows = $database->loadRowsAssoc();
	
	$blubb = get_pages_array(60,0,1);
	?>
	<h2><?=$lang->pages_in?>: <?= $man_data["name"]?></h2>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>"><?=$lang->back?></a> ]
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&add_page=<?=$man_data["root_ID"]?>"><?=$lang->add?></a> ]<br>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->page_ID?></th>
			<th><?=$lang->left?></th>
			<th><?=$lang->right?></th>
			<th><?=$lang->name?></th>
			<th><?=$lang->level?></th>
			<th><?=$lang->numbering?></th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		/** Array for numbers */
		$pages = array();
		foreach($rows as $row) {
			$level = $row["level"];
		
			/** Store number in array */
			if($pages[$level] == "") {
				/** if this is the first page in this level, number is '1' */
				$pages[$level] = 1;
			} else {
				/** else increment the number */
				$pages[$level] = $pages[$level] + 1;
			}
			
			
			/** START numbering */
			$segments = $level - 1;
			$number = "";
			$temp_level = $level;
			for($i = 0; $i < $segments; $i++) {
				if($i == $segments - 1) {
					$number .= $pages[$level] . ".";
				} else {
					$temp_level = $temp_level - 1;
					$number = $pages[$temp_level] . "." . $number;
				}
			}
			$number = substr($number,0,strlen($number) - 1);
			
			if($prev_level == $level) {
				$prev_level = $prev_level - 1;
			} elseif($prev_level > $level) {
				$pages[$prev_level] = 0;
			}
			
			/** indenting */
			$nbsp = "";
			for($i = 0; $i < $level - 1; $i++) {
				$nbsp .= "&nbsp;&nbsp;&nbsp;";
			}
			?>
			<tr class="row<?=$k?>">
				<td><?=$row["page_ID"]?></td>
				<td><?=$row["lft"]?></td>
				<td><?=$row["rgt"]?></td>
				<td><?=$nbsp?><b><?=$number?></b> <?=$row["name"]?></td>
				<td><?=$row["level"]?></td>
				<td><?=$row["numbering"]?></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit_page=<?=$row["page_ID"]?>"><?=$lang->edit?></a></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit_page_lang=<?=$row["page_ID"]?>"><?=$lang->edit_lang?></a></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&delete_page=<?=$row["page_ID"]?>&manual_ID=<?=$manual_ID?>"><?=$lang->delete?></a></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	<?php
};

function editPage($id = 0) {
	global $database,$lang;
	$table = new mlsDBtable("#__pages","page_ID",$database);
	$data = $table->load($id);
	
	$database->setQuery("SELECT `manual_ID` FROM `#__manuals` WHERE `root_ID`='".$data["root_ID"]."'");
	$man_data = $database->loadRowAssoc();
	$numselect = mlsHTML::selectList('data[numbering]',array("arabic" => $lang->arabic, "roman" => $lang->roman),$data["numbering"]);
	?>
	<h2><?=$lang->edit_page?></h2>
	
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&list_pages=<?=$man_data["manual_ID"]?>"><?=$lang->back?></a> ]<br>
	<form method="POST" action="index.php" name="adminForm">
	<input type="hidden" name="manual_ID" value="<?=$man_data["manual_ID"] ?>">
	<input type="hidden" name="data[page_ID]" value="<?=$data["page_ID"] ?>">
	<input type="hidden" name="data[root_ID]" value="<?=$data["root_ID"] ?>">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<td class="form"><?=$lang->numbering?>:</td>
			<td class="form"><?=$numselect?></td>
		</tr>
		<tr>
			<td class="form"><?=$lang->name?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[name]" value="<?=$data["name"] ?>"></td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="submit" name="save_page" value="<?=$lang->save?>">
			<input type="submit" name="delete_page" value="<?=$lang->delete?>">
			</td>
		</tr>
		</table>
		<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
		<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
		</form>
	<?php
};

function addPage($root_ID,$parent_ID = 0) {
	global $database,$lang;
	$table = new mlsDBtable("#__pages","page_ID",$database);
	$data = $table->load($id);
	
	$database->setQuery("SELECT `manual_ID` FROM `#__manuals` WHERE `root_ID`='".$root_ID."'");
	$man_data = $database->loadRowAssoc();
	$numselect = mlsHTML::selectList('data[numbering]',array("arabic" => $lang->arabic, "roman" => $lang->roman),"arabic");
	?>
	<h2><?=$lang->add_page?></h2>
	
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&list_pages=<?=$man_data["manual_ID"]?>"><?=$lang->back?></a> ]<br>
	<form method="POST" action="index.php" name="adminForm">
	<input type="hidden" name="data[root_ID]" value="<?=$root_ID ?>">
	<input type="hidden" name="manual_ID" value="<?=$man_data["manual_ID"];?>">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<td class="form"><?=$lang->parent?>:</td>
			<td class="form">
			<?php
			$pages_array = get_pages_array($root_ID);
			if(!$parent_ID) { $selected = " selected"; } else { $selected = ""; }
			?>
			<select name="data[parent_ID]">
			<option value="0"<?=$selected ?>><?=$lang->choose_page?></option>
			<?php
			foreach($pages_array AS $page) {
				if($page["page_ID"] == $parent_ID) { $selected = " selected"; } else { $selected = ""; }
				?>
				<option value="<?=$page["page_ID"]?>"<?=$selected ?>><?=$page["spaces"]?>(<?=$page["number"]?>) <?=$page["name"]?></option>
				<?php
			}
			?>
			</select>
			</td>
		</tr>
		<?php if($parent_ID) {?>
		<tr>
			<td class="form"><?=$lang->insert_after?>:</td>
			<td class="form">
			<?php
			$pages_array = get_pages_array($root_ID,$parent_ID);
			?>
			<select name="data[insert_after]">
			<option value="first" selected><?=$lang->first_position ?></option>
			<?php
			foreach($pages_array AS $page) {
				if($page["page_ID"] == $parent_ID) { $selected = " selected"; } else { $selected = ""; }
				?>
				<option value="<?=$page["page_ID"]?>"<?=$selected ?>><?=$page["spaces"]?>(<?=$page["number"]?>) <?=$page["name"]?></option>
				<?php
			}
			?>
			</select>
			</td>
		</tr>
		<tr>
			<td class="form"><?=$lang->numbering?>:</td>
			<td class="form"><?=$numselect?></td>
		</tr>
		<tr>
			<td class="form"><?=$lang->name?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[name]" value="<?=$data["name"] ?>"></td>
		</tr>
		<?php } ?>
		<tr>
			<td></td>
			<td>
			<input type="submit" name="save_page_add" value="<?=$lang->save?>">
			</td>
		</tr>
		</table>
		<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
		<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
		</form>
	<?php
};

?>
Return current item: Phpman