コード例 #1
0
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);
}
コード例 #2
0
ファイル: lottery.php プロジェクト: norain2050/benhu
                    //$content = "你的号码:".$randnum."<br/>";
                    $result['error'] = 0;
                    $result['wid'] = $num;
                    $content = "恭喜您中奖了!!写下您获奖感言索取奖品吧..<br/>\n\t\t\t\t\t";
                }
                clear_cache_files('lottery');
            } else {
                //$content = "你的号码:".$randnum."<br/>";
                $result['error'] = 1;
                $content = "没有中奖唉~";
            }
            $content .= "<br/>";
            $sql = "update " . $GLOBALS['ecs']->table('lottery') . " set click=click+1 where id='" . $id . "'";
            $GLOBALS['db']->query($sql);
        }
        $result['credit'] = getusercredit($user_id);
        //	$result['content'] = $content;
        $result['message'] = $content;
        $result['id'] = $id;
    }
    die($json->encode($result));
} elseif ($_REQUEST['act'] == 'view') {
    $page = empty($_REQUEST['page']) ? 1 : intval($_REQUEST['page']);
    $size = 10;
    $record_count = intval(gettotallu());
    $page_count = $record_count > 0 ? intval(ceil($record_count / $size)) : 1;
    if ($page < 1) {
        $page = 1;
    }
    if ($page > $page_count) {
        $page = $page_count;
コード例 #3
0
function changecreditendrental($bike, $userid)
{
    global $db, $watches, $credit;
    if (iscreditenabled() == FALSE) {
        return;
    }
    // if credit system disabled, exit
    $usercredit = getusercredit($userid);
    $result = $db->query("SELECT time FROM history WHERE bikeNum={$bike} AND userId={$userid} AND (action='RENT' OR action='FORCERENT') ORDER BY time DESC LIMIT 1");
    if ($result->num_rows == 1) {
        $row = $result->fetch_assoc();
        $starttime = strtotime($row["time"]);
        $endtime = time();
        $timediff = $endtime - $starttime;
        $creditchange = 0;
        $changelog = "";
        if ($timediff > $watches["freetime"] * 60) {
            $creditchange = $creditchange + $credit["rent"];
            $changelog .= "overfree-" . $credit["rent"] . ";";
        }
        if ($watches["freetime"] == 0) {
            $watches["freetime"] = 1;
        }
        // for further calculations
        if ($credit["pricecycle"] and $timediff > $watches["freetime"] * 60 * 2) {
            $temptimediff = $timediff - $watches["freetime"] * 60 * 2;
            if ($credit["pricecycle"] == 1) {
                $cycles = ceil($temptimediff / ($watches["flatpricecycle"] * 60));
                $creditchange = $creditchange + $credit["rent"] * $cycles;
                $changelog .= "flat-" . $credit["rent"] * $cycles . ";";
            } elseif ($credit["pricecycle"] == 2) {
                $cycles = ceil($temptimediff / ($watches["doublepricecycle"] * 60));
                $tempcreditrent = $credit["rent"];
                for ($i = 1; $i <= $cycles; $i++) {
                    $multiplier = $i;
                    if ($multiplier > $watches["doublepricecyclecap"]) {
                        $multiplier = $watches["doublepricecyclecap"];
                    }
                    // exception for rent=1, otherwise square won't work:
                    if ($tempcreditrent == 1) {
                        $tempcreditrent = 2;
                    }
                    $creditchange = $creditchange + pow($tempcreditrent, $multiplier);
                    $changelog .= "double-" . pow($tempcreditrent, $multiplier) . ";";
                }
            }
        }
        if ($timediff > $watches["longrental"] * 3600) {
            $creditchange = $creditchange + $credit["longrental"];
            $changelog .= "longrent-" . $credit["longrental"] . ";";
        }
        $usercredit = $usercredit - $creditchange;
        $result = $db->query("UPDATE credit SET credit={$usercredit} WHERE userId={$userid}");
        $result = $db->query("INSERT INTO history SET userId={$userid},bikeNum={$bike},action='CREDITCHANGE',parameter='" . $creditchange . "|" . $changelog . "'");
        $result = $db->query("INSERT INTO history SET userId={$userid},bikeNum={$bike},action='CREDIT',parameter={$usercredit}");
        return $creditchange;
    }
}
コード例 #4
0
function mapgetlimit($userId)
{
    global $db;
    if (!isloggedin()) {
        response("");
    }
    $result = $db->query("SELECT count(*) as countRented FROM bikes where currentUser={$userId}");
    $row = $result->fetch_assoc();
    $rented = $row["countRented"];
    $result = $db->query("SELECT userLimit FROM limits where userId={$userId}");
    $row = $result->fetch_assoc();
    $limit = $row["userLimit"];
    $currentlimit = $limit - $rented;
    $usercredit = 0;
    $usercredit = getusercredit($userId);
    echo json_encode(array("limit" => $currentlimit, "rented" => $rented, "usercredit" => $usercredit));
}
コード例 #5
0
   <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>
コード例 #6
0
function changecreditendrental($bikenum, $userid)
{
    global $watches, $credit;
    if (iscreditenabled() == FALSE) {
        return;
    }
    // if credit system disabled, exit
    $usercredit = getusercredit($userid);
    $history = R::find('history', 'bikenum=:bikenum AND userid=:userid AND FIND_IN_SET(action,:action) ORDER BY time DESC LIMIT 1', [':bikenum' => $bikenum, ':userid' => $userid, ':action:' => 'RENT,FORCERENT']);
    if (!empty($history)) {
        $starttime = strtotime($history->time);
        $endtime = time();
        $timediff = $endtime - $starttime;
        $creditchange = 0;
        $changelog = "";
        if ($timediff > $watches["freetime"] * 60) {
            $creditchange = $creditchange + $credit["rent"];
            $changelog .= "overfree-" . $credit["rent"] . ";";
        }
        if ($watches["freetime"] == 0) {
            $watches["freetime"] = 1;
        }
        // for further calculations
        if ($credit["pricecycle"] and $timediff > $watches["freetime"] * 60 * 2) {
            $temptimediff = $timediff - $watches["freetime"] * 60 * 2;
            if ($credit["pricecycle"] == 1) {
                $cycles = ceil($temptimediff / ($watches["flatpricecycle"] * 60));
                $creditchange = $creditchange + $credit["rent"] * $cycles;
                $changelog .= "flat-" . $credit["rent"] * $cycles . ";";
            } elseif ($credit["pricecycle"] == 2) {
                $cycles = ceil($temptimediff / ($watches["doublepricecycle"] * 60));
                $tempcreditrent = $credit["rent"];
                for ($i = 1; $i <= $cycles; $i++) {
                    $multiplier = $i;
                    if ($multiplier > $watches["doublepricecyclecap"]) {
                        $multiplier = $watches["doublepricecyclecap"];
                    }
                    // exception for rent=1, otherwise square won't work:
                    if ($tempcreditrent == 1) {
                        $tempcreditrent = 2;
                    }
                    $creditchange = $creditchange + pow($tempcreditrent, $multiplier);
                    $changelog .= "double-" . pow($tempcreditrent, $multiplier) . ";";
                }
            }
        }
        if ($timediff > $watches["longrental"] * 3600) {
            $creditchange = $creditchange + $credit["longrental"];
            $changelog .= "longrent-" . $credit["longrental"] . ";";
        }
        $usercredit = $usercredit - $creditchange;
        $credit = R::findOne('credit', 'userid=?', [$userid]);
        $credit->credit = $usercredit;
        R::store($credit);
        $history = R::dispense('history');
        $history->userid = $userid;
        $history->bikenum = $bikenum;
        $history->action = 'CREDITCHANGE';
        $history->paremeter = $creditchange . '|' . $changelog;
        R::store($history);
        $history = R::dispense('history');
        $history->userid = $userid;
        $history->bikenum = $bikenum;
        $history->action = 'CREDIT';
        $history->paremeter = $usercredit;
        R::store($history);
        return $creditchange;
    }
}
コード例 #7
0
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);
}