3 // ELGG profile edit page
6 require_once(dirname(dirname(__FILE__
))."/includes.php");
7 require_once($CFG->dirroot
. "profile/profile.class.php");
9 // define what profile to show
10 $profile_name = optional_param('profile_name', '', PARAM_ALPHANUM
);
11 if (!empty($profile_name)) {
12 $profile_id = run("users:name_to_id", $profile_name);
14 if (empty($profile_id)) {
15 // fetch from GET/POST param
16 $profile_id = optional_param('profile_id', -1, PARAM_INT
);
18 // if it wasn't in GET/POST but we have a valid session, use it
19 if ($profile_id === -1 && isset($_SESSION['userid'])) {
20 $profile_id = $_SESSION['userid'];
23 $profile_name = run("users:id_to_name", $profile_id);
27 $profile = new ElggProfile($profile_id);
29 define("context", "profile");
35 $title = run("users:display:name", $page_owner) . " :: ". gettext("Edit profile") ."";
36 templates_page_setup();
39 if ($profile_new = data_submitted()) {
40 $body = profile_update($profile_new);
42 $body = $profile->display_form();
44 $body = templates_draw(array( 'context' => 'contentholder',
48 print templates_page_draw(array($title, $body));
52 function profile_update($profile_new) {
60 $profiledetails = optional_param('profiledetails',array());
61 if (count($profiledetails) > 0) {
62 delete_records('profile_data','owner',$page_owner);
63 foreach($profiledetails as $field => $value) {
64 $field = trim($field);
65 $value = trim($value);
68 //TODO get rid of variable duplication here. (Penny)
69 $access = $_POST['profileaccess'][$field];
74 $pd->access
= $access;
75 $pd->owner
= $page_owner;
77 $insert_id = insert_record('profile_data',$pd);
81 foreach($data['profile:details'] as $datatype) {
82 if ($datatype[1] == $field && $datatype[2] == "keywords") {
83 delete_records('tags', 'tagtype', $field, 'owner', $page_owner);
84 $value = insert_tags_from_string ($value, $field, $insert_id, $access, $page_owner);
88 $messages[] = gettext("Profile updated.");
91 // Changes saved successfully, update RSS feeds
92 $rssresult = run("weblogs:rss:publish", array(1, false));
93 $rssresult = run("profile:rss:publish", array(1, false));
95 // redirect("{$CFG->wwwroot}{$profile_name}", get_string("changessaved"));
96 redirect("{$CFG->wwwroot}{$profile_name}", "");