+
+// template set setup
+//
+$sDefaultTemplateID = Template::get_default_template_set();
+$sTemplateID = getPref($data_dir, $username, 'sTemplateID', $sDefaultTemplateID);
+
+// need to build this object now because it is used below to validate
+// user css theme choice
+//
+$oTemplate = Template::construct_template($sTemplateID);
+
+// check user prefs template selection against templates actually available
+//
+$found_templateset = false;
+for ($i = 0; $i < count($aTemplateSet); ++$i){
+ if ($aTemplateSet[$i]['ID'] == $sTemplateID) {
+ $found_templateset = true;
+ break;
+ }
+}
+
+// FIXME: do we need/want to check here for actual presence of template sets?
+// selected template not available, fall back to default template
+//
+if (!$found_templateset) $sTemplateID = $sDefaultTemplateID;
+
+// Load user theme
+$chosen_theme = getPref($data_dir, $username, 'chosen_theme');
+$found_theme = false;
+$chosen_theme_path = empty($chosen_theme) ?
+ $chosen_theme_path = 'u_'.$user_themes[$user_theme_default]['PATH'] :
+ $chosen_theme;
+
+// Make sure the chosen theme is a legitimate one.
+// need to adjust $chosen_theme path with SM_PATH
+$chosen_theme_path = preg_replace("/(\.\.\/){1,}/", SM_PATH, $chosen_theme_path);
+$k = 0;
+while (!$found_theme && $k < count($user_themes)) {
+ if ('u_'.$user_themes[$k]['PATH'] == $chosen_theme_path)
+ $found_theme = true;
+ $k++;
+}
+$template_themes = $oTemplate->get_alternative_stylesheets();
+while (!$found_theme && (list($path, $name) = each($template_themes))) {
+ if ('t_'.$path == $chosen_theme_path)
+ $found_theme = true;
+}
+
+if (!$found_theme || $chosen_theme == 'none') {
+ $chosen_theme_path = NULL;
+}
+
+/* ----- SB: Holding on to the following code incase I need to reference later.
+ Will remove eventually. :)
+