';
}
}
echo '';
}
function sendMessage() {
global $lang, $site_url;
// Ali posiljamo maile ali ne
$noEmailing = SurveySession::get('inv_noEmailing');
$row = $this->surveySettings;
# Pripravimo izbor komu lahko pošiljamo
echo '
';
if ($this->checkDefaultMessage() == false) {
echo '
';
echo $lang['srv_invitation_note6'];
echo '
';
exit();
}
echo '
';
# damo v tabelo zaradi prilagajanja oblike levo/desno
echo '
';
// Pri volitvah vedno posiljamo samo tistim, katerim se nismo poslali
if(!SurveyInfo::getInstance()->checkSurveyModule('voting')){
echo '';
}
echo '
';
// Desna stran
echo '
';
// Ce posiljamo preko navadne poste ali smsov, nimamo sporocila
if($noEmailing == 0){
echo '';
echo '';
}
else{
echo '';
}
echo '
';
echo '
'; //inv_send_mail
}
function displayMailToSourceLists($source_type) {
global $lang, $site_url;
$canShowSubOption = false;
echo '
';
if ((int)$source_type == 0) {
# vsi respondenti v bazi
echo $lang['srv_inv_send_who_database_note'];
$canShowSubOption = true;
}
elseif ((int)$source_type == 1) {
# Arhivi pošiljanja
# poiščemo arhiv mailingov
# zloopamo še po posameznih pošiljanjih
$sql_string_arc = "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 ank_id = '".$this->sid."' ORDER BY sia.date_send ASC;";
$sql_query_arc = sisplet_query($sql_string_arc);
if (mysqli_num_rows($sql_query_arc) > 0) {
$canShowSubOption = true;
echo $lang['srv_inv_send_who_archive_note'];
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_inv_send_who_table_address'].'
';
echo '
'.$lang['srv_inv_send_who_table_respondents'].'
';
echo '
'.$lang['srv_inv_send_who_table_date_create'].'
';
echo '
';
while ($row_arc = mysqli_fetch_assoc($sql_query_arc)) {
echo '
';
}
else{
echo $lang['srv_inv_send_who_archive_no_archive'];
}
}
elseif ((int)$source_type == 2) {
# seznami respondentov
# zloopamo skozi posamezne sezname respondentov
$sql_string_arc ="";
$sql_query_arc = sisplet_query("SELECT list_id as id, COUNT(*) as cnt_succsess, list_id, sirp.name as naslov, DATE_FORMAT(sirp.insert_time,'%d.%m.%Y, %T') AS ds
FROM srv_invitations_recipients AS sir
LEFT JOIN srv_invitations_recipients_profiles AS sirp
ON sir.list_id = sirp.pid
WHERE ank_id ='".$this->sid."' AND sir.deleted ='0' group BY list_id
");
if (mysqli_num_rows($sql_query_arc) > 0) {
$canShowSubOption = true;
echo $lang['srv_inv_send_who_all_units_note'];
echo '
';
echo '
';
echo '
';
echo '
'.$lang['srv_inv_send_who_table_list_name'].'
';
echo '
'.$lang['srv_inv_send_who_table_respondents'].'
';
echo '
'.$lang['srv_inv_send_who_table_date_create'].'
';
echo '
';
while ($row_arc = mysqli_fetch_assoc($sql_query_arc)) {
if ($row_arc['id'] > 0 && $row_arc['naslov'] == '') {
# če ni imena in je id < 0 je bil izbrisan
}
else {
if ($row_arc['id'] > 0) {
if ($row_arc['naslov'] != '') {
$_naslov = $row_arc['naslov'];
}
else {
$_naslov = $lang['srv_inv_send_who_table_list_deleted'];
}
}
else if ($row_arc['id'] == 0) {
$_naslov = $lang['srv_inv_send_who_table_list_temporary'];
}
else if ($row_arc['id'] < 0) {
$_naslov = $lang['srv_inv_send_who_table_list_noname'];
}
echo '
';
# normalno pošiljanje
$sql_string = "SELECT sia.*, u.name, u.surname, u.email, DATE_FORMAT(sia.date_send,'%d.%m.%Y') AS ds, DATE_FORMAT(sia.date_send,'%T') AS hs 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);
# enostavno pošiljanje na posamezne maile
$SSMI = new SurveySimpleMailInvitation($this->sid);
$simple_recipents = $SSMI -> getRecipients();
echo '';
echo '
'; # id="div_archive_content">';
}
// Glavno posiljanje mail vabil
function sendMail() {
global $lang, $site_path, $site_url, $global_user_id;
Common::getInstance()->Init($this->sid);
if (isset($_POST['rids'])) {
session_start();
# preverimo token, da ne pošiljamo večkrat
if (isset($_SESSION['snd_inv_token'][$this->sid])
&& isset($_POST['_token'])
&& $_SESSION['snd_inv_token'][$this->sid] != null
&& $_SESSION['snd_inv_token'][$this->sid] == isset($_POST['_token'])){
// na send smo kliknili samo 1x
unset($_SESSION['snd_inv_token'][$this->sid]);
session_commit();
$rids = $_POST['rids'];
$comment = '';
$return = array();
$return['error'] = '0';
$return['msg'] = '
'.$lang['srv_invitation_note5'].'
';
// 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'");
}
if ($this->checkDefaultMessage() == false) {
echo '';
echo $lang['srv_invitation_note6'];
echo '';
exit();
}
else {
// 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 {
#nimamo še vsebine sporočila skreiramo privzeto.
echo '';
echo $lang['srv_invitation_note6'];
echo '';
exit();
}
}
$subject_text = $sql_row_m['subject_text'];
$body_text = $sql_row_m['body_text'];
$msg_url = $sql_row_m['url'];
// naslov za odgovor je avtor ankete
if ($this->validEmail($sql_row_m['reply_to'])) {
$reply_to = $sql_row_m['reply_to'];
}
else {
$reply_to = Common::getInstance()->getReplyToEmail();
}
// 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 id IN (".implode(',',$rids).")
ORDER BY id
");
# zloopamo skozi prejemnike in personaliziramo sporočila in jih pošljemo
$date_sent = date ("Y-m-d H:i:s");
$numRows = mysqli_num_rows($sql_query);
# če pošiljamo na večje število reposndentov obvestimo info@1ka.si
if ($numRows > NOTIFY_INFO1KA && !isLastnaInstalacija()) {
// Gorenje tega nima
if (!Common::checkModule('gorenje')){
global $site_url, $global_user_id;
$sqlinfo_query = sisplet_query("SELECT email, name, surname FROM users WHERE id = '".$global_user_id."'");
list($infoEmail,$infoName,$infoSurname) = mysqli_fetch_row($sqlinfo_query);
$infourl = 'anketi';
$preview_url = ''.$lang['srv_poglejanketo'].'';
$format = $lang['srv_inv_send_finish_note'];
$info1ka_mass_email_note = sprintf($format, $infoName, $infoSurname, $infoEmail, $infourl, $numRows, $preview_url);
try{
$MA = new MailAdapter($this->sid, $type='admin');
$MA->addRecipients('info@1ka.si');
$resultX = $MA->sendMail($info1ka_mass_email_note, 'Masovno pošiljanje vabil (poslanih več kot '.NOTIFY_INFO1KA.')');
}
catch (Exception $e){
}
}
}
// 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);
$archive_naslov = 'mailing_'.date("d.m.Y").', '.date("H:i:s");
$sqlQuery = sisplet_query("INSERT INTO srv_invitations_archive
(id, ank_id, date_send, subject_text, body_text, uid, comment, naslov, rec_in_db)
VALUES
(NULL , '$this->sid', '$date_sent', '".addslashes($subject_text)."', '".addslashes($body_text)."', '$global_user_id','$comment','$archive_naslov','$count_all')
");
$arch_id = mysqli_insert_id($GLOBALS['connect_db']);
// Podatki posiljatelja
list($name, $surname, $email) = mysqli_fetch_row(sisplet_query("SELECT name, surname, email FROM users WHERE id='$global_user_id'"));
// Podatki za posiljanje
$sending_data = array(
'body_text' => $body_text,
'subject_text' => $subject_text,
'arch_id' => $arch_id,
'msg_url' => $msg_url,
'date_sent' => $date_sent,
'from_email' => $email,
'from_name' => $name.' '.$surname,
'reply_to_email' => $reply_to
);
// Loop po prejemnikih in posiljanje mailov
$squalo = new SurveyInvitationsSqualo($this->sid);
if($squalo->getSqualoActive()){
$sending_results = $squalo->sendSqualoInvitations($sql_query, $sending_data);
}
else{
$sending_results = $this->sendMailToUsers($sql_query, $sending_data);
}
$send_ok = $sending_results['send_ok'];
$send_ok_ids = $sending_results['send_ok_ids'];
$send_users_data = $sending_results['send_users_data'];
$send_error = $sending_results['send_error'];
$send_error_ids = $sending_results['send_error_ids'];
// dodajmo še userje v povezovalno tabelo (arhiv)
if ($arch_id > 0) {
// updejtamo še tabelo arhivov
$sqlQuery = sisplet_query("UPDATE srv_invitations_archive SET cnt_succsess='".count($send_ok_ids)."', cnt_error='".count($send_error_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($send_error_ids) > 0) {
foreach ( $send_error_ids AS $id) {
$_archive_recipients[] = "('$arch_id','$id','0')";
#status 2=pošta - napaka
$_tracking[] = "('$arch_id',NOW(),'$id','2')";
}
}
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);
}
}
// Izpis rezultatov - errors and successes
if (count($send_error) > 0 ) {
$return['error'] = '1';
$return['msg'] = '
';
}
}
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 '
';
$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 '
';
}
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 '
';
}
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')){
$this->displayInvitationStatusVoting();
}
}
else{
$userAccess = UserAccess::getInstance($global_user_id);
// Ce so izklopljena ne prikazemo leve strani
if((int)$isEmail > 0 && $userAccess->checkUserAccess($what='invitations')){
$this->displayInvitationStatusNew();
}
}
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 '';
}
// Email vabila niso omogocena
else {
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]++;
}
#pregled po pošiljanjih
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 '';
}
// Email vabila niso omogocena
else {
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 '';
}*/
}
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 '
';
// desna stran - nastavitve streznika - samo ce imamo posiljanje preko emaila
if($noEmailing != 1){
// Gorenje tega nima
if (!Common::checkModule('gorenje')){
echo '
';
echo '';
echo '
';
}
}
echo '
';
}
}
# navadni uporabniki, ki nimajo dostopa - text kako lahko pridobijo dostop
else {
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 '
';
}
function showInvitationListsNames($profile_id=null) {
global $lang,$global_user_id;
$onlyThisSurvey = isset($_POST['onlyThisSurvey']) ? (int)$_POST['onlyThisSurvey'] : 1;
if ($profile_id == null) {
$pids = explode(',',$this->invitationAdvancedConditionId);
} 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);
$prefix = '';
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 '
';
}
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 = isset($_POST['onlyThisSurvey']) ? (int)$_POST['onlyThisSurvey'] : 0;
if($profile_id == null){
# preberemo id-je profilov in respondente
if ($this->invitationAdvancedConditionId != '' && $this->invitationAdvancedConditionId != '0'){
$pids = explode(',',$this->invitationAdvancedConditionId);
}
elseif ($_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();
$infoBox = null;
if (is_array($pids) && !empty($pids)){
echo '';
$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 .= '
';
}
$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 '
';
$field_lang = array();
if (count($field_list ) > 0) {
foreach ($field_list AS $field => $checked)
{
# ali je polje izbrano ( če imamo personalizirano e-vabilo, moramo nujno imeti polje email
$is_selected = ($checked == 1 ) ? true : false;
# če je polje obkljukano
$css = $is_selected ? ' class="inv_field_enabled"' : '';
# ali labela sproži klik checkboxa
$label_for = ' for="'.$field.'_chk"';
echo '
'; # id="inv_view_arch_recipients"
}
function listGetName() {
global $lang,$site_url, $global_user_id;
$saveNew = $_POST['saveNew'] == 'true' ? true : false;
$pid = isset($_POST['pid']) ? isset($_POST['pid']) : '';
$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 '
';
// 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 (isset($_SESSION['rec_sort_field']) && $_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 (isset($_SESSION['rec_sort_field']) && $_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 ' ';
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 '';
if (count($emailsToAdd)) {
echo '';
}
# če že imamo prejemnike v bazi ponudimo gumb naprej
if (mysqli_num_rows($queryUser) > 0){
echo '';
}
echo '
';
# če je kaj novih zapisov v bazi
if (mysqli_num_rows($queryUser) > 0){
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'];
}
echo '
';
}
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."','','".$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
';
}
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 '';
echo '';
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 '';
echo '
';
if (isset($_GET['s']) && $_GET['s'] == '1') {
echo '';
}
}
// V session nastavimo nastavitev da se posilja z/brez email posiljanja
function setNoEmailing(){
if(isset($_POST['value'])){
SurveySession::sessionStart($this->sid);
SurveySession::set('inv_noEmailing', (int)$_POST['value']);
// Ce preklopimo na drugo posiljanje (posta, sms...) moramo tudi preklopiti na rocni vnos kode
if($_POST['value'] == '1'){
sisplet_query("UPDATE srv_anketa SET usercode_required='1' WHERE id='".$this->sid."'");
}
}
}
// V session nastavimo tip posiljanja (ce ni email - posta, sms, drugo...)
function setNoEmailingType(){
if(isset($_POST['value'])){
SurveySession::sessionStart($this->sid);
SurveySession::set('inv_noEmailing_type', (int)$_POST['value']);
}
}
// Prikazemo popup za vklop arnes smtp-ja na aai
private function showAAISmtpPopup(){
global $lang;
echo '