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.

478 lines
28 KiB

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