Sindbad~EG File Manager

Current Path : /home/numerotech/public_html/mcq.urbanedge.co.in/app/controllers/
Upload File :
Current File : //home/numerotech/public_html/mcq.urbanedge.co.in/app/controllers/ResultController.php

<?php

class ResultController extends BaseController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/


	   public function GetResult($course_id)
    {
    	try{
        // $results = DB::select("call usp_get_results('.$course_id.')");
        
        
        
        $courses = Course::where('course_id',$course_id)->first();
        if (isset($courses))
        {   
            $course_name = $courses->course_name;
            $exam_date = $courses->exam_date;
            $exam_city = $courses->exam_city;
            $results = DB::select('call usp_get_results_download(?)',array($course_id));
            
            return View::make('results.result_index')->with('results',$results)->with('course_id' ,$course_id)
                                                     ->with('course_name' ,$course_name)->with('exam_date' ,$exam_date)
                                                     ->with('exam_city' ,$exam_city);
        }
        else
        {
            return "<h4 style='color:red;'> Invalid URL </h4>" ;
        }

    
    	
    	}
    	 catch (Exception $e) {
            Log::error('ResultController - GetResult : '.$e->getMessage());
			Session::flash('msg', AppMessage::$GENERAL_ERROR);
           return $e;
        }
        
    }
       public function ExportResult($course_id)
    {
    	try{
    	   //$results = DB::select('call usp_get_results(?)',array($course_id));
    	   $results = DB::select('call usp_get_results_download(?)',array($course_id));
    	   
    	   $courses = Course::where('course_id',$course_id)->first();
    	   
    	   $course_name = $courses->course_name;
            $exam_date = $courses->course_start_at;
            
            $exam_date = date('d-m-Y', strtotime($exam_date));
            $exam_city = $courses->exam_city;
    
            $filename = "result.csv";
            //$handle   = fopen($filename, 'w+');
            $handle = fopen($filename, 'w');
            fputcsv($handle, array( 'S.No','Name', 'Email', 'Mobile', 'Correct' , 'Wrong' , 'Skipped' , 'Total', 'Total Duration'));
            
            $i = 1;
            $total_ques = 0 ;
            $course_name_as_filename = "dowload.csv";
            $course_name_as_filename = $course_name.'_'.$exam_city.'_'.$exam_date.'.xls';
             header("Content-Type: application/vnd.ms-excel");
             header("Content-Disposition: attachment; filename=\"$course_name_as_filename\"");
             
             return $this->ExportFile_1($results);
            
            // foreach($results as $row) {
            //     $total_ques = $total_ques + $row->totalcorrect + $row->totalwrong + $row->totalSkipped;
                
            //     $course_name_as_filename = $row->course_name.'_'.$row->exam_city.'_'.$row->exam_date.'.csv';

            //     fputcsv($handle, array($i, $row->full_name, $row->email, $row->mobile,  $row->totalcorrect, $row->totalwrong,$row->totalSkipped ,$total_ques ));
            //     $i = $i + 1;
            //     $total_ques = 0 ;
            // }
            // fclose($handle);
            // $headers = array(
            //     'Content-Type' => 'application/vnd.ms-excel; charset=utf-8',
            //     'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
            //     'Content-Disposition' => 'attachment; filename=abc.csv',
            //     'Expires' => '0',
            //     'Pragma' => 'public',
            // );
            // return Response::download($filename, $course_name_as_filename, $headers);
            
    	} catch (Exception $e) {
            Log::error('ResultController - ExportResult : '.$e->getMessage());
			Session::flash('msg', AppMessage::$GENERAL_ERROR);
           return $e;
        }
        
    }
    //
    // Download Result as Excel updated by Ganesan on Dec 22 ,2022 start
  function ExportFile_1($records) 
        {
          $heading = false;
        
        $colunms = ['S.No','Name', 'Email', 'Mobile', 'Correct' , 'Wrong' , 'Skipped' , 'Total Questions' , 'Total Marks','Total Duration'];
        $values_1 = array();
            
            if(!empty($records))
              $i = 1 ;
              $total_count = 0 ;
              foreach($records as $key => $value) {
              if(!$heading) {
                // display field/column names as a first row
                echo implode("\t", $colunms) . "\n"; // this line correct
                //echo [ 'S.No','Name', 'Email', 'Mobile'];
                // echo ['S.No','Name', 'Email', 'Mobile', 'Correct' , 'Wrong' , 'Skipped' , 'Total'];
                $heading = true;
              }
                $values_1[] = $i;
                $values_1[] = $value->full_name;
                $values_1[] = $value->email;
                $values_1[] = $value->mobile;
                
                $values_1[] = $value->totalcorrect;
                $values_1[] = $value->totalwrong;
                $values_1[] = $value->totalSkipped;
                $values_1[] = $value->totalcorrect +$value->totalwrong+$value->totalSkipped;
                
                if(isset($value->viva_marks))
                {
                    $viva_marks = $value->viva_marks;
                }
                else
                {
                    $viva_marks = '';
                }
                
                
                if(isset($value->workshop_mark))
                {
                    $workshop_mark = $value->workshop_mark;
                }
                else
                {
                    $workshop_mark = '';
                }
                
                
                if(isset($value->totalcorrect))
                {
                    $totalcorrect = $value->totalcorrect;
                }
                else
                {
                    $totalcorrect ='';
                }
                
                $values_1[] = 0 + $totalcorrect+ 0;
                
                $values_1[] = $value->duration;
                
                echo implode("\t", $values_1) . "\n";
              $i= $i+1;
              $values_1 = array();

              }
            exit;
        }
    // end
    
       public function CourseTime($course_id)
    {
    	try{
        $results = Course::where('course_id',$course_id)->first();
        if(isset($results) )
        {
            $course_end =  $results->course_end_at ;
            $dt = new DateTime($course_end);

            $date_1 = $dt->format('Y-m-d');
            $curr_date = date('Y-m-d');
            $is_update_btn = 1 ;
            // BELOW LINE COMMENTED FOR DEMO 
            // if ($date_1 == $curr_date)
            // {
            //     $is_update_btn = 1 ;
            // }
            // else {
            //     $is_update_btn = 0 ;
            // }
    	return View::make('results.course_time')->with('results',$results)->with('course_id' ,$course_id)->with('is_update_btn',$is_update_btn);
            
        }
        else
        {
            return "<h3 style='color:red;'> Invalid URL </h3> ";
        }
            
    	}
    	 catch (Exception $e) {
            Log::error('ResultController - CourseTime : '.$e->getMessage());
			Session::flash('msg', AppMessage::$GENERAL_ERROR);
           return $e;
        }
    }
    
    // PostCourseTime
        public function PostCourseTime()
    {
    	try{
    	    $course_id      = Input::get('course_id');
    	    $course_start_at = Input::get('course_start_at');
    	    $course_end_at   = Input::get('course_end_at');
    	    
        $results = Course::where('course_id',$course_id)->first();
        if (isset($results) )
        {
            $course_end =  $results->course_end_at ;
            $dt = new DateTime($course_end);

            $date_1 = $dt->format('Y-m-d');
            $curr_date = date('Y-m-d');
            // if ($date_1 == $curr_date)
            // {
                $results->course_start_at  = $course_start_at;
                $results->course_end_at    = $course_end_at ;
                $results->updated_at       = date('Y-m-d H:i:s');
                $results->save();
                return Redirect::to('course-time/'.$course_id)->withFlashMessage('Coures time updated !');
            // }
            // else{
            //     return Redirect::to('course-time/'.$course_id)->withFlashMessage('Sorry , this course not conducted on today.');
            // }
        }

    }
    	 catch (Exception $e) {
            Log::error('ResultController - CourseTime : '.$e->getMessage());
			Session::flash('msg', AppMessage::$GENERAL_ERROR);
           return $e;
        }
    }
    
   
    
    
    //
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists