This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for error page of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
class ImportViewError extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings;
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
$this->ss->assign("ACTION", 'Step1');
$this->ss->assign("MESSAGE",$_REQUEST['message']);
$this->ss->assign("SOURCE","");
if ( isset($_REQUEST['source']) )
$this->ss->assign("SOURCE", $_REQUEST['source']);
$this->ss->display('modules/Import/tpls/error.tpl');
}
}

View File

@@ -0,0 +1,297 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for last step of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
require_once('modules/Import/ImportCacheFiles.php');
class ImportViewLast extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::_getModuleTitleParams()
*/
protected function _getModuleTitleParams()
{
global $mod_strings;
return array(
"<a href='index.php?module={$_REQUEST['import_module']}&action=index'>".translate('LBL_MODULE_NAME',$_REQUEST['import_module'])."</a>",
"<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
$mod_strings['LBL_RESULTS'],
);
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("APP", $app_strings);
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
$this->ss->assign("TYPE", $_REQUEST['type']);
$this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
$this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
// lookup this module's $mod_strings to get the correct module name
$language = (isset($current_language)) ? ($current_language) : ($sugar_config['default_language']);
$module_mod_strings =
return_module_language($current_language, $_REQUEST['import_module']);
$this->ss->assign("MODULENAME",$module_mod_strings['LBL_MODULE_NAME']);
$this->ss->assign("JAVASCRIPT", $this->_getJS());
// read status file to get totals for records imported, errors, and duplicates
$count = 0;
$errorCount = 0;
$dupeCount = 0;
$createdCount = 0;
$updatedCount = 0;
$fp = sugar_fopen(ImportCacheFiles::getStatusFileName(),'r');
while (( $row = fgetcsv($fp, 8192) ) !== FALSE) {
$count += (int) $row[0];
$errorCount += (int) $row[1];
$dupeCount += (int) $row[2];
$createdCount += (int) $row[3];
$updatedCount += (int) $row[4];
}
fclose($fp);
$this->ss->assign("errorCount",$errorCount);
$this->ss->assign("dupeCount",$dupeCount);
$this->ss->assign("createdCount",$createdCount);
$this->ss->assign("updatedCount",$updatedCount);
$this->ss->assign("errorFile",ImportCacheFiles::getErrorFileName());
$this->ss->assign("errorrecordsFile",ImportCacheFiles::getErrorRecordsFileName());
$this->ss->assign("dupeFile",ImportCacheFiles::getDuplicateFileName());
// load bean
$focus = loadImportBean($_REQUEST['import_module']);
if ( !$focus ) {
showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
return;
}
if ( $focus->object_name == "Prospect" ) {
$this->ss->assign("PROSPECTLISTBUTTON",
$this->_addToProspectListButton());
}
else {
$this->ss->assign("PROSPECTLISTBUTTON","");
}
$this->ss->display('modules/Import/tpls/last.tpl');
foreach ( UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname ) {
// load bean
if ( !( $focus instanceof $beanname ) ) {
require_once($GLOBALS['beanFiles'][$beanname]);
$focus = new $beanname;
}
// build listview to show imported records
require_once('include/ListView/ListViewFacade.php');
$lvf = new ListViewFacade($focus, $focus->module_dir, 0);
$params = array();
if(!empty($_REQUEST['orderBy'])) {
$params['orderBy'] = $_REQUEST['orderBy'];
$params['overrideOrder'] = true;
if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
}
$beanname = ($focus->object_name == 'Case' ? 'aCase' : $focus->object_name);
// add users_last_import joins so we only show records done in this import
$params['custom_from'] = ', users_last_import';
$params['custom_where'] = " AND users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}'
AND users_last_import.bean_type = '{$beanname}'
AND users_last_import.bean_id = {$focus->table_name}.id
AND users_last_import.deleted = 0
AND {$focus->table_name}.deleted = 0";
$where = " {$focus->table_name}.id IN (
SELECT users_last_import.bean_id
FROM users_last_import
WHERE users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}'
AND users_last_import.bean_type = '{$beanname}'
AND users_last_import.deleted = 0 )";
$lbl_last_imported = $mod_strings['LBL_LAST_IMPORTED'];
$lvf->lv->mergeduplicates = false;
$module_mod_strings = return_module_language($current_language, $focus->module_dir);
$lvf->setup('', $where, $params, $module_mod_strings, 0, -1, '', strtoupper($beanname), array(), 'id');
$lvf->display($lbl_last_imported.": ".$module_mod_strings['LBL_MODULE_NAME']);
}
}
/**
* Returns JS used in this view
*/
private function _getJS()
{
return <<<EOJAVASCRIPT
<script type="text/javascript">
<!--
document.getElementById('importmore').onclick = function(){
document.getElementById('importlast').action.value = 'Step1';
return true;
}
document.getElementById('finished').onclick = function(){
document.getElementById('importlast').module.value = document.getElementById('importlast').import_module.value;
document.getElementById('importlast').action.value = 'index';
return true;
}
-->
</script>
EOJAVASCRIPT;
}
/**
* Returns a button to add this list of prospects to a Target List
*
* @return string html code to display button
*/
private function _addToProspectListButton()
{
global $app_strings, $sugar_version, $sugar_config, $current_user;
$query = "SELECT distinct
prospects.id,
prospects.assigned_user_id,
prospects.first_name,
prospects.last_name,
prospects.phone_work,
prospects.title,
email_addresses.email_address email1,
users.user_name as assigned_user_name
FROM users_last_import,prospects
LEFT JOIN users
ON prospects.assigned_user_id=users.id
LEFT JOIN email_addr_bean_rel on prospects.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='Prospect' and email_addr_bean_rel.primary_address=1 and email_addr_bean_rel.deleted=0
LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id
WHERE
users_last_import.assigned_user_id=
'{$current_user->id}'
AND users_last_import.bean_type='Prospect'
AND users_last_import.bean_id=prospects.id
AND users_last_import.deleted=0
AND prospects.deleted=0
";
$popup_request_data = array(
'call_back_function' => 'set_return_and_save_background',
'form_name' => 'DetailView',
'field_to_name_array' => array(
'id' => 'subpanel_id',
),
'passthru_data' => array(
'child_field' => 'notused',
'return_url' => 'notused',
'link_field_name' => 'notused',
'module_name' => 'notused',
'refresh_page'=>'1',
'return_type'=>'addtoprospectlist',
'parent_module'=>'ProspectLists',
'parent_type'=>'ProspectList',
'child_id'=>'id',
'link_attribute'=>'prospects',
'link_type'=>'default', //polymorphic or default
)
);
$popup_request_data['passthru_data']['query'] = urlencode($query);
$json = getJSONobj();
$encoded_popup_request_data = $json->encode($popup_request_data);
return <<<EOHTML
<script type="text/javascript" src="include/SubPanel/SubPanelTiles.js?s={$sugar_version}&c={$sugar_config['js_custom_version']}"></script>
<input align=right" type="button" name="select_button" id="select_button" class="button"
title="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
accesskey="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_KEY']}"
value="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
onclick='open_popup("ProspectLists",600,400,"",true,true,$encoded_popup_request_data,"Single","true");' />
EOHTML;
}
}
?>

View File

@@ -0,0 +1,305 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for step 1 of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
class ImportViewStep1 extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::_getModuleTitleParams()
*/
protected function _getModuleTitleParams()
{
global $mod_strings;
return array(
"<a href='index.php?module={$_REQUEST['import_module']}&action=index'>".translate('LBL_MODULE_NAME',$_REQUEST['import_module'])."</a>",
"<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
$mod_strings['LBL_STEP_1_TITLE'],
);
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings, $app_list_strings, $app_strings, $current_user;
global $sugar_config;
$this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("APP", $app_strings);
$this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
$this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
$this->ss->assign("UNPUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" alt="'.$mod_strings['LBL_UNPUBLISH'].'" border="0"'));
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
$this->ss->assign("JAVASCRIPT", $this->_getJS());
// handle publishing and deleting import maps
if (isset($_REQUEST['delete_map_id'])) {
$import_map = new ImportMap();
$import_map->mark_deleted($_REQUEST['delete_map_id']);
}
if (isset($_REQUEST['publish']) ) {
$import_map = new ImportMap();
$result = 0;
$import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
if ($_REQUEST['publish'] == 'yes') {
$result = $import_map->mark_published($current_user->id,true);
if (!$result) {
$this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
}
}
elseif ( $_REQUEST['publish'] == 'no') {
// if you don't own this importmap, you do now!
// unless you have a map by the same name
$result = $import_map->mark_published($current_user->id,false);
if (!$result) {
$this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
}
}
}
// load bean
$focus = loadImportBean($_REQUEST['import_module']);
if ( !$focus ) {
showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
return;
}
// trigger showing other software packages
$this->ss->assign("show_salesforce",false);
$this->ss->assign("show_outlook",false);
$this->ss->assign("show_act",false);
switch ($_REQUEST['import_module']) {
case "Prospects":
break;
case "Accounts":
$this->ss->assign("show_salesforce",true);
$this->ss->assign("show_act",true);
break;
case "Contacts":
$this->ss->assign("show_salesforce",true);
$this->ss->assign("show_outlook",true);
$this->ss->assign("show_act",true);
break;
default:
$this->ss->assign("show_salesforce",true);
break;
}
// get user defined import maps
$this->ss->assign('is_admin',is_admin($current_user));
$import_map_seed = new ImportMap();
$custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
array(
'assigned_user_id' => $current_user->id,
'is_published' => 'no',
'module' => $_REQUEST['import_module'],
)
);
if ( count($custom_imports_arr) ) {
$custom = array();
foreach ( $custom_imports_arr as $import) {
$custom[] = array(
"IMPORT_NAME" => $import->name,
"IMPORT_ID" => $import->id,
);
}
$this->ss->assign('custom_imports',$custom);
}
// get globally defined import maps
$published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
array(
'is_published' => 'yes',
'module' => $_REQUEST['import_module'],
)
);
if ( count($published_imports_arr) ) {
$published = array();
foreach ( $published_imports_arr as $import) {
$published[] = array(
"IMPORT_NAME" => $import->name,
"IMPORT_ID" => $import->id,
);
}
$this->ss->assign('published_imports',$published);
}
$this->ss->display('modules/Import/tpls/step1.tpl');
}
/**
* Returns JS used in this view
*/
private function _getJS()
{
global $mod_strings;
return <<<EOJAVASCRIPT
<script type="text/javascript">
<!--
document.getElementById('custom_enclosure').onchange = function()
{
document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
}
document.getElementById('gonext').onclick = function()
{
clear_all_errors();
var sourceSelected = false;
var typeSelected = false;
var isError = false;
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i ){
if ( !sourceSelected && inputs[i].name == 'source' ){
if (inputs[i].checked) {
sourceSelected = true;
if ( inputs[i].value == 'other' && document.getElementById('importstep1').custom_delimiter.value == '' ) {
add_error_style('importstep1','custom_delimiter',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_CUSTOM_DELIMITER']}");
isError = true;
}
}
}
if ( !typeSelected && inputs[i].name == 'type' ){
if (inputs[i].checked) {
typeSelected = true;
}
}
}
if ( !sourceSelected ) {
add_error_style('importstep1','source\'][\'' + (document.getElementById('importstep1').source.length - 1) + '',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_WHAT_IS']}");
isError = true;
}
if ( !typeSelected ) {
add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
isError = true;
}
return !isError;
}
YAHOO.util.Event.onDOMReady(function()
{
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i ){
if (inputs[i].name == 'source' ) {
inputs[i].onclick = function()
{
parentRow = this.parentNode.parentNode;
switch(this.value) {
case 'other':
enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
parentRow.parentNode.insertBefore(enclosureRow, document.getElementById('customDelimiter').nextSibling);
document.getElementById('customDelimiter').style.display = '';
document.getElementById('customEnclosure').style.display = '';
break;
case 'tab': case 'csv':
enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
parentRow.parentNode.insertBefore(enclosureRow, parentRow.nextSibling);
document.getElementById('customDelimiter').style.display = 'none';
document.getElementById('customEnclosure').style.display = '';
break;
default:
document.getElementById('customDelimiter').style.display = 'none';
document.getElementById('customEnclosure').style.display = 'none';
}
}
}
}
});
-->
</script>
EOJAVASCRIPT;
}
}
?>

View File

@@ -0,0 +1,238 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for step 2 of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
class ImportViewStep2 extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::_getModuleTitleParams()
*/
protected function _getModuleTitleParams()
{
global $mod_strings;
return array(
"<a href='index.php?module={$_REQUEST['import_module']}&action=index'>".translate('LBL_MODULE_NAME',$_REQUEST['import_module'])."</a>",
"<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
$mod_strings['LBL_STEP_2_TITLE'],
);
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
global $import_mod_strings;
$this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("APP", $app_strings);
$this->ss->assign("IMP", $import_mod_strings);
$this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
$this->ss->assign("CUSTOM_DELIMITER",
( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
$this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other'
? $_REQUEST['custom_enclosure'] :
( !empty($_REQUEST['custom_enclosure_other'])
? $_REQUEST['custom_enclosure_other'] : "" ) )));
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
$this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
$this->ss->assign("JAVASCRIPT", $this->_getJS());
// load bean
$focus = loadImportBean($_REQUEST['import_module']);
if ( !$focus ) {
showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
return;
}
// special for importing from Outlook
if ($_REQUEST['source'] == "outlook") {
$this->ss->assign("SOURCE", $_REQUEST['source']);
$this->ss->assign("SOURCE_NAME","Outlook ");
$this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
}
// see if the source starts with 'custom'
// if so, pull off the id, load that map, and get the name
elseif ( strncasecmp("custom:",$_REQUEST['source'],7) == 0) {
$id = substr($_REQUEST['source'],7);
$import_map_seed = new ImportMap();
$import_map_seed->retrieve($id, false);
$this->ss->assign("SOURCE_ID", $import_map_seed->id);
$this->ss->assign("SOURCE_NAME", $import_map_seed->name);
$this->ss->assign("SOURCE", $import_map_seed->source);
if (isset($import_map_seed->delimiter))
$this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
if (isset($import_map_seed->enclosure))
$this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
if ($import_map_seed->has_header)
$this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
}
else {
$classname = 'ImportMap' . ucfirst($_REQUEST['source']);
require("modules/Import/{$classname}.php");
$import_map_seed = new $classname;
if (isset($import_map_seed->delimiter))
$this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
if (isset($import_map_seed->enclosure))
$this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
if ($import_map_seed->has_header)
$this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
$this->ss->assign("SOURCE", $_REQUEST['source']);
}
// add instructions for anything other than custom_delimited
if ($_REQUEST['source'] != 'other')
{
$instructions = array();
$lang_key = '';
switch($_REQUEST['source']) {
case "act":
$lang_key = "ACT";
break;
case "outlook":
$lang_key = "OUTLOOK";
break;
case "salesforce":
$lang_key = "SF";
break;
case "tab":
$lang_key = "TAB";
break;
case "csv":
$lang_key = "CUSTOM";
break;
}
if ( $lang_key != '' ) {
for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++) {
$instructions[] = array(
"STEP_NUM" => $mod_strings["LBL_NUM_$i"],
"INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
);
}
$this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
$this->ss->assign("instructions",$instructions);
}
}
$this->ss->display('modules/Import/tpls/step2.tpl');
}
/**
* Returns JS used in this view
*/
private function _getJS()
{
global $mod_strings;
return <<<EOJAVASCRIPT
<script type="text/javascript">
<!--
document.getElementById('goback').onclick = function(){
document.getElementById('importstep2').action.value = 'Step1';
return true;
}
document.getElementById('gonext').onclick = function(){
document.getElementById('importstep2').action.value = 'Step3';
clear_all_errors();
var isError = false;
// be sure we specify a file to upload
if (document.getElementById('importstep2').userfile.value == "") {
add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
isError = true;
}
return !isError;
}
-->
</script>
EOJAVASCRIPT;
}
}

View File

@@ -0,0 +1,765 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for step 3 of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
require_once('modules/Import/ImportFile.php');
require_once('modules/Import/ImportFileSplitter.php');
require_once('modules/Import/ImportCacheFiles.php');
require_once('modules/Import/ImportDuplicateCheck.php');
require_once('include/upload_file.php');
class ImportViewStep3 extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::_getModuleTitleParams()
*/
protected function _getModuleTitleParams()
{
global $mod_strings;
return array(
"<a href='index.php?module={$_REQUEST['import_module']}&action=index'>".translate('LBL_MODULE_NAME',$_REQUEST['import_module'])."</a>",
"<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
$mod_strings['LBL_STEP_3_TITLE'],
);
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings, $app_strings, $current_user, $sugar_config, $app_list_strings, $locale;
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("APP", $app_strings);
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
$has_header = ( isset( $_REQUEST['has_header']) ? 1 : 0 );
$sugar_config['import_max_records_per_file'] =
( empty($sugar_config['import_max_records_per_file'])
? 1000 : $sugar_config['import_max_records_per_file'] );
// load the bean for the import module
$focus = loadImportBean($_REQUEST['import_module']);
if ( !$focus ) {
showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
return;
}
// Clear out this user's last import
$seedUsersLastImport = new UsersLastImport();
$seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
ImportCacheFiles::clearCacheFiles();
// attempt to lookup a preexisting field map
// use the custom one if specfied to do so in step 1
$field_map = array();
$default_values = array();
$ignored_fields = array();
if ( !empty( $_REQUEST['source_id'])) {
$mapping_file = new ImportMap();
$mapping_file->retrieve( $_REQUEST['source_id'],false);
$_REQUEST['source'] = $mapping_file->source;
$has_header = $mapping_file->has_header;
if (isset($mapping_file->delimiter))
$_REQUEST['custom_delimiter'] = $mapping_file->delimiter;
if (isset($mapping_file->enclosure))
$_REQUEST['custom_enclosure'] = htmlentities($mapping_file->enclosure);
$field_map = $mapping_file->getMapping();
$default_values = $mapping_file->getDefaultValues();
$this->ss->assign("MAPNAME",$mapping_file->name);
$this->ss->assign("CHECKMAP",'checked="checked" value="on"');
}
else {
// Try to see if we have a custom mapping we can use
// based upon the where the records are coming from
// and what module we are importing into
$classname = 'ImportMap' . ucfirst($_REQUEST['source']);
require("modules/Import/{$classname}.php");
$mapping_file = new $classname;
if (isset($mapping_file->delimiter))
$_REQUEST['custom_delimiter'] = $mapping_file->delimiter;
if (isset($mapping_file->enclosure))
$_REQUEST['custom_enclosure'] = htmlentities($mapping_file->enclosure);
$ignored_fields = $mapping_file->getIgnoredFields($_REQUEST['import_module']);
$field_map = $mapping_file->getMapping($_REQUEST['import_module']);
}
$this->ss->assign("CUSTOM_DELIMITER",
( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
$this->ss->assign("CUSTOM_ENCLOSURE",
( !empty($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : "" ));
// handle uploaded file
$uploadFile = new UploadFile('userfile');
if (isset($_FILES['userfile']) && $uploadFile->confirm_upload())
{
$uploadFile->final_move('IMPORT_'.$focus->object_name.'_'.$current_user->id);
$uploadFileName = $uploadFile->get_upload_path('IMPORT_'.$focus->object_name.'_'.$current_user->id);
}
else {
showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'],$_REQUEST['import_module'],'Step2');
return;
}
// split file into parts
$splitter = new ImportFileSplitter(
$uploadFileName,
$sugar_config['import_max_records_per_file']);
$splitter->splitSourceFile(
$_REQUEST['custom_delimiter'],
html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES),
$has_header
);
// Now parse the file and look for errors
$importFile = new ImportFile(
$uploadFileName,
$_REQUEST['custom_delimiter'],
html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES)
);
if ( !$importFile->fileExists() ) {
showImportError($mod_strings['LBL_CANNOT_OPEN'],$_REQUEST['import_module'],'Step2');
return;
}
// retrieve first 3 rows
$rows = array();
$system_charset = $locale->default_export_charset;
$user_charset = $locale->getExportCharset();
$other_charsets = 'UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
$charset_for_import = $user_charset; //We will set the default import charset option by user's preference.
$able_to_detect = function_exists('mb_detect_encoding');
for ( $i = 0; $i < 3; $i++ ) {
$rows[$i] = $importFile->getNextRow();
if(!empty($rows[$i]) && $able_to_detect) {
foreach($rows[$i] as & $temp_value) {
$current_charset = mb_detect_encoding($temp_value, "UTF-8, {$user_charset}, {$system_charset}, {$other_charsets}");
if(!empty($current_charset) && $current_charset != "UTF-8") {
$temp_value = $locale->translateCharset($temp_value, $current_charset);// we will use utf-8 for displaying the data on the page.
$charset_for_import = $current_charset;
//set the default import charset option according to the current_charset.
//If it is not utf-8, tt may be overwritten by the later one. So the uploaded file should not contain two types of charset($user_charset, $system_charset), and I think this situation will not occur.
}
}
}
}
$ret_field_count = $importFile->getFieldCount();
// Bug 14689 - Parse the first data row to make sure it has non-empty data in it
$isempty = true;
if ( $rows[(int)$has_header] != false ) {
foreach ( $rows[(int)$has_header] as $value ) {
if ( strlen(trim($value)) > 0 ) {
$isempty = false;
break;
}
}
}
if ($isempty || $rows[(int)$has_header] == false) {
showImportError($mod_strings['LBL_NO_LINES'],$_REQUEST['import_module'],'Step2');
return;
}
// save first row to send to step 4
$this->ss->assign("FIRSTROW", base64_encode(serialize($rows[0])));
// Now build template
$this->ss->assign("TMP_FILE", $uploadFileName );
$this->ss->assign("FILECOUNT", $splitter->getFileCount() );
$this->ss->assign("RECORDCOUNT", $splitter->getRecordCount() );
$this->ss->assign("RECORDTHRESHOLD", $sugar_config['import_max_records_per_file']);
$this->ss->assign("SOURCE", $_REQUEST['source'] );
$this->ss->assign("TYPE", $_REQUEST['type'] );
$this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('basic_search','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
$this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('advanced_search','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
$this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
$this->ss->assign("STEP4_TITLE",
strip_tags(str_replace("\n","",get_module_title(
$mod_strings['LBL_MODULE_NAME'],
$mod_strings['LBL_MODULE_NAME']." ".$mod_strings['LBL_STEP_4_TITLE'],
false
)))
);
$this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
// we export it as email_address, but import as email1
$field_map['email_address'] = 'email1';
// build each row; row count is determined by the the number of fields in the import file
$columns = array();
$mappedFields = array();
for($field_count = 0; $field_count < $ret_field_count; $field_count++) {
// See if we have any field map matches
$defaultValue = "";
// Bug 31260 - If the data rows have more columns than the header row, then just add a new header column
if ( !isset($rows[0][$field_count]) )
$rows[0][$field_count] = '';
// See if we can match the import row to a field in the list of fields to import
$firstrow_name = trim(str_replace(":","",$rows[0][$field_count]));
if ($has_header && isset( $field_map[$firstrow_name] ) ) {
$defaultValue = $field_map[$firstrow_name];
}
elseif (isset($field_map[$field_count])) {
$defaultValue = $field_map[$field_count];
}
elseif (empty( $_REQUEST['source_id'])) {
$defaultValue = trim($rows[0][$field_count]);
}
// build string of options
$fields = $focus->get_importable_fields();
$options = array();
$defaultField = '';
foreach ( $fields as $fieldname => $properties ) {
// get field name
if (!empty ($properties['vname']))
$displayname = str_replace(":","",translate($properties['vname'] ,$focus->module_dir));
else
$displayname = str_replace(":","",translate($properties['name'] ,$focus->module_dir));
// see if this is required
$req_mark = "";
$req_class = "";
if ( array_key_exists($fieldname, $focus->get_import_required_fields()) ) {
$req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
$req_class = ' class="required" ';
}
// see if we have a match
$selected = '';
if ( !empty($defaultValue) && !in_array($fieldname,$mappedFields)
&& !in_array($fieldname,$ignored_fields) ) {
if ( strtolower($fieldname) == strtolower($defaultValue)
|| strtolower($fieldname) == str_replace(" ","_",strtolower($defaultValue))
|| strtolower($displayname) == strtolower($defaultValue)
|| strtolower($displayname) == str_replace(" ","_",strtolower($defaultValue)) ) {
$selected = ' selected="selected" ';
$defaultField = $fieldname;
$mappedFields[] = $fieldname;
}
}
// get field type information
$fieldtype = '';
if ( isset($properties['type'])
&& isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])]) )
$fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
if ( isset($properties['comment']) )
$fieldtype .= ' - ' . $properties['comment'];
$options[$displayname.$fieldname] = '<option value="'.$fieldname.'" title="'. $displayname . htmlentities($fieldtype) . '"'
. $selected . $req_class . '>' . $displayname . $req_mark . '</option>\n';
}
// get default field value
$defaultFieldHTML = '';
if ( !empty($defaultField) ) {
$defaultFieldHTML = getControl(
$_REQUEST['import_module'],
$defaultField,
$fields[$defaultField],
( isset($default_values[$defaultField]) ? $default_values[$defaultField] : '' )
);
}
if ( isset($default_values[$defaultField]) )
unset($default_values[$defaultField]);
// Bug 27046 - Sort the column name picker alphabetically
ksort($options);
$columns[] = array(
'field_choices' => implode('',$options),
'default_field' => $defaultFieldHTML,
'cell1' => str_replace("&quot;",'',htmlspecialchars($rows[0][$field_count])),
'cell2' => str_replace("&quot;",'',htmlspecialchars($rows[1][$field_count])),
'cell3' => str_replace("&quot;",'',htmlspecialchars($rows[2][$field_count])),
'show_remove' => false,
);
}
// add in extra defaulted fields if they are in the mapping record
if ( count($default_values) > 0 ) {
foreach ( $default_values as $field_name => $default_value ) {
// build string of options
$fields = $focus->get_importable_fields();
$options = array();
$defaultField = '';
foreach ( $fields as $fieldname => $properties ) {
// get field name
if (!empty ($properties['vname']))
$displayname = str_replace(":","",translate($properties['vname'] ,$focus->module_dir));
else
$displayname = str_replace(":","",translate($properties['name'] ,$focus->module_dir));
// see if this is required
$req_mark = "";
$req_class = "";
if ( array_key_exists($fieldname, $focus->get_import_required_fields()) ) {
$req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
$req_class = ' class="required" ';
}
// see if we have a match
$selected = '';
if ( strtolower($fieldname) == strtolower($field_name)
&& !in_array($fieldname,$mappedFields)
&& !in_array($fieldname,$ignored_fields) ) {
$selected = ' selected="selected" ';
$defaultField = $fieldname;
$mappedFields[] = $fieldname;
}
// get field type information
$fieldtype = '';
if ( isset($properties['type'])
&& isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])]) )
$fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
if ( isset($properties['comment']) )
$fieldtype .= ' - ' . $properties['comment'];
$options[$displayname.$fieldname] = '<option value="'.$fieldname.'" title="'. $displayname . $fieldtype . '"' . $selected . $req_class . '>'
. $displayname . $req_mark . '</option>\n';
}
// get default field value
$defaultFieldHTML = '';
if ( !empty($defaultField) ) {
$defaultFieldHTML = getControl(
$_REQUEST['import_module'],
$defaultField,
$fields[$defaultField],
$default_value
);
}
// Bug 27046 - Sort the column name picker alphabetically
ksort($options);
$columns[] = array(
'field_choices' => implode('',$options),
'default_field' => $defaultFieldHTML,
'show_remove' => true,
);
$ret_field_count++;
}
}
$this->ss->assign("COLUMNCOUNT",$ret_field_count);
$this->ss->assign("rows",$columns);
// get list of valid date/time formats
$timeFormat = $current_user->getUserDateTimePreferences();
$timeOptions = get_select_options_with_id($sugar_config['time_formats'], $timeFormat['time']);
$dateOptions = get_select_options_with_id($sugar_config['date_formats'], $timeFormat['date']);
$this->ss->assign('TIMEOPTIONS', $timeOptions);
$this->ss->assign('DATEOPTIONS', $dateOptions);
$this->ss->assign('datetimeformat', $GLOBALS['timedate']->get_cal_date_time_format());
// get list of valid timezones
require_once('include/timezone/timezones.php');
global $timezones;
$userTZ = $current_user->getPreference('timezone');
if(empty($userTZ))
$userTZ = lookupTimezone();
$timezoneOptions = '';
ksort($timezones);
foreach($timezones as $key => $value) {
$selected =($userTZ == $key) ? ' SELECTED="true"' : '';
$dst = !empty($value['dstOffset']) ? '(+DST)' : '';
$gmtOffset =($value['gmtOffset'] / 60);
if(!strstr($gmtOffset,'-')) {
$gmtOffset = '+'.$gmtOffset;
}
$timezoneOptions .= "<option value='$key'".$selected.">".str_replace(array('_','North'), array(' ', 'N.'),translate('timezone_dom','',$key)). "(GMT".$gmtOffset.") ".$dst."</option>";
}
$this->ss->assign('TIMEZONEOPTIONS', $timezoneOptions);
// get currency preference
require_once('modules/Currencies/ListCurrency.php');
$currency = new ListCurrency();
$cur_id = $locale->getPrecedentPreference('currency', $current_user);
if($cur_id) {
$selectCurrency = $currency->getSelectOptions($cur_id);
$this->ss->assign("CURRENCY", $selectCurrency);
} else {
$selectCurrency = $currency->getSelectOptions();
$this->ss->assign("CURRENCY", $selectCurrency);
}
$currenciesVars = "";
$i=0;
foreach($locale->currencies as $id => $arrVal) {
$currenciesVars .= "currencies[{$i}] = '{$arrVal['symbol']}';\n";
$i++;
}
$currencySymbolsJs = <<<eoq
var currencies = new Object;
{$currenciesVars}
function setSymbolValue(id) {
document.getElementById('symbol').value = currencies[id];
}
eoq;
$this->ss->assign('currencySymbolJs', $currencySymbolsJs);
// fill significant digits dropdown
$significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
$sigDigits = '';
for($i=0; $i<=6; $i++) {
if($significantDigits == $i) {
$sigDigits .= '<option value="'.$i.'" selected="true">'.$i.'</option>';
} else {
$sigDigits .= '<option value="'.$i.'">'.$i.'</option>';
}
}
$this->ss->assign('sigDigits', $sigDigits);
$num_grp_sep = $current_user->getPreference('num_grp_sep');
$dec_sep = $current_user->getPreference('dec_sep');
$this->ss->assign("NUM_GRP_SEP",
( empty($num_grp_sep)
? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep ));
$this->ss->assign("DEC_SEP",
( empty($dec_sep)
? $sugar_config['default_decimal_seperator'] : $dec_sep ));
$this->ss->assign('getNumberJs', $locale->getNumberJs());
// Name display format
$this->ss->assign('default_locale_name_format', $locale->getLocaleFormatMacro($current_user));
$this->ss->assign('getNameJs', $locale->getNameJs());
// Charset
$charsetOptions = get_select_options_with_id(
$locale->getCharsetSelect(), $charset_for_import);//wdong, bug 25927, here we should use the charset testing results from above.
$this->ss->assign('CHARSETOPTIONS', $charsetOptions);
// handle building index selector
global $dictionary, $current_language;
require_once("include/templates/TemplateGroupChooser.php");
$chooser_array = array();
$chooser_array[0] = array();
$idc = new ImportDuplicateCheck($focus);
$chooser_array[1] = $idc->getDuplicateCheckIndexes();
$chooser = new TemplateGroupChooser();
$chooser->args['id'] = 'selected_indices';
$chooser->args['values_array'] = $chooser_array;
$chooser->args['left_name'] = 'choose_index';
$chooser->args['right_name'] = 'ignore_index';
$chooser->args['left_label'] = $mod_strings['LBL_INDEX_USED'];
$chooser->args['right_label'] = $mod_strings['LBL_INDEX_NOT_USED'];
$this->ss->assign("TAB_CHOOSER", $chooser->display());
// show notes
if ( $focus instanceof Person )
$module_key = "LBL_CONTACTS_NOTE_";
elseif ( $focus instanceof Company )
$module_key = "LBL_ACCOUNTS_NOTE_";
else
$module_key = "LBL_".strtoupper($_REQUEST['import_module'])."_NOTE_";
$notetext = '';
for ($i = 1;isset($mod_strings[$module_key.$i]);$i++) {
$notetext .= '<li>' . $mod_strings[$module_key.$i] . '</li>';
}
$this->ss->assign("NOTETEXT",$notetext);
$this->ss->assign("HAS_HEADER",($has_header ? 'on' : 'off' ));
// get list of required fields
$required = array();
foreach ( array_keys($focus->get_import_required_fields()) as $name ) {
$properties = $focus->getFieldDefinition($name);
if (!empty ($properties['vname']))
$required[$name] = str_replace(":","",translate($properties['vname'] ,$focus->module_dir));
else
$required[$name] = str_replace(":","",translate($properties['name'] ,$focus->module_dir));
}
// include anything needed for quicksearch to work
require_once("include/TemplateHandler/TemplateHandler.php");
$quicksearch_js = TemplateHandler::createQuickSearchCode($fields,$fields,'importstep3');
$this->ss->assign("JAVASCRIPT", $quicksearch_js . "\n" . $this->_getJS($required));
$this->ss->assign('required_fields',implode(', ',$required));
$this->ss->display('modules/Import/tpls/step3.tpl');
}
/**
* Returns JS used in this view
*/
private function _getJS($required)
{
global $mod_strings;
$print_required_array = "";
foreach ($required as $name=>$display) {
$print_required_array .= "required['$name'] = '". $display . "';\n";
}
$sqsWaitImage = SugarThemeRegistry::current()->getImageURL('sqsWait.gif');
return <<<EOJAVASCRIPT
<script type="text/javascript">
<!--
document.getElementById('goback').onclick = function(){
document.getElementById('importstep3').action.value = 'Step2';
document.getElementById('importstep3').to_pdf.value = '0';
return true;
}
document.getElementById('importnow').onclick = function(){
// get the list of indices chosen
var chosen_indices = '';
var selectedOptions = document.getElementById('choose_index_td').getElementsByTagName('select')[0].options.length;
for (i = 0; i < selectedOptions; i++)
{
chosen_indices += document.getElementById('choose_index_td').getElementsByTagName('select')[0].options[i].value;
if (i != (selectedOptions - 1))
chosen_indices += "&";
}
document.getElementById('importstep3').display_tabs_def.value = chosen_indices;
// validate form
clear_all_errors();
var form = document.getElementById('importstep3');
var hash = new Object();
var required = new Object();
$print_required_array
var isError = false;
for ( i = 0; i < form.length; i++ ) {
if ( form.elements[i].name.indexOf("colnum",0) == 0) {
if ( form.elements[i].value == "-1") {
continue;
}
if ( hash[ form.elements[i].value ] == 1) {
isError = true;
add_error_style('importstep3',form.elements[i].name,"{$mod_strings['ERR_MULTIPLE']}");
}
hash[form.elements[i].value] = 1;
}
}
// check for required fields
for(var field_name in required) {
// contacts hack to bypass errors if full_name is set
if (field_name == 'last_name' &&
hash['full_name'] == 1) {
continue;
}
if ( hash[ field_name ] != 1 ) {
isError = true;
add_error_style('importstep3',form.colnum_0.name,
"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} " + required[field_name]);
}
}
// return false if we got errors
if (isError == true) {
return false;
}
// Move on to next step
document.getElementById('importstep3').action.value = 'Step4';
ProcessImport.begin();
}
// handle adding new row
document.getElementById('addrow').onclick = function(){
rownum = document.getElementById('importstep3').columncount.value;
newrow = document.createElement("tr");
column0 = document.getElementById('row_0_col_0').cloneNode(true);
column0.id = 'row_' + rownum + '_col_0';
for ( i = 0; i < column0.childNodes.length; i++ ) {
if ( column0.childNodes[i].name == 'colnum_0' ) {
column0.childNodes[i].name = 'colnum_' + rownum;
column0.childNodes[i].onchange = function(){
var module = document.getElementById('importstep3').import_module.value;
var fieldname = this.value;
var matches = /colnum_([0-9]+)/i.exec(this.name);
var fieldnum = matches[1];
if ( fieldname == -1 ) {
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '';
return;
}
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '<img src="{$sqsWaitImage}" />'
YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=Import&action=GetControl&import_module='+module+'&field_name='+fieldname,
{
success: function(o)
{
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = o.responseText;
SUGAR.util.evalScript(o.responseText);
enableQS(true);
},
failure: function(o) {/*failure handler code*/}
});
}
}
}
newrow.appendChild(column0);
if ( document.getElementById('row_0_header') ) {
column1 = document.getElementById('row_0_header').cloneNode(true);
column1.innerHTML = '&nbsp;';
newrow.appendChild(column1);
}
column2 = document.getElementById('defaultvaluepicker_0').cloneNode(true);
column2.id = 'defaultvaluepicker_' + rownum;
newrow.appendChild(column2);
column3 = document.createElement('td');
column3.className = 'tabDetailViewDL';
if ( !document.getElementById('row_0_header') ) {
column3.colSpan = 2;
}
column3.innerHTML = '<input title="{$mod_strings['LBL_REMOVE_ROW']}" accessKey="" id="deleterow_' + rownum + '" class="button" type="button" value=" {$mod_strings['LBL_REMOVE_ROW']} ">';
newrow.appendChild(column3);
document.getElementById('importstep3').columncount.value = parseInt(document.getElementById('importstep3').columncount.value) + 1;
document.getElementById('row_0_col_0').parentNode.parentNode.insertBefore(newrow,this.parentNode.parentNode);
document.getElementById('deleterow_' + rownum).onclick = function(){
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
}
}
YAHOO.util.Event.onDOMReady(function(){
var selects = document.getElementsByTagName('select');
for (var i = 0; i < selects.length; ++i ){
if (selects[i].name.indexOf("colnum_") != -1 ) {
// fetch the field input control via ajax
selects[i].onchange = function(){
var module = document.getElementById('importstep3').import_module.value;
var fieldname = this.value;
var matches = /colnum_([0-9]+)/i.exec(this.name);
var fieldnum = matches[1];
if ( fieldname == -1 ) {
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '';
return;
}
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '<img src="{$sqsWaitImage}" />'
YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=Import&action=GetControl&import_module='+module+'&field_name='+fieldname,
{
success: function(o)
{
document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = o.responseText;
SUGAR.util.evalScript(o.responseText);
enableQS(true);
},
failure: function(o) {/*failure handler code*/}
});
}
}
}
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i ){
if (inputs[i].id.indexOf("deleterow_") != -1 ) {
inputs[i].onclick = function(){
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
}
}
}
});
document.getElementById('toggleImportOptions').onclick = function() {
if (document.getElementById('importOptions').style.display == 'none'){
document.getElementById('importOptions').style.display = '';
document.getElementById('toggleImportOptions').value=' {$mod_strings['LBL_HIDE_ADVANCED_OPTIONS']} ';
document.getElementById('toggleImportOptions').title='{$mod_strings['LBL_HIDE_ADVANCED_OPTIONS']}';
}
else {
document.getElementById('importOptions').style.display = 'none';
document.getElementById('toggleImportOptions').value=' {$mod_strings['LBL_SHOW_ADVANCED_OPTIONS']} ';
document.getElementById('toggleImportOptions').title='{$mod_strings['LBL_SHOW_ADVANCED_OPTIONS']}';
}
}
-->
</script>
EOJAVASCRIPT;
}
}

View File

@@ -0,0 +1,623 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for step 4 of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
require_once('modules/Import/ImportFile.php');
require_once('modules/Import/ImportFileSplitter.php');
require_once('modules/Import/ImportCacheFiles.php');
require_once('modules/Import/ImportFieldSanitize.php');
require_once('modules/Import/ImportDuplicateCheck.php');
class ImportViewStep4 extends SugarView
{
/**
* @see SugarView::display()
*/
public function display()
{
global $sugar_config;
// Increase the max_execution_time since this step can take awhile
ini_set("max_execution_time", max($sugar_config['import_max_execution_time'],3600));
// stop the tracker
TrackerManager::getInstance()->pause();
// use our own error handler
set_error_handler('handleImportErrors',E_ALL);
global $mod_strings, $app_strings, $current_user, $import_bean_map;
global $app_list_strings, $timedate;
$update_only = ( isset($_REQUEST['import_type']) && $_REQUEST['import_type'] == 'update' );
$firstrow = unserialize(base64_decode($_REQUEST['firstrow']));
// All the Look Up Caches are initialized here
$enum_lookup_cache=array();
// Let's try and load the import bean
$focus = loadImportBean($_REQUEST['import_module']);
if ( !$focus ) {
trigger_error($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],E_USER_ERROR);
}
// setup the importable fields array.
$importable_fields = $focus->get_importable_fields();
// loop through all request variables
$importColumns = array();
foreach ($_REQUEST as $name => $value) {
// only look for var names that start with "fieldNum"
if (strncasecmp($name, "colnum_", 7) != 0) {
continue;
}
// pull out the column position for this field name
$pos = substr($name, 7);
if ( isset($importable_fields[$value]) ) {
// now mark that we've seen this field
$importColumns[$pos] = $value;
}
}
// set the default locale settings
$ifs = new ImportFieldSanitize();
$ifs->dateformat = $_REQUEST['importlocale_dateformat'];
$ifs->timeformat = $_REQUEST['importlocale_timeformat'];
$ifs->timezone = $_REQUEST['importlocale_timezone'];
$currency = new Currency();
$currency->retrieve($_REQUEST['importlocale_currency']);
$ifs->currency_symbol = $currency->symbol;
$ifs->default_currency_significant_digits
= $_REQUEST['importlocale_default_currency_significant_digits'];
$ifs->num_grp_sep
= $_REQUEST['importlocale_num_grp_sep'];
$ifs->dec_sep = $_REQUEST['importlocale_dec_sep'];
$ifs->default_locale_name_format
= $_REQUEST['importlocale_default_locale_name_format'];
// Check to be sure we are getting an import file that is in the right place
if ( realpath(dirname($_REQUEST['tmp_file']).'/') != realpath($sugar_config['upload_dir']) )
trigger_error($mod_strings['LBL_CANNOT_OPEN'],E_USER_ERROR);
// Open the import file
$importFile = new ImportFile(
$_REQUEST['tmp_file'],
$_REQUEST['custom_delimiter'],
html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES)
);
if ( !$importFile->fileExists() ) {
trigger_error($mod_strings['LBL_CANNOT_OPEN'],E_USER_ERROR);
}
$fieldDefs = $focus->getFieldDefinitions();
unset($focus);
while ( $row = $importFile->getNextRow() ) {
$focus = loadImportBean($_REQUEST['import_module']);
$focus->unPopulateDefaultValues();
$focus->save_from_post = false;
$focus->team_id = null;
$ifs->createdBeans = array();
$do_save = true;
for ( $fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++ ) {
// loop if this column isn't set
if ( !isset($importColumns[$fieldNum]) ) {
continue;
}
// get this field's properties
$field = $importColumns[$fieldNum];
$fieldDef = $focus->getFieldDefinition($field);
$fieldTranslated = translate((isset($fieldDef['vname'])?$fieldDef['vname']:$fieldDef['name']),
$_REQUEST['module'])." (".$fieldDef['name'].")";
// Bug 37241 - Don't re-import over a field we already set during the importing of another field
if ( !empty($focus->$field) ) {
continue;
}
// translate strings
global $locale;
if(empty($locale)) {
$locale = new Localization();
}
if ( isset($row[$fieldNum]) )
$rowValue = $locale->translateCharset(
strip_tags(trim($row[$fieldNum])),
$_REQUEST['importlocale_charset'],
$sugar_config['default_charset']
);
else
$rowValue = '';
// If there is an default value then use it instead
if ( !empty($_REQUEST[$field]) ) {
if ( is_array($_REQUEST[$field]) )
$defaultRowValue = encodeMultienumValue($_REQUEST[$field]);
else
$defaultRowValue = $_REQUEST[$field];
// translate default values to the date/time format for the import file
if ( $fieldDef['type'] == 'date'
&& $ifs->dateformat != $timedate->get_date_format() )
$defaultRowValue = $timedate->swap_formats(
$defaultRowValue, $ifs->dateformat, $timedate->get_date_format());
if ( $fieldDef['type'] == 'time'
&& $ifs->timeformat != $timedate->get_time_format() )
$defaultRowValue = $timedate->swap_formats(
$defaultRowValue, $ifs->timeformat, $timedate->get_time_format());
if ( ($fieldDef['type'] == 'datetime' || $fieldDef['type'] == 'datetimecombo')
&& $ifs->dateformat.' '.$ifs->timeformat != $timedate->get_date_time_format() )
$defaultRowValue = $timedate->swap_formats(
$defaultRowValue, $ifs->dateformat.' '.$ifs->timeformat,
$timedate->get_date_time_format());
if ( in_array($fieldDef['type'],array('currency','float','int','num'))
&& $ifs->num_grp_sep != $current_user->getPreference('num_grp_sep') )
$defaultRowValue = str_replace($current_user->getPreference('num_grp_sep'),
$ifs->num_grp_sep,$defaultRowValue);
if ( in_array($fieldDef['type'],array('currency','float'))
&& $ifs->dec_sep != $current_user->getPreference('dec_sep') )
$defaultRowValue = str_replace($current_user->getPreference('dec_sep'),
$ifs->dec_sep,$defaultRowValue);
$currency->retrieve('-99');
$user_currency_symbol = $currency->symbol;
if ( $fieldDef['type'] == 'currency'
&& $ifs->currency_symbol != $user_currency_symbol )
$defaultRowValue = str_replace($user_currency_symbol,
$ifs->currency_symbol,$defaultRowValue);
if ( empty($rowValue) ) {
$rowValue = $defaultRowValue;
unset($defaultRowValue);
}
}
// Bug 22705 - Don't update the First Name or Last Name value if Full Name is set
if ( in_array($field, array('first_name','last_name')) && !empty($focus->full_name) )
continue;
// loop if this value has not been set
if ( !isset($rowValue) )
continue;
// If the field is required and blank then error out
if ( array_key_exists($field,$focus->get_import_required_fields())
&& empty($rowValue)
&& $rowValue!='0') {
$importFile->writeError(
$mod_strings['LBL_REQUIRED_VALUE'],
$fieldTranslated,
'NULL'
);
$do_save = false;
}
// Handle the special case "Sync to Outlook"
if ( $focus->object_name == "Contacts" && $field == 'sync_contact' ) {
$bad_names = array();
$returnValue = $ifs->synctooutlook(
$rowValue,
$fieldDef,
$bad_names);
// try the default value on fail
if ( !$returnValue && !empty($defaultRowValue) )
$returnValue = $ifs->synctooutlook(
$defaultRowValue,
$fieldDef,
$bad_names);
if ( !$returnValue ) {
$importFile->writeError(
$mod_strings['LBL_ERROR_SYNC_USERS'],
$fieldTranslated,
explode(",",$bad_names));
$do_save = 0;
}
}
// Handle email1 and email2 fields ( these don't have the type of email )
if ( $field == 'email1' || $field == 'email2' ) {
$returnValue = $ifs->email($rowValue, $fieldDef);
// try the default value on fail
if ( !$returnValue && !empty($defaultRowValue) )
$returnValue = $ifs->email(
$defaultRowValue,
$fieldDef);
if ( $returnValue === FALSE ) {
$do_save=0;
$importFile->writeError(
$mod_strings['LBL_ERROR_INVALID_EMAIL'],
$fieldTranslated,
$rowValue);
}
else {
$rowValue = $returnValue;
// check for current opt_out and invalid email settings for this email address
// if we find any, set them now
$emailres = $focus->db->query(
"SELECT opt_out, invalid_email FROM email_addresses
WHERE email_address = '".$focus->db->quote($rowValue)."'");
if ( $emailrow = $focus->db->fetchByAssoc($emailres) ) {
$focus->email_opt_out = $emailrow['opt_out'];
$focus->invalid_email = $emailrow['invalid_email'];
}
}
}
// Handle splitting Full Name into First and Last Name parts
if ( $field == 'full_name' && !empty($rowValue) ) {
$ifs->fullname(
$rowValue,
$fieldDef,
$focus);
}
// to maintain 451 compatiblity
if(!isset($fieldDef['module']) && $fieldDef['type']=='relate')
$fieldDef['module'] = ucfirst($fieldDef['table']);
if(isset($fieldDef['custom_type']) && !empty($fieldDef['custom_type']))
$fieldDef['type'] = $fieldDef['custom_type'];
// If the field is empty then there is no need to check the data
if( !empty($rowValue) ) {
switch ($fieldDef['type']) {
case 'enum':
case 'multienum':
if ( isset($fieldDef['type']) && $fieldDef['type'] == "multienum" )
$returnValue = $ifs->multienum($rowValue,$fieldDef);
else
$returnValue = $ifs->enum($rowValue,$fieldDef);
// try the default value on fail
if ( !$returnValue && !empty($defaultRowValue) )
if ( isset($fieldDef['type']) && $fieldDef['type'] == "multienum" )
$returnValue = $ifs->multienum($defaultRowValue,$fieldDef);
else
$returnValue = $ifs->enum($defaultRowValue,$fieldDef);
if ( $returnValue === FALSE ) {
$importFile->writeError(
$mod_strings['LBL_ERROR_NOT_IN_ENUM']
. implode(",",$app_list_strings[$fieldDef['options']]),
$fieldTranslated,
$rowValue);
$do_save = 0;
}
else
$rowValue = $returnValue;
break;
case 'relate':
case 'parent':
$returnValue = $ifs->relate(
$rowValue,
$fieldDef,
$focus,
empty($defaultRowValue));
if ( !$returnValue && !empty($defaultRowValue) )
$returnValue = $ifs->relate(
$defaultRowValue,
$fieldDef,
$focus);
// Bug 33623 - Set the id value found from the above method call as an importColumn
if ( $returnValue !== false )
$importColumns[] = $fieldDef['id_name'];
break;
case 'teamset':
$returnValue = $ifs->teamset(
$rowValue,
$fieldDef,
$focus);
$importColumns[] = 'team_set_id';
$importColumns[] = 'team_id';
break;
case 'fullname':
break;
default:
if ( method_exists('ImportFieldSanitize',$fieldDef['type']) ) {
$fieldtype = $fieldDef['type'];
$returnValue = $ifs->$fieldtype($rowValue, $fieldDef);
// try the default value on fail
if ( !$returnValue && !empty($defaultRowValue) )
$returnValue = $ifs->$fieldtype(
$defaultRowValue,
$fieldDef);
if ( !$returnValue ) {
$do_save=0;
$importFile->writeError(
$mod_strings['LBL_ERROR_INVALID_'.strtoupper($fieldDef['type'])],
$fieldTranslated,
$rowValue);
}
else
$rowValue = $returnValue;
}
}
}
$focus->$field = $rowValue;
unset($defaultRowValue);
}
// Now try to validate flex relate fields
if ( isset($focus->field_defs['parent_name'])
&& isset($focus->parent_name)
&& ($focus->field_defs['parent_name']['type'] == 'parent') ) {
// populate values from the picker widget if the import file doesn't have them
$parent_idField = $focus->field_defs['parent_name']['id_name'];
if ( empty($focus->$parent_idField) && !empty($_REQUEST[$parent_idField]) )
$focus->$parent_idField = $_REQUEST[$parent_idField];
$parent_typeField = $focus->field_defs['parent_name']['type_name'];
if ( empty($focus->$parent_typeField) && !empty($_REQUEST[$parent_typeField]) )
$focus->$parent_typeField = $_REQUEST[$parent_typeField];
// now validate it
$returnValue = $ifs->parent(
$focus->parent_name,
$focus->field_defs['parent_name'],
$focus,
empty($_REQUEST['parent_name']));
if ( !$returnValue && !empty($_REQUEST['parent_name']) )
$returnValue = $ifs->parent(
$_REQUEST['parent_name'],
$focus->field_defs['parent_name'],
$focus);
}
// check to see that the indexes being entered are unique.
if (isset($_REQUEST['display_tabs_def']) && $_REQUEST['display_tabs_def'] != ""){
$idc = new ImportDuplicateCheck($focus);
if ( $idc->isADuplicateRecord(explode('&', $_REQUEST['display_tabs_def'])) ){
$importFile->markRowAsDuplicate();
$this->_undoCreatedBeans($ifs->createdBeans);
continue;
}
}
// if the id was specified
$newRecord = true;
if ( !empty($focus->id) ) {
$focus->id = $this->_convertId($focus->id);
// check if it already exists
$query = "SELECT * FROM {$focus->table_name} WHERE id='".$focus->db->quote($focus->id)."'";
$result = $focus->db->query($query)
or sugar_die("Error selecting sugarbean: ");
$dbrow = $focus->db->fetchByAssoc($result);
if (isset ($dbrow['id']) && $dbrow['id'] != -1) {
// if it exists but was deleted, just remove it
if (isset ($dbrow['deleted']) && $dbrow['deleted'] == 1 && $update_only==false) {
$query2 = "DELETE FROM {$focus->table_name} WHERE id='".$focus->db->quote($focus->id)."'";
$result2 = $focus->db->query($query2) or sugar_die($mod_strings['LBL_ERROR_DELETING_RECORD']." ".$focus->id);
if ($focus->hasCustomFields()) {
$query3 = "DELETE FROM {$focus->table_name}_cstm WHERE id_c='".$focus->db->quote($focus->id)."'";
$result2 = $focus->db->query($query3);
}
$focus->new_with_id = true;
}
else {
if( !$update_only ) {
$do_save = 0;
$importFile->writeError($mod_strings['LBL_ID_EXISTS_ALREADY'],'ID',$focus->id);
$this->_undoCreatedBeans($ifs->createdBeans);
continue;
}
$existing_focus = loadImportBean($_REQUEST['import_module']);
$newRecord = false;
if ( !( $existing_focus->retrieve($dbrow['id']) instanceOf SugarBean ) ) {
$do_save = 0;
$importFile->writeError($mod_strings['LBL_RECORD_CANNOT_BE_UPDATED'],'ID',$focus->id);
$this->_undoCreatedBeans($ifs->createdBeans);
continue;
}
else {
$newData = $focus->toArray();
foreach ( $newData as $focus_key => $focus_value )
if ( in_array($focus_key,$importColumns) )
$existing_focus->$focus_key = $focus_value;
$focus = $existing_focus;
}
unset($existing_focus);
}
}
else {
$focus->new_with_id = true;
}
}
if ($do_save) {
// Populate in any default values to the bean
$focus->populateDefaultValues();
if ( !isset($focus->assigned_user_id) || $focus->assigned_user_id == '' && $newRecord ) {
$focus->assigned_user_id = $current_user->id;
}
if ( !empty($focus->date_modified) )
$focus->update_date_modified = false;
$focus->optimistic_lock = false;
if ( $focus->object_name == "Contacts" && isset($focus->sync_contact) ) {
//copy the potential sync list to another varible
$list_of_users=$focus->sync_contact;
//and set it to false for the save
$focus->sync_contact=false;
} else if($focus->object_name == "User" && !empty($current_user) && $focus->is_admin && !is_admin($current_user) && is_admin_for_module($current_user, 'Users')) {
sugar_die($GLOBALS['mod_strings']['ERR_IMPORT_SYSTEM_ADMININSTRATOR']);
}
// call any logic needed for the module preSave
$focus->beforeImportSave();
$focus->save(false);
// call any logic needed for the module postSave
$focus->afterImportSave();
if ( $focus->object_name == "Contacts" && isset($list_of_users) )
$focus->process_sync_to_outlook($list_of_users);
// Update the created/updated counter
$importFile->markRowAsImported($newRecord);
// Add ID to User's Last Import records
if ( $newRecord )
ImportFile::writeRowToLastImport(
$_REQUEST['import_module'],
($focus->object_name == 'Case' ? 'aCase' : $focus->object_name),
$focus->id);
}
else
$this->_undoCreatedBeans($ifs->createdBeans);
}
// save mapping if requested
if ( isset($_REQUEST['save_map_as']) && $_REQUEST['save_map_as'] != '' ) {
$mapping_file = new ImportMap();
if ( isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on') {
$header_to_field = array ();
foreach ($importColumns as $pos => $field_name) {
if (isset($firstrow[$pos]) && isset($field_name)) {
$header_to_field[$firstrow[$pos]] = $field_name;
}
}
$mapping_file->setMapping($header_to_field);
}
else {
$mapping_file->setMapping($importColumns);
}
// save default fields
$defaultValues = array();
for ( $i = 0; $i < $_REQUEST['columncount']; $i++ )
if (isset($importColumns[$i]) && !empty($_REQUEST[$importColumns[$i]])) {
$field = $importColumns[$i];
$fieldDef = $focus->getFieldDefinition($field);
if(!empty($fieldDef['custom_type']) && $fieldDef['custom_type'] == 'teamset') {
require_once('include/SugarFields/Fields/Teamset/SugarFieldTeamset.php');
$sugar_field = new SugarFieldTeamset('Teamset');
$teams = $sugar_field->getTeamsFromRequest($field);
if(isset($_REQUEST['primary_team_name_collection'])) {
$primary_index = $_REQUEST['primary_team_name_collection'];
}
//If primary_index was selected, ensure that the first Array entry is the primary team
if(isset($primary_index)) {
$count = 0;
$new_teams = array();
foreach($teams as $id=>$name) {
if($primary_index == $count++) {
$new_teams[$id] = $name;
unset($teams[$id]);
break;
}
}
foreach($teams as $id=>$name) {
$new_teams[$id] = $name;
}
$teams = $new_teams;
} //if
$json = getJSONobj();
$defaultValues[$field] = $json->encode($teams);
} else {
$defaultValues[$field] = $_REQUEST[$importColumns[$i]];
}
}
$mapping_file->setDefaultValues($defaultValues);
$result = $mapping_file->save(
$current_user->id,
$_REQUEST['save_map_as'],
$_REQUEST['import_module'],
$_REQUEST['source'],
( isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on'),
$_REQUEST['custom_delimiter'],
html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES)
);
}
$importFile->writeStatus();
}
/**
* If a bean save is not done for some reason, this method will undo any of the beans that were created
*
* @param array $ids ids of user_last_import records created
*/
protected function _undoCreatedBeans(
array $ids
)
{
$focus = new UsersLastImport();
foreach ($ids as $id)
$focus->undoById($id);
}
/**
* clean id's when being imported
*
* @param string $string
* @return string
*/
protected function _convertId(
$string
)
{
return preg_replace_callback(
'|[^A-Za-z0-9\-]|',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'return ord($matches[0]);'
) ,
$string);
}
}

View File

@@ -0,0 +1,131 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: view handler for undo step of the import process
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
********************************************************************************/
require_once('include/MVC/View/SugarView.php');
class ImportViewUndo extends SugarView
{
/**
* @see SugarView::getMenu()
*/
public function getMenu(
$module = null
)
{
global $mod_strings, $current_language;
if ( empty($module) )
$module = $_REQUEST['import_module'];
$old_mod_strings = $mod_strings;
$mod_strings = return_module_language($current_language, $module);
$returnMenu = parent::getMenu($module);
$mod_strings = $old_mod_strings;
return $returnMenu;
}
/**
* @see SugarView::_getModuleTab()
*/
protected function _getModuleTab()
{
global $app_list_strings, $moduleTabMap;
// Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
if ( !empty($_REQUEST['module_tab']) )
return $_REQUEST['module_tab'];
elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
return $moduleTabMap[$_REQUEST['import_module']];
// Default anonymous pages to be under Home
elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
return 'Home';
else
return $_REQUEST['import_module'];
}
/**
* @see SugarView::display()
*/
public function display()
{
global $mod_strings, $current_user, $current_language;
$this->ss->assign("MOD", $mod_strings);
$this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
// lookup this module's $mod_strings to get the correct module name
$old_mod_strings = $mod_strings;
$module_mod_strings =
return_module_language($current_language, $_REQUEST['import_module']);
$this->ss->assign("MODULENAME",$module_mod_strings['LBL_MODULE_NAME']);
// reset old ones afterwards
$mod_strings = $old_mod_strings;
$last_import = new UsersLastImport();
$this->ss->assign('UNDO_SUCCESS',$last_import->undo($_REQUEST['import_module']));
$this->ss->assign("JAVASCRIPT", $this->_getJS());
$this->ss->display('modules/Import/tpls/undo.tpl');
}
/**
* Returns JS used in this view
*/
private function _getJS()
{
return <<<EOJAVASCRIPT
<script type="text/javascript">
<!--
document.getElementById('finished').onclick = function(){
document.getElementById('importundo').module.value = document.getElementById('importundo').import_module.value;
document.getElementById('importundo').action.value = 'index';
return true;
}
-->
</script>
EOJAVASCRIPT;
}
}