Location: PHPKode > projects > Aratix > admin/classes/Pages.class.php
<?php
/*
** Aratix
** Version 0.1.0beta8 (Anubis)
**
** Autor: Manuel Burghammer
** E-Mail: hide@address.com
** Homepage: http://www.xitara.net
**
** File: Pages.class.php - Version 0.1.0 build 68
** Position: /admin/classes/
** Last Modified: 16.06.2006 - 15:11:23
*/

class Pages{
	function __contruct(){

	}
	function overview($db, $ident){
		$group_list = "";
		$parent_list = "";
		$status_ = $db->read(TB_SESSION, "user_id, groups", "user_md5='" . $ident . "'");
		$status = $status_['groups'];
		$id = $status_['user_id'];

		if(!get('order'))
			$order = "menu_pos ASC";
		else
			$order =  get('order'). " " . get('dir');

		if(($start = get('start')) && $max = get('max'))
			$limit = $start . ", " . $max;
		else
			$limit = "";

		if($status != 99999){
			$groups_ = $db->read(TB_USER, "page_admin", "id='" . $id . "'");
			$groups = explode(" ", $groups_['page_admin']);

			foreach($groups as $group){
				$group_list .= "groups LIKE '%|" . $group . "|%'";

				if($groups[count($groups) - 1] != $group)
					$group_list .= " OR ";
			}
		}
		$pages = $db->read_array(TB_PAGES, "*", $group_list, $order, $limit);
		$counter = 0;

		foreach($pages as $page){
			$child = $db->read_array(TB_PAGES, "id", "parent=" . $page['id']);

			if((!get('parent') && $page['parent'] <= 1) || (get('parent') && get('parent') == $page['parent']) || (get('parent') == 1 && $page['parent'] <= 1)){
				$page_list[$counter] = $page;

				if(count($child) > 0 && $page['id'] != 1)
					$page_list[$counter]['child'] = "true";
				else
					$page_list[$counter]['child'] = "false";

				$counter++;
			}
		}
		$this->page_list = $page_list;

		return $page_list;
	}
	function add(){
		return;
	}
	function edit($db, $ident){
		$page = $db->read(TB_PAGES, "*", "id='" . get('id') . "'");
		$page['content'] = stripslashes($page['content']);

		return $page;
	}
	function delete($db){
		$db->delete(TB_PAGES, "id='" . get('id') . "'");
	}
	function get_menupos_dropdown($menu_pos, $id){
		$menupos_dropdown = "<select name=\"menupos_" . $id . "\" onchange=\"change_menupos('" . $id . "')\" class=\"pages_dropdown\">\n";
		$menupos_dropdown .= "<option value=\"5\"";

		if($menu_pos == 10)
			$menupos_dropdown .= " selected";

		$menupos_dropdown .= ">" . $GLOBALS['config']->i18n("core_to_top") . "</option>\n";

		for($count = 1; $count < count($this->page_list); $count++){
			$page = $this->page_list[$count];

 			if($id != $this->page_list[$count - 1]['id']){
				$menupos_dropdown .= "<option value=\"" . ($page['menu_pos'] - 5) . "\"";

				if($menu_pos == $page['menu_pos'])
					$menupos_dropdown .= " selected";

				if($page['menu_pos'] == "10")
					$menu_text = $GLOBALS['config']->i18n("core_to_top");
				else
					$menu_text = " " . $GLOBALS['config']->i18n("core_after") . " " . $this->page_list[$count - 1]['menu_text'];

				$menupos_dropdown .= ">" . $menu_text . "</option>\n";
			}
		}
		if($id != $this->page_list[$count - 1]['id']){
			$menupos_dropdown .= "<option value=\"" . ($this->page_list[$count - 1]['menu_pos'] + 5) . "\"";

			if($count == count($this->page_list) - 1)
				$menupos_dropdown .= " selected";

			$menupos_dropdown .= ">" . $GLOBALS['config']->i18n("core_after") . " " . $this->page_list[$count - 1]['menu_text'] . "</option>\n";
		}
		$menupos_dropdown .= "</select>\n";

		return $menupos_dropdown;
	}
	function get_parent_dropdown($id){
		$parent = $GLOBALS['db']->read(TB_PAGES, "parent", "id=" . $id);
		$my_parent = $parent['parent'];

		if($my_parent != -1){
			$parents = $GLOBALS['db']->read_array(TB_PAGES, "id, menu_text", "id!=" . $id, "menu_pos ASC");
			$parent_dropdown = "<select name=\"parent_" . $id . "\" onchange=\"change_parent('" . $id . "')\" class=\"pages_dropdown\">\n";

			foreach($parents as $parent){
				$parent_dropdown .= "<option value=\"" . $parent['id'] . "\"";

				if($my_parent == $parent['id'])
					$parent_dropdown .= " selected";

				$parent_dropdown .= ">" . $parent['menu_text'] . "</option>\n";
			}
			$parent_dropdown .= "</select>\n";

			return $parent_dropdown;
		}
		else
			return "";
	}
	function change_menupos($db, $id, $new_pos){
		$db->update(TB_PAGES, "menu_pos", $new_pos, "id='" . $id . "'");
		$pages = $db->read_array(TB_PAGES, "*", "", "menu_pos ASC");
		$menu_pos = 10;

		foreach($pages as $page){
			$db->update(TB_PAGES, "menu_pos", $menu_pos, "id='" . $page['id'] . "'");
			$menu_pos += 10;
		}
	}
	function change_parent($db, $id){
		$db->update(TB_PAGES, "parent", get('parent'), "id='" . $id . "'");
	}
	function change_groups($db, $id){
		if(get('group_acc')){
			$group_list = explode(";", get('group_acc'));
			$counter = 0;
			$query = "|";

			foreach($group_list as $group){
				$groups[$counter] = explode(",", $group);

				if($groups[$counter][1] == "true")
					$query .= $groups[$counter][0] . "|";

				$counter++;
			}
		}
		else
			$query = "";

		$db->update(TB_PAGES, "groups", $query, "id='" . $id . "'");
	}
	function change_categories($db){
		if(get('category_list')){
			$category_list = explode(";", get('category_list'));
			$counter = 0;
			$query = "|";

			foreach($category_list as $category){
				$categories[$counter] = explode(",", $category);

				if($categories[$counter][1] == "true")
					$query .= $categories[$counter][0] . "|";

				$counter++;
			}
		}
		else
			$query = "";

		$db->update(TB_PAGES, "category", $query, "id='" . get('id') . "'");
	}
}
?>
Return current item: Aratix