diff --git a/db/install.xml b/db/install.xml index b6f84ee..3e9cc60 100644 --- a/db/install.xml +++ b/db/install.xml @@ -29,7 +29,8 @@ - + + diff --git a/db/upgrade.php b/db/upgrade.php index 94808b8..ea5e161 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -279,14 +279,32 @@ function xmldb_attforblock_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2010123003, 'attforblock'); } - if ($oldversion < 2011053000) { + if ($oldversion < 2011053006) { $table = new xmldb_table('attendance_sessions'); $field = new xmldb_field('description'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified'); $dbman->change_field_type($table, $field); - upgrade_mod_savepoint(true, 2011053000, 'attforblock'); + $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // conditionally migrate to html format in intro + if ($CFG->texteditors !== 'textarea') { + $rs = $DB->get_recordset('attendance_sessions', array('descriptionformat' => FORMAT_MOODLE), '', 'id,description,descriptionformat'); + foreach ($rs as $s) { + $s->description = text_to_html($s->description, false, false, true); + $s->descriptionformat = FORMAT_HTML; + $DB->update_record('attendance_sessions', $s); + upgrade_set_timeout(); + } + $rs->close(); + } + + upgrade_mod_savepoint(true, 2011053006, 'attforblock'); } return $result; } diff --git a/lang/en/attforblock.php b/lang/en/attforblock.php index c184a77..412e938 100644 --- a/lang/en/attforblock.php +++ b/lang/en/attforblock.php @@ -112,7 +112,7 @@ $string['notfound'] = 'Attendance activity not found in this course!'; $string['olddate'] = 'Old date'; $string['period'] = 'Frequency'; $string['pluginname'] = 'Attendance'; -$string['pluginadministration'] = 'Attendance'; +$string['pluginadministration'] = 'Attendance administration'; $string['report'] = 'Report'; $string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!'; $string['resetstatuses'] = 'Reset statuses to default'; diff --git a/lang/ru/attforblock.php b/lang/ru/attforblock.php index 3c633d6..99c7ee8 100644 --- a/lang/ru/attforblock.php +++ b/lang/ru/attforblock.php @@ -97,7 +97,7 @@ $string['notfound'] = 'Элемент курса - \"Посещаемость\" $string['olddate'] = 'Старая дата'; $string['period'] = 'Периодичность'; $string['pluginname'] = 'Посещаемость'; -$string['pluginadministration'] = 'Посещаемость'; +$string['pluginadministration'] = 'Управление модулем «Посещаемость»'; $string['remarks'] = 'Заметка'; $string['report'] = 'Отчет'; $string['restoredefaults'] = 'Востановить значения по-умолчанию'; diff --git a/locallib.php b/locallib.php index d438cb6..18f9f0e 100644 --- a/locallib.php +++ b/locallib.php @@ -534,6 +534,7 @@ class attforblock { $rec->sessdate = $formdata->sessiondate; $rec->duration = $duration; $rec->description = $formdata->sdescription['text']; + $rec->descriptionformat = $formdata->sdescription['format']; $rec->timemodified = time(); if ($formdata->sessiontype == self::SESSION_COMMON) { @@ -555,6 +556,26 @@ class attforblock { // TODO: log //add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); } + + public function update_session_from_form_data($formdata, $sessionid) { + global $DB; + + if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) { + print_error('No such session in this course'); + } + + $sess->sessdate = $formdata->sessiondate; + $sess->duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; + $description = file_save_draft_area_files($formdata->sdescription['itemid'], + $this->context->id, 'mod_attforblock', 'session', $sessionid, + array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']); + $sess->description = $description; + $sess->descriptionformat = $formdata->sdescription['format']; + $sess->timemodified = time(); + $DB->update_record('attendance_sessions', $sess); + // TODO: log + // add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); + } } diff --git a/renderer.php b/renderer.php index b83e186..c408c0d 100644 --- a/renderer.php +++ b/renderer.php @@ -191,11 +191,11 @@ class mod_attforblock_renderer extends plugin_renderer_base { } } if($sessdata->perm->can_manage()) { - $url = $sessdata->url_sessions($sess->id, 'update'); + $url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_UPDATE); $title = get_string('editsession','attforblock'); $actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title)); - $url = $sessdata->url_sessions($sess->id, 'delete'); + $url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_DELETE); $title = get_string('deletesession','attforblock'); $actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title)); } diff --git a/sessions.php b/sessions.php index 3226124..0438937 100644 --- a/sessions.php +++ b/sessions.php @@ -33,6 +33,7 @@ switch ($att->pageparams->action) { case att_sessions_page_params::ACTION_ADD: $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $mform = new mod_attforblock_add_form($url, $formparams); + if ($mform->is_submitted()) { $formdata = $mform->get_data(); if (isset($formdata->addmultiply)) { @@ -40,24 +41,26 @@ switch ($att->pageparams->action) { } else { $att->add_session_from_form_data($formdata); - notice(get_string('sessionadded','attforblock'), $url); + redirect($url, get_string('sessionadded','attforblock'), 3); } } break; case att_sessions_page_params::ACTION_UPDATE: - $sessionid = required_param('sessionid'); + $sessionid = required_param('sessionid', PARAM_INT); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid)); $formparams['sessionid'] = $sessionid; $mform = new mod_attforblock_update_form($url, $formparams); - if ($mform_update->is_cancelled()) { + if ($mform->is_cancelled()) { redirect($att->url_manage()); } if ($mform->is_submitted()) { - + $att->update_session_from_form_data($mform->get_data(), $sessionid); + + redirect($att->url_manage(), get_string('sessionupdated','attforblock'), 3); } break; } diff --git a/update_form.php b/update_form.php index 041953e..88a9410 100644 --- a/update_form.php +++ b/update_form.php @@ -14,12 +14,18 @@ class mod_attforblock_update_form extends moodleform { $modcontext = $this->_customdata['modcontext']; $sessionid = $this->_customdata['sessionid']; - if (!$sess = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) { error('No such session in this course'); } + $dhours = floor($sess->duration / HOURSECS); + $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); + $defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext); + $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attforblock', 'session', $sess->id); + $data = array('sessiondate' => $sess->sessdate, + 'durtime' => array('hours' => $dhours, 'minutes' => $dmins), + 'sdescription' => $sess->description_editor); + $mform->addElement('header', 'general', get_string('changesession','attforblock')); - $mform->setHelpButton('general', array('changesession', get_string('changesession','attforblock'), 'attforblock')); $mform->addElement('static', 'olddate', get_string('olddate','attforblock'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'))); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate','attforblock')); @@ -34,14 +40,10 @@ class mod_attforblock_update_form extends moodleform { $durselect[] =& MoodleQuickForm::createElement('select', 'minutes', '', $minutes, false, true); $mform->addGroup($durselect, 'durtime', get_string('duration','attforblock'), array(' '), true); - $mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); + $mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, $defopts); $mform->setType('sdescription', PARAM_RAW); - $dhours = floor($sess->duration / HOURSECS); - $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); - $mform->setDefaults(array('sessiondate' => $sess->sessdate, - 'durtime' => array('hours'=>$dhours, 'minutes'=>$dmins), - 'sdescription' => $sess->description)); + $mform->setDefaults($data); //------------------------------------------------------------------------------- // buttons diff --git a/version.php b/version.php index 5881398..ca6c978 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2011053000; // The current module version (Date: YYYYMMDDXX) +$module->version = 2011053006; // The current module version (Date: YYYYMMDDXX) $module->release = '2.3.1'; $module->cron = 0; // Period for cron to check this module (secs) ?>