139 lines
3.8 KiB
PHP
139 lines
3.8 KiB
PHP
|
|
<?php
|
||
|
|
//var_dump($_POST);
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
|
|
error_reporting(E_ALL | E_STRICT);
|
||
|
|
ini_set('display_errors', 1);
|
||
|
|
$get = clearInputData($_GET);
|
||
|
|
|
||
|
|
if (!$_SESSION['id']) {
|
||
|
|
die("Нет сессии");
|
||
|
|
}
|
||
|
|
|
||
|
|
if(isset($get['id']) && is_numeric($get['id']))
|
||
|
|
{
|
||
|
|
$agencyId = User::getUserAgencyID();
|
||
|
|
|
||
|
|
$usersIds = array();
|
||
|
|
$usersIds[] = $agencyId;
|
||
|
|
$sql_users = "SELECT id FROM users WHERE id in (select id from users where id=$agencyId or id_manager=$agencyId or id_manager in
|
||
|
|
(select id from users where id_manager=$agencyId or id_manager in
|
||
|
|
(select id from users where id_manager=$agencyId)))";
|
||
|
|
$q_users = mysql_query($sql_users);
|
||
|
|
while($r_users = mysql_fetch_assoc($q_users)){
|
||
|
|
$usersIds[] = (int)$r_users['id'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$sqlClient = "select id, phone, email, objects, summa, budget from clients where id = $get[id] and (id_agent in (".implode(',', $usersIds).") or who_work in (".implode(',', $usersIds)."))";
|
||
|
|
$clientRes = mysql_query($sqlClient);
|
||
|
|
if (mysql_num_rows($clientRes) > 0) {
|
||
|
|
$client = new Clients;
|
||
|
|
$client->del($get['id']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(isset($get['restore']) && is_numeric($get['restore']))
|
||
|
|
{
|
||
|
|
$client = new Clients;
|
||
|
|
$client->restore($get['restore']);
|
||
|
|
}
|
||
|
|
|
||
|
|
/*if(is_numeric($get['reason']))
|
||
|
|
{
|
||
|
|
$client = new Clients();
|
||
|
|
$get['id_del_client'] = $get['reason'];
|
||
|
|
$client->delReason($get);
|
||
|
|
}*/
|
||
|
|
|
||
|
|
if(isset($_POST['id_del_client']))
|
||
|
|
{
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
if($post['req_id'] > 0){
|
||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
|
$sql = "SET NAMES 'utf8'";
|
||
|
|
$pdo->query($sql);
|
||
|
|
$req = new Requisitions($pdo);
|
||
|
|
$req->deleteReq($post['req_id'], $_SESSION['id'], $post);
|
||
|
|
} else if($post['id_del_client']){
|
||
|
|
$client = new Clients;
|
||
|
|
$client->delReason($post);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if(!empty($_POST['id_del_client_all']))
|
||
|
|
{
|
||
|
|
$all = 0;
|
||
|
|
$clients = json_decode($_POST['id_del_client_all']);
|
||
|
|
if(isset($_POST['all']) && $_POST['all'] > 0){
|
||
|
|
$all = (int)$_POST['all'];
|
||
|
|
}
|
||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
|
$sql = "SET NAMES 'utf8'";
|
||
|
|
$pdo->query($sql);
|
||
|
|
|
||
|
|
if($all == 1){
|
||
|
|
if(isset($_SESSION['where_campaigns'])){
|
||
|
|
$where = $_SESSION['where_campaigns'];
|
||
|
|
$sql = "SELECT id FROM clients WHERE 1 ".$where;
|
||
|
|
$q = $pdo->query($sql);
|
||
|
|
while($r = $pdo->fetch_assoc($q)){
|
||
|
|
$_POST['id_del_client'] = $r['id'];
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
$client = new Clients;
|
||
|
|
$client->delReason($post);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
exit();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
foreach($clients as $cl){
|
||
|
|
$_POST['id_del_client'] = $cl;
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
$client = new Clients;
|
||
|
|
$client->delReason($post);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if(isset($_POST['id_del_req_all']))
|
||
|
|
{
|
||
|
|
$reqs = json_decode($_POST['id_del_req_all']);
|
||
|
|
|
||
|
|
$all = 0;
|
||
|
|
if(isset($_POST['all']) && $_POST['all'] > 0){
|
||
|
|
$all = (int)$_POST['all'];
|
||
|
|
}
|
||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
|
$sql = "SET NAMES 'utf8'";
|
||
|
|
$pdo->query($sql);
|
||
|
|
|
||
|
|
$ids = array();
|
||
|
|
if(isset($_POST['ids_exception'])){
|
||
|
|
$ids = $_POST['ids_exception'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if($all == 1){
|
||
|
|
$reqs = array();
|
||
|
|
if(isset($_SESSION['where_req_campaigns'])){
|
||
|
|
$sql = $_SESSION['where_req_campaigns'];
|
||
|
|
if (!empty($ids)){
|
||
|
|
$sql .= " AND ID NOT IN (".implode(',', $ids).")";
|
||
|
|
}
|
||
|
|
echo $sql;
|
||
|
|
$q = $pdo->query($sql);
|
||
|
|
while($r = $pdo->fetch_assoc($q)) {
|
||
|
|
$reqs[] = $r['id'];
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
exit();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$req = new Requisitions($pdo);
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
//var_dump($reqs);
|
||
|
|
foreach($reqs as $req_id){
|
||
|
|
$req->deleteReq($req_id, $_SESSION['id'], $post);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
?>
|