diff --git a/htdocs/admin/mantis.php b/htdocs/admin/mantis.php new file mode 100644 index 00000000000..b349684e50f --- /dev/null +++ b/htdocs/admin/mantis.php @@ -0,0 +1,206 @@ + + * Copyright (C) 2003 Éric Seigne + * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/admin/mantis.php + \ingroup mantis + \brief Page de configuration du module mantis + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT.'/lib/mantis.class.php'); + + +if (!$user->admin) + accessforbidden(); + + +$langs->load("admin"); +$langs->load("other"); + +$def = array(); +$actiontest=$_POST["test"]; +$actionsave=$_POST["save"]; + +// Sauvegardes parametres +if ($actionsave) +{ + $i=0; + + $db->begin(); + + $i+=dolibarr_set_const($db,'PHPMANTIS_URL',trim($_POST["phpmantis_url"]),'chaine',0); + $i+=dolibarr_set_const($db,'PHPMANTIS_HOST',trim($_POST["phpmantis_host"]),'chaine',0); + $i+=dolibarr_set_const($db,'PHPMANTIS_DBNAME',trim($_POST["phpmantis_dbname"]),'chaine',0); + $i+=dolibarr_set_const($db,'PHPMANTIS_USER',trim($_POST["phpmantis_user"]),'chaine',0); + $i+=dolibarr_set_const($db,'PHPMANTIS_PASS',trim($_POST["phpmantis_pass"]),'chaine',0); + + if ($i >= 5) + { + $db->commit(); + $mesg = "".$langs->trans("MantisSetupSaved").""; + } + else + { + $db->rollback(); + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } +} +elseif ($actiontest) +{ + //$resql=$db->query("select count(*) from llx_const"); + //print "< ".$db." - ".$db->db." - ".$resql." - ".$db->error().">
\n"; + + // Test de la connection a la database mantis + $conf->mantis->db->type=$dolibarr_main_db_type; + $conf->mantis->db->host=$_POST["phpmantis_host"]; + $conf->mantis->db->user=$_POST["phpmantis_user"]; + $conf->mantis->db->pass=$_POST["phpmantis_pass"]; + $conf->mantis->db->name=$_POST["phpmantis_dbname"]; + + $mantis=new Mantis(); + + //print "D ".$db." - ".$db->db."
\n"; + //print "W ".$mantis->localdb." - ".$mantis->localdb->db."
\n"; + + if ($mantis->localdb->connected == 1 && $mantis->localdb->database_selected == 1) + { + // Vérifie si bonne base + $sql="SELECT value FROM mantis_config_table WHERE config_id='database_version'"; + $resql=$mantis->localdb->query($sql); + if ($resql) { + $mesg ="
"; + $mesg.=$langs->trans("MantisTestOk",$_POST["phpmantis_host"],$_POST["phpmantis_dbname"],$_POST["phpmantis_user"]); + $mesg.="
"; + } + else { + $mesg ="
"; + $mesg.=$langs->trans("MantisErrorConnectOkButWrongDatabase"); + $mesg.="
"; + } + + //$mantis->localdb->close(); Ne pas fermer car la conn de mantis est la meme que dolibarr si parametre host/user/pass identique + } + elseif ($mantis->connected == 1 && $mantis->database_selected != 1) + { + $mesg ="
".$langs->trans("MantisTestKo1",$_POST["phpmantis_host"],$_POST["phpmantis_dbname"]); + $mesg.="
".$mantis->localdb->error(); + $mesg.="
"; + //$mantis->localdb->close(); Ne pas fermer car la conn de mantis est la meme que dolibarr si parametre host/user/pass identique + } + else + { + $mesg ="
".$langs->trans("MantisTestKo2",$_POST["phpmantis_host"],$_POST["phpmantis_user"]); + $mesg.="
".$mantis->localdb->error(); + $mesg.="
"; + } + + //$resql=$db->query("select count(*) from llx_const"); + //print "< ".$db." - ".$db->db." - ".$resql." - ".$db->error().">
\n"; +} + + +/** + * Affichage du formulaire de saisie + */ + +llxHeader(); + +print_fiche_titre($langs->trans("MantisSetup"),'','setup'); +print '
'; + + +print '
'; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ''; +print ""; + +print "
".$langs->trans("Parameter")."".$langs->trans("Value")."".$langs->trans("Examples")."
".$langs->trans("MantisURL")."global->PHPMANTIS_URL) . "\" size=\"40\">http://localhost/mantis/"; +print "
https://mantisserver/"; +print "
".$langs->trans("MantisServer")."global->PHPMANTIS_HOST) . "\" size=\"30\">localhost"; +//print "
__dolibarr_main_db_host__ (".$dolibarr_main_db_host.")" +print "
".$langs->trans("MantisDatabaseName")."global->PHPMANTIS_DBNAME) . "\" size=\"30\">bugtracker"; +//print "
__dolibarr_main_db_name__ (".$dolibarr_main_db_name.")"; +print "
".$langs->trans("MantisUser")."global->PHPMANTIS_USER) . "\" size=\"30\">mantis"; +//print "
__dolibarr_main_db_user__ (".$dolibarr_main_db_user.")"; +print "
".$langs->trans("Password")."global->PHPMANTIS_PASS) . "\" size=\"30\">'; +//if ($dolibarr_main_db_pass) print '__dolibarr_main_db_pass__ ('.eregi_replace('.','*',$dolibarr_main_db_pass).')'; +print ' 
"; + + +print '
'; +print "trans("TestConnection")."\">"; +print "   "; +print "trans("Save")."\">"; +print "
"; + +print "
\n"; + + +clearstatcache(); + +if ($mesg) print "
$mesg
"; +print "
"; + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/includes/modules/modMantis.class.php b/htdocs/includes/modules/modMantis.class.php new file mode 100644 index 00000000000..3bf0afbeb69 --- /dev/null +++ b/htdocs/includes/modules/modMantis.class.php @@ -0,0 +1,127 @@ + + * Copyright (C) 2004-2006 Laurent Destailleur + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** \defgroup mantis Module Mantis + \brief Module to include Mantis into Dolibarr +*/ + +/** + \file htdocs/includes/modules/modMantis.class.php + \ingroup mantis + \brief Description and activation file for module Mantis +*/ + +include_once "DolibarrModules.class.php"; + +/** \class modMantis + \brief Description and activation class for module Mantis +*/ + +class modMantis extends DolibarrModules +{ + + /** + * \brief Constructor. Define names, constants, directories, boxes, permissions + * \param DB Database handler + */ + function modMantis($DB) + { + $this->db = $DB; + + // Id of module (must be unique for all modules) + // Use same value here than in file modXxx.class.php + $this->id = 'mantis'; + // Another id for module (must be unique). + // Use here a free id. + $this->numero = 1200; + + // Family can be 'crm','financial','hr','projects','product','technic','other' + // It is used to sort modules in module setup page + $this->family = "projects"; + // Module title used if translation string 'ModuleXXXName' not found (XXX is id value) + $this->name = "Mantis"; + // Module descriptoin used translation string 'ModuleXXXDesc' not found (XXX is id value) + $this->description = "Interfaçage avec le bug tracking Mantis"; + // Possible values for version are: 'experimental' or 'dolibarr' or version + $this->version = 'dolibarr'; + // Id used in llx_const table to manage module status (enabled/disabled) + $this->const_name = 'MAIN_MODULE_MANTIS'; + // Where to store the module in setup page (0=common,1=interface,2=other) + $this->special = 1; + // Name of png file (without png) used for this module + $this->picto='calendar'; + + // Data directories to create when module is enabled + $this->dirs = array(); + + // Config pages + $this->config_page_url = array("mantis.php"); + + // Dependencies + $this->depends = array(); // List of modules id that must be enabled + $this->requiredby = array(); // List of modules id to disable if this one is disabled + + // Constants + $this->const = array(); // List of parameters + + // Boxes + $this->boxes = array(); // List of boxes + + // Permissions + $this->rights_class = 'mantis'; // Permission key + $this->rights = array(); // Permission array used by this module + // Example + // $r++; + // $this->rights[$r][0] = 1200; // Permission id (must not be already used) + // $this->rights[$r][1] = 'Permision label'; // Permission label + // $this->rights[$r][3] = 1; // Permission by default for new user (0/1) + // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + } + + /** + * \brief Function called when module is enabled. + * Add constants, boxes and permissions into Dolibarr database. + * It also creates data directories. + */ + function init() + { + $sql = array(); + + return $this->_init($sql); + } + + /** + * \brief Function called when module is disabled. + * Remove from database constants, boxes and permissions from Dolibarr database. + * Data directories are not deleted. + */ + function remove() + { + $sql = array(); + + return $this->_remove($sql); + } + +} + +?> diff --git a/htdocs/lib/mantis.class.php b/htdocs/lib/mantis.class.php new file mode 100644 index 00000000000..df0cd2a1dc3 --- /dev/null +++ b/htdocs/lib/mantis.class.php @@ -0,0 +1,73 @@ + + * Copyright (C) 2004-2005 Laurent Destailleur + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/lib/mantis.class.php + \ingroup mantis + \brief Ensemble des fonctions permettant d'acceder a la database mantis. + \author Laurent Destailleur. + \version $Revision$ +*/ + + +/** + \class Mantis + \brief Classe permettant d'acceder a la database mantis +*/ + +class Mantis { + + var $localdb; + + var $date; + var $duree = 0; // Secondes + var $texte; + var $desc; + + var $error; + + + /** + \brief Constructeur de la classe d'interface à mantisendar + */ + function Mantis() + { + global $conf; + global $dolibarr_main_db_type,$dolibarr_main_db_host,$dolibarr_main_db_user; + global $dolibarr_main_db_pass,$dolibarr_main_db_name; + + // Défini parametres mantis (avec substitution eventuelle) + $mantistype=eregi_replace('__dolibarr_main_db_type__',$dolibarr_main_db_type,$conf->mantis->db->type); + $mantishost=eregi_replace('__dolibarr_main_db_host__',$dolibarr_main_db_host,$conf->mantis->db->host); + $mantisuser=eregi_replace('__dolibarr_main_db_user__',$dolibarr_main_db_user,$conf->mantis->db->user); + $mantispass=eregi_replace('__dolibarr_main_db_pass__',$dolibarr_main_db_pass,$conf->mantis->db->pass); + $mantisname=eregi_replace('__dolibarr_main_db_name__',$dolibarr_main_db_name,$conf->mantis->db->name); + + // On initie la connexion à la base mantisendar + require_once (DOL_DOCUMENT_ROOT ."/lib/databases/".$mantistype.".lib.php"); + $this->localdb = new DoliDb($mantistype,$mantishost,$mantisuser,$mantispass,$mantisname); + } + + + +} +?>