Skip to content

Commit

Permalink
MDL-12861 overriding of database settings now optional when using pre…
Browse files Browse the repository at this point in the history
…sets; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Apr 20, 2008
1 parent 2dc6be3 commit 8528bf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/data.php
Expand Up @@ -180,6 +180,7 @@
$string['optionalfilename'] = 'Filename (optional)';
$string['other'] = 'Other';
$string['overwrite'] = 'Overwrite';
$string['overwritesettings'] = 'Overwrite current settings';
$string['pagesize'] = 'Entries per page';
$string['participants'] = 'Participants';
$string['picture'] = 'Picture';
Expand Down
29 changes: 23 additions & 6 deletions mod/data/lib.php
Expand Up @@ -1994,8 +1994,8 @@ function import_options() {

list($settings, $newfields, $currentfields) = $this->get_settings();

echo '<div style="text-align:center"><form action="preset.php" method="post">';
echo '<fieldset class="invisiblefieldset">';
echo '<div class="presetmapping"><form action="preset.php" method="post">';
echo '<div>';
echo '<input type="hidden" name="action" value="finishimport" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="d" value="'.$this->data->id.'" />';
Expand Down Expand Up @@ -2031,11 +2031,15 @@ function import_options() {
}
echo '</table>';
echo "<p>$strwarning</p>";
}
else if (empty($newfields)) {

} else if (empty($newfields)) {
error("New preset has no defined fields!");
}
echo '<input type="submit" value="'.$strcontinue.'" /></fieldset></form></div>';

echo '<div class="overwritesettings"><label for="overwritesettings">'.get_string('overwritesettings', 'data').'</label>';
echo '<input id="overwritesettings" name="overwritesettings" type="checkbox" /></label></div>';

echo '<input class="button" type="submit" value="'.$strcontinue.'" /></div></form></div>';

}

Expand All @@ -2045,6 +2049,8 @@ function import() {
list($settings, $newfields, $currentfields) = $this->get_settings();
$preservedfields = array();

$overwritesettings = optional_param('overwritesettings', 0, PARAM_BOOL);

/* Maps fields and makes new ones */
if (!empty($newfields)) {
/* We require an injective mapping, and need to know what to protect */
Expand Down Expand Up @@ -2109,9 +2115,20 @@ function import() {
}
}

// do we want to overwrite current database settings?
if ($overwritesettings) {
// all settings
$overwrite = array_keys((array)$settings);
} else {
// only templates
$overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate',
'asearchtemplate');
}

// existing values MUST be sent too - it can not work without them!
foreach ($this->data as $prop=>$unused) {
if (array_key_exists($prop, (array)$settings)) {
if (in_array($prop, $overwrite)) {
$this->data->$prop = $settings->$prop;
}
}
Expand Down
14 changes: 14 additions & 0 deletions mod/data/styles.php
Expand Up @@ -2,6 +2,20 @@
text-align: right;
}

#mod-data-preset .presetmapping {
text-align: center;
}

#mod-data-preset .presetmapping table {
text-align: left;
margin-left: auto;
margin-right: auto;
}

#mod-data-preset .overwritesettings {
margin-bottom: 1em;
}

.mod-data-field .c0 {
text-align: right;
}
Expand Down

0 comments on commit 8528bf2

Please sign in to comment.