Пример #1
0
function AutoLockCheck($table, $id)
{
    plog("AutoLockCheck: Start");
    global $database, $auth, $auth_model;
    $m = new AutoRowLock($database);
    // Expire old locks
    $m->Delete('Timestamp < ' . strtotime('-10 minutes'));
    $locks = $m->Select(array('I' => $ID, 'T' => $Table));
    if (!false_or_null($locks) && count($locks) > 0) {
        $found = false;
        $others = 0;
        foreach ($locks as $lock) {
            if ($m->Expired($lock)) {
                $m->Delete(array('ID' => $lock['ID']));
            } else {
                if ($m->LockedByMe($lock)) {
                    if ($found === true) {
                        $m->Delete(array('ID' => $lock['ID']));
                    } else {
                        $m->RefreshLock($lock);
                        $found = true;
                    }
                } else {
                    $others++;
                }
            }
        }
        return $found === true || $others === 0;
    }
    plog("AutoLockCheck: End");
    return FALSE;
}
Пример #2
0
$m->Delete('Timestamp < ' . strtotime('-10 minutes'));
// Expire old locks
$locks = $m->Select(array('I' => $ID, 'T' => $Table));
// Find existing locks
if (!false_or_null($locks) && count($locks) > 0) {
    $found = false;
    $others = 0;
    foreach ($locks as $lock) {
        if ($m->Expired($lock)) {
            $m->Delete(array('ID' => $lock['ID']));
        } else {
            if ($m->LockedByMe($lock)) {
                if ($found === true) {
                    $m->Delete(array('ID' => $lock['ID']));
                } else {
                    $m->RefreshLock($lock);
                    $found = true;
                }
            } else {
                $others++;
            }
        }
    }
    if ($found === false && $others > 0) {
        // Locked up
        echo json_encode(array("message" => $m->LockedTo($lock) . ' has edit control', "unlocked" => 0));
        die;
    } else {
        // Locked to user
        echo json_encode(array("message" => 'You have edit control', "unlocked" => 1));
        die;