<?php
 
/*
  |--------------------------------------------------------------------------
  | Application Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register all of the routes for an application.
  | It's a breeze. Simply tell Laravel the URIs it should respond to
  | and give it the Closure to execute when that URI is requested.
  |
 */

Route::any('/', 'HomeController@index');

Route::get('logout', function () {
    Auth::logout();

    return Redirect::to('/');
});

/* * *******************
  FACEBOOK login
 * ********************* */

Route::get('login/fb', 'HomeController@login');
Route::get('login/fb/callback', 'HomeController@callBack');
/* * *******************
 *   TWITTER login
 * ******************** */

Route::get('login/twitter', function () {
    // Reqest tokens
    $tokens = Twitter::oAuthRequestToken();

    // Redirect to twitter and come to /twitter-auth
    Twitter::oAuthAuthenticate(array_get($tokens, 'oauth_token'));
    exit;
});

Route::get('/twitter-auth', function () {
    // Oauth token
    $token = Input::get('oauth_token');

    // Verifier token
    $verifier = Input::get('oauth_verifier');

    // Request access token
    $accessToken = Twitter::oAuthAccessToken($token, $verifier);

    // check if user has been registered already by userId
    $user = User::whereUserid($accessToken['user_id'])->first();

    if (!$user) {

        // if not, get params and register
        $user = new User();
        $user->name = $accessToken['screen_name'];
        $user->userid = $accessToken['user_id'];
        $user->save();
    }

    Auth::login($user);

    return Redirect::to('/')->with('message', 'Logged in with Twitter');
});
/*
 * User route group : http://laravel.com/docs/4.0/routing
 * Laravel Auth see : http://laravel.com/docs/4.0/security
 */
Route::group(array('prefix' => 'user', 'before' => array('auth|user')), function () {
    Route::get('started', 'HomeController@started'); // Quiz start from here
    Route::post('started', 'HomeController@started');
    Route::get('user', 'HomeController@loggedInUser');
    Route::get('result', 'HomeController@quizResult'); // Result url
    Route::get('error', 'HomeController@errorPage'); // Error page handle
    // User Poll //
    Route::post('vote', 'HomeController@userVote'); // User voting by login
    Route::get('poll-form/{poll_id}', 'HomeController@pollForm'); // Load voting form
});
Route::get('share-facebook/{result_id}', 'HomeController@shareFacebook'); // Facebook Share
Route::get('polls-today', 'HomeController@pollsToday'); // Poll page
Route::get('polls-by-id/{poll_id}', 'HomeController@pollsById'); // Poll page
Route::get('polls', 'HomeController@polls'); // Poll page
Route::get('polls-view-more/{poll_id}', 'HomeController@pollsViewMore'); // Poll page
Route::get('poll-share/{short_code}', 'HomeController@pollsShare'); // Poll share page
Route::get('page/{slug}', 'HomeController@pageBySlug'); // Poll page
Route::get('blog', 'HomeController@pageGetBlogs'); // Blog page
Route::get('blog/{slug}', 'HomeController@pageBySlug'); // Poll page
Route::post('facebook-auth', 'HomeController@facebookAuth'); // facebook Auth

Route::get('quiz/{quiz_id?}', 'HomeController@startQuiz'); // Font end Quiz page
Route::get('get-started/{quiz_id?}', 'HomeController@getStartQuiz'); // Get started
Route::post('quiz/{quiz_id?}', 'HomeController@startQuizPost'); // Font end Quiz page
Route::get('quiz-result', 'HomeController@publicQuizResult'); // Font end Quiz page

Route::get('guess-number', 'HomeController@guessNumber'); // Quiz game guess number

/*
 *
 *  Admin route group : http://laravel.com/docs/4.0/routing
 *  Laravel Auth see : http://laravel.com/docs/4.0/security
 *
 */

Route::group(array('prefix' => 'admin', 'before' => array('auth|admin')), function () {
    Route::get('/', 'AdminController@dashboard'); // Admin dashboard
    Route::post('/save-quiz', 'AdminController@addNewQuiz'); // Add quiz
    Route::get('/manage-quiz', 'AdminController@manageQuiz'); // Manage quiz page
    Route::get('/add-new-group', 'AdminController@addNewGroup'); // Add new group
    Route::post('/add-new-group', 'AdminController@postAddNewGroup');
    Route::post('/quiz-delete', 'AdminController@quizDelete'); // Quiz delete
    Route::get('/edit-quiz/{quiz_id}', 'AdminController@editQuiz'); //  Edit quiz
    Route::post('/update-quiz', 'AdminController@updateQuiz'); // Update quiz
    Route::post('/save-new-group', 'AdminController@postAddNewGroup'); // Add new group
    Route::post('/group-delete', 'AdminController@deleteGroupName'); // Delete group
    Route::get('/edit-group/{group_id}', 'AdminController@editGroup'); //Edit group
    Route::post('/update-group', 'AdminController@updateGroup'); // Update group    #Setting
    Route::get('/quiz-setting', 'AdminController@quizSetting'); // Quiz setting
    Route::get('/page-setting', 'AdminController@pageSetting'); // Page setting
    Route::post('/save-quiz-setting', 'AdminController@saveQuizSetting');  // Quiz setting url
    Route::post('/save-page-setting', 'AdminController@savePageSetting'); // Page setting url
    Route::get('/users', 'AdminController@getUsersList'); // Users list
    Route::get('/user-details/{user_id?}', 'AdminController@getUsersQuizResult'); // Users list
    Route::post('/block-user', 'AdminController@blockUser'); // Block user
    Route::get('/logout', 'AdminController@logout'); // Users logout
    Route::get('/reset-pass', 'AdminController@resetPassPage'); // Admin password change
    Route::post('/reset-pass', 'AdminController@resetPass'); // Admin password change
    Route::get('/csv', 'AdminController@exportToCsv'); // Export Csv File
    Route::post('/schedule-delete', 'AdminController@scheduleDelete'); // Schedule delete

    /* New Update */
    Route::get('/manage-poll', 'AdminController@managePolls'); // Manage poll
    Route::post('/save-poll', 'AdminController@savePoll'); // Save poll
    Route::get('/media-manager', 'AdminController@mediaManager'); // Manage poll
    Route::post('/save-media-files', 'AdminController@saveMediaFile'); //Save media files
    Route::post('/delete-media-file', 'AdminController@deleteMediaFile'); //Delete media files
    Route::get('/change-poll-status/{poll_id},{status}', 'AdminController@changePollStatus'); // Change poll status by ID
    Route::get('/poll-delete/{poll_id}', 'AdminController@deletePoll'); // Change poll status by ID
    Route::get('/poll-edit/{poll_id}', 'AdminController@editPoll'); // Edit Poll Form status by ID
    Route::post('/update-poll', 'AdminController@updatePoll'); // Update Poll Form status by ID
    Route::get('/change-poll-feature-status/{poll_id},{status}', 'AdminController@changePollFeature'); // Change poll feature by ID
    Route::get('/load-ajax-media-files', 'AdminController@loadAjaxMediaFiles'); // Change poll feature by ID
    Route::post('/homepage-slider-upload', 'AdminController@homePageSliderUpload'); // Home page slider upload
    Route::get('/manage-pages', 'AdminController@managePages'); // Manage Pages
    Route::post('/manage-pages', 'AdminController@addNewPage'); // Add /  Create new page
    Route::post('/page-delete/{page_id}', 'AdminController@deletePage'); // Delete a page
    Route::post('/save-custom-text', 'AdminController@saveCustomText'); // Save facebook custome text and details text
    Route::get('/analytics-code', 'AdminController@updateAnalytics'); // Save facebook custome text and details text
    Route::post('/analytics-code', 'AdminController@saveAnalytics'); // Save facebook custome text and details text
    Route::get('/guess-number-setting', 'AdminController@guessNumberSetting'); // Guess number setting
    Route::post('/guess-number-setting', 'AdminController@saveNumberSetting'); // Guess number setting
    Route::get('/email-setting', 'AdminController@emailSetting'); //Email Settings
    Route::post('/email-setting', 'AdminController@emailConfigSetting'); //Email Settings
    Route::post('/sign-up-text', 'AdminController@signUptextUpdate'); //Email Settings
});

Route::get('/admin-login', 'AdminController@login'); // Admin Login
Route::post('/admin-login', 'AdminController@adminLogin'); // Login post url


/*
 *  Any missing url
 *  Incase no route found
 */
App::missing(function ($exception) {
    return View::make('user.error')->with('title', 'Hey Dude ! You are trying invalid URL  ');
});

 
