getPath( 'class', 'com_chronocontact' ) ); // the class name must be the same as the file name without the .php at the end class cf_cb_registration { //the next 3 fields must be defined for every plugin var $result_TITLE = "CB Registration"; var $result_TOOLTIP = "Synchronize the submitted data with this form with the default CB users table, please fill in the plugin config and assure the enabled field is marked then mark the checkbox here to get the plugin working!"; var $plugin_name = "cf_cb_registration"; // must be the same as the class name var $event = "ONSUBMIT"; // 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! // the next function must exist and will have the backend config code function show_conf($row, $id, $form_id, $option){ global $mainframe; $database =& JFactory::getDBO(); $database->setQuery( "SELECT * FROM #__comprofiler_fields WHERE `table`='#__comprofiler' AND name <>'NA' AND registration = '1'" ); $fields = $database->loadObjectList(); $paramsvalues = new JParameter($row->params); jimport('joomla.html.pane'); $pane =& JPane::getInstance('tabs'); ?>
startPane("cbregistration"); echo $pane->startPanel( 'General', "general7" ); ?> name; ?>
:
:
:
:
:
:
:
name." field" ); ?> name." Field"; ?>:
:
endPanel(); echo $pane->startPanel( "OnSubmit", 'onSubmit7' ); ?>
:
:
endPanel(); echo $pane->startPanel( "Plugin Keys", 'Legend4' ); ?>
: $MyPlugins->cf_cb_registration['user']
: $MyPlugins->cf_cb_registration['errors']
: $MyPlugins->cf_cb_registration['complete']
endPanel(); echo $pane->endPane(); ?>
bind( $post )) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } ///$params = mosGetParam( $_POST, 'params', '' ); $params = JRequest::getVar( 'params', '', 'post', 'array', array(0) ); if (is_array( $params )) { $txt = array(); foreach ( $params as $k=>$v) { $txt[] = "$k=$v"; } $row->params = implode( "\n", $txt ); } if (!$row->store()) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } $mainframe->redirect( "index2.php?option=".$option, "Config Saved" ); } function onsubmit( $option, $params, $row ) { global $mainframe; $database =& JFactory::getDBO(); // 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'); $MyForm =& CFChronoForm::getInstance(); $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id); /*********do the before onsubmit code**********/ if ( !empty($row->extra4) ) { eval( "?>".$row->extra4 ); } // If user registration is not allowed, show 403 not authorized. $usersConfig = &JComponentHelper::getParams( 'com_users' ); if ($usersConfig->get('allowUserRegistration') == '0') { JError::raiseError( 403, JText::_( 'Access Forbidden' )); return; } // Initialize new usertype setting $newUsertype = $usersConfig->get( 'new_usertype' ); if (!$newUsertype) { $newUsertype = 'Registered'; } // 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'); $post['password'] = JRequest::getVar($params->get('pass'), '', 'post', 'string', JREQUEST_ALLOWRAW); $post['password2'] = JRequest::getVar($params->get('vpass'), '', 'post', 'string', JREQUEST_ALLOWRAW); 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 == '1') { jimport('joomla.user.helper'); $user->set('activation', md5( 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())); $MyPlugins->cf_cb_registration['errors'] = JText::_( $user->getError()); return false; } $MyPlugins->cf_cb_registration['user'] = $user; JRequest::setVar('cf_user_id', $user->id); /********************CB part*************************/ $database->setQuery( "SELECT * FROM #__comprofiler_fields WHERE `table`='#__comprofiler' AND name <>'NA' AND registration = '1'" ); $fields = $database->loadObjectList(); $fields2 = array('id', 'user_id'); $fields3 = array(); foreach($fields as $field){ $fields2[] = $field->name; $fieldname = $field->name; $fields3[] = JRequest::getVar($params->get($fieldname), '', 'post', 'string');//mosGetParam($_POST, $params->get('$fieldname'), ''); } $database->setQuery( "INSERT INTO #__comprofiler (".implode(",",$fields2).") VALUES ('".$user->get('id')."','".$user->get('id')."','".implode("','",$fields3)."');" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); } /**********************************************/ // Send registration confirmation mail $password = JRequest::getString($params->get('pass'), '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email $this->_sendMail($user, $password, $params->get('emailuser'), $params->get('emailadmins')); // Everything went fine, set relevant message depending upon user activation state and display message $MyPlugins->cf_cb_registration['complete'] = true; if ( $useractivation == 1 ) { $message = JText::_( 'REG_COMPLETE_ACTIVATE' ); } else { $message = JText::_( 'REG_COMPLETE' ); } } 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 == 1 ){ $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); } } } } ?>