//Return a content encoded to support interactivities linking. Every module
function data_backup_mods($bf,$preferences) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
// iterate
- if ($datas = get_records('data','course',$preferences->backup_course,"id")) {
+ if ($datas = $DB->get_records('data', array('course'=>$preferences->backup_course),"id")) {
foreach ($datas as $data) {
if (function_exists('backup_mod_selected')) {
// Moodle 1.6
}
function data_backup_one_mod($bf,$preferences,$data) {
- global $CFG;
+ global $CFG, $DB;
if (is_numeric($data)) { // backwards compatibility
- $data = get_record('data','id',$data);
+ $data = $DB->get_record('data', array('id'=>$data));
}
$instanceid = $data->id;
function backup_data_fields($bf,$preferences,$dataid){
- global $CFG;
+ global $CFG, $DB;
$status = true;
- $data_fields = get_records("data_fields","dataid",$dataid);
+ $data_fields = $DB->get_records("data_fields", array("dataid"=>$dataid));
//If there is submissions
if ($data_fields) {
}
function backup_data_content($bf,$preferences,$recordid){
- global $CFG;
+ global $CFG, $DB;
$status = true;
- $data_contents = get_records("data_content","recordid",$recordid);
+ $data_contents = $DB->get_records("data_content", array("recordid"=>$recordid));
//If there is submissions
if ($data_contents) {
}
function backup_data_ratings($bf,$preferences,$recordid){
- global $CFG;
+ global $CFG, $DB;
+
$status = true;
- $data_ratings = get_records("data_ratings","recordid",$recordid);
+ $data_ratings = $DB->get_records("data_ratings", array("recordid"=>$recordid));
//If there is submissions
if ($data_ratings) {
return $status;
}
function backup_data_comments($bf,$preferences,$recordid){
- global $CFG;
+ global $CFG, $DB;
+
$status = true;
- $data_comments = get_records("data_comments","recordid",$recordid);
+ $data_comments = $DB->get_records("data_comments", array("recordid"=>$recordid));
//If there is submissions
if ($data_comments) {
}
function backup_data_records($bf,$preferences,$dataid){
+ global $CFG, $DB;
- global $CFG;
$status = true;
- $data_records = get_records("data_records","dataid",$dataid);
+ $data_records = $DB->get_records("data_records", array("dataid"=>$dataid));
//If there is submissions
if ($data_records) {
//Write start tag
}
function backup_data_files($bf,$preferences) {
-
global $CFG;
$status = true;
}
function backup_data_file_instance($bf,$preferences,$instanceid) {
-
global $CFG;
+
$status = true;
//First we check to moddata exists and create it as necessary
* @return string the content encoded
*/
function data_encode_content_links ($content,$preferences) {
-
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
$confirm = optional_param('confirm','',PARAM_INT);
- if (! $record = get_record('data_records', 'id', $rid)) {
+ if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
print_error('invalidrecord', 'data');
}
- if (! $data = get_record('data', 'id', $record->dataid)) {
+ if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($commentid) {
- if (! $comment = get_record('data_comments', 'id', $commentid)) {
+ if (! $comment = $DB->get_record('data_comments', array('id'=>$commentid))) {
print_error('commentmisconf');
}
if ($comment->recordid != $record->id) {
switch ($mode) {
case 'add':
- if (!$formadata = $mform->get_data()) {
+ if (!$formadata = $mform->get_data(false)) {
break; // something is wrong here, try again
}
$newcomment->modified = time();
$newcomment->content = $formadata->content;
$newcomment->recordid = $formadata->rid;
- if (insert_record('data_comments',$newcomment)) {
+ if ($DB->insert_record('data_comments',$newcomment)) {
redirect('view.php?rid='.$record->id.'&page='.$page);
} else {
print_error('cannotsavecomment');
$updatedcomment->format = $formadata->format;
$updatedcomment->modified = time();
- if (update_record('data_comments',$updatedcomment)) {
+ if ($DB->update_record('data_comments', $updatedcomment)) {
redirect('view.php?rid='.$record->id.'&page='.$page);
} else {
print_error('cannotsavecomment');
case 'delete': //deletes single comment from db
if ($confirm and confirm_sesskey() and $comment) {
- delete_records('data_comments','id',$comment->id);
+ $DB->delete_records('data_comments', array('id'=>$comment->id));
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data'));
} else { //print confirm delete form
$d = optional_param('d', 0, PARAM_INT); // database id
- if ($data = get_record('data', 'id', $d)) {
+ if ($data = $DB->get_record('data', array('id'=>$d))) {
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
header('Cache-control: max_age = '. $lifetime);
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
print_error('invalidcoursemodule');
}
} else {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
/// Can't use this if there are no fields
if (has_capability('mod/data:managetemplates', $context)) {
- if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
+ if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
}
/// Process incoming data for adding/updating records
- if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/edit.php') and confirm_sesskey()) {
+ if ($datarecord = data_submitted(false) and confirm_sesskey()) {
$ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel'); // strings to be ignored in input data
if ($rid) { /// Update some records
/// All student edits are marked unapproved by default
- $record = get_record('data_records','id',$rid);
+ $record = $DB->get_record('data_records', array('id'=>$rid));
/// reset approved flag after student edit
if (!has_capability('mod/data:approve', $context)) {
$record->groupid = $currentgroup;
$record->timemodified = time();
- update_record('data_records',$record);
+ $DB->update_record('data_records', $record);
/// Update all content
$field = NULL;
if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record
/// Insert a whole lot of empty records to make sure we have them
- $fields = get_records('data_fields','dataid',$data->id);
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
foreach ($fields as $field) {
$content->recordid = $recordid;
$content->fieldid = $field->id;
- insert_record('data_content',$content);
+ $DB->insert_record('data_content',$content);
}
//for each field in the add form, add it to the data_content.
* Regular expression replacement section *
******************************************/
if ($data->addtemplate){
- $possiblefields = get_records('data_fields','dataid',$data->id,'id');
+ $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
///then we generate strings to replace
foreach ($possiblefields as $eachfield){
/// Finish the page
// Print the stuff that need to come after the form fields.
- if (!$fields = get_records('data_fields', 'dataid', $data->id)) {
+ if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
print_error('nofieldindatabase', 'data');
}
foreach ($fields as $eachfield) {
$d = required_param('d', PARAM_INT);
// database ID
-if (! $data = get_record('data', 'id', $d)) {
+if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('wrongdataid', 'data');
}
print_error('invalidcoursemodule');
}
-if(! $course = get_record('course', 'id', $cm->course)) {
+if(! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('invalidcourseid', '', '', $cm->course);
}
require_capability('mod/data:managetemplates', $context);
// get fields for this database
-$fieldrecords = get_records('data_fields','dataid', $data->id, 'id');
+$fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
if(empty($fieldrecords)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
}
-$datarecords = get_records('data_records', 'dataid', $data->id);
+$datarecords = $DB->get_records('data_records', array('dataid'=>$data->id));
ksort($datarecords);
$line = 1;
foreach($datarecords as $record) {
// get content indexed by fieldid
- if( $content = get_records('data_content', 'recordid', $record->id, 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) {
+ if( $content = $DB->get_records('data_content', array('recordid'=>$record->id), 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) {
foreach($fields as $field) {
$contents = '';
if(isset($content[$field->field->id])) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
error('Course Module ID was incorrect');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
error('Course is misconfigured');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
error('Course module is incorrect');
}
} else {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
error('Data ID is incorrect');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
switch ($mode) {
case 'add': ///add a new field
- if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){
+ if (confirm_sesskey() and $fieldinput = data_submitted(false)){
//$fieldinput->name = data_clean_field_name($fieldinput->name);
$field->insert_field();
/// Update some templates
- data_append_new_field_to_templates($data, stripslashes($fieldinput->name));
+ data_append_new_field_to_templates($data, $fieldinput->name);
add_to_log($course->id, 'data', 'fields add',
"field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
case 'update': ///update a field
- if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){
+ if (confirm_sesskey() and $fieldinput = data_submitted(false)){
//$fieldinput->name = data_clean_field_name($fieldinput->name);
$rec->id = $data->id;
$rec->defaultsort = 0;
$rec->defaultsortdir = 0;
- if (!update_record('data', $rec)) {
+ if (!$DB->update_record('data', $rec)) {
error('There was an error updating the database');
}
}
$rec->defaultsort = $defaultsort;
$rec->defaultsortdir = $defaultsortdir;
- if (update_record('data', $rec)) {
+ if ($DB->update_record('data', $rec)) {
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2);
} else {
error('There was an error updating the database');
data_print_header($course,$cm,$data,'fields');
- if (!record_exists('data_fields','dataid',$data->id)) {
+ if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) {
notify(get_string('nofieldindatabase','data')); // nothing in database
notify(get_string('pleaseaddsome','data', 'preset.php?id='.$cm->id)); // link to presets
$table->align = array('left','left','left', 'center');
$table->wrap = array(false,false,false,false);
- if ($fff = get_records('data_fields','dataid',$data->id,'id')){
+ if ($fff = $DB->get_records('data_fields', array('dataid'=>$data->id),'id')){
foreach ($fff as $ff) {
$field = data_get_field($ff, $data);
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
echo '<select id="defaultsort" name="defaultsort">';
- if ($fields = get_records('data_fields','dataid',$data->id)) {
+ if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
echo '<optgroup label="'.get_string('fields', 'data').'">';
foreach ($fields as $field) {
if ($data->defaultsort == $field->id) {
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
$content = array();
if ($recordid) {
- $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = explode('##', $content);
}
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_checkbox_content($value);
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
+ global $DB;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$contentArr = array();
if (!empty($content->content)) {
$contentArr = explode('##', $content->content);
}
function display_add_field($recordid=0) {
+ global $DB;
if ($recordid) {
- $content = (int) get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
} else {
$content = time();
}
}
function update_content($recordid, $value, $name='') {
+ global $DB;
$names = explode('_',$name);
$name = $names[2]; // day month or year
$content->recordid = $recordid;
$content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false);
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
}
function display_browse_field($recordid, $template) {
+ global $CFG, $DB;
- global $CFG;
-
- if ($content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid)){
+ if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
return userdate($content, get_string('strftimedate'), 0);
}
}
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
if ($recordid){
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$contents[0] = $content->content;
$contents[1] = $content->content1;
} else {
}
function display_browse_field($recordid, $template) {
- global $CFG;
- if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ global $CFG, $DB;
+
+ if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
return false;
}
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
// content: "a##b" where a is the file name, b is the display name
function update_content($recordid, $value, $name) {
- global $CFG;
- if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ global $CFG, $DB;
+
+ if (!$oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
// Quickly make one now!
$oldcontent = new object;
$oldcontent->fieldid = $this->field->id;
$oldcontent->recordid = $recordid;
- if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
+ if ($oldcontent->id = $DB->insert_record('data_content', $oldcontent)) {
print_error('cannotinsertempty', 'data');
}
}
if ($um->process_file_uploads($dir)) {
$newfile_name = $um->get_new_filename();
$content->content = $newfile_name;
- update_record('data_content',$content);
+ $DB->update_record('data_content',$content);
}
}
break;
case 'filename':
// only changing alt tag
$content->content1 = clean_param($value, PARAM_NOTAGS);
- update_record('data_content', $content);
+ $DB->update_record('data_content', $content);
break;
default:
<?php echo get_string('maxsize', 'data'); ?></label></td>
<td class="c1">
<?php
- $course->maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course);
+ $course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course));
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3');
?>
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
+
$lat = '';
$long = '';
if ($recordid) {
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$lat = $content->content;
$long = $content->content1;
}
}
function display_browse_field($recordid, $template) {
- global $CFG;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ global $CFG, $DB;
+
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$lat = empty($content->content)? '':$content->content;
$long = empty($content->content1)? '':$content->content1;
if (empty($lat) or empty($long)) {
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
default:
break;
}
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
if ($rid) {
- if (! $record = get_record('data_records', 'id', $rid)) {
+ if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
print_error('invalidrecord', 'data');
}
- if (! $data = get_record('data', 'id', $record->dataid)) {
+ if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('invalidcoursemodule');
}
- if (! $field = get_record('data_fields', 'id', $fieldid)) {
+ if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
print_error('invalidfieldtype', 'data');
}
- if (! $content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $rid)) {
+ if (! $content = $DB->get_record('data_content', array('fieldid'=>$fieldid, 'recordid'=>$rid))) {
print_error('nofieldcontent', 'data');
}
} else { // We must have $d
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('invalidcoursemodule');
}
- if (! $field = get_record('data_fields', 'id', $fieldid)) {
+ if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
/// If we have an empty Database then redirect because this page is useless without data
if (has_capability('mod/data:managetemplates', $context)) {
- if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
+ if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
}
echo data_latlong_kml_placemark($pm);
} else { // List all items in turn
- $contents = get_records('data_content', 'fieldid', $fieldid);
+ $contents = $DB->get_records('data_content', array('fieldid'=>$fieldid));
echo '<Document>';
$name = '';
if($field->param2 > 0) {
- $name = htmlspecialchars(get_field('data_content', 'content', 'fieldid', $field->param2, 'recordid', $content->recordid));
+ $name = htmlspecialchars($DB->get_field('data_content', 'content', array('fieldid'=>$field->param2, 'recordid'=>$content->recordid)));
}elseif($field->param2 == -2) {
$name = $content->content . ', ' . $content->content1;
}
<option value="-2"<?php if($this->field->param2==-2) echo ' selected="selected"' ?>><?php echo get_string('latitude', 'data').'/'.get_string('longitude', 'data') ?></option>
<?php
// Fetch all "suitable" other fields that exist for this database
- $textfields = get_records_select('data_fields', 'dataid='.$this->data->id.' AND type="text"');
+ $textfields = $DB->get_records_select('data_fields', array('dataid'=>$this->data->id, 'type'=>'text'));
echo '<optgroup label="'.get_string('latlongotherfields', 'data').':">';
if(sizeof($textfields)>0) {
foreach($textfields as $textfield) {
}
function display_add_field($recordid=0) {
+ global $DB;
if ($recordid){
- $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = trim($content);
} else {
$content = '';
}
function display_search_field($content = '') {
- global $CFG;
+ global $CFG, $DB;
$usedoptions = array();
$sql = "SELECT DISTINCT content
- FROM {$CFG->prefix}data_content
- WHERE fieldid={$this->field->id} AND content IS NOT NULL";
- if ($used = get_records_sql($sql)) {
+ FROM {data_content}
+ WHERE fieldid=: AND content IS NOT NULL";
+ if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$value = $data->content;
if ($value === '') {
function display_add_field($recordid=0) {
+ global $DB;
if ($recordid){
- $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = explode('##', $content);
} else {
$content = array();
}
function display_search_field($value = '') {
- global $CFG;
+ global $CFG, $DB;
if (is_array($value)){
$content = $value['selected'];
// display only used options
$usedoptions = array();
$sql = "SELECT DISTINCT content
- FROM {$CFG->prefix}data_content
- WHERE fieldid={$this->field->id} AND content IS NOT NULL";
- if ($used = get_records_sql($sql)) {
+ FROM {data_content}
+ WHERE fieldid=? AND content IS NOT NULL";
+ if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$valuestr = $data->content;
if ($valuestr === '') {
$found = true;
$str .= '<option value="' . s($option) . '"';
- if (in_array(addslashes($option), $content)) {
+ if (in_array($option, $content)) {
// Selected by user.
$str .= ' selected = "selected"';
}
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_multimenu_content($value);
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
if ($key === 'xxx') {
continue;
}
- if (!in_array(stripslashes($val), $options)) {
+ if (!in_array($val, $options)) {
continue;
}
$vals[] = $val;
function display_browse_field($recordid, $template) {
+ global $DB;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (empty($content->content)) {
return false;
}
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
} else {
$content->content = null;
}
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ global $DB;
+
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (strlen($content->content) < 1) {
return false;
}
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
+
$filepath = '';
$filename = '';
$description = '';
if ($recordid) {
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$filename = $content->content;
$description = $content->content1;
}
}
function display_browse_field($recordid, $template) {
- global $CFG;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
+ global $CFG, $DB;
+
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (isset($content->content)) {
$contents[0] = $content->content;
$contents[1] = $content->content1;
}
function update_field() {
+ global $DB;
+
// Get the old field data so that we can check whether the thumbnail dimensions have changed
- $oldfield = get_record('data_fields', 'id', $this->field->id);
- if (!update_record('data_fields', $this->field)) {
+ $oldfield = $DB->get_record('data_fields', array('id'=>$this->field->id));
+ if (!$DB->update_record('data_fields', $this->field)) {
notify('updating of new field failed!');
return false;
}
// Have the thumbnail dimensions changed?
if ($oldfield && ($oldfield->param4 != $this->field->param4 || $oldfield->param5 != $this->field->param5)) {
// Check through all existing records and update the thumbnail
- if ($contents = get_records('data_content', 'fieldid', $this->field->id)) {
+ if ($contents = $DB->get_records('data_content', array('fieldid'=>$this->field->id))) {
if (count($contents) > 20) {
notify(get_string('resizingimages', 'data'), 'notifysuccess');
echo "\n\n";
}
function update_content($recordid, $value, $name) {
+ global $DB;
+
parent::update_content($recordid, $value, $name);
- $content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid);
+ $content = $DB->get_record('data_content',array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$this->update_thumbnail($content);
// Regenerate the thumbnail
}
<?php echo get_string('maxsize', 'data'); ?></label></td>
<td class="c1">
<?php
- $course->maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course);
+ $course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course));
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3');
?>
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
if ($recordid){
- $content = trim(get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid));
+ $content = trim($DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)));
} else {
$content = '';
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
$text = '';
$format = 0;
if ($recordid){
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$text = $content->content;
$format = $content->content1;
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = clean_param($value, PARAM_CLEAN);
}
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
}
}
function display_add_field($recordid=0) {
- global $CFG;
+ global $CFG, $DB;
+
$url = '';
$text = '';
if ($recordid) {
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$url = $content->content;
$text = $content->content1;
}
}
function display_browse_field($recordid, $template) {
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ global $DB;
+
+ if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$url = empty($content->content)? '':$content->content;
$text = empty($content->content1)? '':$content->content1;
if (empty($url) or ($url == 'http://')) {
}
function update_content($recordid, $value, $name='') {
+ global $DB;
+
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
break;
}
- if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
- return update_record('data_content', $content);
+ return $DB->update_record('data_content', $content);
} else {
- return insert_record('data_content', $content);
+ return $DB->insert_record('data_content', $content);
}
}
// Modified for data module by Vy-Shane SF.
function data_filter($courseid, $text) {
- global $CFG;
+ global $CFG, $DB;
static $nothingtodo;
static $contentlist;
'dr.id AS recordid, ' .
'dc.content AS content, ' .
'd.id AS dataid ' .
- 'FROM '.$CFG->prefix.'data d, ' .
- $CFG->prefix.'data_fields df, ' .
- $CFG->prefix.'data_records dr, ' .
- $CFG->prefix.'data_content dc ' .
- "WHERE (d.course = '$courseid' or d.course = '".SITEID."')" .
+ 'FROM {data} d, ' .
+ '{data_fields} df, ' .
+ '{data_records} dr, ' .
+ '{data_content} dc ' .
+ "WHERE (d.course = ? or d.course = '".SITEID."')" .
'AND d.id = df.dataid ' .
'AND df.id = dc.fieldid ' .
'AND d.id = dr.dataid ' .
"AND df.type = 'text' " .
'AND df.param1 = 1';
- if (!$datacontents = get_records_sql($sql)) {
+ if (!$datacontents = $DB->get_records_sql($sql, array($courseid))) {
return $text;
}
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
print_error('invalidcoursemodule');
}
} else {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
foreach ($records as $record) {
if ($recordid = data_add_record($data, 0)) { // add instance to data_record
- $fields = get_records('data_fields', 'dataid', $data->id, '', 'name, id, type');
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
// Insert new data_content fields with NULL contents:
foreach ($fields as $field) {
$content = new object();
$content->recordid = $recordid;
$content->fieldid = $field->id;
- if (! insert_record('data_content', $content)) {
+ if (! $DB->insert_record('data_content', $content)) {
print_error('cannotinsertrecord', '', '', $recordid);
}
}
$replacements[] = '>';
$value = preg_replace($patterns, $replacements, $value);
}
- $value = addslashes($value);
// for now, only for "latlong" and "url" fields, but that should better be looked up from
// $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php'
// once there is stored how many contents the field can have.
} else {
$content->content = $value;
}
- $oldcontent = get_record('data_content', 'fieldid', $field->id, 'recordid', $recordid);
+ $oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid));
$content->id = $oldcontent->id;
- if (! update_record('data_content', $content)) {
+ if (! $DB->update_record('data_content', $content)) {
print_error('cannotupdaterecord', '', '', $recordid);
}
}
// TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
- $numrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
- 'data_records r WHERE r.dataid ='.$data->id);
+ $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
if ($data->approval == 1) {
- $numunapprovedrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
- 'data_records r WHERE r.dataid ='.$data->id.
- ' AND r.approved <> 1');
+ $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
} else {
$numunapprovedrecords = '-';
}
$d = optional_param('d', 0, PARAM_INT); // database id
- if ($data = get_record('data', 'id', $d)) {
+ if ($data = $DB->get_record('data', array('id'=>$d))) {
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
header('Cache-control: max_age = '. $lifetime);
// Print the relevant form element to define the attributes for this field
// viewable by teachers only.
function display_edit_field() {
- global $CFG;
+ global $CFG, $DB;
if (empty($this->field)) { // No field has been defined yet, try and make one
$this->define_default_field();