<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH 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 3 of the License, or
	(at your option) any later version

	POSH 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.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
# ***************************************
# POSH Module management - add a new directory script
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************

require_once("includes_api.php");
require_once("authentication.php");

header ('Content-Type: text/javascript; charset=utf-8');

$result = "var icons = [";
$iconSelected =  isset($_GET["icon"])?$_GET["icon"]:1;
if($iconSelected==0)
    $iconSelected = 1;
$pt = opendir('../modules/pictures/');
$key = 0;
while ($entry = readdir($pt)) {
    if ($entry != "." && $entry != ".." && substr($entry,0,8)=="_deficon" ) {
        $key = substr($entry,8, (strrpos($entry,".")-8) );
        $tab[$key] = $entry;
    }
}

closedir($pt);

$nb=count($tab);
for ($i=1;$i<$nb;$i++) {
    $result .=  "{'id':".$i.",'icon':'".__LOCALFOLDER."modules/pictures/".$tab[$i]."'},";
}
$result =  substr($result,0, - 1);
$result .= "];";
echo $result;

?>


function selecticon2( iconid )
{	
	if(document.getElementById("iconid").value>0)
		document.getElementById("icon"+document.getElementById("iconid").value).style.border = " 0px solid rgb(255, 0, 0)";
    document.getElementById("icon"+iconid).style.border = " 2px solid rgb(255, 0, 0)";
	document.getElementById("iconlist").value = iconid;
	document.getElementById("iconid").value = iconid;
}
<?php
if( isset($_GET["c"]) ) {
?>
	function buildIconList() {	
			if(document.getElementById("iconid"))
				var selectedIdInTypo3 =  (document.getElementById("iconid").value=="")?1:document.getElementById("iconid").value;
		    var iconList = "";
		    var sel = "";
			
			for(var i=0; i<icons.length; i++) {
		        sel = "0px solid rgb(255, 0, 0);";
		        if(icons[i].id == selectedIdInTypo3 )
		            sel = "border: 2px solid rgb(255, 0, 0);";
		        iconList += '<a href="#" onclick="selecticon2('+icons[i].id+');return false;">';
		        iconList += '<img height="16" width="16" id="icon'+icons[i].id+'" src="'+icons[i].icon+'" style="'+sel+'"/>';
		        iconList += '</a>'+((i==19 || i==39 || i==59 )?"<br />":"");
		    }
			iconList += "<br />";
			if(document.getElementById("iconlist"))
				document.getElementById("iconlist").innerHTML = iconList;
			if(document.getElementById("iconid"))
				document.getElementById("iconid").value = selectedIdInTypo3;
	}
	buildIconList();
<?php
} else {
?>
	function buildIconList() {
	    var iconList = "";
	    var sel = "";
	    for(var i=0; i<icons.length; i++) {
	        sel = "0px solid rgb(255, 0, 0);";
	        if(icons[i].id == <?php echo $iconSelected; ?> )
	            sel = "border: 2px solid rgb(255, 0, 0);";
	        
	        iconList += '<a href="#" onclick="selecticon('+icons[i].id+');return false;">';
	        iconList += '<img height="16" width="16" id="icon'+icons[i].id+'" src="'+icons[i].icon+'" style="'+sel+'"/>';
	        iconList += '</a>';
	    }
	    document.getElementById("iconlist").innerHTML = iconList;
	    document.getElementById("icon").value = <?php echo $iconSelected; ?>;
	}
	buildIconList();

<?php
}
?>
