<?php

//ini_set("display_errors", "1");
//error_reporting(E_ALL); 


$permalink1 = get_site_url();
$permalink2 = get_home_url();
if ($permalink1 == $permalink2) {
    $permalink = $permalink1;
} else {
    $permalink = $permalink2;
}
$find = array('http://', 'https://');
$replace = 'https://';
$siteurl = str_replace($find, $replace, $permalink);
$allMemberPages_obj = DAP_MemberPages::load();
 
?>	
<div id="dap_member_page_wrapper">
	<div class="dap_member_page_outer">
		<div class="master_heading d-flex align-items-center justify-content-between pb-3 mt-3">
			<h4><i class="fa fa-indent mr-2"></i> Manage Member Pages</h4>
			<a href="<?= admin_url('admin.php?page=dap_create_member_pages'); ?>" class="btn btn-success theme-btn">Create New Member Pages</a>
		</div>		
		<div class="dap_custom_table">
			<table class="table hover table-bordered table-striped" id="dap_member_page_table" style="display:none">
				<thead>
					<tr>
						<th>Id</th>
						<th>Page URL</th>
						<th>Type</th>
						<th class="shortcode_table_th">Shortcode</th>
						<th>Date</th>
						<th>Action</th>
					</tr>
				</thead>
				<tbody>
					
					<?php 
					
					foreach($allMemberPages_obj as $allMemberPage_obj){
						$edit_id = $allMemberPage_obj->getId();
						if($allMemberPage_obj->getAction() == 'login'){
							$shortcode = dapMemberGetShortcodeNameById($allMemberPage_obj->getId());	
							$edit_url = admin_url('admin.php?page=dap_member_login&id='.$allMemberPage_obj->getId());
						}else if($allMemberPage_obj->getAction() == 'loginFB'){
							$shortcode = dapMemberLoginFBGetShortcodeNameById($allMemberPage_obj->getId());	
							$edit_url = admin_url('admin.php?page=dap_member_login&id='.$allMemberPage_obj->getId());
						}else if($allMemberPage_obj->getAction() == 'mycontent'){
							$shortcode = dapMemberGetMyCntentShortcodeNameById($allMemberPage_obj->getId());	
							$edit_url = admin_url('admin.php?page=dap_member_content&id='.$allMemberPage_obj->getId());
						}else if($allMemberPage_obj->getAction() == 'affiliate'){
							$shortcode = dapMemberGetAffilateShortcodeNameById($allMemberPage_obj->getId());	
							$edit_url = admin_url('admin.php?page=dap_member_affiliate&id='.$allMemberPage_obj->getId());
						}else if($allMemberPage_obj->getAction() == 'profile'){
							$edit_url = admin_url('admin.php?page=dap_member_profile&id='.$allMemberPage_obj->getId());
							$shortcode = dapMemberGetProfileShortcodeNameById($allMemberPage_obj->getId());	
						}else if($allMemberPage_obj->getAction() == 'cancellation'){
							$edit_url = admin_url('admin.php?page=dap_member_cancellation&id='.$allMemberPage_obj->getId());
							$shortcode = dapMemberGetCancellationShortcodeNameById($allMemberPage_obj->getId());	
						}else if($allMemberPage_obj->getAction() == 'invoice'){
							$edit_url = admin_url('admin.php?page=dap_member_invoice&id='.$allMemberPage_obj->getId());
							$shortcode = dapMemberGetInvoiceShortcodeNameById($allMemberPage_obj->getId());	
						}else if($allMemberPage_obj->getAction() == 'invoice'){
							$edit_url = admin_url('admin.php?page=dap_member_invoice&id='.$allMemberPage_obj->getId());
							$shortcode = dapMemberGetInvoiceShortcodeNameById($allMemberPage_obj->getId());	
						}else if($allMemberPage_obj->getAction() == 'groupmembers'){
							$edit_url = admin_url('admin.php?page=dap_member_subaccount&id='.$allMemberPage_obj->getId());
							$shortcode = dapMemberGetSubaccountShortcodeNameById($allMemberPage_obj->getId());	
						}
						else{
							continue;
						}
						
						if($allMemberPage_obj->getAction() == 'mycontent'){
							$name = 'My Content';	
						}else if($allMemberPage_obj->getAction() == 'loginFB'){
							$name = ' Login FB';	
						}else{
							$name = ucwords($allMemberPage_obj->getAction());	
						}
												
						echo '<tr>';
						echo '<td align="center">'.$allMemberPage_obj->getId().'</td>';						 
						echo '<td align="left"><div class="tool-tip"><div class="tool-tip-outer"><a href="'.get_permalink($allMemberPage_obj->getPageId()).'" target="_blank">'.get_permalink($allMemberPage_obj->getPageId()).'</a><div class="toll-tip-desc"><a href="'.get_permalink($allMemberPage_obj->getPageId()).'" target="_blank">'.get_permalink($allMemberPage_obj->getPageId()).'</a></div></div></div></td>';
						echo '<td align="left">'.$name.'</td>';
						echo '<td align="left"><div class="shortcode_table_td"><span id="dynamic_copyable_text_'.$edit_id.'">'.$shortcode.'</span><span data-id="dynamic_copyable_text_'.$edit_id.'"  id="copy_shortcode" class="copy-btn theme-button btn btn-info " onclick="dap_member_copy_to_clipboard(this)"><i class="fa fa-files-o" aria-hidden="true"></i> Copy</span></div></td>';
						echo '<td align="center">'.$allMemberPage_obj->getDate().'</td>';
						
						echo '<td align="center"><a class="btn btn-info btn-sm" href="'.$edit_url.'"><i class="fa fa-pencil"></i></a> <a class="btn btn-danger btn-sm delete_member_pages" data-id="'.$allMemberPage_obj->getId().'" href=""><i class="fa fa-trash"></i></a></td>';
						echo '</tr>';
						}
					?>
										
				</tbody>
			</table>
		</div>
	</div>
</div>


 
