Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix wrong binding name
Browse files Browse the repository at this point in the history
  • Loading branch information
sc979 committed Apr 15, 2019
1 parent 0e8855a commit 48c9019
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions www/class/centreonCustomView.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public function addPublicViewWidgetParams($viewId, $userId)
'SELECT * FROM widget_views wv ' .
'LEFT JOIN widget_preferences wp ON wp.widget_view_id = wv.widget_view_id ' .
'LEFT JOIN custom_view_user_relation cvur ON cvur.custom_view_id = wv.custom_view_id ' .
'WHERE cvur.custom_view_id = :view_id AND cvur.is_owner = 1 AND cvur.user_id = wp.user_id'
'WHERE cvur.custom_view_id = :viewId AND cvur.is_owner = 1 AND cvur.user_id = wp.user_id'
);
$stmt->bindParam(':viewId', $viewId, PDO::PARAM_INT);
$dbResult = $stmt->execute();
Expand All @@ -677,12 +677,12 @@ public function addPublicViewWidgetParams($viewId, $userId)
while ($row = $stmt->fetch()) {
$stmt2 = $this->db->prepare(
'INSERT INTO widget_preferences ' .
'VALUES (:widget_view_id, :parameter_id, :preference_value, :user_id)'
'VALUES (:widgetViewId, :parameterId, :preferenceValue, :userId)'
);
$stmt2->bindParam(':widget_view_id', $row['widget_view_id'], PDO::PARAM_INT);
$stmt2->bindParam(':parameter_id', $row['parameter_id'], PDO::PARAM_INT);
$stmt2->bindParam(':preference_value', $row['preference_value'], PDO::PARAM_STR);
$stmt2->bindParam(':user_id', $userId, PDO::PARAM_INT);
$stmt2->bindParam(':widgetViewId', $row['widget_view_id'], PDO::PARAM_INT);
$stmt2->bindParam(':parameterId', $row['parameter_id'], PDO::PARAM_INT);
$stmt2->bindParam(':preferenceValue', $row['preference_value'], PDO::PARAM_STR);
$stmt2->bindParam(':userId', $userId, PDO::PARAM_INT);

$dbResult2 = $stmt2->execute();
if (!$dbResult2) {
Expand Down Expand Up @@ -725,11 +725,12 @@ public function shareCustomView($params, $userId)
}

// select user already share
$query = 'SELECT user_id FROM custom_view_user_relation ' .
$stmt = $this->db->prepare(
'SELECT user_id FROM custom_view_user_relation ' .
'WHERE custom_view_id = :viewId ' .
'AND user_id <> :userId ' .
'AND usergroup_id IS NULL ';
$stmt = $this->db->prepare($query);
'AND usergroup_id IS NULL '
);
$stmt->bindParam(':viewId', $params['custom_view_id'], PDO::PARAM_INT);
$stmt->bindParam(':userId', $userId, PDO::PARAM_INT);
$dbResult = $stmt->execute();
Expand All @@ -744,10 +745,11 @@ public function shareCustomView($params, $userId)
// check if the view is share at a new user
foreach ($sharedUsers as $sharedUserId => $locked) {
if (isset($oldSharedUsers[$sharedUserId])) {
$query = 'UPDATE custom_view_user_relation SET is_share = 1, locked = :isLocked ' .
$stmt = $this->db->prepare(
'UPDATE custom_view_user_relation SET is_share = 1, locked = :isLocked ' .
'WHERE user_id = :userId ' .
'AND custom_view_id = :viewId';
$stmt = $this->db->prepare($query);
'AND custom_view_id = :viewId'
);
$stmt->bindParam(':isLocked', $locked, PDO::PARAM_INT);
$stmt->bindParam(':userId', $sharedUserId, PDO::PARAM_INT);
$stmt->bindParam(':viewId', $params['custom_view_id'], PDO::PARAM_INT);
Expand All @@ -757,10 +759,11 @@ public function shareCustomView($params, $userId)
}
unset($oldSharedUsers[$sharedUserId]);
} else {
$query = 'INSERT INTO custom_view_user_relation ' .
$stmt = $this->db->prepare(
'INSERT INTO custom_view_user_relation ' .
'(custom_view_id, user_id, locked, is_consumed, is_share ) ' .
'VALUES ( :viewId, :sharedUser, :isLocked, 0, 1) ';
$stmt = $this->db->prepare($query);
'VALUES ( :viewId, :sharedUser, :isLocked, 0, 1) '
);
$stmt->bindParam(':viewId', $params['custom_view_id'], PDO::PARAM_INT);
$stmt->bindParam(':sharedUser', $sharedUserId, PDO::PARAM_INT);
$stmt->bindParam(':isLocked', $locked, PDO::PARAM_INT);
Expand All @@ -787,24 +790,26 @@ public function shareCustomView($params, $userId)
}

// delete widget preferences for old user
$query = 'DELETE FROM widget_preferences ' .
$stmt = $this->db->prepare(
'DELETE FROM widget_preferences ' .
'WHERE widget_view_id IN (SELECT wv.widget_view_id FROM widget_views wv ' .
'WHERE wv.custom_view_id = ? ) ' .
'AND user_id IN (' . $userIdKey . ') ';
$stmt = $this->db->prepare($query);
'AND user_id IN (' . $userIdKey . ') '
);
$dbResult = $stmt->execute($queryValue);
if (!$dbResult) {
throw new \Exception($stmt->errorInfo());
}

// delete view / user relation
$query = 'DELETE FROM custom_view_user_relation ' .
$stmt = $this->db->prepare(
'DELETE FROM custom_view_user_relation ' .
'WHERE custom_view_id = ? ' .
'AND user_id IN (' . $userIdKey . ') ';
$stmt = $this->db->prepare($query);
'AND user_id IN (' . $userIdKey . ') '
);
$dbResult = $stmt->execute($queryValue);
if (!$dbResult) {
throw new \Exception("An error occured");
throw new \Exception("An error occurred");
}

////////////////////////////
Expand Down

0 comments on commit 48c9019

Please sign in to comment.