funkcije.php
Datoteka funkcije.php vsebuje funkcije, ki so potrebne za delovanje aplikacije.
<?php
function Get_users_ip()
{
//whether ip is from share internet
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from remote address
else
{
$ip_address = $_SERVER['REMOTE_ADDR'];
}
return $ip_address;
}
function Prijava_uspela($email,$geslo)
{
$b = false;
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$sql = "SELECT * FROM uporabniki WHERE email='$email' AND geslo='".sha1($geslo)."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$b = true;
}
$conn->close();
return $b;
}
function Registracija_uspela($email,$geslo,$vrsta_uporabnika,$ime,$priimek,$razred)
{
$b = false;
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "INSERT INTO uporabniki (email,geslo,vrsta_uporabnika,tip_uporabnika) VALUES ('$email','".sha1($geslo)."','$vrsta_uporabnika','user')";
if ($conn->query($sql) === true)
{
$b = true;
}
$id_uporabnika = Get_last_id_uporabnika();
switch ($vrsta_uporabnika)
{
case "dijak":
{
$tabela = "dijaki";
$sql_insert = "INSERT INTO ".$tabela." (ime, priimek, razred, id_uporabnika) VALUES ('$ime', '$priimek', '$razred', '$id_uporabnika')";
break;
}
case "profesor":
{
$tabela = "profesorji";
$sql_insert = "INSERT INTO ".$tabela." (ime, priimek, id_uporabnika) VALUES ('$ime', '$priimek', '$id_uporabnika')";
break;
}
}
if ($conn->query($sql_insert) === true)
{
$b = true;
}
$conn->close();
return $b;
}
function Vpis_prijave($id_uporabnika)
{
$b = false;
$datum = date('Y-m-d');
$ura = date('H:i:s');
$ip = Get_users_ip();
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "INSERT INTO prijave (datum,ura,ip,id_uporabnika) VALUES ('$datum','$ura','$ip','$id_uporabnika')";
if ($conn->query($sql) === true)
{
$b = true;
}
$conn->close();
return $b;
}
function Shrani_oceno($id_dijaka, $id_predmeta, $id_profesorja, $ocena, $datum, $vrsta_ocene, $opomba)
{
$b = false;
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "INSERT INTO ocene (ocena, datum, vrsta_ocene, opomba, id_dijaka, id_predmeta, id_profesorja) VALUES ('$ocena','$datum','$vrsta_ocene','$opomba','$id_dijaka','$id_predmeta','$id_profesorja')";
if ($conn->query($sql) === true)
{
$b = true;
}
$conn->close();
return $b;
}
function Zbrisi_oceno($id_ocene)
{
$b = false;
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$sql = "DELETE FROM ocene WHERE id_ocene='".$id_ocene."'";
if ($conn->query($sql) === true)
{
$b = true;
}
$conn->close();
return $b;
}
function Get_last_id_uporabnika()
{
$last_id = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT * FROM uporabniki ORDER BY id_uporabnika DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$last_id = $row["id_uporabnika"];
}
$conn->close();
return $last_id;
}
function Get_podatek_zadnja_prijava($id_uporabnika,$podatek)
{
$zadnja_prijava = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$sql = "SELECT * FROM prijave WHERE id_uporabnika='$id_uporabnika' ORDER BY id_prijave DESC LIMIT 1 OFFSET 1";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$zadnja_prijava = $row[$podatek];
}
$conn->close();
return $zadnja_prijava;
}
function Get_podatek_uporabnika($email,$geslo,$podatek)
{
$user_data = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT * FROM uporabniki WHERE email='$email' AND geslo='".sha1($geslo)."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$user_data = $row[$podatek];
}
$conn->close();
return $user_data;
}
function Get_podatek_predmeta($id_predmeta,$podatek)
{
$predmet_data = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT * FROM predmeti WHERE id_predmeta='$id_predmeta'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$predmet_data = $row[$podatek];
}
$conn->close();
return $predmet_data;
}
function Get_podatek_tabele($id,$id_naziv,$tabela,$podatek)
{
$data = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT * FROM ".$tabela." WHERE ".$id_naziv."='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$data = $row[$podatek];
}
$conn->close();
return $data;
}
function Get_ime_priimek($id_uporabnika,$vrsta_uporabnika)
{
$user = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
switch ($vrsta_uporabnika)
{
case "dijak":
{
$tabela = "dijaki";
break;
}
case "profesor":
{
$tabela = "profesorji";
break;
}
}
$sql = "SELECT * FROM ".$tabela." WHERE id_uporabnika='$id_uporabnika'";
$conn->set_charset("utf8");
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$user = $row["ime"]." ".$row["priimek"];
}
$conn->close();
return $user;
}
function Get_priimek_ime($id_tabele,$vrsta_uporabnika)
{
$user = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
switch ($vrsta_uporabnika)
{
case "dijak":
{
$tabela = "dijaki";
$id = "id_dijaka";
break;
}
case "profesor":
{
$tabela = "profesorji";
$id = "id_profesorja";
break;
}
}
$sql = "SELECT * FROM ".$tabela." WHERE ".$id."='$id_tabele'";
$conn->set_charset("utf8");
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$row = mysqli_fetch_assoc($result);
$user = $row["priimek"]." ".$row["ime"];
}
$conn->close();
return $user;
}
function Izpis_redovalnice($razred, $id_predmeta)
{
$redovalnica = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT * FROM dijaki WHERE razred='$razred' ORDER BY priimek, ime";
$conn->set_charset("utf8");
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$redovalnica .= "<table class='table table-bordered table'>";
$redovalnica .= "<thead>";
$redovalnica .= "<tr class='bg-secondary text-white text-center'>";
$redovalnica .= "<th style='width: 25%'>Dijak/dijakinja</th>";
$redovalnica .= "<th style='width: 50%'>Ocene</th>";
$redovalnica .= "<th style='width: 25%'>Ukaz</th>";
$redovalnica .= "</tr>";
$redovalnica .= "</thead>";
$redovalnica .= "<tbody>";
while ($row = mysqli_fetch_assoc($result))
{
$redovalnica .= "<tr>";
$id_dijaka = $row["id_dijaka"];
$redovalnica .= "<td style='vertical-align: middle' class='lead'>".$row['priimek']." ".$row['ime']."</td>";
$redovalnica .= "<td style='vertical-align: middle' class='lead'>";
//izpis ocen
$sql_ocene = "SELECT ocena, vrsta_ocene, datum, opomba FROM ocene WHERE id_dijaka='".$id_dijaka."' AND id_predmeta='".$id_predmeta."'";
$ocene_result = $conn->query($sql_ocene);
$st_ocen = $ocene_result->num_rows;
$ocene_dijaka = "";
if ($st_ocen > 0)
{
while ($row_ocene = mysqli_fetch_assoc($ocene_result))
{
$vrsta_ocene = $row_ocene['vrsta_ocene'];
$datum_ocene = $row_ocene['datum'];
$opomba_ocene = $row_ocene['opomba'];
$ocena = $row_ocene['ocena'];
$ocene_dijaka .= "<span aria-label='".$vrsta_ocene.", ".$datum_ocene.", ".$opomba_ocene."' data-balloon-pos='up'>".$ocena."</span> ";
}
}
$redovalnica .= $ocene_dijaka;
$redovalnica .= "</td>";
$redovalnica .= "<td style='vertical-align: middle' class='text-center'><a href='index.php?ukaz=redovalnica&vnos_ocene=1&id_dijaka=".$id_dijaka."' class='btn btn-success'><i class='fas fa-plus-square'></i></a> <a href='index.php?ukaz=redovalnica&izbris_ocene=1&id_dijaka=".$id_dijaka."' class='btn btn-dark'><i class='fas fa-minus-square'></i></a></td>";
$redovalnica .= "</tr>";
}
$redovalnica .= "</tbody>";
$redovalnica .= "</table>";
}
$conn->close();
echo $redovalnica;
}
function Izpis_redovalnice_dijak($id_dijaka)
{
$redovalnica = "";
include "baza.php";
$conn = new mysqli($server,$username,$password,$baza);
$conn->set_charset("utf8");
$sql = "SELECT DISTINCT id_predmeta FROM ocene WHERE id_dijaka='".$id_dijaka."'";
$conn->set_charset("utf8");
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$redovalnica .= "<table class='table table-bordered table'>";
$redovalnica .= "<thead>";
$redovalnica .= "<tr class='bg-secondary text-white text-center'>";
$redovalnica .= "<th style='width: 40%'>Predmet</th>";
$redovalnica .= "<th style='width: 60%'>Ocene</th>";
$redovalnica .= "</tr>";
$redovalnica .= "</thead>";
$redovalnica .= "<tbody>";
while ($row = mysqli_fetch_assoc($result))
{
$id_predmeta = $row["id_predmeta"];
$naziv_predmeta = Get_podatek_tabele($id_predmeta,"id_predmeta","predmeti", "naziv");
$redovalnica .= "<tr>";
$redovalnica .= "<td style='vertical-align: middle' class='lead'>".$naziv_predmeta."</td>";
$redovalnica .= "<td style='vertical-align: middle' class='lead'>";
//izpis ocen
$sql_ocene = "SELECT ocena, vrsta_ocene, datum, opomba FROM ocene WHERE id_dijaka='".$id_dijaka."' AND id_predmeta='".$id_predmeta."'";
$ocene_result = $conn->query($sql_ocene);
$st_ocen = $ocene_result->num_rows;
$ocene_dijaka = "";
if ($st_ocen > 0)
{
while ($row_ocene = mysqli_fetch_assoc($ocene_result))
{
$vrsta_ocene = $row_ocene['vrsta_ocene'];
$datum_ocene = $row_ocene['datum'];
$opomba_ocene = $row_ocene['opomba'];
$ocena = $row_ocene['ocena'];
$ocene_dijaka .= "<span aria-label='".$vrsta_ocene.", ".$datum_ocene.", ".$opomba_ocene."' data-balloon-pos='up'>".$ocena."</span> ";
}
}
$redovalnica .= $ocene_dijaka;
$redovalnica .= "</td>";
$redovalnica .= "</tr>";
}
$redovalnica .= "</tbody>";
$redovalnica .= "</table>";
}
$conn->close();
echo $redovalnica;
}
Created with an evaluation copy of HelpSmith.
To remove this notice, you should purchase the full version of the product.