Exemplo n.º 1
0
<?php

header('Access-Control-Allow-Origin: *');
require_once 'DbUpdate.php';
require_once 'DbStudent.php';
require_once 'GCM.php';
require_once 'Config.php';
/* header( "Location:http://itrackerapp.gear.host/ncigo/manager/" ); */
if (isset($_POST['tag']) && $_POST['tag'] != '') {
    $db = new DbUpdate();
    $dbStudent = new DbStudent();
    $tag = $_POST['tag'];
    $res = array("tag" => $tag, "error" => FALSE);
    if ($tag == "update") {
        $title = $_POST['title'];
        $body = $_POST['body'];
        $target = $_POST['target'];
        $source = $_POST['source'];
        $list = $dbStudent->getDevices();
        if ($list != false) {
            $devices = array();
            foreach ($list as $device) {
                $devices[] = $device['device_id'];
            }
            $result = $db->addUpdate($title, $body, $target, $source);
            $message = "New Update";
            $gcpm = new GCMPushMessage(gcmkey);
            $gcpm->setDevices($devices);
            if ($result != false) {
                $response = $gcpm->send($message, $result[0]);
                echo json_encode($result[0]);
Exemplo n.º 2
0
                } else {
                    $res["error"] = TRUE;
                    $res["error_msg"] = "Student status Not updated";
                    echo json_encode($res);
                }
            } else {
                $response["error"] = TRUE;
                $response["error_msg"] = "Unknown tag. Use a proper tag";
                echo json_encode($response);
            }
        }
    }
} else {
    if (isset($_GET['tag']) && $_GET['tag'] != '') {
        require_once 'DbStudent.php';
        $db = new DbStudent();
        $tag = $_GET['tag'];
        $res = array("tag" => $tag, "error" => FALSE);
        if ($tag == "student") {
            $student_no = $_GET['student_no'];
            $email = $_GET['email'];
            $password = $_GET['password'];
            $device_id = $_GET['reg_id'];
            $course = $_GET['course'];
            $status = $_GET['status'];
            $res = $db->addStudent($student_no, $email, $password, $device_id, $course, $status);
            if ($res != false) {
                if ($db->addDevices($student_no, $device_id)) {
                }
                $stat = $db->updateStatus($student_no, $status);
                if ($stat) {