Advertisement
m4ly

labbd_php

Jan 18th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.23 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8.     <head>
  9.         <title>TODO supply a title</title>
  10.         <meta charset="UTF-8">
  11.         <meta name="viewport" content="width=device-width">
  12.         <style type="text/css">
  13.             table, th, tr, td {
  14.                 border: 1px solid black;
  15.                 border-collapse: collapse;                
  16.  
  17.             }
  18.             .odd { background-color: #6CCF6C; }
  19.         </style>
  20.     </head>
  21.     <body>
  22.  
  23.         <table border="1" ruler="all">    
  24.             <?php
  25.             $Host = '127.0.0.1';
  26.             $DBase = 'oswiata';
  27.             $FUser = 'root';
  28.             $FPass = '';
  29.  
  30.             function polacz($host, $dbase, $user, $pass) {
  31.                 @$pol = mysql_connect($host, $user, $pass);
  32.                 if (!$pol) {
  33.                     echo 'Bład polaczenia z Serwerem Bazy Danych';
  34.                     exit();
  35.                 } else {
  36.                     @mysql_select_db($dbase);
  37.                     if (mysql_errno()) {
  38.                         echo mysql_errno() . ': ' . mysql_errno();
  39.                         echo mysql_error();
  40.                         exit();
  41.                     }
  42.                 }
  43.                 return $pol;
  44.             }
  45.  
  46.             $idpol = polacz($Host, $DBase, $FUser, $FPass);
  47.  
  48.             @$wyniki = mysql_db_query($DBase, "SELECT * FROM studenci", $idpol);
  49.  
  50.  
  51.             if ($wyniki) {
  52.                 echo "<Table style=\"float:left\">";
  53.                 echo "<thead><tr>
  54.                    <th> id </th>
  55.                    <th>nazwisko</th>
  56.                    <th>data</th>
  57.                    <th>plec</th>
  58.                    <th>nr przedm</th>
  59.                   </tr>
  60.                   </thead>
  61.                   <tbody>";
  62.                 $i = 0;
  63.                 while ($wiersz = mysql_fetch_row($wyniki)) {
  64.                     if ($i % 2 == 0) {
  65.                         echo"<tr class=\"odd\">";
  66.                     } else {
  67.                         echo "<tr class=\"even\">";
  68.                     }
  69.                     $i++;
  70.                     echo"<td>";
  71.                     //echo $wiersz[0];    
  72.                     echo '<a href="?pokaz_stud=' . $wiersz[0] . '">' . $wiersz[0] . '</a>';
  73.                     echo"</td>";
  74.  
  75.                     echo"<td>";
  76.                     echo $wiersz[1];
  77.                     echo"</td>";
  78.  
  79.                     echo"<td>";
  80.                     echo $wiersz[2];
  81.                     echo"</td>";
  82.  
  83.                     echo"<td>";
  84.                     echo $wiersz[3];
  85.                     echo"</td>";
  86.  
  87.                     echo"<td>";
  88.                     echo $wiersz[4];
  89.                     echo"</td>";
  90.  
  91.                     echo"</tr>";
  92.                 }
  93.                 echo "</tbody></Table>";
  94.             } else
  95.                 echo "Brak";
  96.  
  97.             if (isset($_GET["pokaz_stud"])) {
  98.                 $idf_nr_stud = $_GET["pokaz_stud"];
  99.                 @$wyniki = mysql_db_query($DBase, "SELECT ocena,nr_stud, nr_przedm, data_zal  FROM oceny WHERE nr_stud =  $idf_nr_stud", $idpol);
  100.                 if ($wyniki) {
  101.                     echo "<Table style=\"float:left; margin-left: 20px;\">";
  102.  
  103.                     while ($wiersz = mysql_fetch_row($wyniki)) {
  104.  
  105.                         echo "<tr><td>" . "\n";
  106.                         echo '<form method="POST" action="?">';
  107.                         echo '<input type="text" name="stara_ocena" value="' . $wiersz[0] . '" />' . "\n";
  108.  
  109.                         echo '<input type="hidden" name="nr_stud" value="' . $wiersz[1] . '" />' . "\n";
  110.                         echo '<input type="hidden" name="nr_przedm" value="' . $wiersz[2] . '" />' . "\n";
  111.                         echo '<input type="hidden" name="data_zal" value="' . $wiersz[3] . '" />' . "\n";
  112.  
  113.                         echo '<input type="submit" name="akcja" value="zmien" />' . "\n";
  114.                         echo '<input type="submit" name="akcja" value="usun" />' . "<br />\n";
  115.  
  116.                         echo '<input type="text" name="_nowa_ocena"  />' . "\n";
  117.                         echo '<input type="submit" name="akcja" value="dodaj" />' . "\n";
  118.  
  119.                         echo '</form>' . "\n";
  120.                         echo"</td></tr>" . "\n";
  121.                     }
  122.                     echo "</Table>";
  123.                 }
  124.             }
  125.  
  126.             if (isset($_REQUEST['akcja'])) {
  127.                 $akcja = $_REQUEST['akcja'];
  128.  
  129.                 if ($akcja == "zmien") {
  130.  
  131.                     $nr_stud = $_REQUEST['nr_stud'];
  132.                     $nr_przedm = $_REQUEST['nr_przedm'];
  133.                     $stara_data = $_REQUEST['data_zal'];
  134.                     $data_zal = date('Y-m-d H:m:s');
  135.                     $nowa_ocena = $_REQUEST['stara_ocena'];
  136.  
  137.                     @mysql_db_query($DBase, "UPDATE oceny SET ocena = $nowa_ocena, data_zal = \"$data_zal\" WHERE nr_stud = $nr_stud and nr_przedm = $nr_przedm and data_zal =  \"$stara_data\"", $idpol);
  138.                 }
  139.  
  140.  
  141.                 if ($akcja == "usun") {
  142.  
  143.                     $nr_stud = $_REQUEST['nr_stud'];
  144.                     $nr_przedm = $_REQUEST['nr_przedm'];
  145.                     $stara_data = $_REQUEST['data_zal'];
  146.                     @mysql_db_query($DBase, "DELETE FROM oceny WHERE nr_stud = $nr_stud and nr_przedm = $nr_przedm and data_zal =  \"$stara_data\"", $idpol);
  147.                 }
  148.  
  149.  
  150.  
  151.                 if ($akcja == "dodaj") {
  152.  
  153.                     $nr_stud = $_REQUEST['nr_stud'];
  154.                     $nr_przedm = $_REQUEST['nr_przedm'];
  155.                     $stara_data = $_REQUEST['data_zal'];
  156.                     $data_zal = date('Y-m-d H:i:s');
  157.                     $nowa_ocena = $_REQUEST['_nowa_ocena'];
  158.                     $zal_egz = "Z";
  159.                     if ($nowa_ocena < 3) {
  160.                         $zal_egz = "E";
  161.                     }
  162.                     @mysql_db_query($DBase, "insert into oceny(nr_stud, nr_przedm, data_zal, termin, zal_egz, ocena) values($nr_stud ,$nr_przedm, \"$data_zal\", 1,\"$zal_egz\", $nowa_ocena) ", $idpol);
  163.                 }
  164.             }
  165.             ?>
  166.  
  167.     </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement