View file modules/index_page/system/index_page.php

File size: 5.47Kb
<?
/**
 * Автор скрипта Орёл
 * Распространение бесплатно
 * icq: 952042
 * E-mail [email protected]
 */
defined('IN_ACCESS') or die('<b>Доступ закрыт =)</b>');

class Index_Page_Controller extends Controller {

        public function action_index() {
                
                # Индексная страница
                $this->action_view_page();
        }
        /**
         * Индекс
         */
        public function action_view_page(){

                ### Upload файла
                f_import('modules/index_page/helpers/index_page_helper.php');
                if ($_POST['submit']){
                        $proccess_upload = index_page_helper::proccess_load();

                        if (!is_array($proccess_upload)){
                                Registry :: set('insertid', $proccess_upload);
                                notice('NOTICEUPLOADSUCCESS');
                        } else {
                                $errors = $proccess_upload;
                        }
                }

                if ($_POST['flash_upload']){
                        $load = index_page_helper::proccess_load(true);
                        if ($load){
                                echo $load;exit;
                        }
                }
                
                if ($this->config['ajax_upload']){
                        f_import('lib/swfupload/swfupload.php');
                        $upload = New swf_upload();
                        $upload->dir_source = URL . 'lib/swfupload/source/';
                        $upload->handler_phpfile = URL . 'index_page';
                }

                $tpl_data = array(
                        'errors'        => $errors,
                        'max_upload_byte'       => index_page_helper::sizeview($this->config['max_upload_byte']),
                        'ajax_upload'   => $this->config['ajax_upload'],
                        'ajax_upload_form'      => $upload ? $upload->display() : ''
                );
                
                $this->tpl->assign($tpl_data);
                $this->tpl->display('index');
        }
        
        public function action_down(){
                if ($_GET['idfile']){
                        $file = DB :: $dbh->queryFetch('SELECT `file_pswd`,`file_nameserver` FROM `files` WHERE `file_id`=?', array((int)$_GET['idfile']));
                        if (!empty($file)){
                                if ($file['file_pswd'] == ''){
                                        DB :: $dbh->query('UPDATE `files` SET `file_countdowm`=`file_countdowm`+?,`file_timelast`=? WHERE `file_id`=?', array(1, SITETIME, $_GET['idfile']));
                                        redirect(URL . 'files/'. $file['file_nameserver']);
                                } else {
                                        if ($_SESSION['auth_file'] == $_GET['idfile']){
                                                DB :: $dbh->query('UPDATE `files` SET `file_countdowm`=`file_countdowm`+?,`file_timelast`=? WHERE `file_id`=?', array(1, SITETIME, $_GET['idfile']));
                                                redirect(URL . 'files/'. $file['file_nameserver']);
                                        } else {
                                                redirect(p_url('main/page_not_found'));
                                        }
                                }
                        } else {
                                redirect(p_url('main/page_not_found'));
                        }
                } else {
                        redirect(p_url('main/page_not_found'));
                }
        }

        public function action_view(){
                if ($_GET['idfile']){
                        f_import('modules/index_page/helpers/index_page_helper.php');
                        $filedata = DB :: $dbh->queryFetch('SELECT * FROM `files` WHERE `file_id`=?', array((int)$_GET['idfile']));

                        # Авторизация по паролю
                        if ($filedata['file_pswd'] != ''){
                                $auth = true;
                                if ($_SESSION['auth_file'] == $filedata['file_id']) $auth = false;
                        }

                        if ($_POST['auth']){
                                if (md5($_POST['auth_pswd']) == $filedata['file_pswd']){
                                        $_SESSION['auth_file'] = $filedata['file_id'];
                                        $auth = false;
                                } else {
                                        $errors[] = 'Пароль неверный';
                                }
                        }
                        

                        if (empty($filedata)){
                                redirect(p_url('main/page_not_found'));
                        } else {
                                $tpl_data = array(
                                        'filedata'      => $filedata,
                                        'auth'  => $auth,
                                        'errors'        => $errors
                                );
                        }

                        $this->tpl->assign($tpl_data);
                        $this->tpl->display('view_file');
                } else {
                        redirect(p_url('main/page_not_found'));
                }
        }

}

?>