function Tab_Full_Fight_Graphs($name, $char, $start_id, $end_id, $eventtext=1, $class='') {
     $data = "<div class='accordion_ajax_ajax'>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=hpprogress&cond[0][]=target_name=".$char."&section[1]=damage&cond[1][]=target_name=".$char."&section[2]=heal&cond[2][]=target_name=".$char."'>HP Verlauf</a></h4><div></div>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=damage&cond[0][]=target_name=".$char."'>Damage an $char</a></h4><div></div>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=damage&cond[0][]=source_name=".$char."'>Damage durch $char</a></h4><div></div>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=allhealers'>Heilung an $char</a></h4><div></div>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=heal&cond[0][]=source_name=".$char."'>Heilung durch $char</a></h4><div></div>
                 <h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=threat&cond[0][]=source_name=".$char."'>Bedrohung durch $char</a></h4><div></div>
                 <!--h4><a href='linechart_google.php?log_id=".$_SESSION['log_id']."&min_id=".$start_id."&max_id=".$end_id."&section[0]=threat&cond[0][]=source_name=".$char."&overall[0]=1'>Summierte Bedrohung durch $char</a></h4><div></div-->
             </div>";
     
     parent::Tab(
         $name, 
         guil('fightprogress').' ('.guil('graphs').')', 
         '', 
         $data,
         $html,
         $class
     );
 }
        function Tab_Full_Fight_Stats($name, $char, $start_id, $end_id, $eventtext=1, $class='') {
            global $parser, $benchmark;
            
            $data = '';
            $html = '';
            $hitpoint_gain_overall=0;
            $threat_gain_overall=0;
            $resource_gain_overall=0;
            $last_fetch = $start_id;
            for($id=$start_id; $id <= $end_id; $id++) {
                if($id >= $last_fetch + PARSER_MAX_FETCH) {
                    $last_fetch +=PARSER_MAX_FETCH;
                    unset($parser->loglines);
                    unset($parser->logdata);
                    $parser->read_loglines($id, $id+PARSER_MAX_FETCH);
                    $parser->gather_logdata();
                }
                $logdata = $parser->logdata[$id];

                if($logdata) {
                    $damage_received=0;
                    $heal_received=0;
                    $damage_done=0;
                    $heal_done=0;
                    $threat_gain=0;
                    $resource='';
                    $resource_spend = 0;
                    $resource_restored = 0;
                    
                    switch($parser->logchar2userchar[$char]['class_id']) {
                        case KNIGHT:
                        case GUARDIAN:
                        case SENTINEL:
                            $resource = 'focus';
                            break;
                        case WARRIOR:
                        case JUGGERNAUT:
                        case MARAUDER:
                            $resource = 'rage';
                            break;
                        case CONSULAR:
                        case INQUISITOR:
                        case SAGE:
                        case SORCERER:
                        case SHADOW:
                        case ASSASSIN:
                            $resource = 'force';
                            break;
                        case TROOPER:
                        case COMMANDO:
                        case VANGUARD:
                            $resource = 'ammo';
                            break;
                        case BOUNTYHUNTER:
                        case MERCENARY:
                        case POWERTECH:
                            $resource = 'heat';
                            break;
                        case SMUGGLER:
                        case IMPERIALAGENT:
                        case GUNSLINGER:
                        case SNIPER:
                        case SCOUNDREL:
                        case OPERATIVE:
                            $resource = 'energy';
                            break;
                    }

                    
                    switch($logdata['effect_type_id']) {
                        case SPEND:
                            switch($logdata['effect_id']) {
                                case HITPOINT:
                                    $damage_received = $logdata['hitpoints'];
                                    break;
                                case FORCE:
                                case ENERGY:
                                case RAGE:
                                case AMMO:
                                case FOCUS:
                                case HEAT:
                                    $resource_spend = $logdata['hitpoints'];
                                    break;
                            }
                            break;
                        case RESTORE:
                            switch($logdata['effect_id']) {
                                case HITPOINT:
                                    $heal_received = $logdata['hitpoints'];
                                    break;
                                case FORCE:
                                case ENERGY:
                                case RAGE:
                                case AMMO:
                                case FOCUS:
                                case HEAT:
                                    $resource_restored = $logdata['hitpoints'];
                                    break;
                            }
                            break;
                    }
                    $resource_gain = $resource_restored - $resource_spend;
                    $resource_gain_overall += $resource_gain;
                    
                    switch($logdata['effect_id']) {
                        case DAMAGE:
                            if($logdata['target_name'] == $char) {
                                $damage_received = $logdata['hitpoints'];
                            }
                            if(preg_match('/^'.$char.'(:.+)?/', $logdata['source_name'])) {
                                // char + companion
                                $damage_done = $logdata['hitpoints'];
                                
                            } 
                            if($logdata['source_name'] == $char) {
                                // char only
                                $threat_gain_overall += $logdata['threat'];
                            }
                            break;
                        case HEAL:
                            if($logdata['target_name'] == $char) {
                                $heal_received = $logdata['hitpoints'];
                            }
                            if(preg_match('/^'.$char.'(:.+)?/', $logdata['source_name'])) {
                                // char + companion
                                $heal_done = $logdata['hitpoints'];
                                $threat_gain += $logdata['threat'];
                            } 
                            if($logdata['source_name'] == $char) {
                                // char only
                                $threat_gain_overall += $logdata['threat'];
                            }
                            break;
                    }
                    $hitpoint_gain_overall += $damage_received;
                    $hitpoint_gain_overall -= $heal_received;
                    
                    // supress output of 0-values
                    $damage_done=($damage_done==0?"":$damage_done);
                    $heal_done=($heal_done==0?"":$heal_done);
                    $damage_received=($damage_received==0?"":$damage_received);
                    $heal_received=($heal_received==0?"":$heal_received);
                    $hitpoint_gain_overall=($hitpoint_gain_overall==0?"":$hitpoint_gain_overall);
                    $threat_gain=($threat_gain==0?"":$threat_gain);
                    $threat_gain_overall=($threat_gain_overall==0?"":$threat_gain_overall);
                    $resource_gain=($resource_gain==0?"":$resource_gain);
                    $resource_gain_overall=($resource_gain_overall==0?"":$resource_gain_overall);
                    
                    $row_style='';
                    if(preg_match('/^'.$char.':.+/', $logdata['source_name'])) {
                        // companion
                        if($logdata['effect_id']==DAMAGE) {
                            $row_style = 'style="background-color:#ccccff"';
                        } else {
                            $row_style = 'style="background-color:#ddddff"';
                        }
                    } elseif($logdata['source_name'] == $char) {
                        // char
                        if($logdata['effect_id']==DAMAGE) {
                            $row_style = 'style="background-color:#ccffcc"';
                        } elseif($logdata['effect_id']==DEATH) {
                            // ...kills something
                            $row_style = 'style="background-color:#00ff00"';
                        } else {
                            $row_style = 'style="background-color:#ddffdd"';
                        }
                    } elseif($logdata['source_type'] == 'player') {
                        // other player
                        if($logdata['effect_id']==DAMAGE) {
                            $row_style = 'style="background-color:#ffffcc"';
                        } else {
                            $row_style = 'style="background-color:#ffffdd"';
                        }
                    } else {
                        // npc
                        if($logdata['effect_id']==DAMAGE) {
                            $row_style = 'style="background-color:#ffcccc"';
                        } elseif($logdata['effect_id']==DEATH) {
                            // ...kills player
                            $row_style = 'style="background-color:#ff0000"';
                        } else {
                            $row_style = 'style="background-color:#ffdddd"';
                        }
                    }
                    
                    $data .= "<tr ".$row_style.">
                                <td>".$id."</td>
                                <td>".date('H:i:s', $logdata['timestamp'])."</td>
                                <td>".$logdata['source_name']."</td>
                                <td>".$logdata['target_name']."</td>
                                <td>".$logdata['ability_name']."</td>
                                <td>".$logdata['effect_name']."</td>
                                <td>".$logdata['damage_type']."</td>";
                    if($resource) {
                        $data .= "<td>".$resource_gain."</td>";
                        //$data .= "<td>".$resource_gain_overall."</td>";
                    }
                    $data .= "<td>".$damage_done."</td>
                                <td>".$heal_done."</td>
                                <td>".$threat_gain."</td>
                                <td>".$damage_received."</td>
                                <td>".$heal_received."</td>
                                <td>".$hitpoint_gain_overall."</td>
                                <td>".$threat_gain_overall."</td>";
                    $data .= "</tr>";
                }
            }
            $html = "<p>".guil('fullfightstats_note_companion')."</p>";

            $headers = array('ID', guil('time'), guil('source'), guil('target'), guil('ability'), guil('effect'), guil('damagetype'));
            if($resource) {
                $headers[] = ucfirst($resource);
                //$headers[] = ucfirst($resource.' '.guil('progress'));
            }
            $headers = array_merge($headers, array('DMG (out)', 'Heal(out)', 'Threat', 'DMG (in)', 'Heal (in)', '-HP '.guil('progress'), 'Threat '.guil('progress')));
            
            parent::Tab(
                $name, 
                guil('fightprogress'), 
                $headers,
                $data,
                $html,
                ($class?$class:'dataTableFullFightStats')
            );
        }
        function Tab_Char_HpsTps_per_Ability($name, $char, $start_id, $end_id, $class='', $hidexps=0) {
            global $parser;
            
            $data = '';
            $html = '';

            $used_abilities = array();
            $overall = array();
            $last_fetch = $start_id;
            for($id=$start_id; $id <= $end_id; $id++) {
                if($id >= $last_fetch + PARSER_MAX_FETCH) {
                    $last_fetch +=PARSER_MAX_FETCH;
                    unset($parser->loglines);
                    unset($parser->logdata);
                    $parser->read_loglines($id, $id+PARSER_MAX_FETCH);
                    $parser->gather_logdata($id, $id+PARSER_MAX_FETCH);
                }
                $logdata = $parser->logdata[$id];
                if($id == $start_id) {
                    $start_timestamp = $logdata['timestamp'];
                } elseif ($id == $end_id) {
                    $end_timestamp = $logdata['timestamp'];
                }

                if(preg_match('/^'.$char.'(:(.+))?/', $logdata['source_name'], $matches)) {
                    $ability_name = $logdata['ability_name'];
                    if($logdata['source_type'] == 'companion') {
                        $ability_name = $matches[2].': '.$ability_name;
                    }
                    switch($logdata['effect_id']) {
                        case HEAL:
                            $used_abilities[$ability_name]['id'] = $logdata['ability_id'];
                            $used_abilities[$ability_name]['heal'] += $logdata['hitpoints'];
                            $used_abilities[$ability_name]['threat'] += $logdata['threat'];
                            $used_abilities[$ability_name]['hit'] += $logdata['hit'];
                            $used_abilities[$ability_name]['crit'] += $logdata['crit'];
                            $used_abilities[$ability_name]['count']++;
                          
                            $overall['heal'] += $logdata['hitpoints'];
                            $overall['threat'] += $logdata['threat'];
                            $overall['hit'] += $logdata['hit'];
                            $overall['crit'] += $logdata['crit'];
                            $overall['count']++;
                    }
                }
            }
            
            $duration = $end_timestamp - $start_timestamp;
            if($overall['count']>0) {
                $overall['overheal'] = 0;

                foreach($used_abilities as $ability_name => $ability) {
                    // experimental! 
                    // see crudedragos comments on http://mmo-mechanics.com/swtor/forums/Thread-Batalyser-SWTOR-Combat-Analyser
                    switch($ability['id']) {
                        // Medpacs
                        case "813312187039744" :
                        case "2176191209406464":
                        case "864164599824384" :
                        case "843162209746944" :
                        case "2176199799341056":
                        case "813316482007040" :
                        case "813320776974336" :
                        case "2628395431100416":
                        case "807518276157440" :
                        case "1143320294195200":
                        case "1481411529801728":
                        case "2176212684242944":
                        case "1481402939867136":
                        case "1481407234834432":
                        case "807544045961216" :
                        case "2176216979210240":
                        case "1481398644899840":
                        case "2471474505973760":
                            if($ability['threat']/$ability['heal']>0.5) {
                                // tank
                                $threatcoefficient = 0.75;
                            } else {
                                // healer, dd
                                $threatcoefficient = 0.50;
                            }
                            break;
                        // Healing Resonance
                        case "2785827457335296":
                        case "2882455631560704":
                        case "2772083561988096":
                        case "2785805982498816":
                            $threatcoefficient = 0.50;
                            break;
                        default:
                            switch($parser->logchar2userchar[$char]['class_id']) {
                                case MERCENARY:
                                case COMMANDO:
                                    // healer
                                    $threatcoefficient = 0.45;
                                    break;
                                case SCOUNDREL:
                                case OPERATIVE:
                                    // healer
                                    $threatcoefficient = 0.45;
                                    break;
                                case SAGE:
                                case SORCERER:
                                    // healer
                                    $threatcoefficient = 0.42;
                                    break;
                                case GUARDIAN:
                                case JUGGERNAUT:
                                case SHADOW:
                                case ASSASSIN:
                                case VANGUARD:
                                case POWERTECH:
                                    if($ability['threat']/$ability['heal']>0.5) {
                                        // tank
                                        $threatcoefficient = 0.75;
                                    } else {
                                        // dd
                                        $threatcoefficient = 0.5;
                                    }
                                    break;
                                default:
                                    // class is not set, try to determine it by calculating the actual threatcoeffecientrange
                                    // overheal may be calculated wrong if this fails, and that's very likely
                                    if($ability['threat']/$ability['heal']>0.5) {
                                        // tank
                                        $threatcoefficient = 0.75;
                                    } elseif($ability['threat']/$ability['heal']>0.45) {
                                        // dd
                                        $threatcoefficient = 0.5;
                                    } else {
                                        // healer
                                        $threatcoefficient = 0.45;
                                    }
                            }
                    }
                    if($ability['threat']) {
                        $ability['overheal'] = $ability['heal'] - $ability['threat'] * pow($threatcoefficient, -1);
                        $overall['overheal'] += $ability['overheal'];
                    }
                    if($ability['heal']>0) {
                        $data .= "<tr>
                                <td>".$ability_name."</td>
                                <td>".$ability['count']."</td>
                                <td>".$ability['heal']."</td>";
                        if(!$hidexps) {
                            $data .= "<td>".round($ability['heal'] / $duration, 2)."</td>";
                        }
                        $data .= "<td>".round($ability['heal'] / $ability['count'], 2)."</td>
                                <td>".round($ability['overheal'], 2)."</td>
                                <td>".round((100/$ability['heal'])*$ability['overheal'], 2)."%</td>
                                <td>".$ability['threat']."</td>";
                        if(!$hidexps) {
                            $data .= "<td>".round($ability['threat'] / $duration, 2)."</td>";
                        }
                        $data .= "<td>".round($ability['threat'] / $ability['count'], 2)."</td>
                                <td>".round($ability['threat'] / $ability['heal'], 2)."</td>
                                <td>".$ability['hit']."</td>
                                <td>".$ability['crit']."</td>
                                <td>".round(100/$ability['count']*$ability['hit'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['crit'], 2)."%</td>
                            </tr>";
                    }
                }
                
                $html = "<div style='border-top: 1px solid silver'>Gesamt:<table>
                    <tr>
                        <td rowspan='2' valign='top'>
                            <table>
                                <tr><td>".guil('normal').":         </td><td>".$overall['hit']."</td>       <td>(".round(100/$overall['count']*$overall['hit'],     2)."%)</td></tr>
                                <tr><td>".guil('crit').":           </td><td>".$overall['crit']."</td>      <td>(".round(100/$overall['count']*$overall['crit'],    2)."%)</td></tr>
                                <tr><td>Overheal:                   </td><td colspan='2'>".round($overall['overheal'], 2)." (".round(100/$overall['heal'] * $overall['overheal'], 2)."%)</td></tr>";
                if(!$hidexps) {
                    $html .= "<tr><td>HPS:                        </td><td colspan='2'>".round($overall['heal']/$duration, 2)."</td></tr>
                                <tr><td>HPS (".guil('effective')."):</td><td colspan='2'>".round(($overall['heal']-$overall['overheal'])/$duration, 2)."</td></tr>";
                }
                $html .= "</table>
                            (Overheal and effective HPS are experimental estimates)
                        </td>
                        <td valign='top'>";
                $params =  guil('normal')."=".$overall['hit'];
                $params .= "&".guil('crit')."=".$overall['crit'];
                $html .= "<iframe width='450' height='250' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('healhitstatistic')."&pieheight=300&piewidth=450'></iframe>
                            <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('healhitstatistic')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                        </td>
                        <td>";
                foreach($used_abilities as $ability_name => $ability) {
                    $piedata[] = $ability_name."=".$ability['heal'];
                }
                $params = join('&', $piedata);
                $html .= "<iframe width='450' height='250' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('healperability')."&pieheight=300&piewidth=450'></iframe>
                            <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('healperability')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                        </td>
                    </tr>
                    <tr>
                        <td>";
                $params = "Effective=".($overall['heal']-$overall['overheal'])."&Overheal=".$overall['overheal'];
                $html .= "<iframe width='450' height='250' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('overhealstatistic')."&pieheight=300&piewidth=450'></iframe>
                            <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('overhealstatistic')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                        </td>
                    </tr>
                </table>
                </div>";
            }

            if(!$hidexps) {
                $headers = array(guil('ability'), 'Use', 'Heal', 'HPS', 'Heal/Use', 'Overheal', 'Overheal %', 'Threat', 'TPS', 'Threat/Use', 'Threat/Heal',
                        'Hit', 'Crit', 'Hit %', 'Crit %');
            } else {
                $headers = array(guil('ability'), 'Use', 'Heal', 'Heal/Use', 'Overheal', 'Overheal %', 'Threat', 'Threat/Use', 'Threat/Heal',
                        'Hit', 'Crit', 'Hit %', 'Crit %');
            }

            parent::Tab(
                $name, 
                guil('healperability'), 
                $headers, 
                $data,
                $html,
                $class
            );
            
            $this->tooltips['Overheal'] = 'experimental estimate!';
            $this->tooltips['Overheal %'] = 'experimental estimate!';
        }
        function Tab_Enemies_Damage_to_Char($name, $char, $start_id, $end_id, $class='', $hidexps=0) {
            global $parser;
            
            $enemies = array();
            $enemies_abilities = array();
            $overall = array();
            $last_fetch = $start_id;
            for($id=$start_id; $id <= $end_id; $id++) {
                if($id >= $last_fetch + PARSER_MAX_FETCH) {
                    $last_fetch +=PARSER_MAX_FETCH;
                    unset($parser->loglines);
                    unset($parser->logdata);
                    $parser->read_loglines($id, $id+PARSER_MAX_FETCH);
                    $parser->gather_logdata($id, $id+PARSER_MAX_FETCH);
                }
                $logdata = $parser->logdata[$id];
                
                if($id == $start_id) {
                    $start_timestamp = $logdata['timestamp'];
                } elseif ($id == $end_id) {
                    $end_timestamp = $logdata['timestamp'];
                }

                if($logdata['target_name'] == $char) {
                    $enemy_name = $logdata['source_name'];
                    $ability_name = $logdata['ability_name'];
                    switch($logdata['effect_id']) {
                        case DAMAGE:
                            $enemies[$enemy_name]['attack_count']++;
                            $enemies[$enemy_name]['damage'] += $logdata['hitpoints'];
                            $enemies[$enemy_name]['threat'] += $logdata['threat'];
                            $enemies[$enemy_name]['hit'] += $logdata['hit'];
                            $enemies[$enemy_name]['crit'] += $logdata['crit'];
                            $enemies[$enemy_name]['miss'] += $logdata['miss'];
                            $enemies[$enemy_name]['dodge'] += $logdata['dodge'];
                            $enemies[$enemy_name]['parry'] += $logdata['parry'];
                            $enemies[$enemy_name]['deflect'] += $logdata['deflect'];
                            $enemies[$enemy_name]['immune'] += $logdata['immune'];
                            $enemies[$enemy_name]['resist'] += $logdata['resist'];
                            
                            $overall['count']++;
                            $overall['damage'] += $logdata['hitpoints'];
                            $overall['threat'] += $logdata['threat'];
                            $overall['hit'] += $logdata['hit'];
                            $overall['crit'] += $logdata['crit'];
                            $overall['miss'] += $logdata['miss'];
                            $overall['dodge'] += $logdata['dodge'];
                            $overall['parry'] += $logdata['parry'];
                            $overall['deflect'] += $logdata['deflect'];
                            $overall['immune'] += $logdata['immune'];
                            $overall['resist'] += $logdata['resist'];
            
                            $enemies_abilities[$enemy_name][$ability_name]['count']++;
                            $enemies_abilities[$enemy_name][$ability_name]['damage'] += $logdata['hitpoints'];
                            $enemies_abilities[$enemy_name][$ability_name]['threat'] += $logdata['threat'];
                            $enemies_abilities[$enemy_name][$ability_name]['hit'] += $logdata['hit'];
                            $enemies_abilities[$enemy_name][$ability_name]['crit'] += $logdata['crit'];
                            $enemies_abilities[$enemy_name][$ability_name]['miss'] += $logdata['miss'];
                            $enemies_abilities[$enemy_name][$ability_name]['dodge'] += $logdata['dodge'];
                            $enemies_abilities[$enemy_name][$ability_name]['parry'] += $logdata['parry'];
                            $enemies_abilities[$enemy_name][$ability_name]['deflect'] += $logdata['deflect'];
                            $enemies_abilities[$enemy_name][$ability_name]['immune'] += $logdata['immune'];
                            $enemies_abilities[$enemy_name][$ability_name]['resist'] += $logdata['resist'];
                            break;
                    }
                }
            }
            
            if(count($enemies) > 0) {
                $html = "<p>".guil('tankstats_note1');
                $html .= "</p>
                    <div class='accordion'>";
                $_html = '';
                $duration = $end_timestamp - $start_timestamp;
                foreach($enemies as $enemy_name => $enemy) {
                    $_html .= "<h4><a href='#'>".$enemy_name." (".$enemy['damage']." ".guil('damage');
                    if(! $hidexps) {
                        $_html .= ", ".round($enemy['damage'] / $duration, 2)." DPS";
                    }
                    $_html .= ")</a></h4>
                            <div>
                                
                                <table class='".($class?$class:'dataTable')."'>
                                    <thead>
                                        <tr>
                                            <th>".guil('ability')."</th>
                                            <th>Use</th>
                                            <th>".guil('damage')."</th>
                                            <th>Dmg/Use</th>";
                                            if(! $hidexps) {
                                                $_html .= "<th>DPS</th>";
                                            }
                                            // enemies generate Thread to chars, but I just don't see any sense in it
                                            //<th>Threat</th>
                                            //<th>Threat/Use</th>
                                            //<th>TPS</th>
                                            $_html .= "<th>Hit (alle)</th>
                                            <th>Hit (-crit)</th>
                                            <th>Crit</th>
                                            <th>Miss</th>
                                            <th>Dodge</th>
                                            <th>Parry</th>
                                            <th>Deflect</th>
                                            <th>Resist</th>
                                            <th>Immune</th>
                                            <th>Hit (all)%</th>
                                            <th>Hit (noncrit) %</th>
                                            <th>Crit %</th>
                                            <th>Miss %</th>
                                            <th>Dodge %</th>
                                            <th>Parry %</th>
                                            <th>Deflect %</th>
                                            <th>Resist %</th>
                                            <th>Immune %</th>
                                        </tr>
                                    </thead>
                                    <tbody>";
                    foreach($enemies_abilities[$enemy_name] as $ability_name => $ability) {
                        $_html .= "<tr>
                                            <td>".$ability_name."</td>
                                            <td>".$ability['count']."</td>
                                            <td>".$ability['damage']."</td>
                                            <td>".round($ability['damage']/$ability['count'], 2)."</td>";
                                            if(! $hidexps) {
                                                $_html .= "<td>".round($ability['damage']/$duration, 2)."</td>";
                                            }
                                            // enemies generate Thread to chars, but I just don't see any sense in it
                                            // <td>".$ability['threat']."</td>
                                            // <td>".round($ability['threat']/$ability['count'], 2)."</td>
                                            // <td>".round($ability['threat']/$duration, 2)."</td>
                                            $_html .= "<td>".($ability['hit']+$ability['crit'])."</td>
                                            <td>".$ability['hit']."</td>
                                            <td>".$ability['crit']."</td>
                                            <td>".$ability['miss']."</td>
                                            <td>".$ability['dodge']."</td>
                                            <td>".$ability['parry']."</td>
                                            <td>".$ability['deflect']."</td>
                                            <td>".$ability['resist']."</td>
                                            <td>".$ability['immune']."</td>
                                            <td>".round(($ability['hit']+$ability['crit'])/$ability['count'], 2)."</td>
                                            <td>".round($ability['hit']/$ability['count'], 2)."</td>
                                            <td>".round($ability['crit']/$ability['count'], 2)."</td>
                                            <td>".round($ability['miss']/$ability['count'], 2)."</td>
                                            <td>".round($ability['dodge']/$ability['count'], 2)."</td>
                                            <td>".round($ability['parry']/$ability['count'], 2)."</td>
                                            <td>".round($ability['deflect']/$ability['count'], 2)."</td>
                                            <td>".round($ability['resist']/$ability['count'], 2)."</td>
                                            <td>".round($ability['immune']/$ability['count'], 2)."</td>
                                        </tr>";
                    }
                    $_html .= "</tbody>
                                    <tfoot>
                                        <tr>
                                            <td>".guil('sum')."</td>
                                            <td>".$enemy['attack_count']."</td>
                                            <td>".$enemy['damage']."</td>
                                            <td>".round($enemy['damage']/$enemy['attack_count'], 2)."</td>";
                                            if(! $hidexps) {
                                                $_html .= "<td>".round($ability['damage']/$duration, 2)."</td>";
                                            }
                                            // enemies generate Thread to chars, but I just don't see any sense in it
                                            // <td>".$enemy['threat']."</td>
                                            // <td>".round($enemy['threat']/$enemy['attack_count'], 2)."</td>
                                            // <td>".round($enemy['threat']/$duration, 2)."</td>
                                            $_html .= "<td>".($enemy['hit']+$enemy['crit'])."</td>
                                            <td>".$enemy['hit']."</td>
                                            <td>".$enemy['crit']."</td>
                                            <td>".$enemy['miss']."</td>
                                            <td>".$enemy['dodge']."</td>
                                            <td>".$enemy['parry']."</td>
                                            <td>".$enemy['deflect']."</td>
                                            <td>".$enemy['resist']."</td>
                                            <td>".$enemy['immune']."</td>
                                            <td>".round(($enemy['hit']+$enemy['crit'])/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['hit']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['crit']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['miss']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['dodge']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['parry']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['deflect']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['resist']/$enemy['attack_count'], 2)."</td>
                                            <td>".round($enemy['immune']/$enemy['attack_count'], 2)."</td>
                                        </tr>
                                    </tfoot>
                                </table>
                                
                            </div>";
                }
                $html .= "<h4><a href='#gesamt_all_vs_".$char."'>".guil('overall')." (".$overall['damage']." ".guil('damage');
                    if(! $hidexps) {
                        $html .= ", ".round($overall['damage'] / $duration, 2)." DPS";
                    }
                    $html .= ")</a></h4>
                                <div>
                                    <table>
                                        <tr>
                                            <td>
                                                <table>
                                                    <tr><td>".guil('hitall').":     </td><td>".($overall['hit']+$overall['crit'])."</td>      <td>".round(100/$overall['count']*($overall['hit']+$overall['crit']),     2)."%</td></tr>
                                                    <tr><td>".guil('hitnoncrit').": </td><td>".$overall['hit']."</td>    <td>".round(100/$overall['count']*$overall['hit'],     2)."%</td></tr>
                                                    <tr><td>".guil('crit').":       </td><td>".$overall['crit']."</td>     <td>".round(100/$overall['count']*$overall['crit'],    2)."%</td></tr>
                                                    <tr><td>".guil('miss').":       </td><td>".$overall['miss']."</td>     <td>".round(100/$overall['count']*$overall['miss'],    2)."%</td></tr>
                                                    <tr><td>".guil('dodge').":      </td><td>".$overall['dodge']."</td>    <td>".round(100/$overall['count']*$overall['dodge'],   2)."%</td></tr>
                                                    <tr><td>".guil('parry').":      </td><td>".$overall['parry']."</td>    <td>".round(100/$overall['count']*$overall['parry'],   2)."%</td></tr>
                                                    <tr><td>".guil('deflect').":    </td><td>".$overall['deflect']."</td>  <td>".round(100/$overall['count']*$overall['deflect'], 2)."%</td></tr>
                                                    <tr><td>".guil('resist').":     </td><td>".$overall['resist']."</td>   <td>".round(100/$overall['count']*$overall['resist'], 2)."%</td></tr>
                                                    <tr><td>".guil('immune').":     </td><td>".$overall['immune']."</td>   <td>".round(100/$overall['count']*$overall['immune'], 2)."%</td></tr>
                                                </table>
                                            </td>
                                            <td>";
                    $params  =     guil('hitnoncrit')."=".$overall['hit'];
                    $params .= "&".guil('crit')."=".$overall['crit'];
                    $params .= "&".guil('miss')."=".$overall['miss'];
                    $params .= "&".guil('dodge')."=".$overall['dodge'];
                    $params .= "&".guil('parry')."=".$overall['parry'];
                    $params .= "&".guil('deflect')."=".$overall['deflect'];
                    $params .= "&".guil('resist')."=".$overall['Resist'];
                    $params .= "&".guil('immune')."=".$overall['Immune'];
                    $html .= "<iframe width='450' height='300' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('counterhitstatistic')."&pieheight=300&piewidth=450'></iframe>
                                                <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('counterhitstatistic')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                                            </td>
                                        </tr>
                                    </table>
                                </div>";
                $html .= $_html."</div>";
            }
            
            parent::Tab(
                $name, 
                'Tankstats / * vs '.$char, 
                '', 
                '',
                $html,
                $class
            );
        }
        function Tab_DpsHpsTps_per_Target($name, $char, $start_id, $end_id, $class='', $hidexps=0) {
            global $parser;

            $targets = array();
            $last_fetch = $start_id;
            for($id=$start_id; $id <= $end_id; $id++) {
                if($id >= $last_fetch + PARSER_MAX_FETCH) {
                    $last_fetch +=PARSER_MAX_FETCH;
                    unset($parser->loglines);
                    unset($parser->logdata);
                    $parser->read_loglines($id, $id+PARSER_MAX_FETCH);
                    $parser->gather_logdata($id, $id+PARSER_MAX_FETCH);
                }
                $logdata = $parser->logdata[$id];
                if($id == $start_id) {
                    $start_timestamp = $logdata['timestamp'];
                } elseif ($id == $end_id) {
                    $end_timestamp = $logdata['timestamp'];
                }

                if(preg_match('/^'.$char.'(:.+)?/', $logdata['source_name'])) {
                    $target_name = $logdata['target_name'];
                    switch($logdata['effect_id']) {
                        case HEAL:
                            $targets[$target_name]['healed'] += $logdata['hitpoints'];
                            break;
                        case DAMAGE:
                            $targets[$target_name]['damage'] += $logdata['hitpoints'];
                    }
                    $targets[$target_name]['threat'] += $logdata['threat'];
                    $targets[$target_name]['target_type'] = $logdata['target_type'];
                }
            }

            $data = '';
            $duration = $end_timestamp - $start_timestamp;
            if($duration) {
                foreach($targets as $target_name => $target) {
                    if($target['target_type'] == 'companion') {
                        $target_name = preg_replace('/'.$char.':/', '', $target_name).' (Companion)';
                    }
                    if($target['damage']>0 || $target['healed']>0 || $target['threat']>0) {
                        switch($target['target_type']) {
                            case 'player':      
                                if($target_name == $char) {
                                    // self
                                    $bgcolor = 'style="background-color:#ddffdd"'; 
                                } else {
                                    // other player
                                    $bgcolor = 'style="background-color:#ffffdd"'; 
                                }
                                break;
                            case 'companion':   $bgcolor = 'style="background-color:#ddddff"'; break;
                            default:            $bgcolor = 'style="background-color:#ffdddd"'; break;
                        }
                        $data .= "<tr>
                                <td ".$bgcolor.">".$target_name."</td>
                                <td>".$target['damage']."</td>
                                <td>".$target['healed']."</td>
                                <td>".$target['threat']."</td>";
                        if(!$hidexps) {
                            $data .= "<td>".round($target['damage'] / $duration, 2)."</td>
                                <td>".round($target['healed'] / $duration, 2)."</td>
                                <td>".round($target['threat'] / $duration, 2)."</td>";
                        }
                        $data .= "</tr>";
                    }
                }
            }

            $headers = array(guil('target'), guil('damage'), guil('heal'), guil('threat'));
            if(!$hidexps) {
                $title = guil('xpspertarget');
                $headers = array_merge($headers, array('DPS', 'HPS', 'TPS'));
            } else {
                $title = guil('damagehealthreatpertarget');
            }

            parent::Tab(
                $name, 
                $title, 
                $headers, 
                $data,
                $html,
                $class
            );
        }
        function Tab_Char_DpsTps_per_Ability($name, $char, $start_id, $end_id, $class='', $hidexps=0) {
            global $parser;

            $data = '';
            $html = '';
            
            $used_abilities = array();
            $overall = array();
            $last_fetch = $start_id;
            for($id=$start_id; $id <= $end_id; $id++) {
                if($id >= $last_fetch + PARSER_MAX_FETCH) {
                    $last_fetch +=PARSER_MAX_FETCH;
                    unset($parser->loglines);
                    unset($parser->logdata);
                    $parser->read_loglines($id, $id+PARSER_MAX_FETCH);
                    $parser->gather_logdata($id, $id+PARSER_MAX_FETCH);
                }
                $logdata = $parser->logdata[$id];
                if($id == $start_id) {
                    $start_timestamp = $logdata['timestamp'];
                } elseif ($id == $end_id) {
                    $end_timestamp = $logdata['timestamp'];
                }
                if(preg_match('/^'.$char.'(:(.+))?/', $logdata['source_name'], $matches)) {
                    $ability_name = $logdata['ability_name'];
                    if($logdata['source_type'] == 'companion') {
                        $ability_name = $matches[2].': '.$ability_name;
                    }
                    switch($logdata['effect_id']) {
                        case DAMAGE:
                            $used_abilities[$ability_name]['damage'] += $logdata['hitpoints'];
                            $used_abilities[$ability_name]['threat'] += $logdata['threat'];
                            $used_abilities[$ability_name]['hit'] += $logdata['hit'];
                            $used_abilities[$ability_name]['crit'] += $logdata['crit'];
                            $used_abilities[$ability_name]['miss'] += $logdata['miss'];
                            $used_abilities[$ability_name]['dodge'] += $logdata['dodge'];
                            $used_abilities[$ability_name]['parry'] += $logdata['parry'];
                            $used_abilities[$ability_name]['deflect'] += $logdata['deflect'];
                            $used_abilities[$ability_name]['immune'] += $logdata['immune'];
                            $used_abilities[$ability_name]['resist'] += $logdata['resist'];
                            $used_abilities[$ability_name]['count']++;
            
                            $overall['damage'] += $logdata['hitpoints'];
                            $overall['threat'] += $logdata['threat'];
                            $overall['hit'] += $logdata['hit'];
                            $overall['crit'] += $logdata['crit'];
                            $overall['miss'] += $logdata['miss'];
                            $overall['dodge'] += $logdata['dodge'];
                            $overall['parry'] += $logdata['parry'];
                            $overall['deflect'] += $logdata['deflect'];
                            $overall['immune'] += $logdata['immune'];
                            $overall['resist'] += $logdata['resist'];
                            $overall['count']++;
                    }
                }
            }
            
            $duration = $end_timestamp - $start_timestamp;
            if($overall['count']>0 && $duration) {
                foreach($used_abilities as $ability_name => $ability) {
                    if($ability['damage']>0) {
                        $data .= "<tr>
                                <td>".$ability_name."</td>
                                <td>".$ability['count']."</td>
                                <td>".$ability['damage']."</td>";
                        if(!$hidexps) {
                            $data .= "<td>".round($ability['damage'] / $duration, 2)."</td>";
                        }
                        $data .= "<td>".round($ability['damage'] / $ability['count'], 2)."</td>
                                <td>".$ability['threat']."</td>";
                        if(!$hidexps) {
                            $data .= "<td>".round($ability['threat'] / $duration, 2)."</td>";
                        }
                        $data .= "<td>".round($ability['threat'] / $ability['count'], 2)."</td>
                                <td>".round($ability['threat'] / $ability['damage'], 2)."</td>
                                <td>".($ability['hit']+$ability['crit'])."</td>
                                <td>".$ability['hit']."</td>
                                <td>".$ability['crit']."</td>
                                <td>".$ability['miss']."</td>
                                <td>".$ability['dodge']."</td>
                                <td>".$ability['parry']."</td>
                                <td>".$ability['deflect']."</td>
                                <td>".$ability['resist']."</td>
                                <td>".$ability['immune']."</td>
                                <td>".round(100/$ability['count']*($ability['hit']+$ability['crit']), 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['hit'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['crit'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['miss'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['dodge'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['parry'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['deflect'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['resist'], 2)."%</td>
                                <td>".round(100/$ability['count']*$ability['immune'], 2)."%</td>
                            </tr>";
                    }
                }
            
                $html = "<div style='border-top: 1px solid silver'>Gesamt:<table>
                    <tr>
                        <td>
                            <table>
                                <tr><td>".guil('hitall').":     </td><td>".($overall['hit']+$overall['crit'])."</td>      <td>".round(100/$overall['count']*($overall['hit']+$overall['crit']),     2)."%</td></tr>
                                <tr><td>".guil('hitnoncrit').": </td><td>".$overall['hit']."</td>    <td>".round(100/$overall['count']*$overall['hit'],     2)."%</td></tr>
                                <tr><td>".guil('crit').":       </td><td>".$overall['crit']."</td>     <td>".round(100/$overall['count']*$overall['crit'],    2)."%</td></tr>
                                <tr><td>".guil('miss')."        </td><td>".$overall['miss']."</td>     <td>".round(100/$overall['count']*$overall['miss'],    2)."%</td></tr>
                                <tr><td>".guil('dodge').":      </td><td>".$overall['dodge']."</td>    <td>".round(100/$overall['count']*$overall['dodge'],   2)."%</td></tr>
                                <tr><td>".guil('parry').":      </td><td>".$overall['parry']."</td>    <td>".round(100/$overall['count']*$overall['parry'],   2)."%</td></tr>
                                <tr><td>".guil('deflect').":    </td><td>".$overall['deflect']."</td>  <td>".round(100/$overall['count']*$overall['deflect'], 2)."%</td></tr>
                                <tr><td>".guil('resist').":     </td><td>".$overall['resist']."</td>   <td>".round(100/$overall['count']*$overall['resist'], 2)."%</td></tr>
                                <tr><td>".guil('immune').":     </td><td>".$overall['immune']."</td>   <td>".round(100/$overall['count']*$overall['immune'], 2)."%</td></tr>
                            </table>
                        </td>
                        <td>";
                $params  =     guil('hitnoncrit')."=".$overall['hit'];
                $params .= "&".guil('crit')."=".$overall['crit'];
                $params .= "&".guil('miss')."=".$overall['miss'];
                $params .= "&".guil('dodge')."=".$overall['dodge'];
                $params .= "&".guil('parry')."=".$overall['parry'];
                $params .= "&".guil('deflect')."=".$overall['deflect'];
                $params .= "&".guil('resist')."=".$overall['resist'];
                $params .= "&".guil('immune')."=".$overall['immune'];
                $html .= "<iframe width='450' height='300' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('hitstatistic')."&pieheight=300&piewidth=450'></iframe><br>
                            <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('hitstatistic')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                        </td>
                        <td>
                            ";
                foreach($used_abilities as $ability_name => $ability) {
                    $piedata[] = $ability_name."=".$ability['damage'];
                }
                $params = join('&', $piedata);
                $html .= "<iframe width='450' height='300' frameborder='0' scrolling='no' src='piechart_google.php?".$params."&pietitle=".guil('damageperability')."&pieheight=300&piewidth=450'></iframe>
                            <center><button class='button_open_dialog_misc' href='piechart_google.php?".$params."&pietitle=".guil('damageperability')."&pieheight=600&piewidth=800'>".guil('enlarge_grafic')."</button></center>
                        </td>
                    </tr>
                </table>
                </div>";
            }
            
            if(!$hidexps) {
                $headers = array(guil('ability'), 'Use', 'Damage', 'DPS', 'Damage/Use', 'Threat', 'TPS', 'Threat/Use', 'Threat/DMG',
                        'Hit (alle)', 'Hit (noncrit)', 'Crit', 'Miss', 'Dodge', 'Parry', 'Deflect', 'Resist', 'Immune',
                        'Hit (alle) %', 'Hit (noncrit) %', 'Crit %', 'Miss %', 'Dodge %', 'Parry %', 'Deflect %', 'Resist %', 'Immune %');
            } else {
                $headers = array(guil('ability'), 'Use', 'Damage', 'Damage/Use', 'Threat', 'Threat/Use', 'Threat/DMG',
                        'Hit (alle)', 'Hit (noncrit)', 'Crit', 'Miss', 'Dodge', 'Parry', 'Deflect', 'Resist', 'Immune',
                        'Hit (alle) %', 'Hit (noncrit) %', 'Crit %', 'Miss %', 'Dodge %', 'Parry %', 'Deflect %', 'Resist %', 'Immune %');
            }
            
            parent::Tab(
                $name, 
                guil('damageperability'), 
                $headers, 
                $data,
                $html,
                $class
            );
        }