diff --git a/class/actions_importzugferd.class.php b/class/actions_importzugferd.class.php
index 2e77ce1..84ab06c 100644
--- a/class/actions_importzugferd.class.php
+++ b/class/actions_importzugferd.class.php
@@ -953,4 +953,58 @@ class ActionsImportZugferd
return 0;
}
+
+ /**
+ * Hook to add info box on products/services dashboard page
+ *
+ * @param array $parameters Parameters
+ * @param object $object Object
+ * @param string $action Action
+ * @param HookManager $hookmanager Hook manager
+ * @return int 0 = OK, >0 = number of errors
+ */
+ public function dashboardProductsServices($parameters, &$object, &$action, $hookmanager)
+ {
+ global $langs, $user, $conf;
+
+ if (!$user->hasRight('produit', 'lire')) {
+ return 0;
+ }
+
+ $langs->load('importzugferd@importzugferd');
+
+ // Count products with ref starting with "New"
+ $sql = "SELECT COUNT(*) as total FROM " . MAIN_DB_PREFIX . "product";
+ $sql .= " WHERE entity IN (" . getEntity('product') . ")";
+ $sql .= " AND ref LIKE 'New%'";
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $obj = $this->db->fetch_object($resql);
+ $count = (int) $obj->total;
+
+ if ($count > 0) {
+ $url = dol_buildpath('/importzugferd/new_products.php', 1);
+
+ $this->resprints = '
+
';
+ }
+ }
+
+ return 0;
+ }
}
diff --git a/core/modules/modImportZugferd.class.php b/core/modules/modImportZugferd.class.php
index 4ecfd6f..a1af114 100755
--- a/core/modules/modImportZugferd.class.php
+++ b/core/modules/modImportZugferd.class.php
@@ -76,7 +76,7 @@ class modImportZugferd extends DolibarrModules
$this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@importzugferd'
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
- $this->version = '2.3';
+ $this->version = '2.5';
// Url to the file with your last numberversion of this module
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
@@ -122,7 +122,7 @@ class modImportZugferd extends DolibarrModules
'hooks' => array(
'data' => array(
'index',
- 'opensurveypollindex',
+ 'productindex',
),
'entity' => '0',
),
@@ -648,38 +648,28 @@ class modImportZugferd extends DolibarrModules
$sql = array();
- // Document templates
- $moduledir = dol_sanitizeFileName('importzugferd');
- $myTmpObjects = array();
- $myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);
+ // Run standard init first (creates box definitions)
+ $result = $this->_init($sql, $options);
- foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
- if ($myTmpObjectArray['includerefgeneration']) {
- $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/'.$moduledir.'/template_myobjects.odt';
- $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/'.$moduledir;
- $dest = $dirodt.'/template_myobjects.odt';
+ // Now activate widget for product index page (area 4)
+ // Box definition is now created by _init(), so we can find it
+ $sql_box = "SELECT rowid FROM ".$this->db->prefix()."boxes_def WHERE file = 'box_new_products.php@importzugferd'";
+ $resql = $this->db->query($sql_box);
+ if ($resql && $this->db->num_rows($resql) > 0) {
+ $obj = $this->db->fetch_object($resql);
+ $box_id = $obj->rowid;
- if (file_exists($src) && !file_exists($dest)) {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- dol_mkdir($dirodt);
- $result = dol_copy($src, $dest, '0', 0);
- if ($result < 0) {
- $langs->load("errors");
- $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
- return 0;
- }
- }
-
- $sql = array_merge($sql, array(
- "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
- "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")",
- "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
- "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")"
- ));
+ // Check if already activated for area 4 (product index)
+ $sql_check = "SELECT rowid FROM ".$this->db->prefix()."boxes WHERE box_id = ".(int)$box_id." AND position = 4 AND entity = ".(int)$conf->entity;
+ $resql2 = $this->db->query($sql_check);
+ if ($resql2 && $this->db->num_rows($resql2) == 0) {
+ // Not yet activated, add it
+ $sql_insert = "INSERT INTO ".$this->db->prefix()."boxes (box_id, position, box_order, fk_user, entity) VALUES (".(int)$box_id.", 4, 'A01', 0, ".(int)$conf->entity.")";
+ $this->db->query($sql_insert);
}
}
- return $this->_init($sql, $options);
+ return $result;
}
/**