Location: PHPKode > projects > Laikwan WMC > wmc_20070325/gmlite/loadFolders.php
<?php

   require_once("config.php");

   $login = (isset($_REQUEST["login"]))? $_REQUEST["login"]: "";
   $pass = (isset($_REQUEST["pass"]))? $_REQUEST["pass"]: ""; 
   $tz = (isset($_REQUEST["tz"]))? 0+$_REQUEST["tz"] : 8;  
   $tz2 = (isset($_REQUEST["tz2"]))? 0+$_REQUEST["tz2"] : 0; 
   
   if (!(strlen($login) == 0 || strlen($pass) == 0)) {
      setcookie("TZ", $tz); 
      setcookie("TZ2",$tz2); 
   } 
   
   if (file_exists("../demo.php")) {
      require_once("../demo.php"); // info of demo account
   }
   
   $gm = new GMailer();
   if (!$gm->created) {
      die("fail to create gmailer");
   }
   quick_init($gm);
   $tz = $tz + $tz2;
   $gm->setLoginInfo($login, $pass, $tz);
   if (!$gm->connect()) {
      header("Location: index.php?err=10");
      exit();
   }
   
   $th = (isset($_REQUEST["th"]))? $_REQUEST["th"] : 0;
   $mg = (isset($_REQUEST["mg"]))? $_REQUEST["mg"] : 0;
   $html = (isset($_REQUEST["html"]))? $_REQUEST["html"] : 0;
   $std = (isset($_REQUEST["std"]))? $_REQUEST["std"] : 0;
   $label = (isset($_REQUEST["label"]))? $_REQUEST["label"] : 0;
   $query = stripslashes((isset($_REQUEST["query"]))? $_REQUEST["query"] : 0);
   $sum = (isset($_REQUEST["sum"]))? $_REQUEST["sum"] : 0;   
   $unread = (isset($_REQUEST["unread"]))? $_REQUEST["unread"] : 0; 
   $pos = (isset($_REQUEST["pos"]))? $_REQUEST["pos"] : 0;    
   $orig = (isset($_REQUEST["orig"]))? $_REQUEST["orig"] : 0;   
    
   // perform action?
   $act = isset($_REQUEST["act"])? $_REQUEST["act"] : 0;
   $lbl = isset($_REQUEST["lbl"])? $_REQUEST["lbl"] : 0;    
   $back = isset($_REQUEST["back"])? $_REQUEST["back"] : 0;
   $t = isset($_REQUEST["t"])? $_REQUEST["t"] : array();    
   
   if ($act && count($t) > 0 && $back) {
      $gm->performAction($act, $t, $lbl);
      header("Location: ".$back);
      exit();   // redirect right away
   }
   
   
   if ($sum) {
      $q = "search=cat&cat=dummyjusttoretrievesummary&view=tl&start=0&init=1";
      $tit = "summary";
   } elseif ($orig && $mg) {
      $q = "view=om&th=".$mg;
      // dump the whole page... with some escaping
      header("Content-type: text/plain; charset=big5");
      echo $gm->dump($q);
      exit();
   } else {   
      if ($unread) {
         $q = "search=query&q=is%3Aunread&view=tl&start=".$pos;
         $tit = "unread";
      } else {   
         if ($th) {
            $tit = "conversation";
            if (!$std)
               $std = "inbox";
               
            if ($mg)
               $q = "search=".$std."&view=cv&th=".$th."&msgs=".$mg;      
            else
               $q = "search=".$std."&view=cv&th=".$th;
               
            if ($html)
               $q .= "&ser=1";      
         } else {
            if ($query) {
               $q = "search=query&q=".urlencode($query)."&view=tl&start=".$pos;
               $tit = "search";
            } elseif ($label) {
               $q = "search=cat&cat=".urlencode($label)."&view=tl&start=".$pos;
               $tit = $label;
            } else {
               if ($std)
                  $q = "search=".$std."&view=tl&start=".$pos;
               else {
                  $q = "search=inbox&view=tl&start=0&init=1";
                  $std = "inbox";
               }
               $tit = $std;
            }
         }
      }
   }
   
   $gm->fetch($q);
   $snapshot = $gm->getSnapshot(GM_STANDARD|GM_LABEL|GM_QUERY|GM_CONVERSATION);   
   if ($snapshot->created == 0) {
      //echo "<pre>".print_r($gm->raw,1)."</pre>";
      // error occurred
      header("Location: main.php?std=".$std."&label=".$label."&".SID);
      exit;
   }   
   $stdbox = GMailer::getStandardBox();
   
	$gm->fetchBox(GM_PREFERENCE, 0, 0);
	$snapshot2 = $gm->getSnapshot(GM_PREFERENCE);
   
	header("Content-type: text/xml; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
	header("Pragma: no-cache");  // stop caching	
?> 


<body>
<msgType>folders</msgType>

<?

	// modded on 4/16/2006

	// boxes
	for ($i = 0; $i < count($stdbox); $i++) {
		$unread = ($snapshot->std_box_new[$i] > 0) ? $snapshot->std_box_new[$i] : 0;
		echo "<box><name>".$stdbox[$i]."</name><unread>".$unread."</unread></box>\n";		
	}

	// labels
	for ($i = 0; $i < count($snapshot->label_list); $i++) {      
		echo "<folder>". 
			"<name>".$snapshot->label_list[$i]."</name>".
			"<unread>".$snapshot->label_new[$i]."</unread>" .
			"<total>".$snapshot2->label_total[$i]."</total>".
			"</folder>";
	}
   
?>
</body>
Return current item: Laikwan WMC