public function uploadAction() { if (isset($_FILES['importfile']) && !empty($_FILES['importfile']['name'])) { $content = file_get_contents($_FILES['importfile']['tmp_name']); $lines = explode("\n", $content); $persons = array(); //'BDAY' $state = 0; foreach ($lines as $line) { $line = str_replace("\r", "", $line); $pos = strpos($line, ':'); if ($pos === false) { continue; } $key = substr($line, 0, $pos); $value = substr($line, $pos + 1); switch ($state) { case 0: if ($key === 'BEGIN' && $value === 'VCARD') { $state = 1; $person = array(); } break; case 1: if ($key === 'END' && $value === 'VCARD') { $state = 0; $persons[] = $person; } else { if ($key === 'FN' || substr($key, 0, 3) === 'FN;') { $name = explode(' ', $value); $person['firstname'] = strip_tags($name[0]); $person['secondname'] = strip_tags($name[1]); } if ($key === 'BDAY' || substr($key, 0, 5) === 'BDAY;') { $value = substr($value, 0, 10); $date = new Zend_Date(); if ($date->isDate($value, 'yyyy-MM-dd')) { $date->set($value); $person['birthdate'] = $date->toString('yyyy-MM-dd'); } } } break; } } } foreach ($persons as $person) { if (isset($person['firstname']) && isset($person['secondname']) && isset($person['birthdate'])) { $user = new Bc_UserDTO(); $user->set('firstname', $person['firstname']); $user->set('secondname', $person['secondname']); $user->set('birthdate', $person['birthdate']); $user->save(); } } $this->_redirect('/'); }
/** * ... simple action to return some json data * */ public function gridAction() { $users = Bc_UserDTO::fetchAsArray(null, 'firstname'); $json = '{ "identifier": "id", "idAttribute":"id", "label": "firstname","items": '; $json .= Zend_Json::encode($users); $json .= '}'; echo $json; exit; }
/** * Notification Action * */ public function indexAction() { // pattern for list-view $pattern = ' - %s %s(%s)'; // define subject for mail $subject = 'Geburtstags-Erinnerung'; $from = 'root@localhost'; $to = 'root@localhost'; // email body $body = null; // upcoming birthdates $upcomingBirthdates = Bc_UserDTO::getUsersWithBirthdayInXDays(1); if (count($upcomingBirthdates) > 0) { foreach ($upcomingBirthdates as $upcomingBirthdate) { $upcomingUsers[] = sprintf($pattern, $upcomingBirthdate->get('firstname'), $upcomingBirthdate->get('secondname'), 'wird ' . (date('Y') - $upcomingBirthdate->get('birthdate'))); } // define mail content $cBody = "Geburtstage morgen:\n\n"; $cBody .= implode("\n", $upcomingUsers); } // todays birthdates $todaysBirthdates = Bc_UserDTO::getUsersWithBirthdayInXDays(0); if (count($todaysBirthdates) > 0) { foreach ($todaysBirthdates as $todaysBirthdate) { $todaysUsers[] = sprintf($pattern, $todaysBirthdate->get('firstname'), $todaysBirthdate->get('secondname'), 'ist ' . (date('Y') - $todaysBirthdate->get('birthdate'))); } // define mail content $tBody = "Geburtstage heute:\n\n"; $tBody .= implode("\n", $todaysUsers); } if (isset($todaysUsers)) { $body .= $tBody; } if (isset($upcomingUsers) && isset($todaysUsers)) { $body .= "\n\n--------------------------------\n\n"; $body .= $cBody; } else { if (isset($upcomingUsers)) { $body .= $cBody; } } if (null != $body) { // set view message $this->view->message = "E-Mail mit Geburstagserinnerungen wurde mit folgendem Inhalt versendet: \n\n" . $body; // build mailer and send $mail = Bc_Notification::getInstance(); $mail->setMailOptions($body, $from, $to, $subject); $mail->send(); } else { // set view message $this->view->message = 'Derzeit gibt es keine Geburtstage.'; } }
public function deleteAction() { $userId = $this->_request->getParam('id', null); if ($userId === null) { $this->_outputAjaxCallResult(false); } else { $result = Bc_UserDTO::remove($userId); if ($result === false) { $this->_outputAjaxCallResult(false); } else { $this->_outputAjaxCallResult(true); } } }
/** * The export action */ public function indexAction() { header("Content-Type: text/Calendar"); header("Content-Disposition: inline; filename=Geburtstage.ics"); $uid = $this->getRequest()->getParam('uid', null); $filter = array(); if ($uid !== null) { $filter['id'] = $uid; } $userDTOs = Bc_UserDTO::fetch($filter); $users = array(); foreach ($userDTOs as $userDTO) { $birthdate = new Zend_Date(); $birthdate->set($userDTO->get('birthdate'), Zend_Date::ISO_8601); $nextdate = new Zend_Date(); $nextdate->set($userDTO->get('birthdate'), Zend_Date::ISO_8601); $nextdate->addDay('1', Zend_Date::DAY); $users[] = array('id' => $userDTO->get('id'), 'birthYear' => $birthdate->get(Zend_Date::YEAR), 'birthDate' => $birthdate->toString('yyyyMMdd'), 'birthMonth' => $birthdate->get(Zend_Date::MONTH), 'birthDay' => $birthdate->get(Zend_Date::DAY), 'nextDate' => $nextdate->toString('yyyyMMdd'), 'firstName' => $userDTO->get('firstname'), 'secondName' => $userDTO->get('secondname')); } $this->view->users = $users; $this->view->timeStamp = date("Ymd") . 'T' . date("His") . 'Z'; }