<?php

/*++++++++++++++++++++++++++++++++++++++++

  Script: Maian Gallery v2.0
  Written by: David Ian Bennett
  E-Mail: support@maianscriptworld.co.uk
  Website: http://www.maianscriptworld.co.uk

  ++++++++++++++++++++++++++++++++++++++++
  
  This File: search.php
  Description: Search Images

  ++++++++++++++++++++++++++++++++++++++++*/

// Make sure that this file is being called from parent file
if (!defined('INCLUDE_FILES')) {
  accessDenied($msg_script18,$msg_script19);
  exit;
}
 
include(FOLDER_PATH.'inc/cal_array.inc.php'); 
 
?>
<div align="center">
<?php
//Display search results
if (isset($SEARCH_RESULTS))
{
?>
<table width="100%" border="0" cellpadding="1" cellspacing="1" style="border: 2px solid #083253">
<tr>
    <td align="left" class="msgBox">&raquo; <b><?php echo $msg_search6; ?></b><br><br><?php echo $msg_search9; ?></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" class="menutable">
<tr>
    <td align="left" width="80%" class="leftPad">&raquo; <b><?php echo strtoupper(str_replace("{count}", rowCount('images',' '.$sql_string), $msg_search10)); ?></b></td>
    <td align="center" width="20%" class="leftPad" style="border-left:0">[ <a href="index.php?cmd=search" title="<?php echo $msg_search7; ?>" style="color:#FFFFFF"><?php echo $msg_search7; ?></a> ]</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" style="border: 2px solid #083253">
<?php

while ($SEARCH = mysql_fetch_object($q_search))
{
?>
<tr>
    <td align="center" class="msgBox" style="line-height:20px">
    <table width="100%" cellspacing="0" cellpadding="2">
    <tr>
      <td align="left" width="15%" class="tdHeight"><a href="index.php?cmd=cat_images&amp;img=<?php echo $SEARCH->id; ?>" rel="gb_page_center[680, 540]" title="<?php echo cleanData($SEARCH->name); ?>"><img src="<?php echo $SETTINGS->folder; ?>/galleries/<?php echo $SETTINGS->folder_name; ?>/<?php echo getFolderName($SEARCH->cat); ?>/<?php echo $SEARCH->thumbpath; ?>" alt="<?php echo cleanData($SEARCH->name); ?>" height="<?php echo ADD_IMG_HGHT; ?>" width="<?php echo ADD_IMG_WDTH; ?>" class="image_pad" title="<?php echo cleanData($SEARCH->name); ?>"></a></td>
      <td align="left" width="65%" class="tdHeight"><a href="index.php?cmd=cat_images&amp;edit=<?php echo $SEARCH->id; ?>" rel="gb_page_center[600, 450]" title="<?php echo cleanData($SEARCH->name); ?>"><b><?php echo cleanData($SEARCH->name); ?></b></a><br>
      <span style="font-size:11px;font-style:italic"><i><?php echo $SEARCH->imagepath; ?></i><br>
      <?php echo $SEARCH->thumbpath; ?><br>
      <?php echo showImgAttributes($SEARCH->id,getFolderName($SEARCH->cat),$SEARCH->imagepath); ?></span></td>
      <td align="center" width="15%" class="tdHeight" style="border:2px solid #083253"><a href="index.php?cmd=cat_images&amp;comments=<?php echo $SEARCH->id; ?>" rel="gb_page_center[680, 540]" title="<?php echo $msg_manage11; ?>"><?php echo $msg_manage11; ?></a><br><b><?php echo rowCount('comments',' WHERE imageID = \''.$SEARCH->id.'\' AND is_active = \'1\''); ?></b></td>
      </tr>
    </table>
    </td>
</tr>
<?php
}

?>
</table>
<?php
  echo admin_page_numbers(rowCount('images',' '.$sql_string),$limit,$page);
}
else
{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="1" style="border: 2px solid #083253">
<tr>
    <td align="left" class="msgBox">&raquo; <b><?php echo $msg_adminmenu5; ?></b><br><br><?php echo $msg_search; ?></td>
</tr>
</table>
<?php
//Display message if no results were found
if (isset($NO_RESULTS))
{
?>
<table cellpadding="0" cellspacing="0" width="100%" class="updateTable" style="margin-bottom:2px">
<tr>
    <td align="center" style="padding:5px"><?php echo $msg_search5; ?></td>
</tr>
</table>
<?php
}
?>
<table width="100%" cellpadding="0" cellspacing="0" class="menutable">
<tr>
    <td align="left" class="leftPad">&raquo; <b><?php echo strtoupper($msg_search8); ?></b></td>
</tr>
</table>
<form method="get" action="index.php">
<input type="hidden" name="cmd" value="search">
<input type="hidden" name="search" value="1">
<table width="100%" border="0" cellpadding="0" cellspacing="1" style="border: 2px solid #083253">
<tr>
    <td align="left" valign="top" class="msgBox">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="30%" align="left" class="tdHeight"><?php echo $msg_search2; ?>:</td>
        <td width="70%" align="left" class="tdHeight"><input class="formbox" type="text" name="keywords" size="25" value="<?php echo (isset($_GET['keywords']) ? cleanData($_GET['keywords']) : ''); ?>"></td>
    </tr>
    <tr>
        <td align="left" class="tdHeight"><?php echo $msg_search3; ?>:</td>
        <td align="left" class="tdHeight">
        <select name="cat">
        <option value="0">--------------</option>
        <?php
            
        $q_cats = mysql_query("SELECT * FROM ".$database['prefix']."categories 
                               WHERE parent = '1'
                               ORDER BY catname
                               ") or die(mysql_error());
  
        while ($CATS = mysql_fetch_object($q_cats)) {
          echo '<option value="'.$CATS->id.'" style="padding-left:3px"'.(isset($_GET['cat']) && $_GET['cat']==$CATS->id ? ' selected="selected"' : '').'>'.cleanData($CATS->catname).'</option>'."\n";
  
          // Does this category have children...
          $q_children = mysql_query("SELECT * FROM ".$database['prefix']."categories
                                     WHERE child = '{$CATS->id}'
                                     ORDER BY catname
                                     ") or die(mysql_error());
  
          if (mysql_num_rows($q_children)>0) {
            while ($CHILDREN = mysql_fetch_object($q_children)) {
              echo '<option value="'.$CHILDREN->id.'" style="padding-left:3px"'.(isset($_GET['cat']) && $_GET['cat']==$CHILDREN->id ? ' selected="selected"' : '').'>- '.cleanData($CHILDREN->catname).'</option>'."\n";
            }
          }
        }

        ?> 
        </select>
        </td>
    </tr>
    <tr>
        <td align="left" class="tdHeight"><?php echo $msg_search4; ?>:</td>
        <td align="left" class="tdHeight"><select name="from_day">
        <option selected value="0"> - </option>
        <?php

        foreach ($days as $s_days)
        {
          echo '<option value="'.$s_days.'" style="padding-left:3px"'.(isset($_GET['from_day']) && $_GET['from_day']==$s_days ? ' selected="selected"' : '').'>'.$s_days.'</option>'."\n";
        }

        ?>
        </select>
        <select name="from_month">
        <option selected value="0"> - </option>
        <?php

        foreach ($months as $s_months => $s_months_value)
        {
          echo '<option value="'.$s_months.'" style="padding-left:3px"'.(isset($_GET['from_month']) && $_GET['from_month']==$s_months ? ' selected="selected"' : '').'>'.$s_months_value.'</option>'."\n";
        }
        
        ?>
        </select>
        <select name="from_year">
        <option selected value="0"> - </option>
        <?php

        foreach ($years as $s_years)
        {
          echo '<option value="'.$s_years.'" style="padding-left:3px"'.(isset($_GET['from_year']) && $_GET['from_year']==$s_years ? ' selected="selected"' : '').'>'.$s_years.'</option>'."\n";
        }

        ?>
        </select>
        </td>
    </tr>
    <tr>
        <td align="left" class="tdHeight">&nbsp;</td>
        <td valign="top" align="left" class="tdHeight"><select name="to_day">
        <option selected value="0"> - </option>
        <?php

        foreach ($days as $s_days)
        {
          echo '<option value="'.$s_days.'" style="padding-left:3px"'.(isset($_GET['to_day']) && $_GET['to_day']==$s_days ? ' selected="selected"' : '').'>'.$s_days.'</option>'."\n";
        }

        ?>
        </select>
        <select name="to_month">
        <option selected value="0"> - </option>
        <?php

        foreach ($months as $s_months => $s_months_value)
        {
          echo '<option value="'.$s_months.'" style="padding-left:3px"'.(isset($_GET['to_month']) && $_GET['to_month']==$s_months ? ' selected="selected"' : '').'>'.$s_months_value.'</option>'."\n";
        }
        
        ?>
        </select>
        <select name="to_year">
        <option selected value="0"> - </option>
        <?php

        foreach ($years as $s_years)
        {
          echo '<option value="'.$s_years.'" style="padding-left:3px"'.(isset($_GET['to_year']) && $_GET['to_year']==$s_years ? ' selected="selected"' : '').'>'.$s_years.'</option>'."\n";
        }

        ?>
        </select>
        </td>
    </tr>
    <tr>
        <td align="left" class="tdHeight">&nbsp;</td>
        <td align="left" class="tdHeight"><input type="submit" class="formbutton" value="<?php echo $msg_adminmenu5; ?>" title="<?php echo $msg_adminmenu5; ?>"></td>
    </tr>
    </table>
    </td>
</tr>
</table>
</form>
<?php
}
?>
</div>
