summaryrefslogtreecommitdiffstats
path: root/viewraid.php
blob: 6a024bc051b7b2eb51e71d43d183b804f7f11f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/******************************
 * EQdkp
 * Copyright 2002-2005
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * viewraid.php
 * Began: Thu December 19 2002
 *
 * $Id: viewraid.php 46 2007-06-19 07:29:11Z tsigo $
 *
 ******************************/

define('EQDKP_INC', true);
$eqdkp_root_path = './';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('u_raid_view');

if ( (isset($_GET[URI_RAID])) && (intval($_GET[URI_RAID] > 0)) )
{
    $sql = 'SELECT raid_id, raid_name, raid_date, raid_note, raid_value, raid_added_by, raid_updated_by
            FROM ' . RAIDS_TABLE . "
            WHERE raid_id='".$_GET[URI_RAID]."'";

    if ( !($raid_result = $db->query($sql)) )
    {
        message_die('Could not obtain raid information', '', __FILE__, __LINE__, $sql);
    }

    // Check for valid raid
    if ( !$raid = $db->fetch_record($raid_result) )
    {
        message_die($user->lang['error_invalid_raid_provided']);
    }
    $db->free_result($raid_result);

    //
    // Attendees
    //
    $sql = 'SELECT member_name
            FROM ' . RAID_ATTENDEES_TABLE . "
            WHERE raid_id='".$raid['raid_id']."'
            ORDER BY member_name";
    $result = $db->query($sql);

   // add a faliure check here

    while ( $arow = $db->fetch_record($result) )
    {
        $attendees[] = addslashes($arow['member_name']);
    }
    $db->free_result($result);

    // Get each attendee's rank
    $ranks = array();
    $sql = 'SELECT m.member_name, r.rank_prefix, r.rank_suffix
            FROM ( ' . MEMBERS_TABLE . ' m
            LEFT JOIN ' . MEMBER_RANKS_TABLE . " r
            ON m.member_rank_id = r.rank_id )
            WHERE m.member_name IN ('" . implode("', '", $attendees) . '\')';
    $result = $db->query($sql);
    while ( $row = $db->fetch_record($result) )
    {
        $ranks[ $row['member_name'] ] = array(
            'prefix' => (( !empty($row['rank_prefix']) ) ? $row['rank_prefix'] : ''),
            'suffix' => (( !empty($row['rank_suffix']) ) ? $row['rank_suffix'] : '')
        );
    }
    $db->free_result($result);

    if ( @sizeof($attendees) > 0 )
    {
        // First get rid of duplicates and resort them just in case,
        // so we're sure they're displayed correctly
        $attendees = array_unique($attendees);
        sort($attendees);
        reset($attendees);
        $rows = ceil(sizeof($attendees) / $user->style['attendees_columns']);

        // First loop: iterate through the rows
        // Second loop: iterate through the columns as defined in template_config,
        // then "add" an array to $block_vars that contains the column definitions,
        // then assign the block vars.
        // Prevents one column from being assigned and the rest of the columns for
        // that row being blank
        for ( $i = 0; $i < $rows; $i++ )
        {
            $block_vars = array();
            for ( $j = 0; $j < $user->style['attendees_columns']; $j++ )
            {
                $offset = ($i + ($rows * $j));
                $attendee = ( isset($attendees[$offset]) ) ? $attendees[$offset] : '';

                $html_prefix = ( isset($ranks[$attendee]) ) ? $ranks[$attendee]['prefix'] : '';
                $html_suffix = ( isset($ranks[$attendee]) ) ? $ranks[$attendee]['suffix'] : '';

                if ( $attendee != '' )
                {
                    $block_vars += array(
                        'COLUMN'.$j.'_NAME' => '<a href="viewmember.php' . $SID . '&amp;' . URI_NAME . '=' . $attendee . '">' . $html_prefix . $attendee . $html_suffix . '</a>'
                    );
                }
                else
                {
                    $block_vars += array(
                        'COLUMN'.$j.'_NAME' => ''
                    );
                }

                // Are we showing this column?
                $s_column = 's_column'.$j;
                ${$s_column} = true;
            }
            $tpl->assign_block_vars('attendees_row', $block_vars);
        }
        $column_width = floor(100 / $user->style['attendees_columns']);
    }
    else
    {
        message_die('Could not get raid attendee information.','Critical Error');
    }

    //
    // Drops
    //
    $sql = 'SELECT item_id, item_buyer, item_name, item_value
            FROM ' . ITEMS_TABLE . "
            WHERE raid_id='".$raid['raid_id']."'";
    if ( !($items_result = $db->query($sql)) )
    {
        message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql);
    }
    while ( $item = $db->fetch_record($items_result) )
    {
        $tpl->assign_block_vars('items_row', array(
            'ROW_CLASS'    => $eqdkp->switch_row_class(),
            'BUYER'        => $item['item_buyer'],
            'U_VIEW_BUYER' => 'viewmember.php' . $SID . '&amp;' . URI_NAME . '='.$item['item_buyer'],
            'NAME'         => stripslashes($item['item_name']),
            'U_VIEW_ITEM'  => 'viewitem.php' . $SID . '&amp;' . URI_ITEM . '='.$item['item_id'],
            'VALUE'        => $item['item_value'])
        );
    }

    //
    // Class distribution
    //
    // If an element is false, that class didn't attend this raid
    // New for 1.3 - grab class information from the database

    $eq_classes = array();
    $total_attendees = sizeof($attendees);

    // Get each attendee's class
    $sql = 'SELECT m.member_name, c.class_name AS member_class
            FROM ' . MEMBERS_TABLE . ' m, ' .CLASS_TABLE ." c
	    WHERE m.member_class_id = c.class_id 
            AND member_name IN ('" . implode("', '", $attendees) . '\')';
    $result = $db->query($sql);
    while ( $row = $db->fetch_record($result) )
    {
        $member_name = $row['member_name'];
	$member_class = $row['member_class'];

        if ( $member_name != '' )
        {
            $html_prefix = ( isset($ranks[$member_name]) ) ? $ranks[$member_name]['prefix'] : '';
            $html_suffix = ( isset($ranks[$member_name]) ) ? $ranks[$member_name]['suffix'] : '';

            $eq_classes[ $row['member_class'] ] .= " " . $html_prefix . $member_name . $html_suffix .",";
	    $class_count[ $row['member_class'] ]++;
        }
    }
    $db->free_result($result);
    unset($ranks);
    

    // Now find out how many of each class there are
    foreach ( $eq_classes as $class => $members )
    {
	$percentage =  ( $total_attendees > 0 ) ? round(($class_count[$class] / $total_attendees) * 100) : 0;

        $tpl->assign_block_vars('class_row', array(
            'CLASS'     => $class,
            'BAR'       => create_bar(($class_count[ $class ] * 10), $class_count[ $class ] . ' (' . $percentage . '%)'),
            'ATTENDEES' => $members)
        );
    }
    unset($eq_classes);





    $tpl->assign_vars(array(
        'L_MEMBERS_PRESENT_AT' => sprintf($user->lang['members_present_at'], stripslashes($raid['raid_name']),
                                  date($user->style['date_notime_long'], $raid['raid_date'])),
        'L_ADDED_BY'           => $user->lang['added_by'],
        'L_UPDATED_BY'         => $user->lang['updated_by'],
        'L_NOTE'               => $user->lang['note'],
        'L_VALUE'              => $user->lang['value'],
        'L_DROPS'              => $user->lang['drops'],
        'L_BUYER'              => $user->lang['buyer'],
        'L_ITEM'               => $user->lang['item'],
        'L_SPENT'              => $user->lang['spent'],
        'L_ATTENDEES'          => $user->lang['attendees'],
        'L_CLASS_DISTRIBUTION' => $user->lang['class_distribution'],
        'L_CLASS'              => $user->lang['class'],
        'L_PERCENT'            => $user->lang['percent'],
        'L_RANK_DISTRIBUTION'  => $user->lang['rank_distribution'],
        'L_RANK'               => $user->lang['rank'],

        'S_COLUMN0' => ( isset($s_column0) ) ? true : false,
        'S_COLUMN1' => ( isset($s_column1) ) ? true : false,
        'S_COLUMN2' => ( isset($s_column2) ) ? true : false,
        'S_COLUMN3' => ( isset($s_column3) ) ? true : false,
        'S_COLUMN4' => ( isset($s_column4) ) ? true : false,
        'S_COLUMN5' => ( isset($s_column5) ) ? true : false,
        'S_COLUMN6' => ( isset($s_column6) ) ? true : false,
        'S_COLUMN7' => ( isset($s_column7) ) ? true : false,
        'S_COLUMN8' => ( isset($s_column8) ) ? true : false,
        'S_COLUMN9' => ( isset($s_column9) ) ? true : false,

        'COLUMN_WIDTH' => ( isset($column_width) ) ? $column_width : 0,
        'COLSPAN'      => $user->style['attendees_columns'],

        'RAID_ADDED_BY'       => ( !empty($raid['raid_added_by']) ) ? stripslashes($raid['raid_added_by']) : 'N/A',
        'RAID_UPDATED_BY'     => ( !empty($raid['raid_updated_by']) ) ? stripslashes($raid['raid_updated_by']) : 'N/A',
        'RAID_NOTE'           => ( !empty($raid['raid_note']) ) ? stripslashes($raid['raid_note']) : '&nbsp;',
        'DKP_NAME'            => $eqdkp->config['dkp_name'],
        'RAID_VALUE'          => $raid['raid_value'],
        'ATTENDEES_FOOTCOUNT' => sprintf($user->lang['viewraid_attendees_footcount'], sizeof($attendees)),
        'ITEM_FOOTCOUNT'      => sprintf($user->lang['viewraid_drops_footcount'], $db->num_rows($items_result)))
    );

    $eqdkp->set_vars(array(
        'page_title'    => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['viewraid_title'],
        'template_file' => 'viewraid.html',
        'display'       => true)
    );
}
else
{
    message_die($user->lang['error_invalid_raid_provided']);
}
?>