Location: PHPKode > projects > Laikwan WMC > wmc_20070325/gmlite/loadActionToConv.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); 
	} 

	$gm = new GMailer();
	if (!$gm->created) {
		header("Content-type: text/xml; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
		header("Pragma: no-cache");  // stop caching	
		echo "<root><status>fail to create gmailer</status></root>";
		exit;
	}
	quick_init($gm);
	$tz = $tz + $tz2;
	$gm->setLoginInfo($login, $pass, $tz);

	if (!$gm->connect()) {
		header("Content-type: text/xml; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
		header("Pragma: no-cache");  // stop caching	
		echo "<root><status>Action Failed</status></root>";
		exit;
	}

	// perform action?
	$act = isset($_REQUEST["act"])? $_REQUEST["act"] : 0;
	$t = isset($_REQUEST["t"])? $_REQUEST["t"] : array();    
	$lbl = isset($_REQUEST["lbl"])? $_REQUEST["lbl"] : 0;    
	$newlbl = isset($_REQUEST["newlbl"])? $_REQUEST["newlbl"] : 0; // for rename lbl    
	$lact = isset($_REQUEST["lact"])? $_REQUEST["lact"] : 0;    // label act
//	$back = isset($_REQUEST["back"])? $_REQUEST["back"] : 0;


	/** quick references:
		define("GM_ACT_APPLYLABEL",		1);
		define("GM_ACT_REMOVELABEL",	2);
		define("GM_ACT_STAR",			3);
		define("GM_ACT_UNSTAR",			4);
		define("GM_ACT_SPAM",			5);
		define("GM_ACT_UNSPAM",			6);
		define("GM_ACT_READ",			7);
		define("GM_ACT_UNREAD",			8);
		define("GM_ACT_TRASH",			9);
		define("GM_ACT_DELFOREVER",		10);
		define("GM_ACT_ARCHIVE",		11);
		define("GM_ACT_INBOX",			12);
		define("GM_ACT_UNTRASH",		13);
		define("GM_ACT_UNDRAFT",		14);
		define("GM_ACT_TRASHMSG",		15);
		define("GM_ACT_DELSPAM",		16);
		define("GM_ACT_DELTRASHED",		17);
	**/

	header("Content-type: text/xml; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
	header("Pragma: no-cache");  // stop caching	


	if ($act && count($t) > 0) {
		$t_arr = preg_split('/,/', $t); // i can't believe they make me put '' around // - ahhh
		echo "<root>";
		foreach ($t_arr as $m){
			$success = $gm->performAction($act, $m, $lbl);
			if($success){
				echo "<msg><id>" . $m . "</id><status>success</status></msg>";
			}else{
				$err = $gm->lastActionStatus();
				echo "<msg><id>" . $m . "</id><status>failed</status><err>" . $err . "</err></msg>";
			}
		}
		echo "</root>";

	}else if($lact && $lbl){	
		if($lact == "N" && $newlbl) {
			$success = $gm->editLabel($lbl, "rename", $newlbl);
		}else if($lact == "R"){
			$success = $gm->editLabel($lbl, "remove", "");
		}else if($lact == "C"){
			$success = $gm->editLabel($lbl, "create", "");
		}	   
		if(!$success)
			  $err = $gm->lastActionStatus();
		echo "<root><status>" . ($success ? 'success' : 'failed: '.$err) . "</status></root>";
	}else{
		echo "<root><status>failed</status><err>Empty Input</err></root>";
	}
   
?>
Return current item: Laikwan WMC