Skip to content

Commit

Permalink
Merge pull request #1385 from OCSInventory-NG/layouts
Browse files Browse the repository at this point in the history
Layouts
  • Loading branch information
charleneauger authored Jun 22, 2022
2 parents dda3b62 + f523a3a commit 2bbeced
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 13 deletions.
1 change: 0 additions & 1 deletion backend/AUTH/methode/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
if(password_verify($mdp, $rowOp->PASSWD)) {
require_once('require/function_users.php');
$update = updatePasswordMd5toHash($login, $mdp);
error_log(print_r($update, true));
if($update) {
$login_status = true;
}
Expand Down
4 changes: 4 additions & 0 deletions config/urls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,8 @@
<value>admin_local_import</value>
<directory>ms_upload_file</directory>
</url>
<url key="ms_layouts">
<value>layouts</value>
<directory>ms_layouts</directory>
</url>
</urls>
10 changes: 10 additions & 0 deletions files/update/7063.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Create layouts table
CREATE TABLE IF NOT EXISTS `layouts` (
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`LAYOUT_NAME` VARCHAR(255) NOT NULL,
`USER` VARCHAR(255) NOT NULL,
`TABLE_NAME` VARCHAR(255) NOT NULL,
`DESCRIPTION` VARCHAR(255) NULL,
`VISIBLE_COL` TEXT NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
12 changes: 12 additions & 0 deletions plugins/language/en_GB/en_GB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1828,3 +1828,15 @@
9704 CAS Configuration

9800 Exclude archived computers from statistics, CVE inventory, all softwares count, computers per TAG count

9900 Layouts
9901 Layout created
9902 Layout deleted
9903 Error creating layout
9904 Please check your input. Repeat the process if the problem persists.
9905 Error deleting layout
9906 A layout with the same name or columns already exists for your user, please choose another name or set of columns
9907 Manage layouts
9908 Show all layouts
9909 Add new layout
9910 Available layouts :
2 changes: 1 addition & 1 deletion plugins/language/es_ES/es_ES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
349 Añadir columna
350 Tipo de CPU
351 Número de CPU
352 Último inventario
352 Último contacto
353 Calidad
354 Fidelidad
355 Entidad
Expand Down
11 changes: 11 additions & 0 deletions plugins/language/fr_FR/fr_FR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1825,3 +1825,14 @@

9800 Exlure les machines archivées des Statistiques, de l'inventaire CVE, du compte de Tous les logiciels, du compte des machines par TAG

9900 Dispositions
9901 Disposition créée
9902 Disposition supprimée
9903 Erreur lors de la création de la disposition
9904 Veuillez vérifier votre entrée. Répétez le processus si le problème persiste.
9905 Erreur lors de la suppression de la disposition
9906 Une disposition avec le même nom ou les mêmes colonnes existe déjà pour votre utilisateur. Veuillez choisir un autre nom ou d'autres colonnes.
9907 Gestion des dispositions
9908 Afficher les dispositions
9909 Ajouter une disposition
9910 Dispositions disponibles :
1 change: 0 additions & 1 deletion plugins/main_sections/ms_dict/ms_dict.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
$querydico .= $value . ',';
}
}
error_log($list_cat[$protectedPost['onglet_soft']]);
$querydico = substr($querydico, 0, -1);
$querydico .= " from dico_soft left join " . $table . " cache on dico_soft.extracted=cache.name
where formatted='" . mysqli_real_escape_string($_SESSION['OCS']["readServer"], $list_cat[$protectedPost['onglet_soft']]) . "' " . $search_count . " group by EXTRACTED";
Expand Down
111 changes: 111 additions & 0 deletions plugins/main_sections/ms_layouts/ms_layouts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/*
* Copyright 2005-2022 OCSInventory-NG/OCSInventory-ocsreports contributors.
* See the Contributors file for more details about them.
*
* This file is part of OCSInventory-NG/OCSInventory-ocsreports.
*
* OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the License,
* or (at your option) any later version.
*
* OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

if (AJAX) {
parse_str($protectedPost['ocs']['0'], $params);
$protectedPost += $params;
ob_start();
}

printEnTete($l->g(9907));
$form_name = "layouts";

$layout = new Layout($protectedGet['value']);
//ADD new layout
if (isset($protectedPost['Valid_modif']) && (!empty($_SESSION['OCS']['layout_visib']))){
$dupli = $layout->insertLayout($protectedPost['LAYOUT_NAME'], $protectedPost['LAYOUT_DESCR'], $_SESSION['OCS']['loggeduser'], $_SESSION['OCS']['layout_visib']);
// if dupli, user needs to be redirected to the form and not to the list
if (!empty($dupli)) {
unset($protectedPost['Valid_modif']);
}

}

// if no layout has been added yet and user did not delete layout : show the form
if ((isset($protectedGet['tab']) && $protectedGet['tab'] == 'add') && (!isset($protectedPost['Valid_modif'])) && (!isset($protectedPost['SUP_PROF']) && !isset($protectedPost['del_check'])) && !isset($protectedPost['show_list'])) {
echo open_form('layouts', '', '', 'form-horizontal');
?>
<div class="col-md-12">
<?php
formGroup('text', 'LAYOUT_NAME', 'Layout name :', '', '', $protectedPost['LAYOUT_NAME']);
formGroup('text', 'LAYOUT_DESCR', 'Layout description :', '', '', $protectedPost['LAYOUT_DESCR']);
?>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" name="Valid_modif" value="<?php echo $l->g(1363) ?>" class="btn btn-success">
<input type="submit" name="show_list" value="<?php echo $l->g(9908) ?>" class="btn btn-info">
</div>
</div>
<?php
echo close_form();

// show the table
} else {
echo open_form('layouts', '', '', 'form-horizontal');
//delete layout
if (isset($protectedPost['SUP_PROF']) && $protectedPost['SUP_PROF'] != '') {
$layout->deleteLayout($protectedPost['SUP_PROF']);
$tab_options['CACHE'] = 'RESET';
}

if (is_defined($protectedPost['del_check'])) {
$layout->deleteLayout($protectedPost['del_check']);
$tab_options['CACHE'] = 'RESET';
}
$table_name = $form_name;
$tab_options['form_name'] = $form_name;
$tab_options['table_name'] = $table_name;

$list_fields = array(
'LAYOUT_NAME' => 'LAYOUT_NAME',
'USER' => 'USER',
'TABLE_NAME' => 'TABLE_NAME',
'DESCRIPTION' => 'DESCRIPTION',
);
$list_col_cant_del = array(
'LAYOUT_NAME' => 'LAYOUT_NAME',
'USER' => 'USER',
'TABLE_NAME' => 'TABLE_NAME',
'SUP' => 'SUP',
'CHECK' => 'CHECK'
);

$list_fields['SUP'] = 'ID';
$list_fields['CHECK'] = 'ID';

$default_fields = $list_col_cant_del;
$queryDetails = "SELECT ID, LAYOUT_NAME, USER, TABLE_NAME, DESCRIPTION FROM `layouts` WHERE USER = '".$_SESSION['OCS']['loggeduser']."'";

ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
$img['image/delete.png'] = $l->g(162);
del_selection($form_name);
echo close_form();

}


if (AJAX) {
ob_end_clean();
tab_req($list_fields, $default_fields, $list_col_cant_del, $queryDetails, $tab_options);
}
36 changes: 27 additions & 9 deletions require/function_table_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function xml_decode($txt) {
*/
function ajaxtab_entete_fixe($columns, $default_fields, $option = array(), $list_col_cant_del) {
global $protectedPost, $l, $pages_refs;

//Translated name of the column
$lbl_column = array("ACTIONS" => $l->g(1381),
"CHECK" => "<input type='checkbox' name='ALL' id='checkboxALL' Onclick='checkall();'>");
Expand Down Expand Up @@ -253,8 +252,18 @@ function ajaxtab_entete_fixe($columns, $default_fields, $option = array(), $list
}
}
?>
</select>
</select><br>

</div>
<?php
// if user is on multisearch page, do not display layouts buttons
if (isset($option['table_name']) && $option['table_name'] != 'affich_multi_crit') {
// layouts
$layout = new Layout($option['table_name']);
$cols = $layout->displayLayoutButtons($_SESSION['OCS']['loggeduser'], $protectedPost['layout'], $option['table_name']);
$visible_col = json_decode($cols['VISIBLE_COL'], true) ?? $visible_col;
}
?>
</div>
</div>
</div>
Expand All @@ -267,6 +276,7 @@ function ajaxtab_entete_fixe($columns, $default_fields, $option = array(), $list
<div id="<?php echo $option['table_name']; ?>_csv_download"
style="display: none">
<?php

//Display of the result count
if (!isset($option['no_download_result'])) {
echo "<div id='" . $option['table_name'] . "_csv_page'><label id='infopage_" . $option['table_name'] . "'></label> " . $l->g(90) . "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs['ms_csv'] . "&no_header=1&tablename=" . $option['table_name'] . "&base=" . $tab_options['BASE'] . "'><small> (" . $l->g(183) . ")</small></a></div>";
Expand All @@ -275,8 +285,11 @@ function ajaxtab_entete_fixe($columns, $default_fields, $option = array(), $list
?>
</div>
<?php
echo "<a href='#' id='reset" . $option['table_name'] . "' onclick='delete_cookie(\"" . $option['table_name'] . "_col\");window.location.reload();' style='display: none;' >" . $l->g(1380) . "</a>";
?>

echo "<a href='#' id='reset" . $option['table_name'] . "' onclick='delete_cookie(\"" . $option['table_name'] . "_col\");window.history.replaceState(null, null, window.location.href);window.location.reload();' style='display: none;' >" . $l->g(1380) . "</a><br>";

?>

</div>

<script>
Expand Down Expand Up @@ -392,9 +405,8 @@ function checkall()
"columns": [
<?php

$index = 0;

// Unset visible columns session var
$index = 0;
// Unset visible columns session var
unset($_SESSION['OCS']['visible_col'][$option['table_name']]);

//Visibility handling
Expand Down Expand Up @@ -428,6 +440,7 @@ function checkall()
if (!empty($option['REPLACE_COLUMN_KEY'][$key])) {
$key = $option['REPLACE_COLUMN_KEY'][$key];
}

echo "{'data' : '" . $key . "' , 'class':'" . $key . "',
'name':'" . $key . "', 'defaultContent': ' ',
'orderable': " . $orderable . ",'searchable': false,
Expand All @@ -439,11 +452,14 @@ function checkall()
if (!empty($option['REPLACE_COLUMN_KEY'][$key])) {
$name = $option['REPLACE_COLUMN_KEY'][$key];
}

echo "{ 'data' : '" . $name . "' , 'class':'" . $name . "',
'name':'" . $column . "', 'defaultContent': ' ',
'orderable': " . $orderable . ", 'visible' : " . $visible . "},\n ";
}

}

?>
],
//Translation
Expand Down Expand Up @@ -526,6 +542,9 @@ function checkall()

</script>
<?php
$layout_visib = json_encode($visible_col);
$_SESSION['OCS']['layout_visib'] = $layout_visib;

if ($titre != "") {
printEnTete_tab($titre);
}
Expand Down Expand Up @@ -1145,7 +1164,6 @@ function onglet($def_onglets,$form_name,$post_name,$ligne)
$current="";

foreach($def_onglets as $key=>$value){

echo "<li ";
if (is_numeric($protectedPost[$post_name])){
if ($protectedPost[$post_name] == $key or (!isset($protectedPost[$post_name]) and $current != 1)){
Expand Down Expand Up @@ -1932,7 +1950,7 @@ function tab_req($list_fields,$default_fields,$list_col_cant_del,$queryDetails,$
}
$data = json_encode($tab_options['visible_col']);
$customized=false;
if (count($tab_options['visible_col'])!=$visible){
if (isset($tab_options['visible_col']) && count($tab_options['visible_col'])!=$visible){
$customized=true;
setcookie($tab_options['table_name']."_col",$data,time()+31536000);
}
Expand Down
1 change: 1 addition & 0 deletions require/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
require_once('require/views/forms.php');
require_once('require/plugin/include.php');
require_once('require/history/History.php');
require_once('require/layouts/Layout.php');

if (isset($_SESSION['OCS']['CONF_RESET'])) {
unset($_SESSION['OCS']['LOG_GUI']);
Expand Down
Loading

0 comments on commit 2bbeced

Please sign in to comment.