<?
class fol{
	function fol(){
	global $db;	
	global $ses;	
	global $pal;		
	$this->db=$db;
	$this->ses=$ses;
	$this->pal=$pal;	
	$this->folArr=array(
	'sport'=>array('Sports','s_id'),
	'country'=>array('Countries','country_id'),
	'league'=>array('Leagues','l_id'),
	'team'=>array('Teams','t_id'),
	'player'=>array('Players','p_id'),
	'game'=>array('Games','g_id'),
	'user'=>array('Users','u_id')

	);
	$this->relType=array(1=>'sport',2=>'country',3=>'league',4=>'team',5=>'player',6=>'game',7=>'user');
	$this->viewRelType=array(1=>'Sport',2=>'Location',3=>'League',4=>'Team',5=>'Player',6=>'Game',7=>'User');
	}


	
	
	
	function userFolWhat(){
	$back=array();
	$fol=$this->db->selectJ('*','u_fol','tags','tags.tag_id=u_fol.tagID','','',' WHERE uID=\''.$this->ses->getSesVar('uID').'\'',' ORDER BY tags.name');	
		if($fol!=false){
			foreach($fol as $i=>$v){
			$back[]=array($fol[$i]['tag_id'],$fol[$i]['name'],$fol[$i]['type'],$fol[$i]['real_id']);
			}
		}
	return $back;
	}
	
	
	function getFolPosts(){	
	$backP='';
		foreach($_SESSION['folWhom'] as $i=>$v){
		$backP.=' OR posts.u_id='.$v[0];
		}
	$where='WHERE (posts.u_id=0 '.$backP.')';
	return  $this->db->selectJ('posts.*,post_tag.tagID,sb_u.name as fName,sb_u.img as uIMG, sb_u.l_name as lName','posts ',' post_tag',' post_tag.postID=posts.post_id','sb_u','sb_u.u_id=posts.u_id',$where,'  ORDER BY posts.updated DESC LIMIT 0,1000' );
	}
	
	
	
	

	
	
	
/*	/// folFor Edit NO NEED
	function folForEdit(){
	$r=$this->userFol();
	$back='';
		foreach ($this->folArr as $i=>$v){
		$all=''; $news=''; $use='';
			if($r[$i]['def']=='1'){$all=' checked="checked"';}
			elseif($r[$i]['def']=='2'){$news=' checked="checked"';}
			if($r[$i]['def']=='3'){$use=' checked="checked"';}
		$defRadio='<div id="defRadio"><input type="radio" name="'.$i.'Def" id="'.$i.'All" value="1" '.$all.' /><label for="'.$i.'All">All</label>
		<input type="radio" name="'.$i.'Def" id="'.$i.'News"  value="2" '.$news.' /><label for="'.$i.'News">Updates & News Only</label><input type="radio" name="'.$i.
		'Def" id="'.$i.'Use"  value="3" '.$use.' /><label for="'.$i.'Use">Users\' Only</label></div>';
			$count1=0;
			$qWhere='';
			if(!empty($r[$i]['some'] )){
				foreach ($r[$i]['some'] as $i2=>$v2){
						if($count1>0){ $qWhere.=' OR ';}
						$qWhere.=' '.$v[1].'='.$v2;
					$count1++;					
				}		
			}
		$checked='';
		$tbl=$this->db->select('*',$i,' WHERE '.$qWhere.' ',' LIMIT 0,'.$count1.'');
			if($tbl!=false){
				foreach($tbl as $i3=>$v3){
					if($i=='player'){$objName=' '.$tbl[$i3]['fName'].' '.$tbl[$i3]['lName'];}
					else{$objName=' '.$tbl[$i3]['name'];}
				$checked.='<span id="'.$i.$tbl[$i3][$v[1]].'Span" onclick="unCheckMe(\''.$i.$tbl[$i3][$v[1]].'\');"><div class="FL150"><div class="custom-checkbox"><input id="
				'.$i.$tbl[$i3][$v[1]].'" name="'.$i.'" value="'.$tbl[$i3][$v[1]].'" class="designed" checked="checked" type="checkbox"><label class="checked" 
				for="'.$i.$tbl[$i3][$v[1]].'">'.$objName.'</label></div></div></span>';
				}
			}
			else{}
		$back.=' '?>
        <div><h3 tabindex="0" aria-selected="true" aria-expanded="true" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-state-active 	
        ui-corner-top"><span class="ui-icon ui-icon-triangle-1-s"></span><a tabindex="-1" href="#"><?=$v[0]?></a></h3><div role="tabpanel" style="height:14px;" class=
        "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active"> Choose <?=$v[0]?>:<br />
		<input class="fSearch" name="stamName" id="fs<?=$v[0]?>" onkeyup="autoComp(this.id);" type="text">&nbsp;<div class="fsOptions" id="fs<?=$v[0]?>Div"></div>
        <div id="<?=$i?>FolDiv" class="slectedObjDiv"><?=$checked?></div><div class="FR">Default view: <span class="f10">(select what type of posts you'll view)</span>
        <br /><?=$defRadio?></div><div id="saves"><input type="button" value="save" name="<?=$i?>" class="savesBut" /></div></div></div><? '';
		}
	}
*/	
	
}



/*	

	function OLD getFolPosts(){	
	$backP='';
		foreach($_SESSION['folWhom'] as $i=>$v){
		$backP.=' OR posts.u_id='.$_SESSION['folWhom'][$i][0];
		}
	$where='WHERE (posts.u_id=0 '.$backP.')'; //AND ('.$backW.') 
	return $this->db->selectJ('posts.*,post_rel.*,sb_u.name as fName,sb_u.img as uIMG, sb_u.l_name as lName, post_rel.type as rType','posts ',' post_rel',' post_rel.post_id=posts.post_id','sb_u','sb_u.u_id=posts.u_id',$where,'  ORDER BY posts.updated DESC LIMIT 0,1000' );
	}
/// create follow tags for posts

function convFol(){
	$u=$this->db->select('post_id','posts','',' ');	
		foreach($u as $i=>$v){
		$count=0;
			while($count<7){
			$rand=rand(1,31);
			$ins=$this->db->insert('post_tag','postID,tagID','"'.$u[$i]['post_id'].'","'.$rand.'"');		
			echo $u[$i]['post_id'].'-'.$count.'-'.$rand;
			if($ins==true){echo '-OK<br />';}
			else {echo '-NOT<br />';}
			$count++;
			}
		}
	
	}
	
*/


/*	
////NO NEED
function userFol(){
	$back=array();
	$fol=$this->db->select('*','fol',' WHERE u_id=\''.$this->ses->getSesVar('uID').'\'',' LIMIT 0,1');	
		if($fol!=false){
			foreach($this->folArr as $i=>$v){
				if(strlen($fol[0][$i])==1){$back[$i]=array('def'=>$fol[0][$i]);}
				else{
				$tmpArr=explode(',',$fol[0][$i]);
				$back[$i]=array('def'=>$tmpArr[0]);
				$back[$i]['some']=array();				
					foreach($tmpArr as $ii=>$vv){
					if ($ii!=0){array_push($back[$i]['some'],$tmpArr[$ii]);}				
					}
				}
			}
		}
	return $back;	
	}
	*/



/*	function updateTag(){
	
		foreach($this->relType as $i=>$v){
			$fol=$this->db->select('*',$v,'','');
			foreach($fol as $ii=>$vv){
				if($v=='player'){$name=$fol[$ii]['fName'].' '.$fol[$ii]['lName'] ;}
				else {$name=$fol[$ii]['name'];}
			$this->db->insert('tags','name,type,real_id', '"'.$name.'","'.$i.'","'.$fol[$ii][$this->folArr[$v][1]].'"' );
			
			
			}
		
		}
	
	
	}
	*/
?>