From kde-commits Sat Aug 31 19:58:30 2013 From: Sayak Banerjee Date: Sat, 31 Aug 2013 19:58:30 +0000 To: kde-commits Subject: [websites/season-kde-org] /: Add notification mails module Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=137797912024103 Git commit aea9f489bd6d8332521941d811b2fc85537be742 by Sayak Banerjee. Committed on 31/08/2013 at 19:58. Pushed by sayakb into branch 'master'. Add notification mails module M +1 -0 classes/class_module.php M +33 -231 cron.php M +16 -0 lang/en-gb.php C +68 -71 modules/mod_notifications.php [from: cron.php - 072% similar= ity] M +6 -0 skins/neverland/html/tpl_header.html M +3 -3 skins/neverland/html/tpl_manage_programs_item.html A +49 -0 skins/neverland/html/tpl_notifications.html A +25 -0 skins/neverland/html/tpl_queue_item.html http://commits.kde.org/websites/season-kde-org/aea9f489bd6d8332521941d811b2= fc85537be742 diff --git a/classes/class_module.php b/classes/class_module.php index 13ed54e..21d0546 100755 --- a/classes/class_module.php +++ b/classes/class_module.php @@ -28,6 +28,7 @@ class module array('name' =3D> 'edit_templates', 'access' =3D> 'a'), array('name' =3D> 'user_ban', 'access' =3D> 'a'), array('name' =3D> 'manage_programs', 'access' =3D> 'a'), + array('name' =3D> 'notifications', 'access' =3D> 'a'), ); } = diff --git a/cron.php b/cron.php index 95cb56e..eac1b37 100755 --- a/cron.php +++ b/cron.php @@ -5,254 +5,56 @@ * @copyright (c) 2012 KDE. All rights reserved. */ = -// We are in CLI, assume OS cron is being used -if (php_sapi_name() =3D=3D 'cli') -{ - define('IN_PANDORA', true); - - // We need longer execution time - set_time_limit(3600); - - // Invoke required files - include_once('init.php'); +if (!defined('IN_PANDORA')) exit; = - // Set default for sending mail - $name =3D $config->ldap_fullname; - $mail =3D $config->ldap_mail; - $mentor_name =3D $lang->get('no_mentor'); - - // Get all entries from the queue and their corresponding program data - $sql =3D "SELECT prg.id as program_id, " . - " prg.title as program_title, " . - " prg.dl_mentor as program_deadline, " . - " prg.end_time as program_complete, " . - " que.deadline as deadline_flag, " . - " que.complete as complete_flag " . - "FROM {$db->prefix}queue que " . - "LEFT JOIN {$db->prefix}programs prg " . - "ON que.program_id =3D prg.id " . - "WHERE (prg.dl_mentor < TIMESTAMP(CURRENT_DATE()) " . - "OR prg.end_time < TIMESTAMP(CURRENT_DATE()))"; - $program_data =3D $db->query($sql); +// Use cache for cron +if ($cache->is_available) +{ + // Get last run time + $last_run =3D $cache->get('last_run', 'cron'); = - // Traverse through each program - foreach ($program_data as $program) + if (!$last_run) { - // Set original deadline and complete flags - $deadline =3D $program['deadline_flag']; - $complete =3D $program['complete_flag']; - - // All projects for this program - $sql =3D "SELECT id as project_id, " . - " title as project_title, " . - " is_accepted " . - "FROM {$db->prefix}projects " . - "WHERE program_id =3D {$program['program_id']}"; - $project_data =3D $db->query($sql); - - // Assign program name - $email->assign('program_name', $program['program_title']); - - // Traverse through each project - foreach ($project_data as $project) - { - $project['student'] =3D ''; - $project['mentor'] =3D ''; - $project['passed'] =3D false; - - // Get student data - $sql =3D "SELECT username, passed " . - "FROM {$db->prefix}participants " . - "WHERE program_id =3D {$program['program_id']} " . - "AND project_id =3D {$project['project_id']} " . - "AND role =3D 's'"; - $student_data =3D $db->query($sql, true); - - if ($student_data !=3D null) - { - $project['student'] =3D $student_data['username']; - $project['passed'] =3D $student_data['passed']; - } - - // Get mentor data - $sql =3D "SELECT username " . - "FROM {$db->prefix}participants " . - "WHERE program_id =3D {$program['program_id']} " . - "AND project_id =3D {$project['project_id']} " . - "AND role =3D 'm'"; - $mentor_data =3D $db->query($sql, true); - - if ($mentor_data !=3D null) - { - $project['mentor'] =3D $mentor_data['username']; - } - - // Get student and mentor data from LDAP - $student_data =3D $user->get_details($project['student'], arra= y($name, $mail)); - $mentor_data =3D $user->get_details($project['mentor'], array= ($name, $mail)); - - // Set student data - if ($student_data !=3D=3D false) - { - $student =3D $project['student']; - $student_to =3D $student_data[$name][0]; - $student_name =3D "{$student_data[$name][0]} <{$student= _data[$mail][0]}>"; - $student_mail =3D $student_data[$mail][0]; - } - - // Set mentor data - if ($mentor_data !=3D=3D false) - { - $mentor =3D $project['mentor']; - $mentor_to =3D $mentor_data[$name][0]; - $mentor_name =3D "{$mentor_data[$name][0]} <{$mentor_da= ta[$mail][0]}>"; - $mentor_mail =3D $mentor_data[$mail][0]; - } - - // Assign data needed for the email - $email->assign(array( - 'project_name' =3D> $project['project_title'], - 'student_name' =3D> $student_name, - 'mentor_name' =3D> $mentor_name, - 'project_url' =3D> "{$config->http_host}?q=3Dview_pr= ojects&prg=3D" . - "{$program['program_id']}&p=3D{= $project['project_id']}", - )); - - // Send out status mails on deadline - if ($program['program_deadline'] < $core->timestamp && $projec= t['is_accepted'] !=3D -1 && $deadline =3D=3D 0) - { - // Output status to console - echo '[' . date('r') . '] ' . $lang->get('sending_status')= . " #{$project['project_id']} "; - - // Set the template based on the status - $status =3D $project['is_accepted'] =3D=3D 1 ? 'accept' : = 'reject'; - - // Set initial flag values - $success_student =3D true; - $success_mentor =3D true; - - if ($student_data !=3D=3D false && !empty($student_mail)) - { - $email->assign('recipient', $student_to); - $success_student =3D $email->send($student_mail, $lang= ->get('subject_status'), $status); - sleep(2); - } - - if ($mentor_data !=3D=3D false && !empty($mentor_mail)) - { - $email->assign('recipient', $mentor_to); - $success_mentor =3D $email->send($mentor_mail, $lang->= get('subject_status'), $status); - sleep(2); - } - - // Determine status for logging - $log_status =3D $success_student && $success_mentor ? $lan= g->get('status_ok') : $lang->get('status_error'); - echo "{$log_status}\n"; - } - - // Send out result mails on program completion - if ($program['program_complete'] < $core->timestamp && $projec= t['passed'] !=3D -1 && $complete =3D=3D 0) - { - // Output status to console - echo '[' . date('r') . '] ' . $lang->get('sending_result')= . " #{$project['project_id']} "; - - // Set the template based on the status - $status =3D $project['passed'] =3D=3D 1 ? 'pass' : 'fail'; - - // Set initial flag status - $success =3D true; - - if ($student_data !=3D=3D false && !empty($student_mail)) - { - $email->assign('recipient', $student_to); - $success =3D $email->send($student_mail, $lang->get('s= ubject_result'), $status); - sleep(2); - } - - // Determine status for logging - $log_status =3D $success ? $lang->get('status_ok') : $lang= ->get('status_error'); - echo "{$log_status}\n"; - } - } - - // Set new flag values - $deadline =3D $program['program_deadline'] < $core->timestamp ? 1 = : 0; - $complete =3D $program['program_complete'] < $core->timestamp ? 1 = : 0; - - // Update the queue entry if at least one flag is still unset - if ($deadline =3D=3D 0 || $complete =3D=3D 0) - { - $sql =3D "UPDATE {$db->prefix}queue " . - "SET deadline =3D {$deadline}, " . - " complete =3D {$complete} " . - "WHERE program_id =3D {$program['program_id']}"; - $db->query($sql); - } - - // Both flags set, remove the item from queue - else - { - $sql =3D "DELETE FROM {$db->prefix}queue " . - "WHERE program_id =3D {$program['program_id']}"; - $db->query($sql); - } + $last_run =3D 0; } } = -// We are in web more, utilize inbuilt cron feature +// Use DB for cron else { - if (!defined('IN_PANDORA')) exit; + // Get last run time + $sql =3D "SELECT timestamp " . + "FROM {$db->prefix}cron"; + $row =3D $db->query($sql, true); = - // Use cache for cron - if ($cache->is_available) + if ($row !=3D null) { - // Get last run time - $last_run =3D $cache->get('last_run', 'cron'); - - if (!$last_run) - { - $last_run =3D 0; - } + $last_run =3D $row['timestamp']; } - - // Use DB for cron else { - // Get last run time - $sql =3D "SELECT timestamp " . - "FROM {$db->prefix}cron"; - $row =3D $db->query($sql, true); - - if ($row !=3D null) - { - $last_run =3D $row['timestamp']; - } - else - { - $last_run =3D 0; - } + $last_run =3D 0; } +} = - // Check the time difference - if (($core->timestamp - $last_run) > 60) +// Check the time difference +if (($core->timestamp - $last_run) > 60) +{ + // Update new run time + if ($cache->is_available) { - // Update new run time - if ($cache->is_available) - { - $cache->put('last_run', $core->timestamp, 'cron'); - } - else - { - $sql =3D "UPDATE {$db->prefix}cron " . - "SET timestamp =3D {$core->timestamp}"; - $db->query($sql); - } - - // Cron tasks - $cache->purge('users'); - $db->query("DELETE FROM {$db->prefix}session WHERE timestamp < {$u= ser->max_age}"); + $cache->put('last_run', $core->timestamp, 'cron'); } + else + { + $sql =3D "UPDATE {$db->prefix}cron " . + "SET timestamp =3D {$core->timestamp}"; + $db->query($sql); + } + + // Cron tasks + $cache->purge('users'); + $db->query("DELETE FROM {$db->prefix}session WHERE timestamp < {$user-= >max_age}"); } = ?> diff --git a/lang/en-gb.php b/lang/en-gb.php index 3d7e7cf..06b796f 100755 --- a/lang/en-gb.php +++ b/lang/en-gb.php @@ -220,6 +220,22 @@ $lang_data =3D array( 'role_g' =3D> 'Guest', 'no_participants' =3D> 'This programs has no participants', 'projects' =3D> 'Projects', + + /* Module: notifications */ + 'notification_mails' =3D> 'Notification mails', + 'mail_queue' =3D> 'Queued emails', + 'mail_queue_exp' =3D> 'Each program has two types of emails: ac= ceptance emails and result emails. Acceptance ' . + 'emails are sent out to students and mentor= s only after the mentor deadline is reached ' . + 'while result emails are sent out once the = program has ended. Use the Send notifications ' . + 'button to trigger these mails. No matter w= hen you trigger them, the mails will be sent ' . + 'only past these deadlines.', + 'acceptance_mails' =3D> 'Acceptance emails', + 'result_mails' =3D> 'Result emails', + 'queue_empty' =3D> 'There are no items in the queue', + 'send_notifications' =3D> 'Send notifications', + 'sendmail_output' =3D> 'Sendmail output', + 'processing_program' =3D> 'Processing program #', + 'program_no_mail' =3D> 'No mails were sent for this program', ); = ?> diff --git a/cron.php b/modules/mod_notifications.php similarity index 72% copy from cron.php copy to modules/mod_notifications.php index 95cb56e..2ceeffc 100755 --- a/cron.php +++ b/modules/mod_notifications.php @@ -5,22 +5,22 @@ * @copyright (c) 2012 KDE. All rights reserved. */ = -// We are in CLI, assume OS cron is being used -if (php_sapi_name() =3D=3D 'cli') -{ - define('IN_PANDORA', true); +if (!defined('IN_PANDORA')) exit; = - // We need longer execution time - set_time_limit(3600); +// We need longer execution time +set_time_limit(3600); = - // Invoke required files - include_once('init.php'); +// Get the program's participant list +$db->escape($program_id); = - // Set default for sending mail - $name =3D $config->ldap_fullname; - $mail =3D $config->ldap_mail; - $mentor_name =3D $lang->get('no_mentor'); +// Set default for sending mail +$name =3D $config->ldap_fullname; +$mail =3D $config->ldap_mail; +$mentor_name =3D $lang->get('no_mentor'); +$output =3D ''; = +if (isset($_POST['process'])) +{ // Get all entries from the queue and their corresponding program data $sql =3D "SELECT prg.id as program_id, " . " prg.title as program_title, " . @@ -32,7 +32,8 @@ if (php_sapi_name() =3D=3D 'cli') "LEFT JOIN {$db->prefix}programs prg " . "ON que.program_id =3D prg.id " . "WHERE (prg.dl_mentor < TIMESTAMP(CURRENT_DATE()) " . - "OR prg.end_time < TIMESTAMP(CURRENT_DATE()))"; + "OR prg.end_time < TIMESTAMP(CURRENT_DATE())) "; + "AND prg.is_active =3D 1"; $program_data =3D $db->query($sql); = // Traverse through each program @@ -53,6 +54,10 @@ if (php_sapi_name() =3D=3D 'cli') // Assign program name $email->assign('program_name', $program['program_title']); = + // Add log line + $output .=3D '[' . date('r') . '] ' . $lang->get('processing_progr= am') . "{$program['program_id']}...\n"; + $processed =3D false; + // Traverse through each project foreach ($project_data as $project) { @@ -122,7 +127,7 @@ if (php_sapi_name() =3D=3D 'cli') if ($program['program_deadline'] < $core->timestamp && $projec= t['is_accepted'] !=3D -1 && $deadline =3D=3D 0) { // Output status to console - echo '[' . date('r') . '] ' . $lang->get('sending_status')= . " #{$project['project_id']} "; + $output .=3D '[' . date('r') . '] ' . $lang->get('sending_= status') . " #{$project['project_id']}... "; = // Set the template based on the status $status =3D $project['is_accepted'] =3D=3D 1 ? 'accept' : = 'reject'; @@ -135,26 +140,25 @@ if (php_sapi_name() =3D=3D 'cli') { $email->assign('recipient', $student_to); $success_student =3D $email->send($student_mail, $lang= ->get('subject_status'), $status); - sleep(2); } = if ($mentor_data !=3D=3D false && !empty($mentor_mail)) { $email->assign('recipient', $mentor_to); $success_mentor =3D $email->send($mentor_mail, $lang->= get('subject_status'), $status); - sleep(2); } = // Determine status for logging $log_status =3D $success_student && $success_mentor ? $lan= g->get('status_ok') : $lang->get('status_error'); - echo "{$log_status}\n"; + $output .=3D "{$log_status}\n"; + $processed =3D true; } = // Send out result mails on program completion if ($program['program_complete'] < $core->timestamp && $projec= t['passed'] !=3D -1 && $complete =3D=3D 0) { // Output status to console - echo '[' . date('r') . '] ' . $lang->get('sending_result')= . " #{$project['project_id']} "; + $output .=3D '[' . date('r') . '] ' . $lang->get('sending_= result') . " #{$project['project_id']}... "; = // Set the template based on the status $status =3D $project['passed'] =3D=3D 1 ? 'pass' : 'fail'; @@ -166,12 +170,12 @@ if (php_sapi_name() =3D=3D 'cli') { $email->assign('recipient', $student_to); $success =3D $email->send($student_mail, $lang->get('s= ubject_result'), $status); - sleep(2); } = // Determine status for logging $log_status =3D $success ? $lang->get('status_ok') : $lang= ->get('status_error'); - echo "{$log_status}\n"; + $output .=3D "{$log_status}\n"; + $processed =3D true; } } = @@ -196,63 +200,56 @@ if (php_sapi_name() =3D=3D 'cli') "WHERE program_id =3D {$program['program_id']}"; $db->query($sql); } - } -} - -// We are in web more, utilize inbuilt cron feature -else -{ - if (!defined('IN_PANDORA')) exit; = - // Use cache for cron - if ($cache->is_available) - { - // Get last run time - $last_run =3D $cache->get('last_run', 'cron'); - - if (!$last_run) + // No mails were processed + if (!$processed) { - $last_run =3D 0; + $output .=3D '[' . date('r') . '] ' . $lang->get('program_no_m= ail'); } - } - - // Use DB for cron - else - { - // Get last run time - $sql =3D "SELECT timestamp " . - "FROM {$db->prefix}cron"; - $row =3D $db->query($sql, true); = - if ($row !=3D null) - { - $last_run =3D $row['timestamp']; - } - else - { - $last_run =3D 0; - } + $output .=3D "\n\n"; } +} = - // Check the time difference - if (($core->timestamp - $last_run) > 60) - { - // Update new run time - if ($cache->is_available) - { - $cache->put('last_run', $core->timestamp, 'cron'); - } - else - { - $sql =3D "UPDATE {$db->prefix}cron " . - "SET timestamp =3D {$core->timestamp}"; - $db->query($sql); - } - - // Cron tasks - $cache->purge('users'); - $db->query("DELETE FROM {$db->prefix}session WHERE timestamp < {$u= ser->max_age}"); - } +// Get the queue data +$sql =3D "SELECT prg.id as program_id, " . + " prg.title as program_title, " . + " que.deadline as deadline_flag, " . + " que.complete as complete_flag " . + "FROM {$db->prefix}queue que " . + "LEFT JOIN {$db->prefix}programs prg " . + "ON que.program_id =3D prg.id " . + "WHERE prg.is_active =3D 1"; +$queue_data =3D $db->query($sql); + +// Populate the queue +$queue_items =3D ''; + +foreach ($queue_data as $queue) +{ + $skin->assign(array( + 'program_id' =3D> $queue['program_id'], + 'program_title' =3D> $queue['program_title'], + 'program_deadline_sent' =3D> $skin->visibility($queue['deadli= ne_flag'] =3D=3D 1), + 'program_deadline_pending' =3D> $skin->visibility($queue['deadli= ne_flag'] =3D=3D 0), + 'program_complete_sent' =3D> $skin->visibility($queue['comple= te_flag'] =3D=3D 1), + 'program_complete_pending' =3D> $skin->visibility($queue['comple= te_flag'] =3D=3D 0), + )); + + $queue_items .=3D $skin->output('tpl_queue_item'); } = +// Assign final skin data +$skin->assign(array( + 'notify_output' =3D> nl2br(trim($output)), + 'queue_items' =3D> $queue_items, + 'output_visibility' =3D> $skin->visibility(empty($output), true), + 'queue_visibility' =3D> $skin->visibility(empty($queue_items), tru= e), + 'notice_visibility' =3D> $skin->visibility(empty($queue_items)), +)); + +// Output the module +$module_title =3D $lang->get('notifications'); +$module_data =3D $skin->output('tpl_notifications'); + ?> diff --git a/skins/neverland/html/tpl_header.html b/skins/neverland/html/tp= l_header.html index 2bb46d9..4b77198 100755 --- a/skins/neverland/html/tpl_header.html +++ b/skins/neverland/html/tpl_header.html @@ -86,6 +86,12 @@ ocalization variable =
  • + + {{notification_mails}} + +
  • + +
  • {{edit_templates}} diff --git a/skins/neverland/html/tpl_manage_programs_item.html b/skins/nev= erland/html/tpl_manage_programs_item.html index 96f24eb..3559daf 100755 --- a/skins/neverland/html/tpl_manage_programs_item.html +++ b/skins/neverland/html/tpl_manage_programs_item.html @@ -2,7 +2,7 @@ [[program_title]] - = + [[program_description]] @@ -16,10 +16,10 @@ - = + - \ No newline at end of file + diff --git a/skins/neverland/html/tpl_notifications.html b/skins/neverland/= html/tpl_notifications.html new file mode 100755 index 0000000..318ae51 --- /dev/null +++ b/skins/neverland/html/tpl_notifications.html @@ -0,0 +1,49 @@ +

    {{notification_mails}}

    +
    + +
    + {{mail_queue_exp}} +
    + +
    + +
    + +

    {{mail_queue}}

    + +
    + {{queue_empty}} +
    + +
    + + + + + + + + + + + + + [[queue_items]] + +
    + {{program_title}} + + {{acceptance_mails}} + + {{result_mails}} +
    +
    + +
    +
    +

    {{sendmail_output}}

    + +
    + [[notify_output]] +
    +
    diff --git a/skins/neverland/html/tpl_queue_item.html b/skins/neverland/htm= l/tpl_queue_item.html new file mode 100755 index 0000000..fa7aa91 --- /dev/null +++ b/skins/neverland/html/tpl_queue_item.html @@ -0,0 +1,25 @@ + + + [[program_title= ]] + + + +
    + +
    + +
    + +
    + + + +
    + +
    + +
    + +
    + +