]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
directory stuff
[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
14
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",
17                         intval($a->argv[1]),
18                         intval($_SESSION['uid'])
19                 );
20                 if(! count($r)) {
21                         $_SESSION['sysmsg'] .= "Profile not found." . EOL;
22                         return;
23                 }
24
25                 $profile_name = notags(trim($_POST['profile_name']));
26                 if(! strlen($profile_name)) {
27                         $a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
28                         return;
29                 }
30         
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('&lt;','&gt;','&amp;'),trim($_POST['about']));
41
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
78
79 }
80
81
82
83
84 function profiles_content(&$a) {
85         if(! local_user()) {
86                 $_SESSION['sysmsg'] .= "Unauthorised." . EOL;
87                 return;
88         }
89
90         if(($a->argc > 1) && ($a->argv[1] == 'new')) {
91
92                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
93                         intval($_SESSION['uid']));
94                 $num_profiles = count($r0);
95
96                 $name = "Profile-" . ($num_profiles + 1);
97
98                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
99                         intval($_SESSION['uid']));
100                 
101                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
102                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
103                         intval($_SESSION['uid']),
104                         dbesc($name),
105                         dbesc($r1[0]['name']),
106                         dbesc($r1[0]['photo']),
107                         dbesc($ra[0]['thumb'])
108                 );
109
110                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
111                         intval($_SESSION['uid']),
112                         dbesc($name)
113                 );
114                 $_SESSION['sysmsg'] .= "New profile created." . EOL;
115                 if(count($r3) == 1)
116                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
117                 goaway($a->get_baseurl() . '/profiles');
118         }                
119
120
121         if(intval($a->argv[1])) {
122                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123                         intval($a->argv[1]),
124                         intval($_SESSION['uid'])
125                 );
126                 if(! count($r)) {
127                         $_SESSION['sysmsg'] .= "Profile not found." . EOL;
128                         return;
129                 }
130
131                 require_once('mod/profile.php');
132                 profile_load($a,$_SESSION['uid'],$r[0]['id']);
133
134                 require_once('view/profile_selectors.php');
135
136                 $tpl = file_get_contents('view/jot-header.tpl');
137                 $profile_in_dir = file_get_contents("view/profile-in-directory.tpl");
138
139                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
140         
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 : '')
162                 ));
163
164                 return $o;
165
166
167         }
168         else {
169
170                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
171                         $_SESSION['uid']);
172                 if(count($r)) {
173
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');
177
178                         foreach($r as $rr) {
179                                 $template = (($rr['is-default']) ? $tpl_default : $tpl);
180                                 $o .= replace_macros($template, array(
181                                         '$photo' => $rr['thumb'],
182                                         '$id' => $rr['id'],
183                                         '$profile_name' => $rr['profile-name']
184                                 ));
185                         }
186                 }
187                 return $o;
188         }
189
190 }