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 
11 $import_profile_id = $_SESSION["import_profile_id"];
12 
13 $multiProfile = Settings::getValue("data_sync", "multiple_import_profiles");
14 
15 if ($multiProfile)
16 {
17  if (!$import_profile_id)
18  {
19  redirect("data_import_field_mapping");
20  }
21 }
22 else
23 {
25 }
26 
27 $obj = new $class;
28 
29 $name = $obj->prettifyClassName(true);
30 
33 $filter->add($obj->primary_key);
34 
35 $obj->filter = $filter;
36 
37 $page_title = "Select $name to Import";
38 
40 
41 trace("Mapping ".count($items)." items", 3);
42 $form = new AutoForm($obj);
43 
44 if (is_array($obj->spreadsheetFieldSizes))
45 {
46  foreach($obj->spreadsheetFieldSizes as $field => $size)
47  {
48  $form->getRenderer($field)->size = $size;
49  }
50 }
51 
53 
54 
55 $isChunked = Settings::getValue("data_sync", "import_in_chunks") ? "true" : "false";
56 $pageSize = Settings::getValue("data_sync", "records_per_page");
58 
59 $offset = checkNumeric($_GET["offset"]);
60 if ($offset == '') $offset = 0;
61 if ($pageSize == '') $pageSize = 0;
62 if ($totalRecords == '') $totalRecords = 0;
63 
64 $spreadsheet = new SpreadsheetForm($form, $items, 0, "POST", "", "", array(DataSyncManager, onItemRow), array(DataSyncManager, isRowSelected));
65 $spreadsheet->formCSS = "list spreadsheet small";
66 
67 $spreadsheet->submitLabel = "Import $name";
68 $spreadsheet->emptyMessage = "<strong>No valid records were found in the import file</strong>";
69 
71 
72 if ($method == "POST")
73 {
74  if ($spreadsheet->save())
75  {
76  Fakoli::notify("Records imported");
77 
78  $spreadsheet = new SpreadsheetForm($form, $items, 0, "POST", "", "", array(DataSyncManager, onItemRow), array(DataSyncManager, isRowSelected));
79  $spreadsheet->formCSS = "list spreadsheet small";
80 
81  $spreadsheet->submitLabel = "Import $name";
82  $spreadsheet->emptyMessage = "<strong>No valid records were found in the import file</strong>";
83 
84  }
85 }
86 
87 $script .= $form->writeScript();
88 $script .= <<<ENDSCRIPT
89 <script type='text/javascript'>
90 
91 var syncManager;
92 
93 window.addEvent('domready', function()
94 {
95  syncManager = new DataSyncManager('{$spreadsheet->id}', 'sync_controls', {chunked: $isChunked, offset: $offset, pageSize: $pageSize, totalRecords: $totalRecords});
96 });
97 </script>
98 ENDSCRIPT;
99 
100 $tabs->writeHTML();
101 ?>
102 <div class="tab_border">
103 <?
104 if (count($spreadsheet->forms))
105 {
106 ?>
107 <div id="sync_controls"></div>
108 <?
109 }
110 ?>
111 <div style='margin-top: 10px; width: 100%; overflow-y: auto'>
112 <?
113 $spreadsheet->drawForm();
114 ?>
115 </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 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