Commit 1309f43c40f0da924e8aef7a2248bf3d42bcefc0
1 parent
aeb0774a
initial revision
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@188 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
53 additions
and
0 deletions
lib/lookup.inc
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id$ | |
| 5 | + * | |
| 6 | + * Contains database helper functions | |
| 7 | + * | |
| 8 | + * Licensed under the GNU GPL. For full terms see the file COPYING. | |
| 9 | + * @version $Revision$ | |
| 10 | + * @author <a href="mailto:michael@jamwarehouse.com>Michael Joseph</a>, Jam Warehouse (Pty) Ltd, South Africa | |
| 11 | + * @package dmslib | |
| 12 | + */ | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Performs an id field lookup on the specified table. | |
| 16 | + * | |
| 17 | + * @param $tableName | |
| 18 | + * the name of table to perform the id lookup. | |
| 19 | + * @param $fieldName | |
| 20 | + * the db field to return. | |
| 21 | + * @param $fieldValue | |
| 22 | + * the value to perform the lookup for | |
| 23 | + * @return the id of the row in the db with $fieldName=$fieldValue | |
| 24 | + */ | |
| 25 | + | |
| 26 | +function lookupID($tableName, $fieldName, $fieldValue){ | |
| 27 | + $sql = new Owl_DB(); | |
| 28 | + $query = "select id from $tableName where $fieldName = '$fieldValue'"; | |
| 29 | + //echo "lookup.inc::lookupID: about to execute $query<br>"; | |
| 30 | + if ($sql->query($query)) { | |
| 31 | + if ($sql->next_record()) { | |
| 32 | + return $sql->f("id"); | |
| 33 | + } else { | |
| 34 | + $_SESSION["errorMessage"] = "id retrieval failed."; | |
| 35 | + return false; | |
| 36 | + } | |
| 37 | + } else { | |
| 38 | + $_SESSION["errorMessage"] = "lookup query ($query) failed."; | |
| 39 | + return false; | |
| 40 | + } | |
| 41 | +} | |
| 42 | + | |
| 43 | +function lookupGroupID($userid) { | |
| 44 | + global $default; | |
| 45 | + $sql = new Owl_DB; | |
| 46 | + $sql->query("select group_id from $default->owl_groups_users_table where user_id = '$userid'"); | |
| 47 | + while($sql->next_record()) | |
| 48 | + { | |
| 49 | + $groupid = $sql->f("group_id"); | |
| 50 | + return $groupid; | |
| 51 | + } | |
| 52 | +} | |
| 53 | +?> | ... | ... |