Adding audio field to mod_form

Adding audio field to mod_form

by Carlos Santos Sáenz -
Number of replies: 1
Hi,
I'm adding the audio functionality to moodle 1.8, but I have a problem. I added to the New/Edit form for forums this new field called "speex". This is the code I added in mod/forum/mod_form.php: (the red code is the new code)

$options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
$mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
$mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
$options2 = array();
$options2[0] = 'default';
$options2[1] = 'off';
$options2[2] = 'on';
$mform->addElement('select', 'speex', 'Audio', $options2);
$mform->setHelpButton('speex', array('speex', get_string('trackingtype', 'forum'), 'forum'));
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);

So I have three options: "default", "off", "on". Everything seems to work correctly because when I choose "on" it works how it is supposed to work, but the only problem is that when I return to the form to edit something, the selected value for that new field (speex) is always "default". It doesn't save the last value as the "selected" value. How could I do it?

Thanks in advance
Average of ratings: -
In reply to Carlos Santos Sáenz

Re: Adding audio field to mod_form

by Paco Paco -

Good morning:

I’m working with Moodle 1.8, and MoodleSpeex.

I develop a course in this platform and one of the activities inside of the course is to record and upload the track recorded.

My problem is to upload the track.

I use the next code in my course:

echo speex_postlet_applet(

 $CFG->wwwroot . '/mod/newmodule' ,
 $CFG->wwwroot . '/course/view.php?id=2',
600, 200, true, $post->subject, 'attachment'

 );

Really there are two parameters unknown for me, $post->subject, 'attachment', I copy both from a forum but really I don’t know what to use instead of that.

Anyway when I run the webpage the applet is loaded and in aparence all works correctly but in fact when I look for my uploaded file It don’t exist in

$CFG->wwwroot . '/mod/newmodule'


Could you advise me what can I do to upload the file?

Best Regards, Paco.


The code of the function speex_postlet_applet is:


function speex_postlet_applet($destination, $endpage, $width=600, $height=200,$isforumpost=false, $subject='', $filefieldname='userfile', $compressionmode=1, $compressionmodes='1,2,3'){

 global $CFG;

 $cookie = htmlspecialchars($_SERVER['HTTP_COOKIE']);

 $code = <<<ENDHTMLFRAGMENT

<applet name="Speexuploader" width ="400" height ="200" mayscript="mayscript"

 code="moodlespeex/MoodleSpeexRecorderApplet.class" style="border: 1px solid rgb(153,153,153);">

<param name="archive" value="$CFG->wwwroot/lib/speex/moodlespeexrecorder.jar"/>

<param name="type" value="application/x-java-applet;version=1.4"/>

<param name="scriptable" value="true"/>

ENDHTMLFRAGMENT;

if($isforumpost) {

 $code .= '<param name="subject" value="'.htmlspecialchars($subject).'"/>';

}

 $code .= <<<ENDHTMLFRAGMENT

<param name="destination" value="$destination"/>

<param name="filefieldname" value="

ENDHTMLFRAGMENT;

 $code .= htmlspecialchars($filefieldname);

 $code .= <<<ENDHTMLFRAGMENT

"/>

<param name="endpage" value="$endpage"/>

<param name="cookie" value="$cookie"/>

<param name="compressionmode" value="$compressionmode"/>

<param name="compressionmodes" value="$compressionmodes"/>

The Moodle Speex audio recorder applet should appear here. Please check that you have Java enabled in your web browser - this is

required in order to use the audio recorder.

</applet>

ENDHTMLFRAGMENT;

 return $code;

}