Location: PHPKode > projects > phpMyRecipes > phpMyRecipes/functions.php
<?php
# Copyright 2006 Todd Palino
#
# This file is part of phpMyRecipes.
#
# phpMyRecipes is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# phpMyRecipes is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# phpMyRecipes; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA

##############################################################################
# MAKING CHANGES BELOW THIS POINT IS NOT RECOMMENDED
##############################################################################

##############################################################################
# Privilege masks.  If you just add another one here, don't expect
# it to work.  It needs to be added to the add/edit users pages as
# well, and worked into whatever you want it to protect.

define("PRIV_ADDRECIPES", 1);
define("PRIV_EDITRECIPES", 2);
define("PRIV_DELETERECIPES", 4);
define("PRIV_ADDCATEGORIES", 8);
define("PRIV_EDITCATEGORIES", 16);
define("PRIV_DELETECATEGORIES", 32);
define("PRIV_ADDUNITS", 64);
define("PRIV_EDITUNITS", 128);
define("PRIV_DELETEUNITS", 256);
define("PRIV_ADDINGREDIENTS", 512);
define("PRIV_EDITINGREDIENTS", 1024);
define("PRIV_DELETEINGREDIENTS", 2048);
define("PRIV_MANAGEUSERS", 4096);
define("PRIV_EMAILRECIPES", 8192);

##############################################################################
# SUPPORT FUNCTIONS

  $IMAGE_TYPES = array("img", "gif", "jpg", "png", "swf", "psd", "bmp", "tiff", "tiff", "jpc", "jp2",
                       "jpx", "jb2", "swc", "iff", "wbmp", "xbm");

  function GetItemIDByName($name) {
    if ($result = mysql_query("SELECT id from ingredients WHERE STRCMP(name, \"$name\")=0")) {
      if (mysql_num_rows($result) == 0) {
        # Item doesn't exist, so add it
        if ($res2 = mysql_query("INSERT INTO ingredients (name) VALUES(\"$name\")")) {
          return(mysql_insert_id());
        } else {
          return(0);
        }
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return(0);
    }
  }

  function GetUnitNameByID($id) {
    if ($result = mysql_query("SELECT name from units WHERE id=$id")) {
      if (mysql_num_rows($result) == 0) {
        return("");
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return("");
    }
  }

  function isPlural($qty) {
    if ($qty == 1) {
      return 0;
    }

    if (preg_match("/^[0-9]+\/[0-9]+/", $qty)) {
      return 0;
    }

    return 1;
  }

  function GetUnitNameByID_qty($id, $qty) {
    if (isPlural($qty)) {
      $query = "SELECT plural from units WHERE id=$id";
    } else {
      $query = "SELECT name from units WHERE id=$id";
    }

    if ($result = mysql_query($query)) {
      if (mysql_num_rows($result) == 0) {
        return("");
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return("");
    }
  }

  function GetIngredientID($qty, $unit, $item) {
    if ($result = mysql_query("SELECT id from recipe_ingredients WHERE STRCMP(quantity, \"$qty\")=0 AND unit=$unit AND ingredient=$item")) {
      if (mysql_num_rows($result) == 0) {
        # Line doesn't exist, so add it
        if ($res2 = mysql_query("INSERT INTO recipe_ingredients (quantity,unit,ingredient) VALUES(\"$qty\", $unit, $item)")) {
          return(mysql_insert_id());
        } else {
          return(0);
        }
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return(0);
    }
  }

  function GetItemNameByID($id) {
    if ($result = mysql_query("SELECT name from ingredients WHERE id=$id")) {
      if (mysql_num_rows($result) == 0) {
        return("");
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return("");
    }
  }

  function GetCategoryNameByID($id) {
    if ($result = mysql_query("SELECT name from categories WHERE id=$id")) {
      if (mysql_num_rows($result) == 0) {
        return("");
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return("");
    }
  }

  function GetCategoryParentByID ($id) {
    if ($result = mysql_query("SELECT parent from categories WHERE id=$id")) {
      if (mysql_num_rows($result) == 0) {
        return(0);
      } else {
        $row = mysql_fetch_array($result);
        return($row[0]);
      }
    } else {
      return(0);
    }
  }

  # Return a plain text version of the selected recipe
  function GetTextRecipe ($id) {
    if (! ($result = mysql_query("SELECT name,category,servings,ingredients,instructions,description,creator,editor FROM recipes WHERE id=$id"))) {
      dberror("functions.php", "Cannot select recipe");
    }
    if (mysql_num_rows($result) == 0) return "";

    $row = mysql_fetch_array($result);
    # Build a category string
    $cat = $row[1];
    $catstr = "";
    while ($cat != 0) {
      if ($catstr == "") {
        $catstr = GetCategoryNameByID($cat);
      } else {
        $catstr = GetCategoryNameByID($cat) . " > " . $catstr;
      }

      $cat = GetCategoryParentByID($cat);
    }

    $retstr = $row[0] . "\n";
    $retstr .= "Category: Main > $catstr \n";
    if ($row[6] > 0) $retstr .= "Added by: " . getname_byuserid($row[6]) . "\n";
    if ($row[7] > 0) $retstr .= "Last updated by: " . getname_byuserid($row[7]) . "\n";
    $retstr .= "Serves " . $row[2] . "\n\n";
    if (!empty($row[5])) $retstr .= "Description:\n" . $row[5] . "\n\n";

    if (!empty($row[3])) {
  	  $retstr .= "Ingredients:\n";
      # Get the ingredients list
      if ($result = mysql_query("SELECT quantity,unit,ingredient FROM recipe_ingredients WHERE FIND_IN_SET(id, \"" .
                                $row[3] . "\")>0")) {
        while ($irow = mysql_fetch_array($result)) {
          $unit = GetUnitNameByID_qty($irow[1], $irow[0]);
          if (($ing = GetItemNameByID($irow[2])) == "") {
            dberror("function.php", "Cannot retrieve ingredient name from database");
          }
          $retstr .= "    " . $irow[0] . " $unit $ing\n";
        }
      } else {
        dberror("function.php", "Cannot retrieve ingredient lines from database");
      }
    
      $retstr .= "\n";
    }

    $retstr .= "Instructions:\n" . wordwrap($row[4]) . "\n";
    return $retstr;
  }
  
  # Return a string containing a list of OPTIONS statements for a SELECT of
  # all categories (recursive).  For a full list, call this as
  # print_subcat_select(0, "", <selid>) where <selid> is the ID number of
  # the category that should be preselected.  You might want to print an
  # OPTION line for the main category before calling this, as well.
  function print_subcat_select ($parent_id, $prefix, $selid) {
    $optstr = "";
    # Get a categories list for the given parent ID
    if ($result = mysql_query("SELECT id,name from categories WHERE parent=$parent_id ORDER BY name")) {
      while ($row = mysql_fetch_array($result)) {
        if ($row[0] == $selid) {
          $optstr .= "<OPTION SELECTED VALUE=\"" . $row[0] . "\">${prefix}-" . $row[1] . "</OPTION>\n";
        } else {
          $optstr .= "<OPTION VALUE=\"" . $row[0] . "\">${prefix}-" . $row[1] . "</OPTION>\n";
        }
        $optstr .= print_subcat_select($row[0], $prefix . " |", $selid);
      }
    } else {
      dberror("common.php", "Cannot select category list for OPTIONS");
    }

    return $optstr;
  }

  function autop($pee, $br = 1) {
    $pee = $pee . "\n"; // just to make things a little easier, pad the end
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $pee = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $pee);
    $pee = preg_replace('!(</(?:table|ul|ol|li|pre|form|blockquote|h[1-6])>)!', "$1\n", $pee);
    $pee = preg_replace("/(\r\n|\r)/", "\n", $pee);
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee);
    $pee = preg_replace('|<p>\s*?</p>|', '', $pee);
    $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee);
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!', "$1", $pee);
    $pee = preg_replace('!(</?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee);
    if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
    $pee = preg_replace('!(</?(?:table|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*<br />!', "$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|th|pre|td|ul|ol)>)!', '$1', $pee);
    $pee = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $pee);
    
    return $pee;
  }

  function dberror($file, $reason) {
    c_header("Database Error", "error", 0, 0);

?>
We seem to have encountered a database error.  Please send email to
<A HREF="mailto:hide@address.com">hide@address.com</A> with the
following information:<UL>
<LI>File - <?php echo($file) ?>
<LI>Reason - <?php echo($reason) ?>
<LI>Text - <?php echo (mysql_error()) ?>
</UL><P>
<?php

    c_footer();
    exit();
  }

  function getsession() {
    if (! empty($_COOKIE)) {
      $cookieOK = 'Y';
      $s = $_COOKIE['sessionID'];
    } elseif (! empty($_GET)) {
      $cookieOK = 'N';
      $s = $_GET['sid'];
    } elseif (! empty($_POST)) {
      $cookieOK = 'N';
      $s = $_POST['sid'];
    } else {
      return NULL;
    }

    if ($result = mysql_query("SELECT * from sessions WHERE sessionID=\"$s\" LIMIT 1")) {
      if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);

        if ($cookieOK != $row{'cookieOK'}) {
          if (mysql_query("UPDATE sessions SET ts=NULL,cookieOK=\"$cookieOK\" WHERE sessionID=\"$s\"")) {
            $row{'cookieOK'} = $cookieOK;
          } else {
            dberror("common.php/getsession", "Cannot update session in DB.");
            exit();
          }
        } else {
          if (! mysql_query("UPDATE sessions SET ts=NULL WHERE sessionID=\"$s\"")) {
            dberror("common.php/getsession", "Cannot update timestamp in DB.");
            exit();
          }
        }

        return $row;
      } else {
        return NULL;
      }
    } else {
      dberror("common.php/getsession", "Cannot select session from DB.");
      exit();
    }
  }

  function slink($link) {
    global $session;

    if (substr($link, -1) == "/") {
      $link .= "index.php";
    }

    if (! empty($session)) {
      if ($session{'cookieOK'} == "N") {
        if (strstr($link, "?")) {
          return $link . "&sid=" . $session{'sessionID'};
        } else {
          return $link . "?sid=" . $session{'sessionID'};
        }
      } else {
        return $link;
      }
    } else {
      return $link;
    }
  }

  function getdomain() {
    $host = $_SERVER["HTTP_HOST"];
    $pieces = explode(".", $host);
    $c = count($pieces);
    if ($c > 1) {
      return $pieces[$c - 2] . "." . $pieces[$c - 1];
    } else {
    	return $host;
    }
  }

  function validate_str($str) {
    if (empty($str)) { return 0; }
    if (strchr($str, "\"")) { return 0; }
    return 1;
  }

  function validate_num($str) {
    if (empty($str)) { return 0; }
    return preg_match("/^[0-9]+$/i", $str);
  }

  function validate_email($str) {
    $str = trim($str);
    return preg_match("/^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$/i", $str);
  }

  function validate_username($str) {
    if (empty($str)) { return 0; }
    if (strlen($str) > 16) { return 0; }
    if (! preg_match("/^[a-zA-Z][a-zA-Z0-9_]+$/", $str)) { return 0; }

    if (getRowCount("users", "username=\"$str\"")) {
      return 0;
    }

    return 1;
  }

  function validate_username_notid($str, $id) {
    if (empty($str)) { return 0; }
    if (strlen($str) > 16) { return 0; }
    if (! preg_match("/^[a-zA-Z][a-zA-Z0-9_]+$/", $str)) { return 0; }

    if (getRowCount("users", "username=\"$str\" AND id != $id")) {
      return 0;
    }

    return 1;
  }

  function validate_password($str1, $str2) {
    if (empty($str1) || empty($str2)) { return 0; }
    if ($str1 != $str2) { return 0; }
    return 1;
  }

  function email_notindb($str, $userid) {
    $result = mysql_query("SELECT id,email from users WHERE strcmp(email, \"$str\") = 0 LIMIT 1");
    $row = mysql_fetch_array($result);

    if ($userid == $row{'id'}) {
      return 1;
    }

    if (mysql_num_rows($result) == 1) {
      return 0;
    }

    return 1;
  }

  function check_user($user) {
    if ($result = mysql_query("SELECT id FROM users WHERE strcmp(username, \"$user\") = 0")) {
      if (mysql_num_rows($result) == 1) {
        return 1;
      } else {
        return 0;
      }
    } else {
      dberror("common.php/check_email", "Cannot select user by user from database");
    }
  }

  function check_email($email) {
    if ($result = mysql_query("SELECT username,email,name FROM users WHERE strcmp(email, \"$email\") = 0")) {
      if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        return $row{'username'} . "\t" . $row{'email'} . "\t" . $row{'name'};
      } else {
        return "";
      }
    } else {
      dberror("common.php/check_email", "Cannot select user by email from database");
    }
  }

  function contactid($user) {
    if ($result = mysql_query("SELECT id FROM users WHERE strcmp(username, \"$user\") = 0")) {
      if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        return $row{'id'};
      } else {
        return 0;
      }
    } else {
      dberror("common.php/contactid", "Cannot select user by user from database");
    }
  }

  function getuser_byid($userid) {
    if (($result = mysql_query("SELECT * from users WHERE id=$userid LIMIT 1")) > 0) {
      if (mysql_num_rows($result) == 1) {
        return mysql_fetch_array($result);
      } else {
        dberror("common.php/getuser_byid", "Cannot find userid");
        exit();
      }
    } else {
      dberror("common.php/getuser_byid", "Cannot perform select");
      exit();
    }
  }

  function getname_byuserid($userid) {
    if (($result = mysql_query("SELECT name from users WHERE id=$userid LIMIT 1")) > 0) {
      if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        return $row[0];
      } else {
        dberror("common.php/getname_byuserid", "Cannot find userid");
        exit();
      }
    } else {
      dberror("common.php/getname_byuserid", "Cannot perform select");
      exit();
    }
  }

  function getemail_byuserid($userid) {
    if (($result = mysql_query("SELECT email from users WHERE id=$userid LIMIT 1")) > 0) {
      if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        return $row[0];
      } else {
        dberror("common.php/getemail_byuserid", "Cannot find userid");
        exit();
      }
    } else {
      dberror("common.php/getemail_byuserid", "Cannot perform select");
      exit();
    }
  }

  function getRowCount ($db_table, $where='') {
    if (! empty($where) ) {
      if (! ($result = mysql_query("SELECT count(*) from $db_table WHERE $where"))) {
        dberror("common/getRowCount", "Cannot select filtered row count");
      }
    } else {
      if (! ($result = mysql_query("SELECT count(*) from $db_table"))) {
        dberror("common/getRowCount", "Cannot select row count");
      }
    }

    return mysql_result($result, 0);
  }

  function rannum() {
    mt_srand((double)microtime()*1000000);
    $num = mt_rand(46,122);
    return $num;
  }

  function genchr() {
    do {
      $num = rannum();
    } while (($num > 57 && $num < 65) || ($num > 90 && $num < 97));
    return chr($num);
  }

  function genstr($num) {
    for ($i=1; $i<=$num; $i++) {
      $string = $string . genchr();
    }
    return $string;
  }

  function bnic_crypt($plaintext) {
    $salt = genchr() . genchr();
    $ciphertext = crypt($plaintext, $salt);
    return $ciphertext;
  }

  function insEditRecipeField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_EDITRECIPES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Edit Recipe" HREF="<?php print slink(URL_PREFIX . "recipes/editrecipe.php?r_id=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Edit]\" SRC=\"" . URL_PREFIX . "images/edit_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insDelRecipeField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_DELETERECIPES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Delete Recipe" HREF="<?php print slink(URL_PREFIX . "recipes/delrecipe.php?r_id=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Delete]\" SRC=\"" . URL_PREFIX . "images/delete_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insEmailRecipeField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_EMAILRECIPES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Email Recipe" HREF="<?php print slink(URL_PREFIX . "recipes/emailrecipe.php?r_id=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Email]\" SRC=\"" . URL_PREFIX . "images/email_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insPrintRecipeField($id, $size = 16) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Printable Version" HREF="<?php print slink(URL_PREFIX . "recipes/textrecipe.php?r_id=$id") ?>">
<?php
    print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Printable Version]\" SRC=\"" . URL_PREFIX . "images/print_$size.png\"></A></TD>";
  }

  function insEditCategoryField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_EDITCATEGORIES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Edit Category" HREF="<?php print slink(URL_PREFIX . "categories/editcategory.php?id=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Edit]\" SRC=\"" . URL_PREFIX . "images/edit_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insAddCategoryField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_ADDCATEGORIES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Add Sub-Category" HREF="<?php print slink(URL_PREFIX . "categories/addcategory.php?parent=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Add Sub]\" SRC=\"" . URL_PREFIX . "images/insrow_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insDelCategoryField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_DELETECATEGORIES)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Delete Category" HREF="<?php print slink(URL_PREFIX . "categories/delcategory.php?id=$id") ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Delete]\" SRC=\"" . URL_PREFIX . "images/delete_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insEditUnitField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_EDITUNITS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Edit Unit" HREF="<?php print slink(URL_PREFIX . "units/editunit.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Edit]\" SRC=\"" . URL_PREFIX . "images/edit_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insDelUnitField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_DELETEUNITS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Delete Unit" HREF="<?php print slink(URL_PREFIX . "units/delunit.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Delete]\" SRC=\"" . URL_PREFIX . "images/delete_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insEditIngredientField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_EDITINGREDIENTS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Edit Ingredient" HREF="<?php print slink(URL_PREFIX . "ingredients/editingredient.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Edit]\" SRC=\"" . URL_PREFIX . "images/edit_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insDelIngredientField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_DELETEINGREDIENTS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Delete Ingredient" HREF="<?php print slink(URL_PREFIX . "ingredients/delingredient.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Delete]\" SRC=\"" . URL_PREFIX . "images/delete_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insEditUserField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_MANAGEUSERS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Edit User" HREF="<?php print slink(URL_PREFIX . "users/edituser.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Edit]\" SRC=\"" . URL_PREFIX . "images/edit_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insDelUserField($id, $size = 16) {
    global $session;

    if (!empty($session) && ($session{'privs'} & PRIV_MANAGEUSERS)) {
?>
    <TD ALIGN=CENTER VALIGN=MIDDLE>
      <A TITLE="Delete User" HREF="<?php print slink(URL_PREFIX . "users/deluser.php?id=$id"); ?>">
<?php
      print "<IMG BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"[Delete]\" SRC=\"" . URL_PREFIX . "images/delete_$size.png\"></A></TD>";
    } else {
      print "<TD>&nbsp;</TD>\n";
    }
  }

  function insSessionField() {
    global $session;

    if (!empty($session) && ($session{'cookieOK'} == 'N')) {
      ?><INPUT TYPE=hidden NAME=sid VALUE="<?php print $session{'sessionID'}; ?>"><?php
    }
  }
?>
Return current item: phpMyRecipes