Login   Register  
PHP Classes
elePHPant
Icontem

File: index.phtml

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Slava Ivanov  >  vCard Class  >  index.phtml  >  Download  
File: index.phtml
Role: Example script
Content type: text/plain
Description: example application
Class: vCard Class
Class to manipulate with vCard information
Author: By
Last change:
Date: 2003-03-25 18:06
Size: 13,613 bytes
 

Contents

Class file image Download
<?
Header("Cache-Control: no-cache");
Header("Pragma: no-cache");
Header("Expires: Sat, Jan 01 2000 01:01:01 GMT");
session_name("SID");
session_start();
include("vcardclass.inc");

$SCRIPT_NAME = "index.phtml";
$title = "vCard";
$FORM_NAME = "jform";

$act = $_POST["act"];
$error = 0;

if ($act == "other" || $act == "personal" || $act == "home" || $act == "business") exit(header("Location: ".$act.".phtml"));

function setvCardInfo(&$vcard) {
	unset($_SESSION["vCardinfo"]);
	// personal info
	$_SESSION["vCardinfo"]["prefix"] = $vcard->getName("PREF");
	$_SESSION["vCardinfo"]["fname"] = $vcard->getName("FIRST");
	$_SESSION["vCardinfo"]["mname"] = $vcard->getName("MIDDLE");
	$_SESSION["vCardinfo"]["lname"] = $vcard->getName("LAST");
	$_SESSION["vCardinfo"]["suffix"] = $vcard->getName("SUFF");
	$_SESSION["vCardinfo"]["nickname"] = $vcard->getNickName();
	$_SESSION["vCardinfo"]["birthday"] = $vcard->getBirthDate("YEAR")."/".$vcard->getBirthDate("MONTH")."/".$vcard->getBirthDate("DAY");
	$input = array("PREF", "INTERNET");
	if ($vcard->getEmail($input)) {
		$_SESSION["vCardinfo"]["email1"] = $vcard->getEmail($input);
		$_SESSION["vCardinfo"]["email2"] = $vcard->getEmail("INTERNET");
	} else {
		$_SESSION["vCardinfo"]["email1"] = $vcard->getEmail("INTERNET");
	}

	// home info
	$arr_address = array("POBOX", "EXTENDED", "STREET", "CITY", "PROVINCE", "POSTAL", "COUNTRY");
	$input = array("HOME");
	while (list(, $v) = each($arr_address)) {
		$res = $vcard->getAdr($v, $input, "AND");
		if (is_array($res)) {
			while (list($key, $value) = each($res)) {
				if ($v == "POBOX") {
					$_SESSION["vCardinfo"]["homeextended"] = $value;
				} elseif ($v == "EXTENDED") {
					$_SESSION["vCardinfo"]["homeextended"] = $value;
				} elseif ($v == "STREET") {
					$_SESSION["vCardinfo"]["homestreet"] = $value;
				} elseif ($v == "CITY") {
					$_SESSION["vCardinfo"]["homecity"] = $value;
				} elseif ($v == "PROVINCE") {
					$_SESSION["vCardinfo"]["homeprov"] = $value;
				} elseif ($v == "POSTAL") {
					$_SESSION["vCardinfo"]["homepostal"] = $value;
				} elseif ($v == "COUNTRY") {
					$_SESSION["vCardinfo"]["homecountry"] = $value;
				}
			}
		}
	}
	$input = array("HOME", "CELL", "FAX");
	$res = $vcard->getTel($input, "OR");
	if (is_array($res)) {
		while (list($key, $value) = each($res)) {
			if (strstr($key, "HOME") && (strstr($key, "MSG") || strstr($key, "VOICE")))
				$_SESSION["vCardinfo"]["homephone"] = $value;
			elseif (strstr($key, "CELL"))
				$_SESSION["vCardinfo"]["cellphone"] = $value;
			elseif (strstr($key, "HOME") && strstr($key, "FAX"))
				$_SESSION["vCardinfo"]["homefax"] = $value;
		}
	}

	// business info
	$_SESSION["vCardinfo"]["orgname"] = $vcard->getOrg("ORGNAME");
	$_SESSION["vCardinfo"]["weburl"] = $vcard->getUrl();
	$_SESSION["vCardinfo"]["jobtitle"] = $vcard->getTitle();
	$_SESSION["vCardinfo"]["orgunit"] = $vcard->getOrg("ORGUNIT");
	$input = array("WORK");
	reset($arr_address);
	while (list(, $v) = each($arr_address)) {
		$res = $vcard->getAdr($v, $input, "AND");
		if (is_array($res)) {
			while (list($key, $value) = each($res)) {
				if ($v == "POBOX") {
					$_SESSION["vCardinfo"]["workextended"] = $value;
				} elseif ($v == "EXTENDED") {
					$_SESSION["vCardinfo"]["workextended"] = $value;
				} elseif ($v == "STREET") {
					$_SESSION["vCardinfo"]["workstreet"] = $value;
				} elseif ($v == "CITY") {
					$_SESSION["vCardinfo"]["workcity"] = $value;
				} elseif ($v == "PROVINCE") {
					$_SESSION["vCardinfo"]["workprov"] = $value;
				} elseif ($v == "POSTAL") {
					$_SESSION["vCardinfo"]["workpostal"] = $value;
				} elseif ($v == "COUNTRY") {
					$_SESSION["vCardinfo"]["workcountry"] = $value;
				}
			}
		}
	}
	$input = array("WORK", "FAX", "PAGER");
	$res = $vcard->getTel($input, "OR");
	if (is_array($res)) {
		while (list($key, $value) = each($res)) {
			if (strstr($key, "WORK") && (strstr($key, "MSG") || strstr($key, "VOICE")))
				$_SESSION["vCardinfo"]["workphone"] = $value;
			elseif ((strstr($key, "WORK") && strstr($key, "FAX")) || (strstr($key, "FAX") && !strstr($key, "HOME")))
				$_SESSION["vCardinfo"]["workfax"] = $value;
			elseif (strstr($key, "PAGER"))
				$_SESSION["vCardinfo"]["workpager"] = $value;
		}
	}

	// other info
	$_SESSION["vCardinfo"]["note"] = $vcard->getNote();

	// digital ID info
	$_SESSION["vCardinfo"]["keyx509"] = $vcard->getKey();
}

function getvCardInfo() {
	$vcard = new VCARD();
	$vcard->mailer = "StrongPost vCard";
	$vcard->setName($_SESSION["vCardinfo"]["lname"], $_SESSION["vCardinfo"]["fname"], $_SESSION["vCardinfo"]["mname"], $_SESSION["vCardinfo"]["prefix"], $_SESSION["vCardinfo"]["suffix"]);
	$vcard->setNickName($_SESSION["vCardinfo"]["nickname"]);
	if ($_SESSION["vCardinfo"]["birthday"]) {
		$arr_date = explode("/", $_SESSION["vCardinfo"]["birthday"]);
		if (sizeof($arr_date) == 3)	$vcard->setBirthDate($arr_date[0], $arr_date[1], $arr_date[2]);
	}
	$vcard->setEmail($_SESSION["vCardinfo"]["email1"], "");
	$vcard->setEmail($_SESSION["vCardinfo"]["email2"]);
	$vcard->setAdr("", $_SESSION["vCardinfo"]["homeextended"], $_SESSION["vCardinfo"]["homestreet"], $_SESSION["vCardinfo"]["homecity"], $_SESSION["vCardinfo"]["homeprov"], $_SESSION["vCardinfo"]["homepostal"], $_SESSION["vCardinfo"]["homecountry"], "HOME");
	$input = array("HOME", "VOICE");
	$vcard->setTel($_SESSION["vCardinfo"]["homephone"], $input);
	$input = array("CELL", "VOICE");
	$vcard->setTel($_SESSION["vCardinfo"]["cellphone"], $input);
	$input = array("FAX", "HOME");
	$vcard->setTel($_SESSION["vCardinfo"]["homefax"], $input);
	$vcard->setOrg($_SESSION["vCardinfo"]["orgname"], $_SESSION["vCardinfo"]["orgunit"]);
	$vcard->setTitle($_SESSION["vCardinfo"]["jobtitle"]);
	$vcard->setUrl($_SESSION["vCardinfo"]["weburl"], "WORK");
	$vcard->setAdr("", $_SESSION["vCardinfo"]["workextended"], $_SESSION["vCardinfo"]["workstreet"], $_SESSION["vCardinfo"]["workcity"], $_SESSION["vCardinfo"]["workprov"], $_SESSION["vCardinfo"]["workpostal"], $_SESSION["vCardinfo"]["workcountry"], "WORK");
	$input = array("WORK", "VOICE");
	$vcard->setTel($_SESSION["vCardinfo"]["workphone"], $input);
	$input = array("WORK", "FAX");
	$vcard->setTel($_SESSION["vCardinfo"]["workfax"], $input);
	$vcard->setTel($_SESSION["vCardinfo"]["workpager"], "PAGER");
	$vcard->setNote($_SESSION["vCardinfo"]["note"]);
	$vcard->setKey($_SESSION["vCardinfo"]["keyx509"]);
	return $vcard->getvCard("2.1");
}


if ($act == "saveit" || $_GET["act"] == "saveit") {
	$vCardvalue = getvCardInfo();
	// here goes code to save $vCardvalue to a file or to database, ex:
	$fp = fopen ("/tmp/vCard.vcf", "w+");
	if ($fp) {
		fputs ($fp, $vCardvalue);	
		$err_msg.= "File has been saved to location: /tmp/vCard.vcf";
	} else {
		$err_msg.= "Can't write to the file, check permission for /tmp/ directory.";
	}		
	$onload = "javascript:alert('".$err_msg."');";
	$act = "cancelit";
}

if ($act == "deleteit") {
	// here goes code to delete vCard from file system or database
	$act = "cancelit";
}

if ($act == "cancelit") {
	unset($vCardinfo);  //remove this if don't register globals
	unset($_SESSION["vCardinfo"]);
}

if ($act == "importit") {
	if (!$file_imp_name || ($file_imp_name && !is_uploaded_file($file_imp))) {
		$error++;
		$err_msg.= "You have to choose a file from your local computer. Use the [Browse...] button. ";
	}
	if ( $file_imp_name && !$file_imp_size ) {
		$error++;
		$err_msg.= "The file contains no data or doesn't exist. ";
	}
	if (!$error) {
		if (strtolower(substr(strrchr($file_imp_name, "."), 1)) != "vcf") {
			$error++;
			$err_msg.= "Invalid file. Check file format or choose another file. ";
		} else {
			$fp = fopen ($file_imp,"r");
			$contents = fread ($fp, filesize($file_imp));
			fclose ($fp);
			$vcard = new VCARD();
			$vcard->setvCard($contents);
			if ($vcard->lasterror_num) {
				$error++;
				$err_msg.= $vcard->lasterror_msg." (Errror #".$vcard->lasterror_num.")";
			} else {
				$vcard->mailer = "StrongPost vCard";
				$vcard->setVersion("2.1");
				setvCardInfo($vcard);
			}
		}
	}
	if ($error) $onload = "javascript:alert('Error: ".$err_msg."');";
}

include("template-header.phtml");
?>

<form method="post" action="<? echo $SCRIPT_NAME ?>" enctype="multipart/form-data" name="<? echo $FORM_NAME ?>">
<table cellspacing="1" cellpadding="0" border="0" width="485" align="center">
<? include("vmenu.phtml"); ?>
<tr>
<td colspan="8" valign="top">
    <table cellspacing="0" cellpadding="0" border="0" width="100%" bgcolor="#bebebe">
    <tr>
    <td bgcolor="#eeeeee" width="1"><img src="../images/spacer.gif" width="1" height="300"></td>
    <td valign="top">
    <br>
    <!------------------------contents go here ---------------------------------------------------------->

    <table  cellspacing="0" cellpadding="0" border="0" width="485">
    <tr>
    <td colspan="2">
        <table cellspacing="0" cellpadding="7" border="0">
        <tr>
        <td>&nbsp;vCard information.</td>
        </tr>
        </table>
    </td>
    </tr>
    <tr>
    <td><img src="../images/spacer.gif" width="2" height="1"></td>
    <td align="center">
        <table cellpadding="1" cellspacing="1">
        <tr>
        <td valign="top" class="medium">Name: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["fname"]." ".$_SESSION["vCardinfo"]["mname"]." ".$_SESSION["vCardinfo"]["lname"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Email Address: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["email1"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Home Phone: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["homephone"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Mobile: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["cellphone"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Pager: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["workpager"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Business Phone: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["workphone"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Business Fax: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["workfax"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Job Title: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["jobtitle"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Department: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["orgunit"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Company Name: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["orgname"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium">Web Page: </td>
        <td valign="top" class="medium"><? echo htmlspecialchars($_SESSION["vCardinfo"]["weburl"]); ?></td>
        </tr>
        <tr>
        <td valign="top" class="medium" colspan=2><? echo ($_SESSION["vCardinfo"]["fname"] || $_SESSION["vCardinfo"]["lname"])? "<a href='download.phtml'>Preview/Download vCard</a>" : "&nbsp;"; ?></td>
        </tr>
        </table>
    </td>
    </tr>
    <tr>
    <td colspan="2"><hr width="98%"></td>
    </tr>
    <tr>
    <td colspan="2">
        <table>
        <tr>
        <td>&nbsp;Import vCard: </td>
        <td><input type="file" name="file_imp"></td>
        <td><input type="button" name="ok" value="  Ok  " onclick="javascript:dosubmit('importit',document.<? echo $FORM_NAME ?>);"></td>
        </tr>
        </table>
    </td>
    </tr>
    </table>

    <!---------------------------------------------------------------------------------->
   </td>
    <td bgcolor="black" width="1"><img src="../images/spacer.gif" width="1" height="1"></td>
    </tr>
    <tr>
    <td  bgcolor="black" colspan="3"><img src="../images/spacer.gif" width="1" height="1"></td>
    </tr>
    </table>
 </td>
</tr>
</table>

<table width="485" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="3"><img src="../images/spacer.gif" width="1" height="2"></td>
</tr>
<tr  bgcolor="#e5e5e5">
<td  align="right"><input type="button" name="delete" value="Delete" onclick="javascript:dochecksubmit('deleteit',document.<? echo $FORM_NAME ?>);">&nbsp;<input type="button" name="cancel" value="Cancel" onclick="javascript:dochecksubmit('cancelit',document.<? echo $FORM_NAME ?>);">&nbsp;<input type="button" name="save" value=" Save " onclick="javascript:dosubmit('saveit',document.<? echo $FORM_NAME ?>);"></td>
</tr>
</table>

<input type="hidden" name="act" value="">
<input type="hidden" name="fname" value="<? echo htmlspecialchars($_SESSION["vCardinfo"]["fname"]); ?>">
<input type="hidden" name="lname" value="<? echo htmlspecialchars($_SESSION["vCardinfo"]["lname"]); ?>">
</form>

<? include("template-footer.phtml"); ?>