| admin_login.php | index.php | plugins_footer.php | plugins_header.php | qt_viewquests.php | qt_viewtimers.php | quest_timer.php | quest_timer/loadquests.php | quest_timer/newquests.php | quest_timer/savequests.php | quest_timer/submitquests.php | scroll_manager.php | show_create.php | sql_config_example.php | viewsource.php |

qt_viewtimers.php

  [Go to page]


<?php
    
    
if (isset($_GET['viewsource']))
    {
        echo(
"<table><tr><td nowrap>");
        
show_source("qt_viewtimers.php");
        die(
"</td></tr></table>");
    }

    
error_reporting(E_ALL E_NOTICE E_WARNING);
    
    
$action $_REQUEST['action'];
    if (
$action == 'account')
    {
        if (isset(
$_POST['qt_username']))
            
setcookie('qt_username'$_POST['qt_username'], strtotime("1 year"));
        else
            
$_POST['qt_username'] = $_COOKIE['qt_username'];
        
        if (isset(
$_POST['qt_password']))
            
setcookie('qt_password'$_POST['qt_password'], strtotime("1 year"));
        else
            
$_POST['qt_password'] = $_COOKIE['qt_password'];
    }
    elseif (
$action == 'logout')
    {
        
setcookie('qt_username''');
        
setcookie('qt_password''');
        
$_REQUEST['qt_username'] = '';
        
$_REQUEST['qt_password'] = '';
    }
    
    if (isset(
$_GET['server']))
    {
        $
$_GET['server'] = 'selected';
        
setcookie('qt_server'$_GET['server'], strtotime("1 year"));
    }
    elseif (isset(
$_COOKIE['qt_server']))
        $
$_COOKIE['qt_server'] = 'selected';
    
    if (isset(
$_GET['qt_sort_type']) || isset($_COOKIE['qt_sort_type']))
    {
        
$qt_sort_type = isset($_GET['qt_sort_type']) ? $_GET['qt_sort_type'] : $_COOKIE['qt_sort_type'];
        if (
$qt_sort_type == 'characters')
            
setcookie('qt_sort_type''characters'strtotime("1 year"));
        else
            
setcookie('qt_sort_type''');
    }
    
    require_once(
'plugins_header.php');
    
    if (!
defined('MYSQL_CONNECTED'))
        die(
"Failed to connect to database");
    
    
//Set up XML parser
    
$x_Parser xml_parser_create();
    
xml_parser_set_option($x_ParserXML_OPTION_CASE_FOLDINGfalse);
    
xml_set_element_handler($x_Parser"parse_startElement""parse_endElement");
        
    function 
parse_startElement($parser$name$attrs)
    {
        global 
$x_QuestName$x_Duration$char$quest_data$quest_durations$char_data$gmtoffset;
        switch (
$name)
        {            
            case 
"Quest":
                
$x_QuestName $attrs['QuestName'];
                
$x_Duration = ($attrs['Days'] * 24 60 60) + ($attrs['Hours'] * 60 60) + ($attrs['Minutes'] * 60);
                
$quest_data[$x_QuestName] = NULL//Add the quest to the array
                
$quest_durations[$x_QuestName] = $attrs[Days] Day" . ($attrs['Days'] == "" "s") . 
                    (
$attrs['Hours'] || $attrs['Minutes'] ? ", $attrs[Hours] Hours" "") . 
                    (
$attrs['Minutes'] ? ", $attrs[Minutes] Minutes" "");
                break;
                
            case 
"Character":
                
$this_char "$attrs[Name] [$attrs[Server]]";
                
$expire strtotime($attrs['Completed'] . $gmtoffset) + $x_Duration;
                
$quest_data[$x_QuestName][$this_char] = $expire time();
                
$char_data[$this_char '$' $x_QuestName] = $expire time();
                break;
        }
    }
    
    function 
parse_endElement($parser$name)
    {
        
// Do nothing
    
}
    
    function 
get_quest_data($sql)
    {
        global 
$x_Parser$gmtoffset$data;
        if (
$result mysql_query($sql))
        {
            if (
$data mysql_fetch_array($result))
            {
                
$gmtoffset $data['gmtoffset'];
                
$questxml gzuncompress($data['questxml']) or die('<error reason="Failed to uncompress Quest XML from database" />');
                
xml_parse($x_Parser$questxml) or die(xml_error_string(xml_get_error_code($parser)));
                return 
true;
            }
            return 
false;
        }
        else die(
"get_results() - SQL Query error: " mysql_error());            
    }
    
    function 
sort_quests(&$quest_data_param)
    {
        
$GLOBALS["quest_data_sort"] =& $quest_data_param;
        return 
uksort($quest_data_param"sort_quests_compare");
    }
    
    function 
sort_quests_compare($a$b
    
// Puts quests that have been completed first, followed by quests that have not been completed
    // Within each category, it sorts by name
    
{
        
$isarr_a is_array($GLOBALS["quest_data_sort"][$a]);
        if (
$isarr_a  == is_array($GLOBALS["quest_data_sort"][$b])) //Both arrays or both not arrays: sort alphabetically
            
return strcasecmp($a$b);
        else
            return 
$isarr_a ? -1;
    }
    
    function 
sort_chars(&$char_data_param)
    {
        
$GLOBALS["char_data_sort"] =& $char_data_param;
        return 
uksort($char_data_param"sort_chars_compare");
    }
    
    function 
sort_chars_compare($a$b
    
// Puts timers that have expired first, followed by timers that are ticking
    // Within each category, it sorts by name
    // $a and $b are CharName$QuestName combos (keys to $char_data)
    
{
        if (
$GLOBALS["char_data_sort"][$a] < && $GLOBALS["char_data_sort"][$b] < 0)
            return 
strcasecmp($a$b);
        else
            return 
$GLOBALS["char_data_sort"][$a] - $GLOBALS["char_data_sort"][$b];
    }
    
    function 
format_time_left($seconds)
    {
        if (
$seconds 0)
            return 
"Time Up";
        
        
$days floor($seconds / (24 60 60));
        
$seconds $seconds % (24 60 60);
        
$hours floor($seconds / (60 60));
        
$seconds $seconds % (60 60);
        
$minutes floor($seconds 60);
        
$seconds $seconds 60;
        if (
$hours 10$hours "0" $hours;
        if (
$minutes 10$minutes "0" $minutes;
        if (
$seconds 10$seconds "0" $seconds;
        return 
$days "D " $hours "H " $minutes "M " $seconds "S";
    }
?>

<script language="javascript">
    function tick(c)
    {
        for(i = 0; i < c; i++)
        {
            seconds = timeleft[i]--;
            if (seconds <= 0)
            {
                document.getElementById('quest' + i).innerHTML = "Time Up";
            }
            else
            {
                days = Math.floor(seconds / (24 * 60 * 60)) + "";
                seconds = seconds % (24 * 60 * 60);
                hours = Math.floor(seconds / (60 * 60)) + "";
                seconds = seconds % (60 * 60);
                minutes = Math.floor(seconds / 60) + "";
                seconds = seconds % 60 + "";
                if (hours.length == 1) hours = "0" + hours;
                if (minutes.length == 1) minutes = "0" + minutes;
                if (seconds.length == 1) seconds = "0" + seconds;
                document.getElementById('quest' + i).innerHTML = days + "D " + hours + "H " + minutes + "M " + seconds + "S";
            }
        }
    }
</script>

<table width="100%" cellpadding="8" cellspacing="2">
    <tr>
        <td class="catHead"><table cellpadding="2" cellspacing="0">
                <tr>
                    <td><?=icon('quest_timer')?></td>
                    <td><span class="subtitle">Quest Timer - View Quest Timers</span></td>
            </table>
        </td>
    </tr>
    <tr>
        <td class="row1"><a href="quest_timer.php">&laquo; Back to the main Quest Timer page</a><br>
            <span class="genmed">Note: If your browser tells you this page has expired, put a space at 
            the end of the URL and hit enter.</span></td>
    </tr>
    <tr>
        <td height="5"></td>
    </tr>
    <tr>
        <td class="catHead"><b>View Timers</b></td>
    </tr>
    <tr>
        <td class="row1">
            You need to be using Quest Timer v2.2.0 or greater and enable quest uploading to acasylum.azurewebsites.net to use this feature<br><br>
            <table cellpadding="2" cellspacing="2" width="100%"><tr><td class="row2_over" width="48%">
            Search for quest timers from a single character<br><br>
            <form action="<?= $_SERVER['SCRIPT_NAME'?>" method="get" name="frmSingleChar">
                <input type="hidden" name="mode" value="<?= $_GET['mode'?>">
                <input type="hidden" name="action" value="char">
                <table cellpadding="2" cellspacing="2">
                    <tr>
                        <td>Character's Name</td>
                        <td><input type="text" name="char_name" size="20" value="<?= isset($_GET['char_name']) ? stripslashes($_GET['char_name']) : "" ?>"></td>
                    </tr>
                    <tr>
                        <td>Server</td>
                        <td>
                            <select name="server">
                                <option value="Leafcull" <?=$Leafcull?>>Leafcull</option>
                                <option value="Frostfell" <?=$Frostfell?>>Frostfell</option>
                                <option value="Harvestgain" <?=$Harvestgain?>>Harvestgain</option>
                                <option value="Thistledown" <?=$Thistledown?>>Thistledown</option>
                                <option value="Morningthaw" <?=$Morningthaw?>>Morningthaw</option>
                                <option value="Wintersebb" <?=$Wintersebb?>>Wintersebb</option>
                                <option value="Solclaim" <?=$Solclaim?>>Solclaim</option>
                                <option value="Verdantine" <?=$Verdantine?>>Verdantine</option>
                                <option value="Darktide" <?=$Darktide?>>Darktide</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input class="mainoption" type="submit" value="Look up"></td>
                    </tr>
                </table>
            </form>
            </td><td class="row2_over" width="52%">
            Or, log in to view the quest timers for all your characters<br><br>
            <form action="<?= $_SERVER['SCRIPT_NAME'] . '?mode=' $_GET['mode'] . '&action=account' ?>" method="post" name="frmAccount">
                <table cellpadding="2" cellspacing="2">
                    <tr>
                        <td>Username</td>
                        <td><input type="text" name="qt_username" size="20" value="<?= $_REQUEST['qt_username'?>"></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="password" name="qt_password" size="20" value="<?= $_REQUEST['qt_password'?>"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input class="mainoption" type="submit" value="Log In">
                            <?php if($_REQUEST['qt_username'] && $_REQUEST['qt_password']) { ?>
                                &nbsp;&nbsp;<input class="liteoption" type="button" value="Log Out" onClick="document.location='<?= $_SERVER['SCRIPT_NAME'] . '?mode=' $_GET['mode'] . '&action=logout' ?>'">
                            <?php ?>
                        </td>
                    </tr>
                </table>
            </form>
            </td></tr></table>
        </td>
    </tr>
<?php
    
if (!isset($_REQUEST['action']) && isset($_COOKIE['qt_username']) && isset($_COOKIE['qt_password']))
        
$action 'auto_account'//Auto-login the person
    
switch ($action)
    {
        case 
'char':
            
$char $_REQUEST['char_name'] . " [" $_REQUEST['server'] . "]";
?>
    <tr>
        <td height="5"></td>
    </tr>
    <tr>
        <td class="catHead"><b>Quest Timers for <?= stripslashes($_REQUEST['char_name']) . " on " $_REQUEST['server'?></b></td>
    </tr>
    <tr>
        <td class="row1">
            <?
            
//$quests_timeleft will store the time left for the quests that the character has completed
            
if (get_quest_data("SELECT * FROM QuestTimer_UserQuests WHERE FIND_IN_SET('$char', acctchars) ORDER BY lastmodified DESC"))
            {
                
$lastuploaded strtotime($data['lastuploaded'] . "+0000");
                if (
strtotime("1 month ago") > $lastuploaded)
                    
$span_style "style='color:#FF1100'"//red
                
elseif (strtotime("1 week ago") > $lastuploaded)
                    
$span_style "class='emote'"//orange
                
switch ($_REQUEST['server'])
                {
                    case 
'Leafcull'$tmp_server 'LC'; break;
                    case 
'Frostfell'$tmp_server 'FF'; break;
                    case 
'Harvestgain'$tmp_server 'HG'; break;
                    case 
'Thistledown'$tmp_server 'TD'; break;
                    case 
'Morningthaw'$tmp_server 'MT'; break;
                    case 
'Wintersebb'$tmp_server 'WE'; break;
                    case 
'Solclaim'$tmp_server 'SC'; break;
                    case 
'Verdantine'$tmp_server 'VT'; break;
                    case 
'Darktide'$tmp_server 'DT'; break;
                }
                
$tmp_url "http://" $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "qt.php?n=" stripslashes($_REQUEST['char_name']) . "&s=$tmp_server";
                if (
$lastuploaded !== -1)
                    echo 
"<span $span_style>Last updated: <b>" date("F j, Y, g:i A"$lastuploaded) . "</b></span><br><br>";
                echo 
"You can use the following as a shorter link to get to this page: <a class='cod' href=\"$tmp_url\">$tmp_url</a><br><br>";
            
?>
            
            <table cellpadding="4" cellspacing="2" width="100%">
                <tr>
                    <th align="left" width="300" nowrap><b>Quest Name</b></th>
                    <th align="left" width="100%" nowrap><b>Time Remaining</b></th>
                </tr>
                <?php
                    
foreach($quest_data as $QuestName => $TimeLeftArr)
                    {
                        foreach(
$TimeLeftArr as $CharName => $TimeLeft)
                        {
                            if (
strtolower($CharName) == strtolower(stripslashes($char)))
                            {
                                
$quests_timeleft[$QuestName] = $TimeLeft;
                                
#unset($quest_data[$QuestName]); //Remove from the array of quests, so that this array can be used as "Quests Not Completed"
                                
break;
                            }
                        }
                    }
                    
sort_chars($quests_timeleft); // Sort "Time Up" quests by name, others by time left
                    //asort($quests_timeleft, SORT_NUMERIC); //Sort by time left
                    
                    
$c 0;
                    
$row 0;
                    foreach(
$quests_timeleft as $QuestName => $TimeLeft)
                    {    
                        
$row++;
                        if (
$TimeLeft 0)
                        {
                            
?>
                            <tr>
                                <td class="row<?= $row 2 ?>" nowrap><?= htmlspecialchars($QuestName?></td>
                                <td class="row<?= $row 2 ?>" nowrap><span id="quest<?=$c?>"><?=format_time_left($TimeLeft)?></span></td>
                            </tr>
                            <?
                            $js_var_inits 
.=  "\n    timeleft[$c] = $TimeLeft;";
                            
$c++;
                        }
                        else
                        {
                            
?>
                            <tr>
                                <td class="row<?= $row 2 ?>" nowrap><?= htmlspecialchars($QuestName?></td>
                                <td class="row<?= $row 2 ?>" nowrap>Time Up</td>
                            </tr>
                            <?
                        
}
                    } 
// foreach($quests_timeleft ...)
                    
?>
            </table>
            <script language="javascript">
                var timeleft = new Array(<?=$c?>);
                <?= $js_var_inits ?>
                
                tick(<?=$c?>);
                window.setInterval("tick(<?=$c?>)", 1000);
            </script>
                    <?
                
// if (get_quest_data(...))
                
else
                    echo 
"<span class='emote'><b><i>No Quest Timer info found for " stripslashes($_REQUEST['char_name']) . " on $_REQUEST[server]</i></b></span><br>
                        Either " 
stripslashes($_REQUEST['char_name']) . " hasn't completed any quests, or isn't uploading to <i>this</i> website with Quest Timer v2.2.0+";
                
?>
        </td>
    </tr>
            <?
            
break;
        
        case 
'auto_account':
        case 
'account':
            
$username $action == 'account' $_POST['qt_username'] : $_COOKIE['qt_username'];
            
$password $action == 'account' $_POST['qt_password'] : $_COOKIE['qt_password'];
            if (
get_quest_data("SELECT * FROM QuestTimer_UserQuests WHERE username='$username' AND password='$password'"))
            {
    
?>
    <tr>
        <td height="5"></td>
    </tr>
    <tr>
        <td class="catHead"><b>Quest Timers for <?= $username ?></b></td>
    </tr>
    <tr>
        <td class="row1">
            <?
                $lastuploaded 
strtotime($data['lastuploaded'] . "+0000");
                if (
strtotime("1 month ago") > $lastuploaded)
                    
$span_style " style='color:#FF1100'"//red
                
elseif (strtotime("1 week ago") > $lastuploaded)
                    
$span_style " class='emote'"//orange
                
                
if ($qt_sort_type != 'characters'):
            
?>
                <table cellpadding="2" cellspacing="2" border="0" width="100%">
                    <tr>
                        <td align="left"><span<?=$span_style?>>Last updated: <b><?= date("F j, Y, g:i A"$lastuploaded?></b></span></td>
                        <td align="right"><a class="genmed" href="<?= $_SERVER['PHP_SELF'] . '?mode=' $_GET['mode'?>&qt_sort_type=characters">Show 
                            only characters sorted by time left</a></td>
                    </tr>
                </table>
                <br>
                <table cellpadding="4" cellspacing="2" width="100%">
                    <tr>
                        <th align="left" width="300" nowrap><b>Quest Name</b></th>
                        <th align="left" width="100%" nowrap><b>Duration / Time Remaining</b></th>
                    </tr>
                <?php
                    sort_quests
($quest_data); //Puts quests that have been completed first, followed by quests that have not been completed
                    
$c 0//Character total count
                    
                    
foreach($quest_data as $QuestName => $TimeLeftArr)
                    {
                        
?>
                        <tr>
                            <td class="row4" nowrap><b><?= htmlspecialchars($QuestName?></b></td>
                            <td class="row4" nowrap><b><?= $quest_durations[$QuestName?></b></td>
                        </tr>
                        <?php
                        
#ksort($TimeLeftArr); //Sort by character name
                        //asort($TimeLeftArr, SORT_NUMERIC); //Sort by time left
                        
sort_chars($TimeLeftArr);
                        foreach(
$TimeLeftArr as $CharName => $TimeLeft)
                        {
                            if (
$TimeLeft 0)
                            {
                                
?>
                                <tr>
                                    <td class="row2_over" nowrap>&nbsp;&nbsp;&bull;&nbsp;<?= htmlspecialchars($CharName?></td>
                                    <td class="row2_over" nowrap><span id="quest<?=$c?>"><?=format_time_left($TimeLeft)?></span></td>
                                </tr>
                                <?php
                                $js_var_inits 
.=  "\n    timeleft[$c] = $TimeLeft;";
                                
$c++;
                            }
                            else
                            {
                                
?>
                                <tr>
                                    <td class="row2_over" nowrap>&nbsp;&nbsp;&bull;&nbsp;<?= htmlspecialchars($CharName?></td>
                                    <td class="row2_over" nowrap>Time Up</td>
                                </tr>
                                <?php
                            
}
                        } 
// foreach($TimeLeftArr)
                    
// foreach($quest_data)
                
?>
                </table>
            <?php else: // $qt_sort_type == 'characters'
            
?>
                <table cellpadding="2" cellspacing="2" border="0" width="100%">
                    <tr>
                        <td align="left"><span<?=$span_style?>>Last updated: <b><?= date("F j, Y, g:i A"$lastuploaded?></b></span></td>
                        <td align="right"><a class="genmed" href="<?= $_SERVER['PHP_SELF'] . '?mode=' $_GET['mode'?>&qt_sort_type=regular">Show 
                                all quests</a></td>
                    </tr>
                </table>
                <br>
                <table cellpadding="4" cellspacing="2" width="100%">
                    <tr>
                        <th align="left" width="25%" nowrap><b>Character Name</b></th>
                        <th align="left" width="25%" nowrap><b>Quest Name</b></th>
                        <th align="left" width="50%" nowrap><b>Time Remaining</b></th>
                    </tr>
                <?php 
                    sort_chars
($char_data); //Sort by time left
                    
$c 0//Character total count
                    
foreach ($char_data as $NameQuest => $TimeLeft)
                    {
                        
$NameQuest explode('$'$NameQuest2);
                        
$CharName $NameQuest[0];
                        
$QuestName $NameQuest[1];
                        if (
$TimeLeft 0)
                        {
                            
?>
                            <tr>
                                <td class="row2_over" width="25%" nowrap><?= htmlspecialchars($CharName?></td>
                                <td class="row2_over" width="25%" nowrap><?= htmlspecialchars($QuestName?></td>
                                <td class="row2_over" width="50%" nowrap><span id="quest<?=$c?>"><?=format_time_left($TimeLeft)?></span></td>
                            </tr>
                            <?php
                            $js_var_inits 
.=  "\n    timeleft[$c] = $TimeLeft;";
                            
$c++;
                        }
                        else
                        {
                            
?>
                            <tr>
                                <td class="row2_over" width="25%" nowrap><?= htmlspecialchars($CharName?></td>
                                <td class="row2_over" width="25%" nowrap><?= htmlspecialchars($QuestName?></td>
                                <td class="row2_over" width="50%" nowrap>Time Up</td>
                            </tr>
                            <?php
                        
}
                    }
                
?>
            <?php endif; // if ($qt_sort_type != 'characters') ?>
        </td>
    </tr>
    <script language="javascript">
        var timeleft = new Array(<?=$c?>);
        <?= $js_var_inits ?>
        
        tick(<?=$c?>);
        window.setInterval("tick(<?=$c?>)", 1000);
    </script>
        <?
            
// if (get_quest_data(...))
            
elseif ($action == 'account')
            {
                
?>
                <tr>
                    <td height="5"></td>
                </tr>
                <tr>
                    <td class="catHead"><b>Quest Timers for <?= $username ?></b></td>
                </tr>
                <tr>
                    <td class="row1">
                        <span class='emote'><b><i>Username not found or Username/Password mismatch</i></b></span><br>
                    </td>
                </tr>
                <?
            
}
            break;
    } 
// switch ($action)
?>
</table>
<?php
    
require_once('plugins_footer.php');
?>