Commit db3df6d5 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Convert to iterator and remove backquotes on ajax dir

parent a93004f5
......@@ -48,69 +48,98 @@ if (class_exists($_POST["itemtype"])
&& isset($_POST["item"])) {
$table = getTableForItemType($_POST["itemtype"]);
$joins = [];
$name_field = new QueryExpression("'' AS " . $DB->quoteName('npname'));
if ($_POST['instantiation_type'] == 'NetworkPortEthernet') {
$npname_field = "`glpi_netpoints`.`name`";
$JOINS = "LEFT JOIN `glpi_networkportethernets`
ON (`glpi_networkportethernets`.`id` = `glpi_networkports`.`id`)
LEFT JOIN `glpi_netpoints`
ON (`glpi_netpoints`.`id`=`glpi_networkportethernets`.`netpoints_id`)";
} else {
$npname_field = "''";
$JOINS = "";
$name_field = 'glpi_netpoints.name AS npname';
$joins = [
'glpi_networkportethernets' => [
'ON' => [
'glpi_networkportethernets' => 'id',
'glpi_networkports' => 'id'
]
],
'glpi_netpoints' => [
'ON' => [
'glpi_networkportethernets' => 'netpoints_id',
'glpi_netpoints' => 'id'
]
]
];
}
$query = "SELECT DISTINCT `glpi_networkports_networkports`.`id` AS wid,
`glpi_networkports`.`id` AS did,
`$table`.`name` AS cname,
`glpi_networkports`.`name` AS nname,
$npname_field AS npname
FROM `$table`
LEFT JOIN `glpi_networkports`
ON (`glpi_networkports`.`items_id` = '".$_POST['item']."'
AND `glpi_networkports`.`itemtype` = '".$_POST["itemtype"]."'
AND `glpi_networkports`.`items_id` = `$table`.`id`
AND `glpi_networkports`.`instantiation_type` = '".$_POST['instantiation_type']."')
LEFT JOIN `glpi_networkports_networkports`
ON (`glpi_networkports_networkports`.`networkports_id_1` = `glpi_networkports`.`id`
OR `glpi_networkports_networkports`.`networkports_id_2`=`glpi_networkports`.`id`)
$JOINS
WHERE `glpi_networkports_networkports`.`id` IS NULL
AND `glpi_networkports`.`id` IS NOT NULL
AND `glpi_networkports`.`id` <> '".$_POST['networkports_id']."'
AND `$table`.`is_deleted` = 0
AND `$table`.`is_template` = 0
ORDER BY `glpi_networkports`.`id`";
$result = $DB->query($query);
$criteria = [
'SELECT' => [
'glpi_networkports_networkports.id AS wid',
'glpi_networkports.id AS did',
"$table.name AS cname",
'glpi_networkports.name AS nname',
$name_field
],
'DISTINCT' => true,
'FROM' => $table,
'LEFT JOIN' => [
'glpi_networkports' => [
'ON' => [
'glpi_networkports' => 'items_id',
$table => 'id', [
'AND' => [
'glpi_networkports.items_id' => $_POST['item'],
'glpi_networkports.itemtype' => $_POST["itemtype"],
'glpi_networkports.instantiation_type' => $_POST['instantiation_type']
]
]
]
],
'glpi_networkports_networkports' => [
'ON' => [
'glpi_networkports_networkports' => 'networkports_id_1',
'glpi_networkports' => 'id', [
'OR' => [
'glpi_networkports_networkports.networkports_id_2' => $DB->quoteName('glpi_networkports.id')
]
]
]
]
] + $joins,
'WHERE' => [
'glpi_networkports_networkports.id' => null,
'NOT' => ['glpi_networkports.id' => null],
'glpi_networkports.id' => ['<>', $_POST['networkports_id']],
"$table.is_deleted" => 0,
"$table.is_template" => 0
],
'ORDERBY' => 'glpi_networkports.id'
];
$iterator = $Db->request($criteria);
echo "<br>";
$values = [];
if ($DB->numrows($result)) {
while ($data = $DB->fetchAssoc($result)) {
// Device name + port name
$output = $output_long = $data['cname'];
while ($data = $iterator->next()) {
// Device name + port name
$output = $output_long = $data['cname'];
if (!empty($data['nname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['nname']);
//TRANS: %1$s is device name, %2$s is port name
$output_long = sprintf(__('%1$s - The port %2$s'), $output_long, $data['nname']);
}
if (!empty($data['nname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['nname']);
//TRANS: %1$s is device name, %2$s is port name
$output_long = sprintf(__('%1$s - The port %2$s'), $output_long, $data['nname']);
}
// display netpoint (which will be copied)
if (!empty($data['npname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['npname']);
//TRANS: %1$s is a string (device name - port name...), %2$s is network outlet name
$output_long = sprintf(__('%1$s - Network outlet %2$s'), $output_long, $data['npname']);
}
$ID = $data['did'];
// display netpoint (which will be copied)
if (!empty($data['npname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['npname']);
//TRANS: %1$s is a string (device name - port name...), %2$s is network outlet name
$output_long = sprintf(__('%1$s - Network outlet %2$s'), $output_long, $data['npname']);
}
$ID = $data['did'];
if ($_SESSION["glpiis_ids_visible"] || empty($output) || empty($output_long)) {
$output = sprintf(__('%1$s (%2$s)'), $output, $ID);
$output_long = sprintf(__('%1$s (%2$s)'), $output_long, $ID);
}
$values[$ID] = $output_long;
if ($_SESSION["glpiis_ids_visible"] || empty($output) || empty($output_long)) {
$output = sprintf(__('%1$s (%2$s)'), $output, $ID);
$output_long = sprintf(__('%1$s (%2$s)'), $output_long, $ID);
}
$values[$ID] = $output_long;
}
Dropdown::showFromArray($_POST['myname'], $values, ['display_emptychoice' => true]);
}
......@@ -44,41 +44,43 @@ if ($_POST['softwares_id'] > 0) {
$_POST['value'] = 0;
}
$where = '';
$where = [];
if (isset($_POST['used'])) {
$used = $_POST['used'];
if (count($used)) {
$where = " AND `glpi_softwareversions`.`id` NOT IN ('".implode("','", $used)."')";
$where = ['NOT' => ['glpi_softwareversions.id' => $used]];
}
}
// Make a select box
$query = "SELECT DISTINCT `glpi_softwareversions`.*,
`glpi_states`.`name` AS sname
FROM `glpi_softwareversions`
LEFT JOIN `glpi_states` ON (`glpi_softwareversions`.`states_id` = `glpi_states`.`id`)
WHERE `glpi_softwareversions`.`softwares_id` = '".$_POST['softwares_id']."'
$where
ORDER BY `name`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$iterator = $DB->request([
'SELECT' => ['glpi_softwareversions.*', 'glpi_states.name AS sname'],
'DISTINCT' => true,
'FROM' => 'glpi_softwareversions',
'LEFT JOIN' => [
'glpi_states' => [
'ON' => [
'glpi_softwareversions' => 'states_id',
'glpi_states' => 'id'
]
]
],
'WHERE' => ['glpi_softwareversions.softwares_id' => $_POST['softwares_id']] + $where
]);
$number = count($iterator);
$values = [];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
$ID = $data['id'];
$output = $data['name'];
if (empty($output) || $_SESSION['glpiis_ids_visible']) {
$output = sprintf(__('%1$s (%2$s)'), $output, $ID);
}
if (!empty($data['sname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['sname']);
}
$values[$ID] = $output;
while ($data = $iterator->next()) {
$ID = $data['id'];
$output = $data['name'];
if (empty($output) || $_SESSION['glpiis_ids_visible']) {
$output = sprintf(__('%1$s (%2$s)'), $output, $ID);
}
if (!empty($data['sname'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $data['sname']);
}
$values[$ID] = $output;
}
Dropdown::showFromArray($_POST['myname'], $values, ['display_emptychoice' => true]);
......
......@@ -44,21 +44,20 @@ if ($_POST['softwares_id'] > 0) {
$_POST['value'] = 0;
}
$restrict = getEntitiesRestrictRequest(' AND', 'glpi_softwarelicenses', 'entities_id',
$_POST['entity_restrict'], true);
// Make a select box
$query = "SELECT DISTINCT *
FROM `glpi_softwarelicenses`
WHERE `glpi_softwarelicenses`.`softwares_id` = '".$_POST['softwares_id']."'
$restrict
ORDER BY `name`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$iterator = $DB->request([
'DISTINCT' => true,
'FROM' => 'glpi_softwarelicenses',
'WHERE' => [
'glpi_softwarelicenses.softwares_id' => (int)$_POST['softwares_id']
] + getEntitiesRestrictCriteria('glpi_softwarelicenses', 'entities_id', $_POST['entity_restrict'], true),
'ORDERBY' => 'name'
]);
$number = count($iterator);
$values = [];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
while ($data = $iterator->next()) {
$ID = $data['id'];
$output = $data['name'];
......
......@@ -79,32 +79,43 @@ if (isset($_GET['node'])) {
}
} else { // standard node
$node_id = $_GET['node'];
$query = "SELECT ent.`id`, ent.`name`, ent.`sons_cache`, count(sub_entities.id) as nb_subs
FROM `glpi_entities` as ent
LEFT JOIN `glpi_entities` as sub_entities
ON sub_entities.entities_id = ent.id
WHERE ent.`entities_id` = '$node_id'
GROUP BY ent.`id`, ent.`name`, ent.`sons_cache`
ORDER BY `name`";
$iterator = $DB->request([
'SELECT' => [
'ent.id',
'ent.name',
'ent.sons_cache',
'COUNT' => 'sub_entities.id AS nb_subs'
],
'FROM' => 'glpi_entities as ent',
'LEFT JOIN' => [
'glpi_entities AS sub_entities' => [
'ON' => [
'sub_entities' => 'entities_id',
'ent' => 'id'
]
]
],
'WHERE' => ['ent.entities_id' => $node_id],
'GROUPBY' => ['ent.id', 'ent.name', 'ent.sons_cache'],
'ORDERBY' => 'name'
]);
if ($result = $DB->query($query)) {
while ($row = $DB->fetchAssoc($result)) {
$path = [
'id' => $row['id'],
'text' => $row['name']
];
while ($row = $iterator->next()) {
$path = [
'id' => $row['id'],
'text' => $row['name']
];
if ($row['nb_subs'] > 0) {
//apend a i tag (one of shortest tags) to have the is_recursive link
$path['text'].= '<i/>';
$path['children'] = true;
if ($row['nb_subs'] > 0) {
//apend a i tag (one of shortest tags) to have the is_recursive link
$path['text'].= '<i/>';
$path['children'] = true;
if (isset($ancestors[$row['id']])) {
$path['state']['opened'] = 'true';
}
if (isset($ancestors[$row['id']])) {
$path['state']['opened'] = 'true';
}
$nodes[] = $path;
}
$nodes[] = $path;
}
}
echo json_encode($nodes);
......
......@@ -48,12 +48,14 @@ if ($_POST['items_id']
$linktype = $devicetype::getItem_DeviceType();
if (count($linktype::getSpecificities())) {
$keys = array_keys($linktype::getSpecificities());
array_walk($keys, function (&$val) use ($DB) { return $DB->quoteName($val); });
$name_field = new QueryExpression(
"CONCAT_WS(' - ', `" . implode('`, `', array_keys($linktype::getSpecificities())) . "`)"
. "AS `name`"
"CONCAT_WS(' - ', " . implode(', ', $keys) . ")"
. "AS ".$DB->quoteName("name")
);
} else {
$name_field = "id AS name";
$name_field = 'id AS name';
}
$result = $DB->request(
[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment