Skip to content

Commit

Permalink
#14 [DoliSIRHTools] add: update user for change employee value at 0 i…
Browse files Browse the repository at this point in the history
…nstead of 1
  • Loading branch information
nicolas-eoxia committed Oct 31, 2022
1 parent 0d91ea5 commit 9d5ff66
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/modules/modDolisirh.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,22 @@ public function __construct($db)
'user' => 0,
);

$this->menu[$r++] = array(
'fk_menu' => 'fk_mainmenu=dolisirh', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type' => 'left', // This is a Left menu entry
'titre' => $langs->trans('Tools'),
'prefix' => '<i class="fas fa-wrench pictofixedwidth"></i> ',
'mainmenu' => 'dolisirh',
'leftmenu' => 'dolisirhtools',
'url' => '/dolisirh/view/dolisirhtools.php',
'langs' => 'dolisirh@dolisirh', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position' => 48520 + $r,
'enabled' => '$conf->dolisirh->enabled', // Define condition to show or hide menu entry. Use '$conf->dolisirh->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms' => '$user->rights->dolisirh->adminpage->read', // Use 'perms'=>'$user->rights->digiriskdolibarr->level1->level2' if you want your menu with a permission rules
'target' => '',
'user' => 0, // 0=Menu for internal users, 1=external users, 2=both
);

$this->menu[$r++] = array(
'fk_menu' => 'fk_mainmenu=dolisirh', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type' => 'left', // This is a Left menu entry
Expand Down
131 changes: 131 additions & 0 deletions view/dolisirhtools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/* Copyright (C) 2022 EVARISK <dev@evarisk.com>
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file view/dolisirhtools.php
* \ingroup dolisirh
* \brief Tools page of dolisirh top menu
*/

// Load Dolibarr environment
$res = 0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if ( ! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
if ( ! $res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
if ( ! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
// Try main.inc.php using relative path
if ( ! $res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if ( ! $res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if ( ! $res) die("Include of main fails");

global $conf, $db, $langs, $user;

// Load translation files required by the page
$langs->loadLangs(array("dolisirh@dolisirh"));

// Parameters
$action = GETPOST('action', 'alpha');


// Initialize technical objects
$usertmp = new User($db);

// Security check
$permissiontoread = $user->rights->dolisirh->adminpage->read;

if (!$permissiontoread) accessforbidden();

/*
* Actions
*/

if (GETPOST('dataUpdate', 'alpha')) {
$allusers = $usertmp->get_full_tree(0, 'u.employee = 1 AND u.fk_soc IS NOT NULL');
if (!empty($allusers) && is_array($allusers)) {
foreach ($allusers as $usersingle) {
$usertmp->fetch($usersingle['id']);
$usertmp->employee = 0;
$usertmp->update($user, 1);
}
setEventMessage($langs->trans('DataUpdateSaved'));
} else {
setEventMessage($langs->trans('DataUpdateNotSaved'));
}
}

/*
* View
*/

$help_url = 'FR:Module_DoliSIRH';
$morejs = array("/dolisirh/js/dolisirh.js");
$morecss = array("/dolisirh/css/dolisirh.css");

llxHeader("", $langs->trans("Tools"), $help_url, '', '', '', $morejs, $morecss);

print load_fiche_titre($langs->trans("Tools"), '', 'wrench');

if ($user->rights->dolisirh->adminpage->read) { ?>
<div class="wpeo-notice notice-info">
<div class="notice-content">
<div class="notice-title"><strong><?php echo $langs->trans("DataUpdateUserHaveTodoTitle"); ?></strong></div>
<div class="notice-subtitle">
<?php
$allusers = $usertmp->get_full_tree(0, 'u.employee = 1 AND u.fk_soc IS NOT NULL');
if (!empty($allusers) && is_array($allusers)) {
$dataUpdateUser = count($allusers);
} else {
$dataUpdateUser = 0;
}
print $langs->trans("DataUpdateUserHaveTodo", $dataUpdateUser) ?>
</div>
</div>
</div>

<?php print load_fiche_titre($langs->trans("DataUpdateManagement"), '', '');

print '<form class="data-update-from" name="DataUpdate" id="DataUpdate" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="">';

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Name") . '</td>';
print '<td>' . $langs->trans("Description") . '</td>';
print '<td class="center">' . $langs->trans("Action") . '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('DataUpdateUser');
print "</td><td>";
print $langs->trans('DataUpdateUserDescription');
print '</td>';

print '<td class="center data-update">';
print '<input type="submit" class="button reposition data-update" name="dataUpdate" value="' . $langs->trans("DataUpdate") . '">';
print '</td>';
print '</tr>';
print '</table>';
print '</form>';
}

// End of page
llxFooter();
$db->close();

0 comments on commit 9d5ff66

Please sign in to comment.