ales
Joined: 13 Jun 2006
Posts: 18
Location: Slovenia
|
| Posted: Thu Jul 27, 2006 5:57 pm Post subject: Auto insert Leads from Email 4.2.x |
|
|
Auto INSERT Leads from Email message.
Something for Email module & Leads.
Between the lines you will notice that can be rearanged for anythin else you migh want to insert.
OK, procedure is the Copy Paste from my code.
1. You have to add navigation in SQUIRRELMAIL module file ../modules/squirrelmail-1.4.4/functions/mailbox_display.php
2. Replace all lines of navigation in function mail_message_listing_beginning()
..
<td width="20%" class="formHeader">'.$mod_strings['LBL_WEBMAILS_LIST'].'</td>
<td><input type="button" class="button" name="fetchmail" value="'.$mod_strings['LBL_FETCH_MY_MAILS'].'" onclick=document.location.href="index.php?module=squirrelmail-1.4.4&action=redirect&smodule=WEBMAILS";></input></td>
<td><input type="SUBMIT" name="addToVtigerCRMButton" value="'.$mod_strings['LBL_ADD_TO_VTIGER_CRM'].'" class="button"></input></td>
<td width="50%"><input type="SUBMIT" name="addToLeadsButton" value="'.$mod_strings['LBL_ADD_TO_LEADS'].'" class="button"></input></td>
<td><input type="SUBMIT" name="markRead" value="'.$mod_strings['LBL_READ'].'" class="button"></input> </td>
<td align="right"><input type="SUBMIT" name="markUnread" value="'.$mod_strings['LBL_UNREAD'].'" class="button"></input> </td>
<td align="right"><input type="SUBMIT" name="delete" value="'.$mod_strings['LBL_DELETE'].'" class="button"></input> </td>
..
3. You have to add sign new email, with subject starting with"SIGN-..." in the same file as above in function printMessageInfo , look fo foreach ($index_order as $index_order_part) { .. code:
..
//Prepare AutoCheck for "SIGN-..." emails
$res = strpos(strtoupper($subject), "SIGN-");
if($res === 0){
if($bold != "")
$checkLeads = 'checked';
else
$checkLeads = '';
}else{
$checkLeads = '';
}
if($checked) $checkLeads = $checked;
..
case 1: /* checkbox */
echo html_tag( 'td',
"<input type=checkbox name="msg[$t]" value="".$msg['ID'].""$checkLeads>",
'center',
$hlt_color );
//"<input type=checkbox name="msg[$t]" value="".$msg['ID'].""$checked>",
break;
..
4. Change file ../modules/squirrelmail-1.4.4/move_messages.php by adding in header:
..
require_once('include/database/PearDatabase.php');
..
5. In the sme file add function after global and IF code
..
/**
* Apply message into Leads tables.
*
* @return nothing.
*/
function leads_2db( $id, $salutation, $firstname, $lastname, $company, $code, $city, $lane, $phone, $mobile, $email, $description ){
//get global data
$date_created = date('YmdHis');
$date_modified = date('YmdHis');
global $current_user;
$creator_user_id = $current_user->id;
$owner_user_id = $current_user->id;
global $adb;
// insert into CRMENTITY
$sql = "insert into crmentity (";
$sql .= "crmid,smcreatorid,smownerid,modifiedby,setype,description,createdtime,modifiedtime,viewedtime,status,version,presence,deleted";
$sql .= ") values(";
$sql .= "$id,$creator_user_id,$owner_user_id,0,'Leads','$description',$date_created,$date_modified,NULL,NULL,0,1,0";
$sql .= ")";
$result = $adb->query($sql);
// insert into LEADDETAILS
$sql = "insert into leaddetails (";
$sql .= "leadid,email,interest,firstname,salutation,lastname,company,annualrevenue,industry,campaign,rating,leadstatus,leadsource,converted,designation,licencekeystatus,space,comments,priority,demorequest,partnercontact,productversion,product,maildate,nextstepdate,fundingsituation,purpose,evaluationstatus,transferdate,revenuetype,noofemployees,yahooid,assignleadchk";
$sql .= ") values(";
$sql .= "$id,'$email',NULL,'$firstname','$salutation','$lastname','$company',0,'-- empty --',NULL,'-- empty --','-- empty --','- empty --',0,'',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'','',0";
$sql .= ")";
$result = $adb->query($sql);
// insert into LEADADDRESS
$sql = "insert into leadaddress (";
$sql .= "leadaddressid,city,code,state,country,phone,mobile,fax,lane,leadaddresstype";
$sql .= ") values(";
$sql .= "$id,'$city','$code','','','$phone','$mobile','','$lane','Billing'";
$sql .= ")";
$result = $adb->query($sql);
// insert into LEADSUBDETAILS
$sql = "insert into leadsubdetails (";
$sql .= "leadsubscriptionid,currency,website,callornot,readornot,empct";
$sql .= ") values(";
$sql .= "$id,'Euro','',0,0,0";
$sql .= ")";
$result = $adb->query($sql);
// insert into LEADSCF
$sql = "insert into leadscf (";
$sql .= "leadid";
$sql .= ") values(";
$sql .= "$id";
$sql .= ")";
$result = $adb->query($sql);
return;
}
..
6. In the same file as above add line after sqgetGlobalVar()
..
sqgetGlobalVar('addToLeadsButton', $addToLeadsButton, SQ_POST);
..
7. In the same file as above where if(isset($addToVtigerCRMButton)).. is, add after IF another IF after second function
..
//Add To Leads CRM
if(isset($addToLeadsButton))
{
$msgsubject = array();
$msgfromemail = array();
$mbodies = array();
sqgetGlobalVar('mailbox', $mailbox);
for($k=0;$k< count($id);$k++)
{
$message = sqimap_get_message($imapConnection, $id[$k], $mailbox);
$header = $message->rfc822_header;
$ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
$body_message = getEntity($message, $ent_ar[0]);
$body = mime_fetch_body ($imapConnection, $id[$k], $ent_ar[0]);
$body = trim($body);
//you can modify to suit your needs or just delete if no special codes are used - from here..
//replacement of balcan special codes
$body = str_replace("=A9", "Š", $body);
$body = str_replace("=C8", "Č", $body);
$body = str_replace("=AE", "Ž", $body);
$body = str_replace("=B9", "š", $body);
$body = str_replace("=E8", "č", $body);
$body = str_replace("=BE", "ž", $body);
//replace CR codes
$body = str_replace(chr(10).chr(13), "//-nl-//", $body);
$body = quoted_printable_decode($body);
$body = str_replace("\n", "", $body);
$body = str_replace("\r", "", $body);
// ..to here
$explodedmessage = explode(";",$body);
$list = array();
foreach($explodedmessage as $e => $i){
if($e == 9){
$a = explode("//-nl-//", $i);
array_push($list, $a[0]);
array_push($list, $a[1]);
}else{
array_push($list, $i);
}
}
foreach($list as $i => $ii){
// required fields 0..9
if($i <= 9){
//salutation
if($i == 0){
$ii = str_replace("salutation=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_salutation = $ii;
}
//firstname
if($i == 1){
$ii = str_replace("firstname=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_firstname = $ii;
}
//lastname
if($i == 2){
$ii = str_replace("lastname=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_lastname = $ii;
}
//company
if($i == 3){
$ii = str_replace("company=", "", $ii);
$ii = str_replace('"', "", $ii);
if($ii == "") $ii = "-- Brez --";
$r_company = $ii;
}
//code
if($i == 4){
$ii = str_replace("code=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_code = $ii;
}
//city
if($i == 5){
$ii = str_replace("city=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_city = ltrim($ii);
}
//lane
if($i == 6){
$ii = str_replace("lane=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_lane = $ii;
}
//phone
if($i == 7){
$ii = str_replace("//-nl-//", " ", $ii);
$ii = str_replace("phone=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_phone = ltrim($ii);
}
//mobile
if($i == 8){
$ii = str_replace("mobile=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_mobile = ltrim($ii);
}
//email
if($i == 9){
$ii = str_replace("email=", "", $ii);
$ii = str_replace('"', "", $ii);
$r_email = $ii;
}
//echo $ii."<br>";
// xyz fields 10..
}else{
$ii = str_replace('"', "", $ii);
$r_description .= $ii."nr";
}
}
$r_id = $adb->getUniqueID("crmentity");
leads_2db( $r_id, $r_salutation, $r_firstname, $r_lastname, $r_company, $r_code, $r_city, $r_lane, $r_phone, $r_mobile, $r_email, $r_description );
}
header("Location: index.php?module=squirrelmail-1.4.4&action=right_main&smodule=WEBMAILS");
return;
}
..
8. Add to file ../squirrelmail-1.4.4/language/en_us.lang.php at the end
..
//For Add To Specific Module
'LBL_ADD_TO_LEADS'=>'Add to Leads',
..
THAT'S ALL
Function leads_2db( $id, $salutation, $firstname, $lastname, $company, $code, $city, $lane, $phone, $mobile, $email, $description )
takes these 11 parametrs:
$salutation, $firstname, $lastname, $company, $code, $city, $lane, $phone, $mobile, $email, $description
last parameter $description is all in one
This is an example of email that has arrived:
Subject begin:
Sign-...
:Subject end
Body begin:
salutation="mr";firstname="John";lastname="Schmid";company="VTIGER";code="007";city="Cleveland";lane="15th Street";phone="001 1111111";mobile="002123456";email="info@vtiger.com"[go to next line]
[empty line]
"Starost prvega otroka"= "17";"Starost drugegaotroka"="13";"Termin"="23-30.7"[don't go to new line, body must end here with "]
:Body end
Hope that not hard to implement in to your code.
Maybe in next few days there will be a patch online.
By Ales |
|