Advertisement
Guest User

Untitled

a guest
May 3rd, 2011
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.96 KB | None | 0 0
  1. <?php
  2.     require_once ('include/utils.php');
  3.     require_once ('include/bugzillaAuth.php');
  4.  
  5.     $options_filetype       = array( "any",
  6.                                      "text",
  7.                                      "msword",
  8.                                      "excel",
  9.                                      "powerpoint",
  10.                                      "pdf",
  11.                                      "jpeg",
  12.                                      "png",
  13.                                      "bmp",
  14.                                      "gif",
  15.                                      "html",
  16.                                      "mhtml",
  17.                                      "swf",
  18.                                      "msword 2007",
  19.                                      "excel 2007",
  20.                                      "powerpoint 2007",
  21.                                      "hangul"
  22.                                    );
  23.  
  24.     sort($options_filetype);
  25.  
  26.     $options_orderby        = array( "id", "filename", "size" );
  27.     $options_orderbyAD      = array( "ascending", "descending" );
  28.     $options_outputformat   = array( "table", "text", "count" );
  29.     $options_outputlocation = array( "link", "url", "unix");
  30.  
  31.     $filetype_dirs          = array( "any"        => "",
  32.                                      "text"       => "text/_/",
  33.                                      "msword"     => "ole/msword/v%/%/_/",
  34.                                      "excel"      => "ole/excel/_/",
  35.                                      "powerpoint" => "ole/ppt/%/_/",
  36.                                      "pdf"        => "pdf/v%/_/",
  37.                                      "jpeg"       => "jpeg/_/",
  38.                                      "png"        => "png/_/",
  39.                                      "bmp"        => "bmp/_/",
  40.                                      "gif"        => "gif/_/",
  41.                                      "html"       => "html/%/_/",
  42.                                      "mhtml"      => "mhtml/_/",
  43.                                      "swf"        => "flash/swf/v%/_/",
  44.                                      "msword 2007" => "docx/_/",
  45.                                      "excel 2007"  => "xlsx/_/",
  46.                                      "powerpoint 2007" => "pptx/_/",
  47.                                      "hangul"     => "hwp/_/"
  48.                                    );
  49.  
  50.     $dbServer               = "";
  51.     $dbUsername             = "";
  52.     $dbPassword             = "";
  53.     $dbDatabase             = "";
  54.  
  55.     $results                = 0;
  56.     $sql                    = "";
  57.  
  58.     $filetype               = $options_filetype[0];
  59.     $filename               = "";
  60.     $filesize_min           = "";
  61.     $filesize_max           = "";
  62.     $numresults             = "";
  63.     $outputformat           = $options_outputformat[0];
  64.     $orderby                = $options_orderby[0];
  65.     $orderbyAD              = $options_orderbyAD[0];
  66.     $outputLocation         = $options_outputlocation[0];
  67.  
  68. ########################################################
  69.  
  70.     FUNCTION buildsql($ftype,
  71.                       $fname,
  72.                       $fsize_min,
  73.                       $fsize_max,
  74.                       $num,
  75.                       $order,
  76.                       $orderAD,
  77.                       $outputFormat,
  78.                       $dirs)
  79.     {
  80.         $name = "%";
  81.         $fsize_min = $fsize_min*1024;
  82.         $fsize_max = $fsize_max*1024;
  83.  
  84.         if ($fname != "")
  85.         {
  86.             $name = str_replace("*", "%", $fname);
  87.         }
  88.  
  89.         if ($ftype == "any")
  90.         {
  91.             $name = "%/".$name;
  92.         }
  93.  
  94.         $sql  = "SELECT id,filename,size FROM document WHERE filename ";
  95.         $sql .= "LIKE '".$dirs[$ftype].$name."' ";
  96.  
  97.         if ($fsize_min > 0)
  98.             $sql .= "AND size >=".$fsize_min." ";
  99.  
  100.         if ($fsize_max > 0)
  101.             $sql .= "AND size <=".$fsize_max." ";
  102.  
  103.         if ($outputFormat <> "count")
  104.         {
  105.             if ($order <> "")
  106.                 $sql .= "ORDER BY ".$order." ";
  107.  
  108.             if ($order <> "" && $orderAD<>"")
  109.             {
  110.                 if ($orderAD == "ascending")
  111.                     $orderAD = "ASC";
  112.                 else
  113.                     $orderAD = "DESC";
  114.  
  115.                 $sql .= $orderAD." ";
  116.             }
  117.  
  118.             if ($num > 0)
  119.                 $sql .= "LIMIT ".$num;
  120.         }
  121.  
  122.         return $sql;
  123.     }
  124.  
  125. ########################################################
  126.  
  127.     FUNCTION getAndDisplayResults($outputformat,
  128.                                   $outputloc,
  129.                                   $dbS,
  130.                                   $dbU,
  131.                                   $dbP,
  132.                                   $dbD,
  133.                                   $sql)
  134.     {
  135.         $numResults = 0;
  136.  
  137.         echo("\n<div id=\"sql\">$sql</div>\n");
  138.  
  139.         $conn = mysql_connect($dbS, $dbU, $dbP) or die ("Error connecting to mysql");
  140.         @mysql_select_db($dbD) or die ("Unable to select database");
  141.  
  142.         $result = mysql_query($sql) or die ("Failed the query bit!");
  143.  
  144.  
  145.         if ($outputformat == "count")
  146.         {
  147.             echo("<b>Num Results: ".mysql_num_rows($result)."</b><br>\n");
  148.             $total = 0;
  149.             while ($row = mysql_fetch_array($result))
  150.                 $total += $row['size'];
  151.  
  152.             echo("<b>Total Size: ".number_format($total, 0, ".", ",")." kb</b>\n");
  153.             return;
  154.         }
  155.         else if ($outputformat == "table")
  156.         {
  157.             echo("<div id=wrapper>\n");
  158.             echo("<table cellpadding=0 cellspacing=0 border=0 class=display id=test-docs-table>\n");
  159.             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");
  160.         }
  161.         while($row = mysql_fetch_array($result))
  162.         {
  163.             $numResults++;
  164.             $loc = "";
  165.  
  166.             if ($outputloc == "url")
  167.             {
  168.                 $loc = "http://testdocs.local.picsel.com/testdocs/".$row['filename'];
  169.             }
  170.             else if ($outputloc == "link")
  171.             {
  172.                 $shortname = $row['filename'];
  173.                 $str = 'someLongString';
  174.                 $max = 50;
  175.  
  176.                 // trim the filenames if they are too long
  177.                 if(strlen($shortname) > $max)
  178.                 {
  179.                     $shortname = substr($shortname, 0, $max) . '...';
  180.                 }
  181.                
  182.                 $lastslash = strrpos($shortname, '/');
  183.                 $shortname = substr($shortname,$lastslash + 1);
  184.                 $tmpurl = "http://testdocs.local.picsel.com/testdocs/".$row['filename'];
  185.                 $loc = "<a href=\"$tmpurl\">$shortname</a>";
  186.             }
  187.             else
  188.             {
  189.                 $loc = "/central/testdocs/".$row['filename'];
  190.             }
  191.  
  192.             if ($outputformat == "table")
  193.             {
  194.                 $row['size'] = ($row['size']) / 1024;
  195.                 $row['size'] = round($row['size'], 0);
  196.                 echo("<tr><td class=\"center\">".$row['id']."</td>\n<td>".$loc."</td>\n");
  197.                 echo("<td class=\"center\">".$row['size']."</td>\n");
  198.                 if ($numResults <= 20)
  199.                 {
  200.                     $shortname = $row['filename'];
  201.                     $doc = "/central/testdocs/".$row['filename'];
  202.                     $thumb = "include/doc-thumbnail.php?doc=$doc";
  203.                     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");
  204.                 }
  205.                 else
  206.                 {
  207.                     echo("<td>&nbsp;</td>\n");
  208.                 }
  209.                 echo("</tr>\n");
  210.             }
  211.             else
  212.             {
  213.                 echo($loc."<br>\n");
  214.             }
  215.         }
  216.  
  217.         if ($outputformat == "table")
  218.             echo("</tbody>\n");
  219.             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");
  220.             echo("</table>\n");
  221.             echo("</div>\n");
  222.  
  223.         echo("\n");
  224.         echo($numResults." results");
  225.     }
  226.  
  227. ########################################################
  228.  
  229.     if (doPost('dosearch', "false") == "true")
  230.     {
  231.         /* do the search */
  232.         $filetype       = doPost('filetype', $filetype);
  233.         $filename       = doPost('filename', $filename);
  234.         $filesize_min   = doPost('filesize_min', $filesize_min);
  235.         $filesize_max   = doPost('filesize_max', $filesize_max);
  236.         $numresults     = doPost('numresults',   $numresults);
  237.         $outputformat   = doPost('outputformat', $outputformat);
  238.         $orderby        = doPost('orderby',      $orderby);
  239.         $orderbyAD      = doPost('orderbyad',    $orderbyAD);
  240.         $outputLocation = doPost('outputlocation', $outputLocation);
  241.  
  242.         $sql = buildsql($filetype,
  243.                         $filename,
  244.                         $filesize_min,
  245.                         $filesize_max,
  246.                         $numresults,
  247.                         $orderby,
  248.                         $orderbyAD,
  249.                         $outputformat,
  250.                         $filetype_dirs);
  251.     }
  252.  
  253. ########################################################
  254. ?>
  255.  
  256. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  257. <html>
  258. <head>
  259.   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  260.   <title>TestDocs Search</title>
  261.   <link rel="stylesheet" type="text/css" href="default.css" />
  262.   <script type="text/javascript" src="js/jquery.js"></script>
  263.   <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
  264.   <script type="text/javascript" src="js/jquery.dataTables.js"></script>
  265.   <script type="text/javascript" src="js/ColReorder.js"></script>
  266.   <script type="text/javascript" src="js/variables.js"></script>
  267.   <script type="text/javascript" src="js/dropdown.js"></script>
  268.   <script type="text/javascript" src="js/jquery.dd.js"></script>
  269.   <script type="text/javascript" src="js/animatedcollapse.js"></script>
  270.   <script type="text/javascript" src="js/jquery.ui.core.js"></script>
  271.   <script type="text/javascript" src="js/jquery.ui.widget.js"></script>
  272.   <script type="text/javascript" src="js/jquery.ui.position.js"></script>
  273.   <script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>
  274.  
  275.   <script type="text/javascript">
  276.    $(document).ready(function()
  277.    {
  278.         $('a.lightbox').lightBox();
  279.         $('select.search').msDropDown();
  280.         $('#test-docs-table').dataTable( {
  281.                     "sPaginationType": "full_numbers",
  282.                     "sDom": 'Rlfrtip'
  283.                   } );
  284.         } );
  285.  
  286.         $(function () {
  287.             $('.advancedsearch a').click(function () {
  288.             $(this.hash).slideToggle(500);
  289.             return false;
  290.         });
  291.     })
  292.     animatedcollapse.addDiv('advancedsearch', 'fade=10,speed=600,persist=0,hide=1')
  293.     animatedcollapse.ontoggle=function($, divobj, state)
  294.     {
  295.         //fires each time a DIV is expanded/contracted
  296.     }
  297.     animatedcollapse.init()
  298.     </script>
  299. </head>
  300. <body id="testdocs" class="example_alt_pagination">
  301. <div id="navbar">
  302.     <table>
  303.         <tr>
  304.             <td class="tname">TestDocs</td>
  305.             <td><a href="http://intranet.picsel.com/~testdocs/">Main</a></td>
  306.             <td><a href="http://intranet.picsel.com/~testdocs/upload.pl">Upload</a></td>
  307.             <td align="center">Browse documents <br /> <a href="http://intranet.picsel.com/~testdocs/browse.pl/">By directory</a> &nbsp;|&nbsp; <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>
  308.             <td><a href="/~ats/cgi-bin/overnightdas.pl">Overnight DA results</a></td>
  309.             <td><a href="/~ats/">ATS proper</a></td> <td>User:<br><?php echo getBugzillaShortname();?></td>
  310.         </tr>
  311.     </table>
  312.     <div class="privacy"><span class="confidential">COMPANY CONFIDENTIAL</span>
  313.         <span class="bond">For Picsel Eyes Only.</span> <span class="doe">Contact Director of Engineering for written permission to show outside company.</span>
  314.     </div>
  315. </div>
  316.  
  317. <div id="container">
  318.     <div id="header"><p>TestDocs Search</p></div>
  319.    
  320. <?php
  321. // set $debug to 1 to see the values of the $_POST variables that are submitted
  322. $debug = 0;
  323.  
  324. if ($debug == 1)
  325. {
  326.     echo "<pre>".print_r($_POST, true). "</pre>";
  327.     error_reporting(E_ALL);
  328. }
  329. ?>
  330.  
  331. <div id ="form">
  332. <form enctype="multipart/form-data" method="post" action="testdocs-db.php" name="search" id="search" class="search">
  333.   <input type="hidden" name="dosearch" value="true">
  334.   <table border=0>
  335.     <tr>
  336.       <td class="label">File Type:</td>
  337.       <td><?php if (isset($_POST['dosearch']))
  338.         {
  339.             doSelect("filetype", 1, $options_filetype, $filetype, "");
  340.         }
  341.         elseif (isset($_POST['advancedsearchsubmit']))
  342.         {
  343.             $key = array_search($_POST['hiddenfiletype'], $options_filetype);
  344.             $hiddenfiletype = $options_filetype[$key];
  345.             doSelect("filetype", 1, $options_filetype, $hiddenfiletype, "");
  346.         }    
  347.         else
  348.         {
  349.             doSelect("filetype", 1, $options_filetype, $filetype, "");
  350.         }
  351.         // select the default filetype in the dropdown based on what form was submitted
  352.         // if neither then just leave default to the first value in the list of options
  353.  ?>
  354.       </td>
  355.     </tr>
  356.     <tr>
  357.       <td class="label">File Name:</td>
  358.       <td>
  359.         <input id="filename" name="filename" class="text" value="<?php if (isset($_POST['dosearch']))
  360.         {
  361.             echo($filename);
  362.         }
  363.         elseif (isset($_POST['advancedsearchsubmit']))
  364.         {
  365.             echo $_POST['hiddenfilename'];
  366.         }
  367.          // echo the correct variable depending on what type of search was submitted
  368.         ?>">
  369.       </td>
  370.       <td>&nbsp;</td>
  371.     </tr>
  372.     <tr>
  373.       <td class="label">File Size:</td>
  374.       <td>
  375.         <input id="filesize_min" name="filesize_min" class="text" value="<?php if (isset($_POST['dosearch']))
  376.         {
  377.             echo($filesize_min);
  378.         }
  379.         elseif (isset($_POST['advancedsearchsubmit']))
  380.         {
  381.             echo($_POST['hiddenfilesize_min']);
  382.         }
  383.         else
  384.         {
  385.             echo "";
  386.         } ?>"><div id="kb">(kb min)</div>
  387.       </td>
  388.       <td>
  389.         <input id="filesize_max" name="filesize_max" class="text" value="<?php if (isset($_POST['dosearch']))
  390.         {
  391.             echo($filesize_max);
  392.         }
  393.         elseif (isset($_POST['advancedsearchsubmit']))
  394.         {
  395.             echo($_POST['hiddenfilesize_max']);
  396.         }
  397.         else
  398.         {
  399.             echo "";
  400.         }?>">
  401.         <div id="kb">(kb max)</div>
  402.       </td>
  403.     </tr>
  404.     <tr>
  405.       <td class="label"># Results:</td>
  406.       <td>
  407.         <input id="numresults" name="numresults" class="text" value="<?php if (isset($_POST['dosearch']))
  408.         {
  409.             echo($numresults);
  410.         }
  411.         elseif (isset($_POST['advancedsearchsubmit']))
  412.         {
  413.             echo($_POST['hiddennumresults']);
  414.         }
  415.         else
  416.         {
  417.             echo "10";
  418.         }?>">
  419.       </td>
  420.       <td>&nbsp;</td>
  421.     </tr>
  422.     <tr>
  423.       <td class="label">Order By:</td>
  424.       <td>
  425. <?php
  426.     if (isset($_POST['dosearch']))
  427.         {
  428.             doSelect("orderbyad", 1, $options_orderbyAD, $orderbyAD, "");            
  429.         }
  430.         elseif (isset($_POST['advancedsearchsubmit']))
  431.         {
  432.             $key = array_search($_POST['hiddenorderbyad'], $options_orderbyAD);
  433.             $hiddenorderbyad = $options_orderbyAD[$key];
  434.             doSelect("orderbyad", 1, $options_orderbyAD, $hiddenorderbyad, "");
  435.         }      
  436.         else
  437.         {
  438.             doSelect("orderbyad", 1, $options_orderbyAD, $orderbyAD, "");
  439.         }    
  440. ?>
  441.       </td>
  442.       <td>
  443. <?php
  444.     if (isset($_POST['dosearch']))
  445.         {
  446.             doSelect("orderby", 1, $options_orderby, $orderby, "");            
  447.         }
  448.         elseif (isset($_POST['advancedsearchsubmit']))
  449.         {
  450.             $key = array_search($_POST['hiddenorderby'], $options_orderby);
  451.             $hiddenorderby = $options_orderby[$key];
  452.             doSelect("orderby", 1, $options_orderby, $hiddenorderby, "");
  453.         }      
  454.         else
  455.         {
  456.             doSelect("orderby", 1, $options_orderby, $orderby, "");
  457.         }    
  458. ?>
  459.       </td>
  460.     </tr>
  461.     <tr>
  462.       <td class="label">Output Format:</td>
  463.       <td>
  464. <?php      
  465.     if (isset($_POST['dosearch']))
  466.         {
  467.             doSelect("outputformat", 1, $options_outputformat, $outputformat, "");            
  468.         }
  469.         elseif (isset($_POST['advancedsearchsubmit']))
  470.         {
  471.             $key = array_search($_POST['hiddenoutputformat'], $options_outputformat);
  472.             $hiddenoutputformat = $options_outputformat[$key];
  473.             doSelect("outputformat", 1, $options_outputformat, $hiddenoutputformat, "");
  474.         }      
  475.         else
  476.         {
  477.             doSelect("outputformat", 1, $options_outputformat, $outputformat, "");
  478.         }
  479. ?>
  480.       </td>
  481.       <td>
  482. <?php      
  483.     if (isset($_POST['dosearch']))
  484.         {
  485.             doSelect("outputlocation", 1, $options_outputlocation, $outputLocation, "");            
  486.         }
  487.         elseif (isset($_POST['advancedsearchsubmit']))
  488.         {
  489.             $key = array_search($_POST['hiddenoutputlocation'], $options_outputlocation);
  490.             $hiddenoutputlocation = $options_outputlocation[$key];
  491.             doSelect("outputlocation", 1, $options_outputlocation, $hiddenoutputlocation, "");
  492.         }      
  493.         else
  494.         {
  495.             doSelect("outputlocation", 1, $options_outputlocation, $outputLocation, "");  
  496.         }
  497.     ?>
  498.       </td>
  499.     </tr>
  500.     <tr>
  501.       <td>&nbsp;</td>
  502.       <td><input type="submit" class="submit" value="Search"></td>
  503.       <td>&nbsp;</td>
  504.     </tr>
  505.   </table>
  506. </form>
  507.  
  508. <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>
  509. <div id="advancedsearch" class="advancedsearch">
  510. <form id="advancedsearchform" enctype="multipart/form-data" class="advancedsearchform" action="testdocs-db.php" method="post">
  511.  
  512. <!-- These hidden inputs are to copy the values entered in the 'simple search' into these hidden inputs -->
  513. <!-- The reason for this is because the simple and advanced searches are split into two separate forms -->
  514. <input type="hidden" name="advancedsearchsubmit" value="1"/>
  515. <input type="hidden" name="hiddenfiletype" id="hiddenfiletype" value=""/>
  516. <input type="hidden" name="hiddenfilename" id="hiddenfilename" value=""/>
  517. <input type="hidden" name="hiddenfilesize_min" id="hiddenfilesize_min" value=""/>
  518. <input type="hidden" name="hiddenfilesize_max" id="hiddenfilesize_max" value=""/>
  519. <input type="hidden" name="hiddennumresults" id="hiddennumresults" value=""/>
  520. <input type="hidden" name="hiddenorderby" id="hiddenorderby" value=""/>
  521. <input type="hidden" name="hiddenorderbyad" id="hiddenorderbyad" value=""/>
  522. <input type="hidden" name="hiddenoutputformat" id="hiddenoutputformat" value=""/>
  523. <input type="hidden" name="hiddenoutputlocation" id="hiddenoutputlocation" value=""/>
  524.  
  525. <!-- This value is the concatenator for the MySQL query - 'AND' or 'OR' -->
  526. <p>
  527. <input type="radio" name="andor" value="AND" checked /> match <span class="all">all</span> of these |
  528. match <span class="any">any</span> of these <input type="radio" name="andor" value="OR" />
  529. </p>
  530.  
  531. <!-- The 'dropdown' div is important - this is what is copied by JQuery. -->
  532. <!-- That is also why all div's are classes in this section as id's must be unique -->
  533. <div class="dropdown">
  534.     <select name="tags[]" class="tags">
  535.         <option value="tags" selected="selected">tags</option>
  536.         <option value="agent">agent</option>
  537.         <option value="extension">extension</option>
  538.         <option value="fileversion">fileversion</option>
  539.         <option value="pages">pages</option>
  540.         <option value="object">object</option>
  541.         <option value="path">path</option>
  542.         <option value="variant">variant</option>
  543.         <option value="bad">bad</option>
  544.         <option value="complex">complex</option>
  545.         <option value="encrypted">encrypted</option>
  546.         <option value="escherpropname">escherpropname</option>
  547.         <option value="escherpropnumber">escherpropnumber</option>
  548.         <option value="escherrecordname">escherecordname</option>
  549.         <option value="escherrecordnumber">eshcerrecordnumber</option>
  550.         <option value="eschershapename">eschershapename</option>
  551.         <option value="eschershapenumber">eschershapenumber</option>
  552.         <option value="mswordpicturetype">mswordpicturetype</option>
  553.         <option value="functionuse">functionuse</option>
  554.         <option value="objects">objects</option>
  555.         <option value="heightpixels">heightpixels</option>
  556.         <option value="widthpixels">widthpixels</option>
  557.         <option value="maxrecordsize">maxrecordsize</option>
  558.         <option value="encoding">encoding</option>
  559.         <option value="dpi">dpi</option>
  560.         <option value="depth">depth</option>
  561.         <option value="mask">mask</option>
  562.         <option value="progressive">progressive</option>
  563.         <option value="colour">colour</option>
  564.     </select>
  565.    
  566.     <!-- The operands and values dropdowns are populated dynamically based on the tags dropdown -->
  567.     <select name="operands[]" class="operands">
  568.         <option>please select a tag</option>
  569.     </select>
  570.  
  571.     <select name="values[]" class="values">
  572.         <option>please select a tag</option>
  573.     </select>
  574.     <!-- The reason for the [] are the select name is because multipl values are submitted. -->
  575.     <!-- These tell the php code that it is an array of values and not a single value -->
  576.  
  577.     <!-- These are the buttons that add or remove the dropdown clones -->
  578.     <img class="addButton" src="images/blank.gif" alt="add" onclick="addNew();"/>
  579.     <img class="deleteButton" alt="delete" src="images/delete1.png" onclick="remove(this)" onmouseover="this.src='images/delete.png'" onmouseout="this.src='images/delete1.png'"/>
  580.    
  581.     <div class="clear"></div>
  582. </div>
  583.  
  584. <!-- This is where the dropdown clones are placed -->
  585. <div class="clonecontainer"></div>
  586.  
  587. <div class="advancedsearchsubmit"><input id="advancedsearchbutton" type="submit" class="advancedsubmit" value="Advanced Search"/></div>
  588. </form> <!-- End of advancedsearchform -->
  589. </div> <!-- End of advancedsearch div -->
  590. </div> <!-- End of form div -->
  591.  
  592. <?php
  593.     // simple search form processing
  594.     if ($sql != "")
  595.     {
  596.         getAndDisplayResults($outputformat,
  597.                              $outputLocation,
  598.                              $dbServer,
  599.                              $dbUsername,
  600.                              $dbPassword,
  601.                              $dbDatabase,
  602.                              $sql);
  603.     }
  604.     else if (doPost('random', "false") == "true")
  605.     {
  606.         foreach ($filetype_dirs as $option)
  607.         {
  608.             if ($option == "")
  609.                 continue;
  610.  
  611.             $sql  = "SELECT id,filename,size FROM document WHERE filename ";
  612.             $sql .= "LIKE '$option%' ";
  613.             $sql .= "ORDER BY RAND() LIMIT 10";
  614.  
  615.             getAndDisplayResults("text",
  616.                                  "Unix Path",
  617.                                  $dbServer,
  618.                                  $dbUsername,
  619.                                  $dbPassword,
  620.                                  $dbDatabase,
  621.                                  $sql);
  622.         }
  623.     }
  624.  
  625.     // advanced search form processing
  626.     if (isset($_POST['advancedsearchsubmit']))
  627.     {
  628.         $tags = $_POST['tags'];
  629.         $operands = $_POST['operands'];
  630.         $values = $_POST['values'];
  631.         $andor = $_POST['andor'];
  632.        
  633.         // hidden input values from simple search
  634.         $filetype= doPost('hiddenfiletype', $filetype);
  635.         $filename= doPost('hiddenfilename', $filename);
  636.         $filesize_min= doPost('hiddenfilesize_min', $filesize_min);
  637.         $filesize_max= doPost('hiddenfilesize_max', $filesize_max);
  638.         $numresults= doPost('hiddennumresults', $numresults);
  639.         $orderby= doPost('hiddenorderby', $orderby);
  640.         $orderbyAD= doPost('hiddenorderbyad', $orderbyAD);
  641.         $outputformat= doPost('hiddenoutputformat', $outputformat);
  642.         $outputLocation= doPost('hiddenoutputlocation', $outputLocation);
  643.        
  644.         // need to convert kb to bytes to query db
  645.         $filesize_min = $filesize_min*1024;
  646.         $filesize_max = $filesize_max*1024;
  647.        
  648.         // end simple search criteria
  649.  
  650.         // start building the query
  651.         $query = "SELECT ";
  652.         $totaljoins = count($tags) + 1;
  653.  
  654.         // what we want from the testdocs database:
  655.         $query .= "document.id, document.filename, document.size FROM document ";
  656.  
  657.         // this loop creates as many joins as there are advanced search criteria
  658.         for ($joins=1 ; $joins < $totaljoins ; $joins++)
  659.         {
  660.             $query .= "JOIN documenttags dt$joins ON dt$joins.id = document.id ";
  661.         }
  662.  
  663.         $query .= "WHERE ";
  664.  
  665.         $joins = 0;
  666.  
  667.         for ($counter=0 ; $counter < count($tags) ; $counter++)
  668.         {
  669.             $joins ++;
  670.            
  671.             // if there is more than one set of advanced search criteria
  672.             // then place the concatenator value in between search terms
  673.             if ($counter>0)
  674.             {
  675.                 $query .= " $andor ";
  676.             }
  677.         // put all the values together in the right place using the sprintf function
  678.         $query .= sprintf("(dt$joins.tag %s '%s' AND dt$joins.value %s '%s' )", $operands[$counter], $tags[$counter], $operands[$counter], $values[$counter]) ;
  679.         }
  680.        
  681.         // tack on simple search criteria:
  682.        
  683.         $name = "%";
  684.        
  685.         // if a filename is specified then remove the % from $name
  686.         if ($filename != "")
  687.         {
  688.             $name = str_replace("*", "%", $filename);
  689.         }
  690.  
  691.         // need to add the following to the $name variable
  692.         // so that we search in all the filetype directories
  693.         if ($filetype == "any")
  694.         {
  695.             $name = "%/".$name;
  696.         }
  697.  
  698.         // otherwise we have to get the correct directory to search
  699.         // from the $filetype_dirs array
  700.         $query .= " AND document.filename ";
  701.         $query .= "LIKE '".$filetype_dirs[$filetype].$name."' ";
  702.        
  703.         // self explanotory maximum and minimum file sizes
  704.         if ($filesize_min > 0)
  705.         {
  706.             $query .= "AND document.size >=".$filesize_min." ";
  707.         }
  708.  
  709.         if ($filesize_max > 0)
  710.         {
  711.             $query .= "AND document.size <=".$filesize_max." ";
  712.         }
  713.        
  714.         if ($outputformat <> "count")
  715.         {
  716.             if ($orderby <> "")
  717.             {
  718.                 $query .= "ORDER BY ".$orderby." ";
  719.             }
  720.  
  721.             if ($orderby <> "" && $orderbyAD<>"")
  722.             {
  723.                 if ($orderbyAD == "ascending")
  724.                 {
  725.                     $orderbyAD = "ASC";
  726.                 }
  727.                 else
  728.                 {
  729.                     $orderbyAD = "DESC";
  730.                 }
  731.  
  732.                 $query .= $orderbyAD." ";
  733.             }
  734.         }
  735.        
  736.         // limit search results based on limit entered by the user
  737.         if ($numresults > 0)
  738.         {
  739.             $query .= " LIMIT $numresults";
  740.         }
  741.        
  742.         else
  743.         {
  744.             $query .= " LIMIT $numresults";
  745.         }
  746.  
  747.         getAndDisplayResults($outputformat,
  748.                              $outputLocation,
  749.                              $dbServer,
  750.                              $dbUsername,
  751.                              $dbPassword,
  752.                              $dbDatabase,
  753.                              $query);
  754.     }
  755. ?>
  756. </div>
  757. </body>
  758. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement