'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 Account() { parent::Company(); $this->setupCustomFields('Accounts'); 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_account_case_relationship($account_id='', $case_id='') { if (empty($case_id)) $where = ''; else $where = " and id = '$case_id'"; $query = "UPDATE cases SET account_name = '', account_id = '' WHERE account_id = '$account_id' AND deleted = 0 " . $where; $this->db->query($query,true,"Error clearing account 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 accounts a1, accounts 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, "Account", "Accounts", $this->id); $this->phone_alternate = EcmFormatPhoneNumber($this->phone_alternate, "Account", "Accounts", $this->id); } //create link to google maps global $mod_strings; $billing = ''.substr($mod_strings['LBL_BILLING_ADDRESS'],0,strlen($mod_strings['LBL_BILLING_ADDRESS'])-1).''; $shippping = ''.substr($mod_strings['LBL_SHIPPING_ADDRESS'],0,strlen($mod_strings['LBL_SHIPPING_ADDRESS'])-1).''; $this->maps = $billing.'
'.$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'], "Account", "Accounts", $this->id); $temp_array['PHONE_ALTERNATE'] = EcmFormatPhoneNumber($temp_array['PHONE_ALTERNATE'], "Account", "Accounts", $this->id); } if($_REQUEST['action']!="Popup"){ $temp_array['NAME']="".$this->name.""; } 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, "accounts.name like '$the_query_string%'"); if (is_numeric($the_query_string)) { array_push($where_clauses, "accounts.phone_alternate like '%$the_query_string%'"); array_push($where_clauses, "accounts.phone_fax like '%$the_query_string%'"); array_push($where_clauses, "accounts.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 accounts.*,email_addresses.email_address email_address, accounts.name as account_name, users.user_name as assigned_user_name "; $query .= $custom_join['select']; $query .= " FROM accounts "; $query .= "LEFT JOIN users ON accounts.assigned_user_id=users.id "; //join email address table too. $query .= ' LEFT JOIN email_addr_bean_rel on accounts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Accounts\' 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 = "( accounts.deleted IS NULL OR accounts.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, $account) { $xtpl->assign("ACCOUNT_NAME", $account->name); $xtpl->assign("ACCOUNT_TYPE", $account->account_type); $xtpl->assign("ACCOUNT_DESCRIPTION", $account->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 account_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 account_addresses VALUES ('".implode("','", $t)."')"; $GLOBALS['db']->query($q); $exists[] = $id; } } //delete old $GLOBALS['db']->query("UPDATE account_addresses SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE account_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')"); } function getPositionList($array = false) { if(isset($this->id) && $this->id != '') { $query = "SELECT * FROM account_addresses WHERE account_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=' '; $i == 0; foreach($arr as $a){ $i++; //create link to google map $name = ''.$a['name'].''; $table.=' '; } $table.='
'.$mod_strings['LBL_ADDRESS_POSITION'].' '.$mod_strings['LBL_ADDRESS_NAME'].' '.$mod_strings['LBL_ADDRESS_STREET'].' '.$mod_strings['LBL_ADDRESS_CITY'].' '.$mod_strings['LBL_ADDRESS_POSTALCODE'].' '.$mod_strings['LBL_ADDRESS_COUNTRY'].' '.$mod_strings['LBL_ADDRESS_PHONE'].' '.$mod_strings['LBL_ADDRESS_FAX'].'
'.$a['position'].' '.$name.' '.$a['street'].' '.$a['city'].' '.$a['postalcode'].' '.$a['country'].' '.$a['phone'].' '.$a['fax'].'
'; } return $table; } function getAddresses($account_id) { $db = $GLOBALS['db']; $res = $db->query("SELECT id, name FROM account_addresses WHERE account_id='$account_id' AND deleted='0' ORDER BY position"); if ($res->num_rows==0) return 0; //echo "SELECT id, name FROM account_addresses WHERE account_id='$account_id' ORDER BY position"; $options = ''; return $options; } function getPayers($account_id) { $db = $GLOBALS['db']; $res = $db->query("SELECT id, name FROM account_addresses WHERE account_id='$account_id' AND deleted='0' ORDER BY position"); if ($res->num_rows==0) return 0; //echo "SELECT id, name FROM account_addresses WHERE account_id='$account_id' ORDER BY position"; $options = ''; return $options; } function getAddress($id) { $db = $GLOBALS['db']; $row = $db->fetchByAssoc($db->query("SELECT a.name as description , a.street, a.postalcode, a.city,ac.to_vatid as nip,a.country FROM account_addresses a inner join accounts ac on ac.id=a.account_id WHERE a.id='$id'")); $ret[] = $row; return $ret; } //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 = 'Account', 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']), 'Account' ); $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)."')"); } //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 accounts_discounts set date_modified = '".date("Y-m-d H:i:s")."', modified_user_id = '".$current_user->id."', account_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 accounts_discounts VALUES ('".implode("','", $t)."')"; $GLOBALS['db']->query($q); $exists[] = $id; } } //delete old $GLOBALS['db']->query("UPDATE accounts_discounts SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE account_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')"); } function getPositionList2($array = false) { if(isset($this->id) && $this->id != '') { $query = "SELECT * FROM accounts_discounts WHERE account_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=' '; $i == 0; foreach($arr as $a){ $i++; $table.=' '; } $table.='
'.$mod_strings['LBL_PRODUCT_GROUP'].' '.$mod_strings['LBL_DISCOUNT'].'
'.$a['product_group'].' '.$a['discount'].'
'; } 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, "Accounts", 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 showPositions55(){ $arr=$this->getPositionList55(true); global $mod_strings; if(count($arr)>0){ $table=' '; $i == 0; foreach($arr as $a){ $i++; $table.=' '; } $table.='
Nazwa grupy Aktywna
'.$a['product_group'].' '.($a['discount']==1 ? 'Tak' : "Nie").'
'; } 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='Account'"; $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 : '[]'; } 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='Accounts'"; $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=' '; $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 = ''; else $af = ''.$a['assigned_file'].''; } $table.=' '; } $table.='
'.$mod_strings['LBL_CATEGORY_NAME'].' '.$mod_strings['LBL_CATEGORY_ASSIGNED_FILE'].'
'.$a['ecmaccountcategory_name'].' '.$af.'
'; } 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; } }