Example #1
0
function set_attendance($raider, $night, $status, $comment = '')
{
    global $error, $success, $db;
    $data = array('raider_id' => $raider->id, 'night' => $night, 'status' => $status, 'time' => time(), 'comment' => $comment);
    if (!is_numeric($night) && $status == STATUS_CLEAR) {
        // A range of nights, convert all nights from start till end to the state
        $sql = 'SELECT time, comment, status FROM ' . RAIDATTENDANCE_TABLE . " WHERE raider_id={$raider->id} AND night='{$night}'";
        $res = $db->sql_query($sql);
        $row = $db->sql_fetchrow($res);
        $time = $row['time'];
        $old_comment = $row['comment'];
        $old_status = $row['status'];
        $db->sql_freeresult($res);
        $day_num = get_day_number($night);
        $all_nights = get_raiding_dates($time, $data['time'], array($day_num));
        $ary = array();
        foreach ($all_nights as $raid_night) {
            // Check whether the night already has another status
            $sql = 'SELECT COUNT(status) cnt FROM ' . RAIDATTENDANCE_TABLE . " WHERE raider_id={$raider->id} AND night='{$raid_night}'";
            $res = $db->sql_query($sql);
            $row = $db->sql_fetchrow($res);
            $already_have_status = $row['cnt'] > 0;
            $db->sql_freeresult($res);
            if (!$already_have_status) {
                $ary[] = array('raider_id' => $raider->id, 'night' => $raid_night, 'status' => $old_status, 'time' => $time, 'comment' => $old_comment);
            }
        }
        $res = $db->sql_multi_insert(RAIDATTENDANCE_TABLE, $ary);
        if (is_dbal_error()) {
            $error[] = $res;
        }
    }
    // One night
    $up_array = array('status' => $status, 'comment' => $comment);
    $sql = 'UPDATE ' . RAIDATTENDANCE_TABLE . " SET " . $db->sql_build_array('UPDATE', $up_array) . " WHERE raider_id={$raider->id} AND night='{$night}'";
    $res = $db->sql_query($sql, 0);
    if ($db->sql_affectedrows() >= 1) {
        return;
    }
    $ary = array($data);
    $res = $db->sql_multi_insert(RAIDATTENDANCE_TABLE, $ary);
    if (is_dbal_error()) {
        $error[] = $res;
    }
}
Example #2
0
function render_open_date($open_date)
{
    $dayCodes = create_day_array($open_date);
    $dayList = array('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su');
    if ($dayCodes == null) {
        return null;
    }
    // Loop on week days to determine if stores are open past midnight
    $result = array();
    $dayIndex = 0;
    $index = 0;
    $cleanedDayArray = getCleanedDayArray($dayCodes);
    //dprint_r($cleanedDayArray);
    ksort($cleanedDayArray);
    foreach ($cleanedDayArray as $key => $day) {
        if (empty($cleanedDayArray[$key + 1])) {
            if (isset($cleanedDayArray[0])) {
                $nextDay = $cleanedDayArray[0];
            }
        } else {
            $nextDay = $cleanedDayArray[$key + 1];
        }
        $today = $day;
        $lastTodayHour = isset($today['openHours'][count($today['openHours']) - 1][1]) ? $today['openHours'][count($today['openHours']) - 1][1] : '';
        if (isset($nextDay['openHours'][0][0])) {
            $firstNextDayHour = $nextDay['openHours'][0][0];
        }
        if (!(strcmp($today['openHours'][0][0], "00H00") == 0 && strcmp($today['openHours'][0][1], "24H00") == 0)) {
            if (strcmp($lastTodayHour, "00H00") == 0 || strcmp($lastTodayHour, "24H00") == 0) {
                if (strcmp($firstNextDayHour, "00H00") == 0 || strcmp($firstNextDayHour, "24H00") == 0) {
                    $today['openHours'][count($today['openHours']) - 1][1] = $nextDay['openHours'][0][1];
                }
            }
        }
        if (count($today['openHours']) > 1 && (strcmp($today['openHours'][0][0], "00H00") == 0 || strcmp($today['openHours'][0][0], "24H00") == 0)) {
            array_shift($today['openHours']);
        }
        $dayNumber = get_day_number($today['dayCode']);
        if ($dayNumber == null) {
            continue;
        }
        $dayInfo = array();
        $dayInfo["day"] = $today['dayCode'];
        $dayInfo["openingHours"] = $today['openHours'];
        $result[$dayNumber] = $dayInfo;
    }
    return $result;
}