diff --git a/class/digiriskresources.class.php b/class/digiriskresources.class.php index 2df78ac2b..9f53aa303 100644 --- a/class/digiriskresources.class.php +++ b/class/digiriskresources.class.php @@ -131,9 +131,16 @@ public function create(User $user, $notrigger = false) /** * Clone an object into another one * + * @param $db + * @param $user_creat * @param string $ref name of resource * @param string $element_type type of resource - * @param int $element_id Id of resource + * @param array $element_id Id of resource + * @param int $entity + * @param string $object_type + * @param int $object_id + * @param int $noupdate + * @return int */ function digirisk_dolibarr_set_resources($db, $user_creat, $ref, $element_type, $element_id, $entity = 1, $object_type = '', $object_id = 0, $noupdate = 0) { diff --git a/class/digirisksignature.class.php b/class/digirisksignature.class.php index 42ca4f309..3beb3b6cb 100644 --- a/class/digirisksignature.class.php +++ b/class/digirisksignature.class.php @@ -407,7 +407,7 @@ public function LibStatut($status, $mode = 0) * * @param int $fk_object ID of object linked * @param string $element_type Type of resource - * @param int $element_ids Id of resource + * @param array $element_ids Id of resource * @param string $role Role of resource * @param string $noupdate Update previous signatories */ diff --git a/class/preventionplan.class.php b/class/preventionplan.class.php index c2afa9325..baa32d82b 100644 --- a/class/preventionplan.class.php +++ b/class/preventionplan.class.php @@ -812,7 +812,7 @@ public function fetch($rowid) * Load preventionplan line line from database * * @param int $rowid id of preventionplan line line to get - * @return int <0 if KO, >0 if OK + * @return array <0 if KO, >0 if OK */ public function fetchAll($parent_id = 0, $limit = 0) { diff --git a/core/modules/modDigiriskDolibarr.class.php b/core/modules/modDigiriskDolibarr.class.php index 04d3f8358..1ae81b26d 100644 --- a/core/modules/modDigiriskDolibarr.class.php +++ b/core/modules/modDigiriskDolibarr.class.php @@ -400,34 +400,34 @@ public function __construct($db) /* FIRE PERMIT PERMISSIONS */ $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('ReadFirePermit'); - $this->rights[$r][4] = 'firepermitdocument'; + $this->rights[$r][4] = 'firepermit'; $this->rights[$r][5] = 'read'; $r++; $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('CreateFirePermit'); - $this->rights[$r][4] = 'firepermitdocument'; + $this->rights[$r][4] = 'firepermit'; $this->rights[$r][5] = 'write'; $r++; $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('DeleteFirePermit'); - $this->rights[$r][4] = 'firepermitdocument'; + $this->rights[$r][4] = 'firepermit'; $this->rights[$r][5] = 'delete'; $r++; /* PREVENTION PLAN PERMISSIONS */ $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('ReadPreventionPlan'); - $this->rights[$r][4] = 'preventionplandocument'; + $this->rights[$r][4] = 'preventionplan'; $this->rights[$r][5] = 'read'; $r++; $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('CreatePreventionPlan'); - $this->rights[$r][4] = 'preventionplandocument'; + $this->rights[$r][4] = 'preventionplan'; $this->rights[$r][5] = 'write'; $r++; $this->rights[$r][0] = $this->numero.$r; $this->rights[$r][1] = $langs->trans('DeletePreventionPlan'); - $this->rights[$r][4] = 'preventionplandocument'; + $this->rights[$r][4] = 'preventionplan'; $this->rights[$r][5] = 'delete'; $r++; diff --git a/lib/digiriskdolibarr_preventionplan.lib.php b/lib/digiriskdolibarr_preventionplan.lib.php index 907feccc1..133422730 100644 --- a/lib/digiriskdolibarr_preventionplan.lib.php +++ b/lib/digiriskdolibarr_preventionplan.lib.php @@ -24,7 +24,7 @@ /** * Prepare array of tabs for DigiriskElement * - * @param DigiriskElement $object DigiriskElement + * @param PreventionPlan $object PreventionPlan * @return array Array of tabs */ function preventionplanPrepareHead($object) diff --git a/preventionplan_agenda.php b/preventionplan_agenda.php index 8b7404e3e..cdb22bbf7 100644 --- a/preventionplan_agenda.php +++ b/preventionplan_agenda.php @@ -35,7 +35,6 @@ if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php"; if (!$res) die("Include of main fails"); -require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -48,38 +47,35 @@ $langs->loadLangs(array("digiriskdolibarr@digiriskdolibarr", "other")); // Get parameters -$id = GETPOST('id', 'int'); +$id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'alpha'); +$action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); -if (GETPOST('actioncode', 'array')) -{ +if (GETPOST('actioncode', 'array')) { $actioncode = GETPOST('actioncode', 'array', 3); if (!count($actioncode)) $actioncode = '0'; } -else -{ +else { $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); } $search_agenda_label = GETPOST('search_agenda_label'); -$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -$offset = $limit * $page; +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortfield) $sortfield = 'a.datep,a.id'; if (!$sortorder) $sortorder = 'DESC,DESC'; // Initialize technical objects -$object = new PreventionPlan($db); +$object = new PreventionPlan($db); $extrafields = new ExtraFields($db); -$diroutputmassaction = $conf->digiriskdolibarr->dir_output.'/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('preventionplanagenda', 'globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); @@ -89,112 +85,77 @@ if ($id > 0 || !empty($ref)) $upload_dir = $conf->digiriskdolibarr->multidir_output[$object->entity]."/".$object->id; // Security check - Protection if external user -//if ($user->socid > 0) accessforbidden(); -//if ($user->socid > 0) $socid = $user->socid; -//$result = restrictedArea($user, 'digiriskdolibarr', $object->id); - -$permissiontoadd = $user->rights->digiriskdolibarr->preventionplan->write; // Used by the include of actions_addupdatedelete.inc.php +$permissiontoread = $user->rights->digiriskdolibarr->preventionplan->read; +if (!$permissiontoread) accessforbidden(); /* * Actions */ -$parameters = array('id'=>$id); +$parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ +if (empty($reshook)) { // Cancel - if (GETPOST('cancel', 'alpha') && !empty($backtopage)) - { + if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { header("Location: ".$backtopage); exit; } // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $actioncode = ''; $search_agenda_label = ''; } } - - /* * View */ -$form = new Form($db); - - -if (true) -{ - - $title = $langs->trans("Agenda"); - //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; - $help_url = 'FR:Module_DigiriskDolibarr'; - $morejs = array("/digiriskdolibarr/js/digiriskdolibarr.js.php"); +if ($object->id > 0) { + $title = $langs->trans("Agenda"); + $help_url = 'FR:Module_DigiriskDolibarr'; + $morejs = array("/digiriskdolibarr/js/digiriskdolibarr.js.php"); $morecss = array("/digiriskdolibarr/css/digiriskdolibarr.css"); llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss); - print '
'; - if (!empty($conf->notification->enabled)) $langs->load("mails"); $head = preventionplanPrepareHead($object); - - dol_fiche_head($head, 'preventionplanAgenda', $title, -1, "digiriskdolibarr@digiriskdolibarr"); + print dol_get_fiche_head($head, 'preventionplanAgenda', $title, -1, "digiriskdolibarr@digiriskdolibarr"); // Object card // ------------------------------------------------------------ - $width = 80; $cssclass = 'photoref'; + //$width = 80; $cssclass = 'photoref'; dol_strlen($object->label) ? $morehtmlref = ' - ' . $object->label : ''; - $morehtmlleft .= '
'.digirisk_show_photos('digiriskdolibarr', $conf->digiriskdolibarr->multidir_output[$entity].'/'.$object->element_type, 'small', 5, 0, 0, 0, $width,0, 0, 0, 0, $object->element_type, $object).'
'; + //$morehtmlleft .= '
'.digirisk_show_photos('digiriskdolibarr', $conf->digiriskdolibarr->multidir_output[$entity].'/'.$object->element_type, 'small', 5, 0, 0, 0, $width,0, 0, 0, 0, $object->element_type, $object).'
'; digirisk_banner_tab($object, 'ref', '', 0, 'ref', 'ref', $morehtmlref, '', 0, $morehtmlleft); print '
'; - print '
'; $object->info($object->id); dol_print_object_info($object, 1); print '
'; - dol_fiche_end(); + print dol_get_fiche_end(); // Actions buttons - $objthirdparty = $object; $objcon = new stdClass(); - $out = '&origin='.$object->element.'@digiriskdolibarr'.'&originid='.$object->id; - $permok = $user->rights->agenda->myactions->create; - if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) - { - //$out.='trans("AddAnAction"),'filenew'); - //$out.=""; - } - + $out = '&origin='.$object->element.'@digiriskdolibarr'.'&originid='.$object->id.'&backtopage=1&percentage=-1'; - $morehtmlcenter = ''; - - if (!empty($conf->agenda->enabled)) - { + if (!empty($conf->agenda->enabled)) { $linktocreatetimeBtnStatus = !empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create); - $morehtmlcenter = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', $linktocreatetimeBtnStatus); } - if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) - { + if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { $param = '&id='.$object->id; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); @@ -203,8 +164,6 @@ // List of all actions $filters = array(); - - // TODO Replace this with same code than into list.php show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, 'digiriskdolibarr'); print '
'; } diff --git a/preventionplan_card.php b/preventionplan_card.php index 57ed883b0..fc7b4ba95 100644 --- a/preventionplan_card.php +++ b/preventionplan_card.php @@ -73,25 +73,25 @@ $objectline = new PreventionPlanLine($db); $signatory = new PreventionPlanSignature($db); $preventionplandocument = new PreventionPlanDocument($db); +$digiriskelement = new DigiriskElement($db); +$digiriskresources = new DigiriskResources($db); $risk = new Risk($db); +$contact = new Contact($db); +$usertmp = new User($db); -$contact = new Contact($db); -$usertmp = new User($db); +$refPreventionPlanMod = new $conf->global->DIGIRISKDOLIBARR_PREVENTIONPLAN_ADDON($db); +$refPreventionPlanDetMod = new $conf->global->DIGIRISKDOLIBARR_PREVENTIONPLANDET_ADDON($db); +// Load object $object->fetch($id); -$digiriskelement = new DigiriskElement($db); -$digiriskresources = new DigiriskResources($db); - -$refPreventionPlanMod = new $conf->global->DIGIRISKDOLIBARR_PREVENTIONPLAN_ADDON($db); -$refPreventionPlanDetMod = new $conf->global->DIGIRISKDOLIBARR_PREVENTIONPLANDET_ADDON($db); - $hookmanager->initHooks(array('preventionplancard', 'globalcard')); // Note that conf->hooks_modules contains array $upload_dir = $conf->digiriskdolibarr->multidir_output[isset($object->entity) ? $object->entity : 1]; -$permissiontoread = $user->rights->digiriskdolibarr->preventionplandocument->read; -$permissiontoadd = $user->rights->digiriskdolibarr->preventionplandocument->write; -$permissiontodelete = $user->rights->digiriskdolibarr->preventionplandocument->delete; +// Security check - Protection if external user +$permissiontoread = $user->rights->digiriskdolibarr->preventionplan->read; +$permissiontoadd = $user->rights->digiriskdolibarr->preventionplan->write; +$permissiontodelete = $user->rights->digiriskdolibarr->preventionplan->delete; if (!$permissiontoread) accessforbidden(); @@ -103,8 +103,7 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ +if (empty($reshook)) { $error = 0; $backurlforlist = dol_buildpath('/digiriskdolibarr/preventionplan_list.php', 1); @@ -117,7 +116,7 @@ } if (GETPOST('cancel')) { - // Creation prevention plan OK + // Cancel prevention plan $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); @@ -126,18 +125,19 @@ // Action to add record if ($action == 'add' && $permissiontoadd) { + // Get parameters $maitre_oeuvre_id = GETPOST('maitre_oeuvre'); $extsociety_id = GETPOST('ext_society'); $extresponsible_id = GETPOST('ext_society_responsible'); $extintervenant_ids = GETPOST('ext_intervenants'); $labour_inspector_id = GETPOST('labour_inspector'); $labour_inspector_contact_id = GETPOST('labour_inspector_contact'); + $label = GETPOST('label'); + $prior_visit_bool = GETPOST('prior_visit_bool'); + $prior_visit_text = GETPOST('prior_visit_text'); + $cssct_intervention = GETPOST('cssct_intervention'); - $label = GETPOST('label'); - $prior_visit_bool = GETPOST('prior_visit_bool'); - $prior_visit_text = GETPOST('prior_visit_text'); - $cssct_intervention = GETPOST('cssct_intervention'); - + // Initialize object preventionplan $now = dol_now(); $object->ref = $refPreventionPlanMod->getNextValue($object); $object->ref_ext = 'digirisk_' . $object->ref; @@ -151,21 +151,20 @@ $date_end = dol_mktime(GETPOST('dateehour', 'int'), GETPOST('dateemin', 'int'), 0, GETPOST('dateemonth', 'int'), GETPOST('dateeday', 'int'), GETPOST('dateeyear', 'int')); $prior_visit_date = dol_mktime(GETPOST('dateihour', 'int'), GETPOST('dateimin', 'int'), 0, GETPOST('dateimonth', 'int'), GETPOST('dateiday', 'int'), GETPOST('dateiyear', 'int')); - $object->description = $description; $object->date_start = $date_start; $object->date_end = $date_end; - $object->prior_visit_bool = $prior_visit_bool; - + $object->prior_visit_bool = $prior_visit_bool; if ($prior_visit_bool) { - $object->prior_visit_text = $prior_visit_text; - $object->prior_visit_date = $prior_visit_date; + $object->prior_visit_text = $prior_visit_text; + $object->prior_visit_date = $prior_visit_date; } $object->cssct_intervention = $cssct_intervention; $object->fk_user_creat = $user->id ? $user->id : 1; + // Check parameters if ($maitre_oeuvre_id < 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('MaitreOeuvre')), null, 'errors'); $error++; @@ -221,16 +220,13 @@ if (!$error) { $result = $object->create($user, false); - if ($result > 0) { - $object->setInProgress($user, true); - $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_EXT_SOCIETY', 'societe', array($extsociety_id), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_LABOUR_INSPECTOR', 'societe', array($labour_inspector_id), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_LABOUR_INSPECTOR_ASSIGNED', 'socpeople', array($labour_inspector_contact_id), $conf->entity, 'preventionplan', $object->id, 0); - if (!empty($maitre_oeuvre_id) || $maitre_oeuvre_id > 0){ + if ($maitre_oeuvre_id > 0) { $signatory->setSignatory($object->id,'user', array($maitre_oeuvre_id), 'PP_MAITRE_OEUVRE'); } @@ -244,8 +240,7 @@ header("Location: " . $urltogo); exit; } - else - { + else { // Creation prevention plan KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); @@ -259,41 +254,40 @@ // Action to update record if ($action == 'update' && $permissiontoadd) { - + // Get parameters $maitre_oeuvre_id = GETPOST('maitre_oeuvre'); $extsociety_id = GETPOST('ext_society'); $extresponsible_id = GETPOST('ext_society_responsible'); $extintervenant_ids = GETPOST('ext_intervenants'); $labour_inspector_id = GETPOST('labour_inspector'); $labour_inspector_contact_id = GETPOST('labour_inspector_contact') ? GETPOST('labour_inspector_contact') : 0; + $label = GETPOST('label'); + $prior_visit_bool = GETPOST('prior_visit_bool'); + $prior_visit_text = GETPOST('prior_visit_text'); + $cssct_intervention = GETPOST('cssct_intervention'); - $label = GETPOST('label'); - $prior_visit_bool = GETPOST('prior_visit_bool'); - $prior_visit_text = GETPOST('prior_visit_text'); - $cssct_intervention = GETPOST('cssct_intervention'); - $description = GETPOST('description'); - - $now = dol_now(); - $object->tms = $now; - $object->label = $label; + // Initialize object preventionplan + $now = dol_now(); + $object->tms = $now; + $object->label = $label; $date_start = dol_mktime(GETPOST('dateohour', 'int'), GETPOST('dateomin', 'int'), 0, GETPOST('dateomonth', 'int'), GETPOST('dateoday', 'int'), GETPOST('dateoyear', 'int')); $date_end = dol_mktime(GETPOST('dateehour', 'int'), GETPOST('dateemin', 'int'), 0, GETPOST('dateemonth', 'int'), GETPOST('dateeday', 'int'), GETPOST('dateeyear', 'int')); $prior_visit_date = dol_mktime(GETPOST('dateihour', 'int'), GETPOST('dateimin', 'int'), 0, GETPOST('dateimonth', 'int'), GETPOST('dateiday', 'int'), GETPOST('dateiyear', 'int')); - $object->description = $description; - $object->date_start = $date_start; - $object->date_end = $date_end; + $object->date_start = $date_start; + $object->date_end = $date_end; - $object->prior_visit_bool = $prior_visit_bool; + $object->prior_visit_bool = $prior_visit_bool; if ($prior_visit_bool) { $object->prior_visit_text = $prior_visit_text; $object->prior_visit_date = $prior_visit_date; } - $object->cssct_intervention = $cssct_intervention; + $object->cssct_intervention = $cssct_intervention; $object->fk_user_creat = $user->id ? $user->id : 1; + // Check parameters if ($maitre_oeuvre_id < 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('MaitreOeuvre')), null, 'errors'); $error++; @@ -349,9 +343,7 @@ if (!$error) { $result = $object->update($user, false); - if ($result > 0) { - $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_EXT_SOCIETY', 'societe', array($extsociety_id), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_LABOUR_INSPECTOR', 'societe', array($labour_inspector_id), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->digirisk_dolibarr_set_resources($db, $user->id, 'PP_LABOUR_INSPECTOR_ASSIGNED', 'socpeople', array($labour_inspector_contact_id), $conf->entity, 'preventionplan', $object->id, 0); @@ -359,7 +351,7 @@ $signatory->setSignatory($object->id,'user', array($maitre_oeuvre_id), 'PP_MAITRE_OEUVRE'); $signatory->setSignatory($object->id,'socpeople', array($extresponsible_id), 'PP_EXT_SOCIETY_RESPONSIBLE'); - // Creation prevention plan OK + // Update prevention plan OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); @@ -367,7 +359,7 @@ } else { - // Creation prevention plan KO + // Update prevention plan KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } @@ -378,13 +370,14 @@ // Action to add line if ($action == 'addLine' && $permissiontoadd) { - + // Get parameters $actions_description = GETPOST('actionsdescription'); $prevention_method = GETPOST('preventionmethod'); $location = GETPOST('fk_element'); $risk_category_id = GETPOST('risk_category_id'); $parent_id = GETPOST('parent_id'); + // Initialize object preventionplan line $objectline->date_creation = $object->db->idate($now); $objectline->ref = $refPreventionPlanDetMod->getNextValue($objectline); $objectline->entity = $conf->entity; @@ -394,6 +387,7 @@ $objectline->fk_preventionplan = $parent_id; $objectline->fk_element = $location; + // Check parameters if ($location < 1) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Location')), null, 'errors'); $error++; @@ -406,41 +400,42 @@ if (!$error) { $result = $objectline->insert($user, false); - if ($result > 0) { + // Creation prevention plan line OK setEventMessages($langs->trans('AddPreventionPlanLine').' '.$objectline->ref.' '.$langs->trans('PreventionPlanMessage'), array()); $objectline->call_trigger('PREVENTIONPLANDET_CREATE', $user); - $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); exit; } - else - { - setEventMessages($objectline->error, $objectline->errors, 'errors'); + else { + // Creation prevention plan line KO + if (!empty($objectline->errors)) setEventMessages(null, $objectline->errors, 'errors'); + else setEventMessages($objectline->error, null, 'errors'); } } } // Action to update line if ($action == 'updateLine' && $permissiontoadd) { - + // Get parameters $actions_description = GETPOST('actionsdescription'); $prevention_method = GETPOST('preventionmethod'); $location = GETPOST('fk_element'); $risk_category_id = GETPOST('risk_category_id'); $parent_id = GETPOST('parent_id'); - $objectline = new PreventionPlanLine($db); $objectline->fetch($lineid); + // Initialize object prevention plan line $objectline->description = $actions_description; $objectline->category = $risk_category_id; $objectline->prevention_method = $prevention_method; $objectline->fk_preventionplan = $parent_id; $objectline->fk_element = $location; + // Check parameters if ($parent_id < 1) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Location')), null, 'errors'); $error++; @@ -452,10 +447,9 @@ if (!$error) { $result = $objectline->update($user, false); - if ($result > 0) { + // Update prevention plan line OK setEventMessages($langs->trans('UpdatePreventionPlanLine').' '.$objectline->ref.' '.$langs->trans('PreventionPlanMessage'), array()); - // Creation prevention plan OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $parent_id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); @@ -463,30 +457,28 @@ } else { - // Creation prevention plan KO - if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); + // Update prevention plan line KO + if (!empty($objectline->errors)) setEventMessages(null, $objectline->errors, 'errors'); + else setEventMessages($objectline->error, null, 'errors'); } } } // Action to delete line if ($action == 'deleteline' && $permissiontodelete) { - $objectline = new PreventionPlanLine($db); $objectline->fetch($lineid); $result = $objectline->delete($user, false); - if ($result > 0) { - // Delete prevention plan OK + // Delete prevention plan line OK setEventMessages($langs->trans('DeletePreventionPlanLine').' '.$objectline->ref.' '.$langs->trans('PreventionPlanMessage'), array()); $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $parent_id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); exit; } else { - // Delete prevention plan KO - if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); + // Delete prevention plan line KO + if (!empty($objectline->errors)) setEventMessages(null, $objectline->errors, 'errors'); + else setEventMessages($objectline->error, null, 'errors'); } } @@ -507,7 +499,7 @@ if (empty($hideref)) $hideref = 0; if (empty($moreparams)) $moreparams = null; - $model = GETPOST('model', 'alpha'); + $model = GETPOST('model', 'alpha'); $moreparams['object'] = $object; $moreparams['user'] = $user; @@ -517,37 +509,30 @@ setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } else { - if (empty($donotredirect)) - { - setEventMessages($langs->trans("FileGenerated") . ' - ' . $preventionplandocument->last_main_doc, null); - - $signatories = $signatory->fetchSignatory("",$object->id); + setEventMessages($langs->trans("FileGenerated") . ' - ' . $preventionplandocument->last_main_doc, null); - $arrayRole = array( 'PP_MAITRE_OEUVRE', 'PP_EXT_SOCIETY_RESPONSIBLE', 'PP_EXT_SOCIETY_INTERVENANTS'); + $signatories = $signatory->fetchSignatory("",$object->id); - if (!empty ($signatories) && $signatories > 0) { - foreach ($signatories as $arrayRole) { - foreach ($arrayRole as $signatory) { - $signatory->signature = $langs->trans("FileGenerated"); - //$signatory->setSigned($user, false); - $signatory->update($user, false); - } + if (!empty ($signatories) && $signatories > 0) { + foreach ($signatories as $arrayRole) { + foreach ($arrayRole as $signatory) { + $signatory->signature = $langs->trans("FileGenerated"); + $signatory->update($user, false); } } + } - $urltoredirect = $_SERVER['REQUEST_URI']; - $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); - $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop + $urltoredirect = $_SERVER['REQUEST_URI']; + $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); + $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop - header('Location: ' . $urltoredirect . '#builddoc'); - exit; - } + header('Location: ' . $urltoredirect . '#builddoc'); + exit; } } // Delete file in doc form - if ($action == 'remove_file' && $permissiontodelete) - { + if ($action == 'remove_file' && $permissiontodelete) { if (!empty($upload_dir)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -571,23 +556,20 @@ } } - // Action to set status STATUS_PENDING_SIGNATURE + // Action to set status STATUS_INPROGRESS if ($action == 'confirm_setInProgress') { - $object->fetch($id); - if (!$error) { $result = $object->setInProgress($user, false); if ($result > 0) { - // Creation signature OK + // Set In progress OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); exit; } - else - { - // Creation signature KO + else { + // Set In progress KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } @@ -596,13 +578,11 @@ // Action to set status STATUS_PENDING_SIGNATURE if ($action == 'confirm_setPendingSignature') { - $object->fetch($id); - if (!$error) { $result = $object->setPendingSignature($user, false); if ($result > 0) { - // Creation signature OK + // Set pending signature OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); @@ -610,7 +590,7 @@ } else { - // Creation signature KO + // Set pending signature KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } @@ -619,44 +599,38 @@ // Action to set status STATUS_LOCKED if ($action == 'confirm_setLocked') { - $object->fetch($id); - if (!$error) { $result = $object->setLocked($user, false); if ($result > 0) { - // Creation signature OK + // Set locked OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); exit; } - else - { - // Creation signature KO + else { + // Set locked KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } } } - // Action to set status STATUS_CLOSE + // Action to set status STATUS_ARCHIVED if ($action == 'setArchived') { - $object->fetch($id); - if (!$error) { $result = $object->setArchived($user, false); if ($result > 0) { - // Creation signature OK + // Set Archived OK $urltogo = str_replace('__ID__', $result, $backtopage); $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: " . $urltogo); exit; } - else - { - // Creation signature KO + else { + // Set Archived KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } @@ -664,36 +638,35 @@ } // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes') - { - if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) - { - setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); - } else { - if ($object->id > 0) { - $result = $object->createFromClone($user, $object->id); - if ($result > 0) { - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); - exit(); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } - } - } - } +// if ($action == 'confirm_clone' && $confirm == 'yes') +// { +// if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) +// { +// setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); +// } else { +// if ($object->id > 0) { +// $result = $object->createFromClone($user, $object->id); +// if ($result > 0) { +// header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); +// exit(); +// } else { +// setEventMessages($object->error, $object->errors, 'errors'); +// $action = ''; +// } +// } +// } +// } } /* * View */ -$form = new Form($db); -$emptyobject = new stdClass($db); +$form = new Form($db); -$title = $langs->trans("PreventionPlan"); -$title_create = $langs->trans("NewPreventionPlan"); -$title_edit = $langs->trans("ModifyPreventionPlan"); +$title = $langs->trans("PreventionPlan"); +$title_create = $langs->trans("NewPreventionPlan"); +$title_edit = $langs->trans("ModifyPreventionPlan"); $object->picto = 'preventionplandocument@digiriskdolibarr'; $help_url = 'FR:Module_DigiriskDolibarr'; @@ -703,8 +676,7 @@ llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss); // Part to create -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($title_create, '', "digiriskdolibarr32px@digiriskdolibarr"); print '
'; @@ -716,16 +688,12 @@ print dol_get_fiche_head(); - print ''."\n"; - - $type = 'DIGIRISKDOLIBARR_'.strtoupper($object->element).'_ADDON'; - $digirisk_addon = $conf->global->$type; - $modele = new $digirisk_addon($db); + print '
'; //Ref -- Ref print ''; //Label -- Libellé @@ -747,7 +715,7 @@ $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', 'minwidth300', 0, 1); print ''; print ''; - print ''; @@ -805,7 +773,7 @@ // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; - print '
'.$langs->trans("Ref").''; - print ''; - print $modele->getNextValue($object); + print ''; + print $refPreventionPlanMod->getNextValue($object); print '
'.$form->editfieldkey('MaitreOeuvre', 'MaitreOeuvre_id', '', $object, 0).''; + print ''; print $form->selectarray('maitre_oeuvre', $userlist, '', $langs->trans('SelectUser'), null, null, null, "40%", 0,0,'','minwidth300',1); if (!GETPOSTISSET('backtopage')) print ' '; print '
'."\n"; + print ''; print dol_get_fiche_end(); @@ -818,8 +786,7 @@ } // Part to edit record -if (($id || $ref) && $action == 'edit') -{ +if (($id || $ref) && $action == 'edit') { print load_fiche_titre($title_edit, '', "digiriskdolibarr32px@digiriskdolibarr"); print ''; @@ -831,21 +798,17 @@ print dol_get_fiche_head(); - unset($object->fields['status']); - unset($object->fields['element_type']); - unset($object->fields['last_main_doc']); - unset($object->fields['entity']); - $object_resources = $digiriskresources->fetchResourcesFromObject('', $object); $object_signatories = $signatory->fetchSignatory('',$object->id); print ''."\n"; + //Ref -- Ref print ''; - + //Label -- Libellé print ''; @@ -860,46 +823,35 @@ print $form->selectDate($object->date_end, 'datee', 1, 1, 0, '', 1); print ''; - $maitre_oeuvre = is_array($object_signatories['PP_MAITRE_OEUVRE']) ? array_shift($object_signatories['PP_MAITRE_OEUVRE'])->element_id : ''; - //Maitre d'oeuvre + $maitre_oeuvre = is_array($object_signatories['PP_MAITRE_OEUVRE']) ? array_shift($object_signatories['PP_MAITRE_OEUVRE'])->element_id : ''; $userlist = $form->select_dolusers($maitre_oeuvre, '', 1, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', 'minwidth300', 0, 1); - print ''; print ''; - print ''; //External society -- Société extérieure print ''; - print ''; //External responsible -- Responsable de la société extérieure $ext_society_responsible_id = is_array($object_signatories['PP_EXT_SOCIETY_RESPONSIBLE']) ? array_shift($object_signatories['PP_EXT_SOCIETY_RESPONSIBLE'])->element_id : ''; - print ''; @@ -992,27 +944,27 @@ $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpenPreventionPlan'), $langs->trans('ConfirmReOpenPreventionPlan', $object->ref), 'confirm_setInProgress', '', 'yes', 'actionButtonInProgress', 350, 600); } -// Clone confirmation -if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js - || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js -{ - // Define confirmation messages - $formquestionclone = array( - 'text' => $langs->trans("ConfirmClone"), - array('type' => 'text', 'name' => 'clone_ref', 'label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'size'=>24), - array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContentProduct"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1), - ); -// if (!empty($conf->global->PRODUIT_MULTIPRICES)) { -// $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0); -// } -// if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) -// { -// $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1); -// } - - $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePreventionPlan', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'actionButtonClone', 350, 600); -} +//// Clone confirmation +//if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js +// || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js +//{ +// // Define confirmation messages +// $formquestionclone = array( +// 'text' => $langs->trans("ConfirmClone"), +// array('type' => 'text', 'name' => 'clone_ref', 'label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'size'=>24), +// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContentProduct"), 'value' => 1), +// array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1), +// ); +//// if (!empty($conf->global->PRODUIT_MULTIPRICES)) { +//// $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0); +//// } +//// if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) +//// { +//// $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1); +//// } +// +// $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePreventionPlan', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'actionButtonClone', 350, 600); +//} // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'object' => $object); @@ -1024,12 +976,11 @@ print $formconfirm; // Part to show record -if ((empty($action) || ($action != 'create' && $action != 'edit'))) -{ +if ((empty($action) || ($action != 'create' && $action != 'edit'))) { // Object card // ------------------------------------------------------------ - $res = $object->fetch_optionals(); + $object->fetch_optionals(); $head = preventionplanPrepareHead($object); print dol_get_fiche_head($head, 'preventionplanCard', $title, -1, "digiriskdolibarr@digiriskdolibarr"); @@ -1043,10 +994,9 @@ print '
'; print '
'; print '
'; - print '
'; print '
'.$langs->trans("Ref").''; print $object->ref; print '
'.$langs->trans("Label").''; print ''; print '
'.$form->editfieldkey('MaitreOeuvre', 'MaitreOeuvre_id', '', $object, 0).''; - + print ''; print $form->selectarray('maitre_oeuvre', $userlist,$maitre_oeuvre, 1, null, null, null, "40%", 0, 0, 0, 'minwidth300',1); - if (!GETPOSTISSET('backtopage')) print ' '; - print '
'; print $langs->trans("ExtSociety"); print ''; - $events = array(); $events[1] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'ext_society_responsible', 'params' => array('add-customer-contact' => 'disabled')); - $events[2] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'ext_intervenants', 'params' => array('add-customer-contact' => 'disabled')); //For external user force the company to user company if (!empty($user->socid)) { print $form->select_company($user->socid, 'ext_society', '', 1, 1, 0, $events, 0, 'minwidth300'); } else { $ext_society_id = is_array($object_resources['PP_EXT_SOCIETY']) ? array_shift($object_resources['PP_EXT_SOCIETY'])->id : ''; - print $form->select_company($ext_society_id, 'ext_society', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); } if (!GETPOSTISSET('backtopage')) print ' '; - print '
'.$langs->trans("ExtSocietyResponsible").''; print $form->selectcontacts(GETPOST('ext_society', 'int'), $ext_society_responsible_id, 'ext_society_responsible', 0, '', '', 0, 'minwidth300', false, 0, array(), false, '', 'ext_society_responsible'); print '
'; - unset($object->fields['entity']); + //Unset for order unset($object->fields['date_start']); unset($object->fields['date_end']); unset($object->fields['prior_visit_bool']); @@ -1176,8 +1126,8 @@ print '' . $langs->trans("Lock") . ''; } } elseif ($object->status == 3) { - print '' . $langs->trans("ToClone") . ''; - print '' . $langs->trans("Close") . ''; + //print '' . $langs->trans("ToClone") . ''; + print '' . $langs->trans("Close") . ''; } if ($object->date_end == dol_now()){ $object->setArchived($user, false); @@ -1196,20 +1146,13 @@ if (empty($forceall)) $forceall = 0; // Define colspan for the button 'Add' - $colspan = 3; // Columns: total ht + col edit + col delete + $colspan = 3; // Lines - $preventionplanline = new PreventionPlanLine($db); - $preventionplanline->db = $db; - $preventionplanlines = $preventionplanline->fetchAll(GETPOST('id')); + $objectlines = $objectline->fetchAll(GETPOST('id')); - print ''; - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print ''; - } - print ''; + print ''; + print ''; print ''; print ''; print ''; @@ -1217,9 +1160,9 @@ print ''; print ''; - if (!empty($preventionplanlines) && $preventionplanlines > 0) { + if (!empty($objectlines) && $objectlines > 0) { print ''; - foreach ($preventionplanlines as $key => $item) { + foreach ($objectlines as $key => $item) { if ($action == 'editline' && $lineid == $key) { print ''; @@ -1265,10 +1208,7 @@ data-is-preset="" data-id="" aria-label=""> - + @@ -1314,7 +1254,7 @@ class="attachment-thumbail size-thumbnail photo photowithmargin" alt="" '; print ''; print '
'; - print '' . $langs->trans('Ref.') . ''; - print '
' . $langs->trans('Ref.') . '' . $langs->trans('Location') . '' . $form->textwithpicto($langs->trans('ActionsDescription'), $langs->trans("ActionsDescriptionTooltip")) . '' . $form->textwithpicto($langs->trans('INRSRisk'), $langs->trans('INRSRiskTooltip')) . ''.$langs->trans('ActionsPreventionPlanRisk').'
'; - print $refPreventionPlanDetMod->getNextValue($preventionplanline); + print $refPreventionPlanDetMod->getNextValue($objectline); print ''; print $digiriskelement->select_digiriskelement_list('', 'fk_element', '', '1', 0, 0, array(), '', 0, 0, 'minwidth100', '', false, 1); @@ -1391,8 +1331,7 @@ class="fas fa-plus-circle button-add"> aria-label=""> + class="attachment-thumbail size-thumbnail photo photowithmargin" alt=""> @@ -1425,14 +1364,14 @@ class="attachment-thumbail size-thumbnail photo photowithmargin" alt="" if ($includedocgeneration) { print '
'; - $objref = dol_sanitizeFileName($object->ref); + $objref = dol_sanitizeFileName($object->ref); $dir_files = $preventionplandocument->element . '/' . $objref; - $filedir = $upload_dir . '/' . $dir_files; + $filedir = $upload_dir . '/' . $dir_files; $urlsource = $_SERVER["PHP_SELF"] . '?id='. $id; - $modulepart = 'digiriskdolibarr:PreventionPlanDocument'; + $modulepart = 'digiriskdolibarr:PreventionPlanDocument'; $defaultmodel = $conf->global->DIGIRISKDOLIBARR_PREVENTIONPLANDOCUMENT_DEFAULT_MODEL; - $title = $langs->trans('PreventionPlanDocument'); + $title = $langs->trans('PreventionPlanDocument'); print digiriskshowdocuments($modulepart, $dir_files, $filedir, $urlsource, $permissiontoadd, $permissiontodelete, $defaultmodel, 1, 0, 28, 0, '', $title, '', $langs->defaultlang, '', $preventionplandocument, 0, 'remove_file', $object->status == 3, $langs->trans('PreventionPlanMustBeLocked') ); } diff --git a/preventionplan_list.php b/preventionplan_list.php index d22d08c25..9e062f14d 100644 --- a/preventionplan_list.php +++ b/preventionplan_list.php @@ -114,7 +114,7 @@ $permissiontoadd = $user->rights->digiriskdolibarr->preventionplan->write; // Security check - Protection if external user -if ($permissiontoread) accessforbidden(); +if (!$permissiontoread) accessforbidden(); /* * Actions diff --git a/preventionplan_schedule.php b/preventionplan_schedule.php index 9c19fa0e8..c0268c204 100644 --- a/preventionplan_schedule.php +++ b/preventionplan_schedule.php @@ -56,12 +56,10 @@ $preventionplan = new PreventionPlan($db); $object = new Openinghours($db); -$preventionplan->fetch($id); - $hookmanager->initHooks(array('preventionplanschedule', 'globalcard')); // Note that conf->hooks_modules contains array -$permissiontoread = $user->rights->digiriskdolibarr->preventionplandocument->read; -$permissiontoadd = $user->rights->digiriskdolibarr->preventionplandocument->write; +// Load object +$preventionplan->fetch($id); $morewhere = ' AND element_id = ' . $id; $morewhere .= ' AND element_type = ' . "'" . $preventionplan->element . "'"; @@ -69,6 +67,9 @@ $object->fetch(0, '', $morewhere); +// Security check - Protection if external user +$permissiontoread = $user->rights->digiriskdolibarr->preventionplandocument->read; +$permissiontoadd = $user->rights->digiriskdolibarr->preventionplandocument->write; if (!$permissiontoread) accessforbidden(); /* @@ -79,27 +80,29 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $preventionplan, $action); // Note that $action and $preventionplan 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->element_type = $preventionplan->element; - $object->element_id = $id; - $object->status = 1; - $object->monday = GETPOST('monday', 'string'); - $object->tuesday = GETPOST('tuesday', 'string'); - $object->wednesday = GETPOST('wednesday', 'string'); - $object->thursday = GETPOST('thursday', 'string'); - $object->friday = GETPOST('friday', 'string'); - $object->saturday = GETPOST('saturday', 'string'); - $object->sunday = GETPOST('sunday', 'string'); - $object->create($user); +if (empty($reshook)) { + if (($action == 'update' && !GETPOST("cancel", 'alpha')) || ($action == 'updateedit')) { + $object->element_type = $preventionplan->element; + $object->element_id = $id; + $object->status = 1; + + $object->monday = GETPOST('monday', 'string'); + $object->tuesday = GETPOST('tuesday', 'string'); + $object->wednesday = GETPOST('wednesday', 'string'); + $object->thursday = GETPOST('thursday', 'string'); + $object->friday = GETPOST('friday', 'string'); + $object->saturday = GETPOST('saturday', 'string'); + $object->sunday = GETPOST('sunday', 'string'); + + $object->create($user); + } } /* * View */ -$title = $langs->trans("PreventionPlanSchedule"); +$title = $langs->trans("PreventionPlanSchedule"); $help_url = ''; llxHeader('', $title, $help_url); @@ -110,12 +113,10 @@ $head = preventionplanPrepareHead($preventionplan); print dol_get_fiche_head($head, 'preventionplanSchedule', $langs->trans("PreventionPlan"), -1, "digiriskdolibarr@digiriskdolibarr"); -$morehtmlref = ' - ' . $preventionplan->label; -$morehtmlleft .= '
'.digirisk_show_photos('digiriskdolibarr', $conf->digiriskdolibarr->multidir_output[$entity].'/'.$object->element_type, 'small', 5, 0, 0, 0, $width,0, 0, 0, 0, $object->element_type, $object).'
'; +dol_strlen($preventionplan->label) ? $morehtmlref = ' - ' . $preventionplan->label : ''; +//$morehtmlleft .= '
'.digirisk_show_photos('digiriskdolibarr', $conf->digiriskdolibarr->multidir_output[$entity].'/'.$object->element_type, 'small', 5, 0, 0, 0, $width,0, 0, 0, 0, $object->element_type, $object).'
'; digirisk_banner_tab($preventionplan, 'ref', '', 0, 'ref', 'ref', $morehtmlref, '', 0, $morehtmlleft); -print '
'; -print '
'; print dol_get_fiche_end(); @@ -124,7 +125,6 @@ //Show common fields include DOL_DOCUMENT_ROOT.'/custom/digiriskdolibarr/core/tpl/digiriskdolibarr_openinghours_view.tpl.php'; -dol_fiche_end(); // End of page llxFooter(); $db->close();