Forums

Call to undefined method JAccess::get_group_id()

rushinge 01 Apr, 2011
Chronoforms Joomla 1.6 V4_RC1.7

I've used the wizard to create a simple form to replace the default Joomla registration form.
On "OnSubmit" I have included the action "Registration" from the "Joomla User Management" category.
When I tested the form in the front-end I got the following error upon submission:

Call to undefined method JAccess::get_group_id() in C:\inetpub\wwwroot\wsunlocked\administrator\components\com_chronoforms\form_actions\joomla_registration\joomla_registration.php on line 85

Is this due to a difference between Joomla 1.5 and 1.6 that hasn't been addressed in the ChronoForms code yet?
GreyHead 01 Apr, 2011
Hi rushinge,

Good catch - I'm sure that's the problem; there are major changes in the ACL in Joomla! 1.6

Bob
rushinge 04 Apr, 2011
In the hope that others may find it useful here are the modifications I had to make to administrator/components/com_chronoforms/form_actions/joomla_registration/joomla_registration.php in order to make it work properly in 1.6. These modifications may not be comprehensive and may not cover every situation. The only use-cases that have been thoroughly tested are those that are being employed in my site. References have been removed in keeping with modern PHP 5.3 best practices (see http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html for more information).

Full code of modified joomla_registration.php file:

<?php
// ECR - Joomla 1.6 change
jimport('joomla.application.component.helper');

/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @author Eric C. Rushing modification of original by Chrono_Man to support Joomla 1.6
* @license		GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
**/
class CfactionJoomlaRegistration{
	var $formname;
	var $formid;
	var $group = array('id' => 'joomla_user', 'title' => 'Joomla User Management');
	var $events = array('success' => 0, 'fail' => 0);
	var $details = array('title' => 'Joomla Registration', 'tooltip' => 'Register some user to Joomla.');

  
	function run($form, $actiondata){
    $params = new JParameter($actiondata->params);
		$mainframe = JFactory::getApplication();
		// Get required system objects
		$user = clone(JFactory::getUser());
		$pathway = $mainframe->getPathway();
		$config = JFactory::getConfig();
		$authorize = JFactory::getACL();
		$document = JFactory::getDocument();
		$language = JFactory::getLanguage();
    $language->load('com_users');

		// If user registration is not allowed, show 403 not authorized.
		$usersConfig = JComponentHelper::getParams( 'com_users' );
		if($usersConfig->get('allowUserRegistration') == '0' && !$params->get('override_allow_user_registration', 0)){
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}

		// Initialize new usertype setting
    // ECR - Joomla 1.6 change
    $userConfig = JComponentHelper::getParams('com_users');
    // Default to Registered.
    $defaultUserGroup = $userConfig->get('new_usertype', 2);
//		$newUsertype = $params->get('new_usertype', $usersConfig->get('new_usertype'));
//		if(!$newUsertype){
//			$newUsertype = 'Registered';
//		}
		
		//set the post fields values
		JRequest::setVar('name', JRequest::getVar($params->get('name', '')));
		JRequest::setVar('username', JRequest::getVar($params->get('username', '')));
		JRequest::setVar('email', JRequest::getVar($params->get('email', '')));
		JRequest::setVar('password', JRequest::getVar($params->get('password', '')));
		JRequest::setVar('password2', JRequest::getVar($params->get('password2', '')));
		
		//generate the random pass if enabled
		if((int)$params->get('random_password', 0) == 1){
			jimport('joomla.user.helper');
			$random_pass = JUserHelper::genRandomPassword();
			JRequest::setVar('password', $random_pass);
			JRequest::setVar('password2', $random_pass);
		}

		//check empty fields
		$checks = array('name', 'username', 'email', 'password');
		foreach($checks as $check){
			if(!trim(JRequest::getVar($check))){
				$this->events['fail'] = 1;
				$form->validation_errors[$params->get($check)] = 'You must provide your '.$check.'.';
				//return false;
			}
		}
		if($this->events['fail'] == 1){
			return false;
		}
		//check the 2 passwords
		if(JRequest::getVar('password') != JRequest::getVar('password2')){
			$this->events['fail'] = 1;
			$form->validation_errors[$params->get('password2')] = 'Passwords do NOT match.';
			$form->debug[] = "Couldn't create new user, Passwords do NOT match.";
			return false;
		}
		// Bind the post array to the user object
		if(!$user->bind(JRequest::get('post'), 'usertype')){
			//JError::raiseError( 500, $user->getError());
			$this->events['fail'] = 1;
			$form->validation_errors[] = $user->getError();
			$form->debug[] = "Couldn't bind new user, Joomla returned this error : ".$user->getError();
			return false;
		}

		// Set some initial user values
		$user->set('id', 0);
    // ECR - Joomla 1.6 change
    $user->set('usertype', 'deprecated');
//		$user->set('usertype', $newUsertype);

    // ECR - Joomla 1.6 change
    $user->set('groups', array($defaultUserGroup));
//		$user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));

		$date = JFactory::getDate();
		$user->set('registerDate', $date->toMySQL());

		// If user activation is turned on, we need to set the activation information
		$useractivation = $params->get('useractivation', $usersConfig->get('useractivation'));
		if((int)$useractivation == 1){
			jimport('joomla.user.helper');
			$user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword()));
			$user->set('block', '1');
		}

		// If there was an error with registration, set the message and display form
		if(!$user->save()){
			/*JError::raiseWarning('', JText::_( $user->getError()));
			$this->register();*/
			$this->events['fail'] = 1;
			$form->validation_errors[] = $user->getError();
			$form->debug[] = "Couldn't save new user, Joomla returned this error : ".$user->getError();
			return false;
		}else{
			$this->events['success'] = 1;
		}
		//store user data
		$user_data = (array)$user;
		$removes = array('params', '_params', 'guest', '_errorMsg', '_errors');
		foreach($removes as $remove){
			unset($user_data[$remove]);
		}
		$form->data['_PLUGINS_']['joomla_registration'] = $user_data;
		// Send registration confirmation mail
		$password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
		$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
		if((int)$params->get('send_joo_activation', 0) == 1){
			$this->_sendMail($user, $password);
		}
		// Everything went fine, set relevant message depending upon user activation state and display message
		if((int)$useractivation == 1){
      // ECR - Joomla 1.6 modification
      $message  = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE');
//			$message  = JText::_('REG_COMPLETE_ACTIVATE');
		}else{
      // ECR - Joomla 1.6 modification
			$message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS');
//      $message = JText::_('REG_COMPLETE');
		}
		
		if($params->get('display_reg_complete', 0) == 1){
			echo $message;
		}
		
		if((int)$params->get('auto_login', 0) == 1){
			$credentials = array();
			$credentials['username'] = JRequest::getVar('username');
			$credentials['password'] = JRequest::getVar('password');
			$mainframe->login($credentials);
		}
	}
	
	function _sendMail(&$user, $password)
	{
		$mainframe = JFactory::getApplication();

		$db = JFactory::getDBO();

		$name 		= $user->get('name');
		$email 		= $user->get('email');
		$username 	= $user->get('username');

		$usersConfig = JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();

    // ECR - Joomla 1.6 modification - changed string identifier
		$subject 	= sprintf ( JText::_( 'COM_USERS_EMAIL_ACCOUNT_DETAILS' ), $name, $sitename);
		$subject 	= html_entity_decode($subject, ENT_QUOTES);

		if ( $useractivation == 1 ){
      // ECR - Joomla 1.6 modification
			//$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password);
      $message = sprintf ( JText::_( 'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY' ), $name, $sitename,
              $siteURL."index.php?option=com_users&task=registration.activate&token=".$user->get('activation'),
              $siteURL, $username, $password);
		} else {
      // ECR - Joomla 1.6 modification
//      $message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
      $message = sprintf ( JText::_( 'COM_USERS_EMAIL_REGISTERED_BODY' ), $name, $sitename, $siteURL);
		}

		$message = html_entity_decode($message, ENT_QUOTES);

		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();

		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}

		JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);

		// Send notification to all administrators
		$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject2 = html_entity_decode($subject2, ENT_QUOTES);

		// get superadministrators id
		foreach ( $rows as $row )
		{
			if ($row->sendEmail)
			{
				$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $sitename, $name, $email, $username);
				$message2 = html_entity_decode($message2, ENT_QUOTES);
				JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
			}
		}
	}
	
	function load($clear){
		if($clear){
			$action_params = array(
				'content1' => '',
				'name' => '',
				'username' => '',
				'email' => '',
				'password' => '',
				'password2' => '',
				'override_allow_user_registration' => 1,
				'new_usertype' => 'Registered',
				'useractivation' => 1,
				'random_password' => 0,
				'auto_login' => 0,
				'send_joo_activation' => 0,
				'display_reg_complete' => 0
			);
		}
		return array('action_params' => $action_params);
	}
}
?>
GreyHead 04 Apr, 2011
Hi rushinge,

Thank you very much; most helpful.

Bob
Max_admin 11 Apr, 2011
Thank you, very helpful!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.