<?php 
namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\model\Source;
use View;
use Illuminate\Support\Facades\Input;
use App\Http\Requests\SourceRequest;

use Session;

class SourceController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
            $success = Session::get('success');
            $sources = Source::all(); 
            return View::make('pages.sources')->with('sources',$sources)->with('success', $success);
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
            return View::make('pages.add_source');
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store(SourceRequest $request)
	{
            $source = new Source();
            $source->source_name = Input::get('source_name');
            if($source->save())
            {
                return redirect('sources')->with('success','Source added successfully.');
            }
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
            $source_to_edit = Source::find($id);
            return View::make('pages.add_source')->with('source_to_edit',$source_to_edit);
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update(SourceRequest $request)
	{
            $source_id = Input::get('source_id');  
            $source = Source::find($source_id);
            $source->source_name = Input::get('source_name');
            if($source->save())
            {                
                return redirect('sources')->with('success','Source Updated successfully.');            
            }
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
