<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<link rel="stylesheet" href="../script/jquery.cluetip.css" type="text/css" />
<style type="text/css">
.entry {width:85%;}
</style>
<script type="text/javascript" src="../script/jquery.cluetip.min.js"></script>
<script type="text/javascript" src="../script/getcolor.js"></script>
<script type="text/javascript" language="javascript">
<!--
var tag = width = height = 0;
var title = "<?php _e('Ad Theme');?>";
$(document).ready(function(){
	var img = '';
	var type = tag = "<?php echo ADVERT_STATUS;?>";
	$('tbody tr:gt(5)').hide();
	if( parseInt(type) == 0 ) {
		$('tbody tr:first').nextAll().hide();
	} else {
		if( type == '1' ) {
			width = 300;
			height = 200;
		} else if( type == '2' ) {
			width = 100;
			height = 100;
		} else if( type == '3' ) {
			width = 100;
			height = 300;
			$('tbody tr:gt(5)').show();
		}
	}
	
	$('input[name="sparam[ADVERT_STATUS]"]').click(function(){
		if( $(this).val() == 0 ) {
			$('tbody tr:first').nextAll().hide();
		} else {
			tag = $(this).val();
			$('tbody tr:lt(6)').show();
			if( tag == '1' ) {
				img = 't1.jpg';
				width = 300;
				height = 200;
				$('tbody tr:gt(5)').hide();
			} else if( tag == '2' ) {
				img = 'f1.jpg';
				width = 100;
				height = 100;
				$('tbody tr:gt(5)').hide();
			} else if( tag == '3' ) {
				img = 'd1.jpg';
				width = 100;
				height = 300;
				$('tbody tr:gt(5)').show();
			}
			
			// show img
			$('#ad_src img').attr('src', 'adtool/theme/'+img);
			$('input[name="sparam[ADVERT_THEME]"]').val('adtool/theme/'+img);
			if( tag == '3' ) {
				$('#rad_src img').attr('src', 'adtool/theme/'+img);
				$('input[name="sparam[ADVERT_RTHEME]"]').val('adtool/theme/'+img);
			}
		}
	});
	
	// get color
	updatecolorpreview('c1');
	updatecolorpreview('c2');
	
	// help
	$('#answer').cluetip({splitTitle: '|',width: '400px',height:'50px'});
	$('#answer2').cluetip({splitTitle: '|',width: '400px',height:'50px'});
});

function popupwin( pos )
{
	popup_win=show_adpicker( tag, title, pos );
	return false;	
}

function upload_theme( index )
{	var nt = "<?php _e('Recommended Size');?>：";
	var wh = width+"px(<?php _e('Width');?>)×"+height+"px(<?php _e('Height');?>)";
	alert(nt+wh);
	$('#uptheme'+index).css('display', 'block');
}

//  表单验证
function check_adform( obj )
{
	var reg = /^\d+(\.\d+)?$/;
		
	// ad type
	var type = 0;
	var l = obj.elements["sparam[ADVERT_STATUS]"].length;
	for( var k=0; k<l; k++ ) {
		if( obj.elements["sparam[ADVERT_STATUS]"][k].checked ) {
			type = obj.elements["sparam[ADVERT_STATUS]"][k].value;
			break;
		}
	}
	
	// form check
	if( parseInt(type) > 0 ) 
	{
		var tpl = obj.elements["sparam[ADVERT_THEME]"];
		if( trim(tpl.value).length == 0 ) {
			alert("<?php _e('Please choose ad theme');?>");
			return false;
		}
	
		var txt = obj.elements["sparam[ADVERT_TEXT]"];
		if( trim(txt.value).length == 0 ) {
			alert("<?php _e('Please input ad text value');?>");
			txt.focus();
			return false;
		}
		
		var fsize = obj.elements["sparam[ADVERT_TEXT_SIZE]"];
		if( trim(fsize.value).length == 0 ) {
			alert("<?php _e('Please input ad text font-size value');?>");
			fsize.focus();
			return false;
		} else if( !reg.test(fsize.value) ) {
			alert("<?php _e('The ad text font-size value is invalid');?>");
			fsize.select();
			return false;
		}
		
		var url = obj.elements["sparam[ADVERT_URL]"];
		if( trim(url.value).length > 0 ) {
			if( isUri(url.value) == false ) {
				alert("<?php _e('The ad url value is invalid');?>");
				url.select();
				return false;
			}
		}
		
		// 
		if( parseInt(type) == 3 ) {
			var rtpl = obj.elements["sparam[ADVERT_RTHEME]"];
			if( trim(rtpl.value).length == 0 ) {
				alert("<?php _e('Please choose ad theme');?>");
				return false;
			}
		
			var rtxt = obj.elements["sparam[ADVERT_RTEXT]"];
			if( trim(rtxt.value).length == 0 ) {
				alert("<?php _e('Please input ad text value');?>");
				rtxt.focus();
				return false;
			}
			
			var rfsize = obj.elements["sparam[ADVERT_RTEXT_SIZE]"];
			if( trim(rfsize.value).length == 0 ) {
				alert("<?php _e('Please input ad text font-size value');?>");
				rfsize.focus();
				return false;
			} else if( !reg.test(rfsize.value) ) {
				alert("<?php _e('The ad text font-size value is invalid');?>");
				rfsize.select();
				return false;
			}
			
			var rurl = obj.elements["sparam[ADVERT_RURL]"];
			if( trim(rurl.value).length > 0 ) {
				if( isUri(rurl.value) == false ) {
					alert("<?php _e('The ad url value is invalid');?>");
					rurl.select();
					return false;
				}
			}
		}
	}
}

function isUri( url )
{
	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
	+ "?(([0-9a-z_!~*'().&amp;=+$%-]+: )?[0-9a-z_!~*'().&amp;=+$%-]+@)?" //ftp的user@
	+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
	+ "|" // 允许IP和DOMAIN（域名）
	+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
	+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
	+ "[a-z]{2,6})" // first level domain- .com or .museum
	+ "(:[0-9]{1,4})?" // 端口- :80
	+ "((/?)|" // a slash isn't required if there is no file name
	+ "(/[0-9a-z_!~*'().;?:@&amp;=+$,%#-]+)+/?)$";
	var reg = new RegExp(strRegex);

	if( reg.test(url) ){
		return true;
	} else {
		return false;
	}
}   
//-->
</script>
<?php echo Notice::get('mod_advert/msg');?>
<div class="status_bar">
	<span id="adminsinfofrm_stat" class="status" style="display:none;"></span>
</div>
<?php
$ad_form = new Form('index.php', 'adform', 'check_adform');
$ad_form->setEncType('multipart/form-data');
$ad_form->p_open('mod_advert', 'admin_list');
?>
<div style="overflow:auto;width:100%;">
<table class="form_table" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
    <tfoot>
        <tr>
        	<td>&nbsp;&nbsp;</td>
            <td>
            <?php
            echo Html::input('submit', 'send', __('Save'), 'style="width:60px;"');
			echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            echo Html::input('reset', 'reset', __('Reset'), 'style="width:60px;" onclick="if(!confirm(\''.__('Do you want to reset ?').'\')){return false;}"');
            echo Html::input('hidden', 'mode', 'submit');
            ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td class="label"><?php _e('Advert Type'); ?></td>
            <td class="entry">
            <?php
            $check0 = $check1 = $check2 = $check3 = '';
            switch( ADVERT_STATUS ) {
            	case 0:
            		$check0 = 'checked';
            	    break;
            	case 1:
            		$check1 = 'checked';
            	    break;
            	case 2:
            		$check2 = 'checked';
            	    break;
            	case 3:
            		$check3 = 'checked';
            	    break;
            }
            echo Html::input('radio', 'sparam[ADVERT_STATUS]', 0, $check0);
            echo '&nbsp;&nbsp;'.__('Advert feature is not enabled').'<br />';
            echo Html::input('radio', 'sparam[ADVERT_STATUS]', 1, $check1);
            echo '&nbsp;&nbsp;'.__('Pop-up ads').'<br />';
            echo Html::input('radio', 'sparam[ADVERT_STATUS]', 2, $check2);
            echo '&nbsp;&nbsp;'.__('Floating Ads').'<br />';
            echo Html::input('radio', 'sparam[ADVERT_STATUS]', 3, $check3);
            echo '&nbsp;&nbsp;'.__('Couplet Ads');
            
            // ad theme
            $show_ad = '<img src="'.ADVERT_THEME.'" border="0" />';
            $show_rad = '<img src="'.ADVERT_RTHEME.'" border="0" />';
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Advert Themes'); ?></td>
            <td class="entry"><span id="ad_src"><?php echo $show_ad;?></span>
            <?php
            echo Html::input('hidden', 'sparam[ADVERT_THEME]', ADVERT_THEME);
            echo '<a href="#" onclick="popupwin(1)">'.__('Click here to select the ad theme').'</a>&nbsp;&nbsp;&nbsp;&nbsp;';
            // self-defined theme
            echo '&nbsp;&nbsp;&nbsp;&nbsp;<a href="###" onclick="upload_theme(1)">'.__('Self-defined theme').'</a>';
            echo '<div id="uptheme1" style="display:none;">'.Html::input('file', 'uptheme').'</div>';
            ?></td>
        </tr>
        <tr>
            <td class="label"><?php _e('Advert Text'); ?></td>
            <td class="entry">
            <?php
            echo Html::textarea('sparam[ADVERT_TEXT]', ADVERT_TEXT, 'rows="3" cols="50"');
            if(SessionHolder::get('_LOCALE', DEFAULT_LOCALE) != 'en') {
            ?>            
            <img id="answer" class="title" src="<?php echo P_TPL_WEB; ?>/images/answer1.gif" alt="help" title="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您可以通过“;”分隔符实现多广告文本轮播(支持HTML标签)，文本过长将会部分屏蔽！"/>
            <?php }?></td>
        </tr>
        <tr>
        	<td class="label"><?php _e('Advert Text Font Size'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'sparam[ADVERT_TEXT_SIZE]', ADVERT_TEXT_SIZE, 'size="10"');
            ?></td>
        </tr>
       	<tr>
        	<td class="label"><?php _e('Advert Text Color'); ?></td>
            <td class="entry">
            <input type="text" name="sparam[ADVERT_TEXT_COLOR]" value="<?php echo ADVERT_TEXT_COLOR;?>" onchange="updatecolorpreview('c1')" id="c1_v">
            <input type="button" style="background: none repeat scroll 0% 0% rgb(0, 0, 0);height:21px;width:40px;" value="" onclick="c1_frame.location='images/getcolor.htm?c1';showMenu({'ctrlid':'c1'})" id="c1">
            <span id="c1_menu" style="display: none"><iframe name="c1_frame" src="" frameborder="0" width="166" height="186" scrolling="no"></iframe></span>
			</td>
        </tr>
        <tr>
        	<td class="label"><?php _e('Advert Url'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'sparam[ADVERT_URL]', ADVERT_URL, 'size="25"');
            ?></td>
        </tr>
        <!-- 对联式（右侧）-->
        <tr>
            <td class="label"><?php _e('Advert Themes');echo '('.__('right').')'; ?></td>
            <td class="entry"><span id="rad_src"><?php echo $show_rad;?></span>
            <?php
            echo Html::input('hidden', 'sparam[ADVERT_RTHEME]', ADVERT_RTHEME);
            echo '<a href="#" onclick="popupwin(2)">'.__('Click here to select the ad theme').'</a>&nbsp;&nbsp;&nbsp;&nbsp;';
            // self-defined theme
            echo '&nbsp;&nbsp;&nbsp;&nbsp;<a href="###" onclick="upload_theme(2)">'.__('Self-defined theme').'</a>';
            echo '<div id="uptheme2" style="display:none;">'.Html::input('file', 'uprtheme').'</div>';
            ?></td>
        </tr>
        <tr>
            <td class="label"><?php _e('Advert Text');echo '('.__('right').')'; ?></td>
            <td class="entry">
            <?php
            echo Html::textarea('sparam[ADVERT_RTEXT]', ADVERT_RTEXT, 'rows="3" cols="50"');
            if(SessionHolder::get('_LOCALE', DEFAULT_LOCALE) != 'en') {
            ?>            
            <img id="answer2" class="title" src="<?php echo P_TPL_WEB; ?>/images/answer1.gif" alt="help" title="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您可以通过“;”分隔符实现多广告文本轮播(不支持HTML标签)，文本过长将会部分屏蔽！"/>
            <?php }?></td>
        </tr>
        <tr>
        	<td class="label"><?php _e('Advert Text Font Size');echo '('.__('right').')'; ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'sparam[ADVERT_RTEXT_SIZE]', ADVERT_RTEXT_SIZE, 'size="10"');
            ?></td>
        </tr>
       	<tr>
        	<td class="label"><?php _e('Advert Text Color');echo '('.__('right').')'; ?></td>
            <td class="entry">
            <input type="text" name="sparam[ADVERT_RTEXT_COLOR]" value="<?php echo ADVERT_RTEXT_COLOR;?>" onchange="updatecolorpreview('c2')" id="c2_v">
            <input type="button" style="background: none repeat scroll 0% 0% rgb(0, 0, 0);height:21px;width:40px;" value="" onclick="c2_frame.location='images/getcolor.htm?c2';showMenu({'ctrlid':'c2'})" id="c2">
            <span id="c2_menu" style="display: none"><iframe name="c2_frame" src="" frameborder="0" width="166" height="186" scrolling="no"></iframe></span>
			</td>
        </tr>
        <tr>
        	<td class="label"><?php _e('Advert Url');echo '('.__('right').')'; ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'sparam[ADVERT_RURL]', ADVERT_RURL, 'size="25"');
            ?></td>
        </tr>
        <!-- 对联式（右侧）-->
    </tbody>
</table>
</div>
<?php
$ad_form->close();
?>
