/** * Returns customer data * * @global array $CONTACTTYPES * @param int $id Customer id * @param boolean $short Basic or expanded data * @return array|boolean Customer data or false on failure */ public function GetCustomer($id, $short = false) { global $CONTACTTYPES; if ($result = $this->db->GetRow('SELECT c.*, ' . $this->db->Concat('UPPER(c.lastname)', "' '", 'c.name') . ' AS customername, d.shortname AS division, d.account FROM customers' . (defined('LMS-UI') ? 'view' : '') . ' c LEFT JOIN divisions d ON (d.id = c.divisionid) WHERE c.id = ?', array($id))) { if (!$short) { $user_manager = new LMSUserManager($this->db, $this->auth, $this->cache, $this->syslog); $result['createdby'] = $user_manager->getUserName($result['creatorid']); $result['modifiedby'] = $user_manager->getUserName($result['modid']); $result['creationdateh'] = date('Y/m/d, H:i', $result['creationdate']); $result['moddateh'] = date('Y/m/d, H:i', $result['moddate']); $result['consentdate'] = $result['consentdate'] ? date('Y/m/d', $result['consentdate']) : ''; $result['up_logins'] = $this->db->GetRow('SELECT lastlogindate, lastloginip, failedlogindate, failedloginip FROM up_customers WHERE customerid = ?', array($result['id'])); // Get country name if ($result['countryid']) { $result['country'] = $this->db->GetOne('SELECT name FROM countries WHERE id = ?', array($result['countryid'])); if ($result['countryid'] == $result['post_countryid']) { $result['post_country'] = $result['country']; } else { if ($result['post_countryid']) { $result['country'] = $this->db->GetOne('SELECT name FROM countries WHERE id = ?', array($result['post_countryid'])); } } } // Get state name if ($cstate = $this->db->GetRow('SELECT s.id, s.name FROM states s, zipcodes WHERE zip = ? AND stateid = s.id', array($result['zip']))) { $result['stateid'] = $cstate['id']; $result['cstate'] = $cstate['name']; } if ($result['zip'] == $result['post_zip']) { $result['post_stateid'] = $result['stateid']; $result['post_cstate'] = $result['cstate']; } else { if ($result['post_zip'] && ($cstate = $this->db->GetRow('SELECT s.id, s.name FROM states s, zipcodes WHERE zip = ? AND stateid = s.id', array($result['post_zip'])))) { $result['post_stateid'] = $cstate['id']; $result['post_cstate'] = $cstate['name']; } } } $result['balance'] = $this->getCustomerBalance($result['id']); $result['bankaccount'] = bankaccount($result['id'], $result['account']); $result['messengers'] = $this->db->GetAllByKey('SELECT uid, type FROM imessengers WHERE customerid = ? ORDER BY type', 'type', array($result['id'])); $result['contacts'] = $this->db->GetAll('SELECT contact AS phone, name, type FROM customercontacts WHERE customerid = ? AND type < ? ORDER BY id', array($result['id'], CONTACT_EMAIL)); $result['emails'] = $this->db->GetAll('SELECT contact AS email, name FROM customercontacts WHERE customerid = ? AND type = ? ORDER BY id', array($result['id'], CONTACT_EMAIL)); if (is_array($result['contacts'])) { foreach ($result['contacts'] as $idx => $row) { $types = array(); foreach ($CONTACTTYPES as $tidx => $tname) { if ($row['type'] & $tidx) { $types[] = $tname; } } if ($types) { $result['contacts'][$idx]['typestr'] = implode('/', $types); } } } return $result; } else { return false; } }
/** * Returns customer data * * @global array $CONTACTTYPES * @param int $id Customer id * @param boolean $short Basic or expanded data * @return array|boolean Customer data or false on failure */ public function GetCustomer($id, $short = false) { global $CONTACTTYPES, $CUSTOMERCONTACTTYPES; require_once LIB_DIR . DIRECTORY_SEPARATOR . 'customercontacttypes.php'; if ($result = $this->db->GetRow('SELECT c.*, ' . $this->db->Concat('UPPER(c.lastname)', "' '", 'c.name') . ' AS customername, d.shortname AS division, d.account FROM customer' . (defined('LMS-UI') ? '' : 'address') . 'view c LEFT JOIN divisions d ON (d.id = c.divisionid) WHERE c.id = ?', array($id))) { if (!$short) { $user_manager = new LMSUserManager($this->db, $this->auth, $this->cache, $this->syslog); $result['createdby'] = $user_manager->getUserName($result['creatorid']); $result['modifiedby'] = $user_manager->getUserName($result['modid']); $result['creationdateh'] = date('Y/m/d, H:i', $result['creationdate']); $result['moddateh'] = date('Y/m/d, H:i', $result['moddate']); $result['consentdate'] = $result['consentdate'] ? date('Y/m/d', $result['consentdate']) : ''; $result['up_logins'] = $this->db->GetRow('SELECT lastlogindate, lastloginip, failedlogindate, failedloginip FROM up_customers WHERE customerid = ?', array($result['id'])); // Get country name if ($result['countryid']) { $result['country'] = $this->db->GetOne('SELECT name FROM countries WHERE id = ?', array($result['countryid'])); if ($result['countryid'] == $result['post_countryid']) { $result['post_country'] = $result['country']; } else { if ($result['post_countryid']) { $result['country'] = $this->db->GetOne('SELECT name FROM countries WHERE id = ?', array($result['post_countryid'])); } } } // Get state name if ($cstate = $this->db->GetRow('SELECT s.id, s.name FROM states s, zipcodes WHERE zip = ? AND stateid = s.id', array($result['zip']))) { $result['stateid'] = $cstate['id']; $result['cstate'] = $cstate['name']; } if ($result['zip'] == $result['post_zip']) { $result['post_stateid'] = $result['stateid']; $result['post_cstate'] = $result['cstate']; } else { if ($result['post_zip'] && ($cstate = $this->db->GetRow('SELECT s.id, s.name FROM states s, zipcodes WHERE zip = ? AND stateid = s.id', array($result['post_zip'])))) { $result['post_stateid'] = $cstate['id']; $result['post_cstate'] = $cstate['name']; } } } $result['balance'] = $this->getCustomerBalance($result['id']); $result['bankaccount'] = bankaccount($result['id'], $result['account']); foreach ($CUSTOMERCONTACTTYPES as $contacttype => $properties) { $result[$contacttype . 's'] = $this->db->GetAll('SELECT contact AS ' . $contacttype . ', contact, name, type FROM customercontacts WHERE customerid = ? AND type & ? > 0 ORDER BY id', array($result['id'], $properties['flagmask'])); } $result['sendinvoices'] = false; foreach (array_keys($CUSTOMERCONTACTTYPES) as $ctype) { $customercontacttype = $CUSTOMERCONTACTTYPES[$ctype]; $ctype .= 's'; if (is_array($result[$ctype])) { foreach ($result[$ctype] as $idx => $row) { $types = array(); foreach ($CONTACTTYPES as $tidx => $tname) { if ($row['type'] & $tidx && isset($customercontacttype['ui']['flags'][$row['type'] & $tidx])) { $types[] = $tname; } } if (isset($customercontacttype['ui']['typeselectors'])) { $result[$ctype][$idx]['typeselector'] = $tidx; } if ($ctype == 'emails' && ($row['type'] & (CONTACT_INVOICES | CONTACT_DISABLED)) == CONTACT_INVOICES) { $result['sendinvoices'] = true; } if ($types) { $result[$ctype][$idx]['typestr'] = implode('/', $types); } } } } $result['contacts'] = $result['phones']; if (empty($result['invoicenotice'])) { $result['sendinvoices'] = false; } return $result; } else { return false; } }
/** * Returns VoIP account data * * @param int $id VoIP account id * @return array|false VoIP account data on success, false on failure */ public function getVoipAccount($id) { $result = $this->db->GetRow(' SELECT v.id, ownerid, login, passwd, phone, creationdate, moddate, creatorid, modid, access, location, location_city, location_street, location_house, location_flat, lb.name AS borough_name, ld.name AS district_name, ls.name AS state_name FROM voipaccounts v LEFT JOIN location_cities lc ON lc.id = v.location_city LEFT JOIN location_boroughs lb ON lb.id = lc.boroughid LEFT JOIN location_districts ld ON ld.id = lb.districtid LEFT JOIN location_states ls ON ls.id = ld.stateid WHERE v.id = ?', array($id)); if ($result) { $customer_manager = new LMSCustomerManager($this->db, $this->auth, $this->cache, $this->syslog); $user_manager = new LMSUserManager($this->db, $this->auth, $this->cache, $this->syslog); $result['createdby'] = $user_manager->getUserName($result['creatorid']); $result['modifiedby'] = $user_manager->getUserName($result['modid']); $result['creationdateh'] = date('Y/m/d, H:i', $result['creationdate']); $result['moddateh'] = date('Y/m/d, H:i', $result['moddate']); $result['owner'] = $customer_manager->getCustomerName($result['ownerid']); return $result; } else { return FALSE; } }
/** * Returns VoIP account data * * @param int $id VoIP account id * @return array|false VoIP account data on success, false on failure */ public function getVoipAccount($id) { $result = $this->db->GetRow(' SELECT v.id, ownerid, login, passwd, creationdate, moddate, creatorid, modid, access, balance, location, location_city, location_street, location_house, location_flat, lb.name AS borough_name, ld.name AS district_name, lst.name AS state_name, lc.name AS city_name, (CASE WHEN ls.name2 IS NOT NULL THEN ' . $this->db->Concat('ls.name2', "' '", 'ls.name') . ' ELSE ls.name END) AS street_name, lt.name AS street_type, v.flags, v.balance, v.cost_limit FROM voipaccounts v LEFT JOIN location_cities lc ON lc.id = v.location_city LEFT JOIN location_streets ls ON (ls.id = v.location_street) LEFT JOIN location_street_types lt ON (lt.id = ls.typeid) LEFT JOIN location_boroughs lb ON lb.id = lc.boroughid LEFT JOIN location_districts ld ON ld.id = lb.districtid LEFT JOIN location_states lst ON lst.id = ld.stateid WHERE v.id = ?', array($id)); if ($result) { $customer_manager = new LMSCustomerManager($this->db, $this->auth, $this->cache, $this->syslog); $user_manager = new LMSUserManager($this->db, $this->auth, $this->cache, $this->syslog); $result['createdby'] = $user_manager->getUserName($result['creatorid']); $result['modifiedby'] = $user_manager->getUserName($result['modid']); $result['creationdateh'] = date('Y/m/d, H:i', $result['creationdate']); $result['moddateh'] = date('Y/m/d, H:i', $result['moddate']); $result['phones'] = $this->db->GetAll('SELECT phone, number_index FROM voip_numbers WHERE voip_account_id = ?;', array($id)); $result['owner'] = $customer_manager->getCustomerName($result['ownerid']); return $result; } return FALSE; }