inc/record.inc.php
changeset 21 31e17a9406eb
parent 19 f9ea2a05149b
child 30 380197766e7e
equal deleted inserted replaced
20:76e20b9d45e6 21:31e17a9406eb
   887 	FROM domains
   887 	FROM domains
   888 	LEFT JOIN zones ON domains.id=zones.domain_id 
   888 	LEFT JOIN zones ON domains.id=zones.domain_id 
   889 	LEFT JOIN records ON records.domain_id=domains.id
   889 	LEFT JOIN records ON records.domain_id=domains.id
   890 	WHERE 1 $add ";
   890 	WHERE 1 $add ";
   891 	if ($letterstart!=all && $letterstart!=1) {
   891 	if ($letterstart!=all && $letterstart!=1) {
   892 	   $sqlq.=" AND domains.name LIKE '".$letterstart."%' ";
   892 	   $sqlq.=" AND substring(domains.name,1,1) REGEXP '^".$letterstart."' ";
   893 	} elseif ($letterstart==1) {
   893 	} elseif ($letterstart==1) {
   894 	      $sqlq.=" AND ";
   894 	   $sqlq.=" AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'";
   895 	   for ($i=0;$i<=9;$i++) {
       
   896 	      $sqlq.="domains.name LIKE '".$i."%'";
       
   897 	      if ($i!=9) $sqlq.=" OR ";
       
   898 	   }
       
   899 	}
   895 	}
   900 	$sqlq.=" GROUP BY domainname, domain_id
   896 	$sqlq.=" GROUP BY domainname, domain_id
   901 	ORDER BY domainname
   897 	ORDER BY domainname
   902 	LIMIT $rowstart,$rowamount";
   898 	LIMIT $rowstart,$rowamount";
   903 
   899 
   904 	$result = $db->query($sqlq);
   900 	$result = $db->query($sqlq);
   905 	$result2 = $db->query($sqlq);
   901 	$result2 = $db->query($sqlq); 
   906 
   902 	
   907 	$andnot="";
   903 	$numrows = $result2->numRows();
   908 	while($r = $result2->fetchRow()) {
   904 	$i=1;
   909 	   $andnot.=" AND domains.id!= '".$r["domain_id"]."' ";
   905 	if ($numrows > 0) {
   910 	}
   906 		$andnot=" AND NOT domains.id IN (";
   911 
   907 		while($r = $result2->fetchRow()) {
   912 if ($letterstart!=all && $letterstart!=1) {
   908 			$andnot.=$r["domain_id"];
   913 
   909 			if ($i < $numrows) {
   914 	$sqlq = "SELECT domains.id AS domain_id,
   910 				$andnot.=",";
   915 	count(DISTINCT record_owners.record_id) AS aantal,
   911 				$i++;
   916 	domains.name AS domainname
   912 			}
   917 	FROM domains, record_owners,records, zones
   913 		}
   918 	WHERE record_owners.user_id = '".$_SESSION["userid"]."'
   914 		$andnot.=")";
   919 	AND (records.id = record_owners.record_id
   915 	}
   920 	AND domains.id = records.domain_id)
   916 	else
   921 	$andnot 
   917 	{
   922 	AND domains.name LIKE '".$letterstart."%' 
   918 		$andnot="";
   923 	AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
   919 	}
   924 	GROUP BY domainname, domain_id
   920 
   925 	ORDER BY domainname";
   921 	if ($letterstart!=all && $letterstart!=1) {
   926 
   922 
   927 	$result_extra = $db->query($sqlq);
   923 		$sqlq = "SELECT domains.id AS domain_id,
   928 
   924 		count(DISTINCT record_owners.record_id) AS aantal,
   929 } else {
   925 		domains.name AS domainname
   930 
   926 		FROM domains, record_owners,records, zones
   931    for ($i=0;$i<=9;$i++) {
   927 		WHERE record_owners.user_id = '".$_SESSION["userid"]."'
   932         $sqlq = "SELECT domains.id AS domain_id,
   928 		AND (records.id = record_owners.record_id
   933         count(DISTINCT record_owners.record_id) AS aantal,
   929 		AND domains.id = records.domain_id)
   934         domains.name AS domainname
   930 		$andnot 
   935         FROM domains, record_owners,records, zones
   931 		AND domains.name LIKE '".$letterstart."%' 
   936         WHERE record_owners.user_id = '".$_SESSION["userid"]."'
   932 		AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
   937         AND (records.id = record_owners.record_id
   933 		GROUP BY domainname, domain_id
   938         AND domains.id = records.domain_id)
   934 		ORDER BY domainname";
   939         $andnot 
   935 
   940         AND domains.name LIKE '".$i."%' 
   936 		$result_extra = $db->query($sqlq);
   941         AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
   937 
   942         GROUP BY domainname, domain_id
   938 	} else {
   943         ORDER BY domainname";
   939 
   944 
   940 		$sqlq = "SELECT domains.id AS domain_id,
   945         $result_extra[$i] = $db->query($sqlq);
   941 		count(DISTINCT record_owners.record_id) AS aantal,
   946    }
   942 		domains.name AS domainname
   947 
   943 		FROM domains, record_owners,records, zones
   948 }
   944 		WHERE record_owners.user_id = '".$_SESSION["userid"]."'
   949 
   945 		AND (records.id = record_owners.record_id
   950 /*
   946 		AND domains.id = records.domain_id)
   951 	if ($result->numRows() == 0)
   947 		$andnot 
   952 	{
   948 		AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'
   953 		// Nothing found.
   949 		AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
   954 		return -1;
   950 		GROUP BY domainname, domain_id
   955 	}
   951 		ORDER BY domainname";
   956 */
   952 
       
   953 		$result_extra[$i] = $db->query($sqlq);
       
   954 
       
   955 	}
   957 
   956 
   958 	while($r = $result->fetchRow())
   957 	while($r = $result->fetchRow())
   959 	{
   958 	{
   960 		$r["owner"] = ($r["owner"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $r["owner"];
   959 		$r["owner"] = ($r["owner"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $r["owner"];
   961 	     	$ret[$r["domainname"]] = array(
   960 	     	$ret[$r["domainname"]] = array(
   965 		"numrec"        =>              $r["aantal"]
   964 		"numrec"        =>              $r["aantal"]
   966 		);
   965 		);
   967 	}
   966 	}
   968 
   967 
   969 
   968 
   970 if ($letterstart!=all && $letterstart!=1) {
   969 	if ($letterstart!=all && $letterstart!=1) {
   971 
   970 
   972 	while($r = $result_extra->fetchRow())
   971 		while($r = $result_extra->fetchRow())
   973         {
   972 		{
   974                $ret[$r["domainname"]] = array(
   973 		       $ret[$r["domainname"]] = array(
   975 	       "name"          =>              $r["domainname"]."*",
   974 		       "name"          =>              $r["domainname"]."*",
   976                "id"            =>              $r["domain_id"],
   975 		       "id"            =>              $r["domain_id"],
   977                "owner"         =>              $_SESSION["userid"],
   976 		       "owner"         =>              $_SESSION["userid"],
   978                "numrec"        =>              $r["aantal"]
   977 		       "numrec"        =>              $r["aantal"]
   979                );
   978 		       );
   980 	       $_SESSION["partial_".$r["domainname"]] = 1;
   979 		       $_SESSION["partial_".$r["domainname"]] = 1;
   981         }
   980 		}
   982 
   981 
   983 } else {
   982 	} else {
   984 
   983 
   985 	foreach ($result_extra as $result_e) {
   984 		foreach ($result_extra as $result_e) {
   986         while($r = $result_e->fetchRow())
   985 		while($r = $result_e->fetchRow())
   987         {
   986 		{
   988                $ret[$r["domainname"]] = array(
   987 		       $ret[$r["domainname"]] = array(
   989                "name"          =>              $r["domainname"]."*",
   988 		       "name"          =>              $r["domainname"]."*",
   990                "id"            =>              $r["domain_id"],
   989 		       "id"            =>              $r["domain_id"],
   991                "owner"         =>              $_SESSION["userid"],
   990 		       "owner"         =>              $_SESSION["userid"],
   992                "numrec"        =>              $r["aantal"]
   991 		       "numrec"        =>              $r["aantal"]
   993                );
   992 		       );
   994 	       $_SESSION["partial_".$r["domainname"]] = 1;
   993 		       $_SESSION["partial_".$r["domainname"]] = 1;
   995         }
   994 		}
   996 	}
   995 		}
   997 
   996 
   998 }
   997 	}
   999 
   998 
  1000 if (empty($ret)) {
   999 	if (empty($ret)) {
  1001    return -1;
  1000 	   return -1;
  1002 } else {
  1001 	} else {
  1003    sort($ret);
  1002 	   sort($ret);
  1004    return $ret;
  1003 	   return $ret;
  1005 }
  1004 	}
  1006 
  1005 
  1007 }
  1006 }
  1008 
  1007 
  1009 
  1008 
  1010 /*
  1009 /*