4 function profiles_post(&$a) {
7 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
11 // todo - delete... ensure that all contacts using the to-be-deleted profile are moved to the default.
15 if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
16 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
18 intval($_SESSION['uid'])
21 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
25 $profile_name = notags(trim($_POST['profile_name']));
26 if(! strlen($profile_name)) {
27 $a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
31 $name = notags(trim($_POST['name']));
32 $gender = notags(trim($_POST['gender']));
33 $address = notags(trim($_POST['address']));
34 $locality = notags(trim($_POST['locality']));
35 $region = notags(trim($_POST['region']));
36 $postal_code = notags(trim($_POST['postal_code']));
37 $country_name = notags(trim($_POST['country_name']));
38 $marital = notags(trim(implode(', ',$_POST['marital'])));
39 $homepage = notags(trim($_POST['homepage']));
40 $about = str_replace(array('<','>','&'),array('<','>','&'),trim($_POST['about']));
42 if(! in_array($gender,array('','Male','Female','Other')))
45 $r = q("UPDATE `profile`
46 SET `profile-name` = '%s',
53 `country-name` = '%s',
57 WHERE `id` = %d AND `uid` = %d LIMIT 1",
70 intval($_SESSION['uid'])
74 $_SESSION['sysmsg'] .= "Profile updated." . EOL;
84 function profiles_content(&$a) {
86 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
90 if(($a->argc > 1) && ($a->argv[1] == 'new')) {
92 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
93 intval($_SESSION['uid']));
94 $num_profiles = count($r0);
96 $name = "Profile-" . ($num_profiles + 1);
98 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
99 intval($_SESSION['uid']));
101 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
102 VALUES ( %d, '%s', '%s', '%s', '%s' )",
103 intval($_SESSION['uid']),
105 dbesc($r1[0]['name']),
106 dbesc($r1[0]['photo']),
107 dbesc($ra[0]['thumb'])
110 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
111 intval($_SESSION['uid']),
114 $_SESSION['sysmsg'] .= "New profile created." . EOL;
116 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
117 goaway($a->get_baseurl() . '/profiles');
121 if(intval($a->argv[1])) {
122 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
124 intval($_SESSION['uid'])
127 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
131 require_once('mod/profile.php');
132 profile_load($a,$_SESSION['uid'],$r[0]['id']);
134 require_once('view/profile_selectors.php');
136 $tpl = file_get_contents('view/jot-header.tpl');
137 $profile_in_dir = file_get_contents("view/profile-in-directory.tpl");
139 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
141 $a->page['aside'] = file_get_contents('view/sidenote.tpl');
142 $is_default = (($r[0]['is-default']) ? 1 : 0);
143 $tpl = file_get_contents("view/profile_edit.tpl");
144 $o .= replace_macros($tpl,array(
145 '$baseurl' => $a->get_baseurl(),
146 '$profile_id' => $r[0]['id'],
147 '$profile_name' => $r[0]['profile-name'],
148 '$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.</p>" : ""),
149 '$name' => $r[0]['name'],
150 '$dob' => $r[0]['dob'],
151 '$address' => $r[0]['address'],
152 '$locality' => $r[0]['locality'],
153 '$region' => $r[0]['region'],
154 '$postal_code' => $r[0]['postal-code'],
155 '$country_name' => $r[0]['country-name'],
156 '$age' => $r[0]['age'],
157 '$gender' => gender_selector($r[0]['gender']),
158 '$marital' => marital_selector($r[0]['marital']),
159 '$about' => $r[0]['about'],
160 '$homepage' => $r[0]['homepage'],
161 '$profile_in_dir' => (($is_default) ? $profile_in_dir : '')
170 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
174 $o .= file_get_contents('view/profile_listing_header.tpl');
175 $tpl_default = file_get_contents('view/profile_entry_default.tpl');
176 $tpl = file_get_contents('view/profile_entry.tpl');
179 $template = (($rr['is-default']) ? $tpl_default : $tpl);
180 $o .= replace_macros($template, array(
181 '$photo' => $rr['thumb'],
183 '$profile_name' => $rr['profile-name']