Skip to content

Commit 80bee61

Browse files
committed
- Added circle access control so that 1) a reseller can create circles that contain only his clients, not all clients, and 2) a reseller can send messages only to his own circles instead of all circles.
1 parent ec3d9ab commit 80bee61

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

interface/web/client/client_message.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//* This function is not available in demo mode
3737
if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.');
3838

39-
$app->uses('tpl');
39+
$app->uses('tpl,tform');
4040

4141
$app->tpl->newTemplate('form.tpl.htm');
4242
$app->tpl->setInclude('content_tpl', 'templates/client_message.htm');
@@ -60,7 +60,7 @@
6060
//* Send message
6161
if($error == '') {
6262
if(intval($_POST['recipient']) > 0){
63-
$circle = $app->db->queryOneRecord("SELECT client_ids FROM client_circle WHERE active = 'y' AND circle_id = ".intval($_POST['recipient']));
63+
$circle = $app->db->queryOneRecord("SELECT client_ids FROM client_circle WHERE active = 'y' AND circle_id = ".intval($_POST['recipient'])." AND ".$app->tform->getAuthSQL('r'));
6464
if(isset($circle['client_ids']) && $circle['client_ids'] != ''){
6565
$tmp_client_ids = explode(',',$circle['client_ids']);
6666
$where = array();
@@ -106,15 +106,25 @@
106106
$app->tpl->setVar('subject',$_POST['subject']);
107107
$app->tpl->setVar('message',$_POST['message']);
108108
}
109+
} else {
110+
// pre-fill Sender field with reseller's email address
111+
if($_SESSION["s"]["user"]["typ"] != 'admin'){
112+
$client_id = intval($_SESSION['s']['user']['client_id']);
113+
if($client_id > 0){
114+
$sql = "SELECT email FROM client WHERE client_id = ".$client_id;
115+
$client = $app->db->queryOneRecord($sql);
116+
if($client['email'] != '') $app->tpl->setVar('sender',$client['email']);
117+
}
118+
}
109119
}
110120

111121
// Recipient Drop-Down
112-
$recipient = '<option value="0">'.$wb['all_clients_resellers_txt'].'</option>';
113-
$sql = "SELECT * FROM client_circle WHERE active = 'y'";
122+
$recipient = '<option value="0"'.(intval($_POST['recipient']) == 0 ? ' selected="selected"' : '').'>'.($_SESSION["s"]["user"]["typ"] == 'admin'? $wb['all_clients_resellers_txt'] : $wb['all_clients_txt']).'</option>';
123+
$sql = "SELECT * FROM client_circle WHERE active = 'y' AND ".$app->tform->getAuthSQL('r');
114124
$circles = $app->db->queryAllRecords($sql);
115125
if(is_array($circles) && !empty($circles)){
116126
foreach($circles as $circle){
117-
$recipient .= '<option value="'.$circle['circle_id'].'">'.$circle['circle_name'].'</option>';
127+
$recipient .= '<option value="'.$circle['circle_id'].'"'.(intval($_POST['recipient']) == $circle['circle_id'] ? ' selected="selected"' : '').'>'.$circle['circle_name'].'</option>';
118128
}
119129
}
120130
$app->tpl->setVar('recipient',$recipient);

interface/web/client/form/client_circle.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
'default' => '',
105105
'separator' => ',',
106106
'datasource' => array ( 'type' => 'SQL',
107-
'querystring' => 'SELECT client_id,contact_name FROM client WHERE 1 ORDER BY contact_name',
107+
'querystring' => 'SELECT client_id,contact_name FROM client WHERE {AUTHSQL} ORDER BY contact_name',
108108
'keyfield'=> 'client_id',
109109
'valuefield'=> 'contact_name'
110110
),

interface/web/client/lib/lang/de_client_message.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ $wb["message_invalid_error"] = 'Nachricht ist leer.';
1212
$wb["email_sent_to_txt"] = 'E-Mail verschickt an:';
1313
$wb["recipient_txt"] = 'Empfänger';
1414
$wb["all_clients_resellers_txt"] = 'Alle Kunden und Reseller';
15+
$wb["all_clients_txt"] = 'Alle Kunden';
1516
?>

interface/web/client/lib/lang/en_client_message.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ $wb["message_invalid_error"] = 'Message is empty.';
1212
$wb["email_sent_to_txt"] = 'Email sent to:';
1313
$wb["recipient_txt"] = 'Recipient';
1414
$wb["all_clients_resellers_txt"] = 'All clients and resellers';
15+
$wb["all_clients_txt"] = 'All clients';
1516
?>

interface/web/client/templates/client_message.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
1212
</tmpl_if>
1313
<div class="ctrlHolder">
1414
<label for="sender">{tmpl_var name='sender_txt'}</label>
15-
<input name="sender" id="sender" value="{tmpl_var name='sender'}" style="width:500px" size="30" maxlength="255" type="text" class="textInput" />
15+
<input name="sender" id="sender" value="{tmpl_var name='sender'}" size="30" maxlength="255" type="text" class="textInput" />
1616
</div>
1717
<div class="ctrlHolder">
1818
<label for="recipient">{tmpl_var name='recipient_txt'}</label>

0 commit comments

Comments
 (0)