[ Index ]

PHP Cross Reference of JPSpan 0.4 (beta)

title

Body

[close]

/examples/ -> xulmail.php (source)

   1  <?php
   2  if ( !isset($_GET['launch']) || $_GET['launch'] != 'xulmail' ) {
   3  ?>
   4  <html>
   5  <head>
   6  <title>Launch XULMail</title>
   7  <script language="Javascript" type="text/javascript">
   8  function loadXul(url,title) {
   9      var width=500;
  10      var height=400;
  11      // check that we're using mozilla
  12      // if not, ask user does he want to proceed anyway
  13      if (checkIsMoz() ||
  14      window.confirm("This application is designed for the mozilla browser. You do not appear to be using mozilla at the moment, do you want to continue anyway?")
  15          ) {
  16          // set the features of the new window
  17          var features = "centerscreen,chrome,close,titlebar";
  18          // including width and height if specified
  19          if (width && height) {
  20              features += ",width=" + width + ",height=" + height;
  21          }
  22          // set the title if not set
  23          if (!title) {
  24              title = "Mozilla";
  25          }
  26          // if nn7, just open the xul window (doesn't work otherwise, for some reason)
  27          if (checkIsNN7()) {
  28              window.open(url,'xul_window',features);
  29          } else {
  30              // open new blank window 
  31              var xulwin = window.open('','xul_window',features);
  32              // set the window to display some text while the xul page is loading
  33              var loadingtext = "Loading...";
  34              xulwin.document.write("<html><head><title>" + title + "</title></head><body><br><p align='center'><strong>" + loadingtext + "</strong></p></body></html>");
  35              xulwin.document.close();
  36              // reload with xul location
  37              xulwin.location = url;
  38          }
  39      }
  40  }
  41  function checkIsMoz() {
  42      return (navigator.userAgent.indexOf("Gecko") != -1);
  43  }
  44  
  45  function checkIsNN7() {
  46      return (navigator.userAgent.indexOf("Netscape/7") != -1);
  47  }
  48  </script>
  49  </head>
  50  <body>
  51  <h1>Launch XULMail</h1>
  52  <a href="javascript:loadXul('<?php echo $_SERVER['PHP_SELF'];?>?launch=xulmail','XULMail');">Launch</a>
  53  </body>
  54  </html>
  55  <?php
  56      die();
  57  }
  58  require_once  '../JPSpan.php';
  59  
  60  require_once JPSPAN . 'Include.php';
  61  JPSpan_Include_Register('util/data.js');
  62  JPSpan_Include_Register('encode/xml.js');
  63  
  64  function path() {
  65      $basePath = explode('/',$_SERVER['SCRIPT_NAME']);
  66      $script = array_pop($basePath);
  67      $basePath = implode('/',$basePath);
  68      if ( isset($_SERVER['HTTPS']) ) {
  69          $scheme = 'https';
  70      } else {
  71          $scheme = 'http';
  72      }
  73      echo $scheme.'://'.$_SERVER['SERVER_NAME'].$basePath;
  74  }
  75  
  76  header ( 'Content-type: application/vnd.mozilla.xul+xml' );
  77  echo '<?xml version="1.0"?>';
  78  ?>
  79  <window title="XULMail"
  80      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  81      xmlns:html="http://www.w3.org/1999/xhtml"
  82          onload="init();">
  83      <?php echo '<?xml-stylesheet href="xulmail.css" type="text/css"?>';?>
  84      <script type="application/x-javascript">
  85      <![CDATA[
  86      <?php JPSpan_Includes_Display(); ?>
  87      
  88      function var_dump(data) {
  89          var Data = new JPSpan_Util_Data();
  90          return Data.dump(data);
  91      }
  92      
  93      function serialize(data) {
  94          var Encoder = new JPSpan_Encode_Xml();
  95          return Encoder.encode(data);
  96      }
  97      
  98      var httpRequest = false;
  99      // Modify this
 100      var mailUrl = "<?php path(); ?>/mailresponder.php";
 101      function getRequest() {
 102          if ( !httpRequest ) {
 103              httpRequest = new XMLHttpRequest();    
 104          }
 105          return httpRequest;
 106      }
 107      function makeRequest(targetUrl) {
 108          var httpRequest = getRequest();
 109          httpRequest.open("GET", targetUrl, false, false, false);
 110          httpRequest.send("");
 111          switch ( httpRequest.status ) {
 112              case 200:
 113                  return httpRequest.responseText;
 114              break;
 115              default:
 116                  alert("Problem accessing url: "+targetUrl+" Code: "+httpRequest.status);
 117                  return null;
 118              break;
 119          }       
 120      }
 121      function getMessages() {
 122          response = makeRequest(mailUrl);
 123          try {
 124              datafunc = eval(response);
 125          } catch (e) {
 126              alert("Problem fetching messages");
 127              return null;
 128          }
 129          try {
 130              result = datafunc();
 131              return result;
 132          } catch (e) {
 133              alert(e.name+": "+e.message);
 134              return null;
 135          }
 136      }
 137      function getMessage(mid,pid) {
 138          var messageUrl = mailUrl + "?mid=" + mid + "&pid=" + pid;
 139          response = makeRequest(messageUrl);
 140          try {
 141              datafunc = eval(response);
 142          } catch (e) {
 143              alert("Invalid response from server");
 144              return null;
 145          }
 146          try {
 147              result = datafunc();
 148              return result;
 149          } catch ( e ) {
 150              alert(e.name+": "+e.message);
 151              return null;
 152          }
 153      }
 154      function displayMessage(id) {
 155          id = id.split(':');
 156          message = getMessage(id[0],id[1]);
 157          if ( !message ) {
 158              alert ('Unable to display message');
 159              return;
 160          }
 161          subject = document.getElementById('subject');
 162          subject.setAttribute('value',message.subject);
 163          from = document.getElementById('from');
 164          from.setAttribute('value',message.from);
 165          date = document.getElementById('date');
 166          date.setAttribute('value',message.date);
 167          body = document.getElementById('body');
 168          body.setAttribute('value',message.body);
 169      }
 170      function init() {
 171          var messages = getMessages();
 172          var messageList = document.getElementById('messageList');
 173          var listhead = messageList.firstChild;
 174          var listitem;
 175          while ( listitem = listhead.nextSibling ) {
 176              messageList.removeChild(listitem);
 177          }
 178          for(var i=0;i<messages.length;i++) {
 179              messagec = document.createElement('listitem');
 180              messagec.setAttribute('id',messages[i].mid);
 181              subjectc = document.createElement('listcell');
 182              subjectc.setAttribute('label',messages[i].subject);
 183              messagec.appendChild(subjectc);
 184              datec = document.createElement('listcell');
 185              datec.setAttribute('label',messages[i].date);
 186              messagec.appendChild(datec);
 187              fromc = document.createElement('listcell');
 188              fromc.setAttribute('label',messages[i].from);
 189              messagec.appendChild(fromc);
 190              messagec.setAttribute('onclick',
 191                  'displayMessage("'+messages[i].mid+':'+messages[i].pid+'");');
 192              messageList.appendChild(messagec);
 193          }
 194      }
 195      ]]>
 196      </script>
 197      <vbox>
 198          <hbox>
 199              <label id="title" value="XULMail" flex="1"/>
 200              <button id="refresh" label="Refresh" onclick="init();"/>
 201          </hbox>
 202          <hbox flex="1">
 203              <listbox flex="1" id="messageList">
 204                  <listhead>
 205                      <listheader label="Subject"/>
 206                      <listheader label="Date"/>
 207                      <listheader label="From"/>
 208                  </listhead>
 209              </listbox>
 210          </hbox>
 211          <vbox>
 212              <grid flex="1" id="messageBody">
 213                  <columns>
 214                      <column/>
 215                      <column flex="1"/>
 216                  </columns>
 217                  <rows>
 218                      <row>
 219                          <label value="Subject"/>
 220                          <textbox id="subject" readonly="true"/>
 221                      </row>
 222                      <row>
 223                          <label value="From"/>
 224                          <textbox id="from" readonly="true"/>
 225                      </row>
 226                      <row>
 227                          <label value="Date"/>
 228                          <textbox id="date" readonly="true"/>
 229                      </row>
 230                  </rows>
 231              </grid>
 232              <textbox id="body" readonly="true" multiline="true" rows="4" flex="1"/>
 233          </vbox>
 234      </vbox>
 235  </window>


Generated: Fri Nov 26 11:42:46 2004 Cross-referenced by PHPXref 0.6