Adsense
Popular Posts
- Code update from PHP 7.4 to PHP 8.1 - PhpSpreadsheet
- MySQL workbench -"Could not decrypt password cache"
- Code update from PHP 7.4 to PHP 8.1 - Worksheet/Iterator.php
- Rendering HTML tags inside textarea
- axios handle blob type data
- Unix Utils and wget in Windows
- Setup vi syntax for PHP
- increase mysql query speed
- git svn conversion
- EXCEL return to the next line in the same cell
Tuesday, January 28, 2014
Department database design (9) - import user csv file
C:\Users\jiansen\Desktop\CAS\jiansen_dir\www_cesei0_mobile\ubc_surgery_pub\scripts\manage\common.php, line 439 add
function userduplication($firstname, $lastname)
{
$results = mysql_query("SELECT * FROM USERS WHERE firstname='$firstname' AND lastname='$lastname'", connectpubsdb());
return mysql_num_rows($results);
}
C:\Users\jiansen\Desktop\CAS\jiansen_dir\www_cesei0_mobile\ubc_surgery_pub\scripts\manage\ superadmin/importcsvuser.php, new file
<?php
session_start();
if(isset($_SESSION['username']))
$_SERVER['REMOTE_USER']='1234567';
else{
echo 'You do not have adminsitraction right. <br />';
echo "\n<p style='text-align:left;'>[<a href='../../../demosite/'>Back to publication homepage</a>]</p>";
exit();
}
require_once(dirname(dirname(__FILE__)) . '/common.php');
require_once($config['homedir'] . 'query/formataref.php');
$uploadRISfile = $_FILES['uploadRISfile']['tmp_name'];
if (!empty($uploadRISfile))
{
if (file_exists($uploadRISfile) && is_uploaded_file($uploadRISfile))
{
$handle = fopen($uploadRISfile, "r");
$i = 0;
$message='Duplicated name not inputed: ';
while (($data0 = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$i =$i + 1;
if($i==1) continue;
// $name=explode(" ", trim($data0[0]));
$name= preg_split('/\s+/',trim($data0[0]));
$lastname = $name[0];
$firstname = $name[1];
$honorifics = $data0[1];
$dept = strtolower($data0[2]);
if (strpos($dept,'cardiac') !== false) {$deptid = 1;}
elseif (strpos($dept,'general') !== false) {$deptid = 2;}
elseif (strpos($dept,'neurosurgery') !== false) {$deptid = 3;}
elseif (strpos($dept,'otolaryngology') !== false) {$deptid = 4;}
elseif (strpos($dept,'pediatric') !== false) {$deptid = 5;}
elseif (strpos($dept,'plastic') !== false) {$deptid = 6;}
elseif (strpos($dept,'radiation') !== false) {$deptid = 7;}
elseif (strpos($dept,'thoracic') !== false) {$deptid = 8;}
elseif (strpos($dept,'vascular') !== false) {$deptid = 9;}
else { $deptid = 10;}
$room = $data0[3];
$email = filter_var($data0[4], FILTER_VALIDATE_EMAIL);
if($firstname=='') {echo 'First name missing'; exit;}
if($lastname=='') {echo 'Last name missing'; exit;}
$PI= strtolower($honorifics);
$IsPI = 0;
if ((strpos($PI,'professor') !== false) ||(strpos($PI,'instructor') !== false) ||(strpos($PI,'associate') !== false))
$IsPI = 1;
$rowreturn = userduplication($firstname, $lastname);
if($rowreturn>0) { $message = $message. $lastname.' '.$firstname.', ';}
elseif($IsPI == 1) addnewpersonwithdept(' ', $firstname, $lastname, $honorifics, $room, $deptid, $email);
}
if($message=='Duplicated name not input') $message='csv data is inputed to publication database. ';
else $message='csv data is inputed to publication database. '.$message;
fclose($handle);
echo '<script type="text/javascript">alert("' . $message . '"); window.location.href ="../index.php";</script>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-UK">
<head>
<link rel="stylesheet" type="text/css" href="../../../demosite/css/search.css" />
</head>
<body>
<h1>Import user csv data into publications database</h1>
<br />
<div class="content">
<form action="./superadmin/importcsvuser.php" method="post" enctype="multipart/form-data">
<p>To add user csv data into the online publications
database. Ths csv data should have 5 columns in the follwoing order:<br />
name (lastname firstname, required field), position, division, location and email.
</p>
<div style="margin: 10px 3px 10px 100px;">
<p><input name="uploadRISfile" type="file" size="30" /></p>
<p align="center"><input type="submit" value="Submit" /></p>
</div>
</form>
<p><br>
</div>
</body>
</html>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment