<?php
require_once(dirname(__FILE__).'/../../../param/parameters.php');
require_once(dirname(__FILE__).'/../lib/class.MySQL.php');
require_once(dirname(__FILE__).'/class.Log.php');
define('EPSILON', 1.0e-8);
/**
* fIsEqual function
*
* @param float $a
* @param float $b
* @return bool returns TRUE if difference is less than EPSILON
*/
function fIsEqual($a, $b){
$diff = $a - $b;
return (( abs($diff) < EPSILON )?TRUE:FALSE);
}//_fIsEqual
/**
* ImportException class
*
* @author Olivier G <hide@address.com>
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://gemibloo.fr
*/
class ImportException extends Exception {
const MAILBOX_REQUEST_FAILED = 1001;
const MESSAGE_REQUEST_FAILED = 1002;
const DATABASE_FAILED = 1003;
public $response;
/**
* __construct
*/
function __construct($msg, $code, $response=null) {
parent::__construct($msg, $code);
$this->response = $response;
}//__construct
}//ImportException
/**
* PluginImport class
*
*This abstract class manages only data insert into DB. Derived classes implements
*the very import method.
*
* @author Olivier G <hide@address.com>
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://gemibloo.fr
*/
abstract class PluginImport{
protected $_newData = false;
/**
* fHasNewData method
*
*/
public function fHasNewData(){
return $_newData;
}
/**
* fImport method
*
* This method must be defined in inherited class
*/
abstract protected function fImport();
/**
* fInsert method
*
*/
protected function _fInsert($aLat, $aLng, $aContent, $aTimestamp, $aFilename, $aRatioHW, $aPlacemark){
$db = new MySQL();
if (FALSE === $db->Open(DB_DATABASE, DB_SERVER, DB_USR, DB_PWD)){
Log::fGetInstance()->fLog(Log::$TYPE['error'] ,__CLASS__, 'Insert in database failed: ('.$aLat."'".$aLng."'".$aContent."'".$aTimestamp."'".$aFilename."'".$aRatioHW."'".$aPlacemark.')');
throw new ImportException("Connection with database KO.", ImportException::DATABASE_FAILED);
}
if(FALSE === $db->Query('INSERT INTO Gemibloo_main_'.GEMIBLOO_VERSION.' (lat, lng, content, timestamp, image, ratioHW, location) VALUES ('.$aLat.",".$aLng.",'".$aContent."',".$aTimestamp.",'".$aFilename."',".$aRatioHW.",'".$aPlacemark."');"))
{
Log::fGetInstance()->fLog(Log::$TYPE['error'] ,__CLASS__, 'Insert in database failed: ('.$aLat."'".$aLng."'".$aContent."'".$aTimestamp."'".$aFilename."'".$aRatioHW."'".$aPlacemark.')');
throw new ImportException("Data cannot be inserted in database.", ImportException::DATABASE_FAILED);
}
Log::fGetInstance()->fLog(Log::$TYPE['info'] ,__CLASS__, 'New insert in database: ('.$aLat."'".$aLng."'".$aContent."'".$aTimestamp."'".$aFilename."'".$aRatioHW."'".$aPlacemark.')');
}//fInsert
}//Import
?>