]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
c6060c8c2f0825a8dfa54786d7471f4ef0582fc0
[friendica.git] / mod / profiles.php
1 <?php
2
3
4 function profiles_post(&$a) {
5
6         if(! local_user()) {
7                 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
8                 return;
9         }
10
11         // todo - delete... ensure that all contacts using the to-be-deleted profile are moved to the default.          
12
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",
15                         intval($a->argv[1]),
16                         intval($_SESSION['uid'])
17                 );
18                 if(! count($r)) {
19                         $_SESSION['sysmsg'] .= "Profile not found." . EOL;
20                         return;
21                 }
22                 $is_default = (($r[0]['is-default']) ? 1 : 0);
23
24                 $profile_name = notags(trim($_POST['profile_name']));
25                 if(! strlen($profile_name)) {
26                         $a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
27                         return;
28                 }
29         
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('&lt;','&gt;','&amp;'),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')))
43                         $gender = '';
44
45                 $r = q("UPDATE `profile` 
46                         SET `profile-name` = '%s',
47                         `name` = '%s',
48                         `gender` = '%s',
49                         `address` = '%s',
50                         `locality` = '%s',
51                         `region` = '%s',
52                         `postal-code` = '%s',
53                         `country-name` = '%s',
54                         `marital` = '%s',
55                         `homepage` = '%s',
56                         `about` = '%s'
57                         WHERE `id` = %d AND `uid` = %d LIMIT 1",
58                         dbesc($profile_name),
59                         dbesc($name),
60                         dbesc($gender),
61                         dbesc($address),
62                         dbesc($locality),
63                         dbesc($region),
64                         dbesc($postal_code),
65                         dbesc($country_name),
66                         dbesc($marital),
67                         dbesc($homepage),
68                         dbesc($about),
69                         intval($a->argv[1]),
70                         intval($_SESSION['uid'])
71                 );
72
73                 if($r)
74                         $_SESSION['sysmsg'] .= "Profile updated." . EOL;
75
76
77                 if($is_default) {
78                         $r = q("UPDATE `profile` 
79                         SET `publish` = %d
80                         WHERE `id` = %d AND `uid` = %d LIMIT 1",
81                         intval($publish),
82                         intval($a->argv[1]),
83                         intval($_SESSION['uid'])
84
85                         );
86                 }
87
88
89         }
90
91
92
93 }
94
95
96
97
98 function profiles_content(&$a) {
99         if(! local_user()) {
100                 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
101                 return;
102         }
103
104         if(($a->argc > 1) && ($a->argv[1] == 'new')) {
105
106                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
107                         intval($_SESSION['uid']));
108                 $num_profiles = count($r0);
109
110                 $name = "Profile-" . ($num_profiles + 1);
111
112                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
113                         intval($_SESSION['uid']));
114                 
115                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
116                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
117                         intval($_SESSION['uid']),
118                         dbesc($name),
119                         dbesc($r1[0]['name']),
120                         dbesc($r1[0]['photo']),
121                         dbesc($ra[0]['thumb'])
122                 );
123
124                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
125                         intval($_SESSION['uid']),
126                         dbesc($name)
127                 );
128                 $_SESSION['sysmsg'] .= "New profile created." . EOL;
129                 if(count($r3) == 1)
130                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
131                 goaway($a->get_baseurl() . '/profiles');
132         }                
133
134
135         if(intval($a->argv[1])) {
136                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
137                         intval($a->argv[1]),
138                         intval($_SESSION['uid'])
139                 );
140                 if(! count($r)) {
141                         $_SESSION['sysmsg'] .= "Profile not found." . EOL;
142                         return;
143                 }
144
145                 require_once('mod/profile.php');
146                 profile_load($a,$_SESSION['uid'],$r[0]['id']);
147
148                 require_once('view/profile_selectors.php');
149
150                 $tpl = file_get_contents('view/jot-header.tpl');
151                 $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
152                 $profile_in_dir = replace_macros($opt_tpl,array(
153                         '$yes_selected' => (($r[0]['publish']) ? " checked=\"checked\" " : ""),
154                         '$no_selected' => (($r[0]['publish'] == 0) ? " checked=\"checked\" " : "")
155                 ));
156
157
158                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
159         
160 //              $a->page['aside'] = file_get_contents('view/sidenote.tpl');     
161                 $is_default = (($r[0]['is-default']) ? 1 : 0);
162                 $tpl = file_get_contents("view/profile_edit.tpl");
163                 $o .= replace_macros($tpl,array(
164                         '$baseurl' => $a->get_baseurl(),
165                         '$profile_id' => $r[0]['id'],
166                         '$profile_name' => $r[0]['profile-name'],
167                         '$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.</p>" : ""),
168                         '$name' => $r[0]['name'],
169                         '$dob' => $r[0]['dob'],
170                         '$address' => $r[0]['address'],
171                         '$locality' => $r[0]['locality'],
172                         '$region' => $r[0]['region'],
173                         '$postal_code' => $r[0]['postal-code'],
174                         '$country_name' => $r[0]['country-name'],
175                         '$age' => $r[0]['age'],
176                         '$gender' => gender_selector($r[0]['gender']),
177                         '$marital' => marital_selector($r[0]['marital']),
178                         '$about' => $r[0]['about'],
179                         '$homepage' => $r[0]['homepage'],
180                         '$profile_in_dir' => (($is_default) ? $profile_in_dir : '')
181                 ));
182
183                 return $o;
184
185
186         }
187         else {
188
189                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
190                         $_SESSION['uid']);
191                 if(count($r)) {
192
193                         $o .= file_get_contents('view/profile_listing_header.tpl');
194                         $tpl_default = file_get_contents('view/profile_entry_default.tpl');
195                         $tpl = file_get_contents('view/profile_entry.tpl');
196
197                         foreach($r as $rr) {
198                                 $template = (($rr['is-default']) ? $tpl_default : $tpl);
199                                 $o .= replace_macros($template, array(
200                                         '$photo' => $rr['thumb'],
201                                         '$id' => $rr['id'],
202                                         '$profile_name' => $rr['profile-name']
203                                 ));
204                         }
205                 }
206                 return $o;
207         }
208
209 }