|
| 1 | +<?php |
| 2 | +/* |
| 3 | +Copyright (c) 2012, Till Brehm, ISPConfig UG |
| 4 | +All rights reserved. |
| 5 | +
|
| 6 | +Redistribution and use in source and binary forms, with or without modification, |
| 7 | +are permitted provided that the following conditions are met: |
| 8 | +
|
| 9 | + * Redistributions of source code must retain the above copyright notice, |
| 10 | + this list of conditions and the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + this list of conditions and the following disclaimer in the documentation |
| 13 | + and/or other materials provided with the distribution. |
| 14 | + * Neither the name of ISPConfig nor the names of its contributors |
| 15 | + may be used to endorse or promote products derived from this software without |
| 16 | + specific prior written permission. |
| 17 | +
|
| 18 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 22 | +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 25 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 27 | +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +*/ |
| 29 | + |
| 30 | +require_once('../../lib/config.inc.php'); |
| 31 | +require_once('../../lib/app.inc.php'); |
| 32 | + |
| 33 | +//* Check permissions for module |
| 34 | +$app->auth->check_module_permissions('client'); |
| 35 | + |
| 36 | +//* This function is not available in demo mode |
| 37 | +if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.'); |
| 38 | + |
| 39 | +$app->uses('tpl'); |
| 40 | + |
| 41 | +$app->tpl->newTemplate('form.tpl.htm'); |
| 42 | +$app->tpl->setInclude('content_tpl', 'templates/client_message.htm'); |
| 43 | + |
| 44 | +//* load language file |
| 45 | +$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_client_message.lng'; |
| 46 | +include($lng_file); |
| 47 | +$app->tpl->setVar($wb); |
| 48 | + |
| 49 | +$msg = ''; |
| 50 | +$error = ''; |
| 51 | + |
| 52 | +//* Save data |
| 53 | +if(isset($_POST) && count($_POST) > 1) { |
| 54 | + |
| 55 | + //* Check values |
| 56 | + if(!preg_match("/^\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\w+\.[a-zA-Z0-9\-]{2,30}$/i", $_POST['sender'])) $error .= $wb['sender_invalid_error'].'<br />'; |
| 57 | + if(empty($_POST['subject'])) $error .= $wb['subject_invalid_error'].'<br />'; |
| 58 | + if(empty($_POST['message'])) $error .= $wb['message_invalid_error'].'<br />'; |
| 59 | + |
| 60 | + //* Send message |
| 61 | + if($error == '') { |
| 62 | + //* Select all clients and resellers |
| 63 | + if($_SESSION["s"]["user"]["typ"] == 'admin'){ |
| 64 | + $sql = "SELECT * FROM client WHERE email != ''"; |
| 65 | + } else { |
| 66 | + $client_id = intval($_SESSION['s']['user']['client_id']); |
| 67 | + if($client_id == 0) die('Invalid Client ID.'); |
| 68 | + $sql = "SELECT * FROM client WHERE email != '' AND parent_client_id = '$client_id'"; |
| 69 | + } |
| 70 | + |
| 71 | + //* Get clients |
| 72 | + $clients = $app->db->queryAllRecords($sql); |
| 73 | + if(is_array($clients)) { |
| 74 | + $msg = $wb['email_sent_to_txt'].' '; |
| 75 | + foreach($clients as $client) { |
| 76 | + |
| 77 | + //* Parse cleint details into message |
| 78 | + $message = $_POST['message']; |
| 79 | + foreach($client as $key => $val) { |
| 80 | + $message = str_replace('{'.$key.'}', $val, $message); |
| 81 | + } |
| 82 | + |
| 83 | + //* Send the email |
| 84 | + $app->functions->mail($client['email'], $_POST['subject'], $message, $_POST['sender']); |
| 85 | + $msg .= $client['email'].', '; |
| 86 | + } |
| 87 | + $msg = substr($msg,0,-2); |
| 88 | + } |
| 89 | + |
| 90 | + } else { |
| 91 | + $app->tpl->setVar('sender',$_POST['sender']); |
| 92 | + $app->tpl->setVar('subject',$_POST['subject']); |
| 93 | + $app->tpl->setVar('message',$_POST['message']); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +if($_SESSION["s"]["user"]["typ"] == 'admin'){ |
| 98 | + $app->tpl->setVar('form_legend_txt',$wb['form_legend_admin_txt']); |
| 99 | +} else { |
| 100 | + $app->tpl->setVar('form_legend_txt',$wb['form_legend_client_txt']); |
| 101 | +} |
| 102 | + |
| 103 | +$app->tpl->setVar('okmsg',$msg); |
| 104 | +$app->tpl->setVar('error',$error); |
| 105 | + |
| 106 | +$app->tpl_defaults(); |
| 107 | +$app->tpl->pparse(); |
| 108 | + |
| 109 | + |
| 110 | +?> |
0 commit comments