"Tofu_Session", "auth" => "Tofu_Default_Auth", "perm" => "Tofu_Perm", "user" => "Tofu_User") ); function edit($row) { echo "
\n"; echo "\n"; // contributor echo "\n"; echo " \n"; if ($GLOBALS['perm']->have_perm('admin')) { if (! empty($row['restaurant_contributor_id'])) { echo " \n"; } else { echo " \n"; } } else { echo " \n"; } echo "\n\n"; // name echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // phone echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // address echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // city echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // state echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // zip echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // country echo "\n"; echo " \n"; /* echo " \n"; */ echo " \n"; echo "\n\n"; // url echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // ethnicity echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // vegetarian factor echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // vegan factor echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // chain echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; if (empty($row['restaurant_date_added']) ) { $date = date('Ymd'); echo " \n"; } // submit echo "\n"; echo " auth["tofu_id"]; echo "\">\n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; echo " \n"; echo "\n\n"; echo "
Contributor:" . $row['restaurant_contributor_id'] . "" . $GLOBALS['auth']->auth['uname'] . "" . $GLOBALS['auth']->auth['uname'] . "
Restaurant Name:
Phone:
Address:
City:
State:
Zip Code:
Country:
URL:
Style:
Vegetarian Factor:
Vegan Factor:
Chain:
\n"; echo "
\n"; } function load($id) { if (! is_numeric($id)) { return ''; } $query ="select restaurant.id as restaurant_id, restaurant.contributor_id as restaurant_contributor_id, restaurant.name as restaurant_name, restaurant.phone as restaurant_phone, restaurant.address as restaurant_address, restaurant.city as restaurant_city, restaurant.state as restaurant_state, restaurant.zip as restaurant_zip, restaurant.country as restaurant_country, restaurant.url as restaurant_url, restaurant.date_added as restaurant_date_added, restaurant.date_updated as restaurant_date_updated, restaurant.vegetarian_id as restaurant_vegetarian_id, restaurant.vegan_id as restaurant_vegan_id, restaurant.chain_id as restaurant_chain_id, restaurant.ethnicity_id as restaurant_ethnicity_id from restaurant left join ethnicity on restaurant.ethnicity_id = ethnicity.id where restaurant.id = $id"; $res = run_query($query); return mysql_fetch_array($res); } function view($view, $id, $search_parms) { global $db_tofu; $valid_parms = array ('ethnicity_id' => 1, 'vegetarian_id' => 1, 'vegan_id' => 1, 'state' => a ); $query = "select restaurant.id, DATE_FORMAT( restaurant.date_updated, '%M %D, %Y') as date_updated, DATE_FORMAT( restaurant.date_added, '%M %D, %Y') as date_added, restaurant.name, restaurant.address, restaurant.city, restaurant.state, restaurant.zip, restaurant.country, restaurant.phone, restaurant.url, restaurant.chain_id, restaurant.ethnicity_id, restaurant.contributor_id, user.login as contributor_login, ethnicity.name as ethnicity, vegetarian.name as vegetarian, vegan.name as vegan from restaurant, ethnicity, vegan, vegetarian, user where restaurant.ethnicity_id = ethnicity.id and restaurant.vegetarian_id = vegetarian.id and restaurant.vegan_id = vegan.id and restaurant.contributor_id = user.id "; for(reset($search_parms); $parm=key($search_parms); next($search_parms)) { if ($valid_parms[$parm] == 1) { if (is_numeric($search_parms[$parm])) { $query .= " and restaurant.$parm = '$search_parms[$parm]'\n"; } } elseif ($valid_parms[$parm] == 'a') { if (strlen($search_parms[$parm]) == 2) { $query .= " and restaurant.$parm = '$search_parms[$parm]'\n"; } } else { err("Rejecting $parm = $search_parms[$parm]"); unset($search_parms[$parm]); } } if (is_numeric($id)) { $query .= "\n and restaurant.id = $id "; } if ($GLOBALS['sort']) { $query .= "\n order by " . $GLOBALS['sort']; } else { $query .= "\n order by country, state, city, name\n"; } $res = run_query($query); #restaurant_search_form(); if ($view == 'long') { while ($db_tofu->next_record()) { longView($db_tofu->Record); } } else { echo "
\n"; while ($db_tofu->next_record()) { compactView($db_tofu->Record); } echo "
"; } } function show_reviews($restaurant_id, $reviewer_id='', $chain_id='') { $query = "select review.id as review_id, review.rank as review_rank, DATE_FORMAT( review.date_updated, '%M %D, %Y') as review_date_updated, review, review.date_updated, user.name, user.id as user_id, user.login, user.email from review left join user on review.user_id = user.id where "; if (is_numeric($chain_id)) { if ($chain_id > 0) { $query .= " review.chain_id = $chain_id or "; } } $query .= " review.restaurant_id = $restaurant_id "; if (is_numeric($reviewer_id)) { $query .= "and\n review.user_id = " . $reviewer_id; } $query .= "\norder by review.date_updated desc"; $res = run_query($query); echo "

Reviews

\n

\n"; while ($row = mysql_fetch_array($res)) { echo ""; echo "{$row['login']}\n"; echo "{$row['review_date_updated']}\n"; if ($row['review_rank'] > 0) { echo "({$row['review_rank']})"; } if (($row['user_id'] == $GLOBALS['auth']->auth['tofu_id']) || ($GLOBALS['perm']->have_perm('admin')) ) { echo "
"; echo ""; echo " Edit review\n"; } echo "

\n{$row['review']}

\n\n"; } echo "

"; if ($reviewer_id) { echo "All reviewers | "; } echo "Add a review \n"; } function avgRank($restaurant_id) { if (! is_numeric($restaurant_id)) { return 0; } $query = "select count(*) as count, avg(rank) as avg from review where restaurant_id=$restaurant_id and rank > 0"; $res = run_query($query); while ($row = mysql_fetch_array($res)) { //echo "Of " . $row['count'] . " votes " . $row['avg'] . " is the average."; $avg = $row['avg']; } return $avg; } function longView($row) { global $db_tofu; echo "\n\n
"; echo "\n

{$row['name']} \n"; $avg = avgRank($row['id']); $avg -= .5; for ($i = 0; $i < $avg; $i++) { echo ""; } echo "

"; if (($row['contributor_id'] == $GLOBALS['auth']->auth['tofu_id']) || ($GLOBALS['perm']->have_perm('admin')) ) { echo "

"; echo ""; echo " Edit

"; } echo "

Fare
\n"; echo "{$row['ethnicity']}
\n"; echo $row['vegetarian'] . " Vegetarian
\n"; echo $row['vegan'] . " Vegan
\n"; echo "

\n"; echo "

Contact
\n"; echo $row['phone'] . "
\n"; echo $row['address'] . "\n
"; // $clean_city = lc($city); // $clean_city =~ s/[\s|\.]+//g; $clean_city = strtolower($row['city']); $clean_city = preg_replace("/\s|\./", "", $clean_city); // city echo "" . $row['city'] . " "; // state echo ", " . $row['state'] . " "; // country echo "" . $row['country'] . " "; echo $row['zip'] . "\n"; $map_url = "http://www.mapsonus.com/bin/maps-map/usr=~new/formName=mapsetaddr?" . "AddrStreetLine=" . urlencode($row['address']) . "&" . "AddrCity=" . urlencode($row['city']) . "&" . "AddrState=" . urlencode($row['state']) . "&" . "AddrZip=" . urlencode($row['zip']); echo "[Map]
\n"; if (! empty($row['url'])) { echo "URL: "; echo "" . $row['url'] . "\n"; } echo "

Submitted: {$row['date_added']} "; echo "by {$row['contributor_login']}
\n"; echo "Updated: {$row['date_updated']}

\n"; if (! empty($row['chain_id'])) { echo "

It's a chain.
\n"; print "

\n"; } echo "
\n"; $image_row = getImage('restaurant', $row['id']); if (! empty($image_row['name'])) { echo "\"{$image_row['alt_text']}\""; } else { $no_image = 1; } echo "
"; echo "
\n"; show_reviews($row['id'],$GLOBALS['reviewer_id'], $row['chain_id']); if ($no_image) { echo " | Add Image
"; } } function compactView($row) { static $count; if ($count++ < 1) { echo "\n"; echo "\n"; echo " Name\n"; echo " City\n"; echo " State\n"; echo " Country\n"; echo " Style\n"; echo " Vegetarian\n"; echo " Vegan\n"; echo " Edit\n"; echo "\n"; } echo "\n"; echo " $count\n"; // name echo " {$row['name']} \n"; // city $clean_city = strtolower($row['city']); $clean_city = preg_replace("/\s|\./", "", $clean_city); echo " {$row['city']}\n"; // state echo " {$row['state']} \n"; // country echo " {$row['country']} \n"; echo " {$row['ethnicity']} \n"; echo " {$row['vegetarian']} \n"; echo " {$row['vegan']} \n"; if (($row['contributor_id'] == $GLOBALS['auth']->auth['tofu_id']) || ($GLOBALS['perm']->have_perm('admin')) ) { echo "Edit\n"; } else { echo " \n"; } echo "\n"; } function footer() { echo "\n"; if ($GLOBALS['id']) { echo "
All |\n"; } echo "Long | "; echo "Compact |\n"; echo "Add Restaurant
"; echo "
\n"; } //--------- main program //if (!isset($title)) { $title = 'Restaurant'; } $tables = parse_tables(); if ($mode == 'edit') { $auth->login_if(! $perm->have_perm('user')); // make sure they own the restaurant or are an admin //print "user id is " . $GLOBALS['user']->auth['user_id']; if ($submit == 'Update') { if (($tables['restaurant']['contributor_id'] != $auth->auth['tofu_id']) and (! $perm->have_perm('admin')) ) { include("header.inc.php3"); echo "

It looks like you shouldn't be editing this. You currently can't update something another user posted. We hope to fix that soon. Thanks for trying. Why don't you tell us what needs changed?

"; print "
";
      var_dump($tables);
      print "
"; } else { $auth->login_if(! $perm->have_perm('user')); $new_id = update($tables); if (! empty($restaurant__id)) { header("Location: /restaurant.php3?view=long&id=$restaurant__id"); } else { header("Location: /restaurant.php3?view=long&id=$new_id"); } } } else { if (is_numeric($id)) { $title = "Edit Restaurant #" . $id . " " . getName('restaurant', $id); } else { $title = "Add Restaurant"; } include("header.inc.php3"); edit(load($id)); } } else { if ($id) { $title = "View Restaurant #" . $id . " " . getName('restaurant', $id); } else { $title = "All Restaurants"; } include("header.inc.php3"); $search_parms['ethnicity_id'] = $ethnicity_id; $search_parms['vegetarian_id'] = $vegetarian_id; $search_parms['vegan_id'] = $vegan_id; $search_parms['state'] = $state; view($view,$id,$search_parms); } footer(); //--------- main program include("footer.inc.php3"); page_close() ?>