diff --git a/.gitignore b/.gitignore index aaec768c..69b72ceb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .env.php -.env.*.php +env.*.php /.idea diff --git a/bootstrap.php b/bootstrap.php index 70fd6160..cf0b8fda 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -2,6 +2,7 @@ // require models require_once __DIR__ . '/models/User.php'; +require_once __DIR__ . '/models/Ad.php'; // require helper classes @@ -10,4 +11,5 @@ // require front controller -require_once __DIR__ . '/controllers/PageController.php'; \ No newline at end of file +require_once __DIR__ . '/controllers/PageController.php'; + diff --git a/controllers/PageController.php b/controllers/PageController.php index 95030863..6d212479 100644 --- a/controllers/PageController.php +++ b/controllers/PageController.php @@ -1,6 +1,8 @@ username !== $_SESSION['IS_LOGGED_IN']){ + header('Location:/index'); + die; + } + $data['ad'] = $ad; + editAd(); + $navbarStatus = 'active'; + $data['adsStatus'] = $navbarStatus; + break; + case ('/index'): + $mainView = '../views/ads/index.php'; + $ads = Ad::all(); + $data['ads'] = $ads; + $navbarStatus = 'active'; + $data['indexStatus'] = $navbarStatus; + break; + case ('/show'): + $mainView = '../views/ads/show.php'; + $ad = Ad::findAd($_GET['ad']); + $data['ad'] = $ad; + $ad->updateClicks(); + break; + case ('/account'): + if(Auth::check()) { + $mainView = '../views/users/account.php'; + } else if (!Auth::check()) { + $mainView = '../views/users/login.php'; + } + $ads = Ad::findAdsByUser(); + $navbarStatus = 'active'; + $data['accountStatus'] = $navbarStatus; + break; + case ('/edit_users'): + if(Auth::check()) { + $mainView = '../views/users/edit.php'; + } else if (!Auth::check()) { + $mainView = '../views/users/login.php'; + } + break; + case ('/login'): + $mainView = '../views/users/login.php'; + logIn(); + $navbarStatus = 'active'; + $data['loginStatus'] = $navbarStatus; + break; + case ('/signup'): + $mainView = '../views/users/signup.php'; + signUp(); + $navbarStatus = 'active'; + $data['signupStatus'] = $navbarStatus; + break; + case ('/update'): + if(Auth::check()) { + $mainView = '../views/users/update.php'; + } else if (!Auth::check()) { + $mainView = '../views/users/login.php'; + } + updateUser(); + break; + case ('/password'): + $mainView = '../views/users/password.php'; + updatePass(); + break; + case ('/logout'): + $mainView = '../views/home.php'; + Auth::logout(); + $ads = Ad::order('clicks'); + $data['ads'] = $ads; + break; default: // displays 404 if route not specified above $mainView = '../views/404.php'; break; } $data['mainView'] = $mainView; - + $data['errorMessage'] = signup(); + $data['user'] = Auth::user(); return $data; } -extract(pageController()); \ No newline at end of file +// var_dump($_SESSION); +extract(pageController()); diff --git a/database/migrations/ads_migration.php b/database/migrations/ads_migration.php new file mode 100644 index 00000000..e47aabd8 --- /dev/null +++ b/database/migrations/ads_migration.php @@ -0,0 +1,20 @@ +exec('DROP TABLE IF EXISTS ads'); + +$query = 'CREATE TABLE ads ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(240) NOT NULL, + description TEXT, + seller_id INT UNSIGNED, + clicks INT UNSIGNED DEFAULT "0", + image VARCHAR(240), + PRIMARY KEY (id) +)'; + +$dbc->exec($query); + +?> diff --git a/database/seeds/ads_seeder.php b/database/seeds/ads_seeder.php new file mode 100644 index 00000000..52953ba8 --- /dev/null +++ b/database/seeds/ads_seeder.php @@ -0,0 +1,44 @@ +name = "Finn's old shoes"; +$ad->description = "Just some old shoes"; +$ad->seller_id = 1; +$ad->image = 'img/uploads/old_shoes.jpg'; +$ad->save(); + +$ad = new Ad; +$ad->name = "Jakes's old shirt"; +$ad->description = "Just an old shirt"; +$ad->seller_id = 2; +$ad->image = 'img/uploads/jakes_Old_shirt.jpg'; +$ad->save(); + +$ad = new Ad; +$ad->name = "Simon's old simon game"; +$ad->description = "Just a simple simon game"; +$ad->seller_id = 3; +$ad->image = 'img/uploads/simon_says.jpg'; +$ad->save(); + +$ad = new Ad; +$ad->name = "Finn's old wooden sword"; +$ad->description = "Just an old wooden sword"; +$ad->seller_id = 1; +$ad->image = 'img/uploads/old_wooden_sword.jpg'; +$ad->save(); + +$ad = new Ad; +$ad->name = "Marceline's old guitar"; +$ad->description = "Just an old guitar"; +$ad->seller_id = 4; +$ad->image = 'img/uploads/old_guitar.jpg'; +$ad->save(); + + ?> + +//just a comment \ No newline at end of file diff --git a/models/Ad.php b/models/Ad.php new file mode 100644 index 00000000..2fe01dff --- /dev/null +++ b/models/Ad.php @@ -0,0 +1,114 @@ +prepare($query); + $stmt->bindValue(":search", "%$search%"); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return array_map(function($result) { + $instance = new static; + $instance->attributes = $result; + return $instance; + }, $results); + } else { + $query = "SELECT ads.*, users.email, users.username + from ". "ads " . + "join users on users.id = ads.seller_id "; + + $stmt = self::$dbc->query($query); + + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + } + return array_map(function($result) { + $instance = new static; + $instance->attributes = $result; + return $instance; + }, $results); + } + + public static function findAd($id) + { + // Get connection to the database + self::dbConnect(); + + //Create select statement using prepared statements + $query = "SELECT ads.*, users.email, users.username + FROM ads + JOIN users ON users.id = ads.seller_id + WHERE ads.id = :id"; + + $stmt = self::$dbc->prepare($query); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + + //Store the resultset in a variable named $result + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + $instance = null; + // if we have a result, create a new instance + if ($result) { + $instance = new static; + $instance->attributes = $result; + } + + // return either the found instance or null + return $instance; + } + + public static function findAdsByUser() + { + self::dbConnect(); + + $query = "SELECT * + FROM ads + WHERE seller_id = :id "; + + $stmt = self::$dbc->prepare($query); + $stmt->bindValue(':id', Auth::id(), PDO::PARAM_INT); + $stmt->execute(); + + //Store the resultset in a variable named $result + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return array_map(function($result) { + $instance = new static; + $instance->attributes = $result; + return $instance; + }, $results); + } + + public function updateClicks(){ + $query = "UPDATE ads + SET clicks = :clicks + WHERE id = :id"; + + $stmt = self::$dbc->prepare($query); + $stmt->bindValue(':clicks', $this->clicks + 1); + $stmt->bindValue('id', $this->id); + + $stmt->execute(); + } +} + + +?> diff --git a/models/Model.php b/models/Model.php index 29d50bc8..b689f2e7 100644 --- a/models/Model.php +++ b/models/Model.php @@ -15,11 +15,11 @@ * is not necessary in instance methods. */ abstract class Model { - /** @var PDO|null the connection to the database */ + /** @var PDO|null the connection to the database */ protected static $dbc; /** @var string the name of the table */ protected static $table; - + /** @var array the attributes of this instance */ protected $attributes = []; @@ -207,6 +207,22 @@ public static function find($id) // return either the found instance or null return $instance; } + public static function order($column_name, $limit = 3) + { + self::dbConnect(); + $query = 'SELECT * FROM ' . static::$table . ' ORDER BY :column_name DESC LIMIT :limit'; + $stmt = self::$dbc->prepare($query); + $stmt->bindValue(':column_name', $column_name, PDO::PARAM_STR); + $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + return array_map(function($result) { + $instance = new static; + $instance->attributes = $result; + return $instance; + }, $results); + + } /** @@ -235,4 +251,4 @@ public static function all() }, $results); } -} \ No newline at end of file +} diff --git a/public/css/main.css b/public/css/main.css index e69de29b..45ee5bc2 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -0,0 +1,316 @@ +body { + padding-top: 52px; + margin-bottom: 100px; +} +a:hover { + text-decoration:none; +} +.jumbodiv { + width: 100vw; + height: 35vh; + margin: 0px; + padding: 0px; + background-image: url("../img/Homepage_bg.jpg"); + background-size: 100vw; + background-position-y: 70%; + background-repeat:no-repeat; +} +#bigLogo { + width: 100vw; + height: 100%; + background-color: rgba(255,255,255,0); + background-image: url("../img/Logo_Lg.gif"); + background-size: 70%; + background-repeat-x: no-repeat; + background-repeat-y: no-repeat; + background-position: center; + margin: -6vh auto 0px auto; +} +#signUp { + width: 220px; + height: 40px; + background-color: #529df9; + background-position: center; + margin: -40px auto 0 auto; + border:none; + color:white; + font-family: 'Work Sans', sans-serif; + text-align: center; + letter-spacing: 0.1em; + line-height: 2.8em; + +} +#signUp:hover { + background-color: #488be6; +} + +#footerIcon{ + height: 50px; + width: 140px; + background-image: url("../img/Logo_sm.gif"); + background-size: 140px 38px; + background-repeat: no-repeat; + background-position: center; + margin:auto; +} +.navbar-nav { + padding-top: 10px; +} +.navbar-nav > li > a { + padding-right: 25px; +} +#links { + list-style: none; + text-decoration: none; +} +.navbar-toggle .icon-bar { + background-color:white; +} +.navbar ul li a { + font-family: 'Work Sans', sans-serif; + color: white; + letter-spacing: .1em; +} + +.nav > li > a:hover { + background-color: #5e9ff7; + color: rgba(255,255,255, .5); +} +.nav .open>a, +.nav .open>a:focus, +.nav .open>a:hover { + background-color: #5392e7; + border-color: #337ab7; +} +.nav .dropDowns{ + color: #5e9ff7; +} +.nav .dropDowns:hover, +.nav .dropDowns:active { + color: #5e9ff7; +} +#sticky { + width:100%; + padding:20px; + padding-bottom:16px; + text-align:center; + position:fixed; + bottom:0; + left:0; + color: #999; +} +#error_message { + color: red; +} + +.ad-img { + width:100%; + height:auto; +} + +#search { + padding-top: 8px; + +} +#search .form-control { + background-color: rgba(255,255,255, 0); + border:none; + -webkit-box-shadow:none; + border-radius: 0px; + border-bottom: 1px solid white; + font-family: 'Work Sans', sans-serif; + color:white; + -webkit-color:white; + } +#search .form-control:focus { + -webkit-box-shadow:none; + box-shadow:none; + border-color: rgba(255,255,255, 1); + color:white; + font-family: 'Work Sans', sans-serif; + -webkit-color:white; + } + +.navbar { + border-radius: 0px; + background-color: #5e9ff7; + + } + +#search .form-control::-webkit-input-placeholder { + color: rgba(255,255,255, .5); + font-family: 'Work Sans', sans-serif; + +} +#searchButton { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #5e9ff7; + font-size: 15px; +} +#searchButton:hover { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #84b6f8; + font-size: 15px; +} +#searchButton:focus { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #84b6f8; + font-size: 15px; +} +#ad_image { + height: 22em; + object-fit: cover; + border-radius: 5px; +} +#ad_image_account { + height: 20em; +} +@media (min-width: 768px) { +.jumbodiv { + width: 100vw; + height: 55vh; + margin: 0px; + padding: 0px; + background-image: url("../img/Homepage_bg.jpg"); + background-size: 100vw; + background-position-y: 70%; +} +#bigLogo { + width: 100vw; + height: 100%; + background-color: rgba(255,255,255,0); + background-image: url("../img/Logo_Lg.gif"); + background-size: 63%; + background-repeat-x: no-repeat; + background-repeat-y: no-repeat; + background-repeat: no-repeat; + background-position: center; + margin: -6vh auto 0px auto; +} +#signUp { + width: 220px; + height: 40px; + background-color: #529df9; + background-position: center; + margin: -90px auto 0 auto; + border:none; + color:white; + font-family: 'Work Sans', sans-serif; + text-align: center; + letter-spacing: 0.1em; + line-height: 2.8em; +} + #search { + float: right; + } + .navbar ul li a { + font-family: 'Work Sans', sans-serif; + color: white; + letter-spacing: .1em; + } + + .nav > li > a:hover { + background-color: #5e9ff7; + color: rgba(255,255,255, .5); + } +#search .form-control { + background-color: rgba(255,255,255, 0); + border:none; + -webkit-box-shadow:none; + border-radius: 0px; + border-bottom: 1px solid white; + font-family: 'Work Sans', sans-serif; + color:white; + -webkit-color:white; + } +#search .form-control:focus { + -webkit-box-shadow:none; + box-shadow:none; + border-color: rgba(255,255,255, 1); + color:white; + font-family: 'Work Sans', sans-serif; + -webkit-color:white; + } + +#search .form-control::-webkit-input-placeholder { + color: rgba(255,255,255, .5); + font-family: 'Work Sans', sans-serif; + +} +#searchButton { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #5e9ff7; + font-size: 15px; +} +#searchButton:hover { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #84b6f8; + font-size: 15px; +} +#searchButton:focus { + color:white; + border-radius: 0px; + margin: 0px; + font-family: 'Work Sans', sans-serif; + font-weight: bold; + background-color: #84b6f8; + font-size: 15px; +} +#search .form-control { + background-color: rgba(255,255,255, 0); + border:none; + -webkit-box-shadow:none; + border-radius: 0px; + border-bottom: 1px solid white; + font-family: 'Work Sans', sans-serif; + color:white; + -webkit-color:white; + } +#search .form-control:focus { + -webkit-box-shadow:none; + box-shadow:none; + border-color: rgba(255,255,255, 1); + color:white; + font-family: 'Work Sans', sans-serif; + -webkit-color:white; + } + + + + + +} + +.close{ + float: right; + font-size: 50px; + font-weight: normal; + padding:0; + margin:0; + +} + +.ad-index a, .ad-index a:hover, .ad-index a:focus, .ad-index:active { + color: #337ab7; + text-decoration: none; +} diff --git a/public/img/Homepage_bg.jpg b/public/img/Homepage_bg.jpg new file mode 100644 index 00000000..3e0e7ff7 Binary files /dev/null and b/public/img/Homepage_bg.jpg differ diff --git a/public/img/Logo_Lg.gif b/public/img/Logo_Lg.gif new file mode 100644 index 00000000..1da93f9d Binary files /dev/null and b/public/img/Logo_Lg.gif differ diff --git a/public/img/Logo_Sm.gif b/public/img/Logo_Sm.gif new file mode 100644 index 00000000..9c537755 Binary files /dev/null and b/public/img/Logo_Sm.gif differ diff --git a/public/img/uploads/jakes_old_shirt.jpg b/public/img/uploads/jakes_old_shirt.jpg new file mode 100644 index 00000000..c82d2b12 Binary files /dev/null and b/public/img/uploads/jakes_old_shirt.jpg differ diff --git a/public/img/uploads/old_guitar.jpg b/public/img/uploads/old_guitar.jpg new file mode 100644 index 00000000..89ca15dc Binary files /dev/null and b/public/img/uploads/old_guitar.jpg differ diff --git a/public/img/uploads/old_iron.jpg b/public/img/uploads/old_iron.jpg new file mode 100644 index 00000000..82d68139 Binary files /dev/null and b/public/img/uploads/old_iron.jpg differ diff --git a/public/img/uploads/old_shoes.jpg b/public/img/uploads/old_shoes.jpg new file mode 100644 index 00000000..7d182f8a Binary files /dev/null and b/public/img/uploads/old_shoes.jpg differ diff --git a/public/img/uploads/old_wooden_sword.jpg b/public/img/uploads/old_wooden_sword.jpg new file mode 100644 index 00000000..609ca51e Binary files /dev/null and b/public/img/uploads/old_wooden_sword.jpg differ diff --git a/public/img/uploads/phpDptMJY.jpg b/public/img/uploads/phpDptMJY.jpg new file mode 100644 index 00000000..82d68139 Binary files /dev/null and b/public/img/uploads/phpDptMJY.jpg differ diff --git a/public/img/uploads/simon_says.jpg b/public/img/uploads/simon_says.jpg new file mode 100644 index 00000000..b1c1598d Binary files /dev/null and b/public/img/uploads/simon_says.jpg differ diff --git a/public/index.php b/public/index.php index 0f048917..4ccdd093 100644 --- a/public/index.php +++ b/public/index.php @@ -1,13 +1,18 @@ +
-