getPath( 'class', 'com_chronocontact' ) ); // the class name must be the same as the file name without the .php at the end class cf_joomla_registration { //the next 3 fields must be defined for every plugin var $result_TITLE = "Joomla Registration"; var $result_TOOLTIP = "Synchronize the submitted data with this form with the default Joomla users table"; var $plugin_name = "cf_joomla_registration"; // must be the same as the class name var $event = "ONLOADONSUBMIT"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD var $plugin_keys ='errors,user,complete';//you can use these keys later here to hold some values in the MyPlugins->plugin_name variable array! var $params = null; // the next function must exist and will have the backend config code function show_conf($row, $id, $form_id, $option) { global $mainframe; require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'plugin.php'); $helper = new ChronoContactHelperPlugin(); // identify and initialise the parameters used in this plugin $params_array = array( 'debugging' => '0', 'name' => '', 'username' => '', 'email' => '', 'pass' => '', 'vpass' => '', 'emailuser' => 'Yes', 'emailadmins' => 'Yes', 'joomlastatus' => '1', 'showmessages' => '1', 'createpassword' => '0', 'onsubmit' => 'before_email', 'autologin' => '0'); $params = $helper->loadParams($row, $params_array); $messages[] = '$params: '.print_r($params, true); if ( $params->get('debugging') ) { $helper->showPluginDebugMessages($messages); } ?>
save_conf($option); } function onsubmit( $option, $params , $row ) { global $mainframe; require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact' .DS.'helpers'.DS.'plugin.php'); $helper = new ChronoContactHelperPlugin(); $messages[] = 'Inside cf_Joomla_registration::onSubmit()'; // Check for request forgeries //JRequest::checkToken() or die( 'Invalid Token' ); // 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_user'); if($row->form_id){ $formname = CFChronoForm::getFormName($row->form_id); }else{ $formname = JRequest::getVar('chronoformname'); } $MyForm =& CFChronoForm::getInstance($formname); $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id); // If user registration is not allowed, show 403 not authorized. $usersConfig = &JComponentHelper::getParams( 'com_users' ); if ($usersConfig->get('allowUserRegistration') == '0') { if($params->get('overrideJallowUserRegistration', '0') != '1'){ JError::raiseError( 403, JText::_( 'Access Forbidden' )); return; } } // Initialize new usertype setting $newUsertype = $usersConfig->get( 'new_usertype' ); if ( !$newUsertype ) { $newUsertype = 'Registered'; } // execute Extra Code before if ( !empty($row->extra4) ) { eval( "?>".$row->extra4 ); } // Bind the post array to the user object $post = JRequest::get( 'post' ); $post['username'] = JRequest::getVar($params->get('username'), '', 'post', 'username'); $post['name'] = JRequest::getVar($params->get('name'), '', 'post', 'name'); $post['email'] = JRequest::getVar($params->get('email'), '', 'post', 'email'); if ( !$params->get('createpassword') ) { $post['password'] = JRequest::getVar($params->get('pass'), '', 'post', 'string'); $post['password2'] = JRequest::getVar($params->get('vpass'), '', 'post', 'string'); if ( $params->get('vpass') && $post['password'] != $post['password2'] ) { $MyPlugins->cf_joomla_registration['errors'] = JText::_('Passwords do not match'); $messages[] = JText::_('Passwords do not match'); if ( $params->get('showmessages') ) { //$mainframe->enqueuemessage(JText::_('Passwords do not match'), 'error'); $MyForm->addErrorMsg(JText::_('Passwords do not match')); } if ( $params->get('debugging') ) { $helper->showPluginDebugMessages($messages); } // remove the password values from display $post['password'] = $post[$params->get('pass')] = ''; $post['password2'] = $post[$params->get('vpass')] = ''; //$MyForm->showForm($MyForm->formrow->name, $post); return false; }else if(!trim($post['password']) && !trim($post['password'])){ $MyPlugins->cf_joomla_registration['errors'] = JText::_('Password required'); if ( $params->get('showmessages') ) { //$mainframe->enqueuemessage(JText::_('Passwords do not match'), 'error'); $MyForm->addErrorMsg(JText::_('Password required')); } return false; }else{ } } else { jimport('joomla.user.helper'); $post['password'] = $post['password2'] = JUserHelper::genRandomPassword(); } $messages[] = '$post: '.print_r($post, true); if ( !$user->bind( $post, 'usertype' ) ) { JError::raiseError( 500, $user->getError()); } // Set some initial user values $user->set('id', 0); $user->set('usertype', ''); $user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' )); // TODO: Should this be JDate? $user->set('registerDate', date('Y-m-d H:i:s')); // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if ( $useractivation ) { 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() ) { $MyPlugins->cf_joomla_registration['errors'] = JText::_( $user->getError()); $messages[] = JText::_( $user->getError()); if ( $params->get('showmessages') ) { //$mainframe->enqueuemessage(JText::_( $user->getError()), 'error'); $MyForm->addErrorMsg(JText::_( $user->getError())); } if ( $params->get('debugging') ) { $helper->showPluginDebugMessages($messages); } // remove the password values from display $post['password'] = $post[$params->get('pass')] = ''; $post['password2'] = $post[$params->get('vpass')] = ''; //$MyForm->showForm($MyForm->formrow->name, $post); return false; } $MyPlugins->cf_joomla_registration['user'] = $user; JRequest::setVar('cf_user_id', $user->id); // Send registration confirmation mail $password = JRequest::getString($params->get('pass'), '', 'post'); //Disallow control chars in the password $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); if ( substr($params->get('emailuser'), 0, 6) != "custom" ) { $this->_sendMail($user, $password, $params->get('emailuser'), $params->get('emailadmins')); } else { $MyForm =& CFChronoForm::getInstance($formname); $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id); $emailid = (int)str_replace("custom", "", $params->get('emailuser')); $MyFormEmails->emails[$emailid - 1]->enabled = 1; $MyFormEmails->emails[$emailid - 1]->template = str_replace("{vlink}", JURI::base()."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $MyFormEmails->emails[$emailid - 1]->template); $MyEmail = array($MyFormEmails->emails[$emailid - 1]); $MyFormEmails->sendEmails($MyForm, $MyEmail); } // Everything went fine, set relevant message depending upon user activation state and display message $MyPlugins->cf_joomla_registration['complete'] = true; if ( $params->get('joomlastatus') ) { if ( $useractivation ) { echo $message = JText::_( 'REG_COMPLETE_ACTIVATE' ); } else { if ( $params->get('autologin') ) { echo $message = JText::_( 'REG_COMPLETE' ); } } } if ( $params->get('autologin') ) { $credentials = array(); $credentials['username'] = $post['username']; $credentials['password'] = JRequest::getVar($params->get('pass'), '', 'post', 'string', JREQUEST_ALLOWRAW); $mainframe->login($credentials); } // execute Extra Code before if ( !empty($row->extra5) ) { eval( "?>".$row->extra5 ); } if ( $params->get('debugging') ) { $helper->showPluginDebugMessages($messages); } } function _sendMail(&$user, $password, $emailuser, $emailadmins) { global $mainframe; $db =& JFactory::getDBO(); $language =& JFactory::getLanguage(); $language->load('com_user'); $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(); $subject = sprintf ( JText::_( 'Account details for' ), $name, $sitename); $subject = html_entity_decode($subject, ENT_QUOTES); if ( $useractivation ){ $message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password); } else { $message = sprintf ( JText::_( 'SEND_MSG' ), $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; } if ( $emailuser == "Yes" ) { 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)&&($emailadmins == "Yes")) { $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 onload( $option, $row, $params, $html_string ) { global $mainframe; $user = JFactory::getUser(); $db =& JFactory::getDBO(); if ( ($user->id) && ($mainframe->isSite()) ) { $html_string = 'You can not re-register while you are already signed in'; } return $html_string ; } } ?>