Mistři v programování na #hovnokod

PHP #2480

nette ninja...

public function actionCreateArticle() {
		$must = array('ArticlePicture','ArticleTitle','ArticlePerex','ArticleContent');		
		if($_POST) {
			$err=0;
			foreach($_POST as $k=>$v) {
				if(in_array($k,$must)) {
					if(empty($v)) {
						$err++;
					}
				}
				if(($k=='PublishedFrom' || $k=='PublishedTo') && $v !='') {
					$v = strtotime($v);
				} else if(($k=='PublishedFrom' || $k=='PublishedTo') && $v ==''){
					$toUnset[] = $k;
				}
				if($k == 'id_articles_categories' && $v == 'null' && $_POST['NewCategory'] == '') {
					$this->flashMessage('Nevybrali ste žiadnu kategóriu a ani ste nezadali názov novej.','warning');
				} else if($k == 'id_articles_categories' && $v != 'null') {
					$toUnset[] = 'NewCategory';
				}
				$toInsert[$k] = $v;
			}
			foreach($toUnset as $k) {
				unset($toInsert[$k]);
			}
			if($err>0) {
				$this->flashMessage('Neboli korektne vyplnené povinné údaje','warning');
			}		 
			$toInsert['CreatedOn'] = time();
			$toInsert['id_user'] = $this->user->getId();
			$this->template->data = $_POST;
			if(!$this->user->isInRole('admin')) {
				$toInsert['ArticleStatus'] = 'new';
				
			}
			
			$in = $this->db->table('articles')->insert($toInsert);
			if($in) {
				if(!$this->user->isInRole('admin')) {
					$this->emailData = $toInsert;
					$this->emailData['ArticleID'] = $in->id;
					if($this->templatedEmail(array('email'=>'cenzurovane','name'=>'cenzurovane'),'newArticle',array('email'=>$this->user->identity->UserEmail,'name'=>$toInsert['AuthorDisplayName']))) {
						$this->flashMessage('Emailom bola odoslaná notifikácia na administrátorov.','info');
					}
				}
				$this->flashMessage('Váš článok bol úspešne pridaný.',"success");
				$this->redirect('Admin:UpdateArticle',array('id'=>$in->id));
			}			
		}
	}

Anonymous,