예제 #1
0
 function runCode($type, $emailevent = '')
 {
     global $mainframe;
     $database =& JFactory::getDBO();
     $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
     //form instance
     $formname = CFChronoForm::getFormName($this->thisformid);
     $MyForm =& CFChronoForm::getInstance($formname);
     //emails instance
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     //run code
     if ($type == 'onsubmitcode') {
         if (!empty($MyForm->formrow->onsubmitcode)) {
             ob_start();
             eval("?>" . $MyForm->formrow->onsubmitcode);
             $onsubmitcode = ob_get_clean();
             foreach ($posted as $name => $post) {
                 if (is_array($post)) {
                     $post = implode(", ", $post);
                 }
                 $onsubmitcode = str_replace("{" . $name . "}", $post, $onsubmitcode);
             }
             echo $onsubmitcode;
         }
     }
     if ($type == 'onsubmitcodeb4') {
         if (!empty($MyForm->formrow->onsubmitcodeb4)) {
             eval("?>" . $MyForm->formrow->onsubmitcodeb4);
         }
     }
     if ($type == 'autogenerated') {
         if ($MyForm->formparams('savedataorder') == $emailevent) {
             if (!empty($MyForm->formrow->autogenerated)) {
                 eval("?>" . $MyForm->formrow->autogenerated);
             }
         }
     }
 }
 function onload($option, $row, $params, $html_string)
 {
     global $mainframe;
     $my = JFactory::getUser();
     $db =& JFactory::getDBO();
     $session =& JFactory::getSession();
     //get chrono instances
     $formname = JRequest::getVar('chronoformname');
     $MyForm =& CFChronoForm::getInstance($formname);
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id);
     $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
     $chrono_next_step = $session->get('chrono_next_step', '', md5('chrono'));
     if (JRequest::getVar('task') != 'beforeshow') {
         $session->set("chrono_next_step", '', md5('chrono'));
     }
     if ($chrono_next_step == 'confirm') {
         if (!JRequest::checkToken() && $MyForm->formparams('checkToken', 1)) {
             echo "You are not allowed to access this URL";
             return;
         }
         $html_string = '';
         $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
         if (JRequest::getVar('confirm') == trim($params->get('submit_button_value', 'Submit'))) {
             $debug = $MyForm->formparams('debug');
             //handle arrays
             $MyForm->handleArrays($MyForm->formrow->name);
             /**
              * If there are no errors and e-mail is required then build and send it.
              */
             if ($MyForm->formrow->emailresults != 0 && !$MyForm->error_found && !$MyForm->stoprunning) {
                 //run before submit code
                 if (!$MyForm->haltFunction["onsubmitcodeb4"]) {
                     $MyCustomCode->runCode('onsubmitcodeb4');
                     if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                         $MyForm->showForm($MyForm->formrow->name, $posted);
                         return;
                     }
                 }
                 if (!$MyForm->haltFunction["autogenerated_before_email"]) {
                     $MyCustomCode->runCode('autogenerated', 'before_email');
                 }
                 //send emails
                 if (!$MyForm->haltFunction["emails"]) {
                     $emails_result = $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
                 }
             }
             if (!$MyForm->error_found && !$MyForm->stoprunning) {
                 /*************** check to see if order was specified, if not then use the default old one ************************/
                 if (!$MyForm->formparams('plugins_order') && !$MyForm->formparams('onsubmitcode_order') && !$MyForm->formparams('autogenerated_order')) {
                     $MyForm->setFormParam('autogenerated_order', 3);
                     $MyForm->setFormParam('onsubmitcode_order', 2);
                     $MyForm->setFormParam('plugins_order', 1);
                 }
                 for ($ixx = 1; $ixx <= 3; $ixx++) {
                     if ($MyForm->formparams('plugins_order') == $ixx) {
                         if (!$MyForm->haltFunction["plugins_after_email"]) {
                             $MyPlugins->runPlugin('after_email');
                             //show errors if any
                             if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                                 $MyForm->showForm($MyForm->formrow->name, $posted);
                                 return;
                             }
                         }
                     }
                     /**
                      * Run the On-submit 'post e-mail' code if there is any
                      */
                     if ($MyForm->formparams('onsubmitcode_order') == $ixx) {
                         if (!$MyForm->haltFunction["onsubmitcode"]) {
                             $MyCustomCode->runCode('onsubmitcode');
                             if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                                 $MyForm->showForm($MyForm->formrow->name, $posted);
                                 return;
                             }
                         }
                     }
                     /**
                      * Run the SQL query if there is one
                      */
                     if ($MyForm->formparams('autogenerated_order') == $ixx) {
                         if (!$MyForm->haltFunction["autogenerated_after_email"]) {
                             $MyCustomCode->runCode('autogenerated', 'after_email');
                         }
                     }
                 }
                 //Mark submission as complete!
                 $MyForm->submission_complete = true;
                 $MyForm->addDebugMsg('Debug End');
                 /**
                  * Redirect the page if requested
                  */
                 if (!empty($MyForm->formrow->redirecturl)) {
                     if (!$debug) {
                         $mainframe->redirect($MyForm->formrow->redirecturl);
                     } else {
                         $MyForm->addDebugMsg("<div class='debug' >Redirect link set, click to test:<br /><a href='" . $MyForm->formrow->redirecturl . "'>" . $MyForm->formrow->redirecturl . "</a></div>");
                     }
                 }
             }
             if (!empty($MyForm->formdebug) && $MyForm->formparams('debug') == '1') {
                 include_once JPATH_COMPONENT . DS . 'libraries' . DS . 'includes' . DS . 'Debug.php';
             }
             $html_string = '';
         } else {
             $session->set("chrono_next_step", '', md5('chrono'));
             $MyForm->showForm($MyForm->formrow->name, $posted);
             $MyForm->stoploading = true;
             return;
             $html_string = '';
         }
     }
     return $html_string;
 }
 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 = false;
     //$usersConfig->get( 'new_usertype' );
     if (!$newUsertype) {
         if ($params->get('new_usertype', 'Registered')) {
             $newUsertype = $params->get('new_usertype', 'Registered');
         } else {
             $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);
     }
 }
예제 #4
0
 function submitForm($formname, $posted = array(), $useCurrent = false)
 {
     global $mainframe;
     $database =& JFactory::getDBO();
     if (empty($posted)) {
         $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
     }
     if ($useCurrent) {
         $MyForm = $this->getInstance($formname);
     } else {
         $MyForm =& CFChronoForm::getInstance($formname);
     }
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id);
     $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
     $MyForm->posted = $posted;
     $debug = $MyForm->formparams('debug');
     $MyForm->addDebugMsg('Form passed first SPAM check OK');
     $session =& JFactory::getSession();
     // Check how soon was the last submission
     $MyForm->checkSubmissionsLimit($MyForm->formrow->name);
     $MyForm->addDebugMsg('Form passed the submissions limit (if enabled) OK');
     /**
      * If imageversification is on check the code
      */
     $MyForm->checkImageVerification($MyForm->formrow->name);
     $MyForm->addDebugMsg('Form passed the Image verification (if enabled) OK');
     //Server side validation
     $MyForm->checkServerValidation($MyForm->formrow->name);
     $MyForm->addDebugMsg('Form passed the server side validation (if enabled) OK');
     //if any check steps failed, quit and reshow the form
     if ($MyForm->showFormErrors($MyForm->formrow->name)) {
         $MyForm->showForm($MyForm->formrow->name, $posted);
         return;
     }
     /**
      * if $debug is true then ChronoForms will show diagnostic output
      */
     $MyForm->addDebugMsg("\$_POST Array: " . print_r($posted, true));
     $MyForm->addDebugMsg("\$_FILES Array: " . print_r($_FILES, true));
     /**
      * Upload attachments
      */
     if (!$MyForm->haltFunction["uploads"]) {
         $MyUploads =& CFUploads::getInstance($MyForm->formrow->id);
         $MyUploads->handleUploads();
         //show errors if any
         if ($MyForm->showFormErrors($MyForm->formrow->name)) {
             $MyForm->showForm($MyForm->formrow->name, $posted);
             return;
         }
     }
     /* Do Onsubmit before_email plugins*/
     if (!$MyForm->haltFunction["plugins_before_email"]) {
         $MyPlugins->runPlugin('before_email');
         $MyForm->addDebugMsg('Form passed the plugins step (if enabled) OK');
         //show errors if any
         if ($MyForm->showFormErrors($MyForm->formrow->name)) {
             $MyForm->showForm($MyForm->formrow->name, $posted);
             return;
         }
     }
     //handle arrays
     $MyForm->handleArrays($MyForm->formrow->name);
     /**
      * If there are no errors and e-mail is required then build and send it.
      */
     if ($MyForm->formrow->emailresults && !$MyForm->error_found && !$MyForm->stoprunning) {
         //run before submit code
         if (!$MyForm->haltFunction["onsubmitcodeb4"]) {
             $MyCustomCode->runCode('onsubmitcodeb4');
             if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                 $MyForm->showForm($MyForm->formrow->name, $posted);
                 return;
             }
         }
         if (!$MyForm->haltFunction["autogenerated_before_email"]) {
             $MyCustomCode->runCode('autogenerated', 'before_email');
         }
         //send emails
         if (!$MyForm->haltFunction["emails"]) {
             $emails_result = $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
         }
     }
     if (!$MyForm->error_found && !$MyForm->stoprunning) {
         /*************** check to see if order was specified, if not then use the default old one ************************/
         if (!$MyForm->formparams('plugins_order') && !$MyForm->formparams('onsubmitcode_order') && !$MyForm->formparams('autogenerated_order')) {
             $MyForm->setFormParam('autogenerated_order', 3);
             $MyForm->setFormParam('onsubmitcode_order', 2);
             $MyForm->setFormParam('plugins_order', 1);
         }
         for ($ixx = 1; $ixx <= 3; $ixx++) {
             if ($MyForm->formparams('plugins_order') == $ixx) {
                 if (!$MyForm->haltFunction["plugins_after_email"]) {
                     $MyPlugins->runPlugin('after_email');
                     //show errors if any
                     if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                         $MyForm->showForm($MyForm->formrow->name, $posted);
                         return;
                     }
                 }
             }
             /**
              * Run the On-submit 'post e-mail' code if there is any
              */
             if ($MyForm->formparams('onsubmitcode_order') == $ixx) {
                 if (!$MyForm->haltFunction["onsubmitcode"]) {
                     $MyCustomCode->runCode('onsubmitcode');
                     if ($MyForm->showFormErrors($MyForm->formrow->name)) {
                         $MyForm->showForm($MyForm->formrow->name, $posted);
                         return;
                     }
                 }
             }
             /**
              * Run the SQL query if there is one
              */
             if ($MyForm->formparams('autogenerated_order') == $ixx) {
                 if (!$MyForm->haltFunction["autogenerated_after_email"]) {
                     $MyCustomCode->runCode('autogenerated', 'after_email');
                 }
             }
         }
         //Mark submission as complete!
         $MyForm->submission_complete = true;
         $MyForm->addDebugMsg('Debug End');
         /**
          * Redirect the page if requested
          */
         if (!empty($MyForm->formrow->redirecturl)) {
             if (!$debug) {
                 $mainframe->redirect($MyForm->formrow->redirecturl);
             } else {
                 $MyForm->addDebugMsg("<div class='debug' >Redirect link set, click to test:<br /><a href='" . $MyForm->formrow->redirecturl . "'>" . $MyForm->formrow->redirecturl . "</a></div>");
             }
         }
     }
     if (!empty($MyForm->formdebug) && $MyForm->formparams('debug') == '1') {
         include_once JPATH_COMPONENT . DS . 'libraries' . DS . 'includes' . DS . 'Debug.php';
     }
 }
예제 #5
0
 function onsubmit($option, $params, $row)
 {
     global $mainframe;
     $database =& JFactory::getDBO();
     $pluginrow = $row;
     $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
     $formname = JRequest::getVar('chronoformname');
     $MyForm =& CFChronoForm::getInstance($formname);
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id);
     //save the data
     $posted[$params->get('vflagfield')] = 0;
     if (!empty($MyForm->formrow->autogenerated)) {
         eval("?>" . $MyForm->formrow->autogenerated);
     }
     //run the onsubmit before verification code
     if (!empty($pluginrow->extra2)) {
         eval("?>" . $pluginrow->extra2);
     }
     //send the verification email
     if ($params->get('subject')) {
         $subject = $params->get('subject');
     } else {
         $subject = $posted[$params->get('dsubject')];
     }
     if ($params->get('to')) {
         $recipients = $params->get('to');
     } else {
         $recipients = $posted[$params->get('dto')];
     }
     if ($params->get('fromname')) {
         $fromname = $params->get('fromname');
     } else {
         $fromname = $posted[$params->get('dfromname')];
     }
     if ($params->get('fromemail')) {
         $fromemail = $params->get('fromemail');
     } else {
         $fromemail = $posted[$params->get('dfromemail')];
     }
     $email_body = $pluginrow->extra1;
     foreach ($posted as $key => $value) {
         $email_body = str_replace("{" . $key . "}", $value, $email_body);
     }
     //global ${'row_'.$params->get('vtablename')};
     $vlink = JURI::Base() . 'index.php?option=com_chronocontact&amp;chronoformname=' . $formname . '&amp;task=beforeshow&amp;uid=' . $MyForm->tablerow[$params->get('vtablename')]->uid;
     $vlink = '<a target="_blank" href="' . $vlink . '">' . $vlink . '</a>';
     $email_body = str_replace("{vlink}", $vlink, $email_body);
     //echo $email_body;
     JUtility::sendMail($fromemail, $fromname, $recipients, $subject, $email_body, true);
     //exit the form routine
     $MyForm->stoprunning = true;
     return;
 }