Advertisement
Guest User

check

a guest
Mar 21st, 2012
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.16 KB | None | 0 0
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 5                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) Oyesanmi Oyedotun                                      |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 2.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available through the world-wide-web at                              |
  10. // | http://www.php.net/license/2_02.txt.                                 |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Oyesanmi Oyedotun <email dotunoyesanmi@gmail.com >          |
  16. // +----------------------------------------------------------------------+
  17. ?>
  18. <?php session_start();
  19.  if(!$_SESSION['logged_username']) {
  20.  header('Location: http://127.0.0.1:8080/result/index.php');} ?>  
  21. <?php require('includes/dbconnect.php'); ?>
  22. <?php require 'includes/header.inc.php'; ?>
  23.  
  24. <?php  
  25.  
  26.             if (isset($_POST['submit'])) {
  27.                                         //variable input sanitization
  28.      
  29.         $matric_no = mysql_real_escape_string($_POST['matric_no']) ;
  30.         $session = mysql_real_escape_string($_POST['session']) ;
  31.         $semester_name = mysql_real_escape_string($_POST['semester_name']) ;
  32.         $level = mysql_real_escape_string($_POST['level']) ;
  33.        
  34.         if (($_POST['matric_no'] == "") || ( $_POST['session'] == "")  ||
  35.           ($_POST['semester_name'] == "" ) || ($_POST['level'] == "" )) {
  36.              
  37.         echo "<div id=\"contentRight\">";
  38.         echo"<id id=\"msg\">" ;
  39.         echo "One of the form entry is empty.";
  40.         echo"</div>" ;
  41.        
  42.         }
  43.         else
  44.        
  45.         {
  46.                    
  47. //query to find if a combination of the user inputs are already in tthe database
  48.    $query1 = "SELECT maintable.matric_no, maintable.session, maintable.semester_name, maintable.level
  49.                  
  50.                  FROM maintable
  51.                  
  52.                  WHERE maintable.matric_no = '$matric_no'
  53.                  AND   maintable.session   = '$session'
  54.                  AND   maintable.semester_name = '$semester_name'
  55.                  AND   maintable.level = '$level'";
  56.                  
  57.                  
  58.         $result1 = mysql_query($query1) ;
  59.         $duplicates1 = mysql_num_rows($result1);
  60.         if ($duplicates1 < 1)
  61.        
  62. {
  63.     echo"<div id=\"contentRight\">";
  64.     echo"<div id=\"msg\">" ;
  65.     echo "You dont have a record for <span style=\"color:red\">$matric_no</span>" ;
  66.     echo"</div>" ;
  67.     echo"</div>" ;
  68. }
  69. //a seperate query from the main query to obtain name of the student
  70. //since it was iterating with the same information, from the query below.
  71.  
  72.      $query2 = mysql_query("SELECT first_name, last_name
  73.                            FROM students
  74.                            WHERE matric_no = '".$matric_no."' ");
  75.                             ($row2 = mysql_fetch_array($query2));
  76.                            
  77. //This query is used to obtain the Total Number of Course_units taken                      
  78. //in a semester
  79.      $query3 = mysql_query("SELECT  SUM(c.course_unit) AS 'TOTAL'
  80.                          FROM    maintable AS m  
  81.                          INNER JOIN students AS s ON
  82.                                  m.matric_no = s.matric_no
  83.                          INNER JOIN courses AS c ON
  84.                                  m.course_code = c.course_code
  85.                          WHERE m.matric_no = '".$matric_no."'
  86.                          AND m.level = '".$level."'") or die (mysql_error());
  87.                          
  88. //this query is used to obtain columns to calculate the cgpa                    
  89.      $query4 = mysql_query("SELECT  c.course_unit, m.score
  90.                          FROM    maintable AS m  
  91.                          INNER JOIN students AS s ON
  92.                                  m.matric_no = s.matric_no
  93.                          INNER JOIN courses AS c ON
  94.                                  m.course_code = c.course_code
  95.                          WHERE m.matric_no = '".$matric_no."'
  96.                          AND m.level = '".$level."'") or die (mysql_error());
  97.                          
  98. //this query is used to obtain columns to calculate the cgpa                    
  99.      $query5 = mysql_query("SELECT  c.course_unit, m.score
  100.                          FROM    maintable AS m  
  101.                          INNER JOIN students AS s ON
  102.                                  m.matric_no = s.matric_no
  103.                          INNER JOIN courses AS c ON
  104.                                  m.course_code = c.course_code
  105.                          WHERE m.matric_no = '".$matric_no."'") or die (mysql_error());
  106.                            
  107.                          
  108. //This query is used to obtain the Cummulative Number of Coures_units
  109. //ever taken by the student
  110.       $query6 = mysql_query("SELECT  SUM(c.course_unit) AS 'TOTAL'
  111.                          FROM    maintable AS m  
  112.                          INNER JOIN students AS s ON
  113.                                  m.matric_no = s.matric_no
  114.                          INNER JOIN courses AS c ON
  115.                                  m.course_code = c.course_code
  116.                          WHERE m.matric_no = '".$matric_no."'") or die (mysql_error());    
  117.                    
  118.        
  119.  //This query takes columns from 3 tables, and the column c.course_unit, takes values from
  120.  //the courses table
  121.  $query7 = mysql_query("SELECT  m.course_code AS 'Course Code', c.course_title AS 'Course Title', c.course_unit AS 'Unit', m.score AS 'Score', m.grade AS 'Grade'
  122.                          FROM    maintable AS m  
  123.                          INNER JOIN students AS s ON
  124.                                  m.matric_no = s.matric_no
  125.                          INNER JOIN courses AS c ON
  126.                                  m.course_code = c.course_code
  127.                          WHERE m.matric_no = '".$matric_no."'
  128.                          AND m.level = '".$level."'") or die (mysql_error());
  129.     $number_cols = mysql_num_fields($query7);
  130.    
  131.  //Query8 is used to determine the coureses that have a grade of "F".
  132.  //It SELECT score and course_code values from the database for the required course taken by the student, in th
  133.  $query8 = mysql_query("SELECT  m.score, m.course_code
  134.                          FROM    maintable AS m  
  135.                          INNER JOIN students AS s ON
  136.                                  m.matric_no = s.matric_no
  137.                          INNER JOIN courses AS c ON
  138.                                  m.course_code = c.course_code
  139.                          WHERE m.matric_no = '".$matric_no."'
  140.                          AND m.score >= 0 AND m.score < 40 ") or die (mysql_error());
  141.  //Query9 is used to determine the coureses that have a grade of "AR".
  142.  //It SELECT score and course_code values from the database for the required course taken by the student, in th
  143.  $query9 = mysql_query("SELECT  m.grade, m.course_code
  144.                          FROM    maintable AS m  
  145.                          INNER JOIN students AS s ON
  146.                                  m.matric_no = s.matric_no
  147.                          INNER JOIN courses AS c ON
  148.                                  m.course_code = c.course_code
  149.                          WHERE m.matric_no = '".$matric_no."'
  150.                          AND m.grade = 'AR'") or die (mysql_error());
  151.          
  152.                          
  153.               echo "<div id=\"contentRight\">" ;
  154.               echo "<span class=\"header\">";
  155.               echo "<p><b>Matric Number: $matric_no"." -- ". " ";
  156.               echo "<b>First Name: ".$row2['first_name'].""." -- ". " ";
  157.               echo "<b>Last Name: ".$row2['last_name']."</p>";
  158.               echo "<p><b>Session: $session"." -- ". " ";
  159.               echo "<b>Semester: $semester_name"." -- ". " ";  
  160.               echo "<b>Level: $level</b></p>";
  161.              
  162.               echo "<table border = \"1\"  cellspacing = \"1\"  cellpadding = \"4\"  bgcolor = red >\n";
  163.               echo "<tr align= \"center\">\n";
  164.               $carry_over = array();
  165.               $score_count = mysql_numrows($query8);echo "<th>"."Failed Courses";
  166.               if($score_count !== 0){
  167.               while ($row8 = mysql_fetch_assoc ($query8)) {
  168.               echo"<td>". $row8['course_code']."</td>\n";
  169.                 }
  170.               }        
  171.                 echo "</tr>\n";
  172.                 echo "</table>";
  173.                
  174.                
  175.             echo "<table border = \"1\"  cellspacing = \"1\"  cellpadding = \"1\"  bgcolor = red >\n";
  176.             echo "<tr align= \"center\">\n";
  177.             $awaiting_result = array();
  178.             $awaiting_result = mysql_numrows($query9);echo "<th>"."Awaiting Results";
  179.             if($awaiting_result !== 0){
  180.             while ($row9 = mysql_fetch_assoc ($query9)) {
  181.             echo"<td>". $row9['course_code']."</td>\n";
  182.               }
  183.             }
  184.             echo "</tr>\n";
  185.             echo "</table>";
  186.                
  187.                
  188.                      //This displays the rows from the query into an html table.
  189.                   echo "<table border = \"1\"  cellspacing = \"1\"  cellpadding = \"1\"  bgcolor = lemonchiffon >\n";
  190.                   echo "<tr align= \"center\">\n";
  191.                                                    
  192.                    echo "<th>";     //this echo out
  193.                    echo"s/n";        //the serial number
  194.                    echo "</th>\n";  //heading for the table  
  195.                              
  196.                                                                    
  197.                    
  198.                         for ($i=0; $i<$number_cols; $i++) {              
  199.                                                                                                        
  200.                   echo "<th>" . mysql_field_name($query7, $i). "</th>\n";
  201.                      
  202.                          
  203.     }             $serial = 0;                                                                                                            
  204.                   while ($row = mysql_fetch_row($query7)) {    
  205.                   $serial++;
  206.                   echo "<tr align=center>\n";
  207.                   echo"<td>";  
  208.                   echo $serial;  
  209.                   echo"</td>\n";  
  210.                                  
  211.                      foreach ($row as $value)  
  212.                      {    
  213.                         echo "<td>$value</td>\n";
  214.                      }      
  215.                          while ($row8 = mysql_fetch_assoc($query8)) {
  216.                          
  217.                              if ( $grade == 'AR' )
  218.                                     {
  219.                                     continue;
  220.                                     }
  221.                 if ($row8['score'] >= 70) {
  222.                   $grade = 'A';  
  223.                }
  224.                 elseif ( $row8['score'] >= 60 AND $row8['score'] < 70 ) {
  225.                 $grade = 'B';
  226.                 }elseif ($row8['score'] >= 50  AND $row8['score'] < 60) {
  227.                 $grade = 'C';
  228.                 }elseif ($row8['score'] >= 45  AND $row8['score'] < 50) {
  229.                 $grade = 'D';
  230.                 }elseif($row8['score'] >= 40  AND $row8['score'] < 45) {
  231.                 $grade = 'E';
  232.                 }elseif($row8['score'] >= 0  AND $row8['score'] < 40) {
  233.                 $grade = 'F';
  234.                 }else{
  235.                 $grade = 'AR';  
  236.                 }  
  237.                          }  
  238.                   }        
  239.                          
  240.                      
  241.                        
  242.                    
  243.                  
  244.                  $query11 = mysql_query("UPDATE maintable
  245.                            SET grade = CASE
  246.                            WHEN score >= 70 THEN 'A'
  247.                            WHEN score >= 60 AND score < 70 THEN 'B'
  248.                            WHEN score >= 50 AND score < 60 THEN 'C'
  249.                            WHEN score >= 45 AND score < 50 THEN 'D'
  250.                            WHEN score >= 40 AND score < 45 THEN 'E'
  251.                            WHEN score >=  0 AND score < 40 THEN 'F'
  252.                            ELSE 'AR'
  253.                            END;") or die(mysql_error());
  254.                      
  255.                 for ($i=0; $i<$number_cols; $i++) {  
  256.                 echo "</tr>\n";
  257.                 echo "</table>";
  258.                 }  
  259.                  while ($row3 = mysql_fetch_row($query3))
  260.                    {    
  261.                      
  262.                     foreach ($row3 as $value3)  
  263.                      {  
  264.                         echo "<td>Present TNU: $value3</td>\n";
  265.                      }      
  266.                          
  267.                    }
  268.                    
  269.                      
  270.                    
  271.                    while ($row6 = mysql_fetch_row($query6))
  272.                    {    
  273.                
  274.                     foreach ($row6 as $value6)  
  275.                      {  
  276.                         echo "<td>Cummulative TNU: $value6</td><br/>\n";
  277.                      }      
  278.                          
  279.                    }
  280.                    
  281.                    
  282.                     $grade_point = 0;
  283.                      while ($row4 = mysql_fetch_assoc($query4)) {  
  284.                 if ($row4['score'] >= 70) {
  285.                   $score = 5;
  286.                }
  287.                 elseif ($row4['score'] >= 60) {
  288.                 $score = 4;
  289.                 }elseif ($row4['score'] >= 50) {
  290.                 $score = 3;
  291.                 }elseif ($row4['score'] >= 45) {
  292.                 $score = 2;
  293.                 }elseif($row4['score'] >= 40) {
  294.                 $score = 1;
  295.                 }else{
  296.                 $score = 0;
  297.                 }  
  298.                 $grade_point += $score * $row4['course_unit'];
  299.                
  300.                 }
  301.                 echo "Present TCP : $grade_point ";
  302.                
  303.                 $grade_point1 = 0;
  304.                      while ($row5 = mysql_fetch_assoc($query5)) {
  305.                 if ($row5['score'] >= 70) {
  306.                   $score = 5;
  307.                }
  308.                 elseif ($row5['score'] >= 60) {
  309.                 $score = 4;
  310.                 }elseif ($row5['score'] >= 50) {
  311.                 $score = 3;
  312.                 }elseif ($row5['score'] >= 45) {
  313.                 $score = 2;
  314.                 }elseif($row5['score'] >= 40) {
  315.                 $score = 1;
  316.                 }else{
  317.                 $score = 0;
  318.                 }
  319.                 $grade_point1 += $score * $row5['course_unit'];
  320.                
  321.                 }
  322.                 echo "Cummulative TCP : $grade_point1 <br/>";
  323.                
  324.                 $present_gpa = sprintf("%.2f", ( $grade_point / $value3)) ;  
  325.                 $cummulative_gpa = sprintf("%.2f", ( $grade_point1 / $value6)) ;  
  326.                  
  327.                  
  328.                 echo "Present GPA : $present_gpa ";
  329.                 echo "Cummulative GPA : $cummulative_gpa ";
  330.                 echo"</span>" ;                              
  331.                 echo"</div>";
  332.                 echo"</div>";
  333.                 require 'includes/footer.php';  
  334.                 exit();
  335.             }  
  336.             }            
  337.  ?>              
  338.     <div id="contentRight">
  339.      <p>
  340.        <span class="header">Update Student Bio Data</span>
  341.        
  342.         Enter the appropriate options below
  343.         <form action="check_result.php" method="post">
  344.         <ul>
  345.         <li>Matric Number: &nbsp;<input type="text" name="matric_no"> </li><br />
  346.         <li>Session:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<select name="session">
  347.                         <option value ="">    </option>
  348.                         <option value ="2011/2012">2011/2012</option>
  349.                         <option value ="2012/2013">2012/2013</option>
  350.                         <option value ="2013/2014">2013/2014</option>
  351.                         <option value ="2014/2015">2014/2015</option>
  352.                         <option value ="2015/2016">2015/2016</option>
  353.                         <option value ="2016/2017">2016/2017</option>
  354.                         <option value ="2017/2018">2017/2018</option>
  355.                         <option value ="2018/2019">2018/2019</option>
  356.                         <option value ="2019/2020">2019/2020</option>
  357.                         <option value ="2020/2021">2020/2021</option>
  358.                         <option value ="2021/2022">2014/2015</option>
  359.                         <option value ="2022/2023">2015/2016</option>
  360.                         <option value ="2023/2024">2016/2017</option>
  361.                         <option value ="2024/2025">2017/2018</option>
  362.                         <option value ="2025/2026">2018/2019</option>
  363.                         <option value ="2026/2027">2019/2020</option>
  364.                         <option value ="2027/2028">2020/2021</option>
  365.                  </select></li> <br />
  366.        
  367.          <li>Semester:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php
  368.                                    $result = mysql_query("SELECT *
  369.                                   FROM semester") or die(mysql_error());
  370.                                    echo'<select name = "semester_name">';
  371.                                    echo'<option value ="">    </option>';
  372.                                    while($row = mysql_fetch_array($result)){                                            
  373.                                    echo '<option value="'.$row['semester_name'].'">'.$row['semester_name'].'</option>';}
  374.                                    echo '</select>' ; ?></li><br />
  375.        
  376.         <li>Level:&nbsp;&nbsp;&nbsp;
  377.                   &nbsp;&nbsp;&nbsp;
  378.                   &nbsp;&nbsp;&nbsp;
  379.                   &nbsp;
  380.                                     <?php
  381.                                    $result1 = mysql_query("SELECT *
  382.                                   FROM year") or die(mysql_error());
  383.                                    echo'<select name = "level">';
  384.                                    echo'<option value ="">    </option>';
  385.                                    while($row1 = mysql_fetch_array($result1)){                                            
  386.                                    echo '<option value="'.$row1['level'].'">'.$row1['level'].'</option>';}
  387.                                    echo '</select>' ; ?> </li><br />              
  388.        
  389.                   <input type="submit" name="submit" value="Check Result" />
  390.                        
  391.                   <input type="hidden" name="submitted" value="TRUE" />
  392.              
  393.                   <input name="Reset" type="reset" value="Reset" />
  394.        
  395.       </ul>
  396.        
  397.      
  398.  
  399.     </div>
  400.  
  401.   </div>
  402.   </div>
  403.   </form>
  404.  
  405. <?php require 'includes/footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement