forked from lane711/excida
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
417 lines (367 loc) · 13.8 KB
/
user.php
File metadata and controls
417 lines (367 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?php
define( 'PMR', true );
include 'config.php';
include PATH . '/defaults.php';
$title = $conf['website_name_short'] . ' - ' . $lang['Menu_User_Login'];
// If they are logged in
if (!auth_check($session->fetch('login'), $session->fetch('password')))
{
header( 'Location: login.php' );
exit();
}
include PATH . '/templates/' . $cookie_template . '/header.php';
$tpl = PATH . '/templates/' . $cookie_template . '/tpl/user.tpl';
$template = new Template;
$template->load ( $tpl );
$template->set( '@add_listing', $lang['Menu_Submit_Property'] );
$template->set( '@control_panel', $lang['Menu_User_Login'] );
$template->set( '@edit_listings', $lang['Edit_Listings'] );
$sid = $session->fetch('site_id');
$clause = isset($sid)? " site_id=".$sid:"1=1";
// Grab all data for this seller
$sql = "
SELECT
u.*,
l1.location_name AS country,
l2.location_name AS state,
l3.location_name AS city,
l1.location_id AS country_id,
l2.location_id AS state_id,
l3.location_id AS city_id
FROM " . USERS_TABLE . " u
LEFT JOIN " . LOCATIONS_TABLE . " AS l1 ON l1.location_id = u.location_1
LEFT JOIN " . LOCATIONS_TABLE . " AS l2 ON l2.location_id = u.location_2
LEFT JOIN " . LOCATIONS_TABLE . " AS l3 ON l3.location_id = u.location_3
WHERE
u.login = '" . $session->fetch( 'login' ) . "' AND ".$clause."
";
$q = $db->query( $sql ) or error( 'Critical Error', mysql_error() );
$f = $db->fetcharray( $q );
// Delete logo
if ( $_REQUEST['action'] == 'remove_logo' )
{
// Get their image name to make sure this is the authorized image to remove
$sql = "
SELECT image
FROM " . USERS_TABLE . "
WHERE login = '" . $_SESSION['login'] . "'
";
$q2 = $db->query( $sql );
$f2 = $db->fetcharray( $q2 );
// Remove from DB
$sql = "
UPDATE " . USERS_TABLE . "
SET
image = ''
WHERE
login = '" . $db->makeSafe( $_SESSION['login'] ) . "'
";
$q2 = $db->query( $sql );
// Delete their image
remove_image( 'photos' , $f2['image'] );
}
// If this account is approved and approval is required, allow them to continue
if ( ( $conf['approve_realtors'] == 'ON' && $f['approved'] == 1 ) || $conf['approve_realtors'] == 'OFF' )
{
if ( $_POST['submit'] == true )
{
$form = $_POST;
$errors = 0;
// Keep newlines
$form['realtor_description'] = safehtml_cms(@$_POST['realtor_description']);
// If password was not changed we do not update the password field
if ($_SESSION['password'] != $_POST['realtor_password'] )
{
$passwordin = md5( $_POST['realtor_password'] );
}
else
{
$passwordin = $session->fetch('password');
}
// Cut the description if JS is disabled
$form['realtor_description'] = substr ($form['realtor_description'], 0, $conf['realtor_description_size']);
if (empty($form['realtor_first_name']) || strlen($form['realtor_first_name']) < 2 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_First_Name'];
$errors++;
}
if (empty($form['realtor_last_name']) || strlen($form['realtor_last_name']) < 2 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_Last_Name'];
$errors++;
}
if ( empty( $form['location1'] ) )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['City'];
$errors++;
}
if (empty($form['realtor_address']) || strlen($form['realtor_address']) < 4 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_Address'];
$errors++;
}
if (empty($form['realtor_phone']) || strlen($form['realtor_phone']) < 4 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_Phone'];
$errors++;
}
if (empty($form['realtor_e_mail']) || strlen($form['realtor_e_mail']) < 4 || !valid_email($form['realtor_e_mail']))
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_e_mail'];
$errors++;
}
if (empty($form['realtor_password']) || strlen($form['realtor_password']) < 4 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Realtor_Password'];
$errors++;
}
if ( preg_match('/[^A-Za-z0-9]+$/', $form['realtor_password']))
{
$error_message = $lang['Password_Incorrect'];
$errors++;
}
// Check if this email is already used
if ( $conf['allow_same_e_mail'] == 'ON' )
{
$sql = 'SELECT id FROM ' . USERS_TABLE . ' WHERE email = "' . $form['realtor_e_mail'] . '" AND login != "' . $session->fetch('login') . '"';
$r = $db->query($sql) or error ('Critical Error', mysql_error () );
if ($db->fetcharray($r) > 0 )
{
$error_message = $lang['Field_Empty'] . ': ' . $lang['Email_User'];
$errors++;
}
}
// If errors found we print out the number of errors
if ( $errors > 0 )
{
$output_message = error( $lang['Error'], $error_message, true );
}
else
{
$proceed = true;
// If uploading a new logo
if ( $_FILES['submit_logo']['tmp_name'] != '' )
{
if ( upload_image( 'photos', $session->fetch( 'u_id' ), $_FILES['submit_logo'] ) == false )
{
$output_message = error( $lang['Error'], $lang['Realtor_Image_NOT_Uploaded'], true );
$proceed = false;
}
else
{
$imageSQL = ", image_uploaded = '1' ";
}
}
// Create a mysql query
if ( $proceed == true )
{
// Strip characters from the phone, etc. fields (numbers only)
$form['phone'] = preg_replace( '/[^0-9]+/', '', $form['phone'] );
$form['fax'] = preg_replace( '/[^0-9]+/', '', $form['fax'] );
$form['mobile'] = preg_replace( '/[^0-9]+/', '', $form['mobile'] );
$sql = "
UPDATE " . USERS_TABLE . "
SET
first_name = '" . $db->makeSafe( $form['realtor_first_name'] ) . "',
last_name = '" . $db->makeSafe( $form['realtor_last_name'] ) . "',
company_name = '" . $db->makeSafe( $form['realtor_company_name'] ) . "',
description = '" . $db->makeSafe( $form['realtor_description'] ) . "',
location_1 = '" . $db->makeSafe( $form['location1'] ) . "',
location_2 = '" . $db->makeSafe( $form['location2'] ) . "',
location_3 = '" . $db->makeSafe( $form['location3'] ) . "',
zip = '" . $db->makeSafe( $form['realtor_zip_code'] ) . "',
address = '" . $db->makeSafe( $form['realtor_address'] ) . "',
phone = '" . $db->makeSafe( $form['realtor_phone'] ) . "',
fax = '" . $db->makeSafe( $form['realtor_fax'] ) . "',
mobile = '" . $db->makeSafe( $form['realtor_mobile'] ) . "',
email = '" . $db->makeSafe( $form['realtor_e_mail'] ) . "',
website = '" . $db->makeSafe( $form['realtor_website'] ) . "',
date_updated = '" . date('Y-m-d') . "',
ip_updated = '" . $_SERVER['REMOTE_ADDR'] . "',
password = '" . $passwordin . "'
" . $imageSQL . "
WHERE
login = '" . $session->fetch('login') . "'
";
$q2 = $db->query( $sql ) or error('Critical Error', mysql_error() );
// Change current session password if user has changed his password in the form
$session->varunset('password');
$session->set('password', $passwordin);
// Let them know these changes are pending review or updated depending upon configuration options
if ($conf['approve_realtors'] == 'ON')
{
$output_message = success( $lang['Success'], $lang['Realtor_Listing_Updated_Approve'], true );
}
else
{
$output_message = success( $lang['Success'], $lang['Realtor_Listing_Updated'], true );
}
}
}
}
}
else
{
$output_message = error( $lang['Not_Approved'], $lang['Not_Approved'], true );
}
// Grab all data for this seller
$sql = "
SELECT
u.*,
l1.location_name AS country,
l2.location_name AS state,
l3.location_name AS city,
l1.location_id AS country_id,
l2.location_id AS state_id,
l3.location_id AS city_id
FROM " . USERS_TABLE . " u
LEFT JOIN " . LOCATIONS_TABLE . " AS l1 ON l1.location_id = u.location_1
LEFT JOIN " . LOCATIONS_TABLE . " AS l2 ON l2.location_id = u.location_2
LEFT JOIN " . LOCATIONS_TABLE . " AS l3 ON l3.location_id = u.location_3
WHERE
u.login = '" . $session->fetch( 'login' ) . "'
";
$q = $db->query( $sql ) or error( 'Critical Error', mysql_error() );
$f = $db->fetcharray( $q );
// Fetching the listings number from the table
$sql = 'SELECT listing_id FROM ' . PROPERTIES_TABLE . ' WHERE userid = "' . $f['u_id'] . '"';
$r_listings = $db->query( $sql );
$total_listings = $db->numrows( $r_listings );
// Fetch the package and the number of listings allowed
if ( $f['package'] != '' && $f['package'] != '0' )
{
// Fetch Packages
$sql = 'SELECT * FROM ' . PACKAGES_AGENT_TABLE . ' WHERE id = "' . $f['package'] . '" LIMIT 1';
$r_package = $db->query ( $sql );
$f_package = $db->fetcharray ( $r_package );
}
else
{
$f_package['listings'] = $conf['free_listings'];
}
$package_selection = payment_gateway( 'account', $f['u_id'], $session->fetch('login') );
// Define the form variables if the form was not updated
if ( !isset( $form ) )
{
$form = array();
$form['realtor_first_name'] = $f['first_name'];
$form['realtor_last_name'] = $f['last_name'];
$form['realtor_company_name'] = $f['company_name'];
$form['realtor_description'] = $f['description'];
$form['realtor_city'] = $f['city'];
$form['realtor_address'] = $f['address'];
$form['realtor_zip_code'] = $f['zip'];
$form['realtor_phone'] = $f['phone'];
$form['realtor_fax'] = $f['fax'];
$form['realtor_mobile'] = $f['mobile'];
$form['realtor_e_mail'] = $f['email'];
$form['realtor_website'] = $f['website'];
$form['realtor_password'] = $f['password'];
$form['realtor_state'] = $f['state'];
}
else
{
// Set new password if the form was changed
$form['realtor_password'] = $passwordin;
}
// Fetch all packages if site is running in portal mode
if ( $conf['site_mode'] == 2 )
{
$custom['show_packages'] = true;
$package_list = payment_gateway( 'account', $f['u_id'], $_SESSION['login'] );
}
// Look up any package selections they currently have
if ($f['package'] != '0' && $f['package'] != '')
{
$sql = 'SELECT * FROM ' . FEATURED_AGENTS_TABLE . ' WHERE id = ' . $f['u_id'];
$r_featured = $db->query($sql) or error ('Critical Error', mysql_error () );
$f_featured = $db->fetcharray($r_featured) or error ('Critical Error', mysql_error () );
$sql = 'SELECT * FROM ' . PACKAGES_AGENT_TABLE . ' WHERE id = ' . $f['package'];
$r_packages = $db->query($sql) or error ('Critical Error', mysql_error () );
$f_packages = $db->fetcharray($r_packages) or error ('Critical Error', mysql_error () );
$package_name = $f_packages['name'];
$package_date = printdate( $f_featured['end_date'] );
}
else
{
$package_name = 'FREE';
$package_date = 'Never';
}
// Default profile image
if ( $f['image'] != '' )
{
$custom['image'] = $f['image'];
$images = get_images( 'photos', $f['u_id'], 100, 74, 1, 1 );
$image = $images[0];
}
else
{
$custom['image'] = '';
$image = $lang['No_Image'];
}
// Location multi-drop down
$custom['location1_name'] = $f['country'];
$custom['location1_id'] = $f['country_id'];
$custom['location2_name'] = $f['state'];
$custom['location2_id'] = $f['state_id'];
$custom['location3_name'] = $f['city'];
$custom['location3_id'] = $f['city_id'];
// Language-specific values
$template->set( '@heading', $lang['Menu_User_Login'] );
$template->set( '@navigation', $navigation );
$template->set( '@output_message', $output_message );
$template->set( 'packages_header', $lang['Upgrade_Account'] );
$template->set( '@personal_info', $lang['Personal_Info'] );
$template->set( '@contact_info', $lang['Contact_Info'] );
$template->set( '@image_info', $lang['Image_Info'] );
$template->set( '@firstname', $lang['Realtor_First_Name'] );
$template->set( '@lastname', $lang['Realtor_Last_Name'] );
$template->set( '@submit_logo', $lang['Realtor_Submit_Logo'] );
$template->set( '@remove_logo', $lang['Realtor_Submit_Logo_Remove'] );
$template->set( '@company', $lang['Realtor_Company_Name'] );
$template->set( '@description', $lang['Realtor_Description'] );
$template->set( '@address', $lang['Realtor_Address'] );
$template->set( '@phone', $lang['Realtor_Phone'] );
$template->set( '@fax', $lang['Realtor_Fax'] );
$template->set( '@password', $lang['Realtor_Password'] );
$template->set( '@mobile', $lang['Realtor_Mobile'] );
$template->set( '@email', $lang['Realtor_e_mail'] );
$template->set( '@url', $lang['Realtor_Website'] );
$template->set( '@location', $lang['Location'] );
$template->set( '@zip', $lang['Zip_Code'] );
$template->set( '@submit', $lang['Save_Changes'] );
$template->set( '@description_limit', $lang['Characters_Left'] );
$template->set( '@updated', $lang['Listing_Updated_Date'] );
$template->set( '@added', $lang['Listing_Added_Date'] );
$template->set( '@hits', $lang['Hits'] );
$template->set( '@package_name', $lang['Admin_Packages_Name'] );
$template->set( '@package_date', $lang['Admin_Listing_Expire'] );
// Form contents
$template->set( 'total_listings', $total_listings );
$template->set( 'firstname', $form['realtor_first_name'] );
$template->set( 'lastname', $form['realtor_last_name'] );
$template->set( 'company', $form['realtor_company_name'] );
$template->set( 'description', $form['realtor_description'] );
$template->set( 'address', $form['realtor_address'] );
$template->set( 'fax', $form['realtor_fax'] );
$template->set( 'password', $form['realtor_password'] );
$template->set( 'mobile', $form['realtor_mobile'] );
$template->set( 'location1', get_locations() );
$template->set( 'email', $form['realtor_e_mail'] );
$template->set( 'url', $form['realtor_website'] );
$template->set( 'phone', $form['realtor_phone'] );
$template->set( 'zip', $form['realtor_zip_code'] );
$template->set( 'image', $image );
$template->set( 'description_limit', $conf['realtor_description_size'] );
$template->set( 'hits', $f['hits'] );
$template->set( 'updated', printdate( $f['date_updated'] ) );
$template->set( 'added', printdate( $f['date_added'] ) );
$template->set( 'package_name', $package_name );
$template->set( 'package_date', $package_date );
$template->set( 'navigation', $navigation );
$template->set( 'output_message', $output_message );
$template->set( 'package_selection', $package_selection );
$template->set( 'package_list', $package_list );
$template->publish();
include PATH . '/templates/' . $cookie_template . '/footer.php';
?>