<?php



namespace App\Http\Controllers;



use App\Models\MarkList;

use App\User;

use Auth;

use Cookie;

use DB;

use File;

use Illuminate\Http\Request;

use Illuminate\Http\Response;

use Illuminate\Support\Facades\Crypt;

use Illuminate\Support\Facades\Redirect;

use Illuminate\Support\Facades\Session;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\View;



class MarkListController extends Controller

{



    public function index(Request $request)

    {



    	if(!session()->has('user_id')){

    	 	Session::flash('message', " Signing-in is required !");

            return abort(403);

    	 }



    	$mark_list = MarkList::GetMarkList(session()->get('user_id'));

    	return View::make('marklist', with(['mark_list' => $mark_list]));

    }



    /**

     * Show the form for creating a new resource.

     *

     * @return Response

     */

      



    /**

     * Store a newly created resource in storage.

     *

     * @return Response

     */

    public function store(Request $request)

    {



    	 if(!session()->has('user_id')){

    	 	Session::flash('message', " Signing-in is required for marking items!");

            return back();

    	 }else{



    	 	$data['type_id'] = $request->itemtype;

    	 	$data['type_detail_id'] = decrypt($request->param);

    	 	$data['user_id'] = session()->get('user_id');

    	 	MarkList::AddMarkItem($data);

    	 	Session::flash('success_message', "Item marked successfully!");

            return back();

    	 }

    }

    

    public function destroy(Request $request)

        {

    	if(!session()->has('user_id')){

    	 	Session::flash('message', " Signing-in is required !");

            return back();

    	 }else{	

    		$nid = decrypt($request->param);

    		$user_id = session()->get('user_id');



    	    MarkList::DeleteMarkItem($nid,$user_id);

    	 	Session::flash('success_message', "Item unmarked successfully!");

            return back();

    	 }

            }

}