| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/Helpdesk/application/models/ |
Upload File : |
<?php
class RequestsModel
{
function __construct($db) {
$this->db = $db;
}
public function getTonerRequest($id)
{
$id = $this->db->strip($id);
$result = $this->db->select("* FROM requests_toners WHERE id='$id'", 'firstrow');
return $result;
}
public function getAllTonersRequests($username="", $period=0)
{
$username = $this->db->strip($username);
$period = $this->db->strip($period);
if (!empty($username))
$where[] = "username='$username'";
if (!empty($period))
$where[] = "period='$period'";
if (!empty($where))
$where = " WHERE ".implode(" AND ", $where);
$result = $this->db->select("rt.*, t.printer, t.type, t.color, t.code, t.price, t.original FROM requests_toners rt INNER JOIN toners t ON rt.toner_id=t.id $where ORDER BY rt.fullname");
return $result;
}
public function getAllTonersRequestsPerCode($period=0)
{
$period = $this->db->strip($period);
if (!empty($period))
$where = " WHERE period='$period'";
$result = $this->db->select("rt.*, t.printer, t.type, t.color, t.code, t.price, t.original, SUM(rt.quantity_approved) as total_quantity, GROUP_CONCAT(DISTINCT rt.fullname SEPARATOR ', ') as users FROM requests_toners rt INNER JOIN toners t ON rt.toner_id=t.id $where GROUP BY rt.toner_id ORDER BY t.printer");
return $result;
}
public function isDoubleTonerRequest($toner_id, $username, $period)
{
$toner_id = $this->db->strip($toner_id);
$username = $this->db->strip($username);
$period = $this->db->strip($period);
$result = $this->db->select("* FROM requests_toners WHERE toner_id=$toner_id AND username='$username' AND period=$period");
return ($result?true:false);
}
public function saveTonerRequest($record)
{
array_walk($record, array($this->db, 'strip_array'));
$old = $this->getTonerRequest($record['id']);
if ($old){
foreach ($record as $field=>$value) {
if ($field!="id") {
if ($value=="NULL")
$set[] = "$field=NULL";
else
$set[] = "$field='$value'";
}
}
$set = implode(", ", $set);
$result = $this->db->update("requests_toners SET $set WHERE id='".$record['id']."'");
} else {
foreach ($record as $field=>$value) {
$fields[] = $field;
if ($value=="NULL")
$values[] = "NULL";
else
$values[] = "'$value'";
}
$fields = implode(", ", $fields);
$values = implode(", ", $values);
$result = $this->db->insert("INTO requests_toners ($fields) VALUES ($values)");
}
return $result;
}
public function updateTonerRequestQuantity($id, $quantity)
{
$id = $this->db->strip($id);
$quantity = $this->db->strip($quantity);
$result = $this->db->update("requests_toners SET quantity=$quantity WHERE id=".$id);
return $result;
}
public function deleteTonerRequest($id)
{
$id = $this->db->strip($id);
$result = $this->db->delete("FROM requests_toners WHERE id=".$id);
return $result;
}
}