public function yes($id, $userid) { if (Request::isMethod('get')) { //cek event aktif, anaknya bukan, udah pernah ngisi belum, kadept bukan if (Auth::user()->positionid != 1) { $user = User::find($userid); // dd($user->deptid); if ($user->deptid != Auth::user()->deptid) { return redirect('/'); } $data = Event::where('enabled', 1)->find($id); if (!$data) { return redirect('/'); } if (!$data->enabled) { return redirect('/'); } $cek = Flag::where('eventid', $id)->where('from', '!=', $userid)->where('to', $userid)->first(); if ($cek != null) { return redirect('/'); } $this->data['event'] = $data; $this->data['questions'] = Pivot::where('eventid', $id)->get(); return view('pages.submit.yes', $this->data); } else { return redirect('/'); } } else { $input = Input::get('score'); $data = Event::where('enabled', 1)->find($id); if (!$data) { return redirect('/'); } if (!$data->enabled) { return redirect('/'); } // dd($input); //set ke mark foreach ($input as $key => $value) { $mark = new Mark(); $mark->userid = $userid; $mark->questionid = $key; $mark->string = $value; $mark->save(); } //set ke score $score = Score::where('eventid', $id)->where('userid', $userid)->first(); if ($score) { foreach ($input as $key => $value) { $question = Question::find($key); if ($question->type == 1) { $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first(); $score->score += $value * $pivot->score / 100; $score->save(); } } } else { $score = new Score(); $score->eventid = $id; $score->userid = $userid; $score->score = 0; foreach ($input as $key => $value) { $question = Question::find($key); // dd($input); if ($question->type == 1) { $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first(); $score->score += $value * $pivot->score / 100; $score->save(); } } } //set ke flag $flag = new Flag(); $flag->from = Auth::id(); $flag->to = $userid; $flag->eventid = $id; $flag->save(); return redirect('submit/' . $id); } }
public function postAddMarkall(Request $request) { //saif for admin or inst mark add 1/25/16 //return 1; $clsassid = Input::get('classId'); $className = Input::get('ClassName'); $markExamName = Input::get('examName'); $markSubj = Input::get('subjName'); $std_id = Input::get('stdId'); $stdRoll = Input::get('stdRoll'); $std_name = Input::get('stdName'); $std_phone = Input::get('stdphone'); $std_image = Input::get('stdImage'); $mark = Input::get('mark'); $sectionName = Input::get('sectionName'); $icode = Auth::user()->institute_id; $data = Input::all(); //return $sectionName; if ($request->ajax()) { $data = Input::all(); $clsassid = $data['classId']; $className = $data['ClassName']; $markExamName = $data['examName']; $markSubj = $data['subjName']; $std_id = $data['stdId']; $stdRoll = $data['stdRoll']; $std_name = $data['stdName']; $std_phone = $data['stdphone']; $std_image = $data['stdImage']; $mark = $data['mark']; $sectionName = $data['sectionName']; //return $sectionName; $icode = $data['iid']; // return $icode; for ($a = 0; $a < count($clsassid); $a++) { //return $clsassid; $markchecktest = Mark::where('exam_name', '=', $markExamName[$a])->where('exam_subject', '=', $markSubj[$a])->where('class_id', '=', $clsassid[$a])->get(); $markcheck = Mark::where('exam_name', '=', $markExamName[$a])->where('exam_subject', '=', $markSubj[$a])->where('class_id', '=', $clsassid[$a])->count(); //return $markcheck; if ($markcheck != 0) { for ($a = 0; $a < count($clsassid); $a++) { $updateMark[] = Mark::where('class_id', '=', $clsassid[$a])->where('exam_subject', '=', $markSubj[$a])->where('exam_name', '=', $markExamName[$a])->where('student_id', '=', $std_id[$a])->where('section', '=', $sectionName[$a])->update(array('sub_mark' => $mark[$a])); } // Session::flash('data', 'You successfully'); return response()->json(); } else { for ($a = 0; $a < count($clsassid); $a++) { $addmark = new Mark(); $addmark->institute_code = $icode[$a]; $addmark->exam_subject = $markSubj[$a]; $addmark->student_id = $std_id[$a]; $addmark->section = $sectionName[$a]; $addmark->student_name = $std_name[$a]; $addmark->class_id = $clsassid[$a]; $addmark->class_name = $className[$a]; $addmark->phone = $std_phone[$a]; $addmark->roll = $stdRoll[$a]; $addmark->image = $std_image[$a]; $addmark->exam_name = $markExamName[$a]; $addmark->sub_mark = $mark[$a]; $addmark->save(); } // Session::flash('data', 'You successfully'); return response()->json(); } } // Session::flash('data', 'You successfully'); return response()->json(); } else { // return 2; redirect()->back(); } }