<?php
if(empty($op)) $op='xc';
?>
  <!--- content -->
  <div class="neir">
    <div class="top">相册管理</div>
      <div class="content">
		<div class="main_nav">
			<ul>
				<li class="<?php if($op=='xc'){ echo 'nava_4';}else{ echo 'navb_5';}?>"><a href="?ac=pic&op=xc">相册管理</a></li>
				<li class="<?php if($op=='pic'){ echo 'nava_4';}else{ echo 'navb_5';}?>"><a href="?ac=pic&op=pic">全部相片</a></li>
			</ul>
			<div class="action"><a href="?ac=pic&op=addxc">创建相册</a></div>
			<div class="action"><a href="?ac=pic&op=addpic">上传相片</a></div>
		</div>
		<div class="main_nav2">
<?php 
if($op=="addxc"){
      $name='';
      $pic='';
      $jiesao='';
      $do='add';
   if(!empty($id)){
      global $db;
      $row=$db->getrow("select * from ".Getdbname('pic')." where CS_ID=".$id."");
      if($row){
          $name=$row['CS_Name'];
          $pic=$row['CS_Pic'];
          $jiesao=$row['CS_Content'];
          $do='edit&id='.$id;
       }
   }
?>
<script type="text/javascript" charset="utf-8" src="../public/editor/kindeditor.js"></script>
<script type="text/javascript"> KE.show({
	id : 'CS_Content',
	resizeMode : 1,
	allowPreviewEmoticons : false,
	allowUpload : false,
	items : [
	'source', '|', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
	'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
	'insertunorderedlist', '|', 'image', 'link', 'unlink']
	});
</script>
<script language="javascript">
$(document).ready(function(){
	$("#addpic").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_Pic=$("#CS_Pic").val();
		var re = /^[a-z0-9]*$/gi
	if(CS_Name==""){
		$("#CS_Name").css("border","1px solid red");
		$("#Msg").text("出错了，请填写相册名称！").css("color","red");
                alert("请填写相册名称！");
		return false;
		}
	else if(CS_Pic==""){
		$("#Msg").text("出错了，请上传相册封面！").css("color","red");
                alert("请上传相册封面！");
		return false;
		}
	});
});
</script>
	<form action="do.php?ac=pic&op=<?php echo $do?>" id="form" name="form" method="post">
	<table class="user_mod_list" cellpadding="0" cellspacing="0"><input type="hidden" class="user_reg_input" name="CS_Pic" id="CS_Pic" value="<?php echo $pic?>">
		<tr><td height='50'><span class="t"><i>*</i>相册封面：</span><span class="button-main"><span><button type="button" onclick="Popsboxif('上传相册封面',470,100,'uppic.php?ac=xc');">上传封面</button></span></span><span class="reg_msg" id="sid_info">请先上传封面。</span></td></tr>
		<tr><td height='50'><span class="t"><i>*</i>相册名称：</span><input type="text" class="user_reg_input" id="CS_Name" name="CS_Name" value="<?php echo $name?>"><span class="reg_msg" id="title_info">请输入专集的名称。</span></td></tr>
		<tr><td style="clear:both; height:140px;"><span class="t">相册介绍：</span><textarea style="width:450px; height:140px;" id="CS_Content" name="CS_Content"><?php echo $jiesao?></textarea></td></tr>
	</table>
	<div style="padding-top:10px;margin-left:150px;"><span class="button-main"><span><button type="submit" id="addpic" >确定创建</button></span></span><div id="Msg"></div></div>
	</form>

<?php }elseif($op=='addpic'){ ?>
<script language="javascript">
$(document).ready(function(){
	$("#uppic").click(function(){
		var id=$("#id").val();
	if(id==0){
                alert("请选择要上传的相册！");
		return false;
		}
	});
});
</script>
	<form action="?" method="get">
	<table class="user_mod_list" cellpadding="0" cellspacing="0">
        <input type="hidden" name="ac" value="pic">
        <input type="hidden" name="op" value="uppic">
		<tr><td height='50'><span class="t"><i>*</i>传到相册：</span><span class="select"><select name="id" id="id"><option value="0">--请选择--</option>
        <?php 
              $sqlt="select * from ".Getdbname('pic')." where CS_User='".$cscms_name."'";
              $results=$db->query($sqlt);
	        if($results){
	           while ($row2=$db->fetch_array($results)){
                     echo '<option value="'.$row2['CS_ID'].'">'.$row2['CS_Name'].'</option>';
                   }
                }
        ?>
        </select></span><span class="reg_msg" id="sid_info">没有相册？<a href="?ac=pic&op=addxc">创建相册</a></span></td></tr>
		<tr><td height='50'><span class="t"></span><span class="button-main"><span><button type="submit" id="uppic" >确定选择</button></span></span></td></tr>
        </table>
	</form>
<?php }elseif($op=='uppic'){ ?>
	<div class="imageUpNote">禁止上传与您无关的照片或与DJ不相关的照片，您上传的每张图片都会审核，发现上传违法图片将封账号处理，谢谢合作！</div>
	<div class="demo-box">	
		<input id="uppicadd" type="file" name="Filedata" />
		<div id="fileList"></div>		
	</div>
	<div id="uploadInfo">请选择您要上传的图片，然后点击上传按钮即可上传图片！</div>
	<div class="btn-group">
		<a href="javascript:swfu.startUpload();" class="btn">上传</a>
		<a href="javascript:Deluplist();" class="btn">清空列表</a>
	</div>

<script language="javascript" src="js/swfupload.js"></script>
<script language="javascript">
	var swfu;
	window.onload=function()
	{
		swfu=new SWFUpload({
			upload_url:'uppic.php?ac=upload&op=pic&cid=<?php echo $id?>',
			flash_url:'swf/uppic.swf',
			file_size_limit:'15MB',
			file_types:"*.jpg;*.gif;*.png",
			button_image_url: "images/uppic.gif", 
			button_placeholder_id : "uppicadd",
			button_width: 100,
			button_height: 30,
			button_text_top_padding: 0,
			button_text_left_padding: 0,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			file_dialog_complete_handler:fileDialogComplete,
			upload_success_handler:uploadSuccess,
			upload_progress_handler:uploadProgress,
			upload_complete_handler: uploadComplete,
			file_queued_handler:fileQueued,
			
			debug: false
		});
		
		function fileDialogComplete(numFilesSelected, numFilesQueued){
			if(numFilesQueued>0){
				try{
				}
				catch(ex){
					this.debug(ex);
				}
			}
		}
                
		function uploadSuccess(file,serverData){
                       if(serverData=='ok'){
			   $('#uploadInfo').html('<font color=red>'+file.name+' - 上传完毕!</font>');
                       }else{
			   $('#uploadInfo').html('<font color=#0000ff>'+file.name+' - 上传失败!</font>');
                       }
		}
		
		function uploadProgress(file, bytesLoaded,total ){
			var c=Math.floor((bytesLoaded/total)*100);
			$("#SWF_"+file.id).css({height:'6px','margin-top':'10px','background-color':'#060','padding-right':c+'px'});
		}
		
		function uploadComplete(file){
			if(this.getStats().files_queued > 0)
				this.startUpload();
		}

		function fileQueued(file){
			var fileSize=Math.floor(file.size/1024)+"kb";
			$("#fileList").append("<div class='uplist'><ul><li class='fileName'>"+file.name+"</li><li class='fileSize'>"+fileSize+"</li><li class='jindu' id='SWF_"+file.id+"'></li></ul></div>");
		}
		
			
	}
function Deluplist(){
  document.getElementById('fileList').innerHTML = '';
}
</script>

<?php }elseif($op=='xc'){ ?>

		<div class="album">
     <?php
        $j=1;
	$sql="select * from ".Getdbname('pic')." where cs_user='".$cscms_name."'";
        if(!empty($id)) $sql.=' and cs_cid='.$id;
        $sql.=' order by cs_addtime desc';
		$Arr=getuserpage($sql,"8");//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$numdate="a";
		if($result){
			while ($row = $db ->fetch_array($result)){
		        $numdate="b";
                        $picnum=$db->getRow("select count(CS_ID) as rc from ".Getdbname('photo')." where CS_CID=".$row['CS_ID']."");
    ?>
			<dl>
						
				<dt><div><a href="<?php echo userlink('picx',$cscms_uid,$row['CS_ID'])?>" title="<?php echo $row['CS_Name']?>"><img src="<?php echo piclink('pic',$row['CS_Pic'])?>" width="100" height="100" alt="<?php echo $row['CS_Name']?>" /></a></div></dt>
				<dd><br />
					<strong><a href="<?php echo userlink('picx',$cscms_uid,$row['CS_ID'])?>"><?php echo $row['CS_Name']?></a></strong><br />
					照片：<?php echo $picnum['rc']?>张<br />
					更新：<?php echo datetime($row['CS_AddTime'])?><br />
					<a href="?ac=pic&op=pic&id=<?php echo $row['CS_ID']?>">详细</a> | <a href="?ac=pic&op=addxc&id=<?php echo $row['CS_ID']?>">修改</a> | <a onclick="return confirm('确定要删除吗？');" href="javascript:picdel(<?php echo $row['CS_ID']?>)">删除</a>
				</dd>
			</dl>
    <?php
                        $j=$j+1;
	                }
                }
        if($numdate=="a") echo '<li>没有相关记录!</li>';
    ?>
		</div>
                </div>
		<div class="page">
		<div class="pages">
                       <?php echo $Arr[0];?>
                </div>
<?php }else{ ?>

			<ul>
			       <li class='<?php if(empty($id)) echo 'nav2a_4';?>'><a href="?ac=pic&op=<?php echo $op?>">全部相片</a></li>
    <?php
	global $db;
	$sqlw="select * from ".Getdbname('pic')." where cs_user='".$cscms_name."' order by CS_id desc";
	$rs=$db->query($sqlw);
	$num=$db->num_rows($rs);
	for($i=0;$i<$num;$i++){
		$rowc=$db->fetch_array($rs);
                if($id==$rowc['CS_ID']){
                      $CSS="nav2a_4";
                }else{
                      $CSS="";
                }
           echo '<li class="'.$CSS.'"><a href="?ac=pic&op=pic&id='.$rowc['CS_ID'].'">'.$rowc["CS_Name"].'</a></li>';
	}
    ?> 
			</ul>
		</div>
		<div class="works_pic">
			<ul id="piclist">
    <?php
        $j=1;
	$sql="select * from ".Getdbname('photo')." where cs_user='".$cscms_name."'";
        if(!empty($id)) $sql.=' and cs_cid='.$id;
        $sql.=' order by cs_addtime desc';
		$Arr=getuserpage($sql,"12");//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$numdate="a";
		if($result){
			while ($row = $db ->fetch_array($result)){
		        $numdate="b";					 
				echo '<ol><div class="pic_list"><a href="'.userlink('pick',$cscms_uid,$row['CS_ID']).'"><img src="'.piclink('pic',$row['CS_Url']).'"  width="110" height="100"/></a><div class="pic_gl"><input type="checkbox" name="checkbox" value="'.$row['CS_ID'].'" /> 时间:'.datetime($row['CS_AddTime']).'</div></div></ol>';
	                }
                }
        if($numdate=="a") echo '<li>没有相关记录!</li>';
    ?>
			</ul>
		</div>
		<div class="page">
		<span class="button2-main"><span><button type="button" onclick=clk('all','piclist');>全选</button></span></span>
		<span class="button2-main"><span><button type="button" onclick=clk('un','piclist');>反选</button></span></span>
		<span class="select"><select name="id" id="id" onchange=clk('zypic','piclist',this.options[this.selectedIndex].value);><option value="0">添加到相册</option>
                <?php 
                     $sqlt="select * from ".Getdbname('pic')." where CS_User='".$cscms_name."'";
                     $results=$db->query($sqlt);
	             if($results){
	                while ($row2=$db->fetch_array($results)){
                          echo '<option value="'.$row2['CS_ID'].'">'.$row2['CS_Name'].'</option>';
                        }
                     }
                ?>
        	</select>
		</span>
		<span class="button3-main"><span><button type="button" onclick=clk('delpic','piclist');>删除所选</button></span></span>
		<div class="pages">
                       <?php echo $Arr[0];?>
                </div>
<?php } ?>
      </div>
      </div>
    <div class="end"></div>
  </div>
