Skip to content

Commit

Permalink
Merge pull request #208 from AntoineLemarchand/update_page
Browse files Browse the repository at this point in the history
Update page
  • Loading branch information
airoine committed Feb 13, 2024
2 parents 21bb966 + 303358a commit e3ee65e
Show file tree
Hide file tree
Showing 25 changed files with 2,167 additions and 1,715 deletions.
4 changes: 1 addition & 3 deletions inc/cartridgeitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ function showForm($ID, $options = []) {
]
];

$form['content']['form_inputs_config'] = ['inputs' => getHiddenInputsForItemForm($this, $this->fields)];

ob_start();
Plugin::doHook("post_item_form", ['item' => $this, 'options' => [
'colspan' => 2,
Expand All @@ -286,7 +284,7 @@ function showForm($ID, $options = []) {
]]);
$additionnalHtml = ob_get_clean();

renderTwigForm($form, $additionnalHtml);
renderTwigForm($form, $additionnalHtml, $this->fields);
return true;
}

Expand Down
1 change: 0 additions & 1 deletion inc/commonglpi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,6 @@ function display($options = []) {
if (isset($_GET["id"]) && $_GET["id"] && !$this->can($_GET["id"], READ)) {
// This triggers from a profile switch.
// If we don't have right, redirect instead to central page
die(dump($this->fields));
if (isset($_SESSION['_redirected_from_profile_selector'])
&& $_SESSION['_redirected_from_profile_selector']) {
unset($_SESSION['_redirected_from_profile_selector']);
Expand Down
2 changes: 0 additions & 2 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,6 @@ function showForm($ID, $options = [])
]
];

$form['content']['form_inputs_config'] = ['inputs' => getHiddenInputsForItemForm($this, $this->fields)];

ob_start();
Plugin::doHook("post_item_form", ['item' => $this, 'options' => [
'colspan' => 2,
Expand Down
4 changes: 1 addition & 3 deletions inc/consumableitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ function showForm($ID, $options = []) {
]
];

$form['content']['form_inputs_config'] = ['inputs' => getHiddenInputsForItemForm($this, $this->fields)];

ob_start();
Plugin::doHook("post_item_form", ['item' => $this, 'options' => [
'colspan' => 2,
Expand All @@ -226,7 +224,7 @@ function showForm($ID, $options = []) {
]]);
$additionnalHtml = ob_get_clean();

renderTwigForm($form, $additionnalHtml);
renderTwigForm($form, $additionnalHtml, $this->fields);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/contract_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static function showForItem(CommonDBTM $item, $withtemplate = 0) {
if (!count($used)) {
$usedCondition = [];
} else {
$usedCondition = ['NOT' => ['id' => $used]];
$usedCondition = ['NOT' => [Contract::getTable() . '.id' => $used]];
};
$form = [
'action' => Toolbox::getItemTypeFormURL(__CLASS__),
Expand Down
2 changes: 0 additions & 2 deletions inc/enclosure.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ function showForm($ID, $options = []) {
]
];

$form['content']['form_inputs_config'] = ['inputs' => getHiddenInputsForItemForm($this, $this->fields)];

ob_start();
Plugin::doHook("post_item_form", ['item' => $this, 'options' => [
'colspan' => 2,
Expand Down
4 changes: 2 additions & 2 deletions inc/group.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function showForm($ID, $options = []) {
__('As child of') => [
'type' => 'select',
'name' => 'groups_id',
'values' => getOptionForItems('Group', ['NOT' => ['id' => $ID]]),
'values' => getOptionForItems('Group', ['NOT' => [Group::getTable() . '.id' => $ID]]),
'value' => $this->fields['groups_id'],
'actions' => getItemActionButtons(['info', 'add'], 'Group'),
'col_lg' => 6,
Expand Down Expand Up @@ -316,7 +316,7 @@ function showForm($ID, $options = []) {
]

];
renderTwigForm($form);
renderTwigForm($form, '', $this->fields);
return true;
}

Expand Down
19 changes: 8 additions & 11 deletions inc/html.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,9 @@ static function header($title, $url = '', $sector = "none", $item = "none", $opt
}

//Main menu
$twig_vars += ["main_menu" => self::getMainMenu($sector, $item, $option)];
$twig_vars += self::getMainMenu($sector, $item, $option)['args']; //TODO : change to only add breadcrumb var.
$mainMenu = self::getMainMenu($sector, $item, $option);
$twig_vars += ["main_menu" => $mainMenu];
$twig_vars += $mainMenu['args']; //TODO : change to only add breadcrumb var.
// TODO : separate menu from header
// Preferences and logout link
$twig_vars += ["top_menu" => self::getBottomMenu(true)];
Expand Down Expand Up @@ -1863,13 +1864,8 @@ static function header($title, $url = '', $sector = "none", $item = "none", $opt
$twig_vars['accessibilityMenu'] = Session::haveRight("accessibility", READ);

$twig_vars['username'] = getUserName(Session::getLoginUserID());
require_once GLPI_ROOT . "/src/twig/twig.class.php";
$twig = Twig::load(GLPI_ROOT . "/templates", false, true);
try {
echo $twig->render('menus/headers/header.twig', $twig_vars );
} catch (\Exception $e) {
echo $e->getMessage();
}
$twig_vars['main_menu']['args']['access'] = Session::getCurrentInterface();
renderTwigTemplate('menus/headers/header.twig', $twig_vars);
// call static function callcron() every 5min
CronTask::callCron();
self::displayMessageAfterRedirect();
Expand Down Expand Up @@ -7114,8 +7110,9 @@ private static function getMainMenu($sector, $item, $option) : array
// list menu item
foreach ($data['content'] as $key => $val) {
// some menu arent arrays and should'nt be showed
if (!is_array($val))
continue;
if (!is_array($val)) {
continue;
}
$menu[$part]['content'][$key]['is_favorite'] = isset($menu_favorites[$part]) && in_array($key, $menu_favorites[$part]);
$menu[$part]['content'][$key]['part'] = $part;
$menu[$part]['content'][$key]['sub_menu_class'] = "";
Expand Down
215 changes: 94 additions & 121 deletions inc/item_devices.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,16 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem

static function showForItem(CommonGLPI $item, $withtemplate = 0)
{
global $CFG_GLPI;
global $CFG_GLPI, $DB;

$is_device = ($item instanceof CommonDevice);

$ID = $item->getField('id');

$devtypes = [];
foreach (self::getItemAffinities($item->getType()) as $link_type) {
$devtypes[] = $link_type::getDeviceType();
}

if (!$item->can($ID, READ)) {
return false;
Expand All @@ -666,107 +671,6 @@ static function showForItem(CommonGLPI $item, $withtemplate = 0)
$canedit = (($withtemplate != 2)
&& $item->canEdit($ID)
&& Session::haveRightsOr('device', [UPDATE, PURGE]));
echo "<div class='spaced'>";
$rand = mt_rand();

$table = new HTMLTableMain();

$table->setTitle(_n('Component', 'Components', Session::getPluralNumber()));
if ($canedit) {
$delete_all_column = $table->addHeader(
'delete all',
Html::getCheckAllAsCheckbox(
"form_device_action$rand",
'__RAND__'
)
);
$delete_all_column->setHTMLClass('center');
} else {
$delete_all_column = null;
}

$column_label = ($is_device ? _n('Item', 'Items', Session::getPluralNumber()) : __('Type of component'));
$common_column = $table->addHeader('common', $column_label);
$specific_column = $table->addHeader('specificities', __('Specificities'));
$specific_column->setHTMLClass('center');

$dynamic_column = '';
if ($item->isDynamic()) {
$dynamic_column = $table->addHeader('is_dynamic', __('Automatic inventory'));
$dynamic_column->setHTMLClass('center');
}

if ($canedit) {
$massiveactionparams = [
'container' => "form_device_action$rand",
'fixed' => false,
'display_arrow' => false
];
$content = [[
'function' => 'Html::showMassiveActions',
'parameters' => [$massiveactionparams]
]];
$delete_column = $table->addHeader('delete one', $content);
$delete_column->setHTMLClass('center');
} else {
$delete_column = null;
}

$table_options = [
'canedit' => $canedit,
'rand' => $rand
];

if ($is_device) {
Session::initNavigateListItems(
static::getType(),
sprintf(
__('%1$s = %2$s'),
$item->getTypeName(1),
$item->getName()
)
);
foreach (array_merge([''], self::getConcernedItems()) as $itemtype) {
$table_options['itemtype'] = $itemtype;
$link = getItemForItemtype(static::getType());

$link->getTableGroup(
$item,
$table,
$table_options,
$delete_all_column,
$common_column,
$specific_column,
$delete_column,
$dynamic_column
);
}
} else {
$devtypes = [];
foreach (self::getItemAffinities($item->getType()) as $link_type) {
$devtypes[] = $link_type::getDeviceType();
$link = getItemForItemtype($link_type);

Session::initNavigateListItems(
$link_type,
sprintf(
__('%1$s = %2$s'),
$item->getTypeName(1),
$item->getName()
)
);
$link->getTableGroup(
$item,
$table,
$table_options,
$delete_all_column,
$common_column,
$specific_column,
$delete_column,
$dynamic_column
);
}
}

$entity = isset($item->fields) ? $item->fields['entities_id'] : 0;
if ($canedit) {
Expand Down Expand Up @@ -909,26 +813,95 @@ static function showForItem(CommonGLPI $item, $withtemplate = 0)
renderTwigForm($form);
}

if ($canedit) {
echo "\n<form id='form_device_action$rand' name='form_device_action$rand'
action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "' method='post'>\n";
echo "\t<input type='hidden' name='items_id' value='$ID'>\n";
echo "\t<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n";
}

$table->display([
'display_super_for_each_group' => false,
'display_title_for_each_group' => false
]);

if ($canedit) {
echo "<input type='submit' class='submit' name='updateall' value='" .
_sx('button', 'Save') . "'>";

Html::closeForm();
foreach (self::getItemAffinities($item->getType()) as $link_type) {
$link = getItemForItemtype($link_type);
$table = $link->getTable();
$criteria = [
'SELECT' => "$table.*",
'FROM' => $table
];
if ($is_device) {
$fk = 'items_id';

// Entity restrict
$criteria['WHERE'] = [
$link->getDeviceForeignKey() => $item->getID(),
"$table.itemtype" => $peer_type,
"$table.is_deleted" => 0
];
$criteria['ORDERBY'] = [
"$table.itemtype",
"$table.$fk"
];
if (!empty($peer_type)) {
$criteria['LEFT JOIN'] = [
getTableForItemType($peer_type) => [
'ON' => [
$table => 'items_id',
getTableForItemType($peer_type) => 'id', [
'AND' => [
"$table.itemtype" => $peer_type
]
]
]
]
];
$criteria['WHERE'] = $criteria['WHERE'] + getEntitiesRestrictCriteria(getTableForItemType($peer_type));
}
} else {
$fk = $link->getDeviceForeignKey();

$criteria['WHERE'] = [
'itemtype' => $item->getType(),
'items_id' => $item->getID(),
'is_deleted' => 0
];
$criteria['ORDERBY'] = $fk;
}
$datas = iterator_to_array($DB->request($criteria));
if (count($datas)) {
$massiveActionContainerId = 'mass'.__CLASS__.rand();
if ($canedit) {
$params = [
'container' => $massiveActionContainerId,
'is_deleted' => 0,
'display_arrow' => false,
];
Html::showMassiveActions($params);
}
$columns = $link->getSpecificities();
$fields = [];
foreach($columns as $name => $column) {
if ((!isset($column['nodisplay']) || $column['nodisplay'] == false) && !isset($column['datatype'])) {
$fields[$name] = $column['long name'];
}
}
if ($canedit) {
$fields[] = __('Update');
}
$values = [];
$massive_action = [];
foreach($datas as $data) {
$newValue = [];
foreach(array_keys($columns) as $column) {
$newValue[$column] = $data[$column];
}
if ($canedit) {
$newValue[] = '<a href=' . $link->getFormURL().'?id='.$data['id'] . '>' . __('Update') . "</a>";
}
$values[] = $newValue;
$massive_action[] = sprintf('item[%s][%s]', $link::class, $data['id']);
}
echo "<hr>";
echo "<h2>".$link::getTypeName()."</h2>";
renderTwigTemplate('table.twig', [
'id' => $massiveActionContainerId,
'fields' => $fields,
'values' => $values,
'massive_action' => $massive_action
]);
}
}

echo "</div>";
// Force disable selected items
$_SESSION['glpimassiveactionselected'] = [];
}
Expand Down
13 changes: 11 additions & 2 deletions inc/item_ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ static function itemAddForm(Ticket $ticket, $options = []) {
echo "<span id='item_ticket_selection_information$rand'></span>";
echo "</div>";

// Add button
echo "<a href='javascript:itemAction$rand(\"add\");' class='vsubmit' style='float:left'>"._sx('button', 'Add')."</a>";
echo "<a href='javascript:itemAction$rand(\"add\");' class='btn btn-secondary' style='float:left'>"._sx('button', 'Add')."</a>";
}

// Display list
Expand Down Expand Up @@ -1209,6 +1208,16 @@ static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype
}
}
echo "<div id='tracking_my_devices'>";
renderTwigTemplate('macros/wrappedInput.twig', [
'title' => __('My devices'),
'input' => [
'type' => 'select',
'name' => 'my_items',
'values' => $my_devices,
'col_lg' => 12,
'col_md' => 12,
]
]);
echo __('My devices')."&nbsp;";
Dropdown::showFromArray('my_items', $my_devices, ['rand' => $rand]);
echo "</div>";
Expand Down
Loading

0 comments on commit e3ee65e

Please sign in to comment.