Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once ('include/utils.php');
- require_once ('include/bugzillaAuth.php');
- $options_filetype = array( "any",
- "text",
- "msword",
- "excel",
- "powerpoint",
- "pdf",
- "jpeg",
- "png",
- "bmp",
- "gif",
- "html",
- "mhtml",
- "swf",
- "msword 2007",
- "excel 2007",
- "powerpoint 2007",
- "hangul"
- );
- sort($options_filetype);
- $options_orderby = array( "id", "filename", "size" );
- $options_orderbyAD = array( "ascending", "descending" );
- $options_outputformat = array( "table", "text", "count" );
- $options_outputlocation = array( "link", "url", "unix");
- $filetype_dirs = array( "any" => "",
- "text" => "text/_/",
- "msword" => "ole/msword/v%/%/_/",
- "excel" => "ole/excel/_/",
- "powerpoint" => "ole/ppt/%/_/",
- "pdf" => "pdf/v%/_/",
- "jpeg" => "jpeg/_/",
- "png" => "png/_/",
- "bmp" => "bmp/_/",
- "gif" => "gif/_/",
- "html" => "html/%/_/",
- "mhtml" => "mhtml/_/",
- "swf" => "flash/swf/v%/_/",
- "msword 2007" => "docx/_/",
- "excel 2007" => "xlsx/_/",
- "powerpoint 2007" => "pptx/_/",
- "hangul" => "hwp/_/"
- );
- $dbServer = "";
- $dbUsername = "";
- $dbPassword = "";
- $dbDatabase = "";
- $results = 0;
- $sql = "";
- $filetype = $options_filetype[0];
- $filename = "";
- $filesize_min = "";
- $filesize_max = "";
- $numresults = "";
- $outputformat = $options_outputformat[0];
- $orderby = $options_orderby[0];
- $orderbyAD = $options_orderbyAD[0];
- $outputLocation = $options_outputlocation[0];
- ########################################################
- FUNCTION buildsql($ftype,
- $fname,
- $fsize_min,
- $fsize_max,
- $num,
- $order,
- $orderAD,
- $outputFormat,
- $dirs)
- {
- $name = "%";
- $fsize_min = $fsize_min*1024;
- $fsize_max = $fsize_max*1024;
- if ($fname != "")
- {
- $name = str_replace("*", "%", $fname);
- }
- if ($ftype == "any")
- {
- $name = "%/".$name;
- }
- $sql = "SELECT id,filename,size FROM document WHERE filename ";
- $sql .= "LIKE '".$dirs[$ftype].$name."' ";
- if ($fsize_min > 0)
- $sql .= "AND size >=".$fsize_min." ";
- if ($fsize_max > 0)
- $sql .= "AND size <=".$fsize_max." ";
- if ($outputFormat <> "count")
- {
- if ($order <> "")
- $sql .= "ORDER BY ".$order." ";
- if ($order <> "" && $orderAD<>"")
- {
- if ($orderAD == "ascending")
- $orderAD = "ASC";
- else
- $orderAD = "DESC";
- $sql .= $orderAD." ";
- }
- if ($num > 0)
- $sql .= "LIMIT ".$num;
- }
- return $sql;
- }
- ########################################################
- FUNCTION getAndDisplayResults($outputformat,
- $outputloc,
- $dbS,
- $dbU,
- $dbP,
- $dbD,
- $sql)
- {
- $numResults = 0;
- echo("\n<div id=\"sql\">$sql</div>\n");
- $conn = mysql_connect($dbS, $dbU, $dbP) or die ("Error connecting to mysql");
- @mysql_select_db($dbD) or die ("Unable to select database");
- $result = mysql_query($sql) or die ("Failed the query bit!");
- if ($outputformat == "count")
- {
- echo("<b>Num Results: ".mysql_num_rows($result)."</b><br>\n");
- $total = 0;
- while ($row = mysql_fetch_array($result))
- $total += $row['size'];
- echo("<b>Total Size: ".number_format($total, 0, ".", ",")." kb</b>\n");
- return;
- }
- else if ($outputformat == "table")
- {
- echo("<div id=wrapper>\n");
- echo("<table cellpadding=0 cellspacing=0 border=0 class=display id=test-docs-table>\n");
- echo("<thead>\n<tr>\n<th>ID</th>\n<th>Filename</th>\n<th>Filesize(kb)</th>\n<th>Thumbnail</th>\n</tr>\n</thead>\n<tbody>\n");
- }
- while($row = mysql_fetch_array($result))
- {
- $numResults++;
- $loc = "";
- if ($outputloc == "url")
- {
- $loc = "http://testdocs.local.picsel.com/testdocs/".$row['filename'];
- }
- else if ($outputloc == "link")
- {
- $shortname = $row['filename'];
- $str = 'someLongString';
- $max = 50;
- // trim the filenames if they are too long
- if(strlen($shortname) > $max)
- {
- $shortname = substr($shortname, 0, $max) . '...';
- }
- $lastslash = strrpos($shortname, '/');
- $shortname = substr($shortname,$lastslash + 1);
- $tmpurl = "http://testdocs.local.picsel.com/testdocs/".$row['filename'];
- $loc = "<a href=\"$tmpurl\">$shortname</a>";
- }
- else
- {
- $loc = "/central/testdocs/".$row['filename'];
- }
- if ($outputformat == "table")
- {
- $row['size'] = ($row['size']) / 1024;
- $row['size'] = round($row['size'], 0);
- echo("<tr><td class=\"center\">".$row['id']."</td>\n<td>".$loc."</td>\n");
- echo("<td class=\"center\">".$row['size']."</td>\n");
- if ($numResults <= 20)
- {
- $shortname = $row['filename'];
- $doc = "/central/testdocs/".$row['filename'];
- $thumb = "include/doc-thumbnail.php?doc=$doc";
- echo("\n<div class=\"thumbnail\">\n<td class=\"center\"><a class=\"lightbox\" title=\"$shortname\" href=\"$thumb&dpi=96\"><img height=50 width=50 src=\"$thumb\"></a></td>\n</div>\n");
- }
- else
- {
- echo("<td> </td>\n");
- }
- echo("</tr>\n");
- }
- else
- {
- echo($loc."<br>\n");
- }
- }
- if ($outputformat == "table")
- echo("</tbody>\n");
- echo("<tfoot>\n<tr>\n<th>ID</th>\n<th>Filename</th>\n<th>Filesize(kb)</th>\n<th>Thumbnail</th>\n</tr>\n</tfoot>\n");
- echo("</table>\n");
- echo("</div>\n");
- echo("\n");
- echo($numResults." results");
- }
- ########################################################
- if (doPost('dosearch', "false") == "true")
- {
- /* do the search */
- $filetype = doPost('filetype', $filetype);
- $filename = doPost('filename', $filename);
- $filesize_min = doPost('filesize_min', $filesize_min);
- $filesize_max = doPost('filesize_max', $filesize_max);
- $numresults = doPost('numresults', $numresults);
- $outputformat = doPost('outputformat', $outputformat);
- $orderby = doPost('orderby', $orderby);
- $orderbyAD = doPost('orderbyad', $orderbyAD);
- $outputLocation = doPost('outputlocation', $outputLocation);
- $sql = buildsql($filetype,
- $filename,
- $filesize_min,
- $filesize_max,
- $numresults,
- $orderby,
- $orderbyAD,
- $outputformat,
- $filetype_dirs);
- }
- ########################################################
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
- <title>TestDocs Search</title>
- <link rel="stylesheet" type="text/css" href="default.css" />
- <script type="text/javascript" src="js/jquery.js"></script>
- <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
- <script type="text/javascript" src="js/jquery.dataTables.js"></script>
- <script type="text/javascript" src="js/ColReorder.js"></script>
- <script type="text/javascript" src="js/variables.js"></script>
- <script type="text/javascript" src="js/dropdown.js"></script>
- <script type="text/javascript" src="js/jquery.dd.js"></script>
- <script type="text/javascript" src="js/animatedcollapse.js"></script>
- <script type="text/javascript" src="js/jquery.ui.core.js"></script>
- <script type="text/javascript" src="js/jquery.ui.widget.js"></script>
- <script type="text/javascript" src="js/jquery.ui.position.js"></script>
- <script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>
- <script type="text/javascript">
- $(document).ready(function()
- {
- $('a.lightbox').lightBox();
- $('select.search').msDropDown();
- $('#test-docs-table').dataTable( {
- "sPaginationType": "full_numbers",
- "sDom": 'Rlfrtip'
- } );
- } );
- $(function () {
- $('.advancedsearch a').click(function () {
- $(this.hash).slideToggle(500);
- return false;
- });
- })
- animatedcollapse.addDiv('advancedsearch', 'fade=10,speed=600,persist=0,hide=1')
- animatedcollapse.ontoggle=function($, divobj, state)
- {
- //fires each time a DIV is expanded/contracted
- }
- animatedcollapse.init()
- </script>
- </head>
- <body id="testdocs" class="example_alt_pagination">
- <div id="navbar">
- <table>
- <tr>
- <td class="tname">TestDocs</td>
- <td><a href="http://intranet.picsel.com/~testdocs/">Main</a></td>
- <td><a href="http://intranet.picsel.com/~testdocs/upload.pl">Upload</a></td>
- <td align="center">Browse documents <br /> <a href="http://intranet.picsel.com/~testdocs/browse.pl/">By directory</a> | <a href="http://intranet.picsel.com/~testdocs/docsearch.pl">By properties</a></td> <td><a href="http://intranet.picsel.com/~testdocs/stats.pl">Statistics</a></td>
- <td><a href="/~ats/cgi-bin/overnightdas.pl">Overnight DA results</a></td>
- <td><a href="/~ats/">ATS proper</a></td> <td>User:<br><?php echo getBugzillaShortname();?></td>
- </tr>
- </table>
- <div class="privacy"><span class="confidential">COMPANY CONFIDENTIAL</span>
- <span class="bond">For Picsel Eyes Only.</span> <span class="doe">Contact Director of Engineering for written permission to show outside company.</span>
- </div>
- </div>
- <div id="container">
- <div id="header"><p>TestDocs Search</p></div>
- <?php
- // set $debug to 1 to see the values of the $_POST variables that are submitted
- $debug = 0;
- if ($debug == 1)
- {
- echo "<pre>".print_r($_POST, true). "</pre>";
- error_reporting(E_ALL);
- }
- ?>
- <div id ="form">
- <form enctype="multipart/form-data" method="post" action="testdocs-db.php" name="search" id="search" class="search">
- <input type="hidden" name="dosearch" value="true">
- <table border=0>
- <tr>
- <td class="label">File Type:</td>
- <td><?php if (isset($_POST['dosearch']))
- {
- doSelect("filetype", 1, $options_filetype, $filetype, "");
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- $key = array_search($_POST['hiddenfiletype'], $options_filetype);
- $hiddenfiletype = $options_filetype[$key];
- doSelect("filetype", 1, $options_filetype, $hiddenfiletype, "");
- }
- else
- {
- doSelect("filetype", 1, $options_filetype, $filetype, "");
- }
- // select the default filetype in the dropdown based on what form was submitted
- // if neither then just leave default to the first value in the list of options
- ?>
- </td>
- </tr>
- <tr>
- <td class="label">File Name:</td>
- <td>
- <input id="filename" name="filename" class="text" value="<?php if (isset($_POST['dosearch']))
- {
- echo($filename);
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- echo $_POST['hiddenfilename'];
- }
- // echo the correct variable depending on what type of search was submitted
- ?>">
- </td>
- <td> </td>
- </tr>
- <tr>
- <td class="label">File Size:</td>
- <td>
- <input id="filesize_min" name="filesize_min" class="text" value="<?php if (isset($_POST['dosearch']))
- {
- echo($filesize_min);
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- echo($_POST['hiddenfilesize_min']);
- }
- else
- {
- echo "";
- } ?>"><div id="kb">(kb min)</div>
- </td>
- <td>
- <input id="filesize_max" name="filesize_max" class="text" value="<?php if (isset($_POST['dosearch']))
- {
- echo($filesize_max);
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- echo($_POST['hiddenfilesize_max']);
- }
- else
- {
- echo "";
- }?>">
- <div id="kb">(kb max)</div>
- </td>
- </tr>
- <tr>
- <td class="label"># Results:</td>
- <td>
- <input id="numresults" name="numresults" class="text" value="<?php if (isset($_POST['dosearch']))
- {
- echo($numresults);
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- echo($_POST['hiddennumresults']);
- }
- else
- {
- echo "10";
- }?>">
- </td>
- <td> </td>
- </tr>
- <tr>
- <td class="label">Order By:</td>
- <td>
- <?php
- if (isset($_POST['dosearch']))
- {
- doSelect("orderbyad", 1, $options_orderbyAD, $orderbyAD, "");
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- $key = array_search($_POST['hiddenorderbyad'], $options_orderbyAD);
- $hiddenorderbyad = $options_orderbyAD[$key];
- doSelect("orderbyad", 1, $options_orderbyAD, $hiddenorderbyad, "");
- }
- else
- {
- doSelect("orderbyad", 1, $options_orderbyAD, $orderbyAD, "");
- }
- ?>
- </td>
- <td>
- <?php
- if (isset($_POST['dosearch']))
- {
- doSelect("orderby", 1, $options_orderby, $orderby, "");
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- $key = array_search($_POST['hiddenorderby'], $options_orderby);
- $hiddenorderby = $options_orderby[$key];
- doSelect("orderby", 1, $options_orderby, $hiddenorderby, "");
- }
- else
- {
- doSelect("orderby", 1, $options_orderby, $orderby, "");
- }
- ?>
- </td>
- </tr>
- <tr>
- <td class="label">Output Format:</td>
- <td>
- <?php
- if (isset($_POST['dosearch']))
- {
- doSelect("outputformat", 1, $options_outputformat, $outputformat, "");
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- $key = array_search($_POST['hiddenoutputformat'], $options_outputformat);
- $hiddenoutputformat = $options_outputformat[$key];
- doSelect("outputformat", 1, $options_outputformat, $hiddenoutputformat, "");
- }
- else
- {
- doSelect("outputformat", 1, $options_outputformat, $outputformat, "");
- }
- ?>
- </td>
- <td>
- <?php
- if (isset($_POST['dosearch']))
- {
- doSelect("outputlocation", 1, $options_outputlocation, $outputLocation, "");
- }
- elseif (isset($_POST['advancedsearchsubmit']))
- {
- $key = array_search($_POST['hiddenoutputlocation'], $options_outputlocation);
- $hiddenoutputlocation = $options_outputlocation[$key];
- doSelect("outputlocation", 1, $options_outputlocation, $hiddenoutputlocation, "");
- }
- else
- {
- doSelect("outputlocation", 1, $options_outputlocation, $outputLocation, "");
- }
- ?>
- </td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="submit" class="submit" value="Search"></td>
- <td> </td>
- </tr>
- </table>
- </form>
- <a href="#" rel="toggle[advancedsearch]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">Advanced Search<img id="expand" src="images/collapse.png"/></a>
- <div id="advancedsearch" class="advancedsearch">
- <form id="advancedsearchform" enctype="multipart/form-data" class="advancedsearchform" action="testdocs-db.php" method="post">
- <!-- These hidden inputs are to copy the values entered in the 'simple search' into these hidden inputs -->
- <!-- The reason for this is because the simple and advanced searches are split into two separate forms -->
- <input type="hidden" name="advancedsearchsubmit" value="1"/>
- <input type="hidden" name="hiddenfiletype" id="hiddenfiletype" value=""/>
- <input type="hidden" name="hiddenfilename" id="hiddenfilename" value=""/>
- <input type="hidden" name="hiddenfilesize_min" id="hiddenfilesize_min" value=""/>
- <input type="hidden" name="hiddenfilesize_max" id="hiddenfilesize_max" value=""/>
- <input type="hidden" name="hiddennumresults" id="hiddennumresults" value=""/>
- <input type="hidden" name="hiddenorderby" id="hiddenorderby" value=""/>
- <input type="hidden" name="hiddenorderbyad" id="hiddenorderbyad" value=""/>
- <input type="hidden" name="hiddenoutputformat" id="hiddenoutputformat" value=""/>
- <input type="hidden" name="hiddenoutputlocation" id="hiddenoutputlocation" value=""/>
- <!-- This value is the concatenator for the MySQL query - 'AND' or 'OR' -->
- <p>
- <input type="radio" name="andor" value="AND" checked /> match <span class="all">all</span> of these |
- match <span class="any">any</span> of these <input type="radio" name="andor" value="OR" />
- </p>
- <!-- The 'dropdown' div is important - this is what is copied by JQuery. -->
- <!-- That is also why all div's are classes in this section as id's must be unique -->
- <div class="dropdown">
- <select name="tags[]" class="tags">
- <option value="tags" selected="selected">tags</option>
- <option value="agent">agent</option>
- <option value="extension">extension</option>
- <option value="fileversion">fileversion</option>
- <option value="pages">pages</option>
- <option value="object">object</option>
- <option value="path">path</option>
- <option value="variant">variant</option>
- <option value="bad">bad</option>
- <option value="complex">complex</option>
- <option value="encrypted">encrypted</option>
- <option value="escherpropname">escherpropname</option>
- <option value="escherpropnumber">escherpropnumber</option>
- <option value="escherrecordname">escherecordname</option>
- <option value="escherrecordnumber">eshcerrecordnumber</option>
- <option value="eschershapename">eschershapename</option>
- <option value="eschershapenumber">eschershapenumber</option>
- <option value="mswordpicturetype">mswordpicturetype</option>
- <option value="functionuse">functionuse</option>
- <option value="objects">objects</option>
- <option value="heightpixels">heightpixels</option>
- <option value="widthpixels">widthpixels</option>
- <option value="maxrecordsize">maxrecordsize</option>
- <option value="encoding">encoding</option>
- <option value="dpi">dpi</option>
- <option value="depth">depth</option>
- <option value="mask">mask</option>
- <option value="progressive">progressive</option>
- <option value="colour">colour</option>
- </select>
- <!-- The operands and values dropdowns are populated dynamically based on the tags dropdown -->
- <select name="operands[]" class="operands">
- <option>please select a tag</option>
- </select>
- <select name="values[]" class="values">
- <option>please select a tag</option>
- </select>
- <!-- The reason for the [] are the select name is because multipl values are submitted. -->
- <!-- These tell the php code that it is an array of values and not a single value -->
- <!-- These are the buttons that add or remove the dropdown clones -->
- <img class="addButton" src="images/blank.gif" alt="add" onclick="addNew();"/>
- <img class="deleteButton" alt="delete" src="images/delete1.png" onclick="remove(this)" onmouseover="this.src='images/delete.png'" onmouseout="this.src='images/delete1.png'"/>
- <div class="clear"></div>
- </div>
- <!-- This is where the dropdown clones are placed -->
- <div class="clonecontainer"></div>
- <div class="advancedsearchsubmit"><input id="advancedsearchbutton" type="submit" class="advancedsubmit" value="Advanced Search"/></div>
- </form> <!-- End of advancedsearchform -->
- </div> <!-- End of advancedsearch div -->
- </div> <!-- End of form div -->
- <?php
- // simple search form processing
- if ($sql != "")
- {
- getAndDisplayResults($outputformat,
- $outputLocation,
- $dbServer,
- $dbUsername,
- $dbPassword,
- $dbDatabase,
- $sql);
- }
- else if (doPost('random', "false") == "true")
- {
- foreach ($filetype_dirs as $option)
- {
- if ($option == "")
- continue;
- $sql = "SELECT id,filename,size FROM document WHERE filename ";
- $sql .= "LIKE '$option%' ";
- $sql .= "ORDER BY RAND() LIMIT 10";
- getAndDisplayResults("text",
- "Unix Path",
- $dbServer,
- $dbUsername,
- $dbPassword,
- $dbDatabase,
- $sql);
- }
- }
- // advanced search form processing
- if (isset($_POST['advancedsearchsubmit']))
- {
- $tags = $_POST['tags'];
- $operands = $_POST['operands'];
- $values = $_POST['values'];
- $andor = $_POST['andor'];
- // hidden input values from simple search
- $filetype= doPost('hiddenfiletype', $filetype);
- $filename= doPost('hiddenfilename', $filename);
- $filesize_min= doPost('hiddenfilesize_min', $filesize_min);
- $filesize_max= doPost('hiddenfilesize_max', $filesize_max);
- $numresults= doPost('hiddennumresults', $numresults);
- $orderby= doPost('hiddenorderby', $orderby);
- $orderbyAD= doPost('hiddenorderbyad', $orderbyAD);
- $outputformat= doPost('hiddenoutputformat', $outputformat);
- $outputLocation= doPost('hiddenoutputlocation', $outputLocation);
- // need to convert kb to bytes to query db
- $filesize_min = $filesize_min*1024;
- $filesize_max = $filesize_max*1024;
- // end simple search criteria
- // start building the query
- $query = "SELECT ";
- $totaljoins = count($tags) + 1;
- // what we want from the testdocs database:
- $query .= "document.id, document.filename, document.size FROM document ";
- // this loop creates as many joins as there are advanced search criteria
- for ($joins=1 ; $joins < $totaljoins ; $joins++)
- {
- $query .= "JOIN documenttags dt$joins ON dt$joins.id = document.id ";
- }
- $query .= "WHERE ";
- $joins = 0;
- for ($counter=0 ; $counter < count($tags) ; $counter++)
- {
- $joins ++;
- // if there is more than one set of advanced search criteria
- // then place the concatenator value in between search terms
- if ($counter>0)
- {
- $query .= " $andor ";
- }
- // put all the values together in the right place using the sprintf function
- $query .= sprintf("(dt$joins.tag %s '%s' AND dt$joins.value %s '%s' )", $operands[$counter], $tags[$counter], $operands[$counter], $values[$counter]) ;
- }
- // tack on simple search criteria:
- $name = "%";
- // if a filename is specified then remove the % from $name
- if ($filename != "")
- {
- $name = str_replace("*", "%", $filename);
- }
- // need to add the following to the $name variable
- // so that we search in all the filetype directories
- if ($filetype == "any")
- {
- $name = "%/".$name;
- }
- // otherwise we have to get the correct directory to search
- // from the $filetype_dirs array
- $query .= " AND document.filename ";
- $query .= "LIKE '".$filetype_dirs[$filetype].$name."' ";
- // self explanotory maximum and minimum file sizes
- if ($filesize_min > 0)
- {
- $query .= "AND document.size >=".$filesize_min." ";
- }
- if ($filesize_max > 0)
- {
- $query .= "AND document.size <=".$filesize_max." ";
- }
- if ($outputformat <> "count")
- {
- if ($orderby <> "")
- {
- $query .= "ORDER BY ".$orderby." ";
- }
- if ($orderby <> "" && $orderbyAD<>"")
- {
- if ($orderbyAD == "ascending")
- {
- $orderbyAD = "ASC";
- }
- else
- {
- $orderbyAD = "DESC";
- }
- $query .= $orderbyAD." ";
- }
- }
- // limit search results based on limit entered by the user
- if ($numresults > 0)
- {
- $query .= " LIMIT $numresults";
- }
- else
- {
- $query .= " LIMIT $numresults";
- }
- getAndDisplayResults($outputformat,
- $outputLocation,
- $dbServer,
- $dbUsername,
- $dbPassword,
- $dbDatabase,
- $query);
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement