/
addlisting.php
executable file
·94 lines (81 loc) · 2.31 KB
/
addlisting.php
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
<?php
include_once('includes/config.php');
$smarty->assign("pageTitle", 'Add a New Listing');
$location_type = $FORM['location_type'];
if($location_type=='')
{
$smarty->assign("body", $smarty->fetch("addlisting_choose_type.tpl"));
$smarty->display("index.tpl");
exit;
}
if($FORM['save'] == 'Add It')
{ //Validate the submitted data
$save_new = true;
if(eregi('^[0-9]{1,2}$', $FORM['space_bedrooms'])===false)
{
$FORM['space_bedrooms'] = '';
$messages[] = "How many bedrooms are there?";
$save_new = false;
}
if(eregi('^[0-9]{1,2}(\.[0-9])?$', $FORM['space_bathrooms'])===false)
{
$FORM['space_bathrooms'] = '';
$messages[] = "How many bathrooms are there?";
$save_new = false;
}
if(eregi('^[0-9]{1,4}(\.[0-9]{1,2})?$', $FORM['space_rent'])===false)
{
$FORM['space_rent'] = '';
$messages[] = "How much is the monthly rent?";
$save_new = false;
}
if(!$User->complete_contact && $User->id == null)
{
if(isset($FORM['save_w_new_account']) ){
$smarty->assign('email', $FORM['email']);
$ready_to_register = true;
if(!ValidEmail($FORM['email'])){
$messages[] = 'You need a valid email address.';
$smarty->assign('email', '');
$ready_to_register = false;
}
if( $AllUsers->find_by_email($FORM['email'])!== false ){
$messages[] = "'<i>".$FORM['email']."</i>' is already registered. <br>Want to <a href='welcome.php'>log in</a> before adding this property?";
$smarty->assign('email', '');
$ready_to_register = false;
}
if($FORM['pass'] <> $FORM['confirm_pass'] OR $FORM['pass']=='')
{
$messages[] = 'Please enter two matching passwords.';
$ready_to_register = false;
}
if($ready_to_register !== false)
{
$user = $AllUsers->new_from_form($FORM, 'owner');
$_SESSION['user_id'] = $user->id;
}
else
{
$save_new = false;
}
} else {
$messages[] = 'Please login or create a new account';
$save_new = false;
}
}
}
if(!$save_new)
{
$smarty->assign('location_type', $location_type);
$smarty->assign('messages', $messages);
$smarty->assign('form', $FORM);
$smarty->assign("body", $smarty->fetch("list_lease.tpl"));
$smarty->display("index.tpl");
}
else
{
$location = $AllLocations->new_from_form($FORM);
$space = $location->new_space_from_form($FORM);
header("Location: editlisting.php?id=".$location->id);
}
?>