function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     // Get customdata
     $action = $this->_customdata['action'];
     $courseid = $this->_customdata['course'];
     $folderid = $this->_customdata['id'];
     /// Print the required moodle fields first
     $mform->addElement('header', 'moodle', get_string('folder', 'block_email_list'));
     $mform->addElement('text', 'name', get_string('namenewfolder', 'block_email_list'));
     $mform->setDefault('name', '');
     $mform->addRule('name', get_string('nofolder', 'block_email_list'), 'required', null, 'client');
     // Get root folders
     $folders = email_get_my_folders($USER->id, $courseid, 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) {
         $menu[$key] = $foldername;
     }
     if ($parent = email_get_parent_folder($folderid)) {
         $parentid = $parent->id;
     } else {
         $parentid = 0;
     }
     // Select parent folder
     $mform->addElement('select', 'parentfolder', get_string('linkto', 'block_email_list'), $menu);
     $mform->setDefault('parentfolder', $parentid);
     $mform->addElement('hidden', 'gost');
     if ($preference = get_record('email_preference', 'userid', $USER->id)) {
         if ($preference->marriedfolders2courses) {
             // Get my courses
             $mycourses = get_my_courses($USER->id);
             $courses = array();
             // Prepare array
             foreach ($mycourses as $mycourse) {
                 strlen($mycourse->fullname) > 60 ? $course = substr($mycourse->fullname, 0, 60) . ' ...' : ($course = $mycourse->fullname);
                 $courses[$mycourse->id] = $course;
             }
             $mform->addElement('select', 'foldercourse', get_string('course'), $courses);
             $mform->setDefault('foldercourse', $courseid);
         }
     }
     /// Add some extra hidden fields
     $mform->addElement('hidden', 'course', $courseid);
     $mform->addElement('hidden', 'oldname');
     $mform->addElement('hidden', 'id');
     $mform->addElement('hidden', 'action', $action);
     // buttons
     $this->add_action_buttons();
 }
/**
 * This function return success/fail if folder corresponding with this type.
 *
 * @param object $folder Folder Object
 * @param string $type Type folder
 * @return boolean Success/Fail
 * @todo Finish documenting this function
 **/
function email_isfolder_type($folder, $type)
{
    if (isset($folder->isparenttype) && $folder->isparenttype) {
        return $type == $folder->isparenttype;
    } else {
        // Get first parent
        $parentfolder = email_get_parent_folder($folder);
        if (!isset($parentfolder->isparenttype)) {
            return false;
        }
        // Return value
        return $parentfolder->isparenttype == $type;
    }
}
Ejemplo n.º 3
0
                    $updatefolder->name = $form->name;
                    $updatefolder->parentfolder = $form->parentfolder;
                    $updatefolder->course = $form->course;
                    // If exist folderid (sending in form), set field
                    if (!email_update_folder($updatefolder)) {
                        print_error('failupdatefolder', 'block_email_list');
                    }
                    // Apply this information
                    $stralert = get_string('modifyfolderok', 'block_email_list');
                }
                redirect($CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $courseid, $stralert, '3');
            } else {
                // Set data
                if (isset($folder)) {
                    $folder->oldname = $folder->name;
                    $parentfolder = email_get_parent_folder($folder);
                    $folder->parentfolder = $parentfolder->id;
                    $folder->folderid = $folder->id;
                    // FIX BUG: When update an folder, on this id has been put $COURSE->id
                    $folder->id = $COURSE->id;
                    $mform->set_data($folder);
                }
                $mform->display();
            }
        }
}
// Close principal column
echo '</td>';
// Close table
echo '</tr>
			</table>';