/**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function getsheet()
 {
     $inputs = Input::all();
     $input = (object) $inputs;
     $subjects = Subject::select('name')->where('class', $input->class)->orderby('code', 'asc')->get();
     if (count($subjects) < 1) {
         return Redirect::to('/tabulation')->withInput(Input::all())->with("error", "There are not subjects for this class!");
     }
     $students = Student::select('regiNo', 'firstName', 'middleName', 'lastName')->where('class', $input->class)->where('section', $input->section)->where('session', trim($input->session))->where('shift', $input->shift)->get();
     if (count($students) < 1) {
         return Redirect::to('/tabulation')->withInput(Input::all())->with("error", "There are not student for this class!");
     }
     $merit = DB::table('MeritList')->select('regiNo', 'grade', 'point', 'totalNo')->where('exam', $input->exam)->where('class', $input->class)->where('session', trim($input->session))->orderBy('point', 'DESC')->orderBy('totalNo', 'DESC')->get();
     if (count($merit) < 1) {
         return Redirect::to('/tabulation')->withInput(Input::all())->with("error", "Marks not submit or result not generate for this exam!");
     }
     foreach ($students as $student) {
         $marks = Marks::select('written', 'mcq', 'practical', 'ca', 'total', 'grade', 'point')->where('regiNo', $student->regiNo)->where('exam', $input->exam)->orderby('subject', 'asc')->get();
         if (count($marks) < 1) {
             return Redirect::to('/tabulation')->withInput(Input::all())->with("error", "Marks not submited yet!");
         }
         /*$marks = DB::table('Marks')
           ->join('MeritList', 'Marks.regiNo', '=', 'MeritList.regiNo')
           ->select('Marks.written','Marks.mcq', 'Marks.practical', 'Marks.ca', 'Marks.total', 'Marks.grade', 'Marks.point', 'MeritList.totalNo', 'MeritList.grade as tgrade','MeritList.point as tpoint')
           ->where('Marks.regiNo',$student->regiNo)
           ->where('Marks.exam', '=',$input->exam)
           ->orderby('Marks.subject','asc')
           ->get();*/
         $meritdata = new Meritdata();
         $position = 0;
         foreach ($merit as $m) {
             $position++;
             if ($m->regiNo === $student->regiNo) {
                 $meritdata->regiNo = $m->regiNo;
                 $meritdata->point = $m->point;
                 $meritdata->grade = $m->grade;
                 $meritdata->position = $position;
                 $meritdata->totalNo = $m->totalNo;
                 break;
             }
         }
         $student->marks = $marks;
         $student->meritdata = $meritdata;
     }
     $cl = ClassModel::Select('name')->where('code', $input->class)->first();
     $input->class = $cl->name;
     $fileName = $input->class . '-' . $input->section . '-' . $input->session . '-' . $input->exam;
     // return $students;
     Excel::create($fileName, function ($excel) use($input, $subjects, $students) {
         $excel->sheet('New sheet', function ($sheet) use($input, $subjects, $students) {
             $sheet->loadView('app.excel', compact('subjects', 'input', 'students'));
         });
     })->download('xlsx');
 }
<?php

require_once '../core/init.php';
if (privilege() == NULL) {
    die;
}
if (Input::exists()) {
    if (Input::get('from_aa') > 100) {
        die("Grade AA cannot be more than 100.");
    }
    $scale = "100," . Input::get('from_aa') . "," . Input::get('to_ab') . "," . Input::get('from_ab') . "," . Input::get('to_ba') . "," . Input::get('from_ba') . "," . Input::get('to_bb') . "," . Input::get('from_bb') . "," . Input::get('to_cc') . "," . Input::get('from_cc') . "," . Input::get('to_cd') . "," . Input::get('from_cd') . "," . Input::get('to_dd') . "," . Input::get('from_dd');
    $m = new Marks();
    $mm = $m->setGradingScale(Input::get('tid'), Input::get('cid'), Input::get('dep'), $scale);
    if ($mm == 1) {
        echo '<div class="alert alert-success alert-dismissible" role="alert">';
        echo 'Saved Successfully!';
        echo '</div>';
    } else {
        if ($mm == 0) {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo 'Temporary Error!';
            echo '</div>';
        } else {
            if ($mm == 2) {
                echo '<div class="alert alert-warning alert-dismissible" role="alert">';
                echo 'No changes made!';
                echo '</div>';
            }
        }
    }
}
<?php

require_once 'core/init.php';
if (!loggedIn()) {
    die;
    exit;
}
$cid_dep = explode(',', Input::get('id'));
$cid = $cid_dep[0];
$dep = $cid_dep[1];
$gmarks = new Marks();
$scale = $gmarks->getGradeScale($cid, $dep);
$grade_set = explode(',', $scale);
?>
<div class="box box-default" id="grade_scale">
	<div class="box-header">
		<h3 class="box-title">Grading Scale</h3>
	</div> <!-- /.box header -->
	<div class="box-body table-responsive no-padding">
		<form  role="form" id="grade_scale">
			<input class="form-control" type="hidden" name="tid" value="<?php 
echo Session::get('teacher_id');
?>
" />
			<input class="form-control" type="hidden" name="cid" value="<?php 
echo $cid;
?>
" />
			<input class="form-control" type="hidden" name="dep" value="<?php 
echo $dep;
?>
         $date = date_create($lastdate);
         echo '<div class="alert alert-danger alert-dismissible" role="alert">';
         echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
         echo "Last Date for " . strtoupper(Input::get('examtype')) . " was " . date_format($date, 'd-M-Y');
         echo '</div>';
         die;
     }
     if (empty($_FILES["file"]["tmp_name"])) {
         echo '<div class="alert alert-danger alert-dismissible" role="alert">';
         echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
         echo 'Please Select CSV File';
         echo '</div>';
         die;
     }
     $input = explode(',', Input::get('course_id'));
     $m = new Marks();
     $import = $m->importCSV($input[0], $input[1], Input::get('examtype'), Input::get('category'), $_FILES["file"]["tmp_name"]);
     if ($import) {
         echo '<div class="alert alert-success alert-dismissible" role="alert">';
         echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
         echo "Successfully Imported";
         echo '</div>';
     } else {
         echo '<div class="alert alert-danger alert-dismissible" role="alert">';
         echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
         echo "Temporary problem!";
         echo '</div>';
     }
 } else {
     echo '<div class="alert alert-warning alert-dismissible" role="alert">';
     echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
<?php

require_once '../core/init.php';
if (privilege() == NULL) {
    die;
}
if (Input::exists('post')) {
    $validate = new Validate();
    $validation = $validate->check($_POST, array('examtype' => array('required' => true), 'lastdate' => array('required' => true)));
    if ($validate->passed()) {
        $dep = new Marks();
        $date = changeDateFormatToDB(Input::get('lastdate'));
        $setDate = $dep->setLastDate(Input::get('examtype'), $date);
        if ($setDate == 3) {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Sorry, you don\'t have privilege to set Last date for examination.';
            echo '</div>';
        } else {
            if ($setDate == 1) {
                echo '<div class="alert alert-success alert-dismissible" role="alert">';
                echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
                echo 'Last date saved successfully.';
                echo '</div>';
            } else {
                if ($setDate == 0) {
                    echo '<div class="alert alert-danger alert-dismissible" role="alert">';
                    echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
                    echo 'Temporary Error!';
                    echo '</div>';
                } else {
<?php

require_once '../core/init.php';
if (!loggedIn()) {
    die;
}
if (privilege() == NULL) {
    die;
}
if (Input::exists()) {
    if (Input::get('course_id') != '') {
        $var = explode(',', Input::get('course_id'));
        $m = new Marks();
        if (!$m->getGradeScale($var[0], $var[1])) {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Set grading scale first!';
            echo '</div>';
            die;
        }
        $m->generateResult($var[0], $var[1]);
        $c = new Course();
        $c->getInfobyId($var[0]);
        ?>
			<div class="box box-success">
				<div class="box-header">
					<h1 class="box-title">Final Result ( <?php 
        echo $var[0] . ' - ' . $c->getCourseName();
        unset($c);
        ?>
 )</h1>
<?php

require_once '../core/init.php';
if (privilege() == NULL) {
    die;
}
if (Input::exists()) {
    $i = 1;
    $j = 0;
    $k = 0;
    $status = "Marks was left empty of Scholar Number :-";
    while (Input::get('scholar_number' . $i)) {
        $m = new Marks();
        if (Input::get('marks' . $i) != '') {
            $mm = $m->MarksEntryLoad(Input::get('scholar_number' . $i), Input::get('c_code'), Input::get('c_dep'), Input::get('examtype'), Input::get('marks' . $i));
            if ($mm == 2) {
                $k++;
                //die("Something went wrong after Scholar number: ".Input::get('scholar_number'.$i)." . Please Try again.");
            }
        } else {
            $status = $status . Input::get('scholar_number' . $i) . ", ";
            $k++;
            $j++;
        }
        $i++;
    }
    if ($k) {
        echo "Number of rows effected:" . ($i - $k - 1) . "<br />";
    }
    if ($j != 0) {
        $log = new Log();
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="box box-default">
				<div class="box-header">
					<h3 class="box-title">Sessional Formula</h3>
					<div class="box-tools pull-right">
	                	<button class="btn btn-default btn-sm" data-widget="collapse"><i class="fa fa-minus"></i></button>
	                </div>
				</div> <!-- /.box header -->
				<div class="box-body">
					<h3><strong>
					 <?php 
unset($gmarks);
$marks = new Marks();
$sf = $marks->getSessionalFormula('', $cid, $dep);
if ($sf->num_rows) {
    $formula = $sf->fetch_object()->formula;
} else {
    $formula = 1;
}
switch ($formula) {
    case 1:
        echo 'Highest of Two Class Tests + Internal Assessment';
        break;
    case 2:
        echo 'Average of Two Class Tests + Internal Assessment';
        break;
    default:
        echo 'Highest of Two Class Tests + Internal Assessment';
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update()
 {
     $rules = ['written' => 'required', 'mcq' => 'required', 'practical' => 'required', 'ca' => 'required'];
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/mark/edit/' . Input::get('id'))->withErrors($validator);
     } else {
         $gparules = GPA::select('gpa', 'grade', 'markfrom')->get();
         $marks = Marks::find(Input::get('id'));
         $marks->written = Input::get('written');
         $marks->mcq = Input::get('mcq');
         $marks->practical = Input::get('practical');
         $marks->ca = Input::get('ca');
         $totalmark = Input::get('written') + Input::get('mcq') + Input::get('practical') + Input::get('ca');
         $marks->total = $totalmark;
         foreach ($gparules as $gpa) {
             if ($totalmark >= $gpa->markfrom) {
                 $marks->grade = $gpa->gpa;
                 $marks->point = $gpa->grade;
                 break;
             }
         }
         $marks->Absent = Input::get('Absent');
         $marks->save();
         return Redirect::to('/mark/list')->with("success", "Marks Update Sucessfully.");
     }
 }
<?php

require_once 'core/init.php';
if (!loggedIn() || privilege() == NULL) {
    die;
}
$cid_dep = explode(',', Input::get('id'));
$cid = $cid_dep[0];
$dep = $cid_dep[1];
$gmarks = new Marks();
$scale = $gmarks->getGradeScale($cid, $dep);
$grade_set = explode(',', $scale);
?>

	<div class="box box-default" id="formula">
	
			<div class="box-header">
				<h3 class="box-title">Sessional Formula</h3>
			</div> <!-- /.box header -->
			<!-- form start -->
			<form role="form" action="post" id="sessional_formula">
				<div class="box-body">
					<div class="form-group">
						<label for="formula">Select formula</label>
						    <?php 
$sf = $gmarks->getSessionalFormula(Session::get('teacher_id'), $cid, $dep);
if ($sf->num_rows) {
    $formula = $sf->fetch_object()->formula;
} else {
    $formula = 1;
}
<?php

require_once '../core/init.php';
if (privilege() == NULL) {
    die;
}
if (Input::exists()) {
    $validate = new Validate();
    $validation = $validate->check($_POST, array('formula' => array('required' => true)));
    if ($validate->passed()) {
        $m = new Marks();
        $add = $m->setSessionalFormula(Session::get('teacher_id'), Input::get('ccode'), Input::get('cdep'), Input::get('formula'));
        if ($add == 1) {
            echo '<div class="alert alert-success alert-dismissible" role="alert">';
            echo 'Saved Successfully!';
            echo '</div>';
        } else {
            if ($add == 0) {
                echo '<div class="alert alert-danger alert-dismissible" role="alert">';
                echo 'Temporary Error!';
                echo '</div>';
            } else {
                if ($add == 2) {
                    echo '<div class="alert alert-warning alert-dismissible" role="alert">';
                    echo 'No changes made!';
                    echo '</div>';
                }
            }
        }
    } else {
        echo '<div class="alert alert-warning alert-dismissible" role="alert">';
    $courses = $s->getCoursesLoad();
    $courses = explode(',', $courses);
    foreach ($courses as $course) {
        ?>
                                        	<tr>
                                        	<td><?php 
        echo $course;
        ?>
</td>
                                        	<td>
                                        		<?php 
        $c = new Course();
        $c->getInfobyId($course);
        echo $c->getCourseName();
        unset($c);
        $m = new Marks();
        $marks = $m->getMarksLoad(Session::get('sn'), $course, '*');
        if ($marks == '') {
            $ct1 = '-';
            $ct2 = '-';
            $ia = '-';
            $ms = '-';
            $es = '-';
            $g = '-';
        } else {
            $marks = $marks->fetch_object();
            $ct1 = $marks->ct1;
            $ct2 = $marks->ct2;
            $ia = $marks->ct3;
            $ms = $marks->midsem;
            $es = $marks->endsem;
<?php

require_once '../core/init.php';
if (!Input::exists('get')) {
    die;
}
if (privilege() == NULL) {
    die;
} else {
    if (Input::get('examtype') == '') {
        ?>
	<input type="text" placeholder="mm/dd/yyyy" class="form-control" data-provide="datepicker" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask="" name="lastdate" id="lastdate">
<?php 
    } else {
        $dep = new Marks();
        $last_date = $dep->getLastDate(Input::get('examtype'));
        if ($last_date->num_rows) {
            $last_date = changeDateFormatFromDB($last_date->fetch_object()->date);
            if ($last_date == '00/00/0000') {
                $last_date = '';
            }
        } else {
            $last_date = '';
        }
        ?>
<input type="text" placeholder="mm/dd/yyyy" class="form-control" data-provide="datepicker" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask="" name="lastdate" id="lastdate" value="<?php 
        echo $last_date;
        ?>
">
<?php 
    }
<?php

require_once '../core/init.php';
require_once ROOT_DIR . 'functions/spline.php';
if (!loggedIn() || !Token::check(Input::get('token'))) {
    die;
}
if (Input::exists('get')) {
    $m = new Marks();
    $aa = $m->totalNumOfGivenGrade('10', Input::get('cid'), Input::get('did'));
    $ab = $m->totalNumOfGivenGrade('9', Input::get('cid'), Input::get('did'));
    $bb = $m->totalNumOfGivenGrade('8', Input::get('cid'), Input::get('did'));
    $bc = $m->totalNumOfGivenGrade('7', Input::get('cid'), Input::get('did'));
    $cc = $m->totalNumOfGivenGrade('6', Input::get('cid'), Input::get('did'));
    $cd = $m->totalNumOfGivenGrade('5', Input::get('cid'), Input::get('did'));
    $dd = $m->totalNumOfGivenGrade('4', Input::get('cid'), Input::get('did'));
    $f = $m->totalNumOfGivenGrade('0', Input::get('cid'), Input::get('did'));
    createSpline(array($aa, $ab, $bb, $bc, $cc, $cd, $dd, $f));
}
            case 'endsem':
                echo "End-Semester <i>(Max Marks : 50)</i>";
                $max = "50";
                break;
        }
        ?>
                    
                    
                    </th>
                 </tr>
            </thead>
            <tbody>
				<?php 
        $j = 0;
        while ($students = $studs->fetch_object()) {
            $mmm = new Marks();
            $saved_m = $mmm->getMarksLoad($students->scholar_no, $c_code, $type);
            if (!empty($saved_m) && $saved_m->num_rows) {
                $marks = $saved_m->fetch_object()->{$type};
            } else {
                $marks = 0.0;
            }
            ?>
				<tr>
					<th><?php 
            echo $j + 1;
            ?>
</th>
					<th><input type="hidden" name="scholar_number<?php 
            echo $j + 1;
            ?>
include 'header.php';
if (!loggedIn()) {
    Redirect::to('index.php');
} else {
    if (loggedIn() && !Session::exists('teacher_id')) {
        Session::destroy();
        Redirect::to('includes/errors/unauthorized.php');
    }
}
if (Input::exists()) {
    $validate = new Validate();
    $validation = $validate->check($_POST, array('course_id' => array('required' => true), 'examtype' => array('required' => true), 'category' => array('required' => true)));
    if ($validate->passed()) {
        $input = Input::get('course_id');
        $input = explode(',', Input::get('course_id'));
        $m = new Marks();
        if ($m->exportCSV($input[0], $input[1], Input::get('examtype'), Input::get('category'))) {
            echo '<div class="alert alert-success alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo '<strong>Export successful</strong>';
            echo '</div>';
        } else {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Temporary Error!';
            echo '</div>';
        }
    } else {
        echo '<div class="alert alert-warning alert-dismissible" role="alert">';
        echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
        foreach ($validate->errors() as $errors) {
 public function postgenerate()
 {
     $rules = ['class' => 'required', 'exam' => 'required', 'session' => 'required'];
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/result/generate')->withErrors($validator)->withInput();
     } else {
         $subjects = Subject::select('name', 'code', 'type', 'subgroup')->where('class', '=', Input::get('class'))->get();
         $marksubmit = Marks::select('subject')->where('class', '=', Input::get('class'))->where('session', trim(Input::get('session')))->where('exam', Input::get('exam'))->distinct()->get();
         if (count($subjects) == count($marksubmit)) {
             $fourthsubjectCode = "";
             foreach ($subjects as $subject) {
                 if ($subject->type === "Electives") {
                     $fourthsubjectCode = $subject->code;
                 }
             }
             $students = Student::select('regiNo')->where('class', '=', Input::get('class'))->where('session', '=', trim(Input::get('session')))->get();
             if (count($students) != 0) {
                 $gparules = GPA::select('gpa', 'grade', 'markfrom')->get();
                 $foobar = array();
                 foreach ($students as $student) {
                     $marks = Marks::select('subject', 'grade', 'point', 'total')->where('regiNo', '=', $student->regiNo)->where('exam', '=', Input::get('exam'))->get();
                     if (count($marks) != 0) {
                         $totalpoint = 0;
                         $totalmarks = 0;
                         $subcounter = 0;
                         $banglamark = 0;
                         $englishmark = 0;
                         $isfail = false;
                         foreach ($marks as $mark) {
                             if ($this->getSubGroup($subjects, $mark->subject) === "Bangla") {
                                 $banglamark += $mark->total;
                             } else {
                                 if ($this->getSubGroup($subjects, $mark->subject) === "English") {
                                     $englishmark += $mark->total;
                                 } else {
                                     if ($mark->subject === $fourthsubjectCode) {
                                         if ($mark->point >= 2.0) {
                                             $totalmarks += $mark->total;
                                             $totalpoint += $mark->point - 2;
                                         } else {
                                             $totalmarks += $mark->total;
                                         }
                                         $subcounter--;
                                     } else {
                                         $totalmarks += $mark->total;
                                         $totalpoint += $mark->point;
                                     }
                                 }
                             }
                             $subcounter++;
                             if ($mark->subject !== $fourthsubjectCode && $mark->grade === "F") {
                                 $isfail = true;
                             }
                         }
                         if ($banglamark > 0) {
                             $blmarks = floor($banglamark / 2);
                             $totalmarks += $banglamark;
                             $totalpoint += $this->pointCalculator($blmarks, $gparules);
                             $subcounter--;
                         }
                         if ($englishmark > 0) {
                             $enmarks = floor($englishmark / 2);
                             $totalmarks += $englishmark;
                             $totalpoint += $this->pointCalculator($enmarks, $gparules);
                             $subcounter--;
                         }
                         $grandPoint = $totalpoint / $subcounter;
                         if ($isfail) {
                             $grandGrade = $this->gradnGradeCal(0.0, $gparules);
                         } else {
                             $grandGrade = $this->gradnGradeCal($grandPoint, $gparules);
                         }
                         $merit = new MeritList();
                         $merit->class = Input::get('class');
                         $merit->session = trim(Input::get('session'));
                         $merit->exam = Input::get('exam');
                         $merit->regiNo = $student->regiNo;
                         $merit->totalNo = $totalmarks;
                         $merit->point = $grandPoint;
                         $merit->grade = $grandGrade;
                         $merit->save();
                     } else {
                         return Redirect::to('/result/generate')->withInput()->with("noresult", "This examintaion marks not submited yet!!");
                     }
                 }
             } else {
                 return Redirect::to('/result/generate')->withInput()->with("noresult", "There is no students in this class!!");
             }
             return Redirect::to('/result/generate')->with("success", "Result Generate and Publish Successfull.");
         } else {
             return Redirect::to('/result/generate')->withInput()->with("noresult", "All subjects marks not submited yet!!");
         }
     }
 }