<?
if(VALID_DOCUMENT != 1) die('what?');
$res = '';
$do_print = true;
$standalone = get_var('standalone')!='';
if($action == 'addressbook-edit'){
$entry = get_var('entry');
$e = $_SESSION['addressbook']->get_entry($entry);
if($e){
?>
<script type="text/javascript">
function check_form(form){
if(form["name"].value=="") alert("Fill name");
// else if(form["nick"].value=="") alert("Fill nick name");
else if(form["email"].value=="") alert("Fill emails");
else if(form["email"].value.indexOf("@")<0) alert("Are email you entered is good ?");
else form.submit();
}
</script>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="entry" value="<?=$entry?>"/>
<input type="hidden" name="action" value=""/>
<table class="content hsides">
<?$e->get_edit_presentation()?>
<tr><td colspan="2">
<input type="button" value="save" onclick="action.value='addressbook-save';check_form(this.form)"/>
<input type="button" value="cancel" onclick="action.value='addressbook-cancel';this.form.submit()"/>
</td></tr>
</table>
</form>
<?
}
else{?>
<div class="error">
<b>Edit Contact:</b><br/>
No such entry
</div>
<?}
}
else if($action == 'addressbook-new' || $action == 'addressbook-new-list' ||
$action == 'addressbook-take'){
$e = $_SESSION['addressbook']->get_entry(false,($action=='addressbook-new-list'),($action=='addressbook-take'));
if($action == 'addressbook-take'){
charset_header($GLOBALS['DEFAULT_CHARSET']);
$title = 'Addressbook';
include(TMPLPATH."html_start.php");
}
if(is_object($e)){
?>
<script type="text/javascript">
function check_form(form){
if(form["name"].value=="") alert("Fill name");
// else if(form["nick"].value=="") alert("Fill nick name");
else if(form["email"].value=="") alert("Fill emails");
else if(form["email"].value.indexOf("@")<0) alert("Are email you entered is good ?");
else form.submit();
}
</script>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="entry" value="<?=$entry?>"/>
<input type="hidden" name="action" value=""/>
<?if($action == 'addressbook-take'){?>
<input type="hidden" name="take" value="ok"/>
<?}?>
<table class="content hsides">
<tr><th colspan="2" class="title">
Add New <?=$action=='addressbook-new-list'?'List':'Entry'?>
</th></tr>
<?$e->get_edit_presentation()?>
<tr><td colspan="2">
<input type="button" value="add" onclick="action.value='addressbook-add';check_form(this.form)"/>
<?if($action == 'addressbook-take'){?>
<input type="button" value="cancel" onclick="window.close();"/>
<?}else{?>
<input type="button" value="cancel" onclick="action.value='addressbook-cancel';this.form.submit()"/>
<?}?>
</td></tr>
</table>
</form>
<?
}
else{?>
<div class="notice"><?=Notice::erase()?></div>
<?
}
if($action == 'addressbook-take'){
include(TMPLPATH."html_end.php");
}
}
else if($action == 'addressbook-add' || $action == 'addressbook-save'){
$entry = get_var('entry');
if($action == 'addressbook-add'){
$_SESSION['addressbook']->load();
}
else{
$_SESSION['addressbook']->load($entry);
}
$_SESSION['addressbook']->store();
if(get_var('take'))
location_header($_SERVER['PHP_SELF'].'?action=addressbook-ok');
else{
if(is_numeric($entry)){
location_header($_SERVER['PHP_SELF'].'?action=addressbook-edit&entry='.$entry);
}
else
location_header($_SERVER['PHP_SELF'].'?action=addressbook');
}
}
else if($action == 'addressbook-delete'){
$keys = get_var('key');
$_SESSION['addressbook']->delete($keys);
$_SESSION['addressbook']->store();
if($standalone)
location_header($_SERVER['PHP_SELF'].'?action=addressbook-standalone&standalone=ok');
else
location_header($_SERVER['PHP_SELF'].'?action=addressbook');
}
else if($action == 'addressbook-import'){
$type = get_var('type');
$ifdelete = get_var('delete-entries')!='';
if(is_uploaded_file($_FILES['import-file']['tmp_name'])){
$method = 'from_'.$type;
if(method_exists($_SESSION['addressbook'],$method)){
if($f = fopen($_FILES['import-file']['tmp_name'],"r")){
call_user_method($method, $_SESSION['addressbook'], $f, $ifdelete);
fclose($f);
}
}
}
location_header($_SERVER['PHP_SELF'].'?action=addressbook');
}
else if($action == 'addressbook-export'){
$type = get_var('type');
if($type == 'csv'){
header('HTTP/1.0 200 OK');
header('Content-Type: application/csv');
header('Content-Disposition:filename="address-book.csv"');
print $_SESSION['addressbook']->get_csv_format();
}
else if($type == 'pine'){
header('HTTP/1.0 200 OK');
header('Content-Type: text/pine-addressbook-format');
header('Content-Disposition:filename="addressbook.txt"');
print $_SESSION['addressbook']->get_pine_format();
}
else if($type == 'vcard'){
header('HTTP/1.0 200 OK');
header('Content-Type: application/x-vcard');
header('Content-Disposition:filename="addressbook.vcf"');
print $_SESSION['addressbook']->get_vcard_format();
}
else if($type == 'ldif'){
header('HTTP/1.0 200 OK');
header('Content-Type: text/ldif');
header('Content-Disposition:filename="addressbook.ldif"');
print $_SESSION['addressbook']->get_ldif_format();
}
}
else if($action == 'addressbook-query'){
print js_string($_SESSION['addressbook']->search(get_var('q')));
exit(0);
}
else if($action == 'addressbook-ok'){
?>
<center>
<input type="button" onclick="window.close()" value="ok" />
</center>
<?
}
else if($action == 'addressbook-choose'){
charset_header($GLOBALS['DEFAULT_CHARSET']);
$type = get_var('type');
include(TMPLPATH."html_start.php");
?>
<a style="position:fixed;right:1px;top:1px;" onclick="parent.close_choose('<?=$type?>')"><img src="images/close.jpg"/></a>
<table class="content hsides w100">
<tr><th class="title nowrap" colspan="3">Choose Address For <u><?=$type?></u> Field</th></tr>
<?=$_SESSION['addressbook']->get_choose_presentation($type)?>
<tr><td class="center" colspan="3">
<input type="button" onclick="parent.close_choose('<?=$type?>');" value="close">
</td></tr>
</table>
<?
include(TMPLPATH."html_end.php");
}
else if($action == 'addressbook-show-export-import'){
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="addressbook-import"/>
<table class="content hsides w100">
<tr><th>Export</th></tr>
<tr><td>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-export&type=csv">export for outlook express</a> (as CSV)<br/>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-export&type=pine">export for pine</a><br/>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-export&type=vcard">export as vCard</a><br/>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-export&type=ldif">export as LDIF</a> (for Thunderbird)<br/>
</td></tr>
<tr><th>Import</th></tr>
<tr><td>
<input name="delete-entries" type="checkbox" value="ok"/> delete old entires<br/>
</td></tr>
<tr><th>Choose file</th></tr>
<tr><td>
<input type="file" name="import-file" size="45"/>
</td></tr>
<tr><th>Choose file type</th></tr>
<tr><td>
<p>
<input type="radio" name="type" value="csv" checked="checked"/> <big>Comma Separeted Values</big><br/>
<ul type="square" style="margin: 1px 1px 1px 5px">
<li>Outlook CSV –
<b>MUST</b> have in the first line headers, where <?=VERSION?> takes :<br/>
<b>first name</b>, <b>family name</b>, <b>e-mail</b> and <b>nickname</b> fields.
</li>
<li>
Gmail CSV – <b>MUST</b> have in the first line headers, where <?=VERSION?> takes :<br/>
<b>Name</b>, <b>Email</b> fields.
</li>
</ul>
<p>
<input type="radio" name="type" value="pine" /> <big>Pine addressbook</big><br/>
Usualy, pine stores addresses in <b>~/.addressbook</b>.
</td></tr>
<tr><td>
<input type="submit" value="import"/>
</td></tr>
</table>
</form>
<?
}
else{
$sort = get_var('sort');
if(is_true($sort))
$_SESSION['addressbook']->sort($sort);
if($standalone){
$title = 'Addressbook';
include(TMPLPATH."html_start.php");
}
?>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-new" class="bold">Add new contact</a>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-new-list" class="bold">Create new contacts list</a>
<a href="<?=$_SERVER['PHP_SELF']?>?action=addressbook-show-export-import" class="bold">Export / Import</a>
<br/>
<br/>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="action" value="addressbook-delete"/>
<table class="content hsides">
<tr><th colspan="6" class="title">Address Book</th></tr>
<?=$_SESSION['addressbook']->get_presentation()?>
<tr><td colspan="6">
<input type="button" value="check all" onclick="javascript:setChecked(this.form,'key',1)"/>
<input type="button" value="clear all" onclick="javascript:setChecked(this.form,'key',0)"/>
<input type="submit" value="delete" onclick="action.value='addressbook-delete'"/>
</td></tr>
</table>
</form>
<?
if($standalone) include(TMPLPATH."html_end.php");
}
?>