2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

modified import.php file + js lib

This commit is contained in:
Alex
2015-03-05 12:32:41 +03:00
parent 1443845b49
commit 3a3023bbe3
2 changed files with 159 additions and 129 deletions

View File

@@ -1,129 +1,158 @@
<?php <?php
/** /**
* Import a sample from a Headered CSV file * Import a sample from a Headered CSV file
* */
*
* This file is part of queXS /**
* * Configuration file
* queXS is free software; you can redistribute it and/or modify */
* it under the terms of the GNU General Public License as published by include ("../config.inc.php");
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. /**
* * XHTML functions
* queXS is distributed in the hope that it will be useful, */
* but WITHOUT ANY WARRANTY; without even the implied warranty of include ("../functions/functions.xhtml.php");
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. /**
* * Sample import functions
* You should have received a copy of the GNU General Public License */
* along with queXS; if not, write to the Free Software include("../functions/functions.import.php");
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* $css = array(
* "../include/bootstrap-3.3.2/css/bootstrap.min.css",
* @author Adam Zammit <adam.zammit@deakin.edu.au> "../include/bootstrap-3.3.2/css/bootstrap-theme.min.css",
* @copyright Deakin University 2007,2008 "../include/font-awesome-4.3.0/css/font-awesome.css",
* @package queXS "../css/bootstrap-switch.min.css",
* @subpackage admin "../css/custom.css"
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility );
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 $js_head = array(
* "../js/jquery-2.1.3.min.js",
*/ "../include/bootstrap-3.3.2/js/bootstrap.min.js",
"../js/bootstrap-switch.min.js"
/** );
* Configuration file $js_foot = array(
*/ "../js/bootstrap-filestyle.min.js",
include ("../config.inc.php"); "../js/custom.js"
);
/**
* XHTML functions if (isset($_POST['import_form']))
*/ {
include ("../functions/functions.xhtml.php"); //form has been submitted
$subtitle = T_("Validating and uploading");
/** xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
* Sample import functions echo "<a href='?' class='btn btn-default pull-left' ><i class='fa fa-chevron-left fa-lg text-primary'></i>&emsp;" . T_("Go back") . "</a>";
*/
include("../functions/functions.import.php");
//verify each GET field is unique (except import_form)
$sfields = array();
if (isset($_POST['import_form'])) foreach($_POST as $getv => $val)
{ //clean up?
//form has been submitted $sfields[$getv] = $val;
xhtml_head(T_("Import: Validating and uploading"));
$error = verify_fields($sfields);
//verify each GET field is unique (except import_form)
$sfields = array(); $description = $_POST['description'];
foreach($_POST as $getv => $val)
//clean up? if ($error == "")
$sfields[$getv] = $val; { //verified so upload
if (import_file($_POST['filename'],$description,$sfields))
$error = verify_fields($sfields); {
print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . "&emsp;<h3>$description</h3></p></div>";
$description = $_POST['description']; }
else
if ($error == "") {
{ //verified so upload print -"<div class='alert alert-danger col-md-offset-2'><p>" . T_("Error importing file. Please try again") . "</p></div>";
if (import_file($_POST['filename'],$description,$sfields)) }
{ }
print "<p>" . T_("Successfully imported file") . "</p>"; else
} print "<div class='alert alert-danger col-md-offset-2'><p>" . T_("Error:") . " $error </p><p>" . T_("Please go back in your browser and fix the problem") . "</p></div>";
else
{ //verifiy that exactly one primary phone number is selected
print "<p>" . T_("Error importing file. Please try again") . "</p>"; //upload to database
}
} xhtml_foot($js_foot);
else
print "<p>" . T_("Error:") . " $error </p><p>" . T_("Please go back in your browser and fix the problem") . "</p>"; }
else if (isset($_POST['import_file']))
//verifiy that exactly one primary phone number is selected {
//upload to database //file has been submitted
$subtitle = T_("Select columns to import");
xhtml_foot(); xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
echo "<a href='' onclick='history.back();return false;' class='btn btn-default pull-left' ><i class='fa fa-chevron-left fa-lg text-primary'></i>&emsp;" . T_("Go back") . "</a>";
}
else if (isset($_POST['import_file']))
{ print "<form action='' method='post' class='col-md-10 form-group col-md-offset-1'>";
//file has been submitted
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
xhtml_head(T_("Import: Select columns to import")); move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
?>
<form action="" method="post"> display_table(get_first_row($tmpfname));
<?php
?>
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO"); <p><input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/></p>
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname); <input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/>
<div class="form-group">
display_table(get_first_row($tmpfname)); <label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" type="submit" name="import_form" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i>&emsp;<?php echo T_("Add sample"); ?></button>
</div>
?> </div>
<p><input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/></p>
<p><input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/></p> </form>
<p><input type="submit" name="import_form"/></p>
</form> <script type="text/javascript">
$('[switch="yes"]').bootstrapSwitch()
<?php </script>
xhtml_foot();
<?php
} xhtml_foot($js_foot);
else }
{ else
//need to supply file to upload {
xhtml_head(T_("Import: Select file to upload")); //need to supply file to upload
?> $subtitle = T_("Select file to upload");
xhtml_head(T_("Import sample") .":",true,$css,$js_head,false,false,false,$subtitle);
<form enctype="multipart/form-data" action="" method="post"> echo "<a href='' onclick='history.back();return false;' class='btn btn-default'><i class='fa fa-chevron-left fa-lg text-primary'></i>&emsp;" . T_("Go back") . "</a>";
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /></p>
<p><?php echo T_("Choose the CSV sample file to upload:"); ?><input name="file" type="file" /></p> $ua = $_SERVER['HTTP_USER_AGENT'];
<p><?php echo T_("Description for file:"); ?><input name="description" type="text" /></p> if (preg_match('/Firefox/i', $ua)) $csv= "text/csv"; else $csv= ".csv";
<p><input type="submit" name="import_file" value="<?php echo T_("Add sample"); ?>"/></p> //print "ua=" . $_SERVER['HTTP_USER_AGENT'];
</form> ?>
<?php <form class="form-horizontal col-sm-12" enctype="multipart/form-data" action="" method="post">
xhtml_foot(); <fieldset>
} <input type="hidden" name="MAX_FILE_SIZE" value="1000000000" />
<!-- File Button -->
<div class="form-group">
?>
<label class="col-md-4 control-label" for="file"><?php echo T_("Choose the CSV sample file to upload:"); ?></label>
<div class="col-md-4">
<input id="file" name="file" class="filestyle" data-buttonBefore="true" data-iconName="fa fa-folder-open fa-lg text-primary " data-buttonText="<?php echo T_("Select file"); ?>" type="file" accept="<?php echo $csv; ?>" />
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="description"><?php echo T_("Sample description :"); ?></label>
<div class="col-md-4">
<input id="description" name="description" type="text" placeholder="<?php echo T_("Enter new sample name..."); ?>" class="form-control input-md">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" type="submit" name="import_file" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i>&emsp;<?php echo T_("Add sample"); ?></button>
</div>
</div>
</fieldset>
</form>
<?php
xhtml_foot($js_foot);
}
?>

1
js/bootstrap-filestyle.min.js vendored Normal file

File diff suppressed because one or more lines are too long