<?php
namespace admin\controls;

class Page {

  public static function checkUrlParams()
  {
    global $user;

    $rw = \System::formGet( 'rw' );

    switch ( $rw )
    {
      case 'user_logon':
        $user = \user\FUser::Login( \System::formGet( 'login' ), \System::formGet( 'password' ) );
				\System::setSessionVar( 'user', $user, true );
      break;

      case 'user_logout':
        \System::deleteSessionVar( 'user' , true );
      break;

      case 'db_edit_save':
        $db_edit_table 	= \System::getSessionVar( 'db_edit_table' );
        $db_edit_key    = \System::getSessionVar( 'db_edit_key' );
        $db_edit_val    = \System::getSessionVar( 'db_edit_val' );
        $db_edit_pols 	= \System::getSessionVar( 'db_edit_pols' );
        $db_edit_pass 	= \System::getSessionVar( 'db_edit_pass' );
        $db_edit_pols_t = \System::getSessionVar( 'db_edit_pols_type' );
        \DataBase::SaveData( $db_edit_table , $db_edit_key , $db_edit_val , $db_edit_pols , $db_edit_pass , $db_edit_pols_t );
      break;

      case 'db_edit_add_new':
        $db_edit_table        	= \System::getSessionVar( 'db_edit_table' );
        $db_edit_pols         	= \System::getSessionVar( 'db_edit_pols' );
        $db_edit_pass         	= \System::getSessionVar( 'db_edit_pass' );
        $db_edit_pols_hidden    = \System::getSessionVar( 'db_edit_pols_hidden' );
        $db_edit_pols_t       	= \System::getSessionVar( 'db_edit_pols_type' );
        $time                 	= \System::formGetHash( 'time' );
        \DataBase::AddData( $db_edit_table , $db_edit_pols , $db_edit_pols_hidden , $db_edit_pols_t , $time , $db_edit_pass );
      break;
    }
  }

	public static function getContent()
	{
		global $user;

		if ( !$user || !$user -> _values['admin'] )
			return \admin\view\Users::drawLoginForm();

		if ( \System::formGet( 'p' ) )
			\System::setSessionVar( 'page_type' , \System::formGet( 'p' ) );
    
		$page_type = \System::getSessionVar( 'page_type' );

		switch ( $page_type )
		{
      case 'newsletter_emails':
        return \admin\controls\Newsletter::getContentEmails();
      break;
      
      case 'static_containers':
        return \admin\controls\SContainers::getContent();
      break;
      
      case 'filemanager':
        return \admin\controls\Filemanager::getContent();
      break;
      
      case 'adverts':
        return \admin\controls\Adverts::getContent();
      break;
      
      case 'page_article_sort':
        return \admin\controls\Articles::getContentArticleSort();
      break;

      case 'users':
        return \admin\controls\Users::getContentUsers();
      break;

      case 'article_archive':
        return \admin\controls\Articles::getContentArticlesArchive();
      break;

			case 'page_definition':
				return \admin\controls\Pages::getContent();
			break;

			case 'page_articles':
      default;
				return \admin\controls\Articles::getContentArticles();
			break;

			case 'admins':
				return \admin\controls\Users::getContentAdmins();
			break;

			case 'lang':
				return \admin\controls\Languages::getContentLanguages();
			break;

			case 'translation':
				return \admin\controls\Languages::getContentTranslation();
			break;

			case 'settings':
				return \admin\controls\Settings::getContent();
			break;

			case 'guest_book':
				return \admin\controls\GuestBook::getContent();
			break;

			case 'banner':
				return \admin\controls\Banners::getContent();
			break;

      case 'layout':
          return \admin\controls\Layouts::getContent();
      break;

      case 'banned_email':
          return \admin\controls\Restriction::getContentEmails();
      break;

      case 'banned_login':
          return \admin\controls\Restriction::getContentLogins();
      break;
		}
	}
}
?>
