Newer
Older
<?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/data/CRMEntity.php,v 1.16 2005/04/29 04:21:31 mickie Exp $
* Description: Defines the base class for all data entities used throughout the
* application. The base class including its methods and variables is designed to
* be overloaded with module-specific methods and variables particular to the
* module's base entity class.
********************************************************************************/
include_once('config.php');
require_once('include/logging.php');
require_once('data/Tracker.php');
require_once('include/utils/utils.php');
require_once('include/utils/UserInfoUtil.php');
require_once("include/Zend/Json.php");
/**
* Detect if we are in bulk save mode, where some features can be turned-off
* to improve performance.
*/
static function isBulkSaveMode() {
global $VTIGER_BULK_SAVE_MODE;
if (isset($VTIGER_BULK_SAVE_MODE) && $VTIGER_BULK_SAVE_MODE) {
return true;
}
return false;
}
static function getInstance($module) {
$modName = $module;
if ($module == 'Calendar' || $module == 'Events') {
$module = 'Calendar';
$modName = 'Activity';
}
// File access security check
if (!class_exists($modName)) {
checkFileAccessForInclusion("modules/$module/$modName.php");
require_once("modules/$module/$modName.php");
}
$focus = new $modName();
$focus->moduleName = $module;
$focus->column_fields = new TrackableObject();
$focus->column_fields = getColumnFields($module);
if (method_exists($focus, 'initialize')) $focus->initialize();
/**
* Function which indicates whether to chagne the modified time or not while saving
*/
static function isTimeStampNoChangeMode(){
global $VTIGER_TIMESTAMP_NO_CHANGE_MODE;
if (isset($VTIGER_TIMESTAMP_NO_CHANGE_MODE) && $VTIGER_TIMESTAMP_NO_CHANGE_MODE) {
return true;
}
return false;
}
/**
* Function which will used to initialize object properties
*/
function initialize() {
$moduleName = $this->moduleName;
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
if($moduleModel && !$moduleModel->isEntityModule()) {
return;
}
$userSpecificTableIgnoredModules = array('SMSNotifier', 'PBXManager', 'ModComments');
if(in_array($moduleName, $userSpecificTableIgnoredModules)) return;
$userSpecificTable = Vtiger_Functions::getUserSpecificTableName($moduleName);
if(!in_array($userSpecificTable, $this->tab_name)) {
$this->tab_name[] = $userSpecificTable;
$this->tab_name_index [$userSpecificTable] = 'recordid';
}
}
function saveentity($module, $fileid = '') {
global $current_user, $adb; //$adb added by raju for mass mailing
$insertion_mode = $this->mode;
$columnFields = $this->column_fields;
$anyValue = false;
foreach ($columnFields as $value) {
if(!empty($value)) {
$anyValue = true;
break;
}
}
if(!$anyValue) {
die("<center>" .getTranslatedString('LBL_MANDATORY_FIELD_MISSING')."</center>");
}
// added to support files transformation for file upload fields like uitype 69,
if(!empty($_FILES) && php7_count($_FILES)) {
$_FILES = Vtiger_Util_Helper::transformUploadedFiles($_FILES, true);
}
foreach ($this->tab_name as $table_name) {
if ($table_name == "vtiger_crmentity") {
$this->insertIntoCrmEntity($module, $fileid);
} else {
$this->insertIntoEntityTable($table_name, $module, $fileid);
}
}
//Calling the Module specific save code
$this->save_module($module);
$this->db->completeTransaction();
// vtlib customization: Hook provide to enable generic module relation.
if ( (isset($_REQUEST['createmode']) && $_REQUEST['createmode'] == 'link') &&
!isset($_REQUEST['__linkcreated'])) {
$for_module = vtlib_purify($_REQUEST['return_module']);
$for_crmid = vtlib_purify($_REQUEST['return_id']);
$with_module = $module;
$with_crmid = $this->id;
$on_focus = CRMEntity::getInstance($for_module);
if ($for_module && $for_crmid && $with_module && $with_crmid) {
relateEntities($on_focus, $for_module, $for_crmid, $with_module, $with_crmid);
}
}
// END
}
/**
* This function is used to upload the attachment in the server and save that attachment information in db.
* @param int $id - entity id to which the file to be uploaded
* @param string $module - the current module name
* @param array $file_details - array which contains the file information(name, type, size, tmp_name and error)
* return void
function uploadAndSaveFile($id, $module, $file_details, $attachmentType='Attachment') {
global $log;
$log->debug("Entering into uploadAndSaveFile($id,$module,$file_details) method.");
global $adb, $current_user;
global $upload_badext;
$date_var = date("Y-m-d H:i:s");
//to get the owner id
$ownerid = $this->column_fields['assigned_user_id'];
if (!isset($ownerid) || $ownerid == '')
$ownerid = $current_user->id;
if (isset($file_details['original_name']) && $file_details['original_name'] != null) {
$file_name = $file_details['original_name'];
} else {
$file_name = $file_details['name'];
}
$save_file = true;
//only images are allowed for Image Attachmenttype
$mimeType = vtlib_mime_content_type($file_details['tmp_name']);
$mimeTypeContents = explode('/', $mimeType);
// For contacts and products we are sending attachmentType as value
if ($attachmentType == 'Image' || ($file_details['size'] && $mimeTypeContents[0] == 'image')) {
$save_file = validateImageFile($file_details);
}
$log->debug("File Validation status in Check1 save_file => $save_file");
if (!$save_file) {
$save_file = true;
//only images are allowed for these modules
if ($module == 'Contacts' || $module == 'Products') {
$save_file = validateImageFile($file_details);
$log->debug("File Validation status in Check2 save_file => $save_file");
$binFile = sanitizeUploadFileName($file_name, $upload_badext);
Loading
Loading full blame...