public function banUser($id)
 {
     if ($this->user->banUser($id) !== 1) {
         Session::setError('something went wrong');
         Redirect::back();
     }
     Session::setMessage('Done');
     Redirect::to('/admin/users');
 }
 public function postAdd(MessageBindingModel $message)
 {
     $validator = $this->validateMessage(new Validation(), $message);
     if (!$validator->validate()) {
         Session::setError($validator->getErrors());
         Redirect::back();
     }
     $this->message->add($message->first_name, $message->last_name, $message->email, $message->phone, $message->content, $message->about, date("Y-m-d H:i:s"), false);
     Session::setMessage('Message is sent successfully');
     Redirect::to('');
 }
 public function delete($id)
 {
     /* @var $image \Models\ViewModels\ImageViewModel */
     $image = $this->image->getById($id);
     if ($this->image->delete($id) !== 1) {
         Session::setError('something went wrong. Try again');
         Redirect::back();
     }
     $this->unlinkImage($image->name);
     Session::setMessage('The image has been deleted');
     Redirect::back();
 }
 public function delete($id)
 {
     if (Auth::isUserInRole(array('admin')) || $this->comment->getComment($id)['user_id'] == Auth::getUserId()) {
         if ($this->comment->delete($id) !== 1) {
             Session::setError('something went wrong');
             Redirect::back();
         }
         Session::setMessage('Done');
         Redirect::back();
     }
     Redirect::back();
 }
 public function setRole($id, $role)
 {
     if (!in_array($role, array('admin', 'editor', 'user'))) {
         Session::setError('incorrect role');
         Redirect::back();
     }
     if ($role == 'user') {
         if ($this->user->deleteUserRole($id) === 0) {
             Session::setError('something went wrong');
             Redirect::back();
         }
         Session::setMessage('Done');
         Redirect::to('/admin/users');
     }
     if ($this->user->setRole($id, $role) !== 1) {
         Session::setError('something went wrong');
         Redirect::back();
     }
     Session::setMessage('Done');
     Redirect::to('/admin/users');
 }
Beispiel #6
0
                        </tr>
                    <?php 
}
?>
                    </tbody>
                    <tfoot>
                    <tr class="summary">
                        <td></td>
                        <td></td>
                        <td id="total_price"></td>
                        <td></td>
                    </tr>
                    </tfoot>
                </table>
                <p class="alert-danger"><?php 
echo Session::hasError() ? Session::getError() : '';
?>
</p>
            </div>

        </div>

    </div>
    <!-- /.container -->

    <div class="container">

        <hr>

        <!-- Footer -->
        <footer>
Beispiel #7
0
?>
                    </div>
                </div>

                <div class="form-group">
                    <?php 
echo Form::label('Ad Type', array('class' => 'control-label'));
?>
                    <div class="radio">
                        <?php 
echo Form::label(Form::radio(array('name' => 'ad_type', 'value' => 1, isset($estate) && $estate->ad_type == 1 || Session::oldInput()['ad_type'] == 1 ? 'checked' : '' => '')) . 'For Sale', array('class' => 'control-label'));
?>
                    </div>
                    <div class="radio">
                        <?php 
echo Form::label(Form::radio(array('name' => 'ad_type', 'value' => 0, isset($estate) && $estate->ad_type != 1 || isset(Session::oldInput()['ad_type']) && Session::oldInput()['ad_type'] != 1 ? 'checked' : '' => '')) . 'For Rent', array('class' => 'control-label'));
?>
                    </div>
                </div>

                <div class="form-group">
                    <?php 
echo Form::label('Category', array('class' => 'control-label'));
?>
                    <?php 
echo Form::select(array('name' => 'category_id', 'required' => 'true', 'class' => 'form-control'), $categories);
?>
                </div>

                <div class="form-group">
                    <?php 
 public static function back()
 {
     header('Location: ' . $_SERVER['HTTP_REFERER']);
     Session::setOldInput(InputData::getInstance()->getPost());
     exit;
 }
            <div class="col-md-9">
                <?php 
if (Session::hasMessage()) {
    ?>
                    <div class="alert alert-success" role="alert"><?php 
    echo Session::getMessage();
    ?>
</div>
                <?php 
}
?>
                <?php 
if (Session::hasError()) {
    ?>
                    <div class="alert alert-danger" role="alert"><?php 
    echo Session::getError();
    ?>
</div>
                <?php 
}
?>
                <div class="col-md-12">
                    <div class="thumbnail">
                        <img src="https://hivemc.com/media/images/game_sg_placeholder.jpg" alt="">
                        <div class="caption">
                            <?php 
if (Auth::isAuth()) {
    ?>
                            <a class="pull-right btn btn-success" href="<?php 
    echo Common::getBaseURL();
    ?>
Beispiel #10
0
 public function __destruct()
 {
     Session::saveSession();
 }
?>
                </div>
                <div class="form-group">
                    <?php 
echo Form::label('Password', array('for' => 'password', 'class' => 'control-label'));
?>
                    <?php 
echo Form::password(array('name' => 'password', 'placeholder' => 'password', 'class' => 'form-control', 'required' => ''));
?>
                </div>
                <div class="form-group">
                    <?php 
echo Form::label('Email', array('for' => 'email', 'class' => 'control-label'));
?>
                    <?php 
echo Form::text(array('name' => 'email', 'placeholder' => 'email', 'value' => isset(Session::oldInput()['email']) ? Session::oldInput()['email'] : '', 'class' => 'form-control', 'required' => ''));
?>
                </div>

                <?php 
echo Form::submit(array('name' => 'submit', 'value' => 'Sign In', 'class' => 'btn btn-success'));
?>
                <?php 
echo Form::close();
?>

            </div>

        </div>

    </div>
 public function postAdd(PromotionModel $promotion)
 {
     $validator = new Validation();
     $validator->setRule('required', $promotion->discount, null, 'discount');
     $validator->setRule('required', $promotion->date, null, 'date');
     $validator->setRule('date', $promotion->date, null, 'date');
     if (!$validator->validate()) {
         Session::setError($validator->getErrors()[0]);
         Redirect::back();
     }
     if ($this->promotion->add($promotion->discount, $promotion->date, $promotion->category_id == 0 ? null : $promotion->category_id, $promotion->product_id == 0 ? null : $promotion->product_id) !== 1) {
         Session::setError('something went wrong');
         Redirect::back();
     }
     Session::setMessage('done');
     Redirect::to('');
 }
Beispiel #13
0
            <div class="col-md-12">

                <?php 
echo Form::open(array('action' => Common::getBaseURL() . $action));
?>
                <?php 
echo Form::text(array('name' => 'name', 'placeholder' => 'Name', 'value' => isset($product) ? $product['name'] : Session::oldInput()['name']));
?>
                <?php 
echo Form::textarea(isset($product) ? $product['description'] : Session::oldInput()['description'], array('name' => 'description', 'placeholder' => 'description'));
?>
                <?php 
echo Form::text(array('name' => 'quantity', 'placeholder' => 'Quantity', 'value' => isset($product) ? $product['quantity'] : Session::oldInput()['quantity']));
?>
                <?php 
echo Form::text(array('name' => 'price', 'placeholder' => 'price', 'value' => isset($product) ? $product['price'] : Session::oldInput()['price']));
?>
                <?php 
echo Form::select(array('name' => 'category_id', 'required' => 'true'), $categories);
?>
                <?php 
echo Form::submit(array('name' => 'submit', 'value' => $submit));
?>
                <?php 
echo Form::close();
?>
            </div>

        </div>

    </div>
 public function postEdit($id, $name)
 {
     if ($this->category->edit($id, $name) !== 1) {
         Session::setError('something went wrong');
         Redirect::back();
     }
     Session::setMessage('done');
     Redirect::to('');
 }
 public function delete($id)
 {
     if ($this->product->delete($id) !== 1) {
         Session::setError('can not delete this product');
         Redirect::back();
     }
     Session::setMessage('done');
     Redirect::to('');
 }
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

<?php 
if (Session::hasMessage()) {
    ?>
    <div class="alert alert-success" role="alert"><?php 
    echo Session::getMessage();
    ?>
</div>
<?php 
}
if (Session::hasError()) {
    ?>
    <div class="alert alert-danger" role="alert">
        <?php 
    foreach (Session::getError() as $error) {
        ?>
            <p>
                <?php 
        echo $error;
        ?>
            </p>
        <?php 
    }
    ?>
    </div>
<?php 
}
 public function postEdit($id, $name)
 {
     $validator = new Validation();
     $validator->setRule('required', $name, null, 'Name');
     if (!$validator->validate()) {
         Session::setError($validator->getErrors());
         Redirect::back();
     }
     $this->city->edit($id, $name);
     Session::setMessage('The city is edited');
     Redirect::to('');
 }
 public function getFavourites()
 {
     $result['title'] = 'User Favorites';
     $userFavourite = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavourite[] = $f['estate_id'];
         }
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         $userFavourite = Session::get('favourites');
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     /* @var $estates \Models\ViewModels\EstateBasicViewModel[] */
     if (!empty($userFavourite)) {
         $estates = $this->estate->getFavoritesEstates($userFavourite);
         foreach ($estates as $estate) {
             $estate->image = EstateController::setEstateMainImage($estate);
             $estate->thumbnailName = EstateController::setImageThumb($estate->image);
         }
         $result['estates'] = $estates;
     } else {
         $result['estates'] = array();
     }
     View::make('user.favorites', $result);
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function dispatch()
 {
     $uri = $this->request->getURI();
     $uriParams = array_filter(explode('/', $uri), 'strlen');
     $controllerName = '';
     $controllerMethod = '';
     $paramsFromGET = array();
     foreach (Route::getRouters() as $route) {
         $paramsFromGET = array();
         if ($route['method'] != $_SERVER['REQUEST_METHOD']) {
             continue;
         }
         if (in_array('auth', explode('|', $route['details']['before']))) {
             if (!Auth::isAuth()) {
                 continue;
             }
         }
         if (!Auth::isUserInRole(array_filter(explode('|', $route['details']['roles']), 'strlen'))) {
             continue;
         }
         $routeParams = array_filter(explode('/', $route['url']), 'strlen');
         $nonRequiredFieldsForRoute = $this->getNonRequiredFieldsCount($routeParams);
         if (count($uriParams) < count($routeParams) - $nonRequiredFieldsForRoute || count($uriParams) > count($routeParams)) {
             continue;
         }
         for ($i = 0; $i < count($uriParams); $i++) {
             if (!Common::startsWith($routeParams[$i], '{') && !Common::endsWith($routeParams[$i], '}')) {
                 if ($uriParams[$i] != $routeParams[$i]) {
                     continue 2;
                 }
             } else {
                 if (!$this->isParameterValid($uriParams[$i], $routeParams[$i])) {
                     continue 2;
                 }
                 $paramName = $this->getParameterName($routeParams[$i]);
                 $paramsFromGET[$paramName] = $uriParams[$i];
             }
             if (count($uriParams) - 1 == $i) {
                 $controllerData = explode('@', $route['details']['use']);
                 $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $controllerData[0];
                 $controllerMethod = $controllerData[1];
                 break 2;
             }
         }
         $paramsFromGET = array();
         if (in_array('csrf', explode('|', $route['details']['before']))) {
             if (!CSRF::validateToken()) {
                 continue;
             }
         }
     }
     if ($controllerMethod === '') {
         if (App::getInstance()->getConfig()->app['enable_default_routing']) {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $uriParams[0] . 'Controller';
             $controllerMethod = $uriParams[1];
             $r = new \ReflectionMethod($controllerName, $controllerMethod);
             $params = $r->getParameters();
             $index = 2;
             foreach ($params as $param) {
                 $paramsFromGET[$param->name] = $uriParams[$index];
                 $index++;
             }
             for ($i = $index; $i < count($uriParams); $i++) {
                 $paramsFromGET[$i] = $uriParams[$i];
             }
         } else {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . App::getInstance()->getConfig()->app['default_controller'];
             $controllerMethod = App::getInstance()->getConfig()->app['default_method'];
         }
     }
     $requestInput = $this->bindDataToControllerMethod($paramsFromGET, $controllerName, $controllerMethod);
     $controller = new $controllerName();
     $controller = DependencyProvider::injectDependenciesToController($controller);
     call_user_func_array(array($controller, $controllerMethod), $requestInput);
     Session::setOldInput(InputData::getInstance()->getPost());
 }
 /**
  * @return array
  */
 public function setUserFavorites()
 {
     $userFavorites = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavorites[] = $f['estate_id'];
         }
     } else {
         $userFavorites = Session::get('favourites');
     }
     return is_array($userFavorites) ? $userFavorites : array();
 }
Beispiel #21
0
</div>
        <?php 
}
?>
        <div class="row">

            <div class="col-md-12">

                <?php 
echo Form::open(array('action' => Common::getBaseURL() . $action));
?>
                <?php 
echo Form::text(array('name' => 'discount', 'placeholder' => 'discount', 'value' => Session::oldInput()['discount']));
?>
                <?php 
echo Form::datetime(array('name' => 'date', 'placeholder' => 'Exp date. yyyy-dd-mm', 'value' => Session::oldInput()['date']));
?>
                <?php 
echo Form::select(array('name' => 'category_id'), $categories);
?>
                <?php 
echo Form::select(array('name' => 'product_id'), $products);
?>
                <?php 
echo Form::submit(array('name' => 'submit', 'value' => $submit));
?>
                <?php 
echo Form::close();
?>
            </div>
Beispiel #22
0
                <div class="form-group">
                    <?php 
echo Form::label('About Estate', array('for' => 'about', 'class' => 'control-label'));
?>
                    <?php 
echo Form::textarea(isset($estateInfo) ? $estateInfo : Session::oldInput()['about'], array('name' => 'about', 'id' => 'about', 'placeholder' => 'Content', 'class' => 'form-control'));
?>
                </div>

                <div class="form-group">
                    <?php 
echo Form::label('Content', array('for' => 'content', 'class' => 'control-label'));
?>
                    <?php 
echo Form::textarea(Session::oldInput()['content'], array('name' => 'content', 'id' => 'content', 'placeholder' => 'Content', 'class' => 'form-control', 'required' => ''));
?>
                </div>

                <?php 
echo Form::submit(array('class' => 'btn btn-success', 'value' => 'Send'));
?>
                <?php 
echo Form::close();
?>
            </div>

        </div>

    </div>
 public function sellProduct($id, $quantity, $upid)
 {
     $this->user->startTran();
     if ($this->user->changeProductQuantity(Auth::getUserId(), $id, $quantity, $upid) !== 1) {
         Session::setError('not enough products');
         $this->user->rollback();
         Redirect::back();
     }
     $userProduct = $this->user->getProduct(Auth::getUserId(), $id, $upid);
     if ($userProduct['quantity'] < 1) {
         if ($this->user->deleteProduct(Auth::getUserId(), $id, $upid) !== 1) {
             Session::setError('something went wrong');
             $this->user->rollback();
             Redirect::back();
         }
     }
     $soldProducts = $this->product->getProduct($id);
     if ($this->product->addQuantity($soldProducts['id'], $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     if ($this->user->addCash(Auth::getUserId(), $soldProducts['price'] * $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     $this->user->commit();
     Session::setMessage('You sold ' . $quantity . ' of ' . $userProduct['name']);
     Redirect::to('/user/' . Auth::getUserId() . '/products');
 }
 public function buy()
 {
     $totalSum = 0;
     $cart = Session::get('cart');
     $this->product->startTran();
     $productsFromCart = $this->getProductsFromCart($cart);
     foreach ($productsFromCart as $item) {
         if ($this->product->changeQuantity($item['id'], $item['cart_quantity']) !== 1) {
             $this->product->rollback();
             Session::setError('not enough available product');
             Redirect::back();
         }
         $totalSum += $item['price'] * $item['cart_quantity'];
     }
     $user = new User();
     if ($user->changeUserCash(Auth::getUserId(), $totalSum) !== 1) {
         $this->product->rollback();
         Session::setError('not enough money');
         Redirect::back();
     }
     foreach ($productsFromCart as $item) {
         if ($user->addProduct(Auth::getUserId(), $item['id'], $item['cart_quantity'], $item['price']) !== 1) {
             $this->product->rollback();
             Session::setError('something went wrong');
             Redirect::back();
         }
     }
     $this->product->commit();
     Session::remove('cart');
     Session::setMessage('Done');
     Redirect::to('user/cart');
 }