User class moved into new file and added all methods needed to run stream
[brisk.git] / web / index_rd_ifra.php
index 2f2d393..e246dd8 100644 (file)
@@ -130,6 +130,7 @@ function blocking_error($is_unrecoverable)
   return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
 }
 
+// FIXME TO SUPPORT iframe
 function page_sync($sess, $page, $table_idx, $table_token)
 {
   GLOBAL $is_page_streaming;
@@ -145,21 +146,21 @@ function page_sync($sess, $page, $table_idx, $table_token)
 
 
 
-function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
+function maincheck(&$user, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate)
 {
     GLOBAL $G_lang, $mlang_indrd, $is_page_streaming;
     // GLOBAL $first_loop;
     GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
     GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
     $CO_splashdate = "CO_splashdate".$G_splash_idx;
-    GLOBAL $$CO_splashdate;
+    $$CO_splashdate = $splashdate;
     
     GLOBAL $S_load_stat;
 
     log_rd("maincheck begin");
 
     $ret = FALSE;
-    // $room = FALSE;
+    // $user->room = FALSE;
     // $user = FALSE;
     $curtime = time();
     
@@ -221,15 +222,15 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
             log_only("F");
             
             $S_load_stat['wR_garbage']++;
-            /* if (($room = Room::load_data()) == FALSE) { */
+            /* if (($user->room = Room::load_data()) == FALSE) { */
             /*     Room::unlock_data($sem); */
             /*     ignore_user_abort(FALSE); */
             /*     return (blocking_error(TRUE)); */
             /* } */
             log_main("pre garbage_manager TRE");
-            $room->garbage_manager(FALSE);
-            /* Room::save_data($room); */
-            /* unset($room); */
+            $user->room->garbage_manager(FALSE);
+            /* Room::save_data($user->room); */
+            /* unset($user->room); */
         }
     }
     log_main("infolock: U");
@@ -255,15 +256,15 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
 //                 log_only("F");
                 
 //                 $S_load_stat['R_garbage']++;
-//                 if (($room = Room::load_data()) == FALSE) {
+//                 if (($user->room = Room::load_data()) == FALSE) {
 //                     Room::unlock_data($sem);
 //                     ignore_user_abort(FALSE);
 //                     return (blocking_error(TRUE));
 //                 }
 //                 log_main("pre garbage_manager TRE");
-//                 $room->garbage_manager(FALSE);
-//                 Room::save_data($room);
-//                 unset($room);
+//                 $user->room->garbage_manager(FALSE);
+//                 Room::save_data($user->room);
+//                 unset($user->room);
 //             }
 //             log_main("infolock: U");
 //             Room::unlock_data($sem);
@@ -324,14 +325,14 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
 
         ignore_user_abort(TRUE);
         /* $sem = Room::lock_data(TRUE); */
-        /* if (($room = Room::load_data()) == FALSE) { */
+        /* if (($user->room = Room::load_data()) == FALSE) { */
         /*     Room::unlock_data($sem); */
         /*     ignore_user_abort(FALSE); */
         /*     return (blocking_error(TRUE)); */
         /* } */
         $S_load_stat['wR_minusone']++;
         
-        /* if (($user = $room->get_user($sess, $idx)) == FALSE) { */
+        /* if (($user = $user->room->get_user($sess, $idx)) == FALSE) { */
         /*     Room::unlock_data($sem); */
         /*     ignore_user_abort(FALSE); */
         /*     return (blocking_error(TRUE)); */
@@ -347,7 +348,7 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
             $cur_step = $user->trans_step;
             $user->trans_step = -1;
             
-            /* Room::save_data($room); */
+            /* Room::save_data($user->room); */
             /* Room::unlock_data($sem); */
             ignore_user_abort(FALSE);
         }
@@ -359,7 +360,7 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
             //          log_rd2("clean element [".$el."]");
             //        }
             //        //        $user->step_inc(COMM_N + 1);
-            //        Room::save_data($room);
+            //        Room::save_data($user->room);
             //        //        $new_step = $user->step;
             
             /* Room::unlock_data($sem); */
@@ -368,7 +369,7 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
     }
     
     
-    /* this part I suppose is read only on $room structure */
+    /* this part I suppose is read only on $user->room structure */
     if ($cur_step == -1) {
         log_rd2("PRE-NEWSTAT: ".$user->stat);
         
@@ -387,7 +388,7 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
                                         ($is_super ? 0 : $G_splash_timeout));
                 $ret .= sprintf('|createCookie("CO_splashdate%d", %d, 24*365, cookiepath);', $G_splash_idx, $curtime);
             }
-            $ret .= $room->show_room($user->step, $user);
+            $ret .= $user->room->show_room($user->step, $user);
             
             // TODO uncomment and test
             /* NOTE the sets went common */
@@ -451,13 +452,13 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
                 /* unset($user); */
 
                 $S_load_stat['wR_the_end']++;
-                /* if (($room = Room::load_data()) == FALSE) { */
+                /* if (($user->room = Room::load_data()) == FALSE) { */
                 /*     Room::unlock_data($sem); */
                 /*     ignore_user_abort(FALSE); */
                 /*     return (blocking_error(TRUE)); */
                 /* } */
 
-                /* if (($user = $room->get_user($sess, $idx)) == FALSE) { */
+                /* if (($user = $user->room->get_user($sess, $idx)) == FALSE) { */
                 /*     Room::unlock_data($sem); */
                 /*     ignore_user_abort(FALSE); */
                 /*     return (blocking_error(TRUE)); */
@@ -471,14 +472,14 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
                     
                     if ($user->subst == 'sitdown') {
                         log_load("ROOM WAKEUP");
-                        $room->room_wakeup($user);
+                        $user->room->room_wakeup($user);
                     }
                     else if ($user->subst == 'standup')
-                        $room->room_outstandup($user);
+                        $user->room->room_outstandup($user);
                     else
                         log_rd2("LOGOUT FROM WHAT ???");
                     
-                    /* Room::save_data($room); */
+                    /* Room::save_data($user->room); */
                 } /* if ($user->the_end == TRUE) { ... */
             } /* if ($user->the_end == TRUE) { ... */
         } /* if ($cur_step < $user->step) { */
@@ -491,6 +492,33 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
     return ($ret);
 }
 
+function index_rd_ifra_fini($is_unrecoverable)
+{
+    GLOBAL $G_four_rnd_string;
+
+    // IF IFRAME THEN:
+    $body = "";
+    $body .= sprintf("<html>
+<head>
+<script type=\"text/javascript\" src=\"commons.js\"></script>
+<script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
+<script type=\"text/javascript\">
+var http_streaming = \"ready\";");
+    $body .= sprintf("
+window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
+</script>
+</head>
+<body>");
+    $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
+    $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
+push(\"%s\");
+// -->
+</script>", 0, escpush(blocking_error($is_unrecoverable)) );
+    // ELSE IF XHR THEN:
+    // return (blocking_error($is_unrecoverable));
+    return ($body);
+}
+
 /*
  *  MAIN
  */
@@ -501,7 +529,7 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
    stat
    step
 */
-function index_rd_ifra_init(&$room, &$user, &$header_out, &$body, $get, $post, $cookie)
+function index_rd_ifra_init(&$user, &$header_out, &$body, $get, $post, $cookie)
 {
     GLOBAL $G_four_rnd_string;
 
@@ -532,9 +560,8 @@ function index_rd_ifra_init(&$room, &$user, &$header_out, &$body, $get, $post, $
 <script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
 <script type=\"text/javascript\">
 var http_streaming = \"ready\";");
-    if (isset($st)) {
-        $body .= sprintf("last_clean = %d;\n", $st);
-    }
+    if ($user->rd_scristp > 0)
+        $body .= sprintf("last_clean = %d;\n", ($user->rd_scristp-1));
     $body .= sprintf("
 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
 </script> 
@@ -545,9 +572,15 @@ window.onload = function () { if (http_streaming != \"ready\") { http_streaming.
     return TRUE;
 }
 
-function index_rd_ifra_main(&$room, &$user, &$body)
+function index_rd_ifra_main(&$user, &$body, $get, $post, $cookie)
 {
-    GLOBAL $is_page_streaming;
+    GLOBAL $is_page_streaming, $G_splash_idx;
+    // FIXME: only to test fwrite
+    // GLOBAL $G_four_rnd_string;
+
+    $CO_splashdate = "CO_splashdate".$G_splash_idx;
+    if (($splashdate = gpcs_var("$CO_splashdate", $get, $post, $cookie)) === FALSE)
+        $splashdate = ""; 
 
     $is_page_streaming = FALSE;
     log_rd2("FROM OUTSIDE - STAT: ".$user->rd_stat." SUBST: ".$user->rd_subst." STEP: ".$user->rd_step." FROM: ".$user->rd_from. "IS_PAGE:" . $is_page_streaming);
@@ -562,7 +595,7 @@ function index_rd_ifra_main(&$room, &$user, &$body)
         $old_stat  = $user->rd_stat;
         $old_subst = $user->rd_subst;
         $old_step  = $user->rd_step;
-        if (($ret = maincheck($room, $user, $old_stat, $old_subst, $old_step, $user->rd_stat, $user->rd_subst, $user->rd_step)) != FALSE) {
+        if (($ret = maincheck($user, $old_stat, $old_subst, $old_step, $user->rd_stat, $user->rd_subst, $user->rd_step, $splashdate)) != FALSE) {
             // $no_data = FALSE;
             if (0 == 1) {
                 echo '@BEGIN@';
@@ -570,6 +603,11 @@ function index_rd_ifra_main(&$room, &$user, &$body)
                 echo "$ret";
                 echo ' @END@'; 
             }
+
+            // FIXME only to test fwrite
+            // for ($u = 0 ; $u < 10 ; $u++) {
+            //    $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
+            // }
             $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
 push(\"%s\");
 // -->