Extending the cleanup and functionality one step further -
Here is how to manage Mantis Access Levels via the Joomla User Manager.
See screenshots at bottom of the post.
Thanks
Cas Nuy - For the bridge in the first place, and helping me out a bit.
http://www.nuy.info/apps/smf/index.php? ... 48#msg4748 (don't follow these instructions though... )
eagle00789 - For cleaning up the mantis integration
cryan - For another set of eyes.
nlilly - For requesting this functionality.
Prerequsites:
mantis tables are in the same db as Joomla!
You're running the Cas Nuy Joomla/Mambo Mantis Bridge
Create column mantisaccess in jos_users as text
You've made backups of everything - DB's, Dirs, Files, Etc.
TODO / WishList/ Need help with
- Check boxes/ Dropdown list for mantisaccess levels.
- Componentize/modularize these changes into joomla, so we're not hacking core files, make it an installable component...
- Make this read / update mantis_user_table, instead of jos_users.mantisaccess
- Git rid of the <IFRAME> - See above comment about component
The Changes
In Joomla/includes/joomla.php around line 1225 in function getUser find:
Code: Select all
if ($user->id) {
$query = "SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params"
. "\n FROM #__users"
Change to:
Code: Select all
if ($user->id) {
$query = "SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params, mantisaccess"
. "\n FROM #__users"
In the same function around line 1239 find:
Code: Select all
$user->activation = $my->activation;
Add beneath this:
Code: Select all
$user->mantisaccess = $my->mantisaccess;
Around line 2816 find:
Code: Select all
/** @var string */
var $params = null;
Add beneath this:
Code: Select all
/** @mantisaccess ADDED FOR xTUPLE MANTIS ACCESS LEVELS */
var $mantisaccess = null;
Save and close joomla.php
Open up joomladir/administrator/components/com_users/admin.users.php find around line 322:
Code: Select all
$row->username = trim( $row->username );
Add beneath this:
Code: Select all
$row->mantisaccess = trim( $row->mantisaccess ); // Mantis Access Level - Gets rid of leading spaces
Close admin.users.php
Open up admin.users.html.php find around line 77:
Code: Select all
<th width="1%" class="title">
ID
</th>
</th>
Add beneath it:
Code: Select all
<!-- MANTIS LEVEL INTEGRATION - THIS DISPLAYS THE VALUE IN jos_users.mantisaccess-->
<th width="15%" class="title">
Mantis Level
</th>
<!-- MANTIS LEVEL INTEGRATION - END -->
Go to someplace around line 146 for:
Code: Select all
<td>
<?php echo $row->id; ?>
</td>
Add beneath:
Code: Select all
<!--MANTIS.. Gets Access Level from jos_users.mantisaccess -->
<td>
<?php echo $row->mantisaccess; ?>
</td>
</tr>
Around line 206 find: (this is optional - adds a check for values in the field)
Code: Select all
} else if (trim(form.email.value) == "") {
alert( "You must provide an e-mail address." );
Add this underneath that:
Code: Select all
} else if (trim(form.mantisaccess.value) == "") {
alert( "Set Mantis Access Level - Viewer, Reporter, Updater, Developer, Manager or Administrator" );
Find this around line 266:
Code: Select all
<tr>
<td>
E-mail:
</td>
<td>
<input class="inputbox" type="text" name="email" size="40" value="<?php echo $row->email; ?>" />
</td>
</tr>
Add underneath it:
Code: Select all
<!-- MANTIS USER LEVEL INTEGRATION START: THIS PUTS THE OPTION ON THE USER:EDIT SCREEN-->
<tr>
<td>Mantis Level:
</td>
<td>Viewer, Reporter, Updater, Developer, Manager, or Administrator<br>
<input type="text" name="mantisaccess" class="inputbox" size="40" value="<?php echo $row->mantisaccess; ?>" maxlength="25" />
</td>
</tr>
<!-- MANTIS USER LEVEL INTEGRATION END -->
Close admin.users.html.php and open up joomladir/components/com_mantis/mantis.php -
The following mods make the Mantis Cas Nuy Joomla integration check the access level set in jos_users.mantisaccess .
Here's the full code, add the appropriate bits for your system.
Code: Select all
<?php
/*
* This is the mantis bridge component for Mambo Open Source
* Created by Cas Nuy March 2005
*/
if (!defined('mantis')){
global $mosConfig_absolute_path;
require ($mosConfig_absolute_path."/administrator/components/com_mantis/config.mantis.php");
}
if (!defined("_MOS_ALLOWHTML")){
define( "_MOS_ALLOWHTML", 0x0002 );
}
$my_id = $my->id;
$name='';
$mail='';
$mantisaccess='';
$sql = "SELECT username,email,mantisaccess FROM ".$mos_prefix."users WHERE id=$my_id";
$result = mysql_query ($sql);
if (isset($result)) {
$row = mysql_fetch_array($result);
$name= $row[0] ;
$mail= $row[1] ;
$mantisaccess= $row[2] ;
}
$check = $name ;
$check .= "|" ;
$check .= $mail ;
$check .= "|" ;
$check .= $mantisaccess ;
$scripturl = $mantis_path ;
$scripturl .= "/index_mambo.php?parm=" ;
$scripturl .= $check ;
echo "<iframe src='$scripturl' align='center' width='100%' height='800px' space=0 vspace=0 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto name='mantis' onload='parent.scrollTo(0,0);' ></iframe>";
?>
Open up mantis/index_mambo.php, Here's the full code...
Code: Select all
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2003 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# --------------------------------------------------------
# $Id: index.php,v 1.13 2003/01/18 02:14:12 jfitzell Exp $
# --------------------------------------------------------
?>
<?php
$reqVar = '_' . $_SERVER['REQUEST_METHOD'];
$form_vars = $$reqVar;
$parm = $form_vars['parm'] ;
$url = explode("|", $parm);
$f_username = $url[0];
$mail = $url[1];
$mantisaccess= $url[2];
// my defined mantis level for joomla level
// MANTIS
// 10:viewer - This is the default if the field is NULL, or doesn't match
// 25:reporter
// 40:updater
// 55:developer
// 70:Manager
// 90:administrator
// Sets the Mantis user access_level to what mantisaccess in joomla says.
// This should be a dropdown or checkboxes eventually.
$access_level= null;
switch ($mantisaccess)
{
case "Reporter":
$access_level = "25";
break;
case "Updater":
$access_level = "40";
break;
case "Developer":
$access_level = "55";
break;
case "Manager":
$access_level = "70" ;
break;
case "Administrator":
$access_level = "90" ;
break;
default:
$access_level = "10";
}
require_once( 'core.php' );
$t_user_table = config_get( 'mantis_user_table' );
$f_perm_login='false';
$direct= config_get( 'default_home_page' );
if ($direct ==""){
$direct= "main_page.php" ;
}
$query = "SELECT password FROM $t_user_table WHERE username='$f_username'";
$result = db_query( $query );
$f_password = db_result( $result );
$query = "UPDATE $t_user_table set access_level=$access_level WHERE username='$f_username' AND protected=0";
$result = db_query( $query );
if ( auth_attempt_login( $f_username, $f_password, $f_perm_login ) ) {
print_header_redirect( $direct );
$t_redirect_url = 'login_cookie_test.php?return=' . $f_return;
}
$hack_pwd = ranpass() ;
if (user_create ($f_username,"$hack_pwd", "$mail", $access_level,false,true,$f_username )) {
if ( auth_attempt_login( $f_username, "$hack_pwd" , $f_perm_login ) ) {
// update table with e-mail address when created an account
$query = "Update $t_user_table set email='$mail' WHERE username='$f_username'";
// $query = "Update $t_user_table set access_level='$access_level' WHERE username='$f_username'";
$result = db_query( $query );
print_header_redirect( 'main_page.php' );
$t_redirect_url = 'login_cookie_test.php?return=' . $f_return;
}
}
function ranpass($len = "8"){
$pass = NULL;
for($i=0; $i<$len; $i++) {
$char = chr(rand(48,122));
while (!ereg("[a-zA-Z0-9]", $char)){
if($char == $lchar) continue;
$char = chr(rand(48,90));
}
$pass .= $char;
$lchar = $char;
}
return $pass;
}
?>
Contact me if you have any problems - pclark-at-xtuple-dot-com.
Sorry for the epic post... Hope it's useful.
Here's some screenshots.
Creating or editing a user:
Not entering a mantis level - if user has no mantis level, it defaults to viewer.
The main user manager screen - I changed the access between screenshots!
Proudly produced by xTuple - The creators of PostBooks, the FREE OpenSource ERP/CRM/Accounting package - online at
http://www.postbooks.com .