{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_modules.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$header.razdel_name}</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$header.sms_statistics_help}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a href="admin_sms_notifications.php?sel=settings">{$lang.admin_menu.sms_settings}</a>
    </li>
    <li>
        <a class="current">{$lang.admin_menu.sms_statistics}</a>
    </li>
</ul>
		<div class="user_operation_line" style="height:4px;font-size:0px;">

		</div>
{/if} <div id="users_table_div" style="width:100%;">
    <div class="user_status_line">
        <div id="tab_user_stat" onclick="UsersList('user')" class="user_status_elem{if $type eq 'user'}_active{/if}" width="80px">
            {if $type eq 'all'}<a>{/if}{$header.users_statistics}{if $type eq 'all'}</a>{/if}
        </div>
        <div id="tab_all_stat" onclick="UsersList('all')" class="user_status_elem{if $type eq 'all'}_active{/if}" width="80px">
            {if $type eq 'user'}<a>{/if}{$header.all_statistics}{if $type eq 'user'}</a>{/if}
        </div>
        <div class="cr"></div>


		<div class="panel_subtabs">		
		<div class="panel_content" style="width:98%;">
       
<table cellpadding="0" cellspacing="0" border="0" width="100%">

{*	<tr>
		<td style="padding-bottom: 10px;">
		{strip}
		&nbsp;&nbsp;&nbsp;
		{if $type == "user"}<b>{else}<a href="{$file_name}?sel=statistics&type=user">{/if}
		{$header.users_statistics}
		{if $type == "user"}</b>{else}</a>{/if}
		&nbsp;&nbsp;&nbsp;
		{if $type == "all"}<b>{else}<a href="{$file_name}?sel=statistics&type=all">{/if}
		{$header.all_statistics}
		{if $type == "all"}</b>{else}</a>{/if}
		&nbsp;&nbsp;&nbsp;			
		{/strip}
		</td>
	</tr>*}
<!-- start (ALL USERS)-->	
	{if !$id_user && $type=='user'}
		{if $user}
		<tr>
			<td>
			<table width="100%"><tr>
				<td height="30px"  align="left" class="main_content_text" >
				{$header.letter_search_help}: {$letter_links}
				</td>
				<td height="30px"  align="right" class="main_content_text" >
				
				
				<table><tr>
				<form name="search_form" action="{$file_name}" method="post">
				<input type="hidden" name="sel" value="statistics">
				<input type="hidden" name="sorter" value="{$sorter}">
				<input type="hidden" name="order" value="{$order}">
				<td class="main_content_text" ><input type="text" name="search" value="{$search}"></td>

				<td class="main_content_text" ><select name="s_type" style="">
				<!--<option value="1" {if $s_type == 1}selected{/if}>{$lang.users_types.type_1}</option>-->
				<option value="2" {if $s_type == 2}selected{/if} >{$lang.users.type_2}</option>
				<option value="3" {if $s_type == 3}selected{/if}>{$lang.users.type_3}</option>
				<option value="4" {if $s_type == 4}selected{/if}>{$lang.users.type_4}</option>
				</select></td>

				<td class="main_content_text" >
{*					<input type="button" class="button_1" value="{$button.search}" onclick="javascript: document.search_form.submit();" name="search_submit">*}
					<a class="admin_button" name="search_submit" onclick="javascript: document.search_form.submit();">{$button.search}<span>&nbsp;</span></a>
				</td>
				</form>
				</tr></table>
				</td>
			</tr></table>
			</td>
		</tr>
		
		<tr>
		<td>
		<form name="user_form" id="user_form" action="" method="POST">
			<table border=0 cellspacing=0 cellpadding=0 width="100%" style="margin-bottom: 0px;">
				
				<tr class="table_header">
					<td class="main_header_text" align="center">{$lang.users.number}</td>
					<!--<td class="main_header_text" align="center">
						<div style="cursor: pointer;" onclick="javascript:location.href='{$file_name}?sorter=1&order={$order}&letter={$letter}&search={$search}&s_type={$s_type}&s_stat={$s_stat}';">{$header.nick}</div>
					</td>-->
					{foreach from=$header_menu_users item=item key=key name=i}
						<td class="main_header_text" align="center">
							<div style="cursor: pointer;" onclick="javascript:location.href='{$file_name}?sel=statistics&type={$type}&sorter={$key}&order={$order}&letter={$letter}&search={$search}&s_type={$s_type}&s_stat={$s_stat}';">{$header[$item]}{if $sorter==$key}{$order_icon}{/if}</div>
						</td>
					{/foreach}
					
					<td class="main_header_text" align="center">
						<div >{$header.details}</div>
					</td>	
				</tr>
				{assign var=page_pr value=$page-1}
				{if $user}
				{section name=u loop=$user}
				<tr {if $smarty.section.u.index mod 2 eq 1}class="table_row even"{else}class="table_row odd"{/if}>
					<td class="main_content_text" align="center"><!--{$user[u].number}-->{$rows_num_page*$page_pr+$smarty.section.u.index+1}</td>
					<!--<td class="main_content_text" align="center">
						{if $user[u].root_user}
							{$user[u].nick}
						{else}
							<a href="{$user[u].edit_link}">{$user[u].nick}</a>
						{/if}
					</td>-->
					<td class="main_content_text" align="center"><a href="{$user[u].view_profile_link}">{$user[u].name}</a></td>
					<td class="main_content_text" align="center">
						{if $user[u].root_user}
							&nbsp;
						{else}
							{$user[u].email}
						{/if}
					</td>
					<input type="hidden" name="id_user[{$user[u].number}]" value="{$user[u].id}">					
					{*<td class="main_content_text" align="center">
					{if !$user[u].root_user}
						{if $user[u].user_type eq 1}{$header.user_type_1}
						{elseif $user[u].user_type eq 2}{$header.user_type_2}
						{elseif $user[u].user_type eq 3}{$header.user_type_3}
						{/if}
					{elseif $user[u].root}
						{$header.admin}
					{elseif $user[u].guest}
						{$header.guest}
					{/if}
					</td>*}	
					<td class="main_content_text" align="center">
						{$user[u].mobile_phone}						
					</td>
					<td class="main_content_text" align="center">
						{$user[u].sms_balance}
					</td>
					<td class="main_content_text" align="center">
						{$user[u].sms_sended}&nbsp;(<a href="{$user[u].detail_link}" style="color:green;text-decoration:none;" title="{$header.without_error}">{$user[u].sms_sended-$user[u].sms_err_ended}</a>,&nbsp;<a href="{$user[u].detail_link}" style="color:red;text-decoration:none;" title="{$header.with_error}">{$user[u].sms_err_ended}</a>)
					</td>
					<td class="main_content_text" align="center">
						{$user[u].last_send_date}
					</td>
					<td class="main_content_text" align="center">
{*						<input type="button" value="{$header.view_detail}" onclick="{literal}javascript: document.location.href='{/literal}{$user[u].detail_link}{literal}';{/literal}">*}
						<div class="block_action fr" style="display: none;float:left;">
							<div class="action_edit" style="display: block;">
								<img width="16" alt="" src="{$site_root}{$template_root}/images/edit.png" onclick="{literal}javascript: document.location.href='{/literal}{$user[u].detail_link}{literal}';{/literal}">
							</div>
						</div>
					</td>					
				</tr>
				{/section}
{*				{else}
				<tr>
					{if $letter != "*" || $search}
						<td colspan="2" align="center"><div>&nbsp;</div><font>{$header.empty_result} {$header.empty_res_search_criteria}</font></td>
					{else}
						<td colspan="2" align="center"><div>&nbsp;</div><font>{$header.empty}</font></td>
					{/if}
				</tr>*}			
				{/if}
			
			{if $links}
					<tr >
						<td height="20"  colspan=9 align="left" >
                            {$links}
						</td>
					</tr>
				{/if}
            </table>    
			</form>
		</td>
		</tr>
		<tr class="table_header"><td></td></tr>
		{else}
		<tr>
		<td>
			<table>
			<tr>
				{if $letter != "*" || $search}
					<td><div>&nbsp;</div><font>{$header.empty_result} {$header.empty_res_search_criteria}</font></td>
				{else}
					<td><div>&nbsp;</div><font>{$header.empty}</font></td>
				{/if}
			</tr>
			</table>
		</td>
		</tr>	
		{/if}
	{elseif $type=='user'}
<!-- end (ALL USERS)-->	
<!-- start (ONE USERS)-->	
		<tr>
			<td width="100%" class="main_content_text">
				<table cellpadding="0" cellspacing="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td width="120">{$header.name}:</td>
						<td><a href='{$user[0].view_profile_link}'>{$user[0].name}</a></td>
					</tr>
					<tr>
						<td>{$header.email}:</td>
						<td>{$user[0].email}</td>
					</tr>
					<tr>
						<td>{$header.mobile_phone}:</td>
						<td><span id="mobile_phone">{$user[0].phone}</span>&nbsp;&nbsp;
						<a style='display:inline' id='edit_phone' onclick="EditPhone('edit_phone','save_phone','mobile_phone','mobile_phone_input');">{$lang.buttons.edit}</a>
						<a style='display:none' id='save_phone' onclick="if (CheckPhone('mobile_phone', 'mobile_phone_input')) SavePhone(document.getElementById('mobile_phone_input').value, '{$user[0].id}', 'mobile_phone', 'edit_phone','save_phone');">{$lang.buttons.save}</a></td>
					</tr>
					<tr>
						<td>{$header.sms_balance_hd}:</td>
						<td>{$user[0].sms_balance}&nbsp;SMS</td>
					</tr>
					<tr>
						<td>{$header.sms_notifications}:</td>
						<td style="padding-left:0px;">
							<table cellpadding="4" cellspacing="0" border="0">
							{foreach from=$sms_cases item=item key=key}							
							{assign var=lang_str value=about_$item}
							<tr>
								<td style="padding:0px;">					
								<input type="checkbox" id="sms_price_{$key}" name="sms_price[{$key}]" {if $user[0].subscribe[$key]}checked{/if} disabled>
								</td>
								<td style="padding:1px;padding-left:0px;">
								{$header[$lang_str]}
								</td>
							</tr>								
							{/foreach}
							<tr>
							<td colspan="2">
								<a style='display:inline' id='edit_event' onclick="EditEvent('edit_event','save_event');">{$lang.buttons.edit}</a>
								<a style='display:none' id='save_event' onclick="SaveEvent('{$user[0].id}', 'edit_event','save_event');">{$lang.buttons.save}</a></td>
							</td>	
							</tr>
							</table>
						</td>
					</tr>						
					<tr>
						<td>{$header.sms_sended}:</td>
						<td>{$user[0].total_sended}&nbsp;SMS</td>
					</tr>
					<tr>
						<td>{$header.success_sms_sended}:</td>
						<td>{$user[0].total_sended-$user[0].error_sended}&nbsp;SMS</td>
					</tr>	
					<tr>
						<td>{$header.last_send_date}:</td>
						<td>{$user[0].last_send_date}</td>
					</tr>				
				</table>
			</td>			
		</tr>
		<tr class="table_header"><td></td></tr>		
		
	{/if}
<!-- end (ONE USERS)-->	
	{if $messages}
		
		<tr>
		<td style="padding-top:10px;">			
		<form name="message_form" id="message_form" action="" method="POST">
			<table border=0 cellspacing=0 cellpadding=0 width="100%" style="margin-bottom: 0px;">
				
				<tr class="table_header">
					<td class="main_header_text" align="center">{$lang.default_select.number}</td>
					{foreach from=$header_menu item=item key=key}
						<td class="main_header_text" align="center">
							<div style="cursor: pointer;" onclick="javascript:location.href='{$file_name}?sel=statistics&type={$type}&id_user={$id_user}&sorter={$key}&order={$order}&redirect=1&pageR={$pageR}&sorterR={$sorterR}&orderR={$orderR}';">{$header[$item]}{if $sorter==$key}{$order_icon}{/if}</div>
						</td>
					{/foreach}				
					
					<td class="main_header_text" align="center">
						<div >{$header.status}</div>
					</td>	
				</tr>
				{assign var=page_pr value=$page-1}
				{if $messages}
				{section name=u loop=$messages}
				<tr {if $smarty.section.u.index mod 2 eq 1}class="table_row even"{else}class="table_row odd"{/if}>
					<td class="main_content_text" align="center"><!--{$user[u].number}-->{$rows_num_page*$page_pr+$smarty.section.u.index+1}</td>
					{if !$id_user}
					<td class="main_content_text" align="center" width="10%"><a href="{$messages[u].view_profile_link}">{$messages[u].name}</a></td>
					{/if}
					<td class="main_content_text" align="center" width="40%">
						{$messages[u].sms_text}
					</td>
					<td class="main_content_text" align="center">
						{$messages[u].from_sa}
					</td>	
					<td class="main_content_text" align="center">
						{$messages[u].delay}						
					</td>
					<td class="main_content_text" align="center">
						{if $messages[u].use_flash}{$header.use}{else}{$header.not_use}{/if}
					</td>
					<td class="main_content_text" align="center">
						{$messages[u].date_send}
					</td>
					<td class="main_content_text" align="center">
						{if $messages[u].error_msg}<font color="red">{$messages[u].error_msg}</font>{else}<span id='status_{$messages[u].id}'></span>{/if}
					</td>
					<td class="main_content_text" align="center">
						{if !$messages[u].error_msg}
						{*<input type="button" value="{$header.check}" onclick="CheckStatus('{$messages[u].api_msg_id}', 'status_{$messages[u].id}');">*}
						<a class="admin_button_major" onclick="CheckStatus('{$messages[u].api_msg_id}', 'status_{$messages[u].id}');">{$header.check}<span>&nbsp;</span></a>
						{/if}
					</td>					
				</tr>
				{/section}
				{/if}
            {if $links}
                    <tr >
                        <td height="20"  colspan=9 align="left" >
                            {$links}
                        </td>
                    </tr>
                {/if}
			</table>
			</form>
		</td>
		</tr>
		<tr class="table_header"><td></td></tr>
	{elseif $id_user || $type=='all'}
		<tr>
			<td style="padding-bottom:3px;">
				<div>&nbsp;</div><font>{$header.no_messages}</font>
			</td>
		</tr>
	{/if}
		{if $id_user}
		<tr><td>&nbsp;</td></tr>
		<tr>
			<td style="padding-top:10px;">
				{*<input type="button" class="button_3" value="{$button.back}" onclick="document.location.href='{$back_link}';">*}
				<a class="admin_button_major" onclick="document.location.href='{$back_link}';">{$button.back}<span>&nbsp;</span></a>
			</td>
		</tr>
		{/if}
</table>
</div>
</div>
</div>

			</div>
			</div>
{literal}
<script>
var tab_id_last = 'user';
function EditPhone(edit_link, save_link, span_id, input_id){
	document.getElementById(edit_link).style.display = 'none';
	document.getElementById(save_link).style.display = 'inline';
	document.getElementById(span_id).innerHTML = "<input type='text' id='"+input_id+"' value='"+document.getElementById(span_id).innerHTML+"'>";
}

function EditEvent(edit_link, save_link){
	document.getElementById(edit_link).style.display = 'none';
	document.getElementById(save_link).style.display = 'inline';
	{/literal}	{foreach from=$sms_cases item=item key=key}	{literal}	
	document.getElementById('sms_price_{/literal}{$key}{literal}').disabled = false;					
	{/literal}  {/foreach}  {literal}
}

function CheckPhone(span_id, input_id){
	if (document.getElementById(input_id).value.search(/^[0-9]{10,14}$/) == -1){
		document.getElementById(span_id).innerHTML = "<input type='text' id='"+input_id+"' value='"+document.getElementById(input_id).value+"'>" + "&nbsp;&nbsp;<font color='red'>{/literal}{$header.incorrect_phone}{literal}</font>";
		return false;
	}
	return true;
}

function SavePhone(mobile_phone, user_id, span_id, edit_link, save_link){
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {								
				document.getElementById(span_id).innerHTML = req.responseText;
				document.getElementById(edit_link).style.display = 'inline';
				document.getElementById(save_link).style.display = 'none';
									
			} else {
				document.getElementById(span_id).innerHTML = "Check data...";
			}
		}
		
		$get_url = "admin_sms_notifications.php?sel=edit_phone&user_id="+user_id+"&mobile_phone="+mobile_phone;
		req.open("GET", $get_url, true);
		req.send(null);
	} else {
		document.getElementById(span_id).innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function SaveEvent(user_id, edit_link, save_link){
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {												
				{/literal}	{foreach from=$sms_cases item=item key=key}	{literal}	
					document.getElementById('sms_price_{/literal}{$key}{literal}').disabled = true;					
				{/literal}  {/foreach}  {literal}
				document.getElementById(edit_link).style.display = 'inline';
				document.getElementById(save_link).style.display = 'none';
									
			} else {
				
			}
		}
		$get_url = "admin_sms_notifications.php?sel=edit_event&user_id="+user_id;
		{/literal}	{foreach from=$sms_cases item=item key=key}	{literal}	
		$get_url = $get_url + "&event_{/literal}{$key}{literal}=";
		if (document.getElementById('sms_price_{/literal}{$key}{literal}').checked){
			$get_url = $get_url + "1";
		}else{
			$get_url = $get_url + "0";
		}
		{/literal}  {/foreach}  {literal}
		
		req.open("GET", $get_url, true);
		req.send(null);
	} else {
		
	}
}

function CheckStatus(api_msg_id, span_id){
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {								
				document.getElementById(span_id).innerHTML = req.responseText;									
			} else {
				document.getElementById(span_id).innerHTML = "Check status...";
			}
		}
		
		$get_url = "admin_sms_notifications.php?sel=check_status&api_msg_id="+api_msg_id;
		req.open("GET", $get_url, true);
		req.send(null);
	} else {
		document.getElementById(span_id).innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function UsersList(par) {
	if ($('#tab_'+par+'_stat').find('a').text() == '') return;
	
	$('#tab_'+tab_id_last+'_stat').html("<a>"+$('#tab_'+tab_id_last+'_stat').text()+"<\/a>");
	$('#tab_'+par+'_stat').text($('#tab_'+par+'_stat').text());

	$('#tab_'+tab_id_last+'_stat').removeClass('user_status_elem_active');
	$('#tab_'+tab_id_last+'_stat').addClass('user_status_elem');
	$('#tab_'+par+'_stat').removeClass('user_status_elem');
	$('#tab_'+par+'_stat').addClass('user_status_elem_active');
	
	ajaxLoadingImage(1, 'users_table_div');
	$.post("admin_sms_notifications.php?sel=statistics", {type:par,ajax:'1'}, function(data){
		ajaxLoadingImage(0, 'users_table_div');
		$('#users_table_div').html(data);
	});
	tab_id_last = par;
}
function PageList(id_div, par) {
	ajaxLoadingImage(1, 'users_table_div');
	$.post("admin_sms_notifications.php?sel=statistics", par, function(data){
		ajaxLoadingImage(0, 'users_table_div');
		$('#users_table_div').html(data);
	});
}
</script>
{/literal}
{if $ajax eq 0}
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}
