<?
/*
Members Manager Plugin (IHS)
Build Date 2.7.2003
*/
include("../renew.code.php");
?>	
					<form action="actions.php?a_mode=delete_selected" method="post">
					<input type="hidden" value="mgr.index.php?n=2&p_mode=members" name="return">
					<?					
							if($orderby == ""){
								$orderby = "signup_date";
							}
							
							if($dir == ""){
								$insert_dir = "&dir=desc";
							}
							else {
								$insert_dir = "&dir=";
							}	
							
							if($_GET['startat'] == "") {
								$startat = 0;
							} else {
								$startat = $_GET['startat'];
							}
							if($_GET['perpage'] == "") {
								$perpage = 50;
							} else {
								$perpage = $_GET['perpage'];
							}	
							
							$line = $startat;
							$templine = 0;
							$recordnum = 0;
							$total_views = 0;
							$count_total = 0;
									
					?>
					<table width="95%">
					
						<tr>
							<td colspan="8" align="right"><font face="verdana" size="1">Show <?php echo "<a href=\"mgr.index.php?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=0&perpage=25&page_num=1\">"; ?>25</a>, <?php echo "<a href=\"mgr.index.php?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=0&perpage=50&page_num=1\">"; ?>50</a>, <?php echo "<a href=\"mgr.index.php?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=0&perpage=100&page_num=1\">"; ?>100</a>, <?php echo "<a href=\"mgr.index.php?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=0&perpage=500&page_num=1\">"; ?>500</a> Records Per Page </td>
						</tr>
					
						<tr bgcolor="#eeeeee">
						
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b>&nbsp;</b></td>
						
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=plan<? echo $insert_dir; ?>" class="mgrheader">Plan</a></b></td>
							
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=used_bandwidth<? echo $insert_dir; ?>" class="mgrheader">Bandwidth</a></b></font></td>
						
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=member_id<? echo $insert_dir; ?>" class="mgrheader">ID</a></b></td>
													
							<td style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=email<? echo $insert_dir; ?>" class="mgrheader">Username</a></b> <font size="1">(Click to edit user)</font></td>
							
							<td style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=l_name<? echo $insert_dir; ?>" class="mgrheader">Name</a></b></td>
							
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=signup_date<? echo $insert_dir; ?>" class="mgrheader">Sign Up Date</a></b></font></td>
							
							<td align="center" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="2" color="#8C8E91"><b><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=members&orderby=active<? echo $insert_dir; ?>" class="mgrheader">Status</a></b></font></td>
														
						</tr>
						
						<?
						$member_result = mysql_query("SELECT * FROM members where email != '' order by '$orderby' " . $dir, $db);
						$rows = mysql_num_rows($member_result);
						while($member = mysql_fetch_object($member_result)){
						
							if($templine < $perpage and $line < $rows) {
				
								if($line == $recordnum) {
									$line++;
									$templine++;
						
									// signup date
									$s_date = substr($member->signup_date, 4, 2) . "/" . substr($member->signup_date, 6, 2) . "/" . substr($member->signup_date, 0, 4);
									$s_time = substr($member->signup_date, 0, 2) . ":" . substr($member->signup_date, 2, 2) . " " . substr($member->signup_date, 4, 2);
									
									// get plan details						
									if($member->custom_plan == 1){
										$plan_code = "C";
										$ratio = $member->used_bandwidth / $member->custom_bandwidth;
									}
									else {
										$plan_result = mysql_query("SELECT * FROM plans WHERE plan_id = '$member->plan'");
										$plan = mysql_fetch_object($plan_result);
											$plan_code = substr($plan->name, 0, 1);
											$ratio = $member->used_bandwidth / $plan->bandwidth;
									}
									
									if(strlen($member->email) > 20){
										$trim_email = substr($member->email, 0, 20) . "...";
									}
									else {
										$trim_email = $member->email;
									}
									
									$used_bw_w = round(75 * $ratio);
									$free_bw_w = 75 - $used_bw_w;
									
									$row_color++;	
									if ($row_color%2 == 0) {
										$bgcolor= "#EFEFEF";
									}
									else {
										$bgcolor= "#ffffff";
									}
						?>
						
						<tr bgcolor="<?php echo $bgcolor; ?>">
						
							<td><input type="checkbox" value="1" name="<?php echo $member->member_id; ?>"></td>
						
							<td <? if($orderby == "plan"){ echo "bgcolor=\"ECF6F8\""; } ?> align="center"><font face="verdana" size="1"><? echo $plan_code; ?></td>
							
							<td <? if($orderby == "used_bandwidth"){ echo "bgcolor=\"ECF6F8\""; } ?> align="center">
							
								<table width="90%" cellpadding="1" cellspacing="0">
								
									<tr>
									
										<td nowrap><img src="images/used.bw.gif" width="<? echo $used_bw_w; ?>" height="8"><img src="images/free.bw.gif" width="<? echo $free_bw_w; ?>" height="8">
										<br><font face="verdana" size="1"><? echo round($member->used_bandwidth, 2); ?>mb</td>
										
									</tr>
									
								</table>
							
							</td>
						
							<td <? if($orderby == "member_id"){ echo "bgcolor=\"ECF6F8\""; } ?> align="center"><font face="verdana" size="1" color="#8C8E91"><? echo $member->member_id; ?></td>
						
							<td <? if($orderby == "email"){ echo "bgcolor=\"ECF6F8\""; } ?>><font face="verdana" size="1"><a href="mgr.index.php?n=<? echo $n; ?>&p_mode=edit_mem&memid=<? echo $member->member_id; ?>"><? if($mgr_login_type == "demo"){ ?>Info Hidden In Demo Mode<? } else { echo $trim_email; } ?></a></td>
							
							<td <? if($orderby == "l_name"){ echo "bgcolor=\"ECF6F8\""; } ?>><font face="verdana" size="1"><? if($mgr_login_type == "demo"){ ?>Demo Mode<? } else { echo $member->l_name . ", " . $member->f_name; } ?></a></td>
							
							<td <? if($orderby == "signup_date"){ echo "bgcolor=\"ECF6F8\""; } ?> align="center"><font face="verdana" size="1"><? echo $s_date; ?></td>
							
							<td <? if($orderby == "active"){ echo "bgcolor=\"ECF6F8\""; } ?> align="center"><font face="verdana" size="1"><? if($member->active == "1"){ echo "Active"; } else { echo "Inactive"; } ?></td>
							
						</tr>
						
						<?
									}
								}
							
							$count_total = $count_total + $fcontents;
							$recordnum++;
							}
							
							if($rows > 0){
								$result_pages = round($rows/$perpage);
								
								if($_GET['page_num'] == ""){
									$page_num = 1;
								} else {
									$page_num = $_GET['page_num'];
								}
								
								if($result_pages < 1){
									$result_pages = 1;
								}
							}
							
						?>
						
						<tr bgcolor="#eeeeee">
						
							<td align="left" colspan="4" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="1" color="#B3B3B3"><? if($mgr_login_type == "demo"){ ?><input type="button" value="Delete Selected" onclick="demo_mode();"><? } else { ?><input type="submit" value="Delete Selected"><? } ?></td>
							
							<td colspan="2">							
								<div name="result_details" id="result_details" style="padding-left: 10px;padding-right: 10px;padding-top: 0px;width: 100%; clear: both;">
								<table width="100%" cellpadding="0" cellspacing="0">
									<tr>
										<td>
											<font face="verdana" size="1">Results: <b><? echo $rows; ?></b> (<? echo $result_pages; ?> Pages)
										</td>
										<td align="right"><font face="verdana" size="1">
										Page:  
										<b>
										<?
											$page_startat = 0;
											for($page=1; $page <= $result_pages; $page++){
												if($page == $page_num){
													echo "[" . $page . "] ";	
												} else {
													echo "<a href=\"mgr.index.php?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=" . $page_startat . "&perpage=" . $perpage . "&page_num=" . $page . "&perpage=" . $perpage . "\">" . $page . "</a> ";	
												}
											$page_startat = $page_startat + $perpage;
											}			
										?>
										: 
										<?
											if($startat == 0){
										?>
											<font color="#B0B0B0" face="verdana" size="1">Previous</font>
										<?
											}
											else{
												if(($startat - $perpage) < 1) {
										?>
													<a href="<?php print($PHP_SELF . "?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=0&perpage=" . $perpage . "&page_num=" . ($page_num-1) . "&sort_by=" . $sort_by . "&perpage=" . $perpage); ?>">Previous</a>
										<?
												} else {
										?>
													<a href="<?php print($PHP_SELF . "?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=" . ($startat - $perpage)); ?>&perpage=<?php print($perpage) . "&page_num=" . ($page_num-1) . "&sort_by=" . $sort_by . "&perpage=" . $perpage; ?>">Previous</a>
										<?
												}
											}
										?>
										 |
										<?
										
											if(($startat + $perpage) >= $rows){
										?>
											<font color="#B0B0B0" face="verdana" size="1">Next</font>
										<?
											}
											else{
												if($line < $rows) {
										?>
												<a href="<?php print($PHP_SELF . "?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=" . ($startat + $perpage)); ?>&perpage=<?php print($perpage) . "&page_num=" . ($page_num+1) . "&sort_by=" . $sort_by . "&perpage=" . $perpage; ?>">Next</a>
										<?
												} else {
										?>
												<a href="<?php print($PHP_SELF . "?n=" . $_GET['n'] . "&p_mode=" . $_GET['p_mode'] . "&startat=" . $startat); ?>&perpage=<?php print($perpage) . "&page_num=" . ($page_num+1) . "&sort_by=" . $sort_by . "&perpage=" . $perpage; ?>">Next</a>
										<?
												}
											}
										?>
										</b>
										</td>
									</tr>
								</table>
								</div>							
							</td>
							
							<td align="right" colspan="2" style="border-bottom: 1px solid #CCCBCB;border-right: 1px solid #CCCBCB"><font face="verdana" size="1" color="#B3B3B3"><? if($mgr_login_type == "demo"){ ?><input type="button" value="Delete Inactive" onclick="demo_mode();"><? } else { ?><input type="button" value="Delete Inactive" onclick="window.location='actions.php?a_mode=delete_inactive'"><? } ?></td>
							
						</tr>
											
					</table>
					
					</form>