Esempio n. 1
0
 function prepareToSave()
 {
     $tpl = new jTpl();
     $rep = $this->getResponse('html');
     if ($this->param('id') === null) {
         $form = jForms::fill('NewsLetter~news');
         $dao = jDao::get('NewsLetter~newsLetter');
         $r = jDao::createRecord('NewsLetter~newsLetter');
         $r->date_create = date("Y-m-d");
         $r->text = $form->getData('text');
         $dao->insert($r);
     } else {
         $id = $this->param('id');
         $dao = jDao::get('NewsLetter~newsLetter');
         $r = $dao->get($this->param('id'));
     }
     $actions = array();
     $emails_dao = jDao::get('emails');
     $conds = jDao::createConditions();
     $count = $emails_dao->countBy($conds);
     $email_rate = 2000;
     for ($i = 0; $i <= $count; $i += $email_rate) {
         $action = array();
         $action['inf'] = $i;
         $action['sup'] = $i + $email_rate;
         $action['url'] = 'send';
         $action['id'] = $r->id;
         $actions[] = $action;
     }
     $tpl->assign('actions', $actions);
     $tpl->assign('id', $r->id);
     $emailSrv = new EmailService();
     if ($emailSrv->nbEmailsToSend($r->id) == 0) {
         $emailSrv->resetLogs($r->id);
     }
     $tpl->assign('n_emails', $emailSrv->nbEmailsToSend($r->id));
     $tpl->assign('n_emails_sent', $emailSrv->nbEmailsSent($r->id));
     $tpl->assign('servers', $emailSrv->getServers());
     $tpl->assign('maxMailPerMin', $emailSrv->maxMailPerMin());
     $tpl->assign('maxMailPerDay', $emailSrv->maxMailPerDay());
     $rep->body->assign('MAIN', $tpl->fetch('prepare_sending'));
     return $rep;
 }