/** * Return the ID of the user connected to the master instance * @return integer|false The ID of the user, otherwise false */ function get_connected_user_id() { if ($cookie = get_master_cookie()) { // Retrieve master database $masterdb = get_master_db(); // Check user ID in database $sql = 'SELECT data FROM omeka_sessions WHERE id = ?'; $result = $masterdb->fetchOne($sql, $cookie); if (strpos($result, 'storage') > 0) { $mySession = $_SESSION; session_decode($result); $data = $_SESSION; $_SESSION = $mySession; if (isset($data['Zend_Auth']['storage']) && ($id = $data['Zend_Auth']['storage'])) { return $id; } } return false; } return false; }
/** * Save a note (ajax) * @param (AJAX param) id The id of the cart * @param (AJAX param) note the note * @return cart_id The cart ID (for removing the 'save button') */ public function saveAction() { $this->_helper->viewRenderer->setNoRender(TRUE); $cart_id = $this->getParam('id'); $note = addslashes($this->getParam('note')); if (isset($cart_id) && ($user_id = get_connected_user_id())) { $masterdb = get_master_db(); $table_name = $masterdb->getConfig()['prefix'] . 'carts'; $sql = "SELECT user_id FROM {$table_name} WHERE id = {$cart_id}"; if ($masterdb->fetchOne($sql) == $user_id) { $sql = "UPDATE {$table_name} SET note = '{$note}' WHERE id = {$cart_id}"; $masterdb->query($sql); } } echo $cart_id; }