<?PHP

class content_Install{

	function install(){

		$this->delete_db_data();

		mysql_query("INSERT INTO templates
		(name, page, language, position, type, page_position, is_active) VALUES
		('content', 'content_list', '"._defaultLanguage."', 'content', 'MODEL', 'admin', 1)");
		$last_id = mysql_insert_id();

		$roles = array(2,5);
		foreach($roles as $v){

			mysql_query("INSERT INTO permissions
			(role_id, table_name, 	table_id, 	created_at, allow_access) VALUES
			(".$v.", 'templates', ".$last_id.", NOW(), 1)");
		}

		$q = mysql_query("SELECT * FROM menus WHERE is_restricted = 1 ORDER BY queue DESC LIMIT 1");
		$row = mysqli_fetch_Assoc($q);

		mysql_query("INSERT INTO menus
		(parent_id, template_id, name, language, queue, is_link, is_enabled, is_restricted) VALUES
		(0, ".$last_id.", 'content', '"._defaultLanguage."', ".($row['queue']+1).", 1, 1, 1)");
	}

	function delete_db_data(){

		$q = mysqli_Query("SELECT * FROM templates WHERE name like 'content' ");
		while($row = mysqli_fetch_Assoc($q)){

			mysql_query("DELETE FROM menus WHERE template_id = ".$row['id']);
			mysql_query("UPDATE menus SET model_id = 0 WHERE model_id = ".$row['id']);
			mysql_query("DELETE FROM permissions WHERE table_name = 'templates' AND table_id = ".$row['id']);
			mysql_query("DELETE FROM templates WHERE id = ".$row['id']);
		}
	}
}

?>