Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#590 [WorkingHours] fix: user picto instead of company and clean code #591

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
113 changes: 54 additions & 59 deletions view/workinghours_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,43 @@
* \brief Page to view Working Hours
*/

// 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");
// Load DoliSIRH environment.
if (file_exists('../dolisirh.main.inc.php')) {
require_once __DIR__ . '/../dolisirh.main.inc.php';
} elseif (file_exists('../../dolisirh.main.inc.php')) {
require_once __DIR__ . '/../../dolisirh.main.inc.php';
} else {
die('Include of dolisirh main fails');
}

// Libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';

require_once './../class/workinghours.class.php';
require_once __DIR__ . '/../class/workinghours.class.php';

// Global variables definitions
global $db, $hookmanager, $langs, $user;

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

// Parameters
$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
$action = (GETPOSTISSET('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
$backtopage = GETPOST('backtopage', 'alpha');
$socid = GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int');

$socid = GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int');
if ($usertmp->socid) $socid = $usertmp->socid;
if (empty($socid) && $action == 'view') $action = 'create';

// Initialize technical objects.
$object = new Workinghours($db);
$usertmp = new User($db);
$form = new Form($db);

if ($usertmp->socid > 0) {
$socid = $usertmp->socid;
}
if (empty($socid) && $action == 'view') {
$action = 'create';
}

// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('userworkinghours', 'globalcard'));
Expand All @@ -68,37 +69,38 @@
}

// Security check
$permissiontoadd = $usertmp->rights->societe->creer;
$permissiontoadd = $user->rights->societe->creer;
saturne_check_access($permissiontoadd);

/*
* Actions
*/

$parameters = array();
$parameters = [];
$reshook = $hookmanager->executeHooks('doActions', $parameters, $usertmp, $action); // Note that $action and $usertmp may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

if (($action == 'update' && ! GETPOST("cancel", 'alpha')) || ($action == 'updateedit')) {
$object = new Workinghours($db);
$object->element_type = $usertmp->element;
$object->element_id = GETPOST('id');
$object->status = 1;
$object->fk_user_creat = $user->id;
$object->schedule_monday = GETPOST('schedule_monday', 'string');
$object->schedule_tuesday = GETPOST('schedule_tuesday', 'string');
$object->schedule_wednesday = GETPOST('schedule_wednesday', 'string');
$object->schedule_thursday = GETPOST('schedule_thursday', 'string');
$object->schedule_friday = GETPOST('schedule_friday', 'string');
$object->schedule_saturday = GETPOST('schedule_saturday', 'string');
$object->schedule_sunday = GETPOST('schedule_sunday', 'string');

$object->workinghours_monday = GETPOST('workinghours_monday', 'integer');
$object->workinghours_tuesday = GETPOST('workinghours_tuesday', 'integer');
$object->workinghours_wednesday = GETPOST('workinghours_wednesday', 'integer');
$object->workinghours_thursday = GETPOST('workinghours_thursday', 'integer');
$object->workinghours_friday = GETPOST('workinghours_friday', 'integer');
$object->workinghours_saturday = GETPOST('workinghours_saturday', 'integer');
$object->workinghours_sunday = GETPOST('workinghours_sunday', 'integer');

$object->fk_user_creat = $user->id;
$object->schedule_monday = GETPOST('schedule_monday', 'string');
$object->schedule_tuesday = GETPOST('schedule_tuesday', 'string');
$object->schedule_wednesday = GETPOST('schedule_wednesday', 'string');
$object->schedule_thursday = GETPOST('schedule_thursday', 'string');
$object->schedule_friday = GETPOST('schedule_friday', 'string');
$object->schedule_saturday = GETPOST('schedule_saturday', 'string');
$object->schedule_sunday = GETPOST('schedule_sunday', 'string');

$object->workinghours_monday = GETPOST('workinghours_monday', 'integer');
$object->workinghours_tuesday = GETPOST('workinghours_tuesday', 'integer');
$object->workinghours_wednesday = GETPOST('workinghours_wednesday', 'integer');
$object->workinghours_thursday = GETPOST('workinghours_thursday', 'integer');
$object->workinghours_friday = GETPOST('workinghours_friday', 'integer');
$object->workinghours_saturday = GETPOST('workinghours_saturday', 'integer');
$object->workinghours_sunday = GETPOST('workinghours_sunday', 'integer');
$result = $object->create($usertmp);
if ($result > 0) {
setEventMessages($langs->trans('UserWorkingHoursSaved'), null, 'mesgs');
Expand All @@ -114,46 +116,39 @@
* View
*/

$object = new Workinghours($db);

$morewhere = ' AND element_id = ' . GETPOST('id');
$morewhere .= ' AND element_type = ' . "'" . $usertmp->element . "'";
$morewhere .= ' AND status = 1';

$object->fetch(0, '', $morewhere);

if ($socid > 0 && empty($usertmp->id)) {
$result = $usertmp->fetch($socid);
if ($result <= 0) dol_print_error('', $usertmp->error);
}

$title = $langs->trans("User");
if ( ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $usertmp->name) $title = $usertmp->name . " - " . $langs->trans('WorkingHours');
$help_url = 'FR:Module_DoliSIRH';

$morecss = array("/dolisirh/css/dolisirh.css");
$title = $langs->trans("User");
$helpUrl = 'FR:Module_DoliSIRH';
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $usertmp->name) {
$title = $usertmp->name . " - " . $langs->trans('WorkingHours');
}

llxHeader('', $title, $help_url, '', '', '', array(), $morecss);
if (!empty($usertmp->id)) {
$res = $usertmp->fetch_optionals();
}

if ( ! empty($usertmp->id)) $res = $usertmp->fetch_optionals();
saturne_header(0, '', $title, $helpUrl);

// Object card
// ------------------------------------------------------------
$morehtmlref = '<div class="refidno">';
$morehtmlref .= '</div>';
$head = user_prepare_head($usertmp);
print dol_get_fiche_head($head, 'workinghours', $langs->trans("User"), 0, 'company');
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
print dol_get_fiche_head($head, 'workinghours', $langs->trans('User'), 0, 'user');

$linkback = '<a href="' . DOL_URL_ROOT . '/user/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
dol_banner_tab($usertmp, 'socid', $linkback, ($usertmp->socid ? 0 : 1), 'rowid', 'nom');

print dol_get_fiche_end();

print load_fiche_titre($langs->trans('WorkingHours'), '', '');

//Show common fields

if ( ! is_object($form)) $form = new Form($db);

print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . GETPOST('id') . '" >';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update">';
Expand Down