1
all、 私はSugarCRMを新たに取り組んでいます。 InboundMailモジュールでhandleCreateCase関数を更新しました。 このモジュールでは、アクティブユーザに大文字小文字を割り当てる必要があります。 すべてのユーザーがそのケースを処理しているとしますが、彼は会社を辞めて アカウントを無効にしましたが、今度は顧客がケースを再生します。 このケースはそのユーザーに割り当てられていますので、ケースを割り当てる前に確認します。 ユーザーはアクティブですsugarcrmでフォローアップケースをアクティブユーザに割り当てる必要があります
だから私はケースを割り当てる前に、これらのコード、
**// Write The Code for Active User -**
$qry_user = "SELECT status FROM users WHERE id='" . $assign_id . "' LIMIT 1";
$res_user = $this -> db -> query($qry_user, true);
$resultUser = $this -> db -> fetchByAssoc($res_user);
$status = $resultUser['status'];
if($status != 'Active'){
$GLOBALS['log'] -> fatal('Not Active User'. $assign_id);
$qry_db = "SELECT id FROM users WHERE is_group=0 AND deleted = 0 AND status = 'active' ORDER BY RAND() LIMIT 1";
$res_db = $this -> db ->query($qry_db, true);
$fetch_db = $this -> db -> fetchByAssoc($res_db);
if (is_array($fetch_db) && count($fetch_db) > 0) {
$assign_id = $fetch_db['id'];
} else {
$GLOBALS['log'] -> fatal('User Not Present in Users table');
}
}
else{
$assign_id = $assign_id;
}
を書かれています。
は、私は、アクティブなユーザーに割り当てる必要がありますケースをフォローアップのためのコードを書かれているが、それは....これらの私を助けてください動作していないです コード:私はこの問題を解決し
function handleCreateCase($email, $userId) {
global $current_user, $mod_strings, $current_language;
$mod_strings = return_module_language($current_language, "Emails");
$GLOBALS['log']->debug('In handleCreateCase');
$c = new aCase();
$this->getCaseIdFromCaseNumber($email->name, $c);
if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) {
// create a case
$GLOBALS['log']->debug('retrieveing email');
$email->retrieve($email->id);
$c = new aCase();
/*Amol If Have open case from this email*/
$new_case = 1;
//create new case?
$skip_checking = 0;
// skip mailbox for attached into existing case?
$email_from = $email -> from_addr;
$sql = "SELECT c.id FROM cases c INNER JOIN emails e on e.parent_id=c.id INNER JOIN emails_text et on et.email_id=e.id WHERE (c.`status`='New' OR c.`status`='FollowUp' OR c.`status`='PartsReqCompleted') AND et.from_addr LIKE '%" . $email_from . "%' ORDER BY c.date_entered DESC LIMIT 1"; //Amol
$results = $this -> db -> query($sql, true);
$row_c = $this -> db -> fetchByAssoc($results);
$skip_emailboxes = $this -> get_stored_options('create_case_skip_emails', "");
// skip mailboxes
if (!empty($skip_emailboxes)) {
$case_skip_followup_mailboxes_from = explode(',', $skip_emailboxes);
if (in_array($email_from, $case_skip_followup_mailboxes_from)) {
$skip_checking = 1;
}
}
if (strpos((trim(strtolower($email->to_addrs))), "[email protected]") !== false) {
$fixedstring = "CASE";
if(count($row_c) <= 0){
if (strpos($email->name, $fixedstring) !== false) {
list($first_str, $second_str) = explode('[CASE:', $subject);
list($first_string, $second_string) = explode(']', $second_str);
$caseId = $first_string;
$new_case=0; // Already exist case
}else{
$new_case=1; // New Case
}
}
else{
$new_case=1;
}else{
preg_match("/Name:(.*)/", $email -> description, $data);
$mailer_name = trim($data[1]);
$email_sender= $email->reply_to_email;
$sql_acc = "SELECT eabr.bean_id, eabr.bean_module FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address = '$email_sender' AND eabr.bean_module='Accounts'";
$res = $this->db->query($sql_acc);
$id;
while ($row = $GLOBALS['db']->fetchByAssoc($res)) {
$id = $row['bean_id'];
}
if(is_null($id)){
$mailer_name = mysql_escape_string($mailer_name);
$acc_id=create_guid();
$id = $acc_id;
$insert_acc="INSERT INTO `accounts`(`id`, `name`) VALUES ('$acc_id','$mailer_name')";
$this->db->query($insert_acc);
$email_add_id = create_guid();
$email_sender_upper = strtoupper($email_sender);
$insert_emai_add="INSERT INTO `email_addresses`(`id`, `email_address`, `email_address_caps`) VALUES ('$email_add_id','$email_sender','$email_sender_upper')";
$this->db->query($insert_emai_add);
$relation_id = create_guid();
$insert_rel="INSERT INTO `email_addr_bean_rel`(`id`, `email_address_id`, `bean_id`, `bean_module`) VALUES ('$relation_id','$email_add_id','$acc_id','Accounts')";
$this->db->query($insert_rel);
}
$c -> account_id = $id;
}
$c -> description = $email -> description;
/* Asssign Case*/
if ($new_case) {
$createCaseAssignId = $this -> get_stored_options('create_case_user_id', "");
} else {
$createCaseAssignId = '';
}
if (!empty($createCaseAssignId)) {
$case_assign_uids = explode(',', $createCaseAssignId);
//check for last assigned
$query = "SELECT * FROM case_email_quene WHERE mailbox_id = '" . $this -> id . "' LIMIT 1 ";
$results = $this -> db -> query($query, true);
$row = $this -> db -> fetchByAssoc($results);
if (is_array($row) && count($row) > 0) {
if ($row['last_uid'] == end($case_assign_uids)) {
$query = "UPDATE case_email_quene SET last_uid='" . $case_assign_uids[0] . "' WHERE mailbox_id = '" . $this -> id . "' ";
$results = $this -> db -> query($query, true);
$assign_id = $case_assign_uids[0];
} else {// if not end of array
$keys = array_keys($case_assign_uids, $row['last_uid']);
if (is_array($keys) && count($keys) > 0) {//if we have this user selected
$new_key = $keys[0] + 1;
$query = "UPDATE case_email_quene SET last_uid='" . $case_assign_uids[$new_key] . "' WHERE mailbox_id = '" . $this -> id . "' ";
$results = $this -> db -> query($query, true);
$assign_id = $case_assign_uids[$new_key];
} else {// if record was updated
$query = "UPDATE case_email_quene SET last_uid='" . $case_assign_uids[0] . "' WHERE mailbox_id = '" . $this -> id . "' ";
$results = $this -> db -> query($query, true);
$assign_id = $case_assign_uids[0];
}
}
} else {//but if not registered?
$query = "INSERT INTO case_email_quene (mailbox_id,last_uid) VALUES ('" . $this -> id . "','" . $case_assign_uids[0] . "') ";
$results = $this -> db -> query($query, true);
$assign_id = $case_assign_uids[0];
}
//$this->id mailbox id
$GLOBALS['log'] -> fatal('New Case - User Id: ' . $assign_id);
**// Write The Code for Active User -**
$qry_user = "SELECT status FROM users WHERE id='" . $assign_id . "' LIMIT 1";
$res_user = $this -> db -> query($qry_user, true);
$resultUser = $this -> db -> fetchByAssoc($res_user);
$status = $resultUser['status'];
if($status != 'Active'){
$GLOBALS['log'] -> fatal('Not Active User'. $assign_id);
$qry_db = "SELECT id FROM users WHERE is_group=0 AND deleted = 0 AND status = 'active' ORDER BY RAND() LIMIT 1";
$res_db = $this -> db ->query($qry_db, true);
$fetch_db = $this -> db -> fetchByAssoc($res_db);
if (is_array($fetch_db) && count($fetch_db) > 0) {
$assign_id = $fetch_db['id'];
} else {
$GLOBALS['log'] -> fatal('User Not Present in Users table');
}
}
else{
$assign_id = $assign_id;
}
$c -> assigned_user_id = $assign_id;
} elseif ($new_case) {
/*check if database not empty then empty it*/
$query = "SELECT * FROM case_email_quene WHERE mailbox_id = '" . $this -> id . "' LIMIT 1 ";
$results = $this -> db -> query($query, true);
$row_id = $this -> db -> fetchByAssoc($results);
if (is_array($row_id) && count($row_id) > 0) {
$query = "DELETE FROM case_email_quene WHERE mailbox_id = '" . $this -> id . "' ";
$results = $this -> db -> query($query, true);
}
$GLOBALS['log'] -> fatal('Existing Case - User Id: ' . $userId);
$c -> assigned_user_id = $userId;
}