Location: PHPKode > scripts > Usenet Downloader > usenet-downloader/save_group_info.php
<?
set_time_limit(0);

include_once("config.inc.php");

class GetNNTPGroups
	{
		function GetGroups()
			{
				$select_str="SELECT * FROM mp_usenet_servers WHERE name!='localhost' ORDER BY RAND()";
				$result1=mysql_query($select_str);
				
				$unreachable_list=array();
				while($row=mysql_fetch_assoc($result1))
					{
						$groups=array();
						$server=$row['name'];
						$server_id=$row['id'];
						$nntp=ConnectToServer($server);
						if(!$nntp)
							{
								if($row['is_searched']=='0')$unreachable_list[]=$server_id;													
								continue;
							}
						else $groups=$nntp->getgroups();
		
						$group_count=0;
						for($count=0;$count<count($groups);$count++)
							{			 
						  		$name=$groups[$count]['name'];
						  		
						  		if($name=='')continue;				  						  		
								
						  		if($groups[$count]['first']==0&&$groups[$count]['last']==0)continue;
						  		
						  		$is_readonly=($groups[$count]['readonly']!='')?1:0;
						  						  		
						  		$select_str="SELECT * FROM mp_usenet_groups WHERE name='".mysql_escape_string($name)."'";
						  		$result=mysql_query($select_str);
						  		if(mysql_num_rows($result)>0)
						  			{
						  				$row=mysql_fetch_assoc($result);
						  				$group_id=$row['id'];
						  				if($row['article_count']==0)
							  				{
								  				$update_str="UPDATE mp_usenet_groups SET is_searched=0,server_id=CONCAT(server_id,',','".$server_id."') WHERE id=".$group_id." AND FIND_IN_SET('".$server_id."',server_id)<=0";
								  				if(mysql_query($update_str))$group_count++;
								  				echo $update_str."<br/>";
								  				flush();
							  				}
						  			}				  		
						  		else 
						  			{
						  				$encoding=(strpos($server,".ru")===false&&strpos($server,".rus")===false)?'UTF-8':'KOI8-R';
						  				$insert_str="INSERT INTO mp_usenet_groups(server_id,name,description,language,encoding,article_count,is_readonly,is_searched,member_id,created_on) VALUES('".$server_id."','".mysql_escape_string($name)."','','','".$encoding."',0,".$is_readonly.",0,-1,'".$created_on."')";
						  				if(mysql_query($insert_str))$group_count++;
						  				echo $insert_str."<br/>";
						  				flush();	  		
						  			}
							}
						$created_on=date('Y-m-d H:i:s',time());
						$update_str="UPDATE mp_usenet_servers SET is_searched=1, group_count=0,created_on='".$created_on."' WHERE id=".$server_id;
						mysql_query($update_str);
					}
				for($count=0;$count<count($unreachable_list);$count++)
					{	
						$server_id=$unreachable_list[$count];
						$update_str="UPDATE mp_usenet_servers SET is_searched=-1,created_on='' WHERE id=".$server_id;
						mysql_query($update_str);
					}
			}
	}			
?>
Return current item: Usenet Downloader