Crafter listing

Copy the code below and paste it into a .php text file.
Save and upload to your web server.
Open script in browser.

*******************

<?php

/**
 * crafterxml.php
 *     a Dark Age of Camelot Guild XML data parser that returns tradeskill information
 *     for use on Dark Age of Camelot community websites.
 * 
 *     Dark Age of Camelot (or DAoC) is a MMORPG
 *     (massively multiplayer online rolepaying game)
 *     developed by Mythic Entertainment (http://www.mythicentertainment.com)
 * 
 *     Author: Julien COQUET
 *     a.k.a Glenfiddich Singlemalt on DAoC Merlin/Albion
 *     e-mail glenfiddich@purpledragons.net
 *     http://www.purpledragons.net
 * 
 *     Adapted from generic PHP code from http://www.php.net
 * 
 *     Developed in November of 2002 under the GNU GPL License.
 *     For more information, visit http://www.gnu.org/licenses/gpl.html
 * 
 *     Enjoy and please link to our site
 *     http://www.purpledragons.net
 * 
 *      Changelog
 *      March 28, 2003 : added flag to exclude characters with skill level of 1
 *      March 28, 2003 : added UTF8 support for GOA XML - Euro servers only
 *      Nov. 15th : added support for Herald Character Display page
 */

class guildXML {
    
/**
     * This class takes a Dark Age of Camelot Herald XML guild data file and parses it
     */

    var $xml_parser;
    var 
$xml_file;
    var 
$html;
    var 
$open_tag ;
    var 
$close_tag ;
    var 
$in_char;
    var 
$in_alliance;
    var 
$chars_array;
    var 
$alliance_array;
    var 
$current_tag '';

    /**
     * Class Constructor
     */

    function guildXML()
    {
        
$this->xml_parser "";
        
$this->xml_file "";
        
$this->html "";
    } 
    
// Class Destructor (has to be invoked manually as PHP does not support destructors)
    
function destroy()
    {
        
xml_parser_free($this->xml_parser);
    } 
    
// Class Members
    
function concat($str)
    {
        
$this->html .= $str;
    } 

    function startElement($parser$name$attrs)
    {
        global 
$totalchars$num_activechars$num_inactivechars$insideElement$in_char$current_tag$i;

        if (($in_char == 1) || ($in_alliance == 1)) {
            
$current_tag trim($name);
        } 
        if (
$name == 'GUILD') {
            
$current_tag $name;
            if (
sizeof($attrs)) {
                while (list(
$k$v) = each($attrs)) {
                    if (
$k == 'GUILDRP') {
                        
$this->guildrp trim($v);
                    } ;
                    if (
$k == 'TIMESTAMP') {
                        
$this->timestamp trim ($v);
                    } ;
                } 
            } 
        } 

        if ($name == 'CHARACTER') {
            
$in_alliance 1;
        } 
        if (
$name == 'CHARACTER') {
            
$in_char 1;
            
$totalchars++;
            if (
sizeof($attrs)) {
                while (list(
$k$v) = each($attrs)) {
                    if (
$k == 'NAME') {
                        
$this->chars_array[$i]['name'] = trim($v);
                        
$this->chars_array[$i]['firstname'] = trim (substr($this->chars_array[$i]['name'], 0strpos($this->chars_array[$i]['name'], ' ')));
                        
$this->chars_array[$i]['lastname'] = trim (substr($this->chars_array[$i]['name'], strpos($this->chars_array[$i]['name'], ' ')));
                        if (!
$this->chars_array[$i]['firstname'] && $this->chars_array[$i]['lastname']) {
                            
$this->chars_array[$i]['firstname'] = $this->chars_array[$i]['lastname'];
                            
$this->chars_array[$i]['lastname'] = '';
                        } 
                    } ;
                    if (
$k == 'ID') {
                        
$this->chars_array[$i]['id'] = $v;
                    } ;
                    if (
$k == 'LASTON') {
                        
$this->chars_array[$i]['laston'] = trim($v);
                        if (
$v != 'Inactive') {
                            
$num_activechars++;
                        } elseif (
$v == 'Inactive') {
                            
$num_inactivechars++;
                        } 
                    } 
                } 
            } 
        } 
    } 

    function endElement($parser$name)
    {
        global 
$close_tag$current_tag$in_char$i;

        if ($name == 'CHARACTER') {
            
$i++;
            
$in_char 0;
        } 
        if (
$name == 'ALLIANCE') {
            
$i++;
            
$in_alliance 0;
        } 
    } 

    function characterData($parser$data)
    {
        global 
$guildrp$inactiverp$current_tag$in_char$i
        
// $content_output .= '<br>'.$current_tag.' = '.$data.'<br>';
        
if (($in_char == 1) && ($current_tag == 'RACE')) {
            
$this->chars_array[$i]['race'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'CLASS')) {
            
$this->chars_array[$i]['class'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'LEVEL')) {
            
$this->chars_array[$i]['level'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'TOTALRP')) {
            
$this->chars_array[$i]['rp'] .= trim($data);
            if (
$this->chars_array[$i]['laston'] == 'Inactive') {
                
$inactiverp += trim($data);
            } else {
                
$guildrp += trim($data);
            } 
        } 

        if (($in_char == 1) && ($current_tag == 'WEAPONCRAFT')) {
            
$this->chars_array[$i]['weaponcraft'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'ARMORCRAFT')) {
            
$this->chars_array[$i]['armorcraft'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'TAILORING')) {
            
$this->chars_array[$i]['tailoring'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'FLETCHING')) {
            
$this->chars_array[$i]['fletching'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'SPELLCRAFT')) {
            
$this->chars_array[$i]['spellcraft'] .= trim($data);
        } 
        if ((
$in_char == 1) && ($current_tag == 'ALCHEMY')) {
            
$this->chars_array[$i]['alchemy'] .= trim($data);
        } 

        if (($in_char == 1) && ($current_tag == 'GUILDRANK')) {
            
$this->chars_array[$i]['guildrank'] .= trim($data);
        } 
        
// $this->html .= $data;
    

    function parse()
    {
        
$this->xml_parser xml_parser_create();
        
xml_set_object($this->xml_parser, &$this); 
        
// use case-folding so we are sure to find the tag in $map_array
        
xml_parser_set_option($this->xml_parserXML_OPTION_CASE_FOLDINGtrue);

        xml_set_element_handler($this->xml_parser"startElement""endElement");
        
xml_set_character_data_handler($this->xml_parser"characterData"); 
        
// xml_set_processing_instruction_handler($this->xml_parser, "PIHandler");
        
if (!($fp fopen($this->xml_file"r"))) {
            die(
"could not open XML input");
        } 
        while (
$data fread($fp4096)) {
            if (!
xml_parse($this->xml_parser$datafeof($fp))) {
                die(
sprintf("XML error: %s at line %d",
                        
xml_error_string(xml_get_error_code($this->xml_parser)),
                        
xml_get_current_line_number($this->xml_parser)));
            } 
        } 
    } 

// End of class
// Support functions
/**
 * The function sortItems() is used for sorting, called upon by uksort()
 *     It uses querystring parameter $param as the sorting parameter
 *     querystring parameter $dir indicates ascending or descending order
 */

function sortItems($a$b)
{
    global 
$gu$dir$param;

    $val_a = ($gu[$a][$param]);
    
$val_b = ($gu[$b][$param]);

    if (!$param) {
        
$param 'level';
    } 
    if (!
$dir) {
        
$dir 'down';
    } 
    switch (
$param) {
        case 
'rp':
            
$val_a $val_a 0;
            
$val_b $val_b 0;
            break;

        case 'level':
            
$val_a $val_a 0;
            
$val_b $val_b 0;
            break;
    } 

    if ($dir == 'up') {
        if (
$val_a$val_b) {
            return 
1;
        } 
        if (
$val_a $val_b) {
            return -
1;
        } 
        if (
$val_a $val_b) {
            return 
0;
        } 
    } else {
        if (
$val_a $val_b) {
            return 
1;
        } 
        if (
$val_a$val_b) {
            return -
1;
        } 
        if (
$val_a $val_b) {
            return 
0;
        } 
    } 

/**
 * This array contains the names of the different trades
 */

$crafts = array(
    array (
'Weaponcraft'),
    array (
'Armorcraft'),
    array (
'Tailoring'),
    array (
'Fletching'),
    array (
'Spellcraft'),
    array (
'Alchemy')
    );

/**
 * This array contains the titles given to crafters depending on their skill
 */

function craft_title ($score)
{
    
$titles = array(
        array (
0"Helper"),
        array (
100"Junior Apprentice"),
        array (
200"Apprentice"),
        array (
300"Neophyte"),
        array (
400"Assistant"),
        array (
500"Junior"),
        array (
600"Journeyman"),
        array (
700"Senior"),
        array (
800"Master"),
        array (
1000"Grandmaster"),
        array (
1100"Legendary Grandmaster")
        );
    foreach (
$titles as $key => $value) {
        if (
$score>= $value[0]) {
            
$title $value[1];
        } 
    } 
    return 
$title;

// Main content
if ($_POST['craft']) {
    
$guild = new guildXML(); //instantiate class
    
$guild->xml_file "http://www.camelotherald.com/guilds/Merlin/804.xml";
    
// the xml_file property refers to your guild XML data file.
    // Example given is the Merlin Albion guild Dragon's Blood

    $newbie_crafters 1// set to 0 to exclude characters with a skill of 1
    
$server "Merlin";
    
    
$herald_char_url "http://www.camelotherald.com/chardisplay.php"

    $guild->parse(); 
    
// Copy some variables
    
$gu $guild->chars_array;
    
$guildrp $guild->guildrp;
    
$guildtimestamp $guild->timestamp;
    
$xml_file $guild->xml_file;

    $guild->destroy(); // destroy the object
    
    
$param strtolower($_POST['craft']); // If a tradeskill was chosen, pass it along to the sort function
    
    
uksort($gu"sortItems"); // call upon sortItems() to sort the guild information array
    
reset($gu);

    /**
     * Creates the output
     */

    foreach ($gu as $key => $value) { // Walk thru the array
        
$craftid $value[strtolower($_POST['craft'])];
        if (
$craftid) { // if craft skill set for this character
            
if ($newbie_crafters == && $craftid == 1) { // exclude
                
unset ($gu[$key]); // exclude : clear array entry that do not match $newbie_crafters flag
            
} else {
                
$num++;
                if (
$num == 0) { // Alternate row color
                    
$bgcolor '#FFFFFF';
                } else {
                    
$bgcolor '#E5E5E5';
                } 
                
$content_output .= '
         <tr bgcolor="' 
$bgcolor '">
             <td nowrap="true" style="font-size: 9pt;"><a href="' 
$herald_char_url '?s=' $server '&c=' $value['id'] . '" target="blank" title="view ' $value['firstname'] . '\'s Herald page">' $value['name'] . '</a></b></td>
             <td width="10">&nbsp;</td>
            <td style="font-size: 9pt;">' 
$craftid '</td>
            <td width="10">&nbsp;</td>
            <td width="100%" nowrap="true"  style="font-size: 9pt;">' 
craft_title($craftid) . '</td>
         </tr>'
;
            } 
        } else {
            unset (
$gu[$key]); // clear array entries that do not match our query
        

    } 

    if (count($gu)) {
        
$table '<table align="center" cellspacing="0" border="0" width="100%">';
        
$table .= '<tr><td colspan="5" nowrap="true" align="right"><h3>' strtolower($_POST['craft']) . '</h3></td></tr>';
        
$table .= $content_output;
        
$table .= '
  <tr>
<FORM ACTION="' 
$PHP_SELF '" METHOD="POST">
      <td valign="center">
        <select name="craft">
'
;
    foreach (
$crafts as $key=>$value){
        
$table .= ' <option value="'.$value[0].'">'.$value[0].'</option> '."\n";
    }
$table .=' </select>&nbsp;<input type="submit"></td></FORM><td width="30">&nbsp;</td></tr> ';
        
$table .= ' </table> ';
        
$content_output $table;
    }
    
/*
    *    Outputs table; end of script
    */

} else {
$content_output =' <table border = "0" cellspacing = "0" cellpadding = "5" width = "100%"> <tr> <FORM ACTION ="'.$PHP_SELF.'" METHOD = "POST"> <td valign = "center"> <select name = "craft"> ';
    foreach (
$crafts as $key=>$value){
        
$content_output .= ' <option value = "'.$value[0].'"> '.$value[0].' </option> '."\n";
    }
$content_output .=' </select> &nbsp; <input type = "submit"> </td> </FORM> <td width = "30"> &nbsp; </td> </tr> </table> ';
}

print $content_output;  // output our crafters list
?>