47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
||
|
|
|
||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
|
$sql = "SET NAMES 'utf8'";
|
||
|
|
$pdo->query($sql);
|
||
|
|
|
||
|
|
/*error_reporting(E_ALL | E_STRICT);
|
||
|
|
ini_set('display_errors', 1);*/
|
||
|
|
$object_id = 0;
|
||
|
|
$result = array();
|
||
|
|
|
||
|
|
if(isset($_SESSION['id']) && isset($_GET['id'])){
|
||
|
|
$object_id = (int)$_GET['id'];
|
||
|
|
|
||
|
|
if($object_id > 0){
|
||
|
|
$user = new User;
|
||
|
|
$user->get($_SESSION['id']);
|
||
|
|
$types = array();
|
||
|
|
$types[] = 4;
|
||
|
|
$sql_types = "SELECT id FROM requisitions_type WHERE heir = 4 AND agency_id = {$user->agencyId}";
|
||
|
|
|
||
|
|
$q_types = $pdo->query($sql_types, true);
|
||
|
|
while($r_types = $pdo->fetch_assoc($q_types)){
|
||
|
|
$types[] = (int)$r_types['id'];
|
||
|
|
}
|
||
|
|
$sql = "SELECT id, name, client_id FROM requisitions WHERE object_id={$object_id} AND type_id in (".implode(',',$types).") AND cancel=0 AND deleted = 0";
|
||
|
|
$q = $pdo->query($sql);
|
||
|
|
while($r = $pdo->fetch_assoc($q)){
|
||
|
|
$phone = '';
|
||
|
|
if($r['client_id'] > 0){
|
||
|
|
$sql_c = "SELECT phone FROM clients WHERE id = {$r['client_id']}";
|
||
|
|
$q_c = $pdo->query($sql_c);
|
||
|
|
$phone = mask_phone_value_if_needed($pdo->result($q_c));
|
||
|
|
}
|
||
|
|
$res['value'] = $r['id'];
|
||
|
|
$res['text'] = $r['name'];
|
||
|
|
if(!empty($phone)){
|
||
|
|
$res['text'] .= ' ('.$phone.')';
|
||
|
|
}
|
||
|
|
$result[] = $res;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|