/**
  * Sends a notification that a match has been modified by a public user
  *
  * @param Match $o_match
  * @param User $o_user
  * @param bool $b_is_new_match
  * @param bool $b_is_deleted_match
  */
 public function MatchUpdated(Match $o_match, User $o_user, $b_is_new_match = false, $b_is_deleted_match = false)
 {
     # Don't send email if match added by a trusted administrator
     if ($o_user->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES)) {
         return;
     }
     # Match may have been added to multiple seasons (though this is theoretical because at the time
     # of writing only an admin can add to multiple seasons... and they don't generate emails.)
     # Nevertheless the object model is geared to that possibility and this way the code makes sense
     # of the object model.
     if ($o_match->Seasons()->GetCount()) {
         $emails_to_send = array();
         foreach ($o_match->Seasons() as $season) {
             /* @var $season Season */
             ### Find the email address to notify for this season. ###
             # If the competition has a manager, use their email address...
             $email = '';
             if (!is_null($season->GetCompetition()) and $season->GetCompetition()->GetNotificationEmail()) {
                 # ...but don't email the competition manager if they're adding/updating the match!
                 if ($season->GetCompetition()->GetNotificationEmail() == $o_user->GetEmail()) {
                     continue;
                 }
                 $email = $season->GetCompetition()->GetNotificationEmail();
             } else {
                 # If there's no competition manager, send to backup email address
                 $email = $this->settings->GetMatchUpdatesEmail();
             }
             # Add the current season to the list of seasons to notify that email address about
             if ($email) {
                 if (!isset($emails_to_send[$email])) {
                     $emails_to_send[$email] = array();
                 }
                 $emails_to_send[$email][] = $season;
             }
         }
         # And now send an email to each address, listing the change for all the seasons they represent
         foreach ($emails_to_send as $email => $seasons) {
             $this->SendMatchUpdatedEmail($o_match, $o_user, $b_is_new_match, $b_is_deleted_match, $email, $seasons);
         }
     } else {
         # If there's no season there's no competition manager, send to backup email address
         $this->SendMatchUpdatedEmail($o_match, $o_user, $b_is_new_match, $b_is_deleted_match, $this->settings->GetMatchUpdatesEmail());
     }
 }
Example #2
0
function send_email_to_user($userid, $emailtext, $Build, $Project)
{
    require_once 'models/user.php';
    $User = new User();
    $User->Id = $userid;
    $email = $User->GetEmail();
    $sent = send_email_to_address($email, $emailtext, $Build, $Project);
    if ($sent) {
        // Record that we have sent the email
        set_email_sent($userid, $Build->Id, $emailtext);
    }
}
Example #3
0
 /** Send an email to the administrator of the project */
 function SendEmailToAdmin($subject, $body)
 {
     if (!$this->Id) {
         echo "Project SendEmailToAdmin(): Id not set";
         return false;
     }
     include 'cdash/config.php';
     // Check if we should send emails
     $project = pdo_query("SELECT emailadministrator,name FROM project WHERE id =" . qnum($this->Id));
     if (!$project) {
         add_last_sql_error("Project SendEmailToAdmin", $this->Id);
         return false;
     }
     $project_array = pdo_fetch_array($project);
     if ($project_array['emailadministrator'] == 0) {
         return;
     }
     // Find the site maintainers
     include_once 'models/userproject.php';
     include_once 'models/user.php';
     $UserProject = new UserProject();
     $UserProject->ProjectId = $this->Id;
     $userids = $UserProject->GetUsers(2);
     // administrators
     $email = "";
     foreach ($userids as $userid) {
         $User = new User();
         $User->Id = $userid;
         if ($email != "") {
             $email .= ", ";
         }
         $email .= $User->GetEmail();
     }
     if ($email != "") {
         $projectname = $project_array['name'];
         $emailtitle = "CDash [" . $projectname . "] - Administration ";
         $emailbody = "Object: " . $subject . "\n";
         $emailbody .= $body . "\n";
         $serverName = $CDASH_SERVER_NAME;
         if (strlen($serverName) == 0) {
             $serverName = $_SERVER['SERVER_NAME'];
         }
         $emailbody .= "\n-CDash on " . $serverName . "\n";
         if (cdashmail("{$email}", $emailtitle, $emailbody, "From: CDash <" . $CDASH_EMAIL_FROM . ">\nReply-To: " . $CDASH_EMAIL_REPLY . "\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0")) {
             add_log("email sent to: " . $email, "Project::SendEmailToAdmin");
             return;
         } else {
             add_log("cannot send email to: " . $email, "Project::SendEmailToAdmin", LOG_ERR, $this->Id);
         }
     }
     // end if email
 }
Example #4
0
             foreach ($files as $file) {
                 $messagePlainText .= $file['path'] . " (" . round($file['percent'], 2) . "%)\n";
             }
             $messagePlainText .= "Details on the submission can be found at ";
             $messagePlainText .= get_server_URI();
             $messagePlainText .= "\n\n";
             $serverName = $CDASH_SERVER_NAME;
             if (strlen($serverName) == 0) {
                 $serverName = $_SERVER['SERVER_NAME'];
             }
             $messagePlainText .= "\n-CDash on " . $serverName . "\n";
             // Send the email
             $title = "CDash [" . $Project->GetName() . "] - Low Coverage";
             $User = new User();
             $User->Id = $userid;
             $email = $User->GetEmail();
             cdashmail("{$email}", $title, $messagePlainText, "From: CDash <" . $CDASH_EMAIL_FROM . ">\nReply-To: " . $CDASH_EMAIL_REPLY . "\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0");
             $xml .= add_XML_value("warning", "*The email has been sent successfully.");
         } else {
             $xml .= add_XML_value("warning", "*No email sent because the coverage is green.");
         }
     }
 }
 // end sendEmail
 // If we change the priority
 if (isset($_POST['prioritySelection'])) {
     $CoverageFile2User = new CoverageFile2User();
     $CoverageFile2User->ProjectId = $projectid;
     $CoverageFile2User->FullPath = htmlspecialchars(pdo_real_escape_string($_POST['fullpath']));
     $CoverageFile2User->SetPriority(pdo_real_escape_numeric($_POST['prioritySelection']));
 }
Example #5
0
 /** Send an email to the administrator of the project */
 public function SendEmailToAdmin($subject, $body)
 {
     if (!$this->Id) {
         echo 'Project SendEmailToAdmin(): Id not set';
         return false;
     }
     include 'config/config.php';
     // Check if we should send emails
     $project = pdo_query('SELECT emailadministrator,name FROM project WHERE id =' . qnum($this->Id));
     if (!$project) {
         add_last_sql_error('Project SendEmailToAdmin', $this->Id);
         return false;
     }
     $project_array = pdo_fetch_array($project);
     if ($project_array['emailadministrator'] == 0) {
         return;
     }
     // Find the site maintainers
     $UserProject = new UserProject();
     $UserProject->ProjectId = $this->Id;
     $userids = $UserProject->GetUsers(2);
     // administrators
     $email = '';
     foreach ($userids as $userid) {
         $User = new User();
         $User->Id = $userid;
         if ($email != '') {
             $email .= ', ';
         }
         $email .= $User->GetEmail();
     }
     if ($email != '') {
         $projectname = $project_array['name'];
         $emailtitle = 'CDash [' . $projectname . '] - Administration ';
         $emailbody = 'Object: ' . $subject . "\n";
         $emailbody .= $body . "\n";
         $serverName = $CDASH_SERVER_NAME;
         if (strlen($serverName) == 0) {
             $serverName = $_SERVER['SERVER_NAME'];
         }
         $emailbody .= "\n-CDash on " . $serverName . "\n";
         if (cdashmail("{$email}", $emailtitle, $emailbody)) {
             add_log('email sent to: ' . $email, 'Project::SendEmailToAdmin');
             return;
         } else {
             add_log('cannot send email to: ' . $email, 'Project::SendEmailToAdmin', LOG_ERR, $this->Id);
         }
     }
 }
 /**
  * @return int or false
  * @param User $user
  * @desc Save the supplied object to the database, and return the id
  */
 public function SaveUser($user)
 {
     # check parameters
     if (!$user instanceof User) {
         throw new Exception('Unable to save person');
     }
     # build query
     $table = $this->GetSettings()->GetTable('User');
     $this->Lock($table);
     $s_sql = "UPDATE {$table} SET " . "known_as = " . Sql::ProtectString($this->GetDataConnection(), $user->GetName()) . ", " . "name_first = " . Sql::ProtectString($this->GetDataConnection(), $user->GetFirstName()) . ", " . "name_last = " . Sql::ProtectString($this->GetDataConnection(), $user->GetLastName()) . ", " . "name_sort = " . Sql::ProtectString($this->GetDataConnection(), $user->GetSortName()) . ", " . "email = " . Sql::ProtectString($this->GetDataConnection(), $user->GetEmail()) . ", " . 'date_changed = ' . gmdate('U') . ' ' . 'WHERE user_id = ' . Sql::ProtectNumeric($user->GetId());
     $result = $this->GetDataConnection()->query($s_sql);
     $this->Unlock();
     $success = !$this->GetDataConnection()->isError();
     return $success ? $user->GetId() : false;
 }