mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
forgotten to include functions.import.php
This commit is contained in:
345
admin/import.php
345
admin/import.php
@@ -1,158 +1,187 @@
|
|||||||
<?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
|
||||||
include ("../config.inc.php");
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* 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,
|
||||||
include ("../functions/functions.xhtml.php");
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* 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
|
||||||
include("../functions/functions.import.php");
|
* along with queXS; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
$css = array(
|
*
|
||||||
"../include/bootstrap-3.3.2/css/bootstrap.min.css",
|
*
|
||||||
"../include/bootstrap-3.3.2/css/bootstrap-theme.min.css",
|
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||||
"../include/font-awesome-4.3.0/css/font-awesome.css",
|
* @copyright Deakin University 2007,2008
|
||||||
"../css/bootstrap-switch.min.css",
|
* @package queXS
|
||||||
"../css/custom.css"
|
* @subpackage admin
|
||||||
);
|
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||||
$js_head = array(
|
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||||
"../js/jquery-2.1.3.min.js",
|
*
|
||||||
"../include/bootstrap-3.3.2/js/bootstrap.min.js",
|
*/
|
||||||
"../js/bootstrap-switch.min.js"
|
|
||||||
);
|
/**
|
||||||
$js_foot = array(
|
* Configuration file
|
||||||
"../js/bootstrap-filestyle.min.js",
|
*/
|
||||||
"../js/custom.js"
|
include ("../config.inc.php");
|
||||||
);
|
|
||||||
|
/**
|
||||||
if (isset($_POST['import_form']))
|
* XHTML functions
|
||||||
{
|
*/
|
||||||
//form has been submitted
|
include ("../functions/functions.xhtml.php");
|
||||||
$subtitle = T_("Validating and uploading");
|
|
||||||
xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
|
/**
|
||||||
echo "<a href='?' class='btn btn-default pull-left' ><i class='fa fa-chevron-left fa-lg text-primary'></i> " . T_("Go back") . "</a>";
|
* Sample import functions
|
||||||
|
*/
|
||||||
|
include("../functions/functions.import.php");
|
||||||
//verify each GET field is unique (except import_form)
|
|
||||||
$sfields = array();
|
$css = array(
|
||||||
foreach($_POST as $getv => $val)
|
"../include/bootstrap-3.3.2/css/bootstrap.min.css",
|
||||||
//clean up?
|
"../include/bootstrap-3.3.2/css/bootstrap-theme.min.css",
|
||||||
$sfields[$getv] = $val;
|
"../include/font-awesome-4.3.0/css/font-awesome.css",
|
||||||
|
"../css/bootstrap-switch.min.css",
|
||||||
$error = verify_fields($sfields);
|
"../css/custom.css"
|
||||||
|
);
|
||||||
$description = $_POST['description'];
|
$js_head = array(
|
||||||
|
"../js/jquery-2.1.3.min.js",
|
||||||
if ($error == "")
|
"../include/bootstrap-3.3.2/js/bootstrap.min.js",
|
||||||
{ //verified so upload
|
"../js/bootstrap-switch.min.js"
|
||||||
if (import_file($_POST['filename'],$description,$sfields))
|
);
|
||||||
{
|
$js_foot = array(
|
||||||
print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . " <h3>$description</h3></p></div>";
|
"../js/bootstrap-filestyle.min.js",
|
||||||
}
|
"../js/custom.js"
|
||||||
else
|
);
|
||||||
{
|
|
||||||
print -"<div class='alert alert-danger col-md-offset-2'><p>" . T_("Error importing file. Please try again") . "</p></div>";
|
if (isset($_POST['import_form']))
|
||||||
}
|
{
|
||||||
}
|
//form has been submitted
|
||||||
else
|
$subtitle = T_("Validating and uploading");
|
||||||
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>";
|
xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
|
||||||
|
echo "<a href='?' class='btn btn-default pull-left' ><i class='fa fa-chevron-left fa-lg text-primary'></i> " . T_("Go back") . "</a>";
|
||||||
//verifiy that exactly one primary phone number is selected
|
|
||||||
//upload to database
|
|
||||||
|
//verify each GET field is unique (except import_form)
|
||||||
xhtml_foot($js_foot);
|
$sfields = array();
|
||||||
|
foreach($_POST as $getv => $val)
|
||||||
}
|
//clean up?
|
||||||
else if (isset($_POST['import_file']))
|
$sfields[$getv] = $val;
|
||||||
{
|
|
||||||
//file has been submitted
|
$error = verify_fields($sfields);
|
||||||
$subtitle = T_("Select columns to import");
|
|
||||||
xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
|
$description = $_POST['description'];
|
||||||
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> " . T_("Go back") . "</a>";
|
|
||||||
|
if ($error == "")
|
||||||
|
{ //verified so upload
|
||||||
print "<form action='' method='post' class='col-md-10 form-group col-md-offset-1'>";
|
if (import_file($_POST['filename'],$description,$sfields))
|
||||||
|
{
|
||||||
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
|
print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . " <h3>$description</h3></p></div>";
|
||||||
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
|
}
|
||||||
|
else
|
||||||
display_table(get_first_row($tmpfname));
|
{
|
||||||
|
print -"<div class='alert alert-danger col-md-offset-2'><p>" . T_("Error importing file. Please try again") . "</p></div>";
|
||||||
?>
|
}
|
||||||
<p><input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/></p>
|
}
|
||||||
<input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/>
|
else
|
||||||
<div class="form-group">
|
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>";
|
||||||
<label class="col-md-4 control-label" for="submit"></label>
|
|
||||||
<div class="col-md-4">
|
//verifiy that exactly one primary phone number is selected
|
||||||
<button id="submit" type="submit" name="import_form" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i> <?php echo T_("Add sample"); ?></button>
|
//upload to database
|
||||||
</div>
|
|
||||||
</div>
|
xhtml_foot($js_foot);
|
||||||
|
|
||||||
</form>
|
}
|
||||||
|
else if (isset($_POST['import_file']))
|
||||||
<script type="text/javascript">
|
{
|
||||||
$('[switch="yes"]').bootstrapSwitch()
|
//file has been submitted
|
||||||
</script>
|
$subtitle = T_("Select columns to import");
|
||||||
|
xhtml_head(T_("Import sample") . ":",true,$css,$js_head,false,false,false,$subtitle);
|
||||||
<?php
|
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> " . T_("Go back") . "</a>";
|
||||||
xhtml_foot($js_foot);
|
|
||||||
}
|
|
||||||
else
|
print "<form action='' method='post' class='col-md-10 form-group col-md-offset-1'>";
|
||||||
{
|
|
||||||
//need to supply file to upload
|
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
|
||||||
$subtitle = T_("Select file to upload");
|
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
|
||||||
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'><i class='fa fa-chevron-left fa-lg text-primary'></i> " . T_("Go back") . "</a>";
|
display_table(get_first_row($tmpfname));
|
||||||
|
|
||||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
|
||||||
if (preg_match('/Firefox/i', $ua)) $csv= "text/csv"; else $csv= ".csv";
|
|
||||||
//print "ua=" . $_SERVER['HTTP_USER_AGENT'];
|
?>
|
||||||
?>
|
<p><input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/></p>
|
||||||
|
<input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/>
|
||||||
<form class="form-horizontal col-sm-12" enctype="multipart/form-data" action="" method="post">
|
<div class="form-group">
|
||||||
<fieldset>
|
<label class="col-md-4 control-label" for="submit"></label>
|
||||||
|
<div class="col-md-4">
|
||||||
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000" />
|
<button id="submit" type="submit" name="import_form" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i> <?php echo T_("Add sample"); ?></button>
|
||||||
|
</div>
|
||||||
<!-- File Button -->
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
|
</form>
|
||||||
<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">
|
<script type="text/javascript">
|
||||||
<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; ?>" />
|
$('[switch="yes"]').bootstrapSwitch()
|
||||||
</div>
|
</script>
|
||||||
</div>
|
|
||||||
|
<?php
|
||||||
<!-- Text input-->
|
xhtml_foot($js_foot);
|
||||||
<div class="form-group">
|
}
|
||||||
<label class="col-md-4 control-label" for="description"><?php echo T_("Sample description :"); ?></label>
|
else
|
||||||
<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">
|
//need to supply file to upload
|
||||||
</div>
|
$subtitle = T_("Select file to upload");
|
||||||
</div>
|
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'><i class='fa fa-chevron-left fa-lg text-primary'></i> " . T_("Go back") . "</a>";
|
||||||
<!-- Button -->
|
|
||||||
<div class="form-group">
|
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||||
<label class="col-md-4 control-label" for="submit"></label>
|
if (preg_match('/Firefox/i', $ua)) $csv= "text/csv"; else $csv= ".csv";
|
||||||
<div class="col-md-4">
|
//print "ua=" . $_SERVER['HTTP_USER_AGENT'];
|
||||||
<button id="submit" type="submit" name="import_file" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i> <?php echo T_("Add sample"); ?></button>
|
?>
|
||||||
</div>
|
|
||||||
</div>
|
<form class="form-horizontal col-sm-12 " enctype="multipart/form-data" action="" method="post">
|
||||||
|
<fieldset>
|
||||||
</fieldset>
|
|
||||||
</form>
|
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000" />
|
||||||
|
|
||||||
<?php
|
<!-- File Button -->
|
||||||
xhtml_foot($js_foot);
|
<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> <?php echo T_("Add sample"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
xhtml_foot($js_foot);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ function verify_fields($fields)
|
|||||||
*/
|
*/
|
||||||
function display_table($data)
|
function display_table($data)
|
||||||
{
|
{
|
||||||
print "<table>";
|
print "<table class='table-hover table-bordered table-condensed tclass'><thead class='highlight'>";
|
||||||
print "<tr><th></th><th>" . T_("Import?") . "</th><th>" . T_("Name") . "</th><th>" . T_("Type") . "</th><th>" . T_("Allow operator to see?") . "</th></tr>";
|
print "<tr><th>" . T_("Selected file column name") . "</th><th>" . T_("Import ?") . "</th><th class='col-sm-4'>" . T_("New Sample Variable Name") . "</th><th>" . T_("Variable Type") . "</th><th>" . T_("Show to operator?") . "</th></tr></thead><tbody>";
|
||||||
$row = 1;
|
$row = 1;
|
||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
@@ -140,21 +140,24 @@ function display_table($data)
|
|||||||
$checked = "checked";
|
$checked = "checked";
|
||||||
if (empty($val)) $val = "samp_$row";
|
if (empty($val)) $val = "samp_$row";
|
||||||
|
|
||||||
print "<tr><td>$value</td><td><input type=\"checkbox\" name=\"i_$row\" checked=\"$checked\"/></td><td><input type=\"text\" value=\"$val\" name=\"n_$row\"/></td><td>";
|
print "<tr><td>$value</td>
|
||||||
print "<select name=\"t_$row\">";
|
<td><input type=\"checkbox\" name=\"i_$row\" checked=\"$checked\" switch=\"yes\" data-size=\"small\" data-on-text=\"" . TQ_("Yes") . "\" data-off-text=" . TQ_("No") . " /></td>
|
||||||
$selected = "selected=\"selected\"";
|
<td><input type=\"text\" value=\"$val\" name=\"n_$row\" class=\"form-control\" /></td>
|
||||||
foreach($rs as $r)
|
<td>";
|
||||||
{
|
print "<select name=\"t_$row\" class=\"form-control\">";
|
||||||
print "<option value=\"{$r['type']}\" $selected>" . T_($r['description']) . "</option>";
|
print "<option value=\"\" $selected></option>";
|
||||||
$selected = "";
|
$selected = "selected=\"selected\"";
|
||||||
}
|
foreach($rs as $r)
|
||||||
print "</select></td>";
|
{
|
||||||
print "<td><input type=\"checkbox\" name=\"a_$row\"/></td>";
|
print "<option value=\"{$r['type']}\" >" . T_($r['description']) . "</option>";
|
||||||
|
$selected = "";
|
||||||
|
}
|
||||||
|
print "</select></td>";
|
||||||
|
print "<td> <input type=\"checkbox\" name=\"a_$row\" switch=\"yes\" data-size=\"small\" data-on-text=\"" . TQ_("Yes") . "\" data-off-text=" . TQ_("No") . " /></td>";
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
$row++;
|
$row++;
|
||||||
|
|
||||||
}
|
}
|
||||||
print "</table>";
|
print "</tbody></table>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user