New field for menus

This commit is contained in:
moodler 2006-01-19 08:22:01 +00:00
parent f5d4ea3242
commit bfadc7ef00
3 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,99 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/// Please refer to lib.php for method comments
global $CFG;
require_once($CFG->dirroot.'/mod/data/lib.php');
class data_field_menu extends data_field_base {
function data_field_menu($fid=0){
parent::data_field_base($fid);
}
var $type = 'menu';
var $id; //field id
function insert_field($dataid, $type='menu', $name, $des='') {
$newfield = new object;
$newfield->dataid = $dataid;
$newfield->type = $type;
$newfield->name = $name;
$newfield->description = $des;
if (!insert_record('data_fields',$newfield)) {
notify('Insertion of new field failed!');
}
}
function display_add_field($id, $rid=0) {
global $CFG;
if (!$field = get_record('data_fields','id',$id)) {
notify("that is not a valid field id!");
exit;
}
//look for that record and pull it out
if ($rid) {
$datacontent = get_record('data_content','fieldid',$id,'recordid',$rid);
if (isset($datacontent->content)) {
$content = $datacontent->content;
}else {
$content = '';
}
}
$str .= '<table><tr><td>';
if ($field->description) {
$str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'">&nbsp;';
}
$str .= get_string('menu','data').'</td><td>';
$str .= '<SELECT name="field_'.$field->id.' id="field_'.$field->id.'>';
foreach (explode("\n",$field->param1) as $option){
if ($content == $option) { //if selected
$str.='<option value="'.ltrim(rtrim($option)).'" SELECTED>'.ltrim(rtrim($option)).'</option>';
} else {
$str.='<option value="'.ltrim(rtrim($option)).'">'.ltrim(rtrim($option)).'</option>';
}
}
$str .= '</SELECT></td></tr></table>';
return $str;
}
function display_edit_field($id, $mode=0) {
parent::display_edit_field($id, $mode);
}
function update($fieldobject) {
$fieldobject->param1 = trim($fieldobject->param1);
if (!update_record('data_fields',$fieldobject)){
notify ('upate failed');
}
}
}
?>

BIN
mod/data/field/menu/icon.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

32
mod/data/field/menu/mod.html Executable file
View file

@ -0,0 +1,32 @@
<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="POST">
<table width="100%">
<tr>
<td span="2">
<input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
<input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
<input type="hidden" name="type" value="<?php echo $this->type; ?>" />
<input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden">
<?php echo ($this->name()); ?>
</td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" value = "<?php echo($field->name); ?>" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" name="description" id="description" value = "<? echo ($field->description);?>" /></td>
</tr>
<tr>
<td>Options (Line Separated)</td>
<td><textarea name="param1" id="param1"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" \>
<input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" \>
</td>
</tr>
</table>
</form>