<?php 
	require_once('_approot.php');	

	$myck=new cktb();
	
	require_once('generalpicrequire.php');  //generalpic类型选择语句, 表名、图片文件存储目录、字段变量名 存储变量在此定义
	$addalt=$myck->checkfield($generalTable,"matealt","ALTER TABLE  `$generalTable` ADD  `matealt` VARCHAR( 256 ) NULL AFTER  `Num` ,
ADD  `matetitle` VARCHAR( 256 ) NULL AFTER  `matealt`
");
	if(isset($_SESSION['savepgenpic'])) $_POST=$_SESSION['savepgenpic']; //saveproducts 变量
	$id=$_GET['id'];
	$ls=$_GET['ls'];
	$thisPicW=240;
	$thisPicH=240;
	
	$title_sql = "select * from ls_config";
	$title_query = $opendb->query($title_sql);
	$title_value = mysqli_fetch_assoc($title_query);
	
	$pos = strpos($title_value['companyName'], '-' );
	$subCompanyName = substr($title_value['companyName'], (mb_strlen($title_value['companyName'],'utf-8') - $pos) * -1 );

if($ls=="insert")
{
	$genOper="添加";
	$modiGeneralpicsTitle=$_POST['modiGeneralpicsTitle'];
	$modiGeneralpicsText=$_POST['modiGeneralpicsText'];
	$folderPic=($_POST['Pic']==""?"images/picture.gif":"../".$_SESSION['dda'].$folder2."/".$_POST['Pic']);
	$Pic=($_POST['Pic']==""?"":$_POST['Pic']);
	$poster="images/picture.gif";
}else{
	$genOper="修改";
	$generalpics_sql="select * from ".$generalTable." where ID=".$id." ";
	$generalpics_query=$opendb->query($generalpics_sql);
	$generalpics_rows=mysqli_fetch_assoc($generalpics_query);
	$modiGeneralpicsTitle=$generalpics_rows[$generalpicsTitle];
	$modiGeneralpicsText=$generalpics_rows[$generalpicsText];
	$folderPic="../".$_SESSION['dda'].$folder2."/".$generalpics_rows[$generalpicsPic];
	$Pic=$generalpics_rows[$generalpicsPic];
	$foldervdo="../".$folder1."/".$generalpics_rows['productVideo'];
	$poster=$generalpics_rows['productVideo']==""?"": "../".$folder1."/".$generalpics_rows[$generalpicsPic] ;
	
}
	$ls_msg=$genOper.$showstr."";


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
        <script language="JavaScript" src="js/jquery.js"></script>
		<script language="JavaScript" src="js/ls.js"></script>
		<title>addmodigenpics</title>
		<link rel="stylesheet" href="kindeditor-4.1.10/themes/default/default.css" />
	<link rel="stylesheet" href="kindeditor-4.1.10/plugins/code/prettify.css" />
    <link rel="stylesheet" href="css/style2.css" />
	<script charset="utf-8" src="kindeditor-4.1.10/kindeditor.js"></script>
	<script charset="utf-8" src="kindeditor-4.1.10/lang/zh_CN.js"></script>
	<script charset="utf-8" src="kindeditor-4.1.10/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="modiGeneralpicsText"]', {
				cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
				uploadJson : 'kindeditor-4.1.10/php/upload_json.php',
				fileManagerJson : 'kindeditor-4.1.10/php/file_manager_json.php',
				allowFileManager : true,
				afterBlur: function(){
					this.sync();
					},
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						K('form[name=example]')[0].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						K('form[name=example]')[0].submit();
					});
				}
			});
			prettyPrint();
		});
	</script>
	</head>

	<body>
		<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
			<tr>
				<td height="18"style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">修改<?=$showstr?>图片</font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top"><br>
				 <form name="myform" enctype="multipart/form-data" method="post" action="savegeneralpics.php?gen=<?=$gen?>" >
					<input type="hidden" value="<?php echo $ls;?>" name="ls">
					<input type="hidden" value="<?php echo $id;?>" name="id">
					<input type="hidden" value="<?php echo $Pic;?>" name="Pic">
					<input type="hidden" name="ChangecatePagePic" value="no">
					<table border="0" width="98%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right"><img src="images/shao.gif">&nbsp;<a href="generalpics.php?gen=<?=$gen?>">返回</a></td>
						</tr>
					</table>
					<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" style="background-color: #f0f0ee;">
				      <tr>
					      <td style="padding-left:50px;">&nbsp;</td>
					      <td   style="padding-left:10px;">&nbsp;</td>
				        <td width="51%" valign="bottom"   style="padding-left:10px;">&nbsp;</td>
				      </tr>
				      <tr>
					    <td style="padding-left:50px;">名称(标题)  *</td>
					    <td   style="padding-left:10px;"><input name="modiGeneralpicsTitle" id="workshopTitle" type="text"  style="width:290px;" value="<?php echo $modiGeneralpicsTitle;?>" onblur="document.myform.matealt.value=this.value;if($('#newsTitle').val().length == 0){$('#newsTitle').val(this.value+'<?php "-". $title_value['companyName'] ?>');}" /></td>
					    <td width="51%" rowspan="2"   style="padding-left:10px;"><table border="0" width="98%" align="center" cellpadding="3" cellspacing="1">
					      <tr>
					        <td width="120"  align="right" >标题 Title *</td>
					        <td  valign="middle" ><textarea name="newsTitle" id="newsTitle" style="width:80%"  rows="3"><?php echo $_POST['newsTitle']!=""?$_POST['newsTitle']:$generalpics_rows['newsTitle'];?></textarea></td>
				          </tr>
					      <tr>
					        <td align="right" >关键字 Keywords</td>
					        <td ><textarea name="newsKeywords" id="newsKeywords"   rows="3" style="width:80%" ><?php echo $_POST['newsKeywords']!=""?$_POST['newsKeywords']:$generalpics_rows['newsKeywords'];?></textarea></td>
				          </tr>
					      <tr>
					        <td align="right">描述 Description *<br /></td>
					        <td ><textarea name="newsDescription" style="width:80%"  rows="5" id="newsDescription"><?php echo $_POST['newsDescription']!=""?$_POST['newsDescription']: $generalpics_rows['newsDescription'];?></textarea>
					          </br>
					         <div style="width:86%"> <?=$promlv>1?$seo:""?></div>
					          </br>
					          </br></td>
				          </tr>
					      <tr>
					        <td align="right">&nbsp;</td>
					        <td align="center" ><button type="submit" value="保存" onclick="
                        if($('#newsText').val().length &gt;= 0){
                        	$('#newsDescription').val($('#modiGeneralpicsText').val().substr(0, 86).replace(/&lt;[^&gt;]+&gt;/g,'').replace(/	/g, '').replace(/\n/g, ''));
                        }" />保存</button>
					          
					          </button>
					          <button name="重置" type="reset"  value="重置"  onclick="document.pic.src='<?php echo $folderPic?>';myform.ChangecatePagePic.value='no';" />重置</button>
					          
					          </button>
					          <button type="button" name="button" id="button" value="SEO"  onclick="
                            if(confirm('您确定要修改SEO设置吗？')){
                            $('#newsTitle').val($('#workshopTitle').val()+'<?php if(strpos($title_value['companyName'],"-")){echo " ".$subCompanyName;}else{echo " - ".$title_value['companyName'];}?>');
$('#newsKeywords').val('<?=$title_value['siteKeywords']?>');
$('#newsDescription').val($('#modiGeneralpicsText').val().substr(0, 86).replace(/&lt;[^&gt;]+&gt;/g,'').replace(/	/g, '').replace(/\n/g, ''));
	}else{
		return false;
	}"/>SEO</button>
					          
					          </button></td>
				          </tr>
					      <tr>
					        <td colspan="2" align="center"></td>
				          </tr>
				        </table></td>
				      </tr>
					  <tr>
					    <td rowspan="2" style="padding-left:50px;" > 图片*					      </td>
					    <td width="22%" height="" style="padding-left:10px;" ><div id="preview"><img src="<?php echo $_SESSION['dda'].$folderPic."?i=".rand();?>" width="<?php echo $SmallPicW ?>"   border="1" name="pic" style="float:left;" /></div>
					      <br />
<script type="text/javascript">
function preview(file)
{
var prevDiv = document.getElementById('preview');
if (file.files && file.files[0])
{
var reader = new FileReader();
reader.onload = function(evt){
prevDiv.innerHTML = '<img src="' + evt.target.result + '" width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" name="pic" style="float:left;" />';
}  
reader.readAsDataURL(file.files[0]);
}
else  
{
prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
}
}
//图片类型验证 ".jpg", 
function pictype(file)
{
   var fileTypes = [<?=$imagetypes2?>];
    var filePath = file.value;
    //当括号里面的值为0、空字符、false 、null 、undefined的时候就至关于false
    if(filePath){
        var isNext = false;
        var fileEnd = filePath.substring(filePath.indexOf("."));
        for (var i = 0; i < fileTypes.length; i++) {
            if (fileTypes[i] == fileEnd) {
                isNext = true;
                break;
            }
        }
        if (!isNext){
            alert('<?=$imagealert?>');
            file.value = "";
            return false;
        }
    }else {
        return false;
    }
}

//图片大小验证
function picsize(file) {
    var fileSize = 0;
    var fileMaxSize =<?=$PicSize/1000?>;// 1M
    var filePath = file.value;
    if(filePath){
        fileSize =file.files[0].size;
        var size = fileSize / 1024;
        if (size > fileMaxSize) {
            alert("<?=$imagealertsize?>");
            file.value = "";
            return false;
        }else if (size <= 0) {
            alert("图片大小不能为0！");
            file.value = "";
            return false;
        }
    }else{
        return false;
    }
}
</script>
					      <br />
					      <div style="padding-left:140px;"></div></td>
				      </tr>
					  <tr>
					    <td height="78" colspan="2" style="padding-left:10px;" ><p><span style="padding-left:10px;">
					      <?=$nmpic_tips?>
					    </span></p>
					      <p>					      
					        <input type="file" name="productPic" style="width:160px;" onchange="pictype(this);picsize(this);preview(this);myform.ChangecatePagePic.value='yes';document.pic.src=myform.productPic.value;" />
			                <span style="padding-left:34%;" > 图片alt </span> <span style="padding-left:20px;">
                            <input name="matealt" type="text" value="<?php echo $generalpics_rows['matealt']==""?$modiGeneralpicsTitle:$generalpics_rows['matealt'];?>" size="60"    />
	                    </span></p></td>
				      </tr>
					<tr>
					    <td width="14%" style="padding-left:50px;">&nbsp;</td>
					    <td style="padding-left:10px;">&nbsp;</td>
					    <td width="51%" valign="top">&nbsp;</td>
                      </tr>
                      <?php file_exists("widget/generalpics/addmodi.php")?include "widget/generalpics/addmodi.php" :"" ?>
					  <tr>
					    <td align="center" bgcolor="#f0f0ee" style="padding-left:12px;" >视频</td>
					    <td align="center" bgcolor="#f0f0ee" style="padding-left:10px;;" ><div id="preview2">
					      <video width="<?php echo $SmallPicW  ?>"  id="vdo" style="float:left;" border="1" poster="<?=$poster?>"   preload="metadata" controls="controls"   >
					        <source src="<?=$foldervdo?>" />
				          </video>
					      </div>
					      <br />
					      <br />
					      <script type="text/javascript">  
function preview2(file)
{
var prevDiv = document.getElementById('preview2');
if (file.files && file.files[0])
{
var reader = new FileReader();
reader.onload = function(evt){
prevDiv.innerHTML = '<img src="' + evt.target.result + '" width="<?php echo $SmallPicW ?>"  border="1" name="vdo" style="float:left;" />';
}  
reader.readAsDataURL(file.files[1]);
}
else  
{
prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
}
}
                          </script>
					      <br />
				        <br /></td>
					    <td align="" bgcolor="#f0f0ee" style="padding-left:1em;"><span style="padding-left:10px;">
					     <input type="file" name="productVideo" style="width:300px;" onchange="preview2(this)" /><?php if($genOper=="修改" && $poster!=""){  ?><button type="submit" name="deletevideo" id="buttondel" value="deletevideo" />删除视频</button> <?php }?>
					      <br />
				        <span style="padding-left:10px;"><?=$video_tips?></span></span></td>
				      </tr>
					  <tr>
					    <td width="14%" style="padding-left:50px;">					      详细</td>
					    <td colspan="2"   style="padding-left:10px;">
                        <?php
								
							?>
                       <textarea name="modiGeneralpicsText" id="modiGeneralpicsText" style="width:100%;height:300px;visibility:hidden;" onblur="if($('#newsDescription').val().length == 0){$('#newsDescription').val(this.value);}"><?php echo  $modiGeneralpicsText ?></textarea>
                       <?=$promlv>1?$detail_tips:""?>
					    </tr>
					  <tr bgcolor="#f0f0ee">
					    <td height="47" align="center" >&nbsp;</td>
					    <td height="47" colspan="2" align="center">
                        <button type="submit" value="保存"   />保存</button>
                        <button name="重置" type="reset"  value="重置"  onclick="document.pic.src='<?php echo $folderPic?>';myform.ChangecatePagePic.value='no';" />重置</button></td>
				      </tr>
				   </table>
					<br />
                 </form>
				</td>
			</tr>
		</table>
</body>
    <?php  if($_SESSION["refreshModi"]){?>
	<script> document.execCommand('Refresh') ;</script>
	<?php 
	$_SESSION["refreshModi"]=false;
	}?>
</html>