diff --git a/oss/vtiger/trunk/modules/uploads/add2db.php b/oss/vtiger/trunk/modules/uploads/add2db.php
new file mode 100644
index 00000000..686938e0
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/add2db.php
@@ -0,0 +1,149 @@
+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 '';
+ }
+ else
+ {
+ $errormessage = "Error Message
+
" ;
+ header("Location: index.php?module=uploads&action=uploadsAjax&msg=true&file=upload&errormessage=".$errormessage);
+ }
+ }
+ else
+ {
+ $errorCode = $_FILES['binFile']['error'];
+ $errormessage = "";
+
+ if($errorCode == 4)
+ {
+ $errormessage = "Kindly give a valid file for upload!
" ;
+ }
+ else if($errorCode == 2)
+ {
+ $errormessage = "Sorry, the uploaded file exceeds the maximum filesize limit. Please try a file smaller than $upload_maxsize bytes
";
+ }
+ else if($errorCode == 6)
+ {
+ $errormessage = "Please configure upload_tmp_dir variable in php.ini file.
" ;
+ }
+ else if($errorCode == 3 || $errorcode == '')
+ {
+ $errormessage = "Problems in file upload. Please try again!
";
+ }
+
+ if($errormessage != '')
+ {
+ echo $errormessage;
+ include("upload.php");
+ }
+ }
+
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/uploads/deleteattachments.php b/oss/vtiger/trunk/modules/uploads/deleteattachments.php
new file mode 100644
index 00000000..df854041
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/deleteattachments.php
@@ -0,0 +1,23 @@
+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());
+
+
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/uploads/downloadfile.php b/oss/vtiger/trunk/modules/uploads/downloadfile.php
new file mode 100644
index 00000000..dca60afa
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/downloadfile.php
@@ -0,0 +1,57 @@
+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'];
+ }
+}
+?>
diff --git a/oss/vtiger/trunk/modules/uploads/language/en_us.lang.php b/oss/vtiger/trunk/modules/uploads/language/en_us.lang.php
new file mode 100644
index 00000000..83c1083f
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/language/en_us.lang.php
@@ -0,0 +1,35 @@
+'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)',
+);
+
+?>
diff --git a/oss/vtiger/trunk/modules/uploads/language/zh_cn.lang.php b/oss/vtiger/trunk/modules/uploads/language/zh_cn.lang.php
new file mode 100644
index 00000000..83c1083f
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/language/zh_cn.lang.php
@@ -0,0 +1,35 @@
+'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)',
+);
+
+?>
diff --git a/oss/vtiger/trunk/modules/uploads/upload.php b/oss/vtiger/trunk/modules/uploads/upload.php
new file mode 100644
index 00000000..a43de410
--- /dev/null
+++ b/oss/vtiger/trunk/modules/uploads/upload.php
@@ -0,0 +1,139 @@
+
+
+