Skip to content

Commit

Permalink
Merge pull request #220 from emrysr/feature/issue-82-public-alias
Browse files Browse the repository at this point in the history
Feature/issue 82 public alias
  • Loading branch information
glynhudson authored Jun 20, 2019
2 parents 8afa1e5 + 9e7880e commit 08d630c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 3 additions & 5 deletions dashboard_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ function dashboard_controller()
$dashid =(int) get('id');
if ($dashid) {
$dash = $dashboard->get($dashid);
}
else if ($session['read']) {
} else if ($session['read']) {
if ($route->subaction) $dash = $dashboard->get_from_alias($session['userid'],$route->subaction);
else $dash = $dashboard->get_main($session['userid']);
} else if (!$session['read']) {
if ($route->subaction) $dash = $dashboard->get_from_public_alias($route->subaction);
}
if (isset($dash)){
if ($dash['public'] || ($session['read'] && $session['userid']>0 && $dash['userid']==$session['userid'] && !isset($session['profile']) )) {
Expand All @@ -54,9 +55,6 @@ function dashboard_controller()
$result = view("Modules/dashboard/Views/dashboard_list.php", array('js_css_version'=>$js_css_version));
}
}
if ($session['write']) {
$submenu = view("Modules/dashboard/Views/dashboard_menu.php", array('id'=>$dash['id'], 'type'=>"view", 'js_css_version'=>$js_css_version));
}
}

else if ($route->action == "edit" && $session['write'])
Expand Down
20 changes: 19 additions & 1 deletion dashboard_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,25 @@ public function get_from_alias($userid, $alias)
$result = $this->mysqli->query("SELECT * FROM dashboard WHERE userid='$userid' and alias='$alias'");
return $result->fetch_array();
}

/**
* Get the public dashboard from $alias
* return array of fields for found database
* @param string $alias
*/
public function get_from_public_alias($alias)
{
$alias = preg_replace('/[^\p{L}_\p{N}\s\-]/u','',$alias);
// access to public dashboards
if(!empty($alias)) {
$stmt = $this->mysqli->prepare("SELECT * FROM dashboard WHERE alias=?");
$stmt->bind_param("s",$alias);
$stmt->execute();
$result = $stmt->get_result();
$stmt->free_result();
$stmt->close();
return $result->fetch_array();
}
}
public function build_menu_array($location)
{
global $session;
Expand Down

0 comments on commit 08d630c

Please sign in to comment.