Skip to content

Commit

Permalink
dont use session transferlist
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisTicgal committed Oct 17, 2023
1 parent 93fc979 commit 8276398
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
14 changes: 4 additions & 10 deletions ajax/quicktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@
$itemtype = $_GET['itemtype'];
$id = $_GET['items_id'];

if (!isset($_SESSION['glpitransfer_list'])) {
$_SESSION['glpitransfer_list'] = [];
}
if (!isset($_SESSION['glpitransfer_list'][$itemtype])) {
$_SESSION['glpitransfer_list'][$itemtype] = [];
}
$_SESSION['glpitransfer_list'][$itemtype][$id] = $id;
$transferlist = [];
$transferlist[$itemtype][$id] = $id;

$config = PluginYagpConfig::getInstance();
$item = new $itemtype();
Expand All @@ -73,11 +68,10 @@
) {
$glpitransfer = new Transfer();
$glpitransfer->moveItems(
$_SESSION['glpitransfer_list'],
$transferlist,
$config->fields['transfer_entity'],
PluginYagpTransfer::getCompleteTransferOptions()
);
unset($_SESSION['glpitransfer_list']);

$msg = __("Ticket transferred to %s", 'yagp');
$sprintf = sprintf(
Expand All @@ -92,6 +86,6 @@
echo "</div>";
echo "</div>";
} else {
$transfer->showTransferList();
$transfer->showTransferList($transferlist);
}
}
25 changes: 9 additions & 16 deletions front/transfer.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Html::header('yagp');

if (isset($_POST['transfer'])) {
if (isset($_SESSION['glpitransfer_list'])) {
if (isset($_POST['transferlist'])) {
if (!Session::haveAccessToEntity($_POST['to_entity'])) {
Html::displayRightError();
}
Expand All @@ -58,15 +58,19 @@
$_POST[$k] = isset($_POST[$k]) ? $_POST[$k] : $v;
}

$transfer->moveItems($_SESSION['glpitransfer_list'], $_POST['to_entity'], $_POST);
unset($_SESSION['glpitransfer_list']);
$transfer->moveItems(
json_decode(stripslashes($_POST['transferlist']), true),
$_POST['to_entity'],
$_POST
);

$entity = new Entity();
$entity->getFromDB($_POST['to_entity']);

$msg = __("Ticket transferred to %s", 'yagp');
$sprintf = sprintf(
__('Items have been transferred to %s', 'yapg'),
$entity->fields['completename']
$msg,
Dropdown::getDropdownName('glpi_entities', $_POST['to_entity'])
);

echo "<div class='d-flex w-100 justify-content-center align-items-center'>";
Expand All @@ -78,15 +82,4 @@

exit();
}
} elseif (isset($_POST['clear'])) {
unset($_SESSION['glpitransfer_list']);

echo "<div class='d-flex w-100 justify-content-center align-items-center'>";
echo "<div class='alert alert-info mt-4'>";
echo "<h3>" . __('Transfer list has been cleaned', 'yapg') . "</h3>";
echo "<span class='text-muted'>" . __('You can close this window', 'yagp') . "</span>";
echo "</div>";
echo "</div>";

exit();
}
10 changes: 10 additions & 0 deletions inc/postshowitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public static function quickTransfer(array $params): bool
$ajax_url = Plugin::getWebDir('yagp') . '/ajax/quicktransfer.php';
$ajax_url .= "?itemtype={$item->getType()}&items_id={$item->getID()}";
$ajax_title = __('Transfer to', 'yagp');
if (
$config->fields['autotransfer'] == 1
&& $config->fields['transfer_entity'] != $item->fields['entities_id']
) {
$entity_name = Dropdown::getDropdownName(
'glpi_entities',
$config->fields['transfer_entity']
);
$ajax_title .= " $entity_name";
}
$icon = "<i class='fa-fw fas fa-level-up-alt'></i>";
$btn_attrs = "class='btn col-auto col-xxl-12' data-bs-toggle='modal'";

Expand Down
12 changes: 7 additions & 5 deletions inc/transfer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function showForm($ID, array $options = [])

echo "<tr><td class='tab_bg_2 top' colspan='4'>";
echo "<div class='center'>";
echo "<input type='hidden' name='transferlist' value='" . json_encode($options['transferlist']) . "'>";
Entity::dropdown(['name' => 'to_entity']);
echo "&nbsp;<input type='submit' name='transfer' value=\"" . __s('Execute') . "\"
class='btn btn-primary'></div>";
Expand Down Expand Up @@ -310,12 +311,12 @@ class='btn btn-primary'></div>";
* Original from GLPI, adapted to modal frames
* @return void
*/
public function showTransferList()
public function showTransferList($transferlist = [])
{
global $DB, $CFG_GLPI;

echo "<div class='d-flex w-100 flex-column'>";
if (isset($_SESSION['glpitransfer_list']) && count($_SESSION['glpitransfer_list'])) {
if (isset($transferlist) && count($transferlist)) {
echo "<div class='my-2 text-center'>";
echo "<span>" . __('Think of making a backup before transferring items.') . "</span>";
echo "</div>";
Expand All @@ -340,7 +341,7 @@ public function showTransferList()
echo "<tbody>";
echo "<tr><td class=''>";
/** @var class-string<CommonDBTM> $itemtype */
foreach ($_SESSION['glpitransfer_list'] as $itemtype => $tab) {
foreach ($transferlist as $itemtype => $tab) {
if (count($tab)) {
if (!($item = getItemForItemtype($itemtype))) {
continue;
Expand Down Expand Up @@ -406,8 +407,9 @@ public function showTransferList()
$transfer->showForm(
1,
[
'target' => Plugin::getWebDir('yagp') . "/front/transfer.form.php",
'display' => $display
'target' => Plugin::getWebDir('yagp') . "/front/transfer.form.php",
'display' => $display,
'transferlist' => $transferlist
]
);
/*
Expand Down

0 comments on commit 8276398

Please sign in to comment.