Joywork/ajax/getInnerSources.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
if ($_SESSION['id'] && $_GET['view'] == "option") {
$output = [];
$get = clearInputData($_GET);
$client_id = 0;
$req_id = 0;
$required = null;
if (isset($get['required']))
$required = $get['required'];
if(isset($get['client_id']))
$client_id = (int)$get['client_id'];
if(isset($get['req_id']))
$req_id = (int)$get['rq_id'];
//Поиск клиента по id заявки
if($req_id > 0){
$sql = "SELECT client_id FROM requisitions WHERE id = {$req_id}";
$q = mysql_query($sql);
if($r = mysql_fetch_assoc($q)){
$client_id = (int)$r['client_id'];
}
}
if ($options = Docs::getSourcesList($get['agency_id'], $get['section'], $required)) {
foreach ($options as $option) {
$name = $option['name'];
$selected = '';
if ($get['section'] == "clients") {
$contacts = [];
if($option['id'] == $client_id)
$selected = 'selected';
if (!empty($option['email']))
$contacts[] = $option['email'];
if (!empty($option['phone']))
$contacts[] = $option['phone'];
if (!empty($contacts))
$name .= ' (' . implode(', ', $contacts) . ')';
} else {
if (!empty($option['address']))
$name .= ' (' . $option['address'] . ')';
}
$output[] = '<option '.$selected.' value="' . $option['id'] . '">' . $name . '</option>';
}
}
echo implode("\r\n", $output);
}