mirror of
https://github.com/VTECRM/vtenext.git
synced 2026-02-26 16:18:47 +00:00
130 lines
4.8 KiB
PHP
130 lines
4.8 KiB
PHP
<?php
|
|
/*************************************
|
|
* SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. <info@vtenext.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
************************************/
|
|
|
|
$module = vtlib_purify($_REQUEST['module']);
|
|
$focus = CRMEntity::getInstance($module);
|
|
|
|
global $mod_strings, $app_strings, $app_list_strings;
|
|
global $current_language, $currentModule, $theme;
|
|
global $adb, $table_prefix;
|
|
|
|
$theme_path="themes/".$theme."/";
|
|
$image_path=$theme_path."images/";
|
|
|
|
$mode = vtlib_purify($_REQUEST['mergemode']);
|
|
|
|
if($mode == 'mergesave') {
|
|
|
|
$return_module=vtlib_purify($_REQUEST['return_module']);
|
|
$action=vtlib_purify($_REQUEST['action']);
|
|
$return_action=vtlib_purify($_REQUEST['return_action']);
|
|
$parenttab=vtlib_purify($_REQUEST['parent']);
|
|
$merge_id=vtlib_purify($_REQUEST['record']);
|
|
$recordids=vtlib_purify($_REQUEST['pass_rec']);
|
|
|
|
$result = $adb->pquery("SELECT count(*) AS count FROM {$focus->getEntityTableInfo('table')} WHERE {$focus->getEntityTableInfo('index')}=? and deleted=0", array($merge_id)); // crmv@185647
|
|
$count = $adb->query_result($result,0,'count');
|
|
|
|
if($count > 0)
|
|
{
|
|
// First, save the primary record
|
|
$focus->mode="edit";
|
|
setObjectValuesFromRequest($focus);
|
|
$focus->save($module);
|
|
$rec_values=$focus->column_fields;
|
|
|
|
// Remove the id of primary record from the list of records to be deleted.
|
|
$del_value=explode(",",$recordids,-1);
|
|
$offset = array_search($merge_id,$del_value);
|
|
unset($del_value[$offset]);
|
|
|
|
// Transfer the related lists of the records to be deleted, to the primary record's related list
|
|
if(method_exists($focus, 'transferRelatedRecords')){
|
|
$focus->transferRelatedRecords($module,$del_value,$merge_id);
|
|
} else {
|
|
transferRelatedRecords($module,$del_value,$merge_id);
|
|
}
|
|
|
|
// Delete the records by id specified in the list
|
|
foreach($del_value as $value)
|
|
{
|
|
DeleteEntity($_REQUEST['module'],$_REQUEST['return_module'],$focus,$value,"");
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!-- crmv@22022 -->
|
|
<script language="JavaScript" type="text/javascript" src="include/js/general.js"></script>
|
|
<script>parent.getDuplicateListViewEntries_js('<?php echo $module;?>','start='+getOpenerObj('current_page').value);closePopup();</script> <!-- crmv@42329 -->
|
|
<!-- crmv@22022e -->
|
|
<?php
|
|
} elseif ($mode == 'mergefields') {
|
|
|
|
// crmv@168103
|
|
$small_page_title = getTranslatedString('LBL_MERGE_DATA_IN', 'APP_STRINGS');
|
|
$small_page_title .= ' > '.getTranslatedString($module, $module);
|
|
include('themes/SmallHeader.php');
|
|
// crmv@168103e
|
|
|
|
$idstring=vtlib_purify($_REQUEST['passurl']);
|
|
$parent_tab=getParentTab();
|
|
|
|
$exploded_id=explode(",",$idstring,-1);
|
|
$record_count = count($exploded_id);
|
|
|
|
$smarty = new VteSmarty();
|
|
$smarty->assign("EDIT_DUPLICATE","");
|
|
if($record_count == 2) {
|
|
if(isPermitted($currentModule,"EditView",$exploded_id[0]) == 'yes' && isPermitted($currentModule,"EditView",$exploded_id[1]) == 'yes'
|
|
&& isPermitted($currentModule,"Delete",$exploded_id[0]) == 'yes' && isPermitted($currentModule,"Delete",$exploded_id[1]) == 'yes')
|
|
$smarty->assign("EDIT_DUPLICATE","permitted");
|
|
}
|
|
else {
|
|
if(isPermitted($currentModule,"EditView",$exploded_id[0]) == 'yes' && isPermitted($currentModule,"EditView",$exploded_id[1]) == 'yes' && isPermitted($currentModule,"EditView",$exploded_id[2]) == 'yes'
|
|
&& isPermitted($currentModule,"Delete",$exploded_id[0]) == 'yes' && isPermitted($currentModule,"Delete",$exploded_id[1]) == 'yes' && isPermitted($currentModule,"Delete",$exploded_id[2]) == 'yes')
|
|
$smarty->assign("EDIT_DUPLICATE","permitted");
|
|
}
|
|
|
|
$all_values_array=getRecordValues($exploded_id,$module);
|
|
$all_values=$all_values_array[0];
|
|
$js_arr_val=$all_values_array[1];
|
|
$fld_array=$all_values_array[2];
|
|
$js_arr=implode(",",$js_arr_val);
|
|
|
|
$imported_records = Array();
|
|
$sql="select bean_id from {$table_prefix}_users_last_import where bean_type=? and deleted=0";
|
|
$result = $adb->pquery($sql, array($module));
|
|
$num_rows=$adb->num_rows($result);
|
|
$count=0;
|
|
for($i=0; $i<$num_rows;$i++)
|
|
{
|
|
foreach($exploded_id as $value)
|
|
if($value == $adb->query_result($result,$i,"bean_id"))
|
|
$count++;
|
|
array_push($imported_records,$adb->query_result($result,$i,"bean_id"));
|
|
}
|
|
|
|
if ($record_count == $count)
|
|
$no_existing=1;
|
|
else
|
|
$no_existing=0;
|
|
|
|
$smarty->assign("MOD", $mod_strings);
|
|
$smarty->assign("APP", $app_strings);
|
|
$smarty->assign("RECORD_COUNT",$record_count);
|
|
$smarty->assign("THEME", $theme);
|
|
$smarty->assign("IMAGE_PATH", $image_path);
|
|
$smarty->assign("MODULENAME", $module);
|
|
$smarty->assign("PARENT_TAB", $parent_tab);
|
|
$smarty->assign("JS_ARRAY", $js_arr);
|
|
$smarty->assign("ID_ARRAY", $exploded_id);
|
|
$smarty->assign("IDSTRING",$idstring);
|
|
$smarty->assign("ALLVALUES", $all_values);
|
|
$smarty->assign("FIELD_ARRAY", $fld_array);
|
|
$smarty->assign("IMPORTED_RECORDS", $imported_records);
|
|
$smarty->assign("NO_EXISTING", $no_existing);
|
|
$smarty->display("MergeFields.tpl");
|
|
}
|