2021-03-17 12:09:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class ki vsebuje funkcije potrebne za posiljanje vabil preko SQUALO
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SurveyInvitationsSqualo {
|
|
|
|
|
|
|
|
private $anketa;
|
|
|
|
|
|
|
|
private $squaloEnabled;
|
|
|
|
private $squaloActive;
|
|
|
|
|
2021-04-12 12:31:10 +02:00
|
|
|
|
2021-03-17 12:09:58 +01:00
|
|
|
public function __construct($anketa){
|
|
|
|
|
|
|
|
$this->anketa = $anketa;
|
|
|
|
|
|
|
|
// Preverimo ce je squalo omogocen na tej instalaciji in anketi
|
|
|
|
$this->squaloEnabled = $this->checkSqualoEnabled() ? true : false;
|
|
|
|
|
|
|
|
// Preverimo ce je squalo vklopljen na anketi
|
|
|
|
$this->squaloActive = $this->checkSqualoActive() ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function squaloEnabled(){
|
|
|
|
return $this->squaloEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function squaloActive(){
|
|
|
|
return $this->squaloActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preverimo ce je squalo omogocen na instalaciji
|
|
|
|
private function checkSqualoEnabled(){
|
|
|
|
global $mysql_database_name;
|
|
|
|
global $admin_type;
|
|
|
|
global $squalo_user;
|
|
|
|
global $squalo_key;
|
|
|
|
|
|
|
|
// Zaenkrat imajo squalo samo admini
|
|
|
|
if($admin_type != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Squalo je omogocen samo na testu, www in virtualkah
|
|
|
|
if($mysql_database_name != 'www1kasi' && $mysql_database_name != 'test1kasi' && $mysql_database_name != 'real1kasi')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Zaenkrat imajo squalo samo admini
|
|
|
|
if(!isset($squalo_user) || $squalo_user == '' || !isset($squalo_key) || $squalo_key == '')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preverimo ce je squalo vklopljen na anketi
|
|
|
|
private function checkSqualoActive(){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-12 12:31:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ustvarimo nov seznam in nanj dodamo respondente
|
|
|
|
public function createList($list_name, $recipients){
|
|
|
|
|
|
|
|
$squalo_api = new SqualoApi();
|
|
|
|
|
|
|
|
// Ustvarimo prazen seznam
|
|
|
|
$list_id = $squalo_api->createList($list_name);
|
|
|
|
|
|
|
|
// Dodamo respondente na ta seznam
|
|
|
|
foreach($recipients as $recipient){
|
|
|
|
|
|
|
|
$email = $recipient['email'];
|
|
|
|
|
|
|
|
$custom_attributes = $recipient['custom_attributes'];
|
|
|
|
|
|
|
|
$squalo_api->addRecipient($email, $list_id, $custom_attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ustvarimo nov email z vsebino (api klic createNewsletter) in posljemo na vse naslove v seznamu
|
|
|
|
public function sendEmail($subject, $body){
|
|
|
|
|
|
|
|
$squalo_api = new SqualoApi();
|
|
|
|
|
|
|
|
// Zamenjamo datapiping npr. #URL# -> {subtag:url}...
|
|
|
|
$subject = self::squaloDatapiping($subject);
|
|
|
|
$body = self::squaloDatapiping($body);
|
|
|
|
|
|
|
|
$list_id = '';
|
|
|
|
$from_email = '';
|
|
|
|
$from_name = '';
|
|
|
|
$reply_to_email = '';
|
|
|
|
$language = '';
|
|
|
|
|
|
|
|
// Api klic za ustvarjanje emaila
|
|
|
|
$newsletter_id = $squalo_api->createNewsletter($list_id, $subject, $body, $body, $from_email, $from_name, $reply_to_email, $language);
|
|
|
|
|
|
|
|
// Api klic za posiljanje na naslove
|
|
|
|
$result = $squalo_api->sendEmails($newsletter_id);
|
|
|
|
|
|
|
|
var_dump($result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function squaloDatapiping($text){
|
|
|
|
|
|
|
|
$text_fixed = str_replace(
|
|
|
|
array(
|
|
|
|
'#URL#',
|
|
|
|
'#URLLINK#',
|
|
|
|
'#UNSUBSCRIBE#',
|
|
|
|
'#FIRSTNAME#',
|
|
|
|
'#LASTNAME#',
|
|
|
|
'#EMAIL#',
|
|
|
|
'#CODE#',
|
|
|
|
'#PASSWORD#',
|
|
|
|
'#PHONE#',
|
|
|
|
'#SALUTATION#',
|
|
|
|
'#CUSTOM#',
|
|
|
|
'#RELATION#',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{subtag:url}',
|
|
|
|
'{subtag:urllink}',
|
|
|
|
'{subtag:unsubscribe}',
|
|
|
|
'{subtag:firstname}',
|
|
|
|
'{subtag:lastname}',
|
|
|
|
'{subtag:email}',
|
|
|
|
'{subtag:code}',
|
|
|
|
'{subtag:password}',
|
|
|
|
'{subtag:phone}',
|
|
|
|
'{subtag:salutation}',
|
|
|
|
'{subtag:custom}'
|
|
|
|
),
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
|
|
|
|
return $text_fixed;
|
|
|
|
}
|
2021-03-17 12:09:58 +01:00
|
|
|
}
|