Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?lc
  2.     function connect_to_db
  3.         put revOpenDatabase("mysql","localhost","lc137543_playlanddb","lc137543_aram","playland1234") into t_id
  4.        
  5.         if t_id is a number then
  6.             return t_id
  7.         else
  8.             return -1
  9.         end if
  10.     end connect_to_db
  11.  
  12.     put connect_to_db() into t_conn_id
  13.    
  14.     if t_conn_id<0 then
  15.         put "error: connecting to database."
  16.     else
  17.         put $_GET["userid"] into t_uid
  18.         put $_GET["action"] into t_action
  19.         put $_GET["value"] into t_val
  20.        
  21.         if t_uid is empty then
  22.             put "error: you must set userid."
  23.         else       
  24.             switch (t_action)
  25.                 -- user logged in
  26.                 case "login"
  27.                     -- add user to db, with action "online" and value NULL
  28.                     -- put "insert into actions values("&(t_uid)&",'online','NULL') on dublicate update key userid=userid" into t_query
  29.                     --put "if not exists(select userid from actions where userid="&t_uid&") insert into actions values("&(t_uid)&",'online','NULL')" into t_query
  30.                     put "select userid from actions where userid="&t_uid into t_query
  31.                     put revDataFromQuery("|",return,t_conn_id,t_query) into t_ret
  32.                     if t_ret is empty then
  33.                         put "insert into actions(userid,username,action,value) values("&(t_uid)&","&(t_val)&",'online','NULL')" into t_query
  34.                     end if
  35.                     revExecuteSQL t_conn_id,t_query
  36.                     break
  37.                    
  38.                 -- user logged out
  39.                 case "logout"
  40.                     -- remove user from db
  41.                     put "delete from actions where userid="&(t_uid) into t_query
  42.                     revExecuteSQL t_conn_id,t_query
  43.                     break
  44.                 case "chat"
  45.                     -- check if the user is logged in
  46.                     put "select userid from actions where userid="&t_uid into t_query
  47.                     put revDataFromQuery("|",return,t_conn_id,t_query) into t_ret
  48.                     if t_ret is empty then
  49.                         put "error: you must be logged in."
  50.                     else
  51.                         -- set the action of the user to chat and set the value to the message
  52.                         put "update actions set action='chat',value='"&t_val&"' where userid="&t_uid into t_query
  53.                         revExecuteSQL t_conn_id,t_query
  54.                     end if
  55.                     break
  56.                 case "status"
  57.                     -- return statuses for all the users
  58.                     --
  59.                     break
  60.                 default
  61.                     put "error: unknown action."
  62.                     break
  63.             end switch
  64.         end if
  65.     end if
  66.    
  67.     -- sending back status after each request
  68.     put "select * from actions" into t_query
  69.     put revDataFromQuery("|",return,t_conn_id,t_query)
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement