<?php
	
	$phpself .= '?op=marketing&type=campaigns';
	$pageName = 'Campaign Administration'; 
	$tableInfo = ''; 
	
	$adminBtns .= '<a href="#" class="admin btn btn-default" data-toggle="modal" data-target="#adminModal" data-admintype="'. $_REQUEST['type'] .'" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW '. ucfirst($_REQUEST['type']) .'</a>';
	
	include('pages/inc/page-header.php');

	$query = 'SELECT * FROM marketing_campaigns AS mc LEFT JOIN marketing_campaign_type AS ms ON (mc.camp_type = ms.typeid) WHERE mc.display=1 ORDER BY mc.camp_name ASC';
	$result = $con->query($query);

	if ($result) {
		$linkVars = '';
		$tableFieldNames = '<th>Campaign</th>
							<th>Type</th>
							<th>Date</th>
							<th>Description</th>
							<th>&nbsp;</th>';
		 
		include('inc/data-tables/table-top.php');
		include('inc/data-tables/table-bottom.php');
		
		$sortColumns = 4;
		$noSortColumns = 4; // Column Number from left (column 1=0) 
		$scrollHeight = '500px';
		$tabTable = false;
		 
		while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
			
			$adminLinks = ''; 
			$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $_REQUEST['type'] .'" data-adminact="edit" data-page="'. $_REQUEST['type'] .'" data-section="" data-editid="' . $row['campid'] . '" title="Edit '. ucfirst($_REQUEST['type']) .'"><i class="fa fa-pencil-square-o"></i></a> ';
				
			$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $_REQUEST['type'] .'" data-adminact="delete" data-page="'. $_REQUEST['type'] .'" data-section="" data-editid="' . $row['campid'] . '" title="Delete '. ucfirst($_REQUEST['type']) .'"><i class="fa fa-trash"></i></a> ';
				
			
			if ($row['camp_date'] == '0000-00-00')
				$camp_date = '';
			else 
				$camp_date = Date::convert($row['camp_date'], 'Y-m-d', 'm/d/Y');
							
			$tableInfo .= '<tr id="record-'. $row['campid'] .'">';
			$tableInfo .= '<td><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $_REQUEST['type'] .'" data-adminact="edit" data-page="'. $_REQUEST['type'] .'" data-section="" data-editid="' . $row['campid'] . '" title="Edit '. ucfirst($_REQUEST['type']) .'">'. $row['camp_name'] .'</a></td>';
			$tableInfo .= '<td>'. $row['type_desc'] .'</td>';
			$tableInfo .= '<td>'. $camp_date .'</td>';
			$tableInfo .= '<td>'. $row['camp_desc'] .'</td>';
			$tableInfo .= '<td class="adminActions">'. $adminLinks .'</td>';
			$tableInfo .= '</tr>';
		}
		$content .= '<div class="row"><div class="col-sm-12">';
		$content .= $tableHeader . '<tbody id="campaigns">' . $tableInfo . '</tbody>'. $tableFooter;
		$content .= '</div></div>';

		include('inc/data-tables/dataTables.php');
	}
?>