From 8b790c9b3c020589a1807661180ea7e4c48d3e0e Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 11 Oct 2018 12:47:52 +0200 Subject: [PATCH] csv import, radio fritz, donate fixes, ... --- js/saimod_mail.js | 33 +++++++++++++++++++++++++++++++++ saimod_mail.php | 30 ++++++++++++++++++++++++++++++ sql/mysql/system_api.sql | 4 +++- tpl/saimod_mail_list.tpl | 7 +++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/js/saimod_mail.js b/js/saimod_mail.js index 63f4a3f..4a6cee1 100644 --- a/js/saimod_mail.js +++ b/js/saimod_mail.js @@ -199,6 +199,39 @@ function init_saimod_mail_list() { } }); }); + + $('#csv-file').change(function (){ + for (var i = 0; i < $(this).get(0).files.length; ++i) { + upload($(this).get(0).files[i],$('#input-list-id').val()); + } + }); +} + +function upload(file,list) { + if(!file) return; + + //FormData Objekt erzeugen + var formData = new FormData(); + //XMLHttpRequest Objekt erzeugen + var client = new XMLHttpRequest(); + client.responseType = 'json'; + + $('#bug-progress .progress-bar').css('width', '0%').attr('aria-valuenow', 0); + $('#bug-progress').show(); + $('#bug-file-list').show(); + $('#bug-file-list').append(''+file.name+''); + + //Fügt dem formData Objekt unser File Objekt hinzu + formData.append("datei", file); + + client.onerror = function(e) { + $('.'+file.lastModified).removeClass('list-group-item-warning'); + $('.'+file.lastModified).removeClass('list-group-item-success'); + $('.'+file.lastModified).addClass('list-group-item-danger'); + }; + client.open("POST", "./sai.php?sai_mod=.SAI.saimod_mail&action=csvimport&list="+list); + client.send(formData); + system.reload(); } function init_saimod_mail_list_new() { diff --git a/saimod_mail.php b/saimod_mail.php index ca83a51..6121d78 100644 --- a/saimod_mail.php +++ b/saimod_mail.php @@ -511,6 +511,36 @@ class saimod_mail extends \SYSTEM\SAI\sai_module{ } return \JsonResult::ok(); } + + public static function sai_mod__SAI_saimod_mail_action_csvimport($list){ + $handle = fopen($_FILES['datei']['tmp_name'],'r'); + while ( ($data = fgetcsv($handle,0,';') ) !== FALSE ) { + $email = $data[0]; + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + continue;} + $db = \SQL\CONTACT_SELECT::Q1(array($email)); + $sex = $db ? $db['sex'] : null; + if(count($data) >= 2 && $data[1]){ + $sex = $data[1]; + } + $name_first = $db ? $db['name_first'] : null; + if(count($data) >= 3 && $data[2]){ + $name_first = $data[2]; + } + $name_last = $db ? $db['name_last'] : null; + if(count($data) >= 4 && $data[3]){ + $name_first = $data[3]; + } + + if($db){ + \SQL\CONTACT_UPDATE::QI(array($sex,$name_first,$name_last,$email)); + } else { + \SQL\CONTACT_INSERT::QI(array($email,$sex,$name_first,$name_last)); + } + + \SQL\SUBSCRIBE::QI(array($email,$list)); + } + } public static function menu(){ return new \SYSTEM\SAI\sai_module_menu( 101, diff --git a/sql/mysql/system_api.sql b/sql/mysql/system_api.sql index 539e407..795b60b 100644 --- a/sql/mysql/system_api.sql +++ b/sql/mysql/system_api.sql @@ -24,4 +24,6 @@ REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `na REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9062, 42, 2, 9000, 'template', 'id', 'UINT0'); REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9065, 42, 2, 9000, 'update_template', 'data', 'JSON'); REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9067, 42, 2, 9000, 'insert_template', 'data', 'JSON'); -REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9069, 42, 2, 9000, 'delete_template', 'data', 'JSON'); \ No newline at end of file +REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9069, 42, 2, 9000, 'delete_template', 'data', 'JSON'); + +REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (9070, 42, 2, 9000, 'csvimport', 'list', 'UINT0'); \ No newline at end of file diff --git a/tpl/saimod_mail_list.tpl b/tpl/saimod_mail_list.tpl index 3f9f35e..e8fd1ce 100644 --- a/tpl/saimod_mail_list.tpl +++ b/tpl/saimod_mail_list.tpl @@ -20,6 +20,13 @@ + + CSV Import + + + + + Members