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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
    session_start();

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

    require_once("constants.php");

    require_once("repositories/UserRepository.php");
    require_once("classes/User.php");
	require_once("repositories/LocalRepository.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;
    $user = new User();
    $user_repo;
	$local = new Local();
	$local_repo;

    if (is_null($params)) {
        $risposta = createErrorMessage(-1, "Nessun parametro passato");
        echo json_encode($risposta);
        die();
    }

    if (!array_key_exists("username", $params) || $params["username"] === "") {
        $risposta = createErrorMessage(-1, "Parametro \"username\" non valido");
        echo json_encode($risposta);
        die();
    }

    if (!array_key_exists("password", $params) || $params["password"] === "") {
        $risposta = createErrorMessage(-1, "Parametro \"password\" non valido");
        echo json_encode($risposta);
        die();
    }

    if (!array_key_exists("nome", $params) || $params["nome"] === "") {
        $risposta = createErrorMessage(-1, "Parametro \"nome\" non valido");
        echo json_encode($risposta);
        die();
    }

    if (!array_key_exists("cognome", $params) || $params["cognome"] === "") {
        $risposta = createErrorMessage(-1, "Parametro \"cognome\" non valido");
        echo json_encode($risposta);
        die();
    }

	try {
        $conn = new PDO("mysql:host=".DB_SERVERNAME.";dbname=".DB_NAME, DB_USERNAME, DB_PASSWORD);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        //echo "Connesso con successo al DB";

        $user_repo = new UserRepository($conn);

        $user->username         = $params["username"];
        //$user->nominativo       = $params["nominativo"];
        $user->nome             = $params["nome"];
        $user->cognome          = $params["cognome"];
        $user->cell             = $params["cell"];
        $user->email            = $params["email"];
        //$user->avatar           = $params["avatar"];
        //$user->is_owner         = 1; //รจ un gestore in questo caso

        $statusUser = $user_repo->registerUser($user, $params["password"]);
        $risposta["user_id"] = $statusUser["id"];
        $risposta["token"] = $statusUser["token"];

        $strToHash = $user->username.$user->nome.$user->cognome.$user->cell.$user->email;

        if ($params["avatar"] != "") {
            $imgExtention = substr(strrchr($params["avatar"],'.'),1);
            $risposta["avatar_name"] = uniqid().".".$imgExtention;
        }
        if ($statusUser["return"]!=0) {
            echo json_encode($statusUser);
        } else {
            $local_repo = new LocalRepository($conn);

            $local->id_utente_owner     = $risposta["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            = array_key_exists("telefono", $params)             ? $params["telefono"] : "";
            $local->sito                = array_key_exists("sito", $params)                 ? $params["sito"] : "";
            $local->n_punti_ricarica    = $params["n_punti_ricarica"];

            $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 && $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 = createErrorMessage(3, "Errore DB");
        $risposta["user_id"] = -1;
        $risposta["local_id"] = -1;
   		//$risposta["return"] = 3;
    } finally {
        $conn = null; //Close the connection to the DBMS    
    }
	

?>

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

Diff revisions: vs.
Revision Author Commited Message
621 Diff Diff FSallustio picture FSallustio Mon 31 Aug, 2015 13:06:11 +0000
615 Diff Diff FSallustio picture FSallustio Mon 31 Aug, 2015 09:48:28 +0000
614 Diff Diff FSallustio picture FSallustio Mon 31 Aug, 2015 09:46:02 +0000
579 Diff Diff FSallustio picture FSallustio Thu 27 Aug, 2015 08:25:11 +0000
507 Diff Diff FSallustio picture FSallustio Thu 20 Aug, 2015 07:51:22 +0000

Merge ramo stable con la nightly.

465 Diff Diff FSallustio picture FSallustio Mon 03 Aug, 2015 12:59:41 +0000
441 Diff Diff FSallustio picture FSallustio Tue 28 Jul, 2015 08:01:07 +0000

Rimossa creazione delle cartelle temporanee per le immagini (ora verranno tutte salvate nella root di temp)

310 Diff Diff FSallustio picture FSallustio Tue 14 Jul, 2015 07:27:01 +0000
309 Diff Diff FSallustio picture FSallustio Mon 13 Jul, 2015 16:08:26 +0000
300 FSallustio picture FSallustio Mon 13 Jul, 2015 15:15:58 +0000