Skip to content

Commit

Permalink
add configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneld committed May 26, 2024
1 parent 81cea2e commit b6137dc
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 298 deletions.
12 changes: 6 additions & 6 deletions actions-qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

function response($message,$error=0,$log=1)
{
global $db, $systemname, $systemURL, $user, $auth;
global $configuration, $db, $user, $auth;
if ($log == 1 and $message) {
$userid = $auth->getUserId();
$number = $user->findPhoneNumber($userid);
logresult($number, $message);
$db->commit();
}
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>',$systemname,'</title>';
echo '<base href="',$systemURL,'" />';
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>',$configuration->get('systemname'),'</title>';
echo '<base href="' . $configuration->get('systemURL') . '" />';
echo '<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />';
echo '<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />';
echo '<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">';
Expand All @@ -37,12 +37,12 @@ function response($message,$error=0,$log=1)

function showrentform($userId,$bike)
{
global $db, $systemname, $systemURL, $user, $auth;
global $db, $configuration;

$stand = $db->query("SELECT s.* FROM bikes b JOIN stands s ON b.currentStand=s.standId WHERE bikeNum=$bike")->fetchAssoc();

echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>',$systemname,'</title>';
echo '<base href="',$systemURL,'" />';
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>',$configuration->get('systemname'),'</title>';
echo '<base href="' . $configuration->get('systemURL') . '" />';
echo '<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />';
echo '<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />';
echo '<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">';
Expand Down
34 changes: 21 additions & 13 deletions actions-sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function where($number,$bike)
function listBikes($number,$stand)
{

global $db,$forcestack, $smsSender, $user;
global $db, $configuration, $smsSender, $user;
$stacktopbike=FALSE;
$userId = $user->findUserIdByNumber($number);
$stand = strtoupper($stand);
Expand All @@ -164,10 +164,9 @@ function listBikes($number,$stand)
$row=$result->fetch_assoc();
$standId=$row["standId"];

if ($forcestack)
{
$stacktopbike=checktopofstack($standId);
}
if ($configuration->get('forcestack')) {
$stacktopbike = checktopofstack($standId);
}

$result=$db->query("SELECT bikeNum FROM bikes where currentStand=$standId ORDER BY bikeNum");
$rentedBikes=$result->num_rows;
Expand Down Expand Up @@ -234,11 +233,17 @@ function freeBikes($number)

function log_sms($sms_uuid, $sender, $receive_time, $sms_text, $ip)
{
global $dbserver, $dbuser, $dbpassword, $dbname, $logger;
global $configuration, $logger;
/**
* @var DbInterface
*/
$localdb = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$localdb = new MysqliDb(
$configuration->get('dbserver'),
$configuration->get('dbuser'),
$configuration->get('dbpassword'),
$configuration->get('dbname'),
$logger
);
$localdb->connect();

#TODO does it needed???
Expand Down Expand Up @@ -731,7 +736,7 @@ function revert($number,$bikeNum)
function add($number,$email,$phone,$message)
{

global $db, $countrycode, $smsSender, $user, $phonePurifier;
global $db, $smsSender, $user, $phonePurifier, $configuration;
$userId = $user->findUserIdByNumber($number); #maybe we should check if the user exist???
$phone = $phonePurifier->purify($phone);

Expand All @@ -748,11 +753,14 @@ function add($number,$email,$phone,$message)
return;
}

if ($phone < $countrycode."000000000" || $phone > ($countrycode+1)."000000000" || !preg_match("/add\s+([a-z0-9._%+-]+@[a-z0-9.-]+)\s+\+?[0-9]+\s+(.{2,}\s.{2,})/i",$message ,$matches))
{
$smsSender->send($number,_('Contact information is in incorrect format. Use:')." ADD king@earth.com 0901456789 Martin Luther King Jr.");
return;
}
if (
$phone < $configuration->get('countrycode') . "000000000"
|| $phone > ($configuration->get('countrycode') + 1) . "000000000"
|| !preg_match("/add\s+([a-z0-9._%+-]+@[a-z0-9.-]+)\s+\+?[0-9]+\s+(.{2,}\s.{2,})/i", $message, $matches)
) {
$smsSender->send($number, _('Contact information is in incorrect format. Use:') . " ADD king@earth.com 0901456789 Martin Luther King Jr.");
return;
}
$userName=$db->escape(trim($matches[2]));
$email=$db->escape(trim($matches[1]));

Expand Down
43 changes: 21 additions & 22 deletions actions-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function where($userId, $bike)

function listbikes($stand)
{
global $db, $forcestack;
global $db, $configuration;

$stacktopbike = false;
$stand = $db->escape($stand);
if ($forcestack) {
if ($configuration->get('forcestack')) {
$result = $db->query("SELECT standId FROM stands WHERE standName='$stand'");
$row = $result->fetch_assoc();
$stacktopbike = checktopofstack($row['standId']);
Expand Down Expand Up @@ -265,7 +265,7 @@ function revert($userId, $bikeNum)

function register($number, $code, $checkcode, $fullname, $email, $password, $password2, $existing)
{
global $db, $dbpassword, $countrycode, $systemURL, $user;
global $db, $configuration, $user;

$number = $db->escape(trim($number));
$code = $db->escape(trim($code));
Expand All @@ -290,7 +290,7 @@ function register($number, $code, $checkcode, $fullname, $email, $password, $pas
} else { // existing user, password change
$userId = $user->findUserIdByNumber($number);
$result = $db->query("UPDATE users SET password=SHA2('$password',512) WHERE userId='$userId'");
response(_('Password successfully changed. Your username is your phone number. Continue to') . ' <a href="' . $systemURL . '">' . _('login') . '</a>.');
response(_('Password successfully changed. Your username is your phone number. Continue to') . ' <a href="' . $configuration->get('systemURL') . '">' . _('login') . '</a>.');
}
} else {
response(_('Problem with the SMS code entered. Please check and try again.'), ERROR);
Expand All @@ -316,7 +316,7 @@ function checkprivileges($userid)

function smscode($number)
{
global $db, $gatewayId, $gatewayKey, $gatewaySenderNumber, $connectors, $smsSender, $user, $phonePurifier;
global $db, $smsSender, $user, $phonePurifier;
srand();

$number = $phonePurifier->purify($number);
Expand Down Expand Up @@ -432,7 +432,7 @@ function saveuser($userid, $username, $email, $phone, $privileges, $limit)

function addcredit($userid, $creditmultiplier)
{
global $db, $credit, $user, $creditSystem;
global $db, $user, $creditSystem;

$minRequiredCredit = $creditSystem->getMinRequiredCredit();
$addcreditamount = $minRequiredCredit * $creditmultiplier;
Expand All @@ -445,7 +445,7 @@ function addcredit($userid, $creditmultiplier)

function getcouponlist()
{
global $db, $credit, $creditSystem;
global $db, $creditSystem;
if ($creditSystem->isEnabled() == false) {
return;
}
Expand All @@ -459,7 +459,7 @@ function getcouponlist()

function generatecoupons($multiplier)
{
global $db, $credit, $codeGenerator, $creditSystem;
global $db, $codeGenerator, $creditSystem;

if ($creditSystem->isEnabled() == false) {
return;
Expand All @@ -476,7 +476,7 @@ function generatecoupons($multiplier)

function sellcoupon($coupon)
{
global $db, $credit, $creditSystem;
global $db, $creditSystem;
if ($creditSystem->isEnabled() == false) {
return;
}
Expand All @@ -487,7 +487,7 @@ function sellcoupon($coupon)

function validatecoupon($userid, $coupon)
{
global $db, $credit, $creditSystem;
global $db, $creditSystem;
if ($creditSystem->isEnabled() == false) {
return;
}
Expand All @@ -506,9 +506,9 @@ function validatecoupon($userid, $coupon)

function changecity($userid, $city)
{
global $db, $cities;
global $db, $configuration;

if (in_array($city, $cities)) {
if (in_array($city, $configuration->get('cities'))) {
$result = $db->query("UPDATE users SET city='$city' WHERE userId=" . $userid);
response('City changed');
}
Expand All @@ -518,7 +518,7 @@ function changecity($userid, $city)

function resetpassword($number)
{
global $db, $mailer, $systemname, $systemrules, $systemURL;
global $db, $mailer;

$number = $db->escape(trim($number));

Expand Down Expand Up @@ -550,16 +550,15 @@ function resetpassword($number)

function mapgetmarkers($userId)
{
global $db, $cities, $user;
global $db, $configuration, $user;
$filtercity = '';
if($cities){

if($userId!=0)
{
$filtercity = ' AND city = "'.$user->findCity($userId).'" ';
}
else $filtercity = "";
}
if ($configuration->get('cities')) {
if ($userId != 0) {
$filtercity = ' AND city = "' . $user->findCity($userId) . '" ';
} else {
$filtercity = "";
}
}
$jsoncontent = array();
$result = $db->query('SELECT standId,count(bikeNum) AS bikecount,standDescription,standName,standPhoto,longitude AS lon, latitude AS lat FROM stands LEFT JOIN bikes on bikes.currentStand=stands.standId WHERE stands.serviceTag=0 '.$filtercity.' GROUP BY standName ORDER BY standName');
while ($row = $result->fetch_assoc()) {
Expand Down
Loading

0 comments on commit b6137dc

Please sign in to comment.