function getUserRanking($idSelected) { $users = getUsers(); $ranking = initialRanking(); $result = runQuery('SELECT userId, matchId, coteResult, coteScore, round, bet.scoreDomicile AS betScoreDomicile, bet.scoreExterieur AS betScoreExterieur, result.scoreDomicile AS resultScoreDomicile, result.scoreExterieur AS resultScoreExterieur FROM bet INNER JOIN result WHERE id IN (' . implode(',', $idSelected) . ') AND bet.matchId = result.id'); foreach ($result as $row) { //Variable sql $userId = intval($row['userId']); $coteResult = floatval($row['coteResult']); $coteScore = floatval($row['coteScore']); $round = intval($row['round']); $betScoreDomicile = intval($row['betScoreDomicile']); $betScoreExterieur = intval($row['betScoreExterieur']); $resultScoreDomicile = intval($row['resultScoreDomicile']); $resultScoreExterieur = intval($row['resultScoreExterieur']); if ($resultScoreDomicile >= 0) { //Variable de calcul $scorePoint = 0; if ($betScoreDomicile == $resultScoreDomicile && $betScoreExterieur == $resultScoreExterieur) { $scorePoint = $coteScore; } $betPoint = 0; if ($betScoreDomicile > $betScoreExterieur && $resultScoreDomicile > $resultScoreExterieur || $betScoreDomicile == $betScoreExterieur && $resultScoreDomicile == $resultScoreExterieur || $betScoreDomicile < $betScoreExterieur && $resultScoreDomicile < $resultScoreExterieur) { $betPoint = $coteResult; } $ranking[$userId]['betCount']++; $ranking[$userId]['betWon'] += $betPoint > 0 ? 1 : 0; $ranking[$userId]['betPoint'] += $betPoint; $ranking[$userId]['scoreWon'] += $scorePoint > 0 ? 1 : 0; $ranking[$userId]['scorePoint'] += $scorePoint; $ranking[$userId]['globalPoint'] += $betPoint + $scorePoint; } } $sortedranking = array_values($ranking); usort($sortedranking, 'compareUserPoint'); $currentRanking = 0; $currentScore = 0; $index = 0; foreach ($sortedranking as $row) { $index++; if ($currentRanking == 0) { $currentRanking = 1; $currentScore = $row['globalPoint']; } if ($currentScore != $row['globalPoint']) { $currentRanking = $index; $currentScore = $row['globalPoint']; } $ranking[$row['userId']]['rank'] = $currentRanking; } $ranking = array_values($ranking); usort($ranking, 'compareUserRanking'); return $userRanking = array('ranking' => $ranking); }
function updateBlog($p) { $q = 'UPDATE Blogs SET title=?, content=?, quote=?'; $b = array($p['title'], $p['content'], $p['quote']); $results = runQuery($q, $b); return $results; }
public function GetNextID($serviceName) { $returnArray = array(); $responseArray = array(); $nextID = 0; $selectQuery = "select id from idinfo where servicename = :servicename;"; $parameters = array(':servicename' => trim($serviceName)); $stmt = runQuery(DB_SERVER, DB_PORT, DB_USERNAME, DB_USERPASSWORD, DB_NAME, $selectQuery, $parameters); if ($stmt == QUERY_FAILED) { return FAILED; } $row = fetchNextRow($stmt['statement']); if ($row != null) { try { $nextID = getValue($row, "id"); $nextID = $nextID + 1; } catch (Exception $e) { error_log('Database Error: ' . $e->getMessage()); return FAILED; } } $updateQuery = "UPDATE idinfo SET id = :id WHERE servicename = :servicename;"; $parameters = array(':id' => $nextID, ':servicename' => trim($serviceName)); $stmt = runQuery(DB_SERVER, DB_PORT, DB_USERNAME, DB_USERPASSWORD, DB_NAME, $updateQuery, $parameters); if ($stmt == QUERY_FAILED) { error_log('Database Error: ' . $e->getMessage()); return FAILED; } return $nextID; }
function updateUIDsForPrevSemester($db) { $datesArr = getPrevSemesterDates(); $startDate = $datesArr["start"]; $endDate = $datesArr["end"]; try { $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->beginTransaction(); $updateBookingIdsQuery = "UPDATE Bookings JOIN BookingSlots ON Bookings.bookingID = BookingSlots.bookingID\n\t\t\t\t\t\t\t\tSET uID = CASE hrsSource\n\t\t\t\t\t\t\t\t\tWHEN 'Admin' THEN 'Admin'\n\t\t\t\t\t\t\t\t\tWHEN 'Faculty' THEN 'Faculty'\n\t\t\t\t\t\t\t\t\tWHEN 'Weekly' THEN 'Student'\n\t\t\t\t\t\t\t\t\tWHEN 'Special' THEN 'Student'\n\t\t\t\t\t\t\t\tEND\n\t\t\t\t\t\t\t\tWHERE bookingDate >= '{$startDate}' AND bookingDate <= '{$endDate}'"; runQuery($db, $updateBookingIdsQuery, []); $checkQuery = "SELECT BookingSlots.bookingID, bookingDate, uID, hrsSource \n\t\t\t\tFROM Bookings JOIN BookingSlots ON Bookings.bookingID = BookingSlots.bookingID \n\t\t\t\tORDER BY BookingSlots.bookingID"; $checkQueryStmt = runQuery($db, $checkQuery, []); $outputArray = $checkQueryStmt->fetchAll(PDO::FETCH_ASSOC); if (sizeof($outputArray) > 0) { // DO NOTHING. Uncomment for debugging // foreach ($outputArray as $rows){ // print_r($rows); // echo "<br>"; // } } else { echo "<br>There are no bookings or booking slots in the database.<br>"; } $db->commit(); } catch (Exception $e) { http_response_code(500); //Internal Server Error if (isset($db)) { $db->rollback(); echo "Error: " . $e; } } }
function findUserByUsernameOrEmail($usernameOrEmail) { $table = getTableQuote("users"); $query = "SELECT * FROM {$table} WHERE (username='******' OR email='{$usernameOrEmail}') AND active=1;"; $queryReturn = runQuery($query); $possibleUser = count($queryReturn) == 1 ? $queryReturn[0] : null; return $possibleUser; }
function updatePrice() { if (isset($_POST['priceId'])) { $price = ($_POST['price'] == 0 or $_POST['price'] == '') ? 'NULL' : $_POST['price']; $updatePriceQuery = 'UPDATE archi SET price=' . $price . ' WHERE id=' . $_POST["priceId"]; runQuery($updatePriceQuery); } }
function getGroupsWeeklyHours($db, $userID) { //TODO check this is the correct date to use $startThirdWeek = date("Y-m-d", strtotime('monday next week next week')); $getWeeklyHrsQuery = "SELECT Sum(UGroups.hours) weeklyHours\n\t\t\tFROM Permission JOIN UGroups on UGroups.groupID = Permission.groupID \n\t\t\tWHERE uID = '{$userID}' and '{$startThirdWeek}' BETWEEN UGroups.startDate and UGroups.endDate"; $getStudentStmt = runQuery($db, $getWeeklyHrsQuery, []); return $getStudentStmt->fetch(PDO::FETCH_ASSOC)["weeklyHours"]; }
function getFullTrait($table, $type) { $query = "SELECT * FROM `" . $table . "` WHERE type='" . $type . "' ORDER BY RAND() LIMIT 1;"; $result = runQuery($query); if (!empty($result[0])) { return $result[0]; } }
function returnResults($conn, $sql) { $result = runQuery($conn, $sql); if (mysqli_num_rows($result)) { return mysqli_fetch_assoc($result); } else { return 0; } }
function getUsers() { $users = array(); $result = runQuery('SELECT * FROM user'); foreach ($result as $row) { $users[$row['id']] = $row['pseudo']; } return $users; }
function getSingleColumnData($table, $column) { $query = "SELECT " . $column . " FROM " . getTableQuote($table); $results = runQuery($query); $data = []; foreach ($results as $row) { array_push($data, $row[$column]); } return $data; }
function countUserBet($ids) { global $countBet; $notificationBet = $countBet; $result = runQuery('SELECT * FROM bet WHERE matchId IN (' . implode(',', $ids) . ') AND userId = ' . $_SESSION['id']); foreach ($result as $row) { $notificationBet = $notificationBet - 1; } echo json_encode(array('notificationBet' => $notificationBet)); }
function teamInfo() { $selectName = 'SELECT * FROM teamInfo'; $result = runQuery($selectName); $teamInfo = array(); foreach ($result as $row) { $teamInfo[$row['name']] = array('trueName' => $row['trueName'], 'littleName' => $row['littleName'], 'countryName' => $row['countryName']); } return $teamInfo; }
function getInviteKey($email) { $table = "invitations"; $sentInviteKey = runQuery("SELECT inviteKey FROM " . getTableQuote($table) . " WHERE email='{$email}';"); if (count($sentInviteKey) == 1) { $inviteKey = $sentInviteKey[0]['inviteKey']; } else { $inviteKey = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); } return $inviteKey; }
function processPlaces($ds, $type) { foreach ($ds as $d) { if (is_null($d['number'])) { $q = "INSERT INTO places (uri, name, type) VALUES ('" . mysql_real_escape_string($d['url']) . "', '" . mysql_real_escape_string($d['name']) . "', '" . mysql_real_escape_string($type) . "')"; } else { $q = "INSERT INTO places (uri, name, num, type) VALUES ('" . mysql_real_escape_string($d['url']) . "', '" . mysql_real_escape_string($d['name']) . "', '" . mysql_real_escape_string($d['number']) . "', '" . mysql_real_escape_string($type) . "')"; } runQuery($q); } }
function getUserInfo() { if (isset($_SESSION['id'])) { $result = runQuery('SELECT * FROM user WHERE id = ' . $_SESSION['id']); foreach ($result as $row) { $user = array('id' => $row['id'], 'username' => $row['username'], 'email' => $row['email'], 'pseudo' => $row['pseudo']); return $user; } } else { return 'not connected'; } }
function fetchAsoc($db, $query) { global $db; $stmt = runQuery($db, $query); if ($stmt) { $dataRows = array(); while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $dataRows[] = $row; } return $dataRows; } return false; }
function printBalanceStatements($net) { $receipts = sprintf("%.2f", runQuery("Select SUM(r_amount) as amt from f_receivables where r_date like '%2015%'", 'amt')); $payables = sprintf("%.2f", runQuery("Select SUM(p_amount) as amt from f_payables where p_date like '%2015%'", 'amt')); $gross = $net + $receipts - $payables; echo "<table class=ptables>\n"; printRow("Mini Balance Sheet", '', '', 'H'); printRow("Cash and Equivalents", '', $net); printRow("Accounts Receivables", '', $receipts); printRow("Accounts Payables", $payables, ''); printRow("Net Assets", '', $gross, 'H'); echo "</table>"; }
function addItemToDB($name, $description, $price, $picture = "", $seller = "", $status = 'For sale') { $name = pg_escape_literal($name); $description = pg_escape_literal($description); $picture = pg_escape_literal($picture); $seller = pg_escape_literal($seller); $status = pg_escape_literal($status); $price = floatval($price); $query = 'INSERT INTO "items" (name,description,picture,seller,status,price) VALUES (' . "{$name},{$description},{$picture},{$seller},{$status},{$price}) RETURNING id;"; $id = runQuery($query); runQuery('UPDATE "items" SET postlink = \'/item.php?id=' . $id[0]['id'] . '\' WHERE id = ' . $id[0]['id']); return $id; }
function checkUser($username, $password) { $password = md5($password); $query = "SELECT * FROM users WHERE username = '******' and password = '******'"; $result = runQuery($query); if ($result->num_rows > 0) { $_SESSION['username'] = $username; $user = $result->fetch_assoc(); $_SESSION['privilege'] = $user['privilege']; return true; } else { $_SESSION['username'] = ""; return false; } }
function deleteUserListFromGroup($db, $groupID, $userArray) { if (sizeof($userArray) == 0) { return; } require_once "groupFunctions.php"; require_once "../util.php"; //$deleteArray = array(); //just use userArray $deleteString = ""; $restUpdateArray = array(); $restUpdateString = ""; //get group hours $groupInfo = getGroupInfo($db, $groupID); foreach ($userArray as $uID) { // create delete string and array $deleteString .= "uID = ? OR "; maybeUpdateUserHours($db, $uID, $groupInfo); // create updateBookingRest string and array if (shouldUpdateBookingRest($db, $uID, $groupInfo, false)) { $restUpdateString .= "uID = ? OR "; array_push($restUpdateArray, $uID); } } //remove extra characters $deleteString = chop($deleteString, " OR "); $restUpdateString = chop($restUpdateString, " OR "); // execute delete $deleteQuery = "DELETE FROM Permission WHERE groupID= ? AND {$deleteString}"; $deleteArray = $userArray; array_unshift($deleteArray, $groupID); runQuery($db, $deleteQuery, $deleteArray); // execute updateBookingRest if (sizeof($restUpdateArray) > 0) { $restUpdateQuery = "UPDATE User SET hasBookingDurationRestriction = 'Yes' WHERE {$restUpdateString}"; runQuery($db, $restUpdateQuery, $restUpdateArray); } }
function masterZoneDropDown() { $masterZone = array(); $zone = array(); $masterZoneQuery = 'SELECT masterZone FROM archi ORDER BY masterZone'; $allMasterZone = runQuery($masterZoneQuery); foreach ($allMasterZone as $row) { if (!in_array($row['masterZone'], $masterZone)) { $masterZone[] = $row['masterZone']; } } ?> <div class="zone-drop-down"> <select name="zone"> <option value="">Toutes zones</option><?php foreach ($masterZone as $row) { ?> <optgroup label="<?php echo $row; ?> "><?php $zoneQuery = 'SELECT zone FROM archi WHERE masterZone = "' . $row . '" ORDER BY zone'; $result = runQuery($zoneQuery); foreach ($result as $row) { if (!in_array($row['zone'], $zone)) { $zone[] = $row['zone']; $selected = (isset($_GET['zone']) and $_GET['zone'] == $row['zone']) ? ' selected' : ''; echo '<option value="' . $row['zone'] . '"' . $selected . '>' . $row['zone'] . '</option>'; } } ?> </optgroup><?php } ?> </select> </div><?php }
function constructDB() { global $pdo; try { //connect to the host // set the PDO error mode to exception $pdo = new PDO('mysql:host=' . DBhost . ';charset=utf8', DBuser, DBpass, array(PDO::ATTR_PERSISTENT => true)); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //connect to the database try { $pdo->query("use " . DBname); } catch (PDOException $e) { $sql = "CREATE DATABASE " . DBname; $pdo->exec($sql); $pdo->query("use " . DBname); } //create the blogs table if it doesn't exist $blogsExist = $pdo->query("SHOW TABLES LIKE 'Blogs'")->rowCount() > 0; if ($blogsExist !== FALSE) { } else { $createBlogs = "CREATE TABLE Blogs (\n code INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n title VARCHAR(100) NOT NULL,\n content VARCHAR(50) NOT NULL,\n quote VARCHAR(500) NOT NULL\n )"; $pdo->exec($createBlogs); //the original list of blogs for fast inputs $jsonBlogs = file_get_contents(JSONlist); $jsonObj = json_decode($jsonBlogs, true); //loop through each JSON blog and insert into the table foreach ($jsonObj as $blog) { $q = 'INSERT INTO Blogs (title, content, quote) VALUES (?,?,?)'; $b = array($blog['title'], $blog['content'], $blog['quote']); runQuery($q, $b); } } } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } }
function AddBudget() { echo "<form action=budgets.php method=post>\n"; echo "<table class=ptables>\n"; $blid = runQuery("SELECT b_id from BUDGET order by b_id DESC limit 1", 'b_id'); $blid++; echo "<tr><td class=pcells>Budget Line ID</td><td class=pcells>{$blid}</td></tr>"; echo "<input type=hidden name=b_id value={$blid}>\n"; echo "<tr><td class=pcells>Budget Event</td><td class=pcells><input type=text name=b_event size=40></td></tr>"; echo "<tr><td class=pcells>Budget Event Date</td><td class=pcells><input type=text name=b_date size=40></td></tr>"; echo "<tr><td class=pcells>Budget Item</td><td class=pcells><input type=text name=b_item size=40></td></tr>"; echo "<tr><td class=pcells>Budget POC</td><td class=pcells><input type=text name=b_poc size=40></td></tr>"; echo "<tr><td class=pcells>Projected Income</td><td class=pcells><input type=text name=b_revenue size=40></td></tr>"; echo "<tr><td class=pcells>Expected Expense</td><td class=pcells><input type=text name=b_expense size=40></td></tr>"; echo "<tr><td class=pcells colspan=2><input type=submit value=Add name=submit></td></tr>"; echo "</select>"; echo "</td></tr>"; echo "</form>"; echo "</table>"; }
// Record paging happens inside the successful curl request block // Outside, an unhandled error can cause faculty with > $countIncrement pubs // to spin into an infinite loop requesting more and more if ($totalResults - $countTotal > 0) { $offset += $countIncrement; } else { $loopThrough = 0; } } } // End CURLRESPONSE structure } // End LOOPTHROUGH control structure curl_close($openCurl); } // End data_try while loop } // End SCOPUSID loop printFile($outputFile, "\tADDED " . $addedPubCount . " faculty publication record(s)\n"); } // end if(count(scopusId)>0) printStatus($thisCount, $facultyCount); } // End FACULTYIDS loop // Record end of process $eventEnd = date("Y-m-d H:i:s"); $endProcess = "UPDATE events_master SET eventFinish = '{$eventEnd}' WHERE eventID = {$processNumber}"; runQuery($con, $endProcess); closeDB($con); printFile($outputFile, "All processes complete.\n"); printFile($outputFile, "Process end: " . $eventEnd . "\n");
<?php session_start(); require dirname(__FILE__) . '/php/mysql-connect.php'; openConnection(); if (!isset($_GET['id'])) { http_response_code(400); echo 'Bad Request'; return; } $id = $_GET['id']; $query = 'SELECT e.id, e.filename, e.title, e.description, e.viewable, t.name as tagName, t.id as tagID FROM (episode e LEFT JOIN tagLink tl ON e.id = tl.episodeID) LEFT JOIN tag t on t.id = tl.tagID WHERE e.id="' . mysqli_escape_string($connection, $id) . '" ORDER BY e.id'; $result = runQuery($query); closeConnection(); if (mysqli_affected_rows($connection) == 0) { http_response_code(404); echo "404"; return; } $episode = null; while ($row = mysqli_fetch_assoc($result)) { if (isset($row['tagID']) && $row['tagName']) { $tag = array('id' => intval($row['tagID']), 'name' => $row['tagName']); } unset($row['tagName']); unset($row['tagID']); $row['id'] = intval($row['id']); if (!isset($episode)) { $row['tags'] = array(); $episode = $row; }
function setCharts() { global $SUBS, $PARAM, $MSG; global $tbl_1d_charts, $tbl_1d_kino_charts, $tbl_1d_videodvd_charts, $tbl_1d_films, $tbl_1d_videodvd; global $MONTHS, $MONTHS2; // check chart length $query = "SELECT Length, Type\n\t\tFROM {$tbl_1d_charts}\n\t\tORDER BY ID = " . dbQuote($PARAM['PLACES']) . " DESC "; $result = runQuery($query, 'setCharts()', 'GET_CHART_LENGTH_AND_TYPE'); if ($row = db_fetch_row($result)) { $max = $row[0]; $type = $row[1]; } else { adminMenu(); return; } //iztriwane if ($PARAM['Delete'] == 1) { reset($PARAM); $Films = '0'; while (list($k, $v) = each($PARAM)) { if (ereg('^c_([0-9]+)$', $k, $R)) { $Films .= ",{$R['1']}"; } } //get chart type $query = "SELECT Type\n\t\t\tFROM {$tbl_1d_charts}\n\t\t\tWHERE ID = " . dbQuote($PARAM['PLACES']); $result = runQuery($query, 'setCharts()', 'GET_CHART_TYPE2'); if ($row = db_fetch_row($result)) { $type = $row[0]; } else { $SUBS['ERROR'] = $MSG[20008]; } switch ($type) { case 'videodvd': $query = "DELETE FROM {$tbl_1d_videodvd_charts} WHERE ID IN ({$Films})"; break; case 'kino': $query = "DELETE FROM {$tbl_1d_kino_charts} WHERE ID IN ({$Films})"; break; } if ($Films == '0') { $SUBS['ERROR'] = $MSG[20008]; } if ($SUBS['ERROR']) { $SUBS['ERROR'] = fileParse('_admin_error.htmlt'); } else { runQuery($query, 'setCharts()', 'DEL_CHART_RECORDS'); $SUBS['COMMAND'] = $PARAM['cmd'] . "&err=20030&WHEN=" . $PARAM['WEEK'] . "&WEEK=" . $PARAM['WEEK'] . "&WHERE=" . $PARAM['WHERE'] . "&PLACES=" . $PARAM['PLACES']; printPage('_admin_done.htmlt'); return; } } //add chart record if ($PARAM['Add'] == 1) { $SUBS['ERROR'] = ''; if ($PARAM['NO'] == '') { //poziciya w klasaciyata $SUBS['ERROR'] = $MSG[20097]; } if ($SUBS['ERROR'] == '' && !is_numeric($PARAM['NO'])) { $SUBS['ERROR'] = $MSG[20099]; } //poziciyata dali e cefira if ($SUBS['ERROR'] == '' && $PARAM['NO'] > $max) { $SUBS['ERROR'] = $MSG[20099]; } //poziciyata dali e po-golyama ot poziciite w klasaciyata if ($SUBS['ERROR'] == '' && $PARAM['NO'] < 0) { $SUBS['ERROR'] = $MSG[20099]; } //poziciyata dali e po-malka ot nula //tipa na filma switch ($PARAM['TYPE']) { case 'list': //list if ($SUBS['ERROR'] == '' && $PARAM['FILMS'] == 0) { $SUBS['ERROR'] = $MSG[20026]; } $film = $PARAM['FILMS']; break; case 'raw': //raw if ($SUBS['ERROR'] == '' && $PARAM['FILM'] == '') { $SUBS['ERROR'] = $MSG[20027]; } $film = $PARAM['FILM']; break; default: if ($SUBS['ERROR'] == '') { $SUBS['ERROR'] = $MSG[20028]; } } switch ($type) { case 'kino': if ($SUBS['ERROR'] == '' && $PARAM['WEEKS'] == '') { $SUBS['ERROR'] = $MSG[20098]; } //sedmici w klasaciyata if ($SUBS['ERROR'] == '' && !is_numeric($PARAM['WEEKS'])) { $SUBS['ERROR'] = $MSG[20100]; } //sedmicite dali sa cefira if ($SUBS['ERROR'] == '' && $PARAM['SCREENS'] == '') { $SUBS['ERROR'] = $MSG[20101]; } //ekrani na klasaciyata if ($SUBS['ERROR'] == '' && !is_numeric($PARAM['SCREENS'])) { $SUBS['ERROR'] = $MSG[20102]; } //ekranite dali sa cefira if ($SUBS['ERROR'] == '' && $PARAM['BO'] == '') { $SUBS['ERROR'] = $MSG[20103]; } //sedmichen prihod na klasaciyata /*if (($SUBS['ERROR'] =='' ) && (!is_numeric($PARAM['BO']))) $SUBS['ERROR'] = $MSG[20104]; //sedmichen prihod dali sa cefira*/ if ($SUBS['ERROR'] == '' && $PARAM['CBO'] == '') { $SUBS['ERROR'] = $MSG[20105]; } //obscht prihod na klasaciyata /*if (($SUBS['ERROR'] =='' ) && (!is_numeric($PARAM['CBO']))) $SUBS['ERROR'] = $MSG[20106]; //obscht prihod dali sa cefira*/ break; case 'videodvd': if ($SUBS['ERROR'] == '' && $PARAM['WEEKS'] == '') { $SUBS['ERROR'] = $MSG[20098]; } //sedmici w klasaciyata if ($SUBS['ERROR'] == '' && !is_numeric($PARAM['WEEKS'])) { $SUBS['ERROR'] = $MSG[20100]; } //sedmicite dali sa cefira break; } if ($SUBS['ERROR'] == '') { if ($PARAM['id'] == '') { switch ($type) { case 'videodvd': $query = "INSERT INTO {$tbl_1d_videodvd_charts} (\n\t\t\t\t\t\t\t\tChartID,\n\t\t\t\t\t\t\t\tNo,\n\t\t\t\t\t\t\t\tType,\n\t\t\t\t\t\t\t\tFilm,\n\t\t\t\t\t\t\t\tWeeks,\n\t\t\t\t\t\t\t\ttsWhen\n\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['PLACES']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['NO']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['TYPE']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($film) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['WEEKS']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['WEEK']) . " )"; break; case 'kino': $query = "INSERT INTO {$tbl_1d_kino_charts} (\n\t\t\t\t\t\t\t\tChartID,\n\t\t\t\t\t\t\t\tNo,\n\t\t\t\t\t\t\t\tType,\n\t\t\t\t\t\t\t\tFilm,\n\t\t\t\t\t\t\t\tBoxOffice,\n\t\t\t\t\t\t\t\tcumBoxOffice,\n\t\t\t\t\t\t\t\tWeeks,\n\t\t\t\t\t\t\t\tScreens,\n\t\t\t\t\t\t\t\ttsWhen\n\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['PLACES']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['NO']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['TYPE']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($film) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['BO']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['CBO']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['WEEKS']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['SCREENS']) . ",\n\t\t\t\t\t\t\t\t" . dbQuote($PARAM['WEEK']) . " )"; break; } } else { switch ($type) { case 'videodvd': $query = "UPDATE {$tbl_1d_videodvd_charts} SET\n\t\t\t\t\t\t\t\tChartID = " . dbQuote($PARAM['PLACES']) . ",\n\t\t\t\t\t\t\t\tNo = " . dbQuote($PARAM['NO']) . ",\n\t\t\t\t\t\t\t\tType = " . dbQuote($PARAM['TYPE']) . ",\n\t\t\t\t\t\t\t\tFilm = " . dbQuote($film) . ",\n\t\t\t\t\t\t\t\tWeeks = " . dbQuote($PARAM['WEEKS']) . ",\n\t\t\t\t\t\t\t\ttsWhen = " . dbQuote($PARAM['WEEK']) . " \n\t\t\t\t\t\t\tWHERE ID = " . dbQuote($PARAM['id']); break; case 'kino': $query = "UPDATE {$tbl_1d_kino_charts} SET\n\t\t\t\t\t\t\t\tChartID = " . dbQuote($PARAM['PLACES']) . ",\n\t\t\t\t\t\t\t\tNo = " . dbQuote($PARAM['NO']) . ",\n\t\t\t\t\t\t\t\tType = " . dbQuote($PARAM['TYPE']) . ",\n\t\t\t\t\t\t\t\tFilm = " . dbQuote($film) . ",\n\t\t\t\t\t\t\t\tBoxOffice = " . dbQuote($PARAM['BO']) . ",\n\t\t\t\t\t\t\t\tcumBoxOffice = " . dbQuote($PARAM['CBO']) . ",\n\t\t\t\t\t\t\t\tWeeks = " . dbQuote($PARAM['WEEKS']) . ",\n\t\t\t\t\t\t\t\tScreens = " . dbQuote($PARAM['SCREENS']) . ",\n\t\t\t\t\t\t\t\ttsWhen = " . dbQuote($PARAM['WEEK']) . " \n\t\t\t\t\t\t\tWHERE ID = " . dbQuote($PARAM['id']); break; } } $result = runQuery($query, 'setCharts()', 'SAVE_CHART'); $SUBS['COMMAND'] = $PARAM['cmd'] . "&err=20107&PLACES=" . $PARAM['PLACES'] . "&WHEN=" . $PARAM['WEEK'] . "&WEEK=" . $PARAM['WEEK']; printPage('_admin_done.htmlt'); return; } else { $SUBS['ERROR'] = fileParse('_admin_error.htmlt'); } } ////----[Mrasnika's] Edition 12.10.2002 if ($PARAM['WHEN']) { $PARAM['Year1'] = date('Y', $PARAM['WHEN']); $PARAM['Month1'] = date('m', $PARAM['WHEN']); $PARAM['Day1'] = date('d', $PARAM['WHEN']); } else { if ($PARAM['Day1'] && $PARAM['Month1'] && $PARAM['Year1']) { $PARAM['WHEN'] = 1 + strToTime($PARAM['Day1'] . ' ' . $MONTHS2[$PARAM['Month1']] . ' ' . $PARAM['Year1']); } else { $PARAM['WHEN'] = getNextWeek(); } } $SUBS['PREV'] = week($PARAM['WHEN']) - 518400; $SUBS['NEXT'] = week($PARAM['WHEN']) + 1026800; //show charts records switch ($type) { case 'kino': $query = "SELECT\t{$tbl_1d_kino_charts}.ID,\n\t\t\t\tChartID,\n\t\t\t\tNo,\n\t\t\t\tType,\n\t\t\t\tFilm,\n\t\t\t\tBoxOffice,\n\t\t\t\tcumBoxOffice,\n\t\t\t\tWeeks,\n\t\t\t\tScreens,\n\t\t\t\ttsWhen,\n\t\t\t\t\n\t\t\t\t{$tbl_1d_films}.Title,\n\t\t\t\t{$tbl_1d_films}.OriginalTitle\n\n\t\t\t\tFROM {$tbl_1d_kino_charts}\n\t\t\t\tLEFT JOIN {$tbl_1d_films}\n\t\t\t\t\tON {$tbl_1d_kino_charts}.Type = 'list'\n\t\t\t\t\t\tAND {$tbl_1d_films}.ID = {$tbl_1d_kino_charts}.Film\n\t\t\t\tWHERE {$tbl_1d_kino_charts}.ChartID = " . dbQuote($PARAM['PLACES']) . "\n\t\t\t\t\tAND {$tbl_1d_kino_charts}.tsWhen >= " . week($PARAM['WHEN']) . "\n\t\t\t\t\tAND {$tbl_1d_kino_charts}.tsWhen <= (" . week($PARAM['WHEN']) . "+604799)\n\t\t\t\tORDER BY {$tbl_1d_kino_charts}.No,\n\t\t\t\t\t{$tbl_1d_kino_charts}.BoxOffice"; break; case 'videodvd': $query = "SELECT\t{$tbl_1d_videodvd_charts}.ID,\n\t\t\t\tChartID,\n\t\t\t\tNo,\n\t\t\t\tType,\n\t\t\t\tFilm,\n\t\t\t\tWeeks,\n\t\t\t\tWeeks,\n\t\t\t\tWeeks,\n\t\t\t\tWeeks,\n\t\t\t\ttsWhen,\n\t\t\t\t\n\t\t\t\t{$tbl_1d_films}.Title,\n\t\t\t\t{$tbl_1d_films}.OriginalTitle\n\n\t\t\t\tFROM {$tbl_1d_videodvd_charts}\n\t\t\t\tLEFT JOIN {$tbl_1d_films}\n\t\t\t\t\tON {$tbl_1d_videodvd_charts}.Type = 'list'\n\t\t\t\t\t\tAND {$tbl_1d_films}.ID = {$tbl_1d_videodvd_charts}.Film\n\t\t\t\tWHERE {$tbl_1d_videodvd_charts}.ChartID = " . dbQuote($PARAM['PLACES']) . "\n\t\t\t\t\tAND {$tbl_1d_videodvd_charts}.tsWhen >= " . week($PARAM['WHEN']) . "\n\t\t\t\t\tAND {$tbl_1d_videodvd_charts}.tsWhen <= (" . week($PARAM['WHEN']) . "+604799)\n\t\t\t\tORDER BY {$tbl_1d_videodvd_charts}.No "; break; } $result = runQuery($query, 'setCharts()', 'GET_CHART_RECORDS'); while ($row = db_fetch_row($result)) { $SUBS['CHECK'] = $row[0]; $SUBS['CHARTID'] = $row[1]; $SUBS['NO2'] = sprintf("%02d", $row[2]); if ($row[3] == 'list') { if ($row[10]) { $SUBS['TITLE'] = htmlEncode($row[10]); } else { $SUBS['TITLE'] = htmlEncode($row[11]); } $SUBS['MOVIE'] = $SUBS['ACTION'] . "?cmd=insertfilm&ID={$row['4']}"; } else { $SUBS['TITLE'] = htmlEncode($row[4]); $SUBS['MOVIE'] = "javascript:alert('{$MSG['20031']}')"; } $SUBS['PRATI'] = $row[9]; switch ($type) { case 'kino': $SUBS['BO2'] = $row[5]; $SUBS['CBO2'] = $row[6]; $SUBS['SCREENS2'] = $row[8]; $SUBS['WEEKS2'] = $row[7]; $SUBS['SHOWCHARTS'] .= fileParse('_admin_charts_row.htmlt'); break; case 'videodvd': $SUBS['WEEKS2'] = $row[7]; $SUBS['SHOWCHARTS'] .= fileParse('_admin_charts_row2.htmlt'); break; } if ($PARAM['Add'] != 1 && $PARAM['id'] == $row[0]) { //load form $PARAM['PLACES'] = $row[1]; $PARAM['TYPE'] = $row[3]; if ($row[3] != 'list') { $PARAM['FILM'] = $row[4]; } else { $PARAM['FILMS'] = htmlEncode($row[4]); } $PARAM['WEEK'] = $row[9]; $PARAM['NO'] = $row[2]; switch ($type) { default: //kino $PARAM['BO'] = $row[5]; $PARAM['CBO'] = $row[6]; $PARAM['WEEKS'] = $row[7]; $PARAM['SCREENS'] = $row[8]; } } } //get charts $SUBS['CHARTS'] = $PARAM['PLACES']; $query = "SELECT ID, Title\n \t\tFROM {$tbl_1d_charts}"; $result = runQuery($query, 'setCharts()', 'GET_CHARTS'); while ($row = db_fetch_row($result)) { ////----[Mrasnika's] Edition 12.10.2002 // if ($row[0] == $PARAM['chartid']) // $SUBS['CHARTS'] .= "<OPTION value=\"$row[0]\" SELECTED>".htmlEncode($row[1]); // else $SUBS['CHARTS'] .= "<OPTION value=\"$row[0]\">".htmlEncode($row[1]); if (!$s1) { //store default chart $s1 = $row[0]; $s2 = $row[1]; } if ($row[0] == $PARAM['PLACES']) { $SUBS['CHARTTITLE'] = htmlEncode($row[1]); } if ($row[0] == $PARAM['PLACES']) { $SUBS['PLACES'] .= "<OPTION value=\"{$row['0']}\" SELECTED>" . htmlEncode($row[1]); } else { $SUBS['PLACES'] .= "<OPTION value=\"{$row['0']}\">" . htmlEncode($row[1]); } } if (!$SUBS['CHARTTITLE']) { //no default chart $SUBS['CHARTS'] = $s1; $SUBS['CHARTTITLE'] = htmlEncode($s2); } //get oldest week switch ($type) { default: //kino $query = "SELECT\tmin({$tbl_1d_kino_charts}.tsWhen)\n\t\t\t\tFROM\t{$tbl_1d_kino_charts}\n\t\t\t\tGROUP BY {$tbl_1d_kino_charts}.ChartID\n\t\t\t\tORDER BY {$tbl_1d_kino_charts}.ChartID=" . dbQuote($PARAM['PLACES']) . " DESC"; $result = runQuery($query, 'setCharts()', 'GET_OLDEST_WEEK_KINO'); if ($row = db_fetch_row($result)) { $span = $row[0]; } break; case 'videodvd': //videodvd $query = "SELECT\tmin({$tbl_1d_videodvd_charts}.tsWhen)\n\t\t\t\tFROM\t{$tbl_1d_videodvd_charts}"; $result = runQuery($query, 'setCharts()', 'GET_OLDEST_WEEK_VIDEO'); if ($row = db_fetch_row($result)) { $span = $row[0]; } break; } if (!$span) { $span = getNextWeek(); } ////----[Mrasnika's] Edition 12.10.2002 // $SUBS['WEEK'] = getWeeks($PARAM['WEEK']); // $SUBS['WHEN'] = getWeeks($PARAM['WHEN']); //compatibility if (!$PARAM['WHEN']) { //no date applied if (!$PARAM['Day1'] || !$PARAM['Month1'] || !$PARAM['Year1']) { $PARAM['WHEN'] = getNextWeek(); $PARAM['Year1'] = date('Y', $PARAM['WHEN']); $PARAM['Month1'] = date('m', $PARAM['WHEN']); $PARAM['Day1'] = date('d', $PARAM['WHEN']); } else { $PARAM['WHEN'] = 1 + strToTime($PARAM['Day1'] . ' ' . $MONTHS2[$PARAM['Month1']] . ' ' . $PARAM['Year1']); } } else { //load date form $PARAM['Year1'] = date('Y', $PARAM['WHEN']); $PARAM['Month1'] = date('m', $PARAM['WHEN']); $PARAM['Day1'] = date('d', $PARAM['WHEN']); } if ($span > $PARAM['WHEN']) { //ima data, no e po-malka ot naj-starata klasaciya $SUBS['COMMAND'] = $PARAM['cmd'] . "&WHEN={$span}&PLACES=" . $PARAM['PLACES']; printPage('_admin_done.htmlt'); return; } $Year2 = 1 + date('Y', max($PARAM['WHEN'], time())); $Year1 = date('Y', $span); for ($i = $Year1; $i <= $Year2; $i++) { if ($i == $PARAM['Year1']) { $SUBS['YEAR1'] .= "<OPTION value=\"{$i}\" selected>{$i}"; } else { $SUBS['YEAR1'] .= "<OPTION value=\"{$i}\">{$i}"; } } for ($i = 1; $i <= 12; $i++) { if ($i == $PARAM['Month1']) { $SUBS['MONTH1'] .= "<OPTION value=\"{$i}\" selected>" . $MONTHS[$i]; } else { $SUBS['MONTH1'] .= "<OPTION value=\"{$i}\">" . $MONTHS[$i]; } } for ($i = 1; $i <= 31; $i++) { if ($i == $PARAM['Day1']) { $SUBS['DAY1'] .= "<OPTION value=\"{$i}\" selected>" . sprintf('%02d', $i); } else { $SUBS['DAY1'] .= "<OPTION value=\"{$i}\">" . sprintf('%02d', $i); } } $SUBS['WEEK'] = $PARAM['WHEN']; $SUBS['DISPLAYWEEK'] = displayWeek($SUBS['WEEK']); //get films switch ($type) { case 'kino': $query = "SELECT\t{$tbl_1d_films}.ID,\n\t\t\t\tTitle,\n\t\t\t\tOriginalTitle\n\t\t\tFROM {$tbl_1d_films}\n\t\t\tLEFT JOIN {$tbl_1d_videodvd}\n\t\t\t\tON {$tbl_1d_videodvd}.FilmID = {$tbl_1d_films}.ID\n\t\t\tWHERE\t{$tbl_1d_videodvd}.ID IS NULL\n\t\t\tGROUP BY {$tbl_1d_films}.ID\n\t\t\tORDER BY OriginalTitle !='' DESC, Title='' DESC"; break; case 'videodvd': $query = "SELECT\t{$tbl_1d_films}.ID, Title\n\t\t\tFROM {$tbl_1d_films}\n\t\t\tLEFT JOIN {$tbl_1d_videodvd}\n\t\t\t\tON {$tbl_1d_videodvd}.FilmID = {$tbl_1d_films}.ID\n\t\t\tWHERE\t{$tbl_1d_videodvd}.ID IS NOT NULL\n\t\t\tGROUP BY {$tbl_1d_films}.ID\n\t\t\tORDER BY Title DESC"; break; } $result = runQuery($query, 'setCharts()', 'GET_FILMS'); while ($row = db_fetch_row($result)) { //fix titles if (!$row[1]) { $row[1] = $row[2]; } if ($PARAM['FILMS'] == $row[0]) { ////----[Mrasnika's] Edition 12.10.2002 // $SUBS['FILM'] .= "\n<option value=\"$row[0]\" selected>".htmlEncode("$row[1] $row[2] "); // else $SUBS['FILM'] .= "\n<option value=\"$row[0]\">".htmlEncode("$row[1] $row[2] "); $SUBS['FILM'] .= "\n<option value=\"{$row['0']}\" selected>" . htmlEncode($row[1]); } else { $SUBS['FILM'] .= "\n<option value=\"{$row['0']}\">" . htmlEncode($row[1]); } } // display $SUBS['TYPE' . strToUpper($PARAM['TYPE'])] = ' checked '; $SUBS['FILM2'] = htmlEncode($PARAM['FILM']); $SUBS['NO'] = htmlEncode($PARAM['NO']); switch ($type) { default: //kino $SUBS['WEEKS'] = htmlEncode($PARAM['WEEKS']); $SUBS['SCREENS'] = htmlEncode($PARAM['SCREENS']); $SUBS['BO'] = htmlEncode($PARAM['BO']); $SUBS['CBO'] = htmlEncode($PARAM['CBO']); $SUBS['DISPLAYCHART'] = fileParse("_admin_charts_kino.htmlt"); break; case 'videodvd': //video & dvd $SUBS['WEEKS'] = htmlEncode($PARAM['WEEKS']); $SUBS['DISPLAYCHART'] = fileParse("_admin_charts_videodvd.htmlt"); break; } $SUBS['ID'] = htmlEncode($PARAM['id']); if ($PARAM['err'] != '' && $SUBS['ERROR'] == '') { $SUBS['ERROR'] = $MSG[$PARAM['err']]; $SUBS['ERROR'] = fileParse('_admin_error.htmlt'); } printPage('_admin_charts.htmlt'); }
function truncateTable($pdo, $tableName, $runQueries) { if (!runQuery($pdo, "TRUNCATE TABLE " . $tableName, $runQueries)) { exit("Unable to truncate: " . $tableName . "\nConversion Stopped....\n"); } }
$username = stripslashes($username); $username = mysqli_real_escape_string($conn, $username); $sql = "SELECT id FROM beetle.users WHERE username = '******'"; if (isExists($conn, $sql)) { $_SESSION["reg"]["regError"] = 1; $_SESSION["reg"]["userExists"] = 1; } $password = $_POST["input-password"]; $password = stripslashes($password); $password = mysqli_real_escape_string($conn, $password); if (!isset($_SESSION["reg"]["regError"])) { $salt = generateSalt(); $password = (string) crypt($password, $salt); $ip = get_client_ip(); $sql = "INSERT INTO beetle.users (username, password, salt, ip_address) VALUES ('{$username}', '{$password}', '{$salt}', '{$ip}')"; if (runQuery($conn, $sql)) { //Account successfully created $_SESSION["acc"]["Username"] = $username; header("Location: ../../webApp/index.php?r=1"); } else { $_SESSION["reg"]["regError"] = 1; $_SESSION["reg"]["dbFail"] = 1; header("Location: ../../webApp/index.php?r=0"); } } else { header("Location: ../../webApp/index.php?r=0"); } } } else { header("Location: ../../webApp/index.php"); }
function fetchBets() { $bets = array(); $betsQuery = 'SELECT * FROM bet'; $result = runQuery($betsQuery); foreach ($result as $row) { $bet = ['userId' => $row['userId'], 'matchId' => $row['matchId'], 'scoreDomicile' => $row['scoreDomicile'], 'scoreExterieur' => $row['scoreExterieur'], 'coteResult' => $row['coteResult'], 'coteScore' => $row['coteScore']]; $bets[] = $bet; } return $bets; }