diff --git a/admin/history_about.php b/admin/history_about.php
index be89515..b0442bf 100644
--- a/admin/history_about.php
+++ b/admin/history_about.php
@@ -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
@@ -37,7 +37,7 @@
// Access control
if (! $user->admin) {
- accessforbidden();
+ accessforbidden();
}
/*
@@ -48,17 +48,17 @@
// Subheader
$linkback = ''
- . $langs->trans("BackToModuleList") . '';
+ . $langs->trans("BackToModuleList") . '';
print_fiche_titre($langs->trans($page_name), $linkback, 'tools');
// Configuration header
$head = historyAdminPrepareHead();
dol_fiche_head(
- $head,
- 'about',
- $langs->trans("ModuleName"),
- -1,
- 'history@history'
+ $head,
+ 'about',
+ $langs->trans("ModuleName"),
+ -1,
+ 'history@history'
);
require_once __DIR__ . '/../class/techatm.class.php';
@@ -73,4 +73,4 @@
llxFooter();
-$db->close();
\ No newline at end of file
+$db->close();
diff --git a/class/actions_history.class.php b/class/actions_history.class.php
index ae4811a..62a57b4 100644
--- a/class/actions_history.class.php
+++ b/class/actions_history.class.php
@@ -23,10 +23,14 @@
* Put some comments here
*/
+
+require_once __DIR__.'/../backport/v19/core/class/commonhookactions.class.php';
+
/**
* Class ActionsHistory
+ *
+ * Hook manager for History module
*/
-require_once __DIR__.'/../backport/v19/core/class/commonhookactions.class.php';
class ActionsHistory extends \history\RetroCompatCommonHookActions
{
/**
@@ -54,39 +58,33 @@ public function __construct()
/**
* 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)
{
- if (!empty($object) && in_array('globalcard', explode(':', $parameters['context'])))
- {
-
+ if (!empty($object) && in_array('globalcard', explode(':', $parameters['context']))) {
global $history_old_object,$conf;
$history_old_object = clone $object;
-
- if($action == 'addline' && property_exists($object, "class_element_line")) $history_old_object = new $object->class_element_line($this->db);
-
- if(getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE') && strpos($action,'delete')!==false) {
-
- if(!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR',true);
- dol_include_once('/history/config.php');
- if($object->id <= 0) {
+ if ($action == 'addline' && property_exists($object, "class_element_line")) $history_old_object = new $object->class_element_line($this->db);
- if(!empty($parameters['id']) && method_exists($object, 'fetch')) $object->fetch($parameters['id']);
+ if (getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE') && strpos($action, 'delete')!==false) {
+ if (!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR', true);
+ dol_include_once('/history/config.php');
+ if ($object->id <= 0) {
+ if (!empty($parameters['id']) && method_exists($object, 'fetch')) $object->fetch($parameters['id']);
}
DeepHistory::makeCopy($object);
-
- }
-
+ }
}
+ return 0;
}
}
diff --git a/class/history.class.php b/class/history.class.php
index 9f964d7..0809714 100644
--- a/class/history.class.php
+++ b/class/history.class.php
@@ -1,40 +1,67 @@
.
+ */
dol_include_once('abricot/includes/class/class.seedobject.php');
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
-class DeepHistory extends SeedObject {
-/*
- * Gestion des équipements
- * */
+/**
+ * Class DeepHistory
+ *
+ * Manages history logs, object comparisons, and restoration of deleted elements.
+ */
+class DeepHistory extends SeedObject
+{
public $table_element = 'history';
+ /**
+ * Constructor.
+ *
+ * @param DoliDB $db Database handler.
+ */
+ public function __construct($db)
+ {
- function __construct($db) {
-
- $this->db = $db;
-
- $this->fields=array(
- 'fk_object'=>array('type'=>'integer','index'=>true)
- ,'fk_object_deleted'=>array('type'=>'integer','index'=>true, 'notnull'=>1, 'default'=>0)
- ,'key_value1'=>array('type'=>'float','index'=>true)
- ,'fk_user'=>array('type'=>'integer')
- ,'type_object'=>array('type'=>'string','length'=>50,'index'=>true)
- ,'type_action'=>array('type'=>'string','length'=>50,'index'=>true)
- ,'ref'=>array('type'=>'string','length'=>50,'index'=>true)
- ,'table_object'=>array('type'=>'string','length'=>50,'index'=>true)
- ,'object'=>array('type'=>'string')
- ,'date_entry'=>array('type'=>'date')
- ,'what_changed'=>array('type'=>'text')
- );
-
- $this->init();
-
- $this->key_value1 = 0;
-
+ $this->db = $db;
+
+ $this->fields=array(
+ 'fk_object'=>array('type'=>'integer','index'=>true)
+ ,'fk_object_deleted'=>array('type'=>'integer','index'=>true, 'notnull'=>1, 'default'=>0)
+ ,'key_value1'=>array('type'=>'float','index'=>true)
+ ,'fk_user'=>array('type'=>'integer')
+ ,'type_object'=>array('type'=>'string','length'=>50,'index'=>true)
+ ,'type_action'=>array('type'=>'string','length'=>50,'index'=>true)
+ ,'ref'=>array('type'=>'string','length'=>50,'index'=>true)
+ ,'table_object'=>array('type'=>'string','length'=>50,'index'=>true)
+ ,'object'=>array('type'=>'string')
+ ,'date_entry'=>array('type'=>'date')
+ ,'what_changed'=>array('type'=>'text')
+ );
+
+ $this->init();
+
+ $this->key_value1 = 0;
}
-
- function show_ref() {
+ /**
+ * Returns the clickable URL or label of the related object.
+ *
+ * @return string|void Link to object
+ */
+ public function showRef()
+ {
global $db,$user,$conf,$langs;
if ($this->type_object == 'ecmfiles') {
@@ -45,50 +72,68 @@ function show_ref() {
$class = ucfirst($this->type_object);
- if($class=='Project_task') $class='Task';
- else if($class=='Order_supplier') $class='CommandeFournisseur';
- else if($class=='Invoice_supplier') $class='FactureFournisseur';
+ if ($class=='Project_task') $class='Task';
+ elseif ($class=='Order_supplier') $class='CommandeFournisseur';
+ elseif ($class=='Invoice_supplier') $class='FactureFournisseur';
- if(!class_exists($class )) return $langs->trans('CantInstanciate').' : '. $class;
- $object=new $class($db);
+ if (!class_exists($class)) return $langs->trans('CantInstanciate').' : '. $class;
+ $object=new $class($db);
- $res = $object->fetch($this->fk_object);
+ $res = $object->fetch($this->fk_object);
- if($res<=0 || $object->id == 0) {
+ if ($res<=0 || $object->id == 0) {
return $langs->trans('WholeObjectDeleted');
}
- if(method_exists($object, 'getNomUrl')) {
- return $object->getNomUrl(1);
- }
-
+ if (method_exists($object, 'getNomUrl')) {
+ return $object->getNomUrl(1);
+ }
}
-
- function setRef(&$object) {
-
- if(!empty($object->code_client)) $this->ref = $object->code_client;
- else if(!empty($object->facnumber)) $this->ref = $object->facnumber;
- else if(!empty($object->ref)) $this->ref = $object->ref;
-
+ /**
+ * Set ref
+ *
+ * @param object $object Object
+ * @return void
+ */
+ public function setRef(&$object)
+ {
+ if (!empty($object->code_client)) $this->ref = $object->code_client;
+ elseif (!empty($object->facnumber)) $this->ref = $object->facnumber;
+ elseif (!empty($object->ref)) $this->ref = $object->ref;
}
- function compare(&$newO, &$oldO) {
- $this->what_changed = '';
- $this->what_changed .= $this->cmp($newO, $oldO);
+ /**
+ * Compares two objects and stores the differences.
+ *
+ * @param object $newO New object state.
+ * @param object $oldO Old object state.
+ * @return void
+ */
+ public function compare(&$newO, &$oldO)
+ {
+ $this->what_changed = '';
+ $this->what_changed .= $this->cmp($newO, $oldO);
}
-
- private function cmp(&$newO, &$oldO) {
+ /**
+ * Internal comparison logic for object properties and extrafields.
+ *
+ * @param object $newO New object state.
+ * @param object $oldO Old object state.
+ * @return string Diff
+ */
+ private function cmp(&$newO, &$oldO)
+ {
global $langs, $db;
- if( empty($newO) || empty($oldO) ) return '';
+ if ( empty($newO) || empty($oldO) ) return '';
- $diff = '';
+ $diff = '';
// ici on a le code de l'attibut et non la clé de trad il faut la récupérer
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($newO->table_element);
- foreach($newO as $k => $v) {
+ foreach ($newO as $k => $v) {
if ($k == "array_options") {
- foreach($v as $k2 => $v2) {
+ foreach ($v as $k2 => $v2) {
$label = substr($k2, 8);
// Check if the extrafield exists and is of type 'datetime' or 'date'
if (
@@ -99,10 +144,10 @@ private function cmp(&$newO, &$oldO) {
in_array($extrafields->attributes[$newO->table_element]['type'][$label], ['datetime', 'date'])
) {
// Formatage du timestamp au format JJ/MM/AAAA
- $oldFormattedDate = isset($oldO->array_options[$k2]) && (int)$oldO->array_options[$k2]
- ? date('d/m/Y', (int)$oldO->array_options[$k2])
+ $oldFormattedDate = isset($oldO->array_options[$k2]) && (int) $oldO->array_options[$k2]
+ ? date('d/m/Y', (int) $oldO->array_options[$k2])
: "";
- $newFormattedDate = (int)$v2 ? date('d/m/Y', (int)$v2) : "";
+ $newFormattedDate = (int) $v2 ? date('d/m/Y', (int) $v2) : "";
if ($oldFormattedDate != $newFormattedDate) {
$diff .= $langs->trans($extrafields->attributes[$newO->element]["label"][$label]) . ' : ' . $oldFormattedDate . ' => ' . $newFormattedDate . "\n";
@@ -113,155 +158,184 @@ private function cmp(&$newO, &$oldO) {
}
}
- if(!is_array($v) && !is_object($v)) {
+ if (!is_array($v) && !is_object($v)) {
if ( property_exists($oldO, $k) // vérifie que l'attribut exist
&& !is_object($oldO->{$k})
&& !is_array($oldO->{$k})
&& $oldO->{$k} != $v
&& (!empty($v) || (!empty($oldO->{$k}) && $oldO->{$k} !== '0.000' ) )
) {
-
if (isset($oldO->fields[$k]) && $oldO->fields[$k]) {
$propName = $oldO->fields[$k]['label'];
- if ($oldO->fields[$k]['type'] == 'datetime' || $oldO->fields[$k]['type'] == 'date') {
- // Formatage du timestamp au format JJ/MM/AAAA
- $oldFormattedDate = (int)$oldO->{$k} ? date('d/m/Y', (int)$oldO->{$k}) : "";
- $newFormattedDate = (int)$v ? date('d/m/Y', (int)$v) : "";
+ if ($oldO->fields[$k]['type'] == 'datetime' || $oldO->fields[$k]['type'] == 'date') {
+ // Formatage du timestamp au format JJ/MM/AAAA
+ $oldFormattedDate = (int) $oldO->{$k} ? date('d/m/Y', (int) $oldO->{$k}) : "";
+ $newFormattedDate = (int) $v ? date('d/m/Y', (int) $v) : "";
- if ($oldFormattedDate != $newFormattedDate) {
- $diff .= $langs->trans($propName) . ' : ' . $oldFormattedDate . ' => ' . $newFormattedDate . "\n";
- }
- } else {
- $diff .= $langs->trans($propName) . ' : ' . $oldO->{$k} . ' => ' . $v . "\n";
+ if ($oldFormattedDate != $newFormattedDate) {
+ $diff .= $langs->trans($propName) . ' : ' . $oldFormattedDate . ' => ' . $newFormattedDate . "\n";
}
+ } else {
+ $diff .= $langs->trans($propName) . ' : ' . $oldO->{$k} . ' => ' . $v . "\n";
+ }
} else {
-
$diff.=$k.' : '.$oldO->{$k}.' => '.$v."\n";
-
}
}
+ }
+ }
- }
-
- }
-
- return $diff;
- }
-
- function show_whatChanged($show_details = true, $show_restore = true) {
- global $conf,$user;
+ return $diff;
+ }
+ /**
+ * Show what changed
+ *
+ * @param boolean $show_details Show details
+ * @param boolean $show_restore Show restore button
+ * @return string HTML content
+ */
+ public function showWhatChanged($show_details = true, $show_restore = true)
+ {
+ global $conf,$user;
$r = nl2br($this->what_changed);
- if(getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE')) {
- if($show_details && !empty($this->object)) $r.=' '.img_view().'';
+ if (getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE')) {
+ if ($show_details && !empty($this->object)) $r.=' '.img_view().'';
- if($show_restore && $user->hasRight('history', 'restore')) {
+ if ($show_restore && $user->hasRight('history', 'restore')) {
$resql = $this->db->query("SELECT * FROM ".MAIN_DB_PREFIX.$this->table_object.'_deletedhistory');
- if ($resql)
- {
- if($obj=$this->db->fetch_object($res)) {
+ if ($resql) {
+ if ($obj=$this->db->fetch_object($res)) {
$r.=' '.img_picto('Restore', 'refresh').'';
}
- }
- else {} // la table n'existe pas, ça veut dire qu'il n'y pas encore eu de suppression d'objet
+ } else {} // la table n'existe pas, ça veut dire qu'il n'y pas encore eu de suppression d'objet
}
-
}
return $r;
+ }
+ /**
+ * Show action
+ *
+ * @return string Trans of action
+ */
+ public function showAction()
+ {
+ global $langs;
+ $action='';
- }
-
- function show_action() {
- global $langs;
- $action='';
-
- $action = $langs->trans($this->type_action);
-
- return $action;
- }
-
- function show_user() {
-
- $u=new User($this->db);
- $u->fetch($this->fk_user);
-
- return $u->getLoginUrl(1);
+ $action = $langs->trans($this->type_action);
- }
+ return $action;
+ }
+ /**
+ * Show user
+ *
+ * @return string User url
+ */
+ public function showUser()
+ {
- function save(&$user) {
+ $u=new User($this->db);
+ $u->fetch($this->fk_user);
- if(empty($this->fk_user) || empty($this->fk_object) || empty($this->type_action) || empty($this->what_changed)) return false;
+ return $u->getLoginUrl(1);
+ }
+ /**
+ * Save
+ *
+ * @param User $user User object
+ * @return int Id
+ */
+ public function save(&$user)
+ {
- return $this->id>0 ? $this->updateCommon($user) : $this->createCommon($user);
- }
+ if (empty($this->fk_user) || empty($this->fk_object) || empty($this->type_action) || empty($this->what_changed)) return false;
- static function getHistory($type_object, $fk_object) {
+ return $this->id>0 ? $this->updateCommon($user) : $this->createCommon($user);
+ }
+ /**
+ * Get history
+ *
+ * @param string $type_object Type object
+ * @param int $fk_object Id object
+ * @return array Array of objects
+ */
+ public static function getHistory($type_object, $fk_object)
+ {
- global $db;
+ global $db;
- if($type_object == 'task') $type_object = 'project_task';
+ if ($type_object == 'task') $type_object = 'project_task';
- if($type_object=='deletedElement') {
+ if ($type_object=='deletedElement') {
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."history
WHERE type_action LIKE '%DELETE%'
ORDER BY date_entry DESC";
-
- }
- else{
+ } else {
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."history
- WHERE type_object='".$type_object."' AND fk_object=".(int)$fk_object."
+ WHERE type_object='".$type_object."' AND fk_object=".(int) $fk_object."
ORDER BY date_entry DESC ";
}
$res = $db->query($sql);
$TRes=array();
- while($obj = $db->fetch_object($res)) {
-
+ while ($obj = $db->fetch_object($res)) {
$h=new DeepHistory($db);
- if($h->fetch($obj->rowid)>0) {
-
+ if ($h->fetch($obj->rowid)>0) {
$TRes[] = $h;
-
- }
- else{
+ } else {
var_dump($h);exit;
}
}
- return $TRes;
-
- }
- static function addHistory(&$user, $type_object, $fk_object, $action, $what_changed = 'cf. action') {
+ return $TRes;
+ }
+ /**
+ * Add history
+ *
+ * @param User $user User object
+ * @param string $type_object Type object
+ * @param int $fk_object Id object
+ * @param string $action Action
+ * @param string $what_changed Details
+ * @return void
+ */
+ public static function addHistory(&$user, $type_object, $fk_object, $action, $what_changed = 'cf. action')
+ {
global $db;
- $h=new DeepHistory($db);
- $h->fk_object = $fk_object;
- $h->what_changed = $what_changed;
- $h->type_action = $action;
- $h->fk_user = $user->id;
- $h->type_object = $type_object;
- $h->create($user);
- }
-
- static function restoreCopy($id_to_restore) {
+ $h=new DeepHistory($db);
+ $h->fk_object = $fk_object;
+ $h->what_changed = $what_changed;
+ $h->type_action = $action;
+ $h->fk_user = $user->id;
+ $h->type_object = $type_object;
+ $h->create($user);
+ }
+ /**
+ * Restore copy
+ *
+ * @param int $id_to_restore Id history
+ * @return void
+ */
+ public static function restoreCopy($id_to_restore)
+ {
global $user,$db,$langs;
$h=new DeepHistory($db);
- if($h->fetch($id_to_restore )){
-
+ if ($h->fetch($id_to_restore)) {
$table = $h->table_object;
$backup_table = $table.'_deletedhistory';
$obj = new SeedObject($db);
$obj->table_element= $backup_table;
$obj->init_vars_by_db();
- $obj->fetch( $h->fk_object_deleted );
+ $obj->fetch($h->fk_object_deleted);
if (empty($obj->rowid)) $obj->rowid = $obj->id;
$obj2 = clone $obj;
@@ -276,9 +350,14 @@ static function restoreCopy($id_to_restore) {
setEventMessage($langs->trans("DeletedObjectRestored"));
}
-
}
-
+ /**
+ * Update/Replace object in database
+ *
+ * @param User $user User object
+ * @param bool $notrigger Disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
public function replaceCommon(User $user, $notrigger = false)
{
if (is_callable('parent::replaceCommon')) return parent::replaceCommon($user, $notrigger);
@@ -303,15 +382,13 @@ public function replaceCommon(User $user, $notrigger = false)
}
// Clean and check mandatory
- foreach($keys as $key)
- {
+ foreach ($keys as $key) {
// If field is an implicit foreign key field
if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]='';
//var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
- if ($this->fields[$key]['notnull'] == 1 && empty($values[$key]))
- {
+ if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) {
$error++;
$this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
}
@@ -325,11 +402,10 @@ public function replaceCommon(User $user, $notrigger = false)
$this->db->begin();
- if (! $error)
- {
+ if (! $error) {
$sql = 'REPLACE INTO '.MAIN_DB_PREFIX.$this->table_element;
- $sql.= ' ('.implode( ", ", $keys ).')';
- $sql.= ' VALUES ('.implode( ", ", $values ).')';
+ $sql.= ' ('.implode(", ", $keys).')';
+ $sql.= ' VALUES ('.implode(", ", $values).')';
$res = $this->db->query($sql);
if ($res===false) {
@@ -338,21 +414,18 @@ public function replaceCommon(User $user, $notrigger = false)
}
}
- if (! $error)
- {
+ if (! $error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
}
- if (! $error)
- {
+ if (! $error) {
$result=$this->insertExtraFields();
if ($result < 0) $error++;
}
- if (! $error && ! $notrigger)
- {
+ if (! $error && ! $notrigger) {
// Call triggers
- $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user);
+ $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user);
if ($result < 0) { $error++; }
// End call triggers
}
@@ -367,19 +440,23 @@ public function replaceCommon(User $user, $notrigger = false)
}
}
-
- static function makeCopy(&$object)
+ /**
+ * Make Copy
+ *
+ * @param object $object Object source
+ * @return void
+ */
+ public static function makeCopy(&$object)
{
global $db,$user;
- if(is_object($object) && !empty($object->table_element))
- {
+ if (is_object($object) && !empty($object->table_element)) {
$db->query('set foreign_key_checks = 0');
$backup_table = $object->table_element.'_deletedhistory';
$obj = new SeedObject($db);
$obj->table_element= $object->table_element; // Target object table to fetch data
$obj->init_vars_by_db();
- $obj->fetch( $object->id );
+ $obj->fetch($object->id);
if (empty($obj->rowid)) $obj->rowid = $obj->id; // pour le replaceCommon
$obj2 = clone $obj;
@@ -391,18 +468,12 @@ static function makeCopy(&$object)
$obj2->date_creation = $obj2->tms = time();
$obj2->replaceCommon($user);
-
}
- foreach($object as $k=>$v) {
-
- if(is_object($v) || is_array($v)) {
+ foreach ($object as $k=>$v) {
+ if (is_object($v) || is_array($v)) {
self::makeCopy($v);
}
-
}
-
-
}
-
}
diff --git a/class/techatm.class.php b/class/techatm.class.php
index 0b020d8..e434570 100644
--- a/class/techatm.class.php
+++ b/class/techatm.class.php
@@ -1,12 +1,13 @@
db = $db;
}
/**
- * @param DolibarrModules $moduleDescriptor
+ * Get about page content
+ *
+ * @param object $moduleDescriptor Module descriptor
+ * @param boolean $useCache Use cache
+ * @return string Content
*/
- function getAboutPage($moduleDescriptor, $useCache = true){
+ public function getAboutPage($moduleDescriptor, $useCache = true)
+ {
global $langs;
$url = self::ATM_TECH_URL.'/modules/modules-page-about.php';
@@ -82,11 +88,11 @@ function getAboutPage($moduleDescriptor, $useCache = true){
$cacheFileName = dol_sanitizeFileName($moduleDescriptor->name.'_'.$langs->defaultlang).'.html';
$cacheFilePath = $cachePath.'/'.$cacheFileName;
- if($useCache && is_readable($cacheFilePath)){
+ if ($useCache && is_readable($cacheFilePath)) {
$lastChange = filemtime($cacheFilePath);
- if($lastChange > time() - 86400){
+ if ($lastChange > time() - 86400) {
$content = @file_get_contents($cacheFilePath);
- if($content !== false){
+ if ($content !== false) {
return $content;
}
}
@@ -94,7 +100,7 @@ function getAboutPage($moduleDescriptor, $useCache = true){
$content = $this->getContents($url);
- if(!$content){
+ if (!$content) {
$content = '';
// About page goes here
$content.= '

';
@@ -104,14 +110,14 @@ function getAboutPage($moduleDescriptor, $useCache = true){
$content.= '';
}
- if($useCache){
- if(!is_dir($cachePath)){
+ if ($useCache) {
+ if (!is_dir($cachePath)) {
$res = dol_mkdir($cachePath, DOL_DATA_ROOT);
- }else{
+ } else {
$res = true;
}
- if($res){
+ if ($res) {
$comment = ''."\r\n";
file_put_contents(
@@ -125,18 +131,26 @@ function getAboutPage($moduleDescriptor, $useCache = true){
}
/**
- * @param string $moduleTechMane
+ * Get module doc URL
+ *
+ * @param string $moduleTechMane Module technical name
+ * @return string URL
*/
- public static function getModuleDocUrl($moduleTechMane){
+ public static function getModuleDocUrl($moduleTechMane)
+ {
$url = self::ATM_TECH_URL.'/modules/doc-redirect.php';
$url.= '?module='.$moduleTechMane;
return $url;
}
/**
- * @param DolibarrModules $moduleDescriptor
+ * Get last module version URL
+ *
+ * @param object $moduleDescriptor Module descriptor
+ * @return string URL
*/
- public static function getLastModuleVersionUrl($moduleDescriptor){
+ public static function getLastModuleVersionUrl($moduleDescriptor)
+ {
$url = self::ATM_TECH_URL.'/modules/modules-last-version.php';
$url.= '?module='.$moduleDescriptor->name;
$url.= '&number='.$moduleDescriptor->numero;
@@ -148,17 +162,20 @@ public static function getLastModuleVersionUrl($moduleDescriptor){
/**
- * @param $url
- * @return false|object
+ * Get JSON data from URL
+ *
+ * @param string $url URL to reach
+ * @return mixed Data content
*/
- public function getJsonData($url){
+ public function getJsonData($url)
+ {
$this->data = false;
$res = @file_get_contents($url);
$this->http_response_header = $http_response_header;
$this->TResponseHeader = self::parseHeaders($http_response_header);
- if($res !== false){
+ if ($res !== false) {
$pos = strpos($res, '{');
- if($pos > 0){
+ if ($pos > 0) {
// cela signifie qu'il y a une erreur ou que la sortie n'est pas propre
$res = substr($res, $pos);
}
@@ -170,168 +187,102 @@ public function getJsonData($url){
}
/**
- * @param $url
- * @return false|string
+ * Get content from URL
+ *
+ * @param string $url URL to reach
+ * @return false|string Content or false
*/
- public function getContents($url){
+ public function getContents($url)
+ {
$this->data = false;
$res = @file_get_contents($url);
$this->http_response_header = $http_response_header;
$this->TResponseHeader = self::parseHeaders($http_response_header);
- if($res !== false){
+ if ($res !== false) {
$this->data = $res;
}
return $this->data;
}
-
- public static function http_response_code_msg($code = NULL)
+ /**
+ * Get HTTP response code message
+ *
+ * @param int $code HTTP Code
+ * @return string Message
+ */
+ public static function httpResponseCodeMsg($code = null)
{
- if ($code !== NULL) {
-
+ if ($code !== null) {
switch ($code) {
- case 100:
- $text = 'Continue';
- break;
- case 101:
- $text = 'Switching Protocols';
- break;
- case 200:
- $text = 'OK';
- break;
- case 201:
- $text = 'Created';
- break;
- case 202:
- $text = 'Accepted';
- break;
- case 203:
- $text = 'Non-Authoritative Information';
- break;
- case 204:
- $text = 'No Content';
- break;
- case 205:
- $text = 'Reset Content';
- break;
- case 206:
- $text = 'Partial Content';
- break;
- case 300:
- $text = 'Multiple Choices';
- break;
- case 301:
- $text = 'Moved Permanently';
- break;
- case 302:
- $text = 'Moved Temporarily';
- break;
- case 303:
- $text = 'See Other';
- break;
- case 304:
- $text = 'Not Modified';
- break;
- case 305:
- $text = 'Use Proxy';
- break;
- case 400:
- $text = 'Bad Request';
- break;
- case 401:
- $text = 'Unauthorized';
- break;
- case 402:
- $text = 'Payment Required';
- break;
- case 403:
- $text = 'Forbidden';
- break;
- case 404:
- $text = 'Not Found';
- break;
- case 405:
- $text = 'Method Not Allowed';
- break;
- case 406:
- $text = 'Not Acceptable';
- break;
- case 407:
- $text = 'Proxy Authentication Required';
- break;
- case 408:
- $text = 'Request Time-out';
- break;
- case 409:
- $text = 'Conflict';
- break;
- case 410:
- $text = 'Gone';
- break;
- case 411:
- $text = 'Length Required';
- break;
- case 412:
- $text = 'Precondition Failed';
- break;
- case 413:
- $text = 'Request Entity Too Large';
- break;
- case 414:
- $text = 'Request-URI Too Large';
- break;
- case 415:
- $text = 'Unsupported Media Type';
- break;
- case 500:
- $text = 'Internal Server Error';
- break;
- case 501:
- $text = 'Not Implemented';
- break;
- case 502:
- $text = 'Bad Gateway';
- break;
- case 503:
- $text = 'Service Unavailable';
- break;
- case 504:
- $text = 'Gateway Time-out';
- break;
- case 505:
- $text = 'HTTP Version not supported';
- break;
+ case 100: $text = 'Continue'; break;
+ case 101: $text = 'Switching Protocols'; break;
+ case 200: $text = 'OK'; break;
+ case 201: $text = 'Created'; break;
+ case 202: $text = 'Accepted'; break;
+ case 203: $text = 'Non-Authoritative Information'; break;
+ case 204: $text = 'No Content'; break;
+ case 205: $text = 'Reset Content'; break;
+ case 206: $text = 'Partial Content'; break;
+ case 300: $text = 'Multiple Choices'; break;
+ case 301: $text = 'Moved Permanently'; break;
+ case 302: $text = 'Moved Temporarily'; break;
+ case 303: $text = 'See Other'; break;
+ case 304: $text = 'Not Modified'; break;
+ case 305: $text = 'Use Proxy'; break;
+ case 400: $text = 'Bad Request'; break;
+ case 401: $text = 'Unauthorized'; break;
+ case 402: $text = 'Payment Required'; break;
+ case 403: $text = 'Forbidden'; break;
+ case 404: $text = 'Not Found'; break;
+ case 405: $text = 'Method Not Allowed'; break;
+ case 406: $text = 'Not Acceptable'; break;
+ case 407: $text = 'Proxy Authentication Required'; break;
+ case 408: $text = 'Request Time-out'; break;
+ case 409: $text = 'Conflict'; break;
+ case 410: $text = 'Gone'; break;
+ case 411: $text = 'Length Required'; break;
+ case 412: $text = 'Precondition Failed'; break;
+ case 413: $text = 'Request Entity Too Large'; break;
+ case 414: $text = 'Request-URI Too Large'; break;
+ case 415: $text = 'Unsupported Media Type'; break;
+ case 500: $text = 'Internal Server Error'; break;
+ case 501: $text = 'Not Implemented'; break;
+ case 502: $text = 'Bad Gateway'; break;
+ case 503: $text = 'Service Unavailable'; break;
+ case 504: $text = 'Gateway Time-out'; break;
+ case 505: $text = 'HTTP Version not supported'; break;
default:
$text = 'Unknown http status code "' . htmlentities($code) . '"';
break;
}
return $text;
-
} else {
- return $text = 'Unknown http status code NULL';
+ return 'Unknown http status code NULL';
}
}
-
- public static function parseHeaders( $headers )
+ /**
+ * Parse Headers
+ *
+ * @param array $headers Headers
+ * @return array Parsed headers
+ */
+ public static function parseHeaders($headers)
{
$head = array();
- if(!is_array($headers)){
+ if (!is_array($headers)) {
return $head;
}
- foreach( $headers as $k=>$v )
- {
- $t = explode( ':', $v, 2 );
- if( isset( $t[1] ) )
- $head[ trim($t[0]) ] = trim( $t[1] );
- else
- {
+ foreach ($headers as $k=>$v) {
+ $t = explode(':', $v, 2);
+ if ( isset($t[1]) )
+ $head[ trim($t[0]) ] = trim($t[1]);
+ else {
$head[] = $v;
- if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
+ if ( preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out) )
$head['reponse_code'] = intval($out[1]);
}
}
return $head;
}
-
}
diff --git a/config.default.php b/config.default.php
index 32ed32b..429f2c3 100644
--- a/config.default.php
+++ b/config.default.php
@@ -1,30 +1,43 @@
.
+ */
+ if (is_file('../main.inc.php'))$dir = '../';
+elseif (is_file('../../../main.inc.php'))$dir = '../../../';
+else $dir = '../../';
- if(!defined('INC_FROM_DOLIBARR') && defined('INC_FROM_CRON_SCRIPT')) {
- include_once($dir."master.inc.php");
- }
- elseif(!defined('INC_FROM_DOLIBARR')) {
- include_once($dir."main.inc.php");
- } else {
- global $dolibarr_main_db_host, $dolibarr_main_db_name, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_type;
- }
- if(!defined('DB_HOST') && !empty($dolibarr_main_db_host)) {
- if(! defined('DB_HOST')) define('DB_HOST',$dolibarr_main_db_host);
- if(! defined('DB_NAME')) define('DB_NAME',$dolibarr_main_db_name);
- if(! defined('DB_USER')) define('DB_USER',$dolibarr_main_db_user);
- if(! defined('DB_PASS')) define('DB_PASS',$dolibarr_main_db_pass);
- if(! defined('DB_DRIVER')) define('DB_DRIVER',$dolibarr_main_db_type);
- }
-if(!dol_include_once('abricot/inc.core.php')) {
+if (!defined('INC_FROM_DOLIBARR') && defined('INC_FROM_CRON_SCRIPT')) {
+ include_once $dir."master.inc.php";
+} elseif (!defined('INC_FROM_DOLIBARR')) {
+ include_once $dir."main.inc.php";
+} else {
+ global $dolibarr_main_db_host, $dolibarr_main_db_name, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_type;
+}
+if (!defined('DB_HOST') && !empty($dolibarr_main_db_host)) {
+ if (! defined('DB_HOST')) define('DB_HOST', $dolibarr_main_db_host);
+ if (! defined('DB_NAME')) define('DB_NAME', $dolibarr_main_db_name);
+ if (! defined('DB_USER')) define('DB_USER', $dolibarr_main_db_user);
+ if (! defined('DB_PASS')) define('DB_PASS', $dolibarr_main_db_pass);
+ if (! defined('DB_DRIVER')) define('DB_DRIVER', $dolibarr_main_db_type);
+}
+
+if (!dol_include_once('abricot/inc.core.php')) {
print $langs->trans('AbricotNotFound'). ' : Abricot';
exit;
- }
+}
dol_include_once('history/class/history.class.php');
-
diff --git a/config.php b/config.php
index 3e32579..c2c38a8 100644
--- a/config.php
+++ b/config.php
@@ -1,3 +1,18 @@
.
+ */
require __DIR__.'/config.default.php';
diff --git a/core/modules/modHistory.class.php b/core/modules/modHistory.class.php
index b0579d7..c030372 100644
--- a/core/modules/modHistory.class.php
+++ b/core/modules/modHistory.class.php
@@ -38,11 +38,11 @@ class modHistory extends DolibarrModules
*
* @param DoliDB $db Database handler
*/
- function __construct($db)
+ public function __construct($db)
{
- global $langs,$conf;
+ global $langs,$conf;
- $this->db = $db;
+ $this->db = $db;
$this->editor_name = 'ATM Consulting';
$this->editor_url = 'https://www.atm-consulting.fr';
@@ -57,7 +57,7 @@ function __construct($db)
// It is used to group modules in module setup page
$this->family = "ATM Consulting - CRM";
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
- $this->name = preg_replace('/^mod/i','',get_class($this));
+ $this->name = preg_replace('/^mod/i', '', get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Description of module History";
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
@@ -87,7 +87,7 @@ function __construct($db)
// 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
// 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
// 'css' => array('/history/css/history.css.php'), // Set this to relative path of css file if module has its own css file
- // 'js' => array('/history/js/history.js'), // Set this to relative path of js file if module must load a js on all pages
+ // 'js' => array('/history/js/history.js'), // Set this to relative path of js file if module must load a js on all pages
// 'hooks' => array('hookcontext1','hookcontext2') // Set here all hooks context managed by module
// 'dir' => array('output' => 'othermodulename'), // To force the default directories names
// 'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'isModEnabled("module1") && isModEnabled("module2")', 'picto'=>'yourpicto@history')) // Set here all workflow context managed by module
@@ -95,7 +95,7 @@ function __construct($db)
$this->module_parts = array(
'triggers' => 1
,'hooks'=>array('globalcard')
- );
+ );
// Data directories to create when module is enabled.
// Example: this->dirs = array("/history/temp");
@@ -126,9 +126,9 @@ function __construct($db)
$this->const = array();
// Array to add new pages in new tabs
- // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@history:$user->rights->history->read:/history/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
- // 'objecttype:+tabname2:Title2:mylangfile@history:$user->rights->othermodule->read:/history/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2
- // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
+ // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@history:$user->hasRight('history', 'read'):/history/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
+ // 'objecttype:+tabname2:Title2:mylangfile@history:$user->hasRight('othermodule', 'read'):/history/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2
+ // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
// where objecttype can be
// 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
// 'contact' to add a tab in contact view
@@ -149,60 +149,59 @@ function __construct($db)
// 'stock' to add a tab in stock view
// 'thirdparty' to add a tab in third party view
// 'user' to add a tab in user view
- $this->tabs = array(
- 'propal:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=propal&id=__ID__'
- ,'propal:-info:NU:true'
+ $this->tabs = array(
+ 'propal:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=propal&id=__ID__'
+ ,'propal:-info:NU:true'
- ,'thirdparty:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=societe&id=__ID__'
- ,'thirdparty:-info:NU:true'
+ ,'thirdparty:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=societe&id=__ID__'
+ ,'thirdparty:-info:NU:true'
- ,'contact:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=contact&id=__ID__'
- ,'contact:-info:NU:true'
+ ,'contact:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=contact&id=__ID__'
+ ,'contact:-info:NU:true'
- ,'action:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=action&id=__ID__'
- ,'action:-info:NU:true'
+ ,'action:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=action&id=__ID__'
+ ,'action:-info:NU:true'
- ,'product:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=product&id=__ID__'
- ,'product:-info:NU:true'
+ ,'product:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=product&id=__ID__'
+ ,'product:-info:NU:true'
- ,'project:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=project&id=__ID__'
- ,'project:-info:NU:true'
+ ,'project:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=project&id=__ID__'
+ ,'project:-info:NU:true'
- ,'task:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=task&id=__ID__'
- ,'task:-info:NU:true'
+ ,'task:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=task&id=__ID__'
+ ,'task:-info:NU:true'
- //TODO : for dolibarr 5.0 order class will manage correctly change so can be uncomment
- ,'order:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=commande&id=__ID__'
- ,'order:-info:NU:true'
+ //TODO : for dolibarr 5.0 order class will manage correctly change so can be uncomment
+ ,'order:+history:History:history@history:$user->hasRight("history","read"):/history/history.php?type_object=commande&id=__ID__'
+ ,'order:-info:NU:true'
- );
+ );
- // Dictionaries
- if (! isModEnabled('history'))
- {
- $conf->history=new stdClass();
- $conf->history->enabled=0;
- }
+ // Dictionaries
+ if (! isModEnabled('history')) {
+ $conf->history=new stdClass();
+ $conf->history->enabled=0;
+ }
$this->dictionaries=array();
- /* Example:
- if (! isModEnabled("history")) $conf->history->enabled=0; // This is to avoid warnings
- $this->dictionaries=array(
- 'langs'=>'mylangfile@history',
- 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
- 'tablib'=>array("Table1","Table2","Table3"), // Label of tables
- 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields
- 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
- 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
- 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
- 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
- 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
- 'tabcond'=>array(isModEnabled("history"),isModEnabled("history"),isModEnabled("history")) // Condition to show each dictionary
- );
- */
-
- // Boxes
+ /* Example:
+ if (! isModEnabled("history")) $conf->history->enabled=0; // This is to avoid warnings
+ $this->dictionaries=array(
+ 'langs'=>'mylangfile@history',
+ 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
+ 'tablib'=>array("Table1","Table2","Table3"), // Label of tables
+ 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields
+ 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
+ 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
+ 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
+ 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
+ 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
+ 'tabcond'=>array(isModEnabled("history"),isModEnabled("history"),isModEnabled("history")) // Condition to show each dictionary
+ );
+ */
+
+ // Boxes
// Add here list of php file(s) stored in core/boxes that contains class to show a box.
- $this->boxes = array(); // List of boxes
+ $this->boxes = array(); // List of boxes
// Example:
//$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
@@ -270,7 +269,7 @@ function __construct($db)
// Example:
// $this->export_code[$r]=$this->rights_class.'_'.$r;
// $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
- // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
+ // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
// $this->export_permission[$r]=array(array("facture","facture","export"));
// $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
// $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
@@ -287,20 +286,20 @@ function __construct($db)
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories
*
- * @param string $options Options when enabling module ('', 'noboxes')
+ * @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
- function init($options='')
+ public function init($options = '')
{
$sql = array();
- define('INC_FROM_DOLIBARR',true);
- dol_include_once('/history/config.php');
+ define('INC_FROM_DOLIBARR', true);
+ dol_include_once('/history/config.php');
- global $db;
+ global $db;
- $o=new DeepHistory($db);
- $o->init_db_by_vars();
+ $o=new DeepHistory($db);
+ $o->init_db_by_vars();
$result=$this->_load_tables('/history/sql/');
@@ -312,14 +311,13 @@ function init($options='')
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
- * @param string $options Options when enabling module ('', 'noboxes')
+ * @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
- function remove($options='')
+ public function remove($options = '')
{
$sql = array();
return $this->_remove($sql, $options);
}
-
}
diff --git a/core/triggers/interface_99_modHistory_Historytrigger.class.php b/core/triggers/interface_99_modHistory_Historytrigger.class.php
index 69ec20f..d4a553a 100644
--- a/core/triggers/interface_99_modHistory_Historytrigger.class.php
+++ b/core/triggers/interface_99_modHistory_Historytrigger.class.php
@@ -37,136 +37,131 @@
class InterfaceHistorytrigger extends DolibarrTriggers
{
- protected $db;
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
-
- $this->name = preg_replace('/^Interface/i', '', get_class($this));
- $this->family = "demo";
- $this->description = "Triggers of this module are empty functions."
- . "They have no effect."
- . "They are provided for tutorial purpose only.";
- // 'development', 'experimental', 'dolibarr' or version
- $this->version = 'development';
- $this->picto = 'history@history';
- }
-
- /**
- * Trigger name
- *
- * @return string Name of trigger file
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * Trigger description
- *
- * @return string Description of trigger file
- */
- public function getDesc()
- {
- return $this->description;
- }
-
- /**
- * Trigger version
- *
- * @return string Version of trigger file
- */
- public function getVersion()
- {
- global $langs;
- $langs->load("admin");
-
- if ($this->version == 'development') {
- return $langs->trans("Development");
- } elseif ($this->version == 'experimental')
-
- return $langs->trans("Experimental");
- elseif ($this->version == 'dolibarr') return DOL_VERSION;
- elseif ($this->version) return $this->version;
- else {
- return $langs->trans("Unknown");
- }
- }
-
- /**
- * Function called when a Dolibarrr business event is done.
- * All functions "run_trigger" are triggered if file
- * is inside directory core/triggers
- *
- * @param string $action Event action code
- * @param Object $object Object
- * @param User $user Object user
- * @param Translate $langs Object langs
- * @param conf $conf Object conf
- * @return int <0 if KO, 0 if no triggered ran, >0 if OK
- */
- public function runTrigger($action, $object, $user, $langs, $conf)
- {
- // Put here code you want to execute when a Dolibarr business events occurs.
- // Data and type of action are stored into $object and $action
- // Users
+ protected $db;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+
+ $this->name = preg_replace('/^Interface/i', '', get_class($this));
+ $this->family = "demo";
+ $this->description = "Triggers of this module are empty functions. They have no effect.They are provided for tutorial purpose only.";
+ // 'development', 'experimental', 'dolibarr' or version
+ $this->version = 'development';
+ $this->picto = 'history@history.png';
+ }
+
+ /**
+ * Return name of trigger file
+ *
+ * @return string Name of trigger file
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Return description of trigger file
+ *
+ * @return string Description of trigger file
+ */
+ public function getDesc()
+ {
+ return $this->description;
+ }
+
+ /**
+ * Return version of trigger file
+ *
+ * @return string Version of trigger file
+ */
+ public function getVersion()
+ {
+ global $langs;
+ $langs->load("admin");
+
+ if ($this->version == 'development') {
+ return $langs->trans("Development");
+ } elseif ($this->version == 'experimental')
+
+ return $langs->trans("Experimental");
+ elseif ($this->version == 'dolibarr') return DOL_VERSION;
+ elseif ($this->version) return $this->version;
+ else {
+ return $langs->trans("Unknown");
+ }
+ }
+
+ /**
+ * Function called when a Dolibarrr business event is done.
+ * All functions "run_trigger" are triggered if file
+ * is inside directory core/triggers
+ *
+ * @param string $action Event action code
+ * @param Object $object Object
+ * @param User $user Object user
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return int <0 if KO, 0 if no triggered ran, >0 if OK
+ */
+ public function runTrigger($action, $object, $user, $langs, $conf)
+ {
+ // Put here code you want to execute when a Dolibarr business events occurs.
+ // Data and type of action are stored into $object and $action
+ // Users
$langs->load("history@history");
- $db = &$object->db;
+ $db = &$object->db;
- if(is_null($db)) {
- $db = &$this->db;
- }
- if(!empty($object->element)) {
-
- if(!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR',true);
- if(!dol_include_once('history/config.php')) return 0;
+ if (is_null($db)) {
+ $db = &$this->db;
+ }
+ if (!empty($object->element)) {
+ if (!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR', true);
+ if (!dol_include_once('history/config.php')) return 0;
$type_object = $object->element;
$noObjects = explode(',', getDolGlobalString('HISTORY_NO_OBJECT_LIST'));
- if(in_array($type_object, $noObjects)) return 0;
+ if (in_array($type_object, $noObjects)) return 0;
$deepHistory = new DeepHistory($db);
- if(substr($type_object,-3) == 'det'){
- $type_object = substr( $type_object,0,-3 );
- if( !empty( $object->{ 'fk_'.$type_object } )) $deepHistory->fk_object = $object->{ 'fk_'.$type_object }; // TODO ça marche pas, pas rempli quand update line :/
- }
+ if (substr($type_object, -3) == 'det') {
+ $type_object = substr($type_object, 0, -3);
+ if ( !empty($object->{ 'fk_'.$type_object })) $deepHistory->fk_object = $object->{ 'fk_'.$type_object }; // TODO ça marche pas, pas rempli quand update line :/
+ }
- if( empty($deepHistory->fk_object) ) $deepHistory->fk_object = $object->id;
+ if ( empty($deepHistory->fk_object) ) $deepHistory->fk_object = $object->id;
global $history_old_object;
- if( !empty($object->oldline) ) $deepHistory->compare($object, $object->oldline);
- else if( !empty($object->oldcopy) ) $deepHistory->compare($object, $object->oldcopy);
- else if( !empty($history_old_object) && get_class( $history_old_object ) == get_class( $object) ) $deepHistory->compare($object, $history_old_object);
- else {
-
+ if ( !empty($object->oldline) ) $deepHistory->compare($object, $object->oldline);
+ elseif ( !empty($object->oldcopy) ) $deepHistory->compare($object, $object->oldcopy);
+ elseif ( !empty($history_old_object) && get_class($history_old_object) == get_class($object) ) $deepHistory->compare($object, $history_old_object);
+ else {
$deepHistory->what_changed = $langs->trans("NOTHING_FOUND");
+ }
- }
-
- if(getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE') && strpos($action,'DELETE')!==false) {
+ if (getDolGlobalString('HISTORY_STOCK_FULL_OBJECT_ON_DELETE') && strpos($action, 'DELETE')!==false) {
//TODO Faire en sorte que ça marche, cette feature n'a jamais été dev complement il y a pas mal de choses à faire pour que ça fonctionne
$deepHistory->table_object = $object->table_element;
$deepHistory->fk_object_deleted = $object->id;
- if(empty($deepHistory->what_changed)) $deepHistory->what_changed = $langs->trans("NOTHING_FOUNDS");
+ if (empty($deepHistory->what_changed)) $deepHistory->what_changed = $langs->trans("NOTHING_FOUNDS");
}
- if($action == 'CATEGORY_LINK' || $action == 'CATEGORY_UNLINK' || $action == 'CATEGORY_MODIFY'){
+ if ($action == 'CATEGORY_LINK' || $action == 'CATEGORY_UNLINK' || $action == 'CATEGORY_MODIFY') {
$langs->load('history@history');
- if($action == 'CATEGORY_LINK') {
+ if ($action == 'CATEGORY_LINK') {
$objectToLink = $object->linkto;
} elseif ($action == 'CATEGORY_MODIFY' && is_object($object->context['linkto'])) {
$objectToLink = $object->context['linkto'];
@@ -182,14 +177,14 @@ public function runTrigger($action, $object, $user, $langs, $conf)
$object->fetch($object->id);
$type_object = $objectToLink->element;
- if($action == 'CATEGORY_LINK' || $action == 'CATEGORY_MODIFY' && is_object($object->context['linkto'])){
+ if ($action == 'CATEGORY_LINK' || $action == 'CATEGORY_MODIFY' && is_object($object->context['linkto'])) {
$deepHistory->what_changed = $langs->transnoentitiesnoconv('CategLinked')." ==> $object->label";
}
- if($action == 'CATEGORY_UNLINK' || $action == 'CATEGORY_MODIFY' && isset($object->context['unlinkoff']) && is_object($object->context['unlinkoff'])){
+ if ($action == 'CATEGORY_UNLINK' || $action == 'CATEGORY_MODIFY' && isset($object->context['unlinkoff']) && is_object($object->context['unlinkoff'])) {
$deepHistory->what_changed = $langs->transnoentitiesnoconv('CategUnlinked')." ==> $object->label";
}
}
- if($action == 'COMPANY_LINK_SALE_REPRESENTATIVE' || $action == 'COMPANY_UNLINK_SALE_REPRESENTATIVE'){
+ if ($action == 'COMPANY_LINK_SALE_REPRESENTATIVE' || $action == 'COMPANY_UNLINK_SALE_REPRESENTATIVE') {
$langs->load('history@history');
$deepHistory->fk_object = $object->id;
@@ -197,47 +192,44 @@ public function runTrigger($action, $object, $user, $langs, $conf)
$usrtarget = new User($db);
$usrtarget->fetch($object->context['commercial_modified']);
$label = $usrtarget->lastname.' '.$usrtarget->firstname;
- if($action == 'COMPANY_LINK_SALE_REPRESENTATIVE')$deepHistory->what_changed = $langs->transnoentitiesnoconv('COMPANY_LINK_SALE_REPRESENTATIVE')." ==> $label";
- if($action == 'COMPANY_UNLINK_SALE_REPRESENTATIVE')$deepHistory->what_changed = $langs->transnoentitiesnoconv('COMPANY_UNLINK_SALE_REPRESENTATIVE')." ==> $label";
-
+ if ($action == 'COMPANY_LINK_SALE_REPRESENTATIVE')$deepHistory->what_changed = $langs->transnoentitiesnoconv('COMPANY_LINK_SALE_REPRESENTATIVE')." ==> $label";
+ if ($action == 'COMPANY_UNLINK_SALE_REPRESENTATIVE')$deepHistory->what_changed = $langs->transnoentitiesnoconv('COMPANY_UNLINK_SALE_REPRESENTATIVE')." ==> $label";
}
$deepHistory->setRef($object);
- $deepHistory->type_action = $action;
- $deepHistory->fk_user = $user->id;
- $deepHistory->type_object = $type_object;
+ $deepHistory->type_action = $action;
+ $deepHistory->fk_user = $user->id;
+ $deepHistory->type_object = $type_object;
- if(!empty($deepHistory->what_changed)) {
+ if (!empty($deepHistory->what_changed)) {
$res = $deepHistory->create($user);
}
+ } else {
+ switch ($action) {
+ case 'STOCK_MOVEMENT':
+ if (!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR', true);
+ dol_include_once('/history/config.php');
- }else{
- switch ($action){
- case 'STOCK_MOVEMENT':
-
- if(!defined('INC_FROM_DOLIBARR')) define('INC_FROM_DOLIBARR',true);
- dol_include_once('/history/config.php');
+ $deepHistory=new DeepHistory($db);
+ $produit = new Product($db);
+ $produit->fetch($object->product_id);
- $deepHistory=new DeepHistory($db);
- $produit = new Product($db);
- $produit->fetch($object->product_id);
+ $deepHistory->setRef($produit);
- $deepHistory->setRef($produit);
+ $deepHistory->type_action = $action;
+ $deepHistory->fk_user = $user->id;
+ $deepHistory->type_object = 'product';
+ $deepHistory->fk_object = $produit->id;
+ $deepHistory->what_changed = 'pmp => '.$produit->pmp."\n".'qty_movement => '.$object->qty;
+ $deepHistory->key_value1 = $produit->pmp;
- $deepHistory->type_action = $action;
- $deepHistory->fk_user = $user->id;
- $deepHistory->type_object = 'product';
- $deepHistory->fk_object = $produit->id;
- $deepHistory->what_changed = 'pmp => '.$produit->pmp."\n".'qty_movement => '.$object->qty;
- $deepHistory->key_value1 = $produit->pmp;
+ $deepHistory->create($user);
- $deepHistory->create($user);
-
- break;
- }
- }
+ break;
+ }
+ }
- return 0;
- }
+ return 0;
+ }
}
diff --git a/history.php b/history.php
index 0f8a3dd..a98f76c 100644
--- a/history.php
+++ b/history.php
@@ -1,187 +1,174 @@
.
+ */
+
+ require 'config.php';
+
+ dol_include_once('/core/lib/functions2.lib.php');
+ dol_include_once('/comm/propal/class/propal.class.php');
+ dol_include_once('/core/lib/propal.lib.php');
+ dol_include_once('/core/lib/contact.lib.php');
+ dol_include_once('/core/lib/agenda.lib.php');
+ dol_include_once('/comm/action/class/actioncomm.class.php');
+ dol_include_once('/core/lib/product.lib.php');
+ dol_include_once('/core/lib/company.lib.php');
+ dol_include_once('/core/lib/project.lib.php');
+ dol_include_once('/projet/class/project.class.php');
+ dol_include_once('/projet/class/task.class.php');
+ dol_include_once('/projet/class/task.class.php');
+ dol_include_once('/fourn/class/fournisseur.commande.class.php');
+ dol_include_once('/fourn/class/fournisseur.facture.class.php');
dol_include_once('/fourn/class/fournisseur.product.class.php');
dol_include_once('/commande/class/commande.class.php');
dol_include_once('/contact/class/contact.class.php');
dol_include_once('/core/lib/order.lib.php');
- global $hookmanager;
+ global $hookmanager;
- $hookmanager->initHooks(array('history'));
+ $hookmanager->initHooks(array('history'));
- $type_object = GETPOST('type_object','alpha');
- $fk_object = GETPOST('id', 'int');
+ $type_object = GETPOST('type_object', 'alpha');
+ $fk_object = GETPOST('id', 'int');
$langs->load('history@history');
- if(GETPOST('restoreObject','int')>0) {
-
- DeepHistory::restoreCopy(GETPOST('restoreObject','int'));
-
- }
-
-
- llxHeader('',$langs->trans('ElementHistory'));
-
-
- $type_object = GETPOST('type_object','alpha');
- $fk_object = GETPOST('id','int');
-
- if($type_object == 'deletedElement') {
-
-
- // Subheader
- $linkback = ''
- . $langs->trans("BackToModuleList") . '';
- print load_fiche_titre($langs->trans('DeletedElements'), $linkback, 'tools');
-
- dol_include_once('/history/lib/history.lib.php');
- $head = historyAdminPrepareHead();
- print dol_get_fiche_head($head, 'delted',$langs->trans("ModuleName"), -1, "history@history");
-
+if (GETPOST('restoreObject', 'int')>0) {
+ DeepHistory::restoreCopy(GETPOST('restoreObject', 'int'));
+}
+
+
+ llxHeader('', $langs->trans('ElementHistory'));
+
+
+ $type_object = GETPOST('type_object', 'alpha');
+ $fk_object = GETPOST('id', 'int');
+
+if ($type_object == 'deletedElement') {
+ // Subheader
+ $linkback = ''
+ . $langs->trans("BackToModuleList") . '';
+ print load_fiche_titre($langs->trans('DeletedElements'), $linkback, 'tools');
+
+ dol_include_once('/history/lib/history.lib.php');
+ $head = historyAdminPrepareHead();
+ print dol_get_fiche_head($head, 'delted', $langs->trans("ModuleName"), -1, "history@history");
+} elseif ($type_object == 'propal') {
+ $object = new Propal($db);
+ $object->fetch($fk_object);
+ $head = propal_prepare_head($object);
+ print dol_get_fiche_head($head, 'history', $langs->trans('Proposal'), -1, 'propal');
+} elseif ($type_object=='societe') {
+ $object = new Societe($db);
+ $object->fetch($fk_object);
+ $head = societe_prepare_head($object);
+ print dol_get_fiche_head($head, 'history', $langs->trans('Company'), -1, 'company');
+} elseif ($type_object=='action') {
+ $object = new ActionComm($db);
+ $object->fetch($fk_object);
+ $head = actions_prepare_head($object);
+ print dol_get_fiche_head($head, 'history', $langs->trans('Company'), 0, 'action');
+} elseif ($type_object=='project') {
+ $object = new Project($db);
+ $object->fetch($fk_object);
+ $head = project_prepare_head($object);
+ print dol_get_fiche_head($head, 'history', $langs->trans('Project'), 0, 'action');
+ /*else if($type_object=='order') {
+ //TODO : for dolibarr 5.0 order class will manage correctly change so can be uncomment
+ $object = new Commande($db);
+ $object->fetch($fk_object);
+ $head = commande_prepare_head($object);
+ dol_fiche_head($head, 'history', $langs->trans('CustomerOrder'), 0, 'action');
+
+ }*/
+} else {
+ $parameters = ['type_object' => &$type_object, 'fk_object' => &$fk_object];
+ $reshook = $hookmanager->executeHooks('printHistoryHeadByTypeObject', $parameters);
+ if ($reshook) print $hookmanager->resPrint;
+
+ else {
+ if ( class_exists(ucfirst($type_object)) ) {
+ global $db, $user;
+
+ $class = ucfirst($type_object);
+ $object = new $class($db);
+ $object->fetch($fk_object);
+
+ if (function_exists($type_object.'_prepare_head')) {
+ $head = call_user_func($type_object.'_prepare_head', $object, $user);
+ print dol_get_fiche_head($head, 'history', $langs->trans($class), 0, $type_object);
+ }
+ } else {
+ exit('Erreur, ce type d\'objet '.ucfirst($type_object).' n\'est pas traité par le module');
+ }
}
- else if($type_object == 'propal') {
- $object = new Propal($db);
- $object->fetch($fk_object);
- $head = propal_prepare_head($object);
- print dol_get_fiche_head($head, 'history', $langs->trans('Proposal'), -1, 'propal');
- }
- else if($type_object=='societe') {
- $object = new Societe($db);
- $object->fetch($fk_object);
- $head = societe_prepare_head($object);
- print dol_get_fiche_head($head, 'history', $langs->trans('Company'), -1, 'company');
-
- }
-
- else if($type_object=='action') {
- $object = new ActionComm($db);
- $object->fetch($fk_object);
- $head = actions_prepare_head($object);
- print dol_get_fiche_head($head, 'history', $langs->trans('Company'), 0, 'action');
-
- }
-
- else if($type_object=='project') {
- $object = new Project($db);
- $object->fetch($fk_object);
- $head = project_prepare_head($object);
- print dol_get_fiche_head($head, 'history', $langs->trans('Project'), 0, 'action');
-
- }
+}
- /*else if($type_object=='order') {
- //TODO : for dolibarr 5.0 order class will manage correctly change so can be uncomment
- $object = new Commande($db);
- $object->fetch($fk_object);
- $head = commande_prepare_head($object);
- dol_fiche_head($head, 'history', $langs->trans('CustomerOrder'), 0, 'action');
+ $THistory = DeepHistory::getHistory($type_object, $fk_object);
- }*/
- else {
+if (GETPOST('restoreObject', 'int')>0) {
+ DeepHistory::restoreCopy(GETPOST('restoreObject', 'int'));
+}
- $parameters = ['type_object' => &$type_object, 'fk_object' => &$fk_object];
- $reshook = $hookmanager->executeHooks('printHistoryHeadByTypeObject', $parameters);
- if($reshook) print $hookmanager->resPrint;
-
- else {
- if( class_exists(ucfirst($type_object)) ) {
- global $db, $user;
-
- $class = ucfirst($type_object);
- $object = new $class($db);
- $object->fetch($fk_object);
-
- if(function_exists($type_object.'_prepare_head')) {
- $head = call_user_func($type_object.'_prepare_head', $object, $user);
- print dol_get_fiche_head($head, 'history', $langs->trans($class), 0, $type_object);
- }
-
- }
- else{
- exit('Erreur, ce type d\'objet '.ucfirst($type_object).' n\'est pas traité par le module');
- }
- }
-
- }
-
- $THistory = DeepHistory::getHistory($type_object, $fk_object) ;
-
- if(GETPOST('restoreObject','int')>0) {
-
- DeepHistory::restoreCopy(GETPOST('restoreObject','int'));
-
- }
-
- ?>
-
-
- | trans('Date') ?> | '.$langs->trans('Ref').'';
+?>
+
+
+ | trans('Date') ?> | '.$langs->trans('Ref').'';
}
- ?>trans('Action') ?> |
- trans('WhatChanged') ?> |
- trans('User') ?> |
-
-
-
-
- | get_date('date_entry','dayhoursec'); ?> |
- show_ref() ?> |
- show_action() ?> |
- show_whatChanged(false, true) ?> |
- show_user() ?> |
-
+ ?>trans('Action') ?> |
+ trans('WhatChanged') ?> |
+ trans('User') ?> |
+
+
+
+
+ | get_date('date_entry', 'dayhoursec'); ?> |
+ showRef() ?> |
+ showAction() ?> |
+ showWhatChanged(false, true) ?> |
+ showUser() ?> |
+
-
- | get_date('date_entry','dayhoursec'); ?> |
- show_action() ?> |
- show_whatChanged() ?> |
- show_user() ?> |
-
- object) && GETPOST('showObject','int') == $history->id) {
- unset($history->object->db);
- echo ''.print_r($history->object,true).' |
';
-
- }
-
+ } else {
+ ?>
+
+ | get_date('date_entry', 'dayhoursec'); ?> |
+ showAction() ?> |
+ showWhatChanged() ?> |
+ showUser() ?> |
+
+ object) && GETPOST('showObject', 'int') == $history->id) {
+ unset($history->object->db);
+ echo ''.print_r($history->object, true).' |
';
+ }
}
+ }
- }
-
- ?>
+ ?>
-
-
-
+
+