search.php
changeset 82 c255196bc447
parent 79 0c0aa144356a
child 110 455405c757e1
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
    18  *  You should have received a copy of the GNU General Public License
    18  *  You should have received a copy of the GNU General Public License
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    20  */
    20  */
    21 
    21 
    22 require_once('inc/toolkit.inc.php');
    22 require_once('inc/toolkit.inc.php');
       
    23 include_once('inc/header.inc.php');
    23 
    24 
    24 if (isset($_POST['s_submit']) || isset($_POST['q']))
    25 if (!(verify_permission(search))) {
    25 {
    26 	error(ERR_PERM_SEARCH);
    26 	$submitted=true;
    27 	include_once('inc/footer.inc.php');
    27 	$search_result=search_record($_POST['q']);
    28 	exit;
       
    29 	
    28 } else {
    30 } else {
    29 	$submitted = false;
    31 	echo "     <h2>" . _('Search zones and records') . "</h2>\n";
    30 }
       
    31 
    32 
    32 // we will continue after the search form ... 
    33 	if ($_POST['submit']) {
    33 include_once('inc/header.inc.php');
       
    34 ?>
       
    35 
    34 
    36     <h2><?php echo _('Search zones or records'); ?></h2>
    35 		if (verify_permission(zone_content_view_others)) { $perm_view = "all" ; }
    37     <h3>Query</h3>
    36 		elseif (verify_permission(zone_content_view_own)) { $perm_view = "own" ; }
    38     <table>
    37 		else { $perm_view = "none" ; }
    39      <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
       
    40       <tr>
       
    41        <td class="n"><?php echo _('Enter a hostname or IP address'); ?></td>
       
    42        <td class="n"><input type="text" class="input" name="q"></td>
       
    43       </tr>
       
    44       <tr>
       
    45        <td class="n">&nbsp;</td>
       
    46        <td class="n"><input type="submit" class="button" name="s_submit" value="<?php echo _('Search'); ?>"></td>
       
    47       </tr>
       
    48      </form>
       
    49     </table>
       
    50       
       
    51 <?php
       
    52 // results
       
    53 
    38 
    54 if ($submitted)
    39 		if (verify_permission(zone_content_edit_others)) { $perm_edit = "all" ; }
    55 {
    40 		elseif (verify_permission(zone_content_edit_own)) { $perm_edit = "own" ; }
    56 	echo '<br><br>';
    41 		else { $perm_edit = "none" ; }
       
    42 	
       
    43 		$holy_grail = $_POST['query'];
    57 
    44 
    58   	// let's check if we found any domains ...
    45 		$result = search_zone_and_record($holy_grail,$perm_view);
    59 	if (count($search_result) == 2 && count($search_result['domains']))
    46 
    60   	{
    47 		if (is_array($result['zones'])) {
    61 	?>
    48 			echo "     <h3>" . _('Zones found') . ":</h3>\n";
    62 	<h4><?php echo _('Zones found'); ?>:</h4>
    49 			echo "     <table>\n";
    63 	<table>
    50 			echo "      <tr>\n";
    64 	 <tr>
    51 			echo "       <th>&nbsp;</th>\n";
    65 	  <th>&nbsp;</th>
    52 			echo "       <th>" . _('Name') . "</th>\n";
    66 	  <th><?php echo _('Name'); ?></th>
    53 			echo "       <th>" . _('Type') . "</th>\n";
    67 	  <th><?php echo _('Records'); ?></th>
    54 			echo "       <th>" . _('Master') . "</th>\n";
    68 	  <th><?php echo _('Owner'); ?></th>
    55 			echo "      </tr>\n";
    69          </tr>
    56 
    70 <?php
    57 			foreach ($result['zones'] as $zone) {
    71 foreach($search_result['domains'] as $d)
    58 				echo "      <tr>\n";
    72 {
    59 				echo "          <td>\n";
    73 ?>
    60 				echo "           <a href=\"edit.php?id=" . $zone['zid'] . "\"><img src=\"images/edit.gif\" title=\"" . _('Edit zone') . " " . $zone['name'] . "\" alt=\"[ " . _('Edit zone') . " " . $zone['name'] . " ]\"></a>\n";
    74          <tr>
    61 				if ( $perm_edit != "all" || $perm_edit != "none") {
    75 <?php
    62 					$user_is_zone_owner = verify_user_is_owner_zoneid($zone['zid']);
    76   if (level(5))
    63 				}
    77   {
    64 				if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) {
    78   ?>
    65 					echo "           <a href=\"delete_domain.php?id=" . $zone['zid'] . "\"><img src=\"images/delete.gif\" title=\"" . _('Delete zone') . " " . $zone['name'] . "\" alt=\"[ ". _('Delete zone') . " " . $zone['name'] . " ]\"></a>\n";
    79      <td class="n">
    66 				}
    80       <a href="edit.php?id=<?php echo $d["id"] ?>"><img src="images/edit.gif" title="<?php echo _('Edit zone') . " " . $d['name']; ?>" alt="[ <?php echo _('Edit zone') . " " . $d['name']; ?> ]"></a>
    67 				echo "          </td>\n";
    81       <a href="delete_domain.php?id=<?php echo $d["id"] ?>"><img src="images/delete.gif" title="<?php print _('Delete zone') . " " . $d['name']; ?>" alt="[<?php echo _('Delete zone') . " " . $d['name']; ?>]"></a>
    68 				echo "       <td>" . $zone['name'] . "</td>\n";
    82      </td>
    69 				echo "       <td>" . $zone['type'] . "</td>\n";
    83 <?php
    70 				if ($zone['type'] == "SLAVE") {
    84 }
    71 					echo "       <td>" . $zone['master'] . "</td>\n";
    85 else
    72 				} else {
    86 {
    73 					echo "       <td>&nbsp;</td>\n";
    87 ?>
    74 				}
    88      <td class="n">
    75 				echo "      </tr>\n";
    89       &nbsp;
       
    90      </td>
       
    91 <?php
       
    92 }
       
    93 ?>
       
    94      <td class="y"><?php echo $d['name']?></td>
       
    95      <td class="y"><?php echo $d['numrec']?></td>
       
    96      <td class="y"><?php echo get_owner_from_id($d['owner'])?></td>
       
    97     </tr>
       
    98 			<?php
       
    99 		} // end foreach ...
       
   100 		?>
       
   101 	</table>
       
   102 	<br><br>
       
   103 	<?php
       
   104 	} // end if
       
   105 	
       
   106 	// any records ?!
       
   107 	if(count($search_result['records']))
       
   108 	{
       
   109 		?>
       
   110 		<b><?php echo _('Records found'); ?>:</b>
       
   111 		<p>
       
   112 		<table>
       
   113 			<tr>
       
   114 				<td class="n">&nbsp;</td>
       
   115 				<td class="n"><?php echo _('Name'); ?></td>
       
   116 				<td class="n"><?php echo _('Type'); ?></td>
       
   117 				<td class="n"><?php echo _('Content'); ?></td>
       
   118 				<td class="n"><?php echo _('Priority'); ?></td>
       
   119 				<td class="n"><?php echo _('TTL'); ?></td>
       
   120 			</tr>
       
   121 		<?php
       
   122 		foreach($search_result['records'] as $r)
       
   123 		{
       
   124 		?>
       
   125 			<tr>
       
   126 				<td class="n">
       
   127 			<?php
       
   128 			if (($r["type"] != "SOA" && $r["type"] != "NS") ||
       
   129 			  ($GLOBALS["ALLOW_SOA_EDIT"] && $r["type"] == "SOA") ||
       
   130 			  ($GLOBALS["ALLOW_NS_EDIT"] && $r["type"] == "NS") ||
       
   131 			  ($r["type"] == "NS" && get_name_from_record_id($r["id"]) != get_domain_name_from_id(recid_to_domid($r["id"])) && 
       
   132 			  $GLOBALS["ALLOW_NS_EDIT"] != 1))
       
   133 			{
       
   134 				?>
       
   135 				<a href="edit_record.php?id=<?php echo $r['id']?>&amp;domain=<?php echo $r['domain_id']?>"><img src="images/edit.gif" alt="[ <?php echo _('Edit record'); ?> ]" border="0"></a>
       
   136 				<a href="delete_record.php?id=<?php echo $r['id']?>&amp;domain=<?php echo $r['domain_id']?>"><img src="images/delete.gif" alt="[ <?php echo _('Delete record'); ?> ]" border="0"></a>
       
   137 				<?php 
       
   138 			} // big if ;-)
       
   139 			?>
       
   140 			</td>
       
   141 			<td class="y"><?php echo $r['name']?></td>
       
   142 			<td class="y"><?php echo $r['type']?></td>
       
   143 			<td class="y"><?php echo $r['content']?></td>
       
   144 			<?php
       
   145 			if ($r['prio'] != 0)
       
   146 			{
       
   147 				?><td class="y"><?php echo $r['prio']?></td><?php
       
   148 			}
    76 			}
   149 			else 
    77 			echo "     </table>\n";
   150 			{
    78 		}
   151 			?><td class="n"></td><?php
    79 
   152 			} // else
    80 		if (is_array($result['records'])) {
   153 			?><td class="y"><?php echo $r['ttl']?></td>
    81 			echo "     <h3>" . _('Records found') . ":</h3>\n";
   154 			</tr>
    82 			echo "     <table>\n";
   155 			<?php
    83 			echo "      <tr>\n";
   156 		} // foreach
    84 			echo "       <th>&nbsp;</th>\n";
   157 	?>
    85 			echo "       <th>" . _('Name') . "</th>\n";
   158 	</table>
    86 			echo "       <th>" . _('Type') . "</th>\n";
   159 	<?php
    87 			echo "       <th>" . _('Prio') . "</th>\n";
   160 	} // if
    88 			echo "       <th>" . _('Content') . "</th>\n";
   161 	if(count($search_result['domains']) == 0 && count($search_result['records']) == 0)
    89 			echo "       <th>" . _('TTL') . "</th>\n";
   162 	{
    90 			echo "      </tr>\n";
   163 	?>
    91 
   164 		<table border="0" cellspacing="4">
    92 			foreach ($result['records'] as $record) {
   165 			<tr>
    93 
   166 				<td width="510" class="n">
    94 				echo "      <tr>\n";
   167 				<?php echo _('Nothing found for query'); ?> "<?php echo $_POST['q']?>".
    95 				echo "          <td>\n";
   168 				</td>
    96 				echo "           <a href=\"edit_record.php?id=" . $record['rid'] . "\"><img src=\"images/edit.gif\" title=\"" . _('Edit record') . " " . $record['name'] . "\" alt=\"[ " . _('Edit record') . " " . $record['name'] . " ]\"></a>\n";
   169 			</tr>
    97 				if ( $perm_edit != "all" || $perm_edit != "none") {
   170 		</table>
    98 					$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']);
   171 	<?php
    99 				}
       
   100 				if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) {
       
   101 					echo "           <a href=\"delete_record.php?id=" . $record['rid'] . "\"><img src=\"images/delete.gif\" title=\"" . _('Delete record') . " " . $record['name'] . "\" alt=\"[ ". _('Delete record') . " " . $record['name'] . " ]\"></a>\n";
       
   102 				}
       
   103 				echo "          </td>\n";
       
   104 				echo "       <td>" . $record['name'] . "</td>\n";
       
   105 				echo "       <td>" . $record['type'] . "</td>\n";
       
   106 				if ($record['type'] == "MX") {
       
   107 					echo "       <td>" . $record['prio'] . "</td>\n";
       
   108 				} else {
       
   109 					echo "       <td>&nbsp;</td>\n";
       
   110 				}
       
   111 				echo "       <td>" . $record['content'] . "</td>\n";
       
   112 				echo "       <td>" . $record['ttl'] . "</td>\n";
       
   113 				echo "      </tr>\n";
       
   114 			}
       
   115 			echo "     </table>\n";
       
   116 		}
       
   117 
   172 	}
   118 	}
   173 		
   119 
       
   120 	echo "     <h3>" . _('Query') . ":</h3>\n";
       
   121 	echo "     <table>\n";
       
   122 	echo "      <form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n";
       
   123 	echo "       <tr>\n";
       
   124 	echo "        <td class=\"n\">" . _('Enter a hostname or IP address') . "</td>\n";
       
   125 	echo "        <td class=\"n\"><input type=\"text\" class=\"input\" name=\"query\" value=\"" . $holy_grail . "\"></td>\n";
       
   126 	echo "       </tr>\n";
       
   127 	echo "       <tr>\n";
       
   128 	echo "        <td class=\"n\">&nbsp;</td>\n";
       
   129 	echo "        <td class=\"n\"><input type=\"submit\" class=\"button\" name=\"submit\" value=\"" . _('Search') . "\"></td>\n";
       
   130 	echo "       </tr>\n";
       
   131 	echo "      </form>\n";
       
   132 	echo "     </table>\n";
       
   133 
   174 }
   134 }
   175 include_once('inc/footer.inc.php');
   135 include_once('inc/footer.inc.php');
   176 ?>
   136 ?>
   177 
   137