now = time(); $this->sender = $sender; $this->error = $error; $this->kvs = new Kvs(); $this->ldap = new Ldap(); } public function run() { $lastrun = $this->kvs->get_value('lastrun'); $interval = 3600*24; //1 day in seconds if($lastrun && $this->now - $lastrun < $interval) { return; } $this->kvs->set_key('lastrun', $this->now); $users = get_items('user'); foreach($users as $user) { $this->check_loans($user); } } private function check_loans($user) { $overdue = $user->get_overdue_loans(); if($overdue) { $this->send_reminder($user, $overdue); } } private function send_reminder($user, $loans) { $subject_template = "DSV Helpdesk: Du har ¤count¤ ¤late¤ lån"; $reminder_template_sv = "¤brand¤ ¤name¤, försenad sedan ¤due¤\n"; $reminder_template_en = "¤brand¤ ¤name¤, late since ¤due¤\n"; $message_template = << 1) { $late = 'försenade'; $product_sv = 'artiklar'; $product_en = 'products'; $it_sv = 'dem'; $it_en = 'them'; $loan_sv = 'lånen'; $loan_en = 'loans'; } foreach($loans as $loan) { $replacements = array('name' => $loan->get_product()->get_name(), 'brand' => $loan->get_product()->get_brand(), 'due' => format_date($loan->get_endtime())); $reminder_list_sv .= replace($replacements, $reminder_template_sv); $reminder_list_en .= replace($replacements, $reminder_template_en); } $subject = replace(array('count' => $overdue_count, 'late' => $late), $subject_template); $message = replace(array('name' => $user->get_displayname($this->ldap), 'list_sv' => $reminder_list_sv, 'product_sv' => $product_sv, 'it_sv' => $it_sv, 'loan_sv' => $loan_sv, 'list_en' => $reminder_list_en, 'product_en' => $product_en, 'it_en' => $it_en, 'loan_en' => $loan_en), $message_template); try { mb_send_mail($user->get_email($this->ldap), $subject, $message, 'From: '.$this->sender); } catch(Exception $e) { mb_send_mail($this->error, "Kunde inte skicka påminnelse", "Påminnelse kunde inte skickas till " .$user->get_name()); } } } ?>