1<?php 2 3require_once DOKU_PLUGIN.'bez/helper.php'; 4 5require_once DOKU_PLUGIN.'bez/exceptions.php'; 6require_once DOKU_PLUGIN.'bez/interfaces.php'; 7 8require_once DOKU_PLUGIN.'bez/mdl/model.php'; 9 10$action = new class extends DokuWiki_Action_Plugin { 11 public function getPluginName() { 12 return 'bez'; 13 } 14 15 public function id() { 16 $args = func_get_args(); 17 array_unshift($args, 'bez'); 18 19 return implode(':', $args); 20 } 21}; 22 23$model = new BEZ_mdl_Model($auth, $dw_user, $action, $conf); 24 25function send_inactive_issue() { 26 global $model; 27 28 $issues = $model->issues->get_all(array( 29 'last_activity' => array('<=', 30 date('Y-m-d', strtotime('-30 days')), 'date' 31 ), 32 'state' => '0' 33 )); 34 35 foreach ($issues as $issue) { 36 //send reminder once a month 37 $day_of_issue_last_activity = date('d', strtotime($issue->last_activity)); 38 if ($day_of_issue_last_activity === date('d')) { 39 //send message to all 40 $issue->mail_notify_issue_inactive($issue->get_subscribents()); 41 } 42 } 43} 44 45function send_one_day_task_reminder() { 46 global $model; 47 48 $tasks = $model->tasks->get_all(array( 49 'plan_date' => date('Y-m-d', strtotime('+1 day')), 50 'state' => '0' //only open tasks 51 )); 52 53 foreach ($tasks as $task) { 54 $task->mail_notify_remind($task->get_subscribents()); 55 } 56} 57 58function send_weekly_message($simulate=true) { 59 global $conf, $auth, $bezlang; 60 61 $helper = new helper_plugin_bez(); 62 63 //email => array('user' => array('issues' => array(), 'tasks' => array())) 64 $msg = array(); 65 $output = array(); 66 67 try { 68 $isso = new Issues(); 69 $tasko = new Tasks(); 70 } catch (Exception $e) { 71 echo $e->getMessage().': '.$e->getFile(); 72 } 73 74 $issues = $isso->cron_get_unsolved(); 75 76 foreach ($issues as $issue) { 77 $key = $issue['coordinator']; 78 if (!isset($msg[$key])) 79 $msg[$key] = array('issues' => array(), 'coming_tasks' => array(), 80 'outdated_tasks' => array()); 81 82 $msg[$key]['issues'][] = $issue; 83 } 84 85 $coming_tasks_all = $tasko->cron_get_coming_tasks(); 86 87 foreach ($coming_tasks_all as $task) { 88 $key = $task['executor']; 89 if (!isset($msg[$key])) 90 $msg[$key] = array('issues' => array(), 'coming_tasks' => array(), 91 'outdated_tasks' => array()); 92 93 $msg[$key]['coming_tasks'][] = $task; 94 } 95 96 $outdated_tasks_all = $tasko->cron_get_outdated_tasks(); 97 98 foreach ($outdated_tasks_all as $task) { 99 $key = $task['executor']; 100 if (!isset($msg[$key])) 101 $msg[$key] = array('issues' => array(), 'coming_tasks' => array(), 102 'outdated_tasks' => array()); 103 104 $msg[$key]['outdated_tasks'][] = $task; 105 } 106 107 //outdated_tasks, coming_tasks, open_tasks 108 109 110 foreach ($msg as $user => $data) { 111 $udata = $auth->getUserData($user); 112 113 $his_issues = $data['issues']; 114 $outdated_tasks = $data['outdated_tasks']; 115 $coming_tasks = $data['coming_tasks']; 116 117 118 if (count($his_issues) + count($outdated_tasks) + count($coming_tasks) == 0) 119 continue; 120 121 $to = $udata['name'].' <'.$udata['mail'].'>'; 122 123 ob_start(); 124 include 'tpl/weekly-message.php'; 125 $body = ob_get_clean(); 126 127 $mailer = new BEZ_Mailer(); 128 $rep = array(); 129 $mailer->setBody('', $rep, NULL, $body, false); 130 131 $mailer->to($to); 132 $subject = 'Nadchodzące zadania'; 133 $mailer->subject($subject); 134 135 if ($simulate === false) { 136 $send = $mailer->send(); 137 } 138 $output[] = array($to, $subject, $body, array()); 139 } 140 141 return $output; 142} 143