diff --git a/db/install.xml b/db/install.xml
index fdaa1df..c7f23d7 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -61,6 +61,7 @@
+
diff --git a/edit_form.php b/edit_form.php
index b087866..e20c5ae 100644
--- a/edit_form.php
+++ b/edit_form.php
@@ -252,6 +252,13 @@ class mod_customcert_edit_form extends moodleform {
// Add element header.
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
get_string('pluginname', 'customcertelement_' . $element->element));
+ // We do not need to expand these elements if the modified time is greater than the created time as it
+ // means the values have already been altered by the user - ie. the element has not just been created.
+ if ($element->timemodified > $element->timecreated) {
+ $mform->setExpanded('headerelement_' . $element->id, false);
+ } else {
+ $mform->setExpanded('headerelement_' . $element->id, true);
+ }
// Only display the move up arrow if it is not the first.
if ($element->sequence > 1) {
$url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $this->_customdata['cmid'], 'emoveup' => $element->id));
diff --git a/elements/element.class.php b/elements/element.class.php
index f537b9b..e1e290f 100644
--- a/elements/element.class.php
+++ b/elements/element.class.php
@@ -54,6 +54,9 @@ class customcert_element_base {
public static function add_element($element, $pageid) {
global $DB;
+ // Set the time as a variable.
+ $time = time();
+
$data = new stdClass();
$data->pageid = $pageid;
$data->element = $element;
@@ -63,7 +66,8 @@ class customcert_element_base {
$data->posx = '250';
$data->posy = '250';
$data->sequence = customcert_element_base::get_element_sequence($pageid);
- $data->timecreated = time();
+ $data->timecreated = $time;
+ $data->timemodified = $time;
$DB->insert_record('customcert_elements', $data);
}
@@ -119,11 +123,6 @@ class customcert_element_base {
$mform->setType('posx_' . $id, PARAM_INT);
$mform->setType('posy_' . $id, PARAM_INT);
- // Add some rules.
- $mform->addRule('colour_' . $id, $strrequired, 'required', null, 'client');
- $mform->addRule('posx_' . $id, $strrequired, 'required', null, 'client');
- $mform->addRule('posy_' . $id, $strrequired, 'required', null, 'client');
-
// Set the values of these elements.
$mform->setDefault('font_' . $id, $this->element->font);
$mform->setDefault('size_' . $id, $this->element->size);
@@ -164,7 +163,7 @@ class customcert_element_base {
$posx = 'posx_' . $id;
$posxdata = $data[$posx];
// Check if posx is not numeric or less than 0.
- if ((!is_numeric($posxdata)) || ($posxdata < 0)) {
+ if (empty($posxdata) || (!is_numeric($posxdata)) || ($posxdata < 0)) {
$errors[$posx] = get_string('invalidposition', 'customcert', 'X');
}
@@ -172,7 +171,7 @@ class customcert_element_base {
$posy = 'posy_' . $id;
$posydata = $data[$posy];
// Check if posy is not numeric or less than 0.
- if ((!is_numeric($posydata)) || ($posydata < 0)) {
+ if (empty($posydata) || (!is_numeric($posydata)) || ($posydata < 0)) {
$errors[$posy] = get_string('invalidposition', 'customcert', 'Y');
}
@@ -208,6 +207,7 @@ class customcert_element_base {
$element->colour = (!empty($data->$colour)) ? $data->$colour : null;
$element->posx = (!empty($data->$posx)) ? $data->$posx : null;
$element->posy = (!empty($data->$posy)) ? $data->$posy : null;
+ $element->timemodified = time();
// Ok, now update record in the database.
$DB->update_record('customcert_elements', $element);