commit 6df253535d9ecbd5e2a7be0ef010acb47d187f6e
Author: root <root@srv-xen-moodle08.tauntons.ac.uk>
Date:   Mon Jun 22 15:58:31 2009 +0100

    Add redirect javascript and link, plus setting to configure delay before redirect.

diff --git a/blocks/createparent/add.php b/blocks/createparent/add.php
index 9f54e7e..04fd664 100644
--- a/blocks/createparent/add.php
+++ b/blocks/createparent/add.php
@@ -10,6 +10,7 @@
     require_once('../../config.php');
 
     $studentid      = required_param('studentid',PARAM_INT);
+    $ref         = required_param('ref',PARAM_TEXT);
     $email      = optional_param('email','',PARAM_TEXT);
 
 
@@ -21,6 +22,7 @@
     $cfg_createparent = get_config('block/createparent');
 
     global $SITE;
+    global $CFG;
 
     print_header($SITE->fullname, $SITE->fullname, '', '',
                 '<meta name="description" content="'. strip_tags(format_text($SITE->summary, FORMAT_HTML)) .'" />',
@@ -36,7 +38,9 @@
             function definition() {
                 $mform    =& $this->_form;
                 global $studentid;
+                global $ref;
                 $mform->addElement('hidden', 'studentid',$studentid);
+                $mform->addElement('hidden', 'ref', $ref);
                 $mform->addElement('text', 'email', get_string('email'));
                 $this->add_action_buttons(false);
 
@@ -96,13 +100,21 @@
 
             echo get_string('sucess','block_createparent');
 
-            //redirect? or popup close?
         }else{
             echo get_string('createuserfail','block_createparent');
         }
+
+        echo '<p>'.get_string('waitforredirect', 'block_createparent').': <a href="'.$CFG->wwwroot.$ref.'">'.get_string('backlink', 'block_createparent').'</a></p>';
+        ?>
+
+    <script src="redirect.js" language="javascript"></script>
+    <script language="javascript">
+        setTimeout("redirect('<?php echo $CFG->wwwroot.$ref; ?>')", <?php echo (isset($cfg_createparent->redirectdelay)?$cfg_createparent->redirectdelay*1000:5000); ?>);
+    </script>
+
+        <?php
     }
 
     print_footer();
 
-
-?>
\ No newline at end of file
+?>
diff --git a/blocks/createparent/block_createparent.php b/blocks/createparent/block_createparent.php
index c4759db..c479d5e 100644
--- a/blocks/createparent/block_createparent.php
+++ b/blocks/createparent/block_createparent.php
@@ -18,6 +18,7 @@ class block_createparent extends block_base {
         $this->content->text='';
         global $CFG;
         global $USER;
+        $ref = $_SERVER['REQUEST_URI'];
         $cfg_createparent = get_config('block/createparent');
         if (!isset($cfg_createparent->sendemail) or ($cfg_createparent->sendemail and (empty($cfg_createparent->emailbody) or empty($cfg_createparent->emailuser)))  or empty($cfg_createparent->parentprefix) or empty($cfg_createparent->parentrole)){
             $this->content->text= get_string('notconfigured','block_createparent');
@@ -33,7 +34,7 @@ class block_createparent extends block_base {
                 foreach($users as $user){
                     $this->content->text .= '<div><h5 style="margin:5px;">'.$user->firstname.' '.$user->lastname;
                     if ( has_capability('block/createparent:addany', $context)or ($USER==$user and has_capability('block/createparent:addown', $context))){
-                        $this->content->text.=' - <a target=_blank href="'.$CFG->wwwroot.'/blocks/createparent/add.php?studentid='.$user->id.'">'.get_string('addparent','block_createparent').'</a>';
+                        $this->content->text.=' - <a href="'.$CFG->wwwroot.'/blocks/createparent/add.php?studentid='.$user->id.'&amp;ref='.$ref.'">'.get_string('addparent','block_createparent').'</a>';
                     }
                     $this->content->text .= '</h5>';
                     $studentcontext = get_context_instance(CONTEXT_USER, $user->id);
@@ -42,7 +43,7 @@ class block_createparent extends block_base {
                             $parent=get_record('user','id',$parentsassignment->userid);
                             $this->content->text.= '<p style="margin-top:0px;margin-bottom:0px;margin-left:10px;">'.$parent->email;
                             if ( has_capability('block/createparent:editany', $context)or ($USER==$user and has_capability('block/createparent:editown', $context))){
-                                $this->content->text.='<br><a target=_blank href="'.$CFG->wwwroot.'/blocks/createparent/del.php?studentid='.$user->id.'&id='.$parent->id.'">'.get_string('delete').'</a>';
+                                $this->content->text.='<br><a href="'.$CFG->wwwroot.'/blocks/createparent/del.php?studentid='.$user->id.'&id='.$parent->id.'&amp;ref='.$ref.'">'.get_string('delete').'</a>';
                             }
                             $this->content->text.='</p>';
                         }
@@ -65,13 +66,13 @@ class block_createparent extends block_base {
                         $parent=get_record('user','id',$parentsassignment->userid);
                         $this->content->text.= '<p>'.$parent->email;
                         if ( has_capability('block/createparent:editown', $context)){
-                            $this->content->text.='<br><a target=_blank href="'.$CFG->wwwroot.'/blocks/createparent/del.php?studentid='.$USER->id.'&id='.$parent->id.'">'.get_string('delete').'</a>';
+                            $this->content->text.='<br><a href="'.$CFG->wwwroot.'/blocks/createparent/del.php?studentid='.$USER->id.'&id='.$parent->id.'&amp;ref='.$ref.'">'.get_string('delete').'</a>';
                         }
                     $this->content->text.='</p>';
                     }
                 }
                 if ( has_capability('block/createparent:addown', $context)){
-                    $this->content->text.='<a target=_blank href="'.$CFG->wwwroot.'/blocks/createparent/add.php?studentid='.$USER->id.'">'.get_string('addparent','block_createparent').'</a>';
+                    $this->content->text.='<a href="'.$CFG->wwwroot.'/blocks/createparent/add.php?studentid='.$USER->id.'&amp;ref='.$ref.'">'.get_string('addparent','block_createparent').'</a>';
                 }
             }
         }
diff --git a/blocks/createparent/del.php b/blocks/createparent/del.php
index b71a6c6..861d7d6 100644
--- a/blocks/createparent/del.php
+++ b/blocks/createparent/del.php
@@ -10,6 +10,7 @@
     require_once('../../config.php');
 
     $studentid      = required_param('studentid',PARAM_INT);
+    $ref         = required_param('ref',PARAM_TEXT);
     $id      = optional_param('id','',PARAM_TEXT);
 
 
@@ -20,6 +21,11 @@
 
     $cfg_createparent = get_config('block/createparent');
 
+    global $SITE;
+    print_header($SITE->fullname, $SITE->fullname, '', '',
+                '<meta name="description" content="'. strip_tags(format_text($SITE->summary, FORMAT_HTML)) .'" />',
+                true, '', user_login_string($SITE));
+
     //check that parent really is a parent of student
     $studentcontext = get_context_instance(CONTEXT_USER, $studentid);
     if (!get_record('role_assignments','userid',$id,'contextid',$studentcontext->id)){
@@ -28,14 +34,17 @@
 
     $parent=get_record('user','id',$id);
     if(delete_user($parent)){
-        global $SITE;
-        print_header($SITE->fullname, $SITE->fullname, '', '',
-                '<meta name="description" content="'. strip_tags(format_text($SITE->summary, FORMAT_HTML)) .'" />',
-                true, '', user_login_string($SITE));
+
         echo get_string('delsucess','block_createparent');
-        print_footer();
     }
 
-    //redirect? or popup close?
+    echo '<p>'.get_string('waitforredirect', 'block_createparent').': <a href="'.$CFG->wwwroot.$ref.'">'.get_string('backlink', 'block_createparent').'</a></p>';
+
+    print_footer();
 
-?>
\ No newline at end of file
+?>
+<script src="redirect.js" language="javascript">
+</script>
+<script language="javascript">
+    setTimeout("redirect('<?php echo $CFG->wwwroot.$ref; ?>')", <?php echo (isset($cfg_createparent->redirectdelay)?$cfg_createparent->redirectdelay*1000:5000); ?>);
+</script>
\ No newline at end of file
diff --git a/blocks/createparent/lang/en_utf8/block_createparent.php b/blocks/createparent/lang/en_utf8/block_createparent.php
index 4e748cf..2f5fc73 100644
--- a/blocks/createparent/lang/en_utf8/block_createparent.php
+++ b/blocks/createparent/lang/en_utf8/block_createparent.php
@@ -16,9 +16,13 @@ $string['parentprefix']         = 'Parent Prefix';
 $string['parentprefix_explain']         = 'This will be prefixed to the usename of all parent accounts to allow easy identification';
 $string['parentrole']         = 'Parent Role';
 $string['parentrole_explain']         = 'What role should the parent accounts be created with (in user context)?';
+$string['redirectdelay']    = 'Redirect Delay';
+$string['redirectdelay_explain']            = 'Seconds to wait before sending user back to the course page after adding/deleting a Parent Account';
 $string['selectrole']        =      'Select a role';
 $string['sendemail']        = 'Send Email';
 $string['sendemail_explain']    = 'Send a notification e-mail to the address entered for the Parent Account? If un-ticked, the following fields will be ignored.';
 $string['sucess']         = 'A parent account has been sucessfully created';
+$string['waitforredirect'] = 'Wait to be redirected or click the following link';
+$string['backlink'] = 'Back';
 
 ?>
\ No newline at end of file
diff --git a/blocks/createparent/redirect.js b/blocks/createparent/redirect.js
new file mode 100644
index 0000000..115b43d
--- /dev/null
+++ b/blocks/createparent/redirect.js
@@ -0,0 +1,3 @@
+function redirect(url) {
+	window.location = url;
+}
\ No newline at end of file
diff --git a/blocks/createparent/settings.php b/blocks/createparent/settings.php
index 1d0608d..9090988 100644
--- a/blocks/createparent/settings.php
+++ b/blocks/createparent/settings.php
@@ -21,6 +21,9 @@ foreach($users as $user){
     $options[$user->id]=$user->firstname.' '.$user->lastname.' ('.$user->username.')';
 }
 
+$settings->add(new admin_setting_configtext('redirectdelay', get_string('redirectdelay', 'block_createparent'),get_string('redirectdelay_explain', 'block_createparent'),'5'));
+$settings->settings->redirectdelay->plugin='block/createparent';
+
 $settings->add(new admin_setting_configcheckbox('sendemail', get_string('sendemail', 'block_createparent'), get_string('sendemail_explain', 'block_createparent'), '1'));
 $settings->settings->sendemail->plugin='block/createparent';
 

