diff --git a/admin/survey/modules/mod_squalo/class.SqualoApi.php b/admin/survey/modules/mod_squalo/class.SqualoApi.php index 3750756b1..6abd05788 100644 --- a/admin/survey/modules/mod_squalo/class.SqualoApi.php +++ b/admin/survey/modules/mod_squalo/class.SqualoApi.php @@ -223,6 +223,19 @@ class SqualoApi { $action = 'create-recipient'; $method = 'POST'; + // Pretvorimo atribute po meri v pravo obliko + $custom_attributes_squalo = array(); + $i = 0; + foreach($custom_attributes as $key => $value){ + + $custom_attributes_squalo[$i] = array( + "name" => $key, + "value" => $value + ); + + $i++; + } + $data = array( 'email' => $email, 'listIds' => array($list_id), @@ -230,7 +243,8 @@ class SqualoApi { 'confirmed' => true, 'enabled' => true, 'gdprCanSend' => true, - 'gdprCanTrack' => true + 'gdprCanTrack' => true, + 'customAttributes' => $custom_attributes_squalo ); $response = $this->executeCall($action, $method, $data); diff --git a/admin/survey/modules/mod_squalo/class.SurveyInvitationsSqualo.php b/admin/survey/modules/mod_squalo/class.SurveyInvitationsSqualo.php index 83379ce2a..a6f78c9f2 100644 --- a/admin/survey/modules/mod_squalo/class.SurveyInvitationsSqualo.php +++ b/admin/survey/modules/mod_squalo/class.SurveyInvitationsSqualo.php @@ -13,6 +13,7 @@ class SurveyInvitationsSqualo { private $squaloEnabled; private $squaloActive; + public function __construct($anketa){ $this->anketa = $anketa; @@ -33,7 +34,6 @@ class SurveyInvitationsSqualo { return $this->squaloActive; } - // Preverimo ce je squalo omogocen na instalaciji private function checkSqualoEnabled(){ global $mysql_database_name; @@ -61,4 +61,87 @@ class SurveyInvitationsSqualo { return false; } + + + + // 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; + } } \ No newline at end of file