Example #1
0
 /**
  * @return bool Whether the operation was successful
  */
 public function toggleInternal($user_id)
 {
     $user = new User();
     $user->findUserById($user_id);
     if ($user->isInternal()) {
         if ($this->isInternal()) {
             $this->setIs_internal(false);
         } else {
             $this->setIs_internal(true);
         }
     } else {
         return false;
     }
     $this->save();
     return true;
 }
Example #2
0
 public function listView($projectName = null, $filterName = null)
 {
     $this->view = new JobsView();
     // $nick is setup above.. and then overwritten here -- lithium
     $nick = '';
     $userId = Session::uid();
     if ($userId > 0) {
         Utils::initUserById($userId);
         $user = new User();
         $user->findUserById($userId);
         // @TODO: this is overwritten below..  -- lithium
         $nick = $user->getNickname();
         $userbudget = $user->getBudget();
         $budget = number_format($userbudget);
         $this->is_internal = $user->isInternal();
     }
     $this->is_runner = !empty($_SESSION['is_runner']) ? 1 : 0;
     $is_payer = !empty($_SESSION['is_payer']) ? 1 : 0;
     $is_admin = !empty($_SESSION['is_admin']) ? 1 : 0;
     $workitem = new WorkItem();
     $queryFilter = empty($_REQUEST['query']) ? '' : $_REQUEST['query'];
     $this->write('queryFilter', $queryFilter);
     $this->write('followingFilter', $filterName != null && $filterName == "following" ? true : false);
     if ($projectName != null && $projectName != "all") {
         $project = Project::find($projectName);
         $this->write('projectFilter', $project ? $project->getProjectId() : 0);
     } else {
         $this->write('projectFilter', 0);
     }
     if ($filterName != null && $filterName != "following") {
         $this->write('statusFilter', $filterName);
     } else {
         $this->write('statusFilter', empty($queryFilter) ? 'Active' : 'All');
     }
     $this->write('labelsFilter', array_slice(func_get_args(), 2));
     // Prevent reposts on refresh
     if (!empty($_POST)) {
         unset($_POST);
         $this->view = null;
         Utils::redirect('./jobs');
         exit;
     }
     $worklist_id = isset($_REQUEST['job_id']) ? intval($_REQUEST['job_id']) : 0;
     $this->write('req_status', isset($_GET['status']) ? $_GET['status'] : '');
     $this->write('review_only', isset($_GET['status']) && $_GET['status'] == 'needs-review' ? 'true' : 'false');
     parent::run();
 }
Example #3
0
 /**
  *  This function notifies selected recipients about updates of workitems
  * except for currently logged in user
  *
  * @param Array $options - Array with options:
  * type - type of notification to send out
  * workitem - workitem object with updated data
  * recipients - array of recipients of the message ('creator', 'runner', 'mechanic')
  * emails - send message directly to list of emails (array) -
  * if 'emails' is passed - 'recipients' option is ignored
  * @param Array $data - Array with additional data that needs to be passed on
  * @param boolean $includeSelf - force user receive email from self generated action
  * example: 'who' and 'comment' - if we send notification about new comment
  */
 public static function workitemNotify($options, $data = null, $includeSelf = true)
 {
     $recipients = isset($options['recipients']) ? $options['recipients'] : null;
     $emails = isset($options['emails']) ? $options['emails'] : array();
     $workitem = $options['workitem'];
     $current_user = User::find(Session::uid());
     if (isset($options['project_name'])) {
         $project_name = $options['project_name'];
     } else {
         try {
             $project = new Project();
             $project->loadById($workitem->getProjectId());
             $project_name = $project->getName();
         } catch (Exception $e) {
             error_log($e->getMessage() . " Workitem: #" . $workitem->getId() . " " . " has an invalid project id:" . $workitem->getProjectId());
             $project_name = "";
         }
     }
     $revision = isset($options['revision']) ? $options['revision'] : null;
     $itemId = $workitem->getId();
     $itemLink = '<a href="' . WORKLIST_URL . $itemId . '">#' . $itemId . '</a>';
     $itemTitle = '#' . $itemId . ' (' . $workitem->getSummary() . ')';
     $itemTitleWithProject = '#' . $itemId . ': ' . $project_name . ': (' . $workitem->getSummary() . ')';
     $itemLinkTitle = '<a href="' . WORKLIST_URL . $itemId . '">#' . $itemId . ' - ' . $workitem->getSummary() . '</a>';
     $body = '';
     $subject = '#' . $itemId . ' ' . html_entity_decode($workitem->getSummary(), ENT_QUOTES);
     $from_address = '<noreply-' . $project_name . '@worklist.net>';
     $headers = array('From' => '"' . $project_name . '-' . strtolower($workitem->getStatus()) . '" ' . $from_address);
     switch ($options['type']) {
         case 'comment':
             $headers['From'] = '"' . $project_name . '-comment" ' . $from_address;
             $headers['Reply-To'] = '"' . $_SESSION['nickname'] . '" <' . $_SESSION['username'] . '>';
             $commentUrl = WORKLIST_URL . $workitem->getId() . '#comment-' . $data['comment-id'];
             $commentLink = ' <a href="' . $commentUrl . '">commented</a> ';
             $body .= $data['who'] . $commentLink . ' on ' . $itemLink . ':<br>' . nl2br($data['comment']) . '<br /><br />';
             if ($current_user->getSelf_notif()) {
                 array_push($emails, $current_user->getUsername());
             }
             break;
         case 'fee_added':
             if ($workitem->getStatus() != 'Draft') {
                 $headers['From'] = '"' . $project_name . '-fee added" ' . $from_address;
                 $body = 'New fee was added to the item ' . $itemLink . '.<br>' . 'Who: ' . $data['fee_adder'] . '<br/>' . 'Amount: ' . $data['fee_amount'] . '<br/>' . '<div>Fee Notes:<br/> ' . nl2br(stripslashes($data['fee_desc'])) . '</div><br/><br/>' . 'Project: ' . $project_name . '<br/>' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
                 if ($workitem->getRunner() != '') {
                     $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
                 }
                 if ($workitem->getMechanic() != '') {
                     $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
                 }
                 $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
             }
             break;
         case 'fee_deleted':
             if ($workitem->getStatus() != 'Draft') {
                 $headers['From'] = '"' . $project_name . '-fee deleted" ' . $from_address;
                 $body = "<p>Your fee has been deleted by: " . $_SESSION['nickname'] . "<br/><br/>";
                 $body .= "If you think this has been done in error, please contact the job Designer.</p>";
                 $body .= 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
                 if ($workitem->getRunner() != '') {
                     $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
                 }
                 if ($workitem->getMechanic() != '') {
                     $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
                 }
                 $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
             }
             break;
         case 'tip_added':
             $headers['From'] = '"' . $project_name . '-tip added" ' . $from_address;
             $body = $data['tip_adder'] . ' tipped you $' . $data['tip_amount'] . ' on job ' . $itemLink . ' for:<br><br>' . $data['tip_desc'] . '<br><br>Yay!' . '<br /><br />' . 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunner() != '') {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             if ($workitem->getMechanic() != '') {
                 $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
             }
             $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
             break;
         case 'bid_accepted':
             $headers['From'] = '"' . $project_name . '-bid accepted" ' . $from_address;
             $body = 'Your bid was accepted for ' . $itemLink . '<br/><br />' . 'If this job requires you to create code, please read through and then follow our coding ' . 'standards which are found <a href="https://github.com/highfidelity/hifi/wiki/Coding-Standard">here</a>.<br/><br/>' . 'Promised by: ' . $_SESSION['nickname'] . '<br /><br />' . 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunner() != '') {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             if ($workitem->getMechanic() != '') {
                 $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
             }
             $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'The job can be viewed <a href="' . WORKLIST_URL . $itemId . '">here</a><br /><br />';
             // render the github branch-created-sub template if necessary
             if (!empty($data) && array_key_exists('branch_name', $data)) {
                 $template = 'branch-created-sub';
                 include APP_PATH . '/email/en.php';
                 $replacedTemplate = !empty($data) ? Utils::templateReplace($emailTemplates[$template], $data) : $emailTemplates[$template];
                 $body .= $replacedTemplate['body'];
             }
             $body .= '<br /><a href="' . SERVER_URL . '">www.worklist.net</a>';
             break;
         case 'bid_placed':
             $projectId = $workitem->getProjectId();
             $jobsInfo = $options['jobsInfo'];
             $lastThreeJobs = $jobsInfo['joblist'];
             $workItemUrl = '<a href="' . WORKLIST_URL;
             //create the last three jobs and link them to those Jobs.
             foreach ($lastThreeJobs as $row) {
                 $jobs .= $workItemUrl;
                 $jobs .= $row['id'] . '">#' . $row['id'] . '</a>' . ' - ' . $row['summary'] . '<br /><br />';
             }
             //if no Jobs then display 'None'
             if (!$jobs) {
                 $jobs = 'None <br />';
             }
             //now get total jobs and total jobs and create links
             $totalJobs = $workItemUrl;
             $totalJobs .= $workitem->getId() . '?action=view&userinfotoshow=' . $_SESSION['userid'] . '">' . $options['totalJobs'] . ' jobs in total</a><br />';
             $totalActiveJobs = $workItemUrl;
             $totalActiveJobs .= $workitem->getId() . '?action=view&userinfotoshow=' . $_SESSION['userid'] . '">' . $options['activeJobs'] . ' jobs currently active</a>';
             $urlAcceptBid = $workItemUrl;
             $urlAcceptBid .= $itemId . '?bid_id=' . $data['bid_id'] . '&action=view_bid">Accept ' . $_SESSION['nickname'] . '\'s bid</a>';
             $body .= $urlAcceptBid;
             $bidder_address = '<' . $_SESSION['username'] . '>';
             $headers['From'] = '"' . $project_name . '-new bid" ' . $bidder_address;
             $body = ' New bid from <a href="' . SERVER_URL . 'user/' . $_SESSION['userid'] . '">' . $_SESSION['nickname'] . '</a> on: <br />' . $itemLink . ' ' . $workitem->getSummary() . '<br />' . '----------------------------------------------------------------<br /><br />' . 'Amount: $' . number_format($data['bid_amount'], 2) . '<br />' . 'Functioning in: ' . $data['done_in'] . '<br />' . '----<br />' . 'Notes: ' . '<br />' . ' ' . nl2br(stripslashes($data['notes'])) . '<br />' . '----<br />' . $urlAcceptBid . ' / reply to this email to ask questions or <a href="https://gitter.im/highfidelity/worklist">chat via Gitter</a><br /><br />' . '----------------------------------------------------------------<br />' . '<a href="' . SERVER_URL . 'user/' . $_SESSION['userid'] . '">' . $_SESSION['nickname'] . '\'s profile</a> / ' . $totalActiveJobs . ' / ' . $totalJobs . '<br />' . '----------------------------------------------------------------';
             break;
         case 'bid_updated':
             $projectId = $workitem->getProjectId();
             $jobsInfo = $options['jobsInfo'];
             $lastThreeJobs = $jobsInfo['joblist'];
             $workItemUrl = '<a href="' . WORKLIST_URL;
             //create the last three jobs and link them to those Jobs.
             foreach ($lastThreeJobs as $row) {
                 $jobs .= $workItemUrl;
                 $jobs .= $row['id'] . '">#' . $row['id'] . '</a>' . ' - ' . $row['summary'] . '<br /><br />';
             }
             //if no Jobs then display 'None'
             if (!$jobs) {
                 $jobs = 'None <br />';
             }
             //now get total jobs and total jobs and create link
             $totalJobs = $workItemUrl;
             $totalJobs .= $workitem->getId() . '?action=view&userinfotoshow=' . $_SESSION['userid'] . '">' . $options['totalJobs'] . ' jobs in total</a><br />';
             $totalActiveJobs = $workItemUrl;
             $totalActiveJobs .= $workitem->getId() . '?action=view&userinfotoshow=' . $_SESSION['userid'] . '">' . $options['activeJobs'] . ' jobs currently active</a>';
             $urlAcceptBid = $workItemUrl;
             $urlAcceptBid .= $itemId . '?bid_id=' . $data['bid_id'] . '&action=view_bid">Accept ' . $_SESSION['nickname'] . '\'s bid</a>';
             $body .= $urlAcceptBid;
             $bidder_address = '<' . $_SESSION['username'] . '>';
             $headers['From'] = '"' . $project_name . '-bid updated" ' . $bidder_address;
             $body = 'Bid updated by <a href="' . SERVER_URL . 'user/' . $_SESSION['userid'] . '">' . $_SESSION['nickname'] . '</a> on: <br />' . $itemLink . ' ' . $workitem->getSummary() . '<br />' . '----------------------------------------------------------------<br /><br />' . 'Amount: $' . number_format($data['bid_amount'], 2) . '<br />' . 'Functioning in: ' . $data['done_in'] . '<br />' . '----<br />' . 'Notes: ' . '<br />' . ' ' . nl2br(stripslashes($data['notes'])) . '<br />' . '----<br />' . $urlAcceptBid . ' / reply to this email to ask questions or <a href="https://gitter.im/highfidelity/worklist">chat via Gitter</a><br /><br />' . '----------------------------------------------------------------<br />' . '<a href="' . SERVER_URL . 'user/' . $_SESSION['userid'] . '">' . $_SESSION['nickname'] . '\'s profile</a> / ' . $totalActiveJobs . ' / ' . $totalJobs . '<br />' . '----------------------------------------------------------------';
             break;
         case 'bid_discarded':
             $headers['From'] = '"' . $project_name . '-bid not accepted" ' . $from_address;
             $body = "<p>Hello " . $data['who'] . ",</p>";
             $body .= "<p>Thanks for adding your bid to <a href='" . WORKLIST_URL . $itemId . "'>#" . $itemId . "</a> '" . $workitem->getSummary() . "'. This job has just been filled by another developer.</br></p>";
             $body .= "There is lots of work to be done so please keep checking the <a href='" . SERVER_URL . "'>worklist</a> and bid on another job soon!</p>";
             $body .= "<p>Hope to see you in the Worklist soon. :)</p>";
             break;
         case 'modified':
             if ($workitem->getStatus() != 'Draft') {
                 $from_changes = "";
                 if (!empty($options['status_change']) && $workitem->getStatus() == 'QA Ready') {
                     $status_change = '-' . strtolower($workitem->getStatus());
                     $headers['From'] = '"' . $project_name . $status_change . '" ' . $from_address;
                     $body = $_SESSION['nickname'] . ' set ' . $itemLink . ' to QA Ready.<br /><br />' . 'Check out the work: ' . $workitem->getSandbox() . '<br /><br />' . 'Checkout the branch created for this job: git checkout ' . $workitem->getSandbox() . ' .<br /><br />' . '<a href="' . WORKLIST_URL . $itemId . '">Leave a comment on the Job</a>';
                 } else {
                     if (!empty($options['status_change'])) {
                         $from_changes = $options['status_change'];
                     }
                     if (isset($options['job_changes'])) {
                         if (count($options['job_changes']) > 0) {
                             $from_changes .= $options['job_changes'][0];
                             if (count($options['job_changes']) > 1) {
                                 $from_changes .= ' +other changes';
                             }
                         }
                     }
                     if (!empty($from_changes)) {
                         $headers['From'] = '"' . $project_name . $from_changes . '" ' . $from_address;
                     } else {
                         $status_change = '-' . strtolower($workitem->getStatus());
                         $headers['From'] = '"' . $project_name . $status_change . '" ' . $from_address;
                     }
                     $body = $_SESSION['nickname'] . ' updated item ' . $itemLink . '<br>' . $data['changes'] . '<br /><br />' . 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
                     if ($workitem->getRunner() != '') {
                         $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
                     }
                     if ($workitem->getMechanic() != '') {
                         $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
                     }
                     $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
                 }
             }
             break;
         case 'new_bidding':
             $urlPlacebid = '<a href="' . WORKLIST_URL . $itemId . '?placeBid">Submit a bid</a>';
             $body = "Now accepting bids: <br />" . $itemLink . ' ' . $workitem->getSummary() . '<br />' . '----------------------------------------------------------------<br />' . 'Project: ' . '<a href="' . SERVER_URL . $project_name . '">' . $project_name . '</a>' . ' / Creator: ' . '<a href="' . SERVER_URL . 'user/' . $workitem->getCreator()->getNickname() . '">' . $workitem->getCreator()->getNickname() . '<a>';
             if ($workitem->getRunner() != '') {
                 $body .= ' / Designer: ' . '<a href="' . SERVER_URL . 'user/' . $workitem->getRunner()->getNickname() . '">' . $workitem->getCreator()->getNickname() . '<a> <br />' . '----------------------------------------------------------------<br />';
             }
             $body .= 'Notes:<br /> ' . nl2br(stripslashes($workitem->getNotes())) . '<br />' . '----------------------------------------------------------------<br />' . '<a href="' . WORKLIST_URL . $itemId . '">View the job</a>' . ' / ' . $urlPlacebid;
             break;
         case 'new_qa':
             $body = $_SESSION['nickname'] . ' set ' . $itemLink . ' to QA Ready.<br /><br />' . 'Check out the work: ' . $workitem->getSandbox() . '<br /><br />' . 'Checkout the branch created for this job: git checkout ' . $workitem->getSandbox() . ' .<br /><br />' . '<a href="' . WORKLIST_URL . $itemId . '">Leave a comment on the Job</a>';
             break;
         case 'new_review':
             $body = "Now ready for a code review: " . $itemLinkTitle . ' <br /><br />';
             break;
         case 'suggested':
             $body = 'Summary: ' . $itemLink . '<br /><br />' . 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunner() != '') {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             if ($workitem->getMechanic() != '') {
                 $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '<br /><br />';
             }
             $body .= 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
             break;
         case 'code-review-completed':
             $headers['From'] = '"' . $project_name . '-review complete" ' . $from_address;
             $body = '<p>Hello,</p>';
             $body .= '<p>The code review on task ' . $itemLink . ' has been completed by ' . $_SESSION['nickname'] . '</p>';
             $body .= '<br>';
             $body .= '<p>Project: ' . $project_name . '<br />';
             $body .= 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             $body .= 'Developer: ' . $workitem->getMechanic()->getNickname() . '</p>';
             $body .= '<p>Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /></p>';
             $body .= '<p>You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /></p>';
             $body .= '<p><a href="' . SERVER_URL . '">www.worklist.net</a></p>';
             break;
         case 'expired_bid':
             $headers['From'] = '"' . $project_name . '-expired bid" ' . $from_address;
             $body = "<p>Job " . $itemLink . "<br />";
             $body .= "Your Bid on #" . $itemId . " has expired and this task is still available for Bidding.</p>";
             $body .= "<p>Bidder: " . $data['bidder_nickname'] . "<br />";
             $body .= "Bid Amount : \$" . $data['bid_amount'] . "</p>";
             $body .= '<p>Project: ' . $project_name . '<br />';
             $body .= 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunnerId()) {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             $body .= '<p>Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /></p>';
             $body .= '<p>You can view the job ';
             $body .= '<a href="' . WORKLIST_URL . $itemId . '">here</a>.<br /></p>';
             $body .= '<p><a href="' . SERVER_URL . '">www.worklist.net</a></p>';
             break;
         case 'auto-pass':
             $headers['From'] = '"' . $project_name . "- Auto PASSED" . '" ' . $from_address;
             if (isset($data['prev_status']) && $data['prev_status'] == 'Bidding') {
                 $headers['From'] = '"' . $project_name . "- BIDDING Item Auto PASSED" . '" ' . $from_address;
                 $body = "Otto has triggered an auto-PASS for job #" . $itemId . ". You may reactivate this job by updating the status or contacting an admin." . '<br/><br/>';
             } else {
                 $body = "Otto has triggered an auto-PASS for your suggested job. You may reactivate this job by updating the status or contacting an admin." . '<br/><br/>';
             }
             $body .= "Summary: " . $itemLink . ": " . $workitem->getSummary() . '<br/>' . 'Project: ' . $project_name . '<br />' . 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />' . 'Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /><br />' . 'You can view the job <a href="' . WORKLIST_URL . $itemId . '">here</a>.' . '<br /><br />' . '<a href="' . SERVER_URL . '">www.worklist.net</a>';
             break;
         case 'virus-found':
             $headers['From'] = '"' . $project_name . '-upload error" ' . $from_address;
             $body = '<p>Hello, <br /><br /> The file ' . $options['file_name'] . ' (' . $options['file_title'] . ') ' . 'that you uploaded for this workitem was scanned and found to be containing a virus and will be quarantined. <br /><br />' . 'Please upload a clean copy of the file.</p>';
             $body .= '<p>Project: ' . $project_name . '<br />';
             $body .= 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunnerId()) {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             $body .= '<p>Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /></p>';
             $body .= '<p>You can view the job ';
             $body .= '<a href="' . WORKLIST_URL . $itemId . '">here</a>.<br /></p>';
             $body .= '<p><a href="' . SERVER_URL . '">www.worklist.net</a></p>';
             break;
         case 'virus-error':
             $headers['From'] = '"' . $project_name . '-upload error" ' . $from_address;
             $body = '<p>Hello, <br /><br /> The file ' . $options['file_name'] . ' (' . $options['file_title'] . ') ' . 'that you uploaded for this workitem caused an unknown error during scanning. <br /><br />' . 'Please upload a clean copy of the file.</p>';
             $body .= '<p>Project: ' . $project_name . '<br />';
             $body .= 'Creator: ' . $workitem->getCreator()->getNickname() . '<br />';
             if ($workitem->getRunnerId()) {
                 $body .= 'Designer: ' . $workitem->getRunner()->getNickname() . '<br />';
             }
             $body .= '<p>Notes:<br/> ' . nl2br($workitem->getNotes()) . '<br /></p>';
             $body .= '<p>You can view the job ';
             $body .= '<a href="' . WORKLIST_URL . $itemId . '">here</a>.<br /></p>';
             $body .= '<p><a href="' . SERVER_URL . '">www.worklist.net</a></p>';
             break;
         case 'change-designer':
             $headers['From'] = '"' . $project_name . '-designer reassigned" ' . $from_address;
             $body = "<p>Hi there,</p>";
             $body .= "<p>I just wanted to let you know that the Job #" . $workitem->getId() . " (" . $workitem->getSummary() . ") has been reassigned to Designer " . $data['runner_nickname'] . ".</p>";
             $body .= "<p>See you in the Worklist!</p>";
             break;
     }
     if ($recipients) {
         foreach ($recipients as $recipient) {
             /**
              *  If there is need to get a new list of users
              *  just add a get[IDENTIFIER]Id function to
              *  workitem.class.php that returns a single user id
              *  or an array with user ids */
             $method = 'get' . ucfirst($recipient) . 'Id';
             $recipientUsers = $workitem->{$method}();
             if (!is_array($recipientUsers)) {
                 $recipientUsers = array($recipientUsers);
             }
             foreach ($recipientUsers as $recipientUser) {
                 if ($recipientUser > 0) {
                     //Does the recipient exists
                     $rUser = new User();
                     $rUser->findUserById($recipientUser);
                     $sendNotification = ($workitem->isInternal() ? $rUser->isInternal() : true) && ($options['type'] == 'comment' && $rUser->getId() == Session::uid() ? $rUser->getSelf_notif() : true);
                     if ($sendNotification) {
                         if ($username = $rUser->getUsername()) {
                             array_push($emails, $username);
                         }
                     }
                 }
             }
         }
     }
     $emails = array_unique($emails);
     if (count($emails) > 0) {
         foreach ($emails as $email) {
             // Small tweak for mails to followers on bid acceptance
             if ($options['type'] == 'bid_accepted' && strcmp($email, $workitem->getMechanic()->getUsername())) {
                 $body = str_replace('Your', $workitem->getMechanic()->getNickname() . "'s", $body);
             }
             if (!Utils::send_email($email, $subject, $body, null, $headers)) {
                 error_log("Notification:workitem: Utils::send_email failed " . json_encode(error_get_last()));
             }
         }
     }
 }
Example #4
0
 public function userIsInternal()
 {
     $user = new User($this->currentUser['id']);
     return $user->isInternal();
 }