commit d5e465ceeca7ffdb46ced004fb83c2c8ebc3c770
Author: root <root@srv-xen-moodle08.tauntons.ac.uk>
Date:   Mon Jun 22 14:00:17 2009 +0100

    Added setting to toggle whether or not to send notification e-mails for new accounts

diff --git a/blocks/createparent/add.php b/blocks/createparent/add.php
index 62e13d7..9f54e7e 100644
--- a/blocks/createparent/add.php
+++ b/blocks/createparent/add.php
@@ -82,17 +82,18 @@
 
             //TODO: Do we enrol parents onto the students courses here? If so, how will we keep the enrolements up to date? (course:view, although can cause problems if course:enrolled hasn't been separated)
 
-           //send the welcome email
-            $fromuser=get_record('user','id',$cfg_createparent->emailuser);
+            if ($cfg_createparent->sendemail) {
+                //send the welcome email
+                $fromuser=get_record('user','id',$cfg_createparent->emailuser);
 
-            $dynamicstrings=array('[sitename]','[siteurl]','[studentname]','[username]','[password]');
-            $dynamicdata=array($SITE->fullname,$CFG->wwwroot,$student->firstname.' '.$student->lastname,$parentuser->username,$parentpassword);
+                $dynamicstrings=array('[sitename]','[siteurl]','[studentname]','[username]','[password]');
+                $dynamicdata=array($SITE->fullname,$CFG->wwwroot,$student->firstname.' '.$student->lastname,$parentuser->username,$parentpassword);
 
-            $emailbody=str_replace($dynamicstrings,$dynamicdata,$cfg_createparent->emailbody);
-
-            $parentuser=get_record('user','id',$parentuser->id);
+                $parentuser=get_record('user','id',$parentuser->id);
+                $emailbody=str_replace($dynamicstrings,$dynamicdata,$cfg_createparent->emailbody);
+                email_to_user($parentuser,$fromuser,'Welcome to '.$SITE->fullname,$emailbody);
+            }
 
-            email_to_user($parentuser,$fromuser,'Welcome to '.$SITE->fullname,$emailbody);
             echo get_string('sucess','block_createparent');
 
             //redirect? or popup close?
diff --git a/blocks/createparent/block_createparent.php b/blocks/createparent/block_createparent.php
index 0380f24..c4759db 100644
--- a/blocks/createparent/block_createparent.php
+++ b/blocks/createparent/block_createparent.php
@@ -19,7 +19,7 @@ class block_createparent extends block_base {
         global $CFG;
         global $USER;
         $cfg_createparent = get_config('block/createparent');
-        if (empty($cfg_createparent->emailbody) or empty($cfg_createparent->emailuser) or empty($cfg_createparent->parentprefix) or empty($cfg_createparent->parentrole)){
+        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');
         }else{
 
diff --git a/blocks/createparent/lang/en_utf8/block_createparent.php b/blocks/createparent/lang/en_utf8/block_createparent.php
index 5dea9b6..126f87c 100644
--- a/blocks/createparent/lang/en_utf8/block_createparent.php
+++ b/blocks/createparent/lang/en_utf8/block_createparent.php
@@ -12,6 +12,8 @@ $string['emailbody']         = 'Email body text';
 $string['emailbody_explain']         = 'What should the test of the welcome email say? You can use the following dynamic data: [sitename],[siteurl],[studentname],[username],[password]';
 $string['defaultemailbody']  =    'Welcome to [sitename], a parent account has been created for you for the student [studentname]; to access this account go to [siteurl] and login with the username: [username] and the password: [password]';
 $string['addparent']         = 'Add a parent account';
+$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['delsucess']         = 'The parent account has been sucessfully deleted';
 $string['createuserfail']         = 'There was an error creating the parent account';
diff --git a/blocks/createparent/settings.php b/blocks/createparent/settings.php
index fbea3e5..1d0608d 100644
--- a/blocks/createparent/settings.php
+++ b/blocks/createparent/settings.php
@@ -20,10 +20,12 @@ $options = array();
 foreach($users as $user){
     $options[$user->id]=$user->firstname.' '.$user->lastname.' ('.$user->username.')';
 }
-$settings->add(new admin_setting_configselect('emailuser', get_string('emailuser', 'block_createparent'),get_string('emailuser_explain', 'block_createparent'), $USER->id, $options));
-$settings->settings->emailuser->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';
 
+$settings->add(new admin_setting_configselect('emailuser', get_string('emailuser', 'block_createparent'),get_string('emailuser_explain', 'block_createparent'), $USER->id, $options));
+$settings->settings->emailuser->plugin='block/createparent';
 
 $settings->add(new admin_setting_configtextarea('emailbody', get_string('emailbody', 'block_createparent'),get_string('emailbody_explain', 'block_createparent'),get_string('defaultemailbody','block_createparent')));
 $settings->settings->emailbody->plugin='block/createparent';

