| 41 | | function isUnique($tablename,$column,$value,$excludeid,$db){ |
| 42 | | |
| 43 | | $thereturn=false; |
| 44 | | |
| 45 | | $querystatement="SELECT count(id) AS thecount FROM ".$tablename." WHERE ".$column."=\"".$value."\" AND id!=".$excludeid; |
| 46 | | $queryresult=$db->query($querystatement); |
| 47 | | if($queryresult){ |
| 48 | | $therecord=$db->fetchArray($queryresult); |
| 49 | | if($therecord["thecount"]==0) |
| 50 | | $thereturn=true; |
| 51 | | } |
| 52 | | |
| 53 | | return $thereturn; |
| 54 | | } |
| 55 | | |
| 56 | | |
| 57 | | $isunique=false; |
| 58 | | |
| 59 | | if(isset($_GET["tdid"]) && isset($_GET["c"]) && isset($_GET["val"]) && isset($_GET["xid"])) { |
| 60 | | $_GET["tdid"]=((int) $_GET["tdid"]); |
| 61 | | $_GET["xid"]=((int) $_GET["xid"]); |
| 62 | | |
| 63 | | $querystatement="SELECT maintable FROM tabledefs WHERE id=".$_GET["tdid"]; |
| 64 | | $queryresult=$db->query($querystatement); |
| 65 | | if($queryresult) |
| 66 | | if($therecord=$db->fetchArray($queryresult)) |
| 67 | | $isunique=isUnique($therecord["maintable"],$_GET["c"],$_GET["val"],$_GET["xid"],$db); |
| 68 | | } |
| 69 | | |
| 70 | | header('Content-Type: text/xml'); |
| 71 | | echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; |
| 72 | | ?> |
| 73 | | <response> |
| 74 | | <isunique><?php echo ((int) $isunique) ?></isunique> |
| 75 | | </response> |
| | 40 | |
| | 41 | class uniqueChecker{ |
| | 42 | |
| | 43 | var $db; |
| | 44 | |
| | 45 | function uniqueChecker($db){ |
| | 46 | |
| | 47 | $this->db = $db; |
| | 48 | $this->db->errorFormat = "json"; |
| | 49 | |
| | 50 | }//end function init |
| | 51 | |
| | 52 | |
| | 53 | function check($tabledefuuid, $columname, $value, $excludeid = NULL){ |
| | 54 | |
| | 55 | $querystatement = " |
| | 56 | SELECT |
| | 57 | `maintable` |
| | 58 | FROM |
| | 59 | `tabledefs` |
| | 60 | WHERE |
| | 61 | `uuid` = '".mysql_real_escape_string($tabledefuuid)."'"; |
| | 62 | |
| | 63 | $queryresult = $this->db->query($querystatement); |
| | 64 | |
| | 65 | if($this->db->numRows($queryresult) === 0) |
| | 66 | return "error"; |
| | 67 | |
| | 68 | $therecord = $this->db->fetchArray($queryresult); |
| | 69 | |
| | 70 | $table = $therecord["maintable"]; |
| | 71 | |
| | 72 | $columname = mysql_real_escape_string(str_replace("`","", $columname)); |
| | 73 | $value = mysql_real_escape_string($value); |
| | 74 | |
| | 75 | $querystatement = " |
| | 76 | SELECT |
| | 77 | count(id) AS thecount |
| | 78 | FROM |
| | 79 | `".$table."` |
| | 80 | WHERE |
| | 81 | `".$columname."` = '".$value."'"; |
| | 82 | |
| | 83 | if($excludeid){ |
| | 84 | |
| | 85 | $querystatement .= " AND `uuid` != '".mysql_real_escape_string($excludeid)."'"; |
| | 86 | |
| | 87 | }//endif |
| | 88 | |
| | 89 | $queryresult = $this->db->query($querystatement); |
| | 90 | |
| | 91 | $therecord = $this->db->fetchArray($queryresult); |
| | 92 | |
| | 93 | return ($therecord["thecount"] == 0); |
| | 94 | |
| | 95 | }//end function check |
| | 96 | |
| | 97 | }//end class |
| | 98 | |
| | 99 | |
| | 100 | /** |
| | 101 | * PROCESSING ================================================================== |
| | 102 | */ |
| | 103 | if(!isset($noOutput)){ |
| | 104 | |
| | 105 | require_once("include/session.php"); |
| | 106 | |
| | 107 | if(!isset($_GET["tduuid"]) || !isset($_GET["cname"]) || !isset($_GET["value"])) |
| | 108 | $error = new appError(200, "passed parameters not set"); |
| | 109 | |
| | 110 | if(!isset($_GET["xuuid"])) |
| | 111 | $_GET["xuuid"] = ""; |
| | 112 | |
| | 113 | $checker = new uniqueChecker($db); |
| | 114 | |
| | 115 | echo json_encode($checker->check($_GET["tduuid"], $_GET["cname"], $_GET["value"], $_GET["xuuid"])); |
| | 116 | |
| | 117 | }//endif |