/** Default Registration when modified is off */ function ym_register_default($user_id) { global $wpdb; if (!isset($_SESSION['error_on_page'])) { $pack_id = ym_get_default_pack(); if (!($user_pass = ym_post('ym_password'))) { $user_pass = substr(md5(uniqid(microtime())), 0, 7); } $user_pass_md5 = md5($user_pass); $wpdb->query("UPDATE {$wpdb->users} SET user_pass = '******' WHERE ID = '{$user_id}'"); wp_new_user_notification($user_id, $user_pass); // redirect to ym_subscribe $userdata = get_userdata($user_id); $redirect = add_query_arg(array('username' => $userdata->user_login, 'ym_subscribe' => 1), get_option('siteurl')); if ($redirector = ym_post('ym_redirector', ym_post('redirect_to'))) { $redirect = add_query_arg(array('redirector' => $redirector), $redirect); } $redirect = add_query_arg(array('pack_id' => $pack_id), $redirect); wp_redirect($redirect); exit; } }
function ym_register_form($return = false, $page = 1, $pack_id = false, $hide_custom_fields = false, $hide_further_pages = false, $autologin = false) { global $duration_str, $ym_sys, $ym_res; $html = ''; $fld_obj = get_option('ym_custom_fields'); $hide = $ym_sys->hide_custom_fields; $user_id = ym_get_user_id(); $hide_custom_fields = explode(',', $hide_custom_fields); if (!is_array($hide_custom_fields)) { $hide_custom_fields = array($hide_custom_fields); } $entries = $fld_obj->entries; $order = $fld_obj->order; if (empty($order)) { return; } if (strpos($order, ';') !== false) { $orders = explode(';', $order); } else { $orders = array($order); } $html .= '<div style="clear:both; height: 1px;"> </div>'; if ($redirect_to = ym_get('ym_redirector')) { $html .= '<input type="hidden" name="ym_redirector" value="' . urlencode($redirect_to) . '" />'; } if ($autologin) { $html .= '<input type="hidden" name="ym_autologin" value="1" />'; } $another_page = false; $lowest_page = ym_get_last_custom_field_page() + 1; //must be higher than the highest page $values = array(); if ($username = ym_get('username')) { $values = ym_get_custom_fields_by_username($username); } foreach ($orders as $order) { foreach ($entries as $entry) { if ($order == $entry['id']) { if (in_array($entry['id'], $hide_custom_fields)) { continue; } $entry['page'] = !isset($entry['page']) ? 1 : $entry['page']; if ($page == $entry['page']) { if (isset($_POST['hide_ym_field-' . $entry['id']])) { $entry['type'] = 'hidden'; //will hide the field if the appropriate post data is present. //This is intended to go with hard coded signups where the register page will act as stage 2 } $value = false; $row = ''; $hide_label = false; if (isset($values[$entry['id']])) { if (trim($values[$entry['id']])) { $value = trim($values[$entry['id']]); } } else { $value = ym_post('ym_field-' . $entry['id']); } if ($value) { $entry['value'] = $value; } if ($value = $entry['value']) { if (strpos($value, ':') !== false) { $array = explode(':', $value); if (count($array)) { switch ($array[0]) { case 'cookie': $entry['value'] = ym_cookie($array[1], ''); break; case 'session': $entry['value'] = ym_session($array[1], ''); break; case 'get': $entry['value'] = ym_get($array[1], ''); break; case 'post': $entry['value'] = ym_post($array[1], ''); break; case 'request': case 'qs': $entry['value'] = ym_request($array[1], ''); break; default: $entry['value'] = ''; break; } } } } if ($entry['name'] == 'terms_and_conditions' && !empty($ym_res->tos)) { $row .= '<p> <textarea name="tos" cols="29" rows="5" readonly="readonly">' . $ym_res->tos . '</textarea>'; $row .= '</p>'; $row .= '<p> <label class="ym_label" for="ym_tos"> <div><input type="checkbox" class="checkbox" name="ym_tos" id="ym_tos" value="1" /> ' . __('I agree to the Terms and Conditions.', 'ym') . '</div> </label> </p>' . "\n"; } else { if ($entry['name'] == 'subscription_introduction' && !empty($ym_res->subs_intro)) { $row .= '<div class="ym_subs_intro">' . $ym_res->subs_intro . '</div>'; } else { if ($entry['name'] == 'subscription_options') { // $pack_restriction = false; // if (strpos(',', $pack_id)) { // $pack_restriction = explode(',', $pack_id); // } if (ym_request('ym_subscription', $pack_id)) { // pre selected! // could be from a ym_register and the reg is hidden so showing the selector here is bad $row .= '<input type="hidden" name="ym_subscription" value="' . ym_request('ym_subscription', $pack_id) . '" />'; $hide_label = TRUE; } else { global $ym_packs; $packs = $ym_packs->packs; $active_modules = get_option('ym_modules'); if (empty($active_modules)) { $row .= '<p>' . __('There are no payment gateways active. Please contact the administrator.', 'ym') . '</p>'; } else { // RENDER $packs_shown = 0; if ($existing_data = ym_request('ym_subscription')) { $default = $existing_data; } else { $default = ym_get_default_pack(); } $did_checked = FALSE; foreach ($packs as $pack) { /* if (count($pack_restriction)) { // has restiction if (in_array($pack['id'], $pack_restriction)) { // do not show aka hide $pack['hide_subscription'] = 1; } } */ if (!$pack['hide_subscription']) { $row .= '<div class="ym_register_form_subs_row"> <div class="ym_reg_form_pack_radio"> <input type="radio" '; if ($pack['id'] == $default && !$did_checked) { $row .= 'checked="checked"'; $did_checked = TRUE; } $packs_shown++; $row .= ' class="checkbox" id="ym_subscription_' . $pack['id'] . '" name="ym_subscription" value="' . $pack['id'] . '" /> </div> <label for="ym_subscription_' . $pack['id'] . '" class="ym_subs_opt_label ym_reg_form_pack_name">' . ym_get_pack_label($pack['id']) . '</label> </div>'; } } if (!$packs_shown) { $hide_label = true; } else { if ($entry['caption']) { $row = '<div class="ym_clear"> </div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>' . $row; } } // END RENDER } } } else { if ($entry['name'] == 'birthdate' && !$hide) { $birthdate_fields = ym_birthdate_fields('ym_birthdate'); $row .= '<p>' . $birthdate_fields . '</p>'; } else { if ($entry['name'] == 'country' && !$hide) { $countries_sel = ym_countries_list('ym_country'); $row .= '<p>' . $countries_sel . '</p>'; } else { if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide) { $ro = $entry['readonly'] ? 'readonly="readonly"' : ''; if ($entry['type'] == 'text') { $fld = '<input type="text" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } else { if ($entry['type'] == 'hidden') { $fld = '<input type="hidden" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" />'; $hide_label = true; } else { if ($entry['type'] == 'yesno') { $fld = '<select class="ym_reg_select" name="ym_field-' . $entry['id'] . '" ' . $ro . '>'; $options = array('Yes', 'No'); foreach ($options as $option) { $fld .= '<option value="' . $option . '" ' . (trim($option) == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } $fld .= '</select>'; } else { if ($entry['type'] == 'password') { // primary use is ym_password if ($entry['name'] == 'ym_password') { $fld = '<input type="password" name="ym_password" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; ym_login_remove_password_string(); } else { // allow other password fields $fld = '<input type="password" name="' . $entry['name'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } } else { if ($entry['type'] == 'html') { $fld = '<div class="ym_reg_html">' . $entry['value'] . '</div>'; } else { if ($entry['type'] == 'textarea') { $fld = '<textarea class="ym_reg_textarea" name="ym_field-' . $entry['id'] . '" cols="29" rows="5" ' . $ro . '>' . $entry['value'] . '</textarea>'; } else { if ($entry['type'] == 'select') { $fld = '<select class="ym_reg_select" name="ym_field-' . $entry['id'] . '" ' . $ro . '>'; $options = explode(';', $entry['available_values']); foreach ($options as $option) { if (strpos($option, ':')) { list($option, $val) = explode(':', $option); $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $val . '</option>'; } else { $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } } $fld .= '</select>'; } else { if ($entry['type'] == 'multiselect') { $fld = '<select class="ym_reg_multiselect" name="ym_field-' . $entry['id'] . '[]" ' . $ro . ' multiple="multiple">'; $options = explode(';', $entry['available_values']); foreach ($options as $option) { if (strpos($option, ':')) { list($option, $val) = explode(':', $option); $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $val . '</option>'; } else { $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } } $fld .= '</select>'; } else { if ($entry['type'] == 'file') { $fld = '<input type="file" name="ym_field-' . $entry['id'] . '" />'; if ($entry['available_values'] == 'image') { $fld .= $entry['value']; } } else { if ($entry['type'] == 'callback') { $callback = 'ym_callback_custom_fields_' . $entry['name'] . '_editor'; if (function_exists($callback)) { $fld = $callback($entry['id']); } } else { if (!($fld = apply_filters('ym_generate_custom_field_type_' . $entry['type'], '', 'ym_field-' . $entry['id'], $entry, $value))) { $fld = '<input type="text" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } } } } } } } } } } } if ($entry['required']) { $fld .= '<div class="ym_clear"> </div><div class="ym_register_form_required">' . $ym_sys->required_custom_field_symbol . '</div>'; } if ($entry['caption']) { $fld .= '<div class="ym_clear"> </div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>'; } $row .= '<p>' . $fld . '</p>'; } } } } } } ////Adding of the row if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide && !$hide_label) { $html .= '<div class="ym_register_form_row" id="' . str_replace(' ', '_', $entry['name']) . '_row">'; $label = $entry['label']; $html .= '<label class="ym_label">' . $label . '</label>'; } $html .= $row; if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide && !$hide_label) { $html .= '<div class="ym_clear"> </div>'; $html .= '</div>'; } ////End adding of the row } if (!$hide_further_pages) { if ($entry['page'] > $page) { if ($entry['page'] < $lowest_page) { $lowest_page = $entry['page']; } $another_page = true; } } } } } $html .= '<input type="hidden" name="ym_page" value="' . $page . '" />'; //so that the update function knows which pages to validate if ($another_page) { $html .= '<input type="hidden" name="another_page_needed" value="' . $lowest_page . '" />'; //so that the rendering function knows to add another page before sending off to the gateway } if ($return) { return $html; } else { echo $html; } }