Skip to content

Commit

Permalink
[PreventionPlan] clean: review code for preventionPlan
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Sep 13, 2021
1 parent 9ebdbf5 commit 2b60d62
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 323 deletions.
9 changes: 8 additions & 1 deletion class/digiriskresources.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion class/digirisksignature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion class/preventionplan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions core/modules/modDigiriskDolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;

Expand Down
2 changes: 1 addition & 1 deletion lib/digiriskdolibarr_preventionplan.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
91 changes: 25 additions & 66 deletions preventionplan_agenda.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -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 '<div id="cardContent" value="">';

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 .= '<div class="floatleft inline-block valignmiddle divphotoref">'.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).'</div>';
//$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.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).'</div>';

digirisk_banner_tab($object, 'ref', '', 0, 'ref', 'ref', $morehtmlref, '', 0, $morehtmlleft);

print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';

$object->info($object->id);
dol_print_object_info($object, 1);

print '</div>';

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.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
$out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
//$out.=$langs->trans("AddAnAction").' ';
//$out.=img_picto($langs->trans("AddAnAction"),'filenew');
//$out.="</a>";
}

$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);
Expand All @@ -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 '</div>';
}
Expand Down
Loading

0 comments on commit 2b60d62

Please sign in to comment.