| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- $http_host = $_SERVER['HTTP_HOST'];
- include("../../functions.php");
- $con = startdb('rw');
- if (!checkSession($con)){
- header("Location: /index.php");
- exit (-1);
- }
- else{
- // Get post data
- $title_es = mysqli_real_escape_string($con, $_POST['title_es']);
- $title_eu = mysqli_real_escape_string($con, $_POST['title_eu']);
- $title_en = mysqli_real_escape_string($con, $_POST['title_en']);
- $text_es = mysqli_real_escape_string($con, $_POST['text_es']);
- $text_eu = mysqli_real_escape_string($con, $_POST['text_eu']);
- $text_en = mysqli_real_escape_string($con, $_POST['text_en']);
- $image = array();
- $image[0] = $_FILES['image_0'];
- $image[1] = $_FILES['image_1'];
- $image[2] = $_FILES['image_2'];
- $image[3] = $_FILES['image_3'];
- $comments = mysqli_real_escape_string($con, $_POST['comments']);
- $visible = mysqli_real_escape_string($con, $_POST['visible']);
- $admin = mysqli_real_escape_string($con, $_POST['admin']);
- $schedule = mysqli_real_escape_string($con, $_POST['schedule']);
- $city = mysqli_real_escape_string($con, $_POST['city']);
- $day = mysqli_real_escape_string($con, $_POST['day']);
- $month = mysqli_real_escape_string($con, $_POST['month']);
- $year = mysqli_real_escape_string($con, $_POST['year']);
- $price = mysqli_real_escape_string($con, $_POST['price']);
- $inscription = mysqli_real_escape_string($con, $_POST['inscription']);
- $people = mysqli_real_escape_string($con, $_POST['people']);
- //Check spanish title and generate permalink
- if ($title_es == null){
- exit();
- }
- else{
- $permalink = permalink($title_es);
- $i = 2;
- $ok = false;
- $tmppermalink = $permalink;
- while ($ok == false){
- $query = mysqli_query($con, "SELECT id FROM activity WHERE permalink = '$tmppermalink';");
- if (mysqli_num_rows($query) > 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/");
- }
- }
- ?>
|