Skip to content

Commit

Permalink
Updated saas handling (#200)
Browse files Browse the repository at this point in the history
Signed-off-by: Janos SUTO <[email protected]>
  • Loading branch information
jsuto authored Nov 14, 2024
1 parent 0f662c7 commit a34b831
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 157 deletions.
14 changes: 4 additions & 10 deletions webui/model/search/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,19 @@ private function assemble_email_address_filter() {

$sd = "";

$domains = $session->get('domain');
foreach ($domains as $d) {
if($sd) { $sd .= '|'; }
$sd .= $this->fix_email_address_for_sphinx($d);
}

foreach ($session_domains as $d) {
if($d) { $sd .= '|' . $this->fix_email_address_for_sphinx($d); }
foreach($session_domains as $d) {
$sd .= '|' . $this->fix_email_address_for_sphinx($d);
}

$sd = preg_replace("/^\|/", "", $sd);

return sprintf(" (%s %s | %s %s ) ", TODOMAIN_TOKEN, $sd, FROMDOMAIN_TOKEN, $sd);
}

else { return ""; }
else { return ''; }
}

if(ENABLE_FOLDER_RESTRICTIONS == 1) { return ""; }
if(ENABLE_FOLDER_RESTRICTIONS == 1) { return ''; }

$all_your_addresses = $this->get_all_your_address("emails");
$all_your_wildcard_domains = $this->get_all_your_address("wildcard_domains");
Expand Down
29 changes: 14 additions & 15 deletions webui/model/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public function get_users_all_domains($uid = 0) {
if($uid > 0) {
$query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN_USER . " WHERE uid=?", array((int)$uid));

if(isset($query->rows)) {
foreach ($query->rows as $q) {
if(!in_array($q['domain'], $data)) { array_push($data, $q['domain']); }
}
foreach ($query->rows as $q) {
array_push($data, $q['domain']);
}
}

if($data) { array_shift($data); }

return $data;
}

Expand Down Expand Up @@ -362,6 +362,8 @@ public function add_user($user) {
if($ret == 0) { return -2; }
}

$this->update_domains_settings($user);

return 1;
}

Expand Down Expand Up @@ -441,26 +443,23 @@ public function update_user($user) {

}

$this->update_domains_settings($user);

return 1;
}


private function update_domains_settings($uid = -1, $domains = '') {
private function update_domains_settings($user = array()) {
$__d = array();

if($uid <= 0) { return 0; }

$query = $this->db->query("DELETE FROM `" . TABLE_DOMAIN_USER . "` WHERE uid=?", array($uid));
if((int)$user['uid'] <= 0) { return 0; }

$all_domains = $this->get_email_domains();
$submitted_domains = explode("\n", $domains);
$query = $this->db->query("DELETE FROM `" . TABLE_DOMAIN_USER . "` WHERE uid=?", array($user['uid']));

foreach($submitted_domains as $d) {
$d = trim($d);
$query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN . " WHERE mapped=?", array($user['domain']));

if($d && checkdomain($d, $all_domains) > 0) {
$query = $this->db->query("INSERT INTO `" . TABLE_DOMAIN_USER . "` (domain, uid) VALUES(?,?)", array($d, (int)$uid));
}
foreach ($query->rows as $q) {
$query = $this->db->query("INSERT INTO `" . TABLE_DOMAIN_USER . "` (domain, uid) VALUES(?,?)", array($q['domain'], $user['uid']));
}

return 1;
Expand Down
282 changes: 150 additions & 132 deletions webui/templates/customer/list.tpl
Original file line number Diff line number Diff line change
@@ -1,153 +1,171 @@
<div id="deleteconfirm-modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" role="dialog" aria-hidden="true"><i class="icon-remove"></i></button>
<h3><?php print $text_confirm; ?> <?php print $text_delete; ?></h3>
</div>
<div class="modal-body">
<p><?php print $text_customer_delete_confirm_message; ?> <span id="name">ERROR</span>?</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" aria-hidden="true"><?php print $text_close; ?></a>
<a href="<?php print PATH_PREFIX; ?>index.php?route=customer/remove&amp;id=-1&amp;name=Error&amp;confirmed=0" class="btn btn-primary" id="id"><?php print $text_delete; ?></a>
</div>
<div class="container text-danger text-start">
<?php if(isset($errorstring)) { print $text_error . ': ' . $errorstring; } ?>
</div>

<form method="get" name="search1" action="customer.php" class="form-inline pull-right">
<div class="input-append">
<input type="text" name="search" class="input-medium" value="<?php print $search; ?>" />
<input type="submit" class="btn" value="<?php print $text_search; ?>" />
<div class="container text-start">
<div class="row">
<div class="col">
</div>
</form>
<div class="col text-end">
<form method="get" name="search1" action="customer.php">
<div class="row justify-content-end">
<div class="col-8">
<input type="text" name="search" class="form-control" value="<?php print $search; ?>">
</div>
<div class="col-2">
<button type="submit" class="btn btn-primary"><?php print $text_search; ?></button>
</div>
</div>
</form>
</div>
</div>
</div>

<h4><?php if(isset($id) && ($id > 0)) { print $text_edit_entry; } else { print $text_add_new_entry; } ?></h4>

<?php if(isset($errorstring)){ ?><div class="alert alert-danger"><?php print $text_error; ?>: <?php print $errorstring; ?></div><?php } ?>
<?php if(isset($x)){ ?>
<div class="alert alert-success"><?php print $x; ?></div>
<?php } ?>
<div class="container text-start">
<div class="row">
<div class="col">

<form method="post" name="add1" action="<?php print PATH_PREFIX; ?>index.php?route=customer/list" class="form-horizontal" enctype="multipart/form-data">
<h4><?php if(isset($id) && ($id > 0)) { print $text_edit_entry; } else { print $text_add_new_entry; } ?></h4>

<?php if(isset($id) && ($id > 0)) { ?>
<input type="hidden" name="id" id="id" value="<?php print $id; ?>" />
<?php } ?>
<form method="post" id="add1" name="add1" action="<?php print PATH_PREFIX; ?>index.php?route=customer/list" class="form-horizontal" enctype="multipart/form-data">

<div class="control-group<?php if(isset($errors['domain'])){ print " error"; } ?>">
<label class="control-label" for="domain"><?php print $text_domain; ?>:</label>
<div class="controls">
<?php if(isset($id) && ($id > 0)) { ?>
<input type="hidden" name="id" id="id" value="<?php print $id; ?>" />
<?php } ?>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="domain" class="col-form-label"><?php print $text_domain; ?></label>
</div>
<div class="col-5">
<select name="domain" id="domain">
<?php foreach ($domains as $domain) { ?>
<option value="<?php print $domain; ?>"<?php if(isset($a['domain']) && $a['domain'] == $domain) { ?> selected="selected"<?php } ?>><?php print $domain; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group<?php if(isset($errors['branding_text'])){ print " error"; } ?>">
<label class="control-label" for="branding_text"><?php print $text_branding_text; ?>:</label>
<div class="controls">
<input type="text" class="text" name="branding_text" id="branding_text" placeholder="" value="<?php if(isset($a['branding_text'])) { print $a['branding_text']; } ?>" />
<?php if ( isset($errors['branding_text']) ) { ?><span class="help-inline"><?php print $errors['branding_text']; ?></span><?php } ?>
</div>
</div>
<div class="control-group<?php if(isset($errors['branding_url'])){ print " error"; } ?>">
<label class="control-label" for="branding_url"><?php print $text_branding_url; ?>:</label>
<div class="controls">
<input type="text" class="text" name="branding_url" id="branding_url" placeholder="" value="<?php if(isset($a['branding_url'])) { print $a['branding_url']; } ?>" />
<?php if ( isset($errors['branding_url']) ) { ?><span class="help-inline"><?php print $errors['branding_url']; ?></span><?php } ?>
</div>
</div>
<div class="control-group<?php if(isset($errors['branding_logo'])){ print " error"; } ?>">
<label class="control-label" for="branding_logo"><?php print $text_branding_logo; ?>:</label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 50px; height: 50px;">
<?php if(isset($a['branding_logo'])) { ?><img src="/images/<?php print $a['branding_logo']; ?>" style="max-height: 50px;" /><?php } else { ?><img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" /><?php } ?>
</div>
<div class="fileupload-preview fileupload-exists thumbnail" style="width: 50px; height: 50px;"></div>
<span class="btn btn-file"><span class="fileupload-new"><?php print $text_select_image; ?></span><span class="fileupload-exists"><?php print $text_modify; ?></span><input type="file" name="branding_logo" id="branding_logo" /></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><?php print $text_remove; ?></a>
</div>
<?php if ( isset($errors['branding_logo']) ) { ?><span class="help-inline"><?php print $errors['branding_logo']; ?></span><?php } ?>
</div>
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="branding_text" class="col-form-label"><?php print $text_branding_text; ?></label>
</div>
<div class="col-4">
<input type="text" name="branding_text" id="branding_text" class="form-control" value="<?php if(isset($a['branding_text'])) { print $a['branding_text']; } ?>" aria-describedby="help1" />
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="branding_url" class="col-form-label"><?php print $text_branding_url; ?></label>
</div>
<div class="col-4">
<input type="text" name="branding_url" id="branding_url" class="form-control" value="<?php if(isset($a['branding_url'])) { print $a['branding_url']; } ?>" aria-describedby="help1" />
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="support_link" class="col-form-label"><?php print $text_support_link; ?></label>
</div>
<div class="col-4">
<input type="text" name="support_link" id="support_link" class="form-control" value="<?php if(isset($a['support_link'])) { print $a['support_link']; } ?>" aria-describedby="help1" />
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="background_colour" class="col-form-label"><?php print $text_background_colour; ?></label>
</div>
<div class="col-4">
<input type="text" name="background_colour" id="background_colour" class="form-control" placeholder="" value="<?php if(isset($a['background_colour'])) { print $a['background_colour']; } ?>" aria-describedby="help1" />
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 align-items-center">
<div class="col-2">
<label for="text_colour" class="col-form-label"><?php print $text_text_colour; ?></label>
</div>
<div class="col-4">
<input type="text" name="text_colour" id="text_colour" class="form-control" placeholder="" value="<?php if(isset($a['text_colour'])) { print $a['text_colour']; } ?>" aria-describedby="help1" />
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

<div class="row g-3 mt-2 align-items-center">
<div class="col-2">
</div>
<div class="col-2">
<button type="submit" class="btn btn-primary"><?php if(isset($id) && ($id > 0)) { print $text_modify; } else { print $text_add; } ?></button>
<a href="<?php print PATH_PREFIX; ?>index.php?route=customer/list" type="reset" class="btn btn-secondary"><?php print $text_cancel; ?></a>
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
</div>
</div>

</form>
</div>
<div class="control-group<?php if(isset($errors['support_link'])){ print " error"; } ?>">
<label class="control-label" for="support_link"><?php print $text_support_link; ?>:</label>
<div class="controls">
<input type="text" class="text" name="support_link" id="support_link" placeholder="" value="<?php if(isset($a['support_link'])) { print $a['support_link']; } ?>" />
<?php if ( isset($errors['support_link']) ) { ?><span class="help-inline"><?php print $errors['support_link']; ?></span><?php } ?>
</div>
</div>

<div class="control-group<?php if(isset($errors['background_colour'])){ print " error"; } ?>">
<label class="control-label" for="background_colour"><?php print $text_background_colour; ?>:</label>
<div class="controls">
<input type="text" class="text color {hash:true}" name="background_colour" id="background_colour" placeholder="" value="<?php if(isset($a['background_colour'])) { print $a['background_colour']; } ?>" />
<?php if ( isset($errors['background_colour']) ) { ?><span class="help-inline"><?php print $errors['background_colour']; ?></span><?php } ?>
</div>
</div>

<div class="control-group<?php if(isset($errors['text_colour'])){ print " error"; } ?>">
<label class="control-label" for="text_colour"><?php print $text_text_colour; ?>:</label>
<div class="controls">
<input type="text" class="text color {hash:true}" name="text_colour" id="text_colour" placeholder="" value="<?php if(isset($a['text_colour'])) { print $a['text_colour']; } ?>" />
<?php if ( isset($errors['text_colour']) ) { ?><span class="help-inline"><?php print $errors['text_colour']; ?></span><?php } ?>
</div>
</div>


<div class="form-actions">
<input type="submit" value="<?php if(isset($id) && ($id > 0)) { print $text_modify; } else { print $text_add; } ?>" class="btn btn-primary" />
<?php if(isset($id) && ($id > 0)) { ?>
<a href="<?php print PATH_PREFIX; ?>index.php?route=customer/list" class="btn"><?php print $text_cancel; ?></a>
<?php } else { ?>
<input type="reset" value="<?php print $text_clear; ?>" class="btn" onclick="Piler.clear_ldap_test();" />
<?php } ?>
</div>

</form>
</div>
</div>

<?php if($id == -1) { ?>
<h4><?php print $text_existing_entries; ?></h4>
<div class="listarea">
<?php if(isset($entries)){ ?>
<table id="ss1" class="table table-striped table-condensed">
<tr>
<th><?php print $text_domain; ?></th>
<th><?php print $text_branding_text; ?></th>
<th><?php print $text_branding_url; ?></th>
<th><?php print $text_branding_logo; ?></th>
<th><?php print $text_background_colour; ?></th>
<th><?php print $text_text_colour; ?></th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?php foreach($entries as $e) { ?>
<tr>
<td><?php print $e['domain']; ?></td>
<td><?php print $e['branding_text']; ?></td>
<td><?php print $e['branding_url']; ?></td>
<td><?php if($e['branding_logo']) { ?><img src="/images/<?php print $e['branding_logo']; ?>" style="height: 50px;" /><?php } ?></td>
<td><span class="label" style="background-color:<?php print $e['background_colour']; ?>"><?php print $e['background_colour']; ?></span></td>
<td><span class="label" style="background-color:<?php print $e['text_colour']; ?>"><?php print $e['text_colour']; ?></span></td>
<td><a href="<?php print PATH_PREFIX; ?>index.php?route=customer/list&amp;id=<?php print $e['id']; ?>"><i class="icon-edit"></i>&nbsp;<?php print $text_edit; ?></a></td>
<td><a href="<?php print PATH_PREFIX; ?>index.php?route=customer/remove&amp;id=<?php print $e['id']; ?>&amp;name=<?php print urlencode($e['domain']); ?>&amp;confirmed=1" class="confirm-delete" data-id="<?php print $e['id']; ?>" data-name="<?php print $e['domain']; ?>"><i class="icon-remove-sign"></i>&nbsp;<?php print $text_remove; ?></a></td>
</tr>
<?php } ?>

</table>
<div class="container text-start mt-5">
<div class="row">
<div class="col">
<h4><?php print $text_existing_entries; ?></h4>
<table class="table table-striped">
<thead class="table-dark">
<tr>
<th><?php print $text_domain; ?></th>
<th><?php print $text_branding_text; ?></th>
<th><?php print $text_branding_url; ?></th>
<th><?php print $text_branding_logo; ?></th>
<th><?php print $text_background_colour; ?></th>
<th><?php print $text_text_colour; ?></th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach($entries as $e) { ?>
<tr>
<td><?php print $e['domain']; ?></td>
<td><?php print $e['branding_text']; ?></td>
<td><?php print $e['branding_url']; ?></td>
<td><?php if($e['branding_logo']) { ?><img src="/images/<?php print $e['branding_logo']; ?>" style="height: 50px;" /><?php } ?></td>
<td><span class="label" style="background-color:<?php print $e['background_colour']; ?>"><?php print $e['background_colour']; ?></span></td>
<td><span class="label" style="background-color:<?php print $e['text_colour']; ?>"><?php print $e['text_colour']; ?></span></td>
<td><a href="<?php print PATH_PREFIX; ?>index.php?route=customer/list&amp;id=<?php print $e['id']; ?>"><i class="bi bi-pencil-square"></i>&nbsp;<?php print $text_edit; ?></a></td>
<td><a href="<?php print PATH_PREFIX; ?>index.php?route=customer/remove&amp;id=<?php print $e['id']; ?>&amp;name=<?php print urlencode($e['domain']); ?>&amp;confirmed=1" class="confirm-delete" data-id="<?php print $e['id']; ?>" data-name="<?php print $e['domain']; ?>"><i class="bi bi-trash text-danger"></i>&nbsp;<?php print $text_remove; ?></a></td>
</tr>
<?php } ?>
<tbody>
</table>

<?php } else { ?>
<div class="alert alert-error lead">
<?php print $text_not_found; ?>
</div>
<?php } ?>
</div>
</div>

<?php } ?>


</div>

0 comments on commit a34b831

Please sign in to comment.