// Copyright: Copyright (C) 2002-2007 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/sql.inc.php"; // new_sn: Generate a new random serial number for an SQL table function new_sn($table) { // S/N is always 9 digits do { // Generate a random serial number $sn = mt_rand(100000000, 999999999); // Check if this serial number exists $select = "SELECT sn FROM $table WHERE sn=$sn;\n"; $result = sql_query($select); } while (sql_num_rows($result) > 0); return $sn; } // new_sn_assoc: Generate a new random serial number for an associative array function new_sn_assoc(&$assoc) { // S/N is always 9 digits do { // Generate a random serial number $sn = mt_rand(100000000, 999999999); } while (array_key_exists($sn, $assoc)); return $sn; } ?>