public function action_index($search = null)
 {
     // check for admin
     if (!Auth::member(5)) {
         \Response::redirect_back('home');
     }
     if (Input::Method() === 'POST') {
         $users = Input::POST();
         if (empty($users) === false) {
             // Update the users
             foreach ($users as $user_id => $new_group) {
                 $found_user = Model_User::Find(str_replace('user_role_', '', $user_id));
                 if (empty($found_user) === false) {
                     $found_user->group_id = $new_group;
                     $found_user->save();
                 }
             }
         }
     }
     if (Input::Method() === 'GET' && Input::Get('search')) {
         $data['total_count'] = Controller_Search::get_users();
         $pagination = Settings::pagination($data['total_count']);
         $data['users'] = Controller_Search::get_users($pagination);
         $data['search'] = Input::GET('search');
     } else {
         $data['total_count'] = Model_User::query()->where('id', '!=', static::$user_id)->count();
         $pagination = Settings::pagination($data['total_count']);
         $data['users'] = Model_User::query()->where('id', '!=', static::$user_id)->order_by('username', 'ASC')->rows_offset($pagination->offset)->rows_limit($pagination->per_page)->get();
     }
     $data['pagination'] = $pagination->render();
     $this->template->content = View::Forge('admin/users', $data);
 }
Example #2
0
    $controller = new Controller_Cart();
    $controller->idDeliveryChecked();
});
// Подтверждение покупки и запись в базу данных
$router->respond('POST', '/purchase/?', function () {
    $controller = new Controller_Cart();
    $controller->purchaseSubmit();
});
// Поиск продуктов
$router->respond('GET', '/search/?', function () {
    $controller = new Controller_Search();
    return $controller->action_index();
});
// Поиск продуктов (отправка формы)
$router->respond('POST', '/search/?', function () {
    $controller = new Controller_Search();
    // Использовал @, потому что не нашел другого решения
    return $controller->getSearchResults($_POST['name'], @$_POST['price'], @$_POST['producer'], @$_POST['category']);
});
// Ошибки
$router->onHttpError(function ($code) {
    switch ($code) {
        case 404:
            $controller = new Controller_404();
            $controller->action_index();
            break;
    }
});
// Страница 404
$router->respond('404/?', function () {
    $controller = new Controller_404();
 public function action_list($all = false, $images = false, $screenshots = false)
 {
     if (Auth::check() === false) {
         Response::Redirect(Uri::Create('login'));
     }
     if ($all == 'false' || $all === false) {
         $all = false;
     } else {
         $all = true;
     }
     if ($screenshots == "true") {
         $image = false;
         $data['screenshots'] = true;
     }
     if ($images == "true") {
         $data['images'] = true;
         $per_page = Settings::get('images_per_page');
         if (empty($per_page) === true) {
             $per_page = 5;
         }
     } else {
         $per_page = Settings::get('data_per_page');
         if (empty($per_page) === true) {
             $per_page = 25;
         }
     }
     if ($all === false) {
         // check for admin
         if (!Auth::member(5)) {
             Response::Redirect(Uri::Create('user/urls'));
         }
     }
     if (Input::Method() === 'GET' && Input::Get('search')) {
         $data['total_count'] = Controller_Search::get_urls($all, null, $images);
         $pagination = Settings::pagination($data['total_count'], $per_page);
         $data['search'] = Input::GET('search');
         $data['my_urls'] = Controller_Search::get_urls($all, $pagination, $images);
     } else {
         if ($all === true) {
             $data['total_count'] = Model_Url::query();
             if ($images == "true") {
                 $data['total_count']->where('url', 'LIKE', Uri::Create('assets/screenshots') . '%');
             } else {
                 $data['total_count']->where('url', 'NOT LIKE', Uri::Create('assets/screenshots') . '%');
             }
             $data['total_count'] = $data['total_count']->count();
         } else {
             $data['total_count'] = Model_Url::query()->where('user_id', static::$user_id);
             if ($images == "true") {
                 $data['total_count']->where('url', 'LIKE', Uri::Create('assets/screenshots') . '%');
             } else {
                 $data['total_count']->where('url', 'NOT LIKE', Uri::Create('assets/screenshots') . '%');
             }
             $data['total_count'] = $data['total_count']->count();
         }
         $pagination = Settings::pagination($data['total_count'], $per_page);
         $data['my_urls'] = Model_Url::query();
         if ($all === false) {
             $data['my_urls']->where('user_id', static::$user_id);
         }
         if ($images == "true") {
             $data['my_urls']->where('url', 'LIKE', Uri::Create('assets/screenshots') . '%');
         } else {
             $data['my_urls']->where('url', 'NOT LIKE', Uri::Create('assets/screenshots') . '%');
         }
         $data['my_urls'] = $data['my_urls']->order_by('created_at', 'DESC')->rows_offset($pagination->offset)->rows_limit($per_page)->get();
     }
     $data['pagination'] = $pagination->render();
     $this->template->content = View::Forge('url/list', $data);
 }