<?php

						/*************************************\
						
						    Handshakes Professional (3.3)
						            by DZOIC LTD
						       Copyright(c) 2005-2007
						        http://www.dzoic.com
						
						\*************************************/

	$vals = array();
	
	include_once(DOC_ROOT."/functions/adodb-time.php");
	
	$totals["members"]     = 0;
	$totals["photos"]      = 0;
	$totals["blogs"]       = 0;
	$totals["classifieds"] = 0;
	$totals["events"]      = 0;
	$totals["clubs"]       = 0;

	//importing members
	$sql_query = "SELECT user,password,email,gender,day,month,year,location,state,city,zip,signup
				  FROM user";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$vals = array();
		$vals["fname"]    = $vals["username"] = $get["user"];
		$vals["lname"]    = "";
		$vals["password"] = $get["password"];
		$vals["email"]    = $get["email"];
		
		$GLOBALS["Member"]->values = $vals;
		$mem_id = $GLOBALS["Member"]->create(1);
		reset($vals);
		
		if($mem_id):
		
		$sql_query = "UPDATE members SET verified='1' WHERE mem_id=".$mem_id;
		$GLOBALS["DB"]->execute($sql_query);
		
		if(!$get["signup"])
			$get["signup"] = time();
		
		$sql_query = "UPDATE profiles SET joined=".$get["signup"]." WHERE mem_id=".$mem_id;
		$GLOBALS["DB"]->execute($sql_query);
		
		$vals["gender"]    = (eregi("^male$",$get["gender"])) ? "1" : "2";
		$vals["birthdate"] = ($get["day"] && $get["month"] && $get["year"]) ? adodb_mktime(0,0,59,$get["month"],$get["day"],$get["year"]) : 0;
		
		$geo = names2geo($vals["location"],$vals["state"],$vals["city"],$vals["zip"]);
		
		$vals["country"]   = $geo["country"];
		$vals["state"]     = $geo["state"];
		$vals["city"]      = $geo["city"];
		$vals["latitude"]  = $geo["latitude"];
		$vals["longitude"] = $geo["longitude"];
		
		$sql_query = "UPDATE profiles SET gender=':gender:',birthdate=':birthdate:',
					  country=':country:',state=':state:',city=':city:',latitude=':latitude:',
					  longitude=':longitude:' WHERE mem_id=:mem_id:";
		$vals["mem_id"] = $mem_id;
		$GLOBALS["DB"]->values = $vals;
		$GLOBALS["DB"]->execute($sql_query);
		
		//main photo
		if(file_exists($values["doc_root"]."/file/pic/user/".$get["user"].".jpg")){
			
			//"upload" file
			$info = getimagesize($values["doc_root"]."/file/pic/user/".$get["user"].".jpg");
			if(eregi("gif",$info["mime"]))
			$ext = ".gif";
			elseif(eregi("jpeg|jpg",$info["mime"]))
			$ext = ".jpeg";
			else
			continue;

			$photo = @build_thumbnailes($values["doc_root"]."/file/pic/user/".$get["user"].".jpg",$ext,0,0);

			$sql_query = "INSERT INTO photos (mem_id,photo,photo_med,photo_small,caption,voting,posted,approved)
					  	  VALUES (:mem_id:,':photo:',':photo_med:',':photo_small:',':caption:','1',':time:','1')";
			$vals = array();
			$vals["mem_id"]      = $mem_id;
			$vals["photo"]       = $photo["ex"];
			$vals["photo_med"]   = $photo["med"];
			$vals["photo_small"] = $photo["small"];
			$vals["caption"]     = $get["text"];
			$vals["time"]        = $get["time"];

			$GLOBALS["DB"]->values = $vals;
			$pho_id = $GLOBALS["DB"]->insert($sql_query);

			$sql_query = "UPDATE profiles SET photo=':photo:',photo_med=':photo_med:',photo_small=':photo_small:'
						  WHERE mem_id=".$mem_id;
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
			
		}//if
		
		$totals["members"]++;
		
		endif;
		
	}//while
	endif;
	
	//importing testimonials
	$sql_query = "SELECT user,gbuser,text,time
				  FROM comment WHERE main='gb'";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){		
		$vals["mem_id"] = name2id($get["gbuser"]);		
		$vals["per_id"] = name2id($get["user"]);
		if($vals["mem_id"] && $vals["per_id"]){
			$vals["feedback"] = strip_tags($get["text"]);
			$vals["time"] = $get["time"];
			$sql_query = "SELECT COUNT(*) FROM testimonials WHERE mem_id=:mem_id: AND per_id=:per_id:
						  AND date=:time:";
			$GLOBALS["DB"]->values = $vals;
			$exists = $GLOBALS["DB"]->single($sql_query);
			if($exists)
				continue;
			
			$sql_query = "INSERT INTO testimonials (mem_id,per_id,feedback,date)
						  VALUES (:mem_id:,:per_id:,':feedback:',:time:)";
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
		}//if
	}//while
	endif;
	
	//importing photos
	$sql_query = "SELECT id,user,text,time
				  FROM main WHERE who_view='everyone'";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){	
		
		//copy required?
		if(file_exists(DOC_ROOT."/temp/".$get["id"].".jpg"))
			continue;
		
		//"upload" file
		$mem_id = name2id($get["user"]);
		if(!$mem_id)
			continue;
			
		$info = getimagesize($values["doc_root"]."/file/pic/gallery/".$get["id"].".jpg");
		if(eregi("gif",$info["mime"]))
			$ext = ".gif";
		elseif(eregi("jpeg|jpg",$info["mime"]))
			$ext = ".jpeg";
		else
			continue;
			
		$photo = @build_thumbnailes($values["doc_root"]."/file/pic/gallery/".$get["id"].".jpg",$ext,0,0);
		copy($values["doc_root"]."/file/pic/gallery/".$get["id"].".jpg",DOC_ROOT."/temp/".$get["id"].".jpg");
		
		$sql_query = "INSERT INTO photos (mem_id,photo,photo_med,photo_small,caption,voting,posted,approved)
					  VALUES (:mem_id:,':photo:',':photo_med:',':photo_small:',':caption:','1',':time:','1')";
		$vals = array();
		$vals["mem_id"]      = $mem_id;
		$vals["photo"]       = $photo["ex"];
		$vals["photo_med"]   = $photo["med"];
		$vals["photo_small"] = $photo["small"];
		$vals["caption"]     = $get["text"];
		$vals["time"]        = $get["time"];
		
		$GLOBALS["DB"]->values = $vals;
		$pho_id = $GLOBALS["DB"]->insert($sql_query);		
		
		//and photo comments
		$sql_query = "SELECT user,text,time FROM comment WHERE main=".$get["id"]." ORDER BY id ASC";
		$res = mysql_query($sql_query,$conn);
		if(mysql_num_rows($res)){
		while($g = mysql_fetch_assoc($res)){
			$vals = array();
			$vals["pho_id"] = $pho_id;
			$vals["mem_id"] = name2id($g["user"]);
			$vals["comment"] = strip_tags($g["text"]);
			
			if($vals["mem_id"]){
				$sql_query = "INSERT INTO photo_comments (pho_id,mem_id,comment)
							  VALUES (:pho_id:,:mem_id:,':comment:')";
				$GLOBALS["DB"]->values = $vals;
				$GLOBALS["DB"]->execute($sql_query);
			}//if
		}//while
		}//if
		
		$totals["photos"]++;
		
	}//while
	endif;
	
	//importing connections
	$sql_query = "SELECT user,buddy FROM buddy";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$vals["mem_id"] = name2id($get["user"]);		
		$vals["per_id"] = name2id($get["buddy"]);
		if($vals["mem_id"] && $vals["per_id"]){
			$GLOBALS["settings"]["handshakes"] = 0;
			$GLOBALS["Network"]->add_friend($vals["mem_id"],$vals["per_id"]);
		}//if
	}//while
	endif;
	
	//importing forums
	$sql_query = "SELECT forum_id,forum_title,forum_info FROM forum ORDER BY forum_id ASC";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$sql_query = "INSERT INTO forums (title,description,created,active,position)
					  VALUES (':title:',':description:',:time:,'1',:id:)";
		$vals = array();
		$vals["title"] = $get["forum_title"];
		$vals["description"] = $get["forum_info"];
		$vals["time"] = time();
		$vals["id"] = $get["forum_id"];
		$GLOBALS["DB"]->values = $vals;
		$frm_id = $GLOBALS["DB"]->insert($sql_query);
		
		//importing topics
		$sql_query = "SELECT id,user,title,text,time,view
					  FROM forum_topic WHERE type='".$get["forum_id"]."'";
		$res = mysql_query($sql_query,$conn);
		if(mysql_num_rows($res)):
		while($g = mysql_fetch_assoc($res)){
			$sql_query = "INSERT INTO topics (frm_id,mem_id,subject,created,views)
						  VALUES (:frm_id:,:mem_id:,':subject:',:time:,:views:)";
			$vals = array();
			$vals["frm_id"] = $frm_id;
			$vals["mem_id"] = name2id($g["user"]);
			if(!$vals["mem_id"])
				continue;
				
			$vals["subject"] = $g["title"];
			$vals["time"]    = $g["time"];
			$vals["views"]   = $g["view"];
			
			$GLOBALS["DB"]->values = $vals;
			$top_id = $GLOBALS["DB"]->insert($sql_query);
			
			//importing posts
			$sql_query = "INSERT INTO posts (top_id,mem_id,message,posted)
						  VALUES (:top_id:,:mem_id:,':message:',:time:)";
			$vals["top_id"] = $top_id;
			$vals["message"] = $g["text"];
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
			
			$sql_query = "SELECT user,text,time FROM forum_reply WHERE fid='".$g["id"]."'
						  AND type='".$get["forum_id"]."'";
			$r = mysql_query($sql_query,$conn);
			if(mysql_num_rows($r)):
			while($subg = mysql_fetch_assoc($r)){
				$sql_query = "INSERT INTO posts (top_id,mem_id,message,posted)
							  VALUES (:top_id:,:mem_id:,':message:',:time:)";
				$vals = array();
				$vals["top_id"]  = $top_id;
				$vals["mem_id"]  = name2id($subg["user"]);
				$vals["message"] = $subg["text"];
				$vals["time"]    = $subg["time"];
				$GLOBALS["DB"]->values = $vals;
				$GLOBALS["DB"]->execute($sql_query);
			}//while
			endif;
			
		}//while
		endif;
		
	}//while
	endif;
	
	//importing blogs
	
	include_once(DOC_ROOT."/classes/Blogs.class.php");
	
	$sql_query = "DELETE FROM blogs";
	$GLOBALS["DB"]->execute($sql_query);
	$sql_query = "SELECT id,user,title,text,time FROM journal";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$vals = array();
		$sql_query = "SELECT mem_id FROM members WHERE username='".mysql_escape_string($get["user"])."'";
		$mem_id = $vals["mem_id"] = $GLOBALS["DB"]->single($sql_query);
		
		if($mem_id):
		
		$sql_query = "SELECT COUNT(*) FROM blogs WHERE title=':title:'";
		$GLOBALS["DB"]->values = array("title" => $get["title"]);
		$exists = $GLOBALS["DB"]->single($sql_query);
		
		if($exists)
			continue;
		
		$vals["title"]  = $get["title"];
		$vals["description"] = hs_substr(strip_tags($get["text"]),0,200)."...";
		$vals["audience"] = "0";
		$vals["posted"] = $get["time"];
		$vals["folder"] = $get["id"];
		$vals["time"] = $get["time"];
		$vals["template"] = ($GLOBALS["Blogs"]->template) ? $GLOBALS["Blogs"]->template : "default";
		$blg_id = $GLOBALS["Blogs"]->create($vals);
		
		$sql_query = "INSERT INTO blogs_posts (blg_id,mem_id,title,message,message_plain,posted)
					  VALUES (:blg_id:,:mem_id:,':title:',':message:',':message_plain:',:time:)";
		$vals = array();
		$vals["blg_id"] = $blg_id;
		$vals["mem_id"] = $mem_id;
		$vals["title"] = $get["title"];
		$vals["message"] = $get["text"];
		$vals["message_plain"] = strip_tags($get["text"]);
		$vals["time"] = $get["time"];
		$GLOBALS["DB"]->values = $vals;
		$pst_id = $GLOBALS["DB"]->insert($sql_query);
		
		$sql_query = "SELECT user,text,time FROM comment WHERE main='journal' AND cid='".$get["id"]."'";
		$res = mysql_query($sql_query,$conn);
		if(mysql_num_rows($res)){
		while($g = mysql_fetch_assoc($res)){			
			$vals = array();
			$sql_query = "SELECT mem_id FROM members WHERE username='".mysql_escape_string($g["user"])."'";
			$vals["mem_id"] = $GLOBALS["DB"]->single($sql_query);
			
			if(!$vals["mem_id"])
				continue;
			
			$sql_query = "INSERT INTO blogs_comments (pst_id,blg_id,mem_id,comment,posted)
						  VALUES (:pst_id:,:blg_id:,:mem_id:,':comment:',:time:)";
			$vals["pst_id"] = $pst_id;
			$vals["blg_id"] = $blg_id;
			$vals["time"]   = $g["time"];
			$vals["comment"] = strip_tags($g["text"]);
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
		}//while
		}//if
		
		$totals["blogs"]++;
		
		endif;
		
	}//while
	endif;
	
	//importing classifieds categories
	$impcats = array();
	$sql_query = "SELECT * FROM listing";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$impcats[$get["id"]] = $get["name"];
	}//while
	endif;
	
	$themes = admin_get_themes();
	while(list($theme,) = each($themes)){
		$categories = array();
		$subcategories = array();
		$file = DOC_ROOT."/themes/".$theme."/system/cls_categories.inc.php";
		include($file);
		$categories[] = "*** IMPORTED ***";
		$category = max(array_keys($categories));
		$subcategories[$category] = $impcats;
		$str = "<?php\n\n";
		while(list($key,$val) = each($categories)){
			$str.= "\$categories[".$key."] = \"".hs_ereg_replace('"','\"',$val)."\";\n";
			if(is_array($subcategories[$key])){
				while(list($k,$v) = each($subcategories[$key])){
					$str.= "\$subcategories[".$key."][".$k."] = \"".hs_ereg_replace('"','\"',$v)."\";\n";
				}//while
			}//if
		}//while
		$str.= "\n?>";
		$file_handler = fopen($file,"w");
		fwrite($file_handler,$str);
		fclose($file_handler);
	}//while
	
	//importing classifieds
	
	include_once(DOC_ROOT."/classes/Classifieds.class.php");
	
	$sql_query = "SELECT * FROM listing_main";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		
		$vals = array();
		$vals["mem_id"] = name2id($get["user"]);
		
		if(!$vals["mem_id"])
			continue;
			
		$sql_query = "SELECT COUNT(*) FROM classifieds WHERE title=':title:'";
		$GLOBALS["DB"]->values = array("title" => $get["title"]);
		$exists = $GLOBALS["DB"]->single($sql_query);
		
		if($exists)
			continue;
		
		$vals["title"] = $get["title"];
		$vals["brief"] = hs_substr(strip_tags($get["text"]),0,200)."...";
		$vals["description"] = $get["text"];
		$vals["description_plain"] = strip_tags($get["text"]);
		
		$member = $GLOBALS["Member"]->info($vals["mem_id"]);
		
		$vals["country"] = $member["country"];
		$vals["state"] = $member["state"];
		$vals["city"] = $member["city"];
		$vals["postal_code"] = $member["postal_code"];
		$vals["latitude"] = $member["latitude"];
		$vals["longitude"] = $member["longitude"];
		$vals["category"] = $category;
		$vals["subcategory"] = $get["list_id"];
		$vals["time"] = $get["time"];
		$vals["audience"] = 0;
		$vals["clb_id"] = 0;
		$vals["folder"] = $get["id"];
		$vals["template"] = ($GLOBALS["Classifieds"]->template) ? $GLOBALS["Classifieds"]->template : "default";
		
		$cls_id = $GLOBALS["Classifieds"]->create($vals);
		
		if($get["views"]){
		
			$sql_query = "UPDATE classifieds SET viewed=".$get["views"]." WHERE cls_id=".$cls_id;
			$GLOBALS["DB"]->execute($sql_query);
		
		}//if
		
		$totals["classifieds"]++;
		
	}//while
	endif;
	
	//importing events categories
	$impcats = array();
	$impcats[0] = "";
	$cats = file($values["doc_root"]."/file/txt/event_items.txt");	
	foreach($cats as $c){
		$impcats[] = trim($c);
	}//foreach
	unset($impcats[0]);
	
	$themes = admin_get_themes();
	while(list($theme,) = each($themes)){
		$categories = array();
		$subcategories = array();
		$file = DOC_ROOT."/themes/".$theme."/system/evn_categories.inc.php";
		include($file);
		$categories[] = "*** IMPORTED ***";
		$category = max(array_keys($categories));
		$subcategories[$category] = $impcats;
		$str = "<?php\n\n";
		while(list($key,$val) = each($categories)){
			$str.= "\$categories[".$key."] = \"".hs_ereg_replace('"','\"',$val)."\";\n";
			if(is_array($subcategories[$key])){
				while(list($k,$v) = each($subcategories[$key])){
					$str.= "\$subcategories[".$key."][".$k."] = \"".hs_ereg_replace('"','\"',$v)."\";\n";
				}//while
			}//if
		}//while
		$str.= "\n?>";
		$file_handler = fopen($file,"w");
		fwrite($file_handler,$str);
		fclose($file_handler);
	}//while
	
	//importing events
	
	include_once(DOC_ROOT."/classes/Events.class.php");
	
	$sql_query = "SELECT * FROM events";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		
		$vals = array();
		$vals["mem_id"] = name2id($get["user"]);
		
		if(!$vals["mem_id"])
			continue;
			
		$sql_query = "SELECT COUNT(*) FROM events WHERE title=':title:'";
		$GLOBALS["DB"]->values = array("title" => $get["title"]);
		$exists = $GLOBALS["DB"]->single($sql_query);
		
		if($exists)
			continue;
		
		$vals["title"] = $get["title"];
		$vals["brief"] = hs_substr(strip_tags($get["text"]),0,200)."...";
		$vals["description"] = $get["text"];
		$vals["description_plain"] = strip_tags($get["text"]);
		
		$member = $GLOBALS["Member"]->info($vals["mem_id"]);
		
		$vals["country"] = $member["country"];
		$vals["state"] = $member["state"];
		$vals["city"] = $member["city"];
		$vals["postal_code"] = $member["postal_code"];
		$vals["latitude"] = $member["latitude"];
		$vals["longitude"] = $member["longitude"];
		$vals["category"] = $category;
		$vals["subcategory"] = array_search($get["type"],$subcategories[$category]);
		$vals["time"] = $get["time"];
		$vals["audience"] = 0;
		$vals["clb_id"] = 0;
		$vals["folder"] = $get["id"];
		$vals["template"] = ($GLOBALS["Events"]->template) ? $GLOBALS["Events"]->template : "default";
		$vals["date"] = strtotime($get["month"]."/".$get["day"]."/".$get["year"]." ".$get["start_time"]);
		
		$evn_id = $GLOBALS["Events"]->create($vals);
		
		if($get["views"]){
		
			$sql_query = "UPDATE events SET viewed=".$get["views"]." WHERE evn_id=".$evn_id;
			$GLOBALS["DB"]->execute($sql_query);
		
		}//if
		
		$totals["events"]++;
		
	}//while
	endif;	
	
	//importing groups categories
	$impcats = array();
	$sql_query = "SELECT * FROM group_name";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		$impcats[$get["id"]] = $get["name"];
	}//while
	endif;
	
	$themes = admin_get_themes();
	while(list($theme,) = each($themes)){
		$categories = array();
		$subcategories = array();
		$file = DOC_ROOT."/themes/".$theme."/system/clb_categories.inc.php";
		include($file);
		$categories[] = "*** IMPORTED ***";
		$category = max(array_keys($categories));
		$subcategories[$category] = $impcats;
		$str = "<?php\n\n";
		while(list($key,$val) = each($categories)){
			$str.= "\$categories[".$key."] = \"".hs_ereg_replace('"','\"',$val)."\";\n";
			if(is_array($subcategories[$key])){
				while(list($k,$v) = each($subcategories[$key])){
					$str.= "\$subcategories[".$key."][".$k."] = \"".hs_ereg_replace('"','\"',$v)."\";\n";
				}//while
			}//if
		}//while
		$str.= "\n?>";
		$file_handler = fopen($file,"w");
		fwrite($file_handler,$str);
		fclose($file_handler);
	}//while*/
	
	$themes = admin_get_themes();
	while(list($theme,) = each($themes)){
		$categories = array();
		$subcategories = array();
		$file = DOC_ROOT."/themes/".$theme."/system/clb_categories.inc.php";
		include($file);
		$category = max(array_keys($categories));
	}//while
	
	//importing groups / clubs
	
	include_once(DOC_ROOT."/classes/Clubs.class.php");
	
	$sql_query = "SELECT * FROM group_main";
	$result = mysql_query($sql_query,$conn);
	if(mysql_num_rows($result)):
	while($get = mysql_fetch_assoc($result)){
		
		$vals = array();
		$vals["mem_id"] = name2id($get["user"]);
		
		if(!$vals["mem_id"])
			continue;
			
		$sql_query = "SELECT COUNT(*) FROM clubs WHERE name=':name:'";
		$GLOBALS["DB"]->values = array("name" => $get["title"]);
		$exists = $GLOBALS["DB"]->single($sql_query);
		
		if($exists)
			continue;
			
		$vals["time"] = $get["time"];
		$vals["name"] = $get["title"];
		$vals["brief"] = hs_substr(strip_tags($get["text"]),0,200)."...";		
		$vals["description"] = $get["text"];
		$vals["description_plain"] = strip_tags($get["text"]);
		
		$member = $GLOBALS["Member"]->info($vals["mem_id"]);
		
		$vals["country"] = $member["country"];
		$vals["state"] = $member["state"];
		$vals["city"] = $member["city"];
		$vals["postal_code"] = $member["postal_code"];
		$vals["latitude"] = $member["latitude"];
		$vals["longitude"] = $member["longitude"];
		$vals["category"] = $category;
		$vals["subcategory"] = $get["type"];
		
		$vals["membership"] = ($get["open_join"] == "Yes") ? "1" : "3";
		$vals["folder"] = $get["id"];
		$vals["template"] = ($GLOBALS["Clubs"]->template) ? $GLOBALS["Clubs"]->template : "default";
		
		$clb_id = $GLOBALS["Clubs"]->create($vals);
		
		//members
		$sql_query = "SELECT user,time FROM group_member WHERE group_id=".$get["id"];
		$res = mysql_query($sql_query,$conn);
		while($g = mysql_fetch_assoc($res)){
			$vals = array();
			$vals["mem_id"] = name2id($g["user"]);
			if(!$vals["mem_id"])
				continue;
			$sql_query = "SELECT COUNT(*) FROM members_clubs WHERE mem_id=".$vals["mem_id"]." AND clb_id=".$clb_id;
			$exists = $GLOBALS["DB"]->single($sql_query);
			if($exists)
				continue;
				
			$sql_query = "INSERT INTO members_clubs(mem_id,clb_id,last_visit)
						  VALUES (:mem_id:,:clb_id:,:time:)";
			$vals["clb_id"] = $clb_id;
			$vals["time"] = $g["time"];
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
		}//while
		
		//forum topics
		$sql_query = "SELECT * FROM group_forum WHERE group_id=".$get["id"]." AND type!='reply'";
		$res = mysql_query($sql_query,$conn);
		if(mysql_num_rows($res)):
		while($g = mysql_fetch_assoc($res)){
			
			$sql_query = "SELECT frm_id FROM forums WHERE clb_id=".$clb_id;
			$frm_id = $GLOBALS["DB"]->single($sql_query);
			
			$sql_query = "INSERT INTO topics (frm_id,mem_id,subject,created,views)
						  VALUES (:frm_id:,:mem_id:,':subject:',:time:,:views:)";
			$vals = array();			
			$vals["frm_id"] = $frm_id;
			$vals["mem_id"] = name2id($g["user"]);
			if(!$vals["mem_id"])
				continue;
				
			$vals["subject"] = $g["title"];
			$vals["time"]    = $g["time"];
			$vals["views"]   = $g["views"];
			
			$GLOBALS["DB"]->values = $vals;
			$top_id = $GLOBALS["DB"]->insert($sql_query);
			
			//importing posts
			$sql_query = "INSERT INTO posts (top_id,mem_id,message,posted)
						  VALUES (:top_id:,:mem_id:,':message:',:time:)";
			$vals["top_id"] = $top_id;
			$vals["message"] = $g["text"];
			$GLOBALS["DB"]->values = $vals;
			$GLOBALS["DB"]->execute($sql_query);
			
			$sql_query = "SELECT user,text,time FROM group_forum WHERE group_id=".$get["id"]." AND type='reply'
						  AND reply_id=".$g["reply_id"]." AND id != ".$g["id"];
			$r = mysql_query($sql_query,$conn);
			if(mysql_num_rows($r)):
			while($subg = mysql_fetch_assoc($r)){
				$sql_query = "INSERT INTO posts (top_id,mem_id,message,posted)
							  VALUES (:top_id:,:mem_id:,':message:',:time:)";
				$vals = array();
				$vals["top_id"]  = $top_id;
				$vals["mem_id"]  = name2id($subg["user"]);
				$vals["message"] = $subg["text"];
				$vals["time"]    = $subg["time"];
				$GLOBALS["DB"]->values = $vals;
				$GLOBALS["DB"]->execute($sql_query);
			}//while
			endif;
		}//while
		endif;
		
		//photos
		$sql_query = "SELECT * FROM group_gallery WHERE group_id='".$get["id"]."'";
		$res = mysql_query($sql_query,$conn);
		if(mysql_num_rows($res)):
		while($g = mysql_fetch_assoc($res)){
			
			if(file_exists($values["doc_root"]."/file/pic/groups/gallery/".$g["id"].".jpg")){
				
				//copy required?
				if(file_exists(DOC_ROOT."/temp/club_".$g["id"].".jpg"))
					continue;
			
				$vals = array();
				$vals["mem_id"] = name2id($g["user"]);
				if(!$vals["mem_id"])
					continue;
				
				$vals["clb_id"] = $clb_id;
				$vals["time"] = $g["time"];
				$vals["caption"] = $g["title"];
				$vals["approved"] = 1;
			
				//"upload" file
				$info = getimagesize($values["doc_root"]."/file/pic/groups/gallery/".$g["id"].".jpg");
				if(eregi("gif",$info["mime"]))
				$ext = ".gif";
				elseif(eregi("jpeg|jpg",$info["mime"]))
				$ext = ".jpeg";
				else
				continue;
	
				$photo = @build_thumbnailes($values["doc_root"]."/file/pic/groups/gallery/".$g["id"].".jpg",$ext,0,0);
				copy($values["doc_root"]."/file/pic/groups/gallery/".$g["id"].".jpg",DOC_ROOT."/temp/club_".$g["id"].".jpg");
	
				$sql_query = "INSERT INTO club_photos (mem_id,clb_id,photo,photo_med,photo_small,caption,posted,approved)
						  	  VALUES (:mem_id:,:clb_id:,':photo:',':photo_med:',':photo_small:',':caption:',':time:','1')";
				
				$vals["photo"]       = $photo["ex"];
				$vals["photo_med"]   = $photo["med"];
				$vals["photo_small"] = $photo["small"];			
	
				$GLOBALS["DB"]->values = $vals;
				$pho_id = $GLOBALS["DB"]->insert($sql_query);
				
				if($g["default"]){
	
					$sql_query = "UPDATE clubs SET photo=':photo:',photo_med=':photo_med:',photo_small=':photo_small:'
								  WHERE clb_id=".$clb_id;
					$GLOBALS["DB"]->values = $vals;
					$GLOBALS["DB"]->execute($sql_query);
					
				}//if
			
			}//if
			
		}//while
		endif;
		
		$totals["clubs"]++;
		
	}//while
	endif;
	
	$dir = opendir(DOC_ROOT."/temp");
	while($file = readdir($dir)){
		if(eregi("\.jpg$",$file))
			@unlink(DOC_ROOT."/temp/".$file);
	}//while
	closedir($dir);
	
	$report = "Members: ".$totals["members"]."<br>".
	"Photos: ".$totals["photos"]."<br>".
	"Blogs: ".$totals["blogs"]."<br>".
	"Classifieds: ".$totals["classifieds"]."<br>".
	"Events: ".$totals["events"]."<br>".
	"Clubs: ".$totals["clubs"];

?>