Skip to content

Commit

Permalink
rent system qr code optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneld committed May 16, 2024
1 parent ecb0bf4 commit 5afe459
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 54 deletions.
2 changes: 1 addition & 1 deletion actions-qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function response($message,$error=0,$log=1)
$userid = $auth->getUserId();
$number = $user->findPhoneNumber($userid);
logresult($number, $message);
$db->commit();
}
$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 '<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />';
Expand Down
6 changes: 4 additions & 2 deletions scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
$bikeno = $parameter;
checkbikeno($bikeno);
if (!empty($_POST['rent']) && $_POST['rent'] == "yes") {
$rentSystem->rentBike($userid, $bikeno);
$result = $rentSystem->rentBike($userid, $bikeno);
response($result['message'], $result['error'], 0);
} else {
showrentform($userid, $bikeno);
}
Expand All @@ -57,7 +58,8 @@
logrequest($userid, $action);
$stand = $parameter;
checkstandname($stand);
$rentSystem->returnBike($userid, 0, $stand);
$result = $rentSystem->returnBike($userid, 0, $stand);
response($result['message'], $result['error'], 0);
break;
default:
unrecognizedqrcode();
Expand Down
20 changes: 19 additions & 1 deletion src/Rent/AbstractRentSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function rentBike($userId, $bikeId, $force = false)
$result = $this->db->query("INSERT INTO history SET userId=$userId,bikeNum=$bikeNum,action='FORCERENT',parameter=$newCode");
//$this->response(_('System override') . ": " . _('Your rented bike') . " " . $bikeNum . " " . _('has been rented by admin') . ".");
}

return $this->response($message);
}

Expand Down Expand Up @@ -226,7 +227,19 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa
}

abstract protected function getRentSystemType();
abstract protected function response($message, $error = 0, $additional = '', $log = 1);

protected function response($message, $error = 0)
{
$userid = $this->auth->getUserId();
$number = $this->user->findPhoneNumber($userid);
$this->logResult($number, $message);
$this->db->commit();

return [
'error' => $error,
'content' => $message,
];
}

private function checktoomany($userId)
{
Expand Down Expand Up @@ -337,4 +350,9 @@ private function changecreditendrental($bike, $userid)
return $creditchange;
}
}

private function logResult($number, $message)
{
logresult($number, $message);
}
}
35 changes: 0 additions & 35 deletions src/Rent/RentSystemQR.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,4 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa
protected function getRentSystemType() {
return 'qr';
}

protected function response($message, $error = 0, $additional = '', $log = 1)
{
global $systemname, $systemURL;

if ($log == 1 and $message) {
$userid = $this->auth->getUserId();
$number = $this->user->findPhoneNumber($userid);
logresult($number, $message);
}
$this->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 '<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">';
echo '<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">';
echo '<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">';
echo '<link rel="manifest" href="/site.webmanifest">';
echo '<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">';
echo '<meta name="msapplication-TileColor" content="#da532c">';
echo '<meta name="theme-color" content="#ffffff">';
if (file_exists("analytics.php")) require("analytics.php");
echo '</head><body><div class="container">';
if ($error)
{
echo '<div class="alert alert-danger" role="alert">',$message,'</div>';
}
else
{
echo '<div class="alert alert-success" role="alert">',$message,'</div>';
}
echo '</div></body></html>';
exit;
}
}
2 changes: 1 addition & 1 deletion src/Rent/RentSystemSms.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function getRentSystemType() {
return 'sms';
}

protected function response($message, $error = 0, $additional = '', $log = 1)
protected function response($message, $error = 0)
{
$this->smsSender->send($this->number, strip_tags($message));
}
Expand Down
18 changes: 4 additions & 14 deletions src/Rent/RentSystemWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,12 @@ protected function getRentSystemType() {
return 'web';
}

protected function response($message, $error = 0, $additional = '', $log = 1)
protected function response($message, $error = 0)
{
$json = array('error' => $error, 'content' => $message);
if (is_array($additional)) {
foreach ($additional as $key => $value) {
$json[$key] = $value;
}
}
$json = json_encode($json);
if ($log == 1 && $message) {
$userid = $this->auth->getUserId();
$response = parent::response($message, $error);

$json = json_encode($response);

$number = $this->user->findPhoneNumber($userid);
logresult($number, $message);
}
$this->db->commit();
echo $json;
exit;
}
Expand Down

0 comments on commit 5afe459

Please sign in to comment.