';
$this->displaySentMessages();
echo '';
// obrazec za posiljanje sporocil
$this->sendMessageForm();
}
else
echo $lang['srv_notifications_admin_alert'];
}
// Prikazemo prejeta sporocila
else{
echo '
';
$this->displayRecievedMessages();
echo '
';
echo '';
}
echo '';
}
private function displayRecievedMessages($active=0){
global $admin_type, $global_user_id, $lang;
echo ''.$lang['srv_notifications_recieved'].':';
// Napolnimo array prejetih sporocil
$recievedMessages = array();
$sql = sisplet_query("SELECT n.id AS id, n.recipient AS recipient, n.viewed AS viewed, m.id AS message_id, m.date AS date, m.title AS title, m.text AS text
FROM srv_notifications n, srv_notifications_messages m
WHERE n.recipient='".$global_user_id."' AND n.message_id=m.id
ORDER BY m.date DESC");
while($row = mysqli_fetch_array($sql)){
$recievedMessages[$row['id']] = $row;
}
echo '';
}
private function displaySentMessages(){
global $admin_type, $global_user_id, $lang;
echo ''.$lang['srv_notifications_sent'].':';
// Napolnimo array poslanih sporocil
$sentMessages = array();
$sql = sisplet_query("SELECT * FROM srv_notifications_messages WHERE author='".$global_user_id."' ORDER BY date DESC");
while($row = mysqli_fetch_array($sql)){
$sentMessages[$row['id']] = $row;
}
echo '';
if(count($sentMessages) > 0){
foreach($sentMessages as $message_id => $message){
//echo '- ';
echo '
- ';
echo ''.$message['title'].' ('.$message['date'].')';
$text = strip_tags((strlen($message['text']) > 70) ? substr($message['text'], 0, 70).'...' : $message['text']);
echo '
'.$text;
// Gumb da se sporocilo razresi vsem (kot da so ga pregledali)
$sqlN = sisplet_query("SELECT message_id FROM srv_notifications WHERE message_id='".$message_id."' AND viewed='0'");
$count = mysqli_num_rows($sqlN);
if($count > 0){
echo '
';
echo ''.$lang['srv_notifications_sent_resolve'].' ('.$count.')'.'';
}
echo ' ';
}
}
echo '
';
}
// Obrazec za posiljanje sporocila
private function sendMessageForm($note=''){
global $admin_type, $global_user_id, $lang;
echo '';
}
// Vrnemo stevilo sporocil
public function countMessages($type='unread'){
global $global_user_id;
$count = 0;
switch($type){
case 'recieved':
$sql = sisplet_query("SELECT COUNT(*) AS count FROM srv_notifications WHERE recipient='$global_user_id' AND viewed='1'");
break;
case 'sent':
$sql = sisplet_query("SELECT COUNT(n.*) AS count FROM srv_notifications n, srv_notifications_messages m WHERE m.author='$global_user_id' AND m.id=n.message_id");
break;
case 'unread':
default:
$sql = sisplet_query("SELECT COUNT(*) AS count FROM srv_notifications WHERE recipient='$global_user_id' AND viewed='0'");
break;
}
if(mysqli_num_rows($sql) > 0){
$row = mysqli_fetch_array($sql);
$count = $row['count'];
}
return $count;
}
// Preveri ce avtomatsko prikaze sporocilo po prijavi
public function checkForceShow(){
global $global_user_id;
$sql = sisplet_query("SELECT m.force_show FROM srv_notifications n, srv_notifications_messages m WHERE n.message_id=m.id AND n.recipient='$global_user_id' AND n.viewed='0' AND m.force_show='1'");
if(mysqli_num_rows($sql) > 0)
return true;
else
return false;
}
public function ajax() {
global $global_user_id;
switch ($_GET['a']) {
case 'sendNotification':
$this->ajax_sendNotification();
break;
case 'viewMessage':
$this->ajax_viewMessage();
break;
case 'viewUnreadMessages':
$this->ajax_viewUnreadMessages();
break;
case 'viewGDPRMessage':
$this->ajax_viewGDPRMessage();
break;
case 'saveGDPRAgree':
$this->ajax_saveGDPRAgree();
break;
case 'resolveMessages':
$this->ajax_resolveMessages();
break;
default:
break;
}
}
public function ajax_sendNotification(){
global $lang, $global_user_id;
if(isset($_POST['recipient']))
$recipient = $_POST['recipient'];
if(isset($_POST['recipient_all_slo']))
$recipient_all_slo = $_POST['recipient_all_slo'];
if(isset($_POST['recipient_all_ang']))
$recipient_all_ang = $_POST['recipient_all_ang'];
if(isset($_POST['title']))
$title = $_POST['title'];
if(isset($_POST['notification']))
$notification = $_POST['notification'];
if(isset($_POST['force_show']))
$force_show = $_POST['force_show'];
// Ce posiljamo vsem uporabnikom nimamo maila
if($recipient_all_slo == 1 || $recipient_all_ang == 1){
// Dodamo novo sporocilo v bazo
$sql = sisplet_query("INSERT INTO srv_notifications_messages (author, date, title, text, force_show) VALUES ('".$global_user_id."', NOW(), '".$title."', '".$notification."', '".$force_show."')");
$message_id = mysqli_insert_id($GLOBALS['connect_db']);
$note = '';
// Loop cez vse uporabnike v bazi - vsakemu dodamo sporocilo
if($recipient_all_slo == 1 && $recipient_all_ang == 1)
$sqlU = sisplet_query("SELECT id, name, surname, email FROM users WHERE status!='0' AND status!='5' AND status!='6'");
elseif($recipient_all_ang == 1)
$sqlU = sisplet_query("SELECT id, name, surname, email FROM users WHERE status!='0' AND status!='5' AND status!='6' AND lang='2'");
else
$sqlU = sisplet_query("SELECT id, name, surname, email FROM users WHERE status!='0' AND status!='5' AND status!='6' AND lang='1'");
while($rowU = mysqli_fetch_array($sqlU)){
$sql = sisplet_query("INSERT INTO srv_notifications (message_id, recipient, viewed) VALUES ('".$message_id."', '".$rowU['id']."', '0')");
if(!$sql)
$note .= mysqli_error($GLOBALS['connect_db']).'
';
}
}
// Posiljamo na specificen mail
else{
// Dobimo user id glede na vnesen mail prejemnika
$sqlU = sisplet_query("SELECT id, name, surname, email FROM users WHERE email='$recipient'");
if(mysqli_num_rows($sqlU) > 0){
$rowU = mysqli_fetch_array($sqlU);
// Dodamo novo sporocilo v bazo
$sql = sisplet_query("INSERT INTO srv_notifications_messages (author, date, title, text, force_show) VALUES ('".$global_user_id."', NOW(), '".$title."', '".$notification."', '".$force_show."')");
$message_id = mysqli_insert_id($GLOBALS['connect_db']);
// Dodamo novo sporocilo v bazo
$sql = sisplet_query("INSERT INTO srv_notifications (message_id, recipient, viewed) VALUES ('".$message_id."', '".$rowU['id']."', '0')");
if(!$sql)
$note = mysqli_error($GLOBALS['connect_db']);
else
$note = 'Sporočilo je bilo uspešno poslano uporabniku '.$recipient.' ('.$rowU['name'].' '.$rowU['surname'].').';
}
else{
$note = 'Vnešeni email ('.$recipient.') ne pripada nobenemu uporabniku!';
}
}
// Refresh vseh poslanih sporocil
echo '';
$this->displaySentMessages();
echo '
';
// Refresh obrazca za posiljanje sporocil
$this->sendMessageForm($note);
echo '';
}
public function ajax_resolveMessages(){
if(isset($_POST['id']))
$message_id = $_POST['id'];
// Oznacimo sporocila kot pregledana
$sql = sisplet_query("UPDATE srv_notifications SET viewed='1' WHERE message_id='$message_id'");
$this->displaySentMessages();
}
public function ajax_viewMessage(){
global $lang, $global_user_id;
if(isset($_POST['id']))
$id = $_POST['id'];
// Oznacimo sporocilo kot pregledano
$sql = sisplet_query("UPDATE srv_notifications SET viewed='1' WHERE id='$id'");
// Dobimo sporocilo
$sql = sisplet_query("SELECT n.id AS id, m.title AS title, m.text AS text, m.date AS date
FROM srv_notifications n, srv_notifications_messages m
WHERE n.id='$id' AND m.id=n.message_id");
$row = mysqli_fetch_array($sql);
// Refresh vseh prejetih sporocil
echo '';
$this->displayRecievedMessages($active=$id);
echo '
';
// Prikaz izbranega sporocila
echo '';
echo '
'.$row['title'].' ('.$row['date'].')';
echo '
'.nl2br($row['text']).'
';
echo '
';
echo '';
}
public function ajax_viewUnreadMessages(){
global $lang, $global_user_id;
echo ''.$lang['srv_notifications_unread'].'
';
echo '';
// Loop cez vsa neprebrana sporocila
$sql = sisplet_query("SELECT n.id AS id, m.title AS title, m.text AS text, m.date AS date, n.viewed AS viewed
FROM srv_notifications n, srv_notifications_messages m
WHERE n.recipient='".$global_user_id."' AND n.viewed='0' AND m.id=n.message_id
ORDER BY m.date DESC");
while($row = mysqli_fetch_array($sql)){
echo '- ';
echo ''.$row['title'].' ('.$row['date'].')';
echo '
'.nl2br($row['text']);
echo ' ';
}
echo '
';
// Gumb za zapiranje
echo '';
// Oznacimo sporocilo kot pregledano
$sql = sisplet_query("UPDATE srv_notifications SET viewed='1' WHERE recipient='".$global_user_id."' AND viewed='0'");
}
public function ajax_viewGDPRMessage(){
global $lang, $global_user_id, $aai_instalacija;
echo ''.$lang['srv_notifications_unread'].'
';
echo '';
echo '- ';
if(isset($aai_instalacija) && $aai_instalacija == true){
echo ''.$lang['srv_gdpr_notification_title_aai'].'';
}
else{
echo ''.$lang['srv_gdpr_notification_title'].'';
}
echo '
';
echo $lang['srv_gdpr_notification_text1'];
echo '
';
echo $lang['srv_gdpr_notification_question'];
echo '
';
echo '';
//echo ' '.$lang['srv_invitation_nonActivated_more'].'';
echo '';
echo '';
echo '
';
echo $lang['srv_gdpr_notification_pogoji'];
echo ' ';
echo '
';
// Gumb za zapiranje
//echo '