You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB
PHTML

2 years ago
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
// $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE , PDO::FETCH_ASSOC );
$terminals = array();
$ts = time();
$result = array('res' => 0, 'data' => array());
$lineId = isset($_POST['lineId']) ? intval($_POST['lineId']) : 0;
$cmdids = isset($_POST['cmdids']) ? $_POST['cmdids'] : '';
$channels = isset($_POST['channels']) ? intval($_POST['channels']) : 1;
$protocol = isset($_POST['protocol']) ? intval($_POST['protocol']) : 0;
1 year ago
$devType = isset($_POST['dev_type']) ? intval($_POST['dev_type']) : 1;
2 years ago
$contents = str_replace("\r\n", "\n", $cmdids);
$contents = str_replace("\n\r", "\n", $contents);
$contents = str_replace("\r", "\n", $contents);
$cmdids = explode("\n", $contents);
$stmt = $db->prepare("SELECT * FROM `lines` WHERE `id`=" . $lineId);
$stmt->execute();
$rows = $stmt->fetchAll();
$stmt = null;
$lineName = '';
if ($rows)
{
$lineName = $rows[0]['name'];
}
$ids = array();
$rows = array();
foreach ($cmdids as $cmdid)
{
$cmdid = trim($cmdid);
if (empty($cmdid)) continue;
$db->query("INSERT INTO `towers`(`line_id`, `name`) VALUES($lineId, '" . $cmdid . "')");
$tower_id = $db->lastInsertId();
1 year ago
$db->query("INSERT INTO `terminals`(`line_id`, `tower_id`, `cmdid`, `protocol`,`dev_type`) VALUES($lineId, " . $tower_id . ",'" . $cmdid . "'," . $protocol . "," . $devType . ")");
2 years ago
$term_id = $db->lastInsertId();
for ($channel = 1; $channel <= $channels; $channel++)
{
$db->query("INSERT INTO `terminal_channel_mapper`(`term_id`, `channel_id`) VALUES(" . $term_id . "," . $channel . ")");
}
$ids[] = $term_id;
$row['id'] = $term_id;
$row['cmdid'] = $cmdid;
$row['protocol'] = $protocol;
$row['line_name'] = $lineName;
$row['tower_name'] = $cmdid;
$row['display_name'] = '';
$rows[] = $row;
unset($row);
}
$result['data'] = $rows;
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);