inc/record.inc.php
changeset 62 ce4919f37489
parent 60 6ffacb626294
child 63 d76966db18e5
equal deleted inserted replaced
61:d015f5c9b308 62:ce4919f37489
  1274 
  1274 
  1275 function search_record($question)
  1275 function search_record($question)
  1276 {
  1276 {
  1277 	global $db;
  1277 	global $db;
  1278 	$question = trim($question);
  1278 	$question = trim($question);
  1279 	if (empty($question)) 
  1279 
  1280 	{
  1280 	if (is_valid_search($question))
  1281 		$S_INPUT_TYPE = -1;
  1281 	{
  1282 	}
  1282 		$sqlq = "SELECT * 
  1283 
  1283 				FROM records 
  1284 	/* now for some input-type searching */
  1284 				WHERE content LIKE '".$question."' 
  1285 	if (is_valid_ip($question) || is_valid_ip6($question))
  1285 				OR name LIKE '".$question."' 
  1286 	{
  1286 				ORDER BY type DESC";
  1287 		$S_INPUT_TYPE = 0;
  1287 		echo " $sqlq ";
  1288 	}
  1288 		$result = $db->query($sqlq);
  1289 	elseif(is_valid_domain($question) || 
  1289 		$ret_r = array();
  1290 		is_valid_hostname($question) ||
  1290 		while ($r = $result->fetchRow())
  1291 		is_valid_mboxfw($question)) // I guess this one can appear in records table too (content?!)
  1291 		{
  1292 	{
  1292 		    if(xs($r['domain_id']))
  1293 		$S_INPUT_TYPE = 1;
  1293 		    {
  1294 	}	  
  1294 			$ret_r[] = array(
  1295 	else 
  1295 			  'id'			=>	$r['id'],
  1296 	{
  1296 			  'domain_id'		=>	$r['domain_id'],
  1297 		$S_INPUT_TYPE = -1;
  1297 			  'name'		=>	$r['name'],
  1298 	}
  1298 			  'type'		=>	$r['type'],
  1299 	switch($S_INPUT_TYPE)
  1299 			  'content'		=>	$r['content'],
  1300 	{
  1300 			  'ttl'			=>	$r['ttl'],
  1301 		case '0': 
  1301 			  'prio'		=>	$r['prio'],
  1302 			$sqlq = "SELECT * FROM records WHERE content = '".$question."' ORDER BY type DESC";
  1302 			  'change_date'		=>	$r['change_date']
  1303 			$result = $db->query($sqlq);
  1303 			);
  1304 			$ret_r = array();
       
  1305 			while ($r = $result->fetchRow())
       
  1306 			{
       
  1307 			    if(xs($r['domain_id']))
       
  1308 			    {
       
  1309     				$ret_r[] = array(
       
  1310     				  'id'			=>	$r['id'],
       
  1311     				  'domain_id'		=>	$r['domain_id'],
       
  1312     				  'name'		=>	$r['name'],
       
  1313     				  'type'		=>	$r['type'],
       
  1314     				  'content'		=>	$r['content'],
       
  1315     				  'ttl'			=>	$r['ttl'],
       
  1316     				  'prio'		=>	$r['prio'],
       
  1317     				  'change_date'		=>	$r['change_date']
       
  1318     				);
       
  1319 				}
       
  1320 			}
  1304 			}
  1321 			break;
  1305 		}
  1322 	    
  1306 
  1323 		case '1' :
  1307 		$sqlq = "SELECT domains.id, domains.name, count(records.id) AS numrec, zones.owner, records.domain_id
  1324 			$sqlq = "SELECT domains.id, domains.name, count(records.id) AS numrec, zones.owner, records.domain_id
  1308 				FROM domains, records, zones  
  1325 					FROM domains, records, zones  
  1309 				WHERE domains.id = records.domain_id 
  1326 					WHERE domains.id = records.domain_id 
  1310 				AND zones.domain_id = domains.id 
  1327 					AND zones.domain_id = domains.id 
  1311 				AND domains.name LIKE '".$question."' 
  1328 					AND domains.name = '".$question."' 
  1312 				GROUP BY domains.id, domains.name, zones.owner, records.domain_id";
  1329 					GROUP BY domains.id, domains.name, zones.owner, records.domain_id";
  1313 
  1330 
  1314 		echo "<br> $sqlq ";
  1331 			$result = $db->query($sqlq);
  1315 		$result = $db->query($sqlq);
  1332 			$ret_d = array();
  1316 		$ret_d = array();
  1333 			while ($r = $result->fetchRow())
  1317 		while ($r = $result->fetchRow())
  1334 			{
  1318 		{
  1335 			    if(xs($r['domain_id']))
  1319 		    if(xs($r['domain_id']))
  1336 			    {
  1320 		    {
  1337 				    $ret_d[] = array(
  1321 			    $ret_d[] = array(
  1338     					'id'			=>	$r['id'],
  1322 				'id'			=>	$r['id'],
  1339     					'name'		=>	$r['name'],
  1323 				'name'		=>	$r['name'],
  1340     					'numrec'		=>	$r['numrec'],
  1324 				'numrec'		=>	$r['numrec'],
  1341     					'owner'		=>	$r['owner']
  1325 				'owner'		=>	$r['owner']
  1342     				);
  1326 			);
  1343 				}
       
  1344 			}
  1327 			}
  1345 
  1328 		}
  1346 			$sqlq = "SELECT * FROM records WHERE name = '".$question."' OR content = '".$question."' ORDER BY type DESC";
       
  1347 			$result = $db->query($sqlq);
       
  1348 			while ($r = $result->fetchRow())
       
  1349 			{
       
  1350 			    if(xs($r['domain_id']))
       
  1351 			    {
       
  1352     				$ret_r[] = array(
       
  1353     					'id'			=>	$r['id'],
       
  1354     					'domain_id'		=>	$r['domain_id'],
       
  1355     					'name'		=>	$r['name'],
       
  1356     					'type'		=>	$r['type'],
       
  1357     					'content'		=>	$r['content'],
       
  1358     					'ttl'			=>	$r['ttl'],
       
  1359     					'prio'		=>	$r['prio'],
       
  1360     				);
       
  1361     			}
       
  1362 			}
       
  1363 			break;
       
  1364 	}
       
  1365 	if($S_INPUT_TYPE == 1)
       
  1366 	{
       
  1367 		return array('domains' => $ret_d, 'records' => $ret_r);
  1329 		return array('domains' => $ret_d, 'records' => $ret_r);
  1368 	}
  1330 	}
  1369 	return array('records' => $ret_r);
  1331 	else
       
  1332 	{
       
  1333 		error(sprintf(ERR_INV_ARGC, "search_record", "Invalid searchstring: $question"));
       
  1334 	}
       
  1335 
  1370 }
  1336 }
  1371 
  1337 
  1372 function get_domain_type($id)
  1338 function get_domain_type($id)
  1373 {
  1339 {
  1374 	global $db;
  1340 	global $db;