View file wip-site-portal/src/photos.php

File size: 8.51Kb
<?
require('ini.php');
$link=connect();

@$mod=$_GET['mod'];
@$uid=intval($_GET['uid']);

$user=login('nick, plim');

mysql_query("UPDATE `wip_users` SET `loc`='photo' WHERE `id`='".$user['id']."';");

$select=mysql_query("select nick from wip_users where id='$uid';");
		if(mysql_affected_rows()<1){
			head('Ошибка');
			echo '<small>Неверный юзер!<br/><anchor>Назад<prev/></anchor></small>';
			foot();
			exit();
		}
$us_res=mysql_fetch_assoc($select);

		
head('Фотографии '.$us_res['nick']);

switch($mod){
	
	default:
		echo '<small>';
		echo '<b>Фотоальбомы '.$us_res['nick'].':</b><br/>';
		echo '---<br/>';	
		$select=mysql_query("select * from wip_photos_albums where uid='$uid' order by id;");
		if(mysql_affected_rows()<1){
			echo 'У '.$us_res['nick'].' нет фотоальбомов<br/>';
		}
		
		else {
			while($res=mysql_fetch_assoc($select)){
				$p=mysql_fetch_row(mysql_query("select count(id) from wip_photos_photos where aid='$res[id]' and uid='$uid';"));
				echo '<a href="photos.php?sid='.$sid.'&amp;mod=photos&amp;uid='.$uid.'&amp;aid='.$res['id'].'">'.$res['name'].' ['.$p[0].']</a><br/>';
				if($res['descr']) echo '<i>'.$res['descr'].'</i><br/>';
			}
			
		}
		echo '</small>';
		break;
		
	case 'photos':
		@$aid=intval($_GET['aid']);
		@$s=intval($_GET['s']);
		$plim=$user['plim'];
		
		$select=mysql_query("select name from wip_photos_albums where id='$aid' and uid='$uid';");
		if(mysql_affected_rows()<1){
			echo '<small>Неверный фотоальбом!</small><br/>';
			break;
		}
		$album=mysql_fetch_row($select);
		
		if (!$s or $s<=0) $s=1;
		$all=mysql_fetch_row(mysql_query("select count(id) from wip_photos_photos where aid='$aid' and uid='$uid';"));
		$pgs=ceil($all[0]/$plim);
		if($s>$pgs) $s=$pgs;
		$n=($s-1)*$plim;
		
		echo '<small>';
		echo 'Альбом: <b>'.$album[0].'</b><br/>';
		echo 'Фотографий: '.$all[0].'<br/>';
		echo '---<br/>';
		
		if($all[0]<1){
			echo 'Альбом пуст!<br/>---<br/>';
		}
		
		else {
			$select=mysql_query("select id,name,time,votes,file from wip_photos_photos where aid='$aid' and uid='$uid' limit $n,$plim;");
			
			while($res=mysql_fetch_assoc($select)){
				echo '<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$res['id'].'"><img src="thumbs/'.$res['file'].'.jpg" alt="photo"/></a><br/>';
				echo '<b>Название:</b> '.$res['name'].'<br/>';
				echo '<b>Рейтинг:</b> '.$res['votes'].'<br/>';
				echo '---<br/>';
			}
			
			//Список страниц
			if ($all[0]>$plim){
				if ($pgs>3 and $s>2){
					echo '<a href="photos.php?sid='.$sid.'&amp;aid='.$aid.'&amp;uid='.$uid.'&amp;mod=photos&amp;s=1">1</a>...';
				}
				$beg=$s-1; $end=$s+1;
				if ($end>$pgs+1){
					$end=$pgs; $beg=$beg-2;
				}
				elseif ($end>$pgs){
					$end=$pgs; $beg=$beg-1;
				}
			
				for($m=$beg;$m<=$end;$m++){
					if ($m<=0){
						$end++;
					}
					
					else{
						if($m==$s){
							echo '<b>'.$m.'</b>';
						}
						else{
							echo '<a href="photos.php?sid='.$sid.'&amp;aid='.$aid.'&amp;uid='.$uid.'&amp;mod=photos&amp;s='.$m.'">'.$m.'</a>';
						}
			
						if($m!=$end){
							echo '-';
						}
					}
				
					if ($end>$pgs) $end=$pgs;
				}
			
				if ($pgs>3 and $s<=($pgs-2)){
					echo '...<a href="photos.php?sid='.$sid.'&amp;aid='.$aid.'&amp;uid='.$uid.'&amp;mod=photos&amp;s='.$pgs.'">'.$pgs.'</a>';
				}
			
				echo '<br/>---<br/>';
			}
			/////
			
		}
		
		echo '</small>';
		break;
		
	case 'photo':
		@$pid=intval($_GET['pid']);
		@$s=intval($_GET['s']);
		@$vote=$_GET['vote'];
		
		$select=mysql_query("select id, name, descr, time, votes, aid, file, votes_id from wip_photos_photos where uid='$uid' and id='$pid';");
		if(mysql_affected_rows()<1){
			echo '<small>Неверная фотография!</small><br/>';
			break;
		}
		$res=mysql_fetch_assoc($select);
		
		if($vote/* and $uid!=$user['id']*/){
			if($vote=='plus') $vt='+1';
			elseif($vote=='minus') $vt='-1';
			else $vt=false;
			
			if(stristr($res['votes_id'],';'.$user['id'].';')) echo '<small><b>Вы уже голосовали за эту фотографию!</b><br/>---<br/></small>';
			else {
				if($vt){
					$votes_id=false;
					if(!$res['votes_id']) $res['votes_id']=';';
					$votes_id=$res['votes_id'].$user['id'].';';
					mysql_query("update wip_photos_photos set votes=votes$vt, votes_id='$votes_id' where id='$pid';");
					echo '<small><b>Голос принят!</b><br/>---<br/></small>';
					$select=mysql_query("select id, name, descr, time, votes, aid, votes_id from wip_photos_photos where uid='$uid' and id='$pid';");
					$res=mysql_fetch_assoc($select);
				}
			}
		}
		
		
		
		echo '<small>';
		echo '<a href="photos/'.$res['file'].'.jpg"><img src="thumbs/'.$res['file'].'.jpg" alt="photo"/></a><br/>';
		echo '<b>Дата:</b> '.date('d.m.Y H:i',$res['time']).'<br/>';
		echo '<b>Название:</b> '.$res['name'].'<br/>';
		echo '<b>Описание:</b> '.$res['descr'].'<br/>';
		echo '<b>Рейтинг:</b> '.$res['votes']; 
		if($user['id'] != $uid and !stristr($res['votes_id'],';'.$user['id'].';')) echo '[<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'&amp;vote=plus">+</a>/<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'&amp;vote=minus">-</a>]';
		echo '<br/>---<br/>';
		
		$clim=5;
		
		echo 'Комментарии:</small><br/>';
		echo '<input name="msg'.$ref.'" type="text" maxlength="300"/> ';
		echo '<small><anchor>Добавить<go href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'" method="post">';
		echo '<postfield name="msg" value="$(msg'.$ref.')"/>';
		echo '</go></anchor><br/>---<br/>';
		
		if(@$_POST['msg']){
			if(@$_POST['msg']){
	
	
			$msg=htmlspecialchars($_POST['msg'],ENT_QUOTES);
			$msg=str_replace('$','$$',$msg);
			
			mysql_query("select id from wip_photos_comments where pid='$pid' and uid='$user[id]' and msg='$msg';");
			if(mysql_affected_rows()<1){
					mysql_query("insert into wip_photos_comments set pid='$pid', uid='$user[id]', time='".time()."', msg='$msg';");
				}
			}
		}
		
		if (!$s or $s<=0) $s=1;
		$all=mysql_fetch_row(mysql_query("select count(id) from wip_photos_comments where pid='$pid' and uid='$uid';"));
		$pgs=ceil($all[0]/$clim);
		if($s>$pgs) $s=$pgs;
		$n=($s-1)*$clim;
		
		if($all[0]<1) echo 'Комментариев нет<br/>';
		else {
			
			$select=mysql_query("SELECT `u`.`id` AS `uid`, `u`.`nick`, `c`.`msg`, `c`.`time` FROM `wip_users` AS `u`, `wip_photos_comments` AS `c` WHERE `u`.`id`=`c`.`uid` AND `c`.`pid`='".$pid."' ORDER BY `c`.`id` DESC LIMIT ".$n.",".$clim.";");
			while($cres=mysql_fetch_assoc($select)){
				if($cres['uid'] == $user['id']) echo '<b>['.$cres['nick'].']</b>';
				else echo '<b>[<a href="user.php?sid='.$sid.'&amp;uid='.$cres['uid'].'">'.$cres['nick'].'</a>]</b>';
				
				echo ', '.date('d.m.y H:i',$cres['time']).'<br/>'.$cres['msg'].'<br/>';
			}
			
			//Список страниц
			if ($all[0]>$clim){
				echo '---<br/>';
				
				if ($pgs>3 and $s>2){
					echo '<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'&amp;s=1">1</a>...';
				}
				$beg=$s-1; $end=$s+1;
				if ($end>$pgs+1){
					$end=$pgs; $beg=$beg-2;
				}
				elseif ($end>$pgs){
					$end=$pgs; $beg=$beg-1;
				}
			
				for($m=$beg;$m<=$end;$m++){
					if ($m<=0){
						$end++;
					}
					
					else{
						if($m==$s){
							echo '<b>'.$m.'</b>';
						}
						else{
							echo '<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'&amp;s='.$m.'">'.$m.'</a>';
						}
			
						if($m!=$end){
							echo '-';
						}
					}
				
					if ($end>$pgs) $end=$pgs;
				}
			
				if ($pgs>3 and $s<=($pgs-2)){
					echo '...<a href="photos.php?sid='.$sid.'&amp;mod=photo&amp;uid='.$uid.'&amp;pid='.$pid.'&amp;s='.$pgs.'">'.$pgs.'</a>';
				}
			
				echo '<br/>';
			}
			/////
			
		}
		
		echo '</small>';
		break;
		
}


echo '<small>';
if($mod!='photos') echo '---<br/>';
if($mod=='photo') echo '<a href="photos.php?sid='.$sid.'&amp;mod=photos&amp;uid='.$uid.'&amp;aid='.$res['aid'].'">Альбом</a><br/>';
if($mod) echo '<a href="photos.php?sid='.$sid.'&amp;uid='.$uid.'">Фотоальбомы '.$us_res['nick'].'</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a>';
echo '</small>';

foot();

mysql_close($link);
?>