Viewing file: test_action.php (6.04 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php require 'connection.php';
$technology=$_REQUEST['technology']; $semester=$_REQUEST['semester']; $subject=$_REQUEST['subject']; $question=$_REQUEST['question']; $option_a=$_REQUEST['optiona']; $option_b=$_REQUEST['optionb']; $option_c=$_REQUEST['optionc']; $option_d=$_REQUEST['optiond']; $correct=$_REQUEST['correct']; $exam_title=$_REQUEST['title']; $qtype=$_REQUEST['qtype'];
//echo $qtype;die(); $query="select * from exam where exam_title='$exam_title'"; $res=$con->query($query); $co=$res->fetch_assoc(); $exam_id=$co['exam_id']; $examtime=$co['examtime'];
if($qtype=='Excel Upload'){ $csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'); // Validate whether selected file is a CSV file if(!empty($_FILES['excel_up']['name']) && in_array($_FILES['excel_up']['type'], $csvMimes)){ // If the file is uploaded if(is_uploaded_file($_FILES['excel_up']['tmp_name'])){ // Open uploaded CSV file with read-only mode $csvFile = fopen($_FILES['excel_up']['tmp_name'], 'r'); // Skip the first line fgetcsv($csvFile); // $prevResult = $con->query("SELECT id FROM syllabus WHERE technology = '$technology' and package='$package'"); // $row = mysqli_fetch_assoc($prevResult); // if($prevResult->num_rows > 0){ // $syllabusid=$row['id']; // $con->query("DELETE FROM syllabus_topics WHERE syllabus_id = '$syllabusid'"); // }else{ // $add=$con->query("INSERT INTO syllabus (technology,package) VALUES ('$technology','$package')"); // $syllabusid=$con->insert_id;; // } // Parse data from CSV file line by line while(($line = fgetcsv($csvFile)) !== FALSE){ // Get row data $question = $line[0]; $option_a =$line[1]; $option_b =$line[2]; $option_c =$line[3]; $option_d =$line[4]; $correct=$line[5]; $add=$con->query("insert into online_test(question,a,b,c,d,semester,subject,batch_id,correct_answer,submit_answer,exam_id) values('$question','$option_a','$option_b','$option_c','$option_d','$semester','$subject','$technology','$correct','1','$exam_id')"); } // Close opened CSV file fclose($csvFile); $qstring = '?status=succ';
}else{ $qstring = '?status=err'; } }else{ $qstring = '?status=invalid_file'; }
header("Location: test_question.php".$qstring); } else{ if($exam_id!=''){ $sql="insert into online_test(question,a,b,c,d,semester,subject,batch_id,correct_answer,submit_answer,exam_id) values('$question','$option_a','$option_b','$option_c','$option_d','$semester','$subject','$technology','$correct','1','$exam_id')"; $result=$con->query($sql); $count=$con->affected_rows; if($count>0){ $c=0; //header('location:online_test.php?status=success'); $sql2=$con->query("select count(*) from `online_test` where exam_id=$exam_id"); $count2=$sql2->num_rows; if($count2>0){ while($row2=$sql2->fetch_assoc()){ $c=$row2['count(*)'];
}}
if($c==$examtime){
$sql1="SELECT * FROM `user_details` INNER JOIN enrolldetails ON user_details.user_id=enrolldetails.user_id where enrolldetails.course_id=$semester "; $result1=$con->query($sql1); $count1=$result1->num_rows; while($row1=$result1->fetch_assoc()){ $phone=$row1['phone']; $sql2="select * from `tb_user` WHERE phone='$phone' and device_token!=''"; $result2=$con_it->query($sql2); $count2=$result2->num_rows; $device=""; if($count2>0){ while ($row2=$result2->fetch_assoc()) { $device=$row2['device_token']; $user=$row2['user_id'];
// API access key from Google API's Console define( 'API_ACCESS_KEY','AAAABLsF19c:APA91bEwIVggcRMYaF4ZHZtpTjaMYSgnvN3Pc5F-R0IRftn1b4_VHsaFpUkzA5ilpZOHiBtStx5edgWc_zQs9bB4lbiW0AErUgfGBq7JOWKQVDBq1VZt2A6z_au1_T_nZOC0kvEUqIP0');
// $device="cc1wbmjCR5-80c0uTdK4mx:APA91bG4Xw4PMETnNC_9Bz7FM786mD6nhEToZ9CG7kBb1lp2dSU6J0i2y7gIkseteNeEGSOO_ocbRovtAXVTarUHzP6QO6Y0spyV-XPEyquRsUenutP5jzvmGBlfTzyoWjQsO7ascMth"; $registrationIds = array($device);
$da="select * from technologies where id='$technology'"; $daresult=$con->query($da); $daRow=$daresult->fetch_assoc(); $name=$daRow['name']; $msg= array('Category'=>'Exam','From'=>'srishti campus','Technology'=>$name,'Subject'=>$subject); $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg );
$headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields)); //curl_setopt( $ch,CURLOPT_POSTFIELDS, json_decode( $fields ) ); $response = curl_exec($ch );
curl_close($ch);
date_default_timezone_set('Asia/Kolkata');
$post = array("payload"=>$msg); $da="select * from technologies where id='$technology'"; $daresult=$con->query($da); $daRow=$daresult->fetch_assoc(); $name=$daRow['name']; $for='for Technology:'.$name.',Subject:'.$subject.''; $date=date('Y-m-d H:i:s');
$notify="insert into app_notifications(title,description,date,type,user_id,read_count) values('New Exam added','$for','$date','a','$user',0)"; $notifyResult=$con_it->query($notify); $notifyResultaffect=$notifyResult->affected_rows;
//echo (json_encode($post)); } }}
}
// echo "success"; header('location:test_question.php?status=failed');
}
} else{ header('location:test_question.php?status=failed'); //echo 'failed'; } } ?>
|