forked from bopoda/fl-ru-damp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.server.php
374 lines (328 loc) · 14.4 KB
/
notes.server.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
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
<?
$rpath = "../";
require_once($_SERVER['DOCUMENT_ROOT'] . "/xajax/notes.common.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/notes.php");
/**
* Èçìåíåíèå çàìåòêè äëÿ ñòðàíèöû ïðîñìîòðà ïðîôèëÿ ïîëüçîâàòåëÿ.
* Äîáàâëåíèå, èçìåíåíèå, óäàëåíèå
*
* @param int $login UID ïîëüçîâàòåëÿ êîòîðîìó ïèøåì çàìåòêó
* @param string $text Òåêñò çàìåòêè
* @return object xajaxResponse
*/
function saveHeaderNote($login, $text, $rating = 0, $fromProject = false) {
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/users.php");
session_start();
$objResponse = new xajaxResponse();
$oNotes = new notes();
$aNote = $oNotes->GetNote( $_SESSION['uid'], $login, $error );
$oUser = new users;
$nTargetId = $oUser->GetUid( $sError, $login );
$text = strip_only( trim($text), '<script>' );
$text = change_q_x( $text, FALSE, TRUE, "", false, false );
//$objResponse->script("$('zametka').removeClass('zametka-lnk').removeClass('zametka');");
if ( $aNote ) {
if ( $text != '' ) {
$error = notes::Update( $_SESSION['uid'], (int)$nTargetId, $text, $rating );
$text = stripslashes( $text );
$objResponse->assign( 'zametkaBD', 'outerHTML', getHeaderNote($login, $text) );
}
else {
$error = notes::DeleteNote( $_SESSION['uid'], (int)$nTargetId );
$objResponse->assign('zametkaBD', 'outerHTML', '
<div id="zametka" class="b-layout__txt b-layout__txt_padtop_5 b-layout__txt_inline-block">
<span class="b-icon b-icon__cont b-icon__cont_note"></span>
<a class="b-layout__link b-layout__link_bordbot_dot_0f71c8 b-layout__link_fontsize_13" href="javascript:void(0);" onclick="$(\'zametka_fmr\').toggleClass(\'b-layout_hide\');">Îñòàâèòü çàìåòêó</a>
</div>
');
}
}
elseif ( $text ) {
$error = notes::Add($_SESSION['uid'], (int)$nTargetId, $text);
$text = stripslashes( $text );
$objResponse->assign( 'zametka', 'outerHTML', getHeaderNote($login, $text) );
}
$objResponse->script('headerNoteText();');
// !!! òóò íóæåí htmlspecialchars_decode - ýòà ïåðåìåííàÿ õðàíèò èñõîäíûé êîä çàìåòêè êîòîðûé â òåêñòàðèþ ïîäñòàâëÿåòñÿ
$objResponse->script("headerNote = '". input_ref_scr(htmlspecialchars_decode($text)) ."';");
return $objResponse;
}
/**
* òî æå ÷òî saveHeaderNote, òîëüêî èñïîëüçóåòñÿ èç ïðîåêòîâ
*/
function saveHeaderNoteFromProject($login, $text, $rating = 0, $fromProject = false) {
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/users.php");
session_start();
$objResponse = new xajaxResponse();
$oNotes = new notes();
$aNote = $oNotes->GetNote( $_SESSION['uid'], $login, $error );
$oUser = new users;
$nTargetId = $oUser->GetUid( $sError, $login );
$text = substr($text, 0, 200);
$text = strip_only( trim($text), '<script>' );
$text = change_q_x( $text, FALSE, TRUE, "", false, false );
// åñëè çàìåòêà óæå åñòü
if ($aNote) {
if ( $text != '' ) {
$error = notes::Update( $_SESSION['uid'], (int)$nTargetId, $text, $rating );
$text = stripslashes( $text );
} else {
$error = notes::DeleteNote( $_SESSION['uid'], (int)$nTargetId );
}
} elseif ($text) {
$error = notes::Add($_SESSION['uid'], (int)$nTargetId, $text);
$text = stripslashes($text);
}
// ýêðàíèðóåì áýêñëýøè
$text = str_replace('\\', '\\\\', $text);
$text = reformat($text, 22, 0, 0, 1, 22);
$text = str_replace('"', '\"', $text);
$objResponse->script('$("noteTextBlock").fireEvent("noteSaved", "' . $text . '")');
return $objResponse;
}
/**
* Ãåíåðèðóåò HTML êîä çàìåòêè äëÿ ñòðàíèöû ïðîñìîòðà ïðîôèëÿ ïîëüçîâàòåëÿ.
*
* @param int $login UID ïîëüçîâàòåëÿ êîòîðîìó ïèøåì çàìåòêó
* @param string $text Òåêñò çàìåòêè
* @return string HTML êîä
*
* êîä óäàëåíèÿ çàìåòêè
* <a href="javascript:void(0);" onclick="if(confirm(\'Âû äåéñòâèòåëüíî õîòèòå óäàëèòü çàìåòêó?\')){xajax_saveHeaderNote(\'' . $login . '\',\'\');}">
* <img src="/images/btn-remove2.png" width="11" height="11" alt="" />
* </a>
*/
function getHeaderNote( $login, $text ) {
return '
<div class="bBD" id="zametkaBD">
<div id="zametka" class="b-layout b-layout_pad_10 b-layout_bord_ffeda9 b-layout_bordrad_1 b-fon_bg_fff9bf_hover b-layout_hover">
<a class="b-icon b-icon__edit b-icon_float_right b-layout_hover_show" href="javascript:void(0);" onclick="headerNoteForm();"></a>
<div class="b-layout__txt b-layout__txt_bold b-layout__txt_padbot_10">Âàøà çàìåòêà</div>
<div class="b-layout__txt b-layout__txt_fontsize_11">' . reformat($text, 24, 0, 0, 1, 24) . '</div>
</div>
</div>
';
}
/**
* Ôóíêöèÿ âûçûâàþùàÿ ôîðìó ðåäàêòèðîâàíèÿ è äîáàâëåíèÿ çàìåòêè
*
* @param integer $uid ÈÄ ïîëüçîâàòåëÿ êîòîðîìó ïèøåì çàìåòêó
* @return object xajaxResponse; @see xajax
*/
function getNotesForm($uid, $to_uid = false, $type=1) {
session_start();
if($to_uid !== false && $_SESSION['uid'] != $uid) return false;
include_once $_SERVER['DOCUMENT_ROOT'].'/classes/notes.php';
if($to_uid !== false) {
$note = notes::GetNoteInt($uid, $to_uid, $error);
$data = array("uid" => $to_uid) + $note;
$spec_uid = $to_uid;
} else {
$data = array("uid" => $uid);
$spec_uid = $uid;
}
$objResponse = new xajaxResponse();
$data['n_text'] = html_entity_decode($data['n_text'], ENT_QUOTES);
if($type == 100) {
$objResponse->script("$('note_user').setStyle('display','block');");
$objResponse->script("$('note_userid').set('value', '{$data['uid']}');");
$objResponse->assign("notesTxt", "innerText", "".$data['n_text']);
$objResponse->script("$('note_action').set('value', '". ( $data['login']?"upd":"add" ) ."');");
} elseif ($type == 101) {
$objResponse->script("$('note_user').removeClass('b-shadow_hide');");
$objResponse->script("$('note_userid').set('value', '{$data['uid']}');");
$objResponse->assign("notesTxt", "value", $data['n_text']);
$objResponse->script("$('note_action').set('value', '". ( $data['login']?"upd":"add" ) ."');");
} else {
$objResponse->script("if($('elm-offset-{$spec_uid}-{$type}')){
$('noteFormContent').destroy();
var noteFormContent = new Element('span#noteFormContent');
$('elm-offset-{$spec_uid}-{$type}').adopt(noteFormContent);
}");
$objResponse->assign("noteFormContent", "innerHTML", notes::getNotesForm($data, $type));
$objResponse->script("$$('#ov-izbr-2').setStyle('display','block');");
$objResponse->script("
$$('.izbr-choose li a').addEvent('click', function(){
this.getParent('li').getParent('.izbr-choose').getElements('li').removeClass('active');
this.getParent('li').addClass('active');
return false;
});");
}
return $objResponse;
}
/**
* Äîáàâëåíèå, ðåäàêòèðîâàíèå çàìåòêè ïîëüçîâàòåëÿ
*
* @param integer $uid ÈÄ ïîëüçîâàòåëÿ êîòîðîìó ïèøåì çàìåòêó
* @param string $text Òåêñò çàìåòêè
* @param integer $rating Òèï çàìåòêè (1 - ïîëîæèòåëüíàÿ, 0 - íåéòðàëüíàÿ, -1 - îòðèöàòåëüíàÿ)
* @param string $act äåéñòâèå ñ çàìåòêîé (upd - îáíîâëåíèå, add - äîáàâëåíèå)
* @return object xajaxResponse; @see xajax
*/
function addNotes($uid, $text, $rating, $act, $type) {
session_start();
include_once $_SERVER['DOCUMENT_ROOT'].'/classes/notes.php';
$objResponse = new xajaxResponse();
$text = trim($text);
if($text == "") {
$objResponse->script("alert('Çàïîëíèòå çàìåòêó')");
return $objResponse;
}
// Ðåæåì òåã <script>
$text = strip_only(trim($text),'<script>');
//$text = stripslashes($text);
$text = change_q_x($text, FALSE, TRUE, "", false, false);
if(strlen($text) > 200)
$text = substr($text, 0, 200);
$note = array("n_text" => ($text));
$rec['uid'] = $uid;
ob_start();
include TPL_DIR_NOTES."/tpl.notes-textitem.php";
$html = ob_get_clean();
switch($rating) {
/*case 1:
$objResponse->script("$$('.userFav_{$uid}').getParent('div').addClass('fs-g');");
break;
case 0:
$objResponse->script("$$('.userFav_{$uid}').getParent('div').removeClass('add-z');");
break;
case -1:
$objResponse->script("$$('.userFav_{$uid}').getParent('div').addClass('fs-p');");
break;*/
default:
$rating = 0;
//$objResponse->script("$$('.userFav_{$uid}').getParent('div').addClass('fs-o');");
break;
}
if($uid>0 && strlen(trim($text)) > 0 && $act=="add") {
notes::Add($_SESSION['uid'], $uid, $text, $rating);
} else {
notes::Update($_SESSION['uid'], $uid, $text, $rating);
}
$html = str_replace("'", "\'", $html);
if($type == 100) {
$html = '<strong class="b-note__bold">Âàøà çàìåòêà :</strong> '.reformat($text, 30, 0, 0, 1, 30);
$objResponse->script("$('note_{$uid}').set('html', '$html');");
$objResponse->script("$('note_user').setStyle('display','none');");
} elseif ($type == 101) {
$html = '<strong class="b-note__bold">Âàøà çàìåòêà :</strong> '.reformat($text, 30, 0, 0, 1, 30);
$objResponse->script("$('note_{$uid}').set('html', '$html');");
$objResponse->script("$('note_user').addClass('b-shadow_hide');");
} else {
// Óäàëÿåì âñå êëàññû
$objResponse->script("$$('.userFav_{$uid}').getParent('div').removeClass('add-z').removeClass('fs-g').removeClass('fs-p');");
$objResponse->script("$$('.userFav_{$uid}').set('html', '$html');");
$objResponse->script("$('ov-izbr-2').destroy();");
}
return $objResponse;
}
function EditNote($login, $action, $text, $rating = 0) {
session_start();
$objResponse = new xajaxResponse();
$nuid = get_uid(false);
//$text = str_replace('&', '&', $text);
//$text = stripslashes($text);
$text = strip_only(trim($text),'<script>');
$text = change_q_x($text, FALSE, TRUE, "", false, false);
// !! êîë-âî ñèìâîëîâ òàêæå óêàçàíî â /scripts/note.js
if(strlen($text) > 200)
$text = substr($text, 0, 200);
switch ($action) {
case "add":
if ($text)
$error = notes::Add($nuid, $login, $text, 0, "?");
break;
case "update":
if ($text) {
$error = notes::Update($nuid, $login, $text, $rating, "?");
} else {
$error = notes::DeleteNote($nuid, $login, "?");
$action = 'delete';
}
break;
}
if ($error) return false;
$text_src = input_ref_scr(stripslashes($text));
$text_src = str_replace('&', '&', $text_src);
$text = reformat($text, 54, 0, 0, 1, 54);
//$text = addslashes($text);
switch ($action) {
case 'add':
case 'update':
if(is_empty_html($text)) {
$s = "
document.getElement('div.form-templ').setStyle('display', 'none');
document.getElement('div.form-templ input').set('disabled', false);
cancelNote();
";
break;
}
$s = "
n = $('note_{$login}');
n.getElement('.uprj-note-cnt>p').set('html', '$text');
n.setStyle('display', 'block');
document.getElement('div.form-templ').setStyle('display', 'none');
document.getElement('div.form-templ input').set('disabled', false);
if($('team_{$login}')) $('team_{$login}').getElement('.uprj-st3').setStyle('display', 'none');
cancelNote();
";
break;
case 'delete':
$s = "
n = $('note_{$login}');
n.getElement('.uprj-note-cnt>p').set('html', '');
n.setStyle('display', 'none');
if($('team_{$login}')) $('team_{$login}').getElement('.uprj-st3').setStyle('display', 'inline-block');
document.getElement('div.uprj-note.form-templ').store('action', false);
cancelNote();
";
break;
}
$objResponse->script($s);
return $objResponse;
}
/**
* Óäàëåíèå çàìåòêè ïîëüçîâàòåëÿ
*
* @param integer $uid ÈÄ ïîëüçîâàòåëÿ âëàäåëüöà çàìåòêè
* @param inetger $to_uid ÈÄ ïîëüçîâàòåëÿ íà êîãî íàïèñàíà çàìåòêà
* @return object xajaxResponse; @see xajax
*/
function delNote($uid, $to_uid, $type) {
session_start();
if($_SESSION['uid'] != $uid) return false;
include_once $_SERVER['DOCUMENT_ROOT'].'/classes/notes.php';
$objResponse = new xajaxResponse();
notes::DeleteNote($uid, $to_uid);
if($type == 100) {
$objResponse->script("$$('.userFav_{$to_uid}').destroy();");
} else {
$html = '<div class="sent-mark"><a href="javascript:void(0)" onclick="xajax_getNotesForm('.$to_uid.', false, '.$type.')">Îñòàâèòü çàìåòêó</a> <span></span></div>';
// $objResponse->script("$$('.userFav_{$to_uid}').getParent('div').removeClass('fs-g').removeClass('fs-p').addClass('add-z');");
// $objResponse->script("$$('.userFav_{$to_uid}').getParent('div').removeClass('fs-o').addClass('add-z');");
$objResponse->script("$$('.userFav_{$to_uid}').set('html', '$html');");
}
//$objResponse->script("$('ov-izbr-2').destroy();"); // Åñëè óäàëÿåì ñ ôîðìû
return $objResponse;
}
function GetNote($login) {
session_start();
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/users.php");
$oUser = new users;
$nTargetId = $oUser->GetUid( $sError, $login );
$objResponse = new xajaxResponse();
$nuid = get_uid(false);
$note = notes::GetNoteInt($nuid, $nTargetId, $err);
$text = htmlspecialchars_decode($note['n_text']);
$text = str_replace("'", "'", $text);
$s = "
$('note_rating').set('value', '{$note['rating']}');
f = document.getElement('div.uprj-note.form-templ');
f.getElements('input,textarea').set('disabled', false);
";
$objResponse->script($s);
$objResponse->assign('f_n_text', 'value', $text);
return $objResponse;
}
$xajax->processRequest();
?>