Location: PHPKode > projects > Modular Site Manager > htdocs/inc/tutorials.inc.php
<?php
$getcat = $_GET['subsec'];
$getid = $_GET['id'];
if(!isset($_GET['subsec']) && !isset($_GET['id']))
{
	echo "Tutorial Sections:<br /><br />";
	$listcattut = $mysql->select(PRE."config", "section='tutorials' AND name='categories'", "id", "DESC", "1") or $mysql->error();
	echo '<ul>';
	for($i = 0; $i < mysql_num_rows($listcattut); $i++)
	{
		$l=mysql_fetch_array($listcattut);
		$expl = explode("~", $l['setting']);
		$expl2 = explode("~", $l['setting2']);
		$comb = array_combine($expl, $expl2);
		foreach($comb as $tuturl => $names)
		{
			$tutno = mysql_num_rows($mysql->select(PRE."tutorials", "cat='".$tuturl."'", "id"));
			echo "<li><a href=\"Tutorials/".$tuturl."/\">".$names." (".$tutno.")</a></li>";
		}
	}
	echo '</ul>';
}
if (isset($getcat) && !isset($getid))
{
	$listcattut = $mysql->select(PRE."config", "section='tutorials' AND name='categories'", "id", "DESC", "1") or $mysql->error();
	while($l=mysql_fetch_array($listcattut))
	{
		$expl = explode("~", $l['setting']);
		$expl2 = explode("~", $l['setting2']);
		$comb = array_combine($expl, $expl2);
		foreach($comb as $tuturl => $names)
		{
			echo "<a href=\"Tutorials/".$tuturl."/\">".$names."</a> &brvbar; ";
		}
	}
	echo "<a href=\"Tutorials/\">Tutorials Home</a><hr />";
	if(mysql_num_rows($mysql->select(PRE."tutorials", "cat='".$getcat."'", "id")) == "0")
	{
	echo "No tutorials yet";
} else {
	// Pagination crap..
	if(empty($_GET['view']) || !isset($_GET['view']))
	{
		$view = 1;
	} else {
		$view = $_GET['view'];
	}
	$limit = getuserinfo('pglimit');}
		if ($limit == 0)
		{
			$limit = 10;
		}
		$totalrows = mysql_num_rows($mysql->select(PRE."tutorials", "cat='".$getcat."'", "id"));
		$limitvalue = $view * $limit - ($limit);
		// end pagination crap
		echo "Tutorials:<br />";
		$tq = $mysql->select(PRE."tutorials", "cat='".$getcat."'", "id", "DESC", $limitvalue.",".$limit);
		$style = "row1";
		while($t=mysql_fetch_array($tq))
		{
			$link = "<a href=\"Tutorial/".$getcat."/".str_replace(array(' ', '+'), "_", urlencode($t['name']))."/\">";
			if(empty($t['link']))
			{
				$ext = "No";
			} else {
				$ext = "Yes";
			}
			if(empty($t['image']))
			{
				$image = "images/tutstuff/".$getcat.".gif";
			} else {
				$image = $t['image'];
			}
			$views = $t['views'];
			if($style == "row1")
			{
				$style = "row2";
			} else {
				$style = "row1";
			}
			echo "<div class=\"".$style."\" style=\"margin-top: 10px; margin-bottom: 10px; height: 125px; width: 100%;\">
			<div style=\"float: left; width: 75px; margin-right: 5px;\">
				".$link."<img src=\"".$image."\" style=\"border:none;\" alt=\"".$t['name']."\" /></a>
			</div>
			<div style=\"float: right; width: 85%;\">
			".$link.$t['name']."</a><br />
			Submitted on: ".date(DATE, $t['date'])."<br />
			Submitted by: ".$t['author']."<br />
			Difficulty: ".$t['level']."<br />
			Description: ".$t['descr']."<br />
			Is External?: ".$ext."<br />
			Views: ".$views."<br /><br />
			</div>
			</div>";
		}
		// More pagination crap..
		echo '<div style="font-weight:bold;text-align:center;">';
		if($view != 1)
		{
			$pageprev = $view-1;
			echo '<a href="Tutorials/'.$_GET['subsec'].'/'.$pageprev.'/">&lt;&lt;</a> ';
		}
		$numofpages = $totalrows / $limit;
		for($i = 1; $i <= $numofpages; $i++)
		{
			if($i == $view)
			{
				echo $i." ";
			} else {
				echo '<a href="Tutorials/'.$_GET['subsec'].'/'.$i.'/">'.$i.'</a> ';
			}
		}
		if(($totalrows % $limit) != 0)
		{
			if($i == $view)
			{
				echo $i.' ';
			} else {
				echo '<a href="Tutorials/'.$_GET['subsec'].'/'.$i.'/">'.$i.'</a> ';
			}
		}
		if(($totalrows - ($limit * $view)) > 0)
		{
			$pagenext = $view+1;
			echo '<a href="Tutorials/'.$_GET['subsec'].'/'.$pagenext.'/">&gt;&gt;</a>';
		}
		echo '</div>';
		// end more pagination crap
}
if(isset($getcat) && isset($getid))
{
	$listcattut = $mysql->select(PRE."config", "section='tutorials' AND name='categories'", "id", "DESC", "1");
	$l=mysql_fetch_array($listcattut);
	$expl = explode("~", $l['setting']);
	$expl2 = explode("~", $l['setting2']);
	$comb = array_combine($expl, $expl2);
	foreach($comb as $tuturl => $names)
	{
		echo "<a href=\"Tutorials/".$tuturl."/\">".$names."</a> &brvbar; ";
	}
	echo "<a href=\"/Tutorials/\">Tutorials Home</a><hr />";
	$tqr = $mysql->select(PRE."tutorials", "cat='".$getcat."' AND name='".str_replace('_', " ", $_GET['id'])."'", "id", "DESC", "1");
	$tr = mysql_fetch_array($tqr);
	$check = $tr['link'];
	$vpone = $tr['views']+1;
	$id = $tr['id'];
	if(!isset($_COOKIE['tut-'.$id]))
	{
		setcookie("tut-".$id, "viewed", time()+604800);
		$mysql->update(PRE."tutorials", "views='".$vpone."'", "id='".$id."'");
	}
	if($check !== "")
	{
		header("Location: ".$check);
	}
	$tutfile = SITE_PATH."tutorials/".$getcat."-".$id.".php";
	if (!is_file($tutfile)){
		echo "Tutorial doesn't exist";
	} else {
		$ckuser2 = mysql_num_rows($mysql->select(PRE."members", "username='".$tr['author']."'", "id", "DESC", "1"));
		if($ckuser2 > 0)
		{
			$author = '<a href="Members/Profile/'.str_replace(" ", "_",$tr["author"]).'/">'.$tr['author'].'</a>';
		} else {
			$author = $tr['author'];
		}
		echo "<strong>".$tr['name']."</strong> by <em>".$author."</em>. <br />Toughness: ".$tr['level']."<hr style=\"width: 60%;\" />";
		include_once($tutfile);
		echo "<hr style=\"width: 75%;\" /><div style=\"margin-top: 10px;\">";
		$tc['query'] = $mysql->select(PRE."tuts_comments", "tutid='".$id."'", "postid", "ASC");
		$tc['rows'] = mysql_num_rows($tc['query']);
		if(!$tc['rows'])
		{
			echo("No comments yet!");
		} else {
			if($tc['rows'] == "1"){
				$a = array("is", "comment");
			} else {
				$a = array("are", "comments");
			}
			echo 'There '.$a["0"].' '.$tc["rows"].' '.$a["1"];
			unset($i);
			for($i = 0; $i < $tc['rows']; $i++)
			{
				$tcom=mysql_fetch_array($tc['query']);
				$email = explode("@", $tcom['email']);
				if(mysql_num_rows($mysql->select(PRE."members", "username='".$tcom['username']."'", "id")) == "0")
				{
					$name = '<a href="javascript:email(\''.$email[0].'\',\''.$email[1].'\');">'.$tcom["username"].'</a>';
				} else {
					$name = '<a href="Members/Profile/'.str_replace(" ","_",$tcom["username"]).'/">'.$tcom["username"].'</a>';
				}
				$message = parse($tcom['message']);
				$date = date(DATE , $tcom['date']);
				$id = $tcom['id'];
				if($i % 2) { //this means if there is a remainder
					$style = "row2";
				} else { //if there isn't a remainder we will do the else
					$style = "row1";
				}
				echo "<div class=\"".$style."\" style=\"margin-top: 5px; float: left; width: 100%;\">
					  <div style=\"width: 15%; float: left;\">".$name."<br />
						  ".$date."</div>
					  <div style=\"width: 80%; float: right;\">".$message."</div>
				  </div>";
			}
		}
		echo '<hr style="float: left;width: 95%;" /><form method="post" action="misc/tut-comment-in.php">
		  <div style="float:left">Post a Comment.</div>';
		if(!isset($_COOKIE['mid']))
		{
			echo "<div class=\"formtext\">Username</div>
				<div class=\"formdiv\"><input name=\"username\" type=\"text\" /></div>
				<div class=\"formtext\">Email</div>
				<div class=\"formdiv\"><input name=\"email\" id=\"email\" /></div>";
		} else {
			echo '<div><input type="hidden" name="username" value="'.$_COOKIE["user"].'" /><input type="hidden" name="email" value="'.getuserinfo("email").'" /></div>';
		}
		echo "<div style=\"text-align: right; width:15%; float:left; padding-top: 3px;\">Message<br /></div><div style=\"float: right; width:80%;\"><textarea name=\"message\" class=\"wysiwyg\" cols=\"60\" rows=\"14\"></textarea></div>
		<div style=\"float: left; width:100%; text-align: center;\">
			<input name=\"id\" type=\"hidden\"  value=\"".$id."\" />
			<input type=\"submit\" name=\"Submit\" value=\"Submit\" />
			<input type=\"reset\" name=\"Reset\" value=\"Reset\" />
		</div>
		</form></div>";
		if(isset($_GET['cerror']))
		{
			echo '<div class="error">Error: You skipped some info. Please fill it all out</div>';
		}
	}
}
?>
Return current item: Modular Site Manager