-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadd-contact.php
160 lines (95 loc) · 6.75 KB
/
add-contact.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
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
<?php
require 'class.base.php';
require 'class.html.php';
$base_instance=new base();
$html_instance=new html();
$userid=$base_instance->get_userid();
$company=isset($_POST['company']) ? $_POST['company'] : '';
$firstname=isset($_POST['firstname']) ? $_POST['firstname'] : '';
$lastname=isset($_POST['lastname']) ? $_POST['lastname'] : '';
$email=isset($_POST['email']) ? $_POST['email'] : '';
$telephone=isset($_POST['telephone']) ? $_POST['telephone'] : '';
$fax=isset($_POST['fax']) ? $_POST['fax'] : '';
$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : '';
$address=isset($_POST['address']) ? $_POST['address'] : '';
$notes=isset($_POST['notes']) ? $_POST['notes'] : '';
$url=isset($_POST['url']) ? $_POST['url'] : '';
$new_category=isset($_POST['new_category']) ? $_POST['new_category'] : '';
$category_id=isset($_REQUEST['category_id']) ? (int)$_REQUEST['category_id'] : '';
$public=isset($_POST['public']) ? (int)$_POST['public'] : 1;
if (isset($_POST['save'])) {
$error='';
if (!$firstname && !$lastname && !$company) { $error.='<li> First name / Last name / Company cannot be left blank'; }
if (!$category_id && !$new_category) { $error.='<li> Category cannot be left blank'; }
if ($new_category) {
$duplicate=$base_instance->get_data('SELECT * FROM '.$base_instance->entity['CONTACT']['CATEGORY'].' WHERE title="'.sql_safe($new_category).'" AND user='.$userid);
if ($duplicate) { $error.='<li> Category with this name already exists'; }
$new_category=str_replace('"','"',$new_category);
if (strlen($new_category)>50) { $error.='<li> Category title is too long (Max. 50 Characters)'; }
}
if (!$error) {
if ($new_category) {
$base_instance->query('INSERT INTO '.$base_instance->entity['CONTACT']['CATEGORY'].' (title,user) VALUES ("'.sql_safe($new_category).'",'.$userid.')');
$category_id=mysqli_insert_id($base_instance->db_link);
}
$datetime=$_POST['datetime'];
$html_instance->check_for_duplicates('CONTACT','MAIN',$datetime,$userid);
$firstname=str_replace('"','"',$firstname);
$lastname=str_replace('"','"',$lastname);
$address=str_replace('"','"',$address);
$company=str_replace('"','"',$company);
$base_instance->query('INSERT INTO '.$base_instance->entity['CONTACT']['MAIN'].' (datetime,user,firstname,lastname,email,telephone,fax,mobile,address,notes,company,url,category,public) VALUES ("'.sql_safe($datetime).'",'.$userid.',"'.sql_safe($firstname).'","'.sql_safe($lastname).'","'.sql_safe($email).'","'.sql_safe($telephone).'","'.sql_safe($fax).'","'.sql_safe($mobile).'","'.sql_safe($address).'","'.sql_safe($notes).'","'.sql_safe($company).'","'.sql_safe($url).'",'.$category_id.','.$public.')');
$contact_id=mysqli_insert_id($base_instance->db_link);
$data=$base_instance->get_data("SELECT title FROM {$base_instance->entity['CONTACT']['CATEGORY']} WHERE user='$userid' AND ID='$category_id'");
$cat_title=$data[1]->title;
$base_instance->show_message('Contact saved','<script language="JavaScript" type="text/javascript">function createRequestObject(){try{var requester=new XMLHttpRequest();}catch(error){try{var requester=new ActiveXObject("Microsoft.XMLHTTP");}catch(error){return false;}} return requester;}var http=createRequestObject();function DelContact(item){if(confirm("Delete Contact?")){http.open(\'get\',\'delete-contact.php?item=\'+item); http.send(null);}}</script>
<a href="add-contact.php?category_id='.$category_id.'">[Add more]</a> <a href="edit-contact.php?contact_id='.$contact_id.'">[Edit]</a> <a href="javascript:DelContact(\''.$contact_id.'\')">[Delete]</a> <a href="send-content.php?contact_id='.$contact_id.'">[Send]</a><p><a href="show-contact-categories.php">[Show all Categories]</a> <a href="show-contact.php">[Show all Contacts]</a><p><b>Internal Link:</b> [c'.$contact_id.'] <b>Category:</b> '.$cat_title.' <a href="show-contact.php?category_id='.$category_id.'">[Show]</a>');
}
else {
$html_instance->error_message=$error;
$company=stripslashes($company);
$address=stripslashes($address);
$notes=stripslashes($notes);
}
}
# default category
if (!$category_id) {
$data=$base_instance->get_data("SELECT default_contact_category FROM {$base_instance->entity['USER']['MAIN']} WHERE ID='$userid'");
$category_id=$data[1]->default_contact_category;
}
# build category section
$data=$base_instance->get_data("SELECT * FROM {$base_instance->entity['CONTACT']['CATEGORY']} WHERE user='$userid' ORDER BY title");
if (!$data) { $cat_title='New Category:'; $select_category=' <input type="text" name="new_category" value="'.$new_category.'">'; }
else {
$cat_title='Category:';
$select_category=' <select name="category_id">';
for ($index=1; $index <= sizeof($data); $index++) {
$category_title=$data[$index]->title;
$ID=$data[$index]->ID;
if ($ID==$category_id) { $select_category.="<option selected value=$ID>$category_title"; }
else { $select_category.="<option value=$ID>$category_title"; }
}
$select_category.='</select> or <b>New Category:</b> <input type="text" name="new_category" value="'.$new_category.'" size="12">';
}
#
$html_instance->add_parameter(
array('ACTION'=>'show_form',
'HEADER'=>'Add Contact',
'FORM_ACTION'=>$_SERVER['PHP_SELF'],
'BODY'=>'onLoad="javascript:document.form1.firstname.focus()"',
'BUTTON_TEXT'=>'Save Contact'
));
$html_instance->add_form_field(array('TYPE'=>'label','TEXT1'=>"$cat_title",'TEXT2'=>$select_category,'SECTIONS'=>2));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'firstname','VALUE'=>$firstname,'SIZE'=>45,'TEXT'=>'First Name'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'lastname','VALUE'=>$lastname,'SIZE'=>45,'TEXT'=>'Last Name'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'company','VALUE'=>$company,'SIZE'=>45,'TEXT'=>'Company'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'email','VALUE'=>$email,'SIZE'=>45,'TEXT'=>'Email'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'telephone','VALUE'=>$telephone,'SIZE'=>45,'TEXT'=>'Telephone'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'fax','VALUE'=>$fax,'SIZE'=>45,'TEXT'=>'Fax'));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'mobile','VALUE'=>$mobile,'SIZE'=>45,'TEXT'=>'Mobile'));
$html_instance->add_form_field(array('TYPE'=>'textarea','NAME'=>'address','VALUE'=>$address,'COLS'=>60,'ROWS'=>3,'TEXT'=>'Address','SECTIONS'=>2));
$html_instance->add_form_field(array('TYPE'=>'textarea','NAME'=>'notes','VALUE'=>$notes,'COLS'=>60,'ROWS'=>6,'TEXT'=>'Notes','SECTIONS'=>2));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'url','VALUE'=>$url,'SIZE'=>45,'TEXT'=>'Website'));
$html_instance->add_form_field(array('TYPE'=>'radio','NAME'=>'public','FIELD_ARRAY'=>'public_array','VALUE'=>$public,'TEXT'=>'Contact is'));
$html_instance->process();
?>