Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("DB.php");
- session_start();
- Class UserClass
- {
- private static $dbh;
- public static function init()
- {
- self::$dbh = DB::$dbh;
- }
- public static function LogIn($login, $password)
- {
- $sth = self::$dbh->prepare("SELECT id FROM client WHERE user =:login AND pass =:pass");
- $sth->execute(array(':login' => $login, ':pass' => $password));
- $row = $sth->rowCount();
- if($row == 1)
- {
- $rows = $sth->fetch(PDO::FETCH_ASSOC);
- $_SESSION['id'] = $rows['id'];
- }
- else
- {
- var_dump($row);
- $_SESSION['err'] = '<p style="text-align: center">Nieprawidłowa nazwa użytkownika lub hasło</p>';
- }
- }
- public static function GetImages()
- {
- $sth = self::$dbh->prepare("SELECT url FROM images WHERE user_id =:id");
- $sth->execute(array(':id' => $_SESSION['id']));
- $row = $sth->rowCount();
- if($row)
- {
- $rows = $sth->fetchAll(PDO::FETCH_ASSOC);
- return $rows;
- }
- else
- {
- return 0;
- }
- }
- public static function InsertImage($id, $url)
- {
- $sth = self::$dbh->prepare("INSERT INTO images(user_id, url) VALUES( :id, :url )");
- $result = $sth->execute(array(':id' => $id, ':url' => $url));
- return $result;
- }
- public static function LogOut()
- {
- unset($_SESSION['id']);
- session_unset();
- header('Location: index.php');
- }
- public static function GetUserList()
- {
- $result = self::$dbh->query('SELECT id, user FROM client');
- $rows = $result->fetchAll(PDO::FETCH_ASSOC);
- return $rows;
- }
- public static function AdminPanel()
- {
- if($_SESSION['id']!=2)
- {
- self::LogOut();
- }
- else
- {
- return 1;
- }
- }
- public static function Max()
- {
- $result= self::$dbh->query('SELECT MAX(id) FROM images');
- $rows = $result->fetchAll();
- return $rows[0][0];
- }
- public static function DeleteImage()
- {
- echo $_POST['id'];
- if(!isset($_SESSION['id']) || $_SESSION['id']!=2)
- {
- return 0;
- }
- else
- {
- $sth = self::$dbh->prepare("DELETE FROM images WHERE user_id =:id");
- $sth->execute(array(':id' => $_POST['id']));
- $_SESSION['deleted'] = 'Zdjęcia zostały usunięte z bazy!';
- header('location: adminpanel.php?delete=1');
- }
- }
- public static function AddImages()
- {
- if(!isset($_SESSION['id']) || $_SESSION['id']!=2)
- {
- header('locatin: index.php');
- }
- else
- {
- $max = userClass::Max();
- $uploads_dir = 'img';
- define('SITE_ROOT', realpath(dirname(__FILE__)));
- echo '<pre>';
- foreach ($_FILES["image"]["error"] as $key => $error) {
- if ($error == UPLOAD_ERR_OK) {
- if (!is_dir(SITE_ROOT . '/' . "$uploads_dir/" . $_POST['id'])) {
- mkdir(SITE_ROOT . '/' . "$uploads_dir/" . $_POST['id']);
- }
- $max++;
- $tmp_name = $_FILES["image"]["tmp_name"][$key];
- $array = explode('.', $_FILES['image']['name'][$key]);
- $extension = end($array);
- move_uploaded_file($tmp_name, SITE_ROOT . '/' . "$uploads_dir/" . $_POST['id'] . "/$max" . '.' . $extension);
- chmod(SITE_ROOT . '/' . "$uploads_dir/" . $_POST['id'] . "/$max" . '.' . $extension, 0644);
- $result = userClass::InsertImage($_POST['id'], "$uploads_dir/" . $_POST['id'] . "/$max" . '.' . $extension);
- echo $result;
- }
- }
- $_SESSION['uploaded'] = 'Pliki zostały dodane do bazy!';
- header('location: adminpanel.php?add=1');
- }
- }
- }
- userClass::init();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement