public static function get_instance() { if (!isset(self::$instance)) { self::$instance = new Caching_SessionVarManager(); } return self::$instance; }
public function is_logged_in() { $svm = Caching_SessionVarManager::get_instance(); if ($svm->is_set('admin-login-data')) { $admin_login_data = $svm->get('admin-login-data'); return isset($admin_login_data['logged-in']) && $admin_login_data['logged-in']; } return FALSE; }
/** * @return * HTMLTags_SimpleOLForm * The form for editing the values of a user to be displayed in the * admin section. */ public function get_edit_user_form() { $user_row = $this->get_element(); $edit_user_form = new HTMLTags_SimpleOLForm('edit_user'); $redirect_script = Admin_AdminIncluderURLFactory::get_url('haddock', 'admin', 'manage-users', 'redirect-script'); $action_href = clone $redirect_script; $action_href->set_get_variable('edit-user'); $action_href->set_get_variable('user_id', $user_row->get_id()); $edit_user_form->set_action($action_href); $edit_user_form->set_legend_text('Update user'); /* * The user's name */ $svm = Caching_SessionVarManager::get_instance(); if ($svm->is_set('manage-users-form: name')) { $edit_user_form->add_input_name_with_value('name', $svm->get('manage-users-form: name')); } else { $edit_user_form->add_input_name_with_value('name', $user_row->get_name()); } /* * The type of admin user. */ $login_manager = Admin_LoginManager::get_instance(); $user_types = $login_manager->get_user_types(); $user_types_select = HTMLTags_SelectFactory::make_select_for_str_array($user_types); $user_types_select->set_attribute_str('id', 'type'); $user_types_select->set_attribute_str('name', 'type'); if ($svm->is_set('manage-users-form: type')) { $user_types_select->set_value($svm->get('manage-users-form: type')); } else { $user_types_select->set_value($user_row->get_type()); } $edit_user_form->add_input_tag('type', $user_types_select); /* * The user's real name */ if ($svm->is_set('manage-users-form: real_name')) { $edit_user_form->add_input_name_with_value('real_name', $svm->get('manage-users-form: real_name')); } else { $edit_user_form->add_input_name_with_value('real_name', $user_row->get_real_name()); } /* * The user's email */ if ($svm->is_set('manage-users-form: email')) { $edit_user_form->add_input_name_with_value('email', $svm->get('manage-users-form: email')); } else { $edit_user_form->add_input_name_with_value('email', $user_row->get_email()); } $edit_user_form->set_submit_text('Update'); $cancel_href = clone $redirect_script; $cancel_href->set_get_variable('cancel'); $edit_user_form->set_cancel_location($cancel_href); return $edit_user_form; }
<?php /** * The main section of the redirect-script for creating a new account * for a customer in the shop plug-in. * * @copyright Clear Line Web Design, 2007-09-23 */ #echo '__FILE__: ' . "\n"; #echo __FILE__ . "\n"; #exit; /* * Create the singleton objects. */ $svm = Caching_SessionVarManager::get_instance(); $page_manager = PublicHTML_PageManager::get_instance(); $log_in_manager = Shop_LogInManager::get_instance(); /* * If the user wants to create an account. */ if (isset($_GET['create_new_account'])) { /* * Check that we know where to go if something has gone * wrong. */ $form_location = new HTMLTags_URL(); if (isset($_GET['form_location'])) { $form_location->parse_url($_GET['form_location']); } elseif (isset($_SERVER['HTTP_REFERER'])) { $form_location->parse_url($_SERVER['HTTP_REFERER']); } else {
public function set_shipping_details_confirmation_answer($shipping_details_confirmation_answer) { $svm = Caching_SessionVarManager::get_instance(); return $svm->set('checkout-shipping-details-confirmation-answer', $shipping_details_confirmation_answer); }
public function get_password_reset_form(HTMLTags_URL $form_location, HTMLTags_URL $redirect_script_location, HTMLTags_URL $desired_location, HTMLTags_URL $cancel_page_location) { $password_reset_form = new HTMLTags_SimpleOLForm('create_new_account'); $password_reset_form->set_attribute_str('id', $this->get_password_reset_form_id()); $password_reset_form->set_attribute_str('class', $this->get_password_reset_form_css_class()); $svm = Caching_SessionVarManager::get_instance(); /* * The action. */ $password_reset_script_location = clone $redirect_script_location; $password_reset_script_location->set_get_variable('password_reset'); $password_reset_script_location->set_get_variable('desired_location', urlencode($desired_location->get_as_string())); $password_reset_script_location->set_get_variable('form_location', urlencode($form_location->get_as_string())); $password_reset_form->set_action($password_reset_script_location); $password_reset_form->set_legend_text('Reset Password'); /* * The input tags. */ if ($svm->is_set('password-reset: email')) { $password_reset_form->add_input_name_with_value('email', $svm->get('password-reset: email')); } else { if ($this->is_logged_in()) { $password_reset_form->add_input_name_with_value('email', $this->get_name()); } else { $password_reset_form->add_input_name('email'); } } /* * The submit button. */ $password_reset_form->set_submit_text('Reset'); /* * The cancel button */ $cancel_location = clone $redirect_script_location; $cancel_location->set_get_variable('cancel'); $cancel_location->set_get_variable('cancel_page_location', urlencode($cancel_page_location->get_as_string())); $password_reset_form->set_cancel_location($cancel_location); return $password_reset_form; }
public function get_row_adding_form(Database_Table $table, HTMLTags_URL $action_href, HTMLTags_URL $cancel_href) { $form = new HTMLTags_SimpleOLForm($this->get_row_adding_form_name()); $svm = Caching_SessionVarManager::get_instance(); $form->set_legend_text($this->get_row_adding_form_legend_text()); $form->set_action($action_href); $form->set_cancel_location($cancel_href); $form->set_cancel_text($this->get_cancel_link_text()); $field_names = $this->get_row_adding_form_field_names(); # print_r($field_names); exit; foreach ($field_names as $field_name) { # echo $field_name; exit; $input = $this->get_row_adding_form_field_input($field_name); # if ($svm->is_set("table-xml: $field_name")) { # $current_value = $svm->get("table-xml: $field_name"); # # # } else { # # } $form->add_input_tag($field_name, $input, $this->has_row_adding_form_field_label_text($field_name) ? $this->get_row_adding_form_field_label_text($field_name) : NULL); } $form->set_submit_text($this->get_row_adding_form_submit_text()); return $form; }
protected function do_actions() { $return_url = $this->get_failed_manage_user_return_url(); /* * Create the singleton objects. */ $svm = Caching_SessionVarManager::get_instance(); $login_manager = UserLogin_LoginManager::get_instance(); /* * ---------------------------------------- * Perform the actions. * ---------------------------------------- */ $_POST['type'] = 'User'; // faking this for now, might be useful later if (isset($_GET['add-new-user'])) { /* * Set the session vars for the form. */ $svm->set('manage-users-form: name', $_POST['name']); // $svm->set('manage-users-form: type', $_POST['type']); $svm->set('manage-users-form: real_name', $_POST['real_name']); $svm->set('manage-users-form: email', $_POST['email']); try { /* * Preliminary checks that the values are valid. */ if (isset($_GET['add-new-user']) && (!isset($_POST['name']) || strlen($_POST['name']) == 0)) { throw new InputValidation_InvalidInputException('The name for the user must be set!'); } if (isset($_GET['add-new-user'])) { if (!isset($_POST['password']) || strlen($_POST['password']) == 0) { throw new InputValidation_InvalidInputException('The password for the user must be set!'); } if (!isset($_POST['confirm_password']) || strlen($_POST['confirm_password']) == 0) { throw new InputValidation_InvalidInputException('Please confirm the password for the user.'); } if ($_POST['password'] != $_POST['confirm_password']) { throw new InputValidation_InvalidInputException('The passwords do not match!'); } } if (isset($_GET['add-new-user'])) { // if ( // !isset($_POST['type']) // || // (strlen($_POST['type']) == 0) // ) { // throw new InputValidation_InvalidInputException( // 'The type for the user must be set!' // ); // } if (!isset($_POST['real_name']) || strlen($_POST['real_name']) == 0) { throw new InputValidation_InvalidInputException('The real name of the user must be set!'); } if (!isset($_POST['email']) || strlen($_POST['email']) == 0) { throw new InputValidation_InvalidInputException('The email address of the user must be set!'); } } /* * Update the tables. */ if (isset($_GET['add-new-user'])) { $login_manager->add_new_user($_POST['name'], $_POST['password'], $_POST['type'], $_POST['real_name'], $_POST['email']); } $return_url = $this->get_successful_manage_user_return_url(); $exception_on_not_set = FALSE; $svm->delete('manage-users-form: name', $exception_on_not_set); $svm->delete('manage-users-form: email', $exception_on_not_set); $svm->delete('manage-users-form: type', $exception_on_not_set); $svm->delete('manage-users-form: real_name', $exception_on_not_set); } catch (InputValidation_InvalidInputException $e) { if (isset($_GET['add-new-user'])) { $return_url = $this->get_failed_add_user_return_url(); } $return_url->set_get_variable('error_message', urlencode($e->getMessage())); } } $this->set_return_to_url($return_url); }
public function get_customer_details_editing_form(HTMLTags_URL $form_location, HTMLTags_URL $redirect_script_location, HTMLTags_URL $desired_location, HTMLTags_URL $cancel_page_location) { $customer = $this->get_element(); $database = $customer->get_database(); $customers_table = $database->get_table('hpi_shop_customers'); $telephone_numbers_table = $database->get_table('hpi_shop_telephone_numbers'); $addresses_table = $database->get_table('hpi_shop_addresses'); $customer_details_form = new HTMLTags_SimpleOLForm('customer_details'); $customer_details_form->set_attribute_str('id', $this->get_customer_details_form_id()); $customer_details_form->set_attribute_str('class', $this->get_customer_details_form_css_class()); $svm = Caching_SessionVarManager::get_instance(); /* * The action. */ $customer_details_script_location = clone $redirect_script_location; $customer_details_script_location->set_get_variable('customer_details'); $customer_details_script_location->set_get_variable('desired_location', urlencode($desired_location->get_as_string())); $customer_details_script_location->set_get_variable('form_location', urlencode($form_location->get_as_string())); $customer_details_form->set_action($customer_details_script_location); $customer_details_form->set_legend_text($this->get_customer_details_form_legend_text()); /* * The input tags. */ /* * The first_name */ $first_name_field = $customers_table->get_field('first_name'); $first_name_field_renderer = $first_name_field->get_renderer(); $input_tag = $first_name_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'first_name'); $input_tag->set_attribute_str('value', $customer->get_first_name()); $customer_details_form->add_input_tag('first_name', $input_tag); /* * The last_name */ $last_name_field = $customers_table->get_field('last_name'); $last_name_field_renderer = $last_name_field->get_renderer(); $input_tag = $last_name_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'last_name'); $input_tag->set_attribute_str('value', $customer->get_last_name()); $customer_details_form->add_input_tag('last_name', $input_tag); /* * The telephone_number */ $telephone_number_field = $telephone_numbers_table->get_field('telephone_number'); $telephone_number_field_renderer = $telephone_number_field->get_renderer(); $input_tag = $telephone_number_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'telephone_number'); if ($customer->get_telephone_number_id() != 0) { $telephone_number = $customer->get_telephone_number(); $input_tag->set_attribute_str('value', $telephone_number->get_telephone_number()); } $customer_details_form->add_input_tag('telephone_number', $input_tag); // /* // * The address (to be put striaght into street_address) // */ // $address_li = $this->get_address_form_input_li(); // $customer_details_form->add_input_li($address_li); /* * The address_street_address */ $address_field = $addresses_table->get_field('street_address'); $address_field_renderer = $address_field->get_renderer(); $input_tag = $address_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'street_address'); if ($customer->get_address_id() != 0) { $address = $customer->get_address(); $input_tag->set_attribute_str('value', $address->get_street_address()); } $customer_details_form->add_input_tag('street_address', $input_tag); /* * The address_locality */ $address_field = $addresses_table->get_field('locality'); $address_field_renderer = $address_field->get_renderer(); $input_tag = $address_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'locality'); if ($customer->get_address_id() != 0) { $address = $customer->get_address(); $input_tag->set_attribute_str('value', $address->get_locality()); } $customer_details_form->add_input_tag('locality', $input_tag, 'City'); /* * The address_postal_code */ $address_field = $addresses_table->get_field('postal_code'); $address_field_renderer = $address_field->get_renderer(); $input_tag = $address_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'postal_code'); if ($customer->get_address_id() != 0) { $address = $customer->get_address(); $input_tag->set_attribute_str('value', $address->get_postal_code()); } $customer_details_form->add_input_tag('postal_code', $input_tag); /* * The address_country_name */ $address_field = $addresses_table->get_field('country_name'); $address_field_renderer = $address_field->get_renderer(); $input_tag = $address_field_renderer->get_form_input(); $input_tag->set_attribute_str('id', 'country_name'); if ($customer->get_address_id() != 0) { $address = $customer->get_address(); if ($address->get_country_name() != '') { $input_tag->set_value($address->get_country_name()); } } elseif (isset($_SESSION['customer_region_id'])) { $customer_regions_table = $database->get_table('hpi_shop_customer_regions'); $customer_region = $customer_regions_table->get_row_by_id($_SESSION['customer_region_id']); $input_tag->set_value($customer_region->get_name()); } $customer_details_form->add_input_tag('country_name', $input_tag); /* * The customer_region_id */ $customer_region_li = $this->get_customer_region_form_select_li(); $customer_details_form->add_input_li($customer_region_li); /* * The submit button. */ $customer_details_form->set_submit_text('Confirm'); /* * The cancel button */ $cancel_location = clone $redirect_script_location; $cancel_location->set_get_variable('cancel'); $cancel_location->set_get_variable('cancel_page_location', urlencode($cancel_page_location->get_as_string())); $customer_details_form->set_cancel_location($cancel_location); return $customer_details_form; }
protected function do_actions() { // print_r($_POST);exit; $return_url = $this->get_failed_manage_user_return_url(); /* * Create the singleton objects. */ $svm = Caching_SessionVarManager::get_instance(); $login_manager = UserLogin_LoginManager::get_instance(); /* * ---------------------------------------- * Perform the actions. * ---------------------------------------- */ $_POST['type'] = 'User'; // faking this for now, might be useful later if (isset($_GET['add-new-user']) || isset($_GET['edit-user']) || isset($_GET['change-password'])) { /* * Set the session vars for the form. */ $svm->set('manage-users-form: name', $_POST['name']); // $svm->set('manage-users-form: type', $_POST['type']); $svm->set('manage-users-form: real_name', $_POST['real_name']); $svm->set('manage-users-form: email', $_POST['email']); try { /** * First, the CAPTCHA, if it exists. * Only checking for reCAPTCHA for now */ if (isset($_POST["recaptcha_challenge_field"]) && isset($_POST["recaptcha_response_field"])) { // This will throw exception if bad Recaptcha_RecaptchaHelper::check_recaptcha_answer($_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); } /* * Preliminary checks that the values are valid. */ if ((isset($_GET['edit-user']) || isset($_GET['change-password'])) && (!isset($_GET['user_id']) || $_GET['user_id'] < 1)) { throw new InputValidation_InvalidInputException('The user\'s ID must be set!'); } if ((isset($_GET['add-new-user']) || isset($_GET['edit-user'])) && (!isset($_POST['name']) || strlen($_POST['name']) == 0)) { throw new InputValidation_InvalidInputException('The name for the user must be set!'); } if (isset($_GET['add-new-user']) || isset($_GET['change-password'])) { if (!isset($_POST['password']) || strlen($_POST['password']) == 0) { throw new InputValidation_InvalidInputException('The password for the user must be set!'); } if (!isset($_POST['confirm_password']) || strlen($_POST['confirm_password']) == 0) { throw new InputValidation_InvalidInputException('Please confirm the password for the user.'); } if ($_POST['password'] != $_POST['confirm_password']) { throw new InputValidation_InvalidInputException('The passwords do not match!'); } } if (isset($_GET['add-new-user']) || isset($_GET['edit-user'])) { // if ( // !isset($_POST['type']) // || // (strlen($_POST['type']) == 0) // ) { // throw new InputValidation_InvalidInputException( // 'The type for the user must be set!' // ); // } if (!isset($_POST['real_name']) || strlen($_POST['real_name']) == 0) { throw new InputValidation_InvalidInputException('The real name of the user must be set!'); } if (!isset($_POST['email']) || strlen($_POST['email']) == 0) { throw new InputValidation_InvalidInputException('The email address of the user must be set!'); } } /* * Update the tables. */ if (isset($_GET['edit-user'])) { $login_manager->update_user($_GET['user_id'], $_POST['name'], $_POST['type'], $_POST['real_name'], $_POST['email']); } if (isset($_GET['change-password'])) { $login_manager->update_password($_GET['user_id'], $_POST['password']); } $return_url = $this->get_successful_manage_user_return_url(); if (isset($_GET['add-new-user'])) { $login_manager->add_new_user($_POST['name'], $_POST['password'], $_POST['type'], $_POST['real_name'], $_POST['email']); $return_url = $this->get_successful_add_user_return_url(); } $exception_on_not_set = FALSE; $svm->delete('manage-users-form: name', $exception_on_not_set); $svm->delete('manage-users-form: email', $exception_on_not_set); $svm->delete('manage-users-form: type', $exception_on_not_set); $svm->delete('manage-users-form: real_name', $exception_on_not_set); $successful = TRUE; } catch (Exception $e) { if (isset($_GET['add-new-user'])) { $return_url = $this->get_failed_add_user_return_url(); } if (isset($_GET['edit-user'])) { $return_url = $this->get_failed_edit_user_return_url($_GET['user_id']); } $return_url->set_get_variable('error_message', urlencode($e->getMessage())); $successful = FALSE; } // And, Log in if ($successful) { $admin_login_manager = UserLogin_LoginManager::get_instance(); try { $admin_login_manager->log_in($_POST['name'], $_POST['password']); // unset($_SESSION['user-login-data']['error-message']); // if (isset($_SESSION['user-login-data']['desired-url'])) { // // print_r($_SESSION['user-login-data']['desired-url']);exit; // $return_url = $_SESSION['user-login-data']['desired-url']; // } } catch (HaddockProjectOrganisation_LoginException $e) { if (isset($_GET['add-new-user'])) { $return_url = $this->get_failed_add_user_return_url(); } if (isset($_GET['edit-user'])) { $return_url = $this->get_failed_edit_user_return_url($_GET['user_id']); } $return_url->set_get_variable('error_message', urlencode($e->getMessage())); } } } // print_r($return_url);exit; $this->set_return_to_url($return_url); }
public static function desired_restricted_page_url_is_set() { $svm = Caching_SessionVarManager::get_instance(); return $svm->is_set('desired_restricted_page_url'); }
public static function get_registration_div_with_extra_line($extra_li = NULL) { $div = new HTMLTags_Div(); $div->set_attribute_str('class', 'registration'); $svm = Caching_SessionVarManager::get_instance(); if ($svm->is_set('manage-users-form: name')) { $name = $svm->get('manage-users-form: name'); } if ($svm->is_set('manage-users-form: email')) { $email = $svm->get('manage-users-form: email'); } if ($svm->is_set('manage-users-form: real_name')) { $real_name = $svm->get('manage-users-form: real_name'); } // print_r($_SESSION);exit; $form = <<<HTML <form name = "registration" method = "POST" class = "basic-form" id = "registration-form" action = "/?oo-page=1&page-class=UserLogin_ManageUsersRedirectScript&add-new-user=1" > <fieldset> <legend>Register</legend> <ul> <li> <label for="email" >Email</label> <input type = "text" id = "email" name = "email" value = "{$email}" /> </li> <li> <label for="name" >Username</label> <input type = "text" id = "name" name = "name" value = "{$name}" /> </li> <li> <label for="real_name" >Real Name</label> <input type = "text" id = "real_name" name = "real_name" value = "{$real_name}" /> </li> <li> <label for="password" >Password</label> <input type = "password" id = "password" name = "password" /> </li> <li> <label for="confirm_password" >Repeat Password</label> <input type = "password" id = "confirm_password" name = "confirm_password" /> </li> HTML; if (!is_null($extra_li)) { $form .= "\n" . $extra_li . "\n"; } $form .= <<<HTML </ul> <div class="submit_buttons_div"> <input type = "submit" value = "Register" class = "submit" /> </div> </fieldset> </form> HTML; $div->append($form); return $div; }