<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript" language="javascript">
<!--
function changeFont() {
	$('#param_service_').html('');
}
function on_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminqqlst_stat");
    if (o_result.result == "ERROR") {
        document.forms["contactusform"].reset();
        
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
	    stat.innerHTML = "<?php _e('OK, redirecting...'); ?>";
	    reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_failure(response) {
    document.forms["contactusform"].reset();
    
    document.getElementById("adminqqlst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}
function on_del_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminqqlst_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
	    stat.innerHTML = "<?php _e('OK, refreshing...'); ?>";
	    reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_del_failure(response) {
    document.getElementById("adminqqlst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function delete_qq(q_id) {
	if (confirm("Delete the selected IM account?")) {
	    var stat = document.getElementById("adminqqlst_stat");
	    stat.style.display = "block";
	    stat.innerHTML = "<?php _e('Deleting selected IM account...'); ?>";
		_ajax_request("mod_qq", 
			"admin_delete", 
	        {
	            q_id:q_id
	        }, 
			on_del_success, 
			on_del_failure);
	}
}
function delete_qqs(){
	var arr = document.getElementsByName("qq");
	var str="";
	for (var i = 0; i < arr.length; i++){
		var e = arr[i];
		if (e.checked){
			str = e.value + "_" + str;
		}
	}
	if(str.length < 1) {
		alert("<?php _e('Please select items to be deleted!'); ?>");
	} else {
		delete_qq(str);
	}
}
function ck_select(){
	try{
		var el=document.getElementById('ckselect');
		var arr = document.getElementsByName("qq");
		if(el.checked){
			for(i=0;i<arr.length;i++){arr[i].checked=true;}
		}else{
			for(i=0;i<arr.length;i++){arr[i].checked=false;}
		}
	}catch(e){
		return false;
	}
}
//-->
</script>
<ul style="margin-left:1px;">
	<li><a class="icontj" href="index.php?<?php echo Html::xuriquery('mod_qq', 'admin_add'); ?>" title=""><?php _e('Add IM account'); ?></a></li>
	<li><a class="iconsc" href="javascript:void(0)" onclick="delete_qqs();"><?php _e('Delete Selected'); ?></a></li>
</ul>
<div class="status_bar">
	<span id="adminqqlst_stat" class="status" style="display:none;"></span>
</div>

<?php
$sinfo_form = new Form('index.php', 'contactusform', 'check_sinfo_info');
$sinfo_form->p_open('mod_static', $next_action, '_ajax');
?>
<table id="sinfoform_table" class="form_table" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
    <tfoot>
        <tr>
        	<td></td>
            <td>
            <?php
            echo Html::input('submit', 'submit', __('Save'));
            ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
		<tr>
            <td class="label" width="13%"><?php _e('service'); ?></td>
            <td class="entry">
            <?php
            if(!empty($service)) {
            	echo Html::textarea('param[service]', $service, 'rows="8" cols="108"');
            }else {
            	echo Html::textarea('param[service]', '请输入53客服系统代码...', 'rows="8" cols="108" onclick="changeFont();"');
            }
            ?>
            </td>
        </tr>
		<tr>
        	<td class="label" ><?php _e('Memo'); ?></td>
        	<td><?php _e('53kf_remark');?></td>
        </tr>
		<tr>
        	<td class="label" rowspan="4"><?php _e('service Provider'); ?></td>
        	<td><a href="http://www.53kf.com" target="_blank">http://www.53kf.com</a></td>
        </tr>
        
    </tbody>
</table>
<?php
$sinfo_form->close();
$running_msg = __('Saving content...');
$custom_js = <<<JS
$("#adminqqlst_stat").css({"display":"block"});
$("#adminqqlst_stat").html("$running_msg");
_ajax_submit(thisForm, on_success, on_failure);
return false;

JS;
$sinfo_form->addCustValidationJs($custom_js);
$sinfo_form->writeValidateJs();
?>
<div style="height:28px;line-height:28px;font-weight:bold;font-size:larger;padding-left:20px;background:#f6f6f4;"><?php _e('Instant Message');?></div>
<table class="list_table" id="admin_qq_list" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
	<thead>
		<tr>
		    <td width="13%"><?php echo Html::input('checkbox', 'ckselect','','onclick=ck_select()'); ?></td>
            <td><?php _e('Account'); ?></td>
            <td width="23%"><?php _e('Preview'); ?></td>
            <td width="13%"><?php _e('Publish'); ?></td>
            <td width="13%"><?php _e('Edit'); ?></td>
            <td width="13%"><?php _e('Delete'); ?></td>
        </tr>
    </thead>
    <tbody>
    <?php
    if (sizeof($qqs) > 0) {
        $row_idx = 0;
        foreach ($qqs as $qq) {
    ?>
        <tr class="row_style_<?php echo $row_idx; ?>">
        	<td><?php echo Html::input('checkbox', 'qq', $qq->id); ?></td>
        	<td><?php echo $qq->account; ?></td>
        	<td>
			<?php
				if($qq->category == 1){
			?>
			<A href="msnim:chat?contact=<?php echo $qq->account; ?>"><img src="<?php echo P_TPL_WEB?>/images/MSN.jpg" alt="MSN"><?php _e('Contact Me'); ?></a>
			<?php }else if($qq->category == 2){?>
				<A href="http://amos.im.alisoft.com/msg.aw?v=2&amp;uid=<?php echo $qq->account; ?>&amp;site=cntaobao&amp;s=1&amp;charset=utf-8" target=_blank><IMG alt="" src="http://amos.im.alisoft.com/online.aw?v=2&amp;uid=<?php echo $qq->account; ?>&amp;site=cntaobao&amp;s=1&amp;charset=utf-8" border=0></A>
			<?php }else{?>
				<IMG src="http://wpa.qq.com/pa?p=4:<?php echo $qq->account; ?>:4" align=absMiddle border=0><A href="tencent://message/?uin=<?php echo $qq->account; ?>&amp;Site=http://www.cndns.com/svcmsg/sales_svc.asp&amp;Menu=yes" target=blank><?php echo $qq->account; ?></A>
			<?php } ?>
			
			</td>
        	<td><?php echo Toolkit::validateYesOrNo($qq->published,$qq->id,"index.php?_m=mod_qq&_a=admin_pic&_r=ajax&_id=".$qq->id);?></td>
        	<td>
        		<a href="index.php?<?php echo Html::xuriquery('mod_qq', 'admin_edit', array('q_id' => $qq->id)); ?>" title="<?php _e('Edit'); ?>"><img style="border:none;" alt="<?php _e('Edit');?>" src="<?php echo P_TPL_WEB; ?>/images/edit.gif"/></a>
        	</td>
        	<td>
        		<a href="#" onclick="delete_qq(<?php echo $qq->id; ?>);return false;" title="<?php _e('Delete'); ?>"><img style="border:none;" alt="<?php _e('Delete');?>" src="<?php echo P_TPL_WEB; ?>/images/cross.gif"/></a>
        	</td>
        </tr>
    <?php
            $row_idx = 1 - $row_idx;
        }
    } else {
    ?>
    	<tr class="row_style_0">
    		<td colspan="5"><?php _e('No Records!'); ?></td>
    	</tr>
    <?php
    }
    ?>
    </tbody>
</table>
