';
$sqlSysMapping = sisplet_query("SELECT * FROM srv_invitations_mapping WHERE sid = '$this->sid'");
if (mysqli_num_rows($sqlSysMapping) > 0) {
$sysUserToAddQuery = sisplet_query("SELECT count(*) FROM srv_user where ank_id='".$this->sid."' AND inv_res_id IS NULL AND deleted='0'");
list($sysUserToAdd) = mysqli_fetch_row($sysUserToAddQuery);
}
echo '';
/*echo '';
echo '';
echo '';
echo Help::display('inv_recipiens_from_system');*/
echo ' ';
echo ' ';
if ($import_type == 3) {
#$this->displayFromSystemVariables();
$this->createSystemVariablesMapping();
} else {
# sporočilo za personalizirana e-vabila in respondente iz baze
echo ''.$lang['srv_inv_recipiens_field_note'].'';
echo ' ';
echo '
';
echo '
';
$field_lang = array();
if (count($field_list ) > 0) {
foreach ($field_list AS $field => $checked) {
# ali je polje izbrano ( če imamo personalizirano e-vabilo, moramo nujno imeti polje email
$is_selected = ($checked == 1 ) ? true : false;
# če je polje obkljukano
$css = $is_selected ? ' class="inv_field_enabled"' : '';
$label_for = ' for="'.$field.'_chk"';
echo '
';
echo ' ';
echo ' ';
}
}
}
// Seznam stevilk ki so v vrsti za klicanje
function callingList() {
global $lang;
global $site_url;
// Najprej cakalna vrsta (stevilke ki se bodo prikazale kasneje)
$this->waitingList();
echo '
';
// Se vrsta stevilk ki se trenutno klicejo
echo '
'.$lang['srv_telephone_navi_calling_list'].'
';
// Dobimo seznam vseh ki se niso bili klicani
$toCall = $this->getAllNumbers();
if (count($toCall) > 0) {
# Katera polja prikazujemo v seznamu prejemnikov
$fields = array();
$default_fields = array(
'phone' => 1,
'email' => 0,
'password' => 0,
'firstname' => 0,
'lastname' => 0,
'salutation' => 0,
'custom' => 0,
);
$sql_select_fields = array();
$fields['ps_icon'] = 1;
$fields['schstatus'] = 1;
$sql_select_fields[] = " i.last_status as ps_icon";
$sql_select_fields[] = " i.last_status as last_status";
$sql_select_fields[] = " scc.rec_id AS sccusr";
$sql_select_fields[] = " scs.call_time AS schedule_call_time";
# polovimo še iz baze klicev, zadnji statuse
$sql_select_fields[] = " sch.status AS schstatus";
$sql_select_fields[] = " scm.comment AS comment";
foreach($toCall as $usr_id => $phone){
#koliko zapisov bi morali prikazovati
$sql_query_filterd_all = sisplet_query("SELECT i.* FROM srv_invitations_recipients AS i WHERE i.ank_id='".$this->sid."' AND i.id='".$usr_id."'");
$sql_row = mysqli_fetch_assoc($sql_query_filterd_all);
foreach ($default_fields AS $key => $value) {
# če polje še ni dodano in če ni prazno, ga dodamo
if ($fields[$key] == 0 && isset($sql_row[$key]) && trim($sql_row[$key]) != '') {
$fields[$key] = 1;
$sql_select_fields[] = 'i.'.$key;
}
}
}
$fields['schedule_call_time'] = 1;
$fields['last_status'] = 1;
$fields['comment'] = 1;
$fields['date_inserted'] = 1;
$fields['usr_email'] = 1;
$fields['list_id'] = 1;
# dodamo še ostala polja
$sql_select_fields[] = 'i.last_status';
$sql_select_fields[] = 'i.date_inserted';
$sql_select_fields[] = 'i.list_id';
$sql_select_fields[] = 'usrs.email AS usr_email';
#dodamo paginacijo in poiščemo zapise
$page = isset($_GET['page']) ? $_GET['page'] : '1';
$limit_start = ($page * REC_ON_PAGE) - REC_ON_PAGE;
# polovimo sezname
$lids = array();
$sql_string_users = "SELECT i.list_id FROM srv_invitations_recipients AS i WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND TRIM(phone) !='' GROUP BY i.list_id ORDER BY i.id LIMIT $limit_start,".REC_ON_PAGE.'';
$sql_query_users = sisplet_query($sql_string_users);
while ($row_users = mysqli_fetch_assoc($sql_query_users)) {
$lids[] = $row_users['list_id'];
}
#seznami
$lists = array();
$lists['-1'] = array('name'=>$lang['srv_invitation_new_templist']);
$lists['0'] = array('name'=>$lang['srv_invitation_new_templist_author']);
if (count($lids) > 0 ) {
$sql_string_lists = "SELECT name, pid from srv_invitations_recipients_profiles WHERE pid IN(".implode(',',$lids).") ";
$sql_query_lists = sisplet_query($sql_string_lists);
while ($row_lists = mysqli_fetch_assoc($sql_query_lists)) {
$lists[$row_lists['pid']] = array('name'=>$row_lists['name']);
}
}
// Stevilo stevilk v vrsti
echo '
';
// Podatki tabele
$cnt = 1;
foreach($toCall as $usr_id => $phone){
$sql_query_filterd = sisplet_query("SELECT i.id, ".implode(',',$sql_select_fields)." FROM srv_invitations_recipients AS i"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id FROM srv_telephone_current) AS scc ON scc.rec_id = i.id"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id, call_time FROM srv_telephone_schedule) AS scs ON scs.rec_id = i.id"
# polovimo še iz baze klicev, zadnji statuse
." LEFT OUTER JOIN (SELECT rsch.status, rsch.rec_id FROM srv_telephone_history AS rsch INNER JOIN (SELECT MAX(id) as iid, rec_id FROM srv_telephone_history GROUP BY rec_id) as insch ON insch.iid = rsch.id) AS sch ON sch.rec_id = i.id"
# polovimo še morebitne komentarje
." LEFT OUTER JOIN (SELECT rec_id,comment FROM srv_telephone_comment) AS scm ON scm.rec_id = i.id"
# polovimo še kdo je dodal
." LEFT OUTER JOIN (SELECT id, email FROM users) AS usrs ON usrs.id = i.inserted_uid"
." WHERE i.ank_id='".$this->sid."' AND i.id='".$usr_id."'");
if (!$sql_query_filterd) echo mysqli_error($GLOBALS['connect_db']);
$sql_row = mysqli_fetch_assoc($sql_query_filterd);
$icon = ' phn_ico_status_go';
switch ($sql_row['schstatus']) {
case 'U':
$icon = ' phn_ico_status';
break;
case 'R':
$icon = ' phn_ico_status_key';
break;
case 'N': #ga ni
case 'Z': #zaseden
case 'T': #zmenjen
case 'D': #prelozen
$icon = ' phn_ico_status_error';
break;
default:
;
break;
}
# če je odjavljen damo isto ikonco za zaklepanje
if ((int)$row_users['unsubscribed'] == 1) {
$icon = ' phn_ico_status_key';
}
echo '
';
echo '
'.$cnt.'
';
foreach ($fields AS $fkey =>$field) {
if ($field == 1) {
switch ($fkey) {
case 'ps_icon':
echo '
';
// Podatki tabele
$cnt = 1;
foreach($toCall as $usr_id => $phone){
$sql_query_filterd = sisplet_query("SELECT i.id, ".implode(',',$sql_select_fields)." FROM srv_invitations_recipients AS i"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id FROM srv_telephone_current) AS scc ON scc.rec_id = i.id"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id, call_time FROM srv_telephone_schedule) AS scs ON scs.rec_id = i.id"
# polovimo še iz baze klicev, zadnji statuse
." LEFT OUTER JOIN (SELECT rsch.status, rsch.rec_id FROM srv_telephone_history AS rsch INNER JOIN (SELECT MAX(id) as iid, rec_id FROM srv_telephone_history GROUP BY rec_id) as insch ON insch.iid = rsch.id) AS sch ON sch.rec_id = i.id"
# polovimo še morebitne komentarje
." LEFT OUTER JOIN (SELECT rec_id,comment FROM srv_telephone_comment) AS scm ON scm.rec_id = i.id"
# polovimo še kdo je dodal
." LEFT OUTER JOIN (SELECT id, email FROM users) AS usrs ON usrs.id = i.inserted_uid"
." WHERE i.ank_id='".$this->sid."' AND i.id='".$usr_id."'");
if (!$sql_query_filterd) echo mysqli_error($GLOBALS['connect_db']);
$sql_row = mysqli_fetch_assoc($sql_query_filterd);
$icon = ' phn_ico_status_go';
switch ($sql_row['schstatus']) {
case 'U':
$icon = ' phn_ico_status';
break;
case 'R':
$icon = ' phn_ico_status_key';
break;
case 'N': #ga ni
case 'Z': #zaseden
case 'T': #zmenjen
case 'D': #prelozen
$icon = ' phn_ico_status_error';
break;
default:
;
break;
}
# če je odjavljen damo isto ikonco za zaklepanje
if ((int)$row_users['unsubscribed'] == 1) {
$icon = ' phn_ico_status_key';
}
echo '
';
echo '
'.$cnt.'
';
foreach ($fields AS $fkey =>$field) {
if ($field == 1) {
switch ($fkey) {
case 'ps_icon':
echo '
';
#polovimo prejemnike ki ne želijo prejemati obvestil
# nastavimo filter
session_start();
$filter = $_SESSION['inv_filter']['value'];
if ($filter != '') {
$mysql_filter = " AND ("
. "i.email LIKE '%".$filter."%'"
. "OR i.firstname LIKE '%".$filter."%'"
. "OR i.lastname LIKE '%".$filter."%'"
. "OR i.password LIKE '%".$filter."%'"
. "OR i.salutation LIKE '%".$filter."%'"
. "OR i.phone LIKE '%".$filter."%'"
. "OR i.custom LIKE '%".$filter."%'"
. ")";
$mysql_filter2 = " AND ("
. "i.email LIKE '%".$filter."%'"
. "OR i.firstname LIKE '%".$filter."%'"
. "OR i.lastname LIKE '%".$filter."%'"
. "OR i.password LIKE '%".$filter."%'"
. "OR i.salutation LIKE '%".$filter."%'"
. "OR i.phone LIKE '%".$filter."%'"
. "OR i.custom LIKE '%".$filter."%'"
. "OR scm.comment LIKE '%".$filter."%'"
. ")";
}
# preštejemo koliko imamo vseh respondentov in koliko jih je brez e-maila
$sql_string_all = "SELECT id FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted = '0' AND TRIM(phone) !=''";
$sql_query_all = sisplet_query($sql_string_all);
$count_all = mysqli_num_rows($sql_query_all);
$sql_string_withot_email = "SELECT count(*) FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted = '0' AND email IS NULL AND sent='0'";
$sql_query_without_email = sisplet_query($sql_string_withot_email);
$sql_row_without_email = mysqli_fetch_row($sql_query_without_email);
$count_without_email = $sql_row_without_email[0];
#koliko zapisov bi morali prikazovati
$sql_string_filterd_all = "SELECT i.* FROM srv_invitations_recipients AS i WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND TRIM(phone) !='' ".$mysql_filter." ORDER BY i.id";
$sql_query_filterd_all = sisplet_query($sql_string_filterd_all);
$filtred_all = mysqli_num_rows($sql_query_filterd_all);
$fields = array();
# Katera polja prikazujemo v seznamu prejemnikov
$default_fields = array(
'phone' => 1,
'email' => 0,
'password' => 0,
'firstname' => 0,
'lastname' => 0,
'salutation' => 0,
'custom' => 0,
);
$sql_select_fields = array();
$fields['ps_icon'] = 1;
$fields['schstatus'] = 1;
$sql_select_fields[] = " i.last_status as ps_icon";
$sql_select_fields[] = " i.last_status as last_status";
$sql_select_fields[] = " scc.rec_id AS sccusr";
$sql_select_fields[] = " scs.call_time AS schedule_call_time";
# polovimo še iz baze klicev, zadnji statuse
$sql_select_fields[] = " sch.status AS schstatus";
$sql_select_fields[] = " scm.comment AS comment";
# pogledamo katera polja dejansko prikazujemo
while ($sql_row = mysqli_fetch_assoc($sql_query_filterd_all)) {
foreach ($default_fields AS $key => $value) {
# če polje še ni dodano in če ni prazno, ga dodamo
if ($fields[$key] == 0 && isset($sql_row[$key]) && trim($sql_row[$key]) != '') {
$fields[$key] = 1;
$sql_select_fields[] = 'i.'.$key;
}
}
}
$fields['schedule_call_time'] = 1;
$fields['last_status'] = 1;
$fields['comment'] = 1;
$fields['date_inserted'] = 1;
$fields['usr_email'] = 1;
$fields['list_id'] = 1;
# dodamo še ostala polja
$sql_select_fields[] = 'i.last_status';
$sql_select_fields[] = 'i.date_inserted';
$sql_select_fields[] = 'i.list_id';
$sql_select_fields[] = 'usrs.email AS usr_email';
#štetje vabil
#$fields['count_inv'] = 1;
#$sql_select_fields[] = 'count(siar.arch_id) AS count_inv';
#dodamo paginacijo in poiščemo zapise
$page = isset($_GET['page']) ? $_GET['page'] : '1';
$limit_start = ($page*REC_ON_PAGE)-REC_ON_PAGE;
#dodamo sortiranje
$sort_string = $this->getSortString();
# $sql_string_filterd = "SELECT i.id, ".implode(',',$sql_select_fields)." FROM srv_invitations_recipients AS i LEFT JOIN srv_invitations_archive_recipients AS siar ON (i.id = siar.rec_id) WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0'".$mysql_filter.' GROUP BY siar.rec_id '.$sort_string." LIMIT $limit_start,".REC_ON_PAGE;
$sql_string_filterd = "SELECT i.id, ".implode(',',$sql_select_fields)." FROM srv_invitations_recipients AS i"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id FROM srv_telephone_current) AS scc ON scc.rec_id = i.id"
# polovimo še iz baze klicev, vse trenutno zacete klice
." LEFT OUTER JOIN (SELECT rec_id, call_time FROM srv_telephone_schedule) AS scs ON scs.rec_id = i.id"
# polovimo še iz baze klicev, zadnji statuse
." LEFT OUTER JOIN (SELECT rsch.status, rsch.rec_id FROM srv_telephone_history AS rsch INNER JOIN (SELECT MAX(id) as iid, rec_id FROM srv_telephone_history GROUP BY rec_id) as insch ON insch.iid = rsch.id) AS sch ON sch.rec_id = i.id"
# polovimo še morebitne komentarje
." LEFT OUTER JOIN (SELECT rec_id,comment FROM srv_telephone_comment) AS scm ON scm.rec_id = i.id"
# polovimo še kdo je dodal
." LEFT OUTER JOIN (SELECT id, email FROM users) AS usrs ON usrs.id = i.inserted_uid"
." WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND TRIM(phone) !='' ".$mysql_filter2.' '.$sort_string." LIMIT $limit_start,".REC_ON_PAGE;
$sql_query_filterd = sisplet_query($sql_string_filterd);
if (!$sql_query_filterd) echo mysqli_error($GLOBALS['connect_db']);
# polovimo sezname
$lids = array();
$sql_string_users = "SELECT i.list_id FROM srv_invitations_recipients AS i WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND TRIM(phone) !=''".$mysql_filter." GROUP BY i.list_id ORDER BY i.id LIMIT $limit_start,".REC_ON_PAGE.'';
$sql_query_users = sisplet_query($sql_string_users);
while ($row_users = mysqli_fetch_assoc($sql_query_users)) {
$lids[] = $row_users['list_id'];
}
#seznami
$lists = array();
$lists['-1'] = array('name'=>$lang['srv_invitation_new_templist']);
$lists['0'] = array('name'=>$lang['srv_invitation_new_templist_author']);
if (count($lids) > 0 ) {
$sql_string_lists = "SELECT name, pid from srv_invitations_recipients_profiles WHERE pid IN(".implode(',',$lids).") ";
$sql_query_lists = sisplet_query($sql_string_lists);
while ($row_lists = mysqli_fetch_assoc($sql_query_lists)) {
$lists[$row_lists['pid']] = array('name'=>$row_lists['name']);
}
}
if (count($msgs) > 0) {
echo '';
foreach($msgs as $msg) {
echo '* '.$msg.' ';
}
echo '';
}
if (count($errors) > 0) {
echo '';
foreach($errors as $error) {
echo '* '.$error.' ';
}
echo '';
}
if ($count_all > 0 ) {
// dodamo filtriranje
echo '
';
}
/**
* @desc prikaze prvo stran z linkom na zacni
*/
function startCall() {
global $lang;
#preverimo koliko številk imamo na voljo
$numbersAvailable = $this->getAllNumbers();
# preverimo aktivnost ankete
if ($this->surveySettings['active'] != 1) {
echo $lang['srv_inv_error9'];
if ($this->isAnketar == true) {
return;
}
}
if (count($numbersAvailable) > 0 ) {
echo '
';
} else {
$this->getNextTimeCall();
}
}
/**
* @desc zacne s klicanjem telefonskih stevilk
*/
function Call() {
global $site_root, $global_user_id;
$schedule = false;
// stevilka je izbrana - klicana
if ($_GET['usr_id'] != '' && (int)$_GET['usr_id'] > 0) {
$usr_id = (int)$_GET['usr_id'];
// zbrisemo cookie za izpolnjevanje -- da ne dobi od prejsnjega, ce je nehu nekje vmes
setcookie('survey-'.$this->sid, '', time()-3600, str_replace($_SERVER['DOCUMENT_ROOT'], '', $site_root).'main/survey/');
sisplet_query("DELETE FROM srv_telephone_schedule WHERE rec_id = '$usr_id'");
sisplet_query("INSERT INTO srv_telephone_current (rec_id, user_id, started_time) VALUES ('$usr_id', '".$global_user_id."', NOW())");
}
else {
// Po novem moramo pri kliku "klici drugo" pobrisati current iz baze
if(isset($_GET['n']) && $_GET['n'] == 'clear_current')
sisplet_query("DELETE srv_telephone_current FROM srv_telephone_current, srv_invitations_recipients
WHERE srv_telephone_current.user_id='".$global_user_id."' AND srv_telephone_current.rec_id = srv_invitations_recipients.id AND srv_invitations_recipients.ank_id='".$this->sid."'");
#uporabnik ni izbran določimo izberemo ga naklučno oziroma če smo dogovorjeni
$row = $this->get_next_number();
$usr_id = $row['usr_id'];
$schedule = (int)$row['schedule'] == 1 ? true : false;
}
if ((int)$usr_id > 0) {
# preverimo ali je uporabnik že začel klicat
$openedSurvey = ($_GET['usr_id'] != '' && (int)$_GET['usr_id'] > 0) ? true : false;
$this->userCallToShow($usr_id,$openedSurvey,$schedule);
// Po novem ze ob prikazu stevilke zaklenemo respondenta (da ga ne moreta 2 anketarja hkrati poklicati preden odpreta anketo)
$sql = sisplet_query("SELECT * FROM srv_telephone_current WHERE rec_id='".$usr_id."' AND user_id='".$global_user_id."' AND started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)");
if(mysqli_num_rows($sql) == 0)
sisplet_query("INSERT INTO srv_telephone_current (rec_id, user_id, started_time) VALUES ('$usr_id', '".$global_user_id."', NOW())");
}
else {
$this->getNextTimeCall();
}
}
function settings() {
global $lang, $site_url;
echo '';
echo '
'.$lang['srv_success_save'].'
';
}
function settingsSave() {
$this->status_z = (int)$_POST[status_z];
$this->status_n = (int)$_POST[status_n];
$this->status_d = (int)$_POST[status_d];
$this->max_calls = (int)$_POST[max_calls];
$this->call_order = (int)$_POST[call_order];
sisplet_query("REPLACE srv_telephone_setting (survey_id, status_z, status_n, status_d, max_calls, call_order) VALUES ('$this->sid', '$this->status_z ', '$this->status_n', '$this->status_d', '$this->max_calls', '$this->call_order')");
#dodamo dostop za anketarja
if (count($_POST['dostop']) > 0) {
$uids = array();
foreach ($_POST['dostop'] AS $uid => $on) {
$uids[] = $uid;
}
#najprej odstranimo vsem kateri niso v post
$str_remove = "UPDATE srv_dostop SET dostop = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', dostop, ','),CONCAT(',', 'phone', ','), ','))"
." WHERE ank_id='$this->sid' AND uid NOT IN(".implode(",",$uids).")";
$s1 = sisplet_query($str_remove);
if (!$s1) echo 'err_phn_dostop_001'.mysqli_error($GLOBALS['connect_db']);
#nato dodamo vsem ki so v post.
;
$str_update = "UPDATE srv_dostop SET dostop = CONCAT(dostop, ',phone')"
." WHERE ank_id='$this->sid' AND uid IN(".implode(",",$uids).")";
$s2 = sisplet_query($str_update);
if (!$s2) echo 'err_phn_dostop_002'.mysqli_error($GLOBALS['connect_db']);
}
}
/**
* @desc vrne ID spremenljivke telefon
*/
function get_spr_telefon_id () {
$sql = sisplet_query("SELECT srv_spremenljivka.id
FROM srv_spremenljivka, srv_grupa
WHERE srv_spremenljivka.variable = 'telefon'
AND srv_spremenljivka.sistem = '1'
AND srv_spremenljivka.gru_id = srv_grupa.id
AND srv_grupa.ank_id = '$this->sid'
");
$row = mysqli_fetch_array($sql);
return $row['id'];
}
function addSortField($field){
$type = 'ASC';
session_start();
if ($_SESSION['phn_rec_sort_field'] == $field) {
if ($_SESSION['phn_rec_sort_type'] == 'DESC') {
$type = 'ASC';
} else {
$type = 'DESC';
}
} else {
$type = 'ASC';
}
return ' onclick="phn_set_sort_field(\''.$field.'\',\''.$type.'\');" ';
}
function addSortIcon($field){
session_start();
if ($_SESSION['phn_rec_sort_field'] == $field) {
if ($_SESSION['phn_rec_sort_type'] == 'DESC') {
return ' ';
} else {
return ' ';
}
}
return;
}
function setSortField() {
session_start();
if (isset($_POST['field']) && trim($_POST['field']) != '') {
$_SESSION['phn_rec_sort_field'] = trim($_POST['field']);
} else {
$_SESSION['phn_rec_sort_field'] = 'date_inserted';
}
if (isset($_POST['type']) && trim($_POST['type']) != '') {
$_SESSION['phn_rec_sort_type'] = trim($_POST['type']);
} else {
$_SESSION['phn_rec_sort_type'] = 'ASC';
}
session_commit();
}
function getSortString() {
session_start();
$sort_string = ' ORDER BY i.id ASC';
if (isset($_SESSION['phn_rec_sort_field']) && trim($_SESSION['phn_rec_sort_field']) != '') {
$prefix = 'i.';
if ($_SESSION['phn_rec_sort_field'] == 'count_inv'
|| $_SESSION['phn_rec_sort_field'] == 'ps_icon'
|| $_SESSION['phn_rec_sort_field'] == 'schedule_call_time'
|| $_SESSION['phn_rec_sort_field'] == 'comment'
|| $_SESSION['phn_rec_sort_field'] == 'usr_email'
|| $_SESSION['phn_rec_sort_field'] == 'schstatus') {
$prefix = '';
}
$sort_string = ' ORDER BY '.$prefix.trim($_SESSION['phn_rec_sort_field']);
if ($_SESSION['phn_rec_sort_type'] == 'DESC') {
$sort_string .= ' DESC, i.id DESC';
} else {
$sort_string .= ' ASC, i.id ASC';
}
}
return $sort_string ;
/*
session_start();
$sort_string = ' ORDER BY u.id';
if (isset($_SESSION['phn_rec_sort_field']) && trim($_SESSION['phn_rec_sort_field']) != '') {
#$prefix = 'std_'.$_SESSION['phn_rec_sort_field'].'.';
$sort_string = ' ORDER BY '.$prefix.trim($_SESSION['phn_rec_sort_field']);
if ($_SESSION['phn_rec_sort_type'] == 'DESC') {
$sort_string .= ' DESC';
} else {
$sort_string .= ' ASC';
}
}
return $sort_string;
*/
}
/**
* @desc preveri ce je kaksna nova stevilka (tudi prek ajaxa)
*/
function preveri_stevilke () {
global $lang;
$row = $this->get_next_number();
if ($row['usr_id'] > 0) {
echo '
';
$sql1 = sisplet_query("SELECT srv_telephone_schedule.*
FROM srv_telephone_schedule, srv_invitations_recipients
WHERE
srv_invitations_recipients.deleted ='0' AND
srv_telephone_schedule.rec_id = srv_invitations_recipients.id AND
srv_invitations_recipients.ank_id = '$this->sid' AND
srv_telephone_schedule.call_time > NOW() AND
srv_telephone_schedule.rec_id NOT IN (
SELECT srv_telephone_current.rec_id
FROM srv_telephone_current
WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
) AND
srv_telephone_schedule.rec_id NOT IN (
SELECT srv_telephone_history.rec_id
FROM srv_telephone_history
GROUP BY srv_telephone_history.rec_id
HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'
)
ORDER BY srv_telephone_schedule.call_time ASC LIMIT 1
");
$row1 = mysqli_fetch_array($sql1);
if (mysqli_num_rows($sql1) > 0)
echo '
';
echo '';
}
}
/**
* @desc vrne naslednji row s stevilko za klic
*/
function get_next_number () {
global $global_user_id;
# najprej pogledamo ce je kaksen v srv_telephone_current - mor ga obvezno razresiti ker je zaklenjen
$sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text"
." FROM srv_telephone_current LEFT JOIN srv_invitations_recipients ON srv_telephone_current.rec_id = srv_invitations_recipients.id "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND srv_telephone_current.user_id = $global_user_id"
." AND srv_telephone_current.rec_id = srv_invitations_recipients.id"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ORDER BY srv_invitations_recipients.id ASC"
." LIMIT 1";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
return mysqli_fetch_array($sql);
}
// najprej selectamo, tiste ki so zmenjeni po urniku
$sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text, '1' AS schedule"
." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_telephone_schedule.call_time <= NOW()"
." AND srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_current.rec_id"
." FROM srv_telephone_current"
." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT DISTINCT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." GROUP BY srv_telephone_history.rec_id"
." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'"
." )"
." ORDER BY srv_telephone_schedule.call_time ASC"
." LIMIT 1";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
return mysqli_fetch_array($sql);
}
// ce ni nobenega na urniku pa nadaljujemo z random izbiro ostalih stevilk
/* fetch random from available
* exclude from fetch:
* - all phones which are currently active
* - all phones which are on the schedule for the future
* - all phones which have "R" or "U" status
* - all phones which are called more that "max_calls" setting
*/
// Sortiranje
if($this->call_order == 1)
$order_by = ' srv_invitations_recipients.id ASC';
elseif($this->call_order == 2)
$order_by = ' srv_invitations_recipients.firstname ASC, srv_invitations_recipients.lastname ASC, srv_invitations_recipients.email ASC, srv_invitations_recipients.id ASC';
elseif($this->call_order == 3)
$order_by = ' srv_invitations_recipients.firstname DESC, srv_invitations_recipients.lastname DESC, srv_invitations_recipients.email DESC, srv_invitations_recipients.id DESC';
else
$order_by = ' RAND()';
$sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text, '0' AS schedule"
." FROM srv_invitations_recipients"
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_current.rec_id"
." FROM srv_telephone_current"
." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_schedule.rec_id"
." FROM srv_telephone_schedule"
." WHERE srv_telephone_schedule.call_time > NOW()"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." GROUP BY srv_telephone_history.rec_id"
." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'"
." )"
." ORDER BY ".$order_by.""
." LIMIT 1";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
return mysqli_fetch_array($sql);
}
/**
* @desc vrne vse stevilke ki se trenutno klicejo (s pravim vrstnim redom)
*/
function getAllNumbers () {
global $global_user_id;
$result = array();
# najprej pogledamo ce je kaksen v srv_telephone_current - mor ga obvezno razresiti ker je zaklenjen
$sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone"
." FROM srv_telephone_current LEFT JOIN srv_invitations_recipients ON srv_telephone_current.rec_id = srv_invitations_recipients.id "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND srv_telephone_current.user_id = $global_user_id"
." AND srv_telephone_current.rec_id = srv_invitations_recipients.id"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ORDER BY srv_invitations_recipients.id ASC";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
while ( list($id,$phone) = mysqli_fetch_row($sql)) {
$result[$id] = $phone;
}
}
# najprej selectamo, tiste ki so zmenjeni po urniku
$sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone"
." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_telephone_schedule.call_time <= NOW()"
." AND srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_current.rec_id"
." FROM srv_telephone_current"
." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT DISTINCT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." GROUP BY srv_telephone_history.rec_id"
." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'"
.")"
." ORDER BY srv_invitations_recipients.id ASC";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
while ( list($id,$phone) = mysqli_fetch_row($sql)) {
$result[$id] = $phone;
}
}
# ce ni nobenega na urniku pa nadaljujemo z random izbiro ostalih stevilk
/* fetch random from available
* exclude from fetch:
* - all phones which are currently active
* - all phones which are on the schedule for the future
* - all phones which have "R" or "U" status
* - all phones which are called more that "max_calls" setting
*/
// Sortiranje
if($this->call_order == 1)
$order_by = ' srv_invitations_recipients.id ASC';
elseif($this->call_order == 2)
$order_by = ' srv_invitations_recipients.firstname ASC, srv_invitations_recipients.lastname ASC, srv_invitations_recipients.email ASC, srv_invitations_recipients.id ASC';
elseif($this->call_order == 3)
$order_by = ' srv_invitations_recipients.firstname DESC, srv_invitations_recipients.lastname DESC, srv_invitations_recipients.email DESC, srv_invitations_recipients.id DESC';
else
$order_by = ' RAND()';
$sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone"
." FROM srv_invitations_recipients "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_current.rec_id"
." FROM srv_telephone_current"
." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_schedule.rec_id"
." FROM srv_telephone_schedule"
." WHERE srv_telephone_schedule.call_time > NOW()"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." GROUP BY srv_telephone_history.rec_id"
." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'"
." )"
."ORDER BY ".$order_by."";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
while ( list($id,$phone) = mysqli_fetch_row($sql)) {
$result[$id] = $phone;
}
}
return $result;
}
/**
* @desc vrne vse stevilke ki so na cakanju in bodo kasneje poklicane
*/
function getAllNumbersWaiting () {
$result = array();
# selectamo, tiste ki so zmenjeni po urniku kasneje
$sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone"
." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id "
." WHERE srv_invitations_recipients.ank_id ='$this->sid'"
." AND srv_invitations_recipients.deleted ='0'"
." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id"
." AND TRIM(srv_invitations_recipients.phone) != ''"
." AND srv_telephone_schedule.call_time > NOW()"
." AND srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_current.rec_id"
." FROM srv_telephone_current"
." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT DISTINCT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'"
." ) AND"
." srv_invitations_recipients.id NOT IN ("
." SELECT srv_telephone_history.rec_id"
." FROM srv_telephone_history"
." GROUP BY srv_telephone_history.rec_id"
." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'"
.")"
." ORDER BY srv_telephone_schedule.call_time ASC";
$sql = sisplet_query($sel);
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0) {
while ( list($id,$phone) = mysqli_fetch_row($sql)) {
$result[$id] = $phone;
}
}
return $result;
}
function addMark($options = array()) {
global $site_url,$global_user_id;
if (is_array($options) && isset($options['usr_id']) && (int)$options['usr_id'] > 0) {
$usr_id = $options['usr_id'];
} else {
$usr_id = $_GET['usr_id'];
}
if (is_array($options) && isset($options['status']) && (int)$options['status'] > 0) {
$status = $options['status'];
} else {
$status = $_GET['status'];
}
if (is_array($options) && isset($options['datetime']) && (int)$options['datetime'] > 0) {
$datetime = $options['status'];
} else {
$datetime = $_GET['datetime'];
}
if ($status != '') {
sisplet_query("INSERT INTO srv_telephone_history (survey_id, user_id, rec_id, insert_time, status) VALUES ('$this->sid', '".$global_user_id."', '$usr_id', NOW(), '$status')");
}
if ($status != 'A') {
sisplet_query("DELETE FROM srv_telephone_current WHERE rec_id='$usr_id'");
} else {
$s = sisplet_query("INSERT INTO srv_telephone_current (rec_id, user_id, started_time) VALUES ('$usr_id', '".$global_user_id."', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
if ($status == 'Z') {
$s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_z MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
if ($status == 'N') {
$s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_n MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)");
}
if ($status == 'D') {
$s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_d MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)");
}
if ($status == 'T' || $status == 'P') {
$datetime = substr($datetime,6,4).'-'.substr($datetime,3,2).'-'.substr($datetime,0,2).' '.substr($datetime,11,5).':00';
$s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', '$datetime') ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)");
}
# če je zavrnil (R) potem izbrišemo morebitne zmenke
if ($status == 'R' ) {
sisplet_query("DELETE FROM srv_telephone_schedule WHERE rec_id='$usr_id'");
}
#nardimo pravilne redirekte
# ker imamo spodaj exit de ne izvede klasičen komit
sisplet_query('COMMIT');
if ($status == 'A') {
header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call&usr_id=".$usr_id.'&status='.$status);
exit();
} else {
session_start();
if (isset($_SESSION['phnNextAction'][$this->sid]) && (int)$_SESSION['phnNextAction'][$this->sid] == '0') {
# če je anketar je lako samo na klicanu
if ($this->isAnketar) {
header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call"); #'&status='.$status
exit();
}
header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=view_recipients");
exit();
} else {
header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call"); #.'&status='.$status
exit();
}
}
}
function preveriStevilkeTimer () {
$this->preveri_stevilke();
}
function addRecipients() {
global $global_user_id;
$fields = $_POST['fields'];
$_recipients = $_POST['recipients_list'];
$recipients_list = str_replace("\n\r", "\n", $recipients_list);
# povezava imena polji iz forem, z imeni polji v bazi
$db_vs_form_array = array(
'inv_field_email' => 'email',
'inv_field_firstname' => 'firstname',
'inv_field_lastname' => 'lastname',
'inv_field_password' => 'password',
'inv_field_cookie' => 'cookie',
'inv_field_salutation' => 'salutation',
'inv_field_phone' => 'phone',
'inv_field_custom' => 'custom',
);
$fields = $_POST['fields'];
if (!is_array($fields)) {
$fields = array();
}
# katero polje je za password
if (in_array('inv_field_password',$fields)) {
$user_password = true;
} else {
$user_password = false;
}
#dodamo potrebna sistemska polja
$this->addSystemVariables($fields);
# dodamo ustrezne uporabnike, neustrezne izpišemo še enkrat da se lahko popravijo
$_recipients = str_replace("\n\r", "\n", $_recipients);
$recipients_list = explode("\n",$_recipients);
$num_recipients_list = count($recipients_list);
# katero polje je za e-mail
if (in_array('inv_field_email',$fields)) {
$user_email = true;
} else {
}
# polje cookie mora bit zraven
if (!in_array('inv_field_cookie',$fields)) {
$fields[] = 'inv_field_cookie';
}
# polovimo že dodane prejemnike iz baze
$user_in_db = array();
$sql_string = "SELECT firstname,lastname,salutation,phone,custom FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted='0'";
$sql_query = sisplet_query($sql_string);
if (mysqli_num_rows($sql_query) > 0 ) {
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$user_in_db[] = $sql_row['firstname'].$sql_row['lastname'].$sql_row['salutation'].$sql_row['phone'].$sql_row['custom'];
}
}
# katero polje je za password
if (in_array('inv_field_password',$fields)) {
$user_password = true;
} else {
$user_password = false;
# dodamo polje password
$fields[] = 'inv_field_password';
}
# polja za bazo
$db_fields = '';
foreach ($fields as $field) {
$db_fields .= ', '.$db_vs_form_array[$field];
}
# katera gesla (code) že imamo v bazi za to anketo
$password_in_db = array();
$sql_string = "SELECT password FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted='0'";
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$password_in_db[$sql_row['password']] = $sql_row['password'];
}
$unsubscribed = array();
/*polovimo prejemnike ki ne želijo prejemati obvestil
$sql_string = "SELECT email FROM srv_invitations_recipients WHERE unsubscribed = '1'";
$sql_query = sisplet_query($sql_string);
$unsubscribed = array();
if (mysqli_num_rows($sql_query) > 0 ) {
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$unsubscribed[] = $sql_row['email'];
}
}*/
#array z veljavnimi zapisi
$valid_recipiens_array = array();
# array z zapisi kjer so napake v geslih
$invalid_password_array = array();
#array z zapisi kjer so neveljavna gesla
$invalid_email_array = array();
#array z podvojenimi zapisi
$duplicate_email_array = array();
#aray z zapisi kjer so uporabniki izbrali da ne želijo prejemat e-mailov
$unsubscribed_recipiens_array = array();
if ( $num_recipients_list > 0 ) {
foreach ($recipients_list AS $recipient_line) {
$recipient_line = trim($recipient_line);
if ($recipient_line != null && $recipient_line != '') {
$line_array = explode(',',$recipient_line);
# predpostavljamo da je vrstica vredu
$invalid_line = false;
#prilagodimo izbrana polja
$recipent_array = array();
$i = 0;
foreach ($fields AS $field) {
$recipent_array[$field] = $line_array[$i];
$i++;
}
# izvedemo validacijo posameznih polij
# najprej preverimo gesla, če niso uporabniško določena, jih dodelimo sami
if ( $invalid_line == false ) {
# če še ni bilo napake ( da ne podvajamo zapisov pri katerih je več napak)
if ($user_password == false) {
# gesla določamo avtomatsko, (ne bo problemov :] )
# Izberemo random hash, ki se ni v bazi
do {
list($code,$cookie) = $this->generateCode();
} while (in_array($code,$password_in_db));
# polje za geslo je na zadnjem mestu (smo ga dodali zgoraj)
$recipent_array['inv_field_password'] = $code;
$recipent_array['inv_field_cookie'] = $cookie;
# če je vse ok, geslo dodamo v seznam že uporabljenih
$password_in_db[$code] = $code;
} else {
# gesla je določil uporabnik, (dajmo ga malo preverit)
$user_password = trim($recipent_array['inv_field_password']);
# preverimo ali je geslo že v bazi
if ($user_password == null || $user_password == '' || in_array($user_password,$password_in_db)) {
$invalid_password_array[] = $recipient_line;
$invalid_line = true;
}
# če je vse ok, geslo dodamo v seznam že uporabljenih
if ($invalid_line == false) {
$password_in_db[$user_password] = $user_password;
#dodamo še piškotek
list($code,$cookie) = $this->generateCode();
$recipent_array['inv_field_cookie'] = $cookie;
}
}
}
# če imamo emaile naredimo validacijo, preverimo zavrnitve.. itd
// if ($user_email == true && $invalid_line == false) {
if ($invalid_line == false) {
# # preberemo uporabniški email
$email_field = trim($recipent_array['inv_field_firstname'])
. trim($recipent_array['inv_field_lastname'])
. trim($recipent_array['inv_field_salutation'])
. trim($recipent_array['inv_field_phone'])
. trim($recipent_array['inv_field_custom']);
/* #ali je email veljaven
if (!$this->validEmail($email_field) && $invalid_line == false) {
$invalid_email_array[] = $recipient_line;
$invalid_line = true;
}*/
# ali je email podvojen
if (in_array(strtolower($email_field),$user_in_db) && $invalid_line == false) {
$duplicate_email_array[] = strtolower($recipient_line);
$invalid_line = true;
}
/* ali uporabnik ne želi prejemati sporočil (opted out)
if (in_array($email_field,$unsubscribed) && $invalid_line == false) {
$unsubscribed_recipiens_array[] = $recipient_line;
$invalid_line = true;
}*/
# če je vse ok, email dodamo v seznam že uporabljenih
if ( $invalid_line == false) {
$user_in_db[] = $email_field;
}
}
# če je vse ok dodamo userja k veljavnim
if ( $invalid_line == false) {
$valid_recipiens_array[] = $recipent_array;
}
}
}
}
$list_id = (int)$_POST['pid'];
# pripravimo sql stavek za vstavljanje
if (count($valid_recipiens_array ) > 0) {
$sql_insert_start = "INSERT INTO srv_invitations_recipients (ank_id".$db_fields.",sent,responded,unsubscribed,deleted,date_inserted,inserted_uid,list_id) VALUES ";
$count = 0;
$sql_insert_array = array();
$cnt = 0;
$max_in_array = 1000; # po koliko respondentov dodajamo naenkeat
$array_loop = 0;
foreach ( $valid_recipiens_array AS $recipent_fields) {
$cnt++;
$sql_insert = "('".$this->sid."'";
foreach ($recipent_fields as $field) {
$sql_insert .= ", '$field'";
}
$sql_insert .= ",'0','0','0','0',NOW(),'".$global_user_id."','".$list_id."')";
$sql_insert_array[$array_loop][] = $sql_insert;
if ($cnt >= $max_in_array) {
$array_loop++;
$cnt = 0;
}
}
$sql_insert_end = " ON DUPLICATE KEY UPDATE firstname=VALUES(firstname), lastname=VALUES(lastname), salutation=VALUES(salutation), phone=VALUES(phone), custom=VALUES(custom), deleted='0', date_inserted=NOW()";
# v loopu dodamo posamezne respondente po skupinah (ker kadar je respondentov veliko mysql crkne)
if (count($sql_insert_array) > 0) {
foreach ($sql_insert_array AS $sub_insert_array) {
$query_insert = $sql_insert_start. implode(',',$sub_insert_array) .$sql_insert_end;
$sqlQuery = sisplet_query($query_insert);
$rows = mysqli_affected_rows($GLOBALS['connect_db']);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
}
sisplet_query("COMMIT");
}
}
return array( 'valid_recipiens' => $valid_recipiens_array,
'invalid_password' => $invalid_password_array,
'invalid_email' => $invalid_email_array,
'duplicate_email' => $duplicate_email_array,
'unsubscribed' => $unsubscribed_recipiens_array);
}
function addSystemVariables($variables) {
$user_base = 0;
global $site_path;
$system_fields = array(
'inv_field_email' => 'email',
'inv_field_firstname' => 'ime',
'inv_field_lastname' => 'priimek',
# 'inv_field_password' => 'geslo', # gesla ne dodajamo kot sistemsko spremenljivko
'inv_field_salutation' => 'naziv',
'inv_field_phone' => 'telefon',
'inv_field_custom' => 'drugo',
);
$variablesResult=array();
$sqlb = sisplet_query("SELECT branching, user_base FROM srv_anketa WHERE id = '".$this->sid."'");
$rowb = mysqli_fetch_array($sqlb);
$ba = new BranchingAjax($this->sid);
if (count($variables) > 0) {
// zakaj je bi ta reverse???
//$variables = array_reverse($variables,true);
foreach ($variables as $var) {
if (isset($system_fields[$var])) {
$spr_id = null;
if (isset($system_fields[$var])) {
$variable = $system_fields[$var];
} else {
$variable = str_replace('inv_field_', '', $var);
}
$sqlVariable = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.variable='".$variable."' AND s.gru_id=g.id AND g.ank_id='".$this->sid."'");
if (mysqli_num_rows($sqlVariable) == 0 && $variable!='pass') { // če varabla še ne obstaja jo kreiramo
// za polje pass - Geslo ne kreiramo sistemske variable
if ($variable != 'language') {
$user_base = 1;
}
// dodamo novo spremenljivko na konec, tip je 21
ob_start();
$ba->ajax_spremenljivka_new(0, 0, 1, 0, 21);
$spr_id = $ba->spremenljivka;
ob_clean();
$s = sisplet_query("UPDATE srv_spremenljivka SET variable='".$variable."', variable_custom='1', naslov='".$variable."', sistem='1', visible='0' WHERE id='$spr_id'");
if (!$s) echo 'err435'.mysqli_error($GLOBALS['connect_db']);
} else {
list($spr_id) = mysqli_fetch_row($sqlVariable);
}
$variablesResult[$variable] = (int)$spr_id;
}
}
}
// če je potreben updejt (ampak najbrž je itak na 1 zaradi e-mail)
if ($user_base > 0 && $user_base != $rowb['user_base']) {
$sql = sisplet_query("UPDATE srv_anketa SET user_base='$user_base' WHERE id='" . $this->sid . "'");
SurveyInfo :: getInstance()->resetSurveyData();
}
return $variablesResult;
}
function generateCode() {
$cookie = md5(mt_rand(1, mt_getrandmax()) . '@' . $_SERVER['REMOTE_ADDR']);
return array(substr($cookie,0,6), $cookie);
}
function displayRecipentsErrors($result) {
global $lang;
$valid_recipiens = is_array($result['valid_recipiens']) ? $result['valid_recipiens'] : array();
$invalid_password = is_array($result['invalid_password']) ? $result['invalid_password'] : array();
$insert_errors = is_array($result['insert_errors']) ? $result['insert_errors'] : array();
# dodani so bili nekateri uporabniki
if (count($valid_recipiens) > 0) {
echo '
';
# preverimo koliko številk še imamo razen trenutno izbrane
$toCall = $allUsers = $this->getAllNumbers();
unset($allUsers[$usr_id]);
# na voljo je še nekaj številk, izberemo novo
if ($allUsers > 0) {
// Dovolimo izbrati novo stevilko samo v primeru ko imamo nakljucno sortiranje
if($this->call_order == 0)
echo '
';
# preverimo koliko številk še imamo razen trenutno izbrane
$toCall = $allUsers = $this->getAllNumbers();
unset($allUsers[$usr_id]);
# na voljo je še nekaj številk, izberemo novo
if ($allUsers > 0) {
// Dovolimo izbrati novo stevilko samo v primeru ko imamo nakljucno sortiranje
if($this->call_order == 0)
echo '