Skip to content

Commit

Permalink
#107 [Core] add: saturne interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Jan 20, 2023
1 parent 5c159a4 commit 287b3ba
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 293 deletions.
2 changes: 1 addition & 1 deletion core/modules/modDoliCar.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($db)
// A condition to hide module
$this->hidden = false;
// List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
$this->depends = array('modProduct', 'modProductBatch', 'modFacture', 'modPropale', 'modCommande', 'modCategorie');
$this->depends = array('modProduct', 'modProductBatch', 'modFacture', 'modPropale', 'modCommande', 'modCategorie', 'modSaturne');
$this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
$this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)

Expand Down
5 changes: 5 additions & 0 deletions dolicar.main.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$module = 'dolicar';

if (file_exists(__DIR__ . "/../saturne/saturne.main.inc.php")) $res = @include __DIR__ . "/../saturne/saturne.main.inc.php";
2 changes: 1 addition & 1 deletion lib/dolicar_registrationcertificatefr.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @param RegistrationCertificateFr $object RegistrationCertificateFr
* @return array Array of tabs
*/
function registrationcertificatefrPrepareHead($object)
function registration_certificate_prepare_head($object)
{
global $db, $langs, $conf;

Expand Down
84 changes: 15 additions & 69 deletions view/registrationcertificatefr/registrationcertificatefr_agenda.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,8 @@
* \brief Tab of events on RegistrationCertificateFr
*/

//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
// Load Dolibarr environment
$res = 0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
$i--; $j--;
}
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
}
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
}
// Try main.inc.php using relative path
if (!$res && file_exists("../main.inc.php")) {
$res = @include "../main.inc.php";
}
if (!$res && file_exists("../../main.inc.php")) {
$res = @include "../../main.inc.php";
}
if (!$res && file_exists("../../../main.inc.php")) {
$res = @include "../../../main.inc.php";
}
if (!$res && file_exists("../../../../main.inc.php")) {
$res = @include "../../../../main.inc.php";
}
if (!$res) {
die("Include of main fails");
}
if (file_exists("../../dolicar.main.inc.php")) $res = @include "../../dolicar.main.inc.php";

require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
Expand All @@ -83,15 +32,17 @@
require_once __DIR__ . '/../../class/registrationcertificatefr.class.php';
require_once __DIR__ . '/../../lib/dolicar_registrationcertificatefr.lib.php';

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

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

// Get parameters
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');

if (GETPOST('actioncode', 'array')) {
Expand All @@ -104,10 +55,10 @@
}
$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', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$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
Expand All @@ -122,7 +73,7 @@
}

// Initialize technical objects
$object = new RegistrationCertificateFr($db);
$object = new RegistrationCertificateFr($db);
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->dolicar->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('registrationcertificatefragenda', 'globalcard')); // Note that conf->hooks_modules contains array
Expand All @@ -135,8 +86,6 @@
$upload_dir = $conf->dolicar->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
}

// There is several ways to check permission.
// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
$enablepermissioncheck = 0;
if ($enablepermissioncheck) {
$permissiontoread = $user->rights->dolicar->registrationcertificatefr->read;
Expand All @@ -146,15 +95,12 @@
$permissiontoadd = 1;
}

// Security check (enable the most restrictive one)
//if ($user->socid > 0) accessforbidden();
//if ($user->socid > 0) $socid = $user->socid;
//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
// Security check - Protection if external user
saturne_check_access($module, $object, $permissiontoread);

if (empty($conf->dolicar->enabled)) accessforbidden();
if (!$permissiontoread) accessforbidden();


/*
* Actions
*/
Expand Down Expand Up @@ -191,12 +137,12 @@
$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 = 'EN:Module_Agenda_En';
llxHeader('', $title, $help_url);
saturneHeader($module, $action, $subaction, 0, $title, $help_url);

if (!empty($conf->notification->enabled)) {
$langs->load("mails");
}
$head = registrationcertificatefrPrepareHead($object);
$head = registration_certificate_prepare_head($object);


print dol_get_fiche_head($head, 'agenda', $langs->trans("RegistrationCertificateFr"), -1, $object->picto);
Expand Down
69 changes: 23 additions & 46 deletions view/registrationcertificatefr/registrationcertificatefr_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,8 @@
*/

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


require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
Expand All @@ -70,22 +40,23 @@
$langs->loadLangs(array("dolicar@dolicar", "other"));

// Get parameters
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$subaction = GETPOST('subaction', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'registrationcertificatefrcard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$subaction = GETPOST('subaction', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'registrationcertificatefrcard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
$lineid = GETPOST('lineid', 'int');
$lineid = GETPOST('lineid', 'int');

// Initialize technical objects
$object = new RegistrationCertificateFr($db);
$product = new Product($db);
$category = new Categorie($db);
$object = new RegistrationCertificateFr($db);
$product = new Product($db);
$category = new Categorie($db);
$extrafields = new ExtraFields($db);

$diroutputmassaction = $conf->dolicar->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('registrationcertificatefrcard', 'globalcard')); // Note that conf->hooks_modules contains array

Expand Down Expand Up @@ -127,6 +98,12 @@
$permissiondellink = 1;
}

// Security check - Protection if external user
saturne_check_access($module, $object, $permissiontoread);

if (empty($conf->dolicar->enabled)) accessforbidden();
if (!$permissiontoread) accessforbidden();

$upload_dir = $conf->dolicar->multidir_output[isset($object->entity) ? $object->entity : 1].'/registrationcertificatefr';

// Security check (enable the most restrictive one)
Expand Down Expand Up @@ -216,7 +193,7 @@
$title = $langs->trans("RegistrationCertificateFr");
$help_url = '';
$morejs = array('/dolicar/js/dolicar.js.php');
llxHeader('', $title, $help_url, '', 0, 0, $morejs);
saturneHeader($module, $action, $subaction, 0, $title, $help_url, '', 0, 0, $morejs);

// Part to create
if ($action == 'create') {
Expand Down Expand Up @@ -322,7 +299,7 @@
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
$res = $object->fetch_optionals();

$head = registrationcertificatefrPrepareHead($object);
$head = registration_certificate_prepare_head($object);
print dol_get_fiche_head($head, 'card', $langs->trans("RegistrationCertificateFr"), -1, $object->picto);

$formconfirm = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,8 @@
*/

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


require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
Expand Down Expand Up @@ -90,11 +63,9 @@
$permission = 1;
}

// Security check (enable the most restrictive one)
//if ($user->socid > 0) accessforbidden();
//if ($user->socid > 0) $socid = $user->socid;
//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
// Security check - Protection if external user
saturne_check_access($module, $object, $permissiontoread);

if (empty($conf->dolicar->enabled)) accessforbidden();
if (!$permissiontoread) accessforbidden();

Expand Down Expand Up @@ -142,7 +113,7 @@
$title = $langs->trans('RegistrationCertificateFr')." - ".$langs->trans('ContactsAddresses');
$help_url = '';
//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);
saturneHeader($module, $action, $subaction, 0, $title, $help_url);

$form = new Form($db);
$formcompany = new FormCompany($db);
Expand All @@ -160,7 +131,7 @@
/*
* Show tabs
*/
$head = registrationcertificatefrPrepareHead($object);
$head = registration_certificate_prepare_head($object);

print dol_get_fiche_head($head, 'contact', $langs->trans("RegistrationCertificateFr"), -1, $object->picto);

Expand Down

0 comments on commit 287b3ba

Please sign in to comment.