예제 #1
0
function audit_amounts(&$state, &$logdate, &$status)
{
    global $_DB;
    if ($state->row > 0) {
        //updating (0 is add row)
        $record = reset($state->records);
        if ($record["ID"] == 0) {
            throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid POST 1", true);
        }
    }
    $day = clone $logdate;
    $columns = $state->mode == "l" ? 1 : $state->columns[COL_COUNT];
    for ($ndx = 0; $ndx < $columns; $ndx++, $day->add(new DateInterval('P1D'))) {
        if (!isset($_POST["amount" . $ndx]) || $_POST["amount" . $ndx] == "" || $ndx < $state->columns[COL_OPEN] && $state->mode == "t") {
            $status[] = '';
            //no change to this record
            continue;
        }
        if (!isset($_POST["rec" . $ndx])) {
            throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid POST 3", true);
        }
        $recID = $_POST["rec" . $ndx];
        //from data-recid attribute
        $amount = $_POST["amount" . $ndx];
        $state->msgStatus = "!Please enter a valid amount (" . $ndx . ")";
        if (!audit_amount($state, $recID, $amount, $day->format("Y-m-d"))) {
            return false;
        }
        if ($recID == 0) {
            //if adding hours, we're done
            if ($amount == 0) {
                $status[] = '';
            } else {
                $status[] = 'a';
            }
            continue;
        }
        foreach ($state->records as $ID => $record) {
            //find our record
            if ($record["ID"] == $recID) {
                break;
            }
            array_shift($state->records);
            if (count($state->records) == 0) {
                throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid POST 5", true);
            }
        }
        if ($amount == 0) {
            $status[] = 'd';
        } elseif ($amount == $record["amount"]) {
            $status[] = '';
        } else {
            $status[] = 'u';
        }
    }
    $state->msgStatus = "-";
    //tell server_call to reset page
    return true;
}
예제 #2
0
function new_amount(&$state)
{
    log_list($state, $state->row);
    //find this row's records
    //Do audits:
    $record = reset($state->records);
    if ($state->type == "") {
        $state->type = $record["type"];
    }
    $status = "";
    if (!audit_amount($state, $status)) {
        return;
    }
    //Do DB changes:
    //	adding a row but didn't select existing activity:
    if ($state->row == 0 && $state->activity_id == 0) {
        add_activity($state);
    }
    switch ($status) {
        case 'a':
            //add
            add_log($state);
            break;
        case 'u':
            //update
            update_log($state);
            break;
        case 'd':
            //delete
            delete_log($state);
            break;
    }
}