…
<?php
class actionExplistAdd extends cmsAction {
public function run(){
if (!$this->request->isAjax()){ cmsCore::error404(); }
$title = $this->request->get('title', '');
if (!$title){
return $this->cms_template->renderJSON(array('error' => true, 'message' => 'Заполнить поле')); }
$cat_id = $this->request->get('cat_id', 0);
if ($cat_id){
$this->model->filterEqual('i.cat_id', $cat_id);
}
$item = $this->model->filterEqual('i.title', $title)->getData('explist', false, true);
if (!empty($item['id'])){ return $this->cms_template->renderJSON(array( 'error' => false,
'html' => '',
'id' => $item['id']
));
}
$result = $this->model->saveData('explist', array('title' => $title, 'cat_id' => $cat_id)); if ($result){
if (!empty($this->options['notices'])){ $text = 'Добавлен новый пункт в список';
foreach ($this->options['notices'] as $idx => $admin){
if (!$this->model->filterEqual('i.user_id', $admin)->filterEqual('i.content', $text)->getItem('users_notices')){
$this->controller_messages->addRecipient($admin);
}
}
$this->controller_messages->sendNoticePM(array( 'content' => $text,
'title' => LANG_SHOW,
'href' => href_to
('admin', 'controllers', array('edit', 'explist', 'items_form', $result)) )
)
));
}
return $this->cms_template->renderJSON(array( 'error' => false,
'html' => '<option value="' . $result . '">' . $title . '</option>',
'id' => $result
));
}
return $this->cms_template->renderJSON(array('error' => true, 'message' => 'Неизвестная ошибка'));
}
}