tpl_set_var('cachename', getCacheName($_GET['cacheid'])); tpl_set_var('cacheid', $_GET['cacheid']); $tplname = "chowner_chooseuser"; } else { if (isset($_GET['accept']) && $_GET['accept'] == 1) { $sql = "SELECT count(id) FROM chowner WHERE cache_id = :1 AND user_id = :2"; $potwierdzenie = $db->multiVariableQueryValue($sql, 0, $_GET['cacheid'], $usr['userid']); if ($potwierdzenie > 0) { // zmiana wlasciciela tpl_set_var("error_msg", tr('adopt_30')); tpl_set_var("info_msg", ""); $db->beginTransaction(); require_once $rootpath . 'lib/cache_owners.inc.php'; $pco = new OrgCacheOwners($db); $pco->populateForCache($_GET['cacheid']); $oldOwnerId = getCacheOwner($_GET['cacheid']); $isCachePublished = isCachePublished($_GET['cacheid']); $sql = "DELETE FROM chowner WHERE cache_id = :1 AND user_id = :2"; $db->multiVariableQuery($sql, $_GET['cacheid'], $usr['userid']); if ($isCachePublished) { $sql = "UPDATE caches SET user_id = :2, org_user_id = IF(org_user_id IS NULL, :3, org_user_id) WHERE cache_id= :1"; $db->multiVariableQuery($sql, $_GET['cacheid'], $usr['userid'], $oldOwnerId); } else { $sql = "UPDATE caches SET user_id = :2 WHERE cache_id= :1"; $db->multiVariableQuery($sql, $_GET['cacheid'], $usr['userid']); } $sql = "UPDATE pictures SET user_id = :2 WHERE object_id = :1"; $db->multiVariableQuery($sql, $_GET['cacheid'], $usr['userid']); // this should be kept consistent by a trigger //$sql = "UPDATE user SET hidden_count = hidden_count - 1 WHERE user_id = :1"; //$db->multiVariableQuery($sql, $oldOwnerId);
foreach (listPendingCaches($usr['userid']) as $cache) { $acceptList .= "<tr><td>"; $acceptList .= "<a href='viewcache.php?cacheid=" . $cache['cache_id'] . "'>"; $acceptList .= $cache['name'] . "</a>"; $acceptList .= " <a href='chowner.php?cacheid=" . $cache['cache_id'] . "&accept=1'>[<font color='green'>" . tr('adopt_12') . "</font>]</a>"; $acceptList .= " <a href='chowner.php?cacheid=" . $cache['cache_id'] . "&accept=0'>[<font color='#ff0000'>" . tr('adopt_13') . "</font>]</a>"; $acceptList .= "</td>\n <td>" . strftime($dateformat, strtotime($cache['date_hidden'])) . "</td>\n </tr>\n "; } tpl_set_var('acceptList', $acceptList); } //user for adoption is selected if (isset($_POST['username'])) { $newUserId = doesUserExist($_POST['username']); if ($newUserId > 0) { // check if selected user not own this cache... $ownerId = getCacheOwner($_REQUEST['cacheid']); if ($ownerId == $newUserId) { tpl_set_var('error_msg', tr('adopt_33') . '<br /><br />'); } else { // uzytkownik istnieje, mozna kontynuowac procedure $q = "INSERT INTO chowner (cache_id, user_id) VALUES ( ?, ?)"; $stmt = XDb::xSql($q, $_REQUEST['cacheid'], $newUserId); if (XDb::xNumRows($stmt) > 0) { tpl_set_var('info_msg', ' ' . tr('adopt_24') . ' <br /><br />'); $mailContent = tr('adopt_26'); $mailContent = str_replace('\\n', "\n", $mailContent); $mailContent = str_replace('{userName}', $usr['username'], $mailContent); $mailContent = str_replace('{cacheName}', getCacheName($_REQUEST['cacheid']), $mailContent); mb_send_mail_2(getUserEmail($newUserId), tr('adopt_25'), $mailContent, emailHeaders()); } else { tpl_set_var('error_msg', tr('adopt_22') . '<br /><br />');