function time_select($name, $time, $type, $max_value) { // генерируем поля формы $result = '<label><select name="' . $name . '">'; for ($i = 0; $i < $max_value; $i++) { $minute = time_left($type, $time); $selected = ''; if ($i == $minute) { $selected = 'selected'; } if ($i < 10) { $i = '0' . $i; } $result .= '<option value="' . $i . '" ' . $selected . '>' . $i . '</option>'; } $result .= '</select></label>'; return $result; }
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); $mirror_timestamp = curl_exec($ch); curl_close($ch); $update = ""; $timediff = ""; $difference = ""; $ts = ""; if ($mirror_timestamp == "") { $bgcolor = "bgcolor=coral"; } else { $ts = split(" ", $mirror_timestamp); $update = strtotime("{$ts['0']} {$ts['1']} {$ts['2']} {$ts['3']} {$ts['5']} {$ts['4']}"); $bgcolor = "bgcolor=lightgreen"; $difference = $now - $update; $timediff = time_left($difference); if ($difference > 86400) { $bgcolor = "bgcolor=coral"; } if ($difference < 86400) { $bgcolor = "bgcolor=khaki"; } if ($difference < 28800) { $bgcolor = "bgcolor=lightgreen"; } } print "<td>{$line_num}</td>\n"; print "<td><a href=\"{$mirror_url}/{$stampfile}\">{$mirror_url}/{$stampfile}</a></td>\n"; print "<td><a mailto=" . htmlspecialchars($mirror_contact) . " >" . htmlspecialchars($mirror_contact) . "</a></td>\n"; print "<td {$bgcolor} >" . htmlspecialchars($timediff) . "</td>\n"; }
function find_match($request_id) { $DB = new DB(); // get request details $result = $DB->query("select * from tutor_request where id={$request_id}"); $row = mysql_fetch_array($result); $student_id = $row["student_id"]; $subject_id = $row["subject"]; $times_per_week = $row["times_per_week"]; $requested_categories = get_request_categories($request_id); // select all tutors which have subject $result = $DB->query("select tutor.* from tutor left join tutor2subject on tutor2subject.tutor_id =tutor.id where tutor2subject.subject_id={$subject_id}"); // for each tutor returned $matches_prefered_cat = array(); $matches_other = array(); while ($row = mysql_fetch_array($result)) { $tutor_id = $row[id]; // figure out if has time left if (time_left($tutor_id) < 1) { continue; // if not, skip } // get tutor category $tutor_category = tutor_category($row["id"]); $category_matches = in_array($tutor_category, $requested_categories); // get list of common available times between tutor and student $common_times = get_common_times($tutor_id, $student_id); $common_times_number = count($common_times); // put data into datastructure if ($category_matches) { array_push($matches_prefered_cat, array($tutor_id, $tutor_category, $common_times, $category_matches, $common_times_number)); } else { array_push($matches_other, array($tutor_id, $tutor_category, $common_times, $category_matches, $common_times_number)); } } // sort matches on common hours $matches_prefered_cat = msort($matches_prefered_cat, 5); $matches_other = msort($matches_other, 5); $matches = array_merge($matches_prefered_cat, $matches_other); // return array return $matches; }
while ($row = $db->fetchArray($res)) { // после добавления обещанной суммы должно пройти не менее min_hold_time_promise_amount сек, чтобы за неё можно было голосовать if ($row['start_time'] > time() - $variables['min_hold_time_promise_amount']) { $tpl['wait_voting'][$row['currency_id']] = str_ireplace('[sec]', time_left($variables['min_hold_time_promise_amount'] - (time() - $row['start_time'])), $lng['hold_time_wait']); continue; } // если по данной валюте еще не набралось >1000 майнеров, то за неё голосовать нельзя. $count_miners = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `user_id`\n\t\t\t\tFROM `" . DB_PREFIX . "promised_amount`\n\t\t\t\tWHERE `start_time` < " . (time() - $variables['min_hold_time_promise_amount']) . " AND\n\t\t\t\t\t\t\t `del_block_id` = 0 AND\n\t\t\t\t\t\t\t `status` IN ('mining', 'repaid') AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']} AND\n\t\t\t\t\t\t\t `del_block_id` = 0\n\t\t\t\tGROUP BY `user_id`\n\t\t\t\t", 'num_rows'); if ($count_miners < $variables['min_miners_of_voting']) { $tpl['wait_voting'][$row['currency_id']] = str_ireplace(array('[miners_count]', '[remaining]'), array($variables['min_miners_of_voting'], $variables['min_miners_of_voting'] - $count_miners), $lng['min_miners_count']); continue; } // голосовать можно не чаще 1 раза в 2 недели $vote_time = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\t\tSELECT `time`\n\t\t\t\t\tFROM `" . DB_PREFIX . "log_time_votes_complex`\n\t\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t\t `time` > " . (time() - $variables['limit_votes_complex_period']) . "\n\t\t\t\t\tLIMIT 1\n\t\t\t\t\t", 'fetch_one'); if ($vote_time) { $tpl['wait_voting'][$row['currency_id']] = str_ireplace('[sec]', time_left($variables['limit_votes_complex_period'] - (time() - $vote_time)), $lng['wait_voting']); continue; } // получим наши предыдущие голоса $votes_user_pct = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `pct`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_user_pct`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one'); $votes_miner_pct = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `pct`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_miner_pct`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one'); $votes_max_other_currencies = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `count`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_max_other_currencies`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one'); $votes_max_promised_amount = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `amount`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_max_promised_amount`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one'); $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_user_pct'] = $votes_user_pct; $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_miner_pct'] = $votes_miner_pct; $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_max_other_currencies'] = $votes_max_other_currencies; $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_max_promised_amount'] = $votes_max_promised_amount; $tpl['promised_amount_currency_list'][$row['currency_id']]['name'] = $row['name']; } } $tpl['referral'] = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT `first`, `second`, `third`\n\t\tFROM `" . DB_PREFIX . "votes_referral`\n\t\tWHERE `user_id` = {$user_id}\n\t\tLIMIT 1\n\t\t", 'fetch_array');