Exemplo n.º 1
0
 public function action_edit($user_id)
 {
     $this->template->title = __("Sửa thông tin tài khoản");
     $this->template->section_title = __("Sửa thông tin tài khoản");
     $data = array();
     $user_id = intval($user_id);
     if ($user_id <= 0) {
         Request::instance()->redirect('admin/user/index');
     }
     $user = BLL_User::getById($user_id);
     if (!$user) {
         Request::instance()->redirect('admin/user/index');
     }
     if (Request::$method == 'POST') {
         $active = isset($_POST['active']);
         $post = $user->validate_update($_POST);
         if ($post->check()) {
             $post = $post->as_array();
             $user->password = Auth::instance()->hash_password($post['password']);
             $user->save();
             Message::success('Thay đổi thông tin thành công');
             Request::instance()->redirect('admin/user/index');
         } else {
             $_POST = $post->as_array();
             $data['errors'] = $post->errors('admin/user/form');
         }
     }
     $data['user'] = $user->toArray();
     $this->template->content = View::factory('admin/user/edit', $data);
 }
Exemplo n.º 2
0
 public function action_user()
 {
     $id = (int) $this->request->param('id', 0);
     $post = ORM::factory('user', $id);
     if (!$post->loaded() or $id === 1) {
         Message::error(__("User doesn't exists!"));
         Log::error('Attempt to access non-existent user.');
         $this->request->redirect(Route::get('admin/user')->uri(array('action' => 'list')), 404);
     }
     $this->title = __(':user Permissions', array(":user" => $post->name));
     $action = Route::get('admin/permission')->uri(array('action' => 'user', 'id' => isset($post->id) ? $post->id : 0));
     $view = View::factory('admin/permission/user')->set('post', $post)->set('oldperms', $post->perms())->set('permissions', ACL::all())->set('action', $action)->bind('errors', $this->_errors);
     if ($this->valid_post('permissions')) {
         $perms = array_filter($_POST['perms']);
         $post->data = array('permissions' => $perms);
         try {
             $post->save();
             Message::success(__('Permissions: saved successful!'));
             $this->request->redirect(Route::get('admin/permission')->uri(array('action' => 'user', 'id' => $post->id)));
         } catch (ORM_Validation_Exception $e) {
             Message::error(__('Permissions save failed!'));
             $this->_errors = $e->errors('models', TRUE);
         } catch (Exception $e) {
             Message::error(__('Permissions save failed!'));
             $this->_errors = array($e->getMessage());
         }
     }
     $this->response->body($view);
 }
Exemplo n.º 3
0
 public function action_create()
 {
     $this->template->title = __("Thêm mới kênh truyền hình");
     $this->template->section_title = __("Thêm mới kênh truyền hình");
     $data = array();
     if (Request::$method == "POST") {
         $channel = new LichTruyenHinh();
         $post = $channel->validate_create($_POST);
         if ($post->check()) {
             $post = $post->as_array();
             $channel->user_id = Auth::instance()->get_user()->id;
             $channel->channel_name = $post['channel_name'];
             $channel->active = true;
             $channel->slug = $post['slug'];
             $channel->meta_keys = $post['meta_keys'];
             $channel->meta_desc = $post['meta_desc'];
             $channel->xml_uri = $post['xml_uri'];
             $channel->created_at = date("Y-m-d h:i:s");
             $channel->save();
             Message::success('Thêm mới kênh truyền hình thành công!');
             Request::instance()->redirect('/admin/lichtruyenhinh/index');
         } else {
             $_POST = $post->as_array();
             $data['errors'] = $post->errors();
         }
     }
     //        $categories = TruyenCuoiCategory::bll()->getCatById_WithStoryCount();
     //        $data['categories'] = $categories;
     $this->template->content = View::factory('/admin/lichtruyenhinh/create', $data);
 }
Exemplo n.º 4
0
 public function action_spam()
 {
     $id = (int) $this->request->param('id', 0);
     $question = ORM::factory('Feedback_Question', $id);
     $user_id = $this->user->id;
     if (!$question->loaded()) {
         $this->redirect('manage/feedback');
     }
     $token = Arr::get($_POST, 'token', false);
     $return = Security::xss_clean(Arr::get($_GET, 'r', 'manage/expert'));
     $this->set('return', Url::media($return));
     if ($this->request->method() == Request::POST && Security::token() === $token) {
         $question->is_spam = ($question->is_spam + 1) % 2;
         $question->spam_mod_id = $user_id;
         $question->save();
         if ($question->is_spam == 1) {
             Message::success(i18n::get('The question is marked as spam'));
         } else {
             Message::success(i18n::get('Marked "Spam" is removed from the question'));
         }
         $this->redirect($return);
     } else {
         if ($question->loaded()) {
             $this->set('question', $question)->set('token', Security::token(true));
         } else {
             $this->redirect('manage/expert');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Edit
  */
 public function action_edit()
 {
     $this->title = __('home.page_edit');
     // Fields for save
     $for_extract = ['text', 'meta_t', 'meta_d', 'meta_k'];
     $config = Config::get('home');
     $data = Arr::extract($_POST, $for_extract);
     if ($this->request->is_post()) {
         $data = Validation::factory(array_map('trim', $data))->rule('meta_t', 'not_empty')->rule('meta_d', 'not_empty')->rule('meta_k', 'not_empty');
         if ($data->check()) {
             foreach ($for_extract as $field) {
                 $config[$field] = $data[$field];
             }
             $config->save();
             Message::success(__('settings.changes_saved'));
             HTTP::redirect(Route::url('b_home'));
         } else {
             Message::error(__('settings.error_saving'));
             $errors = $data->errors('validation');
         }
     } else {
         $data = $config;
     }
     $this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors);
 }
Exemplo n.º 6
0
 public function action_login()
 {
     if ($this->_auth->logged_in()) {
         // redirect to the user account
         $this->request->redirect(Route::get('admin')->uri(), 200);
     }
     // Disable sidebars on login page
     $this->_sidebars = FALSE;
     $this->title = __('Sign In');
     $user = ORM::factory('user');
     // Create form action
     $destination = isset($_GET['destination']) ? $_GET['destination'] : 'admin';
     $params = array('action' => 'login');
     $action = Route::get('admin/login')->uri($params) . URL::query(array('destination' => $destination));
     if ($layout = kohana::find_file('views', 'layouts/login')) {
         $this->template->set_filename('layouts/login');
     }
     $view = View::factory('admin/login')->set('use_username', Config::get('auth.username'))->set('post', $user)->set('action', $action)->bind('errors', $this->_errors);
     if ($this->valid_post('login')) {
         try {
             // Check Auth
             $user->login($this->request->post());
             // If the post data validates using the rules setup in the user model
             Message::success(__('Welcome, %title!', array('%title' => $user->nick)));
             Log::info('User :name logged in.', array(':name' => $user->name));
             // redirect to the user account
             $this->request->redirect(isset($_GET['destination']) ? $_GET['destination'] : 'admin', 200);
         } catch (Validation_Exception $e) {
             $this->_errors = $e->array->errors('login', TRUE);
         }
     }
     $this->response->body($view);
 }
Exemplo n.º 7
0
 public function action_delete()
 {
     $search = $this->request->param('string', "");
     $id = $this->request->param('material_id', 0);
     $id_project = $this->request->param('project_id', 0);
     $type = $this->request->param('type', 0);
     $article = ORM::factory('Material_Project')->where('material_id', '=', $id)->where('project_id', '=', $id_project)->where('type', '=', $type)->find();
     $id = $article->id;
     $article = ORM::factory('Material_Project', $id);
     $article->delete();
     Message::success('Удалено');
     $this->redirect('manage/search/' . $id_project . '/all/' . $search);
     /*if (!$article->loaded())
             {
                 throw new HTTP_Exception_404;
             }
             $token = Arr::get($_POST, 'token', false);
             if (($this->request->method() == Request::POST) && Security::token() === $token)
             {
                 $loger = new Loger('delete',$article->material_id);
                 $loger->logThis($article);
                 $article->delete();
     
     
     
                 Message::success('Удалено');
                 $this->redirect('manage/project/'.$id_project );
             }
             else
             {
                 $this->set('record', $article)->set('token', Security::token(true))->set('cancel_url', Url::media('manage/project/'.$id_project));
             }
     
     */
 }
Exemplo n.º 8
0
 public function action_edit()
 {
     $id = $this->request->param('id', 0);
     $opinion = ORM::factory('Expert_Opinion', $id);
     $experts = ORM::factory('Expert')->order_by('name_' . I18n::$lang)->find_all();
     $user_id = $this->user->id;
     $this->set('opinion', $opinion);
     $this->set('experts', $experts);
     if ($this->request->method() == Request::POST) {
         try {
             $opinion->expert_id = Arr::get($_POST, 'expert_id', '');
             $opinion->title = Arr::get($_POST, 'title', '');
             $opinion->description = Arr::get($_POST, 'description', '');
             $opinion->text = Arr::get($_POST, 'text', '');
             $opinion->protected = Arr::get($_POST, 'protected', '');
             $opinion->date = date('Y-m-d H:i:s');
             $opinion->user_id = $user_id;
             $opinion->save();
             $event = $id ? 'edit' : 'create';
             $loger = new Loger($event, $opinion->title);
             $loger->logThis($opinion);
             Message::success(i18n::get('The position of an expert retained'));
             $this->redirect('manage/expertopinions/view/' . $opinion->id . '/page-' . $this->page);
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors($e->alias());
             foreach ($errors as $key => $item) {
                 $errors[preg_replace("/(_ru|_kz|_en)/", '', $key)] = preg_replace("/(_ru|_kz|_en)/", '', $item);
             }
             $this->set('opinion', $_POST);
             $this->set('errors', $errors);
         }
     }
 }
Exemplo n.º 9
0
 public static function display()
 {
     $messages = "";
     if ($_POST['cc_form'] === 'add-group') {
         $group = $_POST['group'];
         $rows = Database::select('users', 'name', array('name = ? AND type = ?', $group, 'group'), null, 1)->fetch(PDO::FETCH_ASSOC);
         if (!empty($rows)) {
             $messages .= Message::error(__('admin', 'group-in-use'));
         } else {
             $row = DB::select('users', array('data'), array('users_id = ?', $_GET['parent']))->fetch(PDO::FETCH_ASSOC);
             $inheritance = unserialize($row['data']);
             $inheritance = $inheritance['permissions'];
             $result = Database::insert('users', array('name' => filter('admin_add_group_name', $group), 'type' => 'group', 'group' => '-1', 'data' => serialize(filter('admin_add_group_data', array('permissions' => $inheritance)))));
             if ($result === 1) {
                 $messages .= Message::success(__('admin', 'group-added'));
             }
         }
     }
     $form = new Form('self', 'post', 'add-group');
     $form->startFieldset(__("admin", 'group-information'));
     $form->addInput(__('admin', 'group-name'), 'text', 'group', self::get('group'));
     $groups = Users::allGroups();
     foreach ($groups as $key => $value) {
         $groups[$value->getId()] = $value->getName();
     }
     $form->addSelectList(__('admin', 'inherit-permissions'), 'parent', $groups);
     plugin('admin_add_group_custom_fields', array(&$form));
     $form->addSubmit('', 'add-group', __('admin', 'add-group'));
     $form->endFieldset();
     plugin('admin_add_group_custom_fieldset', array(&$form));
     $form = $form->endAndGetHTML();
     return array(__('admin', 'add-group'), $messages . $form);
 }
Exemplo n.º 10
0
 /**
  * Basic
  */
 public function action_edit()
 {
     $this->title = __('settings.settings_general');
     // Fields for save
     $for_extract = ['per_page_frontend', 'per_page_backend', 'sitename', 'siteslogan', 'copyright', 'year_creation_site', 'type_backend_menu'];
     $config = Config::get('settings');
     $data = Arr::extract($_POST, $for_extract);
     if ($this->request->is_post()) {
         $data = Validation::factory(array_map('trim', $data))->rules('per_page_frontend', [['not_empty'], ['digit']])->rules('per_page_backend', [['not_empty'], ['digit']])->rules('year_creation_site', [['not_empty'], ['digit']])->rule('sitename', 'not_empty');
         if ($data->check()) {
             foreach ($for_extract as $field) {
                 $config[$field] = $data[$field];
             }
             $config->save();
             Message::success(__('settings.changes_saved'));
             HTTP::redirect(Route::url('b_settings'));
         } else {
             Message::error(__('settings.error_saving'));
             $errors = $data->errors('validation');
         }
     } else {
         $data = $config;
     }
     $this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors);
 }
Exemplo n.º 11
0
 public function messages(Message $message)
 {
     $this->tpl->error = $message->error();
     $this->tpl->success = $message->success();
     $this->tpl->alert = $message->alert();
     $this->tpl->info = $message->info();
     $this->tpl->debug = $message->debug();
 }
Exemplo n.º 12
0
 public function action_delete()
 {
     $id = (int) $this->request->param('id', 0);
     $token = Arr::get($_POST, 'token', false);
     $acts = ORM::factory('Acts', $id);
     if (!$acts->loaded()) {
         throw new HTTP_Exception_404();
     }
     if ($this->request->post() && Security::token() === $token) {
         $acts->delete();
         Message::success('Акт удален');
         $this->redirect('manage/acts');
     } else {
         $this->set('record', $acts)->set('token', Security::token(true))->set('cancel_url', Url::media('manage/acts'));
     }
 }
Exemplo n.º 13
0
 public function action_delete()
 {
     $id = (int) $this->request->param('id', 0);
     $link = ORM::factory('Link', $id);
     if (!$link->loaded()) {
         throw new HTTP_Exception_404();
     }
     $token = Arr::get($_POST, 'token', false);
     if ($this->request->method() == Request::POST && Security::token() === $token) {
         $link->delete();
         Message::success('Удалено');
         $this->redirect('manage/links');
     } else {
         $this->set('record', $link)->set('token', Security::token(true))->set('cancel_url', Url::media('manage/links'));
     }
 }
Exemplo n.º 14
0
 public function action_delete()
 {
     $type = (int) Arr::get($_GET, 'type', 0);
     $id = (int) $this->request->param('id', 0);
     $item = ORM::factory('Comment', $id);
     if (!$item->loaded()) {
         throw new HTTP_Exception_404();
     }
     $token = Arr::get($_POST, 'token', false);
     if ($this->request->method() == Request::POST && Security::token() === $token) {
         $item->delete();
         Message::success('Комментарий удален');
         $this->redirect('manage/comments?type=' . $type);
     } else {
         $this->set('type', $type);
         $this->set('record', $item)->set('token', Security::token(true))->set('cancel_url', Url::media('manage/comments?type=' . $type));
     }
 }
Exemplo n.º 15
0
 public function action_checked()
 {
     $id = $this->request->param('id', 0);
     $penitentials = ORM::factory('Penitentials', $id);
     if (!$penitentials->loaded()) {
         throw new HTTP_Exception_404();
     }
     if ($penitentials->checked) {
         $penitentials->checked = 0;
         $penitentials->save();
         Message::success('Траурный режим отключен');
     } else {
         $penitentials->checked = 1;
         $penitentials->save();
         Message::success('Траурный режим включен');
     }
     $this->redirect('manage/penitentials/');
 }
Exemplo n.º 16
0
 /**
  * Sending mails
  *
  * @since 1.0.0  First time this method was introduced
  * @since 1.1.0  Added jQuery Textarea Characters Counter Plugin
  *
  * @link  http://roy-jin.appspot.com/jsp/textareaCounter.jsp
  *
  * @uses  Request::query
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  URL::query
  * @uses  URL::site
  * @uses  Validation::rule
  * @uses  Config::get
  * @uses  Config::load
  * @uses  Assets::js
  */
 public function action_mail()
 {
     $this->title = __('Contact us');
     $config = Config::load('contact');
     Assets::js('textareaCounter', 'media/js/jquery.textareaCounter.plugin.js', array('jquery'), FALSE, array('weight' => 10));
     Assets::js('greet/form', 'media/js/greet.form.js', array('textareaCounter'), FALSE, array('weight' => 15));
     //Add schema.org support
     $this->schemaType = 'ContactPage';
     // Set form destination
     $destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array();
     // Set form action
     $action = Route::get('contact')->uri(array('action' => $this->request->action())) . URL::query($destination);
     // Get user
     $user = User::active_user();
     // Set mail types
     $types = $config->get('types', array());
     $view = View::factory('contact/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('types', $types)->set('user', $user)->bind('post', $post)->bind('errors', $this->_errors);
     // Initiate Captcha
     if ($config->get('use_captcha', FALSE) and !$this->_auth->logged_in()) {
         $captcha = Captcha::instance();
         $view->set('captcha', $captcha);
     }
     if ($this->valid_post('contact')) {
         $post = Validation_Contact::factory($this->request->post());
         if ($post->check()) {
             // Create the email subject
             $subject = __('[:category] :subject', array(':category' => $types[$post['category']], ':subject' => Text::plain($post['subject'])));
             // Create the email body
             $body = View::factory('email/contact')->set('name', $post['name'])->set('body', $post['body'])->set('config', Config::load('site'))->render();
             // Create an email message
             $email = Email::factory()->to(Text::plain($this->_config->get('site_email', '*****@*****.**')), __('Webmaster :site', array(':site' => Template::getSiteName())))->subject($subject)->from($post['email'], Text::plain($post['name']))->message($body, 'text/html');
             // @todo message type should be configurable
             // Send the message
             $email->send();
             Log::info(':name sent an e-mail regarding :cat', array(':name' => Text::plain($post['name']), ':cat' => $types[$post['category']]));
             Message::success(__('Your message has been sent.'));
             // Always redirect after a successful POST to prevent refresh warnings
             $this->request->redirect(Route::get('contact')->uri(), 200);
         } else {
             $this->_errors = $post->errors('contact', TRUE);
         }
     }
     $this->response->body($view);
 }
Exemplo n.º 17
0
 public static function display()
 {
     if (!is_numeric($_GET['id'])) {
         cc_redirect(Admin::link('users'));
     }
     if ($_POST['cc_form'] == 'edit-group') {
         $id = $_GET['id'];
         $previous = (array) unserialize(urldecode($_POST['previous']));
         $group = $_POST['group'];
         $permissions = (array) $_POST['permissions'];
         $new = array_merge($previous, $permissions);
         foreach ($new as $k => $v) {
             if ($v == "1") {
                 $new[$k] = true;
             }
             if (!array_key_exists($k, $permissions)) {
                 $new[$k] = false;
             }
         }
         if (DB::update('users', array('name', 'data'), array($group, serialize(filter('admin_edit_group_data', array('permissions' => $new)))), array('users_id = ?', $id))) {
             $message = Message::success(__('admin', 'group-information-updated'));
         } else {
             $message = Message::error(__('admin', 'database-error'));
         }
     }
     $p = Permissions::getAll();
     $g = new Group((int) $_GET['id']);
     $p_form = new Form('');
     $p_form->setCC_Form('edit-group');
     $p_form->startFieldset(__('admin', 'group-information'));
     $p_form->addInput(__('admin', 'group-name'), 'text', 'group', $g->getName());
     $p_form->endFieldset();
     $p_form->addHTML(sprintf("<h3>%s</h3>", __('admin', 'permissions')));
     $p_table = new Table('permissions');
     $p_table->addHeader(array('Name', 'Allowed'));
     foreach ($p as $k => $v) {
         $previous[$v['name']] = $g->isAllowed($v['name']);
         $p_table->addRow(array(__('permissions', $v['name']), sprintf('<input type="checkbox" name="permissions[%s]"%svalue="1"/>', $v['name'], $g->isAllowed($v['name']) ? ' checked="checked"' : '')));
     }
     $p_form->addHidden('previous', urlencode(serialize($previous)));
     $p_form->addHTML($p_table->html());
     $p_form->addSubmit('', 'save-permissions', __('admin', 'save-changes'));
     return array(sprintf('%s: %s', __('admin', 'edit-group'), $g->getName()), $message . $p_form->html());
 }
Exemplo n.º 18
0
 public static function form($controller, $item, $_action = FALSE, $captcha = FALSE)
 {
     // Set default comment form action
     $action = Request::current()->uri();
     $view = View::factory('comment/form')->set('use_captcha', $captcha)->set('action', $action)->set('is_edit', FALSE)->set('auth', Auth::instance())->set('destination', array())->set('item', $item)->bind('errors', $errors)->bind('post', $post);
     // Set form action either from model or action param
     if ($item->url) {
         $action = (string) $item->url;
     } elseif ($_action) {
         $action = $_action;
     }
     // Set if captcha necessary
     if ($captcha) {
         $captcha = Captcha::instance();
         $view->set('captcha', $captcha);
     }
     // Load the comment model
     $post = ORM::factory('comment');
     if ($controller->valid_post('comment')) {
         $values = Arr::merge(array('post_id' => $item->id, 'type' => $item->type), $_POST);
         try {
             $post->values($values)->save();
             if ($post->status != 'publish') {
                 Message::success(__('Your comment has been queued for review by site administrators and will be published after approval.'));
             } else {
                 Message::success(__('Your comment has been posted.', array(':title' => $post->title)));
             }
             // Save the anonymous user information to a cookie for reuse.
             if (User::is_guest()) {
                 User::cookie_save(array('name' => $post->guest_name, 'email' => $post->guest_email, 'url' => $post->guest_url));
             }
             Log::info('Comment: :title has posted.', array(':title' => $post->title));
             // Redirect to post page
             $controller->request->redirect(Request::current()->uri());
         } catch (ORM_Validation_Exception $e) {
             // @todo Add messages
             $errors = $e->errors('models', TRUE);
         }
     }
     return $view;
 }
Exemplo n.º 19
0
 public function action_edit()
 {
     $id = $this->request->param('id', 0);
     $expert = ORM::factory('Expert', $id);
     if ($expert->loaded()) {
         $flag = true;
     } else {
         $flag = false;
     }
     $user_id = $this->user->id;
     $uploader = View::factory('storage/image')->set('user_id', $user_id)->render();
     $this->set('uploader', $uploader);
     $this->set('expert', $expert);
     $this->set('page', $this->page);
     if ($this->request->method() == Request::POST) {
         try {
             $expert->name = Arr::get($_POST, 'name', '');
             $expert->image = (int) Arr::get($_POST, 'image', '');
             $expert->description = Arr::get($_POST, 'description', '');
             $expert->position = Arr::get($_POST, 'position', '');
             $expert->date = date('Y-m-d H:i:s');
             $expert->user_id = $user_id;
             $expert->save();
             if (!$flag) {
                 $list = ORM::factory('Expert');
                 $paginate = Paginate::factory($list);
                 $list = $list->find_all();
                 $this->page = $paginate->page_count();
             }
             Message::success(i18n::get('The expert retained'));
             $this->redirect('manage/expert/view/' . $expert->id . '/page-' . $this->page);
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors($e->alias());
             foreach ($errors as $key => $item) {
                 $errors[preg_replace("/(_ru|_kz|_en)/", '', $key)] = preg_replace("/(_ru|_kz|_en)/", '', $item);
             }
             $this->set('expert', $_POST);
             $this->set('errors', $errors);
         }
     }
 }
Exemplo n.º 20
0
 public function action_edit()
 {
     $type = Arr::get($_GET, 'type');
     $symbols = ORM::factory('Symbol')->where('key', '=', $type)->find();
     $uploader = View::factory('storage/image')->set('user_id', $this->user->id)->render();
     if ($post = $this->request->post()) {
         try {
             $symbols->title = Security::xss_clean(Arr::get($post, 'title', ''));
             $symbols->text = Security::xss_clean(Arr::get($post, 'text', ''));
             $symbols->image = Arr::get($post, 'image', 0);
             $symbols->key = $type;
             $symbols->save();
             Message::success('Информация о государственных символах сохранена');
             $this->redirect('manage/symbols');
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors($e->alias());
             $this->set('errors', $errors);
         }
     }
     $this->set('item', $symbols)->set('type', $type)->set('uploader', $uploader);
 }
Exemplo n.º 21
0
 /**
  * Edit module interface
  * (internationalization module)
  */
 protected function module_i18n()
 {
     if (!isset($this->cms_modules[$this->config_mod['cms_module']])) {
         return false;
     }
     $data = Arr::get($_POST, 'data', []);
     if ($this->request->is_post()) {
         $path = $this->cms_modules[$this->config_mod['cms_module']] . 'i18n' . DS . $this->language . EXT;
         File::var_export($data, $path);
         Message::success(__('settings.changes_saved'));
         HTTP::redirect(Route::url(Request::get('routename'), ['controller' => Request::get('controller'), 'action' => 'i18n']));
     }
     $group = str_replace('cms_', '', $this->config_mod['cms_module']);
     foreach (I18n::load($this->language) as $key => $val) {
         if (preg_match('/^' . $group . '\\./', $key)) {
             $data[$key] = $val;
         }
     }
     $this->title = $this->config_mod['cms_module'] == 'cms_settings' ? __('settings.i18n_edit_global') : __('settings.i18n_edit_iface');
     $this->content = View::factory('backend/v_i18n', ['data' => $data]);
 }
Exemplo n.º 22
0
 public function action_delete($role_id = 0)
 {
     $this->auto_render = false;
     $role_id = intval($role_id);
     if ($role_id > 0) {
         $role = BLL_Role::getById($role_id);
         if ($role) {
             if (count($role->Users) == 0) {
                 $role->delete();
                 Message::success('Xóa nhóm thành công!');
             } else {
                 Message::error('Không thể xóa nhóm vì có chứa thành viên bên trong');
             }
         } else {
             Message::error('Không thể tìm thấy nhóm');
         }
     } else {
         Message::error('Không thể tìm thấy nhóm');
     }
     Request::instance()->redirect('/admin/role/index');
 }
Exemplo n.º 23
0
 public function action_close($id)
 {
     $project = ORM::factory('project', $id);
     if (!$project->loaded()) {
         Message::error('No Such Project');
         Request::instance()->redirect('project/');
     }
     if (Auth::instance()->get_user()->id != $project->user_id) {
         Message::error('That Project Doesn\'t Belong To You');
         Request::instance()->redirect('project/');
     }
     $project->closed = true;
     $project->save();
     if ($project->saved()) {
         Message::success('Closed project, ' . HTML::chars($project->name));
         Request::instance()->redirect('project/');
     } else {
         Message::error('Could not close project.');
         Request::instance()->redirect('project/view/' . $project->id);
     }
 }
Exemplo n.º 24
0
 public static function display()
 {
     $messages = "";
     if ($_POST['cc_form'] === 'add-user') {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $cpassword = $_POST['confirm-password'];
         $group = $_POST['group'];
         if ($password != $cpassword) {
             $messages .= Message::error(__('admin', 'passwords-dont-match'));
         } else {
             $rows = Database::select('users', 'name', array('name = ? AND type = ?', $username, 'user'), null, 1)->fetch(PDO::FETCH_ASSOC);
             if (!empty($rows)) {
                 $messages .= Message::error(__('admin', 'username-in-use'));
             } else {
                 $hash = hash('whirlpool', $password);
                 $result = Database::insert('users', array('name' => filter('admin_add_user_username', $username), 'value' => $hash, 'type' => 'user', 'group' => filter('admin_add_group', $group), 'data' => serialize(filter('admin_add_user_data', array()))));
                 if ($result === 1) {
                     $messages .= Message::success(__('admin', 'user-added'));
                 }
             }
         }
     }
     $form = new Form('self', 'post', 'add-user');
     $groups = Users::allGroups();
     foreach ($groups as $key => $value) {
         $groups[$value->getId()] = $value->getName();
     }
     $form->startFieldset(__("admin", 'user-information'));
     $form->addInput(__('admin', 'username'), 'text', 'username', self::get('username'));
     $form->addInput(__('admin', 'password'), 'password', 'password');
     $form->addInput(__('admin', 'confirm-password'), 'password', 'confirm-password');
     $form->addSelectList(__('admin', 'group'), 'group', $groups, true, self::get('group'));
     plugin('admin_add_user_custom_fields', array(&$form));
     $form->addSubmit('', 'add-user', __('admin', 'add-user'));
     $form->endFieldset();
     plugin('admin_add_user_custom_fieldset', array(&$form));
     $form = $form->endAndGetHTML();
     return array(__('admin', 'add-user'), $messages . $form);
 }
Exemplo n.º 25
0
 /**
  * General Settings
  *
  * @uses  Config::load
  * @uses  Message::success
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  Date::date_time_formats
  * @uses  Date::date_formats
  * @uses  Date::time_formats
  * @uses  Date::weeekdays
  * @uses  Date::timezones
  * @uses  Template::valid_post
  * @uses  Request::redirect
  */
 public function action_index()
 {
     $this->title = __('Settings');
     $config = Config::load('site');
     if (isset($config['maintenance_mode']) and $config['maintenance_mode'] == 1) {
         Message::success(__('Site running in maintenance mode!'));
     }
     $action = Route::get('admin/setting')->uri();
     $view = View::factory('admin/settings')->set('date_time_formats', Date::date_time_formats(1))->set('date_formats', Date::date_formats(1))->set('time_formats', Date::time_formats(1))->set('date_weekdays', Date::weeekdays())->set('timezones', Date::timezones())->bind('title', $this->title)->set('action', $action)->set('post', $config);
     if ($this->valid_post('settings')) {
         unset($_POST['settings'], $_POST['_token'], $_POST['_action']);
         foreach ($_POST as $key => $value) {
             $config->set($key, $value);
             if ($key == 'front_page') {
                 $this->_set_front_page($value);
             }
         }
         Log::info('Site configuration updated.');
         Message::success(__('Site configuration updated!'));
         $this->request->redirect(Route::get('admin/setting')->uri());
     }
     $this->response->body($view);
 }
Exemplo n.º 26
0
 public function action_important()
 {
     $id = $this->request->param('id', 0);
     $item = ORM::factory('Calendar', $id);
     if (!$item->loaded()) {
         throw new HTTP_Exception_404();
     }
     if ($item->is_important) {
         $item->is_important = 0;
         $item->save();
         Message::success('Убрано с главной');
     } else {
         $item->is_important = 1;
         $item->save();
         Message::success('На главную');
     }
     $this->redirect('manage/calendar/list?m=' . $item->month . '&d=' . $item->day);
 }
Exemplo n.º 27
0
 public function action_delete()
 {
     $id = (int) $this->request->param('id', 0);
     $role = ORM::factory('role', $id);
     if (!$role->loaded()) {
         Message::error(__('Role: doesn\'t exists!'));
         Log::error('Attempt to access non-existent role.');
         $this->request->redirect(Route::get('admin/role')->uri());
     }
     $this->title = __('Delete :title', array(':title' => $role->name));
     $view = View::factory('form/confirm')->set('action', Route::url('admin/role', array('action' => 'delete', 'id' => $role->id)))->set('title', $role->name);
     // If deletion is not desired, redirect to list
     if (isset($_POST['no']) and $this->valid_post()) {
         $this->request->redirect(Route::get('admin/role')->uri());
     }
     // If deletion is confirmed
     if (isset($_POST['yes']) and $this->valid_post()) {
         try {
             $role->delete();
             //delete the role
             Message::success(__('Role: :name deleted successful!', array(':name' => $role->name)));
             $this->request->redirect(Route::get('admin/role')->uri());
         } catch (Exception $e) {
             Log::error('Error occured deleting role id: :id, :message', array(':id' => $role->id, ':message' => $e->getMessage()));
             Message::error('An error occured deleting blog, :post.', array(':post' => $post->title));
             $this->request->redirect(Route::get('admin/role')->uri());
         }
     }
     $this->response->body($view);
 }
Exemplo n.º 28
0
 public function action_comment()
 {
     $id = (int) $this->request->param('id', 0);
     $return = Security::xss_clean(Arr::get($_GET, 'r', 'debate/view/' . $id));
     if ($this->request->method() == Request::POST) {
         try {
             if (Auth::instance()->logged_in()) {
                 $user_id = Auth::instance()->get_user()->id;
                 $comment = Arr::get($_POST, 'comment', '');
                 $debate = ORM::factory('Debate_Comment');
                 $debate->debate_id = $id;
                 $debate->date = date('Y-m-d H:i:s');
                 $debate->comment = $comment;
                 $debate->user_id = $user_id;
                 $debate->save();
                 $debate = ORM::factory('Debate', $id);
                 $debate->comments_count += 1;
                 $debate->save();
                 Message::success(i18n::get('Your comment has been saved, thanks!'));
             }
         } catch (ORM_Validation_Exception $e) {
         }
         $this->redirect($return, 301);
     }
 }
Exemplo n.º 29
0
 public function action_delete()
 {
     $id = (int) $this->request->param('id', 0);
     $graph = ORM::factory('Graph', $id);
     if (!$graph->loaded()) {
         throw new HTTP_Exception_404();
     }
     $token = Arr::get($_POST, 'token', false);
     if ($this->request->method() == Request::POST && Security::token() === $token) {
         $items = $graph->items_graph->find_all();
         foreach ($items as $item) {
             $values = $item->values_graph->find_all();
             foreach ($values as $value) {
                 $value->delete();
             }
             $item->delete();
         }
         $graph->delete();
         Message::success('График удален');
         $this->redirect('manage/graphs');
     } else {
         $this->set('record', $graph)->set('token', Security::token(true))->set('cancel_url', Url::media('manage/graphs'));
     }
 }
Exemplo n.º 30
0
 public function action_questions()
 {
     $list = ORM::factory('Expert_Question')->where('is_answered', '=', 1);
     $search = Security::xss_clean(Arr::get($_POST, 'search', ''));
     if (!empty($search)) {
         $list->and_where('question', 'LIKE', '%' . $search . '%');
     }
     $list = $list->order_by('date', 'DESC');
     $paginate = Paginate::factory($list)->paginate(NULL, NULL, 10)->render();
     $list = $list->find_all();
     $this->set('search', $search);
     $this->set('list', $list);
     $this->set('paginate', $paginate);
     if ($this->request->method() == Request::POST) {
         if (Auth::instance()->logged_in()) {
             try {
                 $user_id = Auth::instance()->get_user()->id;
                 $question = ORM::factory('Expert_Question');
                 $question->user_id = $user_id;
                 $question->question = Arr::get($_POST, 'question', '');
                 $question->date = date('Y-m-d H:i:s');
                 $question->save();
             } catch (ORM_Validation_Exception $e) {
             }
         } else {
             Message::success(i18n::get('You have to login'));
         }
     }
     $this->add_cumb('Question-answer', '/');
 }