if (isset($_POST['editAlbum'])) { $user = new User($_POST['editAlbum']); $user->editAlbum($_POST['i'], $_POST['albumName'], $_POST['description']); $statement = true; } else { if (isset($_POST['addAlbum'])) { $user = new User($_POST['addAlbum']); $statement = $user->addAlbum($_POST['albumName'], $_POST['description']); } else { if (isset($_POST['getPhoto'])) { $user = new User($_POST['getPhoto']); $statement = $user->getPhoto($_POST['i'], $_POST['j']); } else { if (isset($_POST['editPhoto'])) { $user = new User($_POST['editPhoto']); $user->editPhoto($_POST['i'], $_POST['j'], $_POST['description'], $_POST['photoDate']); $statement = true; } else { if (isset($_POST['addPhoto'])) { $user = new User($_POST['addPhoto']); $statement = $user->addPhoto($_POST['i'], $_POST['photoName'], $_POST['description'], $_POST['photoSize'], $_POST['photoDate'], $_POST['sourcePath']); } else { if (isset($_POST['deletePhoto'])) { $user = new User($_POST['deletePhoto']); if (is_array($_POST['j'])) { //allow to delete multiple photo at a times by pass array of integers rsort($_POST['j']); //to make sure that deletion will start for behind for ($i = 0; $i < count($_POST['j']); $i++) { $photoInfo = $user->getPhoto($_POST['i'], $_POST['j'][$i]); unlink($photoInfo['sourcePath']);
$userInfo = json_decode(file_get_contents('photo/' . $_SESSION['userID'] . '/userInfo.json'), true); $maxPhoto = 0; for ($i = 0; $i < count($userInfo['album']); $i++) { if ($maxPhoto < count($userInfo['album'][$i]['photo'])) { $maxPhoto = count($userInfo['album'][$i]['photo']); } } if ($_SERVER['REQUEST_METHOD'] == "POST") { include 'class.php'; $user = new User($_SESSION['userID']); $userInfo = $user->getUser(); $albumInfo = $user->getAlbum($_POST['editAlbumNo']); for ($j = count($albumInfo['photo']) - 1; $j >= 0; $j--) { if ($_POST['validPhoto'][$j] > 0) { if ($_POST['photoDesc'][$j] != $albumInfo['photo'][$j]['description'] || $_POST['date'][$j] != str_ireplace(" ", "T", $albumInfo['photo'][$j]['photoDate'])) { $user->editPhoto($_POST['editAlbumNo'], $j, $_POST['photoDesc'][$j], $_POST['date'][$j]); } } else { if ($_POST['validPhoto'][$j] == 0) { unlink($albumInfo['photo'][$j]['sourcePath']); unlink('photo/' . $_SESSION['userID'] . '/' . $albumInfo['albumID'] . '/thumbnail/' . $albumInfo['photo'][$j]['photoName']); $user->deletePhoto($_POST['editAlbumNo'], $j); } } } if ($albumInfo['albumName'] != $_POST['albumTitle'] || $albumInfo['description'] != $_POST['albumDesc']) { $user->editAlbum($_POST['editAlbumNo'], $_POST['albumTitle'], $_POST['albumDesc']); } unset($_POST); ?> <script src="jquery.js"></script>