<?php
/* This file is part of Madcollector.
* Madcollector created by Thomas Andrieu,
* Developped by Mickael Jardet and Thomas Andrieu.
* Madcollector is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* Madcollector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
//defines divers
define("DATA", "data/");
define("LIBS", "libs/");
function mad_date()
{
$lang=$_SESSION['lang'];
switch($lang)
{
case "fr" :
return date("j")."/". date("m")."/". date("Y");
break;
default :
return date("F jS, Y");
break;
}
}
function pagination($page, $redirect, $nbPages)
{
echo "Page ";
for($i = 0; $i<$nbPages; $i++)
{
if($i != 0) echo " - ";
if(($i+1)== ($page))
echo " [<a href=\"".$redirect."&page=".($i+1)."\">".($i+1)."</a>]";
else echo " <a href=\"".$redirect."&page=".($i+1)."\">".($i+1)."</a>";
}
}
function pagination_letter($redirect)
{
echo "<a href=\"".$redirect."&letter=A\">A</a>";
echo " - <a href=\"".$redirect."&letter=B\">B</a>";
echo " - <a href=\"".$redirect."&letter=C\">C</a>";
echo " - <a href=\"".$redirect."&letter=D\">D</a>";
echo " - <a href=\"".$redirect."&letter=E\">E</a>";
echo " - <a href=\"".$redirect."&letter=F\">F</a>";
echo " - <a href=\"".$redirect."&letter=G\">G</a>";
echo " - <a href=\"".$redirect."&letter=H\">H</a>";
echo " - <a href=\"".$redirect."&letter=I\">I</a>";
echo " - <a href=\"".$redirect."&letter=J\">J</a>";
echo " - <a href=\"".$redirect."&letter=K\">K</a>";
echo " - <a href=\"".$redirect."&letter=L\">L</a>";
echo " - <a href=\"".$redirect."&letter=M\">M</a>";
echo " - <a href=\"".$redirect."&letter=N\">N</a>";
echo " - <a href=\"".$redirect."&letter=O\">O</a>";
echo " - <a href=\"".$redirect."&letter=P\">P</a>";
echo " - <a href=\"".$redirect."&letter=Q\">Q</a>";
echo " - <a href=\"".$redirect."&letter=R\">R</a>";
echo " - <a href=\"".$redirect."&letter=S\">S</a>";
echo " - <a href=\"".$redirect."&letter=T\">T</a>";
echo " - <a href=\"".$redirect."&letter=U\">U</a>";
echo " - <a href=\"".$redirect."&letter=V\">V</a>";
echo " - <a href=\"".$redirect."&letter=W\">W</a>";
echo " - <a href=\"".$redirect."&letter=X\">X</a>";
echo " - <a href=\"".$redirect."&letter=Y\">Y</a>";
echo " - <a href=\"".$redirect."&letter=Z\">Z</a>";
}
function display_story_artists($workertable, $story_number)
{
$issue_scenarists = array();
$issue_drawers = array();
$issue_letters = array();
$issue_colors = array();
$issue_cover = array();
$issue_editors = array();
global $lc_Issue_Cast,$lc_Issue_Story,$lc_Works_roles,$lc_Issue_Art,$lc_Issue_Letters,$lc_Issue_Colors,$lc_Issue_Covers,$lc_Issue_Editing;
if(sizeOf($workertable)>0)
{
echo "<div id=\"cast_story".$story_number."\"><h3>".$lc_Issue_Cast." : </h3></div>\n";
for($i = 0; $i< sizeOf($workertable); $i++)
{
$loopWorker = $workertable[$i];
$loopArtist = $loopWorker->artist;
$role_to_team = array();
$role_to_team["boss"] = "editing";
$role_to_team["consultant"] = "plot";
$role_to_team["covers"] = "covers";
$role_to_team["colors"] = "colors";
$role_to_team["editor"] = "editing";
$role_to_team["finishes"] = "art";
$role_to_team["inks"] = "art";
$role_to_team["layout"] = "art";
$role_to_team["letters"] = "letters";
$role_to_team["paint"] = "art";
$role_to_team["pencils"] = "art";
$role_to_team["plotter"] = "plot";
$role_to_team["scenarist"] = "plot";
switch($role_to_team[($loopWorker->role)])
{
case "plot":
array_push($issue_scenarists,$workertable[$i]);
break;
case "art":
array_push($issue_drawers,$workertable[$i]);
break;
case "letters":
array_push($issue_letters,$workertable[$i]);
break;
case "colors":
array_push($issue_colors,$workertable[$i]);
break;
case "cover":
array_push($issue_cover,$workertable[$i]);
break;
case "editing":
array_push($issue_editors,$workertable[$i]);
break;
default:
break;
}
}
}
if(sizeOf($issue_scenarists)>0)
{
echo "<div id=\"story_story".$story_number."\">".$lc_Issue_Story." : ";
for($i = 0; $i< sizeOf($issue_scenarists); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_scenarists[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
if($loopWorker->role != "scenarist")
echo " (".$lc_Works_roles[$loopWorker->role].")";
echo "</a>";
}
echo "</div>\n";
}
if(sizeOf($issue_drawers)>0)
{
echo "<div id=\"art_story".$story_number."\">".$lc_Issue_Art." : ";
for($i = 0; $i< sizeOf($issue_drawers); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_drawers[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
if($loopWorker->role != "pencils")
echo " (".$lc_Works_roles[$loopWorker->role].")";
echo "</a>";
}
echo "</div>\n";
}
if(sizeOf($issue_letters)>0)
{
echo "<div id=\"letters_story".$story_number."\">".$lc_Issue_Letters." : ";
for($i = 0; $i< sizeOf($issue_letters); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_letters[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
echo "</a>";
}
echo "</div>\n";
}
if(sizeOf($issue_colors)>0)
{
echo "<div id=\"colors_story".$story_number."\">".$lc_Issue_Colors." : ";
for($i = 0; $i< sizeOf($issue_colors); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_colors[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
echo "</a>";
}
echo "</div>\n";
}
if(sizeOf($issue_cover)>0)
{
echo "<div id=\"cover_story".$story_number."\">".$lc_Issue_Covers.": ";
for($i = 0; $i< sizeOf($issue_cover); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_cover[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
echo "</a>";
}
echo "</div>\n";
}
if(sizeOf($issue_editors)>0)
{
echo "<div id=\"editors_story".$story_number."\">".$lc_Issue_Editing.": ";
for($i = 0; $i< sizeOf($issue_editors); $i++)
{
if($i>0)
echo ", ";
$loopWorker = $issue_editors[$i];
$loopArtist = $loopWorker->artist;
echo "<a href=\"index.php?rub=artist&id_artist=".$loopArtist->id_artist."\">".$loopArtist->toString();
if($loopWorker->role != "editor")
echo " (".$lc_Works_roles[$loopWorker->role].")";
echo "</a>";
}
echo "</div>\n";
}
}
function div_form_input($id_name, $tag,$content,$empty_text)
{
echo '<div id="'.$id_name.'"';
if($_SESSION["level"]>1)
echo ' >;
echo '><div><'.$tag.'>'.$content.'</'.$tag.'></div>';
if($_SESSION["level"]>1)
{
if($content=="")
echo "<img src=\"images/add.gif\" alt=\"Click to add\" style=\"cursor:pointer;\"/>$empty_text";
echo ' <form method="POST" style="display:none"><input type="text" value="'.$content.'" name="'.$id_name.'_text"/><input type="submit" value="Ok" name="'.$id_name.'_submit"/></form>';
}
echo '</div>';
}
function div_form_textarea($id_name, $tag,$content,$empty_text)
{
echo '<div id="'.$id_name.'"';
if($_SESSION["level"]>1)
echo ' >;
echo '><div><'.$tag.'>'.$content.'</'.$tag.'></div>';
if($_SESSION["level"]>1)
{
if($content=="")
echo "<img src=\"images/add.gif\" alt=\"Click to add\" style=\"cursor:pointer;\"/>$empty_text";
echo ' <form method="POST" style="display:none"><textarea name="'.$id_name.'_text" style="width:100%">'.$content.'</textarea><input type="submit" value="Ok" name="'.$id_name.'_submit"/></form>';
}
echo '</div>';
}
function parse_content($contenuXML,$tagName)
{
$retour = "";
if($contenuXML=="")
{
return "";
}
if (version_compare(PHP_VERSION,'5','>='))
{
$dom = new DOMDocument();
if(!$dom->loadXML($contenuXML))
return "";
$noeuds = $dom->getElementsByTagName($tagName);
for($i=0; $i < $noeuds->length; $i++)
{
if($noeuds->item($i)->getAttribute("lang")==$_SESSION["lang"])
$retour = $noeuds->item($i)->nodeValue;
if($noeuds->item($i)->getAttribute("lang")==$_SESSION["en"])
$backup_retour = $noeuds->item($i)->nodeValue;
}
}
else
{
if(!$dom = domxml_open_mem($contenuXML))
return "";
$root = $dom->document_element();
$noeuds = $root->get_elements_by_tagname($tagname);
for($i=0; $i < sizeOf($noeuds); $i++)
{
if($noeuds[$i]->get_attribute("lang")==$_SESSION["lang"])
$retour = $noeuds[$i]->get_content();
if($noeuds[$i]->get_attribute("lang")==$_SESSION["en"])
$backup_retour = $noeuds[$i]->get_content();
}
}
if($retour != "")
return $retour;
else return $backup_retour;
}
function addXML_content($contenuXML,$tagName,$rootName,$addValue)
{
if (version_compare(PHP_VERSION,'5','>='))
{
$dom = new DOMDocument();
$node_found=false;
if($contenuXML != "")
{
$addValue = htmlspecialchars(nl2br(utf8_encode($addValue)));
if(!$dom->loadXML($contenuXML))
return $contenuXML;
$noeuds = $dom->getElementsByTagName($tagName);
$rootNodeList = $dom->getElementsByTagName($rootName);
$rootNode = $dom->getElementsByTagName($rootName)->item(0);
$node_found=false;
for($i=0; $i < $noeuds->length; $i++)
{
if($noeuds->item($i)->getAttribute("lang")==$_SESSION["lang"])
{
$noeuds->item($i)->nodeValue = $addValue;
$node_found=true;
}
}
}
else
{
$node = $dom->createElement($rootName);
$rootNode = $dom->appendChild($node);
}
if(!$node_found)
{
$node = $dom->createElement($tagName,$addValue);
$new_node = $rootNode->appendChild($node);
$new_node->setAttribute("lang", $_SESSION["lang"]);
}
return $dom->saveXML();
}
else
{
// TODO for PHP4
}
}
?>