~qtheuret/unifield-addons/ref_addons

« back to all changes in this revision

Viewing changes to crm/scripts/php/crmlead.php

  • Committer: Quentin THEURET
  • Date: 2014-03-05 12:14:13 UTC
  • mfrom: (4612.2.2 unifield-addons)
  • Revision ID: qt@tempo-consulting.fr-20140305121413-qgiq1n9ujvojbtmv
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
    include("xmlrpc.inc");      
4
 
 
5
 
class Contact
6
 
{
7
 
    private $subject = '', $to = '';
8
 
    
9
 
    function __construct($to, $sub)
10
 
    {
11
 
        $this->to = $to;
12
 
        $this->subject = $sub;
13
 
    }
14
 
        
15
 
 
16
 
    function xmlCallTo($usr, $password, $database, $server, $post)
17
 
    {
18
 
        $user = $usr;
19
 
        $pass = $password;
20
 
        $db = $database;
21
 
        $server_url = $server; //'http://localhost:8069/xmlrpc/'
22
 
        
23
 
        $client = new xmlrpc_client($server_url.'common');
24
 
        
25
 
        $msg = new xmlrpcmsg('login');
26
 
        $msg->addParam(new xmlrpcval($db, "string"));
27
 
        $msg->addParam(new xmlrpcval($user, "string"));
28
 
        $msg->addParam(new xmlrpcval($pass, "string"));
29
 
 
30
 
 
31
 
        $res =  &$client->send($msg);
32
 
        
33
 
        if(!$res->faultCode()){
34
 
            
35
 
            $val = $res->value();   
36
 
            $id = $val->scalarval();
37
 
 
38
 
            if (empty($id)){
39
 
                
40
 
                echo "Connection error = ";
41
 
                exit;
42
 
            }
43
 
            else
44
 
            {
45
 
                $client2 = new xmlrpc_client($server_url.'object');
46
 
                $key = array(new xmlrpcval(array(new xmlrpcval("code", "string"), new xmlrpcval("=", "string"), new xmlrpcval($post['country'], "string")),"array"),);
47
 
                $msg = new xmlrpcmsg('execute');
48
 
                $msg->addParam(new xmlrpcval($db, "string"));
49
 
                $msg->addParam(new xmlrpcval($id, "int"));
50
 
                $msg->addParam(new xmlrpcval($pass, "string"));
51
 
                $msg->addParam(new xmlrpcval("res.country","string"));
52
 
                $msg->addParam(new xmlrpcval("search", "string"));
53
 
                $msg->addParam(new xmlrpcval($key, "array"));
54
 
                $msg->addParam(new xmlrpcval(0, "int"));
55
 
                $msg->addParam(new xmlrpcval(1, "int"));
56
 
                
57
 
                $res = &$client2->send($msg);
58
 
                
59
 
                $val = $res->value()->scalarval();
60
 
                
61
 
                $countryId = $val[0]->scalarval();
62
 
                
63
 
                $val = array ("name" => new xmlrpcval($post['company'],"string"),
64
 
                              "email_from" => new xmlrpcval($post['email'], "string"),
65
 
                              "phone" => new xmlrpcval($post['phone'], "string"),
66
 
                              "partner_name" => new xmlrpcval($post['name'], "string"),
67
 
                              "function" => new xmlrpcval($post["jobtitle"], "string"),
68
 
                              "zip" => new xmlrpcval($post['zip'], "string"),
69
 
                              "stage_id" => new xmlrpcval(2, "int"),
70
 
                              "city" => new xmlrpcval($post['city'], "string"),
71
 
                              "country_id" => new xmlrpcval($countryId, "int"),
72
 
                              "state" => new xmlrpcval("draft", "string"),
73
 
                              "user_id" => new xmlrpcval(false, "boolean"),
74
 
                              "description" => new xmlrpcval("No.of Employees: ".$post['employees']."\nState: ".$post['state']."\nIndustry: ".$post['industry']."\nAbout: ".$post['about'], "string")
75
 
                            );
76
 
                                                
77
 
                $msg = new xmlrpcmsg('execute');
78
 
                $msg->addParam(new xmlrpcval($db, "string"));
79
 
                $msg->addParam(new xmlrpcval($id, "int"));
80
 
                $msg->addParam(new xmlrpcval($pass, "string"));
81
 
                $msg->addParam(new xmlrpcval("crm.lead", "string"));
82
 
                $msg->addParam(new xmlrpcval("create", "string"));
83
 
                $msg->addParam(new xmlrpcval($val, "struct"));
84
 
                                
85
 
                
86
 
                $res2 = &$client2->send($msg);
87
 
                
88
 
                if(!$res2->faultCode())
89
 
                {
90
 
                    $readVal = $res2->value()->scalarval();
91
 
                    
92
 
                    if (!empty($readVal))
93
 
                    {
94
 
                        $val = array ( "description" => new xmlrpcval("About: ".$post['about']),
95
 
                                "model_id" => new xmlrpcval(276, "int"),
96
 
                                "res_id" => new xmlrpcval($readVal,"int"),
97
 
                                "email_from" => new xmlrpcval($post['email'], "string"),
98
 
                                "email_to" => new xmlrpcval("sales@openerp.com", "string")
99
 
                                );
100
 
 
101
 
                        
102
 
                        $msg = new xmlrpcmsg('execute');
103
 
                        $msg->addParam(new xmlrpcval($db, "string"));
104
 
                        $msg->addParam(new xmlrpcval($id, "int"));
105
 
                        $msg->addParam(new xmlrpcval($pass, "string"));
106
 
                        $msg->addParam(new xmlrpcval("crm.case.history", "string"));
107
 
                        $msg->addParam(new xmlrpcval("create", "string"));
108
 
                        $msg->addParam(new xmlrpcval($val, "struct"));
109
 
                        
110
 
                        $res2 = &$client2->send($msg);
111
 
 
112
 
                        //echo "<br />Successfully created lead";
113
 
                        echo "<br /><h3>Thank You for your interest in openerp, we'll respond to your request shortly.</h3><br />";
114
 
                        if(strstr($post["about"],"Book")) {
115
 
                            echo '<script>window.location="http://www.openerp.com/index.php?option=com_content&amp;id=54"</script>';
116
 
                        }
117
 
                    }
118
 
                    else
119
 
                    {
120
 
                        echo "<br />Lead is not created";
121
 
                    }
122
 
                }
123
 
                else
124
 
                {
125
 
                    echo "<br />Problem in message sending for create lead";
126
 
                }
127
 
            }           
128
 
        }
129
 
        else
130
 
        {
131
 
            echo "<br />Connection not established";
132
 
        }
133
 
    }
134
 
}
135
 
 
136
 
    if(isset($_POST['country']) && $_POST['country'] != '') {
137
 
        $arrData = array();
138
 
        $arrData = array_merge($arrData, (array)$_POST);
139
 
        
140
 
        $cnt = new Contact('sales5@openerp.com', 'Country: '.$arrData['country']. ' About: ' .$arrData['about']);
141
 
        
142
 
        /* This function use for sending mail on perticular mail account */
143
 
        /*$cnt->mailTo($arrData); */
144
 
        
145
 
        /* This function use ceating lead in crm of opener erp database */
146
 
        //Change to fit your configuration
147
 
        $cnt->xmlCallTo('admin', 'a', 'db_1', 'http://localhost:8069/xmlrpc/', $arrData);
148
 
    }
149
 
    else {
150
 
        echo 'please fill the form at <a href="form.php">form.php</a>';
151
 
    }
152
 
    
153
 
    exit;
154
 
?>
155