# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lang/en/webservice.php
--- moodle/lang/en/webservice.php Base (1.4)
+++ moodle/lang/en/webservice.php Locally Modified (Based On 1.4)
@@ -123,6 +123,7 @@
 $string['required'] = 'Required';
 $string['requiredcapability'] = 'Required capability';
 $string['resettokenconfirm'] = 'Do you really want to reset this web service key for <strong>{$a->user}</strong> on the service <strong>{$a->service}</strong>?';
+$string['resettokenconfirmsimple'] = 'Do you really want to reset this key?';
 $string['response'] = 'Response';
 $string['restcode'] = 'REST';
 $string['restexception'] = 'REST';
Index: moodle/lib/navigationlib.php
--- moodle/lib/navigationlib.php Base (1.115)
+++ moodle/lib/navigationlib.php Locally Modified (Based On 1.115)
@@ -1285,6 +1285,9 @@
             }
         }
 
+        $url = new moodle_url('/message/contacts.php',array());
+        $usernode->add(get_string('messages', 'message'), $url);
+
         // Add a node to view the users notes if permitted
         if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $coursecontext)) {
             $url = new moodle_url('/notes/index.php',array('user'=>$user->id));
@@ -2782,6 +2785,13 @@
             }
         }
 
+        // Messaging
+        // TODO this is adding itself to the messaging settings for other people based on one's own setting
+        if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) {
+            $url = new moodle_url('/message/edit.php', array('id'=>$user->id, 'course'=>$course->id));
+            $usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING);
+        }
+
         // View the roles settings
         if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:manage'), $usercontext)) {
             $roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
@@ -2815,8 +2825,16 @@
             }
         }
 
+        $enablemanagetokens = false;
+        if (!empty($CFG->enablerssfeeds)) {
+            $enablemanagetokens = true;
+        } else if (!is_siteadmin($USER->id)
+             && !empty($CFG->enablewebservices)
+             && has_capability('moodle/webservice:createtoken', get_system_context()) ) {
+            $enablemanagetokens = true;
+        }
         // Security keys
-        if ($currentuser) {
+        if ($currentuser && $enablemanagetokens) {
             $url = new moodle_url('/user/managetoken.php', array('sesskey'=>sesskey()));
             $usersetting->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
         }
@@ -2831,13 +2849,6 @@
             }
         }
 
-        // Messaging
-        // TODO this is adding itself to the messaging settings for other people based on one's own setting
-        if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) {
-            $url = new moodle_url('/message/edit.php', array('id'=>$user->id, 'course'=>$course->id));
-            $usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING);
-        }
-
         // Login as ...
         if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
             $url = new moodle_url('/course/loginas.php', array('id'=>$course->id, 'user'=>$user->id, 'sesskey'=>sesskey()));
Index: moodle/user/managetoken.php
--- moodle/user/managetoken.php Base (1.11)
+++ moodle/user/managetoken.php Locally Modified (Based On 1.11)
@@ -34,10 +34,12 @@
 require_login();
 require_sesskey();
 
-$webservicetokenboxhtml = '';
+$rsstokenboxhtml = $webservicetokenboxhtml = '';
 /// Manage user web service tokens
-if ( !is_siteadmin($USER->id) && !empty($CFG->enablewebservices) &&
-        has_capability('moodle/webservice:createtoken', get_system_context())) {
+if ( !is_siteadmin($USER->id) 
+    && !empty($CFG->enablewebservices)
+    && has_capability('moodle/webservice:createtoken', get_system_context() )
+    ) {
 
     $action  = optional_param('action', '', PARAM_ACTION);
     $tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
@@ -57,28 +59,44 @@
             }      
     }
 
+    //no point creating the table is we're just displaying a confirmation screen
+    if (empty($resetconfirmation)) {
     $webservice->generate_user_ws_tokens($USER->id); //generate all token that need to be generated
     $tokens = $webservice->get_user_ws_tokens($USER->id);
     $webservicetokenboxhtml =  $wsrenderer->user_webservice_tokens_box($tokens, $USER->id); //display the box for web service token
 }
+}
 
-//TODO Manage RSS keys
-//1- the reset confirmation page content should go into $resetconfirmation
-//2- create a table/box for the RSS key
-//PS: in 2 if you prefer to add a special row to the ws table in this case move
-//the renderer somewhere else, add a new column to make difference between web service and RSS, change the name of the
-//renderer function.
+//RSS keys
+if (!empty($CFG->enablerssfeeds)) {
+    require_once($CFG->dirroot.'/lib/rsslib.php');
+    $action  = optional_param('action', '', PARAM_ACTION);
+    $confirm = optional_param('confirm', 0, PARAM_BOOL);
 
+    $wsrenderer = $PAGE->get_renderer('core', 'webservice');
+    $token = rss_get_token($USER->id);
+    if ($action=='resetrsstoken') {
+        /// Display confirmation page to Reset the token
+        if (!$confirm) {
+            $resetconfirmation = $wsrenderer->user_reset_rss_token_confirmation($token);
+        } else {
+            rss_delete_token($USER->id);
+            $token = rss_get_token($USER->id);
+        }
+    }
+    if (empty($resetconfirmation)) {
+        $rsstokenboxhtml = $wsrenderer->user_rss_token_box($token); //display the box for the user's RSS token
+    }
+}
 
 
 // PAGE OUTPUT
 echo $OUTPUT->header();
 if (!empty($resetconfirmation)) {
-    echo $resetconfirmation;  //TODO the RSS regenerate confirmation content code should
-                              //be containt into $resetconfirmation too
+    echo $resetconfirmation;
 } else {
     echo $webservicetokenboxhtml;
-    //TODO: echo RSS table html here
+    echo $rsstokenboxhtml;
 }
 echo $OUTPUT->footer();
 
Index: moodle/webservice/renderer.php
--- moodle/webservice/renderer.php Base (1.19)
+++ moodle/webservice/renderer.php Locally Modified (Based On 1.19)
@@ -47,8 +47,24 @@
         return $html;
     }
 
+    /**
+     *  Display Reset token confirmation box
+     * @param object $token to reset
+     * @return string html
+     */
+    public function user_reset_rss_token_confirmation($token) {
+        global $OUTPUT, $CFG;
+        $managetokenurl = $CFG->wwwroot."/user/managetoken.php?sesskey=" . sesskey();
+        $optionsyes = array('action'=>'resetrsstoken', 'confirm'=>1, 'sesskey'=>sesskey());
+        $optionsno  = array('section'=>'webservicetokens', 'sesskey'=>sesskey());
+        $formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes), get_string('reset'));
+        $formcancel = new single_button(new moodle_url($managetokenurl, $optionsno), get_string('cancel'), 'get');
+        $html = $OUTPUT->confirm(get_string('resettokenconfirmsimple', 'webservice'), $formcontinue, $formcancel);
+        return $html;
+    }
 
 
+
     /**
      * Display user tokens with buttons to reset them
      * @param object $tokens
@@ -88,10 +104,14 @@
                     $creator = $token->firstname." ".$token->lastname;
                 } else {
                     //retrive administrator name
+                    if (!empty($token->creatorid)) {
                     require_once($CFG->dirroot.'/user/lib.php');
                     $creators = user_get_users_by_id(array($token->creatorid));
                     $admincreator = $creators[$token->creatorid];
                     $creator = $admincreator->firstname." ".$admincreator->lastname;
+                    } else {
+                        $creator = '';
+                    }
                     $reset = '';
                 }
 
@@ -117,8 +137,47 @@
         return $return;
     }
 
+    /**
+     * Display user tokens with buttons to reset them
+     * @param object $tokens
+     * @param int $userid
+     * @return string html code
+     */
+    public function user_rss_token_box($token) {
+        global $OUTPUT, $CFG;
 
+        // display strings
+        $stroperation = get_string('operation', 'webservice');
+        $strtoken = get_string('key', 'webservice');
 
+        $return = $OUTPUT->heading(get_string('rss'), 3, 'main', true);
+        $return .= $OUTPUT->box_start('generalbox webservicestokenui');
+
+        //$return .= get_string('keyshelp', 'webservice');
+
+        $table = new html_table();
+        $table->head  = array($strtoken, $stroperation);
+        $table->align = array('left', 'center');
+        $table->width = '100%';
+        $table->data  = array();
+
+        if (!empty($token)) {
+            $reset = "<a href=\"".$CFG->wwwroot."/user/managetoken.php?sesskey=".sesskey().
+                    "&amp;action=resetrsstoken\">".get_string('reset')."</a>";
+
+            $table->data[] = array($token, $reset);
+
+            $return .= html_writer::table($table);
+        } else {
+            $return .= get_string('notoken', 'webservice');
+        }
+
+        $return .= $OUTPUT->box_end();
+        return $return;
+    }
+
+
+
      /**
      * Return documentation for a ws description object
      * ws description object can be 'external_multiple_structure', 'external_single_structure' or 'external_value'
