query($sqlstr)) return 1; else return 2; } function UT_insertSQL($table, $insertQuery) { $tmpValue = ""; $tmpField = ""; $UT_db = new DB; if (is_array($insertQuery)) { $currTime = mktime(); $tmpField .= __UT_TEMPLATE_DBFIELD_CREATEDATE__ . ", " . __UT_TEMPLATE_DBFIELD_CREATORID__ . ", " . __UT_TEMPLATE_DBFIELD_LASTEDITDATE__ . ", " . __UT_TEMPLATE_DBFIELD_LASTEDITID__ . ", " . __UT_TEMPLATE_DBFIELD_STATUS__; $tmpValue .= $currTime . ", " . $_SESSION['SESSION_LOGINID'] . ", " . $currTime . ", " . $_SESSION['SESSION_LOGINID'] . ", " . __UT_REC_ACTIVE__; foreach($insertQuery as $currField => $currValue) { if ($currField != "id") { $tmpField .= ", " . $currField; $tmpValue .= ", " . $currValue; } } $sqlstr = "insert into " . $table . " (" . $tmpField . ") value (" . $tmpValue . ")"; } else { $sqlstr = "insert into " . $table . $insertQuery; } if($UT_db->query($sqlstr)) { $UT_db->query("select last_insert_id() as lastID"); $UT_db->next_record(); $currID = $UT_db->f("lastID"); } else { $currID = 0; } return $currID; } function UT_deleteSQL($table, $currID) { $UT_db = new DB; $sqlstr = "update " . $table . " set " . __UT_TEMPLATE_DBFIELD_LASTEDITDATE__ . "=" . mktime() . ", " . __UT_TEMPLATE_DBFIELD_LASTEDITID__ . "=" . $_SESSION['SESSION_LOGINID'] . ", " . __UT_TEMPLATE_DBFIELD_STATUS__ . "=" . __UT_REC_DELETE__ . " where id=" . $currID; if($UT_db->query($sqlstr)) return 1; else return 2; } function UT_checkUniqueSQL($table, $condition) { $UT_db = new DB; if ($condition != "") $sqlstr = "select * from " . $table . " where " . $condition . " and " . __UT_TEMPLATE_DBFIELD_STATUS__ . "<>" . __UT_REC_DELETE__; else $sqlstr = "select * from " . $table . " where " . __UT_TEMPLATE_DBFIELD_STATUS__ . "<>" . __UT_REC_DELETE__; $UT_db->query($sqlstr); if ($UT_db->next_record()) return true; else return false; } function UT_getValueSQL($table, $condition, $field) { $UT_db = new DB; if ($condition != "") $sqlstr = "select " . $field . " from " . $table . " where " . $condition . " and " . __UT_TEMPLATE_DBFIELD_STATUS__ . "<>" . __UT_REC_DELETE__; else $sqlstr = "select " . $field . " from " . $table . " where " . __UT_TEMPLATE_DBFIELD_STATUS__ . "<>" . __UT_REC_DELETE__; if($UT_db->query($sqlstr)) { $UT_db->next_record(); return ($UT_db->f($field)); } else return 0; } function UT_nextIncrementNo($table, $field, $pattern) { $ret = 0; $currValue = 0; $UT_db = new DB; $sqlstr = "select max(" . $field . ") as tmpField from " . $table . " where " . __UT_TEMPLATE_DBFIELD_STATUS__ . "<>" . __UT_REC_DELETE__; $UT_db->query($sqlstr); if ($UT_db->next_record()) { $currValue = $UT_db->f("tmpField"); } else { $currValue = 1; } $prefixLen = strpos($pattern, "#"); $patternLen = strlen($pattern); $newValue = (intval(substr($currValue, $prefixLen+1)) + 1); $newValueLen = strlen($newValue); $ret = substr($pattern, 0, $prefixLen) . str_pad("", $patternLen-$newValueLen-$prefixLen, "0") . $newValue; return $ret; } ?>