<?php
//****************************************************************************************
// Copyright (C) 2000 Koen de Boeve
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Version : MyPhPim-01.05
// Author : Koen de Boeve
// Contact: hide@address.com
//****************************************************************************************
if ( file_exists ( "conf" ) ) { $conf = "conf"; }
if ( file_exists ( "../conf" ) ) { $conf = "../conf"; }
include $conf . "/imap_conf.inc";
Class PilotCl {
//###############################################################################
// This function returns the name of the category according to its ID
Function GetCatNamePDB ( $categories, $id ) {
$numcat = count ( $categories );
$name = "";
for ( $i = 0; $i < $numcat; $i++ ) {
if ( $id == $i ) {
$name = $categories[$i];
}
}
return $name;
}
//###############################################################################
// This function returns an array of names of the categories
Function GetCategoriesPDB ( $filename ) {
global $root_path;
exec( "$root_path/bin/categories.pl --pdb=$filename 2>&1", $lines );
return $lines;
}
//###############################################################################
Function GetAddressPDB ( $filename ) {
global $root_path;
exec( "$root_path/bin/pdb2txt --pdb=$filename 2>&1", $lines );
$numlines = count ( $lines );
for ( $i = 0; $i < $numlines; $i++ ) {
$parts = explode ( ":", $lines[$i] );
$numparts = count ( $parts );
$entry->name = "";
$entry->firstname = "";
$entry->company = "";
$entry->telhome = "";
$entry->telwork = "";
$entry->telother = "";
$entry->main = "";
$entry->pager = "";
$entry->faxwork = "";
$entry->mobile = "";
$entry->email = "";
$entry->address = "";
$entry->city = "";
$entry->zip = "";
$entry->state = "";
$entry->country = "";
$entry->custom1 = "";
$entry->custom2 = "";
$entry->custom3 = "";
$entry->custom4 = "";
$entry->title = "";
$entry->note = "";
for ( $j = 0; $j < $numparts; $j++ ) {
$subpart = explode ( "=", $parts[$j] );
switch ( $subpart[0] ) {
case "name" :
$entry->name = $subpart[1];
break;;
case "firstname" :
$entry->firstname = $subpart[1];
break;;
case "company" :
$entry->company = $subpart[1];
break;;
case "telhome" :
$entry->telhome = $subpart[1];
break;;
case "telwork" :
$entry->telwork = $subpart[1];
break;;
case "telother" :
$entry->telother = $subpart[1];
break;;
case "main" :
$entry->main = $subpart[1];
break;;
case "pager" :
$entry->pager = $subpart[1];
break;;
case "faxwork" :
$entry->faxwork = $subpart[1];
break;;
case "mobile" :
$entry->mobile = $subpart[1];
break;;
case "email" :
$entry->email = $subpart[1];
break;;
case "address" :
$entry->address = $subpart[1];
break;;
case "city" :
$entry->city = $subpart[1];
break;;
case "zip" :
$entry->zip = $subpart[1];
break;;
case "state" :
$entry->state = $subpart[1];
break;;
case "country" :
$entry->country = $subpart[1];
break;;
case "title" :
$entry->title = $subpart[1];
break;;
case "custom1" :
$entry->custom1 = $subpart[1];
break;;
case "custom2" :
$entry->custom2 = $subpart[1];
break;;
case "custom3" :
$entry->custom3 = $subpart[1];
break;;
case "custom4" :
$entry->custom4 = $subpart[1];
break;;
case "note" :
$entry->note = $subpart[1];
break;;
case "id" :
$entry->id = $subpart[1];
break;;
case "cat1" :
$entry->cat1 = $subpart[1];
break;;
case "cat_name" :
$entry->cat_name = $subpart[1];
break;;
case "cat_id" :
$entry->cat_id = $subpart[1];
break;;
}
}
$pdb_addr[$i] = $entry;
}
return $pdb_addr;
}
//###############################################################################
function ArraySize( $Array ) {
$count = 0;
foreach( $Array as $Element ) {
if ( is_array ( $Element ) ) {
$count += ArraySize ( $Element );
} else {
$count++;
}
}
return $count;
}
//###############################################################################
Function ShowListPDB ( $filename ) {
global $user;
$categories = $this->GetCategoriesPDB ( $filename );
$list = $this->GetAddressPDB ( $filename );
$html = new HtmlCl;
$form = new FormCl;
$db = new DB;
$user_id = $db->UserId ( $user );
$num_addr = count ( $list );
$html->htmlheader ( "Palm Pilot",0 );
$strippedname = explode ( "_", $filename );
echo "<center><h2>Addresses from $strippedname[1]</h2>\n";
$form->init ( "main.php3", "post","pilot" );
echo "<table border=0>";
echo "<tr><td width=50> </td><td colspan=3><font size=-1><b>Sync only these categories: </b></font><br>";
$form->multiselect ( "selected_category[]", $categories, $categories, "", 2);
echo "</td><td></td><td></td><td></td></tr>";
$flag = 0;
echo "<tr bgcolor=dimgray><td align=center> </td><td align=center><font size=-1 color=white>ID</font></td><td align=center>";
echo "<font size=-1 color=white>Name</font></td><td align=center><font size=-1 color=white>Company</font></td>
<td align=center><font size=-1 color=white>title</font></td><td align=center><font size=-1 color=white>email</font></td> <td align=center><font size=-1 color=white>category</font></td><td align=center><font size=-1 color=white>flag</font></td>";
echo "</tr>";
for ( $l = 0; $l < $num_addr; $l++ ) {
if ( $flag == 0 ) {
$bgcolor = "lightgrey";
$flag = 1;
} else {
$bgcolor = "white";
$flag = 0;
}
$entry = $list[$l];
//See if we allready have this record in our database
$query = "SELECT * FROM addresses_pilot WHERE pilot_id=$entry->id AND owner=$user_id";
$result = $db->query ( $query );
$numrows = $db->numrows ( $result );
if ( $numrows > 0 ) {
$db_id = $db->result ( $result, 0, "pilot_id" );
} else {
$db_id = FALSE;
}
$entry->fl = "N";
$flcolor = "red";
if ( $db_id == $entry->id ) {
$entry->fl = "U";
$flcolor = "blue";
}
$entry->cat_name = $this->GetCatNamePDB ( $categories, $entry->cat1 );
echo "<tr bgcolor=$bgcolor>";
echo "<td align=center><font size=-1>";
$form->checkbox ( $entry->id, 0, 0 );
echo "</font></td>";
if ( $entry->id ) {
echo "<td><font size=-1>$entry->id</td>";
} else {
echo "<td><font size=-1> </td>";
}
if ( $entry->name ) {
echo "<td><font size=-1>$entry->name";
} else {
echo "<td><font size=-1> ";
}
if ( $entry->firstname ) {
echo " $entry->firstname</font></td>";
} else {
echo " </font></td>";
}
if ( $entry->company ) {
echo "<td><font size=-1>$entry->company</font></td>";
} else {
echo "<td><font size=-1> </font></td>";
}
if ( $entry->title ) {
echo "<td><font size=-1>$entry->title</font></td>";
} else {
echo "<td><font size=-1> </font></td>";
}
if ( $entry->email ) {
echo "<td><font size=-1>$entry->email</font></td>";
} else {
echo "<td><font size=-1> </font></td>";
}
if ( $entry->cat_name ) {
echo "<td><font size=-1>$entry->cat_name</font></td>";
} else {
echo "<td><font size=-1> </font></td>";
}
echo "<td><font size=-1 color=$flcolor>$entry->fl</font></td>";
echo "</tr>";
}
$form->hidden ( "filename", $filename );
$form->hidden ( "fl", $entry->fl );
//$form->hidden ( "menu", "pilot" );
echo "<tr><td>";
$form->submit ( "step1", "Add To DB" );
echo "</td></tr>";
echo "</table>";
$form->close();
echo "</center>";
$html->htmlfooter();
}
}
?>