更新到 5.2 正式版后第一次 SVN 提交。

[email protected]


git-svn-id: https://svn.code.sf.net/p/hawebs/svn@648 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-11-17 02:28:30 +00:00
parent 93137d9590
commit 56fb3bbe0b
7 changed files with 452 additions and 0 deletions
+149
View File
@@ -0,0 +1,149 @@
<?php
/*+********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
********************************************************************************/
require_once('include/utils/utils.php');
require_once('include/logging.php');
global $log;
global $current_user, $upload_badext;
$vtigerpath = $_SERVER['REQUEST_URI'];
$vtigerpath = str_replace("/index.php?module=uploads&action=add2db", "", $vtigerpath);
$crmid = $_REQUEST['return_id'];
$log->debug("DEBUG In add2db.php");
if(isset($_REQUEST['filename_hidden'])) {
$file = $_REQUEST['filename_hidden'];
} else {
$file = $_FILES['filename']['name'];
}
$binFile = sanitizeUploadFileName($file, $upload_badext);
$_FILES["filename"]["name"] = $binFile;
//decide the file path where we should upload the file in the server
$upload_filepath = decideFilePath();
$current_id = $adb->getUniqueID("vtiger_crmentity");
if(move_uploaded_file($_FILES["filename"]["tmp_name"],$upload_filepath.$current_id."_".$_FILES["filename"]["name"]))
{
$filename = ltrim(basename(" ".$binFile)); //allowed filename like UTF-8 characters
$filetype= $_FILES['filename']['type'];
$filesize = $_FILES['filename']['size'];
if($filesize != 0)
{
$desc = $_REQUEST['txtDescription'];
$subject = $_REQUEST['uploadsubject'];
$date_var = $adb->formatDate(date('Y-m-d H:i:s'), true);
$current_date = getdate();
$current_date = $adb->formatDate(date('Y-m-d H:i:s'), true);
$query = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?,?,?,?,?,?,?)";
$params = array($current_id, $current_user->id, $current_user->id, $_REQUEST['return_module'].' Attachment', $desc, $date_var, $current_date);
$result = $adb->pquery($query, $params);
# Added by DG 26 Oct 2005
# Attachments added to contacts are also added to their accounts
$log->debug("DEBUG return_module: ".$_REQUEST['return_module']);
if ($_REQUEST['return_module'] == 'Contacts')
{
$crmid = $_REQUEST['return_id'];
$query = 'select accountid from vtiger_contactdetails where contactid=?';
$result = $adb->pquery($query, array($crmid));
if($adb->num_rows($result) != 0)
{
$log->debug("DEBUG Returned a row");
$associated_account = $adb->query_result($result,0,"accountid");
# Now make sure that we haven't already got this attachment associated to this account
# Hmmm... if this works, should we NOT upload the attachment again, and just set the relation for the contact too?
$log->debug("DEBUG Associated Account: ".$associated_account);
$query = "select attachmentsid, name, path from vtiger_attachments where name=?";
$result = $adb->pquery($query, array($filename));
if($adb->num_rows($result) != 0)
{
$log->debug("DEBUG Matched a row");
# Whoops! We matched the name. Is it the same size?
$fname = $adb->query_result($result,0,"name");
$fpath = $adb->query_result($result,0,"path");
$fid = $adb->query_result($result,0,"attachmentsid");
$dg_size = filesize($fpath . "/".$fid."_". $fname);
//$dg_size = $adb->query_result($result,0,"attachmentsize");
$log->debug("DEBUG: These should be the same size: ".$dg_size." ".$filesize);
if ($dg_size == $filesize)
{
# Yup, it is probably the same file
$associated_account = '';
}
}
}
else
{
$associated_account = '';
}
}
$sql = "insert into vtiger_attachments(attachmentsid, name, description, type,path,subject) values(?,?,?,?,?,?)";
$params = array($current_id, $filename, $desc, $filetype, $upload_filepath, $subject);
$result = $adb->pquery($sql, $params);
$sql1 = "insert into vtiger_seattachmentsrel values(?,?)";
$params1 = array($crmid, $current_id);
$result = $adb->pquery($sql1, $params1);
# Attachments added to contacts are also added to their accounts
if ($associated_account)
{
$log->debug("DEBUG: inserting into vtiger_seattachmentsrel from add2db 2");
$sql1 = "insert into vtiger_seattachmentsrel values(?,?)";
$params1 = array($associated_account, $current_id);
$result = $adb->pquery($sql1, $params1);
}
echo '<script>window.opener.location.href = window.opener.location.href;self.close();</script>';
}
else
{
$errormessage = "<font color='red'><B>Error Message<ul>
<li><font color='red'>Invalid file OR</font>
<li><font color='red'>File has no data</font>
</ul></B></font> <br>" ;
header("Location: index.php?module=uploads&action=uploadsAjax&msg=true&file=upload&errormessage=".$errormessage);
}
}
else
{
$errorCode = $_FILES['binFile']['error'];
$errormessage = "";
if($errorCode == 4)
{
$errormessage = "<B><font color='red'>Kindly give a valid file for upload!</font></B> <br>" ;
}
else if($errorCode == 2)
{
$errormessage = "<B><font color='red'>Sorry, the uploaded file exceeds the maximum filesize limit. Please try a file smaller than $upload_maxsize bytes</font></B> <br>";
}
else if($errorCode == 6)
{
$errormessage = "<B>Please configure <font color='red'>upload_tmp_dir</font> variable in php.ini file.</B> <br>" ;
}
else if($errorCode == 3 || $errorcode == '')
{
$errormessage = "<b><font color='red'>Problems in file upload. Please try again!</font></b><br>";
}
if($errormessage != '')
{
echo $errormessage;
include("upload.php");
}
}
?>
@@ -0,0 +1,23 @@
<?php
/*+********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
********************************************************************************/
require_once('include/database/PearDatabase.php');
$id=$_REQUEST['record'];
$sql = "delete from vtiger_seattachmentsrel where attachmentsid =?";
$adb->pquery($sql, array($id));
$sql = "delete from vtiger_attachments where attachmentsid =?";
$adb->pquery($sql, array($id));
header("Location:index.php?module=".vtlib_purify($_REQUEST['return_module'])."&action=".vtlib_purify($_REQUEST['return_action'])."&record=".vtlib_purify($_REQUEST['return_id'])."&parenttab=".getParentTab());
?>
@@ -0,0 +1,57 @@
<?php
/********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
require_once('config.php');
require_once('include/database/PearDatabase.php');
global $adb;
global $fileId, $default_charset, $app_strings;
$attachmentsid = $_REQUEST['fileid'];
$entityid = $_REQUEST['entityid'];
$returnmodule=$_REQUEST['return_module'];
$deletecheck = false;
if(!empty($entityid)) $deletecheck = $adb->pquery("SELECT deleted FROM vtiger_crmentity WHERE crmid=?", array($entityid));
if(!empty($deletecheck) && $adb->query_result($deletecheck, 0, 'deleted') == 1) {
echo $app_strings['LBL_RECORD_DELETE'];
} else {
$dbQuery = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ?" ;
$result = $adb->pquery($dbQuery, array($attachmentsid)) or die("Couldn't get file list");
if($adb->num_rows($result) == 1)
{
$fileType = @$adb->query_result($result, 0, "type");
$name = @$adb->query_result($result, 0, "name");
$filepath = @$adb->query_result($result, 0, "path");
$name = html_entity_decode($name, ENT_QUOTES, $default_charset);
$saved_filename = $attachmentsid."_".$name;
$disk_file_size = filesize($filepath.$saved_filename);
$filesize = $disk_file_size + ($disk_file_size % 1024);
$fileContent = fread(fopen($filepath.$saved_filename, "r"), $filesize);
header("Content-type: $fileType");
header("Pragma: public");
header("Cache-Control: private");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $fileContent;
}
else
{
echo $app_strings['LBL_RECORD_NOT_FOUND'];
}
}
?>
@@ -0,0 +1,35 @@
<?php
/*********************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version 1.1.2
* ("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.
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
/*********************************************************************************
* $Header: /advent/projects/wesat/vtiger_crm/vtigercrm/modules/uploads/language/en_us.lang.php,v 1.1 2005/01/20 05:29:32 saraj Exp $
* Description: Defines the English language pack
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
$mod_strings = Array(
//Added fields for uploads (attach files)
'LBL_ATTACH_FILE'=>'Attach File',
'LBL_ATTACH'=>'Attach',
'LBL_CANCEL'=>'Cancel',
'LBL_STEP_SELECT_FILE'=>'Step 1 : Select File',
'LBL_BROWSE_FILES'=>'Click the browse button and select the file to be attached',
'LBL_DESCRIPTION'=>'Step 2 : Write some description',
'LBL_OPTIONAL'=>'(optional)',
);
?>
@@ -0,0 +1,35 @@
<?php
/*********************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version 1.1.2
* ("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.
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
/*********************************************************************************
* $Header: /advent/projects/wesat/vtiger_crm/vtigercrm/modules/uploads/language/en_us.lang.php,v 1.1 2005/01/20 05:29:32 saraj Exp $
* Description: Defines the English language pack
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
$mod_strings = Array(
//Added fields for uploads (attach files)
'LBL_ATTACH_FILE'=>'Attach File',
'LBL_ATTACH'=>'Attach',
'LBL_CANCEL'=>'Cancel',
'LBL_STEP_SELECT_FILE'=>'Step 1 : Select File',
'LBL_BROWSE_FILES'=>'Click the browse button and select the file to be attached',
'LBL_DESCRIPTION'=>'Step 2 : Write some description',
'LBL_OPTIONAL'=>'(optional)',
);
?>
+139
View File
@@ -0,0 +1,139 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
global $theme;
$theme_path="themes/".$theme."/";
?>
<HTML>
<head>
<link type="text/css" href="<?php echo $theme_path;?>style.css" rel="stylesheet">
<script>
function titleValidation()
{
var val = document.getElementById('uploadsubject').value;
if(trim(val) == '')
{
alert("Title cannot be empty");
return false;
}
}
function getFileNameOnly(filename) {
var onlyfilename = filename;
// Normalize the path (to make sure we use the same path separator)
var filename_normalized = filename.replace(/\\/g, '/');
if(filename_normalized.lastIndexOf("/") != -1) {
onlyfilename = filename_normalized.substring(filename_normalized.lastIndexOf("/") + 1);
}
return onlyfilename;
}
/* Function to validate the filename */
function validateFilename(form_ele) {
if (form_ele.value == '') return true;
var value = getFileNameOnly(form_ele.value);
// Color highlighting logic
var err_bg_color = "#FFAA22";
if (typeof(form_ele.bgcolor) == "undefined") {
form_ele.bgcolor = form_ele.style.backgroundColor;
}
// Validation starts here
var valid = true;
/* Filename length is constrained to 255 at database level */
if (value.length > 255) {
alert(alert_arr.LBL_FILENAME_LENGTH_EXCEED_ERR);
valid = false;
}
if (!valid) {
form_ele.style.backgroundColor = err_bg_color;
return false;
}
form_ele.style.backgroundColor = form_ele.bgcolor;
form_ele.form[form_ele.name + '_hidden'].value = value;
return true;
}
function trim(str)
{
// str. remove whitespaces from left. remove whitespaces from right
return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
}
</script>
</head>
<BODY marginheight="0" marginwidth="0" leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0">
<FORM METHOD="post" onsubmit="VtigerJS_DialogBox.block();" action="index.php?module=uploads&action=add2db&return_module=<?php echo vtlib_purify($_REQUEST['return_module'])?>" enctype="multipart/form-data" style="margin:0px;">
<?php
$ret_module = ($_REQUEST['return_module'] != "")?vtlib_purify($_REQUEST['return_module']):$_SESSION['return_mod'];
$ret_action = ($_REQUEST['return_action'] != "")?vtlib_purify($_REQUEST['return_action']):$_SESSION['return_act'];
$ret_id = ($_REQUEST['return_id'] != "")?vtlib_purify($_REQUEST['return_id']):$_SESSION['returnid'];
$_SESSION['return_act'] = $ret_action;
$_SESSION['return_mod'] = $ret_module;
$_SESSION['returnid'] = $ret_id;
?>
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="<?php echo $upload_maxsize; ?>">
<INPUT TYPE="hidden" NAME="return_module" VALUE="<?php echo $ret_module ?>">
<INPUT TYPE="hidden" NAME="return_action" VALUE="<?php echo $ret_action ?>">
<INPUT TYPE="hidden" NAME="return_id" VALUE="<?php echo $ret_id ?>">
<table border=0 cellspacing=0 cellpadding=0 width=100% class="layerPopup">
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=5 width=100% class=layerHeadingULine>
<tr>
<td class="layerPopupHeading" align="left"><?php echo $mod_strings["LBL_ATTACH_FILE"];?></td>
<td width="70%" align="right">&nbsp;</td>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=5 width=95% align=center>
<tr>
<td class=small >
<table border=0 celspacing=0 cellpadding=5 width=100% align=center bgcolor=white class="small">
<tr>
<td width="30%" colspan="2" align="left">
<b><?php echo $mod_strings["LBL_STEP_SELECT_FILE"];?></b><br>
<?php echo $mod_strings["LBL_BROWSE_FILES"]; ?>
</td>
</tr>
<tr><td><B><font color=red>*</font>&nbsp;<?php echo $app_strings["LBL_TITLE"];?> </B> <input type ="text" name = "uploadsubject" id="uploadsubject"></td></tr>
<tr>
<td width="30%" colspan="2" align="left">
&nbsp;<input type="file" name="filename" onchange="validateFilename(this)" /><input type="hidden" name="filename_hidden"/>
</td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td width="30%" colspan="2" align="left">
<b> <?php echo $mod_strings["LBL_DESCRIPTION"];?> </b><?php echo $mod_strings["LBL_OPTIONAL"];?>
</td>
</tr>
<tr><td colspan="2" align="left"><textarea cols="50" rows="5" name="txtDescription" class="txtBox"></textarea></td></tr>
</table>
</td>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=5 width=100% class="layerPopupTransport">
<tr>
<td colspan="2" align="center">
<input type="submit" name="save" value="&nbsp;<?php echo $mod_strings["LBL_ATTACH"]; ?>&nbsp;" class="crmbutton small save" onclick = "return titleValidation();" />&nbsp;&nbsp;
<input type="button" name="cancel" value=" <?php echo $mod_strings["LBL_CANCEL"];?> " class="crmbutton small cancel" onclick="self.close();" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
@@ -0,0 +1,14 @@
<?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
require_once('include/Ajax/CommonAjax.php');
?>