<?
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
function __autoload_my_classes( $classname )
{
	$q = explode( '\\' , $classname );
	$c = array_pop( $q );
	$f = 'autoload/' . implode( '/' , $q ) . '/class.' . $c . '.php';
	if ( $c == 'Savant3' )
	{
		require_once 'autoload/Savant3.php';
		return true;
	}
	if ( file_exists( $f ) )
		require_once( $f );
}

spl_autoload_register( '__autoload_my_classes' );
mb_internal_encoding( "UTF-8" );

define( 'OPD_DIR' , 'autoload/' );
require_once OPD_DIR . 'opd.class.php';
require_once 'config.php';
require_once 'libraries/medoo.php';
require_once 'resources/xajax/xajax_core/xajax.inc.php';
require_once 'libraries/grid/config.php';


date_default_timezone_set('Europe/Warsaw');
  
function sortByOption( $a, $b ) {
  return strcmp( $a['date'], $b['date']);
}

session_start();

$mdb = new medoo( [
                    'database_type' => 'mysql',
                    'database_name' => $config['db']['name'],
                    'server'        => $config['db']['host'],
                    'username'      => $config['db']['user'],
                    'password'      => $config['db']['password'],
                    'charset'       => 'utf8'
                ] );

if ( \S::get( 'a' ) == 'phrase-position' )
{
  echo json_encode( [ 
          'position' => $mdb -> get( 'pro_rr_phrases_positions', 'position', [ 
                                  'AND' => [ 
                                    'phrase_id' => \S::get( 'phrase_id' ),
                                    'date'      => date( 'Y-m-d' ) 
                                  ] ] ),
          'last_url' => \factory\Ranker::last_phrase_url( \S::get( 'phrase_id' ) ) 
        ] );
  exit;
}