aces /usr_chk1.php

Language PHP Lines 440
MD5 Hash 0c630905189239c5bb5fba41d180645b Estimated Cost $5,906 (why?)
Repository https://bitbucket.org/krishna2793/aces.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once ('Auth_stu.php');
session_start();
$auth = new Auth_stu();
if (!isset($_SESSION['user_id'])) 
{
	//Not logged in, send to login page.
	header( 'Location: login.php' );
}
else 
{
	//Check we have the right user
	$logged_in = $auth->checkSession();
	
	if(empty($logged_in)){
		//Bad session, ask to login
		$auth->logout();
		header( 'Location: login.php' );
}
else
{
		//User is logged in, show the page
?>

<!DOCTYPE html>
<html>
  <head>
    <title>ACES : HOME</title>
    <!-- Include the bootstrap stylesheets -->
    <link rel="stylesheet" href="bootstrapnew.css"/>
  
 
        </head>
  <body>
  
  <!-- Navbar
    ================================================== -->
 <div class="navbar navbar-fixed-top">
   <div class="navbar-inner">
     <div class="container">
       <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
       </a>
       <a class="brand" href="http://www.amrita.edu/">AMRITA</a>
       <div class="nav-collapse" id="main-menu">
        <ul class="drop" id="main-menu-left">
          <li><a onclick="pageTracker._link(this.href); return false;" href="http://news.bootswatch.com">News</a></li>
          <li><a id="swatch-link" href="/stu_score.php">Scores</a></li>
          <li class="dropdown" id="test-menu">
             <a class="dropdown-toggle" data-toggle="" href="#">Test Offered <b class="caret"></b></a>
             <ul id="take_test" class="dropdown-toggle" >
              <li><a  href="/stu_test.php">Test Code</a></li>
              <li><a  href="/student_mcq.php">MCQs</a></li>
              <li><a  href="/stu_test.php">Test Query</a></li>
                       
              </ul>
            </li>  
              
            </ul>
          </li>
        
        </ul>
        <ul class="nav pull-right" id="main-menu-right">
          <Li>  <form class="navbar-search pull-left">
          
            <input type="text" class="search-query span2" placeholder="Search">
          </form></Li>
          <li><a rel="tooltip" href="#"><?php echo date("d.m.Y") ;?> <i class="icon-share-alt"></i></a></li>
          <li><a rel="tooltip" href="#">Welcome <?php echo $_POST['login']; ?> <i class="icon-share-alt"></i></a></li>
          
           <li><a rel="tooltip" href="/logout.php">Logout <i class="icon-share-alt"></i></a></li>
        </ul>
       </div>
     </div>
   </div>
 </div>

    <div class="container">
    <div class="container">
      <p>         </p>
      <h1 style="font-size:46px" align="center"  >&nbsp;</h1>
      <h1 style="font-size:46px" align="center"  >&nbsp;</h1>
      <h1 style="font-size:46px" align="center"  >ACES</h1>
      <h4 align="center"> Automated Code Evaluation System</h4>
      <p></p>
      <h6 align="left">AMRITA SCHOOL OF ENGINEERING</h6>
      <h6 align="left" >COIMBATORE <small></h6>
    <!-- Forms
================================================== -->
<section id="forms">
  <div class="page-header">
    <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </h1>
  </div>

  <div class="row">
    <div class="span10 offset1">
      <form class="form-horizontal well" action="response.php" method="post" enctype="multipart/form-data">
        <fieldset>
          <legend> Student Home </legend>
           
</fieldset>
      <h2> Query Submitted  </h2>
       <?php     if(($_SESSION['iter']+1)<$_SESSION['no_of_ques'])
{
echo '
<input type="submit" class="btn btn-primary" name="next" value="Next" />';
}?>
    <p><a href = "/query_score.php">See Scores</a></p>
      </form>
    </div>
  </div>

</section>
   <!-- Footer
      ================================================== -->
      <hr>

  <footer id="footer">
        <p class="pull-right"><a href="#">Back to top</a></p>
    <div class="links"></div>
        Made by <a href="http://www.amrita.edu">Amrita</a>. Contact him <a href="mailto:amrita.edu">hello@admin_asec</a>.<br/>
    Based on <a target="_blank" href="http://twitter.github.com/bootstrap/">Bootstrap</a>. Icons from <a target="_blank" href="http://glyphicons.com/">Glyphicons</a>. Web fonts from <a target="_blank" href="http://www.google.com/webfonts">Google</a>.</p>
    </footer>
  </body>
</html>




<?php 


 
//echo 'Success... ' . $mysqli->host_info . "<br />";
//echo 'Retrieving dumpfile' . "<br />";
//echo "...............".$_SESSION['TRY'];
//echo "......<br>";
$prob_id = $_SESSION['ARR'][$_SESSION['iter']];
echo $_SESSION['iter'].':----------------------:'.$prob_id;
$con = mysql_connect('localhost','root','mysql');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("aces", $con) or die('db con faild');

$qry =mysql_query("SHOW TABLES;");
//echo "<br /> all tables deleted <br />";

$ty = mysql_query("select answer from problem_pool where pid = '$prob_id'");
//echo mysql_result($ty,0);
//echo '<br>';

$q_op = mysql_query("select * from problem_pool where pid='$prob_id'") or die(':('.mysql_error());
//echo 'prob_pool query done:)';
//echo 'here....';
$username = $_SESSION['name'];
mysql_query("drop database if exists $username;");
mysql_query("create database $username;") or die('database creation failed!!');

mysql_select_db("$username",$con) or die('db con failure!!');
 
//echo 'Success... ' . $mysqli->host_info . "<br />";
//echo 'Retrieving dumpfile' . "<br />";
//echo "...............".$_SESSION['TRY'];
//echo "......<br>";
//$prob_id = $_SESSION['TRY'];
//$con = mysql_connect('localhost','root','kolam16f');
//if (!$con)
  {
  //die('Could not connect: ' . mysql_error());
  }



$mysqli = new mysqli('127.0.0.1', 'root', 'mysql', $username);
 
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}
if(mysql_num_rows($q_op) == 1)
{
$info = mysql_fetch_array($q_op);


$testquery =file_get_contents($info['answer']);
echo $testquery;
/*echo '<br>';
echo ":)".$info['url'].":( :(";
echo  '<br>';*/
}
//echo $testquery;
$sql = file_get_contents($info['url']);
if (!$sql){
	die ('Error opening file');
}


//echo '<br>'.$sql.'<br>';
mysqli_multi_query($mysqli,$sql) or die('wrong');
$t3  = str_replace("("," ",$testquery);
$chars = preg_split('/ /',$t3,-1,PREG_SPLIT_OFFSET_CAPTURE);
//echo '<br>';
//print_r($chars);
//echo '<br>';
mysql_query("start transaction;") or die('transaction failed!!');
mysql_query("savepoint t;") or die('savepoint failed!!');
if($chars[0][0]=='update')
{
$data = $chars[1][0];
$u1 = mysql_query($testquery);
$testquery = "select * from $data;";
//echo 'inside update';
}
else if($chars[0][0]=='insert'||$chars[0][0]=='delete')
{
$data = $chars[2][0];
//echo '.........inside insert';
$u1 = mysql_query($testquery);
$testquery = "select * from $data;";
}
//echo $testquery;

if($chars[0][0] == 'create')
{
//echo 'inside else';
$data = $chars[2][0];
$u1 = mysql_query($testquery);
$testquery = "describe $data";
//echo $testquery;
}
//echo $chars[0][0];
//echo $chars[1][0];
//echo 'nothing here____';
if($chars[0][0] == 'alter')
{
//echo 'i am here!!!___';
$temptab = 'temp';
$table = $chars[2][0]; 
$query = "create table $temptab as select * from $table ";
mysql_query($query);// or die(mysql_error());
$testquery = str_replace($chars[2][0],$temptab,$testquery);
$u1 = mysql_query($testquery) or die(mysql_error());
$testquery = "describe $temptab";
}
//echo $testquery;
$t2=mysql_query($testquery) or die('test query failed!!'.mysql_error());

$num1 = mysql_num_rows($t2);
//echo $num1;
$i=0;
while($info2 = mysql_fetch_array($t2))
{
$j=0;
$t_a[$i] = $info2;
//print_r($t_a[$i]);
//echo '<br>';
$i++;
}

if($chars[0][0]=='create')
{
$table= $chars[2][0];
$dropquery = "drop table $table";
mysql_query($dropquery) or die('drop query failed!!'.mysql_error());
}
else if($chars[0][0]=='alter')
{
$dropquery = "drop table $temptab";
mysql_query($dropquery) or die('drop query failed alter!!'.mysql_error());
//echo 'in place!!_______________';
}

else
{
mysql_query("rollback to savepoint t;") or die('roll back failed!!');
mysql_query("release savepoint t;") or die('release failed!!');

}

$flags=0;
mysql_query("start transaction;") or die('transaction failed!!');
mysql_query("savepoint t;") or die('savepoint failed!!');
$userquery = $_POST['ques'];
echo $userquery.'___';
//echo $userquery;
$u3  = str_replace("("," ",$userquery);
$uchars = preg_split('/ /',$u3,-1,PREG_SPLIT_OFFSET_CAPTURE);
//if($uchars[0][0]!='create'&&$uchars[0][0]!='alter'&&$uchars[0][0]!='drop')
//{
//if($uchars[0][0]!='select')
if($uchars[0][0]=='update')
{
$data = $uchars[1][0];
$u1=mysql_query($userquery);// or die('user query failed!!');
if(!$u1)
{
$flags = 1;
}
$userquery = "select * from $data;";
//echo 'inside update';
}
else if($uchars[0][0]=='insert'||$uchars[0][0]=='delete')
{
$data = $chars[2][0];
$u1=mysql_query($userquery);// or die('user query failed!!');
if(!$u1)
{
$flags = 1;
}
$userquery = "select * from $data;";
//echo 'inside insert';
}
//echo $selectquery;
if($uchars[0][0] == 'create')
{
//echo 'inside else';
$data = $chars[2][0];
$u1=mysql_query($userquery);// or die('user query failed!!');
if(!$u1)
{
$flags = 1;
}
$userquery = "describe $data";
//echo $testquery;
}
if($uchars[0][0] == 'alter')
{
$temptab = 'temp';
$table = $chars[2][0]; 
$query = "create table $temptab as select * from $table ";
mysql_query($query) or die(mysql_error());
$userquery = str_replace($chars[2][0],$temptab,$userquery);
$u1 = mysql_query($userquery);// or die(mysql_error());

if(!$u1)
{
$flags = 1;
}
$userquery = "describe $temptab";
}
//echo $userquery;
$t2=mysql_query($userquery); //or die('select query failed!!');
if(!$t2)
{
$flags = 1;
}
$num2 = mysql_num_rows($t2);
//echo $num2;
$j=0;
while($uinfo2 = mysql_fetch_array($t2))
{

$u_a[$j] = $uinfo2;
//print_r($u_a[$j]);
//echo '<br>';
$j++;
}
$flag=0;
$y=0;
while($y<$num1)
{

$v = array_diff($u_a[$y],$t_a[$y]);
$v1 = array_diff($t_a[$y],$u_a[$y]);
//print_r($v);
if(!(empty($v))||!(empty($v1)))
{
$flag=1;
break;
}
$y++;
}
$result = 0;
if($flag==0&&$flags!=1)
{
$result++;
}
echo $result;


if($uchars[0][0]=='create')
{
$table= $chars[2][0];
$dropquery = "drop table $table";
mysql_query($dropquery) or die('drop query failed!!'.mysql_error());
}
else if($uchars[0][0]=='alter')
{
$dropquery = "drop table $temptab";
mysql_query($dropquery) or die('drop query failed alter!!'.mysql_error());
}

else
{
mysql_query("rollback to savepoint t;") or die('roll back failed!!');
mysql_query("release savepoint t;") or die('release failed!!');

}


mysql_select_db("aces", $con) or die('db con faild');
mysql_query("use aces")or die('here it is!!');
$temp_iter=$_SESSION['ARR'][$_SESSION['iter']];
echo "====".$_SESSION['ARR'][$_SESSION['iter']]."====".$_SESSION['user_id']."====".$_SESSION['test_id']."====";
	mysql_query("insert into each_query_score(stu_id,test_id,prob_id,score) values ('$_SESSION[user_id]','$_SESSION[test_id]','$temp_iter','$result')") or die('aaaa'.mysql_error());
echo 'crossed insert!!!!!!!!!';
		//store score in user_gradebook_coding
	if(($_SESSION['iter']+1)==$_SESSION['no_of_ques'])
	{
		
$scores_fetch=mysql_query("select score from each_query_score where test_id='$_SESSION[test_id]' and stu_id='$_SESSION[user_id]'");
$score_avg=0;
while($score = mysql_fetch_array ($scores_fetch))
{
	$score_avg += $score['score'];
}

$score_avg = $score_avg/$_SESSION['no_of_ques'];
$score_avg *=100;

mysql_query("update user_gradebook_Query set score_percentage=$score_avg where test_id='$_SESSION[test_id]' and stu_id='$_SESSION[user_id]' ");		
	}
	


mysql_query("drop database $username") or die(mysql_error());
$mysqli->close();
?>
<?php
}
}
?>
Back to Top