VCL-1148 - siteconfig - handle mariadb update query returning -1 when row successfully updated

siteconfig.php:
-added fixAffectedRowsRC
-modified AJaddAffiliationSetting: added btn to data returned in AJAX error when invalid $affilid passed in
-modified AffilHelpAddress->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilHelpAddress->deleteValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilWebAddress->__construct: small change to $constraints
-modified AffilWebAddress->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilWebAddress->deleteValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilKMSserver->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilKMSserver->deleteValue: added code similar to fixAffectedRowsRC specific to this function
-modified AffilTheme->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilTheme->deleteValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilShibOnly->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilShibName->setValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
-modified AffilShibName->deleteValue: added call to fixAffectedRowsRC after $rc = mysqli_affected_rows
diff --git a/web/.ht-inc/siteconfig.php b/web/.ht-inc/siteconfig.php
index 1790405..e299c05 100644
--- a/web/.ht-inc/siteconfig.php
+++ b/web/.ht-inc/siteconfig.php
@@ -209,6 +209,29 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn fixAffectedRowsRC(&$rc)
+///
+/// \param $rc (pass by reference) - return code to evaluate
+///
+/// \brief checks if $rc is -1, and if so check that a row was successfully
+/// updated and no errors were encountered and change $rc to 1 if that is the
+/// case
+///
+////////////////////////////////////////////////////////////////////////////////
+function fixAffectedRowsRC(&$rc) {
+	global $mysqli_link_vcl;
+	if($rc == -1) {
+		# weird condition where row gets successfully updated and there is no
+		# error, but -1 is returned
+		$errno = mysqli_errno($mysqli_link_vcl);
+		$qinfo = mysqli_info($mysqli_link_vcl);
+		if($errno == 0 && $qinfo == 'Rows matched: 1  Changed: 1  Warnings: 0')
+			$rc = 1;
+	}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \class TimeVariable
 ///
 /// \brief base class for time related variables related to when vcld takes
@@ -1070,7 +1093,8 @@
 		if(! array_key_exists($affilid, $affils)) {
 			$arr = array('status' => 'failed',
 			             'msgid' => "{$this->domidbase}msg",
-			             'errmsg' => i('Invalid affiliation submitted.'));
+			             'errmsg' => i('Invalid affiliation submitted.'),
+			             'btn' => "{$this->domidbase}addbtn");
 			sendJSON($arr);
 			return;
 		}
@@ -1216,7 +1240,7 @@
 		if(! array_key_exists($affilid, $origvals)) {
 			$arr = array('status' => 'failed',
 			             'msgid' => "{$this->domidbase}msg",
-			             'msg' => i('Invalid data submitted.'));
+			             'errmsg' => i('Invalid data submitted.'));
 			sendJSON($arr);
 			return;
 		}
@@ -1322,6 +1346,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1345,6 +1370,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1370,7 +1396,7 @@
 		parent::__construct();
 		$this->name = i("Site Web Address");
 		$this->desc = i("This is the web address in emails sent by the VCL system to users.");
-		$this->constraints = '^http(s)?://([-A-Za-z0-9]{1,63})(\.[A-Za-z0-9-_]+)*(\.?[A-Za-z0-9])(/[-a-zA-Z0-9\._~&\+,=:@]*)*$';
+		$this->constraints = '^http(s)?://([-A-Za-z0-9]{1,63})(\.[A-Za-z0-9-_]+)*(\.?[A-Za-z0-9])(/[-a-zA-Z0-9\._~&\+,=:@%\?]*)*$';
 		$this->errmsg = i("Invalid web address(es) specified");
 		$this->domidbase = "affilwebaddr";
 		$this->jsname = "affilwebaddr";
@@ -1421,6 +1447,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1444,6 +1471,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1609,6 +1637,7 @@
 			       .       "affiliationid = $affilid";
 			doQuery($query);
 			$tmp = mysqli_affected_rows($mysqli_link_vcl);
+			fixAffectedRowsRC($tmp);
 			if($rc2)
 				$rc2 = $tmp;
 		}
@@ -1649,6 +1678,17 @@
 		       . "WHERE affiliationid = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		# code to handle mysqli_affected_rows incorrectly returning -1
+		$errno = mysqli_errno($mysqli_link_vcl);
+		if($rc == -1 && $errno == 0) {
+			$query = "SELECT affiliationid FROM winKMS WHERE affiliationid = $affilid";
+			$qh = doQuery($query);
+			if(mysqli_num_rows($qh))
+				return 0;
+			else
+				return 1;
+		}
+		# end -1 handling code
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1740,6 +1780,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1763,6 +1804,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1859,6 +1901,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1974,6 +2017,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -1997,6 +2041,7 @@
 		       . "WHERE id = $affilid";
 		doQuery($query);
 		$rc = mysqli_affected_rows($mysqli_link_vcl);
+		fixAffectedRowsRC($rc);
 		if($rc == 1)
 			return 1;
 		return 0;
@@ -2755,7 +2800,8 @@
 		foreach($vals as $key => $val) {
 			$tmp = explode('|', $key);
 			$id = $tmp[1];
-			$this->values[$id] = $val;
+			if(isset($this->units[$id]))
+				$this->values[$id] = $val;
 		}*/
 		$formbase = ' <hostname or IP>:<export path>,<mount path>';
 		$this->desc = _("NFS Mounts are NFS exports that are to be mounted within each reservation deployed by a given management node.<br>Values must be like") . $formbase;