masks
This commit is contained in:
1
.gitignore
vendored
Normal file → Executable file
1
.gitignore
vendored
Normal file → Executable file
@@ -1,2 +1,3 @@
|
|||||||
/.buildpath
|
/.buildpath
|
||||||
/.project
|
/.project
|
||||||
|
/settings.php
|
||||||
|
|||||||
217
inc/pedidor.php
217
inc/pedidor.php
@@ -7,62 +7,22 @@
|
|||||||
*/
|
*/
|
||||||
class Pedidor extends Main
|
class Pedidor extends Main
|
||||||
{
|
{
|
||||||
//Interface keywords
|
|
||||||
const SUCCESS = 'success';
|
|
||||||
const ERROR = 'error';
|
|
||||||
const UNAUTHORIZED = 'unauthorized';
|
|
||||||
const NOT_FOUND = 'unknown action';
|
|
||||||
|
|
||||||
//SQL tables
|
//SQL tables
|
||||||
const USER_TABLE = 'users';
|
const USER_TABLE = 'users';
|
||||||
const MATL_TABLE = 'materials';
|
const MATL_TABLE = 'materials';
|
||||||
const ORDER_TABLE = 'orders';
|
const ORDER_TABLE = 'orders';
|
||||||
|
|
||||||
//Pedidor
|
|
||||||
const URL_DATE_FORMAT = 'Ymd';
|
|
||||||
const LAYOUT_DATE_FORMAT = 'F \t\h\e jS, Y';
|
|
||||||
const MYSQL_DATE_FORMAT = 'Y-m-d';
|
|
||||||
const LAYOUT_TIME_FORMAT = 'G:i';
|
|
||||||
|
|
||||||
//Objects
|
|
||||||
private $oClassManagement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database Connection
|
|
||||||
* @var MySqlManager
|
|
||||||
*/
|
|
||||||
private $oMySql;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var Auth
|
|
||||||
*/
|
|
||||||
private $oAuth;
|
private $oAuth;
|
||||||
|
|
||||||
//Variables
|
|
||||||
private $asContext;
|
|
||||||
//...
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main constructor [to be called from index.php]
|
|
||||||
* @param ClassManagement $oClassManagement
|
|
||||||
* @param string $sLang
|
|
||||||
*/
|
|
||||||
public function __construct($oClassManagement, $sProcessPage)
|
public function __construct($oClassManagement, $sProcessPage)
|
||||||
{
|
{
|
||||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
parent::__construct($oClassManagement, $sProcessPage);
|
||||||
$this->oClassManagement = $oClassManagement;
|
|
||||||
$this->setContext($sProcessPage);
|
|
||||||
|
|
||||||
//Load classes
|
//Load classes
|
||||||
$this->oClassManagement->incClass('mysqlmanager');
|
|
||||||
$this->oClassManagement->incClass('auth', true);
|
$this->oClassManagement->incClass('auth', true);
|
||||||
//$this->oClassManagement->incClass('calendar', true);
|
|
||||||
|
|
||||||
//Init objects
|
//Init objects
|
||||||
$this->oMySql = new MySqlManager(Settings::DB_SERVER, Settings::DB_LOGIN, Settings::DB_PASS, Settings::DB_NAME, self::getSqlOptions() , Settings::DB_ENC);
|
$this->oAuth = new Auth($this->oMySql, Settings::API_KEY);
|
||||||
if($this->oMySql->sDbState == MySqlManager::DB_NO_DATA) $this->install();
|
|
||||||
else $this->oAuth = new Auth($this->oMySql, Settings::API_KEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function install()
|
private function install()
|
||||||
@@ -75,30 +35,6 @@ class Pedidor extends Main
|
|||||||
$this->addUser('laura');
|
$this->addUser('laura');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setContext($sProcessPage)
|
|
||||||
{
|
|
||||||
//Browser <> PHP <> MySql synchronization
|
|
||||||
date_default_timezone_set(Settings::TIMEZONE);
|
|
||||||
ini_set('default_charset', Settings::TEXT_ENC);
|
|
||||||
header('Content-Type: text/html; charset='.Settings::TEXT_ENC);
|
|
||||||
mb_internal_encoding(Settings::TEXT_ENC);
|
|
||||||
mb_http_output(Settings::TEXT_ENC);
|
|
||||||
mb_http_input(Settings::TEXT_ENC);
|
|
||||||
mb_language('uni');
|
|
||||||
mb_regex_encoding(Settings::TEXT_ENC);
|
|
||||||
|
|
||||||
$this->asContext['process_page'] = basename($sProcessPage);
|
|
||||||
|
|
||||||
$sServerName = array_key_exists('SERVER_NAME', $_SERVER)?$_SERVER['SERVER_NAME']:$_SERVER['PWD'];
|
|
||||||
$sAppPath = 'http://'.str_replace('http://', '', $sServerName.dirname($_SERVER['SCRIPT_NAME']));
|
|
||||||
$this->asContext['serv_name'] = $sAppPath.(mb_substr($sAppPath, -1)!='/'?'/':'');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addUncaughtError($sError)
|
|
||||||
{
|
|
||||||
$this->addError('Uncaught errors:'."\n".$sError);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Authorizations handling */
|
/* Authorizations handling */
|
||||||
|
|
||||||
public function isLoggedIn()
|
public function isLoggedIn()
|
||||||
@@ -121,7 +57,8 @@ class Pedidor extends Main
|
|||||||
public function getPage($bLoggedIn)
|
public function getPage($bLoggedIn)
|
||||||
{
|
{
|
||||||
//Constants
|
//Constants
|
||||||
$asPages = array('logon', 'write', 'settings', 'template');
|
$asPages = array_values($this->asMasks);
|
||||||
|
unset($asPages['index']);
|
||||||
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
|
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
|
||||||
$asGlobalVars['consts']['token_sep'] = Auth::TOKEN_SEP;
|
$asGlobalVars['consts']['token_sep'] = Auth::TOKEN_SEP;
|
||||||
$asGlobalVars['consts']['error'] = self::ERROR;
|
$asGlobalVars['consts']['error'] = self::ERROR;
|
||||||
@@ -136,12 +73,6 @@ class Pedidor extends Main
|
|||||||
return $sPage;
|
return $sPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPageContent($sPage)
|
|
||||||
{
|
|
||||||
$sPageFile = 'masks/'.$sPage.'.html';
|
|
||||||
return file_get_contents($sPageFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DB structure. See MySqlManager::__construct */
|
/* DB structure. See MySqlManager::__construct */
|
||||||
|
|
||||||
private static function getSqlOptions()
|
private static function getSqlOptions()
|
||||||
@@ -178,151 +109,17 @@ class Pedidor extends Main
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* My Thoughts public functions */
|
/* Pedidor public functions */
|
||||||
|
|
||||||
public function register($sNickName)
|
|
||||||
{
|
|
||||||
$iUserId = $this->addUser($sNickName, true);
|
|
||||||
$bSuccess = false;
|
|
||||||
$sDesc = '';
|
|
||||||
switch($iUserId)
|
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
$sDesc = 'There is already a user using this nickname, sorry!';
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
$sDesc = 'A database error occured. Contact admin';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$bSuccess = true;
|
|
||||||
}
|
|
||||||
return self::getJsonResult($bSuccess, $sDesc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateThought($sThought, $iThoughtId=0)
|
|
||||||
{
|
|
||||||
if($iThoughtId==0)
|
|
||||||
{
|
|
||||||
$iThoughtId = $this->addThought($sThought);
|
|
||||||
$sDesc = 'created';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$asKeys = array(MySqlManager::getId(self::USER_TABLE) => $this->oAuth->getUserId(),
|
|
||||||
MySqlManager::getId(self::THOUGHT_TABLE)=> $iThoughtId);
|
|
||||||
$asThought = array(MySqlManager::getText(self::THOUGHT_TABLE) => self::encodeThought($sThought));
|
|
||||||
$iThoughtId = $this->oMySql->updateRow(self::THOUGHT_TABLE, $asKeys, $asThought);
|
|
||||||
$sDesc = 'updated';
|
|
||||||
}
|
|
||||||
$bSuccess = ($iThoughtId>0);
|
|
||||||
$sDesc = 'thought '.($bSuccess?'':'not ').$sDesc;
|
|
||||||
return self::getJsonResult($bSuccess, $sDesc, $this->getThoughtInfo($iThoughtId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* My Thoughts private functions */
|
/* My Thoughts private functions */
|
||||||
|
|
||||||
private function addUser($sNickName, $bLogMeIn=false)
|
private function addUser($sNickName, $bLogMeIn=false)
|
||||||
{
|
{
|
||||||
$iUserId = $this->oAuth->addUser(self::getSafeNickName($sNickName), $sNickName, $bLogMeIn);
|
|
||||||
if($iUserId>0) $this->addThought(file_get_contents(self::WELCOME_MSG_FILE), $iUserId);
|
|
||||||
return $iUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addThought($sThought, $iUserId=-1)
|
|
||||||
{
|
|
||||||
if($iUserId==-1) $iUserId = $this->oAuth->getUserId();
|
|
||||||
if($iUserId!=0)
|
|
||||||
{
|
|
||||||
$asThought = array( MySqlManager::getId(self::USER_TABLE) => $iUserId,
|
|
||||||
MySqlManager::getText(self::THOUGHT_TABLE) => self::encodeThought($sThought));
|
|
||||||
$ithoughtId = $this->oMySql->insertRow(self::THOUGHT_TABLE, $asThought);
|
|
||||||
}
|
|
||||||
else $this->addError('Adding a thought with no user id');
|
|
||||||
return $ithoughtId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getThoughtInfo($iThoughtId, $bThoughtContent=false)
|
|
||||||
{
|
|
||||||
$asThoughtInfo = array();
|
|
||||||
if($iThoughtId>0)
|
|
||||||
{
|
|
||||||
$asThoughtInfo = $this->oMySql->selectRow(self::THOUGHT_TABLE, $iThoughtId);
|
|
||||||
if(!$bThoughtContent) unset($asThoughtInfo[MySqlManager::getText(self::THOUGHT_TABLE)]);
|
|
||||||
}
|
|
||||||
else $this->addError('getting thought info with no thought id');
|
|
||||||
return $asThoughtInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Static toolbox functions */
|
/* Static toolbox functions */
|
||||||
|
|
||||||
private static function encodeThought($sthought)
|
|
||||||
{
|
|
||||||
return base64_encode(serialize(explode("\n", self::shuffleText($sthought))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function decodeThought($sEncodedThought)
|
|
||||||
{
|
|
||||||
return self::shuffleText(implode("\n", unserialize(base64_decode($sEncodedThought))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function shuffleText($sText)
|
|
||||||
{
|
|
||||||
$sRandomText = "let's_mess%a&bit;with~it,!just§for¨the^sake*of-it";
|
|
||||||
for($iIndex=0; $iIndex < strlen($sText); $iIndex++)
|
|
||||||
{
|
|
||||||
$sText[$iIndex] = $sRandomText[$iIndex%strlen($sRandomText)] ^ $sText[$iIndex];
|
|
||||||
}
|
|
||||||
return $sText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getJsonResult($bSuccess, $sDesc='', $asVars=array())
|
|
||||||
{
|
|
||||||
header('Content-type: application/json');
|
|
||||||
return json_encode(array('result'=>$bSuccess?self::SUCCESS:self::ERROR, 'desc'=>ToolBox::mb_ucwords($sDesc))+$asVars);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSafeNickName($sNickName)
|
|
||||||
{
|
|
||||||
return $sNickName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getDateTimeDesc($oTime)
|
|
||||||
{
|
|
||||||
$iTimeStamp = is_numeric($oTime)?$oTime:strtotime($oTime);
|
|
||||||
$sCurTimeStamp = time();
|
|
||||||
|
|
||||||
$asWeekDays = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'satursday', 'sunday');
|
|
||||||
$asMonths = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december');
|
|
||||||
$sSep = '|';
|
|
||||||
$sFormat = 'Y'.$sSep.'n'.$sSep.'W'.$sSep.'N'.$sSep.'j'.$sSep.'G';
|
|
||||||
list($sYear, $sMonth, $sWeek, $sWeekDay, $sDay, $sHour) = explode($sSep, date($sFormat, $iTimeStamp));
|
|
||||||
list($sCurYear, $sCurMonth, $sCurWeek, $sCurWeekDay, $sCurDay, $sCurHour) = explode($sSep, date($sFormat, $sCurTimeStamp));
|
|
||||||
|
|
||||||
$sDesc = '';
|
|
||||||
if($iTimeStamp>$sCurTimeStamp) $sDesc = 'in the future';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60) $sDesc = 'a few seconds ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*10) $sDesc = 'a few minutes ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*20) $sDesc = '15 minutes ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*50) $sDesc = 'half an hour ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*2) $sDesc = 'an hour ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24 && $sDay==$sCurDay) $sDesc = 'at '.$sHour.' o\'clock';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24) $sDesc = 'yesterday';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7 && $sWeek==$sCurWeek) $sDesc = $asWeekDays[$sWeekDay-1];
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7) $sDesc = 'last '.$asWeekDays[$sWeekDay-1];
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*9) $sDesc = 'a week ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*12) $sDesc = '10 days ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*16) $sDesc = '2 weeks ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*23) $sDesc = '3 weeks ago';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*31 && $sMonth==$sCurMonth) $sDesc = 'on '.$asMonths[$sMonth-1].', '.$sDay;
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*30*2 && $sMonth==($sCurMonth-1)) $sDesc = 'last month';
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365 && $sYear==$sCurYear) $sDesc = 'in '.$asMonths[$sMonth-1];
|
|
||||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365) $sDesc = 'in '.$asMonths[$sMonth-1].' '.$sYear;
|
|
||||||
elseif($sYear==($sCurYear-1)) $sDesc = 'last year';
|
|
||||||
else $sDesc = 'in '.$sYear;
|
|
||||||
|
|
||||||
//return self::mb_ucfirst($sDesc);
|
|
||||||
return $sDesc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
26
masks/index.html
Normal file
26
masks/index.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link type="image/x-icon" href="images/favicon.ico" rel="shortcut icon" />
|
||||||
|
<link type="image/png" href="images/favicon_32.png" rel="icon" sizes="32x32" />
|
||||||
|
<link type="text/css" href="style/jquery.mods.css" rel="stylesheet" media="all" />
|
||||||
|
<link type="text/css" href="style/pedidor.css" rel="stylesheet" media="all" />
|
||||||
|
<link type="text/css" href="style/mobile.css" rel="stylesheet" media="(max-width: 40.5em)" />
|
||||||
|
<link type="text/css" href="style/screen.css" rel="stylesheet" media="(min-width: 40.5em)" />
|
||||||
|
<link type="text/css" href="style/print.css" rel="stylesheet" media="print" />
|
||||||
|
<script type="text/javascript" src="script/jquery-2.1.3.min.js"></script>
|
||||||
|
<script type="text/javascript" src="script/jquery.mods.js"></script>
|
||||||
|
<script type="text/javascript" src="script/common.js"></script>
|
||||||
|
<script type="text/javascript" src="script/pedidor.js"></script><title>Insert title here</title>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var oMyThoughts = new MyThoughts(asGlobalVars);
|
||||||
|
$(document).ready(oMyThoughts.init);
|
||||||
|
</script>
|
||||||
|
<title>Pedidor</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
0
masks/orders.html
Normal file
0
masks/orders.html
Normal file
0
masks/products.html
Normal file
0
masks/products.html
Normal file
Reference in New Issue
Block a user