Ejemplo n.º 1
0
 public static function GetAllDescriptions()
 {
     if (!self::$ALL_DESCRIPTIONS) {
         self::$ALL_DESCRIPTIONS = array(self::Undefined => '', self::Meeting => GetMessage('CRM_ACTIVITY_TYPE_MEETING'), self::Call => GetMessage('CRM_ACTIVITY_TYPE_CALL'), self::Task => GetMessage('CRM_ACTIVITY_TYPE_TASK'), self::Email => GetMessage('CRM_ACTIVITY_TYPE_EMAIL'), self::Activity => GetMessage('CRM_ACTIVITY_TYPE_ACTIVITY'));
     }
     return self::$ALL_DESCRIPTIONS;
 }
Ejemplo n.º 2
0
 public function createActivities(array $params)
 {
     $count = isset($params['COUNT']) ? (int) $params['COUNT'] : 0;
     if ($count <= 0) {
         return;
     }
     $typeID = isset($params['TYPE_ID']) ? (int) $params['TYPE_ID'] : \CCrmActivityType::Undefined;
     if (!\CCrmActivityType::IsDefined($typeID)) {
         return;
     }
     $ownerTypeID = isset($params['OWNER_TYPE_ID']) ? (int) $params['OWNER_TYPE_ID'] : \CCrmOwnerType::Undefined;
     if (!\CCrmOwnerType::IsDefined($ownerTypeID)) {
         return;
     }
     $ownerID = isset($params['OWNER_ID']) ? (int) $params['OWNER_ID'] : 0;
     if ($ownerID <= 0) {
         return;
     }
     $clientTypeID = isset($params['CLIENT_TYPE_ID']) ? (int) $params['CLIENT_TYPE_ID'] : \CCrmOwnerType::Undefined;
     $clientID = isset($params['CLIENT_ID']) ? (int) $params['CLIENT_ID'] : 0;
     if (!\CCrmOwnerType::IsDefined($clientTypeID) || $clientID <= 0) {
         $clientTypeID = $ownerTypeID;
         $clientID = $ownerID;
     }
     $commType = $typeID === \CCrmActivityType::Call ? 'PHONE' : '';
     $values = array();
     if ($commType === 'PHONE' || $commType === 'EMAIL') {
         $values = self::getEntityMultifieldValues($clientTypeID, $clientID, $commType);
         if (empty($values)) {
             return;
         }
     }
     $userIDs = isset($params['USER_IDS']) && is_array($params['USER_IDS']) ? $params['USER_IDS'] : array();
     if (empty($userIDs)) {
         $userIDs[] = \CCrmSecurityHelper::GetCurrentUserID();
     }
     $date = isset($params['DATE']) ? $params['DATE'] : null;
     if (!$date) {
         $date = $date = new Date();
     }
     $maxDateOffset = isset($params['MAX_DATE_OFFSET']) ? (int) $params['MAX_DATE_OFFSET'] : 0;
     $dateTimeFormat = Date::convertFormatToPhp(FORMAT_DATETIME);
     $subjectPrefix = isset($params['SUBJECT_PREFIX']) ? $params['SUBJECT_PREFIX'] : '';
     for ($i = 0; $i < $count; $i++) {
         $time = DateTime::createFromTimestamp($date->getTimestamp());
         if ($maxDateOffset > 0) {
             $time->add(mt_rand(0, $maxDateOffset) . ' days');
         }
         $time->setTime(mt_rand(8, 20), mt_rand(0, 59), 0);
         $siteTime = $time->format($dateTimeFormat);
         $fields = array('TYPE_ID' => $typeID, 'START_TIME' => $siteTime, 'END_TIME' => $siteTime, 'SUBJECT' => "{$subjectPrefix} ({$siteTime})", 'COMPLETED' => mt_rand(1, 10) % 2 !== 0 ? 'Y' : 'N', 'PRIORITY' => \CCrmActivityPriority::Medium, 'DESCRIPTION' => '', 'DESCRIPTION_TYPE' => \CCrmContentType::PlainText, 'LOCATION' => '', 'DIRECTION' => \CCrmActivityDirection::Outgoing, 'NOTIFY_TYPE' => \CCrmActivityNotifyType::None, 'RESPONSIBLE_ID' => self::getRandomItem($userIDs), 'OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID, 'BINDINGS' => array(array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID)));
         $ID = \CCrmActivity::Add($fields, false, true, array('REGISTER_SONET_EVENT' => true));
         $comms = array(array('TYPE' => $commType, 'VALUE' => self::getRandomItem($values, ''), 'ENTITY_ID' => $clientID, 'ENTITY_TYPE_ID' => $clientTypeID));
         \CCrmActivity::SaveCommunications($ID, $comms, $fields, false, false);
     }
 }
Ejemplo n.º 3
0
 protected static function getActivityTypeName($code, $htmlEncode = false)
 {
     $name = CCrmActivityType::ResolveDescription($code);
     return $htmlEncode ? htmlspecialcharsbx($name) : $name;
 }
Ejemplo n.º 4
0
</option>
			<?php 
}
?>
		</select>
	</span>

	<span name="report-filter-value-control-TYPE_ID" class="report-filter-vcc">
		<select class="reports-filter-select-small" name="value">
			<option value=""><?php 
echo GetMessage('CRM_REPORT_INCLUDE_ALL');
?>
</option>
			<?php 
if ($arResult['REPORT_OWNER_ID'] === 'crm_activity') {
    $arResult['enumValues']['TYPE_ID'] = CCrmActivityType::PrepareFilterItems();
} else {
    $arResult['enumValues']['TYPE_ID'] = CCrmStatus::GetStatusList('DEAL_TYPE');
}
?>
			<?php 
foreach ($arResult['enumValues']['TYPE_ID'] as $key => $val) {
    ?>
			<option value="<?php 
    echo htmlspecialcharsbx($key);
    ?>
"><?php 
    echo htmlspecialcharsbx($val);
    ?>
</option>
			<?php 
Ejemplo n.º 5
0
    $arResult['MODE'] = 'CREATE';
    $typeID = $arParams['TYPE_ID'] = isset($arParams['TYPE_ID']) ? intval($arParams['TYPE_ID']) : CCrmActivityType::Undefined;
    if ($typeID <= 0 && isset($_REQUEST['type_id'])) {
        $typeID = $arParams['TYPE_ID'] = intval($_REQUEST['type_id']);
    }
    $ownerID = $arParams['OWNER_ID'] = isset($arParams['OWNER_ID']) ? intval($arParams['OWNER_ID']) : 0;
    if ($ownerID <= 0 && isset($_REQUEST['owner_id'])) {
        $ownerID = $arParams['OWNER_ID'] = intval($_REQUEST['owner_id']);
    }
    $ownerTypeName = $arParams['OWNER_TYPE'] = isset($arParams['OWNER_TYPE']) ? $arParams['OWNER_TYPE'] : '';
    if ($ownerTypeName === '' && isset($_REQUEST['owner_type'])) {
        $ownerTypeName = $arParams['OWNER_TYPE'] = $_REQUEST['owner_type'];
    }
    $ownerTypeID = CCrmOwnerType::ResolveID($ownerTypeName);
}
if (!CCrmActivityType::IsDefined($typeID)) {
    ShowError(GetMessage('CRM_ACTIVITY_EDIT_TYPE_IS_NOT_SUPPORTED', array('#TYPE#' => $typeID)));
    return;
}
if ($ownerID > 0 && $ownerTypeID !== CCrmOwnerType::Undefined) {
    if (!CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $userPerms)) {
        ShowError(GetMessage('CRM_PERMISSION_DENIED'));
        return;
    }
} elseif (!CCrmPerms::IsAccessEnabled()) {
    ShowError(GetMessage('CRM_PERMISSION_DENIED'));
    return;
}
$arResult['TYPE_ID'] = $typeID;
$arResult['OWNER_ID'] = $ownerID;
$arResult['OWNER_TYPE_ID'] = $ownerTypeID;
Ejemplo n.º 6
0
 protected function innerAdd(&$fields, &$errors, array $params = null)
 {
     $ownerTypeID = isset($fields['OWNER_TYPE_ID']) ? intval($fields['OWNER_TYPE_ID']) : 0;
     $ownerID = isset($fields['OWNER_ID']) ? intval($fields['OWNER_ID']) : 0;
     $bindings = array();
     if ($ownerTypeID > 0 && $ownerID > 0) {
         $bindings["{$ownerTypeID}_{$ownerID}"] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID);
     }
     $responsibleID = isset($fields['RESPONSIBLE_ID']) ? intval($fields['RESPONSIBLE_ID']) : 0;
     if ($responsibleID <= 0 && $ownerTypeID > 0 && $ownerID > 0) {
         $fields['RESPONSIBLE_ID'] = $responsibleID = CCrmOwnerType::GetResponsibleID($ownerTypeID, $ownerID);
     }
     if ($responsibleID <= 0) {
         $responsibleID = CCrmSecurityHelper::GetCurrentUserID();
     }
     if ($responsibleID <= 0) {
         $errors[] = 'The field RESPONSIBLE_ID is not defined or invalid.';
         return false;
     }
     $typeID = isset($fields['TYPE_ID']) ? intval($fields['TYPE_ID']) : CCrmActivityType::Undefined;
     if (!CCrmActivityType::IsDefined($typeID)) {
         $errors[] = 'The field TYPE_ID is not defined or invalid.';
         return false;
     }
     if (!in_array($typeID, array(CCrmActivityType::Call, CCrmActivityType::Meeting, CCrmActivityType::Email), true)) {
         $errors[] = 'The activity type "' . CCrmActivityType::ResolveDescription($typeID) . ' is not supported in current context".';
         return false;
     }
     $description = isset($fields['DESCRIPTION']) ? $fields['DESCRIPTION'] : '';
     $descriptionType = isset($fields['DESCRIPTION_TYPE']) ? intval($fields['DESCRIPTION_TYPE']) : CCrmContentType::PlainText;
     if ($description !== '' && CCrmActivity::AddEmailSignature($description, $descriptionType)) {
         $fields['DESCRIPTION'] = $description;
     }
     $direction = isset($fields['DIRECTION']) ? intval($fields['DIRECTION']) : CCrmActivityDirection::Undefined;
     $completed = isset($fields['COMPLETED']) && strtoupper($fields['COMPLETED']) === 'Y';
     $communications = isset($fields['COMMUNICATIONS']) && is_array($fields['COMMUNICATIONS']) ? $fields['COMMUNICATIONS'] : array();
     $this->prepareCommunications($ownerTypeID, $ownerID, $typeID, $communications, $bindings);
     if (empty($communications)) {
         $errors[] = 'The field COMMUNICATIONS is not defined or invalid.';
         return false;
     }
     if (($typeID === CCrmActivityType::Call || $typeID === CCrmActivityType::Meeting) && count($communications) > 1) {
         $errors[] = 'The only one communication is allowed for activity of specified type.';
         return false;
     }
     if (empty($bindings)) {
         $errors[] = 'Could not build binding. Please ensure that owner info and communications are defined correctly.';
         return false;
     }
     foreach ($bindings as &$binding) {
         if (!CCrmActivity::CheckUpdatePermission($binding['OWNER_TYPE_ID'], $binding['OWNER_ID'])) {
             $errors[] = 'Access denied.';
             return false;
         }
     }
     unset($binding);
     $fields['BINDINGS'] = array_values($bindings);
     $fields['COMMUNICATIONS'] = $communications;
     $storageTypeID = $fields['STORAGE_TYPE_ID'] = CCrmActivity::GetDefaultStorageTypeID();
     $fields['STORAGE_ELEMENT_IDS'] = array();
     if ($storageTypeID === StorageType::WebDav) {
         $webdavElements = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array();
         foreach ($webdavElements as &$element) {
             $elementID = isset($element['ELEMENT_ID']) ? intval($element['ELEMENT_ID']) : 0;
             if ($elementID > 0) {
                 $fields['STORAGE_ELEMENT_IDS'][] = $elementID;
             }
         }
         unset($element);
     } elseif ($storageTypeID === StorageType::Disk) {
         $diskFiles = isset($fields['FILES']) && is_array($fields['FILES']) ? $fields['FILES'] : array();
         if (empty($diskFiles)) {
             //For backward compatibility only
             $diskFiles = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array();
         }
         foreach ($diskFiles as &$fileInfo) {
             $fileID = isset($fileInfo['FILE_ID']) ? (int) $fileInfo['FILE_ID'] : 0;
             if ($fileID > 0) {
                 $fields['STORAGE_ELEMENT_IDS'][] = $fileID;
             }
         }
         unset($fileInfo);
     }
     if (!($ID = CCrmActivity::Add($fields))) {
         $errors[] = CCrmActivity::GetLastErrorMessage();
         return false;
     }
     CCrmActivity::SaveCommunications($ID, $communications, $fields, false, false);
     if ($completed && $typeID === CCrmActivityType::Email && $direction === CCrmActivityDirection::Outgoing) {
         $sendErrors = array();
         if (!CCrmActivityEmailSender::TrySendEmail($ID, $fields, $sendErrors)) {
             foreach ($sendErrors as &$error) {
                 $code = $error['CODE'];
                 if ($code === CCrmActivityEmailSender::ERR_CANT_LOAD_SUBSCRIBE) {
                     $errors[] = 'Email send error. Failed to load module "subscribe".';
                 } elseif ($code === CCrmActivityEmailSender::ERR_INVALID_DATA) {
                     $errors[] = 'Email send error. Invalid data.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_INVALID_EMAIL) {
                     $errors[] = 'Email send error. Invalid email is specified.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_CANT_FIND_EMAIL_FROM) {
                     $errors[] = 'Email send error. "From" is not found.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_CANT_FIND_EMAIL_TO) {
                     $errors[] = 'Email send error. "To" is not found.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_CANT_ADD_POSTING) {
                     $errors[] = 'Email send error. Failed to add posting. Please see details below.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_CANT_SAVE_POSTING_FILE) {
                     $errors[] = 'Email send error. Failed to save posting file. Please see details below.';
                 } elseif ($code === CCrmActivityEmailSender::ERR_CANT_UPDATE_ACTIVITY) {
                     $errors[] = 'Email send error. Failed to update activity.';
                 } else {
                     $errors[] = 'Email send error. General error.';
                 }
                 $msg = isset($error['MESSAGE']) ? $error['MESSAGE'] : '';
                 if ($msg !== '') {
                     $errors[] = $msg;
                 }
             }
             unset($error);
             return false;
         }
     }
     return $ID;
 }
Ejemplo n.º 7
0
			<?php 
}
?>
		</select>
	</div>

	<div class="filter-field filter-field-type chfilter-field-DEAL_OWNER.TYPE_ID" callback="RTFilter_chooseBoolean">
		<label for="%ID%" class="filter-field-title">%TITLE% "%COMPARE%"</label>
		<select id="%ID%" name="%NAME%" class="filter-dropdown" caller="true">
			<option value=""><?php 
echo GetMessage('CRM_REPORT_INCLUDE_ALL');
?>
</option>
			<?php 
if ($arResult['REPORT_OWNER_ID'] === 'crm_activity') {
    $arTypes = CCrmActivityType::PrepareFilterItems();
} else {
    $arTypes = CCrmStatus::GetStatusList('DEAL_TYPE');
}
?>
			<?php 
foreach ($arTypes as $key => $val) {
    ?>
			<option value="<?php 
    echo htmlspecialcharsbx($key);
    ?>
"><?php 
    echo htmlspecialcharsbx($val);
    ?>
</option>
			<?php 
Ejemplo n.º 8
0
$arResult['HEADERS'] = array(array('id' => 'ID', 'type' => 'number', 'name' => 'ID', 'sort' => 'id', 'default' => false, 'editable' => false, 'class' => 'minimal'));
$arResult['HEADERS'][] = array('id' => 'SUBJECT', 'type' => 'text', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_SUBJECT'), 'default' => true, 'editable' => true);
$arResult['HEADERS'][] = array('id' => 'START_TIME', 'type' => 'date', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_START'), 'default' => false, 'editable' => true, 'class' => 'datetime');
$arResult['HEADERS'][] = array('id' => 'END_TIME', 'type' => 'date', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_END_2'), 'default' => false, 'editable' => true, 'class' => 'datetime');
$arResult['HEADERS'][] = array('id' => 'DEADLINE', 'type' => 'date', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_DEADLINE'), 'sort' => 'DEADLINE', 'default' => true, 'editable' => false, 'class' => 'datetime');
$displayReference = $arResult['DISPLAY_REFERENCE'] = isset($arParams['DISPLAY_REFERENCE']) ? $arParams['DISPLAY_REFERENCE'] : false;
$arResult['HEADERS'][] = array('id' => 'REFERENCE', 'type' => 'text', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_REFERENCE'), 'default' => $displayReference, 'editable' => false);
$displayClient = $arResult['DISPLAY_CLIENT'] = isset($arParams['DISPLAY_CLIENT']) ? $arParams['DISPLAY_CLIENT'] : true;
$arResult['HEADERS'][] = array('id' => 'CLIENT', 'type' => 'text', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_CLIENT'), 'default' => $displayClient, 'editable' => false);
$arResult['HEADERS'][] = array('id' => 'DESCRIPTION', 'type' => 'text', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_DESCRIPTION'), 'default' => false, 'editable' => true);
$arResult['HEADERS'][] = array('id' => 'RESPONSIBLE_FULL_NAME', 'type' => 'text', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_RESPONSIBLE'), 'sort' => 'RESPONSIBLE_FULL_NAME', 'default' => true, 'editable' => false, 'class' => 'username');
$arResult['HEADERS'][] = array('id' => 'COMPLETED', 'type' => 'list', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_COMPLETED'), 'hideName' => true, 'sort' => 'COMPLETED', 'default' => true, 'editable' => array('items' => array('N' => GetMessage('CRM_ACTIVITY_STATUS_NOT_COMPLETED'), 'Y' => GetMessage('CRM_ACTIVITY_STATUS_COMPLETED'))));
$arResult['HEADERS'][] = array('id' => 'CREATED', 'type' => 'date', 'name' => GetMessage('CRM_ACTIVITY_COLUMN_CREATED'), 'sort' => 'CREATED', 'default' => false, 'editable' => false, 'class' => 'date');
$arResult['FILTER'] = array();
$arResult['FILTER_PRESETS'] = array();
$typeListItems = array(strval(CCrmActivityType::Meeting) => CCrmActivityType::ResolveDescription(CCrmActivityType::Meeting), strval(CCrmActivityType::Call) . '.' . strval(CCrmActivityDirection::Incoming) => GetMessage('CRM_ACTIVITY_INCOMING_CALL'), strval(CCrmActivityType::Call) . '.' . strval(CCrmActivityDirection::Outgoing) => GetMessage('CRM_ACTIVITY_OUTGOING_CALL'), strval(CCrmActivityType::Task) => CCrmActivityType::ResolveDescription(CCrmActivityType::Task), strval(CCrmActivityType::Email) . '.' . strval(CCrmActivityDirection::Incoming) => GetMessage('CRM_ACTIVITY_INCOMING_EMAIL'), strval(CCrmActivityType::Email) . '.' . strval(CCrmActivityDirection::Outgoing) => GetMessage('CRM_ACTIVITY_OUTGOING_EMAIL'));
if ($arResult['TAB_ID'] === '' && $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['conv'])) {
    if (CCrmPerms::IsAdmin()) {
        $conv = strtoupper($_GET['conv']);
        if ($conv === 'EXEC_CAL') {
            CCrmActivityConverter::ConvertCalEvents(false, true);
            COption::SetOptionString('crm', '~CRM_ACTIVITY_LIST_CONVERTING_CALENDAR_EVENTS', 'Y');
        } elseif ($conv === 'EXEC_TASK') {
            CCrmActivityConverter::ConvertTasks(false, true);
            COption::SetOptionString('crm', '~CRM_ACTIVITY_LIST_CONVERTING_OF_TASKS', 'Y');
        } elseif ($conv === 'SKIP_CAL') {
            COption::SetOptionString('crm', '~CRM_ACTIVITY_LIST_CONVERTING_CALENDAR_EVENTS', 'Y');
        } elseif ($conv === 'SKIP_TASK') {
            COption::SetOptionString('crm', '~CRM_ACTIVITY_LIST_CONVERTING_OF_TASKS', 'Y');
        } elseif ($conv === 'RESET_CAL') {
            COption::RemoveOption('crm', '~CRM_ACTIVITY_LIST_CONVERTING_CALENDAR_EVENTS');