<style>
.form-control {  width: 500px;}
#shoptext {  width: 500px;}
#shoptext1 {width: 100%;}
.changeColor {display: inline-block;border: 1px solid #ccc;padding: 7px;margin-top: 10px;border-radius: 6px;}
#shopprice {width: 100%;}

.price-title {width: 100%;margin: 0px auto;border-bottom: 1px solid #E5E5E5;padding: 10px; background-color: #F4FBFE;
}

.modal-footer {
	text-align: left;
    padding: 14px 15px 15px;
    margin-bottom: 0;
    margin-left: 42%;
    background-color: #fff; 
    border-top: 0px solid #ddd;
    border-radius: 0 0 6px 6px;
    box-shadow: inset 0 1px 0 #fff;
}

.wzkpz-xgkp-box{width: 680px;}
.xgkp-changeinfo{margin: 10px 0px;}
.regiswidth div.form-group .help-block {
  position: absolute;
  right: 23px;
  top: 0px;
}

.regiswidth div.form-group .form-control-feedback {
  top: -3px !important;
  right: -8px;
}
</style>

<nav class="breadcrumb"> 五折卡模块 <span class="c-gray en">&gt;</span> 五折卡配置 <span class="c-gray en">&gt;</span>修改信息</nav>
<div class="col-md-10" role="main" id="bnb">


    <div class="wzkpz-xgkp-box">  
		<div class="title-box" style="border:0px!important;margin-top:20px;">
			<p class="t-p" style="font-size: 22px;float:left;width:120px;">修改卡片</p>
                <button type="button" class="sjxg_fh" data-dismiss="modal" style="margin-top:6px!important;  margin-right: 30px;">返回</button>		
		</div>
		<div class="bs-example">
			<form action="<?php echo site_url('admin/card/store/')?>" method="post" class="registerForm regiswidth">
			<input type="hidden" name="id" value="<?php echo $id;?>">
                <div class="form-group">
                    
                    <div class="xgkp-changeinfo">
                        <span class="changeInfo-span">客户端名称：</span>
                        <input type="text" name="client_name" class="form-control" maxlength="8" id="client_name" value="<?php echo $client_name;?>">
                        <p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"><strong> 提示</strong>: 例如:mocuz官方论坛。</small></p>
											
                    </div>
                </div>            
				<div class="form-group">
					
					<div class="xgkp-changeinfo">
                        <span class="changeInfo-span">*卡片名称：</span>
						<input type="text" name="card_name" class="form-control" maxlength="5" id="nameFocus" value="<?php echo $name;?>">
		            	<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong> 提示</strong>: 请输入不超过5个汉字含符号。</small></p>
		        	</div>
		        </div>	
				
				<div class="xgkp-changeinfo">
                    <span class="changeInfo-span">*卡片颜色：</span>
					<input type="hidden" value="<?php echo $color?>" name="color">
					<ul class="changeInfo-ul">
						<li class="changeColor colorOn">
							<p class="redCard colorPosition"></p>
							<span class="colorName">红色</span>
						</li>
						<li class="changeColor">
							<p class="roseCard colorPosition"></p>
							<span class="colorName">瑰红</span>
						</li>
						<li class="changeColor">
							<p class="purpleCard colorPosition"></p>
							<span class="colorName">紫色</span>						
						</li>
						<li class="changeColor">
							<p class="grassCard colorPosition"></p>
							<span class="colorName">草绿</span>						
						</li>
						<li class="changeColor">
							<p class="greenCard colorPosition"></p>
							<span class="colorName">绿色</span>						
						</li>
						<li class="changeColor">
							<p class="darkpurpleCard colorPosition"></p>
							<span class="colorName">深紫</span>							
						</li>
						<li class="changeColor">
							<p class="orangeredCard colorPosition"></p>
							<span class="colorName ">橙红</span>							
						</li>
						<li class="changeColor">
							<p class="orangeCard colorPosition"></p>
							<span class="colorName">橙色</span>							
						</li>
						<li class="changeColor">
							<p class="blueCard colorPosition"></p>
							<span class="colorName">蓝色</span>							
						</li>
						<li class="changeColor">
							<p class="coffeeCard colorPosition"></p>
							<span class="colorName">咖啡</span>							
						</li>
						<li class="changeColor">
							<p class="blackCard colorPosition"></p>
							<span class="colorName">黑色</span>							
						</li>
						<li class="changeColor">
							<p class="bluegreyCard colorPosition"></p>
							<span class="colorName">蓝灰</span>							
						</li>												
					</ul>
	            	<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong>提示</strong>: 请选择卡片颜色。</small></p>
	        	</div>	        	
				<div class="form-group">
		        	
		            <div class="xgkp-changeinfo">
                        <span class="changeInfo-span">*卡片简介：</span>
		            	<textarea name="card_des" id="shoptext" class="form-control" cols="30" rows="3" maxlength="120"><?php echo $card_des;?></textarea>
		            	<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
		            </div>
		        </div> 
		        <div class="form-group">  
		        	
		            <div class="xgkp-changeinfo">
                        <span class="changeInfo-span">*普通权益介绍：</span>
		            	<textarea name="level1_des" id="shoptext" class="form-control" cols="30" rows="3" maxlength="120"><?php echo $level1_des;?></textarea>
		            	<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
		            </div>
		        </div> 
		        <div class="form-group">    
		        	
		            <div class="xgkp-changeinfo">
                        <span class="changeInfo-span">*高级权益介绍：</span>
		            	<textarea name="level2_des" id="shoptext" class="form-control" cols="30" rows="3" maxlength="120"><?php echo $level2_des;?></textarea>
		            	<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
		            </div>
		        </div>    	            	            
	        	
	            <div class="xgkp-changeinfo" id="#shopprice">
                    <span class="changeInfo-span">*高级权益价格：</span>
					<div class="price-box">
						<div class="price-title">
							<span class="cardLong">时长</span>
							<span class="cardPrice">价格</span>
						</div>
						<ul class="price-ul">
						<?php foreach($price_default as $row) { ?>
							<li>
								<div class="form-group" id="shoptext1">
									<input name="price_box[]" <?php if($row_new = check_in_price($row['duration'],$now_price)){ $row = $row_new; ?>checked="checked"<?php } ?> value="<?php echo $row['duration']?>" type="checkbox" class="ul-left">
									<span class="ul-mid"><?php echo $row['duration']?>天</span>
									<input type="text" maxlength="5" name="price[<?php echo $row['duration']?>]" class="form-control ul-right" value="<?php echo $row['price']?>">
								</div>
							</li>
						<?php } ?>
							
						</ul>
					</div>
				<div class="error"></div>
        		<p style="padding-left: 120px;"><small><img src="<?php echo asset_url('images/tips.png')?>" alt="" style="width: 18px;vertical-align: text-bottom;"> <strong>提示</strong>: 请勾选可供购买的高级权益时长，并填写价格。</small></p>	            	
	            </div>		        				
	           
	            <div class="xgkp-changeinfo" >	
                 <span class="changeInfo-span">*详细规则：</span>  	
	            	<textarea name="message" class="form-control" style="height:180px"><?php echo $message?></textarea>
	            	<p class="noteErroe">详细规则不能是空的</p>
	
	            </div>
                 <button class="edit_btn " type="submit" id="save" style="margin-right: 30px;">保存修改</button>	           	         
            </form>    
        </div>
         </div>
	</div>

     <script>
    $(function(){

        $('.ul-left').click(function(){

            if($(this).is(':checked')){
                var ckb= $(this).next().next();
                ckb.removeAttr("disabled");
            }else{
                var ckb= $(this).next().next();
                ckb.attr("disabled","disabled");
            }
        }); 

        $('.changeColor').click(function(){

            console.log('dd');
            $(this).addClass('colorOn');
            $(this).siblings().removeClass('colorOn');
            var color = $(this).find('.colorPosition').css('background-color');
            $("input[name='color']").val(rgb2hex(color));
        });
    });
    </script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        $("button[type=button]").on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            location.href="javascript:history.go(-1)";
        });
    });
function zero_fill_hex(num, digits) {
  var s = num.toString(16);
  while (s.length < digits)
    s = "0" + s;
  return s;
}

function rgb2hex(rgb) {

  if (rgb.charAt(0) == '#')
    return rgb;
 
  var ds = rgb.split(/\D+/);
  var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]);
  return "#" + zero_fill_hex(decimal, 6);
}
$(function(){
	/*编辑器*/



	$('.changeColor').each(function(){
		var color = $(this).find('.colorPosition').css('background-color');
		color = rgb2hex(color)
		if( color == '<?php echo $color?>'){
			$(this).addClass('colorOn');
			$(this).siblings().removeClass('colorOn');
		}
	})






	$('.registerForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh',
            excluded : ':disabled'
        },
        submitHandler: function(validator, form, submitButton) {
		    return false;
		},
        fields: {
        	card_name: {
                message: '卡片名称无效',
                validators: {
                    notEmpty: {
                        message: '卡片名不能是空的'
                    },
                    stringLength: {
                        max: 5,
                        message: '卡片名不能大于5个字符'
                    }
                }
            },
            level1_des: {
                message: '普通权益无效',
                validators: {
                    notEmpty: {
                        message: '普通权益不能是空的'
                    },
                    stringLength: {
                        max: 120,
                        message: '普通权益不能大于120个字符'
                    }
                }
            },
            level2_des: {
                message: '高级权益无效',
                validators: {
                    notEmpty: {
                        message: '高级权益不能是空的'
                    },
                    stringLength: {
                        max: 120,
                        message: '高级权益不能大于120个字符'
                    }
                }
            },
            card_des: {
                message: '卡片描述无效',
                validators: {
                    notEmpty: {
                        message: '卡片描述不能是空的'
                    },
                    stringLength: {
                        max: 120,
                        message: '卡片描述不能大于120个字符'
                    }
                }
            },
            color: {
                message: '颜色无效',
                validators: {
                    hexColor: {
                        message: '颜色无效'
                    }
                }
            },
            'price_box[]' : {
                validators: {
                    notEmpty: {
                        message: '至少选择一个',
                    },
                },
                group: '.error',
                container: '.error',
            },
            'price[7]' : {
                validators: {
                	notEmpty: {
                        message: '价格不能为空'
                    },
                    numeric: {
                        message: '请填写正确的金额'
                    }
                }
            },
            'price[30]' : {
                validators: {
                	notEmpty: {
                        message: '价格不能为空'
                    },
                    numeric: {
                        message: '请填写正确的金额'
                    }
                }
            },
            'price[90]' : {
                validators: {
                	notEmpty: {
                        message: '价格不能为空'
                    },
                    numeric: {
                        message: '请填写正确的金额'
                    }
                }
            },
            'price[180]' : {
                validators: {
                	notEmpty: {
                        message: '价格不能为空'
                    },
                    numeric: {
                        message: '请填写正确的金额'
                    }
                }
            },
            'price[365]' : {
                validators: {
                	notEmpty: {
                        message: '价格不能为空'
                    },
                    numeric: {
                        message: '请填写正确的金额'
                    }
                }
            },
         
        }
    })
    .on('success.form.bv',function(e){
        event.preventDefault();
        /* Act on the event */
        var replace = '';
        var form = this;
        $('textarea').each(function() {
            replace = $(this).val();

            replace=replace.replace(/\n/g,'<br/>');
            $(this).val(replace);
            
        });
        form.submit();
    });
    
});
</script>



<?php
function check_in_price($duration, $price){
	foreach($price as $row){
		if($duration == $row['duration']){
			return $row;
		}
	}
	return false;
}

?>