public function register() { $supply_address = 0; $saving_address = false; if (isset($_POST['submit'])) { $u = Model::load('UserItem'); $u->username = $_POST['username']; $u->email = $_POST['email']; $u->validates(); $p = Model::load('UserProfile'); $p->fullname = $_POST['fullname']; $p->validates(); $s = Model::load('ShippingAddress'); $supply_address = isset($_POST['supply_address']) && $_POST['supply_address'] == 1 ? 1 : 0; if ($supply_address == 1) { $saving_address = true; if ($p->fullname != '') { $fullname_arr = explode(' ', $p->fullname); if (sizeof($fullname_arr) > 1) { $s->last_name = $fullname_arr[sizeof($fullname_arr) - 1]; array_pop($fullname_arr); $s->first_name = implode(' ', $fullname_arr); } } $s->address1 = $_POST['address1']; $s->address2 = $_POST['address2']; $s->city = $_POST['city']; $s->state = $_POST['state']; $s->zip = strtoupper($_POST['zip']); $s->country = $_POST['country']; $s->default_address = 1; $s->validates(); } if ($u->hasValErrors() || $s->hasValErrors() || $p->hasValErrors()) { $this->presenter->assign('user', $u); $this->presenter->assign('address', $s); $this->presenter->assign('profile', $p); $this->presenter->assign('errors', array_merge($u->getValErrors(), $s->getValErrors(), $p->getValErrors())); } else { $password = exec(MAKEPASSWD . ' --chars=8'); $reg_code = exec(MAKEPASSWD . ' --chars=16'); $u->password = $password; $u->reg_code = md5($reg_code); $u->auth = 0; $u->active = 0; $u->registered = 'MYSQLTIME'; $u->popups = 'DEFAULT'; $u->user_profile_id = $p->insert(Model::getTable('UserProfile'), 1, array(), 0); $s->user_id = $u->insert(Model::getTable('UserItem'), 1, array(), 0); if ($saving_address) { $s->insert(Model::getTable('ShippingAddress'), 1, array(), 0); $v = Model::load('Vendor'); $v->user_id = $s->user_id; $v->insert(Model::getTable('Vendor'), 1, array(), 0); } $message = "\nHi ___,\n\n" . "Thanks for registering with " . ELIB_EMAIL_ORGANISATION . "\n\nBefore we can let you" . " know your password for using the site, please confirm your email address" . " by clicking the following link:\n\n" . "http://" . WEB_ROOT . PUBLIC_DIR . "/user/confirm_reg/?code=" . $reg_code . "\n\nCheers\n\n"; $r[0]['alias'] = $u->username; $r[0]['address'] = $u->email; $m = new Mailer($r, 'You have been registered with ' . ELIB_EMAIL_ORGANISATION, $message, ELIB_EMAIL_FROM); //$this->postRegister($s->user_id); $this->redirect('user/thanks/1'); } } $titles = array('Mr', 'Mrs', 'Miss', 'Ms', 'Dr'); $this->presenter->assign('titles', $titles); $countries = Country::build(); $this->presenter->assign('countries', $countries); $this->presenter->assign('sc', 'GB'); $this->assign('supply_address', $supply_address); $this->setTemplate('elib://register.tpl'); }
public function add_address() { $this->setTemplate('address.tpl'); $countries = Country::build(); $this->presenter->assign('countries', $countries); $this->presenter->assign('sc', 'GB'); if (isset($_POST['save'])) { $s = Model::load('ShippingAddress'); $s->user_id = CurrentUser::getUserID(); $s->first_name = $_POST['first_name']; $s->last_name = $_POST['last_name']; $s->address1 = $_POST['address1']; $s->address2 = $_POST['address2']; $s->city = $_POST['city']; $s->state = $_POST['state']; $s->zip = $_POST['zip']; $s->country = $_POST['country']; $s->validates(); if ($s->hasValErrors()) { $this->presenter->assign('address', $s); $this->presenter->assign('sc', $s->country); $this->presenter->assign('errors', $s->getValErrors()); } else { $s->insert(Model::getTable('ShippingAddress'), 1, array(), 0); $this->redirect('store/checkout'); } } }