Example #1
0
 public static function select($id)
 {
     $connection = Flight::dbMain();
     try {
         $sql = "SELECT * FROM app_info WHERE id = :id;";
         $query = $connection->prepare($sql);
         $query->bindParam(':id', $id, PDO::PARAM_INT);
         $query->execute();
         if ($query->rowCount() < 1) {
             return null;
         }
         $row = $query->fetch(PDO::FETCH_ASSOC);
         $appInfo = new AppInfo();
         $appInfo->Id = (int) $row['id'];
         $appInfo->Name = $row['info_name'];
         $appInfo->Value = (int) $row['info_value'];
         $appInfo->Desc = $row['info_desc'];
         return $appInfo;
     } catch (PDOException $pdoException) {
         Flight::error($pdoException);
     } catch (Exception $exception) {
         Flight::error($exception);
     } finally {
         $connection = null;
     }
 }
Example #2
0
 public static function logout()
 {
     $connection = Flight::dbMain();
     try {
         // $sql = "
         // DELETE FROM user
         // WHERE
         // id = :id";
         // $query = $connection->prepare($sql);
         // $query->bindParam(':id', $id, PDO::PARAM_INT);
         // $query->execute();
         $result = new Result();
         $result->Status = Result::SUCCESS;
         $result->Message = 'Done';
         //$result->Id = $id;
         Flight::ok($result);
     } catch (PDOException $pdoException) {
         Flight::error($pdoException);
     } catch (Exception $exception) {
         Flight::error($exception);
     } finally {
         $connection = null;
     }
 }
Example #3
0
 public static function insert()
 {
     $connection = Flight::dbMain();
     $dateTime = Flight::dateTime();
     try {
         $unitData = json_decode(file_get_contents("php://input"));
         if ($unitData == null) {
             throw new Exception(json_get_error());
         }
         /* Begin Transaction */
         $connection->beginTransaction();
         //Query 1 //=================================
         $sql = "\n\t\t\tINSERT INTO unitData \n\t\t\t(UnitData_imei, UnitData_serial_number, sim_id, UnitData_type_id, company_id, e_status_UnitData_id, UnitData_dt_created)\n\t\t\tVALUES\n\t\t\t(:UnitData_imei, :UnitData_serial_number, :sim_id, :UnitData_type_id, :company_id, :e_status_UnitData_id, :UnitData_dt_created);";
         $query = $connection->prepare($sql);
         $query->bindParam(':UnitData_imei', $unitData->Imei, PDO::PARAM_INT);
         $query->bindParam(':UnitData_serial_number', $unitData->SerialNumber, PDO::PARAM_STR);
         $query->bindParam(':sim_id', $unitData->Sim->Id, PDO::PARAM_INT);
         $query->bindParam(':UnitData_type_id', $unitData->UnitDataType->Id, PDO::PARAM_INT);
         $query->bindParam(':company_id', $unitData->Company->Id, PDO::PARAM_INT);
         $query->bindParam(':e_status_UnitData_id', $unitData->UnitDataStatus->Id, PDO::PARAM_INT);
         $query->bindParam(':UnitData_dt_created', $dateTime, PDO::PARAM_STR);
         $query->execute();
         $result = new Result();
         $result->Status = Result::INSERTED;
         $result->Id = $connection->lastInsertId();
         $result->Message = 'Done';
         //Query 2 //=================================
         $year = date('Y');
         $schema = "app_data_{$year}";
         // $tableName = "data_id_" .  $result->Id;
         $imei = $unitData->Imei;
         $tableName = "data_{$imei}";
         $sql = "\n\t\t\tCREATE TABLE IF NOT EXISTS `" . $schema . "`.`" . $tableName . "` (\n\t\t\t`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '',\n\t\t\t`dt_server` TIMESTAMP NULL COMMENT '',\n\t\t\t`dt_device` TIMESTAMP NULL COMMENT '',\n\t\t\t`command` SMALLINT NULL COMMENT '',\n\t\t\t`event` SMALLINT NULL COMMENT '',\n\t\t\t`byte` BIGINT NULL COMMENT '',\n\t\t\t`latitude` DOUBLE NULL COMMENT '',\n\t\t\t`longitude` DOUBLE NULL COMMENT '',\n\t\t\t`altitude` DOUBLE NULL COMMENT '',\n\t\t\t`rfid` BIGINT NULL COMMENT '',\n\t\t\t`mode` TINYINT NULL COMMENT '',\n\t\t\t`speed` SMALLINT NULL COMMENT '',\n\t\t\t`time` BIGINT NULL COMMENT '',\n\t\t\t`odometer` BIGINT NULL COMMENT '',\n\t\t\t`heading` SMALLINT NULL COMMENT '',\n\t\t\t`picture` BIGINT NULL COMMENT '',\n\t\t\t`gps_satellite` SMALLINT NULL COMMENT '',\n\t\t\t`gps_status` SMALLINT NULL COMMENT '',\n\t\t\t`gps_accuracy` SMALLINT NULL COMMENT '',\n\t\t\t`gprs_signal` SMALLINT NULL COMMENT '',\n\t\t\t`gprs_status` VARCHAR(25) NULL COMMENT '',\n\t\t\t`di_0` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_1` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_2` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_3` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_4` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_5` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_6` SMALLINT NULL COMMENT '',\n\t\t\t`di_7` SMALLINT NULL COMMENT '',\n\t\t\t`di_8` SMALLINT NULL COMMENT '',\n\t\t\t`di_9` TINYINT(1) NULL COMMENT '',\n\t\t\t`di_10` TINYINT(1) NULL COMMENT '',\n\t\t\t`do_0` TINYINT(1) NULL COMMENT '',\n\t\t\t`do_1` TINYINT(1) NULL COMMENT '',\n\t\t\t`do_2` TINYINT(1) NULL COMMENT '',\n\t\t\t`do_3` TINYINT(1) NULL COMMENT '',\n\t\t\t`ai_0` SMALLINT NULL COMMENT '',\n\t\t\t`ai_1` SMALLINT NULL COMMENT '',\n\t\t\t`ai_2` SMALLINT NULL COMMENT '',\n\t\t\t`ai_3` SMALLINT NULL COMMENT '',\n\t\t\t`ai_4` SMALLINT NULL COMMENT '',\n\t\t\t`ai_5` SMALLINT NULL COMMENT '',\n\t\t\t`ai_6` SMALLINT NULL COMMENT '',\n\t\t\t`ai_7` SMALLINT NULL COMMENT '',\n\t\t\t`ai_8` SMALLINT NULL COMMENT '',\n\t\t\t`ai_9` SMALLINT NULL COMMENT '',\n\t\t\t`ao_0` SMALLINT NULL COMMENT '',\n\t\t\t`ao_1` SMALLINT NULL COMMENT '',\n\t\t\t`ao_2` SMALLINT NULL COMMENT '',\n\t\t\t`ao_3` SMALLINT NULL COMMENT '',\n\t\t\tPRIMARY KEY (`id`)  COMMENT '')\n\t\t\tENGINE = InnoDB\n\t\t\tPACK_KEYS = DEFAULT\n\t\t\tKEY_BLOCK_SIZE = 8;";
         $query = $connection->prepare($sql);
         $query->execute();
         $connection->commit();
         Flight::ok($result);
     } catch (PDOException $pdoException) {
         $connection->rollBack();
         Flight::error($pdoException);
     } catch (Exception $exception) {
         $connection->rollBack();
         Flight::error($exception);
     } finally {
         $connection = null;
     }
 }
Example #4
0
function handle_login()
{
    $request = Flight::request();
    //login/?gw_address=%s&gw_port=%d&gw_id=%s&url=%s
    // If we get called without the gateway parameters, then we better
    // have these in the session already.
    // Initialize or update session parameters
    update_session($request);
    // If we have no session parameters now, we never had them
    if (!is_session_valid()) {
        Flight::error(new Exception('Gateway parameters not set in login handler!'));
    }
    render_boilerplate();
    fblogin();
}
Example #5
0
 static function validate()
 {
     $valid = JWTHelper::authenticate(apache_request_headers());
     if ($valid) {
         echo "Yep.";
     } else {
         Flight::error();
     }
 }
Example #6
0
        Flight::error($exception);
    }
});
Flight::route('POST /v1/main/poi', function () {
    try {
        $object = Poi::insert();
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('PUT /v1/main/poi/@id', function ($id) {
    try {
        $object = Poi::update($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('DELETE /v1/main/poi/@id', function ($id) {
    try {
        $object = Poi::delete($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
//=========================================================================
Flight::set('flight.log_errors', true);
Flight::set('flight.handle_errors', true);
Flight::start();