/**
 * This function prints select folders combobox, for move any mails
 *
 * @uses $USER
 * @param object $options
 */
function email_print_movefolder_button($options)
{
    global $CFG, $USER;
    $courseid = NULL;
    if ($options->id == SITEID and $options->course != SITEID) {
        $courseid = $options->course;
    } else {
        $courseid = $options->id;
    }
    /// TODO: Changed this function, now cases are had:
    //						1.- Inbox folder: Only can move to subfolders inbox and trash folder.
    //						2.- Sendbox and draft folder: Only can move on this subfolders.
    //						3.- Trash folder: Can move any folder
    if (isset($options->folderid)) {
        // Get folder
        $folderbe = email_get_folder($options->folderid);
    } else {
        if (isset($options->folderoldid)) {
            // Get folder
            $folderbe = email_get_folder($options->folderoldid);
        } else {
            // Inbox folder
            $folderbe = email_get_root_folder($USER->id, EMAIL_INBOX);
        }
    }
    if (email_isfolder_type($folderbe, EMAIL_SENDBOX)) {
        // Get my sendbox folders
        $folders = email_get_my_folders($USER->id, $courseid, false, true, false, true);
    } else {
        if (email_isfolder_type($folderbe, EMAIL_DRAFT)) {
            // Get my sendbox folders
            $folders = email_get_my_folders($USER->id, $courseid, false, true, true, true);
        } else {
            if (email_isfolder_type($folderbe, EMAIL_TRASH)) {
                // Get my folders
                $folders = email_get_my_folders($USER->id, $courseid, false, false, false, false);
            } else {
                // Get my folders
                $folders = email_get_my_folders($USER->id, $courseid, false, true, true, false);
            }
        }
    }
    if ($folders) {
        $choose = '';
        // Get my courses
        foreach ($folders as $key => $foldername) {
            $choose .= '<option value="' . $key . '">' . $foldername . '</option>';
        }
    }
    echo '<select name="folderid" onchange="addAction(this)">
					<option value="" selected="selected">' . get_string('movetofolder', 'block_email_list') . ':</option>' . $choose . '
    		</select>';
    // Add 2 space
    echo '&#160;&#160;';
    // Change, now folderoldid is actual folderid
    if (!$options->folderid) {
        if ($inbox = email_get_root_folder($USER->id, EMAIL_INBOX)) {
            echo '<input type="hidden" name="folderoldid" value="' . $inbox->id . '" />';
        }
    } else {
        echo '<input type="hidden" name="folderoldid" value="' . $options->folderid . '" />';
    }
    // Define action
    //echo '<input type="hidden" name="action" value="move2folder" />';
    // Add javascript for insert person/s who I've send mail
    $javascript = '<script type="text/javascript" language="JavaScript">
                <!--
                		function addAction(form) {

                			var d = document.createElement("div");
                        d.setAttribute("id", "action");
                        var act = document.createElement("input");
                        act.setAttribute("type", "hidden");
                        act.setAttribute("name", "action");
                        act.setAttribute("id", "action");
                        act.setAttribute("value", "move2folder");
                        d.appendChild(act);
                        document.getElementById("move2folder").appendChild(d);

                			document.sendmail.submit();
                		}
                	-->
                 </script>';
    echo $javascript;
    // Print sent button
    //echo '<input type="submit" value="' .get_string('move'). '" onclick="javascript:addAction(this);" />';
    //echo '</div>';
}
 function definition_after_data()
 {
     global $USER;
     // Drop actualfolder if it proceding...
     $mform =& $this->_form;
     // Get parentfolder
     $parentfolder =& $mform->getElementValue('parentfolder');
     // Get (actual) folderid
     $folderid =& $mform->getElementValue('id');
     // Drop element.
     $mform->removeElement('parentfolder');
     // Get root folders
     $folders = email_get_my_folders($USER->id, $mform->getElementValue('course'), true, true);
     // Get inbox, there default option on menu
     $inbox = email_get_root_folder($USER->id, EMAIL_INBOX);
     $menu = array();
     // Insert into menu, only name folder
     foreach ($folders as $key => $foldername) {
         if ($key != $folderid) {
             $menu[$key] = $foldername;
         }
     }
     // Select parent folder
     $select =& MoodleQuickForm::createElement('select', 'parentfolder', get_string('linkto', 'block_email_list'), $menu);
     $mform->insertElementBefore($select, 'gost');
     $mform->setDefault('parentfolder', $parentfolder);
 }