-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcp.vwm_secure_files.php
129 lines (110 loc) · 2.9 KB
/
mcp.vwm_secure_files.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php if ( ! defined('EXT')) { exit('Invalid file request'); }
/**
* VWM Secure Files
*
* @package VWM Secure Files
* @author Victor Michnowicz
* @copyright Copyright (c) 2011 Victor Michnowicz
* @license http://www.apache.org/licenses/LICENSE-2.0.html
* @link http://github.com/vmichnowicz/vwm_secure_files
*/
// -----------------------------------------------------------------------------
/**
* VWM Secure Files control panel
*/
class Vwm_secure_files_mcp {
/**
* Constructor
*
* @access public
* @return void
*/
public function __construct()
{
// Make a local reference to the ExpressionEngine super object
$this->EE =& get_instance();
// Load model
$this->EE->load->model('vwm_secure_files_m');
}
/**
* Module CP page
*
* @access public
* @return string
*/
public function index()
{
// Page title
$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('vwm_secure_files_module_name'));
// CP URL
$data['action_url'] = 'C=addons_modules' . AMP . 'M=show_module_cp' . AMP . 'module=vwm_secure_files' . AMP . 'method=add_file';
// Add JavaScript
$this->EE->cp->add_to_head('<script type="text/javascript">EE.CP_URL = "' . $this->EE->config->item('cp_url') . '";</script>');
$this->EE->cp->load_package_js('mcp');
// All members
$data['members'] = $this->EE->vwm_secure_files_m->all_members();
// All groups
$data['groups'] = $this->EE->vwm_secure_files_m->all_groups();
// Get all secure files
$data['files'] = $this->EE->vwm_secure_files_m->all_files();
return $this->EE->load->view('mcp', $data, TRUE);
}
/**
* Update a file
*
* @access public
* @return void
*/
public function update_file()
{
if ($this->EE->vwm_secure_files_m->update_file($_POST))
{
$this->EE->output->send_ajax_response(array('result' => 'success'));
}
else
{
$this->EE->output->send_ajax_response(array('result' => 'failure'));
}
}
/**
* Remove a file
*
* @access public
* @return void
*/
public function remove_file()
{
if ($this->EE->vwm_secure_files_m->remove_file($this->EE->input->post('id')))
{
$this->EE->output->send_ajax_response(array('result' => 'success'));
}
else
{
$this->EE->output->send_ajax_response(array('result' => 'failure'));
}
}
/**
* Add a file
*
* @access public
* @return void
*/
public function add_file()
{
// Redirect user back to this page after adding file
$redirect_to = $this->EE->input->post('redirect_to');
// if file addition was successful
if ($this->EE->vwm_secure_files_m->add_file($_POST))
{
// Great success!
$this->EE->session->set_flashdata('message_success', lang('vwm_secure_files_file_success'));
}
// If file addition failed
else
{
$this->EE->session->set_flashdata('message_failure', lang('vwm_secure_files_file_failure'));
}
$this->EE->functions->redirect(BASE . AMP . $redirect_to);
}
}
// END CLASS