<?php
namespace front\controls;

class Page {

  public static function checkUrlParams()
  {
    global $lang, $config;

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

    switch ( $rw )
    {
      case 'send-ac-form':        
        if ( $_SESSION['ac-check'] == $_POST['check'] || !$_POST['ac-name'] || !$_POST['ac-email'] || !$_POST['ac-text'] ):
          \System::setAlert( 'Brak wszystkich wymaganych danych.' );
        else:
          $tpl = new \Savant3;
          $tpl -> _data = $_POST;
          $out = $tpl -> fetch( 'other/contact-message' );
          
          if ( ( !empty( $_FILES["ac-file"] ) ) && ( $_FILES['ac-file']['error'] == 0 ) ) 
          {
            $filename = basename( $_FILES['ac-file']['name'] );
            if ( in_array( $_FILES["ac-file"]["type"], \System::getImgFileTypes() ) )
            {
                $newname = 'temp/' . $filename;
                move_uploaded_file( $_FILES['ac-file']['tmp_name'], $newname );
            }
          }
          \System::sendEmail( \admin\factory\Settings::getSystemSettings( 'admin_email'), 'Wiadomość ze strony: www.' . $config['page'], $out, $replay = '', $newname );
          \System::setAlert( 'Wiadomość została wysłana.' );
          $_SESSION['ac-check'] = $_POST['check'];
        endif;
      break;
      
      case 'change_language':
        $id   = \System::formGet( 'id' );
        $lang = \language\FLanguage::loadLang( $id );
        \System::setSessionVar( 'lang' , $lang );
      break;

      case 'change_site':
        if ( \System::formGet( 'type' ) )
          $site = \site\FSite::loadSiteStatic( \System::formGet( 'type' ) );
        else
          $site = new \site\Site( \System::formGetInt( 'id' ) );

        \System::setSessionVar( 'site' , $site );
      break;
      
      case 'add_comment':
        \article\FArticle::addComment( \System::formGetInt( 'article_id' ), \System::formGet( 'author' ), \System::formGet( 'text' ), \System::formGet( 'captcha_code' ), \System::formGet( 'check' ) );
      break;
    }
    
    if ( \System::formGetInt( 'download' ) )
      \System::downloadFile( \System::formGetInt( 'download' ) );

    if ( \System::formGet( 'account_activation' ) && \System::formGetInt( 'value' ) )
      \user\FUser::activateAccount( \System::saveString( \System::formGet( 'account_activation' ) ), \System::formGetInt( 'value' ) );

    if ( \System::formGet( 'recover_password' ) && \System::formGetInt( 'value' ) )
      \user\FUser::recoverPassword( \System::saveString( \System::formGet( 'recover_password' ) ), \System::formGetInt( 'value' ) );
  }
}
?>
