SphereCommunity
News and PM System - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Submissions (/Forum-Script-Submissions)
+--- Thread: News and PM System (/Thread-News-and-PM-System)



News and PM System - admin phoenix - 08-13-2014 10:46 PM

PHP Code:
// ***************************************************************************​***************************************************
// *                            News and PM System                            *
// * created by Admin Phoenix aka Levanthis from http://www.uo-tools.com                            *
// *                                                                *
// * Feature:                                                            *
// * Sending Messages to all Players which are Online or Offline                                *
// * The Messages will be saved in the data base                                        *
// * The Messages will be listed in the main display / gump with the subject text                        *
// * You got the Button Read and Delete in the Main Display Gump                                *
// * The Message will be displayed as read and unread                                        *
// * When the player Login and he has a new message a little gump will be open and show him, that he has a new message        *
// * System Message when a player got a new message                                        * 
// * New Message will have a prefix "new" in the gump since the player read it                            *
// * If you have no new message thegump will show it as a text in the gump                            *
// * You can sort your message by all, GM or System Message                                    *
// *                                                                *
// * ATTENTION:                                                            *
// * YOU HAVE TO DECLARE YOUR OWN GUMP PICS AND TOOLTIP UNDER [DEFNAME nachrichten_buttons]                    *
// *
// * Table for your SQL needed:
// * Table Name: nachrichten 
// * Rows: Username, UID, Titel, Betreff, Absender, Datum, Gelesen, Neu
// ***************************************************************************​***************************************************



// ***************************************************************************​*******************************************************************
// *                             Script command for Systemmessage                            *
// * Example:                                                                    *
// * ON=@LOGIN                                                                    *
// * got_message_systemsend <account.name>,<uid>,1,SERVER UPDATE. <def0.br>Check the Homepage for the Revision                    *
// *                                                                        *
// ***************************************************************************​*******************************************************************


[FUNCTION got_message_systemsend]
local.username=<argv[0]>
local.uid=<argv[1]>
local.absender=<argv[2]>
local.titel=<argv[3]>
local.betreff=<argv[4]>
local.datum=<SERV.rtime.format %d>.<SERV.rtime.format %m>.<SERV.rtime.format %Y>, <SERV.rtime.format %H>:<SERV.rtime.format %M>
local.gelesen=1
local
.neu=1
DB
.EXECUTE INSERT INTO nachrichten (UsernameUIDTitelBetreffAbsenderDatumGelesenNeuVALUES ('<local.username>','<local.uid>','<local.titel>','<local.betreff>','<dlocal.absender>','<local.datum>','<dlocal.gelesen>','<dlocal.neu>');



// ***************************************************************************​***************************************************
// *                             GM command                                *
// ***************************************************************************​***************************************************

[PLEVEL 2]
nachricht


[FUNCTION nachricht]
    
smsg @<def.def_smsg_info>,3 Which Player you want to leave a message?
    
targetf f_nachrichten_text

[FUNCTION f_nachrichten_text]
    
ref1=<argo.uid>
 IF (<
ref1> == <uid>)
    
src.smsg @<def.def_smsg_sys>,3 You can not send a PM to youself!
  ELSE
    
ctag0.message_uid=<ref1.uid>
    
sdialog d_nachrichten_verschicken
 
ENDIF

[
DIALOG d_nachrichten_verschicken]
100,100
//NOCLOSE

page 0
ref1
=<ctag0.message_uid>
resizepic 0 0 2620 555 570
CHECKERTRANS 0 0 555 571
dtext 20 14 1152 
<serv.nameStaff Message

resizepic 55 35 3000 280 25
dtext 20 37 1152 To
:
dtext 60 37 1152 Account: <ref1.account.name> / Playerchar: <ref1.name>

dtext 20 62 1152 Title:
resizepic 55 65 3000 480 25
dtextentry 60 67 470 20 1152 0

dtext 20 110 1152 Subject
:
resizepic 20 130 3000 520 400
dtextentry 25 137 510 390 390 1


button 30 535 4029 4030 1 0 1
button 290 535 4020 4021 1 0 2
dtext 65 536 1152 Send
dtext 219 536 1152 Close

[DIALOG d_nachrichten_verschicken BUTTON]
ON=0
smsg 
@<def.def_smsg_sys>,3 Canceled

ON
=1
IF (<DB.CONNECTED>)
    
ref1=<ctag0.message_uid>
    
local.titel=<argtxt[0]>
    
local.betreff=<argtxt[1]>
    
local.datum=<SERV.rtime.format %d>.<SERV.rtime.format %m>.<SERV.rtime.format %Y>, <SERV.rtime.format %H>:<SERV.rtime.format %M>
    
local.gelesen=1
    local
.neu=1
    DB
.EXECUTE INSERT INTO nachrichten (UsernameUIDTitelBetreffAbsenderDatumGelesenNeuVALUES ('<ref1.account.name>','<ref1.uid>','<local.titel>','<local.betreff>','<UID>','<local.datum>','<dlocal.gelesen>','<dlocal.neu>');
    
smsg @<def.def_smsg_info>,3 Message send to <ref1.name>.
    
    IF (<
ref1.isonline>)
        IF (<
ref1.tag0.nachrichten>)
            
ref1.dialog d_nachrichten_anzeigen
        
ELSE
            
ref1.smsg @<def.def_smsg_info>,3 You got a new Message.
        ENDIF
        
ref1.sound=05b4
    
ENDIF
    
    
ELSE
    
smsg @<def.def_smsg_info>,3 No connection to Data BasePlease try it again later!
ENDIF

ON=2
smsg 
@<def.def_smsg_sys>,3 Canceled


[DEFNAME nachrichten_buttons]
lesen_button_1            0482
lesen_button_2            0483
loeschen_button_1        047f
loeschen_button_2        0480
forward_1            094
forward_2            095
backward_1            096
backward_2            097
got_message            0d9
        
tooltip_loeschen        3000154
tooltip_antworten        3000162
tooltip_lesen            601205
tooltip_abbrechen        3000124
tooltip_zurueck            1001011
        
[FUNCTION got_message]
IF (<
DB.CONNECTED>)
    
DB.QUERY "SELECT * FROM nachrichten WHERE username='<account.name>' AND UID='<uid>'";
    IF (<
DB.ROW.NUMROWS> > 0)
        FOR 
x 0 <eval <DB.ROW.NUMROWS>-1>
            
local.neu=<db.row.<dlocal.x>.Neu>
            IF (<
dlocal.neu> == 1)
                
local.aufgehen +=1
            
ENDIF
        ENDFOR
        IF (<
dlocal.aufgehen> >= 1)
            
smsg @<def.def_smsg_info>,3 You have <dlocal.aufgehen> new Messages.
            
sdialog d_got_message
        
ENDIF
    ENDIF
ENDIF

[
DIALOG d_got_message]
0,0

page 0

page 1
button 0 0 
<hval <def0.got_message>> <hval <def0.got_message>> 1 0 1

[DIALOG d_got_message BUTTON]
ON=0
    smsg 
@<def.def_smsg_info>,3 You closed the Message Gump.

ON=1
    nachrichten


// ***************************************************************************​***************************************************
// *                             Player command                                *
// ***************************************************************************​***************************************************

[PLEVEL 1]
nachrichten

[FUNCTION nachrichten]
    
ctag0.page=1
    sdialog d_nachrichten_anzeigen

[DIALOG d_nachrichten_anzeigen]
200,200
//NOCLOSE
page 0
resizepic 0 0 2620 555 600
CHECKERTRANS 0 0 555 601
resizepic 19 14 3000 520 25
dhtmlgump 170 17 320 20 0 0 
<def.BFONT_SIZE7> <def.Bfont_black><serv.nameNews and Message Gump vers1.0

button 20 40 
<hval 01ee> <hval 01ee1 0 7
dtext 37 40 455 All
button 90 40 
<hval 01ee> <hval 01ee1 0 8
dtext 110 40 455 GM
button 160 40 
<hval 01ee> <hval 01ee1 0 9
dtext 167 40 455 System

page 1
IF (<DB.CONNECTED>)
    IF !(<
ctag0.nachrichten_id>)
     IF (<
dctag0.show_page_from> == 1)
         
DB.QUERY "SELECT * FROM nachrichten WHERE username='<account.name>' AND UID='<uid>' AND Absender !='1'";      
      ELSEIF (<
dctag0.show_page_from> == 2)
        
DB.QUERY "SELECT * FROM nachrichten WHERE username='<account.name>' AND UID='<uid>' AND Absender='1'";      
      ELSE
        
DB.QUERY "SELECT * FROM nachrichten WHERE username='<account.name>' AND UID='<uid>'";
     ENDIF
     
        IF (<
DB.ROW.NUMROWS> > 0)
            
local.messages_count=<DB.ROW.NUMROWS>
            
local.page_max=<eval <local.messages_count>/5>
            
local.page_max +=1
            
            
IF (<dlocal.messages_count> > 5)
                IF (<
dctag0.page> == 1)
                    
local.messages_min=0
                    local
.messages_max=5
                
ELSE
                    
                    IF (<
dctag0.page> != <dlocal.page_max>)
                        
local.messages_max=<eval <ctag0.page>*5>
                        
local.messages_min=<eval <ctag0.page>*5>
                        
local.messages_min -=4
                    
ELSE
                        
local.messages_min=<eval <ctag0.page>*5>
                        
local.messages_min -=4
                        local
.messages_max=<eval <local.messages_count>-1>
                    ENDIF
                    
                ENDIF
                
                
            ELSE
                
local.messages_min=0
                local
.messages_max=<eval <local.messages_count>-1>
            ENDIF
            
            FOR 
<dlocal.messages_min> <dlocal.messages_max>
                
local.titel=<db.row.<dlocal.x>.Titel>
                
local.absender=<db.row.<dlocal.x>.Absender>
                IF (<
dlocal.absender> == 1)
                    
local.absender="System Message"
                
ELSE
                    
local.absender=<uid.<local.absender>.name>
                ENDIF
                
local.datum=<db.row.<dlocal.x>.Datum>
                
local.id=<db.row.<dlocal.x>._ID>
                
local.gelesen=<db.row.<dlocal.x>.Gelesen>
                
local.neu=<db.row.<dlocal.x>.Neu>
                
                IF (<
dlocal.gelesen> == 1)
                    IF (<
dlocal.neu> == 1)
                        
dhtmlgump 10 <eval 80+<local.y>> 450 65 025 1 <def.BFONT_SIZE7><def.BFONT_CYAN>New <def.Bfont_black><eval <dlocal.x>+1Message from: <def.BFONT_RED><local.absender> <def0.br><def.Bfont_black>at: <def.BFONT_RED><local.datum> <def0.br><def.Bfont_black>Title: <def.BFONT_RED><local.titel>
                        
local.neu=0
                        DB
.EXECUTE "UPDATE nachrichten SET Neu='<dlocal.neu>' WHERE _ID='<dlocal.id>';"
                    
ELSE
                        
dhtmlgump 10 <eval 80+<local.y>> 450 65 025 1 <def.BFONT_SIZE7><def.Bfont_black> <eval <dlocal.x>+1Message from: <def.BFONT_RED><local.absender> <def0.br><def.Bfont_black>at: <def.BFONT_RED><local.datum> <def0.br><def.Bfont_black>Title: <def.BFONT_RED><local.titel>
                    ENDIF
                ELSE
                    
dhtmlgump 10 <eval 80+<local.y>> 450 65 025 1 <def.BFONT_SIZE7><def.Bfont_black> <eval <dlocal.x>+1Message from: <def.BFONT_white><local.absender> <def0.br><def.Bfont_black>at: <def.BFONT_white><local.datum> <def0.br><def.Bfont_black>Title: <def.BFONT_white><local.titel>
                ENDIF
                
button 470 <eval 100+<local.y>> <hval <def0.lesen_button_1>> <hval <def0.lesen_button_2>> 1 0 <eval <dlocal.id>+500000// Read
                
tooltip <ddef0.tooltip_lesen>
                
button 510 <eval 100+<local.y>> <hval <def0.loeschen_button_1>> <hval <def0.loeschen_button_2>> 1 0 <eval <local.id>+10// Delete
                
tooltip <ddef0.tooltip_loeschen>
                
local.+=80
                
            
ENDFOR
            
dhtmlgump 230 560 320 20 0 0 <def.BFONT_white><dctag0.page>/<dlocal.page_maxPages
            
            
IF (<dctag0.page> != <dlocal.page_max>)
                IF (<
dlocal.messages_count> >= 6)
                    
button 450 560 <hval <def0.forward_1>> <hval <def0.forward_2>> 1 0 2
                
ENDIF
            ENDIF
            IF (<
local.messages_min> >= 5)
                
button 50 560 <hval <def0.backward_1>> <hval <def0.backward_2>> 1 0 3
            
ENDIF
            
        ELSE
            
dhtmlgump 10 <eval 80+<local.y>> 450 65 025 1 <def.BFONT_SIZE7><def.Bfont_blackNo new Messages
        
ENDIF
        
    ELSE
        
DB.QUERY "SELECT * FROM nachrichten WHERE _ID='<dctag0.nachrichten_id>' AND UID='<uid>'";
        
local.titel=<db.row.<dlocal.x>.Titel>
        
local.betreff=<db.row.<dlocal.x>.Betreff>
        
local.absender=<db.row.<dlocal.x>.Absender>
        IF (<
dlocal.absender> == 1)
            
local.absender="System Message"
        
ELSE
            
local.absender=<uid.<local.absender>.name>
        ENDIF
        
local.datum=<db.row.<dlocal.x>.Datum>
        
dhtmlgump 10 40 530 470 025 1 <def.BFONT_SIZE7><def.Bfont_black>Message from: <def.BFONT_white><local.absender> <def0.br><def.Bfont_black>at: <def.BFONT_white><local.datum> <def0.br><def.Bfont_black>Title: <def.BFONT_white><local.titel><def0.br><def.Bfont_black>Subject: <def.BFONT_white><local.betreff>
        
button 470 530 <hval <def0.lesen_button_1>> <hval <def0.lesen_button_2>> 1 0 1 // Back
        
tooltip <ddef0.tooltip_zurueck>
        
button 510 530 <hval <def0.loeschen_button_1>> <hval <def0.loeschen_button_2>> 1 0 <eval <ctag0.nachrichten_id>+10// Delete
        
tooltip <ddef0.tooltip_loeschen>
        
    ENDIF
    
ELSE
    
smsg @<def.def_smsg_info>,3 No connection to Data BasePlease try it again later!
ENDIF



[
DIALOG d_nachrichten_anzeigen BUTTON]
ON=0
    ctag0
.nachrichten_id
    ctag0
.page=

ON=1
    ctag0
.nachrichten_id
    sdialog d_nachrichten_anzeigen

ON
=2
    ctag0
.page +=1
    sdialog d_nachrichten_anzeigen

ON
=3
    ctag0
.page -=1
    sdialog d_nachrichten_anzeigen

ON
=// Alle

ON=// GM

ON=// System

ON=// Alle
    
ctag0.show_page_from=0
    smsg 
@<def.def_smsg_info>,3 All Messages are shown.
    
sdialog d_nachrichten_anzeigen

ON
=// GM
    
ctag0.show_page_from=1
    smsg 
@<def.def_smsg_info>,3 Only GM Messages are shown.
    
sdialog d_nachrichten_anzeigen

ON
=// System
    
ctag0.show_page_from=2
    smsg 
@<def.def_smsg_info>,3 Only System Message are shown.
    
sdialog d_nachrichten_anzeigen

ON
=10 499999
say 
<dargn1>
IF (<
DB.CONNECTED>)
    
local.id=<dargn1>
    
smsg @<def.def_smsg_info>,3 You delete the Messages.
    
DB.EXECUTE "DELETE FROM nachrichten WHERE _ID='<eval <local.id>-10>'"
    
ctag0.nachrichten_id
ELSE
    
smsg @<def.def_smsg_info>,3 No connection to Data BasePlease try it again later!
ENDIF
sdialog d_nachrichten_anzeigen

ON
=500000 1000000

IF (<DB.CONNECTED>)
    
ctag0.nachrichten_id=<dargn1>
    
ctag0.nachrichten_id -= 500000
    DB
.QUERY "UPDATE nachrichten SET Gelesen='0' WHERE _ID='<dctag0.nachrichten_id>';"
ELSE
    
smsg @<def.def_smsg_info>,3 No connection to Data BasePlease try it again later!
ENDIF
sdialog d_nachrichten_anzeigen

[EOF