2009-11-01 10:42:45 +00:00
< ? php
2007-08-15 05:30:49 +00:00
require_once ( '../../config.php' );
2007-08-07 07:26:58 +00:00
require_once ( $CFG -> libdir . '/adminlib.php' );
2007-11-13 08:43:20 +00:00
require_once ( $CFG -> dirroot . '/message/lib.php' );
require_once ( 'user_message_form.php' );
2007-08-07 07:26:58 +00:00
2010-09-02 18:16:45 +00:00
$msg = optional_param ( 'msg' , '' , PARAM_CLEANHTML );
2007-11-13 08:43:20 +00:00
$confirm = optional_param ( 'confirm' , 0 , PARAM_BOOL );
2007-08-07 07:26:58 +00:00
2009-07-20 08:57:18 +00:00
require_login ();
2007-11-13 08:43:20 +00:00
admin_externalpage_setup ( 'userbulk' );
2012-07-23 14:33:02 +08:00
require_capability ( 'moodle/site:readallmessages' , context_system :: instance ());
2007-09-28 03:07:03 +00:00
2007-11-13 08:43:20 +00:00
$return = $CFG -> wwwroot . '/' . $CFG -> admin . '/user/user_bulk.php' ;
if ( empty ( $SESSION -> bulk_users )) {
redirect ( $return );
}
if ( empty ( $CFG -> messaging )) {
2008-04-11 07:49:07 +00:00
print_error ( 'messagingdisable' , 'error' );
2007-08-07 07:26:58 +00:00
}
2007-11-13 08:43:20 +00:00
//TODO: add support for large number of users
if ( $confirm and ! empty ( $msg ) and confirm_sesskey ()) {
2009-11-17 10:21:29 +00:00
list ( $in , $params ) = $DB -> get_in_or_equal ( $SESSION -> bulk_users );
2010-12-30 00:41:47 +01:00
$rs = $DB -> get_recordset_select ( 'user' , " id $in " , $params );
foreach ( $rs as $user ) {
//TODO we should probably support all text formats here or only FORMAT_MOODLE
//For now bulk messaging is still using the html editor and its supplying html
//so we have to use html format for it to be displayed correctly
2011-01-12 17:15:43 +08:00
message_post_message ( $USER , $user , $msg , FORMAT_HTML );
2007-08-07 07:26:58 +00:00
}
2010-12-30 00:41:47 +01:00
$rs -> close ();
2007-11-13 08:43:20 +00:00
redirect ( $return );
2007-08-07 07:26:58 +00:00
}
2007-11-13 08:43:20 +00:00
$msgform = new user_message_form ( 'user_bulk_message.php' );
if ( $msgform -> is_cancelled ()) {
redirect ( $return );
2008-06-09 16:53:30 +00:00
} else if ( $formdata = $msgform -> get_data ()) {
2010-09-21 08:44:02 +00:00
$options = new stdClass ();
2007-11-13 08:43:20 +00:00
$options -> para = false ;
$options -> newlines = true ;
$options -> smiley = false ;
2010-01-25 09:23:02 +00:00
$msg = format_text ( $formdata -> messagebody [ 'text' ], $formdata -> messagebody [ 'format' ], $options );
2007-11-13 08:43:20 +00:00
2009-11-17 10:21:29 +00:00
list ( $in , $params ) = $DB -> get_in_or_equal ( $SESSION -> bulk_users );
$userlist = $DB -> get_records_select_menu ( 'user' , " id $in " , $params , 'fullname' , 'id,' . $DB -> sql_fullname () . ' AS fullname' );
2007-11-13 08:43:20 +00:00
$usernames = implode ( ', ' , $userlist );
2010-03-31 08:05:53 +00:00
echo $OUTPUT -> header ();
2009-08-06 08:17:12 +00:00
echo $OUTPUT -> heading ( get_string ( 'confirmation' , 'admin' ));
2010-09-02 18:16:45 +00:00
echo $OUTPUT -> box ( $msg , 'boxwidthnarrow boxaligncenter generalbox' , 'preview' ); //TODO: clean once we start using proper text formats here
2009-11-01 10:55:31 +00:00
2010-09-02 18:16:45 +00:00
$formcontinue = new single_button ( new moodle_url ( 'user_bulk_message.php' , array ( 'confirm' => 1 , 'msg' => $msg )), get_string ( 'yes' )); //TODO: clean once we start using proper text formats here
2010-10-13 02:38:23 +00:00
$formcancel = new single_button ( new moodle_url ( 'user_bulk.php' ), get_string ( 'no' ), 'get' );
2009-08-20 08:39:07 +00:00
echo $OUTPUT -> confirm ( get_string ( 'confirmmessage' , 'bulkusers' , $usernames ), $formcontinue , $formcancel );
2009-08-06 14:12:46 +00:00
echo $OUTPUT -> footer ();
2007-11-13 08:43:20 +00:00
die ;
2007-08-07 07:26:58 +00:00
}
2010-03-31 08:05:53 +00:00
echo $OUTPUT -> header ();
2007-11-13 08:43:20 +00:00
$msgform -> display ();
2009-08-06 14:12:46 +00:00
echo $OUTPUT -> footer ();