Location: PHPKode > projects > ERPSOD > erpsod/load_usertasks.php

// Are you authorised?
if (!$ok){
	$fout = 'No Access for chosen option';
	header("Location: login.php?error=$fout"); 

if ($form1=="load_usertasks"){
	if ($action == "Cancel") {
		header('Location: copyright.php');
	$filelocal = $f['tmp_name'] ;
	$serverfile = _DIR_HOME . _DIR_UPLOAD . safe_filename($f['name']);
	// Do we have the upload directory?
	if (!is_dir(_DIR_HOME . _DIR_UPLOAD)) {
		//  Let's try to create it.
		if (!@mkdir(_DIR_HOME . _DIR_UPLOAD)) {
			//  If directory can't be made Set error message and output
			echo $serverfile;
			die(" problems creating upload directory, please verify installation");	
	if (!is_file($filelocal)) {
		echo $filelocal;
		die(" file does not exist");
	// delete existing copy
	if (is_file($serverfile)) {
	if (!copy($filelocal, $serverfile)) {
		//  Set error message and output
		die("cannot copy file to server, check installation");

	// clean the tables
	$sql="truncate table usertasktemp";
	$result = mysql_query($sql);
	$sql="truncate table usertask";
	$result = mysql_query($sql);

	// load the fresh data
	$sql .= $serverfile;
	$sql .= "' INTO TABLE usertasktemp FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' (logonid,taskname)"; 
	$result = mysql_query($sql);
	$sql0="truncate table taskerrors";
	$result0 = mysql_query($sq0);
	User/Task Data has been loaded, now converting dataset........
	// use the temp table to fill the relational table
	$sql1= "select * from usertasktemp";
	$result1 = mysql_query($sql1);
	while ($row1 = mysql_fetch_array($result1, MYSQL_NUM)) {
		// retrieve userid
		$logonid = $row1[0];
		$sql2 = "select erpuserid from erpuser where logonid='$logonid'";
		$result2 = mysql_query($sql2);
		$usertel= mysql_num_rows($result2);
		if ($usertel>0){
			$row2 = mysql_fetch_array($result2, MYSQL_NUM);
			$userid= $row2[0];
			// retrieve the taskid
			$sql3= "select taskid from erptask where taskname='$taskname'";
			$result3 = mysql_query($sql3);
			$tasktel= mysql_num_rows($result3);
			if ($tasktel < 1){
				$sql6="select * from taskerrors where taskname='$taskname'";
				$result6 = mysql_query($sql6);
				$errortel= mysql_num_rows($result6);
				if ($errortel<1){
					$sql7="insert into taskerrors values('$taskname')";
					$result7 = mysql_query($sql7);
			} else{
				$row3 = mysql_fetch_array($result3, MYSQL_NUM);
			if ($taskid<>0) {
				$sql9="select * from usertask where taskid=$taskid and erpuserid=$userid";
				$result9 = mysql_query($sql9);
				$tel= mysql_num_rows($result9);
				if ($tel<1){
					$sql4= "insert into usertask values($userid, $taskid)";
					$result4 = mysql_query($sql4);
	User/Task Data has been converted to dataset........
	$sql99 ="select * from taskerrors";
	$result99 = mysql_query($sql99);
				$errortel= mysql_num_rows($result99);
	if ($errortel>0){
		echo '<br>';
		echo 'There were tasks not recognized, please verify export' ;
		echo '<br>';
<link rel="stylesheet" type="text/css" href="<?PHP echo $style ?>">
<script language="JavaScript1.2" src="js/coolmenus4.js">
<body bgcolor="#ffffff">
<script language="JavaScript1.2" src="js/erpsod.js">
<h3>Loading User/Tasks</h3>
<form enctype="multipart/form-data" method="post" >
<input type="hidden" name="form" value="load_usertasks" >
<table border=1 cellpadding=0 cellspacing=0 bgcolor="AQUA"><tr><td>
<tr><td align="center"><b>Select CSV file to reload User/Tasks combinations from</b></td></tr>
<input type="file" name="csv_file" size="50" />
<tr><td align="center">
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Load" style="width: 80px;"   ONCLICK="return confirm('Replace Current Dataset?')">
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Cancel" style="width: 80px;"><br>
Return current item: ERPSOD