<!--
Copyright (c) 2011, Adam Beardwood
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    Neither the name of the Adam Beardwood nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all">@import "cohlog.css";</style>
</head>

<body>

<?php

/*--- Channel display function ---*/
function showtext($channel$val){
    if(isset(
$_POST["$channel"])){

        
$val stripslashes($val);
        echo 
"<span class='$channel'>$val</span><br />";

    }else;
}
/*--- End of function ---*/

if(isset($_POST['submit'])){ //If the form has been submitted

/*--- Cleanup Global boxes if users have entered text but not ticked anything ---*/
if(isset($_POST['global1']) == FALSE$_POST['gname1'] = "";
if(isset(
$_POST['global2']) == FALSE$_POST['gname2'] = "";
if(isset(
$_POST['global3']) == FALSE$_POST['gname3'] = "";
if(isset(
$_POST['global4']) == FALSE$_POST['gname4'] = "";
/*--- End of cleanup ---*/

echo "<div id='Chatparse'>";

$text nl2br($_POST['text']); //Convert the newline chars to <br>'s

$lines explode("<br />",$text); //Split the text into lines

foreach ($lines as $index => $val){ //For each line

/*--- Global Channel Parsing ---*/
if(strpos($val"[".$_POST['gname1']."]") != FALSE){
if(isset(
$_POST['global1'])){

$val stripslashes($val);
echo 
"<span class='global1'>$val</span><br />";
}else;

}elseif(
strpos($val"[".$_POST['gname2']."]") != FALSE){
if(isset(
$_POST['global2'])){

$val stripslashes($val);
echo 
"<span class='global2'>$val</span><br />";
}else;

}elseif(
strpos($val"[".$_POST['gname3']."]") != FALSE){
if(isset(
$_POST['global3'])){

$val stripslashes($val);
echo 
"<span class='global3'>$val</span><br />";
}else;

}elseif(
strpos($val"[".$_POST['gname4']."]") != FALSE){
if(isset(
$_POST['global4'])){

$val stripslashes($val);
echo 
"<span class='global4'>$val</span><br />";
}else;
/*--- End of Global Channel Parsing ---*/

}elseif(strpos($val"[Team]") != FALSE){ //Sort chat types

showtext("team"$val);

}elseif(
strpos($val"[Broadcast]") != FALSE){

showtext("broadcast"$val);

}elseif(
strpos($val"[Coalition]") != FALSE){

showtext("coalition"$val);

}elseif(
strpos($val"[Arena]") != FALSE){

showtext("arena"$val);

}elseif(
strpos($val"[SuperGroup]") != FALSE){

showtext("supergroup"$val);

}elseif(
strpos($val"[Local]") != FALSE){

showtext("local"$val);

}elseif(
strpos($val"[NPC]") != FALSE){

showtext("npc"$val);

}elseif(
strpos($val"[Request]") != FALSE){

showtext("request"$val);

}elseif(
strpos($val"[Tell]") != FALSE){

showtext("tell"$val);

}elseif(
strpos($val"[Friends]") != FALSE){

showtext("friends"$val);

}elseif(
strpos($val"[League]") != FALSE){

showtext("league"$val);

}elseif(
strpos($val"[Help]") != FALSE){

showtext("help"$val);

}elseif(
strpos($val"have defeated") != FALSE){
if(isset(
$_POST['defeated'])){

$val stripslashes($val);
echo 
"<span>$val</span><br />";
}else;

}elseif(
strpos($val"Your friend") != FALSE){
if(isset(
$_POST['friend'])){

$val stripslashes($val);
echo 
"<span>$val</span><br />";
}else;

}else{
if(isset(
$_POST['misc'])){

$val stripslashes($val);
echo 
"<span>$val</span><br />";
}else;

}
}

echo 
"<hr>";
echo 
"<center><button onclick='javascript:history.go(-1)' >Back</button></center>";

echo 
"</div>"//And we're done.

}else{?>
<div id="Content">
<h1>city of heroes / villains chatlog parser v1.5</h1>
<center>
<form action="<?php $PHP_SELF ?>" method="post">
<textarea name="text" rows="25" cols="75"></textarea><br />
<p>
Include the following chatter:<br />
N.B. The top set of options are colour-coded, the bottom set are not<br />
<table class="chatparse"><tr>
<td><input name="team" type="checkbox" /> Team</td>
<td><input name="broadcast" type="checkbox" /> Broadcast</td>
</tr><tr>
<td><input name="coalition" type="checkbox" /> Coalition</td>
<td><input name="arena" type="checkbox" /> Arena</td>
</tr><tr>
<td><input name="supergroup" type="checkbox" /> Supergroup</td>
<td><input name="local" type="checkbox" /> Local</td>
</tr><tr>
<td><input name="npc" type="checkbox" /> NPC</td>
<td><input name="request" type="checkbox" /> Request</td>
</tr><tr>
<td><input name="tell" type="checkbox" /> Tell</td>
<td><input name="friends" type="checkbox" /> Friends</td>
</tr><tr>
<td><input name="league" type="checkbox" /> League</td>
<td><input name="help" type="checkbox" /> Help</td>
</tr><tr>
<td><input name="global1" type="checkbox" /> Global 1 <input name="gname1" type="text" maxlength="25" class="chatparse" /></td>
<td><input name="global2" type="checkbox" /> Global 2 <input name="gname2" type="text" maxlength="25" class="chatparse" /></td>
</tr><tr>
<td><input name="global3" type="checkbox" /> Global 3 <input name="gname3" type="text" maxlength="25" class="chatparse" /></td>
<td><input name="global4" type="checkbox" /> Global 4 <input name="gname4" type="text" maxlength="25" class="chatparse" /></td>
</tr></table>
<br />
<table class="chatparse"><tr>
<td><input name="defeated" type="checkbox" /> Defeated Mobs</td>
<td><input name="friend" type="checkbox" /> Friend Notifications</td>
</tr><tr>
<td><input name="sidekick" type="checkbox" /> Sidekicks/Mentors</td>
<td><input name="misc" type="checkbox" /> Misc</td>
</tr>
</table>
</p><br />
<input type="submit" value="Parse" name="submit" />
</form></center>
</div>
<?php
}
?>

</body>
</html>