예제 #1
0
파일: lib.php 프로젝트: anilch/Personel
    /**
     * @method scheduleexam_update_instance
     * @todo Update existing exam.
     * @param  object $scheduledexam Contains all the details to edit an existing exam
     * @return int Updated instance ID
     */
    function scheduleexam_update_instance($tool) {
        global $DB, $USER;
//$DB->update_record('local_scheduledexams', $tool);
        $ures = $DB->update_record('local_scheduledexams', $tool);
        $sql = "SELECT * FROM {local_user_clclasses} WHERE classid={$tool->classid}";
        $users = $DB->get_records_sql($sql);
        foreach ($users as $user) {
            $conf = new object();
            $conf->username = $DB->get_field('user', 'username', array('id' => $user->userid));
            $conf->classname = $DB->get_field('local_clclasses', 'fullname', array('id' => $tool->classid));
            $message = get_string('msg_stu_exam', 'local_scheduleexam', $conf);
            $userfrom = $DB->get_record('user', array('id' => $USER->id));
            $userto = $DB->get_record('user', array('id' => $user->userid));
            $message_post_message = message_post_message($userfrom, $userto, $message, FORMAT_HTML);
        }

        return $ures;
    }
예제 #2
0
파일: index.php 프로젝트: vuchannguyen/web
            // We are not a contact!
            $messageerror = get_string('userisblockingyounoncontact', 'message');
        }
    }
    if (empty($messageerror)) {
        $mform = new send_form();
        $defaultmessage = new stdClass();
        $defaultmessage->id = $user2->id;
        $defaultmessage->message = '';
        //Check if the current user has sent a message
        $data = $mform->get_data();
        if (!empty($data) && !empty($data->message)) {
            if (!confirm_sesskey()) {
                print_error('invalidsesskey');
            }
            $messageid = message_post_message($user1, $user2, $data->message, FORMAT_PLAIN, 'direct');
            if (!empty($messageid)) {
                redirect($CFG->wwwroot . '/message/index.php?usergroup=' . $usergroup . '&id=' . $user2->id);
            }
        }
    }
}
$strmessages = get_string('messages', 'message');
if (!empty($user2)) {
    $user2fullname = fullname($user2);
    $PAGE->set_title("{$strmessages}: {$user2fullname}");
    $PAGE->set_heading("{$strmessages}: {$user2fullname}");
} else {
    $PAGE->set_title("{$SITE->shortname}: {$strmessages}");
    $PAGE->set_heading("{$SITE->shortname}: {$strmessages}");
}
예제 #3
0
파일: ajax.php 프로젝트: evltuma/moodle
require_sesskey();
$action = optional_param('action', null, PARAM_ALPHA);
$response = null;
switch ($action) {
    // Sending a message.
    case 'sendmessage':
        $userid = required_param('userid', PARAM_INT);
        if (empty($userid) || isguestuser($userid) || $userid == $USER->id) {
            // Cannot send messags to self, nobody or a guest.
            throw new coding_exception('Invalid user to send the message to');
        }
        $message = required_param('message', PARAM_RAW);
        $user2 = core_user::get_user($userid);
        // Only attempt to send the message if we have permission to message
        // the recipient.
        if (message_can_post_message($user2, $USER)) {
            $messageid = message_post_message($USER, $user2, $message, FORMAT_MOODLE);
            if (!$messageid) {
                throw new moodle_exception('errorwhilesendingmessage', 'core_message');
            }
        } else {
            throw new moodle_exception('unabletomessageuser', 'core_message');
        }
        $response = array();
        break;
}
if ($response !== null) {
    echo json_encode($response);
    exit;
}
throw new coding_exception('Invalid request');
예제 #4
0
    /**
     * @method unassign_users_instance Unassigns the manager to a costcenter
     * @param int $id Cost center id
     * @param int $userid User ID
     */
    public function unassign_users_instance($id, $userid) {
        global $DB, $CFG, $USER;

        $currenturl = "{$CFG->wwwroot}/local/costcenter/index.php";
        $conf = new object();
        $conf->username = $DB->get_field('user', 'username', array('id' => $userid));
        $conf->costcentername = $DB->get_field('local_costcenter', 'fullname', array('id' => $id));

        $delete = $DB->delete_records('local_costcenter_permissions', array('costcenterid' => $id, 'userid' => $userid));
        if ($delete) {
            $message = get_string('msg_del_reg_schl', 'local_costcenter', $conf);
            $userfrom = $DB->get_record('user', array('id' => $USER->id));
            $userto = $DB->get_record('user', array('id' => $userid));
            $message_post_message = message_post_message($userfrom, $userto, $message, FORMAT_HTML);
            $this->set_confirmation(get_string('unassignedsuccess', 'local_costcenter'), $currenturl, array('style' => 'notifysuccess'));
        } else {
            $this->set_confirmation(get_string('problemunassignedsuccess', 'local_costcenter'), $currenturl, array('style' => 'notifyproblem'));
        }
    }
예제 #5
0
 /**
  * Send private messages from the current USER to other users
  *
  * @param array $messages An array of message to send.
  * @return array
  * @since Moodle 2.2
  */
 public static function send_instant_messages($messages = array())
 {
     global $CFG, $USER, $DB;
     // Check if messaging is enabled.
     if (!$CFG->messaging) {
         throw new moodle_exception('disabled', 'message');
     }
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('moodle/site:sendmessage', $context);
     $params = self::validate_parameters(self::send_instant_messages_parameters(), array('messages' => $messages));
     //retrieve all tousers of the messages
     $receivers = array();
     foreach ($params['messages'] as $message) {
         $receivers[] = $message['touserid'];
     }
     list($sqluserids, $sqlparams) = $DB->get_in_or_equal($receivers, SQL_PARAMS_NAMED, 'userid_');
     $tousers = $DB->get_records_select("user", "id " . $sqluserids . " AND deleted = 0", $sqlparams);
     $blocklist = array();
     $contactlist = array();
     $sqlparams['contactid'] = $USER->id;
     $rs = $DB->get_recordset_sql("SELECT *\n                                        FROM {message_contacts}\n                                       WHERE userid {$sqluserids}\n                                             AND contactid = :contactid", $sqlparams);
     foreach ($rs as $record) {
         if ($record->blocked) {
             // $record->userid is blocking current user
             $blocklist[$record->userid] = true;
         } else {
             // $record->userid have current user as contact
             $contactlist[$record->userid] = true;
         }
     }
     $rs->close();
     $canreadallmessages = has_capability('moodle/site:readallmessages', $context);
     $resultmessages = array();
     foreach ($params['messages'] as $message) {
         $resultmsg = array();
         //the infos about the success of the operation
         //we are going to do some checking
         //code should match /messages/index.php checks
         $success = true;
         //check the user exists
         if (empty($tousers[$message['touserid']])) {
             $success = false;
             $errormessage = get_string('touserdoesntexist', 'message', $message['touserid']);
         }
         //check that the touser is not blocking the current user
         if ($success and !empty($blocklist[$message['touserid']]) and !$canreadallmessages) {
             $success = false;
             $errormessage = get_string('userisblockingyou', 'message');
         }
         // Check if the user is a contact
         //TODO MDL-31118 performance improvement - edit the function so we can pass an array instead userid
         $blocknoncontacts = get_user_preferences('message_blocknoncontacts', NULL, $message['touserid']);
         // message_blocknoncontacts option is on and current user is not in contact list
         if ($success && empty($contactlist[$message['touserid']]) && !empty($blocknoncontacts)) {
             // The user isn't a contact and they have selected to block non contacts so this message won't be sent.
             $success = false;
             $errormessage = get_string('userisblockingyounoncontact', 'message', fullname(core_user::get_user($message['touserid'])));
         }
         //now we can send the message (at least try)
         if ($success) {
             //TODO MDL-31118 performance improvement - edit the function so we can pass an array instead one touser object
             $success = message_post_message($USER, $tousers[$message['touserid']], $message['text'], external_validate_format($message['textformat']));
         }
         //build the resultmsg
         if (isset($message['clientmsgid'])) {
             $resultmsg['clientmsgid'] = $message['clientmsgid'];
         }
         if ($success) {
             $resultmsg['msgid'] = $success;
         } else {
             // WARNINGS: for backward compatibility we return this errormessage.
             //          We should have thrown exceptions as these errors prevent results to be returned.
             // See http://docs.moodle.org/dev/Errors_handling_in_web_services#When_to_send_a_warning_on_the_server_side .
             $resultmsg['msgid'] = -1;
             $resultmsg['errormessage'] = $errormessage;
         }
         $resultmessages[] = $resultmsg;
     }
     return $resultmessages;
 }
예제 #6
0
            echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
<input type="hidden" name="returnto" value="' . s($returnto) . '" />
<input type="hidden" name="id" value="' . $id . '" />
<input type="hidden" name="format" value="' . $format . '" />
<input type="hidden" name="sesskey" value="' . sesskey() . '" />
';
            echo "<h3>" . get_string('previewhtml') . "</h3>";
            echo "<div class=\"messagepreview\">\n" . format_text($messagebody, $format) . "\n</div>\n";
            echo '<p align="center"><input type="submit" name="send" value="' . get_string('sendmessage', 'message') . '" />' . "\n";
            echo '<input type="submit" name="edit" value="' . get_string('update') . '" /></p>';
            echo "\n</form>";
        } else {
            if (!empty($send)) {
                $good = 1;
                foreach ($SESSION->emailto[$id] as $user) {
                    $good = $good && message_post_message($USER, $user, $messagebody, $format);
                }
                if (!empty($good)) {
                    echo $OUTPUT->heading(get_string('messagedselectedusers'));
                    unset($SESSION->emailto[$id]);
                    unset($SESSION->emailselect[$id]);
                } else {
                    echo $OUTPUT->heading(get_string('messagedselectedusersfailed'));
                }
                echo '<p align="center"><a href="index.php?id=' . $id . '">' . get_string('backtoparticipants') . '</a></p>';
            }
        }
        echo $OUTPUT->footer();
        exit;
    } else {
        echo $OUTPUT->notification(get_string('nousersyet'));
예제 #7
0
    $fromform->school_id = $schoolid;
    $fromform->semesterid = $sem->id;
    $fromform->programid = $pro_id;
    $fromform->notification = 0;
    $fromform->requested_date = time();
    $fromform->reg_approval = 0;
    $fromform->regapproval_date = 0;
    $registrar = $DB->get_records_sql("select userid from {local_school_permissions} where roleid = 9 and schoolid = {$fromform->school_id} group by userid");
    foreach ($registrar as $reg) {
        $registrarid = $reg->userid;
    }
    $userto = $DB->get_record('user', array('id' => $registrarid));
    $userfrom = $DB->get_record('user', array('id' => $USER->id));
    $message = get_string('reqidcardsmsg', 'local_request');
    if ($DB->insert_record('local_request_idcard', $fromform)) {
        message_post_message($userfrom, $userto, $message, FORMAT_HTML);
        $conmessage = get_string('requestsubmit', 'local_request');
        $options = array('style' => 'notifysuccess');
        $hierarchy->set_confirmation($conmessage, $nexturl, $options);
    }
}

echo $OUTPUT->header();
$check = $DB->get_record_sql("SELECT * FROM {local_request_idcard} WHERE studentid = {$USER->id} AND reg_approval = 0");
if (!empty($check)) {
    $message = get_string('requestiderror', 'local_request');
    $options = array('style' => 'notifyproblem');
    $hierarchy->set_confirmation($message, $nexturl, $options);
}

echo $OUTPUT->heading(get_string('requisitions_id', 'local_request'));
예제 #8
0
    if (count($SESSION->emailto[$id])) {
        if ($preview) {
            echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
<input type="hidden" name="returnto" value="' . stripslashes($returnto) . '" />
<input type="hidden" name="id" value="' . $id . '" />
<input type="hidden" name="format" value="' . $format . '" />
';
            echo "<h3>" . get_string('previewhtml') . "</h3><div class=\"messagepreview\">\n" . format_text(stripslashes($messagebody), $format) . "\n</div>\n";
            echo '<p align="center"><input type="submit" name="send" value="' . get_string('sendmessage', 'message') . '" />' . "\n";
            echo '<input type="submit" name="edit" value="' . get_string('edit') . '" /></p>';
            echo "\n</form>";
        } elseif ($send) {
            $good = 1;
            $teachers = array();
            foreach ($SESSION->emailto[$id] as $user) {
                $good = $good && message_post_message($USER, $user, addslashes($messagebody), $format, 'direct');
                if ($user->teacher) {
                    $teachers[] = $user->id;
                }
            }
            if ($good) {
                print_heading(get_string('messagedselectedusers'));
                unset($SESSION->emailto[$id]);
                unset($SESSION->emailselect[$id]);
            } else {
                print_heading(get_string('messagedselectedusersfailed'));
            }
            echo '<p align="center"><a href="index.php?id=' . $id . '">' . get_string('backtoparticipants') . '</a></p>';
        }
        print_footer();
        exit;
예제 #9
0
 /**
  * Test delete_message.
  */
 public function test_delete_message()
 {
     global $DB;
     $this->resetAfterTest(true);
     $user1 = self::getDataGenerator()->create_user();
     $user2 = self::getDataGenerator()->create_user();
     $user3 = self::getDataGenerator()->create_user();
     $user4 = self::getDataGenerator()->create_user();
     // Login as user1.
     $this->setUser($user1);
     $this->assertEquals(array(), core_message_external::create_contacts(array($user2->id, $user3->id)));
     // User user1 does not interchange messages with user3.
     $m1to2 = message_post_message($user1, $user2, 'some random text 1', FORMAT_MOODLE);
     $m2to3 = message_post_message($user2, $user3, 'some random text 3', FORMAT_MOODLE);
     $m3to2 = message_post_message($user3, $user2, 'some random text 4', FORMAT_MOODLE);
     $m3to4 = message_post_message($user3, $user4, 'some random text 4', FORMAT_MOODLE);
     // Retrieve all messages sent by user2 (they are currently unread).
     $lastmessages = message_get_messages($user1->id, $user2->id, 0, false);
     // Delete a message not read, as a user from.
     $result = core_message_external::delete_message($m1to2, $user1->id, false);
     $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
     $this->assertTrue($result['status']);
     $this->assertCount(0, $result['warnings']);
     $deletedmessage = $DB->get_record('message', array('id' => $m1to2));
     $this->assertNotEquals(0, $deletedmessage->timeuserfromdeleted);
     // Try to delete the same message again.
     $result = core_message_external::delete_message($m1to2, $user1->id, false);
     $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
     $this->assertFalse($result['status']);
     // Try to delete a message that does not belong to me.
     try {
         $messageid = core_message_external::delete_message($m2to3, $user3->id, false);
         $this->fail('Exception expected due invalid messageid.');
     } catch (moodle_exception $e) {
         $this->assertEquals('You do not have permission to delete this message', $e->errorcode);
     }
     $this->setUser($user3);
     // Delete a message not read, as a user to.
     $result = core_message_external::delete_message($m2to3, $user3->id, false);
     $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
     $this->assertTrue($result['status']);
     $this->assertCount(0, $result['warnings']);
     $deletedmessage = $DB->get_record('message', array('id' => $m2to3));
     $this->assertNotEquals(0, $deletedmessage->timeusertodeleted);
     // Delete a message read.
     $message = $DB->get_record('message', array('id' => $m3to2));
     $messageid = message_mark_message_read($message, time());
     $result = core_message_external::delete_message($messageid, $user3->id);
     $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
     $this->assertTrue($result['status']);
     $this->assertCount(0, $result['warnings']);
     $deletedmessage = $DB->get_record('message_read', array('id' => $messageid));
     $this->assertNotEquals(0, $deletedmessage->timeuserfromdeleted);
     // Invalid message ids.
     try {
         $result = core_message_external::delete_message(-1, $user1->id);
         $this->fail('Exception expected due invalid messageid.');
     } catch (dml_missing_record_exception $e) {
         $this->assertEquals('invalidrecord', $e->errorcode);
     }
     // Invalid user.
     try {
         $result = core_message_external::delete_message($m1to2, -1, false);
         $this->fail('Exception expected due invalid user.');
     } catch (moodle_exception $e) {
         $this->assertEquals('invaliduser', $e->errorcode);
     }
     // Not active user.
     delete_user($user2);
     try {
         $result = core_message_external::delete_message($m1to2, $user2->id, false);
         $this->fail('Exception expected due invalid user.');
     } catch (moodle_exception $e) {
         $this->assertEquals('userdeleted', $e->errorcode);
     }
     // Now, as an admin, try to delete any message.
     $this->setAdminUser();
     $result = core_message_external::delete_message($m3to4, $user4->id, false);
     $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
     $this->assertTrue($result['status']);
     $this->assertCount(0, $result['warnings']);
     $deletedmessage = $DB->get_record('message', array('id' => $m3to4));
     $this->assertNotEquals(0, $deletedmessage->timeusertodeleted);
 }
예제 #10
0
$return = $CFG->wwwroot . '/' . $CFG->admin . '/user/user_bulk.php';
if (empty($SESSION->bulk_users)) {
    redirect($return);
}
if (empty($CFG->messaging)) {
    print_error('messagingdisable', 'error');
}
//TODO: add support for large number of users
if ($confirm and !empty($msg) and confirm_sesskey()) {
    list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
    $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
        message_post_message($USER, $user, $msg, FORMAT_HTML);
    }
    $rs->close();
    redirect($return);
}
$msgform = new user_message_form('user_bulk_message.php');
if ($msgform->is_cancelled()) {
    redirect($return);
} else {
    if ($formdata = $msgform->get_data()) {
        $options = new stdClass();
        $options->para = false;
        $options->newlines = true;
        $options->smiley = false;
        $msg = format_text($formdata->messagebody['text'], $formdata->messagebody['format'], $options);
        list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
예제 #11
0
파일: tao.php 프로젝트: nadavkav/MoodleTAO
/**
 * event handler for messaging by role
 */
function tao_handle_message_role_event($eventdata)
{
    global $CFG;
    require_once $CFG->dirroot . '/local/lib/messagelib.php';
    require_once $CFG->dirroot . '/message/lib.php';
    if (!($tomessage = tao_message_get_recipients_by_target($eventdata['target'], $eventdata['course'], $eventdata['from']))) {
        return true;
        // done!
    }
    $a = (object) array('target' => get_string('messagetarget' . $eventdata['target']->stringkey, 'local'), 'course' => $eventdata['course']->fullname);
    if ($eventdata['course']->id == SITEID) {
        $footer = get_string('messagelistfooter', 'local', $a);
    } else {
        $footer = get_string('messagelistfootercourse', 'local', $a);
    }
    $eventdata['body'] .= '<br /><br />' . $footer;
    $fromuser = get_record('user', 'id', $eventdata['from']);
    foreach ($tomessage as $user) {
        if ($fromuser->id == $user->id) {
            continue;
        }
        message_post_message($fromuser, $user, $eventdata['body'], $eventdata['format'], 'direct');
    }
    return true;
}
            //case "2":
            //$thistargetstatus = get_string('notachieved', 'ilptarget');
            //break;
            case "3":
                $thistargetstatus = get_string('withdrawn', 'ilptarget');
                break;
        }
        $updatedstatus = get_string('statusupdate', 'ilptarget', $thistargetstatus);
        //Sets message details for Targets
        $messagefrom = get_record('user', 'id', $USER->id);
        $messageto = get_record('user', 'id', $userid);
        $targeturl = $CFG->wwwroot . '/mod/ilptarget/target_view.php?' . ($courseid ? 'courseid=' . $courseid . '&amp;' : '') . 'userid=' . $id . '">';
        $targetview = get_string('targetviewlink', 'ilptarget');
        $updatedstatus = get_string('statusupdate', 'ilptarget', $thistargetstatus);
        $message = '<p>' . $updatedstatus . '<br /><a href="' . $targeturl . '&amp;status=' . $status . '">' . $targetview . '</a></p>';
        message_post_message($messagefrom, $messageto, $message, FORMAT_HTML, 'direct');
    }
}
$mform = new ilptarget_updatetarget_form('', array('userid' => $user->id, 'id' => $id, 'courseid' => $courseid, 'targetpost' => $targetpost, 'linkvalues' => $link_values));
if (!$mform->is_cancelled() && ($fromform = $mform->get_data())) {
    $mform->process_data($fromform);
}
if ($action == 'delete') {
    //Check to see if we are deleting a comment
    $report = get_record('ilptarget_posts', 'id', $targetpost);
    delete_records('ilptarget_posts', 'id', $report->id);
    delete_records('ilptarget_comments', 'targetpost', $report->id, 'userid', $user->id);
    delete_records('event', 'name', $report->name, 'instance', $report->id, 'userid', $user->id);
}
if ($action == 'updatetarget') {
    print_heading(get_string('add', 'ilptarget'));
예제 #13
0
function group_send_invite($userid, $fromuserid, $group, $courseid)
{
    global $CFG, $COURSE;
    if (record_exists('group_invites', 'courseid', $courseid, 'userid', $userid, 'groupid', $group->id)) {
        notify(get_string('invitealready', 'block_tao_team_groups'));
    } else {
        $invite = new stdclass();
        $invite->courseid = $courseid;
        $invite->userid = $userid;
        $invite->fromuserid = $fromuserid;
        $invite->groupid = $group->id;
        $invite->timemodified = time();
        insert_record('group_invites', $invite);
        //now send e-mail
        $sendto = get_record('user', 'id', $userid);
        $sendfrom = get_record('user', 'id', $fromuserid);
        $a = new stdclass();
        $a->firstname = $sendto->firstname;
        $a->group = $group->name;
        $a->course = $COURSE->fullname;
        $a->link = '<a href="' . $CFG->wwwroot . "/course/view.php?id={$courseid}" . '">' . $CFG->wwwroot . "/course/view.php?id={$courseid}</a>";
        message_post_message($sendfrom, $sendto, addslashes(get_string('inviteemailbody', 'block_tao_team_groups', $a)), FORMAT_HTML, 'direct');
        notify(get_string('invitesent', 'block_tao_team_groups'), 'notifysuccess');
    }
}
 function process_data($data)
 {
     global $USER, $CFG;
     require_once "{$CFG->dirroot}/message/lib.php";
     $courseid = $this->_customdata['courseid'];
     $userid = $this->_customdata['userid'];
     $id = $this->_customdata['id'];
     $concernspost = $this->_customdata['concernspost'];
     $commentid = $this->_customdata['commentid'];
     //Sets message details for comments
     $messagefrom = get_record('user', 'id', $USER->id);
     $messageto = get_record('user', 'id', $userid);
     $newcomment = get_string('newcomment', 'ilpconcern');
     $updatedcomment = get_string('updatedcomment', 'ilpconcern');
     $concernview = get_string('concernviewlink', 'ilpconcern');
     $commenturl = $CFG->wwwroot . '/mod/ilpconcern/concerns_comments.php?' . ($courseid != SITEID ? 'courseid=' . $courseid . '&amp;' : '') . '&amp;concernspost=' . $concernspost;
     if (!($report = get_record('ilpconcern_comments', 'concernspost', $concernspost, 'id', $commentid))) {
         $report = new Object();
         $report->concernspost = $concernspost;
         $report->userid = $USER->id;
         $report->created = time();
         $report->modified = time();
         $report->comment = $data->comment;
         $report->format = $data->format;
         $commentinstance = insert_record('ilpconcern_comments', $report, true);
         $message = '<p>' . $newcomment;
     } else {
         $report->userid = $USER->id;
         $report->comment = $data->comment;
         $report->format = $data->format;
         $report->modified = time();
         $commentinstance = update_record('ilpconcern_comments', $report);
         $message = '<p>' . $updatedcomment;
     }
     if ($CFG->ilpconcern_send_comment_message == 1) {
         $message .= '<br /><a href="' . $commenturl . '">' . $concernview . '</a></p>' . $comment;
         message_post_message($messagefrom, $messageto, $message, FORMAT_HTML, 'direct');
     }
 }
                $reportstaburl = !empty($reportsviewtab) ? "&selectedtab={$reportsviewtab->id}&tabitem={$reportsviewtab->id}:{$report->id}" : "";
                $message = new stdClass();
                $message->component = 'block_ilp';
                $message->name = 'ilp_comment';
                $message->subject = get_string('newreportcomment', 'block_ilp', $report);
                $message->userfrom = $dbc->get_user_by_id($USER->id);
                $message->userto = $dbc->get_user_by_id($entry->user_id);
                $message->fullmessage = get_string('newreportcomment', 'block_ilp', $report);
                $message->fullmessageformat = FORMAT_PLAIN;
                $message->contexturl = $CFG->wwwroot . "/blocks/ilp/actions/view_main.php?user_id={$entry->user_id}{$reportstaburl}";
                $message->contexturlname = get_string('viewreport', 'block_ilp');
                if (stripos($CFG->release, "2.") !== false) {
                    message_send($message);
                } else {
                    require_once $CFG->dirroot . '/message/lib.php';
                    message_post_message($message->userfrom, $message->userto, $message->fullmessage, $message->fullmessageformat, 'direct');
                }
            }
            $return_url = $CFG->wwwroot . "/blocks/ilp/actions/view_main.php?user_id={$user_id}&selectedtab={$selectedtab}&tabitem={$tabitem}&course_id={$course_id}";
            redirect($return_url, get_string("commentcreationsuc", 'block_ilp'), ILP_REDIRECT_DELAY);
        }
    }
}
if (!empty($comment_id)) {
    $comment = $dbc->get_comment_by_id($comment_id);
    if (!empty($comment)) {
        //only the creator has the right to edit
        if ($comment->creator_id == $USER->id) {
            //set the form values to the current comment
            $mform->set_data($comment);
        } else {
예제 #16
0
            echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
<input type="hidden" name="returnto" value="' . s($returnto) . '" />
<input type="hidden" name="id" value="' . $id . '" />
<input type="hidden" name="format" value="' . $format . '" />
<input type="hidden" name="sesskey" value="' . sesskey() . '" />
';
            echo "<h3>" . get_string('previewhtml') . "</h3>";
            echo "<div class=\"messagepreview\">\n" . format_text($messagebody, $format) . "\n</div>\n";
            echo '<p align="center"><input type="submit" name="send" value="' . get_string('sendmessage', 'message') . '" />' . "\n";
            echo '<input type="submit" name="edit" value="' . get_string('update') . '" /></p>';
            echo "\n</form>";
        } else {
            if (!empty($send)) {
                $fails = array();
                foreach ($SESSION->emailto[$id] as $user) {
                    if (!message_post_message($USER, $user, $messagebody, $format)) {
                        $user->fullname = fullname($user);
                        $fails[] = get_string('messagedselecteduserfailed', 'moodle', $user);
                    }
                }
                if (empty($fails)) {
                    echo $OUTPUT->heading(get_string('messagedselectedusers'));
                    unset($SESSION->emailto[$id]);
                    unset($SESSION->emailselect[$id]);
                } else {
                    echo $OUTPUT->heading(get_string('messagedselectedcountusersfailed', 'moodle', count($fails)));
                    echo '<ul>';
                    foreach ($fails as $f) {
                        echo '<li>', $f, '</li>';
                    }
                    echo '</ul>';
예제 #17
0
 /**
  * Test message_get_recent_notifications.
  */
 public function test_message_get_recent_notifications()
 {
     global $DB, $USER;
     // Set this user as the admin.
     $this->setAdminUser();
     // Create a user to send messages from.
     $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1'));
     // Add two messages - will mark them as notifications later.
     $m1 = message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN);
     $m2 = message_post_message($user1, $USER, 'Message 2', FORMAT_PLAIN);
     // Mark the second message as a notification.
     $updatemessage = new stdClass();
     $updatemessage->id = $m2;
     $updatemessage->notification = 1;
     $DB->update_record('message_read', $updatemessage);
     // Mark the first message as a notification and change the timecreated to 0.
     $updatemessage->id = $m1;
     $updatemessage->notification = 1;
     $updatemessage->timecreated = 0;
     $DB->update_record('message_read', $updatemessage);
     $notifications = message_get_recent_notifications($USER);
     // Get the messages.
     $firstmessage = array_shift($notifications);
     $secondmessage = array_shift($notifications);
     // Confirm that we have received the notifications with the maximum timecreated, rather than the max id.
     $this->assertEquals('Message 2', $firstmessage->smallmessage);
     $this->assertEquals('Message 1', $secondmessage->smallmessage);
 }
function bigbluebuttonbn_send_notification($sender, $bigbluebuttonbn, $message = "")
{
    global $CFG, $DB;
    $context = bigbluebuttonbn_get_context_course($bigbluebuttonbn->course);
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
    //Complete message
    $msg = new stdClass();
    $msg->user_name = fullname($sender);
    $msg->user_email = $sender->email;
    $msg->course_name = $course->fullname;
    $message .= get_string('email_footer', 'bigbluebuttonbn', $msg);
    $users = bigbluebuttonbn_get_users($context);
    foreach ($users as $user) {
        if ($user->id != $sender->id) {
            $messageid = message_post_message($sender, $user, $message, FORMAT_HTML);
            if (!empty($messageid)) {
                error_log("Msg to " . $msg->user_name . " was sent.");
            } else {
                error_log("Msg to " . $msg->user_name . " was NOT sent.");
            }
        }
    }
}
예제 #19
0
 /**
  * Test get_messages.
  */
 public function test_get_messages()
 {
     global $CFG;
     $this->resetAfterTest(true);
     $this->preventResetByRollback();
     // This mark the messages as read!.
     $sink = $this->redirectMessages();
     $user1 = self::getDataGenerator()->create_user();
     $user2 = self::getDataGenerator()->create_user();
     $user3 = self::getDataGenerator()->create_user();
     $course = self::getDataGenerator()->create_course();
     // Send a message from one user to another.
     message_post_message($user1, $user2, 'some random text 1', FORMAT_MOODLE);
     message_post_message($user1, $user3, 'some random text 2', FORMAT_MOODLE);
     message_post_message($user2, $user3, 'some random text 3', FORMAT_MOODLE);
     message_post_message($user3, $user2, 'some random text 4', FORMAT_MOODLE);
     message_post_message($user3, $user1, 'some random text 5', FORMAT_MOODLE);
     $this->setUser($user1);
     // Get read conversations from user1 to user2.
     $messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(1, $messages['messages']);
     // Get unread conversations from user1 to user2.
     $messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', false, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(0, $messages['messages']);
     // Get read messages send from user1.
     $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(2, $messages['messages']);
     $this->setUser($user2);
     // Get read conversations from any user to user2.
     $messages = core_message_external::get_messages($user2->id, 0, 'conversations', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(2, $messages['messages']);
     $this->setUser($user3);
     // Get read notifications received by user3.
     $messages = core_message_external::get_messages($user3->id, 0, 'notifications', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(0, $messages['messages']);
     // Now, create some notifications...
     // We are creating fake notifications but based on real ones.
     // This one omits notification = 1.
     $eventdata = new stdClass();
     $eventdata->modulename = 'moodle';
     $eventdata->component = 'enrol_paypal';
     $eventdata->name = 'paypal_enrolment';
     $eventdata->userfrom = get_admin();
     $eventdata->userto = $user1;
     $eventdata->subject = "Moodle: PayPal payment";
     $eventdata->fullmessage = "Your PayPal payment is pending.";
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '';
     $eventdata->smallmessage = '';
     message_send($eventdata);
     $message = new stdClass();
     $message->notification = 1;
     $message->component = 'enrol_manual';
     $message->name = 'expiry_notification';
     $message->userfrom = $user2;
     $message->userto = $user1;
     $message->subject = 'Enrolment expired';
     $message->fullmessage = 'Enrolment expired blah blah blah';
     $message->fullmessageformat = FORMAT_MARKDOWN;
     $message->fullmessagehtml = markdown_to_html($message->fullmessage);
     $message->smallmessage = $message->subject;
     $message->contexturlname = $course->fullname;
     $message->contexturl = (string) new moodle_url('/course/view.php', array('id' => $course->id));
     message_send($message);
     $userfrom = core_user::get_noreply_user();
     $userfrom->maildisplay = true;
     $eventdata = new stdClass();
     $eventdata->component = 'moodle';
     $eventdata->name = 'badgecreatornotice';
     $eventdata->userfrom = $userfrom;
     $eventdata->userto = $user1;
     $eventdata->notification = 1;
     $eventdata->subject = 'New badge';
     $eventdata->fullmessage = format_text_email($eventdata->subject, FORMAT_HTML);
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = $eventdata->subject;
     $eventdata->smallmessage = $eventdata->subject;
     message_send($eventdata);
     $eventdata = new stdClass();
     $eventdata->name = 'submission';
     $eventdata->component = 'mod_feedback';
     $eventdata->userfrom = $user1;
     $eventdata->userto = $user2;
     $eventdata->subject = 'Feedback submitted';
     $eventdata->fullmessage = 'Feedback submitted from an user';
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '<strong>Feedback submitted</strong>';
     $eventdata->smallmessage = '';
     message_send($eventdata);
     $this->setUser($user1);
     // Get read notifications from any user to user1.
     $messages = core_message_external::get_messages($user1->id, 0, 'notifications', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(3, $messages['messages']);
     // Get one read notifications from any user to user1.
     $messages = core_message_external::get_messages($user1->id, 0, 'notifications', true, true, 0, 1);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(1, $messages['messages']);
     // Get unread notifications from any user to user1.
     $messages = core_message_external::get_messages($user1->id, 0, 'notifications', false, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(0, $messages['messages']);
     // Get read both type of messages from any user to user1.
     $messages = core_message_external::get_messages($user1->id, 0, 'both', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(4, $messages['messages']);
     // Get read notifications from no-reply-user to user1.
     $messages = core_message_external::get_messages($user1->id, $userfrom->id, 'notifications', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(1, $messages['messages']);
     // Get notifications send by user1 to any user.
     $messages = core_message_external::get_messages(0, $user1->id, 'notifications', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(1, $messages['messages']);
     // Test warnings.
     $CFG->messaging = 0;
     $messages = core_message_external::get_messages(0, $user1->id, 'both', true, true, 0, 0);
     $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
     $this->assertCount(1, $messages['warnings']);
     // Test exceptions.
     // Messaging disabled.
     try {
         $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0);
         $this->fail('Exception expected due messaging disabled.');
     } catch (moodle_exception $e) {
         $this->assertEquals('disabled', $e->errorcode);
     }
     $CFG->messaging = 1;
     // Invalid users.
     try {
         $messages = core_message_external::get_messages(0, 0, 'conversations', true, true, 0, 0);
         $this->fail('Exception expected due invalid users.');
     } catch (moodle_exception $e) {
         $this->assertEquals('accessdenied', $e->errorcode);
     }
     // Invalid user ids.
     try {
         $messages = core_message_external::get_messages(2500, 0, 'conversations', true, true, 0, 0);
         $this->fail('Exception expected due invalid users.');
     } catch (moodle_exception $e) {
         $this->assertEquals('invaliduser', $e->errorcode);
     }
     // Invalid users (permissions).
     $this->setUser($user2);
     try {
         $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0);
         $this->fail('Exception expected due invalid user.');
     } catch (moodle_exception $e) {
         $this->assertEquals('accessdenied', $e->errorcode);
     }
 }
예제 #20
0
파일: lib.php 프로젝트: anilch/Personel
 /**
  * @method assign_instructor_department
  * @todo to assign instructor to department
  * @param array $inslist instructor list    
  * @return int newly inserted record ID.
  */
 function assign_instructor_department($inslist) {
     global $DB, $USER, $CFG;
     //print_object($inslist);
     //  exit();
     $tool = new stdClass();
     $tool->departmentid = $inslist->moveto;
     $tool->schoolid = $inslist->ins_schoolid;
     $tool->timecreated = time();
     $tool->timemodified = time();
     $tool->usermodified = $USER->id;
     $insid = $inslist->check;
     foreach ($insid as $ins_id) {
         $tool->instructorid = $ins_id;
         $exists_inslist = $DB->get_record('local_dept_instructor', array('instructorid' => $ins_id, 'schoolid' => $inslist->ins_schoolid));
         if (!empty($exists_inslist)) {
             return 0;
             //return false;
         } else {
             //  print_object($tool);
             $id = $DB->insert_record('local_dept_instructor', $tool);
             /* ---start of vijaya--- */
             $conf = new object();
             $conf->username = $DB->get_field('user', 'username', array('id' => $ins_id));
             $conf->deptname = $DB->get_field('local_department', 'fullname', array('id' => $tool->departmentid));
             $message = get_string('msg_add_ins_dept', 'local_departments', $conf);
             $userfrom = $DB->get_record('user', array('id' => $USER->id));
             $userto = $DB->get_record('user', array('id' => $ins_id));
             /* Bug report #253  -  Invoice Messages
              * @author hemalatha c arun <*****@*****.**> 
              * Resolved - changed the message format
              */
             $message_post_message = message_post_message($userfrom, $userto, $message, FORMAT_HTML);
             /* ---end of vijaya--- */
         }
     }
     return $id;
 }
예제 #21
0
}
if (get_user_preferences('message_blocknoncontacts', 0, $user->id)) {
    // User is blocking non-contacts
    if (empty($contact)) {
        // We are not a contact!
        print_heading(get_string('userisblockingyounoncontact', 'message'));
        exit;
    }
}
$refreshedmessage = '';
if (!empty($refresh) and data_submitted()) {
    $refreshedmessage = $message;
} else {
    if (empty($refresh) and data_submitted() and confirm_sesskey()) {
        if ($message != '') {
            message_post_message($USER, $user, $message, $format, 'direct');
        }
        redirect('discussion.php?id=' . $userid . '&amp;start=' . $start . '&amp;noframesjs=' . $noframesjs . '&amp;newonly=' . $newonly . '&amp;last=' . $last);
    }
}
$userfullname = fullname($user);
$mefullname = fullname($USER);
print_header(get_string('discussion', 'message') . ': ' . fullname($user), '', '', 'edit-message');
echo '<div class="message-discussion-noframes">';
echo '<div id="userinfo">';
echo print_user_picture($user->id, SITEID, $user->picture, 48, true, true, 'userwindow');
echo '<div class="name"><h1>' . $userfullname . '</h1></div>';
echo '<div class="commands"><ul>';
if ($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $user->id)) {
    if ($contact->blocked) {
        echo '<li>';
 /**
  * Send private messages from the current USER to other users
  *
  * @param $messages  An array of message to send.
  * @return boolean
  */
 public static function send_instantmessages($messages = array())
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . "/message/lib.php";
     //check if messaging is enabled
     if (!$CFG->messaging) {
         throw new moodle_exception('disabled', 'message');
     }
     // Ensure the current user is allowed to run this function
     $context = get_context_instance(CONTEXT_SYSTEM);
     self::validate_context($context);
     require_capability('moodle/site:sendmessage', $context);
     $params = self::validate_parameters(self::send_instantmessages_parameters(), array('messages' => $messages));
     //retrieve all tousers of the messages
     $receivers = array();
     foreach ($params['messages'] as $message) {
         $receivers[] = $message['touserid'];
     }
     list($sqluserids, $sqlparams) = $DB->get_in_or_equal($receivers, SQL_PARAMS_NAMED, 'userid_');
     $tousers = $DB->get_records_select("user", "id " . $sqluserids . " AND deleted = 0", $sqlparams);
     $blocklist = array();
     $contactlist = array();
     $sqlparams['contactid'] = $USER->id;
     $rs = $DB->get_recordset_sql("SELECT *\n                                        FROM {message_contacts}\n                                       WHERE userid {$sqluserids}\n                                             AND contactid = :contactid", $sqlparams);
     foreach ($rs as $record) {
         if ($record->blocked) {
             // $record->userid is blocking current user
             $blocklist[$record->userid] = true;
         } else {
             // $record->userid have current user as contact
             $contactlist[$record->userid] = true;
         }
     }
     $rs->close();
     $canreadallmessages = has_capability('moodle/site:readallmessages', $context);
     $resultmessages = array();
     foreach ($params['messages'] as $message) {
         $text = clean_param($message['text'], PARAM_TEXT);
         $resultmsg = array();
         //the infos about the success of the operation
         //we are going to do some checking
         //code should match /messages/index.php checks
         $success = true;
         //check the user exists
         if (empty($tousers[$message['touserid']])) {
             $success = false;
             $errormessage = get_string('touserdoesntexist', 'message', $message['touserid']);
         }
         //check that the touser is not blocking the current user
         if ($success and !empty($blocklist[$message['touserid']]) and !$canreadallmessages) {
             $success = false;
             $errormessage = get_string('userisblockingyou', 'message');
         }
         // Check if the user is a contact
         //TODO: performance improvement - edit the function so we can pass an array instead userid
         $blocknoncontacts = get_user_preferences('message_blocknoncontacts', NULL, $message['touserid']);
         // message_blocknoncontacts option is on and current user is not in contact list
         if ($success && empty($contactlist[$message['touserid']]) && !empty($blocknoncontacts)) {
             // The user isn't a contact and they have selected to block non contacts so this message won't be sent.
             $success = false;
             $errormessage = get_string('userisblockingyounoncontact', 'message');
         }
         //now we can send the message (at least try)
         if ($success) {
             //TODO: performance improvement - edit the function so we can pass an array instead one touser object
             $success = message_post_message($USER, $tousers[$message['touserid']], $text, FORMAT_MOODLE);
         }
         //build the resultmsg
         if (isset($message['clientmsgid'])) {
             $resultmsg['clientmsgid'] = $message['clientmsgid'];
         }
         if ($success) {
             $resultmsg['msgid'] = $success;
         } else {
             $resultmsg['msgid'] = -1;
             $resultmsg['errormessage'] = $errormessage;
         }
         $resultmessages[] = $resultmsg;
     }
     return $resultmessages;
 }
예제 #23
0
if (!empty($groupid) && !($group = get_record('groups', 'id', $groupid, 'courseid', $courseid))) {
    error('Invalid group id');
}
require_login();
print_header_simple($strheading, $strheading, build_navigation($strheading));
if (groups_is_member($groupid)) {
    $grpmembers = groups_get_members($groupid);
    if (count($grpmembers) > 1) {
        require_once $CFG->dirroot . '/local/forms.php';
        require_once $CFG->dirroot . '/message/lib.php';
        $messageform = new tao_group_message_send_form('', array('course' => $COURSE, 'group' => $group, 'count' => count($grpmembers) - 1));
        if ($data = $messageform->get_data()) {
            foreach ($grpmembers as $touser) {
                if ($touser->id != $USER->id) {
                    //don't send a message to yourself.
                    message_post_message($USER, $touser, $data->body, $data->format, 'direct');
                }
            }
            notify(get_string('groupmessagesent', 'block_tao_team_groups'), 'notifysuccess');
            print_continue($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id);
        } else {
            if (!$messageform->is_cancelled()) {
                $messageform->display();
                return;
            }
        }
    } else {
        notify(get_string('messagenorecipients', 'block_tao_team_groups'));
    }
} else {
    error("you are not a member of this group");
예제 #24
0
        exit;
    }
}
$userpreferences = get_user_preferences(NULL, NULL, $user->id);
if (!empty($userpreferences['message_blocknoncontacts'])) {
    // User is blocking non-contacts
    if (empty($contact)) {
        // We are not a contact!
        print_heading(get_string('userisblockingyounoncontact', 'message'));
        exit;
    }
}
if ($message != '' and confirm_sesskey()) {
    /// Current user has just sent a message
    /// Save it to the database...
    $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
    /// Format the message as HTML
    $options = NULL;
    $options->para = false;
    $options->newlines = true;
    $message = format_text($message, $format, $options);
    $time = userdate(time(), get_string('strftimedaytime'));
    $message = '<div class="message me"><span class="author">' . fullname($USER) . '</span> ' . '<span class="time">[' . $time . ']</span>: ' . '<span class="content">' . $message . '</span></div>';
    $message = addslashes_js($message);
    // So Javascript can write it
    /// Then write it to our own message screen immediately
    echo "\n<script type=\"text/javascript\">\n<!--\n";
    echo 'parent.messages.document.write(\'' . $message . "\\n');\n";
    echo 'parent.messages.scroll(1,5000000);';
    echo "\n-->\n</script>\n\n";
    add_to_log(SITEID, 'message', 'write', 'history.php?user1=' . $user->id . '&amp;user2=' . $USER->id . '#m' . $messageid, $user->id);
예제 #25
0
            $messageerror = get_string('userisblockingyounoncontact', 'message', fullname($user2));
        }
    }
    if (empty($messageerror)) {
        $mform = new send_form();
        $defaultmessage = new stdClass();
        $defaultmessage->id = $user2->id;
        $defaultmessage->viewing = $viewing;
        $defaultmessage->message = '';
        //Check if the current user has sent a message
        $data = $mform->get_data();
        if (!empty($data) && !empty($data->message)) {
            if (!confirm_sesskey()) {
                print_error('invalidsesskey');
            }
            $messageid = message_post_message($user1, $user2, $data->message, FORMAT_MOODLE);
            if (!empty($messageid)) {
                //including the id of the user sending the message in the logged URL so the URL works for admins
                //note message ID may be misleading as the message may potentially get a different ID when moved from message to message_read
                redirect($CFG->wwwroot . '/message/index.php?viewing=' . $viewing . '&id=' . $user2->id);
            }
        }
    }
}
$strmessages = get_string('messages', 'message');
if ($user2realuser) {
    $user2fullname = fullname($user2);
    $PAGE->set_title("{$strmessages}: {$user2fullname}");
    $PAGE->set_heading("{$strmessages}: {$user2fullname}");
} else {
    $PAGE->set_title("{$SITE->shortname}: {$strmessages}");
예제 #26
0
 /**
  * Test message_search.
  */
 public function test_message_search()
 {
     global $USER;
     // Set this user as the admin.
     $this->setAdminUser();
     // Create a user to add to the admin's contact list.
     $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1'));
     $user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'user2'));
     // Send few messages, real (read).
     message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN);
     message_post_message($USER, $user1, 'Message 2', FORMAT_PLAIN);
     message_post_message($USER, $user2, 'Message 3', FORMAT_PLAIN);
     $this->assertCount(2, message_search(array('Message'), true, false));
     $this->assertCount(3, message_search(array('Message'), true, true));
     // Send fake message (not-read).
     $this->send_fake_message($USER, $user1, 'Message 4');
     $this->send_fake_message($user1, $USER, 'Message 5');
     $this->assertCount(3, message_search(array('Message'), true, false));
     $this->assertCount(5, message_search(array('Message'), true, true));
     // If courseid given then should be 0.
     $this->assertEquals(false, message_search(array('Message'), true, true, ''));
     $this->assertEquals(false, message_search(array('Message'), true, true, 2));
     $this->assertCount(5, message_search(array('Message'), true, true, SITEID));
 }
예제 #27
0
    $emailtext = get_string('certemailapprovetext', 'block_tao_certification_path') . "<br><br>" . $description;
    message_post_message($USER, $mtuser, addslashes($emailtext), FORMAT_HTML, 'direct');
    notify(get_string('certificationapproved', 'block_tao_certification_path'), 'notifysuccess');
} elseif ($action == 'declined') {
    $certrequest->status = 'declined';
    $certrequest->changeuserid = $USER->id;
    $certrequest->timechanged = time();
    $certrequest->description = $description;
    if (!update_record('tao_user_certification_status', $certrequest)) {
        notify("Error updating certification status");
        print_footer(NULL, $course);
        die;
    }
    $mtuser = get_record('user', 'id', $certrequest->userid);
    $emailtext = get_string('certemaildeclinetext', 'block_tao_certification_path') . "<br><br>" . $description;
    message_post_message($USER, $mtuser, addslashes($emailtext), FORMAT_HTML, 'direct');
    notify(get_string('certemaildeclinesubject', 'block_tao_certification_path'), 'notifysuccess');
}
if (empty($action)) {
    $ptuser = get_record('user', 'id', $certrequest->userid);
    echo '<div class="approvecertform">';
    echo '<div class="label">' . get_string('name') . ":</div><div class=\"content\"><a href='{$CFG->wwwroot}/user/view.php?id={$certrequest->userid}&course={$certrequest->courseid}'>" . fullname($ptuser) . "</a></div>";
    echo '<div class="label">' . get_string('course') . ":</div><div class=\"content\"><a href='{$CFG->wwwroot}/course/view.php?id={$certrequest->courseid}'>{$course->shortname}</a></div>";
    echo "<div class=\"reviewstatus\"><a href='{$CFG->wwwroot}/local/lp/certification.php?user={$certrequest->userid}'>" . get_string('reviewstatus', 'block_tao_certification_path') . '</a></div>';
    echo "<div class=\"sendmessage\"><form onclick=\"this.target='message{$certrequest->userid}'\" action=\"../message/discussion.php\" method=\"get\">";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$certrequest->userid}\" />";
    echo "<input type=\"submit\" value=\"" . get_string("sendmessage", "message") . "\" onclick=\"return openpopup('/message/discussion.php?id={$certrequest->userid}', 'message_{$certrequest->userid}', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
    echo "</form>";
    echo "</div></div>";
    //print previous Certification requests
    $sql = "userid='{$certrequest->userid}' AND courseid='{$certrequest->courseid}' AND status='declined'";
예제 #28
0
    if (count($SESSION->emailto[$id])) {
        if (!empty($preview)) {
            echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
<input type="hidden" name="returnto" value="' . s($returnto) . '" />
<input type="hidden" name="id" value="' . $id . '" />
<input type="hidden" name="format" value="' . $format . '" />
';
            echo "<h3>" . get_string('previewhtml') . "</h3><div class=\"messagepreview\">\n" . format_text($messagebody, $format) . "\n</div>\n";
            echo '<p align="center"><input type="submit" name="send" value="' . get_string('sendmessage', 'message') . '" />' . "\n";
            echo '<input type="submit" name="edit" value="' . get_string('update') . '" /></p>';
            echo "\n</form>";
        } else {
            if (!empty($send)) {
                $good = 1;
                foreach ($SESSION->emailto[$id] as $user) {
                    $good = $good && message_post_message($USER, $user, $messagebody, $format, 'direct');
                }
                if (!empty($good)) {
                    echo $OUTPUT->heading(get_string('messagedselectedusers'));
                    unset($SESSION->emailto[$id]);
                    unset($SESSION->emailselect[$id]);
                } else {
                    echo $OUTPUT->heading(get_string('messagedselectedusersfailed'));
                }
                echo '<p align="center"><a href="index.php?id=' . $id . '">' . get_string('backtoparticipants') . '</a></p>';
            }
        }
        echo $OUTPUT->footer();
        exit;
    } else {
        echo $OUTPUT->notification(get_string('nousersyet'));
$confirm = optional_param('confirm', 0, PARAM_BOOL);
admin_externalpage_setup('userbulk');
require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
$return = $CFG->wwwroot . '/' . $CFG->admin . '/user/user_bulk.php';
if (empty($SESSION->bulk_users)) {
    redirect($return);
}
if (empty($CFG->messaging)) {
    print_error('messagingdisable', 'error');
}
//TODO: add support for large number of users
if ($confirm and !empty($msg) and confirm_sesskey()) {
    $in = implode(',', $SESSION->bulk_users);
    if ($rs = $DB->get_recordset_select('user', "id IN ({$in})", null)) {
        foreach ($rs as $user) {
            message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
        }
        $rs->close();
    }
    redirect($return);
}
// disable html editor if not enabled in preferences
if (!get_user_preferences('message_usehtmleditor', 0)) {
    $CFG->htmleditor = '';
}
$msgform = new user_message_form('user_bulk_message.php');
if ($msgform->is_cancelled()) {
    redirect($return);
} else {
    if ($formdata = $msgform->get_data()) {
        $options = new object();
예제 #30
0
/**
 * This function sends a message to the development team indicating that
 * the maximum number of attempts to generate a random string has been
 * exhausted
 */
function cm_certificate_email_random_number_fail($tableobj = null)
{
    global $CFG;
    if (empty($tableobj)) {
        return false;
    }
    require_once $CFG->dirroot . '/message/lib.php';
    //construct the message
    $a = new stdClass();
    $a->sitename = get_field('course', 'fullname', 'id', SITEID);
    $a->url = $CFG->wwwroot;
    $message_text = get_string('certificate_code_fail', 'block_curr_admin', $a) . "\n\n";
    $message_text .= get_string('certificate_code_fail_text', 'block_curr_admin') . "\n";
    $message_text .= get_string('certificate_code_fail_text_data', 'block_curr_admin', $tableobj) . "\n";
    $message_html = nl2br($message_text);
    //send message to rladmin user if possible
    if ($rladmin_user = get_record('user', 'username', 'rladmin')) {
        $result = message_post_message($rladmin_user, $rladmin_user, addslashes($message_html), FORMAT_HTML, 'direct');
        if ($result === false) {
            return $result;
        }
    }
    //email to specified address
    $user_obj = new stdClass();
    $user_obj->email = CURR_ADMIN_DUPLICATE_EMAIL;
    $user_obj->mailformat = FORMAT_HTML;
    email_to_user($user_obj, get_admin(), get_string('certificate_code_fail', 'block_curr_admin', $a), $message_text, $message_html);
    //output to screen if possible
    if (!empty($output_to_screen)) {
        echo $message_html;
    }
    return true;
}