-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_record.php
78 lines (52 loc) · 2.12 KB
/
edit_record.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
<?php
// to display as moodle page
require_once dirname(__FILE__)."/../../config.php";
//to read the csv file
require_once($CFG->libdir.'/csvlib.class.php');
//here we store the form to upload the csv file
require_once($CFG->dirroot.'/blocks/simple_map/upload_form.php');
$id = required_param('id', PARAM_INT);
confirm_sesskey();
$url = new moodle_url('/blocks/simple_map/edit_record.php', array('id'=>$id));
require_login();
$context = context_course::instance($COURSE->id);
require_capability('moodle/site:manageblocks', $context);
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$STD_FIELDS = array('id', 'title', 'description', 'opening_hours', 'address', 'city', 'area_code', 'region', 'country', 'lng', 'lat', 'category', 'link_1', 'link_2', 'link_3', 'link_4', 'link_5', 'contact'
);
$place = new stdClass();
// the name of the table in the database
$table = 'block_simple_map_places';
$PAGE->navbar->add("Edit records");
// get a new form object;
$mform = new edit_record_form(null, array('id'=>$id, 'table'=>$table));
if ($formdata = $mform->get_data()) {
//print_header_simple("simple_map", $COURSE->fullname, $navigation, "", "", true);
// The editor gives back an Array, we have to transform this to be able to write it to the database.
$formdata->description = $formdata->description['text'];
$formdata->opening_hours = $formdata->opening_hours['text'];
if ($formdata->address && !$formdata->lat && !$formdata->lng && $formdata->fetch_geo_codes) {
$maps_object = get_lat_lng_by_address($formdata->address, $formdata->city, $formdata->country, $table);
$formdata->lat = $maps_object->lat;
$formdata->lng = $maps_object->lng;
}
unset($formdata->fetch_geo_codes);
if ($formdata->id == -1 || $formdata->id == '') {
$formdata->id = null;
$DB->insert_record($table, $formdata, $returnid=false, $bulk=false);
}
else {
$formdata->id = $id;
$DB->update_record($table, $formdata, $bulk=false);
}
// Back to list-view
header("Location: edit_upload_form.php");
}
else {
echo $OUTPUT->header();
$mform->display();
}
// print_object($mform);
//echo $OUTPUT->footer();
?>