<?PHP
include_once("config.php");
$ok=role_check();
if (!$ok){
header("Location: login.php");
}
$sql=" select logonid, name,rolename,deptdesc,unitdesc,taskname,taskdesc from erpuser,usertask,erptask,erprole,erpunit,erpdept where usertask.erpuserid=erpuser.erpuserid and usertask.taskid=erptask.taskid and erpuser.unitid=erpunit.unitid and erpuser.deptid=erpdept.deptid and erpuser.roleid=erprole.roleid order by logonid,taskname";
$result = mysql_query($sql) or die(mysql_error());
// Put the name of all fields
$out = "Logonid";
$out .= ",";
$out .= "Name";
$out .= ",";
$out .= "Role";
$out .= ",";
$out .= "Department";
$out .= ",";
$out .= "Unit";
$out .= ",";
$out .= "Task";
$out .= ",";
$out .= "Description";
$out .="\n";
// Add all values in the table
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$out .= trim("$row[0]") ;
$out .= ",";
$out .= trim("$row[1]");
$out .= ",";
$out .= trim("$row[2]");
$out .= ",";
$out .= trim("$row[3]");
$out .= ",";
$out .= trim("$row[4]");
$out .= ",";
$out .= trim("$row[5]");
$out .= ",";
$out .= trim("$row[6]");
$out .="\n";
}
// Output to browser
header('Content-type: text/richtext');
header("Content-Disposition: attachment; filename=users_tasks_exported.csv");
echo $out;