-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadd-knowledge.php
170 lines (102 loc) · 6.02 KB
/
add-knowledge.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
168
169
170
<?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'] : '';
$value=isset($_POST['value']) ? (int)$_POST['value'] : 100;
$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['KNOWLEDGE']['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) {
$title=trim($title);
if (strlen($title)>100) { $error.='<li> Title is too long (Max. 100 Characters)'; }
$title=str_replace('"','"',$title);
}
# check text
if (!$text) { $error.='<li> Text cannot be left blank'; }
else {
$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['KNOWLEDGE']['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('KNOWLEDGE','MAIN',$datetime,$userid);
$base_instance->query('INSERT INTO '.$base_instance->entity['KNOWLEDGE']['MAIN'].' (datetime,text,title,user,category,value,public) VALUES ("'.sql_safe($datetime).'","'.sql_safe($text).'","'.sql_safe($title).'",'.$userid.','.$category_id.','.$value.','.$public.')');
$knowledge_id=mysqli_insert_id($base_instance->db_link);
$data=$base_instance->get_data('SELECT title FROM '.$base_instance->entity['KNOWLEDGE']['CATEGORY'].' WHERE user='.$userid.' AND ID='.$category_id);
$cat_title=$data[1]->title;
$base_instance->show_message('Knowledge 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 DelKnow(item){if(confirm("Delete Knowledge?")){http.open(\'get\',\'delete-knowledge.php?item=\'+item); http.send(null);}}</script>
<a href="add-knowledge.php?category_id='.$category_id.'">[Add more]</a> <a href="edit-knowledge.php?knowledge_id='.$knowledge_id.'">[Edit]</a> <a href="javascript:DelKnow(\''.$knowledge_id.'\')">[Delete]</a> <a href="send-content.php?knowledge_id='.$knowledge_id.'">[Send]</a><p><a href="show-knowledge-categories.php">[Show all Categories]</a> <a href="show-knowledge.php">[Show all Knowledge]</a><p><b>Internal Link:</b> [k'.$knowledge_id.'] <b>Category:</b> '.$cat_title.' <a href="show-knowledge.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_know_category FROM '.$base_instance->entity['USER']['MAIN'].' WHERE ID='.$userid);
$category_id=$data[1]->default_know_category;
}
# build category section
$data=$base_instance->get_data("SELECT * FROM {$base_instance->entity['KNOWLEDGE']['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 Knowledge <a href="help-knowledge.php">[Help]</a>',
'HEAD'=>$js,
'FORM_ACTION'=>$_SERVER['PHP_SELF'],
'BODY'=>'onLoad="javascript:document.form1.title.focus()"',
'BUTTON_TEXT'=>'Save Knowledge'
));
$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'=>'text','NAME'=>'value','VALUE'=>$value,'SIZE'=>3,'TEXT'=>'Value'));
$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'=>'Knowledge 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();
?>