Skip to content

Commit

Permalink
Fixes related to presets and MDL-6755.
Browse files Browse the repository at this point in the history
The original code was shocking once I started reviewing it, and even
after heavy editing I'm still not happy with it, but at least it works
more like it was supposed to.

Needs more cleaning up to make it clearer and probably safer.

Also, presets can now contain langage packs and they'll be used.
The image gallery is an example.
  • Loading branch information
moodler committed Oct 2, 2006
1 parent 44abaca commit 8303eb8
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 428 deletions.
2 changes: 1 addition & 1 deletion lang/en_utf8/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
$string['mappingwarning'] = 'All old fields not mapped to a new field will be lost and all data in that field will be removed.';
$string['blank'] = 'Blank';

$string['presetwarning'] = 'Saving as a preset publishes this template across the entire site. All users will be able to use it in their databases.';
$string['presetinfo'] = 'Saving as a preset will publish this template. Other users may be able to use it in their databases.';
$string['deletewarning'] = 'Are you sure you want to delete this preset?';
$string['importsuccess'] = 'The preset has been successfully applied.';
$string['addentries'] = 'Add entries';
Expand Down
30 changes: 29 additions & 1 deletion mod/data/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,36 @@
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

'mod/data:viewalluserpresets' => array(

'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_PREVENT,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

'mod/data:manageuserpresets' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_PREVENT,
'teacher' => CAP_PREVENT,
'editingteacher' => CAP_PREVENT,
'coursecreator' => CAP_PREVENT,
'admin' => CAP_ALLOW
)
)

);

?>
?>
3 changes: 2 additions & 1 deletion mod/data/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
$strdata = get_string('modulenameplural','data');

print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
'', '', true, '', navmenu($course, $cm), '', '');
'', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
navmenu($course, $cm), '', '');

print_heading(format_string($data->name));

Expand Down
8 changes: 4 additions & 4 deletions mod/data/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

} else {

data_fields_print_header($course,$cm,$data, false);
data_print_header($course,$cm,$data, false);

// Print confirmation message.
$field = data_get_field_from_id($fid, $data);
Expand Down Expand Up @@ -232,22 +232,22 @@

if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// Adding a new field
$CFG->pagepath='mod/data/field/'.$newtype;
data_fields_print_header($course,$cm,$data);
data_print_header($course,$cm,$data,'fields');

$field = data_get_field_new($newtype, $data);
$field->display_edit_field();

} else if ($mode == 'display' && confirm_sesskey()) { /// Display/edit existing field
$CFG->pagepath='mod/data/field/'.$newtype;
data_fields_print_header($course,$cm,$data);
data_print_header($course,$cm,$data,'fields');

$field = data_get_field_from_id($fid, $data);
$field->display_edit_field();

} else { /// Display the main listing of all fields

$CFG->pagepath='mod/data/field/'.$newtype;
data_fields_print_header($course,$cm,$data);
data_print_header($course,$cm,$data,'fields');


if (!record_exists('data_fields','dataid',$data->id)) {
Expand Down
136 changes: 107 additions & 29 deletions mod/data/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,34 +1260,6 @@ function data_get_cm($data) {
}


function data_fields_print_header($course,$cm,$data,$showtabs=true) {

global $CFG, $displaynoticegood, $displaynoticebad;

$strdata = get_string('modulenameplural','data');

print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
'', '', true, '', navmenu($course, $cm));

print_heading(format_string($data->name));

/// Print the tabs

if ($showtabs) {
$currenttab = 'fields';
include_once('tabs.php');
}

/// Print any notices

if (!empty($displaynoticegood)) {
notify($displaynoticegood, 'notifysuccess'); // good (usually green)
} else if (!empty($displaynoticebad)) {
notify($displaynoticebad); // bad (usuually red)
}
}


/**
* Converts a database (module instance) to use the Roles System
* @param $data - a data object with the same attributes as a record
Expand Down Expand Up @@ -1429,5 +1401,111 @@ function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array
return true;
}

/*
* Returns the best name to show for a preset
*/
function data_preset_name($shortname, $path) {

/// We are looking inside the preset itself as a first choice, but also in normal data directory
$string = get_string('presetname'.$shortname, 'data', NULL, $path.'/lang/');

if (substr($string, 0, 1) == '[') {
return $shortname;
} else {
return $string;
}
}

/*
* Returns an array of all the available presets
*/
function data_get_available_presets($context) {
global $CFG, $USER;

$presets = array();

if ($dirs = get_list_of_plugins('mod/data/preset')) {
foreach ($dirs as $dir) {
$fulldir = $CFG->dirroot.'/mod/data/preset/'.$dir;

if (is_directory_a_preset($fulldir)) {
$preset = new object;
$preset->path = $fulldir;
$preset->userid = 0;
$preset->shortname = $dir;
$preset->name = data_preset_name($dir, $fulldir);
if (file_exists($fulldir.'/screenshot.jpg')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.jpg';
} else if (file_exists($fulldir.'/screenshot.png')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.png';
} else if (file_exists($fulldir.'/screenshot.gif')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.gif';
}
$presets[] = $preset;
}
}
}

if ($userids = get_list_of_plugins('data/preset', '', $CFG->dataroot)) {
foreach ($userids as $userid) {
$fulldir = $CFG->dataroot.'/data/preset/'.$userid;

if ($userid == 0 || $USER->id == $userid || has_capability('mod/data:viewalluserpresets', $context)) {

if ($dirs = get_list_of_plugins('data/preset/'.$userid, '', $CFG->dataroot)) {
foreach ($dirs as $dir) {
$fulldir = $CFG->dataroot.'/data/preset/'.$userid.'/'.$dir;

if (is_directory_a_preset($fulldir)) {
$preset = new object;
$preset->path = $fulldir;
$preset->userid = $userid;
$preset->shortname = $dir;
$preset->name = data_preset_name($dir, $fulldir);
if (file_exists($fulldir.'/screenshot.jpg')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.jpg';
} else if (file_exists($fulldir.'/screenshot.png')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.png';
} else if (file_exists($fulldir.'/screenshot.gif')) {
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.gif';
}
$presets[] = $preset;
}
}
}
}
}
}

return $presets;
}


function data_print_header($course, $cm, $data, $currenttab='') {

global $CFG, $displaynoticegood, $displaynoticebad;

$strdata = get_string('modulenameplural','data');

print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
'', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
navmenu($course, $cm));

print_heading(format_string($data->name));

/// Print the tabs

if ($currenttab) {
include_once('tabs.php');
}

/// Print any notices

if (!empty($displaynoticegood)) {
notify($displaynoticegood, 'notifysuccess'); // good (usually green)
} else if (!empty($displaynoticebad)) {
notify($displaynoticebad); // bad (usuually red)
}
}

?>
?>
Loading

0 comments on commit 8303eb8

Please sign in to comment.