icon-set.php

File Type: php File Location: monofiles/ File name: icon-set.php
<?php
    
    
// Open images folder and apply either a usericon or a background icon
    
include_once 'data_connect.php';
    include 
'log.php';

    
//mypanel stuff included here
    
libxml_clear_errors;
    
libxml_use_internal_errors(true);
    
    
    
// Check settings file condition
    
if (!file_exists('filesinfo/settings.xml'))
        exit(
'Could not load page. Settings file is missing');
        
    
$settingsXML simplexml_load_file('filesinfo/settings.xml');
        
    if (
$settingsXML === false)
        exit(
'Error: Settings file is corrupt');    
    
    
    
    if (isset(
$_GET['useimg']))
        
$_SESSION['usericon'] = $_GET['useimg'];
        
    elseif (isset(
$_GET['useiconbg'])) 
        
$_SESSION['backgroundicon'] = $_GET['useiconbg'];

    
//Parameter use to redirect
    
$prm = (isset($_GET['backgroundset'])) ? '?backgroundset=1' '';
    
    
    
// Delete userimage or background image which are image files inside the images folder.
    
if (isset($_GET['delimg'])){
        
        
$delimage $_GET['delimg'];
            
        if(
is_file($delimage)) {
                
            
unlink($delimage);
            
$_SESSION['iconsetdelete'] = '<div class="icondelete">Image deleted</div>';
            
header("Location:icon-set.php$prm");
            exit();
        }
        
    }

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Images</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<script type="text/javascript">function conf(form){return confirm('Delete photo?');}</script>
<?php include 'csstheme.php' ?>
</head>
<body>
<?php 
if (isset($_SESSION['iconsetdelete'])){

    print 
$_SESSION['iconsetdelete'];
    unset (
$_SESSION['iconsetdelete']);
    
}

?>
<div id="userimages-wrap">
<h3 style="font-weight:normal">Images</h3>
<div id="userimages">
<?php

    $array_img 
= array();
    
$array_mtime = array();

    
$directory = new DirectoryIterator('../images/');

    foreach (
$directory as $fileinfo) {

        if (
$fileinfo->isFile()) {

            
$name $fileinfo->getFilename();
            
$ext $fileinfo->getExtension();
            
$mtime $fileinfo->getMtime();

            if (
strpos('.png .jpg .gif',$ext) !== false) {
                
$array_img[]= $name;
                
$array_mtime[] = $mtime;
            }
        }    
    }

    
rsort($array_mtime);

    foreach(
$array_mtime as $mt) {

        foreach(
$array_img as $imgkey=>$img) {

            if (
filemtime('../images/'.$img) == $mt) {

                
$indicator '';
                
$na '';
                
$im '../images/'.$img;
                
                if (isset(
$_GET['backgroundset'])) {
                    if (isset(
$_SESSION['backgroundicon']))
                        
$in_use $_SESSION['backgroundicon'];
                    else
                    
$in_use $settingsXML->general->monoback;
                    
                    
$par 'backgroundset=1&amp;useiconbg';
                    
$pardel 'backgroundset=1&amp;delimg';
                }
                
                else {
                    if (isset(
$_SESSION['usericon']))
                        
$in_use $_SESSION['usericon'];
                    else
                    
$in_use get_account($_SESSION['userID'])['icon'];
                    
                    
$par 'useimg';
                    
$pardel 'delimg';
                }
                    
                
                
                if (
$im == $in_use){
                    
$indicator ' current-use';
                    
$na 'style="display:none"';
                }
                
                echo 
'<div class="user-icon-wrap'.$indicator.'"><img class="user" src="'.$im.'"><a href="?'.$pardel.'='.$im.'" '.$na.' onclick="return conf(this)"><div class="delthis">X</div></a><a href="?'.$par.'='.$im.'" '.$na.'><div class="useimg">Use</div></a></div>';

                unset (
$array_img[$imgkey]);
            }    
        }
    }
?>
</div>
</div>
</body>
</html>