/** * Used on github authorization between projects and users (see github.js) * Code moved from the old /GitHub.php file */ public function connect() { $GitHub = new User(Session::uid()); $workitem = new WorkItem(); $workitem->loadById((int) $_GET['job']); $projectId = $workitem->getProjectId(); $project = new Project($projectId); $connectResponse = $GitHub->processConnectResponse($project); if (!$connectResponse['error']) { if ($GitHub->storeCredentials($connectResponse['data']['access_token'], $project->getGithubId())) { $journal_message = sprintf("%s has been validated for project ##%s##", $GitHub->getNickname(), $project->getName()); Utils::systemNotification($journal_message); Utils::redirect('./' . $workitem->getId()); } else { // Something went wrong updating the users details, close this window and // display a proper error message to the user $message = 'Something went wrong and we could not complete the authorization process with GitHub. Please try again.'; } } else { // We have an error on the response, close this window and display an error message // to the user $message = 'We received an error when trying to complete the authorization process with GitHub. Please notify a member of the O-Team for assistance.'; } echo $message; }
function autoPassSuggestedJobs() { $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(DB_NAME, $con); $sql = "SELECT id FROM `" . WORKLIST . "` WHERE status IN ( 'Suggestion', 'Bidding') AND DATEDIFF(now() , status_changed) > 30"; $result = mysql_query($sql); $delay = 0; if (mysql_num_rows($result) > 1) { $delay = 5; } while ($row = mysql_fetch_assoc($result)) { $status = 'Pass'; $workitem = new WorkItem($row['id']); $prev_status = $workitem->getStatus(); // change status of the workitem to PASS. $workitem->setStatus($status); if ($workitem->save()) { $recipients = array('creator'); $emails = array(); $data = array('prev_status' => $prev_status); if ($prev_status == 'Bidding') { $recipients[] = 'usersWithBids'; $emails = preg_split('/[\\s]+/', ADMINS_EMAILS); } //notify Notification::workitemNotify(array('type' => 'auto-pass', 'workitem' => $workitem, 'recipients' => $recipients, 'emails' => $emails), $data); $journal_message = "\\\\#" . $workitem->getId() . " updated by @Otto. Status set to " . $status; Utils::systemNotification(stripslashes($journal_message)); } else { error_log("Otto failed to update the status of workitem #" . $workitem->getId() . " to " . $status); } sleep($delay); } mysql_free_result($result); mysql_close($con); }
private function withdrawBid($bid_id, $withdraw_reason) { $res = mysql_query('SELECT * FROM `' . BIDS . '` WHERE `id`=' . $bid_id); $bid = mysql_fetch_object($res); // checking if is bidder or runner if (!empty($_SESSION['is_runner']) || $bid->bidder_id == $_SESSION['userid']) { // getting the job $res = mysql_query('SELECT * FROM `' . WORKLIST . '` WHERE `id` = ' . $bid->worklist_id); $job = mysql_fetch_assoc($res); if (!in_array($job['status'], array('Draft', 'Suggestion', 'Bidding', 'Done'))) { $creator_fee_desc = 'Creator'; $runner_fee_desc = 'Runner'; $WorkItem = new WorkItem($bid->worklist_id); $fees = $WorkItem->getFees($WorkItem->getId()); foreach ($fees as $fee) { if ($fee['desc'] == $creator_fee_desc) { $this->deleteFee($fee['id']); } if ($fee['desc'] == $runner_fee_desc) { $this->deleteFee($fee['id']); } } } // additional changes if status is WORKING, SVNHOLD, FUNCTIONAL or REVIEW if (($job['status'] == 'In Progress' || $job['status'] == 'Review' || $job['status'] == 'QA Ready') && $bid->accepted == 1 && (!empty($_SESSION['is_runner']) || $bid->bidder_id == $_SESSION['userid'])) { // change status of worklist item mysql_unbuffered_query("UPDATE `" . WORKLIST . "`\n SET `mechanic_id` = '0',\n `status` = 'Bidding'\n WHERE `id` = {$bid->worklist_id}\n LIMIT 1 ;"); } // set back to suggested if swb and is only bid $res = mysql_query('SELECT count(*) AS count_bids FROM `' . BIDS . '` WHERE `worklist_id` = ' . $job['id'] . ' AND `withdrawn` = 0'); $bidCount = mysql_fetch_assoc($res); if ($bidCount['count_bids'] == 1 && $job['status'] == 'Bidding' && $bid->bidder_id == $_SESSION['userid'] && ($job['runner_id'] = 0)) { mysql_unbuffered_query("UPDATE `" . WORKLIST . "` SET `status` = 'Suggestion' WHERE `id` = {$bid->worklist_id} LIMIT 1 ;"); } // change bid to withdrawn and set bids.accepted to 0 mysql_unbuffered_query('UPDATE `' . BIDS . '` SET `withdrawn` = 1 , `accepted` = 0 WHERE `id` = ' . $bid->id); // delete the fee entry for this bid mysql_unbuffered_query('UPDATE `' . FEES . '` SET `withdrawn` = 1 WHERE `worklist_id` = ' . $bid->worklist_id . ' AND `user_id` = ' . $bid->bidder_id . ' AND `bid_id` = ' . $bid->id); // Get user $user = User::find($bid->bidder_id); // Journal message $message = 'A bid was deleted from #' . $job['id']; // Journal notification Utils::systemNotification($message); // Sending email to the bidder or runner $subject = "Bid: " . $job['id'] . " (" . $job['summary'] . ")"; if (!empty($_SESSION['is_runner'])) { // Send to bidder $recipient = $user; $body = "<p>Your bid has been deleted from item #" . $job['id'] . " by: " . $_SESSION['nickname'] . "</p>"; } else { // Send to runner $recipient = User::find($job['runner_id']); $body = "<p>A bid has been deleted from item #" . $job['id'] . " by: " . $_SESSION['nickname'] . "</p>"; } if (strlen($withdraw_reason) > 0) { // nl2br is added for proper formatting in email alert 12-MAR-2011 <webdev> $body .= "<p>Reason: " . nl2br($withdraw_reason) . "</p>"; } // Continue adding text to email body $item_link = SERVER_URL . $bid->worklist_id; $body .= "<p><a href='{$item_link}'>View Item</a></p>"; $body .= "<p>If you think this has been done in error, please contact the job Runner.</p>"; if (!Utils::send_email($recipient->getUsername(), $subject, $body)) { error_log("withdrawBid: Utils::send_email failed"); } // Check if there are any active bids remaining $res = mysql_query("SELECT count(*) AS active_bids FROM `" . BIDS . "` WHERE `worklist_id` = " . $job['id'] . " AND `withdrawn` = 0 AND (NOW() < `bid_expires` OR `bid_expires`='0000-00-00 00:00:00')"); $bids = mysql_fetch_assoc($res); if ($bids['active_bids'] < 1) { // There are no active bids, so resend notifications $workitem = new WorkItem(); $workitem->loadById($job['id']); Notification::massStatusNotify($workitem); } } }