causefx 8 лет назад
Родитель
Сommit
e582a5b8a7
3 измененных файлов с 165 добавлено и 8 удалено
  1. 7 0
      ajax.php
  2. 68 3
      functions.php
  3. 90 5
      settings.php

+ 7 - 0
ajax.php

@@ -123,6 +123,13 @@ switch ($_SERVER['REQUEST_METHOD']) {
             default: // Stuff that you need admin for
                 qualifyUser('admin', true);
                 switch ($action) {
+					case 'get-emails':
+						$response = printEmails(getEmails($_POST['type']));
+						break;
+					case 'mass-email':
+						massEmail($_POST['emailto'],$_POST['emailsubject'],$_POST['emailmessage']);
+						$response['notify'] = sendNotification(true, 'E-Mail Sent', false);
+						break;
                     case 'test-email':
                         sendResult(sendTestEmail($_POST['emailto'], $_POST['emailsenderemail'], $_POST['emailhost'], $_POST['emailauth'], $_POST['emailusername'], $_POST['emailpassword'], $_POST['emailtype'], $_POST['emailport'], $_POST['emailsendername']), "flask", "E-Mail TEST", "SUCCESS", "ERROR");
                         break;

+ 68 - 3
functions.php

@@ -3477,7 +3477,7 @@ function get_client_ip() {
 }
 
 //EMAIL SHIT
-function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
+function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
 
 	$mail = new PHPMailer;
 	$mail->isSMTP();
@@ -3490,7 +3490,22 @@ function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = n
 	$mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
 	$mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
 	$mail->isHTML(true);
-	$mail->addAddress($email, $username);
+	if($email){
+		$mail->addAddress($email, $username);
+	}
+	if($cc){
+		$mail->addCC($cc);
+	}
+	if($bcc){
+		if(strpos($bcc , ',') === false){
+			$mail->addBCC($bcc);
+		}else{
+			$allEmails = explode(",",$bcc);
+			foreach($allEmails as $gotEmail){
+				$mail->addBCC($gotEmail);
+			}
+		}
+	}
 	$mail->Subject = $subject;
 	$mail->Body    = $body;
 	//$mail->send();
@@ -3551,6 +3566,7 @@ function libraryList(){
 			$email = (string)strtolower($child['email']);
 			$libraryList['users'][$username] = (string)$child['id'];
 			$libraryList['emails'][$email] = (string)$child['id'];
+			$libraryList['both'][$username] = $email;
 		}
     }
     return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
@@ -4439,7 +4455,7 @@ function getPing($url, $style, $refresh = null){
 
 function speedTestData(){
 	$file_db = DATABASE_LOCATION."speedtest.db";
-		if(file_exists($file_db)){
+	if(file_exists($file_db)){
 		$conn = new PDO("sqlite:$file_db") or die("1");
 		$result = $conn->query('SELECT * FROM speedtest_users');
 		$conn = null;
@@ -4482,6 +4498,9 @@ function buildMenuPhone($array){
 			if($v['id'] == 'open-invites' && empty(PLEXURL)){
 				continue;
 			}
+			if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
+				continue;
+			}
 			/*$result .= '
 			<li>
 				<a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
@@ -4505,6 +4524,9 @@ function buildMenu($array){
 			if($v['id'] == 'open-invites' && empty(PLEXURL)){
 				continue;
 			}
+			if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
+				continue;
+			}
 			$result .= '
 			<button id="'.$v['id'].'" box="'.$v['box'].'" type="button" style="border-radius: 0px !important; -webkit-border-radius: 0px !important;margin-bottom: 3px;margin-left:5px;color:white;" class="btn '.$v['color2'].' btn-icon waves waves-circle waves-effect waves-float settingsMenu">
 				<i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
@@ -4531,6 +4553,49 @@ function errormessage($msg) {
 	echo "</div>";
 }
 
+function getOrgUsers(){
+	$file_db = DATABASE_LOCATION."users.db";
+	if(file_exists($file_db)){
+		$conn = new PDO("sqlite:$file_db") or die("1");
+		$result = $conn->query('SELECT * FROM users');
+		$conn = null;
+		if (is_array($result) || is_object($result)){
+			foreach($result as $k => $v){
+				$return[$v['username']] = $v['email'];
+			}
+			return $return;
+		}
+	}
+}
+
+function getEmails($type = 'org'){
+	if($type == 'plex'){
+		$emails = array_merge(libraryList()['both'],getOrgUsers());
+	}elseif($type == 'emby'){
+		$emails = getOrgUsers();
+	}else{
+		$emails = getOrgUsers();
+	}
+	return $emails;
+}
+
+function printEmails($emails){
+	$result = '<select multiple="true" id="email-users" class="form-control">';
+	foreach($emails as $k => $v){
+		$result .= '<option value="'.$v.'">'.$k.'</option>';
+	}
+	$result .= '</select>';
+	return $result;
+}
+
+function massEmail($to, $subject, $message){
+	if (!isset($GLOBALS['file_db'])) {
+		$GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+		$GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+	}
+	sendEmail(null, null, $subject, orgEmail("Message From Admin", "Important Information", "There", $message, null, null, "Thank You!", "Thanks for taking the time to read this message from me."),null,$to);
+}
+
 class Mobile_Detect
 {
     /**

+ 90 - 5
settings.php

@@ -425,6 +425,16 @@ $buildMenu = array(
 		'color' => 'green',
 		'color2' => 'palette-Blue-Grey-700 bg',
 		'padding' => '2',
+    ),
+    array(
+		'id' => 'open-email',
+		'box' => 'email-box',
+		'name' => 'Email Users',
+		'icon_1' => 'email',
+		'icon_2' => 'mail',
+		'color' => 'yellow',
+		'color2' => 'palette-Deep-Orange-A400 bg',
+		'padding' => '2',
 	),
 	array(
 		'id' => 'open-logs',
@@ -445,7 +455,7 @@ $buildMenu = array(
 		'color' => 'yellow',
 		'color2' => 'palette-Deep-Orange-A400 bg',
 		'padding' => '2',
-	),
+    ),
 	array(
 		'id' => 'open-invites',
 		'box' => 'invites-box',
@@ -1909,6 +1919,39 @@ echo buildSettings(
                     	</div>
                 	</div>
 				</div>
+                <div class="email-content email-box white-bg"><!-- $('.email-box').find('.panel-body').html(); -->
+                    <div class="email-body">
+                        <div class="email-header gray-bg">
+                            <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
+                            <h1>E-Mail Users</h1>
+                        </div>
+                        <div class="email-inner small-box">
+                            <div class="email-inner-section">
+                                <div class="small-box fade in">
+                                   
+
+                                        <div class="mail-header">
+                                            <p><button class="btn btn-success waves generateEmails">Choose Users</button></p>
+                                            <div class="form-group" id="emailSelect">
+                                                
+                                            </div>
+                                            <div class="form-group">
+                                                <input type="text" class="form-control" id="mailTo" placeholder="To">
+                                            </div>
+                                            <div class="form-group">
+                                                <input type="text" class="form-control" id="subject" placeholder="Subject">
+                                            </div>
+                                        </div>
+
+                                        <div class="summernote"></div>
+                                        <button id="sendEmail" class="btn btn-success waves">Send</button>
+              
+                       
+                            	</div>
+                        	</div>
+                    	</div>
+                	</div>
+				</div>
                 <div class="email-content speed-box white-bg">
                     <div class="email-body">
                         <div class="email-header gray-bg">
@@ -2780,6 +2823,35 @@ echo buildSettings(
 				});
                 console.log('hmmmmm, what the hell is this section?');
             })
+            $(".generateEmails").click(function() {
+                $('.generateEmails').text("Loading...");
+                ajax_request('POST', 'get-emails', {type : 'plex'}).done(function(data){
+                    console.log('start');
+                    $('#emailSelect').html(data);
+                    $("#email-users").niceScroll({
+                        railpadding: {top:0,right:0,left:0,bottom:0}
+                    });
+                    $('#email-users').change(function(e) {
+                        var selected = $(e.target).val();
+                        $('#mailTo').val(selected);
+                    }); 
+                    $('.generateEmails').hide();
+                });
+            })
+            $("#sendEmail").click(function() {
+                var to = $('#mailTo').val();
+                var subject = $('#subject').val();
+                var message = $('.email-box').find('.panel-body').html();
+                console.log(to);
+                console.log(subject);
+                console.log(message);
+                ajax_request('POST', 'mass-email', {
+                    emailto: to,
+                    emailsubject: subject,
+                    emailmessage: message
+                });
+
+            })
             //IP INFO
             $(".ipInfo").click(function(){
                 $.getJSON("https://ipinfo.io/"+$(this).text()+"/?token=<?php echo IPINFOTOKEN;?>", function (response) {
@@ -3382,7 +3454,7 @@ echo buildSettings(
                 }
             });
 
-            $("#open-info, #open-users, #open-logs, #open-advanced, #open-homepage, #open-colors, #open-tabs, #open-donate, #open-invites , #open-themes, #open-speedtest").on("click",function (e) {
+            $("#open-info, #open-users, #open-logs, #open-advanced, #open-homepage, #open-colors, #open-tabs, #open-donate, #open-invites , #open-themes, #open-speedtest, #open-email").on("click",function (e) {
                 $(".email-content").removeClass("email-active");
                 $('html').removeClass("overhid");
                 if($(window).width() < 768){
@@ -3551,8 +3623,21 @@ echo buildSettings(
                 name = $(this).attr("name");
                 author = $(this).attr("author");
                 theme = $(this).attr("name")+'-'+$(this).attr("version");
-                button = '<div class="thumbnail"><div class="caption"><p class="pull-left">'+name+' by: '+author+'</p><p class="pull-right"><button type="button" onclick="layerCakeTheme(\''+file+'\',\''+name+'\',\''+author+'\',\''+theme+'\')" class="btn btn-success waves waves-effect waves-float">Install</button></p></div><img src="https://raw.githubusercontent.com/leram84/layer.Cake/master/Themes/Preview/'+$(this).attr("preview")+'" alt="thumbnail"></div>';
-                console.log(button);
+                $.ajax({
+                    type: 'GET',
+                    url: 'https://raw.githubusercontent.com/leram84/layer.Cake/master/Themes/Information/'+name+'.txt',
+                    dataType: "html",
+                    async: false,
+                    success: function(msg){
+                        gotinformation = msg.replace(/\r\n|\r|\n/g,"<br/>");
+                        
+                    },
+                    error: function(msg){
+                        gotinformation = "There is no information for theme "+name;
+                    }
+                });
+                information = '<div class="caption"><h3>Theme Information</h3><p>'+gotinformation+'</p></div>';
+                button = '<div class="thumbnail"><div class="caption"><p class="pull-left">'+name+' by: '+author+'</p><p class="pull-right"><button type="button" onclick="layerCakeTheme(\''+file+'\',\''+name+'\',\''+author+'\',\''+theme+'\')" class="btn btn-success waves waves-effect waves-float">Install</button></p></div><img src="https://raw.githubusercontent.com/leram84/layer.Cake/master/Themes/Preview/'+$(this).attr("preview")+'" alt="thumbnail">'+information+'</div>';
                 $('#chooseLayer').hide();
                 themeInfo = $('#layerCakeInfo');
                 $('#layerCakePreview').html( ''+button+'' );
@@ -3614,7 +3699,7 @@ echo buildSettings(
             $("textarea").niceScroll({
                 railpadding: {top:0,right:0,left:0,bottom:0}
             });
-			 $(".iconpicker-items").niceScroll({
+			$(".iconpicker-items").niceScroll({
 				railpadding: {top:0,right:0,left:0,bottom:0},
 				scrollspeed: 30,
                 mousescrollstep: 60