Exemplo n.º 1
0
 /**
  * create a new ReceviedMessage with the information in the parameter
  *
  * @param array $messageData
  *   $messageData['message_id']
  *   $messageData['subject']
  *   $messageData['message']
  *   $messageData['sender']
  *   $messageData['send_time']
  *   $messageData['course']
  *   $messageData['group']
  *   $messageData['tools']
  *   $messageData['is_read']
  *   $messageData['is_deleted']
  *   $messageData['user_id']
  *   $messageData['firstName']
  *   $messageData['lastName']
  * 
  * @return ReceivedMessage the message created
  */
 public static function fromArray($messageData)
 {
     $message = new ReceivedMessage($messageData['message_id']);
     $message->setFromArray($messageData);
     return $message;
 }
Exemplo n.º 2
0
 /**
  * diplay a received message
  *
  * @param ReceivedMessage $message Message to display
  * @param string $action list of action autorised on the message
  * @return string HTML source
  */
 private static function displayReceivedMessage($message, $action)
 {
     $content = '<div id="im_message">' . "\n" . '<h4 class="header">' . claro_htmlspecialchars($message->getSubject()) . '</h4>' . "\n" . '<div class="imInfoBlock">' . "\n" . '<div class="imCmdList">' . $action . '</div>' . "\n\n" . '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Sender') . ' : </span>' . "\n" . ' <span class="imInfoValue">';
     $isAllowed = current_user_is_allowed_to_send_message_to_user($message->getSender());
     if ($isAllowed) {
         $content .= '<a href="sendmessage.php?cmd=rqMessageToUser&amp;userId=' . $message->getSender() . '">';
     }
     $content .= get_lang('%firstName %lastName', array('%firstName' => claro_htmlspecialchars($message->getSenderFirstName()), '%lastName' => claro_htmlspecialchars($message->getSenderLastName())));
     if ($isAllowed) {
         $content .= "</a>";
     }
     $isManager = FALSE;
     $isAdmin = claro_is_user_platform_admin($message->getSender());
     if (!is_null($message->getCourseCode())) {
         $isManager = claro_is_user_course_manager($message->getSender(), $message->getCourseCode());
     }
     if ($isManager) {
         $content .= '&nbsp;<img src="' . get_icon_url('manager') . '" alt="" />';
     } elseif ($isAdmin) {
         $content .= '&nbsp;<img src="' . get_icon_url('platformadmin') . '" alt="" />';
     } else {
         $content .= '&nbsp;<img src="' . get_icon_url('user') . '" alt="" />';
     }
     $content .= '' . ' </span>' . "\n" . '</div>' . "\n\n" . '<div class="imInfo">' . "\n" . '<span class="imInfoTitle">' . get_lang('Date') . ' : </span>' . "\n" . '<span class="imInfoValue">' . claro_html_localised_date(get_locale('dateTimeFormatLong'), strtotime($message->getSendTime())) . '</span>' . "\n" . '</div>' . "\n\n";
     if (!is_null($message->getCourseCode())) {
         $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Course') . '</span>' . "\n" . ' <span class="imInfoValue">' . "\n";
         $courseData = claro_get_course_data($message->getCourseCode());
         if ($courseData) {
             $content .= claro_htmlspecialchars($courseData['officialCode']) . ' - ' . claro_htmlspecialchars($courseData['name']);
         } else {
             $content .= '?';
         }
         $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         if (!is_null($message->getGroupId())) {
             $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Group') . ' : </span>' . "\n" . ' <span class="imInfoValue">' . "\n";
             $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $message->getCourseCode(), CLARO_CONTEXT_GROUP => $message->getGroupId()));
             if ($groupData) {
                 $content .= $groupData['name'];
             } else {
                 $content .= '?';
             }
             $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         }
         if (!is_null($message->getToolsLabel())) {
             $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Tool') . ' : </span>' . "\n" . ' <span class="imInfoValue">' . "\n";
             $md = get_module_data($message->getToolsLabel());
             if ($md) {
                 $content .= get_lang($md['moduleName']);
             } else {
                 $content .= '?';
             }
             $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         }
     }
     $body = $message->getMessage();
     $body = claro_html_sanitize_all($body);
     $content .= '</div>' . "\n" . '<div class="imContent">' . claro_parse_user_text($body) . '</div>' . "\n" . '</div>' . "\n\n";
     return $content;
 }
Exemplo n.º 3
0
 /**
  * return the current message
  *
  * @return ReceivedMessage the current message
  */
 public function current()
 {
     return ReceivedMessage::fromArray($this->messageList[$this->index]);
 }
Exemplo n.º 4
0
$currentSection = 'inbox';
if (isset($_REQUEST['userId'])) {
    $userId = (int) $_REQUEST['userId'];
} else {
    $userId = claro_get_current_user_id();
}
if ($userId != claro_get_current_user_id() && !claro_is_platform_admin()) {
    claro_die(get_lang("Not allowed"));
}
// load the message
if (is_null($messageId) || is_null($type) || $type != "received" && $type != "sent") {
    claro_die(get_lang('Missing parameter : %param%', array('%param%' => get_lang('message id'))));
}
if ($type == "received") {
    try {
        $message = ReceivedMessage::fromId($messageId, $userId);
        if ($message->isDeleted()) {
            $currentSection = 'trashbox';
        } else {
            $currentSection = 'inbox';
        }
        if ($message === false) {
            claro_die('Message not found');
        }
        if (claro_get_current_user_id() == $userId) {
            $message->markRead();
        }
    } catch (Exeption $e) {
        claro_die(get_lang('Message not found'));
    }
} else {
Exemplo n.º 5
0
     $dialogBox = new DialogBox();
     $dialogBox->error(get_lang("Subject couldn't be empty"));
     $content .= $dialogBox->render();
     $addForm = TRUE;
 } else {
     $message = new MessageToSend(claro_get_current_user_id(), $subject, $message);
     if ($_REQUEST['typeRecipient'] == 'user') {
         $recipient = new SingleUserRecipient($_POST['userRecipient']);
         if (claro_is_in_a_group()) {
             $message->setCourse(claro_get_current_course_id());
             $message->setGroup(claro_get_current_group_id());
         } elseif (claro_is_in_a_course()) {
             $message->setCourse(claro_get_current_course_id());
         } elseif (!empty($_POST['responseTo'])) {
             if (can_answer_message((int) $_POST['responseTo'])) {
                 $messageParent = ReceivedMessage::fromId((int) $_POST['responseTo'], claro_get_current_user_id());
                 if (!is_null($messageParent->getCourseCode())) {
                     $message->setCourse($messageParent->getCourseCode());
                 }
                 if (!is_null($messageParent->getGroupId())) {
                     $message->setGroup($messageParent->getGroupId());
                 }
             } else {
                 claro_die(get_lang('Not allowed'));
             }
         } else {
             //No context to load
         }
     } elseif ($_REQUEST['typeRecipient'] == 'course') {
         $recipient = new CourseRecipient($_POST['courseRecipient']);
         $message->setCourse($_POST['courseRecipient']);