Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > feedmelinks.com/funnel.php
<%
	# $Id: funnel.php,v 1.21 2005/01/02 21:07:03 hirokai Exp $
	$errorPage = "index";
	$shouldShowCreateEditForm = 1;
	$hotRow = -1;
	$shouldDump = 1;

	include_once( "modules/utils.inc.php" );
	$site = getSiteUrl();

	$tok =  $authenticated = $_COOKIE["c_pass_token"];
	$u   =  $sessionUserId = $_COOKIE["c_uid"];

	$MAX_COLS = 5;
	$BIG_FOLDER_LAYOUT_THRESH = 10;
	$bigLayout = 1;
	$rowsPerSmallColumn = 25;
	$hiddenColor = "#7FA288";

%>
<base href="<%= $site %>/funnel.php" />

<title> Feed Me Links : <%= $op == "change" ? getCatVerb() : "save" %> link </title>

<style type="text/css">
.invisitext {
	background-color: #<%= getBGColor() %>;
	border: 0px;
}
</style>


<% if( $debug ) { %>
	user is "<%= $u %>"<br />
<%
	}
	if( $tok && $tok == md5( getPasswdForUser( $u ))) {
		$noMenu = true;
		include( "$modules/header.inc.php" );


	if( $id || ( $url && $name && $name != "null" )) {
		$name = escapeQuotes( $name );

		if( $op == "change" && $id ) {
			$opVerb = "Categorizing";

			$li = getLinkInfo( $id );
			$name = $li['name'];
			$url = $li['url'];

			$rawCats = getCategoriesForLink( $id, $u );
			if( $debug ) {
				print "rawCats:<br />";
				print_r( $rawCats);
			}
			$hashcats = Array();

			if( $debug )
				echo "<br/> current " . getCatsName() . ":<br />";
			if( $rawCats && count( $rawCats ) ) {
				foreach( $rawCats as $cat ) {
					$hashcats[ $cat ] = 1;
					if( $debug )
						echo "DEBUG: adding existing " . getCatName() . " $cat to \$hashcats[]<br />";
				}
			} else {
				if( $debug )
					echo "no existing " . getCatsName() . " for link $id<br />";
			}
	} else {

			$opVerb = "Saving";
			# cruft from the old jm3.net redirect...
			$regex = "/^http%3A/";
			if( preg_match( $regex, $url )) {
				$url = urldecode( $url );
				$name = urldecode( $name );
			}
		}
		$con_funnel = mysql_connect( );
		mysql_selectdb( getDBName() );

		$qs = "SELECT * FROM linksGroups WHERE userId = '$u' ORDER BY name ASC;";
		if( $debug )
			echo "\$qs: $qs<br />";
		$q = mysql_query( $qs );
		if( $q )
			$numRows = mysql_num_rows($q);
		else if( $debug )
			echo "warning: DB query failed or no " . getCatsName() . " found in DB!<br />";
%>
<center>

<div class="head" style="margin-bottom: 0.5em;">
<% if( $ref != "" ) {

	preg_match("/http:\/\/([^\/]+)\//", $ref, $matches );
	$domain = $matches[1];
%>
Link came from: <a href="<%= $ref %>"><%= $domain %></a>.
or, edit the referrer: <input name="referrer" value="<%= $domain %>" />
<% } %>
</div>
	<form style="margin: 0px;" action="<%= $op == "change" ? "/action" : "/submit-link" %>" name="funnelForm" method="post">

	<script type="javascript">
		var f = document.forms['funnelForm'];
	</script>

<div class="attention" style="text-align: left; width: 626px; margin-bottom: 14px; padding: 8px;">
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td width="526" valign="top">
				<h3><%= $opVerb %> <a style="text-decoration: underline" target="_blank" href="<%= $url %>"><%= $name %></a>:</h3>
				<h2>Choose which <%= getCatsName() %> apply to this link,</h2>
				or, <b>type the name of a new <%= getCatName() %></b>: <input name="new_tag" />
			</td>
			<td valign="top" width="100">
				<center>
					<p>
						<button class="default button" accesskey="S" style="height: 6em; width: 8em;" value="Save It!" onClick="submitLink();"><u>S</u>ave It!</button>
					</p>
					<p>
						<input type="button" class="button" value="Cancel" style="padding: 0px; margin: 0px; width: 8em;" onClick="history.go(-1);" />
					</p>
				</center>
			</td>
		</tr>
	</table>

		<input type="hidden" name="op" value="<%= $op == "change" ? "changeCategories" : "submit" %>" />
		<input type="hidden" name="debug" value="<%= $debug %>" />
		<input type="hidden" name="version" value="<%= $version ? $version : "pre_version" %>" />
<% if( $op == "change" ) { %>
		<input type="hidden" name="id" value="<%= $id %>" />
<% } else { %>
		<input type="hidden" name="from" value="<%= $from ? $from : "funnel" %>" />
		<!-- TODO: what is this linkName field? -->
		<input type="hidden" name="linkName" value="<%= $name %>" />
		<input type="hidden" name="name" value="<%= $name %>" />
		<input type="hidden" name="url" value="<%= $url %>" />
		<input type="hidden" name="ref" value="<%= $ref %>"  />
		<input type="hidden" name="loggedIn" value="<%= $loggedIn == "wasnt" ? "wasnt" : ""  %>" />
<% } %>
	</div>

<%
		if( $numRows ) {
			$catsRendered = 0;
%>
		<table cellspacing="0" cellpadding="8" border="0" width="650">
			<tr>
<%
			$categories = array();
			$count = 0;
			if( $debug ) echo "<p>($numRows " . getCatsName() . ")</p>";
			while( $count < $numRows ) {
				$idx         = $catsRendered; # $i*$rows+$j;
				$id         = mysql_result($q, $idx, "ID");
				$options    = mysql_result($q, $idx, "options");
				$catName = makeSafeName( mysql_result($q, $idx, "name"));
				$public = 0;
				if( isPublic( $catName )) {
					$catName = makePrettyFolderName( $catName );
					++$public;
				}
				$categories[$count] = array( $catName, $options, $id, $public );
				$catsRendered++;
				$count++;
			}
			conClose( $con_funnel );
			$catsRendered = 0;
			$i = 0;
			sort( $categories );
			if( $numRows > $BIG_FOLDER_LAYOUT_THRESH ) {
				$bigLayout = 0;
				$rowsPerSmallColumn = ($numRows / 3) + 1;
			}

			if( !$bigLayout ) { %>

<style type="text/css">
.l { height: 1.6em; }
</style>

<%
			}

			foreach( $categories as $key=>$category ) {

				if( $bigLayout ) {

					# calculate how the rows should be set up
					$rows = $cols = round( sqrt($numRows + 1) );
					if( $cols != sqrt($numRows + 1) )
						$cols++;
					if( $rows > $MAX_COLS )
						$rows = $cols = 5;

					if( $catsRendered % $rows  == 0)
						echo "</tr><tr>";

				} else {
						if( $catsRendered % $rowsPerSmallColumn == 0 )
							echo "</td><td class='funnelTD' valign='top'>";
				}

				if( $catsRendered < $numRows ) {

					$idx        = $catsRendered; # $i*$rows+$j;
					$id         = $category[2];
					$options    = $category[1];
					$catName = $category[0];
					$public     = $category[3];
					$alreadySelected = $hashcats[$id];

					# orig url:
					#
					# from=toolbar
					# op=submit
					# groupid=XXXX
					# name=asd
					# url=http%3A//feedmelinks.com/testing/categories.php%3Furl%3Dfoo
					# ref=
					# loggedIn=(wasnt ? or "")

					$cb = "<input type=\"checkbox\" name=\"cb$id\" onChange=\"cbpc($id)\" " . ($alreadySelected ? "checked" : "" )  . "/>"; #checkbox

					if( $bigLayout ) {

%>
<td class="funnelTD" height="45" align="center" valign="bottom">
	<%= $cb %>
	<a <%= $alreadySelected ? "class=\"hot\" " : "" %>href="javascript:pc(<%= $id %>);"><img src="<%= $public ? "img/big-tag-bice" : "img/big-tag-private-bice" %>.gif" border="0" /><br />
	<b><%= $catName %><%= $debug ? " ($id)" : "" %></b></a><br />
</td>
<%
				} else {
%>
<div class="l">
<%= $cb %>
<a href="javascript:pc(<%= $id %>);"><img src="img/lil-tag<%= !$public ? "-private" : "" %>-bice.gif" align="absmiddle" border="0" /></a>
<a <%= !$public ? "style='color: $hiddenColor;'" : "" %> <%= $alreadySelected ? "class=\"hot\" " : "" %>href="javascript:pc(<%= $id %>);"><%=
	$catName %></a>
</div>
<%
				}
					$catsRendered++;
				} else if ( $catsRendered == $numRows ) {
					$catsRendered++;
%>
<%
				} else {
					echo "&nbsp;";
				} # end if( we should draw another link )
			} # end foreach

			if( $bigLayout ) {
%>
		</td>
		</tr>
		<tr>
		<td class="funnelTD" height="45" align="center" valign="bottom">

			<a href="/?op=submit&from=funnel&name=<%= urlencode( $name )
				%>&url=<%= urlencode( $url ) %><%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : ""  %>"><img 
				src="img/big-tag-private-bice" border="0" /></a><br />
			leave <a href="/?op=submit&from=funnel&name=<%= urlencode( $name )
					%>&url=<%= urlencode( $url ) %><%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : ""  %>"> <b><%= getUnCattedName() %></b></a><br />
		</td>
<% 
			} else {
%>
<div class="l">
<br />
or, leave this link <a href="/?op=submit&name=<%= 
	urlencode( $name ) %>&url=<%= urlencode( $url ) %>&from=funnel<%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : ""  %>"><%= getUnCattedName() %></a>.
</div>
<%
			}
%>
	</tr>
</table>

	<br />
	<button class="default" accesskey="S" style="padding: 3px;" value="Save It!" onClick="submitLink();"><u>S</u>ave It!</button>
	<input type="button" onClick="deselectAllCategories();" value="De-Select All Categories" class="button" />

</form>

<% if( !$bigLayout ) { %>
<p>
(private <%= getCatsName() %> are lighter)
</p>
<% } %>

</center>
<%
		} else {
%>
<div class="attention warning">
You appear to have no <%= getCatsName() %>.
</div>
<%
		}
	} else {
%>

<h2>This page is usually used with the <u>Feed Me Links</u> Button (or "Bookmarklet") to add links</h2>
(go <a href="/install">here</a> to get the <a href="/install">Bookmarklet</a>)
<p />

<br />
<form action="categorize" method="post">

<div class="attention" style="width: 50em;">

<table>
	<tr>
		<td>

			<table border="0">
				<tr>
					<td align="right">url:</td>
					<td><input name="url" value="<%= $url %>" size="30" maxlength="254" /></td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="right">name:</td>
					<td><input name="name" value="<%= $name %>" size="30" maxlength="127" /></td>
				</tr>
			</table>
			</td>
			<td>
	<input type="submit" class="default button" value="Save It!" />
	<p />
	<input type="button"  class="button" value="Cancel" onClick="history.go( -1 );" />
	</td></tr></table>
</div>

</form>

<%
	}
%>

<% include( "$modules/footer.inc.php" ); %>
<% } else {  #end auth %>

<% include( "login.php" ); %>

<% } %>
Return current item: FeedMeLinks, Social BookmarkingSince2002