Exemplo n.º 1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate($key)
 {
     if ($key == 'mainmenu') {
         $id = 0;
     } else {
         $m = Menu::model()->findbyAttributes(array('key' => $key));
         if (!$m) {
             $this->render404();
         }
         $id = $m->id;
     }
     $criteria = new CDbCriteria();
     $criteria->order = "sort";
     $models = Menu::model()->findAllbyAttributes(array('parent_id' => $id), $criteria);
     $new = Menu::model();
     $new->parent_id = $id;
     if ($models) {
         $new->sort = end($models)->sort + 10;
     } else {
         $new->sort = 10;
     }
     $models[] = $new;
     if (isset($_POST['Menu'])) {
         $hasError = false;
         foreach ($models as $k => $model) {
             $mid = (int) $model->id;
             // to int because of null != '0' but 0 == '0'
             if (!isset($_POST['Menu'][$mid])) {
                 continue;
             }
             $models[$k]->attributes = $_POST['Menu'][$mid];
             if (isset($_POST['Menu'][$mid]['delete']) && $_POST['Menu'][$mid]['delete']) {
                 if (!$models[$k]->delete()) {
                     $hasError = true;
                 }
             } else {
                 if (!$models[$k]->save()) {
                     // TODO how to distinct between nothing entered
                     // if ($model->id == 0 && count($model->getErrors()) == 3)
                     // {
                     // 	// this is for new created models, where nothing was entered - so don't display the error
                     // 	$models[$k]->clearErrors();
                     // }
                     // else
                     // {
                     $hasError = true;
                     // }
                 }
             }
             diedump($models);
         }
         if (!$hasError) {
             $this->redirect(array('update', 'key' => $key));
         }
     }
     $this->render('edit', array('models' => $models, 'allpages' => $this->getAllPagesForAutocomplete(), 'allimages' => $this->getAllImagesForAutocomplete()));
 }
Exemplo n.º 2
0
 public function actionForm($key)
 {
     if (!preg_match("/^[a-z0-9A-z_]+\$/", $key)) {
         $this->render('form/404');
     }
     try {
         $this->render("form/" . $key);
     } catch (CException $e) {
         diedump($e);
         if (substr($e->getMessage(), 0, 19) == 'SubscribeController') {
             $this->render('form/404');
         } else {
             throw $e;
         }
     }
 }
Exemplo n.º 3
0
 public function actionExport()
 {
     $curMonth = date('n');
     $curYear = date('Y');
     if ($curMonth == 11) {
         $firstDay2NextMonth = mktime(0, 0, 0, 0, 0, $curYear + 1);
     } else {
         if ($curMonth == 11) {
             $firstDay2NextMonth = mktime(0, 0, 0, 0, 1, $curYear + 1);
         } else {
             $firstDay2NextMonth = mktime(0, 0, 0, $curMonth + 2, 1);
         }
     }
     $criteria = new CDbCriteria(array('condition' => '`to`>' . (time() - 60 * 30), 'order' => '`from` ASC'));
     $dataProviderAll = new CActiveDataProvider('Termin', array('pagination' => array('pageSize' => 9999), 'criteria' => $criteria));
     $all_events = array();
     foreach ($dataProviderAll->getData() as $m) {
         $all_events[$m->id] = date('d.m.y', $m->from) . ' ' . $m->titel;
     }
     // now only get selected
     if (isset($_POST['inc_events'])) {
         $inc_events = array();
         foreach ($_POST['inc_events'] as $v) {
             $inc_events[] = (int) $v;
         }
         $criteria = new CDbCriteria(array('condition' => '`to`>' . (time() - 60 * 30) . ' AND `id` IN (' . implode(',', $inc_events) . ')', 'order' => '`from` ASC'));
     } else {
         $criteria = new CDbCriteria(array('condition' => '`to`>' . (time() - 60 * 30) . ' AND `from` < ' . $firstDay2NextMonth, 'order' => '`from` ASC'));
     }
     $dataProvider = new CActiveDataProvider('Termin', array('pagination' => array('pageSize' => 9999), 'criteria' => $criteria));
     $inc_events = array();
     foreach ($dataProvider->getData() as $m) {
         $inc_events[] = $m->id;
     }
     $textModel = new TextModel();
     if (isset($_POST['TextModel']) && isset($_POST['TextModel']['text'])) {
         $textModel->text = $_POST['TextModel']['text'];
     }
     $subject = 'Newsletter- ' . strftime("%B", time());
     $from = array('*****@*****.**', 'Newsletter');
     $html = $this->renderPartial('export_mail', array('dataProvider' => $dataProvider, 'textModel' => $textModel), true, false);
     $txt = $this->renderPartial('export_mail_txt', array('dataProvider' => $dataProvider, 'textModel' => $textModel), true, false);
     if (isset($_POST['dowhat']) && $_POST['dowhat'] == 1) {
         $mail = new Email('customer');
         $mail->AddAddress('*****@*****.**')->setSubject($subject)->setMsg($html)->setTxtMsg($txt)->setFrom($from[0], $from[1])->send();
         Yii::app()->user->setFlash('success', 'Erfolgreich an Carl gesendet.');
         $this->redirect(array('export'));
     }
     if (isset($_POST['dowhat']) && ($_POST['dowhat'] == 2 || $_POST['dowhat'] == 3)) {
         $adminEmails = [];
         if (isset(Yii::app()->params['adminEmails'])) {
             $adminEmails = Yii::app()->params['adminEmails'];
         }
         if (isset(Yii::app()->params['adminEmail'])) {
             $adminEmails[] = Yii::app()->params['adminEmail'];
         }
         $mail = new Email('customer');
         $mail->setSubject($subject);
         $mail->setMsg($html);
         $html = $mail->getMsgHtml();
         $from[0] = $adminEmails[0];
         $campaign = Yii::app()->mailchimp->createCampaign($subject, $from[0], $from[1], 'Newsletter', $html, $txt);
         if ($campaign['status'] != "save") {
             diedump($campaign);
         }
         $id = $campaign['id'];
         if ($_POST['dowhat'] == 2) {
             $result = Yii::app()->mailchimp->sendtestCampaign($id, $adminEmails);
             dump($result);
         }
         if ($_POST['dowhat'] == 3) {
             $result = Yii::app()->mailchimp->sendCampaign($id);
             dump($result);
         }
     }
     $this->render('export', array('dataProvider' => $dataProvider, 'all_events' => $all_events, 'inc_events' => $inc_events, 'textModel' => $textModel));
 }
Exemplo n.º 4
0
 public function findCachedByKey($key)
 {
     if (!self::$teamCacheByKey) {
         self::$teamCacheByKey = array();
         foreach ($this->findAll() as $m) {
             self::$teamCacheByKey[$m->key] = $m;
         }
     }
     if (!isset(self::$teamCacheByKey[$key])) {
         diedump(array($key, self::$teamCacheByKey), 2);
     }
     return self::$teamCacheByKey[$key];
 }