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 '