$images = photo_parse_scale_input(); $created_albums = array(); foreach ($images as $image) { /* If the user has choosen to create a new album, do that. But first, check if the album has been created recently, if so use the ID stored in $created_albums, otherwise create a new album and cache it in $created_albums. */ if (!is_numeric($image['album'])) { if (isset($created_albums[$image['album']])) { $image['album'] = $created_albums[$image['album']]; } else { $album['owner'] = $_SESSION['login']['id']; $album['owner_type'] = 'user'; $album['label'] = $image['album']; $created_albums[$image['album']] = photo_create_album($album); $image['album'] = $created_albums[$image['album']]; } } $image['owner'] = $_SESSION['login']['id']; $image['owner_type'] = 'user'; photo_create_image($image); } echo '<h1>Dina bilder är uppladdade - såhär blev det</h1>' . "\n"; photo_list_thumbs(array('images' => $images)); echo '<p>Nu kan du gå till <a href="#">startsidan i ditt fotoalbum</a>, <a href="#">ändra inställningar för ditt fotoalbum</a> eller <a href="#">ladda upp fler bilder</a></p>' . "\n"; break; case 'upload': $filenames = photo_upload_to_temp(); photo_scale_and_comment_form(array('filenames' => $filenames, 'owner' => $_SESSION['login']['id'], 'owner_type' => 'user')); break;
function photo_scale_and_comment_form($parameters) { $crop_cords = array('x1', 'x2', 'y1', 'y2'); $count = 1; /* Fetch available albums, if album doesn't exist - try to create a default album */ $albums = photo_get_albums(array('owner_type' => $parameters['owner_type'], 'owner' => $parameters['owner'])); if (count($albums) == 0) { photo_create_album(array('owner' => $parameters['owner'], 'owner_type' => $parameters['owner_type'], 'default_category' => 'true')); $albums = photo_get_albums(array('owner_type' => $parameters['owner_type'], 'owner' => $parameters['owner'])); } if (count($albums) == 0) { die('<h1>Allvarligt internt fel!</h1><p>Inga album för detta mål existerar, försök att skapa album misslyckades. (Typ allt är trasigt, ungefär)</p>'); } echo '<form action="/fotoalbum/beskaer.php" method="post">' . "\n"; foreach ($parameters['filenames'] as $filename) { rounded_corners_top(array('color' => 'white')); echo '<h2>' . $filename['original_name'] . '</h2>' . "\n"; $img_url = PHOTO_UPLOAD_TEMP_URL . $filename['tmp_name'] . '.jpg'; foreach ($crop_cords as $field) { echo '<input type="hidden" name="' . $field . '_' . $filename['tmp_name'] . '" id="' . $field . '_' . $filename['tmp_name'] . '" />' . "\n"; } echo '<script type="text/javascript" charset="utf-8">' . "\n"; echo 'function onEndCrop_' . $filename['tmp_name'] . '(coords, dimensions )' . "\n"; echo '{' . "\n"; foreach ($crop_cords as $field) { echo 'document.getElementById("' . $field . '_' . $filename['tmp_name'] . '").value = coords.' . $field . ";\n"; } echo '}' . "\n"; echo 'womAdd("new Cropper.Img(\'crop_' . $filename['tmp_name'] . '\',{onEndCrop: onEndCrop_' . $filename['tmp_name'] . '})");' . "\n"; echo '</script>' . "\n"; echo '<div class="photo_upload_inputs">' . "\n"; echo '<div class="description_input">' . "\n"; echo '<h5>Frivillig kommentar / beskrivning</h5>' . "\n"; echo '<textarea name="description_' . $filename['tmp_name'] . '"></textarea>' . "\n"; echo '</div>' . "\n"; // echo '<input type="checkbox" name="maximize_' . $filename['tmp_name'] . '" id="maximize_' . $filename['tmp_name'] . '" value="true" />' . "\n"; // echo '<label for="maximize_' . $filename['tmp_name'] . '">Förstora markeringen</label>' . "\n"; echo '<div class="date_and_album_input">' . "\n"; /* Date select */ echo '<h5>När togs fotot?</h5>' . "\n"; echo '<select name="date_' . $filename['tmp_name'] . '">' . "\n"; echo '<option value="' . date('Y-m-d') . '">Idag</option>' . "\n"; echo '<option value="' . date('Y-m-d', strtotime('yesterday')) . '">Igår</option>' . "\n"; for ($j = 2; $j < 10; $j++) { echo '<option value="' . date('Y-m-d', time() - 86400 * $j) . '">' . date('D j/n', time() - 86400 * $j) . '</option>' . "\n"; } echo '<option value="text_input">Annat datum</option>' . "\n"; echo '</select>' . "\n"; /* Album select */ echo '<h5>Fotoalbum</h5>' . "\n"; echo '<select name="album_' . $filename['tmp_name'] . '" class="photo_upload_album_select">' . "\n"; foreach ($albums as $album) { echo '<option value="' . $album['id'] . '">' . $album['label'] . '</option>' . "\n"; } echo '<option value="text_input">Nytt album</option>' . "\n"; echo '</select>' . "\n"; echo '</div>' . "\n"; echo '</div>' . "\n"; echo '<h5>Klicka och dra i bilden för att markera det du vill ha med</h5>' . "\n"; echo '<div class="photo_resize">' . "\n"; echo '<img src="' . $img_url . '" alt="test image" id="crop_' . $filename['tmp_name'] . '" />' . "\n"; echo '</div>' . "\n"; $count++; rounded_corners_bottom(array('color' => 'white')); } echo '<input type="submit" value="Beskär och spara" />' . "\n"; echo '</form>' . "\n"; }