| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Initial Developer of the Original Code is FOSS Labs. 6 * Portions created by FOSS Labs are Copyright (C) FOSS Labs. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 require_once ('modules/Emails/Emails.php'); 13 require_once ('modules/Webmails/Webmail.php'); 14 require_once ('include/logging.php'); 15 require_once ('include/database/PearDatabase.php'); 16 require_once ('include/utils/UserInfoUtil.php'); 17 require_once ('include/utils/CommonUtils.php'); 18 require_once ('modules/Webmails/MailParse.php'); 19 require_once ('modules/Webmails/MailBox.php'); 20 global $current_user; 21 22 $local_log =& LoggerManager::getLogger('index'); 23 $focus = new Emails(); 24 25 $to_address = explode(";",$_REQUEST['to_list']); 26 $cc_address = explode(";",$_REQUEST['cc_list']); 27 $bcc_address = explode(";",$_REQUEST['bcc_list']); 28 29 $start_message=$_REQUEST["start_message"]; 30 if($_REQUEST["mailbox"] && $_REQUEST["mailbox"] != "") {$mailbox=$_REQUEST["mailbox"];} else {$mailbox="INBOX";} 31 32 $MailBox = new MailBox($mailbox); 33 $email = new Webmail($MailBox->mbox, $_REQUEST["mailid"]); 34 $subject = $email->subject; 35 $date = $email->date; 36 37 $email->loadMail(); 38 $msgData = $email->body; 39 40 $focus->column_fields['subject']=$subject; 41 $focus->column_fields["activitytype"]="Emails"; 42 43 $ddate = date("Y-m-d"); 44 $dtime = date("h:m"); 45 $focus->column_fields["assigned_user_id"]=$current_user->id; 46 $focus->column_fields["date_start"]=$ddate; 47 $focus->column_fields["time_start"]=$dtime; 48 49 //$tmpBody = preg_replace(array('/<br(.*?)>/i',"/>/i","/</i","/ /i","/&/i","/©/i","/<style(.*?)>(.*?)<\/style>/i","/\{(.*?)\}/i","/BODY/i"),array("\r",">","<"," ","&","(c)","","",""),$msgData); 50 //$focus->column_fields["description"]=strip_tags($tmpBody); 51 $focus->column_fields["description"]=$msgData; 52 53 54 //to save the email details in vtiger_emaildetails vtiger_tables 55 $fieldid = $adb->query_result($adb->query('select fieldid from vtiger_field where tablename="contactdetails" and fieldname="email" and columnname="email"'),0,'fieldid'); 56 57 if($email->relationship != 0) { 58 $focus->column_fields['parent_id']=$email->relationship["id"].'@'.$fieldid.'|'; 59 60 if($email->relationship["type"] == "Contacts") 61 add_attachment_to_contact($email->relationship["id"],$email); 62 }else { 63 //if relationship is not available create a contact and relate the email to the contact 64 require_once ('modules/Contacts/Contacts.php'); 65 $contact_focus = new Contacts(); 66 $contact_focus->column_fields['lastname'] =$email->fromname; 67 $contact_focus->column_fields['email'] = $email->from; 68 $contact_focus->save("Contacts"); 69 $focus->column_fields['parent_id']=$contact_focus->id.'@'.$fieldid.'|'; 70 71 add_attachment_to_contact($contact_focus->id,$email); 72 } 73 74 function add_attachment_to_contact($cid,$email) { 75 // add vtiger_attachments to contact 76 global $adb,$current_user; 77 for($j=0;$j<2;$j++) { 78 if($j==0) 79 $attachments=$email->downloadAttachments(); 80 else 81 $attachments=$email->downloadInlineAttachments(); 82 83 $upload_filepath = decideFilePath(); 84 for($i=0,$num_files=count($attachments);$i<$num_files;$i++) { 85 $current_id = $adb->getUniqueID("vtiger_crmentity"); 86 $date_var = $adb->formatDate(date('YmdHis')); 87 88 $filename = ereg_replace("[ ()-]+", "_",$attachments[$i]["filename"]); 89 $filetype= substr($filename,strstr($filename,"."),strlen($filename)); 90 $filesize = $attachments[$i]["filesize"]; 91 92 $query = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime) values('"; 93 $query .= $current_id."','".$current_user->id."','".$current_user->id."','Contacts Attachment','Uploaded from webmail during qualification',".$date_var.")"; 94 $result = $adb->query($query); 95 96 $sql = "insert into vtiger_attachments values("; 97 $sql .= $current_id.",'".$filename."','Uploaded ".$filename." from webmail','".$filetype."','".$upload_filepath."')"; 98 echo $query; 99 $result = $adb->query($sql); 100 101 $sql1 = "insert into vtiger_seattachmentsrel values('"; 102 $sql1 .= $cid."','".$current_id."')"; 103 $result = $adb->query($sql1); 104 105 $fp = fopen($upload_filepath.'/'.$filename, "w") or die("Can't open file"); 106 fputs($fp, base64_decode($attachments[$i]["filedata"])); 107 fclose($fp); 108 } 109 } 110 } 111 112 $_REQUEST['parent_id'] = $focus->column_fields['parent_id']; 113 $focus->save("Emails"); 114 115 //saving in vtiger_emaildetails vtiger_table 116 $id_lists = $focus->column_fields['parent_id'].'@'.$fieldid; 117 $all_to_ids = $email->from; 118 $query = 'insert into vtiger_emaildetails values ('.$focus->id.',"","'.$all_to_ids.'","","","","'.$id_lists.'","WEBMAIL")'; 119 $adb->query($query); 120 121 $return_id = $_REQUEST["mailid"]; 122 $return_module='Webmails'; 123 $return_action='ListView'; 124 125 126 if($_POST["ajax"] != "true") 127 header("Location: index.php?action=$return_action&module=$return_module&record=$return_id"); 128 129 return; 130 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |