Example #1
0
    function toHtml()
    {
        global $CFG, $COURSE, $USER;
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }
        $currentfile = '';
        $draftvalue = '';
        if ($draftid = (int) $this->getValue()) {
            $fs = get_file_storage();
            $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
            if ($files = $fs->get_area_files($usercontext->id, 'user_draft', $draftid, 'id DESC', false)) {
                $file = reset($files);
                $currentfile = $file->get_filename();
                $draftvalue = 'value="' . $draftid . '"';
            }
        }
        $strsaved = get_string('filesaved', 'repository');
        if ($COURSE->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
        }
        $client_id = uniqid();
        $repository_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        $str = $this->_getTabs();
        $str .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" ' . $draftvalue . ' />';
        $str .= <<<EOD
<script type="text/javascript">
function updatefile(client_id, obj) {
    document.getElementById('repo_info_'+client_id).innerHTML = obj['file'];
}
function callpicker(client_id, id) {
    document.body.className += ' yui-skin-sam';
    var picker = document.createElement('DIV');
    picker.id = 'file-picker-'+client_id;
    picker.className = 'file-picker';
    document.body.appendChild(picker);
    var el=document.getElementById(id);
    open_filepicker({'env':'filepicker', 'target':el, 'callback':updatefile})
}
</script>
EOD;
        $str .= '<input value="' . get_string('openpicker', 'repository') . '" type="button" onclick="callpicker(\'' . $client_id . '\', \'' . $id . '\')" />' . '<span id="repo_info_' . $client_id . '" class="notifysuccess">' . $currentfile . '</span>' . $repository_info['css'] . $repository_info['js'];
        return $str;
    }
Example #2
0
    function toHtml()
    {
        global $CFG, $COURSE, $USER, $PAGE;
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }
        $strsaved = get_string('filesaved', 'repository');
        $straddfile = get_string('openpicker', 'repository');
        $currentfile = '';
        $draftvalue = '';
        if ($draftitemid = (int) $this->getValue()) {
            $fs = get_file_storage();
            $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
            if ($files = $fs->get_area_files($usercontext->id, 'user_draft', $draftitemid, 'id DESC', false)) {
                $file = reset($files);
                $currentfile = $file->get_filename();
                $draftvalue = 'value="' . $draftitemid . '"';
            }
        }
        if ($COURSE->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
        }
        $client_id = uniqid();
        $repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
        $PAGE->requires->data_for_js('filepicker', array('maxbytes' => $this->_options['maxbytes'], 'maxfiles' => 1));
        $PAGE->requires->js('lib/form/filepicker.js');
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        $str = $this->_getTabs();
        $str .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" ' . $draftvalue . ' />';
        $str .= $repojs;
        $str .= <<<EOD
<a href="#nonjsfp" onclick="return launch_filepicker('{$id}', '{$client_id}', '{$draftitemid}')">{$straddfile}</a>
<span id="file_info_{$client_id}" class="notifysuccess">{$currentfile}</span>

<noscript>
<a name="nonjsfp"></a>
<object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&itemid={$draftitemid}&ctx_id={$context->id}" height="300" width="800" style="border:1px solid #000">Error</object>
</noscript>
EOD;
        return $str;
    }
Example #3
0
/**
 * Prints a basic textarea field.
 *
 * When using this function, you should
 *
 * @uses $CFG
 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
 * @param int $rows Number of rows to display  (minimum of 10 when $height is non-null)
 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
 * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
 * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
 * @param string $name Name to use for the textarea element.
 * @param string $value Initial content to display in the textarea.
 * @param int $obsolete deprecated
 * @param bool $return If false, will output string. If true, will return string value.
 * @param string $id CSS ID to add to the textarea element.
 * @param string $editorclass CSS classes to add to the textarea element when using the htmleditor. Use 'form-textarea-simple' to get a basic editor. Defaults to 'form-textarea-advanced' (complete editor). If this is null or invalid, the htmleditor will not show for this field.
 */
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value = '', $obsolete = 0, $return = false, $id = '', $editorclass = 'form-textarea-advanced')
{
    /// $width and height are legacy fields and no longer used as pixels like they used to be.
    /// However, you can set them to zero to override the mincols and minrows values below.
    global $CFG, $COURSE, $HTTPSPAGEREQUIRED, $THEME;
    $mincols = 65;
    $minrows = 10;
    $str = '';
    if ($id === '') {
        $id = 'edit-' . $name;
    }
    if (empty($CFG->editorsrc) && $usehtmleditor) {
        // for backward compatibility.
        if ($height && $rows < $minrows) {
            $rows = $minrows;
        }
        if ($width && $cols < $mincols) {
            $cols = $mincols;
        }
    }
    if ($usehtmleditor) {
        $THEME->htmleditors[] = $id;
    } else {
        $editorclass = '';
    }
    $str .= "\n" . '<textarea class="form-textarea ' . $editorclass . '" id="' . $id . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . "\n";
    if ($usehtmleditor) {
        $str .= htmlspecialchars($value);
        // needed for editing of cleaned text!
    } else {
        $str .= s($value);
    }
    $str .= '</textarea>' . "\n";
    if ($usehtmleditor) {
        require_once "{$CFG->dirroot}/repository/lib.php";
        $str_toggle = '<span class="helplink"><a href="javascript:mce_toggleEditor(\'' . $id . '\');"><img width="50" height="17" src="' . $CFG->httpswwwroot . '/lib/editor/tinymce/images/toggle.gif" alt="' . get_string('editortoggle') . '" title="' . get_string('editortoggle') . '" class="icontoggle" /></a></span>';
        // Show shortcuts button if HTML editor is in use, but only if JavaScript is enabled (MDL-9556)
        if (empty($COURSE->context)) {
            $ctx = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $ctx = $COURSE->context;
        }
        $client_id = uniqid();
        $ret = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
        $str .= $ret['css'] . $ret['js'];
        $str .= '<div class="textareaicons">';
        $str .= '<script type="text/javascript">
//<![CDATA[
id2clientid[\'' . $id . '\']=\'' . $client_id . '\';
mce_saveOnSubmit(\'' . addslashes_js($id) . '\');
document.write(\'' . addslashes_js($str_toggle) . '\');
document.write(\'' . addslashes_js(editorshortcutshelpbutton()) . '\');
//]]>
</script>';
        $str .= '</div>';
    }
    if ($return) {
        return $str;
    }
    echo $str;
}
Example #4
0
    function toHtml()
    {
        global $CFG, $COURSE;
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        $subdirs = $this->_options['subdirs'];
        $maxbytes = $this->_options['maxbytes'];
        $maxfiles = $this->_options['maxfiles'];
        $changeformat = $this->_options['changeformat'];
        // TO DO: implement as ajax calls
        $text = $this->_values['text'];
        $format = $this->_values['format'];
        $draftitemid = $this->_values['itemid'];
        // security - never ever allow guest/not logged in user to upload anything
        if (isguestuser() or !isloggedin()) {
            $maxfiles = 0;
        }
        $str = $this->_getTabs();
        $str .= '<div>';
        /// format option - TODO: ajax conversion and switching
        $formats = array(FORMAT_MOODLE => 'Moodle', FORMAT_HTML => 'HTML', FORMAT_PLAIN => 'Plaintext', FORMAT_WIKI => 'Wiki');
        // TODO: localise & switch to new formats plugins
        if (!isset($formats[$format])) {
            $format = FORMAT_HTML;
            // TODO: some user pref
        }
        /// print text area - TODO: add on-the-fly switching to tinymce, size configuration
        $editorclass = 'form-textarea';
        if ($format == FORMAT_HTML or $format == FORMAT_MOODLE) {
            $editorclass = 'form-textarea-advanced';
        }
        $str .= '<div><textarea class="' . $editorclass . '" id="' . $id . '" name="' . $elname . '[text]" rows="15" cols="80">';
        $str .= s($text);
        $str .= '</textarea></div>';
        $str .= '<div>';
        if ($changeformat) {
            $str .= '<select name="' . $elname . '[format]">';
            foreach ($formats as $key => $desc) {
                $selected = $format == $key ? 'selected="selected"' : '';
                $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
            }
            $str .= '</select>';
        } else {
            // no changes of format allowed
            $str .= '<input type="hidden" name="' . $elname . '[format]" value="' . $format . '" />';
            $str .= $formats[$format];
        }
        $str .= '</div>';
        if ($maxfiles != 0) {
            // 0 means no files, -1 unlimited
            if (empty($draftitemid)) {
                // no existing area info provided - let's use fresh new draft area
                require_once "{$CFG->libdir}/filelib.php";
                $this->setValue(array('itemid' => file_get_unused_draft_itemid()));
                $draftitemid = $this->_values['itemid'];
            }
            $str .= '<div><input type="hidden" name="' . $elname . '[itemid]" value="' . $draftitemid . '" /></div>';
            /// embedded image files - TODO: hide on the fly when switching editors
            $str .= '<div id="' . $id . '_filemanager">';
            $editorurl = "{$CFG->wwwroot}/files/draftfiles.php?itemid={$draftitemid}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}";
            $str .= '<object type="text/html" data="' . $editorurl . '" height="160" width="600" style="border:1px solid #000">Error</object>';
            // TODO: localise, fix styles, etc.
            $str .= '</div>';
            require_once $CFG->dirroot . '/repository/lib.php';
            if (empty($COURSE->context)) {
                $ctx = get_context_instance(CONTEXT_SYSTEM);
            } else {
                $ctx = $COURSE->context;
            }
            $client_id = uniqid();
            $ret = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
            $str .= $ret['css'] . $ret['js'];
            $str .= <<<EOD
<script type="text/javascript">
id2clientid['{$id}'] = '{$client_id}';
id2itemid['{$id}']   = '{$draftitemid}';
</script>
EOD;
            /// TODO: hide embedded file manager if tinymce used
            if ($editorclass === 'form-textarea-advanced') {
                $str .= <<<EOD
<script type="text/javascript">
//<![CDATA[
var fileman = document.getElementById("{$id}_filemanager");
fileman.style.visibility = "hidden";
fileman.style.height = "0";
//]]>
</script>
EOD;
            }
        }
        $str .= '</div>';
        return $str;
    }
    function toHtml()
    {
        global $CFG, $USER, $COURSE;
        require_once "{$CFG->dirroot}/repository/lib.php";
        $strdelete = get_string('confirmdeletefile', 'repository');
        $straddfile = get_string('add', 'repository');
        // security - never ever allow guest/not logged in user to upload anything or use this element!
        if (isguestuser() or !isloggedin()) {
            print_error('noguest');
        }
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        $subdirs = $this->_options['subdirs'];
        $maxbytes = $this->_options['maxbytes'];
        $draftitemid = $this->getValue();
        if (empty($draftitemid)) {
            // no existing area info provided - let's use fresh new draft area
            require_once "{$CFG->libdir}/filelib.php";
            $this->setValue(file_get_unused_draft_itemid());
            $draftitemid = $this->getValue();
        }
        if ($COURSE->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
        }
        $client_id = uniqid();
        $repo_info = repository_get_client($context, $client_id, $this->filetypes, $this->returnvalue);
        $html = $this->_get_draftfiles($draftitemid, $client_id);
        $str = $this->_getTabs();
        $str .= $html;
        $str .= $repo_info['css'];
        $str .= $repo_info['js'];
        if (empty($CFG->filemanagerjsloaded)) {
            $str .= <<<EOD
<script type="text/javascript">
//<![CDATA[
var elitem = null;
var rm_cb = {
    success: function(o) {
        if(o.responseText && o.responseText == 200){
            elitem.parentNode.removeChild(elitem);
        }
    }
}
function rm(id, name, context) {
    if (confirm('{$strdelete}')) {
        var trans = YAHOO.util.Connect.asyncRequest('POST',
            '{$CFG->httpswwwroot}/repository/ws.php?action=delete&itemid='+id,
                rm_cb,
                'title='+name
                );
        elitem = context.parentNode;
    }
}
function uf(obj) {
    var list = document.getElementById('draftfiles-'+obj.client_id);
    var html = '<li><a href="'+obj['url']+'"><img src="'+obj['icon']+'" class="icon" /> '+obj['file']+'</a> ';
    html += '<a href="###" onclick=\\'rm('+obj['id']+', "'+obj['file']+'", this)\\'><img src="{$CFG->pixpath}/t/delete.gif" class="iconsmall" /></a>';;
    html += '</li>';
    list.innerHTML += html;
}
function callpicker(el_id, client_id, itemid) {
    document.body.className += ' yui-skin-sam';
    var picker = document.createElement('DIV');
    picker.id = 'file-picker-'+client_id;
    picker.className = 'file-picker';
    document.body.appendChild(picker);
    var el=document.getElementById(el_id);
    var obj = {};
    obj.env = 'filemanager';
    obj.itemid = itemid;
    obj.target = el;
    obj.callback = uf;
    var fp = open_filepicker(client_id, obj);
}
//]]>
</script>
EOD;
            $CFG->filemanagerjsloaded = true;
        }
        $str .= <<<EOD
<input value="{$draftitemid}" name="{$this->_attributes['name']}" type="hidden" />
<div>
    <input value="{$straddfile}" onclick="callpicker('{$id}', '{$client_id}', '{$draftitemid}')" type="button" />
</div>
EOD;
        return $str;
    }
Example #6
0
 function toHtml()
 {
     global $CFG, $COURSE, $PAGE;
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     $id = $this->_attributes['id'];
     $elname = $this->_attributes['name'];
     $subdirs = $this->_options['subdirs'];
     $maxbytes = $this->_options['maxbytes'];
     $maxfiles = $this->_options['maxfiles'];
     $changeformat = $this->_options['changeformat'];
     // TO DO: implement as ajax calls
     $text = $this->_values['text'];
     $format = $this->_values['format'];
     $draftitemid = $this->_values['itemid'];
     // security - never ever allow guest/not logged in user to upload anything
     if (isguestuser() or !isloggedin()) {
         $maxfiles = 0;
     }
     $str = $this->_getTabs();
     $str .= '<div>';
     $editor = get_preferred_texteditor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     /// print text area - TODO: add on-the-fly switching, size configuration, etc.
     $editor->use_editor($id, $this->_options);
     $ctx = $this->_options['context'];
     $str .= '<div><textarea id="' . $id . '" name="' . $elname . '[text]" rows="15" cols="80">';
     $str .= s($text);
     $str .= '</textarea></div>';
     $str .= '<div>';
     $str .= '<select name="' . $elname . '[format]">';
     foreach ($formats as $key => $desc) {
         $selected = $format == $key ? 'selected="selected"' : '';
         $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
     }
     $str .= '</select>';
     $str .= '</div>';
     if ($maxfiles != 0) {
         // 0 means no files, -1 unlimited
         if (empty($draftitemid)) {
             // no existing area info provided - let's use fresh new draft area
             require_once "{$CFG->libdir}/filelib.php";
             $this->setValue(array('itemid' => file_get_unused_draft_itemid()));
             $draftitemid = $this->_values['itemid'];
         }
         $str .= '<div><input type="hidden" name="' . $elname . '[itemid]" value="' . $draftitemid . '" /></div>';
         /// embedded image files - TODO: hide on the fly when switching editors
         $str .= '<div id="' . $id . '_filemanager">';
         $editorurl = "{$CFG->wwwroot}/repository/filepicker.php?action=embedded&amp;itemid={$draftitemid}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}&amp;ctx_id=" . $ctx->id;
         $str .= '<object type="text/html" data="' . $editorurl . '" height="160" width="600" style="border:1px solid #000">Error</object>';
         // TODO: localise, fix styles, etc.
         $str .= '</div>';
         require_once $CFG->dirroot . '/repository/lib.php';
         $client_id = uniqid();
         $repojs = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
         $str .= $repojs;
         $str .= $PAGE->requires->js_function_call('id2_add_clientid', array($id, $client_id))->asap();
         $str .= $PAGE->requires->js_function_call('id2_add_itemid', array($id, $draftitemid))->asap();
         if ($editor->supports_repositories()) {
             $str .= $PAGE->requires->js_function_call('hide_item', array("{$id}_filemanager"))->asap();
         }
     }
     $str .= '</div>';
     return $str;
 }
Example #7
0
    function toHtml()
    {
        global $CFG, $USER, $COURSE, $PAGE, $OUTPUT;
        require_once "{$CFG->dirroot}/repository/lib.php";
        $strdelete = get_string('confirmdeletefile', 'repository');
        $straddfile = get_string('add', 'repository');
        // security - never ever allow guest/not logged in user to upload anything or use this element!
        if (isguestuser() or !isloggedin()) {
            print_error('noguest');
        }
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        $subdirs = $this->_options['subdirs'];
        $maxbytes = $this->_options['maxbytes'];
        $draftitemid = $this->getValue();
        if (empty($draftitemid)) {
            // no existing area info provided - let's use fresh new draft area
            require_once "{$CFG->libdir}/filelib.php";
            $this->setValue(file_get_unused_draft_itemid());
            $draftitemid = $this->getValue();
        }
        if ($COURSE->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
        }
        $client_id = uniqid();
        $repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
        $html = $this->_get_draftfiles($draftitemid, $client_id);
        $accessiblefp = get_string('accessiblefilepicker', 'repository');
        $str = $this->_getTabs();
        $str .= $html;
        $str .= $repojs;
        $str .= <<<EOD
<input value="{$draftitemid}" name="{$this->_attributes['name']}" type="hidden" />
<a href="###" id="btnadd-{$client_id}" class="btnaddfile" onclick="return callpicker('{$id}', '{$client_id}', '{$draftitemid}')">{$straddfile}</a>
EOD;
        $PAGE->requires->yui_lib('dom');
        $PAGE->requires->string_for_js('nomorefiles', 'repository');
        $PAGE->requires->js_function_call('YAHOO.util.Dom.setStyle', array("btnadd-{$client_id}", 'display', 'inline'));
        if (empty($CFG->filemanagerjsloaded)) {
            $jsvars = array('clientid' => $client_id, 'strdelete' => $strdelete, 'maxbytes' => $this->_options['maxbytes'], 'maxfiles' => $this->_options['maxfiles'], 'deleteicon' => $OUTPUT->old_icon_url('t/delete'));
            $str .= $PAGE->requires->data_for_js('filemanager', $jsvars)->asap();
            $str .= $PAGE->requires->js('lib/form/filemanager.js')->asap();
            $CFG->filemanagerjsloaded = true;
        }
        return $str;
    }