Esempio n. 1
0
 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);
         }
     }
 }