[Fusionforge-commits] r12353 - in trunk/src/plugins/mantisbt: action common db etc view www

Franck VILLAUME nerville at fusionforge.org
Thu Feb 24 18:51:55 CET 2011


Author: nerville
Date: 2011-02-24 18:51:54 +0100 (Thu, 24 Feb 2011)
New Revision: 12353

Added:
   trunk/src/plugins/mantisbt/action/init.php
   trunk/src/plugins/mantisbt/view/init.php
Modified:
   trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
   trunk/src/plugins/mantisbt/db/mantisbt-init.sql
   trunk/src/plugins/mantisbt/etc/mantisbt.ini
   trunk/src/plugins/mantisbt/www/index.php
Log:
initial rewrite for initialization in mantisbt

Copied: trunk/src/plugins/mantisbt/action/init.php (from rev 12204, trunk/src/plugins/mantisbt/action/addNote.php)
===================================================================
--- trunk/src/plugins/mantisbt/action/init.php	                        (rev 0)
+++ trunk/src/plugins/mantisbt/action/init.php	2011-02-24 17:51:54 UTC (rev 12353)
@@ -0,0 +1,40 @@
+<?php
+/*
+ * Copyright 2011, Franck Villaume - Capgemini
+ *
+ * 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.
+ *
+ * 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
+ */
+
+global $group_id; // the group id
+global $mantisbt; // the mantisbt object
+global $group; // the group object
+
+$confArr = array();
+$confArr['url'] = getStringFromRequest('url');
+$confArr['sync_roles'] = 0;
+$confArr['sync_users'] = 0;
+$confArr['soap_user'] = getStringFromRequest('soap_user');
+$confArr['soap_password'] = getStringFromRequest('soap_password');
+$confArr['mantisbtcreate'] = getIntFromRequest('mantisbtcreate');
+$confArr['mantisbtname'] = getStringFromRequest('mantisbtname');
+
+if (!$mantisbt->initialize($group_id,$confArr))
+	session_redirect('/plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname=mantisbt&error_msg='.urlencode($group->getErrorMessage()));
+
+$feedback = _('MantisBT plugin successfully initialized.');
+session_redirect('/plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname=mantisbt&feedback='.urlencode($feedback));
+?>

Modified: trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
===================================================================
--- trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2011-02-24 14:51:43 UTC (rev 12352)
+++ trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2011-02-24 17:51:54 UTC (rev 12353)
@@ -3,7 +3,7 @@
  * MantisBPlugin Class
  *
  * Copyright 2009, Fabien Dubois - Capgemini
- * Copyright 2009-2010, Franck Villaume - Capgemini
+ * Copyright 2009-2011, Franck Villaume - Capgemini
  * http://fusionforge.org
  *
  * This file is part of FusionForge.
@@ -32,7 +32,8 @@
 require_once 'include/database-pgsql.php';
 
 class MantisBTPlugin extends Plugin {
-	function MantisBTPlugin () {
+
+	function MantisBTPlugin() {
 		$this->Plugin() ;
 		$this->name = "mantisbt" ;
 		$this->text = "MantisBT" ; // To show in the tabs, use...
@@ -53,27 +54,27 @@
 		$this->_addHook('group_update');
 	}
 
-	function CallHook ($hookname, &$params) {
+	function CallHook($hookname, &$params) {
 		global $G_SESSION, $HTML;
 		$returned = false;
 		switch ($hookname) {
 			case "usermenu": {
 				if ($G_SESSION->usesPlugin($this->name)) {
-					$param = '?type=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));
+					$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')));
 				}
 				$returned = true;
 				break;
 			}
 			case "groupmenu": {
-				$group_id=$params['group'];
+				$group_id = $params['group'];
 				$project = group_get_object($group_id);
 				if (!$project || !is_object($project) || $project->isError() || !$project->isProject()) {
 					return;
 				}
 				if ($project->usesPlugin($this->name)) {
 					$params['TITLES'][]=$this->text;
-					$params['DIRS'][]='/plugins/' . $this->name . '/?type=group&id=' . $group_id . '&pluginname=' . $this->name;
+					$params['DIRS'][]='/plugins/' . $this->name . '/?type=group&group_id=' . $group_id . '&pluginname=' . $this->name;
 				}
 				if ($params['toptab'] == $this->name) {
 					$params['selected']=(count($params['TITLES'])-1);
@@ -89,7 +90,7 @@
 				//check if the user has the plugin activated
 				if ($user->usesPlugin($this->name)) {
 					echo '<p>';
-					echo util_make_link("/plugins/mantisbt/index.php?id=$userid&type=user&pluginname=".$this->name,
+					echo util_make_link("/plugins/mantisbt/?user_id=$userid&type=user&pluginname=".$this->name,
 					_('View Personal MantisBT')
 					);
 					echo '</p>';
@@ -103,7 +104,7 @@
 				$group = group_get_object($group_id);
 				if ($group->usesPlugin($this->name)) {
 					echo '<p>';
-					echo util_make_link("/plugins/mantisbt/index.php?id=$group_id&type=admin&pluginname=".$this->name,
+					echo util_make_link("/plugins/mantisbt/?group_id=$group_id&type=admin&pluginname=".$this->name,
 					_('View Admin MantisBT')
 					);
 					echo '</p>';
@@ -111,32 +112,9 @@
 				$returned = true;
 				break;
 			}
-			case "group_approved": {
-				$group_id = $params['1'];
-				$group = group_get_object($group_id);
-				if ($group->usesPlugin($this->name)) {
-					if (!$this->isProjectMantisCreated($group->getID())) {
-						if($this->addProjectMantis($group->getID())) {
-							$members = array();
-							foreach($group->getMembers() as $member) {
-								$members[] = $member->getUnixName();
-								if($this->updateUsersProjectMantis($group->getID(), $members)) {
-									$group->setPluginUse($this->name);
-									$returned = true;
-								};
-							}
-						}
-					} else {
-						$returned = true;
-					}
-				} else {
-					$returned = true;
-				}
-				break;
-			}
 			case "change_cal_permission": {
 				// mise a jour des utilisateurs avec les roles
-				$group_id=$params[1];
+				$group_id = $params[1];
 				$group = group_get_object($group_id);
 				$members = array();
 				foreach($group->getMembers() as $member){
@@ -147,7 +125,7 @@
 			}
 			// mise a jour de l'adresse mail utilisateur
 			case "change_cal_mail": {
-				$user_id=$params[1];
+				$user_id = $params[1];
 				// before activate this, please fix updateUserInMantis
 				//$this->updateUserInMantis($user_id);
 				$returned = true;
@@ -201,46 +179,12 @@
 	}
 
 	/**
-	 * groupisactivecheckboxpost - overwrite default function : initialize plugin
+	 * addProjectMantis - inject the Group into Mantisbt thru SOAP
 	 *
+	 * @param	array	Configuration Array (url, soap_user, soap_password, sync_roles, sync_users)
 	 * @return	bool	success or not
 	 */
-	function groupisactivecheckboxpost(&$params) {
-		// this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
-		$group = group_get_object($params['group']);
-		$flag = strtolower('use_'.$this->name);
-		$returned = false;
-		if (getStringFromRequest($flag) == 1) {
-			if (!$this->isProjectMantisCreated($group->getID())) {
-				if($this->addProjectMantis($group->getID())) {
-					$members = array();
-					foreach($group->getMembers() as $member) {
-						$members[] = $member->getUnixName();
-						if($this->updateUsersProjectMantis($group->getID(), $members)) {
-							$group->setPluginUse($this->name);
-							$returned = true;
-						};
-					}
-				}
-			} else {
-				$group->setPluginUse($this->name);
-				$returned = true;
-			}
-		} else {
-			$group->setPluginUse($this->name, false);
-			$returned = true;
-		}
-		return $returned;
-	}
-
-	/**
-	 * addProjectMantis - inject the Group into Mantisbt
-	 *
-	 * @param	int	The Group Id
-	 * @return	bool	success or not
-	 */
-	function addProjectMantis($groupId) {
-
+	function addProjectMantis($groupId, $confArr) {
 		$groupObject = group_get_object($groupId);
 		$project = array();
 		$project['name'] = $groupObject->getPublicName();
@@ -255,8 +199,8 @@
 		$project['description'] = $groupObject->getDescription();
 
 		try {
-			$clientSOAP = new SoapClient(forge_get_config('server_url','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
-			$idProjetMantis = $clientSOAP->__soapCall('mc_project_add', array("username" => forge_get_config('adminsoap_user', 'mantisbt'), "password" => forge_get_config('adminsoap_passwd', 'mantisbt'), "project" => $project));
+			$clientSOAP = new SoapClient($confArr['url']."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+			$idProjetMantis = $clientSOAP->__soapCall('mc_project_add', array("username" => $confArr['soap_user'], "password" => $confArr['soap_password'], "project" => $project));
 		} catch (SoapFault $soapFault) {
 			$groupObject->setError('addProjectMantis::Error: ' . $soapFault->faultstring);
 			return false;
@@ -264,19 +208,12 @@
 		if (!isset($idProjetMantis) || !is_int($idProjetMantis)){
 			$groupObject->setError('addProjectMantis::Error: ' . _('Unable to create project in Mantisbt'));
 			return false;
-		}else{
-			$res = db_query_params('INSERT INTO group_mantisbt (id_group, id_mantisbt) VALUES ($1,$2)',
-					array($groupObject->getID(), $idProjetMantis));
-			if (!$res) {
-				$groupObject->setError('addProjectMantis::Error: ' . _('db_error') . ' ' .db_error());
-				return false;
-			}
 		}
-		return true;
+		return $idProjetMantis;
 	}
 
 	function removeProjectMantis($idProjet) {
-		$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
+		$resIdProjetMantis = db_query_params('SELECT id_mantisbt FROM plugin_mantisbt WHERE id_group = $1',
 						array($idProjet));
 
 		echo db_error();
@@ -295,7 +232,7 @@
 			if (!isset($delete)){
 				echo 'removeProjetMantis:: ' . _('No project found in MantisBT') . ' ' .$idProjet;
 			}else{
-				db_query_params('DELETE FROM group_mantisbt WHERE group_mantisbt.id_mantisbt = $1',
+				db_query_params('DELETE FROM plugin_mantisbt WHERE id_mantisbt = $1',
 						array($idMantisbt));
 				echo db_error();
 			}
@@ -309,7 +246,7 @@
 	 * @param	int	public or private
 	 * @return	bool	success or not
 	 */
-	function updateProjectMantis($groupId,$groupName, $groupIspublic) {
+	function updateProjectMantis($groupId, $groupName, $groupIspublic) {
 		$groupObject = group_get_object($groupId);
 		$projet = array();
 		$project['name'] = $groupName;
@@ -322,7 +259,7 @@
 			$project['view_state'] = 50;
 		}
 
-		
+
 		$idMantisbt = getIdProjetMantis($groupId);
 
 		if ($idMantisbt) {
@@ -352,7 +289,7 @@
 	 */
 	function isProjectMantisCreated($idProjet){
 
-		$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
+		$resIdProjetMantis = db_query_params('SELECT id_mantisbt FROM plugin_mantisbt WHERE id_group = $1',
 					array($idProjet));
 		if (!$resIdProjetMantis)
 			return false;
@@ -528,26 +465,93 @@
 			}
 		}
 	}
-}
 
-function getIdProjetMantis($groupId) {
+	/**
+	 * getMantisBTConf - get the mantisbt configuration id for a specific group_id
+	 *
+	 * @param	int	the group_id
+	 * @return	array	the mantisbt configuration array
+	 * @access	public
+	 */
+	function getMantisBTConf($groupId) {
+		$group = group_get_object($groupId);
+		$mantisbtConfArray = array();
+		$resIdProjetMantis = db_query_params('SELECT * FROM plugin_mantisbt WHERE id_group = $1', array($groupId));
+		if (!$resIdProjetMantis) {
+			$group->setError('getMantisBTId::error ' .db_error());
+			return $mantisbtConfArray;
+		}
 
-	$group = group_get_object($groupId);
-	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
-				array($groupId));
-	if (!$resIdProjetMantis) {
-		$group->setError('getIdProjetMantis::error ' .db_error());
-		return 0;
+		$row = db_numrows($resIdProjetMantis);
+
+		if ($row == null || count($row)>2) {
+			$mantisbtConfArray['id_mantisbt'] = 0;
+			return $mantisbtConfArray;
+		}
+
+		$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_users'] = $row['sync_users'];
+		$mantisbtConfArray['sync_roles'] = $row['sync_roles'];
+		return $mantisbtConfArray;
 	}
 
-	$row = db_fetch_array($resIdProjetMantis);
-	if ($row == null || count($row)>2) {
-		$group->setError('getIdProjetMantis::error ' . _('ID project not found'));
-		return 0;
-	}else{
-		return $row['id_mantisbt'];
+	function getInitDisplay() {
+		global $gfplugins;
+		require_once $gfplugins.$this->name.'/view/init.php';
 	}
 
+	function getHeader($type) {
+		$params['toptab'] = $this->name;
+		switch ($type) {
+			case 'project': {
+				global $group_id;
+				$params['group'] = $group_id;
+				$params['title'] = $this->name . ' Project Plugin!';
+				$params['pagename'] = $this->name;
+				$params['sectionvals'] = array(group_getname($group_id));
+				site_project_header($params);
+				break;
+			}
+			case 'user': {
+				global $user_id;
+				$params['user'] = $user_id;
+				site_user_header($params);
+				break;
+			}
+			default: {
+				break;
+			}
+		}
+		html_use_tooltips();
+	}
+
+	function initialize($group_id, $confArr) {
+		if ($confArr['mantisbtcreate']) {
+			$idProjectMantis = $this->addProjectMantis($group_id, $confArr);
+		} else {
+			$idProjectMantis = $this->getProjectMantisByName($group_id, $confArr);
+		}
+		if ($idProjectMantis) {
+			$result = db_query_params('insert into plugin_mantisbt (id_group, id_mantisbt, url, soap_user, soap_password, sync_roles, sync_users)
+							values ($1, $2, $3, $4, $5, $6, $7)',
+							array($group_id,
+								$idProjectMantis,
+								$confArr['url'],
+								$confArr['soap_user'],
+								$confArr['soap_password'],
+								$confArr['sync_roles'],
+								$confArr['sync_users']));
+			if (!$result)
+				return false;
+
+			return true;
+		}
+		return false;
+	}
 }
 // Local Variables:
 // mode: php

Modified: trunk/src/plugins/mantisbt/db/mantisbt-init.sql
===================================================================
--- trunk/src/plugins/mantisbt/db/mantisbt-init.sql	2011-02-24 14:51:43 UTC (rev 12352)
+++ trunk/src/plugins/mantisbt/db/mantisbt-init.sql	2011-02-24 17:51:54 UTC (rev 12353)
@@ -1,5 +1,10 @@
-CREATE TABLE group_mantisbt (
-    id_group_mantisbt	serial PRIMARY KEY,
-    id_group			integer NOT NULL,
-    id_mantisbt			integer NOT NULL
+CREATE TABLE plugin_mantisbt (
+	id_group_mantisbt	serial PRIMARY KEY,
+	id_group		integer NOT NULL,
+	id_mantisbt		integer,
+	url			character varying(255),
+	soap_user		character varying(255),
+	soap_password		character varying(255),
+	sync_users		integer DEFAULT 0,
+	sync_roles		integer DEFAULT 0
 );
\ No newline at end of file

Modified: trunk/src/plugins/mantisbt/etc/mantisbt.ini
===================================================================
--- trunk/src/plugins/mantisbt/etc/mantisbt.ini	2011-02-24 14:51:43 UTC (rev 12352)
+++ trunk/src/plugins/mantisbt/etc/mantisbt.ini	2011-02-24 17:51:54 UTC (rev 12353)
@@ -5,17 +5,4 @@
 ; valid means : production ready.
 ; Any other strings means it's under work or broken and plugin 
 ; is available in installation_environment = development only.
-plugin_status = "broken: under heavy rewrite. More info https://fusionforge.org/plugins/mediawiki/wiki/fusionforge/index.php/MantisBT"
-
-; Configuration for SOAP API
-server_url = http://localhost/mantis
-adminsoap_user = administrator
-adminsoap_passwd = root
-
-; Configuration for DB access
-db_type = pgsql
-db_host = locahost
-db_name = mantisbt
-db_port = 5431
-db_user = root
-db_password = root
+plugin_status = "broken: under heavy rewrite. More info https://fusionforge.org/plugins/mediawiki/wiki/fusionforge/index.php/MantisBT"
\ No newline at end of file

Copied: trunk/src/plugins/mantisbt/view/init.php (from rev 12204, trunk/src/plugins/mantisbt/view/addAttachment.php)
===================================================================
--- trunk/src/plugins/mantisbt/view/init.php	                        (rev 0)
+++ trunk/src/plugins/mantisbt/view/init.php	2011-02-24 17:51:54 UTC (rev 12353)
@@ -0,0 +1,54 @@
+<?php
+/*
+ * Copyright 2011, Franck Villaume - Capgemini
+ * 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.
+ *
+ * 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
+ */
+
+/* please do not add include here, use index.php to do so */
+/* global variables */
+global $type;
+global $group_id;
+global $mantisbt;
+global $use_tooltips;
+
+?>
+	<script type="text/javascript" >
+	function doMantisBTName() {
+		if (jQuery('#mantisbtcreate').is(':checked')) {
+			jQuery('#mantisbtname').attr('disabled',true);
+		} else {
+			jQuery('#mantisbtname').attr('disabled',false);
+		}
+	}
+	</script>
+<?
+
+echo '<form method="POST" Action="?type='.$type.'&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&action=init" >';
+echo '<table>';
+echo '<tr><td><label title="'._('Specify the Full URL of the MantisBT Web Server.').'" >URL</label></td><td><input type="text" size="50" maxlength="255" name="url" /></td></tr>';
+echo '<tr><td><label title="'._('Specify the user with admin right to be used thru SOAP API.').'">SOAP User</label></td><td><input type="text" size="50" maxlength="255" name="soap_user" /></td></tr>';
+echo '<tr><td><label title="'._('Specify the password of this user.').'">SOAP Password</label></td><td><input type="text" size="50" maxlength="255" name="soap_password" /></td></tr>';
+echo '<tr><td><label title="'._('If this project does NOT exist in MantisBT, do you want to create it ?').'" >Create the project in MantisBT</label></td><td><input id="mantisbtcreate" type="checkbox" name="mantisbtcreate" onclick="javascript:doMantisBTName()" value="1" ></td></tr>';
+echo '<tr><td><label title="'._('Specify the name of the project in MantisBT if already created in MantisBT').'" >Name of the project in MantisBT</label></td><td><input id="mantisbtname" type="text" size="50" maxlength="255" name="mantisbtname" /></td></tr>';
+echo '<tr><td><label title="'._('Do you want to sync FusionForge -> MantisBT users ?').'">Sync Users</label></td><td><input disabled="disabled" type="checkbox" name="sync_user" /></td></tr>';
+echo '<tr><td><label title="'._('Do you want to sync FusionForge -> MantisBT roles ?').'">Sync Roles</label></td><td><input disabled="disabled" type="checkbox" name="sync_roles" /></td></tr>';
+echo '</table>';
+echo '<input type="submit" value="'._('Initialize').'" />';
+echo '</form>';
+?>

Modified: trunk/src/plugins/mantisbt/www/index.php
===================================================================
--- trunk/src/plugins/mantisbt/www/index.php	2011-02-24 14:51:43 UTC (rev 12352)
+++ trunk/src/plugins/mantisbt/www/index.php	2011-02-24 17:51:54 UTC (rev 12353)
@@ -2,7 +2,7 @@
 /*
  * MantisBT plugin
  *
- * Copyright 2009-2010, Franck Villaume - Capgemini
+ * Copyright 2009-2011, Franck Villaume - Capgemini
  * Copyright 2009, Fabien Dubois - Capgemini
  * Copyright 2010, Antoine Mercadal - Capgemini
  * http://fusionforge.org
@@ -28,28 +28,6 @@
 require_once $gfcommon.'include/pre.php';
 require_once $gfconfig.'plugins/mantisbt/config.php';
 
-// the header that displays for the user portion of the plugin
-function mantisbt_Project_Header($params) {
-	global $DOCUMENT_ROOT,$HTML,$id;
-	$params['toptab']='mantisbt';
-	$params['group']=$id;
-	/*
-	 * Show horizontal links
-	*/
-	site_project_header($params);
-}
-
-// the header that displays for the project portion of the plugin
-function mantisbt_User_Header($params) {
-	global $DOCUMENT_ROOT,$HTML,$user_id;
-	$params['toptab']='mantisbt';
-	$params['user']=$user_id;
-	/*
-	 * Show horizontal links
-	 */
-	site_user_header($params);
-}
-
 if (!session_loggedin()) {
 	exit_not_logged_in();
 }
@@ -57,43 +35,52 @@
 $user = session_get_user(); // get the session user
 
 if (!$user || !is_object($user)) {
-	exit_error(_('Invalid User'),'home');
+	exit_error(_('Invalid User'), 'home');
 } else if ( $user->isError()) {
-	exit_error($user->isError(),'home');
+	exit_error($user->isError(), 'home');
 } else if ( !$user->isActive()) {
-	exit_error(_('User not active'),'home');
+	exit_error(_('User not active'), 'home');
 }
 
 $type = getStringFromRequest('type');
-$id = getStringFromRequest('id');
-$pluginname = getStringFromRequest('pluginname');
+$group_id = getIntFromRequest('group_id');
+$user_id = getIntFromRequest('user_id');
 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
 $error_msg = htmlspecialchars(getStringFromRequest('error_msg'));
 $warning_msg = htmlspecialchars(getStringFromRequest('warning_msg'));
+$action = getStringFromRequest('action');
+$view = getStringFromRequest('view');
 
-$password = $user->getMD5Passwd();
-$username = $user->getUnixName();
-
 if (!$type) {
 	exit_missing_params($_SERVER['HTTP_REFERER'], array('No TYPE specified'), 'mantisbt');
-} elseif (!$id) {
-	exit_missing_params($_SERVER['HTTP_REFERER'], array('No ID specified'), 'mantisbt');
-} else {
-	switch ($type) {
-		case 'group': {
-			$idProjetMantis = getIdProjetMantis($id);
-			$group = group_get_object($id);
-			if (!$group) {
-				exit_no_group();
-			}
-			if (!$group->usesPlugin($pluginname)) {//check if the group has the MantisBT plugin active
-				exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $pluginname), 'home');
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
-			if ( !$userperm->IsMember()) {
-				exit_permission_denied(_('You are not a member of this project'), 'home');
-			}
+} elseif (!$group_id) {
+	exit_missing_params($_SERVER['HTTP_REFERER'], array('No GROUP_ID specified'), 'mantisbt');
+}
 
+$mantisbt = plugin_get_object('mantisbt');
+
+switch ($type) {
+	case 'group': {
+		$group = group_get_object($group_id);
+		if (!$group) {
+			exit_no_group();
+		}
+		if (!$group->usesPlugin($mantisbt->name)) {//check if the group has the MantisBT plugin active
+			exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $mantisbt->name), 'home');
+		}
+
+		$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
+		if ( !$userperm->IsMember()) {
+			exit_permission_denied(_('You are not a member of this project'), 'home');
+		}
+
+		$mantisbtConf = $mantisbt->getMantisBTConf($group_id);
+		$mantisbt->getHeader('project');
+
+		if ($mantisbtConf['id_mantisbt'] === 0) {
+			$warning_msg = _('The mantisbt plugin for this project is not initialized.');
+			session_redirect('/plugins/'.$mantisbt->name.'/?type=admin&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&view=init&warning_msg='.urlencode($warning_msg));
+		} else {
 			// URL analysis
 			$sort = getStringFromRequest('sort');
 			$dir = getStringFromRequest('dir');
@@ -107,77 +94,78 @@
 			// Si la variable $_GET['page'] existe...
 			if($page != null && $page != ''){
 				$pageActuelle=intval($page);
+			} else {
+				$pageActuelle=1; // La page actuelle est la n°1
 			}
-			else {
-				$pageActuelle=1; // La page actuelle est la n°1 
-			}
 
 			$format = "%07d";
+			// do the job
+			include ($mantisbt->name.'/www/group/index.php');
+		}
+		break;
+	}
+	case 'user': {
+		if (!($user) || !($user->usesPlugin($pluginname))) {
+			exit_error(sprintf(_('First activate the User\'s %s plugin through Account Maintenance Page'), $pluginname), 'my');
+		}
+		if ( (!$user) || ($user->getID() != $user_id)) { // if someone else tried to access the private MantisBT part of this user
+			exit_permission_denied(sprintf(_('You cannot access other user\'s personal %s'), $pluginname), 'my');
+		}
 
-			if($idProjetMantis == 0) {
-				exit_error(_('Uninitialized Project. Force his activation by desactivate/activate mantisbt for this project'),'home');
-			} else {
-				// do the job
-				mantisbt_Project_Header(array('title'=>$pluginname . ' Project Plugin!', 'pagename'=>"$pluginname", 'sectionvals'=>array(group_getname($id))));
-				html_use_tooltips();
-				include ('mantisbt/www/group/index.php');
-			}
-			break;
+		// URL analysis
+		$sort = getStringFromRequest('sort');
+		$dir = getStringFromRequest('dir');
+		$action = getStringFromRequest('action');
+		$idBug = getStringFromRequest('idBug');
+		$idNote = getStringFromRequest('idNote');
+		$page = getStringFromRequest('page');
+		// Si la variable $_GET['page'] existe...
+		if($page != null && $page != '') {
+			$pageActuelle=intval($page);
+		} else {
+			$pageActuelle=1; // La page actuelle est la n°1
 		}
-		case 'user': {
-			if (!($user) || !($user->usesPlugin($pluginname))) {
-				exit_error(sprintf(_('First activate the User\'s %s plugin through Account Maintenance Page'), $pluginname), 'my');
-			}
-			if ( (!$user) || ($user->getID() != $id)) { // if someone else tried to access the private MantisBT part of this user
-				exit_permission_denied(sprintf(_('You cannot access other user\'s personal %s'), $pluginname), 'my');
-			}
 
-			// URL analysis
-			$sort = getStringFromRequest('sort');
-			$dir = getStringFromRequest('dir');
-			$action = getStringFromRequest('action');
-			$idBug = getStringFromRequest('idBug');
+		$format = "%07d";
+		// do the job
+		$mantisbt->getHeader('user');
+		include($mantisbt->name.'/www/user/index.php');
+		break;
+	}
+	case 'admin': {
+		$group = group_get_object($group_id);
+		if (!$group) {
+			exit_no_group();
+		}
+		if (!$group->usesPlugin($mantisbt->name)) {//check if the group has the MantisBT plugin active
+			exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$mantisbt->name),'home');
+		}
+		$userperm = $group->getPermission($user);//we'll check if the user belongs to the group
+		if (!$userperm->IsMember()) {
+			exit_permission_denied(_('You are not a member of this project'));
+		}
 
-			$idNote = getStringFromRequest('idNote');
-			$page = getStringFromRequest('page');
-			// Si la variable $_GET['page'] existe...
-			if($page != null && $page != '') {
-				$pageActuelle=intval($page);
-			} else {
-				$pageActuelle=1; // La page actuelle est la n°1 
+		switch ($action) {
+			case "init": {
+				global $gfplugins;
+				include($gfplugins.$mantisbt->name.'/action/'.$action.'.php');
+				break;
 			}
-
-			$format = "%07d";
-
-			// do the job
-			mantisbt_User_Header(array('title'=>sprintf(_('My %s'), $pluginname), 'pagename'=>"$pluginname", 'sectionvals'=>array($username)));
-			html_use_tooltips();
-			include('mantisbt/www/user/index.php');
-			break;
 		}
-		case 'admin': {
-			$group = group_get_object($id);
-			if ( !$group) {
-				exit_no_group();
+
+		$mantisbt->getHeader('project');
+		//only project admin can access here
+		if ($userperm->isAdmin()) {
+			switch ($view) {
+				case "init": {
+					$mantisbt->getInitDisplay();
+					break;
+				}
 			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the MantisBT plugin active
-				exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group
-			if ( !$userperm->IsMember()) {
-				exit_permission_denied(_('You are not a member of this project'));
-			}
-			//only project admin can access here
-			if ( $userperm->isAdmin() ) {
-				// DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
-				mantisbt_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
-				html_use_tooltips();	
-				include ('mantisbt/www/admin/index.php');
-			} else {
-				exit_permission_denied(_('You are not Admin of this project'),'home');
-			}
-			break;
+		} else {
+			exit_permission_denied(_('You are not Admin of this project'), 'home');
 		}
+		break;
 	}
 }
 




More information about the Fusionforge-commits mailing list