]> Softwares of Agnibho - mcquick.git/blob - mcquick/paper.php
Updated copyright year
[mcquick.git] / mcquick / paper.php
1 <?php
2 /**********************************************************************
3 * Title: MCQuick
4 * Description: Application for creating and solving MCQ papers
5 * Author: Agnibho Mondal
6 * Website: http://code.agnibho.com
7 **********************************************************************
8 Copyright (c) 2014-2015 Agnibho Mondal
9 All rights reserved
10 **********************************************************************
11 This file is part of MCQuick.
12
13 MCQuick is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 MCQuick is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with MCQuick. If not, see <http://www.gnu.org/licenses/>.
25 **********************************************************************/
26 ?>
27 <?php
28 session_start();
29 require_once "lib/php/DB.php";
30 ?>
31 <!DOCTYPE html>
32 <html>
33 <head>
34 <title>Papers | MCQuick</title>
35 <?php include("template/head.php"); ?>
36 </head>
37 <body>
38 <?php include("template/heading.php"); ?>
39 <div class="container">
40 <div class="text-primary">
41 <div class="jumbotron">
42 <h2>MCQuick Question Papers</h2>
43 </div>
44 </div>
45 <form class="form-inline col-sm-offset-4" role="search">
46 <input type="text" class="form-control" placeholder="Search papers" id="text"/>
47 <select class="form-control" id="by">
48 <option value="title">Paper Title</option>
49 <option value="name">Compiled by</option>
50 <option value="subject">Subject</option>
51 </select>
52 <button type="button" class="btn btn-success" id="search">Search</button>
53 </form>
54 <hr>
55 <table class="table table-hover" id="paper_list">
56 <tr><th>Title</th><th>Compiled by</th><th>Subject</th><th>Date</th></tr>
57 </table>
58 <div class="text-center">
59 <ul class="pagination" id="page">
60 </ul>
61 </div>
62 </div>
63
64 <script>
65 var page=1;
66 var search="";
67 var term="";
68 $(document).ready(function(){
69 get_data();
70 $("#search").click(function(){
71 search=$("#by").val();
72 term=$("#text").val().trim();
73 get_data();
74 });
75 $("#paper_list").on("click", "tr.linked", function(){
76 document.location="index.php?paper="+$(this).data("id");
77 });
78 $("#page").on("click", ".nav-page", function(){
79 page=$(this).data("page");
80 get_data();
81 });
82 });
83 function get_data(){
84 query="list="+page;
85 if(term.length>0){
86 switch(search){
87 case "title":
88 query="search=title&term="+term+"&list="+page;
89 break;
90 case "name":
91 query="search=name&term="+term+"&list="+page;
92 break;
93 case "subject":
94 query="search=subject&term="+term+"&list="+page;
95 break;
96 }
97 }
98 $("#block-wait").modal("show");
99 $.get("ajax.php?"+query, function(data, status){
100 $("#block-wait").modal("hide");
101 if(status=="success"){
102 obj=JSON.parse(data);
103 papers=obj[0];
104 num=obj[1];
105 $("#paper_list").html('<tr><th>Paper Title</th><th>Compiled by</th><th>Subject</th><th>Date</th></tr>');
106 for(i=0; i<papers.length; i++){
107 date=new Date(0);
108 date.setSeconds(papers[i]['time']);
109 $("#paper_list").append("<tr class='linked' data-id='"+papers[i]['id']+"' style='cursor:pointer'><td>"+esc(papers[i]['title'])+"</th><td>"+papers[i]['user']+"</td><td>"+esc(papers[i]['subject'])+"</td><td>"+date.toLocaleDateString()+"</td></a></tr>");
110 }
111 $("#page").html("");
112 for(i=1; i<=num/10+1; i++){
113 if(i==page){
114 $("#page").append('<li class="active"><a href="#" class="nav-page" data-page="'+i+'">'+i+'</a></li>');
115 }
116 else{
117 $("#page").append('<li><a href="#" class="nav-page" data-page="'+i+'">'+i+'</a></li>');
118 }
119 }
120 }
121 else{
122 $("#connect-fail").modal("show");
123 }
124 });
125 }
126
127 function esc(input){
128 return $("<div/>").text(input).html();
129 }
130 </script>
131 <hr>
132 <?php
133 include("template/modals.php");
134 include("template/footer.php");
135 ?>
136 </div>
137 </body>
138 </html>
139