Location: PHPKode > projects > Course-manager > courseman-0.1.1/send-confirmations.php
<?php
  header('Cache-Control: no-store');
  header('Content-type: text/html; charset=utf-8');
  require('local-criteria.php');
  require('global-php.php');
  $verbindung = database_connection($lang_database_failure[$language]);
  $PHP_AUTH_USER = $_SERVER["PHP_AUTH_USER"];
  $PHP_AUTH_PW = $_SERVER["PHP_AUTH_PW"];
  $amount = intval($_REQUEST["amount"]);
  if ($amount == 0) {
    $amount = 500;
  }
  $ergebnis = db_exec($verbindung,
  			"SELECT * FROM staff_authorization,superuser,"
				. "capability "
  				. "WHERE staff_authorization.id"
				. "=superuser.account "
				. "AND superuser.capability=capability.id "
				. "AND capability.name='registrants' "
				. "AND "
				. login_query_clauses(
					$PHP_AUTH_USER,
					$PHP_AUTH_PW));
  if (pg_numrows($ergebnis) < 1) {
    header('WWW-Authenticate: Basic realm="Kursverwaltung"');
    header("HTTP/1.0 401 Unauthorized");
    echo $lang_authentication_failure[$language];
    exit;
  }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?=$lang_sending_confirmations[$language]?></title>
<link rel="stylesheet"
      href="local.css"
      type="text/css">
<?=$local_stylesheets?>
<?php
  $failure = false;
  $body = conditional_layout_before_content(
			$lang_sending_confirmations[$language]);
  $ergebnis = db_exec($verbindung, "SELECT priority,translation
	FROM priority_translation,language
	WHERE code='$language'
	AND language=language.id;");
  for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
    $col = 0;
    $id = pg_result($ergebnis, $lt, $col++);
    $description = pg_result($ergebnis, $lt, $col++);
    $priorities[$id] = $description;
  }
  $course_period = option_value($course_period_option);
  $ergebnis = db_exec($verbindung, "SELECT person.id,email "
  			. "FROM person_course,"
				. "$course_date_readable,course,person "
			. "WHERE person=person.id "
			. "AND email IS NOT null "
			. "AND person_course.course=$course_date_readable.id "
			. "AND $course_date_readable.course=course.id "
			. "AND course_period=$course_period "
			. "AND NOT EXISTS ("
				. "SELECT true FROM person_emailed "
				. "WHERE person_emailed.person=person.id) "
			. "GROUP BY person.id,email"
			. ($course_date_translated ? ",language" : "")
			. " LIMIT $amount");
  $emails = pg_numrows($ergebnis);
  for ($lt = 0; $lt < $emails; $lt++) {
    $col = 0;
    $person =  pg_result($ergebnis, $lt, $col++);
    $email =  pg_result($ergebnis, $lt, $col++);
    $mail_body = $confirmation_notification[$language];
    $last_priority = 0;
    $person_ergebnis = db_exec($verbindung, "SELECT category.name,course.name,"
    				. "$course_date_readable.description,priority "
			. "FROM person_course,"
			. ($course_date_translated ? "language," : "")
				. "$course_date_readable,course,category "
			. "WHERE person=$person "
			. "AND person_course.course=$course_date_readable.id "
			. "AND $course_date_readable.course=course.id "
			. "AND course_period=$course_period "
			. "AND category=category.id "
			. ($course_date_translated
				?  ("AND code='$language' "
					. "AND language=language.id ")
				: "")
			. "ORDER BY priority");
    for ($person_lt = 0;
         $person_lt < pg_numrows($person_ergebnis);
	 $person_lt++) {
      $person_col = 0;
      $category = pg_result($person_ergebnis, $person_lt, $person_col++);
      $course = pg_result($person_ergebnis, $person_lt, $person_col++);
      $date = pg_result($person_ergebnis, $person_lt, $person_col++);
      $priority = pg_result($person_ergebnis, $person_lt, $person_col++);
      if ($priority != $last_priority) {
        $last_priority = $priority;
	$mail_body .= '

' . lang_confirm_courses($language,$priorities[$priority]) . ':
';
      }
      $mail_body .= "
$category
$course
$date
";
    }
    $subject = ucfirst(possessive($language,2,"polite","female"))
                        . " " . $lang_registration[$language]
			. " (" . $lang_approval[$language] . ")";
    $headers = "From: $system_reply_address\r
Content-type: text/plain; charset=utf-8";
    $options = $set_envelope_header ? "-f $system_reply_address" : "";
    if (mail($email, $subject, $mail_body, $headers, $options)) {
      $body .= "
" . lang_sent($language,$email) . "
";
      db_exec($verbindung, "INSERT INTO person_emailed (person,course_period) "
				. "SELECT $person,$course_period;");
    } else {
      $body .= "
<span class='fehler'>" . lang_not_sent($language,$email) . "</span>
";
      $failure = true;
    }
    $body .= "
<br />
";
  }
  db_close($verbindung);
  if (($emails > 0) && (!$failure)) {
?>
<meta http-equiv="refresh" content="60;url=send-confirmations.php" />
<?php
  }
  if ($emails == 0) {
    $body .= $lang_confirmations_sent[$language];
  }
?>
</head>
<body>
<?=$body?>
<?=$impressum_link?>
<?=conditional_layout_after_content()?>
</body>
</html>
Return current item: Course-manager