mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-24 15:56:22 +00:00
added mail_handler class (from Botanic) still needs to be reworked + added show queue template
This commit is contained in:
parent
4041be72f3
commit
a3f9e44c0c
3 changed files with 479 additions and 1 deletions
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
function oms_mail_send($recipient, $subject, $body, $from = NULL) {
|
||||
|
||||
if(is_numeric($recipient)) {
|
||||
$id_user = $recipient;
|
||||
$recipient = NULL;
|
||||
}
|
||||
db_insert('email', array('recipient' => $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'id_user' => $id_user, 'sender' => $from));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_mail_cron() {
|
||||
|
||||
$oms_inbox_username = '123';
|
||||
$oms_inbox_password = '456';
|
||||
$oms_host = 'test.com';
|
||||
$oms_reply_to = "OMS <oms@".$oms_host.">";
|
||||
global $basedir;
|
||||
|
||||
// Deliver new mail
|
||||
echo("mail cron\n");
|
||||
|
||||
//TO ASK:
|
||||
$pid = oms_fork();
|
||||
$pidfile = '/tmp/oms_cron_email_pid';
|
||||
|
||||
if($pid) {
|
||||
|
||||
// We're the main process.
|
||||
|
||||
} else {
|
||||
|
||||
if(!file_exists($pidfile)) {
|
||||
|
||||
$pid = getmypid();
|
||||
$file = fopen($pidfile, 'w');
|
||||
fwrite($file, $pid);
|
||||
fclose($file);
|
||||
$emails = db_query("select * from email where status = 'NEW' or status = 'FAILED'");
|
||||
|
||||
foreach($emails as $email) {
|
||||
$message_id = oms_new_message_id();
|
||||
echo("Emailing {$email['recipient']}\n");
|
||||
if(!$email['recipient']) {
|
||||
$email['recipient'] = oms_get_email_by_user_id($email['id_user']);
|
||||
}
|
||||
|
||||
if($email['sender']) {
|
||||
$username = oms_get_username_from_id($email['sender']);
|
||||
$from = "$username <$username@$oms_host>";
|
||||
} else {
|
||||
$from = $oms_reply_to;
|
||||
}
|
||||
$headers = "From: $from\r\n" . "Message-ID: " . $message_id;
|
||||
|
||||
if(mail($email['recipient'], $email['subject'], $email['body'], $headers)) {
|
||||
$status = "DELIVERED";
|
||||
echo("Emailed {$email['recipient']}\n");
|
||||
} else {
|
||||
$status = "FAILED";
|
||||
echo("Email to {$email['recipient']} failed\n");
|
||||
}
|
||||
db_exec('update email set status = ?, message_id = ?, attempts = attempts + 1 where id_email = ?', array($status, $message_id, $email['id_email']));
|
||||
}
|
||||
unlink($pidfile);
|
||||
}
|
||||
// Check mail
|
||||
|
||||
//$mailbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $oms_inbox_username, $oms_inbox_password);
|
||||
$mbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $oms_inbox_username, $oms_inbox_password);
|
||||
$message_count = imap_num_msg($mbox);
|
||||
|
||||
for ($i = 1; $i <= $message_count; ++$i) {
|
||||
$header = imap_header($mbox, $i);
|
||||
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
|
||||
$subject = decode_utf8($header->subject);
|
||||
$to = $header->to[0]->mailbox;
|
||||
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
|
||||
$txt = get_part($mbox, $i, "TEXT/PLAIN");
|
||||
$html = get_part($mbox, $i, "TEXT/HTML");
|
||||
//return task ID
|
||||
$tid = oms_create_email($from, $subject, $txt, $html, $to, $from);
|
||||
|
||||
if($tid) {
|
||||
$file = fopen("$basedir/mail/$tid", 'w');
|
||||
fwrite($file, $entire_email);
|
||||
fclose($file);
|
||||
}
|
||||
imap_delete($mbox, $i);
|
||||
}
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_new_message_id() {
|
||||
|
||||
$time = time();
|
||||
$pid = getmypid();
|
||||
global $oms_mail_count;
|
||||
$oms_mail_count = ($oms_mail_count == '') ? 1 : $oms_mail_count + 1;
|
||||
return "<oms.message.$pid.$oms_mail_count.$time@dev1.dev.subrigo.net>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_create_email($from, $subject, $body, $html, $recipient = 0, $sender = NULL) {
|
||||
|
||||
if($recipient == 0 && !is_string($recipient)) {
|
||||
global $user;
|
||||
$recipient = $user->uid;
|
||||
}
|
||||
|
||||
if($sender !== NULL && !is_numeric($sender)) $sender = oms_get_id_from_username($sender);
|
||||
if(!is_numeric($recipient)) $recipient = oms_get_id_from_username($recipient);
|
||||
|
||||
oms_error_log("Sending message: '$subject' from $sender to $recipient", 3);
|
||||
|
||||
$message = array(
|
||||
'creator' => $sender,
|
||||
'owner' => $recipient,
|
||||
'id_module' => 'email',
|
||||
'type' => 'email',
|
||||
'summary' => $subject,
|
||||
'data' => array (
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'html' => $html,
|
||||
'sender' => oms_get_username_from_id($sender),
|
||||
'from' => $from,
|
||||
'recipient' => oms_get_username_from_id($recipient),
|
||||
'time' => time(),
|
||||
),
|
||||
);
|
||||
|
||||
//TO ASK:
|
||||
oms_task_create($message);
|
||||
oms_task_index($message, array('subject', 'body', 'sender', 'recipient'));
|
||||
//---------------------------
|
||||
return $message['id_task'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_get_email($id) {
|
||||
|
||||
$message = oms_task_load($id);
|
||||
if($message) {
|
||||
oms_prepare_email($message);
|
||||
return $message;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_prepare_email(&$message) {
|
||||
|
||||
$data = $message['data'];
|
||||
$data['id_message'] = $message['id_task'];
|
||||
$data['read'] = ($message['status'] != 'NEW' && $message['status'] != 'UNREAD');
|
||||
$message = $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function oms_email_mark_read($mid) {
|
||||
|
||||
db_exec("update task set status = 'READ' where id_task = ? and type = 'email' and module = 'email'", array($mid));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function decode_utf8($str) {
|
||||
|
||||
preg_match_all("/=\?UTF-8\?B\?([^\?]+)\?=/i",$str, $arr);
|
||||
for ($i=0;$i<count($arr[1]);$i++){
|
||||
$str=ereg_replace(ereg_replace("\?","\?",
|
||||
$arr[0][$i]),base64_decode($arr[1][$i]),$str);
|
||||
}
|
||||
return $str;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function get_mime_type(&$structure) {
|
||||
|
||||
$primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER");
|
||||
if($structure->subtype) {
|
||||
return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype;
|
||||
}
|
||||
return "TEXT/PLAIN";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) {
|
||||
|
||||
if(!$structure) {
|
||||
$structure = imap_fetchstructure($stream, $msg_number);
|
||||
}
|
||||
|
||||
if($structure) {
|
||||
if($mime_type == get_mime_type($structure)) {
|
||||
if(!$part_number) {
|
||||
$part_number = "1";
|
||||
}
|
||||
$text = imap_fetchbody($stream, $msg_number, $part_number);
|
||||
if($structure->encoding == 3) {
|
||||
return imap_base64($text);
|
||||
} else if($structure->encoding == 4) {
|
||||
return imap_qprint($text);
|
||||
} else {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
if($structure->type == 1) /* multipart */ {
|
||||
while(list($index, $sub_structure) = each($structure->parts)) {
|
||||
if($part_number) {
|
||||
$prefix = $part_number . '.';
|
||||
} else {
|
||||
$prefix = '';
|
||||
}
|
||||
$data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1));
|
||||
if($data) {
|
||||
return $data;
|
||||
}
|
||||
} // END OF WHILE
|
||||
} // END OF MULTIPART
|
||||
} // END OF STRUTURE
|
||||
return false;
|
||||
|
||||
} // END OF FUNCTION
|
||||
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
{block name=content}
|
||||
<tr><td>
|
||||
<table width="100%" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr bgcolor="{$second_menu_bg_color}" valign="middle">
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<table cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td valign="middle" nowrap><a href="index.php?page=show_queue&get=todo">Todo tickets</a></td>
|
||||
<td valign="middle" nowrap><a href="index.php?page=show_queue&get=all">All tickets</a></td>
|
||||
<td valign="middle" nowrap><a href="index.php?page=show_queue&get=all_open">All open tickets</a></td>
|
||||
<td valign="middle" nowrap><a href="index.php?page=show_queue&get=archive">Ticket Archive</a></td>
|
||||
<td valign="middle" nowrap><a href="index.php?page=show_queue&get=not_assigned">Not Assigned Tickets</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="3" bgcolor="#000000"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
|
||||
<tr><td>
|
||||
<table width="100%" bgcolor="{$title_bg_color}" cellspacing="2">
|
||||
<tr><td height="7"></td><td></td></tr>
|
||||
<tr>
|
||||
<td width="3%"></td>
|
||||
<td width="100%" height="12" valign="middle"><h1>Ticket Queue: {$queue_view}</h1></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="5"></td><td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<table width="100%" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr bgcolor="#000000" valign="middle">
|
||||
<td>
|
||||
<table>
|
||||
<tr><td height="8"></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td height="2"></td></tr>
|
||||
<tr><td height="1" bgcolor="#000000"></td></tr>
|
||||
<tr><td height="10"></td></tr>
|
||||
<tr valign="middle">
|
||||
<td>
|
||||
<table width="100%" height="100%" cellpadding="10">
|
||||
<tr><td>
|
||||
<table width="100%" bgcolor="{$main_tbl_color}" border="2">
|
||||
<tr><td>
|
||||
<table width="100%" cellpadding="10">
|
||||
<tr><td>
|
||||
<p><h3>Tickets</h3></p>
|
||||
<p>
|
||||
<form id="create_queue" method="post" action="index.php?page=show_queue&get=create">
|
||||
<table width="100%" bgcolor="#00000060" border="1">
|
||||
<tr>
|
||||
<td width="5"></td>
|
||||
<td valign="middle"> Show </td>
|
||||
<td>
|
||||
<select size ="100" name="what">
|
||||
<option value="all" {if $prev_created_what eq "all"}selected="selected"{/if}>all</option>
|
||||
<option value="waiting_for_support" {if $prev_created_what eq "waiting_for_support"}selected="selected"{/if}>waiting for support</option>
|
||||
<option value="waiting_for_users" {if $prev_created_what eq "waiting_for_users"}selected="selected"{/if}>waiting for user</option>
|
||||
<option value="closed" {if $prev_created_what eq "closed"}selected="selected"{/if}>closed</option>
|
||||
</select>
|
||||
</td>
|
||||
<td valign="middle"> tickets </td>
|
||||
<td>
|
||||
<select style="width: 110px;" name="how">
|
||||
<option value="assigned" {if $prev_created_how eq "assigned"}selected="selected"{/if}>assigned</option>
|
||||
<option value="not_assigned" {if $prev_created_how eq "not_assigned"}selected="selected"{/if}>not assigned</option>
|
||||
</select>
|
||||
</td>
|
||||
<td valign="middle"> to </td>
|
||||
<td>
|
||||
<select style="width: 140px;" name="who" onchange="aimedforwhochanged(this.value);">
|
||||
<option value="user" {if $prev_created_who eq "user"}selected="selected"{/if}>user</option>
|
||||
<option value="support_group" {if $prev_created_who eq "support_group"}selected="selected"{/if}>Group</option>
|
||||
</select>
|
||||
</td>
|
||||
<td valign="middle">:</td>
|
||||
<td>
|
||||
<select style="width: 140px;" name="userid">
|
||||
<option>select user</option>
|
||||
{foreach from=$teamlist item=member}
|
||||
<option value="{$member.tUserId}" {if $prev_created_userid eq $member.tUserId}selected="selected"{/if}>{$member.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td valign="middle"> or </td>
|
||||
<td>
|
||||
<select style="width: 140px;" name="groupid">
|
||||
<option>select group</option>
|
||||
{foreach from=$grouplist item=group}
|
||||
<option value="{$group.sGroupId}" {if $prev_created_groupid eq $group.sGroupId}selected="selected"{/if}>{$group.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td valign="middle">
|
||||
<input type="hidden" name="action" value="create_queue">
|
||||
<input type="submit" value="View"/>
|
||||
</td>
|
||||
<td width="30%"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</p>
|
||||
<p>
|
||||
<table width="100%" cellpadding="4" cellspacing="2">
|
||||
<tr bgcolor="{$table_header_tr_color}">
|
||||
<td>ID</td>
|
||||
<td>Title</td>
|
||||
<td>Assigned</td>
|
||||
<td>Timestamp</td>
|
||||
<td>Category</td>
|
||||
<td>Status</td>
|
||||
<td>SupportGroup</td>
|
||||
<td>Actions</td>
|
||||
</tr>
|
||||
{foreach from=$tickets item=ticket}
|
||||
<tr>
|
||||
<td>{$ticket.tId}</td>
|
||||
<td><a href ="index.php?page=show_ticket&id={$ticket.tId}">{$ticket.title}</a></td>
|
||||
<td>{if $ticket.assignedText neq ""} <a href="index.php?page=show_user&id={$ticket.assigned}">{$ticket.assignedText}</a>{else} {$not_assigned} {/if}</td>
|
||||
<td class="center"><span title="{$ticket.timestamp_elapsed}" data-rel="tooltip" data-placement="right">{$ticket.timestamp}</span></td>
|
||||
<td class="center">{$ticket.category}</td>
|
||||
<td class="center">{if $ticket.status eq 0}<font color="green">{else if $ticket.status eq 1}<font color="orange">{else if $ticket.status eq 2}<font color="red">{/if}{$ticket.statusText}</font></td>
|
||||
<td class="center">
|
||||
|
||||
{if $ticket.forwardedGroupName eq "0"}
|
||||
{$public_sgroup}
|
||||
{else}
|
||||
<a href="index.php?page=show_sgroup&id={$ticket.forwardedGroupId}">{$ticket.forwardedGroupName}</a>
|
||||
{/if}
|
||||
|
||||
</td>
|
||||
<td>
|
||||
{if $ticket.assigned eq 0}
|
||||
<form id="assign_ticket" class="form-vertical" method="post" action="index.php?page=show_queue&get=todo" style="margin:0px 0px 0px;">
|
||||
<input type="hidden" name="ticket_id" value="{$ticket.tId}">
|
||||
<input type="hidden" name="action" value="assignTicket">
|
||||
<input type="submit" value="Assign Ticket"/>
|
||||
</form>
|
||||
{else if $ticket.assigned eq $user_id}
|
||||
<form id="assign_ticket" class="form-vertical" method="post" action="index.php?page=show_queue&get=todo" style="margin:0px 0px 0px;">
|
||||
<input type="hidden" name="ticket_id" value="{$ticket.tId}">
|
||||
<input type="hidden" name="action" value="unAssignTicket">
|
||||
<input type="submit" value="Remove Assign"/>
|
||||
</form>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
</p>
|
||||
</td></tr>
|
||||
<tr><td align = "center">
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="{$pagination_base_link}&pagenum=1">«</a></td>
|
||||
{foreach from=$links item=link}
|
||||
<td {if $link == $currentPage}bgcolor="{$pagination_current_page_bg}"{/if}><a href="{$pagination_base_link}&pagenum={$link}">{$link}</a></td>
|
||||
{/foreach}
|
||||
<td><a href="{$pagination_base_link}&pagenum={$lastPage}">»</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
{if isset($ACTION_RESULT)}
|
||||
<tr><td>
|
||||
<table width="100%" bgcolor="{$main_tbl_color}" border="1">
|
||||
<tr><td height="4"></td></tr>
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
{if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_ASSIGNED"}
|
||||
<p>
|
||||
<font color="green">{$success_assigned}</font>
|
||||
</p>
|
||||
{else if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_UNASSIGNED"}
|
||||
<p>
|
||||
<font color="green">{$success_unassigned}</font>
|
||||
</p>
|
||||
{else if isset($ACTION_RESULT) and $ACTION_RESULT eq "TICKET_NOT_EXISTING"}
|
||||
<p>
|
||||
<font color="red">{$ticket_not_existing}</font>
|
||||
</p>
|
||||
{else if isset($ACTION_RESULT) and $ACTION_RESULT eq "ALREADY_ASSIGNED"}
|
||||
<p>
|
||||
<font color="red">{$ticket_already_assigned}</font>
|
||||
</p>
|
||||
{else if isset($ACTION_RESULT) and $ACTION_RESULT eq "NOT_ASSIGNED"}
|
||||
<p>
|
||||
<font color="red">{$ticket_not_assigned}</font>
|
||||
</p>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td height="4"></td></tr>
|
||||
<table>
|
||||
</td></tr>
|
||||
{/if}
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td></tr>
|
||||
|
||||
{/block}
|
||||
|
|
@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib';
|
|||
$cfg['db']['lib']['user'] = 'shard';
|
||||
$cfg['db']['lib']['pass'] = '';
|
||||
|
||||
$cfg['db']['shard']['host'] = 'localhosti';
|
||||
$cfg['db']['shard']['host'] = 'localhost';
|
||||
$cfg['db']['shard']['port'] = '3306';
|
||||
$cfg['db']['shard']['name'] = 'nel';
|
||||
$cfg['db']['shard']['user'] = 'shard';
|
||||
|
@ -31,6 +31,10 @@ $cfg['db']['ring']['name'] = 'ring_open';
|
|||
$cfg['db']['ring']['user'] = 'shard';
|
||||
$cfg['db']['ring']['pass'] = '';
|
||||
|
||||
$cfg['mail']['username'] = '123';
|
||||
$cfg['mail']['password'] = '456';
|
||||
$cfg['mail']['host'] = 'test.com';
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// If true= the server will add automatically unknown user in the database
|
||||
// (in nel.user= nel.permission= ring.ring_user and ring.characters
|
||||
|
|
Loading…
Reference in a new issue