Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / admin / functions_tool_notes.php
blob87c590df797f4e20e8ea2004b92bc873794a9672
1 <?php
3 function js_html_entity_decode($string)
5 // replace numeric entities
6 $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
7 $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
8 // replace literal entities
9 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
10 $trans_tbl = array_flip($trans_tbl);
11 return strtr($string, $trans_tbl);
14 function tool_notes_get_list($user_id, $active=null)
16 global $db;
18 $data = array();
20 if ($active === null) // edit note list
21 $sql = "SELECT * FROM ". NELDB_NOTE_TABLE ." WHERE note_user_id=". $user_id ." ORDER BY note_active DESC, note_date DESC";
22 else // view note list
23 $sql = "SELECT * FROM ". NELDB_NOTE_TABLE ." WHERE (note_user_id=". $user_id ." OR note_global=1) AND note_active='". $active ."' ORDER BY note_global DESC, note_title ASC";
25 if ($result = $db->sql_query($sql))
27 if ($db->sql_numrows($result))
29 while ($row = $db->sql_fetchrow($result))
31 if ($active)
33 $row['note_data'] = addslashes(htmlentities(html_entity_decode(str_replace("\r\n","<br>",$row['note_data']), ENT_QUOTES), ENT_COMPAT));
34 $row['note_title2'] = addslashes(htmlentities(html_entity_decode($row['note_title'], ENT_QUOTES), ENT_COMPAT));
36 $data[] = $row;
42 return $data;
45 function tool_notes_add($user_id, $note_title, $note_data, $note_active, $note_global, $note_mode, $note_uri, $note_restriction)
47 global $db;
49 $note_title = trim(stripslashes($note_title));
50 $note_data = trim(stripslashes($note_data));
52 if ($note_title == '') return "/!\ Error: note title is empty!";
53 //if ($note_data == '') return "/!\ Error: note data is empty!";
55 if ($note_mode == 'text') $note_mode = 0;
56 else $note_mode = 1;
58 $sql = "INSERT INTO ". NELDB_NOTE_TABLE ." (`note_user_id`,`note_title`,`note_data`,`note_date`,`note_active`,`note_global`,`note_mode`,`note_popup_uri`,`note_popup_restriction`) VALUES ";
59 $sql .= " ('". $user_id ."','". htmlentities($note_title, ENT_QUOTES) ."','". htmlentities($note_data, ENT_QUOTES) ."','". time() ."',". $note_active .",". $note_global .",". $note_mode .",'". $note_uri ."','". $note_restriction ."')";
61 $db->sql_query($sql);
63 return "";
66 function tool_notes_get_id($user_id, $note_id)
68 global $db;
70 $data = array();
72 $sql = "SELECT * FROM ". NELDB_NOTE_TABLE ." WHERE note_id=". $note_id ." AND note_user_id=". $user_id;
73 if ($result = $db->sql_query($sql))
75 if ($db->sql_numrows($result))
77 $data = $db->sql_fetchrow($result);
78 $data['note_title'] = $data['note_title'];
79 $data['note_data'] = $data['note_data'];
83 return $data;
86 function tool_notes_del($user_id, $note_id)
88 global $db;
90 $sql = "DELETE FROM ". NELDB_NOTE_TABLE ." WHERE note_id=". $note_id ." AND note_user_id=". $user_id;
91 $db->sql_query($sql);
94 function tool_notes_update($user_id, $note_id, $note_title, $note_data, $note_active, $note_global, $note_mode, $note_uri, $note_restriction)
96 global $db;
98 if ($note_mode == 'text') $note_mode = 0;
99 else $note_mode = 1;
101 $sql = "SELECT * FROM ". NELDB_NOTE_TABLE ." WHERE note_id=". $note_id ." AND note_user_id=". $user_id;
102 if ($result = $db->sql_query($sql))
104 if ($db->sql_numrows($result))
106 // $sql = "UPDATE ". NELDB_NOTE_TABLE ." SET note_title='". htmlentities($note_title, ENT_QUOTES) ."',note_data='". htmlentities($note_data, ENT_QUOTES) ."',note_date='". time() ."',note_active='". $note_active ."',note_global='". $note_global ."',note_mode=". $note_mode .",note_popup_uri='". $note_uri ."',note_popup_restriction='". $note_restriction ."' WHERE note_id=". $note_id;
107 $sql = "UPDATE ". NELDB_NOTE_TABLE ." SET note_title='". htmlentities($note_title, ENT_QUOTES) ."',note_data='". htmlentities($note_data, ENT_QUOTES) ."',note_date='". time() ."',note_active='". $note_active ."',note_global='". $note_global ."' WHERE note_id=". $note_id;
108 $db->sql_query($sql);
110 else
112 return "/!\ Error: no such note for this user!";
116 return "";