You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

476 lines
27 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./user_options_modify.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/user_options_modify.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 26-Oct-04, 20:57
  15. // Modified: $Date: 2017-04-13 02:00:18 +0000 (Thu, 13 Apr 2017) $
  16. // $Author: karnesky $
  17. // $Revision: 1416 $
  18. // This script validates user options selected within the form provided by 'user_options.php'.
  19. // If validation succeeds, it UPDATEs the corresponding table fields for that user and redirects to a receipt page;
  20. // if it fails, it creates error messages and these are later displayed by 'user_options.php'.
  21. // TODO: I18n
  22. // Incorporate some include files:
  23. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  24. include 'includes/include.inc.php'; // include common functions
  25. include 'initialize/ini.inc.php'; // include common variables
  26. // --------------------------------------------------------------------
  27. // START A SESSION:
  28. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  29. start_session(true);
  30. // --------------------------------------------------------------------
  31. // Initialize preferred display language:
  32. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  33. include 'includes/locales.inc.php'; // include the locales
  34. // --------------------------------------------------------------------
  35. // Clear any errors that might have been found previously:
  36. $errors = array();
  37. // Write the (POST) form variables into an array:
  38. foreach($_POST as $varname => $value)
  39. $formVars[$varname] = $value;
  40. // Since checkbox form fields do only get included in the '$_POST' array if they were marked,
  41. // we have to add appropriate array elements for all checkboxes that weren't set:
  42. // (we deal with permission checkboxes separately below)
  43. if (!isset($formVars["export_cite_keys"]))
  44. $formVars["export_cite_keys"] = "no";
  45. if (!isset($formVars["autogenerate_cite_keys"]))
  46. $formVars["autogenerate_cite_keys"] = "no";
  47. if (!isset($formVars["prefer_autogenerated_cite_keys"]))
  48. $formVars["prefer_autogenerated_cite_keys"] = "no";
  49. if (!isset($formVars["use_custom_cite_key_format"]))
  50. $formVars["use_custom_cite_key_format"] = "no";
  51. // $formVars["use_custom_handling_of_nonascii_chars_in_cite_keys"] is handled (differently) below
  52. if (!isset($formVars["uniquify_duplicate_cite_keys"]))
  53. $formVars["uniquify_duplicate_cite_keys"] = "no";
  54. if (!isset($formVars["use_custom_text_citation_format"]))
  55. $formVars["use_custom_text_citation_format"] = "no";
  56. // --------------------------------------------------------------------
  57. // First of all, check if this script was called by something else than 'user_options.php':
  58. if (!preg_match("#/user_options\.php#i", $referer)) // variable '$referer' is globally defined in function 'start_session()' in 'include.inc.php'
  59. {
  60. // return an appropriate error message:
  61. $HeaderString = returnMsg($loc["Warning_InvalidCallToScript"] . " '" . scriptURL() . "'!", "warning", "strong", "HeaderString"); // functions 'returnMsg()' and 'scriptURL()' are defined in 'include.inc.php'
  62. header("Location: " . $referer); // redirect to calling page
  63. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  64. }
  65. // --------------------------------------------------------------------
  66. // (1) OPEN CONNECTION, (2) SELECT DATABASE
  67. connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
  68. // --------------------------------------------------------------------
  69. // VALIDATE FORM DATA:
  70. // (Note: checking for missing/incorrect input of the language field isn't really necessary if a popup is used as input field -- as it is right now)
  71. // // Validate the language
  72. // if (empty($formVars["languageName"]))
  73. // // Language cannot be a null string
  74. // $errors["languageName"] = "The language field cannot be blank:";
  75. // Validate the number of records per page
  76. if (($_REQUEST['userID'] != 0) AND !preg_match("/^[1-9]+[0-9]*$/", $formVars["recordsPerPageNo"])) // this form element is disabled for anonymous users ('userID=0')
  77. $errors["recordsPerPageNo"] = "Please enter a number (positive integer greater than zero):";
  78. // Note: currently, the user must select at least one item within the type/style/format lists. Alternatively, we could grey out the corresponding interface elements
  79. // if a user deselects all items. Or, hiding the corresponding interface elements *completely* would actually give the user the possibility to remove unwanted/unneeded "features"!
  80. // Validate the reference type selector
  81. if (empty($formVars["referenceTypeSelector"]))
  82. $errors["referenceTypeSelector"] = "You must choose at least one reference type:";
  83. // Validate the citation style selector
  84. if (empty($formVars["citationStyleSelector"]))
  85. $errors["citationStyleSelector"] = "You must choose at least one citation style:";
  86. // Validate the cite format selector
  87. if (empty($formVars["citationFormatSelector"]))
  88. $errors["citationFormatSelector"] = "You must choose at least one citation format:";
  89. // Validate the export format selector
  90. if (empty($formVars["exportFormatSelector"]))
  91. $errors["exportFormatSelector"] = "You must choose at least one export format:";
  92. // Validate the main fields selector
  93. if (($_REQUEST['userID'] != 0) AND empty($formVars["mainFieldsSelector"])) // this form element is disabled for anonymous users ('userID=0')
  94. $errors["mainFieldsSelector"] = "You must specify at least one field as \"main field\":";
  95. // --------------------------------------------------------------------
  96. // Now the script has finished the validation, check if there were any errors:
  97. if (count($errors) > 0)
  98. {
  99. // Write back session variables:
  100. saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  101. saveSessionVariable("formVars", $formVars);
  102. // There are errors. Relocate back to the client form:
  103. header("Location: user_options.php?userID=" . $_REQUEST['userID']); // 'userID' got included as hidden form tag by 'user_options.php'
  104. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  105. }
  106. // --------------------------------------------------------------------
  107. // If we made it here, then the data is considered valid!
  108. // CONSTRUCT SQL QUERY:
  109. // If a user is logged in and has submitted 'user_options.php' with a 'userID' parameter:
  110. // (while the admin has no restrictions, a normal user can only submit 'user_options.php' with his own 'userID' as parameter!)
  111. if (isset($_SESSION['loginEmail']) && ($_REQUEST['userID'] != "")) // -> perform an update:
  112. {
  113. if ($loginEmail != $adminLoginEmail) // if not admin logged in ('$adminLoginEmail' is specified in 'ini.inc.php')
  114. $userID = getUserID($loginEmail); // Get the 'user_id' using 'loginEmail' (function 'getUserID()' is defined in 'include.inc.php')
  115. else // if the admin is logged in he should be able to make any changes to account data/options of _other_ users...
  116. $userID = $_REQUEST['userID']; // ...in this case we accept 'userID' from the GET/POST request (it got included as hidden form tag by 'user_options.php')
  117. // UPDATE - construct queries to update the relevant table fields for this user
  118. // a) update the language field of the 'users' table:
  119. if ($userID != 0) // the 'languageName' form element is disabled for anonymous users ('userID=0'), and there isn't an entry with 'user_id=0' in table 'users'
  120. $queryArray[] = "UPDATE $tableUsers SET "
  121. . "language = " . quote_smart($formVars["languageName"]) . " "
  122. . "WHERE user_id = " . quote_smart($userID);
  123. if ($loginEmail == $adminLoginEmail) // if the admin is logged in
  124. {
  125. // b) update all entries for this user within the 'user_types' table:
  126. // - first, get a list of IDs for all types within the 'user_types' table that are available and were enabled by the admin for the current user:
  127. $enabledUserTypesArray = getEnabledUserFormatsStylesTypes($userID, "type", "", true); // function 'getEnabledUserFormatsStylesTypes()' is defined in 'include.inc.php'
  128. $enabledUserTypesInSelectedTypesArray = array_intersect($enabledUserTypesArray, $formVars["referenceTypeSelector"]);
  129. $enabledUserTypesNOTInSelectedTypesArray = array_diff($enabledUserTypesArray, $formVars["referenceTypeSelector"]);
  130. $selectedTypesNOTInEnabledUserTypesArray = array_diff($formVars["referenceTypeSelector"], $enabledUserTypesArray);
  131. if (!empty($enabledUserTypesNOTInSelectedTypesArray))
  132. {
  133. // - remove types which do exist within the 'user_types' table but were deselected by the admin:
  134. $enabledUserTypesNOTInSelectedTypesString = implode("|", $enabledUserTypesNOTInSelectedTypesArray); // join array of type IDs using a pipe as separator
  135. $queryArray[] = "DELETE FROM $tableUserTypes "
  136. . "WHERE user_id = " . quote_smart($userID) . " AND type_id RLIKE " . quote_smart("^(" . $enabledUserTypesNOTInSelectedTypesString . ")$");
  137. }
  138. if (!empty($selectedTypesNOTInEnabledUserTypesArray))
  139. {
  140. // - insert types that were selected by the admin but which do not yet exist within the 'user_types' table:
  141. $selectedTypesNOTInEnabledUserTypesString = implode("|", $selectedTypesNOTInEnabledUserTypesArray); // join array of type IDs using a pipe as separator
  142. $insertTypesQuery = "INSERT INTO $tableUserTypes VALUES ";
  143. foreach ($selectedTypesNOTInEnabledUserTypesArray as $newUserTypeID)
  144. $insertTypesQueryValues[] = "(NULL, " . quote_smart($newUserTypeID) . ", " . quote_smart($userID) . ", 'true')";
  145. $queryArray[] = $insertTypesQuery . implode(", ", $insertTypesQueryValues) . ";";
  146. }
  147. // ---------------------
  148. // c) update all entries for this user within the 'user_styles' table:
  149. // - first, get a list of IDs for all styles within the 'user_styles' table that are available and were enabled by the admin for the current user:
  150. $enabledUserStylesArray = getEnabledUserFormatsStylesTypes($userID, "style", "", true); // function 'getEnabledUserFormatsStylesTypes()' is defined in 'include.inc.php'
  151. $enabledUserStylesInSelectedStylesArray = array_intersect($enabledUserStylesArray, $formVars["citationStyleSelector"]);
  152. $enabledUserStylesNOTInSelectedStylesArray = array_diff($enabledUserStylesArray, $formVars["citationStyleSelector"]);
  153. $selectedStylesNOTInEnabledUserStylesArray = array_diff($formVars["citationStyleSelector"], $enabledUserStylesArray);
  154. if (!empty($enabledUserStylesNOTInSelectedStylesArray))
  155. {
  156. // - remove styles which do exist within the 'user_styles' table but were deselected by the admin:
  157. $enabledUserStylesNOTInSelectedStylesString = implode("|", $enabledUserStylesNOTInSelectedStylesArray); // join array of style IDs using a pipe as separator
  158. $queryArray[] = "DELETE FROM $tableUserStyles "
  159. . "WHERE user_id = " . quote_smart($userID) . " AND style_id RLIKE " . quote_smart("^(" . $enabledUserStylesNOTInSelectedStylesString . ")$");
  160. }
  161. if (!empty($selectedStylesNOTInEnabledUserStylesArray))
  162. {
  163. // - insert styles that were selected by the admin but which do not yet exist within the 'user_styles' table:
  164. $selectedStylesNOTInEnabledUserStylesString = implode("|", $selectedStylesNOTInEnabledUserStylesArray); // join array of style IDs using a pipe as separator
  165. $insertStylesQuery = "INSERT INTO $tableUserStyles VALUES ";
  166. foreach ($selectedStylesNOTInEnabledUserStylesArray as $newUserStyleID)
  167. $insertStylesQueryValues[] = "(NULL, " . quote_smart($newUserStyleID) . ", " . quote_smart($userID) . ", 'true')";
  168. $queryArray[] = $insertStylesQuery . implode(", ", $insertStylesQueryValues) . ";";
  169. }
  170. // ---------------------
  171. // d) update all cite entries for this user within the 'user_formats' table:
  172. // - first, get a list of IDs for all cite formats within the 'user_formats' table that are available and were enabled by the admin for the current user:
  173. $enabledUserFormatsArray = getEnabledUserFormatsStylesTypes($userID, "format", "cite", true); // function 'getEnabledUserFormatsStylesTypes()' is defined in 'include.inc.php'
  174. $enabledUserFormatsInSelectedFormatsArray = array_intersect($enabledUserFormatsArray, $formVars["citationFormatSelector"]);
  175. $enabledUserFormatsNOTInSelectedFormatsArray = array_diff($enabledUserFormatsArray, $formVars["citationFormatSelector"]);
  176. $selectedFormatsNOTInEnabledUserFormatsArray = array_diff($formVars["citationFormatSelector"], $enabledUserFormatsArray);
  177. if (!empty($enabledUserFormatsNOTInSelectedFormatsArray))
  178. {
  179. // - remove cite formats which do exist within the 'user_formats' table but were deselected by the admin:
  180. $enabledUserFormatsNOTInSelectedFormatsString = implode("|", $enabledUserFormatsNOTInSelectedFormatsArray); // join array of format IDs using a pipe as separator
  181. $queryArray[] = "DELETE FROM $tableUserFormats "
  182. . "WHERE user_id = " . quote_smart($userID) . " AND format_id RLIKE " . quote_smart("^(" . $enabledUserFormatsNOTInSelectedFormatsString . ")$");
  183. }
  184. if (!empty($selectedFormatsNOTInEnabledUserFormatsArray))
  185. {
  186. // - insert cite formats that were selected by the admin but which do not yet exist within the 'user_formats' table:
  187. $selectedFormatsNOTInEnabledUserFormatsString = implode("|", $selectedFormatsNOTInEnabledUserFormatsArray); // join array of format IDs using a pipe as separator
  188. $insertFormatsQuery = "INSERT INTO $tableUserFormats VALUES ";
  189. foreach ($selectedFormatsNOTInEnabledUserFormatsArray as $newUserFormatID)
  190. $insertFormatsQueryValues[] = "(NULL, " . quote_smart($newUserFormatID) . ", " . quote_smart($userID) . ", 'true')";
  191. $queryArray[] = $insertFormatsQuery . implode(", ", $insertFormatsQueryValues) . ";";
  192. }
  193. // ---------------------
  194. // e) update all export entries for this user within the 'user_formats' table:
  195. // - first, get a list of IDs for all export formats within the 'user_formats' table that are available and were enabled by the admin for the current user:
  196. $enabledUserFormatsArray = getEnabledUserFormatsStylesTypes($userID, "format", "export", true); // function 'getEnabledUserFormatsStylesTypes()' is defined in 'include.inc.php'
  197. $enabledUserFormatsInSelectedFormatsArray = array_intersect($enabledUserFormatsArray, $formVars["exportFormatSelector"]);
  198. $enabledUserFormatsNOTInSelectedFormatsArray = array_diff($enabledUserFormatsArray, $formVars["exportFormatSelector"]);
  199. $selectedFormatsNOTInEnabledUserFormatsArray = array_diff($formVars["exportFormatSelector"], $enabledUserFormatsArray);
  200. if (!empty($enabledUserFormatsNOTInSelectedFormatsArray))
  201. {
  202. // - remove export formats which do exist within the 'user_formats' table but were deselected by the admin:
  203. $enabledUserFormatsNOTInSelectedFormatsString = implode("|", $enabledUserFormatsNOTInSelectedFormatsArray); // join array of format IDs using a pipe as separator
  204. $queryArray[] = "DELETE FROM $tableUserFormats "
  205. . "WHERE user_id = " . quote_smart($userID) . " AND format_id RLIKE " . quote_smart("^(" . $enabledUserFormatsNOTInSelectedFormatsString . ")$");
  206. }
  207. if (!empty($selectedFormatsNOTInEnabledUserFormatsArray))
  208. {
  209. // - insert export formats that were selected by the admin but which do not yet exist within the 'user_formats' table:
  210. $selectedFormatsNOTInEnabledUserFormatsString = implode("|", $selectedFormatsNOTInEnabledUserFormatsArray); // join array of format IDs using a pipe as separator
  211. $insertFormatsQuery = "INSERT INTO $tableUserFormats VALUES ";
  212. foreach ($selectedFormatsNOTInEnabledUserFormatsArray as $newUserFormatID)
  213. $insertFormatsQueryValues[] = "(NULL, " . quote_smart($newUserFormatID) . ", " . quote_smart($userID) . ", 'true')";
  214. $queryArray[] = $insertFormatsQuery . implode(", ", $insertFormatsQueryValues) . ";";
  215. }
  216. // ---------------------
  217. // f) update all permission settings for this user within the 'user_permissions' table:
  218. // get all user permissions for the current user (as they were before submit of 'user_options.php'):
  219. $userPermissionsArray = getPermissions($userID, "user", false); // function 'getPermissions()' is defined in 'include.inc.php'
  220. // copy all array elements that deal with permission settings from the '$formVars' array to '$updatedUserPermissionsArray':
  221. // (note that, except hidden permission settings, only those permission settings were included in the '$formVars' array whose checkboxes were marked!)
  222. $updatedUserPermissionsArray = array();
  223. foreach($formVars as $itemKey => $itemValue)
  224. if (preg_match("/^allow/i", $itemKey))
  225. $updatedUserPermissionsArray[$itemKey] = $itemValue; // allow the particular feature ('$itemValue' will be 'yes' anyhow)
  226. // then, all permission settings that aren't contained within '$updatedUserPermissionsArray' must have been unchecked:
  227. // (note: this logic only works if all permission settings queried by function 'getPermissions()' are also made available by 'user_options.php' -- either as checkbox or as hidden form tag!)
  228. foreach($userPermissionsArray as $permissionKey => $permissionValue)
  229. if (!isset($updatedUserPermissionsArray[$permissionKey]))
  230. $updatedUserPermissionsArray[$permissionKey] = 'no'; // disallow the particular feature
  231. // update all user permissions for the current user:
  232. $updateSucceeded = updateUserPermissions(array($userID), $updatedUserPermissionsArray); // function 'updateUserPermissions()' is defined in 'include.inc.php'
  233. }
  234. // ---------------------------------------------------------------
  235. else // if a normal user is logged in
  236. {
  237. // b) update all entries for this user within the 'user_types' table:
  238. $typeIDString = implode("|", $formVars["referenceTypeSelector"]); // join array of type IDs using a pipe as separator
  239. $queryArray[] = "UPDATE $tableUserTypes SET "
  240. . "show_type = \"true\" "
  241. . "WHERE user_id = " . quote_smart($userID) . " AND type_id RLIKE " . quote_smart("^(" . $typeIDString . ")$");
  242. $queryArray[] = "UPDATE $tableUserTypes SET "
  243. . "show_type = \"false\" "
  244. . "WHERE user_id = " . quote_smart($userID) . " AND type_id NOT RLIKE " . quote_smart("^(" . $typeIDString . ")$");
  245. // c) update all entries for this user within the 'user_styles' table:
  246. $styleIDString = implode("|", $formVars["citationStyleSelector"]); // join array of style IDs using a pipe as separator
  247. $queryArray[] = "UPDATE $tableUserStyles SET "
  248. . "show_style = \"true\" "
  249. . "WHERE user_id = " . quote_smart($userID) . " AND style_id RLIKE " . quote_smart("^(" . $styleIDString . ")$");
  250. $queryArray[] = "UPDATE $tableUserStyles SET "
  251. . "show_style = \"false\" "
  252. . "WHERE user_id = " . quote_smart($userID) . " AND style_id NOT RLIKE " . quote_smart("^(" . $styleIDString . ")$");
  253. // d) update all cite entries for this user within the 'user_formats' table:
  254. $citeFormatIDString = implode("|", $formVars["citationFormatSelector"]); // join array of format IDs using a pipe as separator
  255. $queryArray[] = "UPDATE $tableUserFormats SET "
  256. . "show_format = \"true\" "
  257. . "WHERE user_id = " . quote_smart($userID) . " AND format_id RLIKE " . quote_smart("^(" . $citeFormatIDString . ")$");
  258. $queryArray[] = "UPDATE $tableUserFormats SET "
  259. . "show_format = \"false\" "
  260. . "WHERE user_id = " . quote_smart($userID) . " AND format_id NOT RLIKE " . quote_smart("^(" . $citeFormatIDString . ")$");
  261. // e) update all export entries for this user within the 'user_formats' table:
  262. $exportFormatIDString = implode("|", $formVars["exportFormatSelector"]); // join array of format IDs using a pipe as separator
  263. $queryArray[] = "UPDATE $tableUserFormats SET "
  264. . "show_format = \"true\" "
  265. . "WHERE user_id = " . quote_smart($userID) . " AND format_id RLIKE " . quote_smart("^(" . $exportFormatIDString . ")$");
  266. $queryArray[] = "UPDATE $tableUserFormats SET "
  267. . "show_format = \"false\" "
  268. . "WHERE user_id = " . quote_smart($userID) . " AND format_id NOT RLIKE " . quote_smart("^(" . $exportFormatIDString . ")$") . " AND format_id NOT RLIKE " . quote_smart("^(" . $citeFormatIDString . ")$"); // we need to include '$citeFormatIDString' here, otherwise the user's selected cite formats would get deleted again
  269. }
  270. // ---------------------------------------------------------------
  271. // f) update the user's options in the 'user_options' table:
  272. if (!isset($formVars["use_custom_handling_of_nonascii_chars_in_cite_keys"]))
  273. $nonASCIICharsInCiteKeys = "NULL"; // use the site default given in '$handleNonASCIICharsInCiteKeysDefault' in 'ini.inc.php'
  274. else
  275. $nonASCIICharsInCiteKeys = quote_smart($formVars["nonascii_chars_in_cite_keys"]); // use the setting chosen by the user
  276. if ($userID != 0)
  277. {
  278. $recordsPerPage = $formVars["recordsPerPageNo"];
  279. $showAutoCompletions = $formVars["showAutoCompletionsRadio"];
  280. $mainFieldsString = implode(", ", $formVars["mainFieldsSelector"]); // join array of the user's preferred main fields using a comma (and whitespace) as separator
  281. }
  282. else // the 'recordsPerPageNo', 'showAutoCompletionsRadio' and 'mainFieldsSelector' form elements are disabled for anonymous users ('userID=0'), so we load the defaults:
  283. {
  284. $recordsPerPage = getDefaultNumberOfRecords(0); // function 'getDefaultNumberOfRecords()' is defined in 'include.inc.php'
  285. $showAutoCompletions = getPrefAutoCompletions(0); // function 'getPrefAutoCompletions()' is defined in 'include.inc.php'
  286. $mainFieldsString = implode(", ", getMainFields(0)); // function 'getMainFields()' is defined in 'include.inc.php'
  287. }
  288. // we account for the possibility that no entry in table 'user_options' exists for the current user
  289. // (in which case an entry will be added):
  290. // check if there's already an entry for the current user within the 'user_options' table:
  291. // CONSTRUCT SQL QUERY:
  292. $query = "SELECT option_id FROM $tableUserOptions WHERE user_id = " . quote_smart($userID);
  293. // RUN the query on the database through the connection:
  294. $result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
  295. if (mysqli_num_rows($result) == 1) // if there's already an existing user_data entry, we perform an UPDATE action:
  296. $queryArray[] = "UPDATE $tableUserOptions SET "
  297. . "export_cite_keys = " . quote_smart($formVars["export_cite_keys"])
  298. . ", autogenerate_cite_keys = " . quote_smart($formVars["autogenerate_cite_keys"])
  299. . ", prefer_autogenerated_cite_keys = " . quote_smart($formVars["prefer_autogenerated_cite_keys"])
  300. . ", use_custom_cite_key_format = " . quote_smart($formVars["use_custom_cite_key_format"])
  301. . ", cite_key_format = " . quote_smart($formVars["cite_key_format"])
  302. . ", uniquify_duplicate_cite_keys = " . quote_smart($formVars["uniquify_duplicate_cite_keys"])
  303. . ", nonascii_chars_in_cite_keys = " . $nonASCIICharsInCiteKeys // already quote_smart
  304. . ", use_custom_text_citation_format = " . quote_smart($formVars["use_custom_text_citation_format"])
  305. . ", text_citation_format = " . quote_smart($formVars["text_citation_format"])
  306. . ", records_per_page = " . quote_smart($recordsPerPage)
  307. . ", show_auto_completions = " . quote_smart($showAutoCompletions)
  308. . ", main_fields = " . quote_smart($mainFieldsString)
  309. . " WHERE user_id = " . quote_smart($userID);
  310. else // otherwise we perform an INSERT action:
  311. $queryArray[] = "INSERT INTO $tableUserOptions SET "
  312. . "export_cite_keys = " . quote_smart($formVars["export_cite_keys"])
  313. . ", autogenerate_cite_keys = " . quote_smart($formVars["autogenerate_cite_keys"])
  314. . ", prefer_autogenerated_cite_keys = " . quote_smart($formVars["prefer_autogenerated_cite_keys"])
  315. . ", use_custom_cite_key_format = " . quote_smart($formVars["use_custom_cite_key_format"])
  316. . ", cite_key_format = " . quote_smart($formVars["cite_key_format"])
  317. . ", uniquify_duplicate_cite_keys = " . quote_smart($formVars["uniquify_duplicate_cite_keys"])
  318. . ", nonascii_chars_in_cite_keys = " . $nonASCIICharsInCiteKeys // already quote_smart
  319. . ", use_custom_text_citation_format = " . quote_smart($formVars["use_custom_text_citation_format"])
  320. . ", text_citation_format = " . quote_smart($formVars["text_citation_format"])
  321. . ", records_per_page = " . quote_smart($recordsPerPage)
  322. . ", show_auto_completions = " . quote_smart($showAutoCompletions)
  323. . ", main_fields = " . quote_smart($mainFieldsString)
  324. . ", user_id = " . quote_smart($userID)
  325. . ", option_id = NULL"; // inserting 'NULL' into an auto_increment PRIMARY KEY attribute allocates the next available key value
  326. }
  327. // --------------------------------------------------------------------
  328. // (3) RUN the queries on the database through the connection:
  329. foreach($queryArray as $query)
  330. $result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
  331. // ----------------------------------------------
  332. // we'll only update the appropriate session variables if either a normal user is logged in -OR- the admin is logged in AND the updated user data are his own:
  333. if (($loginEmail != $adminLoginEmail) | (($loginEmail == $adminLoginEmail) && ($userID == getUserID($loginEmail))))
  334. {
  335. // Write back session variables:
  336. saveSessionVariable("userLanguage", $formVars["languageName"]); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  337. // Note: the user's types/styles/formats will be written to their corresponding session variables in function 'getVisibleUserFormatsStylesTypes()'
  338. // which will be called by the following receipt page ('user_receipt.php') anyhow, so we won't call the function here...
  339. // The same is true for the user's preferred number of records per page, the user's pref setting to show auto-completions and for the
  340. // list of "main fields" which will be saved to session variables from within 'user_receipt.php' thru functions 'getMainFields()',
  341. // 'getDefaultNumberOfRecords()' and 'getPrefAutoCompletions()', respectively.
  342. }
  343. // Clear the 'errors' and 'formVars' session variables so a future <form> is blank:
  344. deleteSessionVariable("errors"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  345. deleteSessionVariable("formVars");
  346. // ----------------------------------------------
  347. // (4) Now show the user RECEIPT:
  348. header("Location: user_receipt.php?userID=$userID");
  349. // (5) CLOSE the database connection:
  350. disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
  351. // --------------------------------------------------------------------
  352. ?>