<?php
namespace view;

class RankerClients 
{
  public static function site_edit( $site_id )
  {    
    $tpl = new \Savant3;
    $tpl -> _site = \factory\Ranker::getSite( $site_id, 'ASC', true );
    return $tpl -> fetch( 'client/site-edit' );
  }
  
  public function drawReportsForm()
  {
    global $user;
    
    $tpl = new \Savant3;
    $tpl -> _sites    = \factory\RankerClients::getSites( $user['id'] );
    return $tpl -> fetch( 'client/reports' );
  }
  
  public function drawSummary( $month = '', $year = '' )
  {
    global $user;
    
    if ( $month ) \S::set_session( 'drawSitesList:month', $month );    
    if ( $year ) \S::set_session( 'drawSitesList:year', $year );
    
    $month  = \S::get_session( 'drawSitesList:month' );
    $year   = \S::get_session( 'drawSitesList:year' );
    
    if ( !$month ) $month = date( 'm' );
    if ( !$year ) $year = date( 'Y' );
    
    $tpl = new \Savant3;
    $tpl -> _sites    = \factory\RankerClients::getSitesSummary( $month, $year, $user['id'], $user['login'] );
    $tpl -> _month    = $month;
    $tpl -> _year     = $year;
    return $tpl -> fetch( 'client/ranker-summary' );
  }

  public function main_view( $id, $month = '', $year = '' )
  {    
    global $user;
    
    if ( $id !== null ) 
      \S::set_session( 'ranker:main_view:id', $id );
    
    if ( $month )
      \S::set_session( 'ranker:main_view:month', $month );
    
    if ( $year ) 
      \S::set_session( 'ranker:main_view:year', $year );
    
    if ( !$month and !\S::get_session( 'ranker:main_view:month' ) )
    {
      $month = date( 'm' );
      \S::set_session( 'ranker:main_view:month', $month );
    }
    
    if ( !$year and !\S::get_session( 'ranker:main_view:year' ) )
    {
      $year = date( 'Y' );
      \S::set_session( 'ranker:main_view:year', $year );
    }
    
    $month  = \S::get_session( 'ranker:main_view:month' );
    $year   = \S::get_session( 'ranker:main_view:year' );
    $id     = \S::get_session( 'ranker:main_view:id' );
    
    $site = \factory\RankerClients::getClientSite( $id, $user['id'] );
    
    $tpl = new \Tpl;
    $tpl -> sites          = \factory\RankerClients::getClientSites( $user['id'] );
    $tpl -> phrases        = \factory\Ranker::getSitePhrases( $site['id'], $month, $year, false, $user['reseller_id'], $user['login'] );
    $tpl -> comments        = \factory\Ranker::site_comments( $site['id'], $month, $year );
    $tpl -> site           = $site;
    $tpl -> month          = $month;
    $tpl -> year           = $year;
    $tpl -> next_site_id   = \factory\RankerClients::getNextClientSiteId( $site['id'], $user['id'] );
    $tpl -> prev_site_id   = \factory\RankerClients::getPrevClientSiteId( $site['id'], $user['id'] );
    return $tpl -> render( 'client/site-list' );
  }
}
?>
