1<?php 2 3/** 4 * L2 Domain import form + upload 5 */ 6 7# include required scripts 8require_once( dirname(__FILE__) . '/../../../functions/functions.php' ); 9 10# initialize user object 11$Database = new Database_PDO; 12$User = new User ($Database); 13$Tools = new Tools ($Database); 14 15# verify that user is logged in 16$User->check_user_session(); 17 18$tpl_field_names = ""; 19$tpl_field_types = ""; 20 21# predefine field list 22$expfields = array ("tname","tdescription"); 23$mtable = "deviceTypes"; # main table where to check the fields 24# required fields without which we will not continue 25$reqfields = array("tname"); 26 27# manually adjust the standard fields 28foreach($expfields as $std_field) { 29 # extra table and field 30 if (isset($extfields[$std_field])) { 31 $cfield = $extfields[$std_field]["field"]; 32 $ctable = $extfields[$std_field]["table"]; 33 $pname = $extfields[$std_field]["pname"]." "; 34 } else { 35 # default table and field 36 $cfield = $std_field; 37 $ctable = $mtable; 38 $pname = ""; 39 } 40 41 # read field attributes 42 $field = $Tools->fetch_full_field_definition($ctable,$cfield); 43 $field = (array) $field; 44 45 # mark required fields with * 46 $msgr = in_array($std_field,$reqfields) ? "*" : ""; 47 48 #prebuild template table rows to avoid useless foreach loops 49 $tpl_field_names.= "<th>".$pname.$field['Field'].$msgr."</th>"; 50 $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; 51} 52 53?> 54 55<!-- header --> 56<div class="pHeader"><?php print _("Select fields to import"); ?></div> 57 58<!-- content --> 59<div class="pContent"> 60 61<?php 62if (!is_writeable( dirname(__FILE__) . '/upload' )) $Tools->Result->show("danger", _("'app/admin/import-export/upload' folder is not writeable."), false, false); 63 64# print template form 65print "<form id='selectImportFields'><div id='topmsg'>"; 66print '<h4>'._("Template").'</h4><hr>'; 67print _("The import XLS/CSV should have the following fields and a <b>header row</b> for a succesful import:"); 68print "</div>"; 69print "<input name='expfields' type='hidden' value='".implode('|',$expfields)."' style='display:none;'>"; 70print "<input name='reqfields' type='hidden' value='".implode('|',$reqfields)."' style='display:none;'>"; 71print "<input name='filetype' id='filetype' type='hidden' value='' style='display:none;'>"; 72print "<table class='table table-striped table-condensed' id='fieldstable'><tbody>"; 73print "<tr>" . $tpl_field_names . "</tr>"; 74print "<tr>" . $tpl_field_types . "</tr>"; 75print "</tbody></table>"; 76print "<div id='bottommsg'>"._("The fields marked with * are mandatory")."</div>"; 77print "</form>"; 78 79$templatetype = 'devtype'; 80# print upload section 81print "<div id='uplmsg'>"; 82print '<h4>'._("Upload file").'</h4><hr>'; 83include 'import-button.php'; 84print "</div>"; 85 86?> 87 88</div> 89 90<!-- footer --> 91<div class="pFooter"> 92 <div class="btn-group"> 93 <button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button> 94 <button class="btn btn-sm btn-default" id="dataImportPreview" data-type="devtype" disabled><i class="fa fa-eye"></i> <?php print _('Preview'); ?></button> 95 </div> 96</div> 97