throw new SharingCart_RepositoryException('Repository URL was missing'); } if (empty($config[$repo_id]->instance)) { throw new SharingCart_RepositoryException('Repository course ID was missing'); } if (empty($config[$repo_id]->username)) { throw new SharingCart_RepositoryException('Repository username was missing'); } $zip_path = make_user_directory($USER->id, true) . '/' . $sharing_cart->file; $zip_data = file_get_contents($zip_path); $form = new MoodleQuickForm('upload', 'post', $config[$repo_id]->url . '/course/format/repository/material.php'); $form->addElement('hidden', 'mode', 'upload'); $form->addElement('hidden', 'id', $config[$repo_id]->instance); $form->addElement('hidden', 'username', $config[$repo_id]->username); $form->addElement('hidden', 'password', $config[$repo_id]->password); $form->addElement('hidden', 'icon', $sharing_cart->icon); $form->addElement('hidden', 'type', $sharing_cart->name); $form->addElement('hidden', 'title', $sharing_cart->text); $form->addElement('hidden', 'file', base64_encode($zip_data)); $form->addElement('hidden', 'sha1', sha1($zip_data)); $form->addElement('hidden', 'usersite', $CFG->wwwroot); $form->addElement('hidden', 'sitename', $SITE->fullname); $icon = sharing_cart_lib::get_icon($sharing_cart->name, $sharing_cart->icon); $text = '<span class="icon">' . $icon . '</span><span>' . $sharing_cart->text . '</span>'; $form->addElement('static', NULL, '', $text); $form->addElement('static', NULL, '', SharingCart_Repository::getString('confirm_upload')); $form->addElement('submit', 'upload', SharingCart_Repository::getString('upload')); SharingCart_Repository::printForm($form, SharingCart_Repository::getString('upload_to_repository'), $course_id); } catch (Exception $e) { error((string) $e); }
} $sharing_cart = new stdClass(); $sharing_cart->user = $USER->id; $sharing_cart->name = $type; $sharing_cart->icon = $icon; $sharing_cart->text = $text; $sharing_cart->time = time(); $sharing_cart->file = $zip_name; sharing_cart_table::insert_record($sharing_cart); $completes[$id] = TRUE; } } if (empty($type) && empty($icon)) { $img = '<img src="' . $CFG->pixpath . '/f/unknown.gif" alt="" class="icon" />'; } else { $img = sharing_cart_lib::get_icon($type, $icon); } echo ' <tr> <td class="icon">' . $img . '</td><td>' . htmlspecialchars($text) . '</td> <td class="separator"><span class="arrow sep">►</span></td> <td class="download"> <span style="display:none;"> <input type="hidden" name="materials[' . $id . ']" value="' . htmlspecialchars($fields) . '" /> </span>'; if (!empty($completes[$id])) { echo ' <span style="display:none;"> <input type="hidden" name="completes[' . $id . ']" value="true" /> </span> <span>' . $str_complete . '</span>';
function get_content() { global $CFG, $USER, $COURSE, $DB, $PAGE; //error_reporting(E_ALL); if ($this->content !== NULL) { return $this->content; } if (empty($this->instance)) { return $this->content = ''; } if (empty($USER->id)) { return $this->content = ''; } /*$course = $COURSE->id == $this->instance->pageid ? $COURSE : $DB->get_record('course', array('id' => $this->instance->pageid));*/ $course = $COURSE; $context = get_context_instance(CONTEXT_COURSE, $course->id); $editing = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context); if (!$editing) { return $this->content = ''; } // DBから取得したアイテムを表示すべきものだけ抜き出し、木構造化 // また、ここでドロップダウンリスト用にフォルダ名列挙もしておく $tree = array(); $dirs = array(); if ($shared_items = $DB->get_records('sharing_cart', array("userid" => $USER->id))) { foreach ($shared_items as $shared_item) { $node =& self::path_to_node($tree, explode('/', $shared_item->tree)); $node[] = array('id' => $shared_item->id, 'path' => $shared_item->tree, 'icon' => sharing_cart_lib::get_icon($shared_item->name, $shared_item->icon), 'text' => $shared_item->text, 'sort' => $shared_item->sort); $dirs[$shared_item->tree] = $shared_item->tree; } self::sort_tree($tree); unset($dirs['']); usort($dirs, 'strnatcasecmp'); } // ツリーをHTMLにレンダリング $text = "<ul class=\"list\">\n" . self::render_tree($tree) . '</ul>'; require_once dirname(__FILE__) . '/shared/SharingCart_CourseScript.php'; $courseScript = new SharingCart_CourseScript(); $js_import = $courseScript->import($CFG->wwwroot . '/blocks/sharing_cart/sharing_cart.js', true); foreach (sharing_cart_plugins::get_imports() as $import) { $js_import .= $courseScript->import($CFG->wwwroot . '/blocks/sharing_cart/plugins/' . $import, true); } $js_pre = ' <script type="text/javascript"> //<![CDATA[ var sharing_cart = new sharing_cart_handler({ wwwroot : "' . $CFG->wwwroot . '", instance_id : ' . $this->instance->id . ', course_id : ' . $course->id . ', return_url : "' . urlencode($_SERVER['REQUEST_URI']) . '", directories : [ ' . implode(', ', array_map(create_function('$dir', ' return "\\"".addslashes($dir)."\\""; '), $dirs)) . ' ], str : { rootdir : "' . get_string('rootdir', 'block_sharing_cart') . '", notarget : "' . get_string('notarget', 'block_sharing_cart') . '", copyhere : "' . get_string('copyhere', 'block_sharing_cart') . '", movehere : "' . get_string('movehere') . '", edit : "' . get_string('edit') . '", cancel : "' . get_string('cancel') . '", backup : "' . get_string('backup', 'block_sharing_cart') . '", clipboard : "' . addslashes(get_string('clipboard', 'block_sharing_cart')) . '", confirm_backup : "' . addslashes(get_string('confirm_backup', 'block_sharing_cart')) . '", confirm_delete : "' . addslashes(get_string('confirm_delete', 'block_sharing_cart')) . '" } }); ' . implode(' ', sharing_cart_plugins::get_scripts()) . ' //]]> </script> '; $js_post = $courseScript->addLoadEvent('sharing_cart.init();', true); $footer_html = ''; $footers = sharing_cart_plugins::get_footers(); if (!empty($footers)) { foreach ($footers as &$footer) { $footer = '<div style="margin-top:4px; border-top:1px dashed; padding-top:1px;">' . $footer . '</div>'; } $footer_html = implode('', $footers); } $this->content = new stdClass(); $this->content->text = $js_import . $js_pre . $text; $this->content->footer = '<div id="sharing_cart_header">' . self::get_header_icons() . implode('', sharing_cart_plugins::get_headers()) . $footer_html . $js_post; return $this->content; }
<input type="hidden" name="course" value="', $course_id, '" /> </div> <div><label style="cursor:default;"> <input type="checkbox" checked="checked" onclick="check_all(this);" style="height:16px; vertical-align:middle;" /> <span>', get_string('checkall'), '</span> </label></div>'; $i = 0; echo ' <ul style="list-style-type:none; float:left;">'; foreach ($items as $id => $item) { echo ' <li style="clear:left;"> <input type="checkbox" name="delete[' . $id . ']" checked="checked" onclick="check();" style="float:left; height:16px;" id="delete_' . $id . '" /> <div style="float:left;">', sharing_cart_lib::get_icon($item->name, $item->icon), '</div> <div style="float:left;"> <label for="delete_' . $id . '">', htmlspecialchars($item->text), '</label> </div> </li>'; if (++$i % 10 == 0) { echo ' </ul> <ul style="list-style-type:none; float:left;">'; } } echo ' </ul>'; echo ' <div style="clear:both;"><!-- clear floating --></div> <div>