<?PHP
include_once("config.php");
$ok=role_check();
if (!$ok){
header("Location: login.php");
}
// Selections
$unitid=$_POST["unitlist"] ;
$deptid=$_POST["deptlist"] ;
$roleid=$_POST["rolelist"] ;
// exclusions
$unitid2=$_POST["unitlist2"] ;
$deptid2=$_POST["deptlist2"] ;
$roleid2=$_POST["rolelist2"] ;
// filter
$filter="";
if ($unitid>0) {
$filter .= " and erpuser.unitid=".$unitid ;
}
if ($deptid>0) {
$filter .= " and erpuser.deptid=".$deptid ;
}
if ($roleid>0) {
$filter .= " and erpuser.roleid=".$roleid ;
}
if ($unitid2>0) {
$filter .= " and erpuser.unitid <>".$unitid2 ;
}
if ($deptid2>0) {
$filter .= " and erpuser.deptid <>".$deptid2 ;
}
if ($roleid2>0) {
$filter .= " and erpuser.roleid <>".$roleid2 ;
}
$sql=" select logonid,name,rolename,deptdesc,unitdesc,taskname,reftaskid,usertask.erpuserid from erptask,usertask,erpuser,erprole,erpunit,erpdept where erpuser.erpuserid=usertask.erpuserid and usertask.taskid=erptask.taskid and erpuser.unitid=erpunit.unitid and erpuser.deptid=erpdept.deptid and erpuser.roleid=erprole.roleid ";
$sql .= $filter;
$sql .= " order by logonid,taskname";
$result = mysql_query($sql) or die($sql);
// Put the name of all fields
$out = "Logonid";
$out .= ",";
$out .= "Name";
$out .= ",";
$out .= "Role";
$out .= ",";
$out .= "Department";
$out .= ",";
$out .= "Unit";
$out .= ",";
$out .= "Task with SOD conflict";
$out .= ",";
$out .= "Mitigated";
$out .= ",";
$out .= "Conflict with";
$out .="\n";
// Add all values in the table
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$status=checksod2($row[7],$row[6]);
$stat = explode("|", $status);
if ($stat[1]<>""){
$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 .= ",";
if ($stat[0] = '3') {
$out.="NO" ;
} else{
$out.="YES" ;
}
$out .= ",";
$out .= trim("$stat[1]");
$out .="\n";
}
}
// Output to browser
header('Content-type: text/richtext');
header("Content-Disposition: attachment; filename=user_sod_exported.csv");
echo $out;