+
This commit is contained in:
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of Catriges
|
||||
*
|
||||
* @author andrey
|
||||
*/
|
||||
class Cartriges {
|
||||
//put your code here
|
||||
|
||||
public static function getSumAllCarteiges(){ //получаем сумму всех картриджей(доставленных и замененных) по запросу ниже
|
||||
|
||||
/*SELECT c.name as Имя, sum(aC.value) as Сумма FROM actionsCartriges aC
|
||||
INNER JOIN cartriges c ON aC.id_cartriges = c.id
|
||||
GROUP BY c.name;*/
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT c.name as name, sum(aC.action) as value FROM cartridges aC "
|
||||
. "RIGHT JOIN cartriges c ON aC.id_cartrige = c.id "
|
||||
. "WHERE c.action = 1 "
|
||||
. "GROUP BY c.name";
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$summ_cart[$i]['name'] = $row['name'];
|
||||
$summ_cart[$i]['value'] = $row['value'];
|
||||
if($summ_cart[$i]['value'] == NULL) $summ_cart[$i]['value'] = 0;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $summ_cart;
|
||||
//return arr();
|
||||
}
|
||||
|
||||
public static function getActivCartriges(){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$result = $db->query('SELECT id, name FROM cartriges WHERE action = 1');
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$cart[$i]['id'] = $row['id'];
|
||||
$cart[$i]['name'] = $row['name'];
|
||||
$i++;
|
||||
}
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public static function getAllCartriges(){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$result = $db->query('SELECT id, name, action FROM cartriges');
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$cart[$i]['id'] = $row['id'];
|
||||
$cart[$i]['name'] = $row['name'];
|
||||
$cart[$i]['action'] = $row['action'];
|
||||
if(!Printer::getAllPrintersByCartrige($row['id'])) $cart[$i]['print_list'] = "Нет принтеров использующих данный картридж";
|
||||
else $cart[$i]['print_list'] = Printer::getAllPrintersByCartrige($row['id']);
|
||||
$i++;
|
||||
}
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public static function getHistoryCartridges($limit = 5){
|
||||
$db = Db::getConnection();
|
||||
$result = $db->query('SELECT hc.id, hc.user, hc.date, c.name, hc.action
|
||||
FROM history_cartridges hc
|
||||
LEFT JOIN cartriges c ON hc.id_cartridge = c.id
|
||||
ORDER BY hc.id DESC
|
||||
LIMIT '.$limit.';');
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
foreach($row as $key=>$value){
|
||||
$cartridges[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $cartridges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static function setActionCartriges($user_name, $id_cartrige, $quatity, $act){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$date = date("Y-m-d H:i:s");
|
||||
if($act == "out"){
|
||||
$action = $quatity * -1;
|
||||
}elseif ($act == "in" || "zaro") {
|
||||
$action = $quatity;
|
||||
}
|
||||
/* история действий по картриджам */
|
||||
if($act == "out"){
|
||||
$actions = "Замена ".$quatity." шт";
|
||||
}elseif ($act == "in") {
|
||||
$actions = "Доставка ".$quatity." шт";
|
||||
}elseif ($act == "zero") {
|
||||
$actions = "!!!Обнуление: ".$quatity." шт";
|
||||
}
|
||||
Unit::setToHistoryCartridges($user_name, $id_cartrige, $actions);
|
||||
/*end*/
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("INSERT INTO cartridges (date, id_cartrige, action, user) VALUES (:date, :id_cartrige, :action, :user)");
|
||||
$stmt->bindParam(':date', $date);
|
||||
$stmt->bindParam(':id_cartrige', $id_cartrige);
|
||||
$stmt->bindParam(':action', $action);
|
||||
$stmt->bindParam(':user', $user_name);
|
||||
|
||||
return $stmt->execute();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function ActionCartriges($post_data, $session_data){
|
||||
|
||||
for($i = 0; $i < count($post_data)-2; $i++){
|
||||
self::setActionCartriges($session_data['user_id'], $post_data[$i]['cartrige'], $post_data[$i]['quatity'], $post_data['action']);
|
||||
}
|
||||
|
||||
return "all right";
|
||||
|
||||
}
|
||||
|
||||
public static function colorRow($a){
|
||||
if($a < 3 && $a >= 2) return "class='warning'";
|
||||
elseif($a < 2) return "class='danger'";
|
||||
else return "";
|
||||
}
|
||||
|
||||
public static function resetToZero(){
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT id_cartrige as id, sum(action) as value FROM cartridges GROUP BY id_cartrige";
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$summ_cart[$i]['id'] = $row['id'];
|
||||
$summ_cart[$i]['value'] = $row['value'];
|
||||
if($summ_cart[$i]['value'] == NULL) $summ_cart[$i]['value'] = 0;
|
||||
$i++;
|
||||
}
|
||||
|
||||
for($i = 0; $i < count($summ_cart); $i++){
|
||||
self::setActionCartriges($_SESSION["user_id"]."/resetToZero", $summ_cart[$i]['id'], $summ_cart[$i]['value']*-1, "zero");
|
||||
}
|
||||
|
||||
/*return $stmt->execute();
|
||||
echo "<pre>";
|
||||
print_r($summ_cart);
|
||||
echo "</pre>"; */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function addCartriges($cart){ //добавление действия с картриджеми
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$name = $cart['name'];
|
||||
(!$cart['action']) ? $action = 0 : $action = $cart['action'];
|
||||
//добавление картриджа в бд
|
||||
$stmt = $db->prepare("INSERT INTO cartriges (name, action) VALUES (:name, :action)");
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->bindParam(':action', $action);
|
||||
|
||||
return $stmt->execute();
|
||||
|
||||
}
|
||||
|
||||
//public static function RemoveCartriges()
|
||||
|
||||
public static function reactivCartriges($id){ // изменение статуза задействования принтера
|
||||
|
||||
$db = Db::getConnection();
|
||||
$act_val = 0;
|
||||
$cart = Printer::getCartrigeByID($id);
|
||||
var_dump($cart);
|
||||
($cart[0]['action'] == 1) ? $act_val = 0 : $act_val = 1;
|
||||
//добавление картриджа в бд
|
||||
$stmt = $db->prepare("UPDATE cartriges SET action = :action WHERE id=:id");
|
||||
$stmt->bindParam(':action', $act_val);
|
||||
$stmt->bindParam(':id', $id);
|
||||
|
||||
return $stmt->execute();
|
||||
|
||||
}
|
||||
|
||||
public static function orderCartriges($data){ //формирования массива принтеров для заказа картриджей
|
||||
|
||||
/*приходящие данные
|
||||
|
||||
* array(3) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
["cartrige"]=>
|
||||
string(1) "1"
|
||||
["quatity"]=>
|
||||
string(1) "3"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
["cartrige"]=>
|
||||
string(1) "2"
|
||||
["quatity"]=>
|
||||
string(0) ""
|
||||
}
|
||||
["submit"]=>
|
||||
string(0) ""
|
||||
*}
|
||||
*/
|
||||
|
||||
//запрос к базе - забираем список всех id принтеров по первому массиву заказа
|
||||
//вставляем в массив $arr
|
||||
$list = "";//список для IN
|
||||
//случайные числа
|
||||
for($j = 0; $j < count($data) - 1; $j++){
|
||||
$arr = self::setListPrintByID($data[$j]['cartrige']); //id принетров
|
||||
$quantity = ceil($data[$j]['quantity']/2);
|
||||
|
||||
//получаем нужные поля из таблицы с помощью случайного id из списка
|
||||
if(count($arr)> 1){
|
||||
if(count($arr) < $quantity) $quantity = count($arr);
|
||||
$rand_key = array_rand($arr, $quantity);// подставляем в цикл случайное число из массива
|
||||
|
||||
for($i = 0; $i < $quantity; $i++){
|
||||
$list .= $arr[$rand_key[$i]].",";
|
||||
}
|
||||
|
||||
}elseif(count($arr)== 1){
|
||||
$list .= $arr[0].",";
|
||||
}
|
||||
}
|
||||
|
||||
$list = substr($list, 0, -1);
|
||||
//print_r ($list);
|
||||
$data_ord = array();
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$result = $db->query("SELECT model, name, unit, is_color FROM print WHERE id IN (".$list.")");
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$data_ord[$i]['model'] = $row['model'];
|
||||
$data_ord[$i]['name'] = $row['name'];
|
||||
$data_ord[$i]['unit'] = $row['unit'];
|
||||
$data_ord[$i]['is_color'] = $row['is_color'];
|
||||
//if($row['is_color'] == 1) $data_ord[$i]['unit'] .= " (black, yellow, magenta, blue)";
|
||||
$i++;
|
||||
}
|
||||
|
||||
//print_r($data_ord);
|
||||
return $data_ord;
|
||||
//формируем нужный массив с данными для отправки письма
|
||||
/*
|
||||
*
|
||||
* Array ( [0] => Array ( [model] => HP LJM1212 [name] => PRN0175 [unit] => 0055-7357 ) [1] => Array ( [model] => HP LJ 3030 [name] => DSK0173 [unit] => 0000-0297 ) [2] => Array ( [model] => HP LJ 3030 [name] => DKUR0151 [unit] => 0000-5280 ) [3] => Array ( [model] => HP LJ 3020 [name] => DSK4719 [unit] => 0000-5428 ) [4] => Array ( [model] => HP LJM1212 [name] => PRN0173 [unit] => 0053-3585 ) [5] => Array ( [model] => HP LJ 3030 [name] => dsk0651 [unit] => 0045-5575 ) [6] => Array ( [model] => HP LJM1212 [name] => prn0180 [unit] => 0043-8493 ) [7] => Array ( [model] => Ricoh Aficio SP 3510SF [name] => PRN0185 [unit] => 0045-1758 ) )
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
private static function setListPrintByID($id){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$result = $db->query("SELECT id FROM print WHERE id_cartriges=".$id." AND id_status IN (1, 6, 8)");
|
||||
//$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$ids[$i] = $row['id'];
|
||||
$i++;
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
public static function changeIsPublic($id){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$result = $db->query('SELECT * FROM cartriges WHERE id='.$id);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$row = $result->fetch();
|
||||
|
||||
$is_publication = $row['action'];
|
||||
|
||||
if($is_publication == 0) $is_publication_new = 1;
|
||||
else $is_publication_new = 0;
|
||||
|
||||
$stmt = $db->prepare("UPDATE cartriges SET action = :action WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->bindParam(':action', $is_publication_new);
|
||||
$stmt->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of Phonebook
|
||||
*
|
||||
* @author adm_azashchepkin
|
||||
*/
|
||||
class Phonebook {
|
||||
//put your code here
|
||||
public static function gelAllPhoneList($is_activ = 1){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$arr_dep = Array();
|
||||
|
||||
if($is_activ == 1){
|
||||
$result = $db->query('SELECT id, department FROM dep');
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$arr_dep[$i]['id'] = $row['id'];
|
||||
$arr_dep[$i]['department'] = $row['department'];
|
||||
$i++;
|
||||
for($j = 0; count($arr_dep)>$j; $j++){
|
||||
$phonelist[$arr_dep[$j]['department']] = self::getPhoneInDepartment($arr_dep[$j]['id'], $is_activ);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$phonelist = self::getPhoneInDepartment(0, $is_activ);
|
||||
}
|
||||
|
||||
return $phonelist;
|
||||
}
|
||||
|
||||
private static function getPhoneInDepartment($id_department = 0, $is_activ = 1){
|
||||
$db = Db::getConnection();
|
||||
$id = intval($id_department);
|
||||
$list = [];
|
||||
$sql = "SELECT book.id AS id, book.name AS name, book.mac_address AS mac, book.number AS number, book.post AS post, book.parent_post_id AS parent_id, book.subordination_id AS subordination, book.activ AS activ, dep.department AS department
|
||||
FROM book
|
||||
LEFT JOIN dep
|
||||
ON book.department_id = dep.id";
|
||||
if($id_department != 0){
|
||||
$sql .= " WHERE book.department_id = ".$id;
|
||||
}
|
||||
if($is_activ == 1){
|
||||
$sql .= " AND book.activ = 1";
|
||||
}
|
||||
$sql .= " ORDER BY book.department_id, book.subordination_id, book.post;";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function gerResultSearch($searching, $is_adm = 0){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$list = false;
|
||||
$sql = "SELECT book.id AS id, book.name AS name, book.mac_address AS mac, book.number AS number, book.post AS post, book.activ AS activ, dep.department AS department
|
||||
FROM book
|
||||
LEFT JOIN dep
|
||||
ON book.department_id = dep.id
|
||||
WHERE book.number LIKE '%".$searching."%' OR book.name LIKE '%".$searching."%' OR book.mac_address LIKE '%".$searching."%' ";
|
||||
if($is_adm == 0) $sql .= " ORDER BY book.department_id, book.subordination_id, book.post;";
|
||||
else $sql .= " ORDER BY book.activ, book.number;";
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getExcelList(){
|
||||
include ROOT.'/lib/phpexcel/PHPExcel.php';
|
||||
$phone_list = self::gelAllPhoneList();
|
||||
|
||||
$excel = new PHPExcel();
|
||||
$excelRead = PHPExcel_IOFactory::createReader('Excel2007');
|
||||
$excel = $excelRead->load('phonebook.xlsx');
|
||||
$excel->setActiveSheetIndex(0);
|
||||
|
||||
# массив с параметрами
|
||||
$arHeadStyle = array(
|
||||
'background'=> array(
|
||||
'color' => array('rgb' => 'ff0000')
|
||||
),
|
||||
'font' => array(
|
||||
'bold' => true,
|
||||
'color' => array('rgb' => '778899'),
|
||||
'size' => 13,
|
||||
'name' => 'Verdana'
|
||||
)
|
||||
);
|
||||
|
||||
$i = 2;
|
||||
|
||||
foreach($phone_list as $key => $value){
|
||||
|
||||
$excel->getActiveSheet()->mergeCells("A".$i.":C".$i."");
|
||||
$excel->getActiveSheet()->setCellValue('A'.$i,$key);
|
||||
$excel->getActiveSheet()->getStyle('A'.$i)->applyFromArray($arHeadStyle);
|
||||
$i++;
|
||||
for($j = 0; count($value) > $j; $j++){
|
||||
$excel->getActiveSheet()->setCellValue('A'.$i,$value[$j]['name'])
|
||||
->setCellValue('B'.$i,$value[$j]['number'])
|
||||
->setCellValue('C'.$i,$value[$j]['post']);
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Отдаем на скачивание
|
||||
header("Content-Type:application/vnd.ms-excel");
|
||||
header("Content-Disposition:attachment;filename=Телефонный Справочник на ".date("d-m-Y").".xlsx");
|
||||
|
||||
$Writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
|
||||
|
||||
return $Writer->save('php://output');
|
||||
|
||||
}
|
||||
|
||||
public static function changeIsActiv($id){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$result = $db->query('SELECT * FROM book WHERE id='.$id);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$row = $result->fetch();
|
||||
|
||||
$activ = $row['activ'];
|
||||
|
||||
if($activ == 0) {$activ = 1;}
|
||||
else {$activ = 0;}
|
||||
|
||||
$stmt = $db->prepare("UPDATE book SET activ = :activ WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->bindParam(':activ', $activ);
|
||||
$stmt->execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getElementByID($id){
|
||||
$id = intval($id);
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT book.id AS id, book.name AS name, book.mac_address AS mac, book.number AS number, book.post AS post, book.parent_post_id AS parent_id, book.subordination_id AS subordination, book.department_id AS department, book.activ AS activ, book.login AS login
|
||||
FROM book
|
||||
WHERE book.id=".$id.";";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$row = $result->fetch();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function getSubordination(){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT * FROM subordination;";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getParents(){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT id, name FROM book WHERE subordination_id IN (1,2,3,4) AND activ = 1;";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getDepatmnents(){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = "SELECT id, department FROM dep;";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function save($data) {
|
||||
$db = Db::getConnection();
|
||||
/*array(11) {
|
||||
["id"]=>
|
||||
string(1) "1"
|
||||
["name"]=>
|
||||
string(27) "Токарева Олеся"
|
||||
["number"]=>
|
||||
string(5) "15005"
|
||||
["mac"]=>
|
||||
string(15) "SEP001D70FCF8B8"
|
||||
["parent_id"]=>
|
||||
string(1) "0"
|
||||
["subord"]=>
|
||||
string(1) "1"
|
||||
["department"]=>
|
||||
string(1) "1"
|
||||
["login"]=>
|
||||
string(65) "intranet.rencredit.ru/my/Person.aspx?accountname=rccf%5Cotokareva"
|
||||
["post"]=>
|
||||
string(18) " Директор"
|
||||
["activ"]=>
|
||||
string(2) "on"
|
||||
["save"]=>
|
||||
string(0) ""
|
||||
}*/
|
||||
$id = filter_input(INPUT_POST, 'id');
|
||||
$name = filter_input(INPUT_POST, 'name');
|
||||
$number = filter_input(INPUT_POST, 'number');
|
||||
$mac = filter_input(INPUT_POST, 'mac');
|
||||
$parent_id = filter_input(INPUT_POST, 'parent_id');
|
||||
$subord = filter_input(INPUT_POST, 'subord');
|
||||
$department = filter_input(INPUT_POST, 'department');
|
||||
$login = filter_input(INPUT_POST, 'login');
|
||||
$post = filter_input(INPUT_POST, 'post');
|
||||
$activ = filter_input(INPUT_POST, 'activ');
|
||||
$activ == NULL ? $activ = 0 : $activ =1;
|
||||
|
||||
$stmt = $db->prepare("UPDATE book SET name=:name, number=:number, mac_address=:mac, parent_post_id=:parent_id, subordination_id=:subord, department_id=:department, login=:login, post=:post, activ=:activ WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->bindParam(':number', $number);
|
||||
$stmt->bindParam(':mac', $mac);
|
||||
$stmt->bindParam(':parent_id', $parent_id);
|
||||
$stmt->bindParam(':subord', $subord);
|
||||
$stmt->bindParam(':department', $department);
|
||||
$stmt->bindParam(':login', $login);
|
||||
$stmt->bindParam(':post', $post);
|
||||
$stmt->bindParam(':activ', $activ);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created on 04.10.2016
|
||||
* By NetBeans IDE 8.1
|
||||
* Author: Andrey Zashchepkin
|
||||
*
|
||||
*
|
||||
* ******** Contacts:*********
|
||||
* my e-mails - yaslonane@yandex.ru
|
||||
* - andrey@zashchepkin.ru
|
||||
* - info@zashchepkin.ru
|
||||
* my site zashchepkin.ru
|
||||
* ******** end contacts *********
|
||||
*
|
||||
*
|
||||
* Copyright zashchepkin.ru © 2016. All Rights Reserved.
|
||||
* License https://opensource.org/licenses/mit-license.php MIT License (MIT)
|
||||
*
|
||||
*
|
||||
* Description of Printer
|
||||
*
|
||||
* @author andrey
|
||||
* */
|
||||
class Printer {
|
||||
|
||||
public static function getListPrinters($id_status_print = 1){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
/*$name = "";
|
||||
$unit = "";
|
||||
$floor = "";
|
||||
$department = "";
|
||||
$cartrige = "";
|
||||
$status = "";*/
|
||||
|
||||
if(isset($_POST['submit']) && (isset($_POST['name']) || isset($_POST['unit']) || isset($_POST['floor']) || isset($_POST['department']) || isset($_POST['cartrige']) || isset($_POST['status']))){
|
||||
|
||||
$sql = "SELECT * FROM print";
|
||||
/*echo "<pre>";
|
||||
var_dump($_POST) ;
|
||||
echo "</pre>";*/
|
||||
if(!empty($_POST['name']) || !empty($_POST['unit']) || !empty($_POST['floor']) || !empty($_POST['department']) || !empty($_POST['cartrige']) || !empty($_POST['status'])) {
|
||||
|
||||
$sql .= " WHERE ";
|
||||
|
||||
if(!empty($_POST['name'])) {
|
||||
$name = $_POST['name'];
|
||||
$sql .= "name LIKE '%$name%', ";
|
||||
}
|
||||
|
||||
if(!empty($_POST['unit'])) {
|
||||
$unit = $_POST['unit'];
|
||||
$sql .= "unit = '$unit', ";
|
||||
}
|
||||
|
||||
if(!empty($_POST['floor'])) {
|
||||
$floor = $_POST['floor'];
|
||||
$sql .= "id_floor = $floor, ";
|
||||
}
|
||||
|
||||
if(!empty($_POST['department'])) {
|
||||
$department = $_POST['department'];
|
||||
$sql .= "id_department = $department, ";
|
||||
}
|
||||
|
||||
if(!empty($_POST['cartrige'])) {
|
||||
$cartrige = $_POST['cartrige'];
|
||||
$sql .= "id_cartrige = $cartrige, ";
|
||||
}
|
||||
|
||||
if(!empty($_POST['status'])) {
|
||||
$status = $_POST['status'];
|
||||
$sql .= "id_status = $status, ";
|
||||
}
|
||||
|
||||
|
||||
$sql = substr($sql, 0, -2);
|
||||
$sql .= ";";
|
||||
|
||||
}else $sql .= ";";
|
||||
//echo $sql;
|
||||
$result = $db->query($sql);
|
||||
if($result == false) return 0;
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
//$row = $result->fetch();
|
||||
|
||||
//if($result->fetch() == false) $print = 0;
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$print[$i]['id'] = $row['id'];
|
||||
$print[$i]['name'] = $row['name'];
|
||||
$print[$i]['model'] = $row['model'];
|
||||
$print[$i]['unit'] = $row['unit'];
|
||||
$fl = self::getAllValuesInTable('name', 'floor', $where = 'id', $where_value = $row['id_floor']);
|
||||
$print[$i]['id_floor'] = $fl[0]['name'];
|
||||
$dp = self::getAllValuesInTable('name', 'departments', $where = 'id', $where_value = $row['id_department']);
|
||||
$print[$i]['id_department'] = $dp[0]['name'];;
|
||||
$print[$i]['img'] = $row['img'];
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $print;
|
||||
|
||||
|
||||
}else {
|
||||
$sql = 'SELECT
|
||||
print.id as id,
|
||||
print.name as name,
|
||||
print.model as model,
|
||||
print.unit as unit,
|
||||
print.inventar as indentar,
|
||||
print.sn as sn,
|
||||
cartriges.name as cartrige,
|
||||
departments.name as department,
|
||||
floor.name as floor,
|
||||
status.name as status,
|
||||
print.img as img
|
||||
FROM print
|
||||
LEFT JOIN `cartriges` ON cartriges.id = print.id_cartriges
|
||||
LEFT JOIN `departments` ON departments.id = print.id_department
|
||||
LEFT JOIN `floor` ON floor.id = print.id_floor
|
||||
LEFT JOIN `status` ON status.id = print.id_status ';
|
||||
|
||||
if($id_status_print == 'all'){
|
||||
$sql .= ';';
|
||||
}else
|
||||
$sql .= 'WHERE print.id_status = '.$id_status_print.';';
|
||||
|
||||
|
||||
// $result = $db->query('SELECT * FROM print WHERE id_status = 1');
|
||||
$result = $db->query($sql);
|
||||
|
||||
/*
|
||||
* SELECT id
|
||||
* FROM actionsCartriges aC
|
||||
* INNER JOIN cartriges c ON aC.id_cartriges = c.id
|
||||
*/
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
//$row = $result->fetch();
|
||||
|
||||
//if($result->fetch() == false) $print = 0;
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$print[$i]['id'] = $row['id'];
|
||||
$print[$i]['name'] = $row['name'];
|
||||
$print[$i]['model'] = $row['model'];
|
||||
$print[$i]['unit'] = $row['unit'];
|
||||
$print[$i]['id_floor'] = $row['floor'];
|
||||
$print[$i]['id_department'] = $row['department'];
|
||||
$print[$i]['img'] = $row['img'];
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $print;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static function getListFunction($id_functions){
|
||||
$error = "Отсутствует";
|
||||
if($id_functions){
|
||||
$db = Db::getConnection();
|
||||
$sql = 'SELECT id, name, description FROM functions ';
|
||||
$sql .= 'WHERE id IN ('.$id_functions.')';
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
$arr[$i]['id'] = $row['id'];
|
||||
$arr[$i]['name'] = $row['name'];
|
||||
$arr[$i]['description'] = $row['description'];
|
||||
$i++;
|
||||
}
|
||||
return $arr;
|
||||
}else return $error;
|
||||
}
|
||||
|
||||
public static function getPrintByID($id){
|
||||
$db = Db::getConnection();
|
||||
$result = $db->query('
|
||||
SELECT
|
||||
print.id as id,
|
||||
print.name as name,
|
||||
print.model as model,
|
||||
print.unit as unit,
|
||||
print.inventar as inventar,
|
||||
print.id_functions as functions,
|
||||
print.sn as sn,
|
||||
cartriges.name as cartrige,
|
||||
departments.name as department,
|
||||
adress.city as city,
|
||||
adress.street as street,
|
||||
adress.house as house,
|
||||
floor.name as floor,
|
||||
status.name as status,
|
||||
print.img as img
|
||||
FROM print
|
||||
LEFT JOIN `cartriges` ON cartriges.id = print.id_cartriges
|
||||
LEFT JOIN `departments` ON departments.id = print.id_department
|
||||
LEFT JOIN `adress` ON adress.id = print.id_adress
|
||||
LEFT JOIN `floor` ON floor.id = print.id_floor
|
||||
LEFT JOIN `status` ON status.id = print.id_status
|
||||
WHERE print.id = '.$id.'
|
||||
');
|
||||
|
||||
/*
|
||||
* SELECT id
|
||||
* FROM actionsCartriges aC
|
||||
* INNER JOIN cartriges c ON aC.id_cartriges = c.id
|
||||
*/
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
//$row = $result->fetch();
|
||||
|
||||
//if($result->fetch() == false) $print = 0;
|
||||
|
||||
$row = $result->fetch();
|
||||
$print['id'] = $row['id'];
|
||||
$print['name'] = $row['name'];
|
||||
$print['model'] = $row['model'];
|
||||
$print['unit'] = $row['unit'];
|
||||
$print['inventar'] = $row['inventar'];
|
||||
$print['sn'] = $row['sn'];
|
||||
$print['adress'] = $row['city'] .", ". $row['street'].", ". $row['house'];
|
||||
$print['floor'] = $row['floor'];
|
||||
$print['department'] = $row['department'];
|
||||
$print['status'] = $row['status'];
|
||||
$print['cartrige'] = $row['cartrige'];
|
||||
$print['img'] = $row['img'];
|
||||
$print['functions'] = self::getListFunction($row['functions']);
|
||||
|
||||
return $print;
|
||||
}
|
||||
|
||||
public static function getPrintByIDFullData($id){
|
||||
$db = Db::getConnection();
|
||||
$result = $db->query('
|
||||
SELECT
|
||||
print.id as id,
|
||||
print.name as name,
|
||||
print.model as model,
|
||||
print.unit as unit,
|
||||
print.inventar as inventar,
|
||||
print.id_functions as functions,
|
||||
print.sn as sn,
|
||||
cartriges.name as cartrige,
|
||||
print.id_cartriges as id_cart,
|
||||
departments.name as department,
|
||||
print.id_department as id_dep,
|
||||
floor.name as floor,
|
||||
print.id_floor as id_fl,
|
||||
status.name as status,
|
||||
print.id_status as id_st,
|
||||
print.img as img
|
||||
FROM print
|
||||
LEFT JOIN `cartriges` ON cartriges.id = print.id_cartriges
|
||||
LEFT JOIN `departments` ON departments.id = print.id_department
|
||||
LEFT JOIN `floor` ON floor.id = print.id_floor
|
||||
LEFT JOIN `status` ON status.id = print.id_status
|
||||
WHERE print.id = '.$id.'
|
||||
');
|
||||
|
||||
/*
|
||||
* SELECT id
|
||||
* FROM actionsCartriges aC
|
||||
* INNER JOIN cartriges c ON aC.id_cartriges = c.id
|
||||
*/
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
//$row = $result->fetch();
|
||||
|
||||
//if($result->fetch() == false) $print = 0;
|
||||
|
||||
$row = $result->fetch();
|
||||
$print['id'] = $row['id'];
|
||||
$print['name'] = $row['name'];
|
||||
$print['model'] = $row['model'];
|
||||
$print['unit'] = $row['unit'];
|
||||
$print['inventar'] = $row['inventar'];
|
||||
$print['sn'] = $row['sn'];
|
||||
$print['floor'] = $row['floor'];
|
||||
$print['id_fl'] = $row['id_fl'];
|
||||
$print['department'] = $row['department'];
|
||||
$print['id_dep'] = $row['id_dep'];
|
||||
$print['status'] = $row['status'];
|
||||
$print['id_st'] = $row['id_st'];
|
||||
$print['cartrige'] = $row['cartrige'];
|
||||
$print['id_cart'] = $row['id_cart'];
|
||||
$print['img'] = $row['img'];
|
||||
$print['functions'] = self::getListFunction($row['functions']);
|
||||
|
||||
return $print;
|
||||
}
|
||||
|
||||
public static function checkDataUpdatePrint($old_data, $new_data){
|
||||
|
||||
$message = "";
|
||||
$update = array();
|
||||
$i = 0;
|
||||
|
||||
if($old_data['name'] != $new_data['name']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Имя принтера";
|
||||
$update[$i]['old_data'] = $old_data['name'];
|
||||
$update[$i]['new_data'] = $new_data['name'];
|
||||
}
|
||||
if($old_data['model'] != $new_data['model']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Модель принтера";
|
||||
$update[$i]['old_data'] = $old_data['model'];
|
||||
$update[$i]['new_data'] = $new_data['model'];
|
||||
}
|
||||
if($old_data['unit'] != $new_data['unit']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Номер UNIT принтера";
|
||||
$update[$i]['old_data'] = $old_data['unit'];
|
||||
$update[$i]['new_data'] = $new_data['unit'];
|
||||
}
|
||||
if($old_data['inventar'] != $new_data['inventar']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Инвентарный номер принтера";
|
||||
$update[$i]['old_data'] = $old_data['inventar'];
|
||||
$update[$i]['new_data'] = $new_data['inventar'];
|
||||
}
|
||||
if($old_data['sn'] != $new_data['sn']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Серийный номер принтера";
|
||||
$update[$i]['old_data'] = $old_data['sn'];
|
||||
$update[$i]['new_data'] = $new_data['sn'];
|
||||
}
|
||||
|
||||
if($old_data['id_fl'] != $new_data['id_floor']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Этаж";
|
||||
$update[$i]['old_data'] = $old_data['id_fl'];
|
||||
$update[$i]['new_data'] = $new_data['id_floor'];
|
||||
}
|
||||
if($old_data['id_dep'] != $new_data['id_department']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Отдел";
|
||||
$update[$i]['old_data'] = $old_data['id_dep'];
|
||||
$update[$i]['new_data'] = $new_data['id_department'];
|
||||
}
|
||||
if($old_data['id_cart'] != $new_data['id_cartrige']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Картридж";
|
||||
$update[$i]['old_data'] = $old_data['id_cart'];
|
||||
$update[$i]['new_data'] = $new_data['id_cartrige'];
|
||||
}
|
||||
if($old_data['id_st'] != $new_data['id_status']){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Статус";
|
||||
$update[$i]['old_data'] = $old_data['id_st'];
|
||||
$update[$i]['new_data'] = $new_data['id_status'];
|
||||
}
|
||||
|
||||
if(self::identical_values(self::modAndCheckFunctions($old_data['functions']), $new_data['id_functions']) == false){
|
||||
if($old_data['functions'] != "Отсутствует"){
|
||||
$del = array_diff(self::modAndCheckFunctions($old_data['functions']), $new_data['id_functions']);
|
||||
$add = array_diff( $new_data['id_functions'], self::modAndCheckFunctions($old_data['functions']));
|
||||
}else {
|
||||
$del = false;
|
||||
$add = $new_data['id_functions'];
|
||||
}
|
||||
|
||||
if($del){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Функции удалили";
|
||||
$update[$i]['old_data'] = implode(",", $del);
|
||||
$update[$i]['new_data'] = "";
|
||||
}
|
||||
if($add){
|
||||
$i++;
|
||||
$update[$i]['object'] = "Функции добавили";
|
||||
$update[$i]['old_data'] = "";
|
||||
$update[$i]['new_data'] = implode(",", $add);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $update;
|
||||
|
||||
}
|
||||
|
||||
public static function setHistoryChange($data_change, $id_print, $id_user){
|
||||
//формирования запроса
|
||||
for($i=1; $i <= count($data_change); $i++){
|
||||
self::InsertHistoryChange($id_print, $id_user, $data_change[$i]['object'], $data_change[$i]['old_data'], $data_change[$i]['new_data']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getHistoryChangeByID($id_print){
|
||||
//формирования запроса
|
||||
$db = Db::getConnection();
|
||||
|
||||
$history = $db->query('SELECT * FROM history_change WHERE id_print ='.$id_print.';');
|
||||
|
||||
$history->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 0;
|
||||
while($row = $history->fetch()){
|
||||
foreach($row as $key => $value){
|
||||
$arr[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function message(){
|
||||
if(isset($_SESSION['message'])){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function InsertHistoryChange($id_print, $user, $object_change, $old_data, $new_data){
|
||||
$db = Db::getConnection();
|
||||
$date = date("Y-m-d H:i:s");
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("INSERT INTO history_change (date, id_print, user, object_change, old_data, new_data) VALUES (:date, :id_print, :user, :object_change, :old_data, :new_data)");
|
||||
$stmt->bindParam(':date', $date);
|
||||
$stmt->bindParam(':id_print', $id_print);
|
||||
$stmt->bindParam(':user', $user);
|
||||
$stmt->bindParam(':object_change', $object_change);
|
||||
$stmt->bindParam(':old_data', $old_data);
|
||||
$stmt->bindParam(':new_data', $new_data);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
public static function insertPrint($data, $return_id = false){
|
||||
//формирование запроса и обновление данных в базе
|
||||
$db = Db::getConnection();
|
||||
$functions = "";
|
||||
if(isset($data['id_functions'])) $functions = implode(",", $data['id_functions']);
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("INSERT INTO print
|
||||
(name, unit, model, sn, inventar, id_floor, id_department, id_cartriges, id_status, id_functions)
|
||||
VALUES
|
||||
(:name, :unit, :model, :sn, :inventar, :id_floor, :id_department, :id_cartrige, :id_status, :id_functions)");
|
||||
//$stmt->bindParam(':id', $id_print, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':name', $data['name']);
|
||||
$stmt->bindParam(':unit', $data['unit']);
|
||||
$stmt->bindParam(':model', $data['model']);
|
||||
$stmt->bindParam(':sn', $data['sn']);
|
||||
$stmt->bindParam(':inventar', $data['inventar']);
|
||||
$stmt->bindParam(':id_floor', $data['id_floor']);
|
||||
$stmt->bindParam(':id_department', $data['id_department']);
|
||||
$stmt->bindParam(':id_cartrige', $data['id_cartrige']);
|
||||
$stmt->bindParam(':id_status', $data['id_status']);
|
||||
$stmt->bindParam(':id_functions', $functions);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
if($return_id = false) return true;
|
||||
else return $db->lastInsertId();
|
||||
|
||||
}
|
||||
|
||||
public static function updatePrint($id_print, $data){
|
||||
//формирование запроса и обновление данных в базе
|
||||
$db = Db::getConnection();
|
||||
$functions = implode(",", $data['id_functions']);
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("UPDATE print set name=:name, unit=:unit, model=:model, sn=:sn, inventar=:inventar, id_floor=:id_floor, id_department=:id_department, id_cartriges=:id_cartrige, id_status=:id_status, id_functions=:id_functions WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id_print, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':name', $data['name']);
|
||||
$stmt->bindParam(':unit', $data['unit']);
|
||||
$stmt->bindParam(':model', $data['model']);
|
||||
$stmt->bindParam(':sn', $data['sn']);
|
||||
$stmt->bindParam(':inventar', $data['inventar']);
|
||||
$stmt->bindParam(':id_floor', $data['id_floor']);
|
||||
$stmt->bindParam(':id_department', $data['id_department']);
|
||||
$stmt->bindParam(':id_cartrige', $data['id_cartrige']);
|
||||
$stmt->bindParam(':id_status', $data['id_status']);
|
||||
$stmt->bindParam(':id_functions', $functions);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
private static function identical_values($arrayA, $arrayB) {
|
||||
if(!is_array($arrayA) || !is_array($arrayA)) return false;
|
||||
else{
|
||||
sort( $arrayA );
|
||||
sort( $arrayB );
|
||||
|
||||
return $arrayA == $arrayB;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function modAndCheckFunctions($old_functions){
|
||||
if($old_functions != "Отсутствует"){
|
||||
$old_mod_functions = array();
|
||||
|
||||
for($i=0; $i < count($old_functions); $i++){
|
||||
$old_mod_functions[] = $old_functions[$i]['id'];
|
||||
}
|
||||
|
||||
return $old_mod_functions;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
|
||||
public static function getAllFloors(){
|
||||
|
||||
return self::getAllValuesInTable('*', 'floor');
|
||||
|
||||
}
|
||||
|
||||
public static function getAllDepartments(){
|
||||
|
||||
return self::getAllValuesInTable(array('id', 'name'), 'departments', $where = 'action', $where_value = '1');
|
||||
|
||||
}
|
||||
|
||||
public static function getAllCartriges(){
|
||||
|
||||
return self::getAllValuesInTable(array('id', 'name'), 'cartriges', $where = 'action', $where_value = '1');
|
||||
|
||||
}
|
||||
|
||||
public static function getAllPrintersByCartrige($id_cartriges){
|
||||
|
||||
return self::getAllValuesInTable(array('id', 'name', 'id_status'), 'print', $where = 'id_cartriges', $where_value = $id_cartriges);
|
||||
|
||||
}
|
||||
|
||||
public static function getCartrigeByID($id){
|
||||
|
||||
return self::getAllValuesInTable("*", 'cartriges', $where = 'id', $where_value = $id);
|
||||
|
||||
}
|
||||
|
||||
public static function getAllStatuses(){
|
||||
|
||||
return self::getAllValuesInTable('*', 'status');
|
||||
}
|
||||
|
||||
public static function getAllFunctions(){
|
||||
|
||||
return self::getAllValuesInTable('*', 'functions');
|
||||
}
|
||||
|
||||
private static function getAllValuesInTable($columns, $table, $where = false, $where_value = false){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$arr = null;
|
||||
$sql = "SELECT ";
|
||||
|
||||
if(is_array($columns)) $columns = implode(",", $columns);
|
||||
|
||||
$sql .= "$columns FROM $table";
|
||||
|
||||
if($where != false) {
|
||||
|
||||
$sql .= " WHERE $where=$where_value";
|
||||
}
|
||||
|
||||
$sql .= ";";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
//$result->fetch();
|
||||
//var_dump($row = $result->fetch());
|
||||
//if($result->fetch() == false) return false; СДЕЛАТЬ ИМЕНА КЛЮЧЕЙ МАССИВА ИЗ ВЫГРУЖАЕМЫХ ДАННЫХ!!!!!!!!! НИЖЕ
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
|
||||
foreach($row as $key => $value){
|
||||
$arr[$i][$key] = $value;
|
||||
}
|
||||
/*$arr[$i]['id'] = $row['id'];
|
||||
$arr[$i]['name'] = $row['name'];
|
||||
if(isset($row['id_status'])) $arr[$i]['id_status'] = $row['id_status'];*/
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function getRandPrint($quantity){
|
||||
$db = Db::getConnection();
|
||||
$list = "";//список для IN
|
||||
$arr = array();
|
||||
$print = [];
|
||||
|
||||
$id_list = $db->query('SELECT id FROM print WHERE id_status = 1');
|
||||
|
||||
$id_list->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 0;
|
||||
while($row = $id_list->fetch()){
|
||||
$arr[$i] = $row['id'];
|
||||
$i++;
|
||||
}
|
||||
|
||||
$rand_key = array_rand($arr, $quantity);// подставляем в цикл случайное число из массива
|
||||
|
||||
for($j = 0; $j < $quantity; $j++){
|
||||
$list .= $arr[$rand_key[$j]].",";
|
||||
}
|
||||
|
||||
$list = substr($list, 0, -1);
|
||||
|
||||
echo $list;
|
||||
|
||||
$result = $db->query('
|
||||
SELECT
|
||||
print.id as id,
|
||||
print.name as name,
|
||||
print.model as model,
|
||||
print.unit as unit,
|
||||
print.inventar as indentar,
|
||||
print.sn as sn,
|
||||
cartriges.name as cartrige,
|
||||
departments.name as department,
|
||||
floor.name as floor,
|
||||
status.name as status,
|
||||
print.img as img,
|
||||
print.is_color as color
|
||||
FROM print
|
||||
LEFT JOIN `cartriges` ON cartriges.id = print.id_cartriges
|
||||
LEFT JOIN `departments` ON departments.id = print.id_department
|
||||
LEFT JOIN `floor` ON floor.id = print.id_floor
|
||||
LEFT JOIN `status` ON status.id = print.id_status
|
||||
WHERE print.id IN ('.$list.')');
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$k = 0;
|
||||
while($row = $result->fetch()){
|
||||
$print[$k]['id'] = $row['id'];
|
||||
$print[$k]['name'] = $row['name'];
|
||||
$print[$k]['model'] = $row['model'];
|
||||
$print[$k]['unit'] = $row['unit'];
|
||||
$print[$k]['id_floor'] = $row['floor'];
|
||||
$print[$k]['id_department'] = $row['department'];
|
||||
$print[$k]['img'] = $row['img'];
|
||||
$print[$k]['color'] = $row['color'];
|
||||
$k++;
|
||||
}
|
||||
return $print;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of radio
|
||||
*
|
||||
* @author adm_azashchepkin
|
||||
*/
|
||||
class Radio {
|
||||
//put your code here
|
||||
|
||||
public static function radioList(){
|
||||
|
||||
$radio = Icecast::getConnection();
|
||||
|
||||
//$scfp = fsockopen($scip, $scport, $errno, $errstr, 10);
|
||||
$scfp = fopen("http://".$radio['ip'].":".$radio['port']."/status3.xsl", "r");
|
||||
|
||||
if($scfp) {
|
||||
//fwrite($scfp,"GET /status3.xsl HTTP/1.0\r\n User-Agent: Icecast Song Status (Mozilla Compatible)\r\n\r\n");
|
||||
$info = '';
|
||||
while(!feof($scfp)) {
|
||||
$listeners = fgets($scfp, 1000); // Вот то, что нам надо
|
||||
//вывод количества слушателей
|
||||
$info .= trim($listeners);
|
||||
}
|
||||
|
||||
fclose($scfp);
|
||||
|
||||
$info = explode('!!', $info);
|
||||
unset($info[0]);
|
||||
|
||||
foreach ($info as $value) {
|
||||
$exploded = explode('%%', $value);
|
||||
$new_info[$exploded[0]] = $exploded;
|
||||
}
|
||||
|
||||
return $new_info;
|
||||
}
|
||||
}
|
||||
|
||||
public static function radioImg($a){
|
||||
$a = substr($a,1);
|
||||
$img = "http://dsk7681/player/img/".$a.".jpg";
|
||||
if (@fopen($img, "r")) {
|
||||
return $a;
|
||||
} else {
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getStatistic(){
|
||||
$radio = Icecast::getConnection();
|
||||
|
||||
$scfp = fopen("http://".$radio['ip'].":".$radio['port']."/status3.xsl", "r");
|
||||
$list = fread($scfp, 10000);
|
||||
|
||||
$statistics = [];
|
||||
|
||||
$info = explode('!!', $list);
|
||||
for($i=0; count($info)>$i; $i++){
|
||||
$elements = explode('%%', $info[$i]);
|
||||
$statistics[$i]['stream'] = $elements[0];
|
||||
$statistics[$i]['quantity_listens'] = @$elements[1];
|
||||
$statistics[$i]['artist'] = @$elements[2];
|
||||
$statistics[$i]['title'] = @$elements[3];
|
||||
}
|
||||
/*array(3) {
|
||||
["host"]=>
|
||||
string(7) "dsk7681"
|
||||
["ip"]=>
|
||||
string(11) "10.20.4.219"
|
||||
["port"]=>
|
||||
string(4) "8000"
|
||||
}
|
||||
|
||||
*
|
||||
*
|
||||
* 0 name stream
|
||||
* 1 quantity listens
|
||||
* 2 artist
|
||||
* 3 name composiition
|
||||
*
|
||||
*/
|
||||
array_shift($statistics);
|
||||
|
||||
return $statistics;
|
||||
}
|
||||
}
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of Unit
|
||||
*
|
||||
* @author adm_azashchepkin
|
||||
*/
|
||||
class Unit {
|
||||
//put your code here
|
||||
private static $db;
|
||||
|
||||
const SHOW_BY_DEFAULT = 10;
|
||||
|
||||
public function __construct() {
|
||||
self::$db = Db::getConnection();
|
||||
}
|
||||
|
||||
public static function setRequest($user_id, $id_print, $description){
|
||||
|
||||
$db = Db::getConnection();
|
||||
$date = strval(time());
|
||||
$status = 1;
|
||||
//$username = $user_id;
|
||||
//$id_prn = intval($id_print);
|
||||
//$description = htmlspecialchars($description);
|
||||
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("INSERT INTO requests (date_create, user, id_print, description, status) VALUES (:date_create, :user, :id_print, :description, :status)");
|
||||
$stmt->bindParam(':date_create', $date);
|
||||
$stmt->bindParam(':user', $user_id);
|
||||
$stmt->bindParam(':id_print', $id_print);
|
||||
$stmt->bindParam(':description', $description);
|
||||
$stmt->bindParam(':status', $status);
|
||||
|
||||
$stmt->execute();
|
||||
return $db->lastInsertId();
|
||||
}
|
||||
|
||||
public static function createNewAction($id_request, $act, $user){
|
||||
$db = Db::getConnection();
|
||||
$date = strval(time());
|
||||
if($act === 0) {$action = 1;}
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO actions_request (request_id, action_id, date, user) VALUES (:request_id, :action, :date, :user)");
|
||||
$stmt->bindParam(':request_id', $id_request);
|
||||
$stmt->bindParam(':action', $action);
|
||||
$stmt->bindParam(':date', $date);
|
||||
$stmt->bindParam(':user', $user);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
public static function getAllActionByIDRequest($id_request){
|
||||
$db = Db::getConnection();
|
||||
$sql = "SELECT
|
||||
actions_request.id AS id,
|
||||
actions_request.request_id AS request_id,
|
||||
actions_request.action_id AS action_id,
|
||||
actions_request.description AS description,
|
||||
actions_request.date AS date,
|
||||
actions_request.user AS user,
|
||||
actions.name AS actname
|
||||
FROM actions_request
|
||||
LEFT JOIN actions ON actions.id = actions_request.action_id
|
||||
WHERE actions_request.request_id=".$id_request.";";
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$actions = NULL;
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
//if($row == NULL) return NULL;
|
||||
foreach($row as $key=>$value){
|
||||
$actions[$i][$key] = $value;
|
||||
//$actions[$i]['docs'] = self::getAllLinkByActionID($actions[$i]['id']);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
for($i=0; count($actions)>$i; $i++){
|
||||
$actions[$i]['docs'] = self::getAllLinkByActionID($actions[$i]['id']);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public static function getAllLinkByActionID($id){
|
||||
$docs = false;
|
||||
$db = Db::getConnection();
|
||||
$sql = "SELECT docname, link, id_request, id_actions FROM doc_for_requests WHERE id_actions=".$id.";";
|
||||
$result = $db->query($sql);
|
||||
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
//if($row == NULL) return NULL;
|
||||
foreach($row as $key=>$value){
|
||||
$docs[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $docs;
|
||||
}
|
||||
|
||||
public static function getRequests($page){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$page = intval($page);
|
||||
$offset = ($page - 1) * self::SHOW_BY_DEFAULT;
|
||||
$sql ="";
|
||||
//$sql = "SELECT * FROM requests ORDER BY id DESC LIMIT ".self::SHOW_BY_DEFAULT." OFFSET ".$offset;
|
||||
$sql .= "SELECT
|
||||
requests.id AS id,
|
||||
requests.date_create AS date_create,
|
||||
requests.user AS user,
|
||||
requests.id_print AS id_print,
|
||||
print.name AS printname,
|
||||
print.unit AS unit,
|
||||
print.model AS printmodel,
|
||||
requests.description,
|
||||
requests.status AS id_status,
|
||||
request_status.name AS status,
|
||||
requests.date_close
|
||||
FROM requests
|
||||
LEFT JOIN print ON requests.id_print = print.id
|
||||
LEFT JOIN request_status ON requests.status = request_status.id";
|
||||
$sql .= " ORDER BY id DESC LIMIT ".self::SHOW_BY_DEFAULT." OFFSET ".$offset;
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
|
||||
$list = NULL;
|
||||
|
||||
$i = 0;
|
||||
while($row = $result->fetch()){
|
||||
if($row == NULL) break;
|
||||
foreach($row as $key=>$value){
|
||||
$list[$i][$key] = $value;
|
||||
$list[$i]['actions'] = self::getAllActionByIDRequest($list[$i]['id']);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getTotalRequests(){
|
||||
$db = Db::getConnection();
|
||||
|
||||
$result = $db->query('SELECT count(id) AS count FROM requests');
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$row = $result->fetch();
|
||||
|
||||
return $row['count'];
|
||||
}
|
||||
|
||||
public static function getRequestByID($id){
|
||||
$db = Db::getConnection();
|
||||
$sql = "SELECT
|
||||
requests.id AS id,
|
||||
requests.date_create AS date_create,
|
||||
requests.user AS user,
|
||||
requests.id_print AS id_print,
|
||||
print.name AS printname,
|
||||
print.unit AS unit,
|
||||
print.model AS printmodel,
|
||||
print.img AS img,
|
||||
requests.description,
|
||||
requests.status AS id_status,
|
||||
request_status.name AS status,
|
||||
requests.date_close
|
||||
FROM requests
|
||||
LEFT JOIN print ON requests.id_print = print.id
|
||||
LEFT JOIN request_status ON requests.status = request_status.id
|
||||
WHERE requests.id =".$id.";";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$row = $result->fetch();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function getStringJSONbyModal($data){
|
||||
$data['user'] = $_SESSION['user_id'];
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
public static function setNewActions(){
|
||||
|
||||
$request_id = filter_input(INPUT_POST, 'request_id');
|
||||
$user = filter_input(INPUT_POST, 'user');
|
||||
$date = filter_input(INPUT_POST, 'date'); //2017-10-27
|
||||
$action_id = filter_input(INPUT_POST, 'action_id');
|
||||
$description = filter_input(INPUT_POST, 'description');
|
||||
//$docs = filter_input(INPUT_POST, 'docs');
|
||||
$arr_date = explode("-", $date);
|
||||
$U_date = mktime(0,0,0,$arr_date[1],$arr_date[2],$arr_date[0]); //"2017-10-27"
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
if($action_id == 2){
|
||||
$stmt = $db->prepare("UPDATE requests SET status=2 WHERE id=:id");
|
||||
$stmt->bindParam(':id', $request_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
}elseif($action_id == 4){
|
||||
$stmt = $db->prepare("UPDATE requests SET status=3, date_close=:date WHERE id=:id");
|
||||
$stmt->bindParam(':id', $request_id, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':date', $U_date);
|
||||
$stmt->execute();
|
||||
}
|
||||
//внесение денных об изменениях принтера в бд
|
||||
$stmt = $db->prepare("INSERT INTO actions_request (request_id, action_id, description, date, user) VALUES (:request_id, :action_id, :description, :date, :user)");
|
||||
$stmt->bindParam(':date', $U_date);
|
||||
$stmt->bindParam(':request_id', $request_id);
|
||||
$stmt->bindParam(':user', $user);
|
||||
$stmt->bindParam(':description', $description);
|
||||
$stmt->bindParam(':action_id', $action_id);
|
||||
|
||||
$stmt->execute();
|
||||
return $db->lastInsertId();
|
||||
}
|
||||
|
||||
public static function setNewDocs($id_action, $id_request, $docs){
|
||||
|
||||
$links = explode("\n", $docs);
|
||||
|
||||
$link = array_slice($links, 0, (count($links)-1));
|
||||
|
||||
$docs = [];
|
||||
for($i=0; count($link)>$i;$i++){
|
||||
$docs[$i]['name'] = substr(strrchr($link[$i], "/"), 1); //обрезаем ссылку и получаем имя файла
|
||||
$docs[$i]['link'] = $link[$i]; //обрезаем ссылку и получаем имя файла
|
||||
}
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
for($j=0;count($docs)>$j;$j++){
|
||||
$docname = $docs[$j]['name'];
|
||||
$doclink = $docs[$j]['link'];
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO doc_for_requests (link, docname, id_request, id_actions) VALUES (:link, :docname, :id_request, :id_actions)");
|
||||
$stmt->bindParam(':link', $doclink);
|
||||
$stmt->bindParam(':docname', $docname);
|
||||
$stmt->bindParam(':id_request', $id_request);
|
||||
$stmt->bindParam(':id_actions', $id_action);
|
||||
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function saveOrder($user, $data){
|
||||
|
||||
/*array(3) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
["cartrige"]=>
|
||||
string(1) "1"
|
||||
["quatity"]=>
|
||||
string(1) "3"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
["cartrige"]=>
|
||||
string(1) "2"
|
||||
["quatity"]=>
|
||||
string(0) ""
|
||||
}*/
|
||||
|
||||
for($i=0; $i < count($data)-1; $i++){
|
||||
$a = "Заказ ".$data[$i]['quantity']." шт";
|
||||
self::setToHistoryCartridges($user, $data[$i]['cartrige'], $a);
|
||||
/*$a = "Заказ ".$data[$i]['quantity']." штук";
|
||||
self::setToHistoryCartridges($user, $data[$i]['cartrige'], $a);*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function setToHistoryCartridges($user, $id_catridge, $action){
|
||||
$db = Db::getConnection();
|
||||
$stmt = $db->prepare("INSERT INTO history_cartridges (user, date, id_cartridge, action) VALUES (:user, UNIX_TIMESTAMP(), :id_cartridge, :action)");
|
||||
$stmt->bindParam(':user', $user);
|
||||
$stmt->bindParam(':id_cartridge', $id_catridge);
|
||||
$stmt->bindParam(':action', $action);
|
||||
$stmt->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of user
|
||||
*
|
||||
* @author andrey
|
||||
*/
|
||||
class user {
|
||||
//put your code here
|
||||
|
||||
/*public static function register($name, $password, $email){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = 'INSERT INTO user (name, password, email) VALUES (:name, :password, :email)';
|
||||
|
||||
$result = $db->prepare($sql);
|
||||
$result->bindParam(':name', $name, PDO::PARAM_STR);
|
||||
$result->bindParam(':password', $password, PDO::PARAM_STR);
|
||||
$result->bindParam(':email', $email, PDO::PARAM_STR);
|
||||
|
||||
return $result->execute();
|
||||
|
||||
}*/
|
||||
|
||||
public static function checkAuth(){
|
||||
if(isset($_SESSION['user_id'])) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public static function checkAdmin(){
|
||||
if(isset($_SESSION['user_id']) && ($_SESSION['department'] == "Отдел информационных технологий")) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/* public static function checkName($name){
|
||||
|
||||
if(strlen($name) >= 2){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function checkPassword($password){
|
||||
|
||||
if(strlen($password) >= 6){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function checkEmail($email){
|
||||
|
||||
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function checkEmailExists($email){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = 'SELECT COUNT(*) FROM user WHERE email = :email';
|
||||
|
||||
$result = $db->prepare($sql);
|
||||
$result->bindParam(':email', $email, PDO::PARAM_STR);
|
||||
$result->execute();
|
||||
|
||||
if($result->fetchColumn())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function checkUserData($email, $password){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = 'SELECT * FROM user WHERE email = :email AND password = :password';
|
||||
|
||||
$result = $db->prepare($sql);
|
||||
$result->bindParam(':email', $email, PDO::PARAM_INT);
|
||||
$result->bindParam(':password', $password, PDO::PARAM_INT);
|
||||
$result->execute();
|
||||
|
||||
$user = $result->fetch();
|
||||
if($user){
|
||||
return $user['id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function checkLogged(){
|
||||
|
||||
if($_SESSION['user']){
|
||||
return $_SESSION['user'];
|
||||
}
|
||||
|
||||
header("location: /user/login/");
|
||||
}
|
||||
|
||||
public static function auth($userId){
|
||||
|
||||
$_SESSION['user'] = $userId;
|
||||
}
|
||||
|
||||
public static function isGuest(){
|
||||
if(isset($_SESSION['user'])){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getUserById($id) {
|
||||
if ($id){
|
||||
|
||||
$db = Db::getConnection();
|
||||
|
||||
$sql = 'SELECT * FROM user WHERE id = :id';
|
||||
$result = $db->prepare($sql);
|
||||
$result->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$result->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$result->execute();
|
||||
|
||||
return $result->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit($id, $name, $password, $email){
|
||||
|
||||
$db = DB::getConnection();
|
||||
|
||||
$sql = 'UPDATE user SET name=:name, password=:password, email=:email WHERE id=:id';
|
||||
|
||||
$result = $db->prepare($sql);
|
||||
$result->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$result->bindParam(':name', $name, PDO::PARAM_INT);
|
||||
$result->bindParam(':password', $password, PDO::PARAM_INT);
|
||||
$result->bindParam(':email', $email, PDO::PARAM_INT);
|
||||
return $result->execute();
|
||||
}*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user