Commit 423753be authored by Adarsh's avatar Adarsh

debug

parent 9056dccb
...@@ -8,21 +8,61 @@ header("Content-Type: application/json; charset=UTF-8"); ...@@ -8,21 +8,61 @@ header("Content-Type: application/json; charset=UTF-8");
include_once("../database.php"); include_once("../database.php");
if($_SERVER['REQUEST_METHOD'] === 'GET'){
$sql1 = "SELECT Now()"; $sql1 = "SELECT Now()";
$currtime = $mysqli->query($sql1); $currtime = $mysqli->query($sql1);
$sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime"; // $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
$sql2 = "SELECT * FROM questions";
$data = []; $data = [];
if($result = mysqli->query($sql2)){ if($result = mysqli->query($sql2)){
while($row = mysql_fetch_assoc($request)){
array_push($data,$row); $i = 0;
while($row = mysql_fetch_assoc($result)){
$data[$i]['title'] = $row['title'];
$data[$i]['username'] = $row['username'];
$data[$i]['statement'] = $row['statement'];
$data[$i]['tc1'] = $row['tc1'];
$data[$i]['out1'] = $row['out1'];
$data[$i]['tc2'] = $row['tc2'];
$data[$i]['out2'] = $row['out2'];
$data[$i]['stime'] = $row['stime'];
$data[$i]['etime'] = $row['etime'];
$i++;
} }
echo json_encode($data); echo json_encode($data);
} }
else{ else{
http_response_code(404); http_response_code(404);
} }
}
// if($_SERVER['REQUEST_METHOD'] === 'GET'){
// $sql1 = "SELECT Now()";
// $currtime = $mysqli->query($sql1);
// $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
// $data = [];
// if($result = mysqli->query($sql2)){
// $i = 0;
// while($row = mysql_fetch_assoc($result)){
// $data[$i]['title'] = $row['title'];
// $data[$i]['username'] = $row['username'];
// $data[$i]['statement'] = $row['statement'];
// $data[$i]['tc1'] = $row['tc1'];
// $data[$i]['out1'] = $row['out1'];
// $data[$i]['tc2'] = $row['tc2'];
// $data[$i]['out2'] = $row['out2'];
// $data[$i]['stime'] = $row['stime'];
// $data[$i]['etime'] = $row['etime'];
// $i++;
// }
// echo json_encode($data);
// }
// else{
// http_response_code(404);
// }
// }
?> ?>
...@@ -15,12 +15,12 @@ if(isset($postData) && !empty($postData)){ ...@@ -15,12 +15,12 @@ if(isset($postData) && !empty($postData)){
$title = trim($request->title); $title = trim($request->title);
$username = trim($request->username); //string $username = trim($request->username); //string
$statement = trim($request->statement); //string $statement = trim($request->statement); //string
$tc1 = trim($request->tc1_inp); $tc1 = trim($request->tc1);
$out1 = trim($request->tc1_out); $out1 = trim($request->out1);
$tc2 = trim($request->tc2_inp); $tc2 = trim($request->tc2);
$out2 = trim($request->tc2_out); $out2 = trim($request->out2);
$stime = trim($request->start_time); //string $stime = trim($request->stime); //string
$etime = trim($request->end_time); $etime = trim($request->etime);
$sql = "INSERT INTO questions(title,username,statement,tc1,out1,tc2,out2,stime,etime) VALUES ('$title','$username','$statement','$tc1','$out1','$tc2','$out2','$stime','$etime')"; $sql = "INSERT INTO questions(title,username,statement,tc1,out1,tc2,out2,stime,etime) VALUES ('$title','$username','$statement','$tc1','$out1','$tc2','$out2','$stime','$etime')";
......
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<input type="text" id="title" placeholder="Problem Title" name="title" [(ngModel)]="questiontoPost.title" required> <input type="text" id="title" placeholder="Problem Title" name="title" [(ngModel)]="questiontoPost.title" required>
<textarea id="statement" placeholder="Problem Statement" name="statement" rows="8" cols="80" [(ngModel)]="questiontoPost.statement" required></textarea> <textarea id="statement" placeholder="Problem Statement" name="statement" rows="8" cols="80" [(ngModel)]="questiontoPost.statement" required></textarea>
<textarea id="tc1_i" cols="30" rows="8" name="tc1" placeholder="Testcase1 Input" style="margin-right: 20px;" [(ngModel)]="questiontoPost.tc1_inp"></textarea> <textarea id="tc1_i" cols="30" rows="8" name="tc1" placeholder="Testcase1 Input" style="margin-right: 20px;" [(ngModel)]="questiontoPost.tc1"></textarea>
<textarea id="tc2_i" cols="30" rows="8" name="tc2" placeholder="Testcase2 Input" style="margin-left: 20px;" [(ngModel)]="questiontoPost.tc2_inp"></textarea> <textarea id="tc2_i" cols="30" rows="8" name="tc2" placeholder="Testcase2 Input" style="margin-left: 20px;" [(ngModel)]="questiontoPost.tc2"></textarea>
<textarea id="tc1_o" cols="30" rows="4" name="out1" placeholder="Testcase1 Output" style="margin-right: 20px;" [(ngModel)]="questiontoPost.tc1_out"></textarea> <textarea id="tc1_o" cols="30" rows="4" name="out1" placeholder="Testcase1 Output" style="margin-right: 20px;" [(ngModel)]="questiontoPost.out1"></textarea>
<textarea id="tc2_o" cols="30" rows="4" name="out2" placeholder="Testcase2 Output" style="margin-left: 20px;" [(ngModel)]="questiontoPost.tc2_out"></textarea> <textarea id="tc2_o" cols="30" rows="4" name="out2" placeholder="Testcase2 Output" style="margin-left: 20px;" [(ngModel)]="questiontoPost.out2"></textarea>
<input type="datetime-local" name="stime" id="start_time" [(ngModel)]="questiontoPost.start_time"> <input type="datetime-local" name="stime" id="start_time" [(ngModel)]="questiontoPost.stime">
<input type="datetime-local" name="etime" id="end_time" [(ngModel)]="questiontoPost.end_time"> <input type="datetime-local" name="etime" id="end_time" [(ngModel)]="questiontoPost.etime">
<button type="submit" class="btn" (click) = "submitForm()">Submit</button> <button type="submit" class="btn" (click) = "submitForm()">Submit</button>
<button type="button" class="btn cancel" (click) ="closeForm()">Close</button> <button type="button" class="btn cancel" (click) ="closeForm()">Close</button>
......
...@@ -19,12 +19,12 @@ export class HomeComponent implements OnInit { ...@@ -19,12 +19,12 @@ export class HomeComponent implements OnInit {
title: "", title: "",
username: "", username: "",
statement: "", statement: "",
tc1_inp: "", tc1: "",
tc1_out: "", out1: "",
tc2_inp: "", tc2: "",
tc2_out: "", out2: "",
start_time: "", stime: "",
end_time: "" etime: ""
}; };
questions: any[]; questions: any[];
...@@ -37,9 +37,9 @@ export class HomeComponent implements OnInit { ...@@ -37,9 +37,9 @@ export class HomeComponent implements OnInit {
this.user = JSON.parse(this.dataService.getToken()); this.user = JSON.parse(this.dataService.getToken());
this.questiontoPost.username = this.user.username; this.questiontoPost.username = this.user.username;
this.getProblems(); this.getProblems();
// this.questionService.getQues()
// .subscribe(questions => this.questions = questions);
this.questionService.getQues()
.subscribe(questions => this.questions = questions);
// console.log(this.questions); // console.log(this.questions);
} }
...@@ -61,18 +61,18 @@ export class HomeComponent implements OnInit { ...@@ -61,18 +61,18 @@ export class HomeComponent implements OnInit {
title: "", title: "",
username: this.user.username, username: this.user.username,
statement: "", statement: "",
tc1_inp: "", tc1: "",
tc1_out: "", out1: "",
tc2_inp: "", tc2: "",
tc2_out: "", out2: "",
start_time: "", stime: "",
end_time: "" etime: ""
}; };
} }
submitForm() { submitForm() {
this.questiontoPost.start_time = this.questiontoPost.start_time.split('T').join(' '); this.questiontoPost.stime = this.questiontoPost.stime.split('T').join(' ');
this.questiontoPost.end_time = this.questiontoPost.end_time.split('T').join(' '); this.questiontoPost.etime = this.questiontoPost.etime.split('T').join(' ');
this.questionService.uploadQues(this.questiontoPost).subscribe( this.questionService.uploadQues(this.questiontoPost).subscribe(
(event: any) => { (event: any) => {
if (typeof (event) === 'object') { if (typeof (event) === 'object') {
......
...@@ -10,13 +10,13 @@ import { Question } from './question'; ...@@ -10,13 +10,13 @@ import { Question } from './question';
export class QuestionService { export class QuestionService {
uploadUrl = "http://localhost/sfcode/backend/questions/question_save.php/"; uploadUrl = "http://localhost/sfcode/backend/questions/question_save.php";
getUrl = "http://localhost/sfcode/backend/questions/get_questions.php/"; getUrl = "http://localhost/sfcode/backend/questions/get_questions.php";
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
uploadQues(ques: Question): Observable<any> { uploadQues(ques: Question): Observable<any> {
console.log(ques); // console.log(ques);
return this.http.post(this.uploadUrl, ques); return this.http.post(this.uploadUrl, ques);
} }
......
...@@ -2,10 +2,10 @@ export interface Question { ...@@ -2,10 +2,10 @@ export interface Question {
title: string; title: string;
username: string; username: string;
statement: string; statement: string;
tc1_inp: string; tc1: string;
tc1_out: string; out1: string;
tc2_inp: string; tc2: string;
tc2_out: string; out2: string;
start_time: string; stime: string;
end_time: string; etime: string;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment