<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if (isset($_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"] != "") {
    $adminname = $_SESSION["sess_adminname"];
} else {
    header("Location:login.php");
    exit;
}
if ($_POST['postback1'] == "CS") {//for changing status
    $id = $_POST['uid'];
    $changeto = $_POST['changeto'];
    if ($changeto == "Y") { // Check if ststus for activation
        $sql = "select * from " . $tableprefix . "artists  where artist_id =$id ";
        $rs = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($rs) > 0) {
            $rr = mysql_fetch_array($rs);
            $status = $rr['vapproved'];

            $first_name = $rr['first_name'];

            $last_name = $rr['last_name'];


            if ($status == "NN") { // ststus check 
                $to = $rr['email'];

                /* ---------Multicart Seller Account Acivation Email Confirmation to seller------------ */
                $subject = "Your seller account activated with " . stripslashes(SITE_NAME);
                /* -------Email Template Reading Fuction Call-------- */
                $mailcontent = readEmailTemplate('seller_registration_approval', 'artists');
                $link = SITE_URL . "/sellers/";
                $mailcontent = str_replace('[first_name]', $first_name, $mailcontent);

                $mailcontent = str_replace('[last_name]', $last_name, $mailcontent);
                $mailcontent = str_replace('[link]', $link, $mailcontent);
                $mailcontent = str_replace('[site_name]', SITE_NAME, $mailcontent);

                $headers = "MIME-Version: 1.0" . "\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
                $headers .= "From: " . SITE_EMAIL . "<" . SITE_EMAIL . ">" . "\r\n";
                $mailcontent = nl2br($mailcontent);
                $mail_send_details = "<html><head><link href='" . SITE_URL . "/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=" . $logofolder . "/" . $logoimage . " width='125' height='39'/></div></div><div>" . $mailcontent . "</div></div><div align='left' class='clear_float'><img src=" . $imagefolder . "/clear.gif width=1 height=1/></div></div></div></center></body></html>";

                $mailsent = mail($to, $subject, $mail_send_details, $headers);

                /* ---------Multicart Seller Account Acivation End  Email Confirmation to seller------------ */
            } // end if  sttus check 
        } // end if  number rows check 
    }  // end if Y stsuts check 
    $sqlcs = "UPDATE " . $tableprefix . "artists  SET vapproved = '$changeto' where artist_id =$id  ";
    //echo $sqlcs;
    mysql_query($sqlcs);
    /* $update_product_status = "UPDATE ".$tableprefix."products SET deleted ='".$changeto."' WHERE product_artist_id =".$id;
      mysql_query($update_product_status); */
    $msg = MSG_STATUS_UPDATED_SUCCESSFULLY;
}
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"];
}

if (isset($_GET["msg"]) and $_GET["msg"] != "") {
    $msg = $_GET["msg"];
}
switch ($msg) {
    case "deleted": $message = MSG_USER_DELETED;
        break;
    default: $message = $msg;
        break;
} // switch



if (isset($_POST['gotoPage'])) {
    header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage'] . "&msg=" . $msg);
    exit();
}


$qryopt = "WHERE  s.deleted = 'N' ";
if ($txtSearch != "" && $txtSearch != "all") {
    if ($cmbSearchType == "artistname") {
        $txtkwd = str_replace(" ", "", $txtSearch);
        $qryopt .= "  AND  s.first_name like '%" . addslashes($txtkwd) . "%' OR s.last_name like
			'%" . addslashes($txtkwd) . "%' OR CONCAT(s.first_name,s.last_name) like '%" . addslashes($txtkwd) . "%'";
    } else if ($cmbSearchType == "dateofregn") {
        $dt = $txtSearch;
        $arrdt = explode("/", $dt);
        $day = $arrdt[1];
        $month = $arrdt[0];
        $year = $arrdt[2];
        $dt = $year . "-" . $month . "-" . $day;
        $qryopt .= "  AND   s.date_registered like '" . addslashes($dt) . "%'";
    } else if ($cmbSearchType == "email") {
        $qryopt .= "  AND   s.email like '" . addslashes($txtSearch) . "%'";
    }
}


$sql = " SELECT s.*,CASE WHEN vapproved = 'Y' THEN 'Approved' ELSE 'Not Approved' END AS arists_approved
	   FROM " . $tableprefix . "artists s " . $qryopt . "  order by date_registered DESC  ";


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

$limit = getSettingsValue('npagination_limit');

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


$page = $_GET['page'];

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.frmArtists.submit();
    }
    function ChangeStatus(id,status){

        var frm = document.frmSeller1;
		
        if(status == "N"){
            changeto = "<?php echo DISABLE;?>";
        }
        if(status == "Y")
        {
            changeto = "<?php echo APPROVE;?>";
        }
        if(confirm("<?php echo ARE_YOU_SURE_YOU_WANT_TO;?> "+ changeto +" <?php echo THIS_SELLER?>?")){
            frm.postback1.value="CS";
            frm.uid.value=id;
            frm.changeto.value=status;
            frm.submit();
        }

    }
</script>

<body>
<center>

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




        <!--header area start -->
<?php
include_once("../includes/topheader_admin.php")
?>

        <!--header area end -->




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



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


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

                <!--content area start -->
                <div align="left" class="page_title"><?php echo APPROVE_SELLERS;?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>

                <div align="right">																			

                    <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="get" name="frmArtists">

                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                            <tr>
                                <td width="55%" align="left" valign="middle" class=""><?php echo SEARCH;?>&nbsp;&nbsp;
                                <select name="cmbSearchType" class="textarea">
                                        <option value="all" ><?php echo ALL_SELLERS;?></option>
                                        <option value="artistname"  <?php if ($cmbSearchType == "artistname" || $cmbSearchType == "") {
                echo("selected");
            } ?>><?php echo SELLER_NAME;?></option>
                                        <option value="email"  <?php if ($cmbSearchType == "email") {
                echo("selected");
            } ?>><?php echo EMAIL;?></option>
                                        <option value="dateofregn"  <?php if ($cmbSearchType == "dateofregn") {
                echo("selected");
            } ?>><?php echo DATE_OF_REGN?> (<?php echo MM."/".DD."/".YYYY;?>)</option>
                                    </select>&nbsp;&nbsp;<input type="text" name="txtSearch"  maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }" class="textarea">
                                    &nbsp;&nbsp;<a onClick="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>
                                    
                                    </td>

                                </td>

                            </tr>
                        </table>
                    </form>	
                </div>


                <div align="left">

                    <form action="" method="post" name="frmSeller1">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                            <tr class="page_title2">
                             <th width="6%" align="center" valign="middle">#</th>
                              <th width="19%" align="right" valign="middle"><?php echo LOGIN_NAME;?></th>
                               <th width="21%" align="right" valign="middle"><?php echo NAME;?></th>
                               <th width="19%" align="right" valign="middle"><?php echo EMAIL;?></th>
                                <th width="21%" align="center" valign="middle"><?php echo REGISTERED;?> (<?php echo MM."/".DD."/".YYYY;?>)</th>
                                <th width="14%" align="center" valign="middle" colspan="2"><?php echo STATUS;?></th>
                           </tr>

                            <input name="changeto" type="hidden" id="changeto">
                            <input name="uid" type="hidden" id="uid">
                            <input name="postback1" type="hidden" id="postback1">

<?php
$i = 1;

if (mysql_num_rows($result) > 0) {



    while ($row = mysql_fetch_array($rs)) {
        $link = "<a class=links href='editartist.php?artistid=" . $row["artist_id"] . "' class='smalllink'>";

        if ($row["vapproved"] == "Y") {
            //$statusimg = "cross.gif";
            $changestatuslink = "ChangeStatus(" . $row["artist_id"] . ",'N');";
        } else {
            //$statusimg = "tick.gif";
            $changestatuslink = "ChangeStatus(" . $row["artist_id"] . ",'Y');";
        }


        $link1 = "<a style = 'cursor:pointer' href=\"#\" class='smalllink' onclick=\"$changestatuslink\">";
        switch ($row["arists_approved"]){
        	case 'Approved':$st=APPROVED;
        	break;
        	case 'Not Approved' :$st=NOT_APPROVED;
        	break;
        }
        ?>

                                    <tr>
                                    <td align="center" valign="middle"><?php echo (($page * $limit) + $i - $limit) ?></td>
                                    <td align="right" valign="middle"><?php echo $link . (stripslashes($row["artist_name"])) . "</a>"; ?></td>
                                     <td align="right" valign="middle"><?php echo $link . (stripslashes($row["first_name"]) . " " . stripslashes($row["last_name"])) . "</a>"; ?></td>
                                      <td align="right" valign="middle"><?php echo $link . htmlentities($row["email"]) . "</a>"; ?></td>
                                       <td align="center" valign="middle"><?php echo $link . dateFormat($row["date_registered"], "Y-m-d", "m/d/Y") . "</a>"; ?></td>
                                        <td colspan="2" align="center" valign="middle"><?php echo $link1 . $st . "</a>"; ?></td>
                                    </tr>
                                    <?php
                                    $i++;
                                }
                            } else {
                                ?>										

                                <tr>
                                    <td align="center" valign="middle" colspan="7" class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
                                </tr>




                                <?php
                            }

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

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


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

                                $next = "<a href=" . $_SERVER['PHP_SELF'] . "?rghtMenu=" . $_GET["rghtMenu"] . "&page=$pagenext alt='Next' border='0' class='small_gray_button'>Next</a>";
                            }
                            ?>
                            <tr>
                                <td align="right" class="btn_gotbl" valign="middle">&nbsp;</td>
                                <td align="left" valign="middle" class="page_nos">&nbsp;</td>
                                <td class="page_nos" colspan="4" align="center">&nbsp;</td>
                            </tr>							  <?php
                            if ($page < $numofpages || $page > 1) {
                                ?>
                                <tr>
                                    <td colspan="6" align="left" valign="middle">
										<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 PAGE."(".S.")";?> <?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;
												<?php echo GO_TO;?>
											</td>
											<td width="8%" align="right">
												<select class="textarea2" name="gotoPage" 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.frmSeller1.submit();" class="go_button_2">Go</a>
											</td>
											<td width="41%" align="center"><?php echo $next ?></td>
											</tr>
										</table>
									</td>
                                </tr><?php }
?>
                        </table>

                    </form>											

                </div>


                <!--content area end-->

            </div>

            </form>

            <div align="right" 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";
                                        ?>
																											