function testProfileReadingFunctions()
 {
     // find a user with 'newcss' set
     list($uid, $css) = Dal::query_one("SELECT user_id, field_value FROM user_profile_data WHERE field_type='ui' AND field_name='newcss' ORDER BY user_id LIMIT 1");
     if (empty($uid)) {
         echo "Test not possible as nobody has the newcss field set.  Try again on a more populated database.\n";
         return;
     }
     // find another field, so we can test with more than one
     list($f2_name, $f2_value) = Dal::query_one("SELECT field_name, field_value FROM user_profile_data WHERE field_type='ui' AND user_id=? AND field_name <>'newcss' AND field_value IS NOT NULL LIMIT 1", $uid);
     echo "getting ui/newcss and {$f2_name} properties from user_profile_data for user_id {$uid}.\n";
     $user = new User();
     $user->load((int) $uid);
     // load just the newcss field
     echo "getting just the newcss property for user {$uid}\n";
     $css2 = $user->get_profile_field('ui', 'newcss');
     $this->assertEquals($css, $css2);
     // load just the second field
     echo "getting just the {$f2_name} property for user {$uid}\n";
     $v = $user->get_profile_field('ui', $f2_name);
     $this->assertEquals($v, $f2_value);
     // load newcss and the second field, with get_profile_fields()
     echo "getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // try again, flushing the cache first
     Cache::reset();
     echo "(without cache) getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // regression test (phil) 2007-04-01, for bug spotted by martin
     // 2007-03-23: make sure we don't crash if we request fields that
     // are all cached.
     echo "regression: make sure it doesn't crash if everything is in the cache\n";
     $data = $user->get_profile_fields('ui', array('newcss'));
     $this->assertEquals($css, $data['newcss']);
     // try by loading the entire 'ui' section
     echo "getting entire ui section for user {$uid}\n";
     $ui = User::load_profile_section($uid, "ui");
     $this->assertEquals($css, $ui['newcss']['value']);
     $this->assertEquals($f2_value, $ui[$f2_name]['value']);
 }
function uihelper_set_user_heading($page, $do_theme = TRUE, $userid = NULL)
{
    global $uid;
    $uid = !empty($userid) ? $userid : $uid;
    // Changing ... if we give User id than it will display the information of that user
    // .. if we not give the id than it displayed (Page users id or login user id )
    if (!empty($userid)) {
        $user = new User();
        $user->load((int) $userid);
    } else {
        $user = get_login_user();
        if (!PA::$login_uid) {
            $user = get_page_user();
        }
    }
    if (empty($user)) {
        return;
    }
    if ($do_theme) {
        // put links all theme CSS files in the header
        $theme_details = get_user_theme($uid);
        if (is_array($theme_details['css_files'])) {
            foreach ($theme_details['css_files'] as $key => $value) {
                $page->add_header_css($value);
            }
        }
        $page->header->set('theme_details', $theme_details);
        // see if we have user defined CSS
        // Here we have to load the user
        $usr = new User();
        $usr->user_id = $uid;
        $newcss = $usr->get_profile_field("ui", "newcss");
        if (!empty($newcss)) {
            $usercss = "<style>" . $newcss . "</style>";
            $page->add_header_html($usercss);
        }
    }
    // get selected general user data, so we can set captions, etc.
    $user_data_general = $user->get_profile_fields(GENERAL, array('user_caption', 'sub_caption', 'user_caption_image', 'desktop_image_action', 'desktop_image_display'));
    // set caption value
    if (!empty($user_data_general['user_caption'])) {
        $caption1 = chop_string($user_data_general['user_caption'], 20);
    } else {
        $caption1 = chop_string($user->first_name . " " . $user->last_name, 20);
    }
    $page->header->set('caption1', $caption1);
    $page->header->set('caption2', chop_string(@$user_data_general['sub_caption'], 40));
    $page->header->set('caption_image', $user_data_general['user_caption_image']);
    $page->header->set('desktop_image_action', $user_data_general['desktop_image_action']);
    $page->header->set('display_image', @$user_data_general['desktop_image_display']);
}