public function unlinkImage($name)
 {
     if (file_exists(Common::getPublicFilesDir() . EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR . $name)) {
         unlink(Common::getPublicFilesDir() . EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR . $name);
     }
     if (file_exists(Common::getPublicFilesDir() . EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR . EstateController::IMAGE_THUMBNAIL_PREFIX . $name)) {
         unlink(Common::getPublicFilesDir() . EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR . EstateController::IMAGE_THUMBNAIL_PREFIX . $name);
     }
 }
Esempio n. 2
0
 public static function validateUser($username, $password)
 {
     $appInstance = App::getInstance();
     $user = new DB();
     $user = $user->prepare('Select ' . $appInstance->getConfig()->app['user_table']['id'] . ', ' . $appInstance->getConfig()->app['user_table']['password'] . ' From ' . $appInstance->getConfig()->app['user_table']['name'] . ' where ' . $appInstance->getConfig()->app['user_table']['username'] . '=?');
     $user->execute(array($username));
     $result = $user->fetchAllAssoc();
     if (count($result) > 1) {
         throw new \Exception('there are more than 1 user with this credentials', 500);
     }
     if (count($result) < 1) {
         return false;
     }
     if (!Common::verifyPassword($password, $result[0][$appInstance->getConfig()->app['user_table']['password']])) {
         return false;
     }
     $_SESSION['id'] = $result[0][$appInstance->getConfig()->app['user_table']['id']];
     return true;
 }
Esempio n. 3
0
        <?php 
if (Session::hasError()) {
    ?>
            <div class="alert alert-danger" role="alert"><?php 
    echo Session::getError();
    ?>
</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));
Esempio n. 4
0
        ?>
" class="btn btn-danger">Delete</a>
                            <?php 
    }
    ?>
                        </div>
                    <?php 
}
?>
                    <?php 
if (Auth::isAuth()) {
    ?>
                        <div class="thumbnail">
                            <div class="caption">
                                <?php 
    echo Form::open(array('action' => Common::getBaseURL() . '/product/' . $product['id'] . '/add/comment'));
    ?>
                                <?php 
    echo Form::textarea('', array('name' => 'content', 'placeholder' => 'Write here', 'rows' => '4', 'cols' => '100'));
    ?>
                                <?php 
    echo Form::submit(array('name' => 'submit', 'value' => 'Send', 'class' => 'btn btn-success'));
    ?>
                                <?php 
    echo Form::close();
    ?>
                            </div>
                        </div>
                    <?php 
}
?>
 private function getNonRequiredFieldsCount($routeParams)
 {
     $paramsCount = 0;
     for ($i = count($routeParams) - 1; $i >= 0; $i--) {
         if (Common::endsWith($routeParams[$i], '?}')) {
             $paramsCount++;
         } else {
             return $paramsCount;
         }
     }
     return $paramsCount;
 }
Esempio n. 6
0
                            <td>
                            <?php 
    if ($u->role == 'admin') {
        ?>
                                <a class="btn btn-warning" href="<?php 
        echo Common::getBaseURL();
        ?>
/admin/make/<?php 
        echo $u->id;
        ?>
/user">Make User</a>
                            <?php 
    } else {
        ?>
                                <a class="btn btn-primary" href="<?php 
        echo Common::getBaseURL();
        ?>
/admin/make/<?php 
        echo $u->id;
        ?>
/admin">Make Admin</a>
                            <?php 
    }
    ?>
                            </td>
                        </tr>
                    <?php 
}
?>
                    </tbody>
                </table>
 public function cookies($name, $normalize = null, $default = null)
 {
     if ($this->hasCookies($name)) {
         if ($normalize != null) {
             return Common::normalize($this->_cookies[$name], $normalize);
         }
         return $this->_cookies[$name];
     }
     return $default;
 }
Esempio n. 8
0
use FW\View\View;
use FW\Helpers\Common;
use FW\HTML\Form;
echo View::getLayoutData('header');
?>

    <!-- Page Content -->
    <div class="container">

        <div class="row">

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

                <?php 
echo Form::open(array('action' => Common::getBaseURL() . '/user/login', 'class' => 'form-horizontal'));
?>

                <div class="form-group">
                    <?php 
echo Form::label('Username', array('for' => 'username', 'class' => 'control-label'));
?>
                    <?php 
echo Form::text(array('name' => 'username', 'placeholder' => 'username', 'class' => 'form-control', 'required' => ''));
?>
                </div>
                <div class="form-group">
                    <?php 
echo Form::label('Password', array('for' => 'password', 'class' => 'control-label'));
?>
                    <?php 
Esempio n. 9
0
use FW\View\View;
use FW\Helpers\Common;
use FW\HTML\Form;
echo View::getLayoutData('header');
?>

    <!-- Page Content -->
    <div class="container">

        <div class="row">

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

                <?php 
echo Form::open(array('action' => Common::getBaseURL() . '/user'));
?>
                <?php 
echo Form::text(array('name' => 'username', 'value' => $user['username'], ' disabled' => 'true'));
?>
                <?php 
echo Form::text(array('name' => 'email', 'value' => $user['email']));
?>
                <?php 
echo Form::password(array('name' => 'new_password', 'placeholder' => 'New Password'));
?>
                <?php 
echo Form::password(array('name' => 'password', 'placeholder' => 'Current Password'));
?>
                <?php 
echo Form::submit(array('name' => 'submit', 'value' => 'Change In'));
Esempio n. 10
0
 public static function style($src = '', array $options = array())
 {
     if (!Common::startsWith($src, 'http')) {
         $src = Common::getBaseDir() . $src;
     }
     $options['rel'] = 'stylesheet';
     return '<link href="' . $src . '"' . self::getAttributesAsString($options) . '>';
 }
Esempio n. 11
0
?>
</p>
                </div>

                <?php 
if (isset($estate->images)) {
    ?>
                    <div class="media-bottom">
                        <?php 
    foreach ($estate->images as $image) {
        ?>
                            <img data-gallery="gallery" class="image-cursor" data-toggle="lightbox" data-remote="<?php 
        echo Common::getBaseDir() . 'images/' . $image->name;
        ?>
" style="max-width: 150px;max-height: 100px" src="<?php 
        echo Common::getBaseDir() . 'images/' . (isset($image->thumbnailName) ? $image->thumbnailName : $image->name);
        ?>
" alt="No Image">
                        <?php 
    }
    ?>
                    </div>
                <?php 
}
?>
            </div>

        </div>

    </div>
 public function checkImageResizeNotExceedMemoryLimit($size)
 {
     return $size[0] * $size[1] * 3 * EstateController::TWEAK_FACTOR + EstateController::IMAGE_THUMBNAIL_WIDTH * EstateController::IMAGE_THUMBNAIL_HEIGHT * 3 * EstateController::TWEAK_FACTOR + 5 * 1024 * 1024 < Common::getMemoryLimit();
 }
Esempio n. 13
0
</td>
                            <td class="price"><?php 
    echo number_format($item['bought_price'] * $item['quantity'], 2);
    ?>
</td>
                            <td><?php 
    echo $item['bought_on'];
    ?>
</td>
                            <td><?php 
    echo $item['current_price'];
    ?>
</td>
                            <td>
                                <?php 
    echo Form::open(array('action' => Common::getBaseURL() . '/user/product/' . $item['id'] . '/sell/' . $item['user_product_id']));
    ?>
                                <?php 
    echo Form::text(array('name' => 'quantity'));
    ?>
                                <?php 
    echo Form::submit(array('value' => 'Sell', 'name' => 'submit', 'class' => 'btn btn-success'));
    ?>
                                <?php 
    echo Form::close();
    ?>
                            </td>
                        </tr>
                    <?php 
}
?>
 public function editProfile(UserModel $user, $new_password)
 {
     $validator = new Validation();
     $validator->setRule('required', $user->email, null, 'Email');
     $validator->setRule('required', $user->password, null, 'Current Password');
     $validator->setRule('email', $user->email, null, 'Email');
     if (!$validator->validate()) {
         Session::setError($validator->getErrors());
         Redirect::back();
     }
     /* @var $user \Models\UserModel */
     $userFromDb = $this->user->getUser(Auth::getUserId());
     if (!Common::verifyPassword($user->password, $userFromDb->password)) {
         Session::setError('Current password is not correct');
         Redirect::back();
     }
     if ($this->user->editUser(Auth::getUserId(), $user->email, Common::hashPassword($new_password)) !== 1) {
         Session::setError('Something is wrong. Try again.');
         Redirect::back();
     }
     Session::setMessage('The profile is edited');
     Redirect::to('');
 }
Esempio n. 15
0
 public function displayError($error)
 {
     try {
         View::make('errors.' . $error)->render();
     } catch (\Exception $exc) {
         Common::headerStatus($error);
         echo '<h1>' . $error . '</h1>';
         exit;
     }
 }
Esempio n. 16
0
 public static function to($uri)
 {
     header('Location: ' . Common::getBaseURL() . $uri);
     Session::setOldInput(InputData::getInstance()->getPost());
     exit;
 }