function runPlugin($emailevent, $events = array('ONSUBMIT', 'ONLOADONSUBMIT'), $pluginname = '', $pluginObject = array()) { global $mainframe; $database =& JFactory::getDBO(); $posted = JRequest::get('post', JREQUEST_ALLOWRAW); //form instance $formname = CFChronoForm::getFormName($this->thisformid); $MyForm =& CFChronoForm::getInstance($formname); $qouted_events = array(); foreach ($events as $event) { $qouted_events[] = $database->Quote($event); } $pluginevent = implode(",", $qouted_events); //emails instance $ava_plugins = explode(",", $MyForm->formparams('plugins')); $ava_plugins_order = explode(",", $MyForm->formparams('mplugins_order')); array_multisort($ava_plugins_order, $ava_plugins); //if a plugin name is specified then execute it only if ($pluginname) { $ava_plugins = explode(",", $pluginname); } foreach ($ava_plugins as $ava_plugin) { $query = "SELECT * FROM `#__chrono_contact_plugins` WHERE `form_id` = '" . $MyForm->formrow->id . "' AND event IN (" . $pluginevent . ") AND `name` = '" . $ava_plugin . "'"; $database->setQuery($query); $plugins = $database->loadObjectList(); if (is_object($pluginObject)) { $plugins[0] = $pluginObject; } if (count($plugins)) { require_once JPATH_SITE . "/components/com_chronocontact/plugins/" . $ava_plugin . ".php"; ${$ava_plugin} = new $ava_plugin(); $params = new JParameter($plugins[0]->params); $methods = get_class_methods(${$ava_plugin}); if (in_array('onsubmit', $methods) && in_array('ONSUBMIT', $events) && in_array('ONLOADONSUBMIT', $events) && $emailevent) { if ($params->get('onsubmit') == $emailevent) { ${$ava_plugin}->onsubmit('com_chronocontact', $params, $plugins[0]); } } if (in_array('onload', $methods) && in_array('ONLOAD', $events) && in_array('ONLOADONSUBMIT', $events) && !$emailevent) { $MyForm->formrow->html = ${$ava_plugin}->onload('com_chronocontact', $plugins[0], $params, $MyForm->formrow->html); } } //check for any errors reported by current plugin and halt the loop if ($MyForm->formerrors) { break; } } }
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 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); } }
function handleUploads($posted = array()) { global $mainframe; $database =& JFactory::getDBO(); if (empty($posted)) { $posted = JRequest::get('post', JREQUEST_ALLOWRAW); } //form instance //$MyForm =& CFChronoForm::getInstance(); $formname = CFChronoForm::getFormName($this->thisformid); $MyForm =& CFChronoForm::getInstance($formname); $attachments = array(); if (is_array($MyForm->formparams('uploadfields'))) { $MyForm->setFormParam('uploadfields', implode('|', $MyForm->formparams('uploadfields'))); } else { $MyForm->setFormParam('uploadfields', $MyForm->formparams('uploadfields')); } if (trim($MyForm->formparams('uploads') == 'Yes') && trim($MyForm->formparams('uploadfields'))) { jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); if (!JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_chronocontact' . DS . 'uploads' . DS . $MyForm->formrow->name . DS . 'index.html')) { if (!JFolder::create($MyForm->formparams('uploadpath', JPATH_SITE . DS . 'components' . DS . 'com_chronocontact' . DS . 'uploads' . DS . $MyForm->formrow->name))) { JError::raiseWarning(100, 'Couldn\'t create upload directroy 1'); } if (!JFile::write($MyForm->formparams('uploadpath', JPATH_SITE . DS . 'components' . DS . 'com_chronocontact' . DS . 'uploads' . DS . $MyForm->formrow->name) . DS . 'index.html', 'NULL')) { JError::raiseWarning(100, 'Couldn\'t create upload directroy 2'); } } $allowed_s1 = explode(",", trim($MyForm->formparams('uploadfields'))); foreach ($allowed_s1 as $allowed_1) { $allowed_s2 = explode(":", trim($allowed_1)); $allowed_s3 = explode("|", trim($allowed_s2[1])); $allowed_s4 = explode("{", trim($allowed_s3[count($allowed_s3) - 1])); $allowed_s3[count($allowed_s3) - 1] = $allowed_s4[0]; $allowed_s5 = explode("-", str_replace('}', '', trim($allowed_s4[1]))); $chronofile = JRequest::getVar($allowed_s2[0], array("error" => 4), 'files', 'array'); if ($chronofile["error"] == 0) { if ($chronofile['error']) { $MyForm->addDebugMsg('PHP returned this error for file upload by : ' . $allowed_s2[0] . ', PHP error is: ' . $chronofile['error']); } else { $MyForm->addDebugMsg('Upload routine started for file upload by : ' . $allowed_s2[0]); } $chronofile['name'] = JFile::makeSafe($chronofile['name']); $original_name = $chronofile['tmp_name']; ob_start(); eval($MyForm->formparams('filename_format', "\$filename = date('YmdHis').'_'.\$chronofile['name'];")); $ignorethis = ob_get_clean(); //$filename = date('YmdHis').'_'.$chronofile['name']; $fileok = true; $posted[$allowed_s2[0]] = ' NOFILE '; JRequest::setVar($allowed_s2[0], ' NOFILE '); if ($chronofile['error'] == 1) { $fileok = false; $MyForm->addErrorMsg($MyForm->formparams('upload_exceedslimit', 'Sorry, Your uploaded file size exceeds the allowed limit.')); } if ($original_name) { if ($chronofile["size"] / 1024 > trim($allowed_s5[0])) { $fileok = false; $MyForm->addErrorMsg($MyForm->formparams('upload_exceedslimit', 'Sorry, Your uploaded file size exceeds the allowed limit.')); } if ($chronofile["size"] / 1024 < trim($allowed_s5[1])) { $fileok = false; $MyForm->addErrorMsg($MyForm->formparams('upload_lesslimit', 'Sorry, Your uploaded file size is less than the allowed limit')); } $fn = $chronofile['name']; $fext = substr($fn, strrpos($fn, '.') + 1); if (!in_array(strtolower($fext), $allowed_s3)) { $fileok = false; $MyForm->addErrorMsg($MyForm->formparams('upload_notallowed', 'Sorry, Your uploaded file type is not allowed')); } if ($fileok) { $uploadpath = $MyForm->formparams('uploadpath', JPATH_SITE . DS . 'components' . DS . 'com_chronocontact' . DS . 'uploads' . DS . $MyForm->formrow->name . DS); $uploadedfile = JFile::upload($original_name, $uploadpath . $filename); $posted[$allowed_s2[0]] = $filename; JRequest::setVar($allowed_s2[0], $filename); if ($uploadedfile) { $attachments[$allowed_s2[0]] = $uploadpath . $filename; $MyForm->addDebugMsg($uploadpath . $filename . ' has been uploaded OK'); } else { $MyForm->addDebugMsg($uploadpath . $filename . ' has NOT been uploaded!!'); } } } } } $this->attachments = $attachments; } return $posted; }
function onsubmit($option, $params, $row) { global $mainframe; //echo "XXX"; require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_chronocontact' . DS . 'helpers' . DS . 'plugin.php'; $helper = new ChronoContactHelperPlugin(); if ($row->form_id) { $formname = CFChronoForm::getFormName($row->form_id); } else { $formname = JRequest::getVar('chronoformname'); } $MyForm =& CFChronoForm::getInstance($formname); $MyUploads =& CFUploads::getInstance($MyForm->formrow->id); $session =& JFactory::getSession(); $pluginrow = $row; $newposted = JRequest::get('post', JREQUEST_ALLOWRAW); $oldposted = array(); if ($session->get('chrono_formpages_data_' . $formname, array(), md5('chrono'))) { $oldposted = $session->get('chrono_formpages_data_' . $formname, array(), md5('chrono')); } if ($session->get('chrono_formpages_files_' . $formname, array(), md5('chrono'))) { $MyUploads->attachments = $session->get('chrono_formpages_files_' . $formname, array(), md5('chrono')); } $posted = array_merge($oldposted, $newposted); $messages[] = 'Posted: ' . print_r($posted, true); $messages[] = 'Files: ' . print_r($MyUploads->attachments, true); JRequest::set($posted, 'post'); $session->set('chrono_formpages_data_' . $formname, $posted, md5('chrono')); $pages = explode(",", $params->get('formsnames')); $current_step = $session->get('chrono_step_' . $formname, '', md5('chrono')); $messages[] = 'Current step: ' . print_r($current_step, true); if ($params->get('debugging')) { $helper->showPluginDebugMessages($messages); } if (JRequest::getVar($params->get('finalbuttonname'))) { $current_step = 'end'; } if ($current_step != 'end') { if ($current_step) { $newForm =& CFChronoForm::getInstance(trim($pages[$current_step - 1])); $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name); $newForm->formrow->html = $newForm->formrow->html . '<input type="hidden" name="cfformstep" value="' . $current_step . '" />'; $newForm->submitForm($newForm->formrow->name, $posted); $newUploads =& CFUploads::getInstance($newForm->formrow->id); $MyUploads->attachments = array_merge($MyUploads->attachments, $newUploads->attachments); $session->set('chrono_formpages_files_' . $formname, $MyUploads->attachments, md5('chrono')); //check if the previous form submission completed successfully if ($newForm->submission_complete) { if ($current_step == (int) $params->get('stepscount')) { $session->set('chrono_step_' . $formname, 'end', md5('chrono')); //$MyForm->submitForm($MyForm->formrow->name); return; } $nextForm =& CFChronoForm::getInstance(trim($pages[$current_step])); $nextForm->formrow->submiturl = $nextForm->getAction($MyForm->formrow->name); $nextForm->formrow->html = $nextForm->formrow->html . '<input type="hidden" name="cfformstep" value="' . $current_step . '" />'; $session->set('chrono_step_' . $formname, $current_step + 1, md5('chrono')); $nextForm->showForm($nextForm->formrow->name, $posted); } } else { $newForm =& CFChronoForm::getInstance(trim($pages[0])); $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name); $session->set('chrono_step_' . $formname, 1, md5('chrono')); $newForm->showForm($newForm->formrow->name, $posted); } //exit the form routine $MyForm->stoprunning = true; return; } }