function getstats($u, $items = 0, $class = 0) { $stat = array('HP', 'MP', 'Atk', 'Def', 'Int', 'MDf', 'Dex', 'Lck', 'Spd'); $p = $u[posts]; $d = (ctime() - $u[regdate]) / 86400; for ($i = 0; $i < 9; $i++) { $m[$i] = 1; } for ($i = 1; $i < 7; $i++) { $item = $items[$u['eq' . $i]]; for ($k = 0; $k < 9; $k++) { $is = $item['s' . $stat[$k]]; if (substr($item[stype], $k, 1) == 'm') { $m[$k] *= $is / 100; } else { $a[$k] += $is; } } } for ($i = 0; $i < 9; $i++) { $stats[$stat[$i]] = max(1, floor(basestat($p, $d, $i) * $m[$i]) + $a[$i]); } // after calculating stats with items for ($k = 0; $k < 9; $k++) { if (isset($class[$stat[$k]])) { //$stats[$stat[$k]] = ceil($stats[$stat[$k]] * ($class[$stat[$k]] != 0 ? $class[$stat[$k]] : -1)); // 0 can be 0, anything else will result in 1 because of max(1) $stats[$stat[$k]] = ceil($stats[$stat[$k]] * $class[$stat[$k]]); } } $stats[GP] = coins($p, $d) - $u[spent]; $stats[exp] = calcexp($p, $d); $stats[lvl] = calclvl($stats[exp]); return $stats; }
function printLinks($showLinkTypes, $row, $showQuery, $showLinks, $wrapResults, $userID, $viewType, $orderBy) { global $databaseBaseURL; // these variables are defined in 'ini.inc.php' global $filesBaseURL; global $fileVisibility; global $fileVisibilityException; global $openURLResolver; global $isbnURLFormat; global $tableRefs, $tableUserData; // defined in 'db.inc.php' global $loc; // '$loc' is made globally available in 'core.php' global $client; // Note: for proper placement of links within the Links column we don't use the 'mergeLinks()' function here (as is done for Details view), // since spacing before links is handled individually for each link type $links = ""; // make sure that our buffer variable is empty // count the number of available link elements: $linkElementCounterLoggedOut = 0; // if the 'user_permissions' session variable contains 'allow_details_view'... if (in_array("details", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_details_view/", $_SESSION['user_permissions'])) { $linkElementCounterLoggedOut = $linkElementCounterLoggedOut + 1; } // if the 'user_permissions' session variable contains 'allow_edit'... if (in_array("edit", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_edit/", $_SESSION['user_permissions'])) { $linkElementCounterLoggedOut = $linkElementCounterLoggedOut + 1; } // if either the URL or the DOI field contain something if (in_array("url", $showLinkTypes) and !empty($row["url"]) or in_array("doi", $showLinkTypes) and !empty($row["doi"])) { $linkElementCounterLoggedOut = $linkElementCounterLoggedOut + 1; } elseif (in_array("isbn", $showLinkTypes) and !empty($isbnURLFormat) and !empty($row["isbn"])) { // provide a link to an ISBN resolver $linkElementCounterLoggedOut = $linkElementCounterLoggedOut + 1; } elseif (in_array("xref", $showLinkTypes) and !empty($openURLResolver)) { $linkElementCounterLoggedOut = $linkElementCounterLoggedOut + 1; } $linkElementCounterLoggedIn = $linkElementCounterLoggedOut; // if a user is logged in and a FILE is associated with the current record if (in_array("file", $showLinkTypes) and ($fileVisibility == "everyone" or $fileVisibility == "login" and isset($_SESSION['loginEmail']) or $fileVisibility == "user-specific" and (isset($_SESSION['user_permissions']) and preg_match("/allow_download/", $_SESSION['user_permissions'])) or !empty($fileVisibilityException) and preg_match($fileVisibilityException[1], $row[$fileVisibilityException[0]]))) { if (!empty($row["file"])) { // if the 'file' field is NOT empty $linkElementCounterLoggedIn = $linkElementCounterLoggedIn + 1; } } if (preg_match("/^inc/i", $client)) { // we open links in a new browser window if refbase data are included somewhere else: $target = " target=\"_blank\""; } else { $target = ""; } if (preg_match("/^(cli|inc)/i", $client) or $wrapResults == "0") { // we use absolute links for CLI clients, for include mechanisms, or when returning only a partial document structure $baseURL = $databaseBaseURL; } else { $baseURL = ""; } if (in_array("details", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_details_view/", $_SESSION['user_permissions'])) { // display a link that opens the Details view for this record: // NOTE: we use a 'show.php' URL here since it is much shorter and easier to bookmark as a permanent link; however, // this means one additional redirect; the old code that directly generates a 'search.php' URL is commented out below // TODO: verify that the time lag introduced by the redirect action is generally acceptable! $queryParametersArray = array("record" => $row["serial"]); // we only add further parameters to the 'show.php' URL if their current value differs from the defaults used by 'show.php' or 'search.php': if (!empty($viewType) and !preg_match("/^Web\$/i", $viewType)) { $queryParametersArray["viewType"] = $viewType; } if ($showQuery == "1") { $queryParametersArray["showQuery"] = $showQuery; } if ($showLinks == "0") { // this is kinda superfluous since, for '$showLinks=0', the link isn't shown in the first place $queryParametersArray["showLinks"] = $showLinks; } $links .= "\n\t\t<a href=\"" . $baseURL . generateURL("show.php", "html", $queryParametersArray, true) . "\"" . $target . ">" . "<i class=\"fa fa-search\"></i></a>"; // Old code that directly generates a 'search.php' URL which points to Details view for this record: // // Construct the SQL query: // // TODO: build the complete SQL query first (using functions 'buildFROMclause()' and 'buildORDERclause()'), then rawurlencode and add to link // $showDetailsQuery = buildSELECTclause("Display", $showLinks, "", false, false); // function 'buildSELECTclause()' is defined in 'include.inc.php' // // // ... display a link that opens the Details view for this record: // if (isset($_SESSION['loginEmail'])) // if a user is logged in, show user specific fields: // $links .= "\n\t\t<a href=\"" . $baseURL . "search.php" // . "?sqlQuery=" . rawurlencode($showDetailsQuery) . "%20FROM%20" . $tableRefs . "%20LEFT%20JOIN%20" . $tableUserData . "%20ON%20serial%20%3D%20record_id%20AND%20user_id%20%3D%20" . $userID . "%20"; // else // if NO user logged in, don't display any user specific fields and hide the 'location' field: // $links .= "\n\t\t<a href=\"" . $baseURL . "search.php" // . "?sqlQuery=" . rawurlencode($showDetailsQuery) . "%20FROM%20" . $tableRefs . "%20"; // // $links .= "WHERE%20serial%20RLIKE%20%22%5E%28" . $row["serial"] // . "%29%24%22%20ORDER%20BY%20" . rawurlencode($orderBy) // . "&formType=sqlSearch" // . "&showQuery=" . $showQuery // . "&showLinks=" . $showLinks // . "&submit=Display" // . "&viewType=" . $viewType // . "\"" . $target . ">" // . "<img src=\"" . $baseURL . "img/details.gif\" alt=\"" . $loc["details"] . "\" title=\"" . $loc["LinkTitle_ShowDetails"] . "\" width=\"9\" height=\"17\" hspace=\"0\" border=\"0\"></a>"; } if (($linkElementCounterLoggedOut > 0 or isset($_SESSION['loginEmail']) and $linkElementCounterLoggedIn > 0) and (in_array("details", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_details_view/", $_SESSION['user_permissions']))) { $links .= " "; } if (in_array("edit", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_edit/", $_SESSION['user_permissions'])) { // if the 'user_permissions' session variable contains 'allow_edit'... // ... display a link that opens the edit form for this record: $links .= "\n\t\t<a href=\"" . $baseURL . "record.php" . "?serialNo=" . $row["serial"] . "&recordAction=edit" . "\"" . $target . ">" . "<i class=\"fa fa-pencil\"></i></a>"; } if (($linkElementCounterLoggedOut > 1 or isset($_SESSION['loginEmail']) and $linkElementCounterLoggedIn > 1) and (in_array("edit", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_edit/", $_SESSION['user_permissions']))) { if (in_array("details", $showLinkTypes) and isset($_SESSION['user_permissions']) and preg_match("/allow_details_view/", $_SESSION['user_permissions'])) { $links .= "\n\t\t"; } else { $links .= " "; } } // show a link to any corresponding file if one of the following conditions is met: // - the variable '$fileVisibility' (defined in 'ini.inc.php') is set to 'everyone' // - the variable '$fileVisibility' is set to 'login' AND the user is logged in // - the variable '$fileVisibility' is set to 'user-specific' AND the 'user_permissions' session variable contains 'allow_download' // - the array variable '$fileVisibilityException' (defined in 'ini.inc.php') contains a pattern (in array element 1) that matches the contents of the field given (in array element 0) if (in_array("file", $showLinkTypes) and ($fileVisibility == "everyone" or $fileVisibility == "login" and isset($_SESSION['loginEmail']) or $fileVisibility == "user-specific" and (isset($_SESSION['user_permissions']) and preg_match("/allow_download/", $_SESSION['user_permissions'])) or !empty($fileVisibilityException) and preg_match($fileVisibilityException[1], $row[$fileVisibilityException[0]]))) { if (!empty($row["file"])) { if (preg_match("#^(https?|ftp|file)://#i", $row["file"])) { // if the 'file' field contains a full URL (starting with "http://", "https://", "ftp://" or "file://") $URLprefix = ""; } else { // use the base URL of the standard files directory as prefix: if (preg_match('#^/#', $filesBaseURL)) { if (preg_match("/^(cli|inc)/i", $client) or $wrapResults == "0") { // we use absolute links for CLI clients, for include mechanisms, or when returning only a partial document structure $URLprefix = 'http://' . $_SERVER['HTTP_HOST'] . $filesBaseURL; } else { $URLprefix = $filesBaseURL; } } else { // relative path -> file dir is located within refbase root dir $URLprefix = $baseURL . $filesBaseURL; } } if (preg_match("/\\.pdf\$/i", $row["file"])) { // if the 'file' field contains a link to a PDF file $links .= "\n\t\t<a href=\"" . $URLprefix . $row["file"] . "\"" . $target . "><img src=\"" . $baseURL . "img/file_PDF.gif\" alt=\"" . $loc["pdf"] . "\" title=\"" . $loc["LinkTitle_DownloadPDFFile"] . "\" width=\"17\" height=\"17\" hspace=\"0\" border=\"0\"></a>"; } else { $links .= "\n\t\t<a href=\"" . $URLprefix . $row["file"] . "\"" . $target . "><img src=\"" . $baseURL . "img/file.gif\" alt=\"" . $loc["file"] . "\" title=\"" . $loc["LinkTitle_DownloadFile"] . "\" width=\"11\" height=\"15\" hspace=\"0\" border=\"0\"></a>"; } // display a generic file icon as download link } } // if a DOI number exists for this record, we'll prefer it as link, otherwise we use the URL (if available): // (note, that in List view, we'll use the same icon, no matter if the DOI or the URL is used for the link) if (in_array("doi", $showLinkTypes) and !empty($row["doi"])) { $links .= "\n\t\t<a href=\"http://dx.doi.org/" . rawurlencode($row["doi"]) . "\"" . $target . "><img src=\"" . $baseURL . "img/link.gif\" alt=\"" . $loc["doi"] . "\" title=\"" . $loc["LinkTitle_GotoWebPageViaDOI"] . "\" width=\"11\" height=\"8\" hspace=\"0\" border=\"0\"></a>"; } elseif (in_array("url", $showLinkTypes) and !empty($row["url"])) { // 'htmlentities()' is used to convert any '&' into '&' $links .= "\n\t\t<a href=\"" . encodeHTML($row["url"]) . "\"" . $target . "><img src=\"" . $baseURL . "img/link.gif\" alt=\"" . $loc["url"] . "\" title=\"" . $loc["LinkTitle_GotoWebPage"] . "\" width=\"11\" height=\"8\" hspace=\"0\" border=\"0\"></a>"; } elseif (in_array("isbn", $showLinkTypes) and !empty($isbnURLFormat) and !empty($row["isbn"])) { // this is a stupid hack that maps the names of the '$row' array keys to those used // by the '$formVars' array (which is required by function 'parsePlaceholderString()') // (eventually, the '$formVars' array should use the MySQL field names as names for its array keys) $formVars = buildFormVarsArray($row); // function 'buildFormVarsArray()' is defined in 'include.inc.php' // auto-generate an ISBN link according to the naming scheme given in '$isbnURLFormat' (in 'ini.inc.php'): $isbnURL = parsePlaceholderString($formVars, $isbnURLFormat, ""); // function 'parsePlaceholderString()' is defined in 'include.inc.php' $encodedURL = encodeHTML($isbnURL); // 'htmlentities()' is used to convert higher ASCII chars into its entities and any '&' into '&' $encodedURL = str_replace(" ", "%20", $encodedURL); // ensure that any spaces are also properly urlencoded if (!empty($isbnURL)) { $links .= "\n\t\t<a href=\"" . $encodedURL . "\"" . $target . "><i class=\"fa fa-external-link\"></i></a>"; } } elseif (in_array("xref", $showLinkTypes) and !empty($openURLResolver)) { $openURL = openURL($row); // function 'openURL()' is defined in 'openurl.inc.php' $links .= "\n\t\t<a href=\"" . $openURL . "\"" . " target=\"_blank\"><i class=\"fa fa-external-link\"></i></a>"; } // insert COinS (ContextObjects in Spans): $links .= "\n\t\t" . coins($row); // function 'coins()' is defined in 'openurl.inc.php' return $links; }