'email','geslo'=>'password','ime'=>'firstname','priimek'=>'lastname','naziv'=>'salutation','telefon'=>'phone','drugo'=>'custom','odnos'=>'relation','last_status'=>'last_status','sent'=>'sent','responded'=>'responded','unsubscribed'=>'unsubscribed');
private $inv_variables_excel = array('email'=>'email','geslo'=>'password','ime'=>'firstname','priimek'=>'lastname','naziv'=>'salutation','telefon'=>'phone','drugo'=>'custom','odnos'=>'relation','last_status'=>'last_status','sent'=>'sent','responded'=>'responded','unsubscribed'=>'unsubscribed'
,'date_inserted'=>'date_inserted','date_sent'=>'date_sent','date_responded'=>'date_responded','date_unsubscribed'=>'date_unsubscribed','list_name'=>'list_name');
private $inv_variables_tel_excel = array('status'=>'status','email'=>'email','geslo'=>'password','ime'=>'firstname','priimek'=>'lastname','naziv'=>'salutation','telefon'=>'phone','drugo'=>'custom','odnos'=>'relation','call_time'=>'call_time','last_status'=>'last_status'
,'comment'=>'comment','date_inserted'=>'date_inserted','list_name'=>'list_name');
#private $inv_sys_db_map = array('email'=>'email','password'=>'geslo','firstname'=>'ime','lastname'=>'priimek','salutation'=>'naziv','phone'=>'telefon','custom'=>'drugo');
private $invitationAdvancedConditionId = 0;
private $user_inv_ids = array();
private $db_table = '';
function __construct($sid) {
$this->sid = $sid;
SurveyInfo::SurveyInit($this->sid);
$this->db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
$this->surveySettings = SurveyInfo::getInstance()->getSurveyRow();
# koliko respondentov je že v bazi
$sql_query_all = sisplet_query("SELECT count(*) FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted = '0'");
$sql_row_all = mysqli_fetch_row($sql_query_all);
$this->count_all = (int)$sql_row_all[0];
SurveyDataSettingProfiles :: Init($this->sid);
if (isset($_SESSION['rec_on_send_page']) && (int)$_SESSION['rec_on_send_page'] > 0) {
$this->rec_send_page_limit = (int)$_SESSION['rec_on_send_page'];
}
else {
$this->rec_send_page_limit = REC_ON_SEND_PAGE;
}
SurveySession::sessionStart($this->sid);
$this->invitationAdvancedConditionId = (int)SurveySession::get('invitationAdvancedConditionId');
}
function ajax() {
if (isset($_REQUEST['a']) && trim($_REQUEST['a']) != '') {
if (isset($_POST['recipients_list']) && $_POST['recipients_list'] != null) {
$_POST['recipients_list'] = mysql_real_unescape_string($_POST['recipients_list']);
}
if (isset($_POST['fields']) && $_POST['fields'] != null) {
$_POST['fields'] = mysql_real_unescape_string($_POST['fields']);
}
$this->action($_REQUEST['a']);
}
else {
echo 'Ajax error!';
return 'Ajax error!';
}
}
function action($action) {
global $lang;
global $site_url;
global $global_user_id;
$NoNavi = $_POST['noNavi'];
if ($action == 'inv_lists') {
#$NoNavi = true;
}
if ($action == 'view_archive') {
$NoNavi = true;
}
if ($NoNavi == false) {
echo '
Pošiljam . . . Prosimo počakajte.
';
echo 'Pošiljam . . . Prosimo počakajte.
';
echo '';
foreach ($send_ok AS $email) {
$return['msg'] .= ' '.$email.' ';
}
$return['msg'] .= '
';
}
}
else {
$return['error'] = '0';
$return['msg'] = ''.sprintf($lang['srv_invitation_note5_noEmailing'], $site_url.'admin/survey/index.php?anketa='.$this->sid.'&a='.A_INVITATIONS.'&m=view_archive').' ';
$return['msg'] .= sprintf($lang['srv_invitation_note5_noEmailing2'], $site_url.'admin/survey/index.php?anketa='.$this->sid.'&a='.A_INVITATIONS.'&m=view_recipients').'
';
// Shranimo komentar h posiljanju
if(isset($_POST['comment']) && $_POST['comment'] != ''){
$comment = $_POST['comment'];
$sqlC = sisplet_query("UPDATE srv_invitations_messages SET comment='$comment' WHERE ank_id='$this->sid' AND isdefault='1'");
}
// Preberemo tip posiljanja (navadna posta, sms...)
$noMail_type = SurveySession::get('inv_noEmailing_type');
// Pripravimo arhiv pošiljanj, da dobimo arch_id
$sql_query_all = sisplet_query("SELECT count(*) FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted = '0'");
list($count_all) = mysqli_fetch_row($sql_query_all);
$date_sent = date ("Y-m-d H:i:s");
$archive_naslov = 'mailing_'.date("d.m.Y").', '.date("H:i:s");
// Naslov in body
// polovimo sporočilo in prejemnike
$sql_query_m = sisplet_query("SELECT id, subject_text, body_text, reply_to, isdefault, comment, naslov, url FROM srv_invitations_messages WHERE ank_id = '$this->sid' AND isdefault='1'");
if (mysqli_num_rows($sql_query_m) > 0 ) {
$sql_row_m = mysqli_fetch_assoc($sql_query_m);
}
else {
$subject_text = $lang['srv_inv_message_noemailing_subject'];
$body_text = '';
}
$subject_text = $sql_row_m['subject_text'];
$body_text = $sql_row_m['body_text'];
$msg_url = $sql_row_m['url'];
// Vstavimo podatke v arhiv
$sqlQuery = sisplet_query("INSERT INTO srv_invitations_archive
(id, ank_id, date_send, subject_text, body_text, tip, uid, comment, naslov, rec_in_db)
VALUES
(NULL , '$this->sid', '$date_sent', '".addslashes($subject_text)."', '".addslashes($body_text)."', '$noMail_type', '$global_user_id', '$comment', '$archive_naslov', '$count_all')
");
$arch_id = mysqli_insert_id($GLOBALS['connect_db']);
$duplicated = array();
// Polovimo sistemske spremenljivke
$sys_vars = $this->getSystemVars();
// prejeminki besedila
$sql_query = sisplet_query("SELECT id, firstname, lastname, email, password, cookie, phone, salutation, custom, relation
FROM srv_invitations_recipients
WHERE ank_id = '".$this->sid."' AND deleted='0' AND id IN (".implode(',',$rids).")
ORDER BY id
");
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$password = $sql_row['password'];
$email = $sql_row['email'];
if ($dont_send_duplicated == true && isset($duplicated[$email]) && $email != '') {
$duplicated[$email] ++;
continue;
}
$duplicated[$email] = 1;
$individual = (int)$this->surveySettings['individual_invitation'];
$_user_data = $sql_row;
$send_ok[] = $email;
$send_ok_ids[] = $sql_row['id'];
$_user_data['status'] = 1;
$send_users_data[] = $_user_data;
}
// updejtamo userja da mu je bilo poslano
if ( count($send_ok_ids) > 0) {
$sqlQuery = sisplet_query("UPDATE srv_invitations_recipients SET sent = '1', date_sent = '".$date_sent."' WHERE id IN (".implode(',',$send_ok_ids).")");
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
// statuse popravimo samo če vabilo še ni bilo poslano ali je bila napaka
$sqlQuery = sisplet_query("UPDATE srv_invitations_recipients SET last_status = '1' WHERE id IN (".implode(',',$send_ok_ids).") AND last_status IN ('0','2')");
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
}
$comment = $_POST['comment'];
// dodajmo še userje v povezovalno tabelo
if ($arch_id > 0) {
// updejtamo še tabelo arhivov
$sqlQuery = sisplet_query("UPDATE srv_invitations_archive SET cnt_succsess='".count($send_ok_ids)."' WHERE id ='$arch_id'");
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
# za arhive
$_archive_recipients = array();
# za tracking
$_tracking = array();
if (count($send_ok_ids) > 0) {
foreach ( $send_ok_ids AS $id) {
$_archive_recipients[] = "('$arch_id','$id','1')";
#status 1=pošta poslana
$_tracking[] = "('$arch_id',NOW(),'$id','1')";
}
}
if (count($_archive_recipients) > 0) {
$sqlString = 'INSERT INTO srv_invitations_archive_recipients (arch_id,rec_id,success) VALUES ';
$sqlString .= implode(', ', $_archive_recipients);
$sqlQuery = sisplet_query($sqlString);
}
if (count($_tracking) > 0) {
$sqlStrTracking = "INSERT INTO srv_invitations_tracking (inv_arch_id, time_insert, res_id, status) VALUES ";
$sqlStrTracking .= implode(', ', $_tracking);
$sqlQueryTracking = sisplet_query($sqlStrTracking);
}
}
sisplet_query("COMMIT");
# če mamo personalizirana email vabila, userje dodamo v bazo
if ($individual == 1 && count($send_users_data) > 0) {
# dodamo še userja v srv_user da je kompatibilno s staro logiko
$strInsertDataText = array();
$strInsertUserbase = array();
$strInsertUserstatus = array();
foreach ($send_users_data AS $user_data) {
$_r = sisplet_query("INSERT INTO srv_user
(ank_id, email, cookie, pass, last_status, time_insert, inv_res_id)
VALUES
('".$this->sid."', '".$user_data['email']."', '".$user_data['cookie']."', '".$user_data['password']."', '".$user_data['status']."', NOW(), '".$user_data['id']."') ON DUPLICATE KEY UPDATE cookie = '".$user_data['cookie']."', pass='".$user_data['password']."'
");
$usr_id = mysqli_insert_id($GLOBALS['connect_db']);
sisplet_query("COMMIT");
if ($usr_id) {
# dodamo še srv_userbase in srv userstatus
$strInsertUserbase[] = "('".$usr_id."','0',NOW(),'".$global_user_id."')";
$strInsertUserstatus[] = "('".$usr_id."', '0', '0', NOW())";
# dodamo še podatke za posameznega userja za sistemske spremenljivke
foreach ($sys_vars AS $sid => $spremenljivka) {
$_user_variable = $this->inv_variables_link[$spremenljivka['variable']];
if (trim($user_data[$_user_variable]) != '' && $user_data[$_user_variable] != null) {
$strInsertDataText[] = "('".$sid."','".$spremenljivka['vre_id']."','".trim($user_data[$_user_variable])."','".$usr_id."')";
}
}
}
else {
// lahko da user že obstaja in je šlo za duplicated keys
}
}
// vstavimo v srv_userbase
if (count($strInsertUserbase) > 0) {
$strInsert = "INSERT INTO srv_userbase (usr_id, tip, datetime, admin_id) VALUES ";
$strInsert .= implode(',',$strInsertUserbase);
sisplet_query($strInsert);
}
// vstavimo v srv_userstatus
if (count($strInsertUserstatus) > 0) {
$strInsert = "INSERT INTO srv_userstatus (usr_id, tip, status, datetime) VALUES ";
$strInsert .= implode(',',$strInsertUserstatus);
sisplet_query($strInsert);
}
// vstavimo v srv_data_text
if (count($strInsertDataText) > 0) {
$strInsert = "INSERT INTO srv_data_text".$this->db_table." (spr_id, vre_id, text, usr_id) VALUES ";
$strInsert .= implode(',',$strInsertDataText);
sisplet_query($strInsert);
}
sisplet_query("COMMIT");
}
if (count($send_ok) > 0 ) {
list($name,$surname,$email) = mysqli_fetch_row(sisplet_query("SELECT name, surname, email FROM users WHERE id='$global_user_id'"));
$who='';
if (trim($name) != '') {
$who = $name;
}
if (trim($surname) != '') {
if ($who != '') {
$who .=' ';
}
$who .= $surname;
}
if ($email != '') {
if ($who != '') {
$who .=' ('.$email.')';
} else {
$who = $email;
}
}
$return['error'] = '0';
}
else {
$return['error'] = '0';
$return['msg'] = '';
$data = explode('_',$_POST['arch_to_view']);
$_success = (int)$data[2];
$_arch_id = $data[3];
#polovimo podatke arhiva
$sql_string = "SELECT comment FROM srv_invitations_archive WHERE id = '".$_arch_id."'";
$sql_query = sisplet_query($sql_string);
list($comment) = mysqli_fetch_row($sql_query);
echo '
';
echo $lang['srv_invitation_comment'];
echo ' ';
echo '';
echo '
'; // id="arc_content"
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_zapri'].' ';
echo ''.$lang['save'].' ';
echo '
';
echo '
';
echo '
';
}
function deleteRecipientConfirm() {
global $lang;
if (isset($_POST['inv_rid']) && trim($_POST['inv_rid']) != '') {
$rid = $_POST['inv_rid'];
echo '
';
echo '
Ali ste prepričani da želite izbrisati respondenta: ';
echo '
';
echo '
';
# polovimo podatke respondenta
$sql_string = "SELECT * FROM srv_invitations_recipients WHERE id = '".(int)$_POST['inv_rid']."'";
$sql_query = sisplet_query($sql_string);
$sql_row = mysqli_fetch_assoc($sql_query);
echo '
';
echo '
';
echo '
';
#email
if (trim($sql_row['email']) != '') {
echo ''.$lang['srv_inv_field_email'].' ';
echo $sql_row['email'];
echo ' ';
}
#geslo
if (trim($sql_row['password']) != '') {
echo ''.$lang['srv_inv_field_password'].' ';
echo $sql_row['password'];
echo ' ';
}
#ime
if (trim($sql_row['firstname']) != '') {
echo ''.$lang['srv_inv_field_firstname'].' ';
echo $sql_row['firstname'];
echo ' ';
}
#priimek
if (trim($sql_row['lastname']) != '') {
echo ''.$lang['srv_inv_field_lastname'].' ';
echo $sql_row['lastname'];
echo ' ';
}
#naziv
if (trim($sql_row['salutation']) != '') {
echo ''.$lang['srv_inv_field_salutation'].' ';
echo $sql_row['salutation'];
echo ' ';
}
#telefon
if (trim($sql_row['phone']) != '') {
echo ''.$lang['srv_inv_field_phone'].' ';
echo $sql_row['phone'];
echo ' ';
}
#drugo
if (trim($sql_row['custom']) != '') {
echo ''.$lang['srv_inv_field_custom'].' ';
echo $sql_row['custom'];
echo ' ';
}
#odnos
if(SurveyInfo::getInstance()->checkSurveyModule('360_stopinj')){
if (trim($sql_row['relation']) != '') {
echo ''.$lang['srv_inv_field_relation'].' ';
echo $sql_row['relation'];
echo ' ';
}
}
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_inv_list_profiles_delete'].' ';
echo '
'.$lang['srv_cancel'].' ';
echo '
';
echo '
'; # id="inv_delete_rec_confirm"
}
}
function deleteRecipient() {
global $lang, $global_user_id, $site_url;
$return = array('success'=>'0');
#array z napakami
$errors = array();
$rids = $_POST['inv_rids'];
if (isset($rids) && is_array($rids) && count($rids)) {
$sqlString = "UPDATE srv_invitations_recipients SET deleted='1', date_deleted=NOW(), uid_deleted='".$global_user_id."' WHERE ank_id='".$this->sid."' AND id IN(".implode(',',$rids).")";
$sqlQuery = sisplet_query($sqlString);
sisplet_query("COMMIT");
if (!$sqlQuery) {
$errors[] = $lang['srv_inv_recipient_delete_error'];
} else {
# updejtamo še srv_users
$sqlString = "UPDATE srv_user SET inv_res_id=NULL WHERE ank_id='".$this->sid."' AND inv_res_id IN(".implode(',',$rids).")";
$sqlQuery = sisplet_query($sqlString);
sisplet_query("COMMIT");
$return['success'] = 2;
//$this->viewRecipients();
}
} else {
$errors[] = $lang['srv_inv_recipient_delete_error'];
}
header('location: ' . $site_url . 'admin/survey/index.php?anketa='.$this->sid.'&a='.A_INVITATIONS.'&m=view_recipients');
}
function deleteRecipientSingle() {
global $lang, $global_user_id, $site_url;
$return = array('success'=>'0');
# single delete
$inv_rid = $_POST['inv_rid'];
if ((int)$inv_rid > 0) {
$sqlString = "UPDATE srv_invitations_recipients SET deleted='1', date_deleted=NOW(), uid_deleted='".$global_user_id."' WHERE ank_id='".$this->sid."' AND id ='$inv_rid'";
sisplet_query("COMMIT");
$sqlQuery = sisplet_query($sqlString);
if (!$sqlQuery) {
$return['error'] = $lang['srv_inv_recipient_delete_error'];
} else {
$return['success'] = 1;
echo json_encode($return);
exit;
}
} else {
$return['error'] = $lang['srv_inv_recipient_delete_error'];
}
echo json_encode($return);
exit;
}
function deleteRecipientAll() {
global $lang, $global_user_id, $site_url;
$return = array('success'=>'0');
# all delete
$sqlString = "UPDATE srv_invitations_recipients SET deleted='1', date_deleted=NOW(), uid_deleted='".$global_user_id."' WHERE ank_id='".$this->sid."' AND deleted ='0'";
sisplet_query("COMMIT");
$sqlQuery = sisplet_query($sqlString);
if (!$sqlQuery) {
$return['error'] = $lang['srv_inv_recipient_delete_error'];
} else {
$return['success'] = 1;
echo json_encode($return);
exit;
}
echo json_encode($return);
exit;
}
function addSystemVariables($variables) {
global $site_path, $lang;
// Pri modulu za volitve so responsi anonimni, zato nimamo nobenih sistemskih spremenljivk
if(SurveyInfo::getInstance()->checkSurveyModule('voting'))
return;
$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',
'inv_field_relation' => 'odnos',
);
$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;
$variable = $system_fields[$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;
// za polje odnos (module 360 - adecco) ustvarimo radio tip spremenljivke
if($system_fields[$var] == 'odnos'){
ob_start();
$ba->ajax_spremenljivka_new(0, 0, 1, 0, 1);
$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']);
// če gre za sistemsko "odnos" za module 360 (adecco) ustvarimo 4 vrednosti (nadrejeni, podrejeni, sodelavec, samoocenjevalec)
$sql = sisplet_query("UPDATE srv_vrednost SET naslov='".$lang['srv_inv_field_relation_1']."', variable='1' WHERE spr_id='".$spr_id."' AND vrstni_red='1'");
$sql = sisplet_query("UPDATE srv_vrednost SET naslov='".$lang['srv_inv_field_relation_2']."', variable='2' WHERE spr_id='".$spr_id."' AND vrstni_red='2'");
$sql = sisplet_query("UPDATE srv_vrednost SET naslov='".$lang['srv_inv_field_relation_3']."', variable='3' WHERE spr_id='".$spr_id."' AND vrstni_red='3'");
$sql = sisplet_query("INSERT INTO srv_vrednost (id, spr_id, naslov, variable, vrstni_red) VALUES ('', '$spr_id', '".$lang['srv_inv_field_relation_4']."', '4', '4')");
}
// dodamo novo spremenljivko na konec, tip je 21
else{
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']);
#MAPPING za povezavo podatkov
# če smo dodajali email, ga dodamo tudi v mapping
if ($variable == 'email' && (int)$spr_id > 0) {
$insertString = "INSERT INTO srv_invitations_mapping (sid, spr_id, field) VALUES ('$this->sid','$spr_id','email')";
sisplet_query($insertString);
}
}
}
}
}
}
}
function listRecipientsProfiles() {
global $lang, $global_user_id;
$ppid = isset($_POST['pid']) ? (int)$_POST['pid'] : -1;
# polovimo vse profile
$array_profiles = array();
session_start();
# če obstaja seznam iz seje za to anketo
if (isset($_SESSION['inv_rec_profile'][$this->sid])) {
$array_profiles[-1] = array('name' => $_SESSION['inv_rec_profile'][$this->sid]['name']);
}
$array_profiles[0] = array('name' => $lang['srv_temp_profile_author']);
$onlyThisSurvey = (isset($_SESSION['inv_rec_only_this_survey']) && (int)$_SESSION['inv_rec_only_this_survey'] == 1) ? false : true;
if ($onlyThisSurvey == 0) {
#id-ji profilov do katerih lahko dostopamo
$sql_string = "SELECT * FROM srv_invitations_recipients_profiles WHERE uid in('".$global_user_id."') OR pid IN (SELECT DISTINCT pid FROM srv_invitations_recipients_profiles_access where uid = '$global_user_id')";
$sql_query = sisplet_query($sql_string);
} else {
# 1
$sql_string = "SELECT rp.* FROM srv_invitations_recipients_profiles AS rp WHERE from_survey = '$this->sid'";
$sql_query = sisplet_query($sql_string);
}
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$array_profiles[$sql_row['pid']] = array('name' => $sql_row['name']);
}
echo '
';
echo '
';
foreach ($array_profiles AS $_pid => $profile) {
echo '';
echo $profile['name'];
echo ' ';
}
echo ' ';
echo '
';
echo '
';
if ((int)$ppid > 0) {
# polovimo še ostale porfile
$sql_string = "SELECT * FROM srv_invitations_recipients_profiles WHERE pid='".(int)$ppid."' AND from_survey ='".$this->sid."' ";
$sql_query = sisplet_query($sql_string);
if (mysqli_num_rows($sql_query) > 0) {
# če je iz iste ankete, potem lahko urejamo
echo '
'.$lang['srv_inv_recipients_delete_profile'].' ';
echo '
'.$lang['srv_inv_recipients_edit_profile'].' ';
echo '
';
}
}
echo '
';
}
function getRecipientsProfile($pid) {
global $lang, $global_user_id;
session_start();
$fields = array();
$recipients_list = null;
$noEmailing = SurveySession::get('inv_noEmailing');
# če ne obstaja začasen seznam ga naredimo (praznega)
if (!isset($_SESSION['inv_rec_profile'][$this->sid])) {
$_SESSION['inv_rec_profile'][$this->sid] = array(
'pid' => -1,
'name' => $lang['srv_invitation_new_templist'],
'fields' => ($noEmailing == 1 ? 'firstname,lastname' : 'email'),
'respondents' => '',
'comment' => $lang['srv_invitation_new_templist']
);
}
#polovimo emaile in poljaiz seznama
if ($pid > 0) {
# če imamo pid in je večji kot nič polovimo podatke iz tabele
$sql_query = sisplet_query("SELECT fields,respondents FROM srv_invitations_recipients_profiles WHERE pid = '".$pid."'");
$sql_row = mysqli_fetch_assoc($sql_query);
if (trim($sql_row['respondents']) != '') {
//$recipients_list = explode("\n",trim($sql_row['respondents']));
// Zamenjamo 1ka delimiter z default vejico, ker drugače je v seznamih porušeno
$recipients_list = explode("\n",str_replace ("|~|", ",", trim($sql_row['respondents'])));
}
$_fields = explode(",", $sql_row['fields']);
if (count($_fields) > 0) {
foreach ($_fields AS $field) {
$fields[] = 'inv_field_'.$field;
}
}
}
else if ($pid == 0) {
# če ne je začasin porfil - avtor
$sql_query = sisplet_query("SELECT email, name, surname FROM users WHERE id = '".$global_user_id."'");
$rowEmail = mysqli_fetch_assoc($sql_query);
// default smo rekli je vejica, ane?
$recipients_list[] = $rowEmail['email'];
//$recipients_list[] = $rowEmail['email'].','.$rowEmail['name'].','.$rowEmail['surname'];
$fields[]= 'inv_field_email';
/*$fields[]= 'inv_field_firstname';
$fields[]= 'inv_field_lastname';*/
}
else if ($pid == -1) {
# začasen profil iz seje
$_fields = explode(",",$_SESSION['inv_rec_profile'][$this->sid]['fields']);
if (count($_fields) > 0) {
foreach ($_fields AS $field) {
$fields[] = 'inv_field_'.$field;
}
}
if (trim($_SESSION['inv_rec_profile'][$this->sid]['respondents']) != '') {
$recipients_list = explode("\n",trim($_SESSION['inv_rec_profile'][$this->sid]['respondents']));
}
}
else {
$recipients_list[] = '';
$fields[]= 'inv_field_email';
}
return array($recipients_list,$fields);
}
function useRecipientsList($profile_id = null) {
if (isset($profile_id) && !is_null($profile_id))
{
$pid = $profile_id;
$_POST['pid'] = $profile_id;
}
else if (isset($_POST['pid']))
{
$pid = (int)$_POST['pid'];
}
else
{
if (isset($_SESSION['inv_rec_profile'][$this->sid]))
{
$pid = -1;
}
else
{
$pid = 0;
}
}
list($recipients_list,$fields) = $this->getRecipientsProfile($pid);
$this->addRecipientsView($fields,$recipients_list);
}
function saveRecipientList() {
global $lang,$site_url, $global_user_id;
echo 'DEPRCATED!';
return false;
$return = array('success'=>'0');
# shranjujemo v nov profil
$post_fields = str_replace('inv_field_','',implode(',',$_POST['fields']));
$post_recipients = $this->getCleanString($_POST['recipients_list']);
$pid = (int)$_POST['pid'];
# če je pid < 0 shranimo v nov porfil
if ($pid <= 0) {
# dodelimo ime
#zaporedno številčimo ime seznama1,2.... če slučajno ime že obstaja
$new_name = $lang['srv_inv_recipient_list_new'];
$names = array();
$s = "SELECT name FROM srv_invitations_recipients_profiles WHERE name LIKE '%".$new_name."%' AND uid='$global_user_id'";
$q = sisplet_query($s);
while ($r = mysqli_fetch_assoc($q)) {
$names[] = $r['name'];
}
if (count($names) > 0) {
$cnt = 1;
while (in_array($lang['srv_inv_recipient_list_new'].$cnt, $names)) {
$cnt++;
}
$new_name = $lang['srv_inv_recipient_list_new'].$cnt;
}
$sql_insert = "INSERT INTO srv_invitations_recipients_profiles".
" (name,uid,fields,respondents,insert_time,comment, from_survey) ".
" VALUES ('$new_name', '$global_user_id', '$post_fields', '$post_recipients', NOW(), '', '".$this->sid."' )";
$sqlQuery = sisplet_query($sql_insert);
if (!$sqlQuery) {
$return['success'] = '0';
$return['msg'] = mysqli_error($GLOBALS['connect_db']);
} else {
$return['success'] = '1';
$return['pid'] = mysqli_insert_id($GLOBALS['connect_db']);
}
} else {
# updejtamo obstoječ profil
$sql_update = " UPDATE srv_invitations_recipients_profiles".
" SET fields = '$post_fields', respondents ='$post_recipients' WHERE pid = '$pid'";
$sqlQuery = sisplet_query($sql_update);
if (!$sqlQuery) {
$return['success'] = '0';
$return['msg'] = mysqli_error($GLOBALS['connect_db']);
} else {
$return['success'] = '1';
$return['pid'] = $pid;
}
}
sisplet_query("COMMIT");
echo json_encode($return);
exit;
}
function getProfileName() {
echo 'DEPRECATED';
}
function saveRecProfile() {
global $lang, $site_url, $global_user_id;
$return = array('error'=>'0');
$profile_id = isset($_POST['profile_id'])? (int)$_POST['profile_id'] : -1;
$profile_name = (isset($_POST['profile_name']) && trim($_POST['profile_name']) != '') ? trim($_POST['profile_name']) : $lang['srv_invitation_new_templist'];
$profile_comment = (isset($_POST['profile_comment']) && trim($_POST['profile_comment']) != '') ? trim($_POST['profile_comment']) : '';
$recipients_list = trim($this->getCleanString($_POST['recipients_list']));
$field_list = (isset($_POST['field_list']) && trim($_POST['field_list']) != '') ? trim($_POST['field_list']) : 'email';
if ((int)$profile_id == -1) {
# shranimo v začasni profil
session_start();
$_SESSION['inv_rec_profile'][$this->sid] = array(
'pid'=>-1,
'name'=>$lang['srv_invitation_new_templist'],
'fields'=>$field_list,
'respondents'=>$recipients_list,
'comment'=>$profile_comment
);
$return = array('error'=>'0', 'msg'=>'x0', 'pid'=>-1);
}
else if ((int)$profile_id == 0) {
# shranjujemo v nov profil
$sql_insert = "INSERT INTO srv_invitations_recipients_profiles (name,uid,fields,respondents,insert_time,comment, from_survey) VALUES ('$profile_name', '$global_user_id', '$field_list', '$recipients_list', NOW(), '$profile_comment', '".$this->sid."' )";
$sqlQuery = sisplet_query($sql_insert);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error, 'pid'=>mysqli_insert_id($GLOBALS['connect_db']));
} else {
$return = array('error'=>'0', 'msg'=>'x1', 'pid'=>mysqli_insert_id($GLOBALS['connect_db']));
}
sisplet_query("COMMIT");
}
else {
# dodajamo v obstoječ profil
# polovimo podatke obstoječega profila
$sql_string = "SELECT * FROM srv_invitations_recipients_profiles WHERE uid in('".$global_user_id."') AND pid = '".$profile_id."'";
$sql_query = sisplet_query($sql_string);
$sql_row = mysqli_fetch_assoc($sql_query);
$respondents = $sql_row['respondents']."\n".$recipients_list;
$sql_string_update = "UPDATE srv_invitations_recipients_profiles SET respondents = '".$respondents."', comment='".$profile_comment."' WHERE uid in('".$global_user_id."') AND pid = '".$profile_id."'";
$sqlQuery = sisplet_query($sql_string_update);
sisplet_query("COMMIT");
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error, 'pid'=>$profile_id());
} else {
$return = array('error'=>'0', 'msg'=>'x2', 'pid'=>$profile_id);
}
}
echo json_encode($return);
exit;
}
function updateRecProfile() {
global $lang,$site_url, $global_user_id;
$return = array('error'=>'0', 'msg'=>'');
$pid = (int)(int)$_POST['pid'];
$profile_name = (isset($_POST['profile_name']) && trim($_POST['profile_name']) != '') ? trim($_POST['profile_name']) : '';
/*$profile_comment = (isset($_POST['profile_comment']) && trim($_POST['profile_comment']) != '') ? trim($_POST['profile_comment']) : '';
$profile_respondents = (isset($_POST['profile_respondents']) && trim($_POST['profile_respondents']) != '') ? trim($_POST['profile_respondents']) : '';*/
if ($pid > 0) {
if ($profile_name != '') {
//$sql_update = "UPDATE srv_invitations_recipients_profiles SET name = '$profile_name', comment = '$profile_comment', respondents = '$profile_respondents' WHERE pid = '$pid'";
$sql_update = "UPDATE srv_invitations_recipients_profiles SET name = '$profile_name' WHERE pid = '$pid'";
$sqlQuery = sisplet_query($sql_update);
sisplet_query("COMMIT");
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error);
} else {
$return = array('error'=>'0', 'msg'=>$sql_update);
}
sisplet_query("COMMIT");
} else {
$return = array('error'=>'1', 'msg'=>$lang['srv_inv_msg_1']);
}
} else {
$return = array('error'=>'1', 'msg'=>$lang['srv_inv_msg_2']);
}
echo json_encode($return);
exit;
}
function deleteRecProfile() {
global $lang, $site_url, $global_user_id;
$return = array('error'=>'0');
$pid = isset($_POST['pid']) && (int)$_POST['pid'] > 0 ? (int)$_POST['pid'] : null;
if ($_POST['pid']) {
$sql_string = "DELETE FROM srv_invitations_recipients_profiles WHERE pid='".$pid."' AND uid='".$global_user_id."'";
$return['str'] = $sql_string;
$sqlQuery = sisplet_query($sql_string);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return['error'] = '1';
$return['msg'] = $error;
}
sisplet_query("COMMIT");
}
echo json_encode($return);
exit;
}
function editRecProfile() {
global $lang, $site_url, $global_user_id;
$return = array('error'=>'0');
$pid = (int)$_POST['pid'];
if ($pid > 0) {
$sql_string = "SELECT * FROM srv_invitations_recipients_profiles WHERE pid='".$pid."'";
$sqlQuery = sisplet_query($sql_string);
$sqlRow = mysqli_fetch_assoc($sqlQuery);
echo '
'; # id="inv_view_arch_recipients"
sisplet_query("COMMIT");
}
echo json_encode($return);
exit;
}
function deleteMsgProfile() {
global $lang, $site_url, $global_user_id;
$return = array('error'=>'0');
$mid = isset($_POST['mid']) && (int)$_POST['mid'] > 0 ? (int)$_POST['mid'] : null;
# preštejemo koliko profilov imamo. Zadnjega ne pustimo izbrisati
$sql_string = "SELECT id FROM srv_invitations_messages WHERE ank_id = '$this->sid' AND id <> '".$mid."' LIMIT 1";
$sql_query = sisplet_query($sql_string);
list($id) = mysqli_fetch_row($sql_query);
if ((int)$id > 0 ) {
# nastavimo na nov id
$sql_string = "UPDATE srv_invitations_messages SET isdefault = '1' WHERE ank_id = '$this->sid' AND id='$id'";
$sqlQuery = sisplet_query($sql_string);
# če imamo še kak profil pustimo zbrisat izbranega
if ((int)$mid > 0) {
$sql_string = "DELETE FROM srv_invitations_messages WHERE id='".$mid."'";
$return['str'] = $sql_string;
$sqlQuery = sisplet_query($sql_string);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return['error'] = '1';
$return['msg'] = $error;
}
}
sisplet_query("COMMIT");
$this->viewMessage($id);
}
#$this->viewMessage();
# echo json_encode($return);
# exit;
}
function showMessageRename() {
global $lang;
$mid = (int)$_POST['mid'];
echo '
';
echo $lang['srv_inv_message_rename_new_name'].' ';
# polovimo vsa sporočila
$sql_string = "SELECT naslov, comment FROM srv_invitations_messages WHERE ank_id = '$this->sid' AND id = '$mid'";
list($naslov, $comment) = mysqli_fetch_row(sisplet_query($sql_string));
echo '
';
echo '
';
echo $lang['srv_inv_message_draft_list_comment'];
echo '';
echo '
';
echo '
'.$lang['save'].' ';
echo '
'.$lang['srv_cancel'].' ';
echo '
';
echo '
';
}
function messageRename() {
global $lang;
$return = array('msg'=>'', 'error'=>'0');
$mid = (int)$_POST['mid'];
$return['mid'] = $mid;
$name = trim($_POST['name']);
$comment = trim($_POST['comment']);
if ($name == '' || $name == null) {
$name = $this->generateMessageName();
}
if ($mid > 0) {
#updejtamo obstoječ profil
$sql_string = "UPDATE srv_invitations_messages SET naslov='".$name."', comment='".$comment."', edit_uid='".$global_user_id."', edit_time=NOW() WHERE ank_id = '$this->sid' AND id='$mid'";
$sqlQuery = sisplet_query($sql_string);
if ( $sqlQuery != 1) {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_msg_4'];
}
sisplet_query("COMMIT");
} else {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_msg_4'];
}
echo json_encode($return);
exit;
}
function editRecipient() {
global $lang;
echo '
';
echo '
Urejanje respondenta ';
if ((int)$_POST['inv_rid'] > 0) {
# polovimo podatke respondenta
$sql_string = "SELECT * FROM srv_invitations_recipients WHERE id = '".(int)$_POST['inv_rid']."'";
$sql_query = sisplet_query($sql_string);
$sql_row = mysqli_fetch_assoc($sql_query);
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_inv_recipient_save'].' ';
}
echo '
'.$lang['srv_cancel'].' ';
echo '
';
echo '
';
}
function saveRecipient() {
global $lang;
$return = array('msg'=>$lang['srv_inv_error1'], 'error'=>'0');
$rid = (int)trim($_POST['inv_rid']);
$rec_email = trim($_POST['rec_email']);
$rec_password = trim($_POST['rec_password']);
$rec_firstname = trim($_POST['rec_firstname']);
$rec_lastname = trim($_POST['rec_lastname']);
$rec_salutation = trim($_POST['rec_salutation']);
$rec_phone = trim($_POST['rec_phone']);
$rec_custom = trim($_POST['rec_custom']);
$rec_relation = (int)trim($_POST['rec_relation']);
$return['rid'] = $rid;
$sql_string = "SELECT email FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND id = '".$rid."'";
$sql_query = sisplet_query($sql_string);
$sql_row = mysqli_fetch_assoc($sql_query);
$newline= '
';
# če smo imeli polje email ga preverjamo
if ($sql_row['email'] != null || trim($sql_row['email']) != '' || ($rec_email != null && $rec_email != '')) {
# email ne sme biti prazen
if (($sql_row['email'] != null || trim($sql_row['email']) != '') && ($rec_email == null || $rec_email == '')) {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_error2'];
$return['error_email'] = '1';
$newline= '
';
} else if (!$this->validEmail($rec_email)) {
# email mora biti pravilne oblike
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_error3'];
$return['error_email'] = '1';
$newline= '
';
}
}
# password ne sme biti prazen
if ($rec_password == null || $rec_password == '') {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_error4'];
$return['error_password'] = '1';
$newline= '
';
} else {
#preverimo da geslo še ni uporabljeno za to anketo za katerega drugega respondenta
$sql_string = "SELECT * FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND password = '".$rec_password."' AND id != '".$rid."'";
$sql_query = sisplet_query($sql_string);
if (mysqli_num_rows($sql_query) > 0) {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_error5'];
$return['error_password'] = '1';
$newline= '
';
}
}
# če ni napak shranimo
if ( $return['error'] == '0') {
# ali shranjujemo obstoječ msg
$sql_string = "UPDATE srv_invitations_recipients SET"
." email = '".strtolower($rec_email)."',"
." password = '$rec_password',"
." firstname = '$rec_firstname',"
." lastname = '$rec_lastname',"
." salutation = '$rec_salutation',"
." phone = '$rec_phone',"
." custom = '$rec_custom',"
." relation = '$rec_relation'"
." WHERE ank_id = '$this->sid' AND id='$rid'";
$sqlQuery = sisplet_query($sql_string);
sisplet_query("COMMIT");
if ( $sqlQuery != 1) {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_error6'];
}
}
# MAP: če imamo mapirano, updejtamo tudi pri podatkih
$strMap = "SELECT spr_id FROM srv_invitations_mapping WHERE sid = '".$this->sid."' AND field='email'";
$qryMap = sisplet_query($strMap);
list($mapSprId) = mysqli_fetch_row($qryMap);
if ((int)$mapSprId > 0) {
# preverimo ali ima respondent povezavo na srv_user
$selectUser = "SELECT id FROM srv_user where ank_id='".$this->sid."' AND inv_res_id='$rid' AND deleted='0'";
$qryUser = sisplet_query($selectUser);
list($uid) = mysqli_fetch_row($qryUser);
if ((int)$uid > 0 && $this->validEmail($rec_email)) {
$updateStr = "UPDATE srv_data_text".$this->db_table." SET text = '$rec_email' WHERE spr_id='$mapSprId' AND usr_id='".(int)$uid."'";
$qryUpdate = sisplet_query($updateStr);
if ((int)$qryUpdate > 0) {
# updejtamo še timestamp userja
$updateUserString = "UPDATE srv_user SET time_edit=NOW() WHERE id='".(int)$uid."'";
$qryUserUpdate = sisplet_query($updateUserString);
}
}
}
$sql_string = "SELECT * FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND id = '".$rid."'";
$sql_query = sisplet_query($sql_string);
$return['rec'] = mysqli_fetch_assoc($sql_query);
echo json_encode($return);
exit;
}
function setRecipientFilter(){
session_start();
if (isset($_POST['inv_filter_on']) && $_POST['inv_filter_on'] == 'true') {
$_SESSION['inv_filter_on'] = true;
} else {
$_SESSION['inv_filter_on'] = false;
}
$_SESSION['inv_filter']['value'] = trim($_POST['inv_filter_value']);
$_SESSION['inv_filter']['send'] = (int)$_POST['inv_filter_send'];
$_SESSION['inv_filter']['respondet'] = (int)$_POST['inv_filter_respondet'];
$_SESSION['inv_filter']['unsubscribed'] = (int)$_POST['inv_filter_unsubscribed'];
# če ni seznama privzeto damo na vsi
if (!isset($_POST['inv_filter_list']) && !isset($_SESSION['inv_filter']['list'])) {
$_SESSION['inv_filter']['list'] = '-2';
} else {
$_SESSION['inv_filter']['list'] = (int)$_POST['inv_filter_list'];
}
if (isset($_POST['inv_filter_duplicates']) && $_POST['inv_filter_duplicates'] == 'true') {
$_SESSION['inv_filter']['duplicated'] = true;
} else {
$_SESSION['inv_filter']['duplicated'] = false;
}
session_commit();
return;
}
function exportRecipients() {
global $lang;
$convertTypes = array('charSet' => 'UTF-8', # windows-1250',
'delimit' => ';',
'newLine' => "\n",
'BOMchar' => "\xEF\xBB\xBF");
#header('Content-Type: application/octet-stream; charset='.$convertTypes['charSet']);
header('Content-type: application/csv; charset='.$convertTypes['charSet']);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="respondenti_anketa_'.$this->sid.'-'.date('Y-m-d').'.csv"');
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
ob_clean();
# dodami boomchar za utf-8
echo $convertTypes['BOMchar'];
#array z napakami
$errors = array();
$inv_rids = $_POST['inv_rids'];
if (is_array($inv_rids) && count($inv_rids) > 0) {
// Ce delamo izvoz za telefonski modul
if(SurveyInfo::getInstance()->checkSurveyModule('phone')){
$delimit = '';
foreach ($this->inv_variables_tel_excel AS $vkey => $inv_variable) {
echo $delimit.$lang['srv_inv_recipients_'.$inv_variable];
$delimit = $convertTypes['delimit'];
}
#echo $delimit.$lang['srv_inv_recipients_count_inv'];
echo $convertTypes['newLine'];
$sqlString = "SELECT sir.*, IF(sirp.name IS NULL, '".$lang['srv_invitation_new_templist_author']."', sirp.name) AS list_name, scm.comment, scs.call_time, sch.status "
." FROM srv_invitations_recipients AS sir"
." LEFT JOIN srv_invitations_recipients_profiles AS sirp ON (sir.list_id = sirp.pid)"
." LEFT JOIN srv_telephone_comment AS scm ON (scm.rec_id = sir.id)"
." LEFT JOIN srv_telephone_schedule AS scs ON (scs.rec_id = sir.id)"
." LEFT JOIN srv_telephone_history AS sch ON (sch.rec_id = sir.id)"
." WHERE sir.id IN(".implode(',',$inv_rids).") ORDER BY id";
$sqlQuery = sisplet_query($sqlString);
if (mysqli_num_rows($sqlQuery)) {
while ($sql_row = mysqli_fetch_assoc($sqlQuery)) {
foreach ($this->inv_variables_tel_excel AS $vkey => $inv_variable) {
if($inv_variable == 'status' && $sql_row[$inv_variable] == '')
echo $lang['srv_telephone_status_'].$convertTypes['delimit'];
else
echo $sql_row[$inv_variable].$convertTypes['delimit'];
}
echo $convertTypes['newLine'];
}
}
}
// Izvoz za navadna vabila
else{
$delimit = '';
foreach ($this->inv_variables_excel AS $vkey => $inv_variable) {
echo $delimit.$lang['srv_inv_recipients_'.$inv_variable];
$delimit = $convertTypes['delimit'];
}
#echo $delimit.$lang['srv_inv_recipients_count_inv'];
echo $convertTypes['newLine'];
$sqlString = "SELECT sir.*, IF(sirp.name IS NULL, '".$lang['srv_invitation_new_templist_author']."', sirp.name) AS list_name "
." FROM srv_invitations_recipients AS sir"
." LEFT JOIN srv_invitations_recipients_profiles AS sirp ON (sir.list_id = sirp.pid)"
#." LEFT JOIN srv_invitations_archive_recipients AS siar ON (sir.id = siar.rec_id)"
." WHERE sir.id IN(".implode(',',$inv_rids).") ORDER BY id";
/*
$sqlString = "SELECT sir.*, IF(sirp.name IS NULL, '".$lang['srv_invitation_new_templist_author']."', sirp.name) AS list_name, count(siar.arch_id) AS count_inv"
." FROM srv_invitations_recipients AS sir"
." LEFT JOIN srv_invitations_recipients_profiles AS sirp ON (sir.list_id = sirp.pid)"
." LEFT JOIN srv_invitations_archive_recipients AS siar ON (sir.id = siar.rec_id)"
." WHERE sir.id IN(".implode(',',$inv_rids).") GROUP BY siar.rec_id ORDER BY id";
*/
$sqlQuery = sisplet_query($sqlString);
if (mysqli_num_rows($sqlQuery)) {
while ($sql_row = mysqli_fetch_assoc($sqlQuery)) {
foreach ($this->inv_variables_excel AS $vkey => $inv_variable) {
echo $sql_row[$inv_variable].$convertTypes['delimit'];
}
# echo $sql_row['count_inv'];
echo $convertTypes['newLine'];
}
}
}
}
else {
echo $lang['srv_inv_error7'];
}
ob_flush();
}
function exportRecipients_all() {
global $lang;
$convertTypes = array('charSet' => 'UTF-8', # windows-1250',
'delimit' => ';',
'newLine' => "\n",
'BOMchar' => "\xEF\xBB\xBF");
#header('Content-Type: application/octet-stream; charset='.$convertTypes['charSet']);
header('Content-type: application/csv; charset='.$convertTypes['charSet']);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="respondenti_anketa_'.$this->sid.'-'.date('Y-m-d').'.csv"');
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
ob_clean();
# dodami boomchar za utf-8
echo $convertTypes['BOMchar'];
// Ce delamo izvoz za telefonski modul
if(SurveyInfo::getInstance()->checkSurveyModule('phone')){
#array z napakami
$errors = array();
$delimit = '';
foreach ($this->inv_variables_tel_excel AS $vkey => $inv_variable) {
echo $delimit.$lang['srv_inv_recipients_'.$inv_variable];
$delimit = $convertTypes['delimit'];
}
#echo $delimit.$lang['srv_inv_recipients_count_inv'];
echo $convertTypes['newLine'];
$sqlString = "SELECT sir.*, IF(sirp.name IS NULL, '".$lang['srv_invitation_new_templist_author']."', sirp.name) AS list_name, scm.comment, scs.call_time, sch.status "
." FROM srv_invitations_recipients AS sir"
." LEFT JOIN srv_invitations_recipients_profiles AS sirp ON (sir.list_id = sirp.pid)"
." LEFT JOIN srv_telephone_comment AS scm ON (scm.rec_id = sir.id)"
." LEFT JOIN srv_telephone_schedule AS scs ON (scs.rec_id = sir.id)"
." LEFT JOIN srv_telephone_history AS sch ON (sch.rec_id = sir.id)"
." WHERE sir.ank_id = '$this->sid' AND deleted='0' ORDER BY id";
$sqlQuery = sisplet_query($sqlString);
if (mysqli_num_rows($sqlQuery)) {
while ($sql_row = mysqli_fetch_assoc($sqlQuery)) {
foreach ($this->inv_variables_tel_excel AS $vkey => $inv_variable) {
if($inv_variable == 'status' && $sql_row[$inv_variable] == '')
echo $lang['srv_telephone_status_'].$convertTypes['delimit'];
else
echo $sql_row[$inv_variable].$convertTypes['delimit'];
}
echo $convertTypes['newLine'];
}
}
}
// Izvoz za navadna vabila
else{
#array z napakami
$errors = array();
$delimit = '';
foreach ($this->inv_variables_excel AS $vkey => $inv_variable) {
echo $delimit.$lang['srv_inv_recipients_'.$inv_variable];
$delimit = $convertTypes['delimit'];
}
echo $convertTypes['newLine'];
$sqlString = "SELECT sir.*, IF(sirp.name IS NULL, '".$lang['srv_invitation_new_templist_author']."', sirp.name) AS list_name "
." FROM srv_invitations_recipients AS sir"
." LEFT JOIN srv_invitations_recipients_profiles AS sirp ON (sir.list_id = sirp.pid)"
." WHERE sir.ank_id = '$this->sid' AND deleted='0' ORDER BY id";
$sqlQuery = sisplet_query($sqlString);
if (mysqli_num_rows($sqlQuery)) {
while ($sql_row = mysqli_fetch_assoc($sqlQuery)) {
foreach ($this->inv_variables_excel AS $vkey => $inv_variable) {
echo $sql_row[$inv_variable].$convertTypes['delimit'];
}
echo $convertTypes['newLine'];
}
}
}
ob_flush();
}
function onlyThisSurvey() {
session_start();
$_SESSION['inv_rec_only_this_survey'] = (isset($_POST['checked']) && $_POST['checked'] == 'true');
}
function hightlight($str, $keywords = '') {
$keywords = preg_replace('/\s\s+/', ' ', strip_tags(trim($keywords))); // filter
$style = 'inv_high';
$style_i = 'inv_high_i';
/* Apply Style */
$var = '';
foreach(explode(' ', $keywords) as $keyword)
{
$replacement = "
".$keyword." ";
$var .= $replacement." ";
$str = str_ireplace($keyword, $replacement, $str);
}
/* Apply Important Style */
$str = str_ireplace(rtrim($var), "
".$keywords." ", $str);
return $str;
}
// Dodamo vse userje v bazo podatkov kot respondente
function add_users_to_database() {
// Preverimo ce je vklopljen modul za volitve
$voting = SurveyInfo::getInstance()->checkSurveyModule('voting');
# prejeminki besedila
$sql_query = sisplet_query("SELECT id, firstname, lastname, email, password, password, cookie, phone, salutation, custom, relation
FROM srv_invitations_recipients
WHERE ank_id = '".$this->sid."' AND deleted='0' AND sent='0'
");
# polovimo sistemske spremenljivke z vrednostmi
$qrySistemske = sisplet_query("SELECT s.id, s.naslov, s.variable
FROM srv_spremenljivka s, srv_grupa g
WHERE s.sistem='1' AND s.gru_id=g.id AND g.ank_id='".$this->sid."'
AND variable IN("."'" . implode("','",$this->inv_variables)."')
ORDER BY g.vrstni_red, s.vrstni_red
");
$sys_vars = array();
$sys_vars_ids = array();
while ($row = mysqli_fetch_assoc($qrySistemske)) {
$sys_vars[$row['id']] = array('id'=>$row['id'], 'variable'=>$row['variable'],'naslov'=>$row['naslov']);
$sys_vars_ids[] = $row['id'];
}
$sqlVrednost = sisplet_query("SELECT spr_id, id AS vre_id, vrstni_red, variable
FROM srv_vrednost
WHERE spr_id IN(".implode(',',$sys_vars_ids).")
ORDER BY vrstni_red ASC
");
while ($row = mysqli_fetch_assoc($sqlVrednost)) {
// Ce gre za odnos imamo radio
if($sys_vars[$row['spr_id']]['variable'] == 'odnos'){
if(!isset($sys_vars[$row['spr_id']]['vre_id'][$row['vrstni_red']]))
$sys_vars[$row['spr_id']]['vre_id'][$row['variable']] = $row['vre_id'];
}
elseif (!isset($sys_vars[$row['spr_id']]['vre_id'])) {
$sys_vars[$row['spr_id']]['vre_id'] = $row['vre_id'];
}
}
# array za rezultate
$send_users_data = array();
# zloopamo skozi prejemnike in personaliziramo sporočila in jih pošljemo
$date_sent = date ("Y-m-d H:i:s");
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$_user_data = $sql_row;
$_user_data['status'] = 1;
$send_users_data[] = $_user_data;
}
# dodamo še userja v srv_user da je kompatibilno s staro logiko
$strInsertDataText = array();
$strInsertUserbase = array();
$strInsertUserstatus = array();
foreach ($send_users_data AS $user_data) {
// Pri volitvah zaradi anonimizacije ignoriramo vse identifikatorje
if($voting){
sisplet_query("INSERT INTO srv_user
(ank_id, cookie, pass, last_status, inv_res_id)
VALUES
('".$this->sid."', '".$user_data['cookie']."', '".$user_data['password']."', '".$user_data['status']."', '-1') ON DUPLICATE KEY UPDATE last_status=VALUES(last_status)
");
// Ce ne belezimo parapodatka za cas responsa, anonimno zabelezimo cas zadnjega responsa
sisplet_query("UPDATE srv_anketa SET last_response_time=NOW() WHERE id='".$this->sid."'");
}
else{
sisplet_query("INSERT INTO srv_user
(ank_id, email, cookie, pass, last_status, time_insert, inv_res_id)
VALUES
('".$this->sid."', '".$user_data['email']."', '".$user_data['cookie']."', '".$user_data['password']."', '".$user_data['status']."', NOW(), '".$user_data['id']."') ON DUPLICATE KEY UPDATE last_status=VALUES(last_status), inv_res_id=VALUES(inv_res_id)
");
}
$usr_id = mysqli_insert_id($GLOBALS['connect_db']);
if ($usr_id) {
# za update v srv_invitations_respondents
$send_ok_ids[] = $user_data['id'];
}
else {
$send_error_ids[] = $user_data;
}
# dodamo še srv_userbase in srv userstatus
$strInsertUserbase[] = "('".$usr_id."','0',NOW(),'".$global_user_id."')";
$strInsertUserstatus[] = "('".$usr_id."', '0', '0', NOW())";
# dodamo še podatke za posameznega userja za sistemske spremenljivke
foreach ($sys_vars AS $sid => $spremenljivka) {
$_user_variable = $this->inv_variables_link[$spremenljivka['variable']];
if (trim($user_data[$_user_variable]) != '' && $user_data[$_user_variable] != null) {
if($spremenljivka['variable'] == 'odnos')
$strInsertDataVrednost[] = "('".$sid."','".$spremenljivka['vre_id'][trim($user_data[$_user_variable])]."','".$usr_id."')";
else
$strInsertDataText[] = "('".$sid."','".$spremenljivka['vre_id']."','".trim($user_data[$_user_variable])."','".$usr_id."')";
}
}
sisplet_query("COMMIT");
}
# vstavimo v srv_userbase
if (count($strInsertUserbase) > 0) {
$strInsert = "INSERT INTO srv_userbase (usr_id, tip, datetime, admin_id) VALUES ";
$strInsert .= implode(',',$strInsertUserbase);
sisplet_query($strInsert);
}
# vstavimo v srv_userstatus
if (count($strInsertUserstatus) > 0) {
$strInsert = "INSERT INTO srv_userstatus (usr_id, tip, status, datetime) VALUES ";
$strInsert .= implode(',',$strInsertUserstatus);
sisplet_query($strInsert);
}
// Pri volitvah zaradi anonimizacije ne vsatvimo nicesar v sistemske spremenljivke
if(!$voting){
# vstavimo v srv_data_text
if (count($strInsertDataText) > 0) {
$strInsert = "INSERT INTO srv_data_text".$this->db_table." (spr_id, vre_id, text, usr_id) VALUES ";
$strInsert .= implode(',',$strInsertDataText);
sisplet_query($strInsert);
}
# vstavimo v srv_data_vrednost
if (count($strInsertDataVrednost) > 0) {
$strInsert = "INSERT INTO srv_data_vrednost".$this->db_table." (spr_id, vre_id, usr_id) VALUES ";
$strInsert .= implode(',',$strInsertDataVrednost);
sisplet_query($strInsert);
}
}
sisplet_query("COMMIT");
# zloopamo skozi prejemnike in personaliziramo sporočila in jih pošljemo
$date_sent = date ("Y-m-d H:i:s");
# updejtamo userja da mu je bilo poslano
if ( count($send_ok_ids) > 0) {
$sqlQuery = sisplet_query("UPDATE srv_invitations_recipients SET sent='1', date_sent = '".$date_sent."' WHERE id IN (".implode(',',$send_ok_ids).")");
if (!$sqlQuery)
$error = mysqli_error($GLOBALS['connect_db']);
$sqlQuery = sisplet_query("UPDATE srv_invitations_recipients SET last_status='1' WHERE id IN (".implode(',',$send_ok_ids).") AND last_status IN ('0','2')");
if (!$sqlQuery)
$error = mysqli_error($GLOBALS['connect_db']);
}
$msg = array($lang['srv_inv_activate_respondents']. count($send_ok_ids));
if (count($send_error_ids) > 0) {
print_r("
");
print_r($lang['srv_inv_error0']);
print_r($send_error_ids);
print_r(" ");
}
# popravimo timestamp za regeneracijo dashboarda
Common::getInstance()->Init($anketa);
Common::getInstance()->updateEditStamp();
$this->viewRecipients(/*array(),$msg*/);
}
// Dodamo samo izbrane userje v bazo podatkov kot respondente
function add_checked_users_to_database() {
global $site_url;
// Prejemniki, ki jih ročno dodajamo med respondente
$inv_rids = $_POST['inv_rids'];
# prejeminki besedila
$sql_string = "SELECT id, firstname, lastname, email, password, cookie, phone, salutation, custom, relation FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted='0' AND sent='0' AND id IN(".implode(',',$inv_rids).")";
$sql_query = sisplet_query($sql_string);
# polovimo sistemske spremenljivke z vrednostmi
$strSistemske = "SELECT s.id, s.naslov, s.variable FROM srv_spremenljivka s, srv_grupa g WHERE s.sistem='1' AND s.gru_id=g.id AND g.ank_id='".$this->sid."' AND variable IN("."'" . implode("','",$this->inv_variables)."') ORDER BY g.vrstni_red, s.vrstni_red";
$qrySistemske = sisplet_query($strSistemske);
$sys_vars = array();
$sys_vars_ids = array();
while ($row = mysqli_fetch_assoc($qrySistemske)) {
$sys_vars[$row['id']] = array('id'=>$row['id'], 'variable'=>$row['variable'],'naslov'=>$row['naslov']);
$sys_vars_ids[] =$row['id'];
}
$sqlVrednost = sisplet_query("SELECT spr_id, id AS vre_id, vrstni_red, variable FROM srv_vrednost WHERE spr_id IN(".implode(',',$sys_vars_ids).") ORDER BY vrstni_red ASC ");
while ($row = mysqli_fetch_assoc($sqlVrednost)) {
// Ce gre za odnos imamo radio
if($sys_vars[$row['spr_id']]['variable'] == 'odnos'){
if(!isset($sys_vars[$row['spr_id']]['vre_id'][$row['vrstni_red']]))
$sys_vars[$row['spr_id']]['vre_id'][$row['variable']] = $row['vre_id'];
}
elseif (!isset($sys_vars[$row['spr_id']]['vre_id'])) {
$sys_vars[$row['spr_id']]['vre_id'] = $row['vre_id'];
}
}
# array za rezultate
$send_users_data = array();
# zloopamo skozi prejemnike in personaliziramo sporočila in jih pošljemo
$date_sent = date ("Y-m-d H:i:s");
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$_user_data = $sql_row;
$_user_data['status'] = 1;
$send_users_data[] = $_user_data;
}
# dodamo še userja v srv_user da je kompatibilno s staro logiko
$strInsertDataText = array();
$strInsertUserbase = array();
$strInsertUserstatus = array();
foreach ($send_users_data AS $user_data) {
$strInsert = "INSERT INTO srv_user (ank_id, email, cookie, pass, last_status, time_insert, inv_res_id) VALUES ('".$this->sid."', '".$user_data['email']."', '".$user_data['cookie']."', '".$user_data['password']."', '".$user_data['status']."', NOW(), '".$user_data['id']."') ON DUPLICATE KEY UPDATE last_status=VALUES(last_status), inv_res_id=VALUES(inv_res_id)";
sisplet_query($strInsert);
$usr_id = mysqli_insert_id($GLOBALS['connect_db']);
if ($usr_id) {
# za update v srv_invitations_respondents
$send_ok_ids[] = $user_data['id'];
} else {
$send_error_ids[] = $user_data;
}
# dodamo še srv_userbase in srv userstatus
$strInsertUserbase[] = "('".$usr_id."','0',NOW(),'".$global_user_id."')";
$strInsertUserstatus[] = "('".$usr_id."', '0', '0', NOW())";
# dodamo še podatke za posameznega userja za sistemske spremenljivke
foreach ($sys_vars AS $sid => $spremenljivka) {
$_user_variable = $this->inv_variables_link[$spremenljivka['variable']];
if (trim($user_data[$_user_variable]) != '' && $user_data[$_user_variable] != null) {
if($spremenljivka['variable'] == 'odnos')
$strInsertDataVrednost[] = "('".$sid."','".$spremenljivka['vre_id'][trim($user_data[$_user_variable])]."','".$usr_id."')";
else
$strInsertDataText[] = "('".$sid."','".$spremenljivka['vre_id']."','".trim($user_data[$_user_variable])."','".$usr_id."')";
}
}
sisplet_query("COMMIT");
}
# vstavimo v srv_userbase
if (count($strInsertUserbase) > 0) {
$strInsert = "INSERT INTO srv_userbase (usr_id, tip, datetime, admin_id) VALUES ";
$strInsert .= implode(',',$strInsertUserbase);
sisplet_query($strInsert);
}
# vstavimo v srv_userstatus
if (count($strInsertUserstatus) > 0) {
$strInsert = "INSERT INTO srv_userstatus (usr_id, tip, status, datetime) VALUES ";
$strInsert .= implode(',',$strInsertUserstatus);
sisplet_query($strInsert);
}
# vstavimo v srv_data_text
if (count($strInsertDataText) > 0) {
$strInsert = "INSERT INTO srv_data_text".$this->db_table." (spr_id, vre_id, text, usr_id) VALUES ";
$strInsert .= implode(',',$strInsertDataText);
sisplet_query($strInsert);
}
# vstavimo v srv_data_vrednost
if (count($strInsertDataVrednost) > 0) {
$strInsert = "INSERT INTO srv_data_vrednost".$this->db_table." (spr_id, vre_id, usr_id) VALUES ";
$strInsert .= implode(',',$strInsertDataVrednost);
sisplet_query($strInsert);
}
sisplet_query("COMMIT");
# zloopamo skozi prejemnike in personaliziramo sporočila in jih pošljemo
$date_sent = date ("Y-m-d H:i:s");
# updejtamo userja da mu je bilo poslano
if ( count($send_ok_ids) > 0) {
$sqlString = "UPDATE srv_invitations_recipients SET sent = '1', date_sent = '".$date_sent."' WHERE id IN (".implode(',',$send_ok_ids).")";
$sqlQuery = sisplet_query($sqlString);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
$sqlString = "UPDATE srv_invitations_recipients SET last_status = '1' WHERE id IN (".implode(',',$send_ok_ids).") AND last_status IN ('0','2')";
$sqlQuery = sisplet_query($sqlString);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
}
}
$msg = array($lang['srv_inv_activate_respondents']. count($send_ok_ids));
if (count($send_error_ids) > 0) {
print_r("
");
print_r($lang['srv_inv_error0']);
print_r($send_error_ids);
print_r(" ");
}
# popravimo timestamp za regeneracijo dashboarda
Common::getInstance()->Init($anketa);
Common::getInstance()->updateEditStamp();
header('location: ' . $site_url . 'admin/survey/index.php?anketa='.$this->sid.'&a='.A_INVITATIONS.'&m=view_recipients');
}
function getRespondents2Send($send_type, $checkboxes, $source_type, $source_lists, $noEmailing=0) {
$respondenti = array();
# če imamo dodatne omejitve source_type > 0 (arhivi, seznami) dodamo dodatno kontrolo na id-je respondentov
$advancedConditionJoin = '';
$advancedCondition = '';
if ($source_type == 0)
{
$this->user_inv_ids = array();
if ((int)$this->invitationAdvancedConditionId > 0)
{
$this->user_inv_ids = $this->getConditionUserIds($this->invitationAdvancedConditionId);
if (isset($this->user_inv_ids) && is_array($this->user_inv_ids) && count($this->user_inv_ids) > 0 )
{
$advancedConditionJoin = " INNER JOIN srv_user AS su ON i.id = su.inv_res_id";
$advancedCondition = " AND su.ank_id = '$this->sid' AND su.inv_res_id IS NOT NULL AND su.deleted = '0' AND su.id IN ('".(implode('\',\'',$this->user_inv_ids))."')";
}
}
}
else if ($source_type == 1)
{
# arhivi
if ($source_lists != '')
{
$sub_query = " AND i.id IN(SELECT rec_id AS id FROM srv_invitations_archive_recipients WHERE arch_id IN(".$source_lists.")) ";
} else {
$sub_query = " AND 0=1 ";
}
}
else if ($source_type == 2)
{
if ($source_lists != '')
{
$sub_query = " AND i.list_id IN(".$source_lists.") ";
}
else
{
$sub_query = " AND 0=1 ";
}
}
# polovimo respondente ki ustrezajo posameznemu statusu
if ($send_type == 0 )
{
}
if ($send_type == 1)
{
$sql_sub_condition = " AND i.sent = '0'";
}
if ($send_type == 2)
{
$sql_sub_condition = " AND i.sent = '1' AND i.responded = '0'";
}
if ($send_type == 3)
{
$sql_sub_condition = " AND i.sent = '1' AND i.responded = '1'";
}
if ($send_type == 4)
{
if ($_POST['checkboxes'] != null && trim($_POST['checkboxes']) != '' )
{
$sql_sub_condition = " AND i.last_status IN (".$_POST['checkboxes'].")";
}
}
// Ce imamo vklopljene volitve potem posiljamo samo tistim, katerim še nismo poslali vabila (ponovno posiljanje ni mogoce)
$sql_voting_condition = (SurveyInfo::getInstance()->checkSurveyModule('voting')) ? " AND i.sent = '0' AND i.cookie != '' AND i.password != ''" : "";
// Ce imamo posiljanje brez emaila, ni potrebno da je email vnesen za posameznega respondenta
if($noEmailing == 1){
$sql_fields = "SELECT DISTINCT i.password, i.id, i.email, i.firstname, i.last_status, i.list_id FROM srv_invitations_recipients AS i";
$sql_main_condition = " WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND i.unsubscribed = '0'";
$sql_sort = " ORDER BY i.id ASC";
$sql_string = $sql_fields
. $advancedConditionJoin
. $sql_main_condition
. $advancedCondition
. $sql_sub_condition
. $sub_query
. $sql_sort;
if ($sql_string != null) {
$qry = sisplet_query($sql_string);
while ($row = mysqli_fetch_assoc($qry)) {
$respondenti[$row['password']] = array('id'=>$row['id'], 'email'=>$row['email'], 'firstname'=>$row['firstname'], 'status'=>$row['last_status'], 'list_id'=>$row['list_id']);
}
}
}
else{
$sql_fields = "SELECT DISTINCT i.password, i.id, i.email, i.last_status, i.list_id FROM srv_invitations_recipients AS i";
$sql_main_condition = " WHERE i.ank_id = '".$this->sid."' AND i.deleted = '0' AND i.unsubscribed = '0' AND i.email IS NOT NULL";
$sql_sort = " ORDER BY i.id ASC";
$sql_string = $sql_fields
. $advancedConditionJoin
. $sql_main_condition
. $sql_voting_condition
. $advancedCondition
. $sql_sub_condition
. $sub_query
. $sql_sort;
if ($sql_string != null) {
$qry = sisplet_query($sql_string);
while ($row = mysqli_fetch_assoc($qry)) {
$respondenti[$row['password']] = array('id'=>$row['id'], 'email'=>$row['email'], 'status'=>$row['last_status'], 'list_id'=>$row['list_id']);
}
}
}
return($respondenti);
}
/* Paginacija za pregled respondentov pred pošiljanjem
*
*/
function displaySendPagination($all_records) {
global $lang,$site_url;
#trenutna stran
$page = isset($_GET['page']) ? $_GET['page'] : '1';
$current = is_numeric($_GET['page']) && (int)$_GET['page'] > 0 ? $page : '1';
$all = ceil($all_records / $this->rec_send_page_limit);
# current nastavimo na zadnji element
if ( $all > 1 ) {
echo '';
}
echo '
'.$lang['srv_inv_pagination_shown'];
$rec_on_page_options = array(20,50,100,200,500,1000);
$none_added = true;
$added_over = false;
echo '';
foreach ($rec_on_page_options AS $option) {
if ($all_records >= $option || $none_added == true || $added_over == false) {
echo 'rec_send_page_limit ? ' selected="selected"' : '').'>'.$option.' ';
$none_added = false;
if ($option > $all_records) {
$added_over = true;
}
}
#$rec_on_page;
}
echo ' ';
echo $lang['srv_inv_pagination_shown_records'].'
';
}
/* Paginacija za pregled reposndentov
*
*/
function displayPagination($all_records) {
global $lang, $site_url;
#trenutna stran
$page = isset($_GET['page']) ? $_GET['page'] : '1';
$current = is_numeric($_GET['page']) && (int)$_GET['page'] > 0 ? $page : '1';
$all = ceil($all_records / REC_ON_PAGE);
# current nastavimo na zadnji element
if ( $all > 1) {
echo '';
}
}
function saveArchiveComment() {
$id = $_POST['aid'];
$comment = $_POST['comment'];
if ((int)$id > 0) {
$sql_string = "UPDATE srv_invitations_archive SET comment= '".$comment ."' WHERE id = '".$id."'";
$sqlQuery = sisplet_query($sql_string);
sisplet_query("COMMIT");
}
}
function generateMessageName() {
global $lang;
# poiščemo nov naslov
# zaporedno številčimo ime sporočilo1,2.... če slučajno ime že obstaja
$new_name = $lang['srv_inv_message_draft_name'];
$names = array();
$s = "SELECT naslov FROM srv_invitations_messages WHERE ank_id = '".$this->sid."' AND naslov LIKE '%".$new_name."%'";
$q = sisplet_query($s);
while (list($naslov) = mysqli_fetch_row($q)) {
$names[] = $naslov;
}
if (count($names) > 0) {
$cnt = 1;
while (in_array($lang['srv_inv_message_draft_name'].$cnt, $names)) {
$cnt++;
}
$new_name = $lang['srv_inv_message_draft_name'].$cnt;
}
return $new_name;
}
function editMessageDetails() {
global $lang;
echo '
';
echo $lang['srv_inv_message_draft_new_save'].': ';
# polovimo vsa sporočila
$sql_string = "SELECT * FROM srv_invitations_messages WHERE ank_id = '$this->sid'";
$sql_query = sisplet_query($sql_string);
echo '
';
echo ''.$lang['srv_inv_message_draft_new'].' ';
$messages = array();
while ( $row = mysqli_fetch_assoc($sql_query) ) {
$messages[$row['id']] = $row;
#'.((int)$_POST['mid'] == $row['id'] ? ' selected="selected"' : '').'
echo ''.$row['naslov'].' ';
}
echo ' ';
#'.((int)$_POST['mid'] > 0 ? ' class="displayNone"' : '').'
echo '
';
echo ' ';
echo ''.$lang['srv_inv_message_rename_new_name'];
$newName = $this->generateMessageName();
echo ' ';
echo ' ';
echo ' ';
echo '
';
echo $lang['srv_inv_message_draft_list_comment'];
#.((int)$_POST['mid'] > 0 ? $messages[(int)$_POST['mid']]['comment'] : '').
echo '';
echo '
';
echo '
'.$lang['save'].' ';
echo '
'.$lang['srv_cancel'].' ';
echo '
';
echo '
'; # id="inv_view_arch_recipients"
}
function messageSaveDetails() {
global $lang, $global_user_id;
$return = array('msg'=>'', 'error'=>'0');
#echo json_encode($return);
$mid = (int)$_POST['mid'];
$return['mid'] = $mid;
$comment = trim($_POST['profile_comment']);
$naslov = trim($_POST['naslov']);
$body = $_POST['body'];
$subject = $_POST['subject'];
if ($mid > 0) {
#updejtamo obstoječ profil
$sql_string = "UPDATE srv_invitations_messages SET subject_text='".$subject."', body_text='".$body."', comment='".$comment."', edit_uid='".$global_user_id."', edit_time=NOW() WHERE ank_id = '$this->sid' AND id='$mid'";
$sqlQuery = sisplet_query($sql_string);
$return['mid'] = $mid;
if ( $sqlQuery != 1) {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_msg_4'];
}
sisplet_query("COMMIT");
} else {
# shranimo v nov profil
# ali shranjujemo v novo sporočilo
$sql_insert = "INSERT INTO srv_invitations_messages (ank_id, naslov, isdefault, uid, insert_time, comment, edit_uid, edit_time, subject_text, body_text) "
."VALUES ('$this->sid', '$naslov', '1', '$global_user_id', NOW(), '$comment', '$global_user_id', NOW(), '$subject', '$body')";
$sqlQuery = sisplet_query($sql_insert);
$mid = mysqli_insert_id($GLOBALS['connect_db']);
if ($mid > 0) {
$return['mid'] = $mid;
# popravmo še isdefault pri starem zapisz
$sql_string = "UPDATE srv_invitations_messages SET isdefault = '0' WHERE ank_id = '$this->sid' AND id != '$mid'";
$sqlQuery = sisplet_query($sql_string);
} else {
$return['error'] = '1';
$return['msg'] .= $newline.$lang['srv_inv_msg_4'];
}
sisplet_query("COMMIT");
}
echo json_encode($return);
exit;
}
function prepareSaveMessage() {
global $lang;
echo '
';
echo $lang['srv_inv_message_draft_new_save'].': ';
# polovimo vsa sporočila
$sql_string = "SELECT * FROM srv_invitations_messages WHERE ank_id = '$this->sid'";
$sql_query = sisplet_query($sql_string);
echo '
';
echo ''.$lang['srv_inv_message_draft_new'].' ';
$messages = array();
while ( $row = mysqli_fetch_assoc($sql_query) ) {
$messages[$row['id']] = $row;
echo ''.$row['naslov'].' ';
}
echo ' ';
echo '
0 ? ' class="displayNone"' : '').'>';
echo ' ';
echo ''.$lang['srv_inv_message_draft_list_name'];
$newName = $this->generateMessageName();
echo ' ';
echo ' ';
echo ' ';
echo '
';
echo $lang['srv_inv_message_draft_list_comment'];
echo '';
echo '
';
echo '
'.$lang['srv_cancel'].' ';
echo '
'.$lang['save'].' ';
echo '
';
echo '
'; # id="inv_view_arch_recipients"
}
function showRecipientTracking() {
global $lang,$site_url,$global_user_id;
$_rec_id = $_POST['rid'];
# polovimo podatke o uporabniku
$sql_string = "SELECT firstname,lastname,email,last_status, DATE_FORMAT(date_inserted,'%d.%m.%Y, %T') AS di FROM srv_invitations_recipients WHERE id = '".(int)$_rec_id."'";
$sql_query = sisplet_query($sql_string);
$sql_row = mysqli_fetch_assoc($sql_query);
$avtor = array();
if (trim($sql_row['firstname'])) {
$avtor[] = iconv("iso-8859-2", "utf-8",trim ($sql_row['firstname']));
}
if (trim($sql_row['lastname'])) {
$avtor[] = iconv("iso-8859-2", "utf-8",trim ($sql_row['lastname']));
}
$lastStatus = $sql_row['last_status'];
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_invitation_user_chronology_note'];
if ( count($avtor) > 0 ) {
echo '';
echo implode(' ',$avtor);
if($sql_row['email'] != '')
echo ' ('.trim($sql_row['email']).')';
echo ' ';
} else {
# izpišemo samo email
echo trim($sql_row['email']);
}
echo ' ';
echo '
';
echo $lang['srv_inv_recipients_date_inserted'].': '.$sql_row['di'];
# polovimo podatke uporabnikovih arhivov
$sql_string = "SELECT ia.*, u.name, u.surname, u.email FROM srv_invitations_archive AS ia LEFT JOIN users AS u ON ia.uid = u.id WHERE ia.id IN (SELECT inv_arch_id FROM srv_invitations_tracking WHERE res_id = '$_rec_id' ) ";
$sql_query = sisplet_query($sql_string);
$cnt =0;
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$cnt++;
$avtor_email = iconv("iso-8859-2", "utf-8",trim ($sql_row['email']));
$avtor = array();
if (trim($sql_row['name'])) {
$avtor[] = trim ($sql_row['name']);
}
if (trim($sql_row['surname'])) {
$avtor[] = trim ($sql_row['surname']);
}
if ( count($avtor) > 0 ) {
$avtor_name = implode(' ',$avtor);
} else {
$avtor_name = $avtor_email;
}
echo '
';
echo $cnt.$lang['srv_invitation_user_chronology_sending'];
echo ' ('.$lang['srv_invitation_user_chronology_send_by'];
echo ' '.$avtor_name.' ';
echo ')';
echo '
';
echo '
';
echo '
';
echo '';
echo ''.$lang['srv_invitation_user_chronology_date'].' ';
// Volitve nimajo nekaterih polj
if(!SurveyInfo::getInstance()->checkSurveyModule('voting'))
echo ''.$lang['srv_invitation_user_chronology_status'].' ';
echo ''.$lang['srv_inv_message_type'].' ';
echo ' ';
$sql_string1 = "SELECT status, DATE_FORMAT(time_insert,'%d.%m.%Y, %T') AS status_time FROM srv_invitations_tracking WHERE res_id = '$_rec_id' AND inv_arch_id='".$sql_row['id']."' ORDER BY uniq ASC";
$sql_query1 = sisplet_query($sql_string1);
while ($sql_row1 = mysqli_fetch_assoc($sql_query1)) {
echo '';
echo ''.$sql_row1['status_time'].' ';
// Volitve nimajo nekaterih polj
if(!SurveyInfo::getInstance()->checkSurveyModule('voting'))
echo '('.$sql_row1['status'].') - '.$lang['srv_userstatus_'.$sql_row1['status']].' ';
echo '';
if ($sql_row['tip'] == '0')
echo $lang['srv_inv_message_noemailing_type1'];
elseif($sql_row['tip'] == '1')
echo $lang['srv_inv_message_noemailing_type2'];
elseif($sql_row['tip'] == '2')
echo $lang['srv_inv_message_noemailing_type3'];
else
echo $lang['email'];
echo ' ';
echo ' ';
}
echo '
';
echo '
';
}
// Volitve nimajo nekaterih polj
if(!SurveyInfo::getInstance()->checkSurveyModule('voting')){
echo '
';
echo ''.$lang['srv_inv_recipients_final_status'].' ('.$lastStatus.') - '.$lang['srv_userstatus_'.$lastStatus];
echo '
';
}
echo '
'; // inv_select_mail_preview
echo '
'; // id="arc_content"
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_zapri'].' ';
echo '
';
echo '
';
echo '
';
}
function showArchiveRecipients($_arch_id = null, $archType = 'all') {
global $lang,$site_url,$global_user_id;
echo '
';
if ($_arch_id == null) {
$_arch_id = $_POST['aid'];
}
#polovimo podatke arhiva
$sql_string = "SELECT sia.*, DATE_FORMAT(sia.date_send,'%d.%m.%Y, %T') AS ds, u.name, u.surname, u.email FROM srv_invitations_archive AS sia LEFT JOIN users AS u ON sia.uid = u.id WHERE sia.id = '".$_arch_id."'";
$sql_query = sisplet_query($sql_string);
$row = mysqli_fetch_assoc($sql_query);
# polovimo sezname
$lists = array();
$sql_string = "SELECT pid, name,comment FROM srv_invitations_recipients_profiles WHERE uid in('".$global_user_id."')";
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$lists[$sql_row['pid']] = $sql_row['name'];
}
$lists['-1'] = $lang['srv_invitation_new_templist'];
$lists['0'] = $lang['srv_invitation_new_templist_author'];
#max ststusi po userjih
$arch_user_max_status = array();
$str_max_status = "select res_id AS rid, max(status) AS usr_status from srv_invitations_tracking where inv_arch_id = '$_arch_id' GROUP BY res_id";
$qry_max_status = sisplet_query($str_max_status);
while (list($res_id,$arch_status) = mysqli_fetch_row($qry_max_status)) {
$arch_user_max_status[$res_id] = $arch_status;
}
#$data = explode('_',$_POST['arch_to_view']);
#$_success = (int)$data[2];
#$_arch_id = $data[3];
$sql_string = "SELECT * FROM srv_invitations_archive WHERE id = '$_arch_id'";
$sql_query = sisplet_query($sql_string);
$sql_a_row = mysqli_fetch_assoc($sql_query);
#$sql_string = "SELECT id as res_id,email,firstname,lastname, password,sent,responded,unsubscribed,deleted,list_id,last_status FROM srv_invitations_recipients WHERE id IN (SELECT DISTINCT res_id FROM srv_invitations_tracking WHERE inv_arch_id = '$_arch_id' )";
$sql_string = "SELECT DISTINCT sir.id as res_id,sir.email,sir.firstname,sir.lastname, sir.password,sir.sent,sir.responded,sir.unsubscribed,sir.deleted,"
."sir.list_id,sir.last_status FROM srv_invitations_recipients AS sir INNER JOIN srv_invitations_tracking AS sit ON sir.id = sit.res_id WHERE sit.inv_arch_id = '$_arch_id'";
// prikazujemo samo napake
if ($archType == 'err') {
$sql_string = "SELECT DISTINCT sir.id as res_id,sir.email,sir.firstname,sir.lastname, sir.password,sir.sent,sir.responded,sir.unsubscribed,sir.deleted,"
."sir.list_id,sir.last_status FROM srv_invitations_recipients AS sir INNER JOIN srv_invitations_tracking AS sit ON sir.id = sit.res_id "
." JOIN srv_invitations_archive_recipients siar ON sir.id = siar.rec_id AND siar.arch_id = sit.inv_arch_id AND siar.success = '0'"
."WHERE sit.inv_arch_id = '$_arch_id'";
}
// priazujemo samo ok
if ($archType == 'succ') {
$sql_string = "SELECT DISTINCT sir.id as res_id,sir.email,sir.firstname,sir.lastname, sir.password,sir.sent,sir.responded,sir.unsubscribed,sir.deleted,"
."sir.list_id,sir.last_status FROM srv_invitations_recipients AS sir INNER JOIN srv_invitations_tracking AS sit ON sir.id = sit.res_id "
." JOIN srv_invitations_archive_recipients siar ON sir.id = siar.rec_id AND siar.arch_id = sit.inv_arch_id AND siar.success = '1'"
."WHERE sit.inv_arch_id = '$_arch_id'";
}
$sql_query = sisplet_query($sql_string);
echo '
';
$avtor_email = iconv("iso-8859-2", "utf-8",trim ($row['email']));
$avtor = array();
if (trim($row['name'])) {
$avtor[] = trim ($row['name']);
}
if (trim($row['surname'])) {
$avtor[] = trim ($row['surname']);
}
if ( count($avtor) > 0 ) {
$avtor_name = implode(' ',$avtor);
} else {
$avtor_name = $avtor_email;
}
echo '
';
echo '
';
echo $lang['srv_inv_archive_naslov'];
echo ': '.$row['naslov'].' ';
echo ' ';
echo '
';
echo $lang['srv_invitation_user_chronology_send_by'];
echo ' '.$avtor_name.' ';
echo ', ';
echo $row['ds'];
echo ' ';
echo '
';
echo $lang['srv_inv_message_type'];
echo ': ';
if ($row['tip'] == '0')
echo $lang['srv_inv_message_noemailing_type1'];
elseif($row['tip'] == '1')
echo $lang['srv_inv_message_noemailing_type2'];
elseif($row['tip'] == '2')
echo $lang['srv_inv_message_noemailing_type3'];
else
echo $lang['email'];
echo ' ';
echo '
'; // inv_select_mail_preview
echo '
'; // id="arc_content"
echo '
';
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_zapri'].' ';
echo '
';
echo '
';
echo '
';
}
function editArchiveDetails() {
global $lang,$site_url;
echo '
';
$_arch_id = $_POST['aid'];
#polovimo podatke arhiva
$sql_string = "SELECT * FROM srv_invitations_archive WHERE id = '".$_arch_id."'";
$sql_query = sisplet_query($sql_string);
$row = mysqli_fetch_assoc($sql_query);
echo '
';
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_inv_message_draft_content_subject'].': ';
echo '';
echo ''.$row['subject_text'].' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_content_body'].': ';
echo '';
echo ''.($row['body_text']).' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_comment'].': ';
echo '';
echo '';
echo '';
echo ' ';
echo ' ';
echo '
';
echo '
'; // inv_select_mail_preview
echo '
'; // id="arc_content"
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_zapri'].' ';
echo ''.$lang['save'].' ';
echo '
';
echo '
';
echo '
';
}
function showArchiveDetails() {
global $lang,$site_url;
echo '
';
$_arch_id = $_POST['aid'];
#polovimo podatke arhiva
$sql_string = "SELECT * FROM srv_invitations_archive WHERE id = '".$_arch_id."'";
$sql_query = sisplet_query($sql_string);
$row = mysqli_fetch_assoc($sql_query);
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_inv_message_draft_content_subject'].': ';
echo '';
echo ''.$row['subject_text'].' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_content_body'].': ';
echo '';
echo ''.($row['body_text']).' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_comment'].': ';
echo '';
echo '';
echo '';
echo ' ';
echo ' ';
echo '
';
echo '
'; // inv_select_mail_preview
echo '
'; // id="arc_content"
echo '
';
echo '
';
echo '
';
echo ''.$lang['srv_zapri'].' ';
echo '
';
echo '
';
echo '
';
}
function showInvitationStatus() {
global $admin_type, $global_user_id;
$isEmail = (int)SurveyInfo::getInstance()->checkSurveyModule('email');
$d = new Dostop();
echo '
';
// Pri volitvah prikazemo samo osnovne stevilke - zaradi anonimizacije ni trackinga
if(SurveyInfo::getInstance()->checkSurveyModule('voting')){
$userAccess = UserAccess::getInstance($global_user_id);
// Ce so izklopljena ne prikazemo leve strani
if((int)$isEmail > 0 && $userAccess->checkUserAccess($what='invitations')){
echo '';
$this->displayInvitationStatusVoting();
echo ' ';
}
}
else{
$userAccess = UserAccess::getInstance($global_user_id);
// Ce so izklopljena ne prikazemo leve strani
if((int)$isEmail > 0 && $userAccess->checkUserAccess($what='invitations')){
echo '';
$this->displayInvitationStatusNew();
echo ' ';
}
}
echo '
';
}
// Prikaz statusov posiljanj
private function displayInvitationStatusNew() {
global $lang, $admin_type, $global_user_id, $site_url, $site_path;
$isEmail = (int)SurveyInfo::getInstance()->checkSurveyModule('email');
$userAccess = UserAccess::getInstance($global_user_id);
// Email vabila so omogocena
if ((int)$isEmail > 0 && $userAccess->checkUserAccess($what='invitations')) {
echo '
'.$lang['srv_inv_nav_email_status'].' ';
echo '';
echo '
';
#koliko je vseh uporabnikov v bazi
$sql_query = sisplet_query("SELECT count(*) as cnt FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted ='0'");
list($cnt_all_in_db) = mysqli_fetch_row($sql_query);
#zloopamo skozi posamezna pošiljanja in preštejemo vse potrebno
$sql_query = sisplet_query("SELECT sia.id, sia.tip, rec_in_db, DATE_FORMAT(sia.date_send,'%d.%m.%Y, %T') AS ds, u.name, u.surname, u.email
FROM srv_invitations_archive AS sia
INNER JOIN users AS u ON sia.uid = u.id
WHERE ank_id = '".$this->sid."'
ORDER BY sia.date_send ASC;
");
$array_dashboard = array();
$array_archive_subdata = array();
$user_max_status = array();
$user_lurker = array();
# štetje po pošiljanjih
$cnt_by_user = array();
if (mysqli_num_rows($sql_query) > 0) {
#loop po vseh arhivih
while($row = mysqli_fetch_assoc($sql_query)) {
$array_archive_subdata[$row['id']] = $row;
$sql_subStr = "SELECT sit.res_id,sit.status FROM srv_invitations_tracking AS sit WHERE sit.inv_arch_id = '".$row['id']."' AND sit.res_id IN (SELECT id FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted ='0')";
$sql_subStr = "SELECT sit.res_id,sit.status, su.lurker FROM srv_invitations_tracking AS sit"
." INNER JOIN srv_invitations_recipients AS sir ON sit.res_id = sir.id"
." INNER join srv_user AS su ON sit.res_id = su.inv_res_id"
." WHERE sir.ank_id='$this->sid' AND sir.deleted ='0' AND su.ank_id='$this->sid' AND sit.inv_arch_id = '$row[id]'";
$sql_subQry = sisplet_query($sql_subStr);
$sub_max = array();
#loop po vseh trackingih posameznega arhiva
while($subRow = mysqli_fetch_assoc($sql_subQry)) {
if ((int)$subRow['status'] == 2) {
$subRow['status'] = -2;
}
if ((int)$subRow['status'] == 1) {
$cnt_by_user[$subRow['res_id']]++;
}
#maximalni status uporabnika za posamezen arhiv
$sub_max[$subRow['res_id']] = max($sub_max[$subRow['res_id']],$subRow['status']);
#globalni max statusi posameznih uporabnikov
$_userMaxStatus = max($user_max_status[$subRow['res_id']],$subRow['status']);
$user_max_status[$subRow['res_id']] = $_userMaxStatus;
$user_lurker[$subRow['res_id']] = $subRow['lurker'];
}
#maximalni statusi uporabniak v posameznem arhivu
$array_dashboard[$row['id']] = $sub_max;
}
}
# preštejemo respondente po statusu
$recipients_by_status = array();
$recipients_by_status['all']=(int)$cnt_all_in_db;
$user_by_status_for_archive = array();
if (count($user_max_status) > 0) {
foreach ($user_max_status AS $uid => $status) {
switch ((int)$status) {
# 2 - E-pošta - napaka
case -2:
$recipients_by_status['not_send'] ++;
$recipients_by_status['error'] ++;
break;
# 0 - E-pošta - ni poslana
case 0:
$recipients_by_status['not_send'] ++;
break;
# 1 - E-pošta - neodgovor
case 1:
$recipients_by_status['send'] ++;
break;
# 3 - klik na nagovor
case 3:
$recipients_by_status['send'] ++;
$recipients_by_status['clicked'] ++;
break;
# 4 - klik na anketo
case 4:
$recipients_by_status['send'] ++;
$recipients_by_status['clicked'] ++;
break;
# 5 - delno prazna
case 5:
$recipients_by_status['send'] ++;
#$recipients_by_status['clicked'] ++;
if ($user_lurker[$uid] == 1) {
# če je lurker
$recipients_by_status['clicked'] ++;
} else {
$recipients_by_status['finished'] ++;
}
break;
# 6 - končana
case 6:
$recipients_by_status['send'] ++;
if ($user_lurker[$uid] == 1) {
# če je lurker
$recipients_by_status['clicked'] ++;
} else {
$recipients_by_status['finished'] ++;
}
break;
# null - neznan
default:
$recipients_by_status['unknown'] ++;
break;
}
}
echo '
';
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_all'].' ';
echo ''.(int)$recipients_by_status['all'].' ';
echo '- ';
echo '100% ';
echo ' ';
#popslano enotam
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_send'].' ';
echo ''.(int)$recipients_by_status['send'].' ';
echo ''.((int)$recipients_by_status['send'] > 0 ? '100%' : '0%').' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['send'] > 0 ? (int)$recipients_by_status['send']*100/(int)$recipients_by_status['all'] : 0),0,'%').' ';
echo ' ';
#neodgovori
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_unanswered'].' ';
$unanswered = ((int)$recipients_by_status['send']-(int)$recipients_by_status['clicked']-(int)$recipients_by_status['finished']);
echo ''.$unanswered.' ';
echo ''.$this->formatNumber(($unanswered > 0 ? $unanswered*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(($unanswered > 0 ? $unanswered*100/(int)$recipients_by_status['all'] : 0),0,'%').' ';
echo ' ';
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_clicked'].' ';
echo ''.(int)$recipients_by_status['clicked'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['clicked'] > 0 ? (int)$recipients_by_status['clicked']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['clicked'] > 0 ? (int)$recipients_by_status['clicked']*100/(int)$recipients_by_status['all'] : 0),0,'%').' ';
echo ' ';
#če se slučajno pojavijo kaki neznani statusi
if ((int)$recipients_by_status['unknown'] > 0) {
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_unknown'].' ';
echo ''.(int)$recipients_by_status['unknown'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['unknown'] > 0 ? (int)$recipients_by_status['unknown']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['unknown'] > 0 ? (int)$recipients_by_status['unknown']*100/(int)$recipients_by_status['all'] : 0),0,'%').' ';
echo ' ';
}
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_finished'].' ';
echo ''.(int)$recipients_by_status['finished'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['finished'] > 0 ? (int)$recipients_by_status['finished']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['finished'] > 0 ? (int)$recipients_by_status['finished']*100/(int)$recipients_by_status['all'] : 0),0,'%').' ';
echo ' ';
echo '
';
echo '
';
# POSAMEZNA pošiljanja
if (count($array_dashboard ) > 0) {
foreach ($array_dashboard AS $archive_id => $archive_data) {
if (count($archive_data ) > 0) {
foreach ($archive_data AS $uid => $status) {
if ((int)$status == 6 && $user_lurker[$uid] == 1) {
$user_by_status_for_archive[$archive_id]['6l']++;
} else if ((int)$status == 5 && $user_lurker[$uid] == 1) {
$user_by_status_for_archive[$archive_id]['5l']++;
} else {
$user_by_status_for_archive[$archive_id][$status]++;
}
}
}
}
}
$cnt = 0;
if (count($user_by_status_for_archive ) > 0) {
foreach ($user_by_status_for_archive AS $arch_id => $archive_data) {
$cnt++;
if (count($archive_data ) > 0) {
$recipients_by_status = array();
$recipients_by_status['all']=(int)$array_archive_subdata[$arch_id]['rec_in_db'];
foreach ($archive_data AS $status => $cntUsers) {
# 0 - E-pošta - ni poslana
if( $status == '0') {
$recipients_by_status['not_send'] +=$cntUsers;
# 1 - E-pošta - neodgovor'
} else if( $status == '1') {
$recipients_by_status['send'] +=$cntUsers;
# 2 - E-pošta - napaka
} else if( $status == '2') {
$recipients_by_status['error'] +=$cntUsers;
# 3 - klik na nagovor
} else if( $status == '3') {
$recipients_by_status['send'] +=$cntUsers;
$recipients_by_status['clicked'] +=$cntUsers;
# 4 - klik na anketo
} else if( $status == '4') {
$recipients_by_status['send'] +=$cntUsers;
$recipients_by_status['clicked'] +=$cntUsers;
# 5 - delno prazna
} else if( $status == '5') {
$recipients_by_status['send'] +=$cntUsers;
#$recipients_by_status['clicked'] +=$cntUsers;
$recipients_by_status['finished'] +=$cntUsers;
# 5 - delno prazna -lurker
} else if( $status == '5l') {
$recipients_by_status['send'] +=$cntUsers;
$recipients_by_status['clicked'] +=$cntUsers;
# 6 - končana
} else if( $status == '6') {
$recipients_by_status['send'] +=$cntUsers;
$recipients_by_status['finished'] +=$cntUsers;
# 6 - končana - lurker
} else if( $status == '6l') {
$recipients_by_status['send'] +=$cntUsers;
$recipients_by_status['clicked'] +=$cntUsers;
} else {
# null - neznan
$recipients_by_status['unknown'] +=$cntUsers;
}
}
$avtor_email = iconv("iso-8859-2", "utf-8",trim ($array_archive_subdata[$arch_id]['email']));
$avtor = array();
if (trim($array_archive_subdata[$arch_id]['name'])) {
$avtor[] = trim ($array_archive_subdata[$arch_id]['name']);
}
if (trim($array_archive_subdata[$arch_id]['surname'])) {
$avtor[] = trim ($array_archive_subdata[$arch_id]['surname']);
}
if ( count($avtor) > 0 ) {
$avtor_name = implode(' ',$avtor);
} else {
$avtor_name = $avtor_email;
}
$all_rec_in_survey = (int)$recipients_by_status['all'];
echo '
';
echo '';
echo '+ ';
echo '- ';
echo $cnt.$lang['srv_inv_dashboard_list_cnt_title'];
echo ' ';
// avtor
echo ''.$avtor_name.' ';
// datum
echo ', ';
echo ''.$array_archive_subdata[$arch_id]['ds'].' ';
// nacin posiljanja
echo ', ';
echo '';
if ($array_archive_subdata[$arch_id]['tip'] == '0')
echo ''.$lang['srv_inv_message_noemailing_type1'].' ';
elseif($array_archive_subdata[$arch_id]['tip'] == '1')
echo ''.$lang['srv_inv_message_noemailing_type2'].' ';
elseif($array_archive_subdata[$arch_id]['tip'] == '2')
echo ''.$lang['srv_inv_message_noemailing_type3'].' ';
else
echo ''.$lang['email'].' ';
echo ' ';
echo ' ';
// arhiv
echo '
arhiv ';
echo '
';
echo '
';
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_all'].' ';
echo ''.(int)$all_rec_in_survey.' ';
#echo ''.(int)$recipients_by_status['all'].' ';
echo ' ';
echo '100% ';
echo ' ';
# poslano enotam
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_send'].' ';
echo ''.(int)$recipients_by_status['send'].' ';
echo ''.((int)$recipients_by_status['send'] > 0 ? '100%' : '0%').' ';
echo ''.$this->formatNumber(((int)$all_rec_in_survey > 0 ? (int)$recipients_by_status['send']*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
# neodgovori
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_unanswered'].' ';
$unanswered = ((int)$recipients_by_status['send']-(int)$recipients_by_status['clicked']-(int)$recipients_by_status['finished']);
echo ''.$unanswered.' ';
echo ''.$this->formatNumber(($recipients_by_status['send'] > 0 ? $unanswered*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(($all_rec_in_survey > 0 ? $unanswered*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_clicked'].' ';
echo ''.(int)$recipients_by_status['clicked'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['send'] > 0 ? (int)$recipients_by_status['clicked']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$all_rec_in_survey > 0 ? (int)$recipients_by_status['clicked']*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
#če se slučajno pojavijo kaki neznani statusi
if ((int)$recipients_by_status['unknown'] > 0) {
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_unknown'].' ';
echo ''.(int)$recipients_by_status['unknown'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['send'] > 0 ? (int)$recipients_by_status['unknown']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$all_rec_in_survey > 0 ? (int)$recipients_by_status['unknown']*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
}
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_finished'].' ';
echo ''.(int)$recipients_by_status['finished'].' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['send'] > 0 ? (int)$recipients_by_status['finished']*100/(int)$recipients_by_status['send'] : 0),0,'%').' ';
echo ''.$this->formatNumber(((int)$all_rec_in_survey > 0 ? (int)$recipients_by_status['finished']*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
#napake
if ((int)$recipients_by_status['error'] > 0) {
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_error'].' ';
echo ''.(int)$recipients_by_status['error'].' ';
echo ' ';
echo ''.$this->formatNumber(((int)$recipients_by_status['error'] > 0 ? (int)$recipients_by_status['error']*100/(int)$all_rec_in_survey : 0),0,'%').' ';
echo ' ';
}
echo '
';
}
}
}
} else {
// Imamo sezname, ni pa poslanih vabil
if ((int)$cnt_all_in_db > 0){
echo $lang['srv_inv_dashboard_has_list2'];
//echo '
'.$lang['srv_inv_dashboard_add_list'].'
';
echo '
';
echo '
';
echo '
';
//echo '
'.$lang['srv_inv_dashboard_view_list'].'
';
}
// Ni seznamov in ni poslanih vabil
else{
echo $lang['srv_inv_dashboard_empty'];
//echo '
'.$lang['srv_inv_dashboard_add_list'].'
';
echo '
';
echo '
';
}
}
echo '';
echo '
';
echo '';
}
// Email vabila niso omogocena
else {
echo '
'.$lang['srv_inv_nav_email_status'].' ';
echo '';
echo '
';
echo $lang['srv_inv_dashboard_not_enabled'];
# uporabnik nima pravic omogočit vabil
if (!$userAccess->checkUserAccess($what='invitations')) {
echo ' '.$lang['srv_inv_dashboard_no_permissions'];
}
# uporabnik lahko vklopi email vabila
else {
echo ' '.$lang['srv_omogoci'].' ';
}
echo '
';
echo '
';
echo '';
}
// predpripravimo podatke za vsa pošiljanja
$cnt_by_sendings = array();
$all_units_count = count($cnt_by_user);
if ($all_units_count > 0) {
foreach ($cnt_by_user AS $uid => $ucnt) {
$cnt_by_sendings[$ucnt]++;
}
echo '
';
#pregled po pošiljanjih
echo '
';
echo '';
echo '';
echo '+ ';
echo '- ';
echo ''.$lang['srv_inv_nav_email_sending_status'].' ';
echo ' ';
echo Help::display('srv_inv_cnt_by_sending');
echo ' ';
echo ' ';
echo '';
echo '
';
echo '';
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo '';
echo ''.$lang['srv_inv_sending_overview_cnt'].' ';
echo ''.$lang['srv_inv_sending_overview_units'].' ';
echo ''.$lang['srv_inv_sending_overview_percentage'].' ';
echo ' ';
if ($cnt_by_sendings > 0) {
foreach ($cnt_by_sendings AS $cnt => $units) {
echo '';
echo ''.$cnt.' ';
echo ''.$units.' ';
$percent = ($all_units_count > 0) ? $units / $all_units_count * 100 : 0;
echo ''.Common::formatNumber ($percent,0,null,'%').' ';
echo ' ';
}
}
echo '';
echo ''.$lang['srv_inv_sending_overview_sum'].' ';
echo ''.$all_units_count.' ';
$percent = ($all_units_count > 0) ? $all_units_count / $all_units_count * 100 : 0;
echo ''.Common::formatNumber ($percent,0,null,'%').' ';
echo ' ';
echo '
';
echo '
';
echo ' ';
}
}
// Prikaz statusov posiljanj pri volitvah
private function displayInvitationStatusVoting() {
global $lang, $admin_type, $global_user_id, $site_url, $site_path;
$isEmail = (int)SurveyInfo::getInstance()->checkSurveyModule('email');
$userAccess = UserAccess::getInstance($global_user_id);
// Email vabila so omogocena
if ((int)$isEmail > 0 && $userAccess->checkUserAccess($what='invitations')) {
echo '
'.$lang['srv_inv_nav_email_status'].' ';
echo '';
echo '
';
#koliko je vseh uporabnikov v bazi in kolkim je bil mail poslan
$sql_count = sisplet_query("SELECT count(id) as cnt, sent
FROM srv_invitations_recipients
WHERE ank_id='".$this->sid."' AND deleted ='0'
GROUP BY sent
");
$cnt_all_in_db = 0;
$cnt_sent_in_db = 0;
while($row_count = mysqli_fetch_array($sql_count)){
$cnt_all_in_db += (int)$row_count['cnt'];
if($row_count['sent'] == '1'){
$cnt_sent_in_db += (int)$row_count['cnt'];
}
}
echo '
';
// Vsi v bazi
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_all'].' ';
echo ''.(int)$cnt_all_in_db.' ';
echo '- ';
echo '100% ';
echo ' ';
// Poslani
echo '';
echo ''.$lang['srv_inv_dashboard_tbl_send'].' ';
echo ''.(int)$cnt_sent_in_db.' ';
echo ''.((int)$cnt_sent_in_db > 0 ? '100%' : '0%').' ';
echo ''.$this->formatNumber(((int)$cnt_sent_in_db > 0 ? (int)$cnt_sent_in_db*100/(int)$cnt_all_in_db : 0),0,'%').' ';
echo ' ';
echo '
';
echo '';
echo '
';
echo '';
}
// Email vabila niso omogocena
else {
echo '
'.$lang['srv_inv_nav_email_status'].' ';
echo '';
echo '
';
echo $lang['srv_inv_dashboard_not_enabled'];
# uporabnik nima pravic omogočit vabil
if (!$userAccess->checkUserAccess($what='invitations')) {
echo ' '.$lang['srv_inv_dashboard_no_permissions'];
}
# uporabnik lahko vklopi email vabila
else {
echo ' '.$lang['srv_omogoci'].' ';
}
echo '
';
echo '
';
echo '';
}
// predpripravimo podatke za vsa pošiljanja
/*$cnt_by_sendings = array();
$all_units_count = count($cnt_by_user);
if ($all_units_count > 0) {
foreach ($cnt_by_user AS $uid => $ucnt) {
$cnt_by_sendings[$ucnt]++;
}
echo '
';
#pregled po pošiljanjih
echo '
';
echo '';
echo '';
echo '+ ';
echo '- ';
echo ''.$lang['srv_inv_nav_email_sending_status'].' ';
echo ' ';
echo Help::display('srv_inv_cnt_by_sending');
echo ' ';
echo ' ';
echo '';
echo '
';
echo '';
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo '';
echo ''.$lang['srv_inv_sending_overview_cnt'].' ';
echo ''.$lang['srv_inv_sending_overview_units'].' ';
echo ''.$lang['srv_inv_sending_overview_percentage'].' ';
echo ' ';
if ($cnt_by_sendings > 0) {
foreach ($cnt_by_sendings AS $cnt => $units) {
echo '';
echo ''.$cnt.' ';
echo ''.$units.' ';
$percent = ($all_units_count > 0) ? $units / $all_units_count * 100 : 0;
echo ''.Common::formatNumber ($percent,0,null,'%').' ';
echo ' ';
}
}
echo '';
echo ''.$lang['srv_inv_sending_overview_sum'].' ';
echo ''.$all_units_count.' ';
$percent = ($all_units_count > 0) ? $all_units_count / $all_units_count * 100 : 0;
echo ''.Common::formatNumber ($percent,0,null,'%').' ';
echo ' ';
echo '
';
echo '
';
echo ' ';
}*/
}
function showInvitationSettings() {
global $lang, $admin_type, $global_user_id, $site_url, $site_path;
$row = $this->surveySettings;
$_email = (int)SurveyInfo::getInstance()->checkSurveyModule('email');
$userAccess = UserAccess::getInstance($global_user_id);
$noEmailing = SurveySession::get('inv_noEmailing');
# Admini, managerji in Clani, ki imajo odobren dostop - lahko vklopijo vabila
if ($userAccess->checkUserAccess($what='invitations')) {
// Vklop vabil
if ($_email == 0) {
echo '
';
echo '
'.$lang['srv_invitation_nonActivated_title'].' ';
echo '';
echo '
';
echo $lang['srv_invitation_nonActivated_text1'];
echo '
';
echo '
';
if($lang['id'] == '1')
echo sprintf($lang['srv_invitation_nonActivated_text2'], 'https://www.1ka.si/d/sl/pomoc/prirocniki/posiljanje-email-vabil-pridobitev-dovoljenja?from1ka=1');
else
echo sprintf($lang['srv_invitation_nonActivated_text2'], 'https://www.1ka.si/d/en/help/manuals/sending-email-invitations-and-obtaining-authorization?from1ka=1');
echo '
';
echo '
';
// Za gorenje popravimo text
$text3 = (Common::checkModule('gorenje')) ? str_replace('1KA', 'ESurvey', $lang['srv_invitation_nonActivated_text3']) : $lang['srv_invitation_nonActivated_text3'];
echo $text3;
echo '
';
// Gumb OMOGOCI VABILA
echo '
';
$text_button = (Common::checkModule('gorenje')) ? str_replace('1KA', 'ESurvey', $lang['srv_invitation_nonActivated_button_activate']) : $lang['srv_invitation_nonActivated_button_activate'];
echo ''.$text_button.' ';
echo '
';
echo '
';
echo '';
echo '
';
}
// Vabila so vklopljena - NASTAVITVE
else{
if($noEmailing == 1){
echo '
';
}
else{
echo '
';
}
// Leva stran - navadne nastavitve
echo '
';
echo '
'.$lang['srv_inv_nav_invitations_settings_general'].' '.Help::display('srv_inv_general_settings').' ';
echo '';
echo '
';
// Preverimo ce je vklopljen modul za volitve - potem ne pustimo nobenih preklopov
$voting_disabled = '';
if(SurveyInfo::getInstance()->checkSurveyModule('voting')){
$voting_disabled = ' disabled';
// Warning za volitve
echo '
'.$lang['srv_voting_warning'].'
';
}
$individual = (int)$this->surveySettings['individual_invitation'];
// Individualizirana vabila - GLAVNA NASTAVITEV
echo '
';
echo '
'.$lang['srv_user_base_individual_invitaition'];
if($individual == 0)
echo ' '.Help::display('srv_user_base_individual_invitaition_note2').' ';
else
echo ' '.Help::display('srv_user_base_individual_invitaition_note').' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['no1'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['yes'].' ';
echo '
';
echo '
';
// Ce niso indvidualizirana imamo samo nacin posiljanja
if ($individual == 0) {
// Nacin posiljanja (email, posta, sms...)
echo '
';
echo '
'.$lang['srv_inv_message_type'].': '.Help::display('srv_inv_sending_type').'
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_0'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_1'].' ';
echo '
';
echo '
';
// Nacin dokumentiranja (posta, sms, drugo)
if($noEmailing == 1){
$noEmailingType = SurveySession::get('inv_noEmailing_type');
echo '
';
echo '
'.$lang['srv_inv_message_type_external'].':
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type1'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type2'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type3'].' ';
echo '
';
echo '
';
}
}
# Normalna vabila z unikatinim URL
else {
// Nacin posiljanja (email, posta, sms...)
echo '
';
echo '
'.$lang['srv_inv_message_type'].': '.Help::display('srv_inv_sending_type').'
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_0'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_1'].' ';
echo '
';
echo '
';
// Nacin dokumentiranja (posta, sms, drugo)
if($noEmailing == 1){
$noEmailingType = SurveySession::get('inv_noEmailing_type');
echo '
';
echo '
'.$lang['srv_inv_message_type_external'].':
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type1'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type2'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_inv_message_noemailing_type3'].' ';
echo '
';
echo '
';
}
// Vnos kode - samo ce je email (drugace itak vedno rocni vnos)
if($noEmailing != 1){
echo '
';
echo '
'.$lang['usercode_required1'].':'.Help::display('usercode_required').'
';
echo '
';
echo ' ';
echo ' '.$lang['usercode_required2'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['usercode_required3'].' ';
echo '
';
echo '
';
}
if ($row['usercode_required'] != 0) {
echo '
';
if($noEmailing == 1)
echo ''.$lang['usercode_text2'].': ';
else
echo ''.$lang['usercode_text'].': ';
$nagovorText = ($row['usercode_text'] && $row['usercode_text'] != null && $row['usercode_text'] != "") ? $row['usercode_text'] : $lang['srv_basecode'];
echo ' ';
echo '
';
}
// Dostop brez kode
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_user_base_access_check'].' '.Help::display('srv_inv_no_code');
echo '
';
echo '
';
if($row['usercode_skip'] > 0){
echo '
';
echo '
'.$lang['srv_user_base_access'].Help::display('usercode_skip').'
';
echo '
';
echo ' ';
echo ' '.$lang['srv_vsi'].' ';
echo '
';
echo '
';
echo ' ';
echo ' '.$lang['srv_setting_onlyAuthor'].' ';
echo '
';
echo '
';
}
}
// Gumb shrani - samo provizorično
echo '
';
echo '
';
echo '
';
echo '';
echo '
';
// desna stran - nastavitve streznika - samo ce imamo posiljanje preko emaila
if($noEmailing != 1){
// Gorenje tega nima
if (!Common::checkModule('gorenje')){
echo '
';
echo '
'.$lang['srv_email_setting_title'].' ';
echo '';
echo '
';
$this->viewServerSettings();
echo '
';
echo '
';
echo '';
echo '
';
}
}
echo '
';
}
}
# navadni uporabniki, ki nimajo dostopa - text kako lahko pridobijo dostop
else {
echo '
';
echo '
'.$lang['srv_invitation_nonActivated_title'].' ';
echo '';
echo '
';
echo $lang['srv_invitation_nonActivated_text1'];
echo '
';
echo '
';
if($lang['id'] == '1')
echo sprintf($lang['srv_invitation_nonActivated_text2'], 'https://www.1ka.si/d/sl/pomoc/prirocniki/posiljanje-email-vabil-pridobitev-dovoljenja?from1ka=1');
else
echo sprintf($lang['srv_invitation_nonActivated_text2'], 'https://www.1ka.si/d/en/help/manuals/sending-email-invitations-and-obtaining-authorization?from1ka=1');
echo '
';
echo '
';
echo $lang['srv_invitation_nonActivated_text3'];
echo '
';
// Gumb ZAPROSI ZA DOSTOP DO VABIL
echo '
';
echo '
';
echo '';
echo '
';
}
}
function formatNumber ($value, $digit = 0, $sufix = "") {
if ($value <> 0 && $value != null)
$result = round($value, $digit);
else
$result = "0";
# polovimo decimalna mesta in vejice za tisočice
$decimal_point = SurveyDataSettingProfiles :: getSetting('decimal_point');
$thousands = SurveyDataSettingProfiles :: getSetting('thousands');
$result = number_format($result, $digit, $decimal_point, $thousands) . $sufix;
return $result;
}
function showInvitationLists($profile_id=null) {
global $lang,$global_user_id;
echo '
'.$lang['srv_inv_list_edit_header'].' ';
echo '
';
}
function showInvitationListsNames($profile_id=null) {
global $lang,$global_user_id;
$onlyThisSurvey = isset($_POST['onlyThisSurvey']) ? (int)$_POST['onlyThisSurvey'] : 1;
if ($profile_id == null) {
$pids = explode(',',$_POST['pids']);
} else {
$pids = explode(',',$profile_id);
}
if ($onlyThisSurvey == 0) {
#id-ji profilov do katerih lahko dostopamo
$accPid = '';
$accStr = "SELECT DISTINCT pid FROM srv_invitations_recipients_profiles_access where uid = '$global_user_id'";
$accQry = sisplet_query($accStr);
while (list($pid) = mysqli_fetch_row($accQry)) {
$accPid .= $prefix ."'".$pid."'";
$prefix = ',';
}
# polovimo še ostale porfile
$sql_string = "SELECT rp.*,DATE_FORMAT(rp.insert_time,'%d.%m.%Y, %T') AS ds, u.name as firstname, u.surname, u.email FROM srv_invitations_recipients_profiles AS rp LEFT JOIN users AS u ON rp.uid = u.id WHERE rp.uid in('".$global_user_id."')".($accPid != '' ? ' OR pid IN ('.$accPid.')':'');
$sql_query = sisplet_query($sql_string);
} else if ($onlyThisSurvey == 2) {
$sql_string = "SELECT sia.*,sia.id as pid, sia.naslov AS name, DATE_FORMAT(sia.date_send,'%d.%m.%Y, %T') AS ds, u.name as firstname, u.surname, u.email FROM srv_invitations_archive AS sia LEFT JOIN users AS u ON sia.uid = u.id WHERE ank_id = '".$this->sid."' ORDER BY sia.date_send DESC;";
$sql_query = sisplet_query($sql_string);
} else {
# 1
$sql_string = "SELECT rp.*, DATE_FORMAT(rp.insert_time,'%d.%m.%Y, %T') AS ds , u.name as firstname, u.surname, u.email FROM srv_invitations_recipients_profiles AS rp LEFT JOIN users AS u ON rp.uid = u.id WHERE from_survey = '$this->sid'";
$sql_query = sisplet_query($sql_string);
}
if (mysqli_num_rows($sql_query)>0) {
echo '
';
/*
* Osznačevanje vseh seznamov in brisanje le teh*/
echo '
';
} else {
echo $lang['srv_inv_list_no_lists'];
}
return (int)mysqli_num_rows($sql_query);
}
function showNoEditRecList($profile_id = null) {
global $lang;
$pids=array();
$onlyThisSurvey = (int)$_POST['onlyThisSurvey'];
if ($profile_id == null)
{
# preberemo id-je profilov in respondente
if ($_POST['pids'] != '')
{
$pids = explode(',',$_POST['pids']);
}
} else
{
# preberemo id-je profilov in respondente
if ($profile_id != '')
{
$pids = explode(',',$profile_id);
}
}
if (empty($pids))
{
echo $lang['srv_inv_list_choose_left'].'
';
}
session_start();
$infoBox = null;
if (is_array($pids) && count($pids) > 0)
{
echo '
'.$lang['srv_inv_list_edit'].'
';
$respondents = array();
$fields = array();
# info box prikazujemo samo ko imamo izbran 1 seznam
if ($onlyThisSurvey <= 1)
{
# če imamo normalne sezname
if (is_array($pids) && count($pids) == 1) {
$sql_string = "SELECT rp.respondents, fields,rp.name, rp.comment, u.email AS iemail, DATE_FORMAT(rp.insert_time,'%d.%m.%Y, %T') AS fitime, e.email AS eemail, DATE_FORMAT(rp.edit_time,'%d.%m.%Y, %T') AS fetime FROM srv_invitations_recipients_profiles AS rp LEFT JOIN users AS u ON rp.uid = u.id LEFT JOIN users AS e ON rp.uid = e.id WHERE rp.pid IN(".(implode(',',$pids)).")";
} else {
$sql_string = "SELECT rp.respondents, fields FROM srv_invitations_recipients_profiles AS rp WHERE rp.pid IN(".(implode(',',$pids)).")";
}
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query))
{
# info box prikazujemo samo ko imamo izbran 1 seznam
if (is_array($pids) && count($pids) == 1)
{
$infoBox .= '
';
$infoBox .= $lang['srv_inv_list_edit_added'];
$infoBox .= trim($sql_row['iemail']) != '' ? $sql_row['iemail'] : $lang['srv_inv_list_edit_1kasi'];
$infoBox .= $lang['srv_inv_list_edit_date'].$sql_row['fitime'];
if ($sql_row['fitime'] != $sql_row['fetime']) {
$infoBox .= ' '.$lang['srv_inv_list_edit_changed'];
$infoBox .= trim($sql_row['eemail']) != '' ? $sql_row['eemail'] : $lang['srv_inv_list_edit_1kasi'];
$infoBox .= $lang['srv_inv_list_edit_date'].$sql_row['fetime'];
}
$infoBox .= ''.$lang['srv_inv_list_edit_name'].$sql_row['name'].' ';
$infoBox .= ''.$lang['srv_inv_list_edit_comment'].$sql_row['comment'].' ';
}
#$array_profiles[$sql_row['pid']] = array('name' => $sql_row['name']);
$respondents_list = str_replace("\n\r", "\n", $sql_row['respondents']);
$respondents_list = explode("\n",$respondents_list);
$respondents = array_merge($respondents,$respondents_list);
$_fields = explode(",",$sql_row['fields']);
foreach ($_fields as $_field)
{
if (!in_array($_field,$fields)) {
$fields[] = $_field;
}
}
} # end-while
}
else
{
# imamo arhive
$fields = array();
$_recipients = array();
$sql_string = "SELECT email,firstname,lastname,salutation,phone,custom,relation FROM srv_invitations_recipients AS sir WHERE sir.id IN (SELECT siar.rec_id FROM srv_invitations_archive_recipients siar WHERE siar.arch_id IN (".(implode(',',$pids))."))";
$sql_query = sisplet_query($sql_string);
while ($row = mysqli_fetch_assoc($sql_query) ) {
$_recipients[] = $row;
foreach ($row AS $key => $value) {
if ($value !== null && !in_array($key,$fields)) {
$fields[] = $key;
}
}
}
# pripravimo respondente
foreach ($_recipients AS $_recipient) {
$recipient = '';
$prefix='';
foreach ($fields AS $field) {
$recipient.=$prefix.$_recipient[$field];
$prefix=',';
}
if ($recipient != '') {
$respondents[] = $recipient;
}
}
}
# pohandlamo polja
$field_list = array();
$default_fields = array(
'inv_field_email' => count($fields) == 0 ? 1 : 0,
'inv_field_firstname' => 0,
'inv_field_lastname' => 0,
'inv_field_password' => 0,
'inv_field_salutation' => 0,
'inv_field_phone' => 0,
'inv_field_custom' => 0,
);
// Ce imamo modul 360 imamo tudi odnos
if(SurveyInfo::getInstance()->checkSurveyModule('360_stopinj')){
$default_fields['inv_field_relation'] = 0;
}
# skreiramo nov vrstni red polj
if (count($fields) > 0) {
foreach ($fields as $field) {
$field_list['inv_field_'.$field] = 1;
if (isset($default_fields['inv_field_'.$field])) {
unset($default_fields['inv_field_'.$field]);
}
}
}
if (count($default_fields) > 0)
{
foreach ($default_fields as $key =>$field) {
$field_list[$key] = $field;
unset($default_fields[$key]);
}
}
$respondents = array_unique($respondents);
echo '';
echo '';
$fields_cnt = 0;
foreach ($field_list AS $field => $checked)
{
if ($checked == 1) {
$fields_cnt++;
echo ''.$lang['srv_'.$field].' ';
}
}
echo ' ';
if (is_array($respondents) && count($respondents) > 0 )
{
foreach ($respondents AS $respondent_data) {
$row_cnt = 0;
echo '';
$respondent_data_array = explode('|~|',$respondent_data);
if (count($respondent_data_array) > 0) {
foreach ($respondent_data_array AS $tekst) {
if ($row_cnt < $fields_cnt) {
echo ''.str_replace ("|~|", ",", $tekst).' ';
$row_cnt++;
}
}
}
echo ' ';
}
}
echo '
';
}
echo $infoBox;
}
function showEditRecList($profile_id = null)
{
global $lang;
$pids=array();
$onlyThisSurvey = (int)$_POST['onlyThisSurvey'];
if ($profile_id == null) {
# preberemo id-je profilov in respondente
if ($_POST['pids'] != '') {
$pids = explode(',',$_POST['pids']);
}
} else {
# preberemo id-je profilov in respondente
if ($profile_id != '') {
$pids = explode(',',$profile_id);
}
}
if (is_array($pids) && count($pids) == 0) {
echo $lang['srv_inv_list_choose_left'].' ';
}
session_start();
if (is_array($pids) && !empty($pids))
{
echo ' '.$lang['srv_inv_list_edit'].'
';
$respondents = array();
$fields = array();
$infoBox = null;
if ($onlyThisSurvey <= 1)
{
# če imamo normalne sezname
if (is_array($pids) && count($pids) == 1) {
$sql_string = "SELECT rp.respondents, fields,rp.name, rp.comment, u.email AS iemail, DATE_FORMAT(rp.insert_time,'%d.%m.%Y, %T') AS fitime, e.email AS eemail, DATE_FORMAT(rp.edit_time,'%d.%m.%Y, %T') AS fetime FROM srv_invitations_recipients_profiles AS rp LEFT JOIN users AS u ON rp.uid = u.id LEFT JOIN users AS e ON rp.uid = e.id WHERE rp.pid IN(".(implode(',',$pids)).")";
} else {
$sql_string = "SELECT rp.respondents, fields FROM srv_invitations_recipients_profiles AS rp WHERE rp.pid IN(".(implode(',',$pids)).")";
}
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query))
{
# info box prikazujemo samo ko imamo izbran 1 seznam
if (is_array($pids) && count($pids) == 1)
{
$infoBox = '';
$infoBox .= $lang['srv_inv_list_edit_added'];
$infoBox .= trim($sql_row['iemail']) != '' ? $sql_row['iemail'] : $lang['srv_inv_list_edit_1kasi'];
$infoBox .= $lang['srv_inv_list_edit_date'].$sql_row['fitime'];
if ($sql_row['fitime'] != $sql_row['fetime'])
{
$infoBox .= ' '.$lang['srv_inv_list_edit_changed'];
$infoBox .= trim($sql_row['eemail']) != '' ? $sql_row['eemail'] : $lang['srv_inv_list_edit_1kasi'];
$infoBox .= $lang['srv_inv_list_edit_date'].$sql_row['fetime'];
}
$infoBox .= ''.$lang['srv_inv_list_edit_name'].' ';
$infoBox .= ''.$lang['srv_inv_list_edit_comment'].' ';
}
#$array_profiles[$sql_row['pid']] = array('name' => $sql_row['name']);
$respondents_list = str_replace("\n\r", "\n", $sql_row['respondents']);
$respondents_list = explode("\n",$respondents_list);
$respondents = array_merge($respondents,$respondents_list);
$_fields = explode(",",$sql_row['fields']);
foreach ($_fields as $_field)
{
if (!in_array($_field,$fields))
{
$fields[] = $_field;
}
}
}
}
else
{
# imamo arhive
$fields = array();
$_recipients = array();
$sql_string = "SELECT email,firstname,lastname,salutation,phone,custom,relation FROM srv_invitations_recipients AS sir WHERE sir.id IN (SELECT siar.rec_id FROM srv_invitations_archive_recipients siar WHERE siar.arch_id IN (".(implode(',',$pids))."))";
$sql_query = sisplet_query($sql_string);
while ($row = mysqli_fetch_assoc($sql_query) ) {
$_recipients[] = $row;
foreach ($row AS $key => $value) {
if ($value !== null && !in_array($key,$fields)) {
$fields[] = $key;
}
}
}
# pripravimo respondente
foreach ($_recipients AS $_recipient) {
$recipient = '';
$prefix='';
foreach ($fields AS $field) {
$recipient.=$prefix.$_recipient[$field];
$prefix=',';
}
if ($recipient != '') {
$respondents[] = $recipient;
}
}
}
# pohandlamo polja
$field_list = array();
$default_fields = array(
'inv_field_email' => count($fields) == 0 ? 1 : 0,
'inv_field_firstname' => 0,
'inv_field_lastname' => 0,
'inv_field_password' => 0,
'inv_field_salutation' => 0,
'inv_field_phone' => 0,
'inv_field_custom' => 0,
);
// Ce imamo modul 360 imamo tudi odnos
if(SurveyInfo::getInstance()->checkSurveyModule('360_stopinj')){
$default_fields['inv_field_relation'] = 0;
}
# skreiramo nov vrstni red polj
if (count($fields) > 0) {
foreach ($fields as $field) {
$field_list['inv_field_'.$field] = 1;
if (isset($default_fields['inv_field_'.$field])) {
unset($default_fields['inv_field_'.$field]);
}
}
}
if (count($default_fields) > 0) {
foreach ($default_fields as $key =>$field) {
$field_list[$key] = $field;
unset($default_fields[$key]);
}
}
$respondents = array_unique($respondents);
echo '';
echo ' ';
echo '';
echo '';
echo '';
echo '
';
echo $infoBox;
echo ' ';
echo ' ';
if (count($pids) <= 1 ) {
echo ''.$lang['srv_inv_list_save_old'].' ';
}
echo ''.$lang['srv_inv_list_save_new'].' ';
echo ' ';
}
}
function invListEdit() {
global $lang,$site_url, $global_user_id;
# polovimo podatke profila
$sql_string = "SELECT pid, name, comment, uid FROM srv_invitations_recipients_profiles WHERE pid='".$_POST['pid']."'";
$sql_query = sisplet_query($sql_string);
list($pid, $name, $comment, $uid) = mysqli_fetch_row($sql_query);
echo ''; # id="inv_view_arch_recipients"
/* echo '';
*/
}
function listGetName() {
global $lang,$site_url, $global_user_id;
$saveNew = $_POST['saveNew'] == 'true' ? true : false;
$array_profiles = array();
#ne vem če je fino da lahko dodaja kar na vse sezname
session_start();
# polovimo še ostale porfile
$sql_string = "SELECT pid, name,comment FROM srv_invitations_recipients_profiles WHERE uid in('".$global_user_id."')";
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$array_profiles[$sql_row['pid']] = array('name' => $sql_row['name'], 'comment'=>$sql_row['comment']);
}
echo '';
if ($saveNew == true) {
echo '
';
echo ''.$lang['srv_inv_recipient_list_name'];
# zaporedno številčimo ime seznama1,2.... če slučajno ime že obstaja
$new_name = $lang['srv_inv_recipient_list_new'];
$names = array();
$s = "SELECT name FROM srv_invitations_recipients_profiles WHERE name LIKE '%".$new_name."%' AND uid='$global_user_id'";
$q = sisplet_query($s);
while ($r = mysqli_fetch_assoc($q)) {
$names[] = $r['name'];
}
if (count($names) > 0) {
$cnt = 1;
while (in_array($lang['srv_inv_recipient_list_new'].$cnt, $names)) {
$cnt++;
}
$new_name = $lang['srv_inv_recipient_list_new'].$cnt;
}
echo ' ';
echo ' ';
echo ' ';
} else {
echo '
';
echo ''.$lang['srv_inv_recipient_list_name'];
echo ' ';
echo ' ';
echo ' ';
}
echo '
';
echo $lang['srv_inv_recipient_list_comment'];
echo '';
# skrita polja za respondente in polja
$_fields = str_replace('inv_field_','',implode(',',$_POST['fields']));
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_cancel'].' ';
echo '
'.$lang['save'].' ';
echo '
';
echo '
'; # id="inv_view_arch_recipients"
echo '';
}
function invListSaveOld() {
global $lang,$site_url, $global_user_id;
$return = array('error'=>'0');
$recipients_list = trim($this->getCleanString($_POST['recipients_list']));
$field_list = (is_array($_POST['field_list']) && count($_POST['field_list']) > 0) ? implode(',',$_POST['field_list']) : trim($_POST['field_list']);
$field_list = str_replace('inv_field_','',$field_list);
$profile_id = explode(',',$_POST['profile_id']);
$profile_id = $profile_id[0];
$rec_profile_name = $_POST['rec_profile_name'];
$rec_profile_comment = $_POST['rec_profile_comment'];
# dodajamo v obstoječ profil
$sql_string_update = "UPDATE srv_invitations_recipients_profiles SET name='$rec_profile_name', comment='$rec_profile_comment', respondents = '$recipients_list', fields='$field_list' WHERE uid in('$global_user_id') AND pid = '$profile_id'";
$sqlQuery = sisplet_query($sql_string_update);
sisplet_query("COMMIT");
$this->removeDuplicates($profile_id);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error, 'pid'=>$profile_id());
} else {
$return = array('error'=>'0', 'msg'=>'x2', 'pid'=>$profile_id);
}
#echo json_encode($return);
$this->showInvitationLists($profile_id);
}
function listSave() {
global $lang,$site_url, $global_user_id;
$return = array('error'=>'0');
$profile_name = (isset($_POST['profile_name']) && trim($_POST['profile_name']) != '') ? trim($_POST['profile_name']) : $lang['srv_invitation_new_templist'];
$profile_comment = (isset($_POST['profile_comment']) && trim($_POST['profile_comment']) != '') ? trim($_POST['profile_comment']) : '';
$recipients_list = trim($this->getCleanString($_POST['recipients_list']));
$field_list = (isset($_POST['field_list']) && trim($_POST['field_list']) != '') ? trim($_POST['field_list']) : 'email';
$profile_id = explode(',',$_POST['profile_id']);
$profile_id = $profile_id[0];
$saveNew = $_POST['saveNew'] == 'true' ? true : false;
if ($saveNew == true) {
# shranjujemo v nov profil
$sql_insert = "INSERT INTO srv_invitations_recipients_profiles (name,uid,fields,respondents,insert_time,comment, from_survey) VALUES ('$profile_name', '$global_user_id', '$field_list', '$recipients_list', NOW(), '$profile_comment', '".$this->sid."' )";
$sqlQuery = sisplet_query($sql_insert);
$new_pid = mysqli_insert_id($GLOBALS['connect_db']);
sisplet_query("COMMIT");
#odstranimo podvojene
$this->removeDuplicates($new_pid);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error, 'pid'=>$new_pid);
} else {
$return = array('error'=>'0', 'msg'=>'x1', 'pid'=>$new_pid);
}
sisplet_query("COMMIT");
} else {
# dodajamo v obstoječ profil
$sql_string_update = "UPDATE srv_invitations_recipients_profiles SET name='$profile_name', respondents = '$recipients_list', comment='$profile_comment' WHERE uid in('$global_user_id') AND pid = '$profile_id'";
$sqlQuery = sisplet_query($sql_string_update);
sisplet_query("COMMIT");
#odstranimo podvojene
$this->removeDuplicates($profile_id);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$return = array('error'=>'1', 'msg'=>$error, 'pid'=>$profile_id());
} else {
$return = array('error'=>'0', 'msg'=>'x2', 'pid'=>$profile_id);
}
}
#echo json_encode($return);
$this->showInvitationLists();
}
function invListEditSave() {
global $lang,$site_url, $global_user_id;
/*
* rec_profile_name] => Seznam1 [rec_profile_comment] => Komentar [uid] => Array ( [0] => 1045 [1] => 1049 [2] => 1046 ) [profile_id] => 2 [anketa] => 94 )
*/
$return = array('error'=>'0');
$profile_name = (isset($_POST['rec_profile_name']) && trim($_POST['rec_profile_name']) != '') ? trim($_POST['rec_profile_name']) : $lang['srv_invitation_new_templist'];
$profile_comment = (isset($_POST['rec_profile_comment']) && trim($_POST['rec_profile_comment']) != '') ? trim($_POST['rec_profile_comment']) : '';
$uids = $_POST['uid'];
$pid = (int)$_POST['profile_id'];
# pripravimo insert query (id avtorja ne dodajamo v dostope, ker je tako v uid profila)
$insert_string = array();
if (count($uids) > 0) {
foreach ($uids AS $key => $uid) {
$insert_string[] = "('".$pid."','".$uid."')";
}
}
# pobrišemo stare vrednosti dostopov in jih nastavimo na novo
$delStr = "DELETE FROM srv_invitations_recipients_profiles_access WHERE pid = '$pid'";
$delQuery = sisplet_query($delStr);
if (count($insert_string)) {
# dodamo nove vrednosti dostopov
$insStr = "INSERT INTO srv_invitations_recipients_profiles_access VALUES ".implode(',',$insert_string);
$insQuery = sisplet_query($insStr);
}
sisplet_query("COMMIT");
# dodajamo v obstoječ profil
# $sql_string_update = "UPDATE srv_invitations_recipients_profiles SET name='$profile_name', comment='$profile_comment' WHERE pid = '$pid'";
# $sqlQuery = sisplet_query($sql_string_update);
# sisplet_query("COMMIT");
// if (!$sqlQuery) {
# $error = mysqli_error($GLOBALS['connect_db']);
# $return = array('error'=>'1', 'msg'=>$error, 'pid'=>$pid);
# } else {
# $return = array('error'=>'0', 'msg'=>'x2', 'pid'=>$pid);
# }
#echo json_encode($return);
$this->showInvitationLists();
}
function deleteRecipientsList() {
global $global_user_id;
$id = (int)$_POST['id'];
if ($id > 0 ) {
$sql_string = "DELETE FROM srv_invitations_recipients_profiles WHERE pid='".$id."' AND uid='".$global_user_id."'";
$sqlQuery = sisplet_query($sql_string);
sisplet_query("COMMIT");
}
$this->showInvitationLists();
}
function deleteRecipientsListMulti() {
$return = array('success'=>'0');
global $global_user_id;
$ids = $_POST['ids'];
if(count($ids) > 0){
$sql_string = "DELETE FROM srv_invitations_recipients_profiles WHERE uid='".$global_user_id."' AND pid IN(".implode(',',$ids).")";
$sqlQuery = sisplet_query($sql_string);
$sqlQuery = sisplet_query("COMMIT");
}
if (!$sqlQuery) {
$errors[] = $lang['srv_inv_recipient_delete_error'];
} else {
$return['success'] = 2;
//$this->showInvitationLists();
}
}
function removeDuplicates($pid) {
# dodamo tracking
if ((int)$pid > 0) {
$sql_string = "SELECT respondents FROM srv_invitations_recipients_profiles WHERE pid = '$pid'";
$sql_query = sisplet_query($sql_string);
$respondents = array();
list ($new_recipients) = mysqli_fetch_row($sql_query);
$new_recipients = str_replace("\n\r", "\n", $new_recipients);
$new_recipients = explode("\n",$new_recipients);
$new_recipients = implode("\n",array_unique($new_recipients));
$sql_string_update = "UPDATE srv_invitations_recipients_profiles SET respondents='".$new_recipients."' WHERE pid = '$pid'";
$sqlQuery = sisplet_query($sql_string_update);
sisplet_query("COMMIT");
}
}
function displayListAccess($pid) {
global $lang, $global_user_id, $admin_type;
# polovimo avtorja profila
$uidQuery = sisplet_query("SELECT uid FROM srv_invitations_recipients_profiles WHERE pid ='$pid'");
list($uid) = mysqli_fetch_row($uidQuery);
# polovimo id-je userjev ki imajo dostop do tega profila
$accessArray = array();
$accessQuery = sisplet_query("SELECT uid FROM srv_invitations_recipients_profiles_access WHERE pid ='$pid'");
while (list($uid_) = mysqli_fetch_row($accessQuery)) {
$accessArray[] = $uid_;
}
$sqlQuery = null;
// tip admina: 0=>admin, 1=>manager, 2=>clan, 3=>user
switch ( $admin_type ) {
case 0: // admin vidi vse
$sqlQuery = sisplet_query("SELECT name, surname, id, email FROM users ORDER BY name ASC");
break;
case 1: // manager vidi ljudi pod sabo
// polovimo vse clane ki spo pod managerjem
$sqlQuery = sisplet_query("SELECT DISTINCT name, surname, id, email FROM users WHERE id IN (SELECT DISTINCT user FROM srv_dostop_manage WHERE manager='$global_user_id') OR id = '$global_user_id'");
break;
case 2:
case 3:
// TODO
// clani in userji lahko vidijo samo tiste ki so jim poslali maile in so se registrirali
$sqlQuery = sisplet_query("SELECT name FROM users WHERE 1 = 0");
break;
}
echo ''.$lang['srv_inv_list_access'].' ';
echo ''.$lang['srv_inv_list_access_legend'].' ';
echo ''.$lang['srv_dostop_show_all'].' ';
echo ''.$lang['srv_dostop_hide_all'].' ';
echo '';
while ($row1 = mysqli_fetch_assoc($sqlQuery)) {
$checked = ( in_array($row1[id],$accessArray) ||$uid == $row1['id']) ? ' checked="checked"' : '';
$_css_hidden = ($checked != '' ? '' : ' displayNone');
echo '
';
echo '';
echo ' ';
echo $row1['name'] . ($uid == $row1['id'] ? ' (' . $lang['author'] . ')' : '') . ' ';
echo '
';
}
echo '
';
}
function changeInvRecListEdit() {
session_start();
$_SESSION['inv_edit_rec_profile'][$this->sid] = ($_POST['checked'] == 'true' ? true : false);
session_commit();
}
function getUrlLists() {
global $lang,$site_url;
$result = array();
$p = new Prevajanje($this->sid);
$lang_array = $p->get_all_translation_langs();
$link = SurveyInfo::getSurveyLink();
$sqll = sisplet_query("SELECT link FROM srv_nice_links WHERE ank_id = '$this->sid' ORDER BY id ASC");
$default_checked =false;
$cnt=0;
#lepi linki
while ($rowl = mysqli_fetch_assoc($sqll)) {
$result[$cnt] = array('url'=>$site_url.$rowl['link'], 'name'=>$site_url.$rowl['link'].(count($lang_array) > 0 ? ' - '.$lang['language'].' ' : ''));
if ($default_checked == false) {
$result[$cnt]['dc'] = true;
$default_checked = true;
}
$cnt++;
if (count($lang_array) > 0) {
#jezikovni podlinki
foreach ($lang_array AS $lang_id => $lang_name) {
$result[$cnt] = array('url'=>$site_url.$rowl['link'].'?language='.$lang_id, 'name'=>$site_url.$rowl['link'].'?language='.$lang_id.' - '.$lang_name);
$cnt++;
}
}
}
$link1 = $site_url.'a/'.SurveyInfo::getInstance()->getSurveyHash();
# normalen link
$result[$cnt] = array('url'=>$link1, 'name'=>$link1.(count($lang_array) > 0 ? ' - '.$lang['language'] : ''));
if ($default_checked == false) {
$result[$cnt]['dc'] = true;
$default_checked = true;
}
$cnt++;
#jezikovni link
if (count($lang_array) > 0) {
foreach ($lang_array AS $lang_id => $lang_name) {
$result[$cnt] = array('url'=>$link1.'?language='.$lang_id, 'name'=>$link1.'?language='.$lang_id.' - '.$lang_name);
if ($default_checked == false) {
$result[$cnt]['dc'] = true;
$default_checked = true;
}
$cnt++;
}
}
return $result;
}
function upload_list() {
global $lang, $site_path, $site_url;
$fields = array();
$field_list = array();
# odvisno od tipa sporočil prikažemo različna polja
# Personalizirano e-poštno vabilo
$default_fields = array(
'inv_field_email' => 1,
'inv_field_firstname' => 0,
'inv_field_lastname' => 0,
'inv_field_password' => 0,
'inv_field_salutation' => 0,
'inv_field_phone' => 0,
'inv_field_custom' => 0,
);
// Ce imamo modul 360 imamo tudi odnos
if(SurveyInfo::getInstance()->checkSurveyModule('360_stopinj')){
$default_fields['inv_field_relation'] = 0;
}
# pri personaliziranih aporočilih je e-mail obvezno polje
array_push($fields, 'inv_field_email');
# skreiramo nov vrstni red polj
if (count($fields) > 0) {
foreach ($fields as $key=>$field) {
$field_list[$field] = 1;
if (isset($default_fields[$field])) {
unset($default_fields[$field]);
}
}
}
if (count($default_fields) > 0) {
foreach ($default_fields as $key =>$field) {
$field_list[$key] = $field;
unset($default_fields[$key]);
}
}
echo '';
echo '
'.$lang['srv_inv_list_upload_header'].' ';
echo '
'.$lang['srv_inv_recipiens_field_note'].': ';
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo $lang['srv_inv_recipiens_sample'].' ';
echo $lang['srv_inv_recipiens_sample1'];
echo ' ';
echo '
';
echo '
';
echo '
';
}
function send_upload_list() {
global $lang, $global_user_id;
$errors = array();
$allowedExtensions = array("txt","csv","dat");
$_fields = trim($_POST['fields']);
if ($_fields != null && $_fields != '') {
$fields = explode(',',$_fields);
} else {
$fields = array();
}
$file_name = $_FILES["invListFile"]["name"];
$file_type = $_FILES["invListFile"]["type"];
$file_size = $_FILES["invListFile"]["size"] > 0 ? $_FILES["invListFile"]["size"] / 1024 : 0;
$file_tmp = $_FILES["invListFile"]["tmp_name"];
$okFileType = ( $file_type == 'text/plain' || $file_type == 'text/csv' || $file_type == 'application/vnd.ms-excel' );
$okFileEnd = ( pathinfo($file_name, PATHINFO_EXTENSION) != 'txt'
|| pathinfo($file_name, PATHINFO_EXTENSION) != 'csv'
|| pathinfo($file_name, PATHINFO_EXTENSION) != 'dat');
# preverimo ali smo uploadali datoteko in če smo izbrali katero polje
if ($_POST['posted'] == '1' && count($fields) == 0) {
$errors[] = $lang['srv_inv_recipiens_upload_error_no_fields'];
}
#preverimo ime datoteke
if ( trim($file_name) == '' || $file_name == null ) {
$errors[] = $lang['srv_respondents_invalid_file'];
# preverimo tip:
} else if ( $okFileType == false ) {
$errors[] = $lang['srv_respondents_invalid_file_type'];
# prevermio še končnico (.txt)
} else if ($okFileEnd == false) {
$errors[] = $lang['srv_respondents_invalid_file_type'];
}
# preverimo velikost
else if ( (float)$file_size == 0 ) {
$errors[] = $lang['srv_respondents_invalid_file_size'];
}
# če so napake jih prikažemo če ne obdelamo datoteko
if (count($errors) > 0) {
echo ' ';
echo ''.$lang['srv_inv_recipiens_upload_error'].' ';
echo ' ';
echo ' ';
echo '';
foreach($errors as $error) {
echo '* '.$error.' ';
}
echo ' ';
#$this->addRecipientsView($fields, $invalid_recipiens_array);
} else {
$fh = @fopen($file_tmp, "rb");
if ($fh) {
$_recipients = fread($fh, filesize($file_tmp));
fclose($fh);
}
$_recipients = str_replace("\n\r", "\n", $_recipients);
$recipients_list = explode("\n",$_recipients);
$num_recipients_list = count($recipients_list);
# pri prejemnikih odrežemo "polja", katerih nismo navedli
$fields_cont = (int)count($fields);
$fields = str_replace('inv_field_','',$fields);
$clean_recipients = array();
if (count($recipients_list) > 0) {
if (isset ($_POST['recipientsDelimiter'])) {
$delimiter = $_POST['recipientsDelimiter'];
}
else {
$delimiter = "|~|";
}
foreach ($recipients_list AS $recipient) {
#poiščemo n-ti delimiter
$clean_recipients[] = trim(substr($recipient, 0, $this->strpos_offset($delimiter, $recipient, $fields_cont)));
}
}
$clean_fields = trim(implode(',', $fields));
$clean_recipients = trim(implode("\n", $clean_recipients));
if ($fields!=null && $fields != '' && $clean_recipients != null && $clean_recipients != '') {
$sql_insert = "INSERT INTO srv_invitations_recipients_profiles".
" (name,uid,fields,respondents,insert_time,comment, from_survey) ".
" VALUES ('Uploaded list', '$global_user_id', '$clean_fields', '$clean_recipients', NOW(), 'Uploaded list', '".$this->sid."' )";
$sqlQuery = sisplet_query($sql_insert);
}
}
$this->showInvitationLists();
}
/*
function strpos_index($haystack = '',$needle = '',$offset = 0,$limit = 99,$return = null)
{
$length = strlen($needle);
$occurances = array();
while((($count = count($occurances)) < $limit) && (false !== ($offset = strpos($haystack,$needle,$offset))))
{
$occurances[$count]['length'] = $length;
$occurances[$count]['start'] = $offset;
$occurances[$count]['end'] = $offset = $offset + $length;
}
return $return === null ? $occurances : $occurances[$return];
}
*/
/**
* Find position of Nth $occurrence of $needle in $haystack
* Starts from the beginning of the string
**/
function strpos_offset($needle, $haystack, $occurrence) {
// explode the haystack
$arr = explode($needle, $haystack);
// check the needle is not out of bounds
switch( $occurrence ) {
case $occurrence == 0:
return false;
case $occurrence > max(array_keys($arr)):
return strlen($haystack);
default:
$index = (int)strlen(implode($needle, array_slice($arr, 0, $occurrence)));
return $index;
}
}
function changePaginationLimit() {
session_start();
if (isset($_POST['limit']) && (int)$_POST['limit'] > 0) {
$_SESSION['rec_on_send_page'] = (int)$_POST['limit'];
$this->rec_send_page_limit = (int)$_POST['limit'];
}
session_commit();
$this->displaySendPagination((int)$_POST['cnt']);
}
function displayMessagePreview() {
global $lang;
$sql_string_m = "SELECT id, naslov, subject_text, body_text, reply_to, isdefault, comment, url FROM srv_invitations_messages WHERE ank_id = '$this->sid' AND isdefault='1'";
$sql_query_m = sisplet_query($sql_string_m);
$preview_message = mysqli_fetch_assoc($sql_query_m);
# polovimo imena vseh sporocil
$sql_string_m = "SELECT id, naslov FROM srv_invitations_messages WHERE ank_id = '$this->sid'";
echo '';
echo ''.$lang['srv_inv_message_draft_content_name'].': ';
echo '';
echo '';
$sql_query_m = sisplet_query($sql_string_m);
if (mysqli_num_rows($sql_query_m) > 0 ) {
echo '';
while ($row = mysqli_fetch_assoc($sql_query_m)) {
echo ''.$row['naslov'].' ';
}
echo ' ';
}
#.$preview_message['naslov'];
echo ' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_content_subject'].': ';
echo '';
echo ''.$preview_message['subject_text'].' ';
echo ' ';
echo ''.$lang['srv_inv_message_draft_content_body'].': ';
echo '';
echo ''.($preview_message['body_text']).' ';
echo ' ';
echo '
';
// Opozorilo ce manjka #URL# v besedilu maila in imamo individualizirano vabilo
if(strpos($preview_message['body_text'], '#URL#') == false && $this->surveySettings['usercode_required'] == 0 && $this->surveySettings['individual_invitation'] != 0)
echo ''.$lang['srv_inv_message_draft_nourl_warning'].' ';
// Opozorilo ce je #URL# v besedilu maila in imamo neindividualizirano vabilo
elseif(strpos($preview_message['body_text'], '#URL#') == true && $this->surveySettings['individual_invitation'] == 0)
echo ''.$lang['srv_inv_message_draft_url_warning'].' ';
// Popravi sporocilo
echo ''.$lang['srv_invitation_reedit_message'].' ';
}
function addSortField($field){
$type = 'ASC';
session_start();
if ($_SESSION['rec_sort_field'] == $field) {
if ($_SESSION['rec_sort_type'] == 'DESC') {
$type = 'ASC';
} else {
$type = 'DESC';
}
} else {
$type = 'ASC';
}
return ' onclick="inv_set_sort_field(\''.$field.'\',\''.$type.'\');" ';
}
function addSortIcon($field){
session_start();
if ($_SESSION['rec_sort_field'] == $field) {
if ($_SESSION['rec_sort_type'] == 'DESC') {
return ' ';
} else {
return ' ';
}
}
return;
}
function setSortField() {
session_start();
if (isset($_POST['field']) && trim($_POST['field']) != '') {
$_SESSION['rec_sort_field'] = trim($_POST['field']);
} else {
$_SESSION['rec_sort_field'] = 'date_inserted';
}
if (isset($_POST['type']) && trim($_POST['type']) != '') {
$_SESSION['rec_sort_type'] = trim($_POST['type']);
} else {
$_SESSION['rec_sort_type'] = 'ASC';
}
session_commit();
}
function getSortString() {
session_start();
$sort_string = ' ORDER BY i.last_status';
if (isset($_SESSION['rec_sort_field']) && trim($_SESSION['rec_sort_field']) != '') {
$prefix = 'i.';
if ($_SESSION['rec_sort_field'] == 'count_inv') {
$prefix = '';
}
if ($_SESSION['rec_sort_field'] == 'date(date_expired)') {
$sort_string = ' ORDER BY '.$prefix.'date_expired';
}
else{
$sort_string = ' ORDER BY '.$prefix.trim($_SESSION['rec_sort_field']);
}
if ($_SESSION['rec_sort_type'] == 'DESC') {
$sort_string .= ' DESC';
} else {
$sort_string .= ' ASC';
}
}
// Vedno dodatno se sortirtamo po mailu
$sort_string .= ', i.email';
return $sort_string;
}
function getAvailableSysVars() {
$result = array();
$qry = sisplet_query("SELECT s.variable, s.naslov FROM srv_spremenljivka s, srv_grupa g WHERE g.ank_id='".$this->sid."' AND s.gru_id=g.id AND s.tip!='5' AND (s.tip < '10' OR s.tip = '22' OR s.tip = '25' OR s.tip='21') AND s.sistem='1'");
while ($row = mysqli_fetch_assoc($qry)) {
$result[$row['variable']] = $row['naslov'];
}
return $result;
}
function getAvailableIndicators() {
$result = array();
$_indicators = array('email','password','firstname','lastname','salutation','phone','custom','relation');
#za vsako spremenljivko preverimo zapise v bazi
foreach ($_indicators AS $indicator) {
$sql_string = "SELECT count(*) FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted = '0' AND $indicator IS NOT NULL";
list($cnt) = mysqli_fetch_row(sisplet_query($sql_string));
if ((int)$cnt > 0) {
$result[] = $indicator;
}
}
return $result;
}
function createSystemVariablesMapping() {
global $lang;
# polovimo sistemske variable
$sys_db_maps = array('email');
$strSelect = "SELECT spr_id, field FROM srv_invitations_mapping WHERE sid = '".$this->sid."'";
$qrySelect = sisplet_query($strSelect);
$mappingArray = array();
while (list($spr_id,$field) = mysqli_fetch_row($qrySelect)) {
$mappingArray[$spr_id] = $field;
}
$qryString = "SELECT s.id, s.naslov, s.variable, s.variable_custom, s.coding FROM srv_spremenljivka s, srv_grupa g WHERE s.sistem='1' AND s.tip IN (1,3,17,21) AND s.gru_id=g.id AND g.ank_id='".$this->sid."' ORDER BY g.vrstni_red, s.vrstni_red";
$sqlSpremenlivka = sisplet_query($qryString);
if (mysqli_num_rows($sqlSpremenlivka) > 0) {
echo '';
echo ' ';
echo '';
} else {
echo ''.$lang['srv_invitation_system_error3'].' ';
}
}
function validateSysVarsMapping() {
global $lang,$global_user_id;
# preverimo sistemske spremenljivke
$strSistemske = "SELECT count(*) FROM srv_spremenljivka s, srv_grupa g WHERE s.sistem='1' AND s.gru_id=g.id AND g.ank_id='".$this->sid."' AND variable IN("."'" . implode("','",$this->inv_variables)."') ORDER BY g.vrstni_red, s.vrstni_red";
list($cntSistemske) = mysqli_fetch_row(sisplet_query($strSistemske));
$emailsToAdd = array();
$invalidEmails = array();
$errors = array();
$emailSpr = (int)$_POST['sysVarMap'];
if ((int)$emailSpr > 0) {
# preverimo ali lovimo samo ustrezne ali vse userje , preverimo kako imamo nastavljeno pri podatkih
global $global_user_id;
$_POST['meta_akcija'] = 'data';
SurveyStatusProfiles :: Init($this->sid, $global_user_id);
$currentProfileId = SurveyStatusProfiles :: getCurentProfileId();
$statusProfileCondition = SurveyStatusProfiles :: getStatusAsQueryString($currentProfileId);
#zloopamo skozi userje in dodamo kateri še niso bili dodani
$selectUser = "SELECT id,cookie,pass,last_status,lurker,unsubscribed FROM srv_user where ank_id='".$this->sid."' AND inv_res_id IS NULL AND deleted='0' ".$statusProfileCondition;
$queryUser = sisplet_query($selectUser );
if (mysqli_num_rows($queryUser) ) {
#zakeširamo vrednosti za email
$this->getUsersDataForSpr($emailSpr);
while ($row = mysqli_fetch_assoc($queryUser)) {
$email = trim($this->cacheArrayVrednost[$emailSpr][$row['id']]);
if ($this->validEmail($email)) {
$emailsToAdd[] = $email;
} else {
$invalidEmails[] = $email;
}
}
if (count($invalidEmails) > 0) {
$errors[] = $lang['srv_invitation_system_error1']."(".count($invalidEmails).')';
}
} else {
$errors[] = $lang['srv_invitation_system_error2'];
}
} else {
if ((int)$cntSistemske == 0) {
# ni sistemskih spremenljivk
$errors[] = $lang['srv_invitation_system_error3'];
} else {
# ni določena email spremenljivka
$errors[] = $lang['srv_invitation_system_error4'];
}
}
echo ''.$lang['srv_invitation_system_validate'].' ';
if (count($emailsToAdd)) {
echo ''.$lang['srv_invitation_system_validateAndAdd'].' ';
}
if (mysqli_num_rows($queryUser) > 0)
{ # če je kaj novih zapisov v bazi
# če že imamo prejemnike v bazi ponudimo gumb naprej
echo ''.$lang['srv_invitation_forward'].' ';
echo ' ';
echo ' ';
echo '';
printf($lang['srv_invitation_system_found'],mysqli_num_rows($queryUser));
echo ' ';
echo ' ';
echo $lang['srv_invitation_system_from_this'];
if (count($emailsToAdd)) {
echo $lang['srv_invitation_system_from_this_valid'].(int)count($emailsToAdd);
if (count($invalidEmails) > 0) {
echo ' ';
echo $lang['srv_invitation_system_and'];
}
}
if (count($invalidEmails) > 0) {
echo $lang['srv_invitation_system_from_this_invalid'].(int)count($invalidEmails);
}
}
else
{
echo ' ';
echo ' ';
echo $lang['srv_invitation_system_not_found'];
}
}
function addSysVarsMapping() {
global $lang,$global_user_id;
$addedEmails = array();
$errorEmails = array();
$invalidEmails = array();
$errors = array();
#pobrišemo obstoječe povezave
$strDelete = "DELETE FROM srv_invitations_mapping WHERE sid = '".$this->sid."'";
$qryDelete = sisplet_query($strDelete);
$emailSpr = (int)$_POST['sysVarMap'];
if ((int)$emailSpr > 0) {
$insertString = "INSERT INTO srv_invitations_mapping (sid, spr_id, field) VALUES ('$this->sid','$emailSpr','email')";
sisplet_query($insertString);
sisplet_query("COMMIT");
# preverimo ali lovimo samo ustrezne ali vse userje , preverimo kako imamo nastavljeno pri podatkih
global $global_user_id;
$_POST['meta_akcija'] = 'data';
SurveyStatusProfiles :: Init($this->sid, $global_user_id);
$currentProfileId = SurveyStatusProfiles :: getCurentProfileId();
$statusProfileCondition = SurveyStatusProfiles :: getStatusAsQueryString($currentProfileId);
#zloopamo skozi userje in dodamo kateri še niso bili dodani
$selectUser = "SELECT id,cookie,pass,last_status,lurker,unsubscribed FROM srv_user where ank_id='".$this->sid."' AND inv_res_id IS NULL AND deleted='0' ".$statusProfileCondition;
$queryUser = sisplet_query($selectUser );
if (mysqli_num_rows($queryUser)) {
#zakeširamo vrednosti za email
$this->getUsersDataForSpr($emailSpr);
while ($row = mysqli_fetch_assoc($queryUser)) {
$email = trim($this->cacheArrayVrednost[$emailSpr][$row['id']]);
if ($this->validEmail($email)) {
$pass = (trim($row['pass']) != '') ? trim($row['pass']) : substr($row['cookie'],0,6);
#dodamo respondenra in naredimo povezav
$sql_insert = "INSERT IGNORE INTO srv_invitations_recipients (ank_id,email,password,cookie,sent,responded,unsubscribed,deleted,date_inserted,inserted_uid,list_id,last_status) VALUES ";
$sql_insert .= "('".$this->sid."','$email','$pass','".$row['cookie']."'";
$sql_insert .= ",'0','0','".(int)$row['unsubscribed']."','0',NOW(),'".$global_user_id."','".$list_id."','".$row['last_status']."')";
$sqlQuery = sisplet_query($sql_insert);
if (!$sqlQuery) {
$error = mysqli_error($GLOBALS['connect_db']);
$errorEmails[] = $email;
} else {
$rid = mysqli_insert_id($GLOBALS['connect_db']);
if ((int)$rid > 0) {
# updejtamo srv user
$sqlString2 = "UPDATE srv_user SET inv_res_id='$rid' WHERE id='".$row['id']."'";
$updateQuery2 = sisplet_query($sqlString2);
$addedEmails[] = $email;
} else {
$errorEmails[] = $email;
}
}
sisplet_query("COMMIT");
} else {
if ($email != '') {
$invalidEmails[] = $email;
} else {
$invalidEmails[] = $lang['srv_invitation_system_empty_email'];
}
}
}
} else {
#V bazi ni respondentov, katere lahko dodam v vabila!
$errors[] = $lang['srv_invitation_system_error2'];
}
} else {
# ni določena email spremenljivka
$errors[] = $lang['srv_invitation_system_error4'];
}
echo ''.$lang['srv_invitation_system_validate'].' ';
echo ' ';
echo ' ';
if (count($errors) > 0) {
foreach ($errors AS $error) {
echo ''.$error.' ';
}
}
if (count($addedEmails) > 0) {
echo ''.$lang['srv_invitation_system_added_users_finish']."(".(int)count($addedEmails)."): ";
foreach ($addedEmails AS $email) {
echo ''.$email.' ';
}
}
if (count($errorEmails) > 0) {
echo $lang['srv_invitation_system_error6']." (".(int)count($errorEmails)."): ";
foreach ($errorEmails AS $email) {
echo ''.$email.' ';
}
}
if (count($invalidEmails) > 0) {
echo ''.$lang['srv_invitation_system_error6'].'('.(int)count($invalidEmails).'): ';
foreach ($invalidEmails AS $email) {
echo ''.$email.' ';
}
}
}
private $cacheArrayVrednost = array();
function getUsersDataForSpr($spr_id = 0) {
if ((int)$spr_id > 0 ) {
if (!isset($this->cacheArrayVrednost[$spr_id])) {
list($tip) = mysqli_fetch_row(sisplet_query("SELECT tip FROM srv_spremenljivka WHERE id = '$spr_id'"));
switch ($tip) {
case 21:
$str = "SELECT u.id, sdt.text FROM srv_data_text".$this->db_table." AS sdt LEFT JOIN srv_user AS u ON u.id=sdt.usr_id WHERE sdt.spr_id ='$spr_id' AND ank_id='".$this->sid."' AND inv_res_id IS NULL AND deleted='0'";
$sql = sisplet_query($str);
while (list($uid,$txt) = mysqli_fetch_row($sql)) {
if ((int)$uid > 0 && trim($txt) != '') {
$this->cacheArrayVrednost[$spr_id][$uid] = $txt;
}
}
break;
return $this->cacheArrayVrednost[$spr_id];
}
} else {
return $this->cacheArrayVrednost[$spr_id];
}
}
}
function saveRecipientListName() {
global $lang,$site_url, $global_user_id;
$array_profiles = array();
#ne vem če je fino da lahko dodaja kar na vse sezname
session_start();
$_only_this_survey = (isset($_SESSION['inv_rec_only_this_survey']) && (int)$_SESSION['inv_rec_only_this_survey'] == 1) ? '' : " AND from_survey = '".$this->sid. "'" ;
# polovimo še ostale porfile
$sql_string = "SELECT pid, name,comment FROM srv_invitations_recipients_profiles WHERE uid in('".$global_user_id."')".$_only_this_survey;
$sql_query = sisplet_query($sql_string);
while ($sql_row = mysqli_fetch_assoc($sql_query)) {
$array_profiles[$sql_row['pid']] = array('name' => $sql_row['name'], 'comment'=>$sql_row['comment']);
}
echo '';
# echo '
';
# echo $lang[''].'Izberite seznam kamor želite dodati prejemnike. Izbirate lahko med:\'Nov seznam\' - prejemniki se dodajo v nov seznam, kateremu določite ime \'Začasen seznam\' - seznam obstaja samo v času seje brskalnika ali izberete obstoječ seznam, h kateremu se bodo dodali prejemniki ';
# echo ' ';
echo $lang['srv_invitation_recipients_list_add'].': ';
echo '
';
echo ' 0 ? '' : ' selected="selected"' ).'>'.$lang['srv_invitation_new_list'].' ';
echo ''.$lang['srv_invitation_new_templist'].' ';
if (count($array_profiles) > 0){
foreach($array_profiles AS $key => $profile) {
echo ''.$profile['name'].' ';
}
}
echo ' ';
echo '
';
echo ' ';
echo ' ';
echo $lang[''].'Uporabniki bodo dodani v seznam: ';
echo $array_profiles[$_POST['pid']]['name'];
echo ' ';
echo ' ';
echo '
0 ? ' class="displayNone"' : '' ).'>';
echo ' ';
echo ' ';
echo ''.$lang['srv_inv_recipient_list_name'];
# zaporedno številčimo ime seznama1,2.... če slučajno ime že obstaja
$new_name = $lang['srv_inv_recipient_list_new'];
$names = array();
$s = "SELECT name FROM srv_invitations_recipients_profiles WHERE name LIKE '%".$new_name."%' AND uid='$global_user_id'";
$q = sisplet_query($s);
while ($r = mysqli_fetch_assoc($q)) {
$names[] = $r['name'];
}
if (count($names) > 0) {
$cnt = 1;
while (in_array($lang['srv_inv_recipient_list_new'].$cnt, $names)) {
$cnt++;
}
$new_name = $lang['srv_inv_recipient_list_new'].$cnt;
}
echo ' ';
echo ' ';
echo ' ';
echo '
';
echo $lang['srv_inv_recipient_list_comment'];
echo '';
echo '
';
}
function getCleanString($string) {
return preg_replace ("/'/", "`", $string);
}
function recipientsAddForward() {
$doSave = $_POST['doSave'] == 'true' ? true : false;
$doAdd = $_POST['doAdd'] == 'true' ? true : false;
$fields = $_POST['fields'];
$recipients_list = $this->getCleanString($_POST['recipients_list']);
$delimiter = $_POST['recipientsDelimiter'];
$profileName = $_POST['profile_name'];
$profileComment = $_POST['profile_comment'];
$pid = $_POST['profile_id'];
// Bom kar tule rešil konverzijo iz delimiterja v |~|
$recipients_list = str_replace ($delimiter, "|~|", $recipients_list);
# če shranjujemo respondente
if ($doSave == true){
$pid = $this->saveAppendRecipientList($pid, $fields, $recipients_list, $profileName, $profileComment);
}
# če dodajamo respondente v bazo
if ($doAdd == true){
#dodamo polja
$result = $this->addMassRecipients($recipients_list, $fields, $pid);
# prikažemo napake
$invalid_recipiens_array = $this->displayRecipentsErrors($result);
}
# če smo dodajali repsondente v bazo, prikažemo tabelo respondentov
if ($doAdd == true){
$this->viewRecipients();
}
# če ne prikažemo profile respondentov
else {
$this->useRecipientsList($pid);
}
// Ce smo dodajali respondente rocno v bazo, to shranimo, ker potem ne smemo povezati mailov s podatki
// TEGA NE SMEMO NAREDITI, KER DRUGACE SE VSAKIC OB DODAJANJU NA NOVO UGASNE
/*if ($doAdd == true) {
$update = sisplet_query("UPDATE srv_anketa SET show_email='0' WHERE id='".$this->sid."'");
}*/
}
function saveAppendRecipientList($pid, $fields, $recipients, $profileName, $profileComment) {
global $lang,$site_url, $global_user_id;
# shranjujemo v nov profil
$post_fields = str_replace('inv_field_','',implode(',',$fields));
$post_recipients = $this->getCleanString($recipients);
$pid = (int)$pid;
# če je pid < 0 shranimo v nov porfil
if ($pid <= 0)
{
# ali shranjujemo v sejo
if ($pid == -1)
{
$this->saveSessionRecipients($post_recipients,$post_fields,$profileComment);
}
else
{
# dodelimo ime
if ($profileName == NULL || trim($profileName) == '')
{
#zaporedno številčimo ime seznama1,2.... če slučajno ime že obstaja
$profileName = $lang['srv_inv_recipient_list_new'];
$names = array();
$s = "SELECT name FROM srv_invitations_recipients_profiles WHERE name LIKE '%".$new_name."%' AND uid='$global_user_id'";
$q = sisplet_query($s);
while ($r = mysqli_fetch_assoc($q))
{
$names[] = $r['name'];
}
if (count($names) > 0)
{
$cnt = 1;
while (in_array($lang['srv_inv_recipient_list_new'].$cnt, $names))
{
$cnt++;
}
$profileName = $lang['srv_inv_recipient_list_new'].$cnt;
}
}
$sql_insert = "INSERT INTO srv_invitations_recipients_profiles".
" (name,uid,fields,respondents,insert_time,comment, from_survey) ".
" VALUES ('$profileName', '$global_user_id', '$post_fields', '$post_recipients', NOW(), '$profileComment', '".$this->sid."' )";
$sqlQuery = sisplet_query($sql_insert);
if (!$sqlQuery)
{
}
else
{
$pid = mysqli_insert_id($GLOBALS['connect_db']);
}
}
} else {
# polovimo obstoječe podatke
$s = "SELECT fields, respondents FROM srv_invitations_recipients_profiles WHERE pid ='$pid'";
$q = sisplet_query($s);
list($old_fields, $old_respondents) = mysqli_fetch_row($q);
# najprej polja
$old_fields = explode(',',$old_fields);
$post_fields = explode(',',$post_fields);
foreach ($post_fields AS $post_field )
{
#če polje še ni v bazi ga dodamo
if (!in_array($post_field, $old_fields))
{
$old_fields[] = $post_field;
}
}
# nato porihtamo podatke
$old_recipients_list = explode("\n", $old_respondents);
$new_recipients_list = explode("\n", $post_recipients);
foreach ($new_recipients_list AS $post_recipient )
{
#če polje še ni v bazi ga dodamo
if (!in_array($post_recipient, $old_recipients_list))
{
$old_recipients_list[] = $post_recipient;
}
}
# počistimo prazne
foreach ($old_recipients_list AS $k => $post_recipient )
{
if (is_null($post_recipient) || $post_recipient == '')
{
unset($old_recipients_list[$k]);
}
}
$post_fields = implode(",",$old_fields);;
$post_recipients = implode("\n",$old_recipients_list);
# updejtamo obstoječ profil
$sql_update = " UPDATE srv_invitations_recipients_profiles".
" SET fields = '$post_fields', respondents ='$post_recipients' WHERE pid = '$pid'";
$sqlQuery = sisplet_query($sql_update);
if (!$sqlQuery)
{
}
else
{
}
}
sisplet_query("COMMIT");
#vrnemo pid seznama (če smo kreirali nov seznam je tako now pid)
return $pid;
}
function showAdvancedConditions()
{
global $lang;
$scp = new SurveyCondition($this->sid);
$scp->setChooseAction('invitationSetCondition()');
$scp->displayConditions($_POST['cid']);
}
function setAdvancedCondition()
{
global $lang;
SurveySession::sessionStart($this->sid);
SurveySession::set('invitationAdvancedConditionId', (int)$_POST['cid']);
$this->invitationAdvancedConditionId = (int)$_POST['cid'];
$this->viewRecipients();
}
function getConditionUserIds($cid = 0){
global $global_user_id;
if ($cid > 0){
// Poskrbimo za datoteko s podatki
$SDF = SurveyDataFile::get_instance();
$SDF->init($this->sid);
$SDF->prepareFiles();
$headFileName = $SDF->getHeaderFileName();
$dataFileName = $SDF->getDataFileName();
$dataFileStatus = $SDF->getStatus();
if ($dataFileStatus >= 0){
$_HEADERS = unserialize(file_get_contents($headFileName));
SurveyConditionProfiles :: Init($this->sid, $global_user_id);
SurveyConditionProfiles :: setHeader($_HEADERS);
$_condition_profile_AWK = SurveyConditionProfiles:: getAwkConditionString($cid);
if (IS_WINDOWS) {
$_command = 'gawk -F"'.STR_DLMT.'" "'.$_condition_profile_AWK.' { if ('.USER_ID_FIELD.'!=0) print \"$invUsrId[]=\",'.USER_ID_FIELD.',\";\" }" '.$dataFileName .' >> '. $dataFileName.'.tmp';
}
else {
$_command = 'awk -F"'.STR_DLMT.'" \' '.$_condition_profile_AWK.' { if ('.USER_ID_FIELD.'!=0) print "$invUsrId[]=",'.USER_ID_FIELD.',";" }\' '.$dataFileName .' >> '.$dataFileName.'.tmp';
}
$file_handler = fopen($dataFileName.'.tmp',"w");
fwrite($file_handler,"');
fclose($file_handler);
include($dataFileName.'.tmp');
if (file_exists($dataFileName.'.tmp')) {
unlink($dataFileName.'.tmp');
}
if (is_array($invUsrId) && count($invUsrId) > 0){
return $invUsrId;
}
}
else{
echo '!!!OLD DATA FILE!!!';
}
}
return array();
}
function advancedCondition()
{
global $lang;
echo '';
echo $lang['srv_inv_condition_filter'].' ';
if ((int)$this->invitationAdvancedConditionId > 0)
{
$scp = new SurveyCondition($this->sid);
echo ' '.$scp->getConditionName((int)$this->invitationAdvancedConditionId).' ';
$this->user_inv_ids = $this->getConditionUserIds($this->invitationAdvancedConditionId);
$note = $scp -> getConditionString($this->invitationAdvancedConditionId );
echo $note;
if (is_array($this->user_inv_ids) && count($this->user_inv_ids) > 0)
{
}
else
{
}
echo ''.$lang['srv_profile_edit'].' ';
echo ''.$lang['srv_profile_remove'].' ';
}
else
{
echo ''.$lang['srv_inv_condition_no_filter'].' ';
echo ' ';
}
echo ' ';
}
function listCondition()
{
global $lang;
# get all lists
$lists = $this->getSurveyInvitationLists(true);
$selected = (int)(isset($_SESSION['inv_filter']['list']) ? (int)$_SESSION['inv_filter']['list'] : -2);
echo ' ';
echo ''.$lang['srv_invitation_recipients_filter_list'];
echo '';
foreach ($lists AS $list_id => $list)
{
echo ''.$list['name'].' ';
}
echo ' ';
}
function getSurveyInvitationLists($add_all = false)
{
global $lang;
# polovimo sezname
$lists = array();
if ($add_all)
{
$lists['-2'] = array('name'=>$lang['srv_invitation_recipients_filter_list_all']);
}
$lists['-1'] = array('name'=>$lang['srv_invitation_new_templist']);
$lists['0'] = array('name'=>$lang['srv_invitation_new_templist_author']);
$sql_string_lists = "SELECT * from srv_invitations_recipients_profiles WHERE pid IN(SELECT i.list_id FROM srv_invitations_recipients AS i WHERE i.ank_id = '{$this->sid}' AND i.deleted = '0' GROUP BY i.list_id ORDER BY i.id) ";
$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']);
}
return $lists;
}
private function viewServerSettings(){
global $lang;
global $site_url;
global $site_url;
global $site_path;
global $admin_type;
global $global_user_id;
global $mysql_database_name;
$row = SurveyInfo::getInstance()->getSurveyRow();
echo '