Files
crm.e5.pl/modules/EcmDocuments/SendAttachment.php

224 lines
12 KiB
PHP
Raw Normal View History

2024-04-27 09:23:34 +02:00
<?
require_once("../../config.php");
require_once("dirstree.php");
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
mysql_query("set charaecterset utf8");
if($_POST['send'])
{
$name=explode("/",$_GET['file']);
$nn=$name[count($name)-1];
function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false)
{
$eol="\r\n";
$mime_boundary=md5(time());
# Common Headers
$headers .= 'From: E5<'.$fromaddress.'>'.$eol;
$headers .= 'Reply-To: E5<'.$fromaddress.'>'.$eol;
$headers .= 'Return-Path: E5<'.$fromaddress.'>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
# File for Attachment
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
fclose($handle);
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
}
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-2".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-2".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
}
# To Email Address
$emailaddress=$_POST['email'];
# From Email Address
$fromaddress = "kl@e5.pl";
# Message Subject
$emailsubject=iconv("UTF-8","ISO-8859-2",$_POST['subject']);
# Use relative paths to the attachments
$attachments = array(
Array("file"=>$_GET['file'], "content_type"=>"application/pdf")
);
# Message Body
$body=iconv("UTF-8","ISO-8859-2",$_POST['body']);
send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments);
print "<script language='javascript'>location.href='index.php?module=Quotes&action=DetailView&record=".$_REQUEST['record']."';</script>";
}
?>
<!--
/*********************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version
* 1.1.3 ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* All copies of the Covered Code must include on each user interface screen:
* (i) the "Powered by SugarCRM" logo and
* (ii) the SugarCRM copyright notice
* in the same form as they appear in the distribution. See full license for
* requirements.
*
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
-->
<script type="text/javascript" src="include/javascript/cookie.js?s=4.5.0g&c="></script><link rel="stylesheet" type="text/css" media="all" href="../../themes/Sugar/calendar-win2k-cold-1.css?s=4.5.0g&c="><script>jscal_today = 1.195210724E+012; if(typeof app_strings == "undefined") app_strings = new Array();</script><script type="text/javascript" src="jscalendar/calendar.js?s=4.5.0g&c="></script><script type="text/javascript" src="jscalendar/lang/calendar-en.js?s=4.5.0g&c="></script><script type="text/javascript" src="jscalendar/calendar-setup_3.js?s=4.5.0g&c="></script><script src="include/javascript/yui/YAHOO.js?s=4.5.0g&c="></script><script src="include/javascript/yui/log.js?s=4.5.0g&c="></script><script src="include/javascript/yui/dom.js?s=4.5.0g&c="></script><script src="include/javascript/yui/event.js?s=4.5.0g&c="></script><script src="include/javascript/yui/animation.js?s=4.5.0g&c="></script><script src="include/javascript/yui/connection.js?s=4.5.0g&c="></script><script src="include/javascript/yui/dragdrop.js?s=4.5.0g&c="></script><script src="include/javascript/yui/ygDDList.js?s=4.5.0g&c="></script><script type="text/javascript" src="include/javascript/sugar_3.js?s=4.5.0g&c="></script><script type="text/javascript">
var time_reg_format = '([0-9]{1,2}):([0-9]{1,2})';
var date_reg_format = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})';
var date_reg_positions = {'Y': 1,'m': 2,'d': 3};
var time_separator = ':';
var cal_date_format = '%Y-%m-%d';
var time_offset = 0;
</script><script type="text/javascript" src="cache/jsLanguage/en_us.js?s=4.5.0g&c=&j=3"></script><script type="text/javascript" src="cache/jsLanguage/Contracts/en_us.js?s=4.5.0g&c=&j=3"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN">
<html >
<style type="text/css">
<!--
body {
margin-left: 20px;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 20px;
}
-->
</style><head >
<link REL="SHORTCUT ICON" HREF="include/images/sugar_icon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SugarCRM - Commercial Open Source CRM</title>
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/navigation.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/style.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/colors.sugar.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/fonts.normal.css?s=4.5.0g&c=" />
<link href="../../themes/Sugar/colors.sugar.css?s=4.5.0g&c=" rel="stylesheet" type="text/css" title="color:sugar" />
<link href="../../themes/Sugar/colors.blue.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:blue" />
<link href="../../themes/Sugar/colors.green.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:green" />
<link href="../../themes/Sugar/colors.purple.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:purple" />
<link href="../../themes/Sugar/colors.ocher.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:ocher" />
<link href="../../themes/Sugar/fonts.normal.css?s=4.5.0g&c=" rel="stylesheet" type="text/css" title="font:normal" />
<link href="../../themes/Sugar/fonts.larger.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="font:larger" />
<link href="../../themes/Sugar/fonts.largest.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="font:largest" />
<script language="javascript" src="../../themes/Sugar/menu.js?s=4.5.0g&c="></script>
<script language="javascript" src="../../themes/Sugar/cookie.js?s=4.5.0g&c="></script>
<script language="javascript" src="../../themes/Sugar/style.js?s=4.5.0g&c="></script>
</head>
<body onLoad="<?if($ok=="ok")print "window.close();";?>">
<script type="text/javascript" src="include/javascript/popup_parent_helper.js?s=4.5.0g&c="></script>
<form name="EditView" method="POST" enctype="multipart/form-data" action="SendEmail.php?mod=<?print $_REQUEST['mod'];?>&record=<?print $_REQUEST['record'];?>">
<table width='100%' cellpadding='0' cellspacing='0' border='0' class='moduleTitle'><tr><td valign='top'>
<h2>EcmDocuments: Send Information</h2></td>
</tr></table>
<div style="padding-top: 2px">
<input name="send" type="submit" class="button" id="send" title="save" value="Send">
<input name="cancel" type="button" class="button" id="cancel" title="cancel" value="Cancel" onClick="window.close();">
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabForm">
<tr>
<td rowspan="2" valign="top" class="dataLabel"><strong>E-mail</strong></td>
<td rowspan="2" valign="top" class="dataField"><input type="hidden" name="email"><select name="user[]" size="6" multiple="multiple">
<?
$z="select email1,first_name,last_name,user_name from users where deleted='0' and email1 IS NOT NULL order by user_name asc";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
print "<option value='".$r['email1']."'>".$r['first_name']." ".$r['last_name']."</option>";
}
?>
</select></td>
<td valign="top" class="dataLabel"><strong>Subject</strong></td>
<td valign="top" class="dataField"><textarea name="subject" cols="80" rows="2" id="subject">New Document</textarea></td>
</tr>
<tr>
<td valign="top" class="dataLabel"><strong>Text</strong></td>
<td valign="top" class="dataField"><textarea name="text" cols="80" rows="20" id="text">Please notice a new document in CRM: <a href='http://192.168.1.200<?
$ps=str_replace("modules/EcmDocuments/SendEmail.php","index.php",$_SERVER['PHP_SELF']);
print $ps;?>?module=<?print $_REQUEST['mod'];?>&action=DetailView&amp;record=<?print $_REQUEST['record'];?>'>http://192.168.1.200<?
$ps=str_replace("modules/EcmDocuments/SendEmail.php","index.php",$_SERVER['PHP_SELF']);
print $ps;?>?module=<?print $_REQUEST['mod'];?>&action=DetailView&amp;record=<?print $_REQUEST['record'];?></a></textarea></td>
<!-- BEGIN: pro -->
<!-- END: pro -->
<!-- BEGIN: open_source -->
<!-- END: open_source -->
</tr>
</table>
<input type="hidden" name="numusers" value="<?print $i;?>" />
<br>
<input name="addfromcrm" type="button" onClick='window.open("modules/EcmDocuments/SelectFile.php","Account","resizable=yes,scrollbars=yes,status=no,height=450,width=600").focus();return false;' class="button" id="addfromcrm" value="Add from CRM" />
<div style="padding-top: 2px">
<input name="send" type="submit" class="button" id="send" title="save" value="Send" >
<input name="cancel" type="button" class="button" id="cancel" title="cancel" value="Cancel" onClick="window.close();">
</div>
</form>
</body>
</html>
<!-- END: main -->
<? mysql_close($sql);?>