*
* Copyright 2009, Fabien Dubois - Capgemini
* Copyright 2009-2011, Franck Villaume - Capgemini
+ * Copyright 2011-2012, Franck Villaume - TrivialDev
* http://fusionforge.org
*
- * This file is part of FusionForge.
- *
- * FusionForge 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 file is part of FusionForge. FusionForge 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 Licence, or (at your option)
+ * any later version.
*
* FusionForge 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 FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * @todo : need a massive cleanup
- * deal correctly with password (might need direct db access ?)
- * limit non SOAP call aka direct db access to mantisbt
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class MantisBTPlugin extends Plugin {
$this->_addHook('userisactivecheckbox'); // The "use ..." checkbox in user account
$this->_addHook('userisactivecheckboxpost'); //
$this->_addHook('project_admin_plugins'); // to show up in the admin page fro group
- $this->_addHook('change_cal_permission');
- $this->_addHook('change_cal_mail');
- $this->_addHook('add_cal_link_father');
- $this->_addHook('del_cal_link_father');
- $this->_addHook('group_approved');
$this->_addHook('group_delete');
$this->_addHook('group_update');
+ $this->_addHook('site_admin_option_hook');
+ $this->_addHook('widget_instance', 'myPageBox', false);
+ $this->_addHook('widgets', 'widgets', false);
}
function CallHook($hookname, &$params) {
case "usermenu": {
if ($G_SESSION->usesPlugin($this->name)) {
$param = '?type=user&user_id=' . $G_SESSION->getId() . '&pluginname=' . $this->name; // we indicate the part we're calling is the user one
- echo $HTML->PrintSubMenu(array($this->text), array('/plugins/mantisbt/index.php' . $param), array(_('Personnal MantisBT page')));
+ echo $HTML->PrintSubMenu(array($this->text), array('/plugins/mantisbt/index.php' . $param), array(array('class'=> 'tabtitle', 'title' => _('Personal MantisBT page'))));
}
$returned = true;
break;
if ($project->usesPlugin($this->name)) {
$params['TITLES'][] = $this->text;
$params['DIRS'][] = '/plugins/'.$this->name.'/?type=group&group_id=' . $group_id . '&pluginname=' . $this->name;
+ $params['TOOLTIPS'][] = _('Tickets Management');
if (session_loggedin()) {
$user = session_get_user();
$userperm = $project->getPermission($user);
if ($userperm->isAdmin()) {
- $params['TITLES'][] = $this->text . _('Admin');
$params['ADMIN'][] = '/plugins/'.$this->name.'/?type=admin&group_id=' . $group_id . '&pluginname=' . $this->name;
}
}
- }
- if ($params['toptab'] == $this->name) {
- $params['selected']=(count($params['TITLES'])-1);
+ if (isset($params['toptab'])) {
+ (($params['toptab'] == $this->name) ? $params['selected'] = (count($params['TITLES'])-1) : '' );
+ }
}
$returned = true;
break;
// this displays the link in the user's profile page to it's personal MantisBT (if you want other sto access it, youll have to change the permissions in the index.php
$userid = $params['user_id'];
$user = user_get_object($userid);
- $text = $params['text'];
//check if the user has the plugin activated
if ($user->usesPlugin($this->name)) {
echo '<p>';
- echo util_make_link('/plugins/'.$this->name.'/?user_id=$userid&type=user&pluginname='.$this->name, _('View Personal MantisBT'));
+ $arr_t = array();
+ $arr_t[] = array('title' => _('Manage your mantisbt account and follow your tickets'), 'class' => 'tabtitle');
+ echo util_make_link('/plugins/'.$this->name.'/?user_id='.$userid.'&type=user&pluginname='.$this->name, _('View Personal MantisBT'), $arr_t);
echo '</p>';
}
$returned = true;
$group = group_get_object($group_id);
if ($group->usesPlugin($this->name)) {
echo '<p>';
- echo util_make_link("/plugins/mantisbt/?group_id=$group_id&type=admin&pluginname=".$this->name,
- _('View Admin MantisBT')
- );
+ echo util_make_link("/plugins/mantisbt/?group_id=$group_id&type=admin&pluginname=".$this->name, _('View Admin MantisBT'), array('class' => 'tabtitle', 'title' => _('MantisBT administration page')));
echo '</p>';
}
$returned = true;
break;
}
- case "change_cal_permission": {
- // mise a jour des utilisateurs avec les roles
- $group_id = $params[1];
- $group = group_get_object($group_id);
- $members = array();
- foreach($group->getMembers() as $member){
- $members[] = $member->data_array['user_name'];
- }
- $this->updateUsersProjetMantis($group->data_array['group_id'],$members);
- break;
- }
- // mise a jour de l'adresse mail utilisateur
- case "change_cal_mail": {
- $user_id = $params[1];
- // before activate this, please fix updateUserInMantis
- //$this->updateUserInMantis($user_id);
- $returned = true;
- break;
- }
- case "add_cal_link_father":
- case "del_cal_link_father": {
- $sub_group_id = $params[0];
- $group_id = $params[1];
- // before activate this, please fix refreshHierarchyMantisBt
- //$this->refreshHierarchyMantisBt();
+ case "site_admin_option_hook": {
+ echo '<li>'.$this->getAdminOptionLink().'</li>';
$returned = true;
break;
}
}
break;
}
+ case "widgets": {
+ $group = group_get_object($GLOBALS['group_id']);
+ if ($group->usesPlugin($this->name)) {
+ return $this->widgets($params);
+ }
+ break;
+ }
+ case "widget_instance": {
+ $group = group_get_object($GLOBALS['group_id']);
+ if ((is_object($group)? $group->usesPlugin($this->name) : false) || $G_SESSION->usesPlugin($this->name)) {
+ return $this->myPageBox($params);
+ }
+ break;
+ }
}
return $returned;
}
function removeProjectMantis($idProjet) {
$groupObject = group_get_object($idProjet);
- $localMantisbtConf = $this->getMantisBTConf();
+ $localMantisbtConf = $this->getMantisBTConf($groupObject->getID());
if (!$localMantisbtConf) {
$groupObject->setError('removeProjetMantis::Error' . ' '. _('No project found'));
$groupObject->setError('removeProjetMantis:: ' . _('No project found in MantisBT') . ' ' .$localMantisbtConf['id_mantisbt']);
return false;
} else {
- db_query_params('DELETE FROM plugin_mantisbt WHERE id_mantisbt = $1',
+ $res = db_query_params('DELETE FROM plugin_mantisbt WHERE id_mantisbt = $1',
array($localMantisbtConf['id_mantisbt']));
+ if (!$res) {
+ $groupObject->setError('removeProjetMantis:: ' . _('Cannot delete in database') . ' ' .$localMantisbtConf['id_mantisbt']);
+ return false;
+ }
}
return true;
}
function updateProjectMantis($groupId, $groupName, $groupIspublic) {
$groupObject = group_get_object($groupId);
$projet = array();
- $localMantisbtConf = $this->getMantisBTConf();
+ $localMantisbtConf = $this->getMantisBTConf($groupObject->getID());
$project['name'] = $groupName;
$project['status'] = "development";
}
}
- function updateUserInMantis($user_id) {
- global $sys_mantisbt_host, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_db_port, $sys_mantisbt_db_name;
- // recuperation du nouveau mail
- $resUser = db_query_params('SELECT user_name, email FROM users WHERE user_id = $1',array($user_id));
- echo db_error();
- $row = db_fetch_array($resUser);
-
- // WONT WORK : db_connect_host is not in any fusionforge api
- $dbConnection = db_connect_host($sys_mantisbt_db_name, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_host, $sys_mantisbt_db_port);
- if(!$dbConnection){
- $errMantis1 = "Error : Could not open connection" . db_error($dbConnection);
- echo $errMantis1;
- db_rollback($dbConnection);
- } else {
- db_query_params('UPDATE mantis_user_table set email = $1 where username = $2',array($row['email'],$row['user_name']),'-1','0',$dbConnection);
- echo db_error($dbConnection);
- }
- }
-
- /**
- * updateUsersProjectMantis - inject Username in mantisbt for specific project
- *
- * @param int Group Id
- * @param array Unix username array
- * @return boolean success or not
- */
- function updateUsersProjectMantis($groupId, $members) {
- $groupObject = group_get_object($groupId);
- $returned = false;
- global $role;
-
- // @TODO put that in config file ?
- if ($role == null){
- $role['Manager'] = 70;
- $role['Concepteur'] = 55;
- $role['Collaborateur'] = 55;
- $role['Rapporteur'] = 55;
- }
-
- // @TODO : make a robust function there based on RBAC ?
- $stateForge = array();
- foreach ($members as $key => $member){
- $resUserRole = db_query_params('SELECT role.role_name
- FROM role, user_group, users
- WHERE users.user_name = $1
- AND ( user_group.user_id = users.user_id AND user_group.group_id = $2 )
- AND user_group.role_id = role.role_id',
- array($member, $groupObject->getID()));
- if (!$resUserRole) {
- $groupObject->setError('updateUsersProjectMantis::'. _('Error : Cannot retrieve information about role') . ' ' .db_error());
- return $returned;
- } else {
- $row = db_fetch_array($resUserRole);
- $stateForge[$member]['name'] = $member;
- $stateForge[$member]['role'] = $row['role_name'];
- }
- }
-
- if ($this->__getDBType() === "pgsql") {
- if ($this->__updateUsersProjectMantisPgsql($groupObject->getID(), $stateForge)) {
- $returned = true;
- }
- }
- return $returned;
- }
-
-
-
- function refreshHierarchyMantisBt(){
- global $sys_mantisbt_host, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_db_port, $sys_mantisbt_db_name;
-
- $hierarchies=db_query_params('SELECT project_id, sub_project_id FROM plugin_projects_hierarchy WHERE activated=true',array());
- echo db_error();
- // WONT WORK : db_connect_host is not in any fusionforge api
- $dbConnection = db_connect_host($sys_mantisbt_db_name, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_host, $sys_mantisbt_db_port);
- if(!$dbConnection){
- db_rollback($dbConnection);
- return false;
- }
-
- db_begin($dbConnection);
- db_query_params('TRUNCATE TABLE mantis_project_hierarchy_table', array() , '-1', 0, $dbConnection);
- while ($hierarchy = db_fetch_array($hierarchies)) {
- $result = db_query_params ('INSERT INTO mantis_project_hierarchy_table (child_id, parent_id, inherit_parent) VALUES ($1, $2, $3)',
- array (getIdProjetMantis($hierarchy['sub_project_id']), getIdProjetMantis($hierarchy['project_id']), 1),
- '-1',
- 0,
- $dbConnection);
-
- if (!$result) {
- $this->setError(_('Insert Failed') . db_error($dbConnection));
- db_rollback($dbConnection);
- return false;
- }
- }
-
- db_commit($dbConnection);
- pg_close($dbConnection);
- return true;
- }
-
- /**
- * __updateUsersProjectMantisPgsql - update Users for this project in PostgreSQL DB
- *
- * @param int this Group Id
- * @param array the role of this forge
- * @return boolean success or not
- * @private
- */
- function __updateUsersProjectMantisPgsql($groupId, $stateForge) {
- $groupObject = group_get_object($groupId);
- $returned = false;
- // WONT WORK : db_connect_host is not in any fusionforge api
- $dbConnection = db_connect_host(forge_get_config('db_name','mantisbt'), forge_get_config('db_user','mantisbt'), forge_get_config('db_password','mantisbt'), forge_get_config('db_host','mantisbt'), forge_get_config('db_port','mantisbt'));
- if(!$dbConnection) {
- $groupObject->setError('updateUsersProjectMantis::'. _('Error : Could not open connection') . db_error($dbConnection));
- db_rollback($dbConnection);
- } else {
- $idMantis = getIdProjetMantis($groupId);
- $result = pg_delete($dbConnection,"mantis_project_user_list_table",array("project_id"=>$idMantis));
- if (!$result){
- echo 'updateUsersProjectMantis::Error '. _('Unable to clean roles in Mantisbt');
- }else{
- foreach($stateForge as $member => $array){
-
- $resultIdUser = db_query_params('SELECT mantis_user_table.id FROM mantis_user_table WHERE mantis_user_table.username = $1',
- array($member), '-1', 0, $dbConnection);
-
- $rowIdUser = db_fetch_array($resultIdUser);
- $idUser = $rowIdUser['id'];
-
- $resultInsert = pg_insert($dbConnection,
- "mantis_project_user_list_table",
- array("project_id" => $idMantis, "user_id" => $idUser, "access_level" => $role[$array['role']])
- );
- if (!isset($resultInsert)) {
- echo 'updateUsersProjectMantis::Error '. _('Unable to update roles in mantisbt');
- } else {
- $returned = true;
- }
- }
- }
- }
- return $returned;
- }
-
- /**
- * __getDBType - return the type of DB used for mantisbt
- *
- * @return string type of the DB
- * @private
- */
- function __getDBType() {
- switch (forge_get_config('db_name','mantisbt')) {
- case "pgsql": {
- return "pgsql";
- break;
- }
- default: {
- return false;
- break;
- }
- }
- }
-
/**
* getMantisBTConf - get the mantisbt configuration id for a specific group_id
*
+ * @param integer the group_id
* @return array the mantisbt configuration array
* @access public
*/
- function getMantisBTConf() {
- global $group_id;
+ function getMantisBTConf($group_id) {
$group = group_get_object($group_id);
$mantisbtConfArray = array();
$resIdProjetMantis = db_query_params('SELECT * FROM plugin_mantisbt WHERE id_group = $1', array($group_id));
$row = db_fetch_array($resIdProjetMantis);
$mantisbtConfArray['id_mantisbt'] = $row['id_mantisbt'];
- $mantisbtConfArray['url'] = $row['url'];
- $mantisbtConfArray['soap_user'] = $row['soap_user'];
- $mantisbtConfArray['soap_password'] = $row['soap_password'];
$mantisbtConfArray['sync_roles'] = $row['sync_roles'];
+ $mantisbtConfArray['use_global'] = $row['use_global'];
+ if ($mantisbtConfArray['use_global']) {
+ $mantisbtGlobConf = $this->getGlobalconf();
+ $mantisbtConfArray['url'] = $mantisbtGlobConf['url'];
+ $mantisbtConfArray['soap_user'] = $mantisbtGlobConf['soap_user'];
+ $mantisbtConfArray['soap_password'] = $mantisbtGlobConf['soap_password'];
+ } else {
+ $mantisbtConfArray['url'] = $row['url'];
+ $mantisbtConfArray['soap_user'] = $row['soap_user'];
+ $mantisbtConfArray['soap_password'] = $row['soap_password'];
+ }
+
return $mantisbtConfArray;
}
* @param int enable tooltips : default NO
* @return bool true only currently
*/
- function getSubMenu($enable_tooltips = 0) {
+ function getSubMenu() {
global $HTML;
global $group_id;
global $user;
$labelPage[] = "/plugins/".$this->name."/?type=group&group_id=".$group_id."&pluginname=".$this->name."&view=roadmap";
$labelPage[] = "/plugins/".$this->name."/?type=group&group_id=".$group_id."&pluginname=".$this->name;
$labelAttr = array();
- if ($enable_tooltips) {
- $labelAttr[] = array('title' => _('View the roadmap, per version tickets'), 'id' => 'roadmapView');
- $labelAttr[] = array('title' => _('View all tickets.'), 'id' => 'ticketView');
- } else {
- $labelAttr[] = array();
- $labelAttr[] = array();
- }
+ $labelAttr[] = array('title' => _('View the roadmap, per version tickets'), 'id' => 'roadmapView', 'class' => 'tabtitle-nw');
+ $labelAttr[] = array('title' => _('View all tickets.'), 'id' => 'ticketView', 'class' => 'tabtitle');
$userperm = $group->getPermission($user);
- if ( $userperm->isAdmin() ) {
+ if ($userperm->isAdmin()) {
$labelTitle[] = _('Administration');
$labelPage[] = "/plugins/".$this->name."/?type=admin&group_id=".$group_id."&pluginname=".$this->name;
$labelTitle[] = _('Statistics');
$labelPage[] = "/plugins/".$this->name."/?type=admin&group_id=".$group_id."&pluginname=".$this->name."&view=stat";
- if ($enable_tooltips) {
- $labelAttr[] = array('title' => _('Manage versions, categories and general configuration.'), 'id' => 'adminView');
- $labelAttr[] = array('title' => _('View global statistics.'), 'id' => 'statView');
- } else {
- $labelAttr[] = array();
- $labelAttr[] = array();
- }
+ $labelAttr[] = array('title' => _('Manage versions, categories and general configuration.'), 'id' => 'adminView', 'class' => 'tabtitle');
+ $labelAttr[] = array('title' => _('View global statistics.'), 'id' => 'statView', 'class' => 'tabtitle');
}
echo $HTML->subMenu($labelTitle, $labelPage, $labelAttr);
function getHeader($type) {
global $gfplugins;
$returned = false;
- html_use_tooltips();
use_javascript('/plugins/'.$this->name.'/scripts/MantisBTController.js');
use_stylesheet('/plugins/'.$this->name.'/style.css');
switch ($type) {
}
case 'user': {
global $user_id;
- $params['user'] = $user_id;
+ $params['user_id'] = $user_id;
site_user_header($params);
$returned = true;
break;
}
+ case 'globaladmin': {
+ session_require_global_perm('forge_admin');
+ global $gfwww;
+ require_once($gfwww.'admin/admin_utils.php');
+ site_admin_header(array('title'=>_('Site Global MantisBT Admin'), 'toptab' => ''));
+ $returned = true;
+ break;
+ }
default: {
break;
}
* @return bool success or not
*/
function initialize($group_id, $confArr) {
+ if ($confArr['globalconf']) {
+ $globalConfArr = $this->getGlobalconf();
+ $confArr['url'] = $globalConfArr['url'];
+ $confArr['soap_user'] = $globalConfArr['soap_user'];
+ $confArr['soap_password'] = $globalConfArr['soap_password'];
+ }
if ($confArr['mantisbtcreate']) {
$idProjectMantis = $this->addProjectMantis($group_id, $confArr);
- } else {
+ } elseif ($confArr['mantisbtname'] && sizeof($confArr['mantisbtname'])) {
$idProjectMantis = $this->getProjectMantisByName($group_id, $confArr);
+ } else {
+ $groupObject = group_get_object($group_id);
+ $groupObject->setError('initialize::Error: '. _('MantisBT project not initialized, missing params'));
}
- if ($idProjectMantis) {
- $result = db_query_params('insert into plugin_mantisbt (id_group, id_mantisbt, url, soap_user, soap_password, sync_roles)
- values ($1, $2, $3, $4, $5, $6)',
+
+ if (isset($idProjectMantis) && $idProjectMantis) {
+ $result = db_query_params('insert into plugin_mantisbt (id_group, id_mantisbt, url, soap_user, soap_password, sync_roles, use_global)
+ values ($1, $2, $3, $4, $5, $6, $7)',
array($group_id,
$idProjectMantis,
$confArr['url'],
$confArr['soap_user'],
$confArr['soap_password'],
- $confArr['sync_roles']));
- if (!$result)
+ $confArr['sync_roles'],
+ $confArr['globalconf']));
+ if (!$result) {
+ $groupObject = group_get_object($group_id);
+ $groupObject->setError('initialize::Error: '. db_error());
return false;
-
+ }
return true;
}
return false;
* @return bool success or not
*/
function updateConf($group_id, $confArr) {
- $result = db_query_params('update plugin_mantisbt set url = $1 , soap_user = $2, soap_password = $3
- where id_group = $4',
+ $result = db_query_params('update plugin_mantisbt set url = $1 , soap_user = $2, soap_password = $3, use_global = $4
+ where id_group = $5',
array($confArr['url'],
$confArr['soap_user'],
$confArr['soap_password'],
+ $confArr['global_conf'],
$group_id));
if (!$result)
return false;
return $mantisbtProject->id;
}
}
- $groupObject->setError('getProjectMantisByName::Error: mantisbt project not found');
+ $groupObject->setError('getProjectMantisByName::Error: '. _('MantisBT project not found'));
return false;
}
$row = db_fetch_array($resIdUser);
$userConf['user'] = $row['mantisbt_user'];
$userConf['password'] = $row['mantisbt_password'];
+ $userConf['url'] = array();
+ foreach ($user->getGroups() as $groupObject) {
+ if ($groupObject->usesPlugin($this->name)) {
+ $mantisbtGroupConf = $this->getMantisBTConf($groupObject->getID());
+ $userConf['url'][] = $mantisbtGroupConf['url'];
+ }
+ }
return $userConf;
}
+
+ /**
+ * getGlobalconf - return the global configuration defined at forge level
+ *
+ * @return array the global configuration array
+ */
+ function getGlobalconf() {
+ $resGlobConf = db_query_params('SELECT * from plugin_mantisbt_global',array());
+ if (!$resGlobConf) {
+ return false;
+ }
+
+ $row = db_numrows($resGlobConf);
+
+ if ($row == null || count($row) > 2) {
+ return false;
+ }
+
+ return db_fetch_array($resGlobConf);
+ }
+
+ /**
+ * updateGlobalConf - update the global configuration in database
+ *
+ * @param array configuration array (url, soap_user, soap_password)
+ * @return bool true on success
+ */
+ function updateGlobalConf($confArr) {
+ if (!isset($confArr['url']) || !isset($confArr['soap_user']) || !isset($confArr['soap_password']))
+ return false;
+
+ $res = db_query_params('truncate plugin_mantisbt_global', array());
+ if (!$res)
+ return false;
+
+ $res = db_query_params('insert into plugin_mantisbt_global (url, soap_user, soap_password)
+ values ($1, $2, $3)',
+ array(
+ $confArr['url'],
+ $confArr['soap_user'],
+ $confArr['soap_password'],
+ ));
+ if (!$res)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * getGlobalAdminView - display the Global Admin View
+ *
+ * @return bool true
+ */
+ function getGlobalAdminView() {
+ global $gfplugins;
+ $user = session_get_user();
+ include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
+ return true;
+ }
+
+ function getAdminOptionLink() {
+ return util_make_link('/plugins/'.$this->name.'/?type=globaladmin&pluginname='.$this->name, _('Global MantisBT admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
+ }
+
+ function widgets($params) {
+ $group = group_get_object($GLOBALS['group_id']);
+ if ( !$group || !$group->usesPlugin ( $this->name ) ) {
+ return false;
+ }
+ require_once('common/widget/WidgetLayoutManager.class.php');
+ if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
+ $params['fusionforge_widgets'][] = 'plugin_mantisbt_project_latestissues';
+ }
+ return true;
+ }
+
+ function myPageBox($params) {
+ global $gfplugins;
+ require_once('common/widget/WidgetLayoutManager.class.php');
+ if ($params['widget'] == 'plugin_mantisbt_project_latestissues') {
+ require_once $gfplugins.$this->name.'/common/mantisbt_Widget_ProjectLastIssues.class.php';
+ $params['instance'] = new mantisbt_Widget_ProjectLastIssues($this);
+ }
+ }
}
// Local Variables:
// mode: php