Skip to content

Commit

Permalink
devel/codeclenup: refactoring, bugfixing of telecentrum callcenter v2…
Browse files Browse the repository at this point in the history
… scripts
  • Loading branch information
interduo committed Jun 18, 2023
1 parent 2b84047 commit 5bfadb9
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 108 deletions.
134 changes: 71 additions & 63 deletions contrib/tele.centrum.v2/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

$uid = isset($_GET['id']) ? intval($_GET['id']) : null;
$agentnr = isset($_GET['agentnr']) ? intval($_GET['agentnr']) : null;

require_once('..' . DIRECTORY_SEPARATOR . 'initLMS.php');
require_once('lib' . DIRECTORY_SEPARATOR . 'definitions.php');

$uid = intval($_GET['id']);
$phone = intval($_GET['phone']);
$agentnr = intval($_GET['agentnr']);
$ticket['phonetype'] = 'on';

$newticket_subject = ConfigHelper::getConfig(
'callcenter.newticket_subject',
'Zgłoszenie telefoniczne z E-Południe Call Center nr [#' . $uid . ']'
);
if (!empty($_GET['phone'])) {
$phone = intval($_GET['phone']);
$ticket['phone'] = $phone;
} else {
$phone = null;
}

$ticket['phonetype'] = 'on';

str_replace(
array('%uid', '%customerphone', '%agentnr'),
Expand Down Expand Up @@ -53,107 +54,115 @@
// get all customers with valid phone number
if (!empty($phone)) {
$result = $DB->GetAll(
'SELECT c.id, cc.contact AS phone, address, city, deleted,
' . $DB->Concat('UPPER(lastname)', "' '", 'c.name') . ' AS username
'SELECT c.id, address, city, deleted,
' . $DB->Concat('UPPER(lastname)', "' '", 'c.name') . ' AS username,
REPLACE(REPLACE(cc.contact, \'-\', \'\'), \' \', \'\') AS phone
FROM customerview c
LEFT JOIN customercontacts cc ON cc.customerid = c.id
WHERE REPLACE(REPLACE(cc.contact, \'-\', \'\'), \' \', \'\') ?LIKE? ?
LEFT JOIN customercontacts cc ON cc.customerid = c.id
WHERE
REPLACE(REPLACE(cc.contact, \'-\', \'\'), \' \', \'\') ?LIKE? \'?\'
AND c.deleted = 0
ORDER BY deleted, username, cc.contact, address',
AND (cc.type & ' . CONTACT_MOBILE . ' > 0 OR cc.type & ' . CONTACT_LANDLINE . ' > 0)
ORDER BY username, cc.contact, address, deleted',
array($phone)
);
// prepare result to put in js
$js_result = json_encode($result, JSON_UNESCAPED_UNICODE);
if (!empty($result)) {
$js_result = json_encode($result, JSON_UNESCAPED_UNICODE);
} else {
$js_result = null;
}
}

if (!empty($_POST)) {
$ticket = $_POST;

if (empty($ticket['phone'])) {
$ticket['phone'] = $ticket['contactphone'];
$ticket['phone'] = empty($ticket['contactphone']) ? null : $ticket['contactphone'];
}

// simple form validation
if ($ticket['body'] == '' && $ticket['queue'] == 1) {
if (isset($ticket['body']) && $ticket['body'] == '' && $ticket['queue'] == 1) {
$error['body'] = 'Podaj treść zgłoszenia!';
}

if ($ticket['name'] == '') {
if (isset($ticket['name']) && $ticket['name'] == '') {
$error['name'] = 'Podaj imię i nazwisko/nazwę klienta!';
}

if ($ticket['address'] == '') {
if (isset($ticket['address']) && $ticket['address'] == '') {
$error['address'] = 'Podaj adres instalacji z którą jest problem!';
}

if ($ticket['phone'] == '') {
if (isset($ticket['phone']) && $ticket['phone'] == '') {
$error['phone'] = 'Podaj telefon do kontaktu ze zgłaszającym usterkę!';
}

// continue if no error found
if (!$error) {
if (!isset($error) || empty($error)) {
if (!$agentnr || !isset($agents[$agentnr])) {
$agent = 'Brak informacji';
} else {
$agent = $agents[$agentnr];
}

//prepare body
$ticket['contactphone'] = $ticket['phone'];
$ticket['mailfrom'] = '';
$ticket['owner'] = null;
// if valid user found in db
if (isset($ticket['othercustomer']) || empty($result)) {
$ticket['customerid'] = null;
if ($ticket['odblokowanie_komunikatu'] == 'tak') {
if (isset($ticket['odblokowanie_komunikatu']) && $ticket['odblokowanie_komunikatu'] == 'tak') {
$ticket['requestor'] = $ticket['name'] . ', ' . $ticket['address'];
$ticket['body'] = 'Prośba o odblokowanie internetu.' . PHP_EOL . 'Agent: ' . $agent . PHP_EOL . 'Numer kontaktowy: ' . $ticket['contactphone'];
} elseif ($ticket['kontakt'] == 'tak') {
$ticket['body'] = 'Prośba o odblokowanie internetu.' . PHP_EOL;
} elseif (isset($ticket['kontakt']) && $ticket['kontakt'] == 'tak') {
$ticket['requestor'] = $ticket['name'].', '.$ticket['address'];
$ticket['body'] = 'Prośba o kontakt z ofertą handlową.' . PHP_EOL . 'Agent: '.$agent . PHP_EOL .'Numer kontaktowy: ' . $ticket['contactphone'];
$ticket['body'] = 'Prośba o kontakt z ofertą handlową.' . PHP_EOL;
} else {
$ticket['requestor'] = $ticket['name'].', '.$ticket['address'];
$ticket['body'] .= PHP_EOL . 'Agent: ' . $agent . PHP_EOL . 'Numer kontaktowy: ' . $ticket['contactphone'];
}
} else {
$ticket['customerid'] = $result[$ticket['customer']]['id'];
$ticket['requestor'] = '';
if ($ticket['odblokowanie_komunikatu'] == 'tak') {
$ticket['requestor'] = $ticket['name'] . ', '.$ticket['address'];
$ticket['body'] = 'Prośba o odblokowanie internetu.' . PHP_EOL . 'Agent: ' . $agent . PHP_EOL . 'Numer kontaktowy: ' . $ticket['contactphone'];
} elseif ($ticket['kontakt'] == 'tak') {
if (isset($ticket['odblokowanie_komunikatu']) && $ticket['odblokowanie_komunikatu'] == 'tak') {
$ticket['requestor'] = $ticket['name'] . ', ' . $ticket['address'];
$ticket['body'] = 'Prośba o kontakt z ofertą handlową.' . PHP_EOL . 'Agent: '.$agent . PHP_EOL . 'Numer kontaktowy: ' . $ticket['contactphone'];
$ticket['body'] = 'Prośba o odblokowanie internetu.' . PHP_EOL;
} elseif (isset($ticket['kontakt']) && $ticket['kontakt'] == 'tak') {
$ticket['requestor'] = $ticket['name'] . ', ' . $ticket['address'];
$ticket['body'] = 'Prośba o kontakt z ofertą handlową.' . PHP_EOL;
} else {
$ticket['requestor'] = $ticket['name'] . ', ' . $ticket['address'];
$ticket['body'] .= PHP_EOL . 'Agent: ' . $agent . PHP_EOL . 'Numer kontaktowy: ' . $ticket['contactphone'];
}
}
$ticket['body'] .= PHP_EOL . PHP_EOL
. (empty($ticket['address']) ? null : 'Adres instalacji: ' . $ticket['address'] . PHP_EOL)
. 'Agent: ' . $agent . PHP_EOL
. (empty($ticket['contactphone']) ? null : 'Numer kontaktowy: ' . $ticket['contactphone'] . PHP_EOL)
. (empty($phone) ? null : 'Numer dzwoniącego: ' . $phone . PHP_EOL);
$ticket['subject'] = $newticket_subject;
// set real quque id
if ($ticket['queue'] == 1) {
$ticket['queue'] = $queues[0];
} elseif ($ticket['queue'] == 2) {
$ticket['queue'] = $queues[1];
} elseif ($ticket['queue'] == 3) {
$ticket['queue'] = $queues[2];
}
$queue = $CUSTOMER_ISSUES[$ticket['queue']]['queueid'];

$firstservice = empty($ticket['service']) ?
null : array_shift(array_slice($ticket['service'], 0, 1));

//insert ticket
$DB->Execute(
'INSERT INTO rttickets (queueid, customerid, requestor, subject,
state, owner, createtime, cause, source, creatorid)
VALUES (?, ?, ?, ?, ?, ?, ?NOW?, ?, ?, ?)',
state, owner, createtime, cause, source, creatorid, type, service)
VALUES (?, ?, ?, ?, ?, ?, ?NOW?, ?, ?, ?, ?, ?)',
array(
$ticket['queue'],
$queue,
$ticket['customerid'],
$ticket['requestor'],
//matched client by phone cleans requestor field - there is no use to duplicate this in requestor field
(empty($ticket['customerid']) ? $ticket['requestor'] : null),
$ticket['subject'],
RT_NEW,
$ticket['owner'],
RT_CAUSE_OTHER,
RT_SOURCE_CALLCENTER,
$user_id,
$CUSTOMER_ISSUES[$ticket['queue']]['ticket_type'],
$firstservice,
)
);
$id = $DB->GetLastInsertID('rttickets');
Expand All @@ -162,28 +171,25 @@
'INSERT INTO rtmessages (ticketid, customerid, createtime,
subject, body, mailfrom)
VALUES (?, ?, ?NOW?, ?, ?, ?)',
array($id,
array(
$id,
$ticket['customerid'],
$ticket['subject'],
preg_replace("/\r/", "", $ticket['body']),
$ticket['mailfrom'],
)
);

if (isset($ticket['internet'])) {
$DB->Execute('INSERT INTO rtticketcategories (ticketid, categoryid) VALUES (?, ?)', array($id, $categories[0]));
}
if (isset($ticket['tv'])) {
$DB->Execute('INSERT INTO rtticketcategories (ticketid, categoryid) VALUES (?, ?)', array($id, $categories[1]));
}
if (isset($ticket['telefon'])) {
$DB->Execute('INSERT INTO rtticketcategories (ticketid, categoryid) VALUES (?, ?)', array($id, $categories[2]));
}
if (is_null($ticket['internet']) && is_null($ticket['tv']) && is_null($ticket['telefon'])) {
$DB->Execute('INSERT INTO rtticketcategories (ticketid, categoryid) VALUES (?, ?)', array($id, $categories[3]));
}
$ticket['service'] = empty($ticket['service']) ? array($default_category) : $ticket['service'];

$queue = $ticket['queue'];
foreach ($ticket['service'] as $idx => $t) {
if (isset($CUSTOMER_VISIBLE_SERVICETYPES[$idx]['categoryid'])) {
$DB->Execute(
'INSERT INTO rtticketcategories (ticketid, categoryid) VALUES (?, ?)',
array($id, $t)
);
}
}

if (ConfigHelper::checkConfig(
'rt.new_ticket_notify',
Expand Down Expand Up @@ -257,7 +263,7 @@
}

if ($id) {
$msg = 'Zgłoszenie zostoło dodane.';
$msg = 'Zgłoszenie o numerze ' . $id . ' zostało dodane.';
$ticket = array();
} else {
$msg = 'Wystąpił błąd. Nie dodano zgłoszenia!';
Expand All @@ -271,12 +277,14 @@
$SMARTY->assign(array(
'welcomeMsg' => $welcomeMsg,
'warning' => $warning,
'result' => $result,
'js_result' => $js_result,
'_CUSTOMER_ISSUES' => $CUSTOMER_ISSUES,
'_CUSTOMER_VISIBLE_SERVICETYPES' => $CUSTOMER_VISIBLE_SERVICETYPES,
'result' => isset($result) ? $result : null,
'js_result' => isset($js_result) ? $js_result : null,
'information' => $information,
'ticket' => $ticket,
'phone' => $phone,
'error' => $error
'error' => !empty($error) ? $error : null,
));

$SMARTY->display('index.html');
65 changes: 62 additions & 3 deletions contrib/tele.centrum.v2/lib/definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@
);

$user_id = ConfigHelper::getConfig('callcenter.queueuser');
$queues = explode(',', ConfigHelper::getConfig('callcenter.queues'));
$categories = explode(',', ConfigHelper::getConfig('callcenter.categories'));
$default_category = ConfigHelper::getConfig('callcenter.default_category');
$default_queue = ConfigHelper::getConfig('callcenter.default_queue', 1);
$warning = ConfigHelper::getConfig('callcenter.warning');
$information = ConfigHelper::getConfig('callcenter.information');
$callcenterip = ConfigHelper::getConfig('callcenter.callcenterip');
$networks = explode(",", ConfigHelper::getConfig('callcenter.networks'));

$service_internet_category = ConfigHelper::getConfig('callcenter.service_internet_category', $default_category);
$service_phone_category = ConfigHelper::getConfig('callcenter.service_phone_category', $default_category);
$service_tv_category = ConfigHelper::getConfig('callcenter.service_tv_category', $default_category);

$fault_issues_queue = ConfigHelper::getConfig('callcenter.fault_issues_queue', $default_queue);
$offer_issues_queue = ConfigHelper::getConfig('callcenter.offer_issues_queue', $default_queue);
$payment_issues_queue = ConfigHelper::getConfig('callcenter.payment_issues_queue', $default_queue);

$newticket_subject = ConfigHelper::getConfig(
'callcenter.newticket_subject',
'Zgłoszenie telefoniczne z E-Południe Call Center nr [#' . $uid . ']'
);

$time = localtime(time(), true)['tm_hour'];
empty($agents[$agentnr]) ? $ag = '...' : $ag = $agents[$agentnr];

$ag = empty($agents[$agentnr]) ? '...' : $agents[$agentnr];
if ($time >= 19 or $time < 6) {
$welcomeMsg = "Dobry wieczór. Nazywam się $ag, w czym mogę pomóc?";
} else {
Expand All @@ -53,3 +67,48 @@ function ip_in_range($ip, $range)

return ( ( $ip_decimal & $netmask_decimal ) == ( $range_decimal & $netmask_decimal ) );
}

define('CUSTOMER_ISSUE_FAULT', 1);
define('CUSTOMER_ISSUE_OFFER', 2);
define('CUSTOMER_ISSUE_PAYMENT', 3);

$CUSTOMER_ISSUES = array(
CUSTOMER_ISSUE_FAULT => array(
'label' => 'Zgłoszenie awarii',
'queueid' => $fault_issues_queue,
'ticket_type' => RT_TYPE_FAULT,
),
CUSTOMER_ISSUE_OFFER => array(
'label' => 'Informacja handlowa',
'queueid' => $offer_issues_queue,
'ticket_type' => RT_TYPE_OFFER,
),
CUSTOMER_ISSUE_PAYMENT => array(
'label' => 'Sprawy finansowe',
'queueid' => $payment_issues_queue,
'ticket_type' => RT_TYPE_PAYMENT,
),
);

$CUSTOMER_VISIBLE_SERVICETYPES = array(
SERVICE_INTERNET => array(
'label' => 'Internet',
'categoryid' => $service_internet_category,
'value' => SERVICE_INTERNET,
),
SERVICE_PHONE => array(
'label' => 'Telefon',
'categoryid' => $service_phone_category,
'value' => SERVICE_PHONE,
),
SERVICE_TV => array(
'label' => 'Telewizja',
'categoryid' => $service_tv_category,
'value' => SERVICE_TV,
),
SERVICE_OTHER => array(
'label' => 'Inna',
'categoryid' => $default_category,
'value' => SERVICE_OTHER,
),
);
15 changes: 9 additions & 6 deletions contrib/tele.centrum.v2/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ mkdir /var/www/html/lms/contrib/tele.centrum.v2/templates_c/;
chmod 755 /var/www/html/lms/contrib/tele.centrum.v2/templates_c/;
chown 48:48 /var/www/html/lms/contrib/tele.centrum.v2/templates_c/;

Uzupełniamy sekcje o zmienne:
Uzupełniamy zmienne konfiguracyjne z sekcji callcenter:
- callcenterip - podać adres IP z którego łączyć się będą agenci callcenter,
- networks - adresacja sieci, która może wyświetlać formularz callcenter np. 10.10.10.0/24 (można podać kilka sieci oddzielonych przecinkiem),
- queues - id kolejek w LMS, odzielone przecinkami.

Kolejno: Zgłoszenie awarii, informacja handlowa oraz sprawy finansowe,
- categories - id kategorii zgłoszeń w LMS, odzielone przecinkami.
- fault_issues_queue - ID kolejki helpdesk dla zgłoszeń usterek,
- offer_issues_queue - ID kolejki helpdesk dla zgłoszeń ze sprawami handlowymi,
- payment_issues_queue - ID kolejki helpdesk dla zgłoszeń ze sprawami księgowymi,

- service_internet_category - kategoria nadawana zgłoszeniom które dotyczą usługi internet
- service_phone_category - kategoria nadawana zgłoszeniom które dotyczą usługi telefon
- service_tv_category - kategoria nadawana zgłoszeniom które dotyczą usługi telewizja
- default_category - domyślna kategoria, która zostanie nadana zgłoszeniu bez przypisanej usługi

Kolejno: Internet, telewizja, telefon oraz ogólna,
(UWAGA! ZACHOWANIE KOLEJNOŚCI JEST WYMAGANE DO POPRAWNEGO DZIAŁANIA.)
- queueuser - id użytkownika do którego ma być przypisane zgłoszenie (może być 0),
- warning - treść wiadomości specjalnej wyświetlanej na górze strony,
- information - możliwość dodanie dodatkowych informacji do wysuwającego się panelu (np. tabela z godzinami pracy).
Expand Down
Loading

0 comments on commit 5bfadb9

Please sign in to comment.