-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditconnection.php
90 lines (75 loc) · 2.52 KB
/
editconnection.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
<?php
/**
* Push/pull remote files on a schedule
*
* Main landing page
*
* @package local
* @subpackage rfiles
* @author Shane Elliott, [email protected]
* @copyright Pukunui, http://pukunui.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('lib.php');
require_once('forms.php');
$systemcontext = context_system::instance();
require_login();
require_capability('moodle/site:config', $systemcontext);
$strrfiles = get_string('pluginname', 'local_rfiles');
$PAGE->set_context($systemcontext);
$PAGE->set_pagelayout('standard');
$PAGE->set_title($strrfiles);
$PAGE->set_cacheable(false);
$PAGE->set_popup_notification_allowed(false);
$PAGE->set_heading($strrfiles);
$PAGE->set_url('/local/rfiles/editconnection.php');
$PAGE->navbar->add($strrfiles);
$id = optional_param('id', 0, PARAM_INT);
$hostform = new rfiles_hostform();
if ($data = $hostform->get_data()) {
if (empty($data->active)) $data->active = 0; // Set value for empty checkbox.
if (empty($data->port)) {
switch ($data->protocol) {
case RFILES_PR_FTP:
case RFILES_PR_FTPPASV:
case RFILES_PR_FTPSSL:
$data->port = 21;
break;
case RFILES_PR_SFTP:
$data->port = 22;
break;
default:
$data->port = 21;
}
}
if (empty($data->username)) $data->username = '';
if (empty($data->password)) $data->password = '';
$data->remotedirectory = rtrim($data->remotedirectory, '/');
$data->localdirectory = rtrim($data->localdirectory, '/');
$data->sourceproccessdirectory = rtrim($data->sourceprocessdirectory, '/');
if ($data->id) {
if ($DB->update_record('local_rfiles_host', $data)) {
$message = get_string('connectionupdated', 'local_rfiles');
} else {
$message = get_string('connectionupdateproblem', 'local_rfiles');
}
} else {
if ($DB->insert_record('local_rfiles_host', $data)) {
$message = get_string('connectionadded', 'local_rfiles');
} else {
$message = get_string('connectionaddedproblem', 'local_rfiles');
}
}
redirect($CFG->wwwroot.'/local/rfiles/index.php', $message);
exit;
}
// Set the default data.
if ($id) {
if ($host = $DB->get_record('local_rfiles_host', array('id' => $id))) {
$hostform->set_data($host);
}
}
echo $OUTPUT->header();
$hostform->display();
echo $OUTPUT->footer();