[feladat @ 247]
authorrejo
Thu, 24 Apr 2008 22:33:28 +0000
changeset 141 1ede5203910d
parent 140 e68c3d6094d1
child 142 edd0c3ee3e1d
[feladat @ 247] If the user was listing the details of a zone that did not exist, all kinds of error messages were given. Now we first determine if the ID is valid and if not, immediately return the correct error message.
docs/i18n-template-php.pot
edit.php
inc/error.inc.php
inc/record.inc.php
locale/nl_NL/LC_MESSAGES/nl.po
--- a/docs/i18n-template-php.pot	Thu Apr 24 21:07:27 2008 +0000
+++ b/docs/i18n-template-php.pot	Thu Apr 24 22:33:28 2008 +0000
@@ -16,6 +16,9 @@
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
+msgid "There is no zone with this ID."
+msgstr ""
+
 #: add_perm_templ.php:35 list_perm_templ.php:60
 msgid "Add permission template"
 msgstr ""
--- a/edit.php	Thu Apr 24 21:07:27 2008 +0000
+++ b/edit.php	Thu Apr 24 22:33:28 2008 +0000
@@ -69,164 +69,138 @@
 	delete_owner_from_zone($zone_id, $_POST["delete_owner"]);
 }
 
-$domain_type=get_domain_type($zone_id);
-$record_count=count_zone_records($zone_id);
-
-echo "   <h2>" . _('Edit zone') . " \"" . get_zone_name_from_id($zone_id) . "\"</h2>\n";
-
 if ( $perm_view == "none" || $perm_view == "own" && $user_is_zone_owner == "0" ) {
 	error(ERR_PERM_VIEW_ZONE);
 } else {
-	echo "   <div class=\"showmax\">\n";
-	show_pages($record_count,$iface_rowamount,$zone_id);
-	echo "   </div>\n";
+
+	if (zone_id_exists($zone_id) == "0") {
+		error(ERR_ZONE_NOT_EXIST);
+	} else  {	
+		$domain_type=get_domain_type($zone_id);
+		$record_count=count_zone_records($zone_id);
+
+		echo "   <h2>" . _('Edit zone') . " \"" . get_zone_name_from_id($zone_id) . "\"</h2>\n";
+
+		echo "   <div class=\"showmax\">\n";
+		show_pages($record_count,$iface_rowamount,$zone_id);
+		echo "   </div>\n";
 
-	$records = get_records_from_domain_id($zone_id,ROWSTART,$iface_rowamount);
-	if ( $records == "-1" ) { 
-		echo " <p>" .  _("This zone does not have any records. Weird.") . "</p>\n";
-	} else {
-		echo "   <form method=\"post\">\n";
-		echo "   <table>\n";
-		echo "    <tr>\n";
-		echo "     <th>&nbsp;</th>\n";
-		echo "     <th>" . _('Name') . "</th>\n";
-		echo "     <th>" . _('Type') . "</th>\n";
-		echo "     <th>" . _('Content') . "</th>\n";
-		echo "     <th>" . _('Priority') . "</th>\n";
-		echo "     <th>" . _('TTL') . "</th>\n";
-		echo "    </tr>\n";
-		foreach ($records as $r) {
-			echo "    <input type=\"hidden\" name=\"record[" . $r['id'] . "][rid]\" value=\"" . $r['id'] . "\">\n";
-			echo "    <input type=\"hidden\" name=\"record[" . $r['id'] . "][zid]\" value=\"" . $zone_id . "\">\n";
+		$records = get_records_from_domain_id($zone_id,ROWSTART,$iface_rowamount);
+		if ( $records == "-1" ) { 
+			echo " <p>" .  _("This zone does not have any records. Weird.") . "</p>\n";
+		} else {
+			echo "   <form method=\"post\">\n";
+			echo "   <table>\n";
 			echo "    <tr>\n";
-			if ( $domain_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) {
-				echo "     <td class=\"n\">&nbsp;</td>\n";
-			} else {
-				echo "     <td class=\"n\">\n";
-				echo "      <a href=\"edit_record.php?id=" . $r['id'] . "&amp;domain=" . $zone_id . "\">
-						<img src=\"images/edit.gif\" alt=\"[ ". _('Edit record') . " ]\"></a>\n";
-				echo "      <a href=\"delete_record.php?id=" . $r['id'] . "&amp;domain=" . $zone_id . "\">
-						<img src=\"images/delete.gif\" ALT=\"[ " . _('Delete record') . " ]\" BORDER=\"0\"></a>\n";
-				echo "     </td>\n";
-			}
-			echo "      <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][name]\" value=\"" . $r['name'] . "\"></td>\n";
-			echo "      <td class=\"u\">\n";
-			echo "       <select name=\"record[" . $r['id'] . "][type]\">\n";
-			foreach (get_record_types() as $type_available) {
-				if ($type_available == $r['type']) {
-					$add = " SELECTED";
+			echo "     <th>&nbsp;</th>\n";
+			echo "     <th>" . _('Name') . "</th>\n";
+			echo "     <th>" . _('Type') . "</th>\n";
+			echo "     <th>" . _('Content') . "</th>\n";
+			echo "     <th>" . _('Priority') . "</th>\n";
+			echo "     <th>" . _('TTL') . "</th>\n";
+			echo "    </tr>\n";
+			foreach ($records as $r) {
+				echo "    <input type=\"hidden\" name=\"record[" . $r['id'] . "][rid]\" value=\"" . $r['id'] . "\">\n";
+				echo "    <input type=\"hidden\" name=\"record[" . $r['id'] . "][zid]\" value=\"" . $zone_id . "\">\n";
+				echo "    <tr>\n";
+				if ( $domain_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) {
+					echo "     <td class=\"n\">&nbsp;</td>\n";
 				} else {
-					$add = "";
+					echo "     <td class=\"n\">\n";
+					echo "      <a href=\"edit_record.php?id=" . $r['id'] . "&amp;domain=" . $zone_id . "\">
+							<img src=\"images/edit.gif\" alt=\"[ ". _('Edit record') . " ]\"></a>\n";
+					echo "      <a href=\"delete_record.php?id=" . $r['id'] . "&amp;domain=" . $zone_id . "\">
+							<img src=\"images/delete.gif\" ALT=\"[ " . _('Delete record') . " ]\" BORDER=\"0\"></a>\n";
+					echo "     </td>\n";
 				}
-				echo "         <option" . $add . " value=\"" . $type_available . "\" >" . $type_available . "</option>\n";
+				echo "      <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][name]\" value=\"" . $r['name'] . "\"></td>\n";
+				echo "      <td class=\"u\">\n";
+				echo "       <select name=\"record[" . $r['id'] . "][type]\">\n";
+				foreach (get_record_types() as $type_available) {
+					if ($type_available == $r['type']) {
+						$add = " SELECTED";
+					} else {
+						$add = "";
+					}
+					echo "         <option" . $add . " value=\"" . $type_available . "\" >" . $type_available . "</option>\n";
+				}
+				echo "       </select>\n";
+				echo "      </td>\n";
+				echo "      <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][content]\" value=\"" . $r['content'] . "\"></td>\n";
+				if ($r['type'] == "MX") { 
+					echo "      <td class=\"u\"><input name=\"record[" . $r['id'] . "][prio]\" value=\"" .  $r['prio'] . "\"></td>\n";
+				} else {
+					echo "      <td class=\"n\">&nbsp;</td>\n";
+				}
+				echo "      <td class=\"u\"><input name=\"record[" . $r['id'] . "][ttl]\" value=\"" . $r['ttl'] . "\"></td>\n";
+				echo "     </tr>\n";
 			}
-			echo "       </select>\n";
-			echo "      </td>\n";
-			echo "      <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][content]\" value=\"" . $r['content'] . "\"></td>\n";
-			if ($r['type'] == "MX") { 
-				echo "      <td class=\"u\"><input name=\"record[" . $r['id'] . "][prio]\" value=\"" .  $r['prio'] . "\"></td>\n";
-			} else {
-				echo "      <td class=\"n\">&nbsp;</td>\n";
-			}
-			echo "      <td class=\"u\"><input name=\"record[" . $r['id'] . "][ttl]\" value=\"" . $r['ttl'] . "\"></td>\n";
-			echo "     </tr>\n";
-		}
-		echo "    </table>\n";
-		echo "     <input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Commit changes') . "\">\n";
-		echo "    </form>";
-	}
-	
-	if ( $perm_content_edit == "all" || $perm_content_edit == "own" && $user_is_zone_owner == "1" ) {
-		if ( $domain_type != "SLAVE") {
-			echo "    <input type=\"button\" class=\"button\" OnClick=\"location.href='add_record.php?id=" . $zone_id . "'\" value=\"" . _('Add record') . "\">&nbsp;&nbsp\n";
+			echo "    </table>\n";
+			echo "     <input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Commit changes') . "\">\n";
+			echo "    </form>";
 		}
-		echo "    <input type=\"button\" class=\"button\" OnClick=\"location.href='delete_domain.php?id=" . $zone_id . "'\" value=\"" . _('Delete zone') . "\">\n";
-	}
-
-	echo "   <div id=\"meta\">\n";
-	echo "    <table>\n";
-	echo "     <tr>\n";
-	echo "      <th colspan=\"2\">" . _('Owner of zone') . "</th>\n";
-	echo "     </tr>\n";
-
-	$owners = get_users_from_domain_id($zone_id);
-
-	if ($owners == "-1") {
-		echo "      <tr><td>" . _('No owner set for this zone.') . "</td></tr>";
-	} else {
-		if ($meta_edit) {
-			foreach ($owners as $owner) {
-				echo "      <form method=\"post\" action=\"edit.php?id=" . $zone_id . "\">\n";
-				echo "       <tr>\n";
-				echo "        <td>" . $owner["fullname"] . "</td>\n";
-				echo "        <td>\n";
-				echo "         <input type=\"hidden\" name=\"delete_owner\" value=\"" . $owner["id"] . "\">\n";
-				echo "         <input type=\"submit\" class=\"sbutton\" name=\"co\" value=\"" . _('Delete') . "\">\n";
-				echo "        </td>\n";
-				echo "       </tr>\n";
-				echo "      </form>\n";
+		
+		if ( $perm_content_edit == "all" || $perm_content_edit == "own" && $user_is_zone_owner == "1" ) {
+			if ( $domain_type != "SLAVE") {
+				echo "    <input type=\"button\" class=\"button\" OnClick=\"location.href='add_record.php?id=" . $zone_id . "'\" value=\"" . _('Add record') . "\">&nbsp;&nbsp\n";
 			}
-		} else {
-			foreach ($owners as $owner) {
-				echo "    <tr><td>" . $owner["fullname"] . "</td><td>&nbsp;</td></tr>";
-			}
+			echo "    <input type=\"button\" class=\"button\" OnClick=\"location.href='delete_domain.php?id=" . $zone_id . "'\" value=\"" . _('Delete zone') . "\">\n";
 		}
 
-	}
-	if ($meta_edit) {
-		echo "      <form method=\"post\" action=\"edit.php?id=" . $zone_id . "\">\n";
-		echo "       <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
-		echo "       <tr>\n";
-		echo "        <td>\n";
-		echo "         <select name=\"newowner\">\n";
-		$users = show_users();
-		foreach ($users as $user) {
-			$add = '';
-			if ($user["id"] == $_SESSION["userid"]) {
-				$add = " SELECTED";
-			}
-			echo "          <option" . $add . " value=\"" . $user["id"] . "\">" . $user["fullname"] . "</option>\n";
-		}
-		echo "         </select>\n";
-		echo "        </td>\n";
-		echo "        <td>\n";
-		echo "         <input type=\"submit\" class=\"sbutton\" name=\"co\" value=\"" . _('Add') . "\">\n";
-		echo "        </td>\n";
-		echo "       </tr>\n";
-		echo "      </form>\n";
-	}
-	echo "      <tr>\n";
-	echo "       <th colspan=\"2\">" . _('Type') . "</th>\n";
-	echo "      </tr>\n";
+		echo "   <div id=\"meta\">\n";
+		echo "    <table>\n";
+		echo "     <tr>\n";
+		echo "      <th colspan=\"2\">" . _('Owner of zone') . "</th>\n";
+		echo "     </tr>\n";
+
+		$owners = get_users_from_domain_id($zone_id);
 
-	if ($meta_edit) {
-		echo "      <form action=\"" . $_SERVER['PHP_SELF'] . "?id=" . $zone_id . "\" method=\"post\">\n";
-		echo "       <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
-		echo "       <tr>\n";
-		echo "        <td>\n";
-		echo "         <select name=\"newtype\">\n";
-		foreach($server_types as $type) {
-			$add = '';
-			if ($type == $domain_type) {
-				$add = " SELECTED";
+		if ($owners == "-1") {
+			echo "      <tr><td>" . _('No owner set for this zone.') . "</td></tr>";
+		} else {
+			if ($meta_edit) {
+				foreach ($owners as $owner) {
+					echo "      <form method=\"post\" action=\"edit.php?id=" . $zone_id . "\">\n";
+					echo "       <tr>\n";
+					echo "        <td>" . $owner["fullname"] . "</td>\n";
+					echo "        <td>\n";
+					echo "         <input type=\"hidden\" name=\"delete_owner\" value=\"" . $owner["id"] . "\">\n";
+					echo "         <input type=\"submit\" class=\"sbutton\" name=\"co\" value=\"" . _('Delete') . "\">\n";
+					echo "        </td>\n";
+					echo "       </tr>\n";
+					echo "      </form>\n";
+				}
+			} else {
+				foreach ($owners as $owner) {
+					echo "    <tr><td>" . $owner["fullname"] . "</td><td>&nbsp;</td></tr>";
+				}
 			}
-			echo "          <option" .  $add . " value=\"" . $type . "\">" .  strtolower($type) . "</option>\n";
+
 		}
-		echo "         </select>\n";
-		echo "        </td>\n";
-		echo "        <td>\n";
-		echo "         <input type=\"submit\" class=\"sbutton\" name=\"type_change\" value=\"" . _('Change') . "\">\n";
-		echo "        </td>\n";
-		echo "       </tr>\n";
-		echo "      </form>\n";
-	} else {
-		echo "      <tr><td>" . strtolower($domain_type) . "</td><td>&nbsp;</td></tr>\n";
-	}
-
-	if ($domain_type == "SLAVE" ) { 
-		$slave_master=get_domain_slave_master($zone_id);
+		if ($meta_edit) {
+			echo "      <form method=\"post\" action=\"edit.php?id=" . $zone_id . "\">\n";
+			echo "       <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
+			echo "       <tr>\n";
+			echo "        <td>\n";
+			echo "         <select name=\"newowner\">\n";
+			$users = show_users();
+			foreach ($users as $user) {
+				$add = '';
+				if ($user["id"] == $_SESSION["userid"]) {
+					$add = " SELECTED";
+				}
+				echo "          <option" . $add . " value=\"" . $user["id"] . "\">" . $user["fullname"] . "</option>\n";
+			}
+			echo "         </select>\n";
+			echo "        </td>\n";
+			echo "        <td>\n";
+			echo "         <input type=\"submit\" class=\"sbutton\" name=\"co\" value=\"" . _('Add') . "\">\n";
+			echo "        </td>\n";
+			echo "       </tr>\n";
+			echo "      </form>\n";
+		}
 		echo "      <tr>\n";
-		echo "       <th colspan=\"2\">" . _('IP address of master NS') . "</th>\n";
+		echo "       <th colspan=\"2\">" . _('Type') . "</th>\n";
 		echo "      </tr>\n";
 
 		if ($meta_edit) {
@@ -234,19 +208,50 @@
 			echo "       <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
 			echo "       <tr>\n";
 			echo "        <td>\n";
-			echo "         <input type=\"text\" name=\"new_master\" value=\"" . $slave_master . "\" class=\"input\">\n";
+			echo "         <select name=\"newtype\">\n";
+			foreach($server_types as $type) {
+				$add = '';
+				if ($type == $domain_type) {
+					$add = " SELECTED";
+				}
+				echo "          <option" .  $add . " value=\"" . $type . "\">" .  strtolower($type) . "</option>\n";
+			}
+			echo "         </select>\n";
 			echo "        </td>\n";
 			echo "        <td>\n";
-			echo "         <input type=\"submit\" class=\"sbutton\" name=\"slave_master_change\" value=\"" . _('Change') . "\">\n";
+			echo "         <input type=\"submit\" class=\"sbutton\" name=\"type_change\" value=\"" . _('Change') . "\">\n";
 			echo "        </td>\n";
 			echo "       </tr>\n";
 			echo "      </form>\n";
 		} else {
-			echo "      <tr><td>" . $slave_master . "</td><td>&nbsp;</td></tr>\n";
+			echo "      <tr><td>" . strtolower($domain_type) . "</td><td>&nbsp;</td></tr>\n";
 		}
+
+		if ($domain_type == "SLAVE" ) { 
+			$slave_master=get_domain_slave_master($zone_id);
+			echo "      <tr>\n";
+			echo "       <th colspan=\"2\">" . _('IP address of master NS') . "</th>\n";
+			echo "      </tr>\n";
+
+			if ($meta_edit) {
+				echo "      <form action=\"" . $_SERVER['PHP_SELF'] . "?id=" . $zone_id . "\" method=\"post\">\n";
+				echo "       <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
+				echo "       <tr>\n";
+				echo "        <td>\n";
+				echo "         <input type=\"text\" name=\"new_master\" value=\"" . $slave_master . "\" class=\"input\">\n";
+				echo "        </td>\n";
+				echo "        <td>\n";
+				echo "         <input type=\"submit\" class=\"sbutton\" name=\"slave_master_change\" value=\"" . _('Change') . "\">\n";
+				echo "        </td>\n";
+				echo "       </tr>\n";
+				echo "      </form>\n";
+			} else {
+				echo "      <tr><td>" . $slave_master . "</td><td>&nbsp;</td></tr>\n";
+			}
+		}
+		echo "     </table>\n";
+		echo "   </div>\n";	// eo div meta 
 	}
-	echo "     </table>\n";
-	echo "   </div>\n";	// eo div meta 
 }
 
 include_once("inc/footer.inc.php");
--- a/inc/error.inc.php	Thu Apr 24 21:07:27 2008 +0000
+++ b/inc/error.inc.php	Thu Apr 24 22:33:28 2008 +0000
@@ -58,6 +58,7 @@
 define("ERR_INV_ARGC", _('Invalid argument(s) given to function %s %s'));
 define("ERR_UNKNOWN", _('Unknown error.'));
 define("ERR_INV_EMAIL", _('Enter a valid email address.'));
+define("ERR_ZONE_NOT_EXIST", _('There is no zone with this ID.'));
 
 /* DATABASE */
 define("ERR_DB_NO_DB_NAME", _('No database name has been set in config.inc.php.'));
--- a/inc/record.inc.php	Thu Apr 24 21:07:27 2008 +0000
+++ b/inc/record.inc.php	Thu Apr 24 22:33:28 2008 +0000
@@ -19,6 +19,15 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+function zone_id_exists($zid) {
+	global $db;
+	$query = "SELECT COUNT(id) FROM domains WHERE id = " . $db->quote($zid);
+	$count = $db->queryOne($query);
+	if (PEAR::isError($result)) { error($result->getMessage()); return false; }
+	return $count;
+}
+
+
 function get_zone_id_from_record_id($rid) {
 	global $db;
 	$query = "SELECT domain_id FROM records WHERE id = " . $db->quote($rid);
--- a/locale/nl_NL/LC_MESSAGES/nl.po	Thu Apr 24 21:07:27 2008 +0000
+++ b/locale/nl_NL/LC_MESSAGES/nl.po	Thu Apr 24 22:33:28 2008 +0000
@@ -16,6 +16,9 @@
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
+msgid "There is no zone with this ID."
+msgstr "Er bestaat geen zone met dit ID."
+
 #: add_perm_templ.php:35 list_perm_templ.php:60
 msgid "Add permission template"
 msgstr "Permissie template toevoegen"