diff --git a/admin.php b/admin.php index ce4fce01d84a3b7b734a120ba391e8eecdd2e1f4..9bf4327f884b2a1c5d2b8ad2964888f715a4ada2 100644 --- a/admin.php +++ b/admin.php @@ -48,6 +48,10 @@ case 'add_image' : case 'delete_admin' : include 'admin/delete_admin.php'; break; +case 'manage_albums' : + include 'admin/manage_albums.php'; + break; + default : include 'views/404.php'; diff --git a/admin/add_image.php b/admin/add_image.php index 7395af1731a63033f328fa6224d8a9f68d44717b..3418767c0a30754422cca7457506a736287210a0 100644 --- a/admin/add_image.php +++ b/admin/add_image.php @@ -51,7 +51,41 @@ if(isset($_POST["submit"])) { } +$content .= " Existing images: "; +/* Showing existing images */ + $dir = 'uploads/'; + $file_display = array('jpg', 'jpeg', 'png', 'gif'); + + if (file_exists($dir) == false) { + echo 'Directory \''. $dir. '\' not found!'; + } else { + $dir_contents = scandir($dir); + + foreach ($dir_contents as $file) { + $file_type = strtolower(end(explode('.', $file))); + + if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) { + $content .='<img src="'. $dir. '/'. $file. '" alt="'. $file. '" width="100" height="100" />'; + } + } + } echo($content); ?> + + +<!-- +<div class="img"> + + <img src="uploads/b.jpg" alt="Fjords" width="100" height="100"> + </a> +</div> +<div class="img"> + + <img src="uploads/a.png" alt="Fjords" width="100" height="100"> + </a> +</div> +--> + + diff --git a/admin/manage_albums.php b/admin/manage_albums.php new file mode 100644 index 0000000000000000000000000000000000000000..518ce1c11009269a1e01475f94718f5e4a9cf6f8 --- /dev/null +++ b/admin/manage_albums.php @@ -0,0 +1,115 @@ +<?php +confirm_logged_in(); + +// define a variable with path to the script which will process form +// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) +// -> htmlspecialchars() is used to replace special characters with HTML entities */ +$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=manage_albums"); +// empty option +$options = ""; +// pull data from database +$sql = "SELECT a.name, a.lastName, al.title, a.id, al.price, al.cover + FROM artist a + INNER JOIN album al + ON al.artist_id=a.id"; + +$result = mysqli_query($link, $sql); + +if ($result === false) { + echo mysqli_error($link); +} else { + + + + $content .= "<table border='1'><tbody>"; + $content .= " <th>".Album."</th>"; + $content .= " <th>".Artist."</th>"; + $content .= " <th>".Price."</th>"; + $content .= " <th>".Cover."</th>"; + + + // fetch associative array + while ($row = mysqli_fetch_assoc($result)) { + + // filling ooption menu + $options .= "<option value='".$row['id']."'>"; + $options .= $row['name']." ".$row['lastName']; + $options .= "</option>"; + + + // table + $content .= "<tr>"; + $content .= "<td>".$row['title']."</td>"; + $content .= "<td><a>".$row['name']." ".$row['lastName']."</a></td>"; + $content .= "<td>£".$row['price']."</td>"; + $content .= "<td><img src=".$row['cover']." width='50' height='50'>"; + $content .= "</tr>"; + + //form + $form_html = "<form enctype='multipart/form-data' action='".$action."' method='POST'> + <fieldset> + <label for='artist_id'>Change cover for:</label> + <select name='artist_id'> + ".$options." + <option value='NULL'>Not listed</option> + </select> + </fieldset> + <input type='file' name='fileToUpload' id='fileToUpload'> + <input type='submit' value='Upload Image' name='submit'> + </form>"; + + } + $content .= "</tbody></table>"; + + // free result set + mysqli_free_result($result); + $content .= $form_html; + +} + +$cover = $artist_id = ""; + + +$target_dir = "uploads/"; +$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); +$uploadOk = 1; +$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); +// Check if image file is a actual image or fake image +if(isset($_POST["submit"])) { + $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); + // Check file size + if ($_FILES["fileToUpload"]["size"] > 500000) { + echo "Sorry, your file is too large."; + $uploadOk = 0; + } + // Check if $uploadOk is set to 0 by an error + if ($uploadOk == 0) { + + echo "Sorry, your file was not uploaded."; + // if everything is ok, try to upload file + } else { + if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { + $content .= "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; + $cover = $target_file; + } else { + echo "Sorry, there was an error uploading your file."; + } + } + + + + // update cover column + if(empty($errors)){ + $artist_id = mysql_prep(clean_input($_POST["artist_id"])); + + $query = "UPDATE album SET "; + $query .= "cover = '{$cover}' "; + $query .= "WHERE artist_id = {$artist_id} "; + $result = mysqli_query($link, $query); + } + +} + +echo ($content); + +?> diff --git a/css/styles.css b/css/styles.css index ec319a0dba70ffbac26c2c69108005ec4bd48844..fc0b1c00c27252bded01878fdd221eddb1155d8d 100755 --- a/css/styles.css +++ b/css/styles.css @@ -130,10 +130,6 @@ ul ,li{ color:#8D0D19; } - - - - label { /* To make sure that all labels have the same size and are properly aligned */ display: inline-block; @@ -142,4 +138,31 @@ label { } form div + div { margin-top: 1em; +} + + +div.img { + margin: 5px; + border: 1px solid #ccc; + float: left; + width: 180px; +} + +div.img:hover { + border: 1px solid #777; +} + +div.img img { + width: 100%; + height: auto; +} + +div.desc { + padding: 15px; + text-align: center; +} + +form{ + + width: 50%; } \ No newline at end of file diff --git a/templates/navigation2.html b/templates/navigation2.html index 6beda5045dfd2581103fee77a153d933a9f969f1..84375d313120d57957bfe39fdd960f9f44a291d9 100644 --- a/templates/navigation2.html +++ b/templates/navigation2.html @@ -6,6 +6,7 @@ <li><a href="?page=add_artist" title="">Add Artists</a></li> <li><a href="?page=add_record" title="Add record">Add Record</a></li> <li><a href="?page=add_image" title="Add record">Upload Image</a></li> + <li><a href="?page=manage_albums" title="Add record">Manage Albums</a></li> <li><a href="?page=logout">Logout</a></li> </ul> </nav> \ No newline at end of file diff --git a/views/album.php b/views/album.php index 26e0100d01d246edc5100898437e36a4a62a2336..213e48d758a7c3b92f213712e99e62fbd50f1a61 100644 --- a/views/album.php +++ b/views/album.php @@ -12,7 +12,7 @@ $sql = "SELECT A.title, A.genreName, A.price, b.name FROM artist b, (SELECT a.t ON a.genre_id = g.id) as A WHERE A.artist_id = b.id"; */ -$sql = "SELECT a.name, a.lastName, al.title, a.id, al.price +$sql = "SELECT a.name, a.lastName, al.title, a.id, al.price, al.cover FROM artist a INNER JOIN album al ON al.artist_id=a.id"; @@ -36,6 +36,9 @@ $content .= " <th>".Album."</th>"; $content .= " <th>".Artist."</th>"; $content .= " <th>".Price."</th>"; $content .= " <th>".Price."</th>"; +$content .= " <th>".Cover."</th>"; + + // fetch associative array while ($row = mysqli_fetch_assoc($result)) { @@ -54,6 +57,9 @@ $content .= " <th>".Price."</th>"; //fetching prices in euro in real time $content .= "<td>€".currencyConverter("GBP","EUR",$row['price'])."</td>"; + $content .= "<td><img src=".$row['cover']." width='50' height='50'>"; +/* $content .=" "; */ +