<?php
/**
* Created by PhpStorm.
* User: lambasoft
* Date: 8/29/17
* Time: 12:11 AM
*/



$this->load->library('form_validation');

if(!isset($this->data['activeTab'])){
    $this->data['activeTab'] = (isset($_GET['tab'])? (($_GET['tab'] == "login")? "login" : "register"): "login");
}

if(isset($this->data['registered']) && $this->data['registered'] == TRUE){
    $this->jsData['alerts']['registered'] = array(
        "title" => "Registered",
        "text" => "Thank you for registering, please login to access all site features.",
        "type" => "success"
    );
}


if($this->input->get("registered") == "true"){
    $this->jsData['alerts']['registered'] = array(
        "title" => "Registered",
        "text" => "Thank you for registering, please login to access all site features.",
        "type" => "success"
    );
}

$this->load->model('CMS_model');
$schools = $this->CMS_model->getSchools();
$this->data['schools'] = $schools;


if(isset($this->data['logged']) && $this->data['logged'] == TRUE){

    $this->load->model('CMS_model');
    $user = $this->ion_auth->user()->row();
    $savedVideos = $this->CMS_model->getUserSavedVideos($user->id);
    $this->jsData['alerts']['registered'] = array(
        "title" => "Logged In",
        "text" => "Successfully Logged In; redirecting ...",
        "type" => "success"
    );

    if(!empty($savedVideos)){
        $this->jsData['alerts']['registered']['redirect'] = "my_videos";
    }else{
        if (isset($_SESSION['fromvideopage'])) {
            if (strpos($_SESSION['fromvideopage'],'video-playing') !== false) {
                $this->jsData['alerts']['registered']['redirect'] = $_SESSION['fromvideopage'];
            }
        }else {
            $this->jsData['alerts']['registered']['redirect'] = "category-select";
        }
    }


    echo "  <script>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-107117288-1']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

    _gaq.push(['_setCustomVar',
    1,                // This custom var is set to slot #1.  Required parameter.
    'School',    // The name of the custom variable.  Required parameter.
    'school name',        // The value of the custom variable.  Required parameter.
    //  (possible values might be Free, Bronze, Gold, and Platinum)
    1                 // Sets the scope to visitor-level.  Optional parameter.
    ]); 

    </script>
    ";



}

if(isset($_GET['social_login'])){
    echo $_GET['social_login'];
}
$this->data['_categories'] = $this->CMS_model->getCategories();