10 // Load Elgg framework
11 @require_once
("../../includes.php");
13 // We need to be logged on for this!
18 define("context","widget");
20 // Load global variables
21 global $CFG, $PAGE, $db, $page_owner, $messages;
23 // Load external variables
24 $action = trim(optional_param('_widget_action'));
26 $ident = optional_param('wid',0,PARAM_INT
);
27 $widget = get_record("widgets", "ident", $ident);
28 // Page owner = where the widget resides
29 $page_owner = $widget->owner
;
33 $title = __gettext("Edit widget");
34 templates_page_setup();
36 // If action is specified
38 if (!empty($action) && ($action == "widget:save" ||
$action == "widget:save:ajax")) {
40 // Get the username of the widget owner
42 $username = user_info("username",$widget->owner
);
45 $widget_data = optional_param('widget_data');
47 if (!empty($widget_data)) {
49 widget_remove_data($widget->ident
);
51 if (is_array($widget_data)) {
52 foreach($widget_data as $key => $value) {
53 widget_set_data($key, $widget->ident
, $value);
59 $widget->access
= optional_param('_widget_access',"user".$_SESSION['userid']);
60 update_record('widgets',$widget);
62 if ($action == "widget:save") {
65 $messages[] = __gettext("Widget edited.");
66 $_SESSION['messages'] = $messages;
68 // Redirect back to the relevant location
69 switch( $widget->location
) {
72 $redirect_url = $CFG->wwwroot
. $username . "/profile/";
75 // get module from the widget type
77 $mod_pos = strpos($widget->type
,"::");
79 $module = substr($widget->type
,0,$mod_pos);
81 $redirect_url = widget_get_display_url($module).'?'.widget_get_display_query();
85 header("Location: " . $redirect_url);
90 $result = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
91 $result .= '<answer>';
92 $result .= '<result>'.$widget->ident
.'</result>';
93 $result .= '</answer>';
94 header('Content-Type: application/xml');
101 // Do we have permission to touch this?
102 // If so, display edit screen
103 if (run("permissions:check","profile")) {
105 $body = widget_edit($widget);
109 $body = "<p>" . __gettext("You do not have permission to edit this widget.") . "</p>";
114 // Output to the screen
115 $body = templates_draw(array(
116 'context' => 'contentholder',
122 echo templates_page_draw( array(