Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logo handling for saas mode #202

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved logo handling for saas mode
Signed-off-by: Janos SUTO <sj@acts.hu>
  • Loading branch information
jsuto committed Nov 15, 2024
commit dbdc6ef04f3492e033aeaa470c1b1e4e58210df5
4 changes: 2 additions & 2 deletions config.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ $config['BRANDING_FAVICON'] = '
$config['SITE_LOGO_LG'] = $config['PATH_PREFIX'] . 'assets/images/archive-logo-lg.png';
$config['SITE_LOGO_SM'] = $config['PATH_PREFIX'] . 'assets/images/archive-logo-sm.png';

$config['BRANDING_LOGO_PLACEHOLDER'] = $config['PATH_PREFIX'] . 'assets/images/branding-logo.png';

$config['BRANDING_TEXT'] = '';
$config['BRANDING_URL'] = '';
$config['BRANDING_LOGO'] = $config['SITE_LOGO_SM'];
$config['BRANDING_BACKGROUND_COLOUR'] = '';
$config['BRANDING_TEXT_COLOUR'] = '';

$config['ICON_DOC'] = $config['PATH_PREFIX'] . 'assets/images/fileicons/doc.png';
$config['ICON_XLS'] = $config['PATH_PREFIX'] . 'assets/images/fileicons/xls.png';
Expand Down
2 changes: 2 additions & 0 deletions webui/assets/css/piler.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ th.centered, td.centered { text-align: center; }
th.auto-width, td.auto-width { width: 1%; white-space: nowrap; }

.tsa {border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;}

.branding_logo {max-height:25px;}
Binary file added webui/assets/images/branding-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions webui/controller/customer/removelogo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php


class ControllerCustomerRemoveLogo extends Controller {
private $error = array();

public function index(){

$this->id = "content";

$request = Registry::get('request');
$db = Registry::get('db');

$this->load->model('saas/customer');

$this->data['username'] = Registry::get('username');

$this->data['id'] = $this->request->get['id'];
$this->data['confirmed'] = (int)$this->request->get['confirmed'];


if($this->validate() == true) {
$ret = $this->model_saas_customer->delete_logo($this->data['id']);
header('Location: ' . SITE_URL . 'index.php?route=customer/list&id=' . $this->data['id']);
}
}


private function validate() {

if(Registry::get('admin_user') == 0) {
$this->error['admin'] = $this->data['text_you_are_not_admin'];
}

if(!isset($this->request->get['id']) || !is_numeric($this->request->get['id'])) {
$this->error['id'] = $this->data['text_invalid_data'];
}

if (!$this->error) {
return true;
} else {
return false;
}

}


}
28 changes: 12 additions & 16 deletions webui/model/saas/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function delete($id = 0, $description = '') {
}


public function delete_logo($id = 0) {
if($id == 0) { return 0; }

$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET branding_logo='' WHERE id=?", array($id));
}


public function add($arr = array()) {
$branding_logo = '';

Expand All @@ -50,11 +57,11 @@ public function add($arr = array()) {
move_uploaded_file($_FILES['branding_logo']['tmp_name'], DIR_BASE . "/images/" . $_FILES['branding_logo']['name']);
}

$query = $this->db->query("INSERT INTO " . TABLE_CUSTOMER_SETTINGS . " (domain, branding_text, branding_url, branding_logo, support_link, background_colour, text_colour) VALUES (?,?,?,?,?,?,?)", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo, $arr['support_link'], $arr['background_colour'], $arr['text_colour']));
$query = $this->db->query("INSERT INTO " . TABLE_CUSTOMER_SETTINGS . " (domain, branding_text, branding_url, branding_logo) VALUES (?,?,?,?)", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo));

$rc = $this->db->countAffected();

LOGGER("add ldap entry: " . $arr['domain'] . " / " . $arr['branding_text'] . " / " . $arr['branding_url'] . " / " . $arr['support_link'] . " (rc=$rc)");
LOGGER("add ldap entry: " . $arr['domain'] . " / " . $arr['branding_text'] . " / " . $arr['branding_url'] . " (rc=$rc)");

if($rc == 1){ return 1; }

Expand All @@ -70,14 +77,11 @@ public function update($arr = array()) {
if(isset($_FILES['branding_logo']['name']) && $_FILES['branding_logo']['name']) {
$branding_logo = $_FILES['branding_logo']['name'];
move_uploaded_file($_FILES['branding_logo']['tmp_name'], DIR_BASE . "/images/" . $_FILES['branding_logo']['name']);

$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=?, branding_logo=?, support_link=?, background_colour=?, text_colour=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo, $arr['support_link'], $arr['background_colour'], $arr['text_colour'], $arr['id']));
}
else {
$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=?, support_link=?, background_colour=?, text_colour=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $arr['support_link'], $arr['background_colour'], $arr['text_colour'], $arr['id']));
$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=?, branding_logo=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo, $arr['id']));
} else {
$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $arr['id']));
}


return $this->db->countAffected();
}

Expand All @@ -87,9 +91,6 @@ public function get_customer_settings_by_email() {
'branding_text' => BRANDING_TEXT,
'branding_url' => BRANDING_URL,
'branding_logo' => BRANDING_LOGO,
'support_link' => SUPPORT_LINK,
'background_colour' => BRANDING_BACKGROUND_COLOUR,
'text_colour' => BRANDING_TEXT_COLOUR
);


Expand All @@ -113,9 +114,6 @@ public function get_customer_settings_by_email() {
if($query->row['branding_text']) { $data['branding_text'] = $query->row['branding_text']; }
if($query->row['branding_url']) { $data['branding_url'] = $query->row['branding_url']; }
if($query->row['branding_logo']) { $data['branding_logo'] = $query->row['branding_logo']; }
if($query->row['support_link']) { $data['support_link'] = $query->row['support_link']; }
if($query->row['background_colour']) { $data['background_colour'] = $query->row['background_colour']; }
if($query->row['text_colour']) { $data['text_colour'] = $query->row['text_colour']; }
}

if(MEMCACHED_ENABLED && $cache_key) {
Expand Down Expand Up @@ -167,5 +165,3 @@ public function get_online_users() {


}

?>
2 changes: 1 addition & 1 deletion webui/templates/common/menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="d-flex align-items-center">

<?php if(FULL_GUI) { ?>
<a class="menulink"<?php if($settings['branding_url']) { ?> target="_blank" href="<?php print $settings['branding_url']; ?>" title="<?php print $settings['branding_text']; ?>"<?php } ?>><?php if($settings['branding_logo']) { ?><img src="<?php print $settings['branding_logo']; ?>" alt="<?php print $settings['branding_text']; ?>"/><?php } ?></a>
<a class="menulink"<?php if($settings['branding_url']) { ?> target="_blank" href="<?php print $settings['branding_url']; ?>" title="<?php print $settings['branding_text']; ?>"<?php } ?>><?php if($settings['branding_logo']) { ?><img class="branding_logo" src="<?php print PATH_PREFIX . 'images/' . $settings['branding_logo']; ?>" alt="<?php print $settings['branding_text']; ?>"/><?php } ?></a>
<?php } ?>

<?php if($admin_user) { ?>
Expand Down
7 changes: 5 additions & 2 deletions webui/templates/customer/list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@

<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>
<label for="branding_logo" class="col-form-label"><?php print $text_branding_logo; ?></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" />
<input type="file" name="branding_logo" id="branding_logo" class="form-control" aria-describedby="help1" />
</div>
<div class="col-2">
<?php if(isset($a['branding_logo']) && $a['branding_logo']) { ?><img class="branding_logo" src="<?php print PATH_PREFIX; ?>images/<?php print htmlspecialchars($a['branding_logo'], ENT_QUOTES, 'UTF-8'); ?>" /> <a href="<?php print PATH_PREFIX; ?>index.php?route=customer/removelogo&amp;id=<?php print $id; ?>"><i class="bi bi-trash text-danger"></i></a><?php } else { ?><img src="<?php print BRANDING_LOGO_PLACEHOLDER; ?>" /><?php } ?>
</div>
<div class="col-auto">
<span id="help1" class="form-text"></span>
Expand Down