Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/email/components/manage.php
Строк: 77
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_email_manage
{
    private 
$db;
    private 
$tpl;
    private 
$option;
    public function 
__construct()
    {
        
$this->db     = &VF::factory('database');
        
$this->tpl    = &VF::factory('template');
    }
    
    public function 
render()
    {
        
$cfg VF::cfg('core.config');

        
$errors     = array();
        
$messages   = array();
        if (isset(
$_POST['action']) && isset($_POST['email_id'])) {
            
$action     trim($_POST['action']);
            
$email_id      = (int) trim($_POST['email_id']);
            if (
$email_id) {
                switch (
$action) {
                    case 
'activate':
                    case 
'suspend':
                        
$msg    = ($action == 'activate') ? 'activated' 'suspended';
                        
$status = ($action == 'activate') ? 0;
                        
$this->db->query("UPDATE #__email SET status = '".$status."' WHERE email_id = ".$email_id." LIMIT 1");
                        
$messages[] = 'Email '.$msg.'!';
                        break;
                    case 
'delete':
                        
$this->db->query("DELETE FROM #__email WHERE email_id = ".$email_id." LIMIT 1");
                        
$messages[] = 'Email deleted!';
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[]   = 'Invalid email id! Are you sure this email exists!?';
            }
        }

       if (isset(
$_POST['submit_actions'])) {
            
$ids    $this->get_checkbox_ids();
            
$action trim($_POST['action']);
            if (
$ids) {
                if (
$action == 'activate' OR
                    
$action == 'suspend') {
                    
$msg    = ($action == 'activate') ? 'activated' 'suspended';
                    
$status = ($action == 'activate') ? 0;
                    
$this->db->query("UPDATE #__email SET status = '".$status."' WHERE email_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selected emails '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__email WHERE email_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selected emails deleted!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'You must select at least one email!';
            }
        }
        
        
$page            = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$this->option    = array(
            
'name' => '''description' => '''subject' => '',
            
'sort' => 'e.email_id''order' => 'DESC''display' => 10
        
);
        
        if (isset(
$_SESSION['search_email_option'])) {
            
$this->option $_SESSION['search_email_option'];
        }
        
        
$search            $this->search_emails();
        
$emails_total   $this->db->get_field($search['sql_count'], 'total_emails');
        
$pagination     VPagination::get($page$emails_total$search['display']);
        
$emails            $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
    
        
$tpl = &VF::factory('template');
        
$tpl->menu            'main';
        
$tpl->submenu        'email_manage';
        
$tpl->meta_title    'Admin::Email::Manage';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->option        $this->option;
        
$tpl->emails        $emails;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''email_manage''footer'));
        
$tpl->display();
    }
    
    private function 
search_emails()
    {
        
$sql        "SELECT e.* FROM #__email AS e";
        
$sql_count    "SELECT COUNT(e.email_id) AS total_emails FROM #__email AS e";
    
        return array(
            
'sql'        => $sql,
            
'sql_count'    => $sql_count,
            
'display' => 10
        
);
    }

    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key'checkbox_email_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_email_'''$key);
            }
        }
            
        return 
$ids;
    }    
}
?>
Онлайн: 0
Реклама