Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions admin/objecthistory_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* Put some comments here
*/
// Dolibarr environment
$res = @include("../../main.inc.php"); // From htdocs directory
$res = @include "../../main.inc.php"; // From htdocs directory
if (! $res) {
$res = @include("../../../main.inc.php"); // From "custom" directory
$res = @include "../../../main.inc.php"; // From "custom" directory
}

// Libraries
Expand All @@ -39,7 +39,7 @@

// Access control
if (! $user->admin) {
accessforbidden();
accessforbidden();
}

// Parameters
Expand All @@ -48,33 +48,25 @@
/*
* Actions
*/
if (preg_match('/set_(.*)/',$action,$reg))
{
if (preg_match('/set_(.*)/', $action, $reg)) {
$code=$reg[1];
$val = GETPOST($code);
if ($code == 'OBJECTHISTORY_HOOKS_ALLOWED' && !empty($val)) $val = implode(',', $val);

if (dolibarr_set_const($db, $code, $val, 'chaine', 0, '', $conf->entity) > 0)
{
if (dolibarr_set_const($db, $code, $val, 'chaine', 0, '', $conf->entity) > 0) {
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
} else {
dol_print_error($db);
}
}

if (preg_match('/del_(.*)/',$action,$reg))
{

if (preg_match('/del_(.*)/', $action, $reg)) {
$code=$reg[1];
if (dolibarr_del_const($db, $code, 0) > 0)
{
if (dolibarr_del_const($db, $code, 0) > 0) {
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
} else {
dol_print_error($db);
}
}
Expand All @@ -87,18 +79,18 @@

// Subheader
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">'
. $langs->trans("BackToModuleList") . '</a>';
. $langs->trans("BackToModuleList") . '</a>';
print load_fiche_titre($langs->trans($page_name), $linkback);

$notab = -1;
// Configuration header
$head = objecthistoryAdminPrepareHead();
dol_fiche_head(
$head,
'settings',
$langs->trans("Module104089Name"),
$head,
'settings',
$langs->trans("Module104089Name"),
$notab,
"objecthistory@objecthistory"
"objecthistory@objecthistory"
);

// Setup page goes here
Expand All @@ -107,9 +99,9 @@
print '<table class="noborder" width="100%">';


if(!function_exists('setup_print_title')){
print '<div class="error" >'.$langs->trans('AbricotNeedUpdate').' : <a href="http://wiki.atm-consulting.fr/index.php/Accueil#Abricot" target="_blank"><i class="fa fa-info"></i> Wiki</a></div>';
exit;
if (!function_exists('setup_print_title')) {
print '<div class="error" >'.$langs->trans('AbricotNeedUpdate').' : <a href="http://wiki.atm-consulting.fr/index.php/Accueil#Abricot" target="_blank"><i class="fa fa-info"></i> Wiki</a></div>';
exit;
}

setup_print_title("Parameters");
Expand Down
169 changes: 88 additions & 81 deletions class/actions_objecthistory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class ActionsObjectHistory

/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
Expand All @@ -83,38 +85,33 @@ public function __construct($db)
/**
* Overloading the doActions function : replacing the parent's function with the one below
*
* @param array() $parameters Hook metadatas (context, etc...)
* @param CommonObject &$object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string &$action Current action (if set). Generally create or edit or null
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
function doActions($parameters, &$object, &$action, $hookmanager)
public function doActions($parameters, &$object, &$action, $hookmanager)
{
global $conf,$langs,$user;

$TContext = explode(':',$parameters['context']);
$TContext = explode(':', $parameters['context']);

$interSect = array_intersect($TContext, ObjectHistory::getTHookAllowed());
if (!empty($interSect))
{
if (getDolGlobalString('OBJECTHISTORY_ARCHIVE_ON_MODIFY'))
{
if (!empty($interSect)) {
if (getDolGlobalString('OBJECTHISTORY_ARCHIVE_ON_MODIFY')) {
// CommandeFournisseur = reopen
if ($action == 'modif' || $object->element == 'order_supplier' && $object->statut == 2 && $action == 'reopen')
{
if ($action == 'modif' || $object->element == 'order_supplier' && $object->statut == 2 && $action == 'reopen') {
$action = 'objecthistory_modif';
return 1; // on saute l'action par défaut en retournant 1, puis on affiche la pop-in dans formConfirm()
}

// Ask if proposal archive wanted
if ($action == 'objecthistory_confirm_modify')
{
if ($action == 'objecthistory_confirm_modify') {
// New version if wanted
$archive_object = GETPOST('archive_object', 'alpha');
if ($archive_object == 'on')
{
// TPropaleHist::archiverPropale($ATMdb, $object);
if ($archive_object == 'on') {
// TPropaleHist::archiverPropale($ATMdb, $object);
$res = ObjectHistory::archiveObject($object);

if ($res > 0) setEventMessage($langs->trans('ObjectHistoryVersionSuccessfullArchived'));
Expand All @@ -132,16 +129,14 @@ function doActions($parameters, &$object, &$action, $hookmanager)
}

// l'action "delete_archive" affiche une popin de confirmation, donc il faut garder l'arrière plan dans la version précédemment sélectionnée
if($action == 'confirm_view_archive' || $action == 'delete_archive')
{
if ($action == 'confirm_view_archive' || $action == 'delete_archive') {
$id = $object->id;

if ($object->element == 'propal') $object = new PropalHistory($this->db);
elseif ($object->element == 'commande') $object = new CommandeHistory($this->db);
elseif ($object->element == 'supplier_proposal') $object = new SupplierProposalHistory($this->db);
elseif ($object->element == 'order_supplier') $object = new CommandeFournisseurHistory($this->db);
else
{
else {
// Object not handled
return 0;
}
Expand All @@ -152,54 +147,45 @@ function doActions($parameters, &$object, &$action, $hookmanager)
$version->fetch(GETPOST('idVersion'));
$version->unserializeObject();

// if (!empty($object->fields))
// {
// foreach ($object->fields as $key => &$val)
// {
// $val = $version->serialized_object_source->{$key};
// }
// }
// else
// {
foreach($version->serialized_object_source as $k => $v)
{
if ($k == 'db') continue;
$object->{$k} = $v;
}
// if (!empty($object->fields))
// {
// foreach ($object->fields as $key => &$val)
// {
// $val = $version->serialized_object_source->{$key};
// }
// }
// else
// {
foreach ($version->serialized_object_source as $k => $v) {
if ($k == 'db') continue;
$object->{$k} = $v;
}

foreach($object->lines as &$line)
{
$line->description = $line->desc;
$line->db = $this->db;
//$line->fetch_optionals();
}
// }
foreach ($object->lines as &$line) {
$line->description = $line->desc;
$line->db = $this->db;
//$line->fetch_optionals();
}
// }

return 1;

}
elseif($action == 'create_archive')
{
} elseif ($action == 'create_archive') {
$res = ObjectHistory::archiveObject($object);

if ($res > 0) setEventMessage($langs->trans('ObjectHistoryVersionSuccessfullArchived'));
else setEventMessage($this->db->lasterror(), 'errors');

header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
exit;
}
elseif($action == 'restore_archive')
{
} elseif ($action == 'restore_archive') {
$res = ObjectHistory::restoreObject($object, GETPOST('idVersion'));

if ($res > 0) setEventMessage($langs->trans('ObjectHistoryVersionSuccessfullRestored'));
else setEventMessage($this->db->lasterror(), 'errors');

header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
exit;
}
elseif($action == 'confirm_delete_archive')
{
} elseif ($action == 'confirm_delete_archive') {
$version = new ObjectHistory($this->db);
$version->fetch(GETPOST('idVersion'));

Expand All @@ -209,17 +195,22 @@ function doActions($parameters, &$object, &$action, $hookmanager)
header('Location: '.$_SERVER['PHP_SELF'].'?id='.GETPOST('id'));
exit;
}


}

return 0;
}

function formConfirm($parameters, &$object, &$action, $hookmanager)
/**
* Add confirmation content
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process
* @param string $action Current action
* @param HookManager $hookmanager Hook manager
* @return int 0
*/
public function formConfirm($parameters, &$object, &$action, $hookmanager)
{
if ($action == 'objecthistory_modif' || $action == 'view_archive' || $action == 'delete_archive')
{
if ($action == 'objecthistory_modif' || $action == 'view_archive' || $action == 'delete_archive') {
$form = new Form($this->db);
$formConfirm = getFormConfirmObjectHistory($form, $object, $action);
$this->results = array();
Expand All @@ -230,32 +221,36 @@ function formConfirm($parameters, &$object, &$action, $hookmanager)

return 0;
}

function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
/**
* Add more actions buttons
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process
* @param string $action Current action
* @param HookManager $hookmanager Hook manager
* @return int 0
*/
public function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
{
global $conf;

$TContext = explode(':',$parameters['context']);
$TContext = explode(':', $parameters['context']);

$interSect = array_intersect($TContext, ObjectHistory::getTHookAllowed());
if (!empty($interSect) && !empty($object->id))
{
if (!empty($interSect) && !empty($object->id)) {
$TVersion = ObjectHistory::getAllVersionBySourceId($object->id, $object->element);
print getHtmlListObjectHistory($object, $TVersion, $action);

if(!getDolGlobalString('OBJECTHISTORY_HIDE_VERSION_ON_TABS'))
{
if (!getDolGlobalString('OBJECTHISTORY_HIDE_VERSION_ON_TABS')) {
$idVersion = GETPOST('idVersion', 'int');

if (!empty($idVersion) && isset($TVersion[$idVersion]))
{
if (!empty($idVersion) && isset($TVersion[$idVersion])) {
$num = array_search($idVersion, array_keys($TVersion)) + 1;
print '<script type="text/javascript">
$("#id-right div.tabsElem a:first").append(" / v.'.$num.'");
// console.log($("#id-right div.tabsElem a:first"));
</script>';
}
else if(! empty($TVersion)) {
} elseif (! empty($TVersion)) {
$num = count($TVersion) + 1; // TODO voir pour afficher le bon numéro de version si on est en mode visu
print '<script type="text/javascript">
$("#id-right div.tabsElem a:first").append(" / v.'.$num.'");
Expand All @@ -268,22 +263,27 @@ function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)

return 0;
}

function beforePDFCreation($parameters, &$object, &$action, $hookmanager)
/**
* Execute action before PDF creation
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process
* @param string $action Current action
* @param HookManager $hookmanager Hook manager
* @return int 0
*/
public function beforePDFCreation($parameters, &$object, &$action, $hookmanager)
{
global $conf;

if (getDolGlobalString('OBJECTHISTORY_SHOW_VERSION_PDF'))
{
$TContext = explode(':',$parameters['context']);
if (getDolGlobalString('OBJECTHISTORY_SHOW_VERSION_PDF')) {
$TContext = explode(':', $parameters['context']);

$interSect = array_intersect($TContext, ObjectHistory::getTHookAllowed());
if (!empty($interSect))
{
if (!empty($interSect)) {
$TVersion = ObjectHistory::getAllVersionBySourceId($object->id, $object->element);
$num = count($TVersion);
if ($num > 0)
{
if ($num > 0) {
$this->old_object_ref = $object->ref;
$object->ref .='/'.($num+1);
}
Expand All @@ -292,13 +292,20 @@ function beforePDFCreation($parameters, &$object, &$action, $hookmanager)

return 0;
}

function afterPDFCreation($parameters, &$object, &$action, $hookmanager)
/**
* Execute action after PDF creation
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process
* @param string $action Current action
* @param HookManager $hookmanager Hook manager
* @return int 0
*/
public function afterPDFCreation($parameters, &$object, &$action, $hookmanager)
{
global $conf;

if (getDolGlobalString('OBJECTHISTORY_SHOW_VERSION_PDF')&& !empty($this->old_object_ref))
{
if (getDolGlobalString('OBJECTHISTORY_SHOW_VERSION_PDF')&& !empty($this->old_object_ref)) {
$object_src = $parameters['object'];
if (!empty($object_src)) $object_src->ref = $this->old_object_ref;
else $object->ref = $this->old_object_ref;
Expand Down
Loading