AddEventHandler('tasks', "OnBeforeTaskAdd", "MultiTaskAdd");
function MultiTaskAdd(&$arFields){
if(\COption::GetOptionString("main",'MULTITASK_IS_ENABLED','') == 'checked'){
$stopExp = 0;
$checkFiestDeal = 9999;
$findStr = "";
/* //битрикс обновился, не работает условие
if($_REQUEST['back_url']) {
if (strpos($_REQUEST['back_url'], 'deal')) {
$findStr = 'D_';
} else if (strpos($_REQUEST['back_url'], 'lead')) {
$findStr = 'L_';
}
}*/
//замена
if(($_REQUEST["IFRAME"]=="Y") && ($_REQUEST['TITLE']=="CRM: ") && !empty($_REQUEST['UF_CRM_TASK'])){
if(strpos($_REQUEST['UF_CRM_TASK'],"D_")!==false){
$findStr = 'D_';
}
elseif(strpos($_REQUEST['UF_CRM_TASK'],"L_")!==false){
$findStr = 'L_';
}
}
if(is_countable($arFields['UF_CRM_TASK']) && count($arFields['UF_CRM_TASK'])>1 and $findStr){
foreach ($arFields['UF_CRM_TASK'] as $key => $taskCrmBinding){
if(stripos($taskCrmBinding, $findStr) === 0 and $checkFiestDeal==9999){
$checkFiestDeal=$key;
$unsetKeys[$key]=$key;
}
elseif(stripos($taskCrmBinding, $findStr) === 0){
$newArfield=$arFields;
unset($newArfield['GUID']);
$newArfield['key']=$key;
$newTaskCompitableArrays[]=$newArfield;
$unsetKeys[$key]=$key;
}
}
foreach ($unsetKeys as $key){
if($key != $checkFiestDeal){
unset($arFields['UF_CRM_TASK'][$key]);
}
}
$obTask = new \CTasks;
foreach ($newTaskCompitableArrays as $key => $compitableArray){
foreach ($unsetKeys as $unKey){
if($unKey !== $compitableArray['key']){
unset($compitableArray['UF_CRM_TASK'][$unKey]);
unset($newTaskCompitableArrays[$key]['UF_CRM_TASK'][$unKey]);
}
}
unset($compitableArray['key']);
$obTask->Add($compitableArray);
}
}
}
} |