46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
class Tarif {
|
||
|
|
|
||
|
|
public function get($id)
|
||
|
|
{
|
||
|
|
if(!is_numeric($id)) return false;
|
||
|
|
$sql="SELECT * FROM tariffs WHERE id=$id";
|
||
|
|
$rez=mysql_query($sql);
|
||
|
|
if(mysql_num_rows($rez))
|
||
|
|
{
|
||
|
|
$user = mysql_fetch_assoc($rez);
|
||
|
|
foreach($user as $k => $v)
|
||
|
|
{
|
||
|
|
$this->$k = $v;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function getAll()
|
||
|
|
{
|
||
|
|
$sql = "SELECT * FROM tariffs ORDER BY num";
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
$result = array();
|
||
|
|
while($trf = mysql_fetch_assoc($rez))
|
||
|
|
{
|
||
|
|
$sql = "SELECT COUNT(*) FROM users WHERE id_tarif=$trf[id]";
|
||
|
|
$trf['users'] = mysql_result(mysql_query($sql),0);
|
||
|
|
$result[] = $trf;
|
||
|
|
}
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addEdit()
|
||
|
|
{
|
||
|
|
if($_GET[id]) $sql = "UPDATE tariffs SET num='$_GET[num]', nazv='$_GET[nazv]', max_worker='$_GET[max_worker]', cena='$_GET[cena]', period='$_GET[period]', opis='$_GET[opis]' WHERE id=$_GET[id]";
|
||
|
|
else $sql = "INSERT INTO tariffs(num, nazv, cena, period, opis, max_worker) VALUES('$_GET[num]', '$_GET[nazv]', '$_GET[cena]', '$_GET[period]', '$_GET[opis]', '$_GET[max_worker]')";
|
||
|
|
mysql_query($sql);
|
||
|
|
// header("location:tariffs.php");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function changeStatus($status, $id)
|
||
|
|
{
|
||
|
|
$sql = "UPDATE tariffs SET status='$status' WHERE id=$id";
|
||
|
|
mysql_query($sql);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
?>
|