4 function profiles_post(&$a) {
7 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
10 if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
11 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
13 intval($_SESSION['uid'])
16 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
19 $is_default = (($r[0]['is-default']) ? 1 : 0);
21 $profile_name = notags(trim($_POST['profile_name']));
22 if(! strlen($profile_name)) {
23 $a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
27 $year = intval($_POST['year']);
28 if($year < 1900 || $year > 2100 || $year < 0)
30 $month = intval($_POST['month']);
31 if(($month > 12) || ($month < 0))
33 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
34 $day = intval($_POST['day']);
35 if(($day > $mtab[$month]) || ($day < 0))
38 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
41 $name = notags(trim($_POST['name']));
42 $gender = notags(trim($_POST['gender']));
43 $address = notags(trim($_POST['address']));
44 $locality = notags(trim($_POST['locality']));
45 $region = notags(trim($_POST['region']));
46 $postal_code = notags(trim($_POST['postal_code']));
47 $country_name = notags(trim($_POST['country_name']));
48 $marital = notags(trim(implode(', ',$_POST['marital'])));
49 $sexual = notags(trim($_POST['sexual']));
50 $homepage = notags(trim($_POST['homepage']));
51 $politic = notags(trim($_POST['politic']));
52 $religion = notags(trim($_POST['religion']));
54 $about = escape_tags(trim($_POST['about']));
55 $interest = escape_tags(trim($_POST['interest']));
56 $contact = escape_tags(trim($_POST['contact']));
57 $music = escape_tags(trim($_POST['music']));
58 $book = escape_tags(trim($_POST['book']));
59 $tv = escape_tags(trim($_POST['tv']));
60 $film = escape_tags(trim($_POST['film']));
61 $romance = escape_tags(trim($_POST['romance']));
62 $work = escape_tags(trim($_POST['work']));
63 $education = escape_tags(trim($_POST['education']));
64 if(x($_POST,'profile_in_directory'))
65 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
66 if(! in_array($gender,array('','Male','Female','Other')))
69 $r = q("UPDATE `profile`
70 SET `profile-name` = '%s',
78 `country-name` = '%s',
94 WHERE `id` = %d AND `uid` = %d LIMIT 1",
103 dbesc($country_name),
120 intval($_SESSION['uid'])
124 $_SESSION['sysmsg'] .= "Profile updated." . EOL;
128 $r = q("UPDATE `profile`
130 WHERE `id` = %d AND `uid` = %d LIMIT 1",
133 intval($_SESSION['uid'])
148 function profiles_content(&$a) {
150 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
154 if(($a->argc > 2) && ($a->argv[1] == "drop") && intval($a->argv[2])) {
155 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
157 intval($_SESSION['uid'])
160 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
161 goaway($a->get_baseurl() . '/profiles');
162 return; // NOTREACHED
165 // move every contact using this profile as their default to the user default
167 $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
168 intval($_SESSION['uid']),
170 intval($_SESSION['uid'])
172 $r = q("DELETE FROM `profile` WHERE `id` = %d LIMIT 1",
176 notice("Profile deleted." . EOL);
178 goaway($a->get_baseurl() . '/profiles');
179 return; // NOTREACHED
186 if(($a->argc > 1) && ($a->argv[1] == 'new')) {
188 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
189 intval($_SESSION['uid']));
190 $num_profiles = count($r0);
192 $name = "Profile-" . ($num_profiles + 1);
194 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
195 intval($_SESSION['uid']));
197 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
198 VALUES ( %d, '%s', '%s', '%s', '%s' )",
199 intval($_SESSION['uid']),
201 dbesc($r1[0]['name']),
202 dbesc($r1[0]['photo']),
203 dbesc($ra[0]['thumb'])
206 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
207 intval($_SESSION['uid']),
210 $_SESSION['sysmsg'] .= "New profile created." . EOL;
212 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
213 goaway($a->get_baseurl() . '/profiles');
216 if(($a->argc > 2) && ($a->argv[1] == 'clone')) {
218 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
219 intval($_SESSION['uid']));
220 $num_profiles = count($r0);
222 $name = "Profile-" . ($num_profiles + 1);
223 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
224 intval($_SESSION['uid']),
228 notice("Profile unavailable to clone." . EOL);
232 $r1[0]['is-default'] = 0;
233 $r1[0]['publish'] = 0;
234 $r1[0]['profile-name'] = dbesc($name);
238 $r2 = q("INSERT INTO `profile` (`"
239 . implode("`, `", array_keys($r1[0]))
241 . implode("', '", array_values($r1[0]))
244 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
245 intval($_SESSION['uid']),
248 $_SESSION['sysmsg'] .= "New profile created." . EOL;
250 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
251 goaway($a->get_baseurl() . '/profiles');
252 return; // NOTREACHED
259 if(intval($a->argv[1])) {
260 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
262 intval($_SESSION['uid'])
265 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
269 require_once('mod/profile.php');
270 profile_load($a,$_SESSION['uid'],$r[0]['id']);
272 require_once('view/profile_selectors.php');
274 $tpl = file_get_contents('view/profed_head.tpl');
275 $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
276 $profile_in_dir = replace_macros($opt_tpl,array(
277 '$yes_selected' => (($r[0]['publish']) ? " checked=\"checked\" " : ""),
278 '$no_selected' => (($r[0]['publish'] == 0) ? " checked=\"checked\" " : "")
281 $opt_tpl = file_get_contents("view/profile-hide-friends.tpl");
282 $hide_friends = replace_macros($opt_tpl,array(
283 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
284 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
288 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
289 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
295 $is_default = (($r[0]['is-default']) ? 1 : 0);
296 $tpl = file_get_contents("view/profile_edit.tpl");
297 $o .= replace_macros($tpl,array(
298 '$baseurl' => $a->get_baseurl(),
299 '$profile_id' => $r[0]['id'],
300 '$profile_name' => $r[0]['profile-name'],
301 '$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.</p>" : ""),
302 '$name' => $r[0]['name'],
303 '$dob' => dob($r[0]['dob']),
304 '$hide_friends' => $hide_friends,
305 '$address' => $r[0]['address'],
306 '$locality' => $r[0]['locality'],
307 '$region' => $r[0]['region'],
308 '$postal_code' => $r[0]['postal-code'],
309 '$country_name' => $r[0]['country-name'],
310 '$age' => ((intval($r[0]['dob'])) ? '(Age: '. age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
311 '$gender' => gender_selector($r[0]['gender']),
312 '$marital' => marital_selector($r[0]['marital']),
313 '$sexual' => sexpref_selector($r[0]['sexual']),
314 '$about' => $r[0]['about'],
315 '$homepage' => $r[0]['homepage'],
316 '$politic' => $r[0]['politic'],
317 '$religion' => $r[0]['religion'],
318 '$music' => $r[0]['music'],
319 '$book' => $r[0]['book'],
320 '$tv' => $r[0]['tv'],
321 '$film' => $r[0]['film'],
322 '$interest' => $r[0]['interest'],
323 '$romance' => $r[0]['romance'],
324 '$work' => $r[0]['work'],
325 '$education' => $r[0]['education'],
326 '$contact' => $r[0]['contact'],
327 '$profile_in_dir' => (($is_default) ? $profile_in_dir : '')
336 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
340 $o .= file_get_contents('view/profile_listing_header.tpl');
341 $tpl_default = file_get_contents('view/profile_entry_default.tpl');
342 $tpl = file_get_contents('view/profile_entry.tpl');
345 $template = (($rr['is-default']) ? $tpl_default : $tpl);
346 $o .= replace_macros($template, array(
347 '$photo' => $rr['thumb'],
349 '$profile_name' => $rr['profile-name']