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
<?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     = $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           = $params["email"];
        $local->telefono        = $params["telefono"];
        $local->sito            = $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);
            }
            //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/nightly/add_locale.php

Diff revisions: vs.
Revision Author Commited Message
424 Diff Diff FSallustio picture FSallustio Wed 22 Jul, 2015 14:40:43 +0000

Aggiunto supporto token ad alcune chiamate.

423 Diff Diff FSallustio picture FSallustio Wed 22 Jul, 2015 13:45:01 +0000
417 FSallustio picture FSallustio Wed 22 Jul, 2015 10:09:37 +0000

giro della registrazione modificato e chiamate add_locale.php e get_locals_by_user.php implementate.