function deleteAlbumChild($currentUserId, $db, $albumId) { $query_for_parent_album = "SELECT parentAlbumId, id, ownerId, name FROM albums WHERE id='" . mysql_real_escape_string($albumId) . "'"; $parent_album = mysql_fetch_assoc($db->query($query_for_parent_album)); if (!empty($parent_album)) { if ($parent_album['ownerId'] == $currentUserId) { $albumsChild = $db->query('SELECT * FROM albums WHERE parentAlbumId="' . $albumId . ' "'); if (!empty($albumsChild)) { while ($childAlbum = mysql_fetch_array($albumsChild)) { $images = $db->query('SELECT * FROM imagestoalbums WHERE albumId=' . $childAlbum['id']); if (!empty($images)) { while ($image = mysql_fetch_array($images)) { $delete_sql_string = 'DELETE FROM imagestoalbums WHERE imageId="' . $image['imageId'] . '" AND albumId="' . $childAlbum['id'] . '"'; $db->query($delete_sql_string); deleteImage($currentUserId, $db, $image['imageId']); } } deleteAlbumChild($currentUserId, $db, $childAlbum['id']); $delete_sql_string = 'DELETE FROM albums WHERE id="' . $childAlbum['id'] . '" '; $db->query($delete_sql_string); } } } } }
header('Location: ./index.html'); exit; } } if ($album['ownerId'] != $currentUser['id']) { $denied = true; if (!$phpunit['isTest']) { include dirname(__FILE__) . '/../common/error401.php'; exit; } $accessDenied = true; } } } if (isset($_POST["Delete"])) { deleteAlbumChild($currentUser['id'], $db, $_POST["albumId"]); $images = $db->query('SELECT * FROM imagestoalbums WHERE albumId="' . $_POST["albumId"] . '"'); if (!empty($images)) { while ($image = mysql_fetch_array($images)) { $delete_sql_string = 'DELETE FROM imagestoalbums WHERE imageId="' . $image['imageId'] . '" AND albumId="' . $_POST["albumId"] . '"'; $db->query($delete_sql_string); deleteImage($currentUser['id'], $db, $image['imageId']); } } $delete_sql_string = 'DELETE FROM albums WHERE id="' . $_POST["albumId"] . '" '; $db->query($delete_sql_string); if (!$phpunit['isTest']) { header('Location: ./index.html?id=' . $album['parentAlbumId']); exit; } }