NAVIGATION
Home
Gallery
Java
Linux
Web
Scripts And Utilities
Mobile And Sms
Misc
Contact
pixelWIKI
Nabaz Tag




<<

Schedule World Round Cube Contacts Sync


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
<?php
## Author christian.simon  simon----|a-t|---swine.de
## Modified by Chris Hembrow
## March 2009
## Copy your Scheduleworld Addressbook to your roundcube webmail
## You need the PHP-Pear Module Contact_Vcard_Parse


define(SW_USER,"sw account");           #Your Scheduleworld account
define(SW_PASS,"sw password");             #Your password for Scheduleworld account
define(DB_USER,"roundcube");            #Your MySQL user for roundcube
define(DB_PASS,"password");            #Your MySQL password for roundcube
define(DB_BASE,"roundcube");            #Your MySQL database for roundcube
define(DB_HOST,"localhost");            #Your MySQL host for roundcube
define(CUBE_ID,"roundcube user id");       #The userid of your roundcube user
# FILTER by category, leave empty to select all. Ensure UPPERCASE for matches to work
$FILTER = array( "MISC", "FAMILY", "PERSONAL" );

function connectdb($db_host,$db_user,$db_pass,$datab=false)
{
        iconv_set_encoding("input_encoding", "UTF-8");
        iconv_set_encoding("internal_encoding", "UTF-8");
        iconv_set_encoding("output_encoding", "UTF-8");
        if (!$db = @mysql_connect($db_host,$db_user,$db_pass)){
        return false;
        }
        else{
                mysql_query("SET CHARACTER SET utf8");
                mysql_query("SET NAMES utf8");
                setlocale(LC_ALL, 'de_DE.UTF-8');
                if($datab AND !mysql_select_db($datab,$db)) return false;
                else return true;
        }
}
function getVcfSw($sw_user,$sw_pass){
        $first_site = file("http://www.scheduleworld.com/tg/card/getContactsVCF.jsp");
        foreach ($first_site as $first_line)
        {
                if(strstr($first_line,"action") and strstr($first_line,"login")){
                        $session = preg_replace("/.*action="(.*)" id=.*/","$1",$first_line);
                }
        }
        $login_commands = "?continue=http%3A%2F%2Fwebview.ScheduleWorld.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&rm=false&j_username=".urlencode($sw_user)."&j_password=".urlencode($sw_pass)."&signin=Sign+in";
        #echo "http://www.scheduleworld.com/tg/card/".trim($session).$login_commands;
        $return = file_get_contents("http://www.scheduleworld.com/tg/card/".trim($session).$login_commands);
        if(strstr($return,"VCARD"))
        {
                return $return;
        }
        else
        {
                return false;
        }
}

if(!connectdb(DB_HOST,DB_USER,DB_PASS,DB_BASE))
{
        die("MySQL connection failed");
}
else
{
        $data_vcards = getVcfSw(SW_USER,SW_PASS);
        if(!$data_vcards)
        {
                die("Failed getting VCARDS from Scheduleworld");
        }
        else
        {
                if(!require_once ("Contact_Vcard_Parse.php"))
                {
                        die("Contact_Vcard_Parse.php not found. Please install the Pear Module");
                }
                else
                {
                        $parse = new Contact_Vcard_Parse();
                        $cardinfo = $parse->fromText($data_vcards);
                        mysql_query("DELETE FROM `contacts` WHERE `user_id` = '".CUBE_ID."'");
                        $added = 0;
                        foreach($cardinfo as $card)
                        {
                                if ( array_key_exists("EMAIL", $card) ) {

                                        $add = count( $FILTER ) == 0;
                                        if ( !$add ) {
                                                $cats = $card["CATEGORIES"]["0"]["value"]["0"];
                                                foreach ( $cats as $cat ) {
                                                        if ( in_array( strtoupper( $cat ), $FILTER ) ) {
                                                                $add = true;
                                                        }
                                                }
                                        }
                                        if ( $add ) {
#                                               echo $card["N"]["0"]["value"]["0"]["0"].", ".$card["N"]["0"]["value"]["1"]["0"].": ".$card["EMAIL"]["0"]["value"]["0"]["0"] . "n";
                                                $ret = false;
                                                $ret = mysql_query("INSERT INTO contacts (contact_id, changed, del, name, email, firstname, surname, vcard, user_id) VALUES (NULL, '0000-00-00 00:00:00', '0', '".$card["N"]["0"]["value"]["0"]["0"].", ".$card["N"]["0"]["value"]["1"]["0"]."', '".$card["EMAIL"]["0"]["value"]["0"]["0"]."', '".$card["N"]["0"]["value"]["1"]["0"]."', '".$card["N"]["0"]["value"]["0"]["0"]."', '', '".CUBE_ID."')");
                                                if ( $ret ) {
                                                        $added ++;
#                                                       echo "insertedn";
                                                } else {
#                                                       echo "failed to insertn";
                                                }
                                        }
                                }
                        }
                        echo "finished! Added " . $added  . " rows";
                }
        }
}

?>