<?php
namespace front\controls;

class Newsletter 
{
  public static function signin()
  {
    $result = [ 'status' => 'bad' ];
    
    if ( \front\factory\Newsletter::newsletter_signin( \S::get( 'email' ) ) )
      $result = [ 'status' => 'ok' ];
    
    echo json_encode( $result );
    exit;
  }
  
  public static function confirm()
  {
    global $lang;
    
    if ( \front\factory\Newsletter::newsletter_confirm( \S::get( 'hash' ) ) )
      \S::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
    
    header( 'Location: /' );
    exit;
  }
  
  public static function unsubscribe()
  {
    global $lang;
    
    if ( \front\factory\Newsletter::newsletter_unsubscribe( \S::get( 'hash' ) ) )
      \S::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
    
    header( 'Location: /' );
    exit;
  }
}