/** * returns the current user used when navidating the site, not the current loged user! * @return Model_User */ public static function current() { //we don't have so let's retrieve if (self::$_current === NULL and Request::current()->param('seoname') != NULL and strtolower(Request::current()->action()) == 'profile' and strtolower(Request::current()->controller()) == 'user') { self::$_current = new self(); self::$_current = self::$_current->where('seoname', '=', Request::current()->param('seoname'))->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->cached()->find(); } return self::$_current; }
/** * Handle GET requests. */ public function action_index() { try { if (is_numeric($this->request->param('id'))) { $this->action_get(); } else { $output = array(); $users = new Model_User(); $users->where('status', '=', Model_User::STATUS_ACTIVE); //filter results by param, verify field exists and has a value and sort the results $users->api_filter($this->_filter_params)->api_sort($this->_sort); //how many? used in header X-Total-Count $count = $users->count_all(); //pagination with headers $pagination = $users->api_pagination($count, $this->_params['items_per_page']); $users = $users->cached()->find_all(); //as array foreach ($users as $user) { $output[] = self::get_user_array($user); } $this->rest_output(array('users' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
public function action_profile() { $this->auto_render = FALSE; $xml = 'FALSE'; $seoname = $this->request->param('seoname', NULL); if ($seoname !== NULL) { $user = new Model_User(); $user->where('seoname', '=', $seoname)->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->cached()->find(); if ($user->loaded()) { $info = array('title' => 'RSS ' . $user->name, 'pubDate' => date("r"), 'description' => $user->name . ' - ' . $user->description, 'generator' => 'Open Classifieds'); $items = array(); //last ads, you can modify this value at: advertisement.feed_elements $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('id_user', '=', $user->id_user)->order_by('published', 'desc')->limit(Core::config('advertisement.feed_elements')); $ads = $ads->cached()->find_all(); foreach ($ads as $a) { $url = Route::url('ad', array('category' => $a->category->seoname, 'seotitle' => $a->seotitle)); $item = array('title' => htmlspecialchars($a->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($a->published), 'description' => htmlspecialchars(Text::removebbcode($a->description), ENT_QUOTES), 'guid' => $url); if ($a->get_first_image() !== NULL) { $item['description'] = '<img src="' . $a->get_first_image() . '" />' . $item['description']; } $items[] = $item; } $xml = Feed::create($info, $items); } } $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('User Profile'))); $seoname = $this->request->param('seoname', NULL); if ($seoname !== NULL) { $user = new Model_User(); $user->where('seoname', '=', $seoname)->limit(1)->cached()->find(); if ($user->loaded()) { $this->template->title = __('User Profile') . ' - ' . $user->name; //$this->template->meta_description = $user->name;//@todo phpseo $this->template->bind('content', $content); $ads = new Model_Ad(); $ads = $ads->where('id_user', '=', $user->id_user)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->order_by('created', 'desc')->cached()->find_all(); // case when user dont have any ads if ($ads->count() == 0) { $profile_ads = NULL; } $this->template->content = View::factory('pages/userprofile', array('user' => $user, 'profile_ads' => $ads)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }
public function before() { $config = Kohana::$config->load('common'); $this->template = $config->template_name; parent::before(); if (Auth::instance()->logged_in()) { $user = new Model_User(); $this->template->topbar = View::factory('profile/topbar')->set('users', $user->where('id', '=', Auth::instance()->get_user()->pk())->find())->set('users_levels', $user->get_level(Auth::instance()->get_user()->pk())); } else { $this->template->topbar = View::factory('login'); } $this->template->stylesheets = $config->stylesheets; $this->template->site_name = $config->site_name; if (Auth::instance()->logged_in()) { $user_id = Auth::instance()->get_user()->pk(); $roles = ORM::factory('Roles_User')->get_last_role_id($user_id); foreach ($roles as $role) { if ($role->role_id == 1) { if ($this->request->directory() == 'dashboard') { $this->request->redirect(''); } if ($this->request->uri() == 'dashboard') { $this->request->redirect(''); } } } } else { if ($this->request->directory() == 'dashboard') { $this->request->redirect(''); } if ($this->request->uri() == 'dashboard') { $this->request->redirect(''); } } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/users/online.plug.html'; $data = $data->fork(); $users = new Model_User(); $users->where('DATE_ADD(lastrequest, INTERVAL 30 MINUTE) > NOW()'); $data->set('usersonline', $users->getTotal()); parent::output($data, $stream); }
public function registerAction() { if ($this->oAuth->isLoggedIn()) { $this->redirect('/'); return; } $this->mTemplate->title = $this->getLang('title_registration'); $this->mTemplate->sSectionTitle = $this->getLang('title_registration'); $sUser = $this->post('user_name'); $sPass = $this->post('user_pass'); $sEmail = $this->post('user_email'); $sAccount_name = $this->post('account_name'); $oValidator = new Module_Validator(); $oValidator->field('nick', $sUser, $this->getLang('user.nick'))->rules('required'); $oValidator->field('password', $sPass, $this->getLang('user.password'))->rules('required|md5'); $oValidator->field('email', $sEmail, $this->getLang('user.email'))->rules('required|email'); $oValidator->field('account_name', $sAccount_name, $this->getLang('user.account_name'))->rules('required'); if (isset($_POST['submit'])) { if ($oValidator->validate()) { // sprawdzamy czy nie ma juz takiego konta lub usera $oUser = new Model_User(); $aRes = $oUser->where('email', $sEmail)->getRow(); if (empty($aRes)) { $oUser->reset(); $oAccount = new Model_Account(); $oAccount->name = $sAccount_name; if ($iAccountId = $oAccount->save()) { $oUser->name = $sUser; $oUser->email = $sEmail; $oUser->password = $sPass; $oUser->role_id = 1; $oUser->account_id = $iAccountId; if ($oUser->save()) { $this->redirect('/user/login/'); } else { $error = $this->getLang('failed_creating_user'); } } else { $error = $this->getLang('failed_creating_account'); } } else { $error = $this->getLang('user_already_exists'); } } else { $error = 'Blad danych wejsciowych.'; $aErrors = $oValidator->getError(); foreach ($aErrors as $sField => $aError) { $error .= '<br />' . $this->getLang($aError['msg'], $aError['field_name']); } } } // generate form $aData = array('label_user' => $this->getLang('user.nick'), 'label_pass' => $this->getLang('user.password'), 'label_email' => $this->getLang('user.email'), 'label_accountname' => $this->getLang('user.account_name'), 'user_name' => $sUser, 'user_pass' => '', 'user_email' => $sEmail, 'account_name' => $sAccount_name, 'submit' => $this->getLang('user.register'), 'error' => isset($error) ? $error : null); $this->mTemplate->content = View::factory('user/registration_form', $aData)->render(); }
public function action_index() { //template header $this->template->title = __('Black list'); $this->template->meta_description = __('Black list'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List'))); //find all tables $user = new Model_User(); $black_list = $user->where('status', '=', Model_User::STATUS_SPAM)->order_by('id_user')->find_all(); $this->template->content = View::factory('oc-panel/pages/black_list', array('black_list' => $black_list)); }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Newsletter'))); $this->template->title = __('Newsletter'); //count all users $user = new Model_User(); $user->where('status', '=', Model_User::STATUS_ACTIVE); $count_all_users = $user->count_all(); //count support expired $query = DB::select(DB::expr('COUNT(id_order) count'))->from('orders')->where('status', '=', Model_Order::STATUS_PAID)->where('support_date', '<', Date::unix2mysql())->execute(); $count_support_expired = $query->as_array(); $count_support_expired = $count_support_expired[0]['count']; //count license expired $query = DB::select(DB::expr('COUNT(id_license) count'))->from('licenses')->where('valid_date', 'IS NOT', NULL)->where('valid_date', '<', Date::unix2mysql())->execute(); $count_license_expired = $query->as_array(); $count_license_expired = $count_license_expired[0]['count']; //orders per product, not accuarate since 1 user could buy more than 1 product but will do $query = DB::select(DB::expr('COUNT(id_order) count'))->select('p.title')->select('p.id_product')->from(array('products', 'p'))->join(array('orders', 'o'))->using('id_product')->where('o.status', '=', Model_Order::STATUS_PAID)->group_by('p.id_product')->execute(); $products = $query->as_array(); //post done sending newsletter if ($this->request->post() and Core::post('subject') != NULL) { $users = array(); if (core::post('send_all') == 'on') { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->execute(); $users = array_merge($users, $query->as_array()); } if (Theme::get('premium') == 1) { if (core::post('send_expired_support') == 'on') { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'))->using('id_user')->where('o.status', '=', Model_Order::STATUS_PAID)->where('o.support_date', '<', Date::unix2mysql())->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_expired_license') == 'on') { $query = DB::select('email')->select('name')->from(array('licenses', 'l'))->join(array('users', 'u'))->using('id_user')->where('l.valid_date', 'IS NOT', NULL)->where('l.valid_date', '<', Date::unix2mysql())->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (is_numeric(core::post('send_product'))) { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'))->using('id_user')->where('o.id_product', '=', core::post('send_product'))->where('o.status', '=', Model_Order::STATUS_PAID)->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } } //NOTE $users may have duplicated emails, but phpmailer takes care of not sending the email 2 times to same recipient //sending! if (count($users) > 0) { if (!Email::send($users, '', Core::post('subject'), Kohana::$_POST_ORIG['description'], Core::post('from'), Core::post('from_email'))) { Alert::set(Alert::ERROR, __('Error on mail delivery, not sent')); } else { Alert::set(Alert::SUCCESS, __('Email sent')); } } else { Alert::set(Alert::ERROR, __('Mail not sent')); } } $this->template->content = View::factory('oc-panel/pages/newsletter', array('count_all_users' => $count_all_users, 'count_support_expired' => $count_support_expired, 'count_license_expired' => $count_license_expired, 'products' => $products)); }
public function action_index() { $email = Core::post('email_subscribe'); if (Valid::email($email, TRUE)) { /* find user and compare emails */ $obj_user = new Model_User(); $user = $obj_user->where('email', '=', $email)->limit(1)->find(); // case when user is not logged in. // We create new user if he doesn't exists in DB // and send him mail for ad created + new profile created if (!$user->loaded()) { $user = Model_User::create_email($email); } /* save this user to data base as subscriber */ $arr_cat = Core::post('category_subscribe'); // string in this case is returned as "int,int" so we need to format min/max price $price = Core::post('price_subscribe'); if ($price = Core::post('price_subscribe')) { $min_price = substr($price, '0', stripos($price, ',')); $max_price = substr($price, strrpos($price, ',') + 1); } else { //in case of mobile version // jquery mobile have different slider, so we need to get data differently $min_price = Core::post('price_subscribe-1'); $max_price = Core::post('price_subscribe-2'); } //if categry is not selected, subscribe them for al, set category to 0 thats all... if ($arr_cat === NULL) { $arr_cat[] = 0; } // create entry table subscriber for each category selected foreach ($arr_cat as $c => $id_value) { $obj_subscribe = new Model_Subscribe(); $obj_subscribe->id_user = $user->id_user; $obj_subscribe->id_category = $id_value; $obj_subscribe->id_location = Core::post('location_subscribe'); $obj_subscribe->min_price = $min_price; $obj_subscribe->max_price = $max_price; try { $obj_subscribe->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } Alert::set(Alert::SUCCESS, __('Thank you for subscribing')); $this->redirect(Route::url('default')); } else { Alert::set(Alert::ALERT, __('Invalid Email')); $this->redirect(Route::url('default')); } }
/** * Log in the current user with the provided credentials. * @param string $usernameOrEmail User name or email of account * @param string $password * @param bool $cookie Use a cookie to store the login * @param string $use The field being used to identify the user (username, email, or either) * @return bool False if login failed */ public function login($usernameOrEmail, $password, $cookie = false, $use = 'either') { switch ($use) { case 'username': $field = 'username'; break; case 'email': $field = 'email'; break; default: $field = 'username'; if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $usernameOrEmail)) { $field = 'email'; } break; } $users = new Model_User(); $users->where("{$field} = ?", $userNameOrEmail); if ($users->count() == 0) { Typeframe::Log("WARNING: {$usernameOrEmail} matches more than one {$field} in the user table."); //return false; } $row = $users->getFirst(); // Did this even find a record? if (!$row) { Typeframe::Log("Login failed for {$usernameOrEmail} due to: no {$field} found"); return false; } // Does the password not match? if (!self::CheckPassword($row, $password)) { Typeframe::Log("Login failed for {$usernameOrEmail} due to: incorrect password"); return false; } //check to see if account is suspended. if ($row['confirmed'] == 0) { Typeframe::Log("Login failed for {$usernameOrEmail} due to: suspended account"); return false; } // Whee, all the error checks must have passed! unset($row['salt']); unset($row['hashtype']); $_SESSION['typef_user'] = $row; if ($cookie) { // Store cookie // TODO: It might make more sense to store the user ID instead of the name. setcookie('typef_username', $row['username'], time() + 60 * 60 * 24 * 30, '/'); setcookie('typef_passhash', $row['passhash'], time() + 60 * 60 * 24 * 30, '/'); } Typeframe::Log("{$usernameOrEmail} logged in"); return true; }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __('Orders'); $this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen'); $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/oc-panel/crud/index.js', 'js/oc-panel/stats/dashboard.js'); $orders = new Model_Order(); $orders = $orders->where('status', '=', Model_Order::STATUS_PAID); //filter email if (core::request('email') !== NULL) { $user = new Model_User(); $user->where('email', '=', core::request('email'))->limit(1)->find(); if ($user->loaded()) { $orders = $orders->where('id_user', '=', $user->id_user); } } //filter date if (!empty(Core::request('from_date')) and !empty(Core::request('to_date'))) { //Getting the dates range $from_date = Core::request('from_date', strtotime('-1 month')); $to_date = Core::request('to_date', time()); $orders = $orders->where('pay_date', 'between', array($from_date, $to_date)); } //filter coupon if (is_numeric(core::request('id_coupon'))) { $orders = $orders->where('id_coupon', '=', core::request('id_coupon')); } //filter product if (is_numeric(core::request('id_product'))) { $orders = $orders->where('id_product', '=', core::request('id_product')); } //filter status if (is_numeric(core::request('status'))) { $orders = $orders->where('status', '=', core::request('status')); } //order by paid if we are filtering paid.... if (core::request('status') == Model_Order::STATUS_PAID) { $orders->order_by('pay_date', 'desc'); } else { $orders->order_by('id_order', 'desc'); } $items_per_page = core::request('items_per_page', 10); $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $orders->count_all(), 'items_per_page' => $items_per_page))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $orders = $orders->limit($items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $products = new Model_Product(); $products = $products->find_all(); $this->render('oc-panel/pages/order/index', array('orders' => $orders, 'pagination' => $pagination, 'products' => $products)); }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __($this->_orm_model); $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js'; $users = new Model_User(); // filter users by search value if ($q = $this->request->query('search')) { $users->where('email', 'like', '%' . $q . '%')->or_where('name', 'like', '%' . $q . '%'); } $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $users->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $users = $users->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $this->render('oc-panel/crud/index', array('elements' => $users, 'pagination' => $pagination)); }
/** * Logs a user in. * * @param string $username Username * @param string $password Password * @param boolean $remember Enable autologin (not supported) * @return boolean */ protected function _login($username, $password, $remember) { if (is_string($password)) { // Create a hashed password $password = $this->hash($password); } $user = new Model_User(); $user->where('username', '=', $username)->find(); if ($user->loaded() and $user->password === $password) { // Complete the login return $this->complete_login($user); } // Login failed return FALSE; }
/** Showing users on various status */ public function action_index() { $ref = $this->request->param('id'); if (empty($ref)) { $ref = 'APPLIED'; } $this->_secondary_menu['APPLIED'] = new Model_Ui_Menuitem("Applied", "/admin/user/index/APPLIED"); $this->_secondary_menu['ACTIVATED'] = new Model_Ui_Menuitem("Activated", "/admin/user/index/ACTIVATED"); $this->_secondary_menu['BLOCKED'] = new Model_Ui_Menuitem("Blocked", "/admin/user/index/BLOCKED"); $this->_secondary_menu[$ref]->active = true; if ($ref == 'APPLIED') { $this->_actions = array('activate' => "Activate"); } $model = new Model_User(); $elements = $model->where("user.status", "=", $ref)->find_all(); return $this->render('index', array('elements' => $elements)); }
protected function _create_default_admin() { $user = new Model_User(); $user->where('email', mdi::config('admin_default_email'))->get(); if ($user->exists()) { return; } $credential = new MDI_Credential_Native(); $credential->email = mdi::config('admin_default_email'); $credential->password = mdi::config('admin_default_password'); $credential->_need_encrpyt = TRUE; $credential->save(); $user->email = mdi::config('admin_default_email'); $user->grade = mdi::config('admin_default_grade'); $user->name = 'Admin'; $user->phone = '0000-0000'; $user->save($credential, 'credential_native'); }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __('Affiliates Commissions'); $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js'; $commissions = new Model_Affiliate(); //filter by email if (core::get('email') !== NULL) { $user = new Model_User(); $user->where('email', '=', core::get('email'))->limit(1)->find(); if ($user->loaded()) { $commissions = $commissions->where('id_user', '=', $user->id_user); } } $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $commissions->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $commissions = $commissions->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $this->render('oc-panel/pages/affiliate/index', array('commissions' => $commissions, 'pagination' => $pagination)); }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __('Reviews'); $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js'; $reviews = new Model_Review(); //$reviews = $reviews->where('status', '=', Model_Review::STATUS_ACTIVE); if (core::get('email') !== NULL) { $user = new Model_User(); $user->where('email', '=', core::get('email'))->limit(1)->find(); if ($user->loaded()) { $reviews = $reviews->where('id_user', '=', $user->id_user); } } $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $reviews->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $reviews = $reviews->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $this->render('oc-panel/pages/review/index', array('reviews' => $reviews, 'pagination' => $pagination)); }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __($this->_orm_model); $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js'; $elements = ORM::Factory($this->_orm_model); //->find_all(); //email search if (Valid::email(core::get('email'))) { $users = new Model_User(); $users->where('email', '=', core::get('email'))->limit(1)->find(); if ($users->loaded()) { $elements->where('id_user', '=', $users->id_user); } } $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $elements->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $elements = $elements->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $this->render('oc-panel/pages/download/index', array('elements' => $elements, 'pagination' => $pagination)); }
/** * Create an Auth object based on a user's auth setting or the default authentication method. * @param string $usernameOrEmail The user name or email address of the user. * @param string $field Which field to use (username, email, or either) * @param string $method Default authentication method for nonexistent users (e.g., so users can authenticate through LDAP even if they don't have a user record yet) * @return Auth */ public static function ForUser($usernameOrEmail, $field = 'either', $method = TYPEF_AUTH_DEFAULT) { switch ($field) { case 'username': $field = 'username'; break; case 'email': $field = 'email'; break; default: $field = 'username'; if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $usernameOrEmail)) { $field = 'email'; } break; } $users = new Model_User(); $users->where("{$field} = ?", $usernameOrEmail); $obj = null; if ($users->getTotal() == 0) { $user = Model_User::Create(); $user[$field] = $usernameOrEmail; $cls = 'Auth_' . $method; } else { if ($users->getTotal() > 1) { Typeframe::Log("WARNING: {$usernameOrEmail} matches more than one {$field} in the user table."); } $user = $users->getFirst(); $userAuth = $user['auth']; if (!$userAuth) { $userAuth = 'Hash'; } // Older users might have a blank auth field. Assume Hash $cls = 'Auth_' . $userAuth; } if (!is_subclass_of($cls, 'Auth')) { throw new Exception("{$cls} is not a subclass of Auth"); } $obj = new $cls($user); return $obj; }
public function action_index() { // validation active Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Newsletter'))); $this->template->title = __('Newsletter'); $user = new Model_User(); $user->where('status', '=', Model_User::STATUS_ACTIVE); $user = $user->count_all(); if ($this->request->post()) { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->execute(); $users = $query->as_array(); if (count($users) > 0 or Core::post('subject') != NULL) { if (!Email::send($users, '', Core::post('subject'), Core::post('description'), Core::post('from'), Core::post('from_email'))) { Alert::set(Alert::ERROR, __('Error on mail delivery, not sent')); } else { Alert::set(Alert::SUCCESS, __('Email sent to all the users')); } } else { Alert::set(Alert::ERROR, __('Mail not sent')); } } $this->template->content = View::factory('oc-panel/pages/newsletter', array('count' => $user)); }
/** * * Check if we need to login the user or display the form, same form for normal user and admin */ public function action_login() { //if user loged in redirect home if (Auth::instance()->logged_in()) { Auth::instance()->login_redirect(); } elseif ($this->request->post() and CSRF::valid('login')) { $blocked_login = FALSE; // Load the user $user = new Model_User(); $user->where('email', '=', core::post('email'))->where('status', 'in', array(Model_User::STATUS_ACTIVE, Model_User::STATUS_SPAM))->limit(1)->find(); // Check if we must block this login attempt. if ($user->loaded() and $user->failed_attempts > 2) { // failed 2 or 3 attempts, wait 1 minute until next attempt if ($user->failed_attempts < 5 and $user->last_failed > Date::unix2mysql(strtotime('-1 minute'))) { $blocked_login = TRUE; Alert::set(Alert::ERROR, __('Login has been temporarily disabled due to too many unsuccessful login attempts. Please try again in a minute.')); } elseif ($user->failed_attempts > 4 and $user->last_failed > Date::unix2mysql(strtotime('-24 hours'))) { $blocked_login = TRUE; Alert::set(Alert::ERROR, __('Login has been temporarily disabled due to too many unsuccessful login attempts. Please try again in 24 hours.')); } } //not blocked so try to login if (!$blocked_login) { Auth::instance()->login(core::post('email'), core::post('password'), (bool) core::post('remember')); //redirect index if (Auth::instance()->logged_in()) { if ($user->loaded()) { $user->failed_attempts = 0; try { // Save the user $user->update(); } catch (ORM_Validation_Exception $e) { Form::set_errors($e->errors('')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } //is an admin so redirect to the admin home Auth::instance()->login_redirect(); } else { Form::set_errors(array(__('Wrong email or password') . '. ' . '<a class="alert-link" href="' . Route::url('oc-panel', array('directory' => 'user', 'controller' => 'auth', 'action' => 'forgot')) . '">' . __('Have you forgotten your password?') . '</a>')); if ($user->loaded()) { // this is fifth failed attempt, invalidate token? if ($user->failed_attempts == 4) { $user->token = NULL; $user->user_agent = NULL; $user->token_created = NULL; $user->token_expires = NULL; } $user->failed_attempts = new Database_Expression('failed_attempts + 1'); $user->last_failed = Date::unix2mysql(time()); try { // Save the user $user->update(); } catch (ORM_Validation_Exception $e) { Form::set_errors($e->errors('')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } } } //Login page $this->template->title = __('Login'); $this->template->meta_description = __('Login to') . ' ' . Core::config('general.site_name'); $this->template->content = View::factory('pages/auth/login'); }
if ('POST' == $_SERVER['REQUEST_METHOD']) { // save typing below $typef_app_dir = TYPEF_WEB_DIR . '/admin/users/groups'; // get and validate user group id $usergroupid = @$_REQUEST['usergroupid']; $usergroup = Model_Usergroup::Get($usergroupid); if (!$usergroup->exists()) { Typeframe::Redirect('No user group provided.', $typef_app_dir, 1); return; } if (in_array($usergroupid, array(TYPEF_DEFAULT_USERGROUPID, TYPEF_ADMIN_USERGROUPID))) { Typeframe::Redirect('Unable to delete primary user groups.', $typef_app_dir, -1); return; } $users = new Model_User(); $users->where('usergroupid = ?', $usergroupid); if ($users->count() > 0) { Typeframe::Redirect('Unable to delete a group containing users. Delete the users or move them to a different group first.', $typef_app_dir, -1); return; } // delete application associations /*$ugadmin = UserGroupAdmin::DAOFactory(); $ugadmin->select()->where('usergroupid = ?', $usergroupid); foreach ($ugadmin->getAll() as $uga) $uga->delete();*/ // delete the user group $usergroup->delete(); // done Typeframe::Redirect('User group deleted.', $typef_app_dir); return; }
if ($user->exists()) { echo "That name is already taken.\n"; } else { $valid = true; } } } $valid = false; while (!$valid) { echo "Email:"; $email = trim(fgets(STDIN)); if ($email) { $field = new Form_Field_Email(); if ($field->validate($email, 'email')) { $users = new Model_User(); $users->where('email = ?', $email); $user = $users->getFirst(); if ($user->exists()) { echo "That address is already in use.\n"; } else { $valid = true; } } else { echo $field->error() . "\n"; } } } $valid = false; while (!$valid) { echo "User group:"; $usergroup = trim(fgets(STDIN));
/** * does the DB migration * @param pointer $db * @param string $pf db_prefix */ private function migrate($db, $pf) { set_time_limit(0); $db_config = core::config('database.default'); $prefix = $db_config['table_prefix']; //connect DB original/to where we migrate $dbo = Database::instance('default'); //oc_accounts --> oc_users $users_map = array(); $accounts = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'accounts`'); foreach ($accounts as $account) { $user = new Model_User(); $user->where('email', '=', $account['email'])->limit(1)->find(); if (!$user->loaded()) { $user->name = $account['name']; $user->email = $account['email']; $user->password = $account['password']; $user->created = $account['createdDate']; $user->last_modified = $account['lastModifiedDate']; $user->last_login = $account['lastSigninDate']; $user->status = $account['active']; $user->id_role = 1; $user->seoname = $user->gen_seo_title($user->name); $user->save(); } $users_map[$account['email']] = $user->id_user; } //categories --> categories $categories_map = array(0 => 1); $categories = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'categories` ORDER BY `idCategoryParent` ASC'); foreach ($categories as $category) { $cat = new Model_Category(); $cat->name = $category['name']; $cat->order = $category['order']; $cat->created = $category['created']; $cat->seoname = $category['friendlyName']; $cat->price = $category['price']; $cat->description = substr($category['description'], 0, 250); $cat->parent_deep = $category['idCategoryParent'] > 0 ? 1 : 0; //there's only 1 deep $cat->id_category_parent = isset($categories_map[$category['idCategoryParent']]) ? $categories_map[$category['idCategoryParent']] : 1; $cat->save(); //we save old_id stores the new ID, so later we know the category parent, and to changes the ADS category id $categories_map[$category['idCategory']] = $cat->id_category; } //locations --> locations $locations_map = array(0 => 1); $locations = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'locations` ORDER BY `idLocationParent` ASC'); foreach ($locations as $location) { $loc = new Model_Location(); $loc->name = $location['name']; $loc->seoname = $location['friendlyName']; $loc->parent_deep = $location['idLocationParent'] > 0 ? 1 : 0; //there's only 1 deep $loc->id_location_parent = isset($locations_map[$location['idLocationParent']]) ? $locations_map[$location['idLocationParent']] : 1; $loc->save(); //we save old_id stores the new ID, so later we know the location parent, and to changes the ADS location id $locations_map[$location['idLocation']] = $loc->id_location; } //posts --> ads $ads_map = array(); $ads = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'posts`'); foreach ($ads as $a) { if (Valid::email($a['email'])) { //gettin the id_user if (isset($users_map[$a['email']])) { $id_user = $users_map[$a['email']]; } else { $user = Model_User::create_email($a['email'], $a['name']); $id_user = $user->id_user; } $ad = new Model_Ad(); $ad->id_ad = $a['idPost']; //so images still work $ad->id_user = $id_user; $ad->id_category = isset($categories_map[$a['idCategory']]) ? $categories_map[$a['idCategory']] : 1; $ad->id_location = isset($locations_map[$a['idLocation']]) ? $locations_map[$a['idLocation']] : 1; $ad->title = $a['title']; $ad->seotitle = $ad->gen_seo_title($a['title']); $ad->description = !empty($a['description']) ? Text::html2bb($a['description']) : $a['title']; $ad->address = $a['place']; $ad->price = $a['price']; $ad->phone = $a['phone']; $ad->has_images = $a['hasImages']; $ad->ip_address = ip2long($a['ip']); $ad->created = $a['insertDate']; $ad->published = $ad->created; //Status migration...big mess! if ($a['isAvailable'] == 0 and $a['isConfirmed'] == 0) { $ad->status = Model_Ad::STATUS_NOPUBLISHED; } elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 0) { $ad->status = Model_Ad::STATUS_NOPUBLISHED; } elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 1) { $ad->status = Model_Ad::STATUS_PUBLISHED; } elseif ($a['isAvailable'] == 0 and $a['isConfirmed'] == 1) { $ad->status = Model_Ad::STATUS_UNAVAILABLE; } elseif ($a['isAvailable'] == 2) { $ad->status = Model_Ad::STATUS_SPAM; } else { $ad->status = Model_Ad::STATUS_UNAVAILABLE; } try { $ad->save(); } catch (ORM_Validation_Exception $e) { // d($e->errors('')); } $ads_map[$a['idPost']] = $ad->id_ad; } } //posthits --> visits, mass migration $insert = 'INSERT INTO `' . $prefix . 'visits` ( `id_ad`, `created`, `ip_address`) VALUES'; $step = 5000; $total = $db->query(Database::SELECT, 'SELECT count(*) cont FROM `' . $pf . 'postshits`')->as_array(); $total = $total[0]['cont']; for ($i = 0; $i < $total; $i += $step) { $hits = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'postshits` LIMIT ' . $i . ', ' . $step); $values = ''; foreach ($hits as $hit) { //build insert query $values .= '(' . $hit['idPost'] . ', \'' . $hit['hitTime'] . '\', \'' . ip2long($hit['ip']) . '\'),'; } $dbo->query(Database::INSERT, $insert . substr($values, 0, -1)); } //old way of migrating // $hits = $db->query(Database::SELECT, 'SELECT * FROM `'.$pf.'postshits` '); // foreach ($hits as $hit) // { // //build insert query // $visit = new Model_Visit(); // $visit->id_ad = (isset($ads_map[$hit['idPost']]))?$ads_map[$hit['idPost']]:NULL; // $visit->created = $hit['hitTime']; // $visit->ip_address = ip2long($hit['ip']); // $visit->save(); // } }
<?php /** * User password reset controller. * * Allows users to begin the password reset process. * * @package User */ // process the form if ('POST' == $_SERVER['REQUEST_METHOD']) { $users = new Model_User(); $users->where('email = ?', $_REQUEST['email']); if (1 == $users->getTotal()) { // get userid, resetkey, and set to expire in 1 day $user = $users->getFirst(); $userid = $user->get('userid'); $resetkey = randomID(); $expire = date('Y-m-d H:i:s', time() + 86400); // create an entry in the password reset table $reset = Model_UserReset::Create(); $reset->set('userid', $userid); $reset->set('resetkey', $resetkey); $reset->set('expire', $expire); $reset->save(); // construct e-mail body $mm = new Pagemill($pm->root()->fork()); $mm->setVariable('username', $user->get('username')); $mm->setVariable('reseturl', sprintf('http://%s%s/password?userid=%d&resetkey=%s', $_SERVER['HTTP_HOST'], TYPEF_WEB_DIR, $userid, $resetkey)); $body = str_replace('&', '&', $mm->writeString('<pm:include template="/users/reset.eml" />', true)); // e-mail the user so they can reset their password
public function action_view() { $user_id = $this->request->param('id'); if (empty($user_id)) { throw new Exception("User ID Must not be empty!"); } $user = new Model_User(); $view = View::factory('profile/view'); $topic = new Model_Topic(); $reply = new Model_Reply(); $view->replies = $reply->get_replies_by_user_id($user_id); $view->topics = $topic->get_topics_by_user_id($user_id); $view->user = $user->where('id', '=', $user_id)->find(); $this->template->content = $view->render(); }
public function action_index() { $email = $this->request->post('email_subscribe'); if (Valid::email($email, TRUE)) { /* find user and compare emails */ $obj_user = new Model_User(); $user = $obj_user->where('email', '=', $email)->limit(1)->find(); // case when user is not logged in. // We create new user if he doesn't exists in DB // and send him mail for ad created + new profile created if (!$user->loaded()) { $name = substr($email, '0', stripos($email, '@')); $new_password_hash = Auth::instance()->hash_password('password'); $user->email = $email; $user->name = $name; $user->status = Model_User::STATUS_ACTIVE; $user->id_role = Model_Role::ROLE_USER; $user->password = $new_password_hash; $user->seoname = $name; try { $user->save(); Alert::set(Alert::SUCCESS, __('New profile has been created. Welcome ') . $name . ' !'); //we get the QL, and force the regen of token for security $url_pwch = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE); $ret = $user->email('user.new', array('[URL.PWCH]' => $url_pwch, '[USER.PWD]' => $new_password_hash)); } catch (ORM_Validation_Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } /* save this user to data base as subscriber */ $arr_cat = $this->request->post('category_subscribe'); // string in this case is returned as "int,int" so we need to format min/max price $price = $this->request->post('price_subscribe'); if ($price = $this->request->post('price_subscribe')) { $min_price = substr($price, '0', stripos($price, ',')); $max_price = substr($price, strrpos($price, ',') + 1); } else { //in case of mobile version // jquery mobile have different slider, so we need to get data differently $min_price = $this->request->post('price_subscribe-1'); $max_price = $this->request->post('price_subscribe-2'); } //if categry is not selected, subscribe them for all $obj_category = new Model_Category(); if ($arr_cat === NULL) { $all_cats = $obj_category->get_all(); $arr_cat = array(); foreach ($all_cats as $ac) { foreach ($ac as $key => $v) { $arr_cat[] = $key; } } } // create entry table subscriber for each category selected foreach ($arr_cat as $c => $id_value) { $obj_subscribe = new Model_Subscribe(); $obj_subscribe->id_user = $user->id_user; $obj_subscribe->id_category = $id_value; $obj_subscribe->id_location = $this->request->post('location_subscribe'); $obj_subscribe->min_price = $min_price; $obj_subscribe->max_price = $max_price; try { $obj_subscribe->save(); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } Alert::set(Alert::SUCCESS, __('Thank you for subscribing')); $this->request->redirect(Route::url('default')); } else { Alert::set(Alert::ALERT, __('Invalid Email')); $this->request->redirect(Route::url('default')); } }
public function action_advanced_search() { if (Theme::get('infinite_scroll')) { $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js'; $this->template->scripts['footer'][] = 'js/listing.js'; } if (core::config('general.auto_locate') or core::config('advertisement.map')) { Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry,places&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; } $this->template->scripts['footer'][] = 'js/jquery.toolbar.js'; $this->template->scripts['footer'][] = 'js/sort.js'; //template header $this->template->title = __('Advanced Search'); $this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name'); //breadcrumbs Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $pagination = NULL; $ads = NULL; $res_count = NULL; $user = $this->user ? $this->user : NULL; if ($this->request->query()) { // variables $search_advert = core::get('title'); $search_loc = core::get('location'); // filter by each variable $ads = new Model_Ad(); //if sort by distance if ((core::request('sort', core::config('advertisement.sort_by')) == 'distance' or core::request('userpos') == 1) and Model_User::get_userlatlng()) { $ads->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL); } // early filter $ads = $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } if (core::request('userpos') == 1 and Model_User::get_userlatlng()) { if (is_numeric(Core::cookie('mydistance')) and Core::cookie('mydistance') <= 500) { $location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::cookie('mydistance') * 1.60934) : Core::cookie('mydistance'); } else { $location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance'); } $ads->where(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), '<=', $location_distance); } if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) { // if user is using search from header if (core::get('search')) { $search_advert = core::get('search'); } if (core::config('general.search_by_description') == TRUE) { $ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close(); } else { $ads->where('title', 'like', '%' . $search_advert . '%'); } } //cf filter arrays $cf_fields = array(); $cf_user_fields = array(); foreach ($this->request->query() as $name => $field) { if (isset($field) and $field != NULL) { // get by prefix cf if (strpos($name, 'cf_') !== FALSE and array_key_exists(str_replace('cf_', '', $name), Model_Field::get_all())) { $cf_fields[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $cf_fields[$name] = 1; } elseif (empty($field)) { $cf_fields[$name] = NULL; } } elseif (strpos($name, 'cfuser_') !== FALSE and array_key_exists(str_replace('cfuser_', '', $name), Model_UserField::get_all())) { $name = str_replace('cfuser_', 'cf_', $name); $cf_user_fields[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $cf_user_fields[$name] = 1; } elseif (empty($field)) { $cf_user_fields[$name] = NULL; } } } } $category = NULL; $location = NULL; if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) { //filter by category if (is_array(core::get('category'))) { $cat_siblings_ids = array(); foreach (core::get('category') as $cat) { if ($cat !== NULL) { $category = new Model_Category(); $category->where('seoname', '=', $cat)->cached()->limit(1)->find(); if ($category->loaded()) { $cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids()); } } } if (count($cat_siblings_ids) > 0) { $ads->where('id_category', 'IN', $cat_siblings_ids); } } //filter by location if (is_array(core::get('location'))) { $loc_siblings_ids = array(); foreach (core::get('location') as $loc) { if ($loc !== NULL) { $location = new Model_location(); $location->where('seoname', '=', $loc)->cached()->limit(1)->find(); if ($location->loaded()) { $loc_siblings_ids = array_merge($loc_siblings_ids, $location->get_siblings_ids()); } } } if (count($loc_siblings_ids) > 0) { $ads->where('id_location', 'IN', $loc_siblings_ids); } } } else { if (core::get('category') !== NULL) { $category = new Model_Category(); $category->where('seoname', is_array(core::get('category')) ? 'in' : '=', core::get('category'))->cached()->limit(1)->find(); if ($category->loaded()) { $ads->where('id_category', 'IN', $category->get_siblings_ids()); } } $location = NULL; //filter by location if (core::get('location') !== NULL) { $location = new Model_location(); $location->where('seoname', is_array(core::get('location')) ? 'in' : '=', core::get('location'))->cached()->limit(1)->find(); if ($location->loaded()) { $ads->where('id_location', 'IN', $location->get_siblings_ids()); } } } //filter by price(s) if (is_numeric($price_min = str_replace(',', '.', core::get('price-min')))) { // handle comma (,) used in some countries for prices $price_min = (double) $price_min; } // round((float)$price_min,2) if (is_numeric($price_max = str_replace(',', '.', core::get('price-max')))) { // handle comma (,) used in some countries for prices $price_max = (double) $price_max; } // round((float)$price_max,2) if (is_numeric($price_min) and is_numeric($price_max)) { // swap 2 values if ($price_min > $price_max) { $aux = $price_min; $price_min = $price_max; $price_max = $aux; unset($aux); } $ads->where('price', 'BETWEEN', array($price_min, $price_max)); } elseif (is_numeric($price_min)) { $ads->where('price', '>=', $price_min); } elseif (is_numeric($price_max)) { $ads->where('price', '<=', $price_max); } //filter by CF ads if (count($cf_fields) > 0) { foreach ($cf_fields as $key => $value) { //filter by range if (array_key_exists(str_replace('cf_', '', $key), Model_Field::get_all()) and Model_Field::get_all()[str_replace('cf_', '', $key)]['type'] == 'range') { $cf_min = isset($value[0]) ? $value[0] : NULL; $cf_max = isset($value[1]) ? $value[1] : NULL; if (is_numeric($cf_min = str_replace(',', '.', $cf_min))) { // handle comma (,) used in some countries $cf_min = (double) $cf_min; } if (is_numeric($cf_max = str_replace(',', '.', $cf_max))) { // handle comma (,) used in some countries $cf_max = (double) $cf_max; } if (is_numeric($cf_min) and is_numeric($cf_max)) { // swap 2 values if ($cf_min > $cf_max) { $aux = $cf_min; $cf_min = $cf_max; $cf_max = $aux; unset($aux); } $ads->where($key, 'BETWEEN', array($cf_min, $cf_max)); } elseif (is_numeric($cf_min)) { // only min cf has been provided $ads->where($key, '>=', $cf_min); } elseif (is_numeric($cf_max)) { // only max cf has been provided $ads->where($key, '<=', $cf_max); } } elseif (is_numeric($value)) { $ads->where($key, '=', $value); } elseif (is_string($value)) { $ads->where($key, 'like', '%' . $value . '%'); } elseif (is_array($value)) { if (!empty($value = array_filter($value))) { $ads->where($key, 'IN', $value); } } } } //filter by user if (count($cf_user_fields) > 0) { $users = new Model_User(); foreach ($cf_user_fields as $key => $value) { if (is_numeric($value)) { $users->where($key, '=', $value); } elseif (is_string($value)) { $users->where($key, 'like', '%' . $value . '%'); } elseif (is_array($value)) { if (!empty($value = array_filter($value))) { $ads->where($key, 'IN', $value); } } } $users = $users->find_all(); if ($users->count() > 0) { $ads->where('id_user', 'in', $users->as_array()); } else { $ads->where('id_user', '=', 0); } } // count them for pagination $res_count = $ads->count_all(); if ($res_count > 0) { // pagination module $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('advertisement.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL)); Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->offset)); /** * order depending on the sort parameter */ switch (core::request('sort', core::config('advertisement.sort_by'))) { //title z->a case 'title-asc': $ads->order_by('title', 'asc')->order_by('published', 'desc'); break; //title a->z //title a->z case 'title-desc': $ads->order_by('title', 'desc')->order_by('published', 'desc'); break; //cheaper first //cheaper first case 'price-asc': $ads->order_by('price', 'asc')->order_by('published', 'desc'); break; //expensive first //expensive first case 'price-desc': $ads->order_by('price', 'desc')->order_by('published', 'desc'); break; //featured //featured case 'featured': $ads->order_by('featured', 'desc')->order_by('published', 'desc'); break; //rating //rating case 'rating': $ads->order_by('rate', 'desc')->order_by('published', 'desc'); break; //favorited //favorited case 'favorited': $ads->order_by('favorited', 'desc')->order_by('published', 'desc'); break; //distance //distance case 'distance': if (Model_User::get_userlatlng() and core::config('general.auto_locate')) { $ads->order_by('distance', 'asc')->order_by('published', 'asc'); } break; //oldest first //oldest first case 'published-asc': $ads->order_by('published', 'asc'); break; //newest first //newest first case 'published-desc': default: $ads->order_by('published', 'desc'); break; } //we sort all ads with few parameters $ads = $ads->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); } else { $ads = NULL; } } $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => Model_Category::get_as_array(), 'order_categories' => Model_Category::get_multidimensional(), 'locations' => Model_Location::get_as_array(), 'order_locations' => Model_Location::get_multidimensional(), 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all(), 'total_ads' => $res_count)); }
/** * test auth delete multiple users * @author Gabriel Giannattasio * @test */ public function test_auth_delete_multiple_users() { // Setup valid users $this->add_valid_users(); $validUsers = $this->providerValidUsers(); array_walk($validUsers, function (&$user) { $username = $user[0]['username']; $user = new Model_User(); $user->where("username", "=", $username)->find(); }); $this->assertNull(Auth::instance()->unregister($validUsers), "Delete the users in array"); foreach ($validUsers as $user) { $this->assertFalse($user->loaded(), "Ok, so you think the user was deleted? think again!"); } }