2017-10-04 6 views
1

모두 저는 SugarCRM에서 새롭게 일하고 있습니다. InboundMail 모듈에서 handleCreateCase 함수를 업데이트했습니다. 이 모듈에서는 활성 사용자에게 대소 문자를 할당해야합니다. 모든 사용자가 사례를 처리하고 있다고 가정하지만 이제 그는 회사를 떠나 Google 계정을 비활성화 했으므로 고객이 사례를 재생할 것입니다. 사례를 할당하기 전에 확인하기 위해이 사용자를이 사용자로 할당합니다. 사용자가 활성 상태인지 아닌지 후속 사례가 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; 

        }   

답변

1

,

코드를 handleCaseAssignment()에 입력하십시오.

function handleCaseAssignment($email) { 
    $c = new aCase(); 
    if ($caseId = $this -> getCaseIdFromCaseNumber($email -> name, $c)) { 
     $c -> retrieve($caseId); 
     if (($c -> status == "Closed") || ($c -> status == "Rejected")) {//Amol 
      $c -> status = "ReOpened"; 
     } else { 
      $c -> status = "FollowUp"; 
     } 
     $c -> save(); 

     $email -> retrieve($email -> id); 
     //assign the case info to parent id and parent type so that the case can be linked to the email on Email Save 
     $email -> parent_type = "Cases"; 
     $email -> parent_id = $caseId; 
     // assign the email to the case owner 

     $GLOBALS['log'] -> fatal('Case - cassigned_user_id11: ' . $c->assigned_user_id); 
     $GLOBALS['log'] -> fatal('Case - caseId Id11: ' . $caseId); 
     $GLOBALS['log'] -> fatal('emailid11: ' . $email->id); 
      $qry_user = "SELECT status FROM users WHERE id='" . $c->assigned_user_id . "' LIMIT 1"; 
      $res_user = $this -> db -> query($qry_user, true); 
      $resultUser = $this -> db -> fetchByAssoc($res_user); 
      $status = $resultUser['status']; 
      if($status != 'Active'){ 
       $qry_db = "SELECT id FROM users WHERE is_group=0 AND deleted = 0 AND status = 'active' AND department='CS' 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) { 
        $email->assigned_user_id = $fetch_db['id']; 
        $c -> assigned_user_id = $email->assigned_user_id; 
        $c -> save(); 
       } else { 
        $GLOBALS['log'] -> fatal('User Not Present in Users table'); 
       } 
      } 
      else{ 
       $email->assigned_user_id = $c->assigned_user_id; 

     //$email->assigned_user_id = $c->assigned_user_id; 
     $email->save(); 
     $GLOBALS['log']->debug('InboundEmail found exactly 1 match for a case: '.$c->name); 
     return true; 
    } // if 
    return false; 
} // fn