0){ $tmppermalink = $permalink . "-" . $i; $i ++; } else{ $permalink = $tmppermalink; $ok = true; } } } //Check city if ($city == ''){ $city = 'Vitoria-Gasteiz'; } //Check booleans and assign default values if not if ($comments == 'off'){ $comments = 0; } else{ $comments = 1; } if ($visible == 'off'){ $visible = 0; } else{ $visible = 1; } if ($admin == 'on'){ $admin = 1; } else{ $admin = 0; } if ($inscription == 'off'){ $inscription = 0; } else{ $inscription = 1; } //TODO: Check valid date if ($day == '' || $month == '' || $year == ''){ exit(); } $date = "str_to_date('$year-$month-$day', '%Y-%m-%d')"; //Assign numeric inputs, defaulting to 0 if not numeric $price = intval($price); $people = intval($people); // If no translations, same text in all languages if (strlen($text_eu) == 0){ $text_eu = $text_es; $title_eu = $title_es; } if (strlen($text_en) == 0){ $text_en = $text_es; $title_en = $title_es; } //Get user if ($admin){ $user = 0; } else{ $user = $_SESSION["id"]; } //Insert into database and get id mysqli_query($con, "INSERT INTO activity (permalink, date, title_es, title_eu, title_en, text_es, text_eu, text_en, price, inscription, max_people, user, visible, comments, city) VALUES('$permalink', $date, '$title_es', '$title_eu', '$title_en', '$text_es', '$text_eu', '$text_en', $price, $inscription, $people, $user, $visible, $comments, '$city');"); $q = mysqli_query($con, "SELECT id FROM activity WHERE permalink = '$permalink' ORDER BY dtime DESC LIMIT 1;"); $r = mysqli_fetch_array($q); $id = $r['id']; //Process images $file_idx = 0; $img_idx = 0; while ($file_idx < 4 && $img_idx < 4){ if (file_exists($image[$file_idx]['tmp_name']) > 0){ //Convert to jpg $im = new imagick($image[$file_idx]['tmp_name']); $im->setImageFormat('jpg'); $im->writeImage("../../../www/img/actividades/$permalink-n$img_idx.jpg"); $im->resizeImage(800, 800, Imagick::FILTER_POINT, false); $im->writeImage("../../../www/img/actividades/view/$permalink-n$img_idx.jpg"); $im->resizeImage(600, 600, Imagick::FILTER_POINT, false); $im->writeImage("../../../www/img/actividades/preview/$permalink-n$img_idx.jpg"); $im->resizeImage(340, 340, Imagick::FILTER_POINT, false); $im->writeImage("../../../www/img/actividades/miniature/$permalink-n$img_idx.jpg"); $im->resizeImage(180, 180, Imagick::FILTER_POINT, false); $im->writeImage("../../../www/img/actividades/thumb/$permalink-n$img_idx.jpg"); $im->clear(); $im->destroy(); //Database mysqli_query($con, "INSERT INTO activity_image (activity, image, idx) VALUES ($id, '$permalink-n$img_idx.jpg', $img_idx);"); $img_idx ++; } $file_idx ++; } //Edit schedule if requires, return if not if ($schedule == 'on'){ header("Location: /actividades/add/itinerary.php?id=$id"); } else{ header("Location: /actividades/"); } } ?>