Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
    session_start();

    header("Access-Control-Allow-Origin: *");
    header('Content-Type: application/json; charset=UTF-8');

    require_once("constants.php");

	require_once("repositories/LocalRepository.php");
    require_once("repositories/UserRepository.php");
	require_once("classes/Local.php");

    require_once("utilities.php");

	$servername = "localhost";
	$username = "smartcharging";
	$password = "LXRLBaEAuRr7M7jY";

	//$params = json_decode($_REQUEST["params"], true);

    //$input = file_get_contents('php://input');
    $params = json_decode(file_get_contents('php://input'), true);

	$conn;
	$risposta = array();
    $statusUser;
    $statusLocal;
	$local = new Local();
	$local_repo;

	try {
        $conn = new PDO("mysql:host=".$servername.";dbname=smartcharging", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        //echo "Connesso con successo al DB";

        if (!array_key_exists("token", $params) || !UserRepository::checkToken($params["token"], $conn)) {
            $risposta["return"] = -1;
            echo json_encode($risposta);
            die();
        }

        $local_repo = new LocalRepository($conn);

        $local->id_utente_owner = $params["user_id"];
        $local->nomelocale      = $params["nomelocale"];
        $local->descrizione     = array_key_exists("descrizione", $params)          ? $params["descrizione"] : "";
        $local->tipologia       = $params["tipologia"];
        //$local->imgs            = $params["imgs"];
        $local->lat             = array_key_exists("lat", $params)                  ? $params["lat"] : null;
        $local->lon             = array_key_exists("lon", $params)                  ? $params["lon"] : null;
        $local->indirizzo       = array_key_exists("indirizzo", $params)            ? $params["indirizzo"] : null;
        $local->email           = array_key_exists("email", $params)                ? $params["email"] : "";
        $local->telefono        = array_key_exists("telefono", $params)             ? $params["telefono"] : "";
        $local->sito            = array_key_exists("sito", $params)                 ? $params["sito"] : "";

        $statusLocal = $local_repo->registerLocal($local);      
        $risposta["local_id"] = $statusLocal["local_id"];      
        $risposta["return"] = $statusLocal["return"];


        $localImgs = array_key_exists("imgs", $params) ? $params["imgs"] : null;

        if ($risposta["return"] == 0 && count($localImgs)>0) {
            foreach($localImgs as $image) {
                //rename($_SERVER['DOCUMENT_ROOT'].TEMP_IMAGES_PATH.session_id()."/".$image, $_SERVER['DOCUMENT_ROOT'].IMAGES_PATH.$image);
                rename($_SERVER['DOCUMENT_ROOT'].TEMP_IMAGES_PATH."/".$image, $_SERVER['DOCUMENT_ROOT'].IMAGES_PATH.$image);
            }
            //rmdir("./images/temp/".session_id()."/");
            //deleteDirectory($_SERVER['DOCUMENT_ROOT'].TEMP_IMAGES_PATH.session_id()."/");
            $local_repo->addImages($risposta["local_id"], $localImgs);
        }

        //unset($_SESSION["images"]);

        echo json_encode($risposta);
    }
	catch(PDOException $e)
    {
   		echo $e->getMessage();
        $risposta["local_id"] = -1;
   		$risposta["return"] = 3;
    } finally {
        $conn = null; //Close the connection to the DBMS    
    }
	

?>

Commits for Nextrek/Android/SmartCharging/endPoints/add_locale.php

Diff revisions: vs.
Revision Author Commited Message
507 FSallustio picture FSallustio Thu 20 Aug, 2015 07:51:22 +0000

Merge ramo stable con la nightly.