0 limit 1 "; $showall = (db_firstval($sql))?1:0; $clienttypeid = db_nextid('clienttype'); $sql = " insert into tblclienttype ( clienttypeid , clienttypegroupid , clienttypename , companyid , clienttypeshowall , clienttypeseller ) values ( " . $clienttypeid . " , " . db_number($clienttypegroupid) . " , '" . db_col($clienttypename) . "' , " . companyid() . " , " . $showall. " , " . ($clienttypeseller ? "1" : "null") . " )"; if(db_exec($sql)) return $clienttypeid; else return false; } function clienttype_update($_POST){ extract($_POST); if(!$clienttypeid || !trim($clienttypename)) return false; $sql = "select 1 from tblclienttype where clienttypename = '" . db_col($clienttypename) . "' and clienttypegroupid in (select clienttypegroupid from tblclienttype where clienttypeid = " . db_number($clienttypeid) . ") and (companyid = 0 or companyid = " . companyid() . ") and clienttypeid != " . db_number($clienttypeid) . " "; $exists = db_query($sql); //Same name exists for a different client in same group. if($exists) return false; $sql = "update tblclienttype set clienttypename = " . ($clienttypename ? "'" . db_col($clienttypename) . "'" : "null") . " ,clienttypeseller = " . ($clienttypeseller ? "1" : "null") . " where clienttypeid = " . db_number($clienttypeid) . " and companyid = " . companyid(); if(db_exec($sql)) return true; else return false; } function clienttype_delete($_POST){ extract($_POST); if(!$clienttypeid) return false; $sql = "delete from tblclienttype where clienttypeid = " . db_number($clienttypeid); if(db_exec($sql)) return true; else return false; } function clienttype_reassign($oldclienttypeid,$newclienttypeid){ if(!$oldclienttypeid || !$newclienttypeid) return false; $sql = "update tblclient set clienttypeid = " . db_number($newclienttypeid) . " where clienttypeid = " . db_number($oldclienttypeid) . " and companyid = " . companyid(); if(db_exec($sql)) return true; else return false; } function clienttype_get($clienttypeid){ $sql = "select * from tblclienttype where clienttypeid = " . db_col($clienttypeid); $clienttype = db_first($sql); if($clienttype) return $clienttype; else return false; } function clienttypes_get(){ $sql = "select * from tblclienttype where companyid = " . companyid() . " or companyid = 0 order by clienttypename"; $clienttypes = db_query($sql); if($clienttypes) return $clienttypes; else return array(); } function clienttypename($clienttypeid){ $clienttype = clienttype_get($clienttypeid); return $clienttype['clienttypename']; } ?>