/** * Function to show result of undo import * @param Vtiger_Request $request */ public function undoImport(Vtiger_Request $request) { $currentUserModel = Users_Record_Model::getCurrentUserModel(); $moduleName = $request->getModule(); $lastImport = new iCalLastImport(); $returnValue = $lastImport->undo($moduleName, $currentUserModel->getId()); if (!empty($returnValue)) { $undoStatus = true; } else { $undoStatus = false; } $viewer = $this->getViewer($request); $viewer->assign('MODULE', $moduleName); $viewer->assign('VIEW', 'List'); $viewer->assign('UNDO_STATUS', $undoStatus); $viewer->view('ImportFinalResult.tpl', $moduleName); }
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(); }
$smarty->assign("RETURN_MODULE", $currentModule); $smarty->assign("RETURN_ACTION", 'ListView'); $smarty->assign("MODULE", $currentModule); $smarty->assign("MODULENAME", $currentModule); $smarty->display("iCalImport.tpl"); } else { $smarty->assign("IMAGE_PATH", $last_imported); $smarty = new vtigerCRM_Smarty(); $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("IMP", $import_mod_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE", vtlib_purify($_REQUEST['module'])); $smarty->assign("SINGLE_MOD", vtlib_purify($_REQUEST['module'])); $smarty->display("Buttons_List1.tpl"); $last_import = new iCalLastImport(); $ret_value = $last_import->undo('Calendar', $current_user->id); if (!empty($ret_value)) { $message = "<b>" . $mod_strings['LBL_SUCCESS'] . "</b>" . "<br><br>" . $mod_strings['LBL_LAST_IMPORT_UNDONE'] . " "; } else { $message = "<b>" . $mod_strings['LBL_FAILURE'] . "</b>" . "<br><br>" . $mod_strings['LBL_NO_IMPORT_TO_UNDO'] . " "; } $smarty->assign("MESSAGE", $message); $smarty->assign("UNDO", 'yes'); $smarty->assign("RETURN_MODULE", $currentModule); $smarty->assign("RETURN_ACTION", 'ListView'); $smarty->assign("MODULE", $currentModule); $smarty->assign("MODULENAME", $currentModule); $smarty->display("iCalImport.tpl"); }