From db8f5ed5928f66d63ff6af6d897e4d1833399c50 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 19 Apr 2010 07:55:46 +0000 Subject: [PATCH] Add possibility to include boxes of external module --- htdocs/admin/boxes.php | 77 ++++++++++++++++++++++++++++++++++-------- htdocs/boxes.php | 36 ++++++++++++++++---- htdocs/index.php | 4 +-- 3 files changed, 95 insertions(+), 22 deletions(-) diff --git a/htdocs/admin/boxes.php b/htdocs/admin/boxes.php index d2ad9cbe3b8..d34532f15b7 100644 --- a/htdocs/admin/boxes.php +++ b/htdocs/admin/boxes.php @@ -50,7 +50,10 @@ if ($_POST["action"] == 'add') { $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."boxes"; - $sql.= " WHERE fk_user=0 AND box_id=".$_POST["boxid"]." AND position=".$_POST["pos"]; + $sql.= " WHERE fk_user = 0"; + $sql.= " AND box_id = ".$_POST["boxid"]; + $sql.= " AND position = ".$_POST["pos"]; + $resql = $db->query($sql); dol_syslog("boxes.php::search if box active sql=".$sql); if ($resql) @@ -61,13 +64,24 @@ if ($_POST["action"] == 'add') $db->begin(); // Si la boite n'est pas deja active, insert with box_order='' - $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position, box_order, fk_user) values (".$_POST["boxid"].",".$_POST["pos"].", '', 0)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes ("; + $sql.= "box_id"; + $sql.= ", position"; + $sql.= ", box_order"; + $sql.= ", fk_user"; + $sql.= ") values ("; + $sql.= $_POST["boxid"]; + $sql.= ", ".$_POST["pos"]; + $sql.= ", ''"; + $sql.= ", 0"; + $sql.= ")"; + dol_syslog("boxes.php activate box sql=".$sql); $resql = $db->query($sql); // Remove all personalized setup when a box is activated or disabled $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param"; - $sql.= " WHERE param like 'MAIN_BOXES_%'"; + $sql.= " WHERE param LIKE 'MAIN_BOXES_%'"; dol_syslog("boxes.php delete user_param sql=".$sql); $resql = $db->query($sql); @@ -93,7 +107,7 @@ if ($_GET["action"] == 'delete') // Remove all personalized setup when a box is activated or disabled $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param"; - $sql.= " WHERE param like 'MAIN_BOXES_%'"; + $sql.= " WHERE param LIKE 'MAIN_BOXES_%'"; $resql = $db->query($sql); $db->commit(); @@ -260,10 +274,19 @@ if ($resql) while ($i < $num) { $obj = $db->fetch_object($resql); - - $module=preg_replace('/.php$/i','',$obj->file); - include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); - + + if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) + { + $module = $regs[1]; + $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + } + else + { + $module=preg_replace('/.php$/i','',$obj->file); + $sourcefile = "/includes/boxes/".$module.".php"; + } + + include_once(DOL_DOCUMENT_ROOT.$sourcefile); $box=new $module($db,$obj->note); // if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) @@ -274,14 +297,22 @@ if ($resql) else { $var = ! $var; + + if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) + { + $logo = $box->boximg; + } + else + { + $logo=preg_replace("/^object_/i","",$box->boximg); + } print '
'; print ''; - $logo=preg_replace("/^object_/i","",$box->boximg); print ''; print ''.img_object("",$logo).' '.$box->boxlabel.''; print '' . ($obj->note?$obj->note:' ') . ''; - print '' . $obj->file . ''; + print '' . $sourcefile . ''; // Pour chaque position possible, on affiche un lien // d'activation si boite non deja active pour cette position @@ -346,11 +377,29 @@ if ($resql) $var = ! $var; $objnext = $db->fetch_object($resql); - $module=preg_replace('/.php$/i','',$obj->file); - include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); + if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) + { + $module = $regs[1]; + $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + } + else + { + $module=preg_replace('/.php$/i','',$obj->file); + $sourcefile = "/includes/boxes/".$module.".php"; + } + + include_once(DOL_DOCUMENT_ROOT.$sourcefile); $box=new $module($db,$obj->note); - - $logo=preg_replace("/^object_/i","",$box->boximg); + + if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) + { + $logo = $box->boximg; + } + else + { + $logo=preg_replace("/^object_/i","",$box->boximg); + } + print ''; print ''.img_object("",$logo).' '.$box->boxlabel.''; print '' . ($obj->note?$obj->note:' ') . ''; diff --git a/htdocs/boxes.php b/htdocs/boxes.php index fbdb4d045a1..1522a3ad919 100644 --- a/htdocs/boxes.php +++ b/htdocs/boxes.php @@ -80,9 +80,21 @@ class InfoBox while ($j < $num) { $obj = $this->db->fetch_object($result); - $boxname=preg_replace('/\.php$/i','',$obj->file); - include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"); - $box=new $boxname($this->db,$obj->note); + + if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) + { + $module = $regs[1]; + $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + } + else + { + $module=preg_replace('/.php$/i','',$obj->file); + $sourcefile = "/includes/boxes/".$module.".php"; + } + + include_once(DOL_DOCUMENT_ROOT.$sourcefile); + $box=new $module($db,$obj->note); + $box->rowid=$obj->rowid; $box->box_id=$obj->box_id; $box->position=$obj->position; @@ -128,9 +140,21 @@ class InfoBox while ($j < $num) { $obj = $this->db->fetch_object($result); - $boxname=preg_replace('/\.php$/i','',$obj->file); - include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"); - $box=new $boxname($this->db,$obj->note); + + if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) + { + $module = $regs[1]; + $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + } + else + { + $module=preg_replace('/.php$/i','',$obj->file); + $sourcefile = "/includes/boxes/".$module.".php"; + } + + include_once(DOL_DOCUMENT_ROOT.$sourcefile); + $box=new $module($db,$obj->note); + $box->rowid=$obj->rowid; $box->box_id=$obj->box_id; $box->position=$obj->position; diff --git a/htdocs/index.php b/htdocs/index.php index b4dd099a5a9..ffba410bf95 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by