CMS  Version 3.9
data_import_select.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("data_sync");
3 Fakoli::usingFeature("spreadsheet_form");
4 
5 $menu_item = "Data Import";
6 
8 
9 $class = $_SESSION["data_import_class"];
10 $format = $_SESSION["data_file_format"];
11 $file = $_SESSION["data_import_file"];
12 
13 $import_profile_id = $_SESSION["import_profile_id"];
14 
15 $multiProfile = Settings::getValue("data_sync", "multiple_import_profiles");
16 
17 if ($multiProfile)
18 {
19  if (!$import_profile_id)
20  {
21  redirect("data_import_field_mapping");
22  }
23 }
24 else
25 {
27 }
28 
29 $obj = new $class;
30 
31 $name = $obj->prettifyClassName(true);
32 
34 
36 {
37  redirect("data_import_field_mapping?import_profile_id={$import_profile_id}");
38 }
39 
41 $filter->add($obj->primary_key);
42 
43 $obj->filter = $filter;
44 
45 $page_title = "Select $name to Import";
46 
48 
49 trace("Mapping ".count($items)." items", 3);
50 $form = new AutoForm($obj);
51 
52 if (is_array($obj->spreadsheetFieldSizes))
53 {
54  foreach($obj->spreadsheetFieldSizes as $field => $size)
55  {
56  $form->getRenderer($field)->size = $size;
57  }
58 }
59 
61 
62 
63 $isChunked = Settings::getValue("data_sync", "import_in_chunks") ? "true" : "false";
64 $pageSize = Settings::getValue("data_sync", "records_per_page");
66 
67 $offset = checkNumeric($_GET["offset"]);
68 if ($offset == '') $offset = 0;
69 if ($pageSize == '') $pageSize = 0;
70 if ($totalRecords == '') $totalRecords = 0;
71 
72 $spreadsheet = new SpreadsheetForm($form, $items, 0, "POST", "", "", array(DataSyncManager, onItemRow), array(DataSyncManager, isRowSelected));
73 $spreadsheet->formCSS = "list spreadsheet small";
74 
75 $spreadsheet->submitLabel = "Import $name";
76 $spreadsheet->emptyMessage = "<strong>No valid records were found in the import file</strong>";
77 
79 
80 if ($method == "POST")
81 {
82  if ($spreadsheet->save())
83  {
84  Fakoli::notify("Records imported");
85 
86  $spreadsheet = new SpreadsheetForm($form, $items, 0, "POST", "", "", array(DataSyncManager, onItemRow), array(DataSyncManager, isRowSelected));
87  $spreadsheet->formCSS = "list spreadsheet small";
88 
89  $spreadsheet->submitLabel = "Import $name";
90  $spreadsheet->emptyMessage = "<strong>No valid records were found in the import file</strong>";
91 
92  }
93 }
94 
95 $script .= $form->writeScript();
96 $script .= <<<ENDSCRIPT
97 <script type='text/javascript'>
98 
99 var syncManager;
100 
101 window.addEvent('domready', function()
102 {
103  syncManager = new DataSyncManager('{$spreadsheet->id}', 'sync_controls', {chunked: $isChunked, offset: $offset, pageSize: $pageSize, totalRecords: $totalRecords});
104 });
105 </script>
106 ENDSCRIPT;
107 
108 $tabs->writeHTML();
109 ?>
110 <div class="tab_border">
111 <?
112 if (count($spreadsheet->forms))
113 {
114 ?>
115 <div id="sync_controls"></div>
116 <?
117 }
118 ?>
119 <div style='margin-top: 10px; width: 100%; overflow-y: auto'>
120 <?
121 $spreadsheet->drawForm();
122 ?>
123 </div></div>
$table pageSize
if(!DataSyncManager::fieldMappingHasMatchField($fieldMapping)) $filter
$import_profile_id
if($method=="POST") $script
$helpTree style
Definition: tree.inc:46
$size
Definition: download.inc:47
Provides a central management class for event handlers and common functionality for the data_sync com...
static fieldMappingHasMatchField($fieldMappings)
static getFieldMapping($class, $import_profile_id)
static createImportItems($class, $import_profile_id=0, $file="", $format=null)
static generateFilter($fieldMapping)
static extendForm($form)
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static notify($message, $blocking=false, $button="OK", $onClick="null")
Utility method to display a notification message to the user when the page has finished loading.
Definition: core.inc:1198
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$_SESSION["useMobile"]
Definition: override.inc:7