<?php function get_message_sender_name_dataset($msg,$msg_attribs) { $dataset=array(); $dataset['SENDER-'.$msg['msg_from_as']]=array(0); $dataset[$msg['msg_from_as']]=array(0); if ($msg['mb_id_from']) { switch ($msg['msg_from_as']) { case 'MEMBER': $dataset['sender.name']=$msg['mb_nickname_from']; break; case 'COMPERE': $dataset['sender.name']=$msg['cp_name_from']; break; default: trigger_error("Invalid `msg_from_as` with non-NULL `mb_id_from`.",E_USER_WARNING); $dataset['sender.name']=$msg['mb_nickname_from']; } } else { $dataset['sender.name']=$msg_attribs['sender.name']; } return $dataset; } function get_message_receiver_name_dataset($msg,$msg_attribs) { $dataset=array(); $dataset['RECEIVER-'.$msg['msg_to_as']]=array(0); $dataset[$msg['msg_to_as']]=array(0); if ($msg['mb_id_to']) { switch ($msg['msg_to_as']) { case 'MEMBER': $dataset['receiver.name']=$msg['mb_nickname_to']; break; case 'COMPERE': $dataset['receiver.name']=$msg['cp_name_to']; break; default: trigger_error("Invalid `msg_to_as` with non-NULL `mb_id_to`.",E_USER_WARNING); $dataset['receiver.name']=$msg['mb_nickname_to']; } } else { $dataset['receiver.name']=$msg_attribs['receiver.name']; } return $dataset; } function send_message( $dbconn, $msg_type, $mb_id_from, $msg_from_as, $mb_id_tos, $msg_to_ases, $text=false, $brief=false, $related_info=array(), $msg_attribs=array()) { global $Config; $mb_id_tos=db_get_canonical_member_ids($dbconn,$mb_id_tos); $file_id=db_insert_file($dbconn,$text,$brief); $msg_id_least=db_insert_message($dbconn,$msg_type,$mb_id_from,$msg_from_as,$mb_id_tos,$msg_to_ases,$file_id,$related_info); $msg_ids=db_load_message_ids($dbconn,$msg_id_least,$file_id); foreach ($msg_attribs as $prop=>$value) if ($value) db_set_message_attrib($dbconn,$msg_ids,$prop,$value); if (!$mb_id_tos && $related_info['msg_id_replyto']) { $to_attribs=db_get_message_attrib($dbconn,$related_info['msg_id_replyto']); $to_info=rowset2map($to_attribs,'msga_prop','msga_value'); if ($to_info['sender.email']) { db_set_message_attrib($dbconn,$msg_ids,'receiver.name',$to_info['sender.name']); db_set_message_attrib($dbconn,$msg_ids,'receiver.email',$to_info['sender.email']); $msglist=db_load_messages($dbconn,$msg_id_least); $dataset=get_message_sender_name_dataset($msglist[0],$msg_attribs); if ($related_info['msg_lctr_id']) { $dataset['LECTURE']=array(0); $dataset['REFERENCE']=array(0); } else { $dataset['COURSE']=array(0); $dataset['REFERENCE']=array(0); } $dataset+=$related_info; $dataset['subject']=$brief; $dataset['content']=$text; $dataset['server.domain']=$Config->SERVER_DOMAIN; $dataset['ROOT-URL']='http'.(is_https()?'s':'').'://'.$Config->SERVER_DOMAIN; $mailcontent=prepare_email_from_templates('toguest.email.subject','toguest.email.content',$dataset); sendmail($Config->MailerAddress,$to_info['sender.email'],$mailcontent['subject'],$mailcontent['body']); } } else if ($mb_id_tos) { $mb_emails=db_load_notifying_emails($dbconn,$mb_id_tos); $msglist=db_load_messages($dbconn,$msg_id_least); $dataset=get_message_sender_name_dataset($msglist[0],$msg_attribs); $dataset['server.domain']=$Config->SERVER_DOMAIN; $dataset['ROOT-URL']='http'.(is_https()?'s':'').'://'.$Config->SERVER_DOMAIN; $mailcontent=prepare_email_from_templates('newmessage.email.subject','newmessage.email.content',$dataset); $to=array_projection($mb_emails,'mb_email'); if ($to) sendmail($Config->MailerAddress,$to,$mailcontent['subject'],$mailcontent['body']); } return array('msg_id_least'=>$msg_id_least,'file_id'=>$file_id,'msg_ids'=>$msg_ids); } function prepare_message_from_display_type($msg,$mb_id_current) { $dataset=array(); switch ($msg['msg_type']) { case 'INVITE': $dataset['INVITE']=array(0); break; case 'INQUIRY': $dataset['INQUIRY']=array(0); break; case 'RESERVE': $dataset['RESERVE']=array(0); break; case 'CANCEL': $dataset['CANCEL']=array(0); break; case 'REPLY': $dataset['REPLY']=array(0); break; case 'DECLINE': $dataset['DECLINE']=array(0); break; case 'MESSAGE': $dataset['MESSAGE']=array(0); break; } if ($mb_id_current) { if ($mb_id_current==$msg['mb_id_from']) { $dataset['READ']=$msg['msg_read_from']?array(0):array(); $dataset['UNREAD']=$msg['msg_read_from']?array():array(0); } else if ($mb_id_current==$msg['mb_id_to']) { $dataset['READ']=$msg['msg_read_to']?array(0):array(); $dataset['UNREAD']=$msg['msg_read_to']?array():array(0); } } $dataset['HAS-DECISION']=$msg['msg_decision']?array(0):array(); $dataset['DECISION-ACCEPT']=$msg['msg_decision']=='ACCEPT'?array(0):array(); $dataset['DECISION-DENY']=$msg['msg_decision']=='DENY'?array(0):array(); return $dataset; } function update_unread_message_count($DBConn,$mb_id) { global $Config; $msg_count=db_count_messages($DBConn,null,$mb_id); $_SESSION['reserv.status']['unread_msg_count'][$mb_id]=$msg_count; SET_COOKIE('reserv_message_count_still_valid','1',$Config->MessageCountLifetime); } function get_unread_message_count() { return $_SESSION['reserv.status']['unread_msg_count'][current_mb_id()]; } ?>