Example #1
0
         $messages[] = __gettext("Widget edited.");
         $_SESSION['messages'] = $messages;
         // Redirect back to the relevant location
         switch ($widget->location) {
             case 'profile':
             case '':
                 $redirect_url = $CFG->wwwroot . $username . "/profile/";
                 break;
             default:
                 // get module from the widget type
                 $module = '';
                 $mod_pos = strpos($widget->type, "::");
                 if ($mod_pos) {
                     $module = substr($widget->type, 0, $mod_pos);
                 }
                 $redirect_url = widget_get_display_url($module) . '?' . widget_get_display_query();
                 break;
         }
         header("Location: " . $redirect_url);
         exit;
     } else {
         $result = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
         $result .= '<answer>';
         $result .= '<result>' . $widget->ident . '</result>';
         $result .= '</answer>';
         header('Content-Type: application/xml');
         print $result;
     }
 } else {
     // Do we have permission to touch this?
     // If so, display edit screen
Example #2
0
function widget_display($widget, $collapsed = 0)
{
    global $CFG;
    global $PAGE;
    $widget_menu_template = '<div class="widget_menu">%s</div>';
    $widget_template = <<<END
<div class="widget_title">%s</div>
%s
<div class="widget_content">
%s
</div>
<div class="widget_bottom">
</div>
END;
    $body = '';
    $title = '';
    // get module from the widget type
    $module = '';
    $mod_pos = strpos($widget->type, "::");
    if ($mod_pos) {
        $module = substr($widget->type, 0, $mod_pos);
    }
    // If the handler for displaying this particular widget type exists,
    // run it - otherwise display nothing
    if ($collapsed) {
        $mod_widget_display = $module . '_widget_display_collapsed';
    } else {
        $mod_widget_display = $module . '_widget_display';
    }
    if ($module && function_exists($mod_widget_display)) {
        $widget_array = $mod_widget_display($widget);
        if (isset($widget_array['content'])) {
            $body = $widget_array['content'];
        } else {
            $body = '';
        }
        if (isset($widget_array['title'])) {
            $title = $widget_array['title'];
        } else {
            $title = '';
        }
        if (isset($widget_array['menu'])) {
            $menu = $widget_array['menu'];
        } else {
            $menu = array();
        }
    } else {
        $result = '';
        $title = '';
        $menu = array();
        if (!empty($CFG->widgets->display[$widget->type])) {
            $body = $CFG->widgets->display[$widget->type]($widget);
        } else {
            $body = "";
        }
    }
    if ($menu) {
        // menu generation goes here
        $menu_html = '<ul>' . "\n";
        foreach ($menu as $menu_item) {
            $menu_html .= '<li><a alt="' . $menu_item['title'] . '" title="' . $menu_item['title'] . '" href="' . $menu_item['link'] . '">' . $menu_item['text'] . '</a></li>' . "\n";
        }
        $menu_html .= '</ul>' . "\n";
    }
    if (!empty($menu_html)) {
        $menu_bit = sprintf($widget_menu_template, $menu_html);
    } else {
        $menu_bit = '';
    }
    $body = sprintf($widget_template, $title, $menu_bit, $body);
    // If we have permission, display edit buttons
    if (isloggedin() && run("permissions:check", "profile")) {
        $q = widget_get_display_query($widget);
        // print("widget_get_display_query: $q");
        $edit_msg = gettext("Edit widget");
        $delete_msg = gettext("Delete widget");
        $moveup_msg = gettext("Move up");
        $movedown_msg = gettext("Move down");
        $moveright_msg = gettext("Move right");
        $moveleft_msg = gettext("Move left");
        $img_template = '<img border="0" width="16" height="16" alt="%s" title="%s" src="' . $CFG->wwwroot . 'mod/widget/images/%s" />';
        $edit_img = sprintf($img_template, $edit_msg, $edit_msg, "16-em-pencil.png");
        $delete_img = sprintf($img_template, $delete_msg, $delete_msg, "16-em-cross.png");
        $moveup_img = sprintf($img_template, $moveup_msg, $moveup_msg, "16-em-open.png");
        $movedown_img = sprintf($img_template, $movedown_msg, $movedown_msg, "16-em-down.png");
        $moveright_img = sprintf($img_template, $moveright_msg, $moveright_msg, "16-em-right.png");
        $moveleft_img = sprintf($img_template, $moveleft_msg, $moveleft_msg, "16-em-left.png");
        $body .= "<div class=\"widget_admin_menu\">";
        $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/edit.php?wid=" . $widget->ident . "&amp;" . $q . "\">" . $edit_img . "</a>  ";
        $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/delete.php?wid=" . $widget->ident . "&amp;" . $q . "\">" . $delete_img . "</a>  ";
        if (empty($CFG->uses_YUI)) {
            $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/move.php?_widget_move=up&amp;wid=" . $widget->ident . "&amp;" . $q . "\">" . $moveup_img . "</a>  ";
            $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/move.php?_widget_move=down&amp;wid=" . $widget->ident . "&amp;" . $q . "\">" . $movedown_img . "</a> ";
            if ($widget->wcolumn == 0) {
                $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/move.php?_widget_move=2&amp;wid=" . $widget->ident . "&amp;" . $q . "\">" . $moveright_img . "</a> ";
            } else {
                $body .= "<a href=\"" . $CFG->wwwroot . "mod/widget/move.php?_widget_move=1&amp;wid=" . $widget->ident . "&amp;" . $q . "\">" . $moveleft_img . "</a> ";
            }
        }
        $body .= "</div>";
    }
    // Return HTML
    return $body;
}