$raid_id = get_default_raid_id();
 }
 $user->add_lang(array('mods/mod_raidattendance', 'mods/info_acp_raidattendance', 'mods/logs_raidattendance'));
 $success = array();
 $error = array();
 $tstamp = request_var('tstamp', 0);
 #$tnow = $user->time_now;
 date_default_timezone_set("Etc/UTC");
 $tnow = time();
 $tnow += 60 * 60 * $config['raidattendance_timezone'];
 $tstamp = $tstamp > 0 ? $tstamp : $tnow;
 $now = strftime('%H:%M', $tnow);
 $today = strftime('%Y%m%d', $tnow);
 $raid_time = $config['raidattendance_raid_time'];
 $signoff_time = $config['raidattendance_raid_late'];
 $raids = get_raiding_days($tstamp, $raid_id);
 $raider_db = new raider_db();
 $raiders = array();
 $raider_db->get_raider_list($raiders, $raid_id, $sort_order);
 $action = request_var('u_action', '');
 if ($action) {
     handle_action($action, $raiders);
 }
 $day_names = get_raiding_day_names($raids);
 $attendance = get_attendance($raids, $raid_id);
 $static_attendance = get_static_attendance($raids);
 add_static_attendance($raids, $attendance, $static_attendance);
 $rowno = 0;
 $statusses = array(STATUS_ON => 'on', STATUS_OFF => 'off', STATUS_NOSHOW => 'noshow', STATUS_LATE => 'late', STATUS_SUBSTITUTE => 'substitute', 0 => 'future', -1 => 'past', -2 => 'unset', STATUS_LATE_SIGNOFF => 'late_signoff');
 $raid_sums = array();
 $raidData = array();
Example #2
0
function get_attendance_for_time($starttime, $endtime, $raid_id = 0)
{
    global $db, $error;
    $raiding_days = get_raiding_days($endtime, $raid_id);
    $start_raid = strftime("%Y%m%d", $starttime);
    $end_raid = strftime("%Y%m%d", $endtime);
    $raiding_day_names = array();
    // raiding_days is for 3 weeks
    for ($i = 0; $i < sizeof($raiding_days) / 3; $i++) {
        $raiding_day_names[] = get_raiding_day_name($raiding_days[$i]);
    }
    $sql = 'SELECT n.status status, r.name name, n.night night FROM ' . RAIDATTENDANCE_TABLE . ' n, ' . RAIDER_TABLE . " r WHERE r.id = n.raider_id AND ((n.night >='{$start_raid}' AND n.night <= '{$end_raid}' AND (" . $db->sql_in_set("DATE_FORMAT(STR_TO_DATE(n.night,'%Y%m%d'),'%a')", $raiding_day_names) . ')) OR (' . $db->sql_in_set('n.night', $raiding_day_names) . '))';
    // TODO: day_name <= now (static shouldn't be counted when in future...)
    // Overlay instead of one query!
    $sql = $sql . " UNION SELECT n.status status, '__RAID__' name, n.night FROM " . RAIDATTENDANCE_TABLE . ' n WHERE n.raid_id=' . $raid_id . " AND n.night >='{$start_raid}' AND n.night <= '{$end_raid}'";
    $result = $db->sql_query($sql);
    $attendance = array();
    $nights = array();
    // Add summary columns
    for ($i = STATUS_CLEAR; $i <= STATUS_CANCELLED; $i++) {
        $nights['summary_' . $i] = 0;
    }
    while ($row = $db->sql_fetchrow($result)) {
        //$name = utf8_decode($row['name']);
        $name = $row['name'];
        if (is_array($attendance[$name])) {
            $attendance[$name][$row['night']] = $row['status'];
        } else {
            $attendance[$name] = array($row['night'] => $row['status']);
        }
        if (is_array($nights[$row['night']])) {
            $nights[$row['night']][$name] = $row['status'];
        } else {
            $nights[$row['night']] = array($name => $row['status']);
        }
    }
    $db->sql_freeresult($result);
    // Static attendance
    $raider_active = array();
    ksort($nights);
    foreach ($nights as $night => $raiders) {
        $day_name = is_numeric($night) ? get_raiding_day_name($night) : $night;
        foreach ($attendance as $raider => &$rnights) {
            if (!is_numeric($night)) {
                if (strncmp('summary_', $night, 8) == 0 && !isset($rnights[$night])) {
                    $rnights[$night] = 0;
                }
                continue;
                // Only handle the "real nights" this way...
            }
            // If raider is not active, but have a status for this night - make him active
            if (!isset($raider_active[$raider]) && isset($rnights[$night])) {
                $raider_active[$raider] = true;
            }
            // If raider is active, but don't have an entry for this night, but one for the name
            if ($raider_active[$raider] && !isset($rnights[$night]) && isset($rnights[$day_name])) {
                $rnights[$night] = $rnights[$day_name];
            }
            if (!isset($rnights[$night])) {
                // Explicitly set the "NOTHING" status
                $rnights[$night] = STATUS_CLEAR;
            }
            // Should not be needed (we have it above) - but just in case...
            if (!isset($rnights['summary_' . $rnights[$night]])) {
                $rnights['summary_' . $rnights[$night]] = 0;
            }
            // Only count the nights within the begin-end
            if ($night >= $begintime && $night <= $end_raid) {
                $rnights['summary_' . $rnights[$night]] = 1 + $rnights['summary_' . $rnights[$night]];
            }
        }
    }
    foreach ($attendance as $raider => &$nights) {
        $sum = $nights['summary_1'] + $nights['summary_2'] + $nights['summary_3'] + $nights['summary_4'] + $nights['summary_5'] + $nights['summary_6'];
        if ($sum == 0) {
            $sum = 1;
        }
        for ($i = 1; $i <= 6; $i++) {
            $nights['summary_' . $i . '_num'] = $nights['summary_' . $i];
            $nights['summary_' . $i] = $nights['summary_' . $i] * 100 / $sum;
        }
    }
    return $attendance;
}