<?php session_start();?>
<html>
<head>
<title>deltasql - Searching ...</title>
<link rel="stylesheet" type="text/css" href="deltasql.css">
<link rel="shortcut icon" href="pictures/favicon.ico" />
</head>
<body>
<?php
include("head.inc.php");
include("utils/utils.inc.php");
if (!isset($_SESSION["userid"])) $userid="NULL"; else $userid=$_SESSION["userid"];
$filtertitle=$_POST['title'];
$filtercomment=$_POST['comments'];
$filterscript=$_POST['script'];
$authorid=$_POST['authorid'];
$moduleid=$_POST['moduleid'];
$branchid=$_POST['branchid'];
if (!isset($_POST['frmisaview'])) $frmisaview=""; else $frmisaview=$_POST['frmisaview'];
if (!isset($_POST['frmisapackage'])) $frmisapackage=""; else $frmisapackage=$_POST['frmisapackage'];
$fromversion=$_POST['fromversion'];
$toversion=$_POST['toversion'];
$fromdata=$_POST['fromdata'];
$todata=$_POST['todata'];
$frmprojectid=$_POST['frmprojectid'];
if (!isset($_POST['frmtextlistoutput'])) $textoutput=0; else $textoutput=$_POST['frmtextlistoutput'];
if (!isset($_POST['frmmodified'])) $modified=0; else $modified=$_POST['frmmodified'];
$scriptoffset = 0;
$_SESSION["scriptoffset"] = $scriptoffset;
$_SESSION["search_title"] = $filtertitle;
$_SESSION["search_comments"] = $filtercomment;
$_SESSION["search_script"] = $filterscript;
$_SESSION["search_authorid"] = $authorid;
$_SESSION["search_moduleid"] = $moduleid;
$_SESSION["search_branchid"] = $branchid;
$_SESSION["search_frmisaview"] = $frmisaview;
$_SESSION["search_frmisapackage"] = $frmisapackage;
$_SESSION["search_fromversion"] = $fromversion;
$_SESSION["search_toversion"] = $toversion;
$_SESSION["search_fromdata"] = $fromdata;
$_SESSION["search_todata"] = $todata;
$_SESSION["search_modified"] = $modified;
$_SESSION["search_projectid"] = $frmprojectid;
$link=mysql_connect($dbserver, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
// adapting empty field to NULL database terminology
if ($fromdata=="") $ins_fromdata="NULL"; else $ins_fromdata="'$fromdata'";
if ($todata=="") $ins_todata="NULL"; else $ins_todata="'$todata'";
if ($authorid=="") $ins_authorid="NULL"; else $ins_authorid=$authorid;
if ($moduleid=="") $ins_moduleid="NULL"; else $ins_moduleid=$moduleid;
if ($frmprojectid=="") $ins_projectid="NULL"; else $ins_projectid=$frmprojectid;
if ($branchid=="") $ins_branchid="NULL"; else $ins_branchid=$branchid;
if ($frmisaview=="") $ins_isaview="NULL"; else $ins_isaview=$frmisaview;
if ($frmisapackage=="") $ins_isapackage="NULL"; else $ins_isapackage=$frmisapackage;
if ($fromversion=="") $ins_fromversion="NULL"; else $ins_fromversion=$fromversion;
if ($toversion=="") $ins_toversion="NULL"; else $ins_toversion=$toversion;
// we insert the query first
$query="INSERT INTO tbsearchquery (id, title, content, comments, fromdate, todate, author_id, module_id, project_id, branch_id, isaview, isapackage, fromversion, toversion, modifiedscripts, textlistoutput, user_id, insertdate)
VALUES('','$filtertitle','$filterscript','$filtercomment',$ins_fromdata,$ins_todata,$ins_authorid,$ins_moduleid,$ins_projectid,$ins_branchid,$ins_isaview,$ins_isapackage,$ins_fromversion,$ins_toversion,$modified,$textoutput,$userid,NOW());";
//echo $query;
mysql_query($query);
// now we give a meaningful name to the query
// we retrieve the id first
$queryid="select max(id) from tbsearchquery";
$resid=mysql_query($queryid);
$id=mysql_result($resid, 0, "max(id)");
$queryupdate1="update tbsearchquery set queryname='' where id=$id ";
mysql_query($queryupdate1);
$queryupdate2="update tbsearchquery set queryname=CONCAT(queryname,'title: ',title) where id=$id and title is not null and title<>''";
mysql_query($queryupdate2);
$queryupdate3="update tbsearchquery set queryname=CONCAT(queryname,' content: ',content) where id=$id and content is not null and content<>''";
mysql_query($queryupdate3);
$queryupdate4="update tbsearchquery set queryname=CONCAT(queryname,' comments: ',comments) where id=$id and comments is not null and comments<>''";
mysql_query($queryupdate4);
$queryupdate5="update tbsearchquery set queryname=CONCAT(queryname,' from ',DATE_FORMAT(fromdate, '%d.%m.%Y')) where id=$id and fromdate is not null";
mysql_query($queryupdate5);
$queryupdate6="update tbsearchquery set queryname=CONCAT(queryname,' to ',DATE_FORMAT(todate, '%d.%m.%Y')) where id=$id and todate is not null";
mysql_query($queryupdate6);
if ($ins_authorid!="NULL") {
$queryupdate7="update tbsearchquery set queryname=CONCAT(queryname,' author: ',(select username from tbuser where id=$ins_authorid)) where id=$id";
mysql_query($queryupdate7);
}
if ($ins_moduleid!="NULL") {
$queryupdate8="update tbsearchquery set queryname=CONCAT(queryname,' module: ',(select name from tbmodule where id=$ins_moduleid)) where id=$id";
mysql_query($queryupdate8);
}
if ($ins_projectid!="NULL") {
$queryupdate9="update tbsearchquery set queryname=CONCAT(queryname,' project: ',(select name from tbproject where id=$ins_projectid)) where id=$id";
mysql_query($queryupdate9);
}
if ($ins_branchid!="NULL") {
$queryupdate10="update tbsearchquery set queryname=CONCAT(queryname,' branch: ',(select name from tbbranch where id=$ins_branchid)) where id=$id";
mysql_query($queryupdate10);
}
if ($ins_isaview=="1") {
$queryupdate11="update tbsearchquery set queryname=CONCAT(queryname,' isview') where id=$id";
mysql_query($queryupdate11);
}
if ($ins_isapackage=="1") {
$queryupdate12="update tbsearchquery set queryname=CONCAT(queryname,' ispackage') where id=$id";
mysql_query($queryupdate12);
}
if ($ins_fromversion!="NULL") {
$queryupdate13="update tbsearchquery set queryname=CONCAT(queryname,' from $ins_fromversion') where id=$id";
mysql_query($queryupdate13);
}
if ($ins_toversion!="NULL") {
$queryupdate14="update tbsearchquery set queryname=CONCAT(queryname,' to $ins_toversion') where id=$id";
mysql_query($queryupdate14);
}
if ($modified=="1") {
$queryupdate15="update tbsearchquery set queryname=CONCAT(queryname,' modified') where id=$id";
mysql_query($queryupdate15);
}
if ($textoutput=="1") {
$queryupdate16="update tbsearchquery set queryname=CONCAT(queryname,' text') where id=$id";
mysql_query($queryupdate16);
}
mysql_close();
if ($textoutput==1) {
js_redirect("list_scripts.php?textoutput=1&showall=1");
} else {
js_redirect("list_scripts.php");
}
?>
</body>
</html>