3 // ELGG profile edit page
5 global $profile_name, $profile_id, $messages;
8 require_once(dirname(dirname(__FILE__
))."/includes.php");
9 require_once($CFG->dirroot
. "profile/profile.class.php");
11 // define what profile to show
12 $profile_name = optional_param('profile_name', '', PARAM_ALPHANUM
);
13 if (!empty($profile_name)) {
14 $profile_id = user_info_username('ident', $profile_name);
16 if (empty($profile_id)) {
17 // fetch from GET/POST param
18 $profile_id = page_owner();
20 // if it wasn't in GET/POST but we have a valid session, use it
21 if ($profile_id === -1 && isset($_SESSION['userid'])) {
22 $profile_id = $_SESSION['userid'];
25 $profile_name = user_info('username', $profile_id);
28 $profile = new ElggProfile($profile_id);
30 define("context", "profile");
34 global $page_owner, $metatags, $CFG, $data;
36 if (isset($_SESSION['profile:preload'])) {
37 $data['profile:preload'] = $_SESSION['profile:preload'];
38 unset($_SESSION['profile:preload']);
40 if (isset($_SESSION['profile:preload:access'])) {
41 $data['profile:preload:access'] = $_SESSION['profile:preload:access'];
42 unset($_SESSION['profile:preload:access']);
45 $title = user_name($page_owner) . " :: ". __gettext("Edit profile") ."";
46 templates_page_setup();
48 $metatags .= "<script type=\"text/javascript\" src=\"" . $CFG->wwwroot
. "mod/profile/tabber/tabber.js\"></script>";
49 $metatags .= "<link rel=\"stylesheet\" href=\"" . $CFG->wwwroot
. "mod/profile/tabber/example.css\" type=\"text/css\" media=\"screen\" />";
51 if ($profile_new = data_submitted()) {
52 $body = profile_update($profile_new);
54 $body = $profile->display_form();
56 $body = templates_draw(array( 'context' => 'contentholder',
60 print templates_page_draw(array($title, $body));
64 function profile_update($profile_new) {
72 $profiledetails = optional_param('profiledetails',array());
73 if (count($profiledetails) > 0) {
74 // delete_records('profile_data','owner',$page_owner);
76 $insertvalues = array();
77 $requiredmissing = array();
79 foreach($profiledetails as $field => $value) {
80 $field = trim($field);
81 $value = trim($value);
84 //TODO get rid of variable duplication here. (Penny)
85 if (!empty($data['profile:details'][$field]->invisible
)) {
86 $access = 'user' . $page_owner;
88 $access = $_POST['profileaccess'][$field];
94 $pd->access
= $access;
95 $pd->owner
= $page_owner;
97 // $insert_id = insert_record('profile_data',$pd);
98 $insertvalues[] = $pd;
101 foreach($data['profile:details'] as $datatype) {
102 if (is_array($datatype)) {
103 $fname = !empty($datatype[1]) ?
$datatype[1] : '';
104 $flabel = !empty($field[0]) ?
$field[0] : '';
106 $fcat = __gettext("Main");
107 // Otherwise map things the new way!
109 $fname = $datatype->internal_name
;
110 $flabel = $datatype->name
;
111 $frequired = $datatype->required
;
112 if (empty($datatype->category
)) {
113 $fcat = __gettext("Main");
115 $fcat = $datatype->category
;
118 if ($fname == $field) {
119 if ($frequired == true) {
120 $requiredmissing[] = sprintf(__gettext("%s (in category %s)"),$flabel,$fcat);
122 delete_records('profile_data','owner',$page_owner,'name',$fname);
128 if (sizeof($requiredmissing) == 0) {
132 foreach($insertvalues as $insertvalue) {
133 delete_records('profile_data','owner',$page_owner,'name',$insertvalue->name
);
134 $insertvalue = plugin_hook("profile_data","create",$insertvalue);
135 if (!empty($insertvalue)) {
136 $insert_id = insert_record('profile_data',$insertvalue);
137 $insertvalue->ident
= $insert_id;
138 plugin_hook("profile_data","publish",$insertvalue);
139 foreach($data['profile:details'] as $datatype) {
140 if (is_array($datatype)) {
141 $fname = !empty($datatype[1]) ?
$datatype[1] : '';
142 $ftype = !empty($datatype[2]) ?
$datatype[2] : '';
143 // Otherwise map things the new way!
145 $fname = $datatype->internal_name
;
146 $ftype = $datatype->field_type
;
148 if ($fname == $insertvalue->name
&& $ftype == "keywords") {
149 delete_records('tags', 'tagtype', $insertvalue->name
, 'owner', $page_owner);
150 $value = insert_tags_from_string ($insertvalue->value
, $insertvalue->name
, $insert_id, $insertvalue->access
, $page_owner);
152 if (isset($CFG->display_field_module
[$ftype])) {
153 $callback = $CFG->display_field_module
[$ftype] . "_validate_input_field";
154 $updatedok = $callback($insertvalue);
159 $messages[] = __gettext("Profile updated.");
164 foreach($insertvalues as $insertvalue) {
165 $savedata['profile:preload'][$insertvalue->name
] = $insertvalue->value
;
166 $savedata['profile:preload:access'][$insertvalue->name
] = $insertvalue->access
;
168 foreach($requiredmissing as $key=> $missinglabel) {
173 $message .= $missinglabel;
176 $messages[] = sprintf(__gettext("You need to fill in the following required fields: %s"),$message);
179 $_SESSION['profile:preload'] = $savedata['profile:preload'];
180 $_SESSION['profile:preload:access'] = $savedata['profile:preload:access'];
184 // Changes saved successfully, update RSS feeds
185 $rssresult = run("weblogs:rss:publish", array(1, false));
186 $rssresult = run("profile:rss:publish", array(1, false));
188 $_SESSION['messages'] = $messages;
190 // redirect("{$CFG->wwwroot}{$profile_name}", get_string("changessaved"));
192 redirect("{$CFG->wwwroot}{$profile_name}/profile/", "");
194 redirect("{$CFG->wwwroot}profile/edit.php?profile_id=".$page_owner, "");