125 lines
3.1 KiB
PHP
Executable File
125 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Main Class
|
|
* @author franzz
|
|
* @version 0.1
|
|
*/
|
|
class Pedidor extends Main
|
|
{
|
|
//SQL tables
|
|
const USER_TABLE = 'users';
|
|
const MATL_TABLE = 'materials';
|
|
const ORDER_TABLE = 'orders';
|
|
|
|
private $oAuth;
|
|
|
|
public function __construct($oClassManagement, $sProcessPage)
|
|
{
|
|
parent::__construct($oClassManagement, $sProcessPage);
|
|
|
|
//Load classes
|
|
$this->oClassManagement->incClass('auth', true);
|
|
|
|
//Init objects
|
|
$this->oAuth = new Auth($this->oMySql, Settings::API_KEY);
|
|
}
|
|
|
|
private function install()
|
|
{
|
|
$this->oAuth = new Auth($this->oMySql, Settings::API_KEY, false);
|
|
|
|
//Install DB
|
|
$this->oMySql->install();
|
|
$this->addUser('franzz');
|
|
$this->addUser('laura');
|
|
}
|
|
|
|
/* Authorizations handling */
|
|
|
|
public function isLoggedIn()
|
|
{
|
|
return $this->oAuth->isLoggedIn();
|
|
}
|
|
|
|
public function logMeIn($sToken)
|
|
{
|
|
return $this->oAuth->logMeIn($sToken);
|
|
}
|
|
|
|
public function checkApiKey($sApiKey)
|
|
{
|
|
return $this->oAuth->checkApiKey($sApiKey);
|
|
}
|
|
|
|
/* Building main pages */
|
|
|
|
public function getPage($bLoggedIn)
|
|
{
|
|
//Constants
|
|
$asPages = array_values($this->asMasks);
|
|
unset($asPages['index']);
|
|
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
|
|
$asGlobalVars['consts']['token_sep'] = Auth::TOKEN_SEP;
|
|
$asGlobalVars['consts']['error'] = self::ERROR;
|
|
$asGlobalVars['consts']['success'] = self::SUCCESS;
|
|
$asGlobalVars['consts']['context'] = $this->asContext;
|
|
$asGlobalVars['vars']['id'] = $this->oAuth->getUserId();
|
|
$asGlobalVars['vars']['log_in'] = $bLoggedIn;
|
|
|
|
//Main Page
|
|
$sPage = $this->getPageContent('index');
|
|
$sPage = str_replace('asGlobalVars', json_encode($asGlobalVars), $sPage);
|
|
return $sPage;
|
|
}
|
|
|
|
/* DB structure. See MySqlManager::__construct */
|
|
|
|
private static function getSqlOptions()
|
|
{
|
|
return array
|
|
(
|
|
'tables' => array
|
|
(
|
|
self::USER_TABLE =>array(MySqlManager::getText(self::USER_TABLE), 'nickname', 'pass', 'cookie'),
|
|
self::THOUGHT_TABLE =>array(MySqlManager::getId(self::USER_TABLE),
|
|
MySqlManager::getText(self::THOUGHT_TABLE)),
|
|
self::SETTINGS_TABLE=>array(MySqlManager::getId(self::USER_TABLE),
|
|
MySqlManager::getText(self::SETTINGS_TABLE),
|
|
'value')
|
|
),
|
|
'types' => array
|
|
(
|
|
MySqlManager::getText(self::USER_TABLE)=>"varchar(50) NOT NULL",
|
|
'nickname'=>'varchar(60) NOT NULL',
|
|
'pass'=>"varchar(256) NOT NULL",
|
|
'cookie'=>"varchar(255) NOT NULL",
|
|
MySqlManager::getText(self::THOUGHT_TABLE)=>"longtext",
|
|
MySqlManager::getText(self::SETTINGS_TABLE)=>"varchar(20) NOT NULL",
|
|
'value'=>"varchar(20) NOT NULL"
|
|
),
|
|
'constraints' => array
|
|
(
|
|
self::USER_TABLE=>"UNIQUE KEY `username` (`".MySqlManager::getText(self::USER_TABLE)."`)"
|
|
),
|
|
'cascading_delete' => array
|
|
(
|
|
self::USER_TABLE=>array(self::SETTINGS_TABLE)
|
|
)
|
|
);
|
|
}
|
|
|
|
/* Pedidor public functions */
|
|
|
|
/* My Thoughts private functions */
|
|
|
|
private function addUser($sNickName, $bLogMeIn=false)
|
|
{
|
|
|
|
}
|
|
|
|
/* Static toolbox functions */
|
|
|
|
}
|
|
|
|
?>
|