<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if(isset( $_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"]!= "") {
    $artistid = $_SESSION["sess_artistid"];
}else {
    header("Location:login.php");
    exit;
}
if(checkArtistExpired($artistid)){
    header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
    exit;
}

if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!="") {
    $txtSearch = $_GET["txtSearch"];
    $cmbSearchType = $_GET["cmbSearchType"];
}
else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!="") {
    $txtSearch = $_POST["txtSearch"];
    $cmbSearchType = $_POST["cmbSearchType"];
}


$message = $_GET['msg'];


if($_GET['delete_permanent'] == 'N') {


    switch($_GET['delete_status']) {


        CASE 'N':
            $delete_image = "UPDATE ".$tableprefix."product_view_images SET vproduct_image_delete_status = 'Y'
							 WHERE nimage_productid = ".$_GET['del_id'];
            mysql_query($delete_image) or die(mysql_error());

            header('Location:list_productview_images_artist.php');

            break;
        CASE 'Y':
            $delete_image = "UPDATE ".$tableprefix."product_view_images SET vproduct_image_delete_status = 'N'
							 WHERE nimage_productid = ".$_GET['del_id'];
            mysql_query($delete_image) or die(mysql_error());

            header('Location:list_productview_images_artist.php');

            break;

    }

}

else if($_GET['delete_permanent'] == 'Y') {


    $select_bulk_images = "SELECT vimage_name FROM ".$tableprefix."product_view_images WHERE nimage_productid = ".$_GET['del_id'];
    $result_bulk_images = mysql_query($select_bulk_images) or die(mysql_error());

    if(mysql_num_rows($result_bulk_images) > 0) {
        while($bulk_images_row = mysql_fetch_array($result_bulk_images)) {
            unlink("../products/bulk_images/".$bulk_images_row['vimage_name']);
        }
    }

    $delete_bulk_images = "DELETE FROM ".$tableprefix."product_view_images WHERE nimage_productid = ".$_GET['del_id'];
    mysql_query($delete_bulk_images) or die(mysql_error());

    header('Location:list_productview_images_artist.php');




}


if(isset($_POST['gotoPage'])) {

    header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);


}


$qryopt = "";

if(isset($_POST['cmbSearchType'])) {

    $qryopt = " AND pvm.nimage_productid = ".$_POST['cmbSearchType'];


}


$sql = " SELECT pr.product_name,pvm.nproduct_image_id,pvm.nimage_productid,pr.product_name,pvm.vproduct_image_delete_status,
		 CASE WHEN pvm.vproduct_image_delete_status = 'Y' THEN 'No' ELSE 'Yes' END AS active_status
		 FROM ".$tableprefix."product_view_images pvm,".$tableprefix."products pr
		 WHERE pvm.nimage_productid = pr.product_id
		  AND pr.product_artist_id = ".$artistid.$qryopt;

$sql .= " GROUP BY pvm.nimage_productid";




if(!(isset($pagenum))) {
    $pagenum = 1;
}

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page'])? trim($_GET['page']):1;


if(empty($page)) {
    $page = 1;
}

$result=mysql_query($sql) or die(mysql_error());

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string = " LIMIT $limitvalue, $limit";

$sql = $sql.$query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">

    function clickSearch()
    {

        document.frmProductBulkImages.submit();

    }


    function deleteImages()
    {

        return confirm('<?php echo MSG_DEL_BULK_IMG;?> !!')
    }

    function blockImages(val)
    {


        if(val == 'N')
        {

            return confirm('<?php echo MSG_DIS_BULK_IMG;?>!!')

        }
        else if(val == 'Y')
        {

            return confirm('<?php echo MSG_EN_BULK_IMG;?> !!')

        }


    }

</script>

<body>

    <center>

        <div align="left" id="layout">




            <!--header area start -->
<?php

include_once("../includes/topheader_seller.php")

        ?>

            <!--header area end -->




            <div align="left" class="main_body">
                <!--main body start -->



<?php
include_once("../includes/artisttopmenu.php")
        ?>


                <div align="left" class="content_area">

                    <!--content area start -->

                    <div align="left" class="page_title"><?php echo TEXT_PROD_IMG; ?></div>
                    <div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>

                    <div align="left">

                        <form action="" method="post" name="frmProductBulkImages">

                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">

                                <tr>
                                    <td width="75%" align="left" valign="middle">

						Product ::
                                        <select name="cmbSearchType" class="textarea">
<?php

$select_product = "SELECT DISTINCT pr.product_name,pr.product_id
					   FROM ".$tableprefix."products pr
						where pr.product_artist_id='".$artistid."' ORDER BY pr.product_name ";
$result_product = mysql_query($select_product) or die(mysql_error());

if(mysql_num_rows($result_product) != 0) {

                                            while($product_row = mysql_fetch_array($result_product)) {

                                                    if($product_row['nimage_productid'] == $_POST['cmbSearchType']) {

                                                        $product_checked = "selected";

                                                    }
                                                    else {

                                                        $product_checked = "";

                                                    }

                                                    ?>

                                            <option value="<?php echo $product_row['product_id']?>" <?php echo $product_checked?>><?php echo stripslashes($product_row['product_name']);?></option>


                                                    <?php

                                                }

                                            }

                                            ?>
                                        </select> &nbsp;

                                        &nbsp;
                                        <a style="cursor:pointer" onClick="return clickSearch();"><img src='<?php echo $imagefolder;?>/go.jpg' border='0'></a>
                                    </td>
                                    <td align="right"><a href="product_viewimages_add_artist.php" style="cursor:pointer" class="add_new_button"><?php echo BTN_ADD_NEW; ?></a></td>
                                </tr>
                            </table>

                        </form>

                    </div>

                    <div align="left">

                        <form action="" method="post" name="frmProductBulkImages1">


                            <table border="0" width="100%" cellpadding="0" cellspacing="0" class='manage_table'>
                                <tr class="form_header">
                                    <th width="4%"><?php echo TEXT_SL_NO; ?></th>
                                    <th width="20%"><?php echo TXT_PRODUCT_NAME; ?></th>
                                    <th width="40%"><?php echo TEXT_PROD_IMG; ?></th>
                                    <th width="21%"><?php echo TEXT_ACTIVE; ?></th>
                                    <th width="15%" align="center"><?php echo TEXT_ACTION; ?></th>
                                </tr>
<?php
if(mysql_num_rows($result) > 0 ) {
    $i = 1;

    while($row = mysql_fetch_array($rs)) {

        ?>
                                <tr>
                                    <td><?php echo $i?></td>
                                    <td align="left"><?php echo htmlentities($row["product_name"]);?></td>

        <?php

        $select_product_images = "SELECT vimage_name FROM ".$tableprefix."product_view_images
							  WHERE nimage_productid = ".$row["nimage_productid"];
                                        $result_product_images = mysql_query($select_product_images) or die(mysql_error());
                                        ?>

                                    <td align="left">

                                        <?php
                                        while($product_image_row = mysql_fetch_array($result_product_images)) {

                                            ?>

                                        <img height="30" width="50" src="../products/bulk_images/<?php echo $product_image_row["vimage_name"]?>">
            <?php

                                            }

                                            ?>
                                    </td>
                                    <td align="left"><?php echo $row['active_status']?></td>
                                    <td align="left"><a href="product_viewimages_edit_artist.php?edit_id=<?php echo $row["nimage_productid"]?>" style="cursor:pointer" title="Edit image"><img src="../images/btn_edit.gif" border="0" alt="Edit image" id="<?php echo $i;?>"></a>&nbsp;/&nbsp;<a href="list_productview_images_artist.php?del_id=<?php echo $row["nimage_productid"]?>&delete_status=<?php echo $row['vproduct_image_delete_status']?>&delete_permanent=Y" style="cursor:pointer" onClick="return deleteImages();" title="Delete Image"><img src="../images/btn_del.gif" border="0" alt="Delete Image" id="d<?php echo $i;?>"></a>&nbsp;/&nbsp;
        <?php


                                                if($row['vproduct_image_delete_status'] == "Y") {

                                                    ?>
                                        <a href="list_productview_images_artist.php?del_id=<?php echo $row["nimage_productid"]?>&delete_status=<?php echo $row['vproduct_image_delete_status']?>&delete_permanent=N" style="cursor:pointer" title="Delete Image" onClick="return blockImages('<?php echo $row['vproduct_image_delete_status']?>')"><?php echo LINK_ENABLE; ?></a>

            <?php

                                                }
                                                else {

                                                    ?>

                                        <a href="list_productview_images_artist.php?del_id=<?php echo $row["nimage_productid"]?>&delete_status=<?php echo $row['vproduct_image_delete_status']?>&delete_permanent=N" style="cursor:pointer" onClick="return blockImages('<?php echo $row['vproduct_image_delete_status']?>')"><?php echo LINK_DISABLE; ?></a>

            <?php
                                                }

                                                ?>

                                    </td>
                                </tr>
                                                <?php
        $i++;

                                            }

                                        }
                                        else {

                                            ?>
                                <tr>
                                    <td align="center" valign="middle" colspan="6"  class="text_information">No Records Found !!</td>
                                </tr>
    <?php
                                        }

                                        if($page > 1) {
                                            $pageprev = $page-1;

    $previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PAGES_PREV."</a>";

                                }


                                if($page < $numofpages) {
                                    $pagenext = ($page + 1);

                                    $next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_PAGES_NEXT."</a>";

                                }



?>


                                <tr>
                                    <td class="page_nos"  align="center" colspan="2">&nbsp;</td>
                                    <td align="right" valign="middle" class="page_nos" colspan="2">&nbsp;</td>
                                    <td align="left" valign="middle" class="btn_gotbl">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="page_nos"  align="center" colspan="5">
                                        <table width="100%" border="0" cellspacing="10" cellpadding="0">
                                            <tr align="left" valign="middle">
                                                <td width="21%" align="right"><?php echo $previous_page?></td>
                                                <td width="23%" align="right">
															<?php echo TEXT_PAGES; ?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;<?php echo TEXT_GOTO; ?>
                                                </td>
                                                <td width="8%" align="right">
                                                    <select name="gotoPage" class="textarea2" style="padding:4px 5px; margin-bottom:1px; ">
                                <?php
                                for($i=1;$i<=$numofpages;$i++) {


                                    if($i == $_GET['page']) {
                                        $page_selected = "selected";
    }
    else {
        $page_selected = "";
    }


    ?>
                                                        <option value="<?php echo $i?>" <?php echo $page_selected?>><?php echo $i?></option>

    <?php
}

?>
                                                    </select>
                                                </td>
                                                <td width="7%">
                                                    <a onClick="Javascript:document.frmProductBulkImages1.submit();" class="go_button_2"><?php echo BTN_GO; ?></a>
                                                </td>
                                                <td width="41%" align="center"><?php echo $next?></td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>

                        </form>



                    </div>


                    <!--content area end-->

                </div>


                <div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
                <!--main body end -->
            </div>


<?php
include "../includes/footer.php";
?>