Esempio n. 1
0
 /**
  * Displays the registration form
  *
  * @param	array 	$form_errors
  * @return	@e void
  */
 public function registerForm($form_errors = array())
 {
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $final_errors = array();
     $coppa = IPSCookie::get('coppa');
     $step = $this->request['step'] ? intval($this->request['step']) : 1;
     $this->settings['username_errormsg'] = str_replace('{chars}', $this->settings['username_characters'], $this->settings['username_errormsg']);
     if ($coppa == 'yes') {
         $this->registry->output->showError('awaiting_coppa', 10124);
     }
     $this->_resetMember();
     //-----------------------------------------
     // COPPA swapout
     //-----------------------------------------
     if ($this->settings['use_coppa']) {
         $this->lang->words['confirm_over_thirteen'] = str_replace("<#FORM_LINK#>", "{$this->settings['base_url']}app=core&amp;module=global&amp;section=register&amp;do=12", $this->lang->words['confirm_over_thirteen']);
     }
     //-----------------------------------------
     // T & C
     //-----------------------------------------
     $cache = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_sys_conf_settings', 'where' => "conf_key='reg_rules'"));
     $text = $cache['conf_value'] ? $cache['conf_value'] : $cache['conf_default'];
     IPSText::getTextClass('bbcode')->parse_smilies = 1;
     IPSText::getTextClass('bbcode')->parse_html = 1;
     IPSText::getTextClass('bbcode')->parse_nl2br = 1;
     IPSText::getTextClass('bbcode')->parse_bbcode = 1;
     IPSText::getTextClass('bbcode')->parsing_section = 'global';
     $this->settings['_termsAndConditions'] = IPSText::getTextClass('bbcode')->preDisplayParse($text);
     //-----------------------------------------
     // Page title / navigation
     //-----------------------------------------
     $this->registry->output->setTitle($this->lang->words['registration_form'] . ' - ' . ipsRegistry::$settings['board_name']);
     $this->registry->output->addNavigation($this->lang->words['registration_form'], '');
     //-----------------------------------------
     // If Nexus is installed, that is the first step
     //-----------------------------------------
     if (IPSLib::appIsInstalled('nexus') and $this->settings['nexus_reg_show'] and $this->settings['nexus_store_online']) {
         //-----------------------------------------
         // We just submitted the form
         //-----------------------------------------
         if ($this->request['nexus_pass']) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('nexus') . '/sources/hooks.php', 'nexusHooks', 'nexus');
             $hookGateway = new $classToLoad($this->registry);
             //-----------------------------------------
             // Check for errors
             //-----------------------------------------
             if ($this->settings['nexus_reg_force'] and !IPSCookie::get('cm_reg') and empty($this->request['cm_package'])) {
                 $nexusError = $this->lang->words['forceby_no_sel'];
             }
         }
         //-----------------------------------------
         // If no errors, create invoice and set cookie
         //-----------------------------------------
         if (!$nexusError and $this->request['nexus_pass']) {
             //-----------------------------------------
             // Did we buy a package?
             //-----------------------------------------
             $chosenPackages = ipsRegistry::$request['cm_package'];
             if (!empty($chosenPackages)) {
                 foreach ($chosenPackages as $itemID) {
                     require_once IPSLib::getAppDir('nexus') . '/sources/packageCore.php';
                     /*noLibHook*/
                     $package = package::load($itemID);
                     $shippingData = $package->shippingData();
                     $renewTerm = $package->renewalTerms();
                     $items[] = array('act' => 'new', 'app' => 'nexus', 'type' => $package->data['p_type'], 'cost' => $package->price($this->memberData['member_id'], FALSE), 'tax' => $package->data['p_tax'], 'renew_term' => $renewTerm['term'], 'renew_units' => $renewTerm['unit'], 'renew_cost' => $renewTerm['price'], 'physical' => is_null($shippingData) ? FALSE : TRUE, 'shipping' => is_null($shippingData) ? array() : $shippingData['shipping'], 'weight' => is_null($shippingData) ? 0 : $shippingData['weight'], 'itemName' => $package->data['p_name'], 'itemID' => $package->data['p_id'], 'groupRenewals' => $package->data['p_group_renewals'], 'methods' => $package->data['p_methods'] ? explode(',', $package->data['p_methods']) : array());
                 }
                 // Generate it
                 require_once IPSLib::getAppDir('nexus') . '/sources/nexusApi.php';
                 /*noLibHook*/
                 $invoiceID = nexusApi::generateInvoice(NULL, $this->memberData['member_id'], $items);
                 IPSCookie::set('cm_reg', $invoiceID);
             }
         } else {
             //-----------------------------------------
             // "step 1" if Nexus is set to show packages on registration
             //-----------------------------------------
             require_once IPSLib::getAppDir('nexus') . '/sources/packageCore.php';
             /*noLibHook*/
             $packages = array();
             $this->DB->build(array('select' => '*', 'from' => 'nexus_packages', 'where' => 'p_reg=1', 'order' => 'p_position'));
             $e = $this->DB->execute();
             while ($row = $this->DB->fetch($e)) {
                 $packages[$row['p_id']] = package::load($row['p_id'])->buildDisplayData();
             }
             if (!empty($packages)) {
                 if (isset($this->request['cm_package'])) {
                     foreach ($this->request['cm_package'] as $packageID) {
                         $packages[$packageID]['checked'] = "checked='checked'";
                     }
                 }
                 $this->output .= $this->registry->output->getTemplate('nexus_payments')->regForm32($packages, $nexusError);
                 return;
             } else {
                 $this->settings['nexus_reg_show'] = false;
             }
         }
     }
     //-----------------------------------------
     // Send to an alternate registration URL?
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'login_methods', 'where' => 'login_enabled=1'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         if ($r['login_register_url']) {
             $this->registry->output->silentRedirect($r['login_register_url']);
         }
     }
     //-----------------------------------------
     // Adjust text as needed based on validation type
     //-----------------------------------------
     if ($this->settings['reg_auth_type']) {
         if ($this->settings['reg_auth_type'] == 'admin_user' or $this->settings['reg_auth_type'] == 'user') {
             $this->lang->words['std_text'] .= "<br />" . $this->lang->words['email_validate_text'];
         }
         /* User then admin? */
         if ($this->settings['reg_auth_type'] == 'admin_user') {
             $this->lang->words['std_text'] .= "<br />" . $this->lang->words['user_admin_validation'];
         }
         if ($this->settings['reg_auth_type'] == 'admin') {
             $this->lang->words['std_text'] .= "<br />" . $this->lang->words['just_admin_validation'];
         }
     }
     //-----------------------------------------
     // Captcha / Q&A
     //-----------------------------------------
     $captchaHTML = '';
     $qandaHTML = '';
     $question = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'question_and_answer', 'order' => $this->DB->buildRandomOrder(), 'limit' => array(1)));
     if ($question and count($question)) {
         $qandaHTML = $this->registry->output->getTemplate('global_other')->questionAndAnswer($question);
     }
     if ($this->settings['bot_antispam_type'] != 'none') {
         $captchaHTML = $this->registry->getClass('class_captcha')->getTemplate();
     }
     //-----------------------------------------
     // Custom fields
     //-----------------------------------------
     $custom_fields_out = array('required', 'optional');
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $custom_fields = new $classToLoad();
     $custom_fields->member_data = $this->memberData;
     $custom_fields->initData('edit', 0, array('tabindex' => 6));
     $custom_fields->parseToEdit('register');
     if (count($custom_fields->out_fields)) {
         foreach ($custom_fields->out_fields as $id => $form_element) {
             if ($custom_fields->cache_data[$id]['pf_not_null'] == 1) {
                 $ftype = 'required';
             } else {
                 $ftype = 'optional';
             }
             $custom_fields_out[$ftype][] = array('name' => $custom_fields->field_names[$id], 'desc' => $custom_fields->field_desc[$id], 'field' => $form_element, 'id' => $id, 'error' => '', 'type' => $custom_fields->cache_data[$id]['pf_type']);
         }
     }
     //-----------------------------------------
     // If Nexus is installed, also add billing information
     //-----------------------------------------
     $nexusFields = array();
     $nexusStates = array();
     if (IPSLib::appIsInstalled('nexus') and $this->settings['nexus_reg_show'] and $this->settings['nexus_store_online']) {
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_countries'), 'nexus');
         $fields = array();
         $_fields = ipsRegistry::cache()->getCache('customer_fields');
         if (is_array($_fields) and count($_fields)) {
             foreach ($_fields['reg'] as $k) {
                 $nexusFields[] = $_fields['fields'][$k];
             }
         }
         $nexusStates = customer::generateStateDropdown(TRUE);
     }
     //-----------------------------------------
     // Got errors to show?
     //-----------------------------------------
     $final_errors = array('dname' => NULL, 'password' => NULL, 'email' => NULL, 'tos' => NULL);
     foreach (array('dname', 'password', 'email', 'tos') as $thing) {
         if (isset($form_errors[$thing]) and is_array($form_errors[$thing]) and count($form_errors[$thing])) {
             $final_errors[$thing] = implode("<br />", $form_errors[$thing]);
         }
     }
     $this->request['PassWord'] = $this->request['PassWord'] ? $this->request['PassWord'] : '';
     $this->request['EmailAddress'] = $this->request['EmailAddress'] ? $this->request['EmailAddress'] : '';
     $this->request['EmailAddress_two'] = $this->request['EmailAddress_two'] ? $this->request['EmailAddress_two'] : '';
     $this->request['PassWord_Check'] = $this->request['PassWord_Check'] ? $this->request['PassWord_Check'] : '';
     $this->request['members_display_name'] = $this->request['members_display_name'] ? $this->request['members_display_name'] : '';
     $this->request['time_offset'] = $this->request['time_offset'] ? $this->request['time_offset'] : '';
     //-----------------------------------------
     // Create time zone dropdown array
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_usercp'), 'core');
     $time_select = array();
     foreach ($this->lang->words as $k => $v) {
         if (strpos($k, "time_") === 0) {
             $k = str_replace("time_", '', $k);
             if (preg_match('/^[\\-\\d\\.]+$/', $k)) {
                 $time_select[$k] = $v;
             }
         }
     }
     ksort($time_select);
     $this->request['time_offset'] = $this->request['time_offset'] ? $this->request['time_offset'] : $this->settings['time_offset'];
     //-----------------------------------------
     // Start output
     //-----------------------------------------
     $this->output .= $this->registry->output->getTemplate('register')->registerForm($form_errors['general'], array('TEXT' => $this->lang->words['std_text'], 'coppa_user' => $coppa, 'captchaHTML' => $captchaHTML, 'qandaHTML' => $qandaHTML, 'showCOPPA' => $this->settings['use_coppa'] and !(IPSLib::appIsInstalled('nexus') and $this->settings['nexus_reg_show'] and $this->settings['nexus_store_online'])), $final_errors, $time_select, $custom_fields_out, $nexusFields, $nexusStates);
     //-----------------------------------------
     // Member sync module
     //-----------------------------------------
     IPSLib::runMemberSync('onRegisterForm');
 }