Ejemplo n.º 1
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $ics = $request->get('ics') . '.ics';
     $icsUrl = 'cache/import/' . $ics;
     if (file_exists($icsUrl)) {
         $currentUserModel = Users_Record_Model::getCurrentUserModel();
         $userId = $currentUserModel->getId();
         $lastImport = new iCalLastImport();
         $lastImport->clearRecords($userId);
         $eventModule = 'Events';
         $todoModule = 'Calendar';
         $skipFields = array($eventModule => array('duration_hours'), $todoModule => array('eventstatus'));
         $requiredFields = array();
         $modules = array($eventModule, $todoModule);
         $calendarModel = Vtiger_Module_Model::getInstance($moduleName);
         foreach ($modules as $module) {
             $moduleRequiredFields = array_keys($calendarModel->getRequiredFields($module));
             $requiredFields[$module] = array_diff($moduleRequiredFields, $skipFields[$module]);
             $totalCount[$module] = 0;
             $skipCount[$module] = 0;
         }
         $ical = new iCal();
         $icalActivities = $ical->iCalReader($ics);
         $noOfActivities = count($icalActivities);
         for ($i = 0; $i < $noOfActivities; $i++) {
             if ($icalActivities[$i]['TYPE'] == 'VEVENT') {
                 $activity = new iCalendar_event();
                 $module = $eventModule;
             } else {
                 $activity = new iCalendar_todo();
                 $module = $todoModule;
             }
             $totalCount[$module]++;
             $activityFieldsList = $activity->generateArray($icalActivities[$i]);
             if (!array_key_exists('visibility', $activityFieldsList)) {
                 $activityFieldsList['visibility'] = ' ';
             }
             if (array_key_exists('taskpriority', $activityFieldsList)) {
                 $priorityMap = array('0' => 'Medium', '1' => 'High', '2' => 'Medium', '3' => 'Low');
                 $priorityval = $activityFieldsList['taskpriority'];
                 if (array_key_exists($priorityval, $priorityMap)) {
                     $activityFieldsList['taskpriority'] = $priorityMap[$priorityval];
                 }
             }
             $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
             $recordModel->setData($activityFieldsList);
             $recordModel->set('assigned_user_id', $userId);
             $skipRecord = false;
             foreach ($requiredFields[$module] as $key) {
                 $value = $recordModel->get($key);
                 if (empty($value)) {
                     $skipCount[$module]++;
                     $skipRecord = true;
                     break;
                 }
             }
             $recordModel->save();
             $lastImport = new iCalLastImport();
             $lastImport->setFields(array('userid' => $userId, 'entitytype' => $todoModule, 'crmid' => $recordModel->getId()));
             $lastImport->save();
             if (!empty($icalActivities[$i]['VALARM'])) {
                 $recordModel->setActivityReminder(0, '', '');
             }
         }
         $return = 'LBL_IMPORT_ICS_ERROR_NO_RECORD';
         $importedEvents = $totalCount[$eventModule] - $skipCount[$eventModule];
         $importedTasks = $totalCount[$todoModule] - $skipCount[$todoModule];
         if ($importedEvents > 0 || $importedTasks > 0) {
             $return = 'LBL_IMPORT_ICS_SUCCESS';
         }
         @unlink($icsUrl);
     } else {
         $return = 'LBL_IMPORT_ICS_ERROR_NO_RECORD';
     }
     $response = new Vtiger_Response();
     $response->setResult(vtranslate($return, $moduleName));
     $response->emit();
 }
Ejemplo n.º 2
0
 /**
  * Function that create the exported file
  * @param Vtiger_Request $request
  * @param <Array> $result
  * @param Vtiger_Module_Model $moduleModel
  */
 public function output($request, $result, $moduleModel)
 {
     $fileName = $request->get('filename');
     $exportType = $this->getExportContentType($request);
     // Send the right content type and filename
     header("Content-type: {$exportType}");
     header("Content-Disposition: attachment; filename={$fileName}.ics");
     $timeZone = new iCalendar_timezone();
     $timeZoneId = split('/', date_default_timezone_get());
     if (!empty($timeZoneId[1])) {
         $zoneId = $timeZoneId[1];
     } else {
         $zoneId = $timeZoneId[0];
     }
     $timeZone->add_property('TZID', $zoneId);
     $timeZone->add_property('TZOFFSETTO', date('O'));
     if (date('I') == 1) {
         $timeZone->add_property('DAYLIGHTC', date('I'));
     } else {
         $timeZone->add_property('STANDARDC', date('I'));
     }
     $myiCal = new iCalendar();
     $myiCal->add_component($timeZone);
     while (!$result->EOF) {
         $eventFields = $result->fields;
         $id = $eventFields['activityid'];
         $type = $eventFields['activitytype'];
         if ($type != 'Task') {
             $temp = $moduleModel->get('eventFields');
             foreach ($temp as $fieldName => $access) {
                 /* Priority property of ical is Integer
                  * http://kigkonsult.se/iCalcreator/docs/using.html#PRIORITY
                  */
                 if ($fieldName == 'priority') {
                     $priorityMap = array('High' => '1', 'Medium' => '2', 'Low' => '3');
                     $priorityval = $eventFields[$fieldName];
                     $icalZeroPriority = 0;
                     if (array_key_exists($priorityval, $priorityMap)) {
                         $temp[$fieldName] = $priorityMap[$priorityval];
                     } else {
                         $temp[$fieldName] = $icalZeroPriority;
                     }
                 } else {
                     $temp[$fieldName] = $eventFields[$fieldName];
                 }
             }
             $temp['id'] = $id;
             $iCalTask = new iCalendar_event();
             $iCalTask->assign_values($temp);
             $iCalAlarm = new iCalendar_alarm();
             $iCalAlarm->assign_values($temp);
             $iCalTask->add_component($iCalAlarm);
         } else {
             $temp = $moduleModel->get('todoFields');
             foreach ($temp as $fieldName => $access) {
                 if ($fieldName == 'priority') {
                     $priorityMap = array('High' => '1', 'Medium' => '2', 'Low' => '3');
                     $priorityval = $eventFields[$fieldName];
                     $icalZeroPriority = 0;
                     if (array_key_exists($priorityval, $priorityMap)) {
                         $temp[$fieldName] = $priorityMap[$priorityval];
                     } else {
                         $temp[$fieldName] = $icalZeroPriority;
                     }
                 } else {
                     $temp[$fieldName] = $eventFields[$fieldName];
                 }
             }
             $iCalTask = new iCalendar_todo();
             $iCalTask->assign_values($temp);
         }
         $myiCal->add_component($iCalTask);
         $result->MoveNext();
     }
     echo $myiCal->serialize();
 }
Ejemplo n.º 3
0
 /**
  * Function that create the exported file
  * @param Vtiger_Request $request
  * @param <Array> $result
  * @param Vtiger_Module_Model $moduleModel
  */
 public function output($request, $result, $moduleModel)
 {
     $fileName = $request->get('filename');
     $exportType = $this->getExportContentType($request);
     // Send the right content type and filename
     header("Content-type: {$exportType}");
     header("Content-Disposition: attachment; filename={$fileName}.ics");
     $timeZone = new iCalendar_timezone();
     $timeZoneId = split('/', date_default_timezone_get());
     if (!empty($timeZoneId[1])) {
         $zoneId = $timeZoneId[1];
     } else {
         $zoneId = $timeZoneId[0];
     }
     $timeZone->add_property('TZID', $zoneId);
     $timeZone->add_property('TZOFFSETTO', date('O'));
     if (date('I') == 1) {
         $timeZone->add_property('DAYLIGHTC', date('I'));
     } else {
         $timeZone->add_property('STANDARDC', date('I'));
     }
     $myiCal = new iCalendar();
     $myiCal->add_component($timeZone);
     while (!$result->EOF) {
         $eventFields = $result->fields;
         $id = $eventFields['activityid'];
         $type = $eventFields['activitytype'];
         if ($type != 'Task') {
             $temp = $moduleModel->get('eventFields');
             foreach ($temp as $fieldName => $access) {
                 $temp[$fieldName] = $eventFields[$fieldName];
             }
             $temp['id'] = $id;
             $iCalTask = new iCalendar_event();
             $iCalTask->assign_values($temp);
             $iCalAlarm = new iCalendar_alarm();
             $iCalAlarm->assign_values($temp);
             $iCalTask->add_component($iCalAlarm);
         } else {
             $temp = $moduleModel->get('todoFields');
             foreach ($temp as $fieldName => $access) {
                 $temp[$fieldName] = $eventFields[$fieldName];
             }
             $iCalTask = new iCalendar_todo();
             $iCalTask->assign_values($temp);
         }
         $myiCal->add_component($iCalTask);
         $result->MoveNext();
     }
     echo $myiCal->serialize();
 }
Ejemplo n.º 4
0
}
$myical = new iCalendar();
$myical->add_component($tz);
while ($row = $adb->fetch_array($calendar_results)) {
    $this_event = $row;
    $id = $this_event['activityid'];
    $type = $this_event['activitytype'];
    if ($type != 'Task') {
        $temp = $event;
        foreach ($temp as $key => $val) {
            $temp[$key] = $this_event[$key];
        }
        $temp['id'] = $id;
        $ev = new iCalendar_event();
        $ev->assign_values($temp);
        $al = new iCalendar_alarm();
        $al->assign_values($temp);
        $ev->add_component($al);
    } else {
        $temp = $todo;
        foreach ($temp as $key => $val) {
            $temp[$key] = $this_event[$key];
        }
        $ev = new iCalendar_todo();
        $ev->assign_values($temp);
    }
    $myical->add_component($ev);
    $calendar_results->MoveNext();
}
// Print the actual calendar
echo $myical->serialize();
Ejemplo n.º 5
0
 /**
  * Function to show result of import
  * @param Vtiger_Request $request
  */
 public function importResult(Vtiger_Request $request)
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $userId = $currentUserModel->getId();
     $moduleName = $request->getModule();
     $viewer = $this->getViewer($request);
     $request->set('type', 'ics');
     if (Import_Utils_Helper::validateFileUpload($request)) {
         $lastImport = new iCalLastImport();
         $lastImport->clearRecords($userId);
         $eventModule = 'Events';
         $todoModule = 'Calendar';
         $skipFields = array($eventModule => array('duration_hours'), $todoModule => array('activitystatus'));
         $requiredFields = array();
         $modules = array($eventModule, $todoModule);
         $calendarModel = Vtiger_Module_Model::getInstance($moduleName);
         foreach ($modules as $module) {
             $moduleRequiredFields = array_keys($calendarModel->getRequiredFields($module));
             $requiredFields[$module] = array_diff($moduleRequiredFields, $skipFields[$module]);
             $totalCount[$module] = 0;
             $skipCount[$module] = 0;
         }
         $ical = new iCal();
         $icalActivities = $ical->iCalReader("IMPORT_" . $userId);
         $noOfActivities = count($icalActivities);
         for ($i = 0; $i < $noOfActivities; $i++) {
             if ($icalActivities[$i]['TYPE'] == 'VEVENT') {
                 $activity = new iCalendar_event();
                 $module = $eventModule;
             } else {
                 $activity = new iCalendar_todo();
                 $module = $todoModule;
             }
             $totalCount[$module]++;
             $activityFieldsList = $activity->generateArray($icalActivities[$i]);
             if (!array_key_exists('visibility', $activityFieldsList)) {
                 $activityFieldsList['visibility'] = ' ';
             }
             if (array_key_exists('taskpriority', $activityFieldsList)) {
                 $priorityMap = array('0' => 'Medium', '1' => 'High', '2' => 'Medium', '3' => 'Low');
                 $priorityval = $activityFieldsList['taskpriority'];
                 if (array_key_exists($priorityval, $priorityMap)) {
                     $activityFieldsList['taskpriority'] = $priorityMap[$priorityval];
                 }
             }
             $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
             $recordModel->setData($activityFieldsList);
             $recordModel->set('assigned_user_id', $userId);
             $skipRecord = false;
             foreach ($requiredFields[$module] as $key) {
                 $value = $recordModel->get($key);
                 if (empty($value)) {
                     $skipCount[$module]++;
                     $skipRecord = true;
                     break;
                 }
             }
             if ($skipRecord === true) {
                 continue;
             }
             $recordModel->save();
             $lastImport = new iCalLastImport();
             $lastImport->setFields(array('userid' => $userId, 'entitytype' => $todoModule, 'crmid' => $recordModel->getId()));
             $lastImport->save();
             if (!empty($icalActivities[$i]['VALARM'])) {
                 $recordModel->setActivityReminder(0, '', '');
             }
         }
         $importedEvents = $totalCount[$eventModule] - $skipCount[$eventModule];
         $importedTasks = $totalCount[$todoModule] - $skipCount[$todoModule];
         $viewer->assign('SUCCESS_EVENTS', $importedEvents);
         $viewer->assign('SKIPPED_EVENTS', $skipCount[$eventModule]);
         $viewer->assign('SUCCESS_TASKS', $importedTasks);
         $viewer->assign('SKIPPED_TASKS', $skipCount[$todoModule]);
     } else {
         $viewer->assign('ERROR_MESSAGE', $request->get('error_message'));
     }
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('VIEW', 'List');
     $viewer->view('ImportResult.tpl', $moduleName);
 }
Ejemplo n.º 6
0
 $modules = array('Events', 'Calendar');
 foreach ($modules as $module) {
     $calendar = CRMEntity::getInstance('Calendar');
     $calendar->initRequiredFields($module);
     $val = array_keys($calendar->required_fields);
     $required_fields[$module] = array_diff($val, $skip_fields[$module]);
 }
 $ical = new iCal();
 $ical_activities = $ical->iCalReader($binFile);
 $count['Events'] = $count['Calendar'] = $skip_count['Events'] = $skip_count['Calendar'] = 0;
 for ($i = 0; $i < count($ical_activities); $i++) {
     if ($ical_activities[$i]['TYPE'] == 'VEVENT') {
         $activity = new iCalendar_event();
         $module = 'Events';
     } else {
         $activity = new iCalendar_todo();
         $module = 'Calendar';
     }
     $count[$module]++;
     $calendar = CRMEntity::getInstance('Calendar');
     $calendar->column_fields = $activity->generateArray($ical_activities[$i]);
     $calendar->column_fields['assigned_user_id'] = $current_user->id;
     foreach ($required_fields[$module] as $key) {
         if (empty($calendar->column_fields[$key])) {
             $skip_count[$module]++;
             break;
         }
     }
     $calendar->save('Calendar');
     $last_import = new UsersLastImport();
     $last_import->assigned_user_id = $current_user->id;