[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Calendar/ -> iCalImport.php (source)

   1  <?php
   2  define('_BENNU_VERSION', '0.1');
   3  include ('modules/Calendar/iCal/iCalendar_rfc2445.php');
   4  include ('modules/Calendar/iCal/iCalendar_components.php');
   5  include ('modules/Calendar/iCal/iCalendar_properties.php');
   6  include ('modules/Calendar/iCal/iCalendar_parameters.php');
   7  include ('modules/Calendar/iCal/ical-parser-class.php');
   8  require_once ('include/Zend/Json.php');
   9  require_once ('modules/Calendar/iCalLastImport.php');
  10  
  11  require_once ('include/utils/utils.php');
  12  require_once ('data/CRMEntity.php');
  13  
  14  global $import_dir,$current_user,$mod_strings,$app_strings,$currentModule;
  15  
  16  if($_REQUEST['step']!='undo'){
  17      $last_import = new iCalLastImport();
  18      $last_import->clearRecords($current_user->id);
  19      $file_details = $_FILES['ics_file'];
  20      $binFile = 'vtiger_import'.date('YmdHis');
  21      $file = $import_dir.''.$binFile;
  22      $filetmp_name = $file_details['tmp_name'];
  23      $upload_status = move_uploaded_file($filetmp_name,$file);
  24  
  25      $skip_fields = array(
  26          'Events'=>array('duration_hours'),
  27          'Calendar'=>array('eventstatus')
  28      );
  29      $required_fields = array();
  30  
  31      $modules = array('Events','Calendar');
  32      foreach($modules as $module){
  33          $calendar = CRMEntity::getInstance('Calendar');
  34          $calendar->initRequiredFields($module);
  35          $val = array_keys($calendar->required_fields);
  36          $required_fields[$module] = array_diff($val,$skip_fields[$module]);
  37      }
  38  
  39      $ical = new iCal();
  40      $ical_activities = $ical->iCalReader($binFile);
  41  
  42      $count['Events'] = $count['Calendar'] = $skip_count['Events'] = $skip_count['Calendar'] = 0;
  43      for($i=0;$i<count($ical_activities);$i++){
  44          if($ical_activities[$i]['TYPE'] == 'VEVENT'){
  45              $activity = new iCalendar_event;
  46              $module = 'Events';
  47          } else {
  48              $activity = new iCalendar_todo;
  49              $module = 'Calendar';
  50          }
  51  
  52          $count[$module]++;
  53          $calendar = CRMEntity::getInstance('Calendar');
  54          $calendar->column_fields = $activity->generateArray($ical_activities[$i]);
  55          $calendar->column_fields['assigned_user_id'] = $current_user->id;
  56          $skip_record = false;
  57          foreach($required_fields[$module] as $key){
  58              if(empty($calendar->column_fields[$key])){
  59                  $skip_count[$module]++;
  60                  $skip_record = true;
  61                  break;
  62              }
  63          }
  64          if($skip_record === true) {
  65              continue;
  66          }
  67          $calendar->save('Calendar');
  68          $last_import = new iCalLastImport();
  69          $last_import->setFields(array('userid' => $current_user->id,
  70                                      'entitytype' => 'Calendar',
  71                                      'crmid' => $calendar->id));
  72          $last_import->save();
  73          if(!empty($ical_activities[$i]['VALARM'])){
  74              $calendar->activity_reminder($calendar->id,$calendar->column_fields['reminder_time'],0,'','');
  75          }
  76      }
  77      unlink($file);
  78      $smarty->assign("IMAGE_PATH", $last_imported);
  79      $smarty = new vtigerCRM_Smarty;
  80  
  81      $smarty->assign("MOD", $mod_strings);
  82      $smarty->assign("APP", $app_strings);
  83      $smarty->assign("IMP", $import_mod_strings);
  84      $smarty->assign("THEME", $theme);
  85      $smarty->assign("IMAGE_PATH", $image_path);
  86      $parent_tab = vtlib_purify($_SESSION['import_parenttab']);
  87      if(empty($parent_Tab)){
  88          $parent_tab = getParentTab();
  89      }
  90      $smarty->assign("MODULE", vtlib_purify($_REQUEST['module']));
  91      $smarty->assign("SINGLE_MOD", vtlib_purify($_REQUEST['module']));
  92      $smarty->assign("CATEGORY", $parent_tab);
  93      //@session_unregister("import_parenttab");
  94          $smarty->display("Buttons_List1.tpl");
  95  
  96      $imported_events = $count['Events'] - $skip_count['Events'];
  97      $imported_tasks = $count['Calendar'] - $skip_count['Calendar'];
  98       $message= "<b>".$mod_strings['LBL_SUCCESS']."</b>"
  99                   ."<br><br>" .$mod_strings['LBL_SUCCESS_EVENTS_1']."  $imported_events"
 100                   ."<br><br>" .$mod_strings['LBL_SKIPPED_EVENTS_1'].$skip_count['Events']
 101                   ."<br><br>" .$mod_strings['LBL_SUCCESS_CALENDAR_1']."  $imported_tasks"
 102                   ."<br><br>" .$mod_strings['LBL_SKIPPED_CALENDAR_1'].$skip_count['Calendar']
 103                   ."<br><br>";
 104  
 105      $smarty->assign("MESSAGE", $message);
 106      $smarty->assign("RETURN_MODULE", $currentModule);
 107      $smarty->assign("RETURN_ACTION", 'ListView');
 108      $smarty->assign("MODULE", $currentModule);
 109      $smarty->assign("MODULENAME", $currentModule);
 110      $smarty->display("iCalImport.tpl");
 111  
 112  } else {
 113      $smarty->assign("IMAGE_PATH", $last_imported);
 114      $smarty = new vtigerCRM_Smarty;
 115  
 116      $smarty->assign("MOD", $mod_strings);
 117      $smarty->assign("APP", $app_strings);
 118      $smarty->assign("IMP", $import_mod_strings);
 119      $smarty->assign("THEME", $theme);
 120      $smarty->assign("IMAGE_PATH", $image_path);
 121      $parent_tab = vtlib_purify($_SESSION['import_parenttab']);
 122      if(empty($parent_Tab)){
 123          $parent_tab = getParentTab();
 124      }
 125      $smarty->assign("MODULE", vtlib_purify($_REQUEST['module']));
 126      $smarty->assign("SINGLE_MOD", vtlib_purify($_REQUEST['module']));
 127      $smarty->assign("CATEGORY", $parent_tab);
 128      //@session_unregister("import_parenttab");
 129          $smarty->display("Buttons_List1.tpl");
 130  
 131      $last_import = new iCalLastImport();
 132      $ret_value = $last_import->undo('Calendar', $current_user->id);
 133  
 134      if(!empty($ret_value)){
 135       $message= "<b>".$mod_strings['LBL_SUCCESS']."</b>"
 136                   ."<br><br>" .$mod_strings['LBL_LAST_IMPORT_UNDONE']." ";
 137      } else {
 138       $message= "<b>".$mod_strings['LBL_FAILURE']."</b>"
 139                   ."<br><br>" .$mod_strings['LBL_NO_IMPORT_TO_UNDO']." ";
 140      }
 141  
 142      $smarty->assign("MESSAGE", $message);
 143      $smarty->assign("UNDO", 'yes');
 144      $smarty->assign("RETURN_MODULE", $currentModule);
 145      $smarty->assign("RETURN_ACTION", 'ListView');
 146      $smarty->assign("MODULE", $currentModule);
 147      $smarty->assign("MODULENAME", $currentModule);
 148      $smarty->display("iCalImport.tpl");
 149  }
 150  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1