public function newUserAction() { /** * Check permission */ if (false == $this->checkPermission('new_user')) { $this->_forwardToNoPermissionPage(); return; } $data = $this->_getParam('data', false); $errors = array(); if (false !== $data) { /** * Insert new user */ $objUser = new Models_User(); $objUserExp = new Models_UserExpand(); $newUser = array('group_id' => $data['group_id'], 'username' => $data['username'], 'email' => $data['email'], 'full_name' => $data['full_name'], 'password' => $data['password'], 'repeat_password' => $data['repeat_password'], 'created_date' => time(), 'enabled' => $data['enabled']); $errors = $objUser->validate($newUser); if (true === $errors) { $newUser['password'] = md5($newUser['password']); /** * TODO Read date format from language table */ unset($newUser['repeat_password']); try { $id = $objUser->insert($newUser); $newUserExp = array('user_id' => $id, 'admin_note' => $data['admin_note']); $objUserExp->insert($newUserExp); $this->_redirect('user/admin/user-manager'); } catch (Exception $e) { $errors = array('main' => Vi_Language::translate('Can not insert into database now')); } } } /** * Prepare for template */ $this->view->errors = $errors; $this->view->data = $data; $this->view->headTitle(Vi_Language::translate('New user')); $this->view->menu = array('usergroup', 'newuser'); /** * Get all groups */ $objGroup = new Models_Group(); $this->view->allGroups = $objGroup->getAll(array('sorting ASC', 'group_id ASC'))->toArray(); // /** // * Get all countries // */ // $objCountry = new Models_Country(); // $this->view->allCountries = $objCountry->getAll(array('sorting ASC', 'country_id ASC'))->toArray(); }
public function restaurantRegisterAction() { /** * Get all provice CODE */ $objCountry = new Models_Country(); $this->view->allProvinces = $objCountry->getAllProvinces(); /** * Get some list */ $objCat = new Models_Category(); $this->view->leadTimeNormal = $objCat->getAllValues('lead_time_normal'); $this->view->leadTimeCatering = $objCat->getAllValues('lead_time_catering'); // echo '<pre>';print_r($this->view->allProvinces);die; /** * Get data */ $objRes = new Models_Restaurant(); $objUser = new Models_User(); $objUserExp = new Models_UserExpand(); /** * Clear all draft user */ $objUser->delete(array('is_draft=?' => 1, 'created_date<?' => time() - 24 * 3600)); $data = $this->_getParam('data', false); $user = $this->_getParam('user', false); $condition = $this->_getParam('condition', false); $error = ''; /** * Insert restaurant */ if ('1' == $condition && null != $this->session->newRes && is_array($this->session->newRes) && null != $this->session->newUserId) { /** * Insert restaurant */ $res = $this->session->newRes; $res['user_id'] = $this->session->newUserId; $objRes->insert($res); /** * Make real user */ $objUser->update(array('is_draft' => 0, 'enabled' => 1), array('user_id=?' => $this->session->newUserId)); /** * Send email */ $objUser = new Models_User(); $objMail = new Models_Mail(); $data = $this->session->newRes; unset($data['created_date']); $admin = $objUser->getByUserName('admin'); $objMail->sendHtmlMail('restaurant_register', $data, array($admin['email'], $data['owner_email'])); /** * Clear data */ $this->session->newRes = null; $this->session->newUserId = null; /** * Redirect to thankyou page */ $objContent = new Models_ScontentLang(); $this->_redirect($objContent->getUrlWithoutAppBaseUrl(20)); } /** * Check new account */ $errors = array(); if (false != $data && false != $user) { $newUser = array('group_id' => 2, 'username' => $user['username'], 'email' => $data['owner_email'], 'full_name' => $data['owner'], 'password' => $user['password'], 'repeat_password' => $user['retype_password'], 'company' => $data['name'], 'created_date' => time(), 'enabled' => 0, 'send_discount_code' => 0, 'is_draft' => 1, 'is_restaurant' => 1); $errors = $objUser->validate($newUser); if (true === $errors) { $newUser['password'] = md5($newUser['password']); /** * TODO Read date format from language table */ unset($newUser['repeat_password']); /** * Insert draft user */ $id = $objUser->insert($newUser); $newUserExp = array('user_id' => $id); $objUserExp->insert($newUserExp); $this->session->newUserId = $id; } else { /** * Error, display template */ $this->view->user = $user; $this->view->data = $data; $this->view->errors = $errors; $this->view->headTitle('Restaurant Owner Register'); $this->setLayout('front2'); return; } } if (false != $data) { /** * Insert new restaurant */ $newRes = $data; /** * Modify date */ $dateArr = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'); foreach ($dateArr as $item) { if ('1' != @$newRes["date_{$item}"]) { unset($newRes["date_{$item}_start"]); unset($newRes["date_{$item}_end"]); } else { /** * Change correct time */ if (null == @$newRes["date_{$item}_start"]) { $newRes["date_{$item}_start"] = '00:00'; //0 hours } else { $tmp = explode(':', $newRes["date_{$item}_start"]); /** * Hour */ if (null == @$tmp[0]) { $tmp[0] = 0; } $tmp[0] = '00' . abs(intval($tmp[0])); $tmp[0] = substr($tmp[0], -2, 2); if (23 < intval($tmp[0])) { $tmp[0] = '00'; } /** * Minute */ if (null == @$tmp[1]) { $tmp[1] = 0; } $tmp[1] = '00' . abs(intval($tmp[1])); $tmp[1] = substr($tmp[1], -2, 2); if (59 < intval($tmp[1])) { $tmp[1] = '00'; } $newRes["date_{$item}_start"] = $tmp[0] . ':' . $tmp[1]; } if (null == @$newRes["date_{$item}_end"]) { $newRes["date_{$item}_end"] = 24 * 3600 - 60; //23:59:59 hours } else { $tmp = explode(':', $newRes["date_{$item}_end"]); /** * Hour */ if (null == @$tmp[0]) { $tmp[0] = 23; } $tmp[0] = '00' . abs(intval($tmp[0])); $tmp[0] = substr($tmp[0], -2, 2); if (23 < intval($tmp[0])) { $tmp[0] = '23'; } /** * Minute */ if (null == @$tmp[1]) { $tmp[1] = 59; } $tmp[1] = '00' . abs(intval($tmp[1])); $tmp[1] = substr($tmp[1], -2, 2); if (59 < intval($tmp[1])) { $tmp[1] = '59'; } $newRes["date_{$item}_end"] = $tmp[0] . ':' . $tmp[1]; } } } /** * Modify data */ if ('1' != @$newRes['check']['pickup']) { unset($newRes['pickup']); } if ('1' != @$newRes['check']['curbside']) { unset($newRes['curbside']); } if ('1' != @$newRes['check']['delivery']) { unset($newRes['delivery']); unset($newRes['delivery_limit_hour']); unset($newRes['delivery_charge']); unset($newRes['delivery_minimum']); } if ('1' != @$newRes['check']['catering_pickup']) { unset($newRes['catering_pickup']); } if ('1' != @$newRes['check']['catering_delivery']) { unset($newRes['catering_delivery']); unset($newRes['catering_delivery_limit_hour']); unset($newRes['catering_delivery_charge']); unset($newRes['catering_delivery_minimum']); } /** * Remove tempory data */ unset($newRes['check']); $newRes['enabled'] = 0; $newRes['created_date'] = time(); // echo '<pre>';print_r($newRes);die; $this->session->newRes = $newRes; $this->_forward('restaurant-register2', 'index', 'user'); return; } $this->view->data = $data; $this->view->error = $error; $this->view->headTitle('Restaurant Owner Register'); $this->setLayout('front2'); }