From cb2c085f9eb1cc3d8f5da074ff9795a50b843db0 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Tue, 14 Dec 2010 16:31:15 +0100 Subject: [PATCH] [FIX, IMP] crm/scripts : maintenance of the php script, add a contact form bzr revid: tfr@openerp.com-20101214153115-bh7sy2ofgt97tvin --- addons/crm/scripts/php/countrylist.php | 186 +++++++------- addons/crm/scripts/php/crmlead.php | 328 +++++++++++-------------- addons/crm/scripts/php/form.php | 74 ++++++ 3 files changed, 309 insertions(+), 279 deletions(-) create mode 100644 addons/crm/scripts/php/form.php diff --git a/addons/crm/scripts/php/countrylist.php b/addons/crm/scripts/php/countrylist.php index 857bda4fa9b..478947623c6 100644 --- a/addons/crm/scripts/php/countrylist.php +++ b/addons/crm/scripts/php/countrylist.php @@ -1,103 +1,105 @@ addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($user, "string")); - $msg->addParam(new xmlrpcval($pass, "string")); + include("xmlrpc.inc"); + + //Change to fit your configuration + $user = "admin"; + $password = "a"; + $db = "db_1"; + $serverUri = "http://localhost:8069/xmlrpc/"; + + + $client = new xmlrpc_client($serverUri.'common'); + + $msg = new xmlrpcmsg('login'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($user, "string")); + $msg->addParam(new xmlrpcval($password, "string")); - $res = &$client->send($msg); + $res = &$client->send($msg); - if(!$res->faultCode()){ - - $id = $res->value()->scalarval(); + if(!$res->faultCode()){ + + $id = $res->value()->scalarval(); - $client = new xmlrpc_client($serverUri.'object'); + $client = new xmlrpc_client($serverUri.'object'); - $key = array(new xmlrpcval(array(new xmlrpcval("id", "string"), - new xmlrpcval(">", "string"), - new xmlrpcval(0, "int")),"array"),); - - - - $msg = new xmlrpcmsg('execute'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($id, "int")); - $msg->addParam(new xmlrpcval($pass, "string")); - $msg->addParam(new xmlrpcval("res.country","string")); - $msg->addParam(new xmlrpcval("search", "string")); - $msg->addParam(new xmlrpcval($key, "array")); - $msg->addParam(new xmlrpcval(0, "int")); - $msg->addParam(new xmlrpcval(0, "int")); - $msg->addParam(new xmlrpcval("id ASC", "string")); - - $res = &$client->send($msg); + $key = array(new xmlrpcval(array(new xmlrpcval("id", "string"), + new xmlrpcval(">", "string"), + new xmlrpcval(0, "int")),"array"),); + + + + $msg = new xmlrpcmsg('execute'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($id, "int")); + $msg->addParam(new xmlrpcval($password, "string")); + $msg->addParam(new xmlrpcval("res.country","string")); + $msg->addParam(new xmlrpcval("search", "string")); + $msg->addParam(new xmlrpcval($key, "array")); + $msg->addParam(new xmlrpcval(0, "int")); + $msg->addParam(new xmlrpcval(0, "int")); + $msg->addParam(new xmlrpcval("id ASC", "string")); + + $res = &$client->send($msg); - if(!$res->faultCode()) - { - $val = $res->value()->scalarval(); - - $ides = array(); - - for ($i=0 ; $iscalarval(), "int")); - } - - $client = new xmlrpc_client($serverUri.'object'); - - $fields = array(new xmlrpcval("code", "string"), new xmlrpcval("name", "string")); - - $msg = new xmlrpcmsg('execute'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($id, "int")); - $msg->addParam(new xmlrpcval($pass, "string")); - $msg->addParam(new xmlrpcval("res.country","string")); - $msg->addParam(new xmlrpcval("read", "string")); - $msg->addParam(new xmlrpcval($ides, "array")); - $msg->addParam(new xmlrpcval($fields, "array")); + if(!$res->faultCode()) + { + $val = $res->value()->scalarval(); + + $ides = array(); + + for ($i=0 ; $iscalarval(), "int")); + } + + $client = new xmlrpc_client($serverUri.'object'); + + $fields = array(new xmlrpcval("code", "string"), new xmlrpcval("name", "string")); + + $msg = new xmlrpcmsg('execute'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($id, "int")); + $msg->addParam(new xmlrpcval($password, "string")); + $msg->addParam(new xmlrpcval("res.country","string")); + $msg->addParam(new xmlrpcval("read", "string")); + $msg->addParam(new xmlrpcval($ides, "array")); + $msg->addParam(new xmlrpcval($fields, "array")); - $res = &$client->send($msg); - - if (!$res->faultCode()) - { - $val = $res->value()->scalarval(); - - $select =' + '; + + for ($i=0; $iscalarval(); + $select .= ''; + } + + $select .= ''; + + echo $select; + } + else + { + echo "Country not getting"; + } + } + else + { + echo "Country list id empty"; + } + } + else + { + echo "connection not establish"; + } - for ($i=0; $iscalarval(); - $select .= ''; - } - - $select .= ''; - - echo $select; - } - else - { - echo "Country not getting"; - } - } - else - { - echo "Country list id empty"; - } - } - else - { - echo "connection not establish"; - } - exit; ?> diff --git a/addons/crm/scripts/php/crmlead.php b/addons/crm/scripts/php/crmlead.php index 91cfe7649ed..12c43085a14 100644 --- a/addons/crm/scripts/php/crmlead.php +++ b/addons/crm/scripts/php/crmlead.php @@ -1,201 +1,155 @@ to = $to; - $this->subject = $sub; - } - - function mailTo($post) - { - if (!empty($post)) - { - - if (empty($this->to)) - { - $this->to = 'sales@tinyerp.com'; - } - - if (empty($this->subject)) - { - $this->subject = 'Contact form information'; - } + private $subject = '', $to = ''; + + function __construct($to, $sub) + { + $this->to = $to; + $this->subject = $sub; + } + - $body = ' - - - - - '; - - foreach ($post as $key => $value) - { - $body .= " - - - - "; - } - - $body .= '
$key:$value
'; - - $header = 'MEME-version : 1.0'."\r\n"; - $header .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; - $header .= 'From: '.$post['name'].' <'.$post['email'].'>'."\r\n"; - $header .= 'Reply-To: '.$post['name'].' <'.$post['email'].'>'."\r\n"; - $header .= 'Return-Path: '.$post['name'].' <'.$post['email'].'>'."\r\n"; - - if (mail($this->to, $this->subject, $body, $header)) - { - echo "

Thank You, Your information has been successfully submitted.


We will be in touch very soon.

"; - - } - else - { - echo "

Sorry, Due to some problem Your information has not been submitted.

"; - } - - } - } - - function xmlCallTo($usr, $password, $database, $server, $post) - { - $user = $usr; - $pass = $password; - $db = $database; - $server_url = $server; //'http://localhost:8069/xmlrpc/' - - $client = new xmlrpc_client($server_url.'common'); - - $msg = new xmlrpcmsg('login'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($user, "string")); - $msg->addParam(new xmlrpcval($pass, "string")); + function xmlCallTo($usr, $password, $database, $server, $post) + { + $user = $usr; + $pass = $password; + $db = $database; + $server_url = $server; //'http://localhost:8069/xmlrpc/' + + $client = new xmlrpc_client($server_url.'common'); + + $msg = new xmlrpcmsg('login'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($user, "string")); + $msg->addParam(new xmlrpcval($pass, "string")); - $res = &$client->send($msg); - - if(!$res->faultCode()){ - - $val = $res->value(); - $id = $val->scalarval(); + $res = &$client->send($msg); + + if(!$res->faultCode()){ + + $val = $res->value(); + $id = $val->scalarval(); - if (empty($id)){ - - echo "Connection error = "; - exit; - } - else - { - $client2 = new xmlrpc_client($server_url.'object'); + if (empty($id)){ + + echo "Connection error = "; + exit; + } + else + { + $client2 = new xmlrpc_client($server_url.'object'); + $key = array(new xmlrpcval(array(new xmlrpcval("code", "string"), new xmlrpcval("=", "string"), new xmlrpcval($post['country'], "string")),"array"),); + $msg = new xmlrpcmsg('execute'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($id, "int")); + $msg->addParam(new xmlrpcval($pass, "string")); + $msg->addParam(new xmlrpcval("res.country","string")); + $msg->addParam(new xmlrpcval("search", "string")); + $msg->addParam(new xmlrpcval($key, "array")); + $msg->addParam(new xmlrpcval(0, "int")); + $msg->addParam(new xmlrpcval(1, "int")); + + $res = &$client2->send($msg); + + $val = $res->value()->scalarval(); + + $countryId = $val[0]->scalarval(); + + $val = array ("name" => new xmlrpcval($post['company'],"string"), + "email_from" => new xmlrpcval($post['email'], "string"), + "phone" => new xmlrpcval($post['phone'], "string"), + "partner_name" => new xmlrpcval($post['name'], "string"), + "function" => new xmlrpcval($post["jobtitle"], "string"), + "zip" => new xmlrpcval($post['zip'], "string"), + "stage_id" => new xmlrpcval(2, "int"), + "city" => new xmlrpcval($post['city'], "string"), + "country_id" => new xmlrpcval($countryId, "int"), + "state" => new xmlrpcval("draft", "string"), + "user_id" => new xmlrpcval(false, "boolean"), + "description" => new xmlrpcval("No.of Employees: ".$post['employees']."\nState: ".$post['state']."\nIndustry: ".$post['industry']."\nAbout: ".$post['about'], "string") + ); + + $msg = new xmlrpcmsg('execute'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($id, "int")); + $msg->addParam(new xmlrpcval($pass, "string")); + $msg->addParam(new xmlrpcval("crm.lead", "string")); + $msg->addParam(new xmlrpcval("create", "string")); + $msg->addParam(new xmlrpcval($val, "struct")); + + + $res2 = &$client2->send($msg); + + if(!$res2->faultCode()) + { + $readVal = $res2->value()->scalarval(); + + if (!empty($readVal)) + { + $val = array ( "description" => new xmlrpcval("About: ".$post['about']), + "model_id" => new xmlrpcval(276, "int"), + "res_id" => new xmlrpcval($readVal,"int"), + "email_from" => new xmlrpcval($post['email'], "string"), + "email_to" => new xmlrpcval("sales@openerp.com", "string") + ); - $key = array(new xmlrpcval(array(new xmlrpcval("code", "string"), new xmlrpcval("=", "string"), new xmlrpcval($post['country'], "string")),"array"),); - $msg = new xmlrpcmsg('execute'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($id, "int")); - $msg->addParam(new xmlrpcval($pass, "string")); - $msg->addParam(new xmlrpcval("res.country","string")); - $msg->addParam(new xmlrpcval("search", "string")); - $msg->addParam(new xmlrpcval($key, "array")); - $msg->addParam(new xmlrpcval(0, "int")); - $msg->addParam(new xmlrpcval(1, "int")); - - $res = &$client2->send($msg); - - $val = $res->value()->scalarval(); - - $countryId = $val[0]->scalarval(); - - $val = array ("name" => new xmlrpcval($post['company'],"string"), - "title" => new xmlrpcval($post['salutation'], "string"), - "email_from" => new xmlrpcval($post['email'], "string"), - "phone" => new xmlrpcval($post['phone'], "string"), - "partner_name" => new xmlrpcval($post['name'], "string"), - "function" => new xmlrpcval($post["jobtitle"], "string"), - "zip" => new xmlrpcval($post['zip'], "string"), - "stage_id" => new xmlrpcval(6, "int"), - "city" => new xmlrpcval($post['city'], "string"), - "country_id" => new xmlrpcval($countryId, "int"), - "state" => new xmlrpcval("draft", "string"), - "user_id" => new xmlrpcval(false, "boolean"), - "description" => new xmlrpcval("No.of Employees: ".$post['employees']."\nState: ".$post['state']."\nIndustry: ".$post['industry']."\nReasons: ".$post['reasons']."\nAbout: ".$post['about']."\nQuestions: ".stripslashes($post['questions'])."\nUpdate: ".$post['update'], "string") - ); - - $msg = new xmlrpcmsg('execute'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($id, "int")); - $msg->addParam(new xmlrpcval($pass, "string")); - $msg->addParam(new xmlrpcval("crm.lead", "string")); - $msg->addParam(new xmlrpcval("create", "string")); - $msg->addParam(new xmlrpcval($val, "struct")); - - - $res2 = &$client2->send($msg); - - if(!$res2->faultCode()) - { - $readVal = $res2->value()->scalarval(); - - if (!empty($readVal)) - { - $val = array ( "description" => new xmlrpcval("About: ".$post['about']."\nQuestions: ".$post['questions']), - "model_id" => new xmlrpcval(276, "int"), - "res_id" => new xmlrpcval($readVal,"int"), - "email_from" => new xmlrpcval($post['email'], "string"), - "email_to" => new xmlrpcval("sales@openerp.com", "string") - ); + + $msg = new xmlrpcmsg('execute'); + $msg->addParam(new xmlrpcval($db, "string")); + $msg->addParam(new xmlrpcval($id, "int")); + $msg->addParam(new xmlrpcval($pass, "string")); + $msg->addParam(new xmlrpcval("crm.case.history", "string")); + $msg->addParam(new xmlrpcval("create", "string")); + $msg->addParam(new xmlrpcval($val, "struct")); + + $res2 = &$client2->send($msg); - - $msg = new xmlrpcmsg('execute'); - $msg->addParam(new xmlrpcval($db, "string")); - $msg->addParam(new xmlrpcval($id, "int")); - $msg->addParam(new xmlrpcval($pass, "string")); - $msg->addParam(new xmlrpcval("crm.case.history", "string")); - $msg->addParam(new xmlrpcval("create", "string")); - $msg->addParam(new xmlrpcval($val, "struct")); - - $res2 = &$client2->send($msg); - - //echo "
Successfully created lead"; - echo "

Thank You for your interest in openerp, we'll respond to your request shortly.


"; - if(strstr($post["about"],"Book")) { - echo ''; - } - } - else - { - echo "
Lead is not created"; - } - } - else - { - echo "
Problem in message sending for create lead"; - } - } - } - else - { - echo "
Connection not established"; - } - } + //echo "
Successfully created lead"; + echo "

Thank You for your interest in openerp, we'll respond to your request shortly.


"; + if(strstr($post["about"],"Book")) { + echo ''; + } + } + else + { + echo "
Lead is not created"; + } + } + else + { + echo "
Problem in message sending for create lead"; + } + } + } + else + { + echo "
Connection not established"; + } + } } - $arrData = array(); - $arrData = array_merge($arrData, (array)$_POST); - - $cnt = new Contact('sales5@openerp.com', 'Country: '.$arrData['country']. ' About: ' .$arrData['about']); - - /* This function use for sending mail on perticular mail account */ - /*$cnt->mailTo($arrData); */ - - /* This function use ceating lead in crm of opener erp database */ - $cnt->xmlCallTo('', '', '', '', $arrData); - - exit; + if(isset($_POST['country']) && $_POST['country'] != '') { + $arrData = array(); + $arrData = array_merge($arrData, (array)$_POST); + + $cnt = new Contact('sales5@openerp.com', 'Country: '.$arrData['country']. ' About: ' .$arrData['about']); + + /* This function use for sending mail on perticular mail account */ + /*$cnt->mailTo($arrData); */ + + /* This function use ceating lead in crm of opener erp database */ + //Change to fit your configuration + $cnt->xmlCallTo('admin', 'a', 'db_1', 'http://localhost:8069/xmlrpc/', $arrData); + } + else { + echo 'please fill the form at form.php'; + } + + exit; ?> + diff --git a/addons/crm/scripts/php/form.php b/addons/crm/scripts/php/form.php new file mode 100644 index 00000000000..2d255e87cb3 --- /dev/null +++ b/addons/crm/scripts/php/form.php @@ -0,0 +1,74 @@ + + +Contact form + + +

Contact Form

+
+ +
+ +
+ +
+ +
+ + + + +
+ +
+
+
+ + +
+ + +
+

+ +

+

+ +

+
+ + + + + + + + +