-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadd-note.php
167 lines (99 loc) · 5.67 KB
/
add-note.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
161
162
163
164
165
166
167
<?php
require 'class.base.php';
require 'class.html.php';
$base_instance=new base();
$html_instance=new html();
$userid=$base_instance->get_userid();
$title=isset($_POST['title']) ? $_POST['title'] : '';
$text=isset($_POST['text']) ? $_POST['text'] : '';
$category_id=isset($_REQUEST['category_id']) ? (int)$_REQUEST['category_id'] : '';
$new_category=isset($_POST['new_category']) ? $_POST['new_category'] : '';
$public=isset($_POST['public']) ? (int)$_POST['public'] : 1;
if (isset($_POST['save'])) {
$error='';
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['NOTE']['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 (!$title && !$text) { $error.='<li> Both Title and Text cannot be blank'; }
if ($title) {
$title=trim($title);
if (strlen($title)>100) { $error.='<li> Title is too long (Max. 100 Characters)'; }
$title=str_replace('"','"',$title);
}
if ($text) {
$text=trim($text);
if (strlen($text)>65535) { $error.='<li> Text is too long (Max. 65535 Characters)'; }
}
if (!$error) {
if ($new_category) {
$base_instance->query('INSERT INTO '.$base_instance->entity['NOTE']['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('NOTE','MAIN',$datetime,$userid);
$base_instance->query('INSERT INTO '.$base_instance->entity['NOTE']['MAIN'].' (datetime,text,title,user,category,public) VALUES ("'.sql_safe($datetime).'","'.sql_safe($text).'","'.sql_safe($title).'",'.$userid.','.$category_id.','.$public.')');
$note_id=mysqli_insert_id($base_instance->db_link);
$data=$base_instance->get_data('SELECT title FROM '.$base_instance->entity['NOTE']['CATEGORY'].' WHERE user='.$userid.' AND ID='.$category_id);
$cat_title=$data[1]->title;
$base_instance->show_message('Note 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 DelNote(item){if(confirm("Delete Note?")){http.open(\'get\',\'delete-note.php?item=\'+item); http.send(null);}}</script>
<a href="add-note.php?category_id='.$category_id.'">[Add more]</a> <a href="edit-note.php?note_id='.$note_id.'">[Edit]</a> <a href="javascript:DelNote(\''.$note_id.'\')">[Delete]</a> <a href="send-content.php?note_id='.$note_id.'">[Send]</a><p><a href="show-note-categories.php">[Show all Categories]</a> <a href="show-note.php">[Show all Notes]</a><p><b>Internal Link:</b> [n'.$note_id.'] <b>Category:</b> '.$cat_title.' <a href="show-note.php?category_id='.$category_id.'">[Show]</a>');
}
else {
$html_instance->error_message=$error;
$text=stripslashes($text);
$title=stripslashes($title);
}
}
# default category
if (empty($category_id)) {
$data=$base_instance->get_data("SELECT default_note_category FROM {$base_instance->entity['USER']['MAIN']} WHERE ID='$userid'");
$category_id=$data[1]->default_note_category;
}
# build category section
$data=$base_instance->get_data("SELECT * FROM {$base_instance->entity['NOTE']['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">';
}
#
$js='<script language="JavaScript" type="text/javascript">
function bigger(what,add) {
if (what.style.height==\'\') { what.style.height=\'300px\'; }
newHeight=parseInt(what.style.height)+add;
what.style.height=newHeight+"px";
}
function smaller(what,deduct) {
if ((parseInt(what.style.height)-deduct) > 50) {
newHeight=parseInt(what.style.height)-deduct;
what.style.height=newHeight+"px";
} else { newHeight=50; what.style.height="50px"; }
}
</script>';
$html_instance->add_parameter(
array('ACTION'=>'show_form',
'HEADER'=>'Add Note',
'HEAD'=>$js,
'FORM_ACTION'=>$_SERVER['PHP_SELF'],
'BODY'=>'onLoad="javascript:document.form1.title.focus()"',
'BUTTON_TEXT'=>'Save Note'
));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'title','VALUE'=>$title,'SIZE'=>50,'TEXT'=>'Title'));
$html_instance->add_form_field(array('TYPE'=>'label','TEXT1'=>$cat_title,'TEXT2'=>$select_category,'SECTIONS'=>2));
$html_instance->add_form_field(array('TYPE'=>'textarea','NAME'=>'text','VALUE'=>$text,'COLS'=>120,'ROWS'=>12));
$html_instance->add_form_field(array('TYPE'=>'radio','NAME'=>'public','FIELD_ARRAY'=>'public_array','VALUE'=>$public,'TEXT'=>'Note is'));
$html_instance->add_form_field(array('TYPE'=>'label','TEXT'=>'<span class="fakelink" onclick="bigger(document.form1.text,100);">[+]</span>
<span class="fakelink" onclick="smaller(document.form1.text,100);">[-]</span>'));
$html_instance->process();
?>