예제 #1
0
 public function render()
 {
     $this->jobId = $this->read('jobId');
     if ($this->jobId > 0) {
         $this->editing = true;
         $this->workItem = WorkItem::getById($this->jobId);
         $WorkItem = new WorkItem();
         $this->worklist = $WorkItem->getWorkItem($this->jobId);
         $this->title = 'Edit #' . $this->jobId . ' job - Worklist';
     }
     return parent::render();
 }
예제 #2
0
 public function status()
 {
     $statuses = WorkItem::getStates();
     $ret = array();
     $default = isset($_REQUEST['status']) ? $_REQUEST['status'] : 'Done';
     foreach ($statuses as $status) {
         $ret[] = array('status' => $status, 'selected' => $default == $status);
     }
     return $ret;
 }
예제 #3
0
 public function biddingJobs()
 {
     $jobs = $this->read('biddingJobs');
     $ret = array();
     foreach ($jobs as $key => $job_number) {
         $workitem = WorkItem::getById($job_number);
         if (!$workitem->getProjectId()) {
             continue;
         }
         $project = Project::getById($workitem->getProjectId());
         $ret[] = array('id' => $workitem->getId(), 'summary' => $workitem->getSummary(), 'labels' => $workitem->getLabels(), 'project' => $project->getName());
     }
     return $ret;
 }
예제 #4
0
 public function setPaid($id, $paid)
 {
     try {
         $user = User::find(Session::uid());
         // Check if we have a payer
         if (!$user->isPayer()) {
             throw new Exception('Nothing to see here. Move along!');
         }
         // Get clean data
         $paid = $paid ? true : false;
         $notes = trim($_POST['notes']);
         if (!$notes) {
             throw new Exception('You must write a note!');
         }
         $fund_id = Fee::getFundId($id);
         // Exit of this script
         if (!Fee::markPaidById($id, $user->getId(), $notes, $paid, false, $fund_id)) {
             throw new Exception('Payment Failed!');
         }
         /* Only send the email when marking as paid. */
         if ($paid) {
             $fee = Fee::getFee($fee_id);
             $workitem = new WorkItem($fee['worklist_id']);
             $summary = $workitem->getSummary();
             $fee_user = User::find($fee['user_id']);
             $subject = "Worklist.net paid you " . $fee['amount'] . " for " . $summary;
             $body = "Your Fee was marked paid.<br/>" . "Job <a href='" . SERVER_URL . $fee['worklist_id'] . "'>#" . $fee['worklist_id'] . ': ' . $summary . '</a><br/>' . "Fee Description : " . nl2br($fee['desc']) . "<br/>" . "Paid Notes : " . nl2br($notes) . "<br/><br/>" . "Contact the job Designer with any questions<br/><br/>Worklist.net<br/>";
             if (!Utils::send_email($fee_user->getUsername(), $subject, $body)) {
                 error_log("FeeController::setPaid: Utils::send_email failed");
             }
         }
         return $this->setOutput(array('success' => true, 'notes' => 'Payment has been saved!'));
     } catch (Exception $e) {
         return $this->setOutput(array('success' => false, 'notes' => $e->getMessage()));
     }
 }
예제 #5
0
 public static function getById($id)
 {
     $workitem = new WorkItem();
     $workitem->loadById($id);
     return $workitem;
 }
예제 #6
0
function getMultipleBidList()
{
    $job_id = isset($_REQUEST['job_id']) ? (int) $_REQUEST['job_id'] : 0;
    if ($job_id == 0) {
        echo $job_id;
        return;
    }
    $workItem = new WorkItem();
    $bids = $workItem->getBids($job_id);
    $ret = array();
    foreach ($bids as $bid) {
        $bid['expired'] = $bid['expires'] <= BID_EXPIRE_WARNING;
        $bid['expires_text'] = Utils::relativeTime($bid['expires'], false, false, false, false);
        $ret[] = $bid;
    }
    echo json_encode(array('bids' => $ret));
    return;
}
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 public static function isJobId($id)
 {
     if (WorkItem::idExists($id)) {
         return true;
     }
     return false;
 }
예제 #9
0
 /**
  * Checks whether a #<number> string should be taken as a workitem link or not.
  * This function is used as a callback with preg_replace_callback (see below lines)
  */
 function workitemLinkPregReplaceCallback($matches)
 {
     $job_id = (int) $matches[1];
     if ($job_id < 99999 && WorkItem::idExists($job_id)) {
         return DELIMITER . '<a href="' . WORKLIST_URL . $job_id . '"' . ' class="worklist-item" id="worklist-' . $job_id . '" >#' . $job_id . '</a>' . DELIMITER . $matches[2];
     } else {
         return $matches[0];
     }
 }
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @category  Microsoft
 * @package   DealOfTheDay
 * @author    Ben Lobaugh <*****@*****.**>
 * @copyright 2011 Copyright Microsoft Corporation. All Rights Reserved
 * @license   http://www.apache.org/licenses/LICENSE-2.0
 **/
//set error handler
//set_error_handler("customError");
require_once 'include.php';
$work = new WorkItem('');
$timer->mark('start_perf_subscriptions');
// Ensure that all the roles currently running are submitting metrics information
// this may not work the first time the worker runs if the web roles are not yet running
// run it again till the web roles accept it
do {
    $again = false;
    try {
        add_perf_counters(find_role_instances_by_name('WebRole'));
    } catch (Exception $e) {
        echo "\nUnable to add performance counters on worker statup. Web roles may still be starting.";
        echo "\nTrying again in 10 seconds...";
        print_r($e);
        sleep(10);
        $again = true;
    }
예제 #11
0
 public function scanFile($id)
 {
     set_time_limit(15 * 60);
     //scan_files = array();
     $sql_get_files = 'SELECT `id`, `userid`,(SELECT `username` FROM `' . USERS . '` where `id`=files.userid)
     AS `useremail`, files.workitem AS `worklist_id`, `url`, `title`, `description`
     FROM `' . FILES . '` WHERE id=' . $id;
     $result = mysql_query($sql_get_files);
     $row = mysql_fetch_assoc($result);
     // Get the file name.
     $file_name = pathinfo(parse_url($row['url'], PHP_URL_PATH), PATHINFO_BASENAME);
     // Get the full path and prepare it for the command line.
     $real_path = UPLOAD_PATH . '/' . $file_name;
     $safe_path = escapeshellarg($real_path);
     // Reset the values.
     $return = -1;
     $out = '';
     $cmd = VIRUS_SCAN_CMD . ' ' . $safe_path;
     $fct_return = false;
     if (!empty($safe_path) && file_exists($real_path) && filesize($real_path) > 0) {
         // Execute the command.
         exec($cmd, $out, $return);
         if ($return == 0) {
             //if clean update db
             $sql = 'UPDATE `' . FILES . '` SET is_scanned = 1, scan_result = 0 WHERE `id` = ' . $id;
             $notify = '';
             $fct_return = true;
         } else {
             $workitem = new WorkItem();
             $workitem->loadById($row['worklist_id']);
             if ($return == 1) {
                 // If the file contains a virus send email to the user and update db.
                 $notify = 'virus-found';
                 $sql = 'UPDATE `' . FILES . '` SET is_scanned = 1, scan_result = 1 WHERE `id` = ' . $id;
             } else {
                 // <unknown error
                 $notify = 'virus-error';
                 $sql = 'UPDATE `' . FILES . '` SET is_scanned = 1, scan_result = 2 WHERE `id` = ' . $id;
             }
         }
         if (mysql_query($sql)) {
             // send mail if there's a problem
             if (!empty($notify)) {
                 Notification::workitemNotify(array('type' => $notify, 'workitem' => $workitem, 'emails' => array($row['useremail']), 'file_name' => $file_name, 'file_title' => $row['title']));
                 if (!Utils::send_email($row['title'], $subject, $message)) {
                     //Don't fail silently if we can't send the message also
                     error_log("cron ScanAssets: Utils::send_email failed, msg: " . $message);
                 }
             }
         } else {
             error_log('error SQL');
         }
     }
     return $fct_return;
 }
예제 #12
0
 public function listForJob($job_id)
 {
     try {
         $files = File::fetchAllFilesForWorkitem($job_id);
         $user = User::find(Session::uid());
         if (!$user->getId()) {
             throw new Exception('Not enough rights');
         }
         $job = WorkItem::getById($job_id);
         $data = array();
         foreach ($files as $file) {
             if (!File::isAllowed($file->getStatus(), $user) || !$file->getIs_scanned()) {
                 continue;
             }
             $fileUrl = $file->getUrl();
             $iconUrl = $file->getUrl();
             $userInvolved = $user->getId() == $file->getUserid() || $user->getId() == $job->getCreatorId() || $user->getId() == $job->getMechanicId() || $user->getId() == $job->getRunnerId();
             $icon = File::getIconFromMime($file->getMime());
             $data[] = array('fileid' => $file->getId(), 'url' => $fileUrl, 'can_delete' => $user->isRunner() || $user->isPayer() || $userInvolved, 'title' => $file->getTitle(), 'description' => $file->getDescription());
         }
         return $this->setOutput(array('success' => true, 'data' => $data));
     } catch (Exception $e) {
         return $this->setOutput(array('success' => false, 'message' => $e->getMessage()));
     }
 }
예제 #13
0
 private function deleteFee($fee_id)
 {
     $workitem = new WorkItem($fee->worklist_id);
     $res = mysql_query('SELECT * FROM `' . FEES . '` WHERE `id`=' . $fee_id);
     $fee = mysql_fetch_object($res);
     // checking if is bidder or runner
     if (!empty($_SESSION['is_runner']) || $fee->user_id == $_SESSION['userid']) {
         mysql_unbuffered_query('UPDATE `' . FEES . '`
                                     SET `withdrawn` = 1
                                     WHERE `id` = ' . $fee_id);
         // Get worklist item summary
         $summary = $workitem->getSummary();
         // Get user
         $user = User::find($fee->user_id);
         if ($user->getId()) {
             // Journal message
             $message = '@' . $_SESSION['nickname'] . ' deleted a fee from @';
             $message .= $user->getNickname() . ' on #' . $fee->worklist_id;
             // Journal notification
             Utils::systemNotification($message);
             //sending email to the bidder
             $options = array();
             $options['emails'] = array($user->getUsername());
             $options['workitem'] = new WorkItem();
             $options['workitem']->loadById($fee->worklist_id);
             $options['type'] = "fee_deleted";
             Notification::workitemNotify($options);
             $data = array('nick' => $_SESSION['nickname'], 'fee_nick' => $user->getNickname());
             Notification::workitemNotifyHipchat($options, $data);
         }
     }
 }