Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- Make the plugin compatible with the Content Security Policy (requires the GLPI release with CSP support)

### Fixed

- Faster order form, reception, bills and budget tabs on large volumes (missing indexes, budget check and prices read in one query)
Expand Down
1 change: 0 additions & 1 deletion ajax/linkactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
case "update_entity":
Entity::dropdown(['name' => "id[" . $_POST['id'] . "][entities_id]",
'value' => $_POST['value'],
'on_change' => "plugin_order_adaptOnSelectedEntity(" . $_POST['id'] . ", this.value);",
]);

$order_web_dir = $CFG_GLPI['root_doc'] . '/plugins/order';
Expand Down
11 changes: 5 additions & 6 deletions inc/bill.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ public static function showOrder($data_ref, $result_ref, $canedit, $order, $refe
$itemtype = $data_ref["itemtype"];
$item = getItemForItemtype($itemtype);
echo "<tr><th><ul class='list-unstyled'><li>";
echo sprintf("<a href=\"javascript:showHideDiv('generation%d','generation_img%d', '", $rand, $rand)
. $CFG_GLPI['root_doc'] . "/pics/plus.png','" . $CFG_GLPI['root_doc'] . "/pics/moins.png');\">";
echo sprintf("<a href='#' data-order-show-div='generation%d' data-order-show-img='generation_img%d'>", $rand, $rand);
echo sprintf("<img alt='' name='generation_img%d' src=\"", $rand) . $CFG_GLPI['root_doc'] . '/pics/plus.png">';
echo "</a>";
echo "</li></ul></th>";
Expand Down Expand Up @@ -479,12 +478,12 @@ public static function showOrder($data_ref, $result_ref, $canedit, $order, $refe
echo "<div class='center'>";
echo "<table width='950px' class='tab_glpi'>";
echo "<tr><td<i class='fas fa-level-up-alt fa-flip-horizontal fa-lg mx-2'></i></td><td class='center'>";
echo sprintf("<a onclick= \"if ( markCheckboxes('bills_form%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Check all") . "</a></td>";
echo sprintf("<a data-order-mark-checkboxes='bills_form%d' href='#'>", $rand)
. __s("Check all") . "</a></td>";

echo "<td>/</td><td class='center'>";
echo sprintf("<a onclick= \"if ( unMarkCheckboxes('bills_form%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Uncheck all") . "</a>";
echo sprintf("<a data-order-unmark-checkboxes='bills_form%d' href='#'>", $rand)
. __s("Uncheck all") . "</a>";
echo "</td><td align='left' width='80%'>";
echo Html::hidden('plugin_order_orders_id', ['value' => $order->getID()]);
$order_item->dropdownBillItemsActions($order->getID());
Expand Down
12 changes: 6 additions & 6 deletions inc/order.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1696,9 +1696,9 @@ public function showValidationForm($orders_id)
$link = "";

if ($this->canCancelOrder()) {
echo "<input type='submit' onclick=\"return confirm('"
echo "<input type='submit' data-order-confirm=\""
. __s("Do you really want to cancel this order ? This option is irreversible !", "order")
. "')\" name='cancel_order' value=\"" . __s("Cancel order", "order") . "\" class='submit'>";
. "\" name='cancel_order' value=\"" . __s("Cancel order", "order") . "\" class='submit'>";
$link = "<br><br>";
}

Expand All @@ -1709,9 +1709,9 @@ public function showValidationForm($orders_id)
}

if ($this->canCancelValidationRequest()) {
echo $link . "<input type='submit' onclick=\"return confirm('"
echo $link . "<input type='submit' data-order-confirm=\""
. __s("Do you want to cancel the validation approval ?", "order")
. "')\" name='cancel_waiting_for_approval' value=\""
. "\" name='cancel_waiting_for_approval' value=\""
. __s("Cancel ask for validation", "order") . "\" class='submit'>";
$link = "<br><br>";
}
Expand All @@ -1723,9 +1723,9 @@ public function showValidationForm($orders_id)
}

if ($this->canUndoValidation()) {
echo $link . "<input type='submit' onclick=\"return confirm('"
echo $link . "<input type='submit' data-order-confirm=\""
. __s("Do you really want to edit the order ?", "order")
. "')\" name='undovalidation' value=\""
. "\" name='undovalidation' value=\""
. __s("Edit order", "order") . "\" class='submit'>";
$link = "<br><br>";
}
Expand Down
13 changes: 6 additions & 7 deletions inc/order_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public function showAddForm($plugin_order_orders_id)
}

};");
echo "<input type='checkbox' id='addreference' onclick='plugin_order_checkboxAction()' name='addreference' value='0' />";
echo "<input type='checkbox' id='addreference' data-order-add-reference name='addreference' value='0' />";
echo "</span></td>";

echo "<td class='tab_bg_1' name='add_reference' style='display: none;'><span id='show_addreference'>";
Expand Down Expand Up @@ -1755,8 +1755,7 @@ public function showBillsItemsDetail($data_ref, $result_ref, $canedit, $order, $
$itemtype = $data_ref["itemtype"];
$item = getItemForItemtype($itemtype);
echo "<tr><th><ul class='list-unstyled'><li>";
echo sprintf("<a href=\"javascript:showHideDiv('generation%d','generation_img%d', '", $rand, $rand)
. $CFG_GLPI['root_doc'] . "/pics/plus.png','" . $CFG_GLPI['root_doc'] . "/pics/moins.png');\">";
echo sprintf("<a href='#' data-order-show-div='generation%d' data-order-show-img='generation_img%d'>", $rand, $rand);
echo sprintf("<img alt='' name='generation_img%d' src=\"", $rand) . $CFG_GLPI['root_doc'] . '/pics/plus.png">';
echo "</a>";
echo "</li></ul></th>";
Expand Down Expand Up @@ -1881,12 +1880,12 @@ public function showBillsItemsDetail($data_ref, $result_ref, $canedit, $order, $
echo "<div class='center'>";
echo "<table width='950px' class='tab_cadre_fixe left'>";
echo "<tr><td><i class='fas fa-level-up-alt fa-flip-horizontal fa-lg mx-2'></i></td><td class='center'>";
echo sprintf("<a onclick= \"if ( markCheckboxes('bills_form%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Check all") . "</a></td>";
echo sprintf("<a data-order-mark-checkboxes='bills_form%d' href='#'>", $rand)
. __s("Check all") . "</a></td>";

echo "<td>/</td><td class='center'>";
echo sprintf("<a onclick= \"if ( unMarkCheckboxes('bills_form%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Uncheck all") . "</a>";
echo sprintf("<a data-order-unmark-checkboxes='bills_form%d' href='#'>", $rand)
. __s("Uncheck all") . "</a>";
echo "</td><td align='left' width='80%'>";
echo Html::hidden('plugin_order_orders_id', ['value' => $order->getID()]);
$this->dropdownBillItemsActions($order->getID());
Expand Down
4 changes: 2 additions & 2 deletions inc/order_supplier.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ public static function showOrderSupplierInfos($ID)
echo "<tr>";
echo sprintf("<td><i class='%s fa-flip-horizontal fa-lg mx-2'></i></td>", $arrow);
echo "<td class='center' style='white-space:nowrap;'>";
echo sprintf("<a onclick= \"if ( markCheckboxes('%s') ) return false;\" href='#'>", $formname) . __s('Check all') . "</a></td>";
echo sprintf("<a data-order-mark-checkboxes='%s' href='#'>", htmlescape($formname)) . __s('Check all') . "</a></td>";
echo "<td>/</td>";
echo "<td class='center' style='white-space:nowrap;'>";
echo sprintf("<a onclick= \"if ( unMarkCheckboxes('%s') ) return false;\" href='#'>", $formname) . __s('Uncheck all') . "</a></td>";
echo sprintf("<a data-order-unmark-checkboxes='%s' href='#'>", htmlescape($formname)) . __s('Uncheck all') . "</a></td>";
echo "<td class='left' width='80%'>";

echo "<input type='submit' name='delete' ";
Expand Down
10 changes: 5 additions & 5 deletions inc/reception.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference,
$item = getItemForItemtype($typeRef);
$rand = mt_rand();
echo "<tr><th><ul class='list-unstyled'><li>";
echo sprintf("<a href=\"javascript:showHideDiv('reception%d','reception_img%d', '", $rand, $rand)
. $CFG_GLPI['root_doc'] . "/pics/plus.png','" . $CFG_GLPI['root_doc'] . "/pics/moins.png');\">";
echo sprintf("<a href='#' data-order-show-div='reception%d' data-order-show-img='reception_img%d'>", $rand, $rand);
echo sprintf("<img alt='' name='reception_img%d' src=\"", $rand) . $CFG_GLPI['root_doc'] . '/pics/plus.png">';
echo "</a>";
echo "</li></ul></th>";
Expand Down Expand Up @@ -507,7 +506,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference,
'rand' => $rand,
],
);
echo "&nbsp;<button type='button' class='btn btn-secondary btn-sm' onclick='selectNItems(\"mass" . self::class . sprintf("%d\", \"dropdown_nb_items_to_check_top_%d\")'>", $rand, $rand) . __s("Select") . "</button>";
echo sprintf("&nbsp;<button type='button' class='btn btn-secondary btn-sm' data-order-select-container='%s' data-order-select-target='%s'>", htmlescape('mass' . self::class . $rand), htmlescape('dropdown_nb_items_to_check_top_' . $rand)) . __s("Select") . "</button>";
echo "</span>";
}

Expand Down Expand Up @@ -625,7 +624,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference,
'rand' => $rand,
],
);
echo "&nbsp;<button type='button' class='btn btn-secondary btn-sm' onclick='selectNItems(\"mass" . self::class . sprintf("%d\", \"dropdown_nb_items_to_check_bottom_%d\")'>", $rand, $rand) . __s("Select") . "</button>";
echo sprintf("&nbsp;<button type='button' class='btn btn-secondary btn-sm' data-order-select-container='%s' data-order-select-target='%s'>", htmlescape('mass' . self::class . $rand), htmlescape('dropdown_nb_items_to_check_bottom_' . $rand)) . __s("Select") . "</button>";
echo "</span>";
}

Expand Down Expand Up @@ -685,7 +684,8 @@ private function displayBulkReceptionForm($order_order, $orders_id, $references_

if ($order_order->canDeliver() && $this->checkItemStatus($orders_id, $references_id, PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED) && $typeRef != 'SoftwareLicense') {
$bulk_rand = mt_rand();
$button = "<p><a href='javascript:viewmassreception" . $suffix . $orders_id . ($bulk_rand . "();'>");
$button_id = 'massreception_button' . $suffix . $orders_id . $bulk_rand;
$button = sprintf("<p><a href='#' id='%s' data-order-bulk-reception='%s'>", $button_id, htmlescape('viewmassreception' . $suffix . $orders_id . $bulk_rand));
$button .= __s("Take item delivery (bulk)", "order") . "</a></p>";
echo "<form method='post' name='order_reception_form{$suffix}{$bulk_rand}'
action='" . Toolbox::getItemTypeFormURL("PluginOrderReception") . "'>";
Expand Down
8 changes: 4 additions & 4 deletions inc/reference_supplier.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ public function showReferenceManufacturers($ID)
echo "<div class='center'>";
echo "<table width='900px' class='tab_glpi'>";
echo "<tr><td><i class='fas fa-level-up-alt fa-flip-horizontal fa-lg mx-2'></i></td>";
echo sprintf("<td class='center'><a onclick= \"if ( markCheckboxes('show_supplierref%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Check all") . "</a></td>";
echo sprintf("<td class='center'><a data-order-mark-checkboxes='show_supplierref%d' href='#'>", $rand)
. __s("Check all") . "</a></td>";

echo sprintf("<td>/</td><td class='center'><a onclick= \"if ( unMarkCheckboxes('show_supplierref%d') ) ", $rand)
. "return false;\" href='#'>" . __s("Uncheck all") . "</a>";
echo sprintf("<td>/</td><td class='center'><a data-order-unmark-checkboxes='show_supplierref%d' href='#'>", $rand)
. __s("Uncheck all") . "</a>";
echo "</td><td align='left' width='80%'>";
echo "<input type='submit' name='delete' value=\"" . __s("Delete permanently")
. "\" class='submit' >";
Expand Down
27 changes: 15 additions & 12 deletions inc/surveysupplier.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

use Glpi\DBAL\QueryExpression;

use function Safe\json_encode;

class PluginOrderSurveySupplier extends CommonDBChild
{
public static $rightname = 'plugin_order_order';
Expand Down Expand Up @@ -96,20 +98,21 @@ public function addNotation($field, $value)
}

echo "</select>";
echo sprintf("<div class='rateit' id='notation%d'></div>", $rand);
$rateit_options = [
'value' => $value,
'min' => 0,
'max' => 5,
'step' => 1,
'backingfld' => sprintf('#%s%d', $field, $rand),
'ispreset' => true,
'resetable' => false,
];
echo sprintf("<div class='rateit' id='notation%d' data-order-rateit='%s'></div>", $rand, htmlescape(json_encode($rateit_options)));
echo "</td>";
echo "</tr>";
echo "</table>";

echo "<script type='text/javascript'>\n";
echo sprintf("\$('#notation%d').rateit({value: '", $rand) . $value . "',
min : 0,
max : 5,
step: 1,
backingfld: '#{$field}{$rand}',
ispreset: true,
resetable: false});";
echo "</script>";
echo Html::script('/plugins/order/js/order_items.js', [], false);
}


Expand Down Expand Up @@ -474,10 +477,10 @@ public static function showOrderSupplierSurvey($ID)
echo "<tr>";
echo sprintf("<td><i class='%s fa-flip-horizontal fa-lg mx-2'></i></td>", $arrow);
echo "<td class='center' style='white-space:nowrap;'>";
echo sprintf("<a onclick= \"if ( markCheckboxes('%s') ) return false;\" href='#'>", $formname) . __s('Check all') . "</a></td>";
echo sprintf("<a data-order-mark-checkboxes='%s' href='#'>", htmlescape($formname)) . __s('Check all') . "</a></td>";
echo "<td>/</td>";
echo "<td class='center' style='white-space:nowrap;'>";
echo sprintf("<a onclick= \"if ( unMarkCheckboxes('%s') ) return false;\" href='#'>", $formname) . __s('Uncheck all') . "</a></td>";
echo sprintf("<a data-order-unmark-checkboxes='%s' href='#'>", htmlescape($formname)) . __s('Uncheck all') . "</a></td>";
echo "<td class='left' width='80%'>";

echo "<input type='submit' name='delete' ";
Expand Down
Loading