function status($action, $result, $values = FALSE) { if ($action == 'RENT') { if ($result == OK) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ': <span class="label label-primary">' . _('Open with code') . ' ' . $values->bike->currentcode . '.</span></h3>' . _('Change code immediately to') . ' <span class="label label-default">' . $values->newcode . '</span><br />' . _('(open, rotate metal part, set new code, rotate metal part back)') . '.'; if (isset($values->note)) { $message .= "<br />" . _('Reported issue:') . " <em>" . $values->note . "</em>"; } response($message); } elseif ($result == 100) { response(_('You can not rent any bikes. Contact the admins to lift the ban.'), ERROR); } elseif ($result == 101) { response(_('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once') . ".", ERROR); } elseif ($result == 102) { response(_('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once and you have already rented') . " " . $values->userlimit . ".", ERROR); } elseif ($result == 110) { response(_('Bike') . " " . $values->bikenum . " " . _('is not rentable now, you have to rent bike') . " " . $values->stacktopbike . " " . _('from this stand') . ".", ERROR); } elseif ($result == 120) { response(_('You have already rented the bike') . ' ' . $values->bikenum . '. ' . _('Code is') . ' <span class="label label-primary">' . $values->currentcode . '</span>. ' . _('Return bike by scanning QR code on a stand') . '.', ERROR); } elseif ($result == 121) { response(_('Bike') . " " . $values->bikenum . " " . _('is already rented by someone else') . ".", ERROR); } elseif ($result == 130) { response(_('You are below required credit') . " " . $values->requiredcredit . getcreditcurrency() . ". " . _('Please, recharge your credit.'), ERROR); } } elseif ($action == 'RETURN') { if ($result == OK) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ': <span class="label label-primary">' . _('Lock with code') . ' ' . $values->currentcode . '.</span></h3>'; $message .= '<br />' . _('Please') . ', <strong>' . _('rotate the lockpad to') . ' <span class="label label-default">0000</span></strong> ' . _('when leaving') . '.'; if (iscreditenabled() and isset($values->creditchange)) { $message .= '<br />' . _('Credit change') . ': -' . $values->creditchange . getcreditcurrency() . '.'; } response($message); } elseif ($result == 100) { response(_('You have no rented bikes currently.'), ERROR); } elseif ($result == 101) { $message = _('You have') . ' ' . $values->countrented . ' ' . _('rented bikes currently. QR code return can be used only when 1 bike is rented. Please, use web'); if ($connectors["sms"]) { $message .= _(' or SMS'); } $message .= _(' to return the bikes.'); response($message, ERROR); } } response('Unhandled status ' . $result . ' in ' . $action . ' in file ' . __FILE__ . '.', ERROR); }
function returnbike($userId, $stand) { global $db, $connectors; $stand = strtoupper($stand); $result = $db->query("SELECT bikeNum FROM bikes WHERE currentUser={$userId} ORDER BY bikeNum"); $bikenumber = $result->num_rows; if ($bikenumber == 0) { response(_('You have no rented bikes currently.'), ERROR); } elseif ($bikenumber > 1) { $message = _('You have') . ' ' . $bikenumber . ' ' . _('rented bikes currently. QR code return can be used only when 1 bike is rented. Please, use web'); if ($connectors["sms"]) { $message .= _(' or SMS'); } $message .= _(' to return the bikes.'); response($message, ERROR); } else { $result = $db->query("SELECT bikeNum,currentCode FROM bikes WHERE currentUser={$userId}"); $row = $result->fetch_assoc(); $currentCode = sprintf("%04d", $row["currentCode"]); $bikeNum = $row["bikeNum"]; $result = $db->query("SELECT standId FROM stands where standName='{$stand}'"); $row = $result->fetch_assoc(); $standId = $row["standId"]; $result = $db->query("UPDATE bikes SET currentUser=NULL,currentStand={$standId} WHERE bikeNum={$bikeNum} and currentUser={$userId}"); $message = '<h3>' . _('Bike') . ' ' . $bikeNum . ': <span class="label label-primary">' . _('Lock with code') . ' ' . $currentCode . '.</span></h3>'; $message .= '<br />' . _('Please') . ', <strong>' . _('rotate the lockpad to') . ' <span class="label label-default">0000</span></strong> ' . _('when leaving') . '.'; $creditchange = changecreditendrental($bikeNum, $userId); if (iscreditenabled() and $creditchange) { $message .= '<br />' . _('Credit change') . ': -' . $creditchange . getcreditcurrency() . '.'; } $result = $db->query("INSERT INTO history SET userId={$userId},bikeNum={$bikeNum},action='RETURN',parameter={$standId}"); response($message); } }
function status($action, $result, $values = FALSE) { if ($action == 'CREDIT') { if ($result == OK) { sendSMS($number, _('Your remaining credit:') . " " . $values->usercredit . getcreditcurrency()); } } elseif ($action == 'LISTBIKES') { if ($result == OK) { $listbikes = ""; foreach ($values->bicycles as $bicycle) { $listbikes .= $bicycle; if ($values->stacktopbike == $bicycle) { $listbikes .= " " . _('(first)'); } $listbikes .= ","; } if ($values->standcount > 1) { $listbikes = substr($listbikes, 0, strlen($listbikes) - 1); } sendSMS($number, sprintf(ngettext('%d bike', '%d bikes', $values->standcount), $values->standcount) . " " . _('on stand') . " " . $values->standname . ": " . $listbikes); } elseif ($result == 100) { sendSMS($number, _('Stand') . " " . $values->standname . " " . _('is empty') . "."); } } elseif ($action == 'RENT') { if ($result == OK) { $message = _('Bike') . " " . $values->bikenum . ": " . _('Open with code') . " " . $values->currentcode . ". " . _('Change code immediately to') . " " . $values->newcode . " " . _('(open,rotate metal part,set new code,rotate metal part back)') . "."; if ($values->note) { $message .= "(" . _('Reported issue:') . ":" . $values->note . ")"; } sendSMS($number, $message); if (isset($values->currentusernumber)) { sendSMS($values->currentusernumber, _('System override') . ": " . _('Your rented bike') . " " . $bikeNum . " " . _('has been rented by admin') . "."); } } elseif ($result == 100) { sendSMS($number, _('You can not rent any bikes. Contact the admins to lift the ban.')); } elseif ($result == 101) { sendSMS($number, _('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once') . "."); } elseif ($result == 102) { sendSMS($number, _('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once') . " " . _('and you have already rented') . " " . $values->userlimit . "."); } elseif ($result == 110) { sendSMS($number, _('Bike') . " " . $values->bikenum . " " . _('is not rentable now, you have to rent bike') . " " . $values->stacktopbike . " " . _('from this stand') . "."); } elseif ($result == 120) { sendSMS($number, _('You have already rented the bike') . " " . $values->bikenum . ". " . _('Code is') . " " . $values->currentcode . ". " . _('Return bike with command:') . " RETURN " . _('bikenumber') . " " . _('standname') . "."); } elseif ($result == 121) { sendSMS($number, _('Bike') . " " . $values->bikenum . " " . _('is already rented by someone else') . "."); } elseif ($result == 130) { sendSMS($number, _('Please, recharge your credit:') . " " . $values->credit . getcreditcurrency() . ". " . _('Credit required:') . " " . $values->requiredcredit . getcreditcurrency() . "."); } } elseif ($action == 'RETURN') { if ($result == OK) { $message = _('Bike') . " " . $values->bikenum . " " . _('returned to stand') . " " . $values->standname . ". " . _('Make sure you set code to') . " " . $currentCode . "."; $message .= " " . _('Rotate lockpad to 0000.'); if (iscreditenabled()) { $message .= " " . _('Credit') . ": " . getusercredit($values->userid) . getcreditcurrency(); if (isset($values->creditchange)) { $message .= " (-" . $values->creditchange . ")"; } $message .= "."; } if (isset($values->note)) { $message .= " (" . _('note') . ":" . $tempnote . ")"; } sendSMS($number, $message); if (isset($values->currentusernumber)) { sendSMS($values->currentusernumber, _('System override') . ": " . _('Your rented bike') . " " . $values->bikenum . " " . _('has been returned by admin') . "."); } } elseif ($result == 100) { sendSMS($number, _('You have no rented bikes currently.')); } elseif ($result == 102) { $message = _('You do not have the bike') . " " . $values->bikenum . " rented."; if (isset($values->bikelist)) { $message .= " " . _('You have rented the following') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->countrented), $values->countrented) . ": " . $values->bikelist . "."; } sendSMS($number, $message); } elseif ($result == 103) { sendSMS($number, _('Bike') . " " . $values->bikenum . " " . _('is not rented. Saint Thomas, the patron of unrented bikes, prohibited returning it.')); } } elseif ($action == 'CHECKBIKE') { if ($result == 100) { response('<h3>Bike ' . $bikenum . ' does not exist!</h3>', ERROR); } } elseif ($action == 'CHECKSTAND') { if ($result == 100) { sendSMS($values->number, _("Stand") . " " . $values->standname . _("does not exist") . "." . _("Stands are marked by CAPITALLETTERS") . "."); } } elseif ($action == 'WHERE') { if ($result == 100) { $message = _('Bike') . " " . $values->bikenum . " " . _('is at stand') . " " . $values->standname . "."; if (isset($values->note)) { $message .= " (" . _('Reported issue:') . ":" . $values->note . ")"; } sendSMS($number, $message); } elseif ($result == 101) { $message = _('Bike') . " " . $values->bikenum . " " . _('is rented by') . " " . $values->username . " (+" . $values->phone . ")."; if (isset($values->note)) { $message .= " (" . _('Reported issue:') . ":" . $values->note . ")"; } sendSMS($number, $message); } } response('Unhandled status ' . $result . ' in ' . $action . ' in file ' . __FILE__ . '.', ERROR); }
function status($action, $result, $values = FALSE) { if ($action == 'LISTBIKES') { if ($result == OK) { response($values->bicycles, 0, array("notes" => $values->notes, "stacktopbike" => $values->stacktopbike), 0); } elseif ($result == 100) { response(''); } } elseif ($action == 'RENT') { if ($result == OK) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ': <span class="label label-primary">' . _('Open with code') . ' ' . $values->bike->currentcode . '.</span></h3>' . _('Change code immediately to') . ' <span class="label label-default">' . $values->newcode . '</span><br />' . _('(open, rotate metal part, set new code, rotate metal part back)') . '.'; if (isset($values->note)) { $message .= "<br />" . _('Reported issue:') . " <em>" . $values->note . "</em>"; } response($message); } elseif ($result == 100) { response(_('You can not rent any bikes. Contact the admins to lift the ban.'), ERROR); } elseif ($result == 101) { response(_('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once') . ".", ERROR); } elseif ($result == 102) { response(_('You can only rent') . " " . sprintf(ngettext('%d bike', '%d bikes', $values->userlimit), $values->userlimit) . " " . _('at once and you have already rented') . " " . $values->userlimit . ".", ERROR); } elseif ($result == 110) { response(_('Bike') . " " . $values->bikenum . " " . _('is not rentable now, you have to rent bike') . " " . $values->stacktopbike . " " . _('from this stand') . ".", ERROR); } elseif ($result == 120) { response(_('You have already rented the bike') . " " . $values->bikenum . ". " . _('Code is') . " " . $values->currentcode . ".", ERROR); } elseif ($result == 121) { response(_('Bike') . " " . $values->bikenum . " " . _('is already rented by someone else') . ".", ERROR); } elseif ($result == 130) { response(_('You are below required credit') . " " . $requiredcredit . $credit["currency"] . ". " . _('Please, recharge your credit.'), ERROR); } } elseif ($action == 'RETURN') { if ($result == OK) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ': <span class="label label-primary">' . _('Lock with code') . ' ' . $values->currentcode . '.</span></h3>'; $message .= '<br />' . _('Please') . ', <strong>' . _('rotate the lockpad to') . ' <span class="label label-default">0000</span></strong> ' . _('when leaving') . '.'; if (iscreditenabled() and isset($values->creditchange)) { $message .= '<br />' . _('Credit change') . ': -' . $values->creditchange . getcreditcurrency() . '.'; } if (isset($values->note)) { $message .= '<br />' . _('You have also reported this problem:') . ' ' . $values->note . '.'; } response($message); } elseif ($result == 100) { response(_('You have no rented bikes currently.'), ERROR); } } elseif ($action == 'CHECKBIKE') { if ($result == 100) { response('<h3>Bike ' . $bikenum . ' does not exist!</h3>', ERROR); } } elseif ($action == 'CHECKSTAND') { if ($result == 100) { response('<h3>' . _('Stand') . ' ' . $standname . ' ' . _('does not exist') . '!</h3>', ERROR); } } elseif ($action == 'WHERE') { if ($result == 100) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ' ' . _('at') . ' <span class="label label-primary">' . $values->standname . '</span>.</h3>'; if (isset($values->note)) { $message .= ' (' . _('Reported issue:') . " " . $values->note . ')'; } response($message); } elseif ($result == 101) { $message = '<h3>' . _('Bike') . ' ' . $values->bikenum . ' ' . _('rented by') . ' <span class="label label-primary">' . $values->username . '</span>.</h3>' . _('Phone') . ': <a href="tel:+' . $values->phone . '">+' . $values->phone . '</a>.'; if (isset($values->note)) { $message .= ' (' . _('Reported issue:') . " " . $values->note . ')'; } response($message); } } response('Unhandled status ' . $result . ' in ' . $action . ' in file ' . __FILE__ . '.', ERROR); }
<ul class="list-inline"> <li><a href="<?php echo $systemrules; ?> "><span class="glyphicon glyphicon-question-sign"></span> <?php echo _('Help'); ?> </a></li> <?php if (isloggedin() and getprivileges($_COOKIE["loguserid"]) > 0) { echo '<li><a href="admin.php"><span class="glyphicon glyphicon-cog"></span> ', _('Admin'), '</a></li>'; } if (isloggedin()) { echo '<li><span class="glyphicon glyphicon-user"></span> <small>', getusername($_COOKIE["loguserid"]), '</small>'; if (iscreditenabled()) { echo ' (<span id="usercredit" title="', _('Remaining credit'), '">', getusercredit($_COOKIE["loguserid"]), '</span> ', getcreditcurrency(), ' <button type="button" class="btn btn-success btn-xs" id="opencredit" title="', _('Add credit'), '"><span class="glyphicon glyphicon-plus"></span></button>)<span id="couponblock"><br /><span class="form-inline"><input type="text" class="form-control input-sm" id="coupon" placeholder="XXXXXX" /><button type="button" class="btn btn-primary btn-sm" id="validatecoupon" title="', _('Confirm coupon'), '"><span class="glyphicon glyphicon-plus"></span></button></span></span></li>'; } echo '<li><a href="command.php?action=logout" id="logout"><span class="glyphicon glyphicon-log-out"></span> ', _('Log out'), '</a></li>'; } ?> </ul> </div> <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"> </div> </div> <div class="row"> <div class="col-xs-11 col-sm-11 col-md-11 col-lg-11"> <h1 class="pull-left"><?php echo $systemname; ?> </h1>
function returnBike($number, $bike, $stand, $message = "", $force = FALSE) { global $db; $userId = getUser($number); $bikeNum = intval($bike); $stand = strtoupper($stand); $result = $db->query("SELECT standId FROM stands WHERE standName='{$stand}'"); if (!$result->num_rows) { sendSMS($number, _('Stand name') . " '" . $stand . "' " . _('does not exist. Stands are marked by CAPITALLETTERS.')); return; } $row = $result->fetch_assoc(); $standId = $row["standId"]; if ($force == FALSE) { $result = $db->query("SELECT bikeNum FROM bikes WHERE currentUser={$userId} ORDER BY bikeNum"); $bikenumber = $result->num_rows; if ($bikenumber == 0) { sendSMS($number, _('You have no rented bikes currently.')); return; } $listBikes = ""; while ($row = $result->fetch_assoc()) { $listBikes .= $row["bikeNum"] . ","; } if ($bikenumber > 1) { $listBikes = substr($listBikes, 0, strlen($listBikes) - 1); } } if ($force == FALSE) { $result = $db->query("SELECT currentCode FROM bikes WHERE currentUser={$userId} AND bikeNum={$bikeNum}"); if ($result->num_rows != 1) { sendSMS($number, _('You does not have bike') . " " . $bikeNum . " rented. " . _('You have rented the following') . " " . sprintf(ngettext('%d bike', '%d bikes', $bikenumber), $bikenumber) . ": {$listBikes}"); return; } $row = $result->fetch_assoc(); $currentCode = sprintf("%04d", $row["currentCode"]); $result = $db->query("SELECT note FROM notes WHERE bikeNum={$bikeNum} AND deleted IS NULL ORDER BY time DESC LIMIT 1"); $row = $result->fetch_assoc(); $note = $row["note"]; } else { $result = $db->query("SELECT currentCode,currentUser FROM bikes WHERE bikeNum={$bikeNum}"); if ($result->num_rows != 1) { sendSMS($number, _('Bike') . " " . $bikeNum . " " . _('is not rented. Saint Thomas, the patronus of all unrented bikes, prohibited returning unrented bikes.')); return; } $row = $result->fetch_assoc(); $currentCode = sprintf("%04d", $row["currentCode"]); $currentUser = $row["currentUser"]; $result = $db->query("SELECT note FROM notes WHERE bikeNum={$bikeNum} AND deleted IS NULL ORDER BY time DESC LIMIT 1"); $row = $result->fetch_assoc(); $note = $row["note"]; if ($currentUser) { $result = $db->query("SELECT number FROM users WHERE userId={$currentUser}"); $row = $result->fetch_assoc(); $currentUserNumber = $row["number"]; } } if (!preg_match("/return[\\s,\\.]+[0-9]+[\\s,\\.]+[a-zA-Z0-9]+[\\s,\\.]+(.*)/i", $message, $matches)) { $userNote = ""; } else { $userNote = $db->conn->real_escape_string(trim($matches[1])); } $result = $db->query("UPDATE bikes SET currentUser=NULL,currentStand={$standId} WHERE bikeNum={$bikeNum}"); if ($userNote) { $db->query("INSERT INTO notes SET bikeNum={$bikeNum},userId={$userId},note='{$userNote}'"); $result = $db->query("SELECT userName,number FROM users WHERE userId='{$userId}'"); $row = $result->fetch_assoc(); $userName = $row["userName"]; $phone = $row["number"]; $result = $db->query("SELECT stands.standName FROM bikes LEFT JOIN users ON bikes.currentUser=users.userID LEFT JOIN stands ON bikes.currentStand=stands.standId WHERE bikeNum={$bikeNum}"); $row = $result->fetch_assoc(); $standName = $row["standName"]; if ($standName != NULL) { $bikeStatus = _('at') . " " . $standName; } else { $bikeStatus = _('used by') . " " . $userName . " +" . $phone; } notifyAdmins(_('Note') . " b.{$bikeNum} (" . $bikeStatus . ") " . _('by') . " {$userName}/{$phone}:" . $userNote); } $message = _('Bike') . " " . $bikeNum . " " . _('returned to stand') . " " . $stand . ". " . _('Make sure you set code to') . " " . $currentCode . "."; if ($note or $userNote) { $tempnote = $note; if ($userNote) { $tempnote = $userNote; } if ($tempnote) { $message .= "(note:" . $tempnote . ")"; } } $message .= " " . _('Rotate lockpad to 0000.'); if ($force == FALSE) { $creditchange = changecreditendrental($bikeNum, $userId); $result = $db->query("INSERT INTO history SET userId={$userId},bikeNum={$bikeNum},action='RETURN',parameter={$standId}"); } else { $result = $db->query("INSERT INTO history SET userId={$userId},bikeNum={$bikeNum},action='FORCERETURN',parameter={$standId}"); if ($currentUserNumber) { sendSMS($currentUserNumber, _('System override') . ": " . _('Your rented bike') . " " . $bikeNum . " " . _('has been returned by admin') . "."); } } if (iscreditenabled()) { $message .= _('Credit') . ": " . getusercredit($userId) . getcreditcurrency(); if ($creditchange) { $message .= " (-" . $creditchange . ")"; } $message .= "."; } sendSMS($number, $message); }
function returnBike($userId, $bike, $stand, $note = "", $force = FALSE) { global $db; $bikeNum = intval($bike); $stand = strtoupper($stand); if ($force == FALSE) { $result = $db->query("SELECT bikeNum FROM bikes WHERE currentUser={$userId} ORDER BY bikeNum"); $bikenumber = $result->num_rows; if ($bikenumber == 0) { response(_('You currently have no rented bikes.'), ERROR); } } if ($force == FALSE) { $result = $db->query("SELECT currentCode FROM bikes WHERE currentUser={$userId} and bikeNum={$bikeNum}"); } else { $result = $db->query("SELECT currentCode FROM bikes WHERE bikeNum={$bikeNum}"); } $row = $result->fetch_assoc(); $currentCode = sprintf("%04d", $row["currentCode"]); $result = $db->query("SELECT standId FROM stands WHERE standName='{$stand}'"); $row = $result->fetch_assoc(); $standId = $row["standId"]; $result = $db->query("UPDATE bikes SET currentUser=NULL,currentStand={$standId} WHERE bikeNum={$bikeNum} and currentUser={$userId}"); if ($note) { addNote($userId, $bikeNum, $note); } $message = '<h3>' . _('Bike') . ' ' . $bikeNum . ': <span class="label label-primary">' . _('Lock with code') . ' ' . $currentCode . '.</span></h3>'; $message .= '<br />' . _('Please') . ', <strong>' . _('rotate the lockpad to') . ' <span class="label label-default">0000</span></strong> ' . _('when leaving') . '.'; if ($note) { $message .= '<br />' . _('You have also reported this problem:') . ' ' . $note . '.'; } if ($force == FALSE) { $creditchange = changecreditendrental($bikeNum, $userId); if (iscreditenabled() and $creditchange) { $message .= '<br />' . _('Credit change') . ': -' . $creditchange . getcreditcurrency() . '.'; } $result = $db->query("INSERT INTO history SET userId={$userId},bikeNum={$bikeNum},action='RETURN',parameter={$standId}"); } else { $result = $db->query("INSERT INTO history SET userId={$userId},bikeNum={$bikeNum},action='FORCERETURN',parameter={$standId}"); } response($message); }