<?php

final class File {

    private $sql;
    var $cleaner = '<div style="clear: both;"></div>';
    var $form_action;
    var $var_paging = 5;

    public function __construct() {
        global $sql;
        $this->sql = &$sql;
        $this->form_action = str_replace('&', '&amp;', $_SERVER['REQUEST_URI']);
    }


    public function foto_upload_exe() {//$db_name, $koncovky, $upload_path,
        if	( isset($_FILES['pic']['name']) && (trim($_FILES['pic']['name']) != "") && isset($_POST['add_pic']) ) {
            $this->sql->sql_connect('e_learning');
            $img = getimagesize($_FILES['pic']['tmp_name']);
            $koncovka = strtolower(substr($_FILES['pic']['name'], strpos($_FILES['pic']['name'], '.')+1));
            if ($img) {
                if ( ($_FILES['pic']['error'] == UPLOAD_ERR_OK) ) {
                    if ( ($koncovka == 'jpg') || ($koncovka == 'jpeg') || ($koncovka == 'png') || ($koncovka == 'gif') ) {
                        if (is_uploaded_file($_FILES['pic']['tmp_name'])) {
                            $nazov = $_FILES['pic']['name'];

                            $location = './images/uploaded';

                            $sql_get_num = "UPDATE foto_inc SET kolko=kolko+1;";
                            $result_get_num = mysql_query($sql_get_num);
                            $sql_get_num = "SELECT kolko FROM foto_inc";
                            $result_get_num = mysql_query($sql_get_num);
                            $row_get_num = mysql_fetch_assoc($result_get_num);

                            $num = (100000 + $row_get_num['kolko']);
                            $location .= '/' . $num . '.jpg';
                            move_uploaded_file($_FILES['pic']['tmp_name'], $location);
                            chmod($location, 0777);
                            if ( $_SESSION['uploadnute'] == '' ) {
                                $_SESSION['uploadnute'] = '<div><img style="width: 120px; border: 1px solid #CCCCCC;" src="' . $location . '" /><br /><div>' . str_replace('../', '', $location) . '</div>';
                                //return true;
                            } else {
                                $_SESSION['uploadnute'] .= '<br />' . '<img style="text-align: center; width: 120px; border: 1px solid #CCCCCC;" src="' . $location . '" /><br /><div style="text-align: center;">' . str_replace('../', '', $location) . '</div>';
                                //return true;
                            }
                        }
                    } else {
                        echo '<span style="color: red;">Nie je to súbor s koncovkou jpg/jpeg/png/gif</span><br />';
                        //return false;
                    }
                } else {
                    echo '<p style="color: #FF0000;">Chyba</p>';
                    //return false;
                }
            } else {
                echo '<p style="color: #FF0000;">Súbor má priveľké rozmery alebo to nieje obrázok typu jpeg/jpg/png/gif.</p>';
                //return false;
            }
        }
    }


}
?>