public function update() { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $data = $_POST; $data['id'] = $id; if (isset($data['has_sub'])) { $data['has_sub'] = 1; } else { $data['has_sub'] = 0; } $message = $this->validate($data, true); if (!empty($message)) { set_flash_error($message); } $statusSelectbox = selectBox($this->_config['status'], array('Name' => 'status', 'Selected' => $data['status'])); $data['statusSelectbox'] = $statusSelectbox; $allSeries = $this->Series_model->getAllShort(); $seriesSelectbox = selectBox($allSeries, array('Name' => 'series_id', 'Selected' => $data['series_id'])); $data['seriesSelectbox'] = $seriesSelectbox; if (!has_error()) { $result = $this->Video_model->update($id, $data); set_flash_message($this->lang->line('admin.video.updated')); $url = base_url() . 'admin_video/index'; redirect($url); } else { $this->layout->title('Edit video'); $this->layout->view('admin_video/edit', $data); } }
protected function get_admin_user_params() { if (!user_is('admin')) { show_error('Что-то нет прав? Не получается, да?', 500); exit; } $user_id = param('user_id'); if (empty($user_id)) { set_flash_error('Нет id нужного пользователя'); redirect(); } $user = $this->user->find($user_id, 1); if (empty($user)) { set_flash_error('Такого пользователя у нас нет'); } return $user; }
public function update() { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $data = $_POST; $data['id'] = $id; $data['is_complete'] = isset($data['is_complete']) ? SERIES_STATUS_COMPLETE : SERIES_STATUS_ONGOING; $obj = $this->Series_model->getById($id); $data['thumbnail'] = $obj['thumbnail']; $message = $this->validate($data, TRUE); if (!empty($message)) { set_flash_error($message); } $listGenre = $this->Genre_model->getAll(); $defaultGenre = isset($data['genre']) ? $data['genre'] : array(); $genreSelectbox = selectBox($listGenre, array('Name' => 'genre[]', 'multiple' => 'multiple', 'size' => 10, 'Selected' => $defaultGenre)); $data['genreSelectbox'] = $genreSelectbox; $statusSelectbox = selectBox($this->_config['status'], array('Name' => 'status', 'Selected' => $data['status'])); $data['statusSelectbox'] = $statusSelectbox; $countrySelectbox = selectBox($this->_config['countries'], array('Name' => 'country', 'Selected' => $data['country'])); $data['countrySelectbox'] = $countrySelectbox; $typeSelectbox = selectBox($this->_config['video_type'], array('Name' => 'type', 'Selected' => $data['type'])); $data['typeSelectbox'] = $typeSelectbox; if (!has_error()) { $canUpdate = FALSE; if (!empty($_FILES) && !empty($_FILES['thumbnail']['tmp_name'])) { $result = upload_image($_FILES, SERIE_IMAGE_THUMBNAIL_PATH); if ($result['error'] != 0) { $this->layout->title('Edit video'); $this->layout->view('admin_series/edit', $data); } else { $data['thumbnail'] = $result['fileName']; $this->_deleteImage($id); $canUpdate = TRUE; } } else { $canUpdate = TRUE; } if ($canUpdate) { $id = $this->Series_model->update($id, $data); $this->Series_Genre_model->deleteBySeriesId($id); if ($data['genre']) { foreach ($data['genre'] as $genreId) { $seriesGenreData = array(); $seriesGenreData['genre_id'] = $genreId; $seriesGenreData['series_id'] = $id; $this->Series_Genre_model->insert($seriesGenreData); } } $url = base_url() . 'admin_series/index'; set_flash_message($this->lang->line('admin.series.updated')); redirect($url); } } else { $this->layout->title('Edit series'); $this->layout->view('admin_series/edit', $data); } }
/** * Add new comment to topic */ public function comment() { $this->load->model('comment'); $comment['post_id'] = param('post_id'); if (empty($comment['post_id'])) { set_flash_error('Ошибка в параметрах комментария'); redirect(); } $post = $this->post->find($comment['post_id'], 1); if (empty($post)) { set_flash_error('Такого топика не существует'); redirect(); } $comment['parent_id'] = param('parent_id'); $comment['text'] = prepare_text(param('text', TRUE, FALSE)); if (empty($comment['text'])) { set_flash_error('Вы не написали свой комментарий к топику'); redirect(post_link($post)); } $comment['user_id'] = $this->current_user['id']; $comment['added_at'] = now2mysql(); $id = $this->comment->save($comment); if ($id) { set_flash_ok('Спасибо за ваш комментарий'); } else { set_flash_error('Извините, но произошла ошибка и ваш комментарий сохранить не удалось'); } redirect(post_link($post) . '#com' . $id); }
public function update() { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $data = $_POST; $data['id'] = $id; $data['status'] = isset($data['is_active']) ? STATUS_SHOW : 0; $message = $this->validate($data); if (!empty($message)) { set_flash_error($message); } if (!has_error()) { $result = $this->Config_model->update($id, $data); set_flash_message($this->lang->line('admin.config.updated')); $url = base_url() . 'config/index'; redirect($url); } else { $this->layout->title('Edit Config'); $this->layout->view('config/edit', $data); } }
public function save() { $data = $_POST; $importType = $this->_config['import_type']; unset($importType[IMPORT_TYPE_COUNTRY]); $importTypeSelectbox = selectBox($importType, array('Name' => 'import_type_id', 'Selected' => $data['import_type_id'])); $data['importTypeSelectbox'] = $importTypeSelectbox; $typeSelectbox = selectBox($this->_config['video_type'], array('Name' => 'type', 'Selected' => $data['type'])); $data['typeSelectbox'] = $typeSelectbox; $message = $this->validate($data); if (!empty($message)) { set_flash_error($message); } if (!has_error()) { $siteUrl = strtolower($data['site_url']); $id = 0; $importTypeId = $data['import_type_id']; if (strpos($siteUrl, "dramacool.com/")) { if ($importTypeId == IMPORT_TYPE_VIDEO) { $ret = $this->dramaCool->importFromVideoUrl($siteUrl); } elseif ($importTypeId == IMPORT_TYPE_SERIES) { $ret = $this->dramaCool->importFromSeriesUrl($siteUrl); } elseif ($importTypeId == IMPORT_TYPE_COUNTRY) { die; //$ret = $this->dramaCool->importFromCountryUrl($siteUrl); } $id = $ret['id']; } if ($id) { $url = base_url() . 'admin_video/show?id=' . $id; set_flash_message($this->lang->line('admin.import.success')); redirect($url); } else { set_flash_error($ret['msg']); $this->layout->title('Import Data'); $this->layout->view('import_data/import', $data); } } else { $this->layout->title('Import Data'); $this->layout->view('import_data/import', $data); } }
public function update_box_item() { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $data = $_POST; $data['id'] = $id; $obj = $this->Editor_Box_Item_model->getById($id); $data['item_thumbnail'] = $obj['item_thumbnail']; $originalThumb = $obj['item_thumbnail']; $message = $this->validate_box_item($data, TRUE); if (!empty($message)) { set_flash_error($message); } $listBox = $this->Editor_Box_model->getAll(); $boxSelectbox = selectBox($listBox, array('Name' => 'box_id', 'MainOption' => TRUE, 'Selected' => $data['box_id'])); $data['boxSelectbox'] = $boxSelectbox; if (!has_error()) { $isUpload = FALSE; $canUpdate = FALSE; if (!empty($_FILES) && !empty($_FILES['item_thumbnail']['tmp_name'])) { $result = upload_image($_FILES, EDITOR_IMAGE_THUMBNAIL_PATH); if ($result['error'] != 0) { $this->layout->title('Edit box item'); $this->layout->view('admin_editor/edit_box_item', $data); } else { $data['item_thumbnail'] = $result['fileName']; $canUpdate = TRUE; $isUpload = TRUE; } } else { $canUpdate = TRUE; } if ($canUpdate) { $id = $this->Editor_Box_Item_model->update($id, $data); if ($isUpload && file_exists(EDITOR_IMAGE_THUMBNAIL_PATH . $originalThumb)) { unlink(EDITOR_IMAGE_THUMBNAIL_PATH . $originalThumb); } $url = base_url() . 'admin_editor/list_box_item'; set_flash_message($this->lang->line('admin.box.updated')); redirect($url); } } else { $this->layout->title('Edit box item'); $this->layout->view('admin_editor/list_box_item', $data); } }
/** * Index default method. Main LJ import logic implements here. */ public function index() { //Loading necessary libs and models $this->load->library(array('form_validation', 'session')); $this->load->model(array('post', 'tag', 'module', 'user', 'comment')); //N last posts from LJ $nlast = $this->settings['nlast']; //Import comments $comments = $this->settings['comments']; //Before date $beforedate = ''; //Posts count $nposts = 0; //If user has not logged in - redirect him at login page $user = current_user(); if ($user['id'] == '') { set_flash_error('Прежде чем импортировать вам надо войти на сайт'); redirect('user/login'); } //If user have already sent login & password ... //... do import posts from LJ if ($this->session->userdata('lj_cookie') != '') { $this->data['lj_authorized'] = true; $beforedate = $this->session->userdata('beforedate'); //Check if user has logged in $user = current_user(); //Loading LJ_Reader library $params = array('cookie' => $this->session->userdata('lj_cookie'), 'username' => $this->session->userdata('lj_user'), 'prefetch' => false, 'nlast' => $nlast, 'comments' => $comments); $this->load->library('LJ_Reader', $params); //fetching posts $lj_posts = $this->lj_reader->fetch_posts('', $beforedate); foreach ($lj_posts as $lj_post) { //Creating the post $post_id = $this->create_post($user['id'], $lj_post['subject'], $lj_post['event']); //Adding the comments if (!empty($lj_post['comments'])) { foreach ($lj_post['comments'] as $comment) { $this->add_comment($post_id, $comment); } } //Incrementing current posts count and saving beforedate param $nposts++; $beforedate = $lj_post['eventtime']; } if ($nposts == $nlast) { $this->session->set_userdata(array('beforedate' => $beforedate, 'ntotal' => $this->session->userdata('ntotal') + $nposts)); $this->data['redirect'] = true; //redirect(current_url()); } else { $this->data['import_complete'] = 'Импорт постов из жж завершен успешно. Добавлено записей : ' . ($this->session->userdata('ntotal') + $nposts); $this->session->unset_userdata(array('lj_cookie' => '', 'lj_user' => '', 'beforedate' => '', 'ntotal' => '')); } //If user just entered user data - validate it and redirect with lj_authorized=true } elseif ($_POST) { $config = array(array('field' => 'login', 'label' => 'Имя пользователя', 'rules' => 'required|trim|max_length[15]'), array('field' => 'password', 'label' => 'Пароль', 'rules' => 'required|trim|min_length[1]|max_length[255]')); $this->form_validation->set_rules($config); // If form has been validated - do lj authorise and getting cookie to the session if ($this->form_validation->run($this) === TRUE) { $params = array('username' => $_POST['login'], 'password' => $_POST['password'], 'prefetch' => false, 'nlast' => $nlast); $this->load->library('LJ_Reader', $params); if ($this->lj_reader->get_cookie() != '') { $this->data['lj_authorized'] = true; } //Put cookie to the session $this->session->set_userdata(array('lj_cookie' => $this->lj_reader->get_cookie(), 'lj_user' => $_POST['login'], 'ntotal' => 0)); $this->data['redirect'] = true; //redirect(current_url()); } else { $this->data['lj_authorized'] = false; } } $this->template->render_to('content', $this->view . 'index', $this->data); $this->draw(); }