<?php
	
final class Rs
	{
	
	private $sql;
	var $cleaner = '<div style="clear: both;"></div>';
	
	public function __construct()
		{ 
		global $sql;
		$this->sql = &$sql;
		}
		
	public function return_section()
		{
		$sql_sekcie = 'SELECT * FROM categories WHERE id_parent=0';
		if ( $result_sekcie = mysql_query($sql_sekcie) )
			{
			echo 'Sekcia:<br /><select onchange="this.form.submit();" name="category">';
			echo 	'<option>--</option>';
			while ( $row_sekcie = mysql_fetch_assoc($result_sekcie) )
				{
				echo '<optgroup label="' . $row_sekcie['category'] . '">';
				$sql_podsekcie = 'SELECT * FROM categories WHERE id_parent=' . $row_sekcie['id_category'];
				if ( $result_podsekcie = mysql_query($sql_podsekcie) )
					{
					while ( $row_podsekcie = mysql_fetch_assoc($result_podsekcie) )
						{
						if ( isset($_POST['category']) && ($_POST['category']==$row_podsekcie['id_category']) )
							{
							$selected = 'selected="selected"';
							}
						else
							{
							$selected = '';
							}
						echo '<option ' . $selected . ' value="' . $row_podsekcie['id_category'] . '">' . $row_podsekcie['category'] . '</option>';
						}
					}
				echo '</optgroup>';
				}
			echo '</select><br />';
			if ( isset($_POST['category']) )
				{
				echo 'Predmet:<br /><select name="subject">';
				echo 	'<option>--</option>';
				$sql_sub_subject = 'SELECT * FROM categories WHERE id_parent=' . $_POST['category'];
				if ( $result_sub_subject = mysql_query($sql_sub_subject) )
					{
					while ( $row_sub_subject = mysql_fetch_assoc($result_sub_subject) )
						{
						if ( isset($_POST['subject']) && ($_POST['subject']==$row_sub_subject['id_category']) )
							{
							$selected2 = 'selected="selected"';
							}
						else
							{
							$selected2 = '';
							}
						echo '<option ' . $selected2 . ' value="' . $row_sub_subject['id_category'] . '">' . $row_sub_subject['category_alt'] . '</option>';
						}
					}
				echo '</select>';
				}
				}
		echo '<br />';
		}
	
	public function add_article()
		{
		$this->sql->sql_connect('e_learning');
			
		$this->sql->sql_free_result($result_section);
		$this->sql->sql_close();
		}
	
	}
?>