<?php

//---------下載地址組合
function ReturnDownpath($downname,$downpath,$delpathid,$pathid,$downuser,$fen,$thedownqz,$add,$foruser,$downurl,$down=0){
	$downname=eCheckEmptyArray($downname);
	$delpathid=eCheckEmptyArray($delpathid);
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	//增加軟件
	if(empty($down))
	{
		for($i=0;$i<count($downname);$i++)
		{
			//替換非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$name);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$path);
			//批量更換權限
			if($add['doforuser'])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新點數
			if($add['dodownfen'])
			{
				if(empty($add['downfen']))
				{
					$add['downfen']=0;
				}
				$ffen=$add['downfen'];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{
				$fuser=(int)$fuser;
				$ffen=(int)$ffen;
				$downqz=(int)$downqz;
				$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;
			}
		}
	}
	else//修改軟件
	{
		for($i=0;$i<count($downname);$i++)
		{
			//刪除下載地址
			$del=0;
			for($j=0;$j<count($delpathid);$j++)
			{
				if($delpathid[$j]==$pathid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			//替換非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$name);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$path);
			//批量更換權限
			if($add['doforuser'])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新點數
			if($add['dodownfen'])
			{
				if(empty($add['downfen']))
				{
					$add['downfen']=0;
				}
				$ffen=$add['downfen'];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{
				$fuser=(int)$fuser;
				$ffen=(int)$ffen;
				$downqz=(int)$downqz;
				$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;
			}
		}
	}
	//去掉最後的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	$returnstr=hRepPostStr($returnstr,1,0,1);
	return $returnstr;
}

//---------圖片地址組合
function ReturnMorepicpath($smallpic,$bigpic,$picname,$delpicid,$picid,$add,$downurl,$down=0,$modtype=0,$fstb=1){
	global $loginin,$logininid;
	$smallpic=eCheckEmptyArray($smallpic);
	$delpicid=eCheckEmptyArray($delpicid);
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	$add['msavepic']=(int)$add['msavepic'];
	$add['classid']=(int)$add['classid'];
	$add['id']=(int)$add['id'];
	$add['filepass']=(int)$add['filepass'];
	$modtype=(int)$modtype;
	$fstb=(int)$fstb;
	$logininid=(int)$logininid;
	$loginin=RepPostVar($loginin);
	//增加信息
	if(empty($down))
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替換非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存圖片
			$smpr=SaveMorepicFile("msmallpfile",$add['msavepic'],$i,$spic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
			$spic=$smpr['url'];

			//如沒有大圖的話跟縮略圖一樣
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存圖片
				$bmpr=SaveMorepicFile("mbigpfile",$add['msavepic'],$i,$bpic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
				$bpic=$bmpr['url'];
				//生成縮圖
				if(empty($spic)&&$bpic&&$bmpr['tran']&&$add['mcreatespic'])
				{
					$picno='[b]'.($name?$name:$bmpr['filename']);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr['insertfile'],$bmpr['filepath'],$bmpr['yname'],$add['mcreatespicwidth'],$add['mcreatespicheight'],$bmpr['name'],$add['filepass'],$add['filepass'],$logininid,$loginin,$modtype,$fstb);
					$spic=str_replace("/".$bmpr['filename'],"/small".$bmpr['insertfile'].$sfiler['filetype'],$bmpr['url']);
				}
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	else//修改信息
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			//刪除地址
			$del=0;
			for($j=0;$j<count($delpicid);$j++)
			{
				if($delpicid[$j]==$picid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替換非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存圖片
			$smpr=SaveMorepicFile("msmallpfile",$add['msavepic'],$i,$spic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
			$spic=$smpr['url'];

			//如沒有大圖的話跟縮略圖一樣
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存圖片
				$bmpr=SaveMorepicFile("mbigpfile",$add['msavepic'],$i,$bpic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
				$bpic=$bmpr['url'];
				//生成縮圖
				if(empty($spic)&&$bpic&&$bmpr['tran']&&$add['mcreatespic'])
				{
					$picno='[b]'.($name?$name:$bmpr['filename']);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr['insertfile'],$bmpr['filepath'],$bmpr['yname'],$add['mcreatespicwidth'],$add['mcreatespicheight'],$bmpr['name'],$add['filepass'],$add['filepass'],$logininid,$loginin,$modtype,$fstb);
					$spic=str_replace("/".$bmpr['filename'],"/small".$bmpr['insertfile'].$sfiler['filetype'],$bmpr['url']);
				}
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	//去掉最後的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	$returnstr=hRepPostStr($returnstr,1,0,1);
	return $returnstr;
}



//----------------------------------- 前台 -----------------------------------

//---------下載地址組合
function QReturnDownpath($downname,$downpath,$delpathid,$pathid,$downuser,$fen,$thedownqz,$add,$foruser,$downurl,$down=0){
	$downname=eCheckEmptyArray($downname);
	$delpathid=eCheckEmptyArray($delpathid);
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	//增加軟件
	if(empty($down))
	{
		for($i=0;$i<count($downname);$i++)
		{
			//替換非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$name);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$path);
			//批量更換權限
			if($add['doforuser'])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新點數
			if($add['dodownfen'])
			{
				if(empty($add['downfen']))
				{
					$add['downfen']=0;
				}
				$ffen=$add['downfen'];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{
				$fuser=(int)$fuser;
				$ffen=(int)$ffen;
				$downqz=(int)$downqz;
				$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;
			}
		}
	}
	else//修改軟件
	{
		for($i=0;$i<count($downname);$i++)
		{
			//刪除下載地址
			$del=0;
			for($j=0;$j<count($delpathid);$j++)
			{
				if($delpathid[$j]==$pathid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			//替換非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$name);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$path);
			//批量更換權限
			if($add['doforuser'])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新點數
			if($add['dodownfen'])
			{
				if(empty($add['downfen']))
				{
					$add['downfen']=0;
				}
				$ffen=$add['downfen'];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{
				$fuser=(int)$fuser;
				$ffen=(int)$ffen;
				$downqz=(int)$downqz;
				$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;
			}
		}
	}
	//去掉最後的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	$returnstr=RepPostStr($returnstr,0,0,1);
	return $returnstr;
}

//---------圖片地址組合
function QReturnMorepicpath($smallpic,$bigpic,$picname,$delpicid,$picid,$add,$downurl,$down=0,$modtype=0,$fstb=1){
	global $loginin,$logininid;
	$smallpic=eCheckEmptyArray($smallpic);
	$delpicid=eCheckEmptyArray($delpicid);
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	$add['msavepic']=(int)$add['msavepic'];
	$add['classid']=(int)$add['classid'];
	$add['id']=(int)$add['id'];
	$add['filepass']=(int)$add['filepass'];
	$modtype=(int)$modtype;
	$fstb=(int)$fstb;
	$logininid=(int)$logininid;
	$loginin=RepPostVar($loginin);
	//增加信息
	if(empty($down))
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替換非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存圖片
			//$smpr=SaveMorepicFile("msmallpfile",$add['msavepic'],$i,$spic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
			//$spic=$smpr['url'];

			//如沒有大圖的話跟縮略圖一樣
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存圖片
				//$bmpr=SaveMorepicFile("mbigpfile",$add['msavepic'],$i,$bpic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
				//$bpic=$bmpr['url'];
				/*
				//生成縮圖
				if(empty($spic)&&$bpic&&$bmpr['tran']&&$add['mcreatespic'])
				{
					$picno='[b]'.($name?$name:$bmpr['filename']);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr['insertfile'],$bmpr['filepath'],$bmpr['yname'],$add['mcreatespicwidth'],$add['mcreatespicheight'],$bmpr['name'],$add['filepass'],$add['filepass'],$logininid,$loginin,$modtype,$fstb);
					$spic=str_replace("/".$bmpr['filename'],"/small".$bmpr['insertfile'].$sfiler['filetype'],$bmpr['url']);
				}
				*/
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	else//修改信息
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			//刪除地址
			$del=0;
			for($j=0;$j<count($delpicid);$j++)
			{
				if($delpicid[$j]==$picid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替換非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存圖片
			//$smpr=SaveMorepicFile("msmallpfile",$add['msavepic'],$i,$spic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
			//$spic=$smpr['url'];

			//如沒有大圖的話跟縮略圖一樣
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存圖片
				//$bmpr=SaveMorepicFile("mbigpfile",$add['msavepic'],$i,$bpic,$name,$add['classid'],$add['id'],$add,$modtype,$fstb);
				//$bpic=$bmpr['url'];
				/*
				//生成縮圖
				if(empty($spic)&&$bpic&&$bmpr['tran']&&$add['mcreatespic'])
				{
					$picno='[b]'.($name?$name:$bmpr['filename']);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr['insertfile'],$bmpr['filepath'],$bmpr['yname'],$add['mcreatespicwidth'],$add['mcreatespicheight'],$bmpr['name'],$add['filepass'],$add['filepass'],$logininid,$loginin,$modtype,$fstb);
					$spic=str_replace("/".$bmpr['filename'],"/small".$bmpr['insertfile'].$sfiler['filetype'],$bmpr['url']);
				}
				*/
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	//去掉最後的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	$returnstr=RepPostStr($returnstr,0,0,1);
	return $returnstr;
}

?>