4 function profiles_post(&$a) {
7 notice( t('Permission denied.') . EOL);
13 if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
14 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
16 intval($_SESSION['uid'])
19 notice( t('Profile not found.') . EOL);
22 $is_default = (($orig[0]['is-default']) ? 1 : 0);
24 $profile_name = notags(trim($_POST['profile_name']));
25 if(! strlen($profile_name)) {
26 notify( t('Profile Name is required.') . EOL);
30 $year = intval($_POST['year']);
31 if($year < 1900 || $year > 2100 || $year < 0)
33 $month = intval($_POST['month']);
34 if(($month > 12) || ($month < 0))
36 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
37 $day = intval($_POST['day']);
38 if(($day > $mtab[$month]) || ($day < 0))
41 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
44 $name = notags(trim($_POST['name']));
46 if($orig[0]['name'] != $name)
49 $gender = notags(trim($_POST['gender']));
50 $address = notags(trim($_POST['address']));
51 $locality = notags(trim($_POST['locality']));
52 $region = notags(trim($_POST['region']));
53 $postal_code = notags(trim($_POST['postal_code']));
54 $country_name = notags(trim($_POST['country_name']));
56 $marital = notags(trim($_POST['marital']));
57 if($marital != $orig[0]['marital'])
58 $maritalchanged = true;
60 $sexual = notags(trim($_POST['sexual']));
61 $homepage = notags(trim($_POST['homepage']));
62 $politic = notags(trim($_POST['politic']));
63 $religion = notags(trim($_POST['religion']));
65 $about = escape_tags(trim($_POST['about']));
66 $interest = escape_tags(trim($_POST['interest']));
67 $contact = escape_tags(trim($_POST['contact']));
68 $music = escape_tags(trim($_POST['music']));
69 $book = escape_tags(trim($_POST['book']));
70 $tv = escape_tags(trim($_POST['tv']));
71 $film = escape_tags(trim($_POST['film']));
72 $romance = escape_tags(trim($_POST['romance']));
73 $work = escape_tags(trim($_POST['work']));
74 $education = escape_tags(trim($_POST['education']));
75 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
78 $r = q("UPDATE `profile`
79 SET `profile-name` = '%s',
87 `country-name` = '%s',
104 WHERE `id` = %d AND `uid` = %d LIMIT 1",
105 dbesc($profile_name),
113 dbesc($country_name),
129 intval($hide_friends),
131 intval($_SESSION['uid'])
135 notice( t('Profile updated.') . EOL);
138 if($namechanged && $is_default) {
139 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
140 dbesc(datetime_convert()),
141 intval($_SESSION['uid'])
146 // Update global directory in background
147 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
148 $url = $_SESSION['my_url'];
149 if($url && strlen(get_config('system','directory_submit_url')))
150 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
159 function profiles_content(&$a) {
160 $o .= '<script> $(document).ready(function() { $(\'#nav-profiles-link\').addClass(\'nav-selected\'); });</script>';
162 notice( t('Permission denied.') . EOL);
166 if(($a->argc > 2) && ($a->argv[1] == "drop") && intval($a->argv[2])) {
167 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 AND `self` = 0 LIMIT 1",
169 intval($_SESSION['uid'])
172 notice( t('Profile not found.') . EOL);
173 goaway($a->get_baseurl() . '/profiles');
174 return; // NOTREACHED
177 // move every contact using this profile as their default to the user default
179 $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 ",
180 intval($_SESSION['uid']),
182 intval($_SESSION['uid'])
184 $r = q("DELETE FROM `profile` WHERE `id` = %d LIMIT 1",
188 notice( t('Profile deleted.') . EOL);
190 goaway($a->get_baseurl() . '/profiles');
191 return; // NOTREACHED
198 if(($a->argc > 1) && ($a->argv[1] == 'new')) {
200 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
201 intval($_SESSION['uid']));
202 $num_profiles = count($r0);
204 $name = t('Profile-') . ($num_profiles + 1);
206 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
207 intval($_SESSION['uid']));
209 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
210 VALUES ( %d, '%s', '%s', '%s', '%s' )",
211 intval($_SESSION['uid']),
213 dbesc($r1[0]['name']),
214 dbesc($r1[0]['photo']),
215 dbesc($ra[0]['thumb'])
218 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
219 intval($_SESSION['uid']),
222 notice( t('New profile created.') . EOL);
224 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
225 goaway($a->get_baseurl() . '/profiles');
228 if(($a->argc > 2) && ($a->argv[1] == 'clone')) {
230 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
231 intval($_SESSION['uid']));
232 $num_profiles = count($r0);
234 $name = t('Profile-') . ($num_profiles + 1);
235 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
236 intval($_SESSION['uid']),
240 notice( t('Profile unavailable to clone.') . EOL);
244 $r1[0]['is-default'] = 0;
245 $r1[0]['publish'] = 0;
246 $r1[0]['net-publish'] = 0;
247 $r1[0]['profile-name'] = dbesc($name);
251 $r2 = q("INSERT INTO `profile` (`"
252 . implode("`, `", array_keys($r1[0]))
254 . implode("', '", array_values($r1[0]))
257 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
258 intval($_SESSION['uid']),
261 notice( t('New profile created.') . EOL);
263 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
264 goaway($a->get_baseurl() . '/profiles');
265 return; // NOTREACHED
269 if(intval($a->argv[1])) {
270 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
272 intval($_SESSION['uid'])
275 notice( t('Profile not found.') . EOL);
279 require_once('mod/profile.php');
280 profile_load($a,$a->user['nickname'],$r[0]['id']);
282 require_once('view/profile_selectors.php');
284 $tpl = file_get_contents('view/profed_head.tpl');
286 $opt_tpl = file_get_contents("view/profile-hide-friends.tpl");
287 $hide_friends = replace_macros($opt_tpl,array(
288 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
289 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
293 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
294 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
300 $is_default = (($r[0]['is-default']) ? 1 : 0);
301 $tpl = file_get_contents("view/profile_edit.tpl");
302 $o .= replace_macros($tpl,array(
303 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
304 '$baseurl' => $a->get_baseurl(),
305 '$profile_id' => $r[0]['id'],
306 '$profile_name' => $r[0]['profile-name'],
307 '$default' => (($is_default) ? '<p id="profile-edit-default-desc">' . t('This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.') . '</p>' : ""),
308 '$name' => $r[0]['name'],
309 '$dob' => dob($r[0]['dob']),
310 '$hide_friends' => $hide_friends,
311 '$address' => $r[0]['address'],
312 '$locality' => $r[0]['locality'],
313 '$region' => $r[0]['region'],
314 '$postal_code' => $r[0]['postal-code'],
315 '$country_name' => $r[0]['country-name'],
316 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
317 '$gender' => gender_selector($r[0]['gender']),
318 '$marital' => marital_selector($r[0]['marital']),
319 '$sexual' => sexpref_selector($r[0]['sexual']),
320 '$about' => $r[0]['about'],
321 '$homepage' => $r[0]['homepage'],
322 '$politic' => $r[0]['politic'],
323 '$religion' => $r[0]['religion'],
324 '$music' => $r[0]['music'],
325 '$book' => $r[0]['book'],
326 '$tv' => $r[0]['tv'],
327 '$film' => $r[0]['film'],
328 '$interest' => $r[0]['interest'],
329 '$romance' => $r[0]['romance'],
330 '$work' => $r[0]['work'],
331 '$education' => $r[0]['education'],
332 '$contact' => $r[0]['contact']
341 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
345 $o .= file_get_contents('view/profile_listing_header.tpl');
346 $tpl_default = file_get_contents('view/profile_entry_default.tpl');
347 $tpl = file_get_contents('view/profile_entry.tpl');
350 $template = (($rr['is-default']) ? $tpl_default : $tpl);
351 $o .= replace_macros($template, array(
352 '$photo' => $rr['thumb'],
354 '$profile_name' => $rr['profile-name']