884 lines
30 KiB
PHP
884 lines
30 KiB
PHP
<?php
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
|
/*********************************************************************************
|
|
* SugarCRM Community Edition is a customer relationship management program developed by
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU Affero General Public License version 3 as published by the
|
|
* Free Software Foundation with the addition of the following permission added
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
|
*
|
|
* 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 Affero General Public License for more
|
|
* details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License along with
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301 USA.
|
|
*
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions
|
|
* of this program must display Appropriate Legal Notices, as required under
|
|
* Section 5 of the GNU Affero General Public License version 3.
|
|
*
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by
|
|
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
|
* technical reasons, the Appropriate Legal Notices must display the words
|
|
* "Powered by SugarCRM".
|
|
********************************************************************************/
|
|
|
|
/*********************************************************************************
|
|
|
|
* Description: Defines the Lead SugarBean Lead entity with the necessary
|
|
* methods and variables.
|
|
********************************************************************************/
|
|
|
|
require_once("include/SugarObjects/templates/company/Company.php");
|
|
|
|
// Lead is used to store lead information.
|
|
class Lead extends Company {
|
|
var $field_name_map = array();
|
|
// Stored fields
|
|
var $date_entered;
|
|
var $date_modified;
|
|
var $modified_user_id;
|
|
var $assigned_user_id;
|
|
var $annual_revenue;
|
|
var $billing_address_street;
|
|
var $billing_address_city;
|
|
var $billing_address_state;
|
|
var $billing_address_country;
|
|
var $billing_address_postalcode;
|
|
|
|
var $billing_address_street_2;
|
|
var $billing_address_street_3;
|
|
var $billing_address_street_4;
|
|
|
|
var $description;
|
|
var $email1;
|
|
var $email2;
|
|
var $email_opt_out;
|
|
var $invalid_email;
|
|
var $employees;
|
|
var $id;
|
|
var $industry;
|
|
var $name;
|
|
var $ownership;
|
|
var $parent_id;
|
|
var $phone_alternate;
|
|
var $phone_fax;
|
|
var $phone_office;
|
|
var $rating;
|
|
var $shipping_address_street;
|
|
var $shipping_address_city;
|
|
var $shipping_address_state;
|
|
var $shipping_address_country;
|
|
var $shipping_address_postalcode;
|
|
|
|
var $shipping_address_street_2;
|
|
var $shipping_address_street_3;
|
|
var $shipping_address_street_4;
|
|
|
|
var $campaign_id;
|
|
|
|
var $sic_code;
|
|
var $ticker_symbol;
|
|
var $lead_type;
|
|
var $website;
|
|
var $custom_fields;
|
|
|
|
var $created_by;
|
|
var $created_by_name;
|
|
var $modified_by_name;
|
|
|
|
// These are for related fields
|
|
var $opportunity_id;
|
|
var $case_id;
|
|
var $contact_id;
|
|
var $task_id;
|
|
var $note_id;
|
|
var $meeting_id;
|
|
var $call_id;
|
|
var $email_id;
|
|
var $member_id;
|
|
var $parent_name;
|
|
var $assigned_user_name;
|
|
var $lead_id = '';
|
|
var $lead_name = '';
|
|
var $bug_id ='';
|
|
var $module_dir = 'Leads';
|
|
var $emailAddress;
|
|
|
|
|
|
var $table_name = "leads";
|
|
var $object_name = "Lead";
|
|
var $importable = true;
|
|
var $new_schema = true;
|
|
// This is used to retrieve related fields from form posts.
|
|
var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'opportunity_id', 'bug_id', 'case_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id', 'parent_name', 'member_id'
|
|
);
|
|
var $relationship_fields = Array('opportunity_id'=>'opportunities', 'bug_id' => 'bugs', 'case_id'=>'cases',
|
|
'contact_id'=>'contacts', 'task_id'=>'tasks', 'note_id'=>'notes',
|
|
'meeting_id'=>'meetings', 'call_id'=>'calls', 'email_id'=>'emails','member_id'=>'members',
|
|
'project_id'=>'project',
|
|
);
|
|
|
|
//Meta-Data Framework fields
|
|
var $push_billing;
|
|
var $push_shipping;
|
|
|
|
function Lead() {
|
|
parent::Company();
|
|
|
|
$this->setupCustomFields('Leads');
|
|
|
|
foreach ($this->field_defs as $field)
|
|
{
|
|
if(isset($field['name']))
|
|
{
|
|
$this->field_name_map[$field['name']] = $field;
|
|
}
|
|
}
|
|
|
|
|
|
//Email logic
|
|
if (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type']) && $_REQUEST['parent_type'] == 'Emails'
|
|
&& !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails') {
|
|
$_REQUEST['parent_name'] = '';
|
|
$_REQUEST['parent_id'] = '';
|
|
}
|
|
}
|
|
|
|
function get_summary_text()
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
function get_contacts() {
|
|
return $this->get_linked_beans('contacts','Contact');
|
|
}
|
|
|
|
|
|
|
|
function clear_lead_case_relationship($lead_id='', $case_id='')
|
|
{
|
|
if (empty($case_id)) $where = '';
|
|
else $where = " and id = '$case_id'";
|
|
$query = "UPDATE cases SET lead_name = '', lead_id = '' WHERE lead_id = '$lead_id' AND deleted = 0 " . $where;
|
|
$this->db->query($query,true,"Error clearing lead to case relationship: ");
|
|
}
|
|
|
|
/**
|
|
* This method is used to provide backward compatibility with old data that was prefixed with http://
|
|
* We now automatically prefix http://
|
|
* @deprecated.
|
|
*/
|
|
function remove_redundant_http()
|
|
{ /*
|
|
if(preg_match("@http://@", $this->website))
|
|
{
|
|
$this->website = substr($this->website, 7);
|
|
}
|
|
*/
|
|
}
|
|
|
|
function fill_in_additional_list_fields()
|
|
{
|
|
parent::fill_in_additional_list_fields();
|
|
// Fill in the assigned_user_name
|
|
// $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
|
|
|
|
}
|
|
|
|
function fill_in_additional_detail_fields()
|
|
{
|
|
parent::fill_in_additional_detail_fields();
|
|
|
|
//rrs bug: 28184 - instead of removing this code altogether just adding this check to ensure that if the parent_name
|
|
//is empty then go ahead and fill it.
|
|
if(empty($this->parent_name) && !empty($this->id)){
|
|
$query = "SELECT a1.name from leads a1, leads a2 where a1.id = a2.parent_id and a2.id = '$this->id' and a1.deleted=0";
|
|
$result = $this->db->query($query,true," Error filling in additional detail fields: ");
|
|
|
|
// Get the id and the name.
|
|
$row = $this->db->fetchByAssoc($result);
|
|
|
|
if($row != null)
|
|
{
|
|
$this->parent_name = $row['name'];
|
|
}
|
|
else
|
|
{
|
|
$this->parent_name = '';
|
|
}
|
|
}
|
|
|
|
// Set campaign name if there is a campaign id
|
|
if( !empty($this->campaign_id)){
|
|
|
|
$camp = new Campaign();
|
|
$where = "campaigns.id='{$this->campaign_id}'";
|
|
$campaign_list = $camp->get_full_list("campaigns.name", $where, true);
|
|
$this->campaign_name = $campaign_list[0]->name;
|
|
}
|
|
|
|
require_once("include/ECM/EcmFormatPhoneNumber/EcmFormatPhoneNumber.php");
|
|
if($_REQUEST['action']=="DetailView"){
|
|
$this->phone_office = EcmFormatPhoneNumber($this->phone_office, "Lead", "Leads", $this->id);
|
|
$this->phone_alternate = EcmFormatPhoneNumber($this->phone_alternate, "Lead", "Leads", $this->id);
|
|
}
|
|
|
|
//create link to google maps
|
|
global $mod_strings;
|
|
$billing = '<a target="new" href="https://maps.google.com/?q='.$this->billing_address_country.'+'.$this->billing_address_city.'+'.$this->billing_address_street.'">'.substr($mod_strings['LBL_BILLING_ADDRESS'],0,strlen($mod_strings['LBL_BILLING_ADDRESS'])-1).'</a>';
|
|
$shippping = '<a target="new" href="https://maps.google.com/?q='.$this->shipping_address_country.'+'.$this->shipping_address_city.'+'.$this->shipping_address_street.'">'.substr($mod_strings['LBL_SHIPPING_ADDRESS'],0,strlen($mod_strings['LBL_SHIPPING_ADDRESS'])-1).'</a>';
|
|
$this->maps = $billing.'<br>'.$shippping;
|
|
}
|
|
|
|
function get_email_addresses($id,$module){
|
|
|
|
$w=mysql_query("select email_addresses.email_address as addr from email_addresses inner join email_addr_bean_rel on email_addresses.id=email_addr_bean_rel.email_address_id where email_addr_bean_rel.bean_module='".$module."' and email_addr_bean_rel.bean_id='".$id."' and email_addr_bean_rel.deleted='0'");
|
|
while($r=mysql_fetch_array($w)){
|
|
$addrs[]=$r['addr'];
|
|
}
|
|
return $addrs;
|
|
}
|
|
|
|
function get_list_view_data(){
|
|
|
|
$temp_array = parent::get_list_view_data();
|
|
|
|
$temp_array["ENCODED_NAME"] = $this->name;
|
|
|
|
if(!empty($this->billing_address_state))
|
|
{
|
|
$temp_array["CITY"] = $this->billing_address_city . ', '. $this->billing_address_state;
|
|
}
|
|
else
|
|
{
|
|
$temp_array["CITY"] = $this->billing_address_city;
|
|
}
|
|
$temp_array["BILLING_ADDRESS_STREET"] = $this->billing_address_street;
|
|
$temp_array["SHIPPING_ADDRESS_STREET"] = $this->shipping_address_street;
|
|
|
|
|
|
require_once("include/ECM/EcmFormatPhoneNumber/EcmFormatPhoneNumber.php");
|
|
if($_REQUEST['action']!="Popup"){
|
|
$temp_array['PHONE_OFFICE'] = EcmFormatPhoneNumber($temp_array['PHONE_OFFICE'], "Lead", "Leads", $this->id);
|
|
$temp_array['PHONE_ALTERNATE'] = EcmFormatPhoneNumber($temp_array['PHONE_ALTERNATE'], "Lead", "Leads", $this->id);
|
|
}
|
|
|
|
$temp_array['CUSTOM_WEBSITE'] = '<a href="http://'.$this->website.'" target="new">'.$this->website.'</a>';
|
|
if($_REQUEST['action']!="Popup"){
|
|
$temp_array['NAME']="<a target='_blank' href='index.php?module=Leads&action=DetailView&record=".$this->id."'>".$this->name."</a>";
|
|
}
|
|
return $temp_array;
|
|
}
|
|
/**
|
|
builds a generic search based on the query string using or
|
|
do not include any $this-> because this is called on without having the class instantiated
|
|
*/
|
|
function build_generic_where_clause ($the_query_string) {
|
|
$where_clauses = Array();
|
|
$the_query_string = $this->db->quote($the_query_string);
|
|
array_push($where_clauses, "leads.name like '$the_query_string%'");
|
|
if (is_numeric($the_query_string)) {
|
|
array_push($where_clauses, "leads.phone_alternate like '%$the_query_string%'");
|
|
array_push($where_clauses, "leads.phone_fax like '%$the_query_string%'");
|
|
array_push($where_clauses, "leads.phone_office like '%$the_query_string%'");
|
|
}
|
|
|
|
$the_where = "";
|
|
foreach($where_clauses as $clause)
|
|
{
|
|
if(!empty($the_where)) $the_where .= " or ";
|
|
$the_where .= $clause;
|
|
}
|
|
|
|
return $the_where;
|
|
}
|
|
|
|
|
|
function create_export_query(&$order_by, &$where, $relate_link_join='')
|
|
{
|
|
$custom_join = $this->getCustomJoin(true, true, $where);
|
|
$custom_join['join'] .= $relate_link_join;
|
|
$query = "SELECT
|
|
leads.*,email_addresses.email_address email_address,
|
|
leads.name as lead_name,
|
|
users.user_name as assigned_user_name ";
|
|
$query .= $custom_join['select'];
|
|
$query .= " FROM leads ";
|
|
$query .= "LEFT JOIN users
|
|
ON leads.assigned_user_id=users.id ";
|
|
|
|
//join email address table too.
|
|
$query .= ' LEFT JOIN email_addr_bean_rel on leads.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Leads\' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 ';
|
|
$query .= ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
|
|
|
|
$query .= $custom_join['join'];
|
|
|
|
$where_auto = "( leads.deleted IS NULL OR leads.deleted=0 )";
|
|
|
|
if($where != "")
|
|
$query .= "where ($where) AND ".$where_auto;
|
|
else
|
|
$query .= "where ".$where_auto;
|
|
|
|
if(!empty($order_by))
|
|
$query .= " ORDER BY ". $this->process_order_by($order_by, null);
|
|
|
|
return $query;
|
|
}
|
|
|
|
function set_notification_body($xtpl, $lead)
|
|
{
|
|
$xtpl->assign("ACCOUNT_NAME", $lead->name);
|
|
$xtpl->assign("ACCOUNT_TYPE", $lead->lead_type);
|
|
$xtpl->assign("ACCOUNT_DESCRIPTION", $lead->description);
|
|
|
|
return $xtpl;
|
|
}
|
|
|
|
function bean_implements($interface){
|
|
switch($interface){
|
|
case 'ACL':return true;
|
|
}
|
|
return false;
|
|
}
|
|
function get_unlinked_email_query($type=array()) {
|
|
|
|
return get_unlinked_email_query($type, $this);
|
|
}
|
|
//start managing addresses
|
|
function savePositions($pl) {
|
|
global $current_user;
|
|
$exists = array();
|
|
foreach ($pl as $p) {
|
|
if (!isset($p['name']) || $p['name']=='') continue;
|
|
if (isset($p['id']) && $p['id']!='') {
|
|
//update exists
|
|
$q = "
|
|
UPDATE lead_addresses set
|
|
name = '".addslashes($p['name'])."',
|
|
date_modified = '".date("Y-m-d H:i:s")."',
|
|
modified_user_id = '".$current_user->id."',
|
|
street = '".addslashes($p['street'])."',
|
|
postalcode = '".addslashes($p['postalcode'])."',
|
|
city = '".addslashes($p['city'])."',
|
|
country = '".addslashes($p['country'])."',
|
|
position = '".addslashes($p['position'])."',
|
|
phone = '".addslashes($p['phone'])."',
|
|
fax = '".addslashes($p['fax'])."'
|
|
WHERE id = '".$p['id']."'
|
|
";
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $p['id'];
|
|
} else {
|
|
//insert new record
|
|
$id = create_guid();
|
|
$t = array(
|
|
$id,
|
|
$this->id,
|
|
addslashes($p['name']),
|
|
date("Y-m-d H:i:s"),
|
|
date("Y-m-d H:i:s"),
|
|
$current_user->id,
|
|
$current_user->id,
|
|
addslashes($p['street']),
|
|
addslashes($p['postalcode']),
|
|
addslashes($p['city']),
|
|
addslashes($p['country']),
|
|
addslashes($p['position']),
|
|
'0',
|
|
addslashes($p['phone']),
|
|
addslashes($p['fax']),
|
|
);
|
|
$q = "INSERT INTO lead_addresses VALUES ('".implode("','", $t)."')";
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $id;
|
|
}
|
|
}
|
|
//delete old
|
|
$GLOBALS['db']->query("UPDATE lead_addresses SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE lead_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')");
|
|
}
|
|
function getPositionList($array = false) {
|
|
if(isset($this->id) && $this->id != '') {
|
|
$query = "SELECT * FROM lead_addresses WHERE lead_id='".$this->id."' AND deleted='0' ORDER BY position";
|
|
$r = $this->db->query($query);
|
|
$return_array = array();
|
|
if($r) {
|
|
|
|
while($w = $this->db->fetchByAssoc($r)) {
|
|
$return_array [] = $w;
|
|
}
|
|
$json = getJSONobj();
|
|
return $array ? $return_array : $json->encode($return_array);
|
|
}
|
|
}
|
|
return $array ? false : '[]';
|
|
}
|
|
function showPositions(){
|
|
$arr=$this->getPositionList(true);
|
|
global $mod_strings;
|
|
if(count($arr)>0){
|
|
$table='
|
|
<table cellpadding="0" cellspacing="0" border="0" class="list view">
|
|
<tr class="oddListRowS1">
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_POSITION'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_NAME'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_STREET'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_CITY'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_POSTALCODE'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_COUNTRY'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_PHONE'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_ADDRESS_FAX'].'</b></td>
|
|
</tr>
|
|
';
|
|
$i == 0;
|
|
foreach($arr as $a){
|
|
$i++;
|
|
//create link to google map
|
|
$name = '<a target="new" href="https://maps.google.com/?q='.$a['country'].'+'.$a['city'].'+'.$a['street'].'">'.$a['name'].'</a>';
|
|
$table.='
|
|
<tr class="oddListRowS1">
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['position'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$name.'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['street'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['city'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['postalcode'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['country'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['phone'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['fax'].'</td>
|
|
';
|
|
}
|
|
$table.='</table>';
|
|
}
|
|
|
|
return $table;
|
|
}
|
|
|
|
function getAddresses($lead_id) {
|
|
|
|
$db = $GLOBALS['db'];
|
|
|
|
$res = $db->query("SELECT id, name FROM lead_addresses WHERE lead_id='$lead_id' AND deleted='0' ORDER BY position");
|
|
|
|
if ($res->num_rows==0) return 0;
|
|
//echo "SELECT id, name FROM lead_addresses WHERE lead_id='$lead_id' ORDER BY position";
|
|
$options = '<select id="address_id" onchange="getAddress();">';
|
|
$options .= '<option value=\'\'></option>';
|
|
while ($row = $db->fetchByAssoc($res)) {
|
|
$options.='<option value="'.$row['id'].'">'.$row['name'].'</option>';
|
|
}
|
|
$options.='</select>';
|
|
|
|
return $options;
|
|
}
|
|
|
|
function getAddress($id) {
|
|
|
|
$db = $GLOBALS['db'];
|
|
|
|
$row = $db->fetchByAssoc($db->query("SELECT name as description , street, postalcode, city, country FROM lead_addresses WHERE id='$id'"));
|
|
|
|
$ret[] = $row;
|
|
|
|
return $ret;
|
|
|
|
}
|
|
//end managing addresses
|
|
|
|
//start managing discounts
|
|
function savePositions2($pl) {
|
|
global $current_user;
|
|
$exists = array();
|
|
foreach ($pl as $p) {
|
|
if (!isset($p['product_group']) || $p['product_group']=='') continue;
|
|
if (!isset($p['discount']) || $p['discount']=='' || floatval($p['discount'])==0) continue;
|
|
if (isset($p['id']) && $p['id']!='') {
|
|
//update exists
|
|
$q = "
|
|
UPDATE leads_discounts set
|
|
date_modified = '".date("Y-m-d H:i:s")."',
|
|
modified_user_id = '".$current_user->id."',
|
|
lead_id = '".addslashes($this->id)."',
|
|
discount = '".addslashes($p['discount'])."',
|
|
product_group = '".addslashes($p['product_group'])."'
|
|
WHERE id = '".$p['id']."'
|
|
";
|
|
|
|
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes($q)."')");
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $p['id'];
|
|
|
|
} else {
|
|
//insert new record
|
|
$id = create_guid();
|
|
$t = array(
|
|
$id,
|
|
$this->id,
|
|
addslashes($p['product_group']),
|
|
addslashes($p['discount']),
|
|
date("Y-m-d H:i:s"),
|
|
$current_user->id,
|
|
'0'
|
|
);
|
|
$q = "INSERT INTO leads_discounts VALUES ('".implode("','", $t)."')";
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $id;
|
|
}
|
|
|
|
}
|
|
//delete old
|
|
$GLOBALS['db']->query("UPDATE leads_discounts SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE lead_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')");
|
|
}
|
|
|
|
function getPositionList2($array = false) {
|
|
if(isset($this->id) && $this->id != '') {
|
|
$query = "SELECT * FROM leads_discounts WHERE lead_id='".$this->id."' AND deleted='0'";
|
|
|
|
$r = $this->db->query($query);
|
|
$return_array = array();
|
|
if($r) {
|
|
|
|
while($w = $this->db->fetchByAssoc($r)) {
|
|
$return_array [] = $w;
|
|
}
|
|
$json = getJSONobj();
|
|
|
|
return $array ? $return_array : $json->encode($return_array);
|
|
}
|
|
}
|
|
return $array ? false : '[]';
|
|
}
|
|
function showPositions2(){
|
|
$arr=$this->getPositionList2(true);
|
|
|
|
global $mod_strings;
|
|
if(count($arr)>0){
|
|
$table='
|
|
<table cellpadding="0" cellspacing="0" border="0" class="list view" width="40%">
|
|
<tr class="oddListRowS1">
|
|
<th><b>'.$mod_strings['LBL_PRODUCT_GROUP'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_DISCOUNT'].'</b></td>
|
|
</tr>
|
|
';
|
|
$i == 0;
|
|
foreach($arr as $a){
|
|
$i++;
|
|
$table.='
|
|
<tr class="oddListRowS1">
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['product_group'].'</td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$a['discount'].'</td>
|
|
|
|
';
|
|
}
|
|
$table.='</table>';
|
|
}
|
|
|
|
return $table;
|
|
}
|
|
|
|
//start managing categories
|
|
function savePositions3($pl) {
|
|
global $current_user;
|
|
$exists = array();
|
|
|
|
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes(json_encode($pl))."')");
|
|
foreach ($pl as $p) {
|
|
if (!isset($p['ecmaccountcategory_id']) || $p['ecmaccountcategory_id']=='') continue;
|
|
if (isset($p['id']) && $p['id']!='') {
|
|
//update exists
|
|
$q = "
|
|
UPDATE ecmaccountcategories_bean set
|
|
date_modified = '".date("Y-m-d H:i:s")."',
|
|
modified_user_id = '".$current_user->id."',
|
|
bean_id = '".addslashes($this->id)."',
|
|
ecmaccountcategory_id = '".addslashes($p['ecmaccountcategory_id'])."'
|
|
WHERE id = '".$p['id']."'
|
|
";
|
|
|
|
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes($q)."')");
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $p['id'];
|
|
|
|
} else {
|
|
//insert new record
|
|
$id = create_guid();
|
|
$t = array(
|
|
$id,
|
|
addslashes($p['ecmaccountcategory_id']),
|
|
$this->id,
|
|
"Leads",
|
|
date("Y-m-d H:i:s"),
|
|
date("Y-m-d H:i:s"),
|
|
$current_user->id,
|
|
$current_user->id,
|
|
'0'
|
|
);
|
|
$q = "INSERT INTO ecmaccountcategories_bean VALUES ('".implode("','", $t)."')";
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $id;
|
|
}
|
|
|
|
}
|
|
//delete old
|
|
$GLOBALS['db']->query("UPDATE ecmaccountcategories_bean SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE bean_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')");
|
|
}
|
|
|
|
function getPositionList3($array = false) {
|
|
if(isset($this->id) && $this->id != '') {
|
|
$query = "SELECT * FROM ecmaccountcategories_bean WHERE bean_id='".$this->id."' AND deleted='0' AND bean_name='Leads'";
|
|
|
|
$r = $this->db->query($query);
|
|
$return_array = array();
|
|
if($r) {
|
|
|
|
while($w = $this->db->fetchByAssoc($r)) {
|
|
//get category name && assigned_file
|
|
$n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name, assigned_file FROM ecmaccountcategories WHERE id='".$w['ecmaccountcategory_id']."'"));
|
|
$w['ecmaccountcategory_name'] = $n['name'];
|
|
$w['assigned_file'] = $n['assigned_file'];
|
|
$return_array [] = $w;
|
|
|
|
}
|
|
$json = getJSONobj();
|
|
|
|
return $array ? $return_array : $json->encode($return_array);
|
|
}
|
|
}
|
|
return $array ? false : '[]';
|
|
}
|
|
|
|
function showPositions3(){
|
|
$arr=$this->getPositionList3(true);
|
|
|
|
global $mod_strings;
|
|
if(count($arr)>0){
|
|
$table='
|
|
<table cellpadding="0" cellspacing="0" border="0" class="list view" width="40%">
|
|
<tr class="oddListRowS1">
|
|
<th><b>'.$mod_strings['LBL_CATEGORY_NAME'].'</b></td>
|
|
<th><b>'.$mod_strings['LBL_CATEGORY_ASSIGNED_FILE'].'</b></td>
|
|
</tr>
|
|
';
|
|
$i == 0;
|
|
foreach($arr as $a){
|
|
$i++;
|
|
//assigned file
|
|
if ($a['assigned_file']!="" && $a['assigned_file']) {
|
|
$tmp = explode(".", $a['assigned_file']);
|
|
if (end($tmp) == 'jpeg' || end($tmp) == 'jpg' || end($tmp) == 'png' || end($tmp) == 'bmp')
|
|
$af = '<img src="modules/EcmAccountCategories/files/'.$a['assigned_file'].'"/>';
|
|
else
|
|
$af = '<a href="modules/EcmAccountCategories/files/'.$a['assigned_file'].'" target="new">'.$a['assigned_file'].'</a>';
|
|
}
|
|
$table.='
|
|
<tr class="oddListRowS1">
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;"><a href="index.php?module=EcmAccountCategories&action=DetailView&record='.$a['ecmaccountcategory_id'].'">'.$a['ecmaccountcategory_name'].'</a></td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.$af.'</td>
|
|
|
|
';
|
|
}
|
|
$table.='</table>';
|
|
}
|
|
|
|
return $table;
|
|
}
|
|
//end managing categories
|
|
|
|
function AddGoogleContact() {
|
|
global $current_user;
|
|
if (!$current_user->google_login || $current_user->google_login=='' || !$current_user->google_p || $current_user->google_p=='') return -1;
|
|
|
|
require_once 'Zend/Loader.php';
|
|
Zend_Loader::loadClass('Zend_Gdata');
|
|
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
|
|
Zend_Loader::loadClass('Zend_Http_Client');
|
|
Zend_Loader::loadClass('Zend_Gdata_Query');
|
|
Zend_Loader::loadClass('Zend_Gdata_Feed');
|
|
|
|
try {
|
|
// perform login and set protocol version to 3.0
|
|
$client = Zend_Gdata_ClientLogin::getHttpClient($current_user->google_login, $current_user->google_p, 'cp');
|
|
|
|
$gdata = new Zend_Gdata($client);
|
|
$gdata->setMajorProtocolVersion(3);
|
|
|
|
//return serialize($gdata);
|
|
|
|
// create new entry
|
|
$doc = new DOMDocument();
|
|
$doc->formatOutput = true;
|
|
$entry = $doc->createElement('atom:entry');
|
|
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:atom', 'http://www.w3.org/2005/Atom');
|
|
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:gd', 'http://schemas.google.com/g/2005');
|
|
$doc->appendChild($entry);
|
|
|
|
// add name element
|
|
$name = $doc->createElement('gd:name');
|
|
$entry->appendChild($name);
|
|
$fullName = $doc->createElement('gd:fullName', $this->name);
|
|
$name->appendChild($fullName);
|
|
|
|
// add email element
|
|
$email = $doc->createElement('gd:email');
|
|
$email->setAttribute('address' ,$this->emailAddress->getPrimaryAddress($this));
|
|
$email->setAttribute('rel' ,'http://schemas.google.com/g/2005#home');
|
|
$entry->appendChild($email);
|
|
|
|
// add org name element
|
|
$org = $doc->createElement('gd:organization');
|
|
$org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
|
|
$entry->appendChild($org);
|
|
$orgName = $doc->createElement('gd:orgName', $this->name);
|
|
$org->appendChild($orgName);
|
|
|
|
if ($this->phone_office) {
|
|
$phone = $doc->createElement('gd:phoneNumber', $this->phone_office);
|
|
$phone->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
|
|
$entry->appendChild($phone);
|
|
//$phoneName = $doc->createElement('gd:phoneNumberName', $this->phone_office);
|
|
//$phone->appendChild($phoneName);
|
|
}
|
|
// insert entry
|
|
$entryResult = $gdata->insertEntry($doc->saveXML(), 'https://www.google.com/m8/feeds/contacts/default/full');
|
|
|
|
return 1;
|
|
} catch (Exception $e) {
|
|
//return 4;
|
|
return $e->getMessage();
|
|
//return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
function showPositions55(){
|
|
$arr=$this->getPositionList55(true);
|
|
|
|
global $mod_strings;
|
|
if(count($arr)>0){
|
|
$table='
|
|
<table cellpadding="0" cellspacing="0" border="0" class="list view" width="40%">
|
|
<tr class="oddListRowS1">
|
|
<th><b>Nazwa grupy</b></td>
|
|
<th><b>Aktywna</b></td>
|
|
</tr>
|
|
';
|
|
$i == 0;
|
|
foreach($arr as $a){
|
|
$i++;
|
|
|
|
|
|
$table.='
|
|
<tr class="oddListRowS1">
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;"><a href="index.php?module=EcmMailingCategories&action=DetailView&record='.$a['cat_id'].'">'.$a['product_group'].'</a></td>
|
|
|
|
<td valign="top" class="oddListRowS1" style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">'.($a['discount']==1 ? 'Tak' : "Nie").'</td>
|
|
|
|
';
|
|
}
|
|
$table.='</table>';
|
|
}
|
|
|
|
return $table;
|
|
}
|
|
|
|
function getPositionList55($array = false) {
|
|
if(isset($this->id) && $this->id != '') {
|
|
$query = "SELECT * FROM ecmmailingcategories_relation WHERE parent_id='".$this->id."' AND deleted='0' AND parent_type='Lead'";
|
|
|
|
$r = $this->db->query($query);
|
|
$return_array = array();
|
|
if($r) {
|
|
|
|
while($w = $this->db->fetchByAssoc($r)) {
|
|
//get category name && assigned_file
|
|
$n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name FROM ecmmailingcategories WHERE id='".$w['ecmmailingcategoriy_id']."'"));
|
|
$w['product_group'] = $n['name'];
|
|
$w['cat_id'] =$w['ecmmailingcategoriy_id'];
|
|
$w['discount'] =$w['available'];
|
|
$return_array [] = $w;
|
|
|
|
}
|
|
$json = getJSONobj();
|
|
|
|
return $array ? $return_array : $json->encode($return_array);
|
|
}
|
|
}
|
|
|
|
return $array ? false : '[]';
|
|
}
|
|
|
|
//end managing addresses
|
|
function savePositions55($pl) {
|
|
|
|
global $current_user;
|
|
|
|
$exists = array();
|
|
foreach ($pl as $p) {
|
|
|
|
if (!isset($p['product_group']) || $p['product_group']=='') continue;
|
|
|
|
|
|
if (isset($p['id']) && $p['id']!='') {
|
|
|
|
//update exists
|
|
$q = "
|
|
UPDATE ecmmailingcategories_relation set
|
|
parent_id = '".addslashes($this->id)."',
|
|
ecmmailingcategoriy_id= '".addslashes($p['cat_id'])."',
|
|
available = '".addslashes($p['discount'])."',
|
|
parent_type = 'Lead',
|
|
parent_name = '".addslashes($p['product_group'])."'
|
|
WHERE id = '".$p['id']."'
|
|
";
|
|
|
|
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes($q)."')");
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $p['id'];
|
|
|
|
} else {
|
|
//insert new record
|
|
$id = create_guid();
|
|
$t = array(
|
|
$id,
|
|
addslashes($p['cat_id']),
|
|
'0',
|
|
addslashes($p['discount']),
|
|
$this->id,
|
|
addslashes($p['product_group']),
|
|
'Lead'
|
|
|
|
);
|
|
$q = "INSERT INTO ecmmailingcategories_relation VALUES ('".implode("','", $t)."')";
|
|
|
|
$GLOBALS['db']->query($q);
|
|
$exists[] = $id;
|
|
}
|
|
|
|
}
|
|
|
|
//delete old
|
|
$GLOBALS['db']->query("UPDATE ecmmailingcategories_relation SET deleted='1' WHERE parent_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')");
|
|
}
|
|
}
|