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.
13 if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
14 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
16 intval($_SESSION['uid'])
19 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
22 $is_default = (($r[0]['is-default']) ? 1 : 0);
24 $profile_name = notags(trim($_POST['profile_name']));
25 if(! strlen($profile_name)) {
26 $a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
30 $name = notags(trim($_POST['name']));
31 $gender = notags(trim($_POST['gender']));
32 $address = notags(trim($_POST['address']));
33 $locality = notags(trim($_POST['locality']));
34 $region = notags(trim($_POST['region']));
35 $postal_code = notags(trim($_POST['postal_code']));
36 $country_name = notags(trim($_POST['country_name']));
37 $marital = notags(trim(implode(', ',$_POST['marital'])));
38 $homepage = notags(trim($_POST['homepage']));
39 $about = str_replace(array('<','>','&'),array('<','>','&'),trim($_POST['about']));
40 if(x($_POST,'profile_in_directory'))
41 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
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;
78 $r = q("UPDATE `profile`
80 WHERE `id` = %d AND `uid` = %d LIMIT 1",
83 intval($_SESSION['uid'])
98 function profiles_content(&$a) {
100 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
104 if(($a->argc > 1) && ($a->argv[1] == 'new')) {
106 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
107 intval($_SESSION['uid']));
108 $num_profiles = count($r0);
110 $name = "Profile-" . ($num_profiles + 1);
112 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
113 intval($_SESSION['uid']));
115 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
116 VALUES ( %d, '%s', '%s', '%s', '%s' )",
117 intval($_SESSION['uid']),
119 dbesc($r1[0]['name']),
120 dbesc($r1[0]['photo']),
121 dbesc($ra[0]['thumb'])
124 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
125 intval($_SESSION['uid']),
128 $_SESSION['sysmsg'] .= "New profile created." . EOL;
130 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
131 goaway($a->get_baseurl() . '/profiles');
134 if(($a->argc > 2) && ($a->argv[1] == 'clone')) {
136 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
137 intval($_SESSION['uid']));
138 $num_profiles = count($r0);
140 $name = "Profile-" . ($num_profiles + 1);
141 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
142 intval($_SESSION['uid']),
146 notice("Profile unavailable to clone." . EOL);
150 $r1[0]['is-default'] = 0;
151 $r1[0]['publish'] = 0;
152 $r1[0]['profile-name'] = dbesc($name);
156 $r2 = q("INSERT INTO `profile` (`"
157 . implode("`, `", array_keys($r1[0]))
159 . implode("', '", array_values($r1[0]))
162 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
163 intval($_SESSION['uid']),
166 $_SESSION['sysmsg'] .= "New profile created." . EOL;
168 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
169 goaway($a->get_baseurl() . '/profiles');
170 return; // NOTREACHED
177 if(intval($a->argv[1])) {
178 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
180 intval($_SESSION['uid'])
183 $_SESSION['sysmsg'] .= "Profile not found." . EOL;
187 require_once('mod/profile.php');
188 profile_load($a,$_SESSION['uid'],$r[0]['id']);
190 require_once('view/profile_selectors.php');
192 $tpl = file_get_contents('view/jot-header.tpl');
193 $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
194 $profile_in_dir = replace_macros($opt_tpl,array(
195 '$yes_selected' => (($r[0]['publish']) ? " checked=\"checked\" " : ""),
196 '$no_selected' => (($r[0]['publish'] == 0) ? " checked=\"checked\" " : "")
200 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
201 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
203 // $a->page['aside'] = file_get_contents('view/sidenote.tpl');
204 $is_default = (($r[0]['is-default']) ? 1 : 0);
205 $tpl = file_get_contents("view/profile_edit.tpl");
206 $o .= replace_macros($tpl,array(
207 '$baseurl' => $a->get_baseurl(),
208 '$profile_id' => $r[0]['id'],
209 '$profile_name' => $r[0]['profile-name'],
210 '$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.</p>" : ""),
211 '$name' => $r[0]['name'],
212 '$dob' => $r[0]['dob'],
213 '$address' => $r[0]['address'],
214 '$locality' => $r[0]['locality'],
215 '$region' => $r[0]['region'],
216 '$postal_code' => $r[0]['postal-code'],
217 '$country_name' => $r[0]['country-name'],
218 '$age' => $r[0]['age'],
219 '$gender' => gender_selector($r[0]['gender']),
220 '$marital' => marital_selector($r[0]['marital']),
221 '$about' => $r[0]['about'],
222 '$homepage' => $r[0]['homepage'],
223 '$profile_in_dir' => (($is_default) ? $profile_in_dir : '')
232 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
236 $o .= file_get_contents('view/profile_listing_header.tpl');
237 $tpl_default = file_get_contents('view/profile_entry_default.tpl');
238 $tpl = file_get_contents('view/profile_entry.tpl');
241 $template = (($rr['is-default']) ? $tpl_default : $tpl);
242 $o .= replace_macros($template, array(
243 '$photo' => $rr['thumb'],
245 '$profile_name' => $rr['profile-name']