public function action_index($identifier = false) { // TODO: cache this crap if (!$identifier) { Message::instance()->set('No user specified.'); return $this->request->redirect(''); } if (is_numeric($identifier)) { // pass $user = ORM::factory('user', $identifier); } else { $user = ORM::factory('user')->where('username', '=', $identifier)->find(); } if ($user->loaded()) { $user = (object) $user->as_array(); unset($user->password); $user->avatar = Gravatar::avatar($user->email, 128); unset($user->email); $this->template->user = $user; $pg = isset($_GET['p']) && (int) $_GET['p'] ? $_GET['p'] : 1; $pg = max($pg, 1); $l = 10; $q = array('user' => $user->id, 'l' => $l, 'o' => ($pg - 1) * $l, 'p' => $pg, 'recent' => 'yes'); $r = Sourcemap_Search::find($q); $this->template->search_result = $r; $p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic')); $this->template->pager = $p; $this->template->supplychains = $r->results; } else { Message::instance()->set('That user doesn\'t exist.'); return $this->request->redirect(''); } }
public static function singleton() { if (!isset(self::$instance)) { self::$instance = new Message(); } return self::$instance; }
public function action_index($supplychain_id) { if (!is_numeric($supplychain_id)) { $supplychain_id = $this->_match_alias($supplychain_id); } $supplychain = ORM::factory('supplychain', $supplychain_id); $sc = $supplychain->kitchen_sink($supplychain_id); if ($supplychain->loaded()) { $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0; $owner_id = (int) $supplychain->user_id; if ($supplychain->user_can($current_user_id, Sourcemap::READ)) { $this->layout->supplychain_id = $supplychain_id; // pass supplychain metadeta to template $this->template->supplychain_id = $supplychain_id; $this->template->supplychain_date = date('F j, Y', $sc->created); $this->template->supplychain_name = isset($sc->attributes->name) ? $sc->attributes->name : ""; $this->template->supplychain_owner = isset($sc->owner->name) ? $sc->owner->name : ""; $this->template->supplychain_ownerid = isset($sc->owner->id) ? $sc->owner->id : ""; $this->template->supplychain_avatar = isset($sc->owner->avatar) ? $sc->owner->avatar : ""; $this->template->supplychain_desc = isset($sc->attributes->description) ? $sc->attributes->description : ""; $this->layout->scripts = array('blog-view'); $this->layout->styles = array('sites/default/assets/styles/reset.css', 'assets/styles/base.less', 'assets/styles/general.less'); // qrcode url $qrcode_query = URL::query(array('q' => URL::site('view/' . $supplychain->id, true), 'sz' => 8)); $this->template->qrcode_url = URL::site('services/qrencode', true) . $qrcode_query; } else { Message::instance()->set('That map is private.'); $this->request->redirect('browse'); } } else { Message::instance()->set('That map could not be found.'); $this->request->redirect('browse'); } }
/** * Page editor */ public function action_edit() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Page::action_edit'); $this->template->content = View::factory('cms/pages/form')->bind('legend', $legend)->set('submit', __('Save'))->bind('page', $this->_resource)->bind('errors', $errors); // Bind locally $page =& $this->_resource; $legend = __('Edit :title', array(':title' => $page->title)); if ($_POST) { $page->values($_POST); $page->editor = $this->a1->get_user()->id; try { $page->update(); Message::instance()->info('The page, :title, has been updated.', array(':title' => $page->title)); if (!$this->_internal) { $this->request->redirect($this->request->uri(array('action' => 'list'))); } } catch (Validate_Exception $e) { $errors = $e->array->errors('admin'); } } // Set template scripts and styles $this->template->scripts[] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js'; $this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/jquery.markitup.js')); $this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/sets/html/set.js')); $this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/skins/markitup/style.css'))] = 'screen'; $this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/sets/html/style.css'))] = 'screen'; }
public static function getInstace() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
public function action_index() { $supplychain_alias = ORM::factory('supplychain_alias'); $page = max($this->request->param('page'), 1); $items = 20; $offset = $items * ($page - 1); $count = $supplychain_alias->count_all(); $pagination = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'page'), 'total_items' => $supplychain_alias->count_all(), 'items_per_page' => $items)); $this->template->supplychain_alias = $supplychain_alias->limit($pagination->items_per_page)->offset($pagination->offset)->find_all()->as_array(null, array('id', 'site', 'alias', 'supplychain_id')); $this->template->page_links = $pagination->render(); $this->template->offset = $pagination->offset; $supplychain_alias_count = $supplychain_alias->count_all(); $post = Validate::factory($_POST); $post->rule('site', 'not_empty')->rule('alias', 'not_empty')->filter('site', 'strip_tags')->filter('alias', 'strip_tags')->rule('supplychain_id', 'not_empty')->filter(true, 'trim'); if (strtolower(Request::$method) === 'post' && $post->check()) { $check = false; $post = (object) $post->as_array(); $site_added = $post->site; $alias_added = $post->alias; $id = $post->supplychain_id; // check if the alias already exists, if not add new alias $supplychain_alias = ORM::factory('supplychain_alias'); $supplychain_alias->supplychain_id = $id; $supplychain_alias->site = $site_added; $supplychain_alias->alias = $alias_added; try { $supplychain_alias->save(); } catch (Exception $e) { Message::instance()->set('Could not create alias. Violates the unique (site, alias)'); } $this->request->redirect('admin/aliases'); } Breadcrumbs::instance()->add('Management', 'admin/')->add('Aliases', 'admin/aliases'); }
public static function getInstance() { $config = Config::getInstance()->getConfigurations(); if (!isset(self::$instance)) { self::$instance = new Message($config['language']); } return self::$instance; }
/** * Perform user logout */ public function action_logout() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Auth::action_logout'); $this->a1->logout(); Kohana::$log->add('ACCESS', 'Successful logout made by user.'); Message::instance()->info(Kohana::message('a2', 'logout.success')); if (!$this->_internal) { $this->request->redirect(Route::get('admin')->uri()); } }
public function action_index() { $this->layout->page_title = 'Create a supply chain'; $f = Sourcemap_Form::load('/create'); $f->action('create')->method('post'); if (!Auth::instance()->get_user()) { $this->request->redirect('auth'); } $this->layout->scripts = array('sourcemap-core', 'sourcemap-template'); $import_role = ORM::factory('role')->where('name', '=', 'import')->find(); $admin_role = ORM::factory('role')->where('name', '=', 'admin')->find(); if (Auth::instance()->get_user()->has('roles', $import_role) || Auth::instance()->get_user()->has('roles', $admin_role)) { $this->template->can_import = true; } else { $this->template->can_import = false; } $this->template->create_form = $f; if (strtolower(Request::$method) === 'post') { if ($f->validate($_POST)) { // create! $p = $f->values(); $title = $p['title']; $description = substr($p['description'], 0, 80); $tags = Sourcemap_Tags::join(Sourcemap_Tags::parse($p['tags'])); $category = $p['category']; $public = isset($_POST['publish']) ? Sourcemap::READ : 0; $raw_sc = new stdClass(); if ($category) { $raw_sc->category = $category; } $raw_sc->attributes = new stdClass(); $raw_sc->attributes->title = $title; $raw_sc->attributes->description = $description; $raw_sc->attributes->tags = $tags; $raw_sc->stops = array(); $raw_sc->hops = array(); $raw_sc->user_id = Auth::instance()->get_user()->id; $raw_sc->other_perms = 0; if ($public) { $raw_sc->other_perms |= $public; } else { $raw_sc->other_perms &= ~Sourcemap::READ; } try { $new_scid = ORM::factory('supplychain')->save_raw_supplychain($raw_sc); return $this->request->redirect('view/' . $new_scid); } catch (Exception $e) { $this->request->status = 500; Message::instance()->set('Couldn\\t create your supplychain. Please contact support.'); } } else { Message::instance()->set('Correct the errors below.'); } } }
public function action_delete_role_entry($id) { $role = ORM::factory('role', $id); try { $role->delete(); Message::instance()->set('Role deleted.'); } catch (Exception $e) { Message::instance()->set('Role could not be deleted.'); } $this->request->redirect("admin/roles/"); }
public function before() { $this->current_user = Auth::instance()->get_user(); $admin = ORM::factory('role')->where('name', '=', 'admin')->find(); if ($this->current_user && $this->current_user->has('roles', $admin)) { // pass } else { Message::instance()->set('You\'re not allowed to access the management dashboard.', Message::ERROR); $this->request->redirect('auth'); } parent::before(); $this->layout->page_title = 'Management'; }
public function action_index($supplychain_id = false) { if (!$supplychain_id) { $this->request->redirect('home'); } if (!is_numeric($supplychain_id)) { $supplychain_id = $this->_match_alias($supplychain_id); } $supplychain = ORM::factory('supplychain', $supplychain_id); if ($supplychain->loaded()) { $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0; $owner_id = (int) $supplychain->user_id; if ($current_user_id && $supplychain->user_can($current_user_id, Sourcemap::WRITE)) { $supplychain = $supplychain->kitchen_sink($supplychain->id); $this->layout->page_title = 'Delete a supply chain'; // create the form object and add fields $form = Sourcemap_Form::factory('delete')->method('post')->action('delete/' . $supplychain_id)->add_class('vertical')->select('confirm_once', 'Are you sure?')->select('confirm_twice', 'We can\'t undo this. Are you still sure you want to delete this map?')->select('confirm_thrice', 'Seriously. This is a permanent thing. Are you *sure*?')->submit('delete', 'Delete'); $form->field('confirm_once')->option('no', 'No')->option('yes', 'Yes'); $form->field('confirm_twice')->option('no', 'No')->option('yes', 'Yes'); $form->field('confirm_thrice')->option('no', 'No')->option('yes', 'Yes'); if (strtolower(Request::$method) === 'post') { $post = Validate::factory($_POST); $post->rule('confirm_once', 'in_array', array(array('yes')))->rule('confirm_twice', 'in_array', array(array('yes')))->rule('confirm_thrice', 'in_array', array(array('yes'))); if ($post->check()) { try { ORM::factory('supplychain', $supplychain->id)->delete(); Message::instance()->set('Map deleted.', Message::SUCCESS); return $this->request->redirect('home'); } catch (Exception $e) { $this->request->status = 500; Message::instance()->set('Couldn\'t delete your supplychain. Please contact support.'); } } else { Message::instance()->set('You don\'t seem sure.'); $form->errors($post->errors('forms/create')); } } $this->template->supplychain = $supplychain; $this->template->form = $form; } else { Message::instance()->set('You\'re not allowed to edit that map.'); $this->request->redirect('home'); } } else { Message::instance()->set('That map does not exist.'); $this->request->redirect('home'); } }
public function action_remove($id) { $sc = ORM::factory('supplychain', $id); if ($sc->loaded()) { $sc->flags = $sc->flags & ~Sourcemap::FEATURED; $sc->save(); if (Sourcemap_Search_Index::should_index($sc->id)) { Sourcemap_Search_Index::update($sc->id); } Message::instance()->set('Unfeatured map.', Message::SUCCESS); $this->request->redirect('admin/featured'); } else { Message::instance()->set('That supplychain does not exist.'); $this->request->redirect('admin/featured'); } }
public function action_index($category = false) { $this->layout->scripts = array('sourcemap-core'); $this->layout->page_title = 'Browsing supply chains'; $cats = Sourcemap_Taxonomy::arr(); $nms = array(); foreach ($cats as $i => $cat) { $nms[Sourcemap_Taxonomy::slugify($cat->name)] = $cat; } $this->template->taxonomy = Sourcemap_Taxonomy::load_tree(); $defaults = array('q' => false, 'p' => 1, 'l' => 20); $params = $_GET; if (strtolower(Request::$method) == 'post') { $params = $_POST; } $params = array_merge($defaults, $params); $params['recent'] = 'yes'; $params['l'] = 20; if ($category && isset($nms[$category])) { $slug = $category; $category = $nms[$category]; $this->template->category = $category; $params['c'] = $category->name; $this->layout->page_title .= ' - ' . $category->title; } elseif ($category) { Message::instance()->set('"' . $category . '" is not a valid category slug.'); return $this->request->redirect('browse'); } else { $this->template->category = false; } $r = Sourcemap_Search::find($params); $p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic')); $this->template->primary = $r; $this->template->pager = $p; $params['l'] = 1; $this->template->favorited = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes')); $this->template->discussed = Sourcemap_Search_Simple::find($params + array('comments' => 'yes')); $this->template->interesting = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes', 'comments' => 'yes')); $this->template->recent = Sourcemap_Search_Simple::find($params + array('recent' => 'yes')); }
public function action_add() { $post = Validate::factory($_POST)->rule('user_id', 'not_empty'); if ($post->check()) { $user_id = $post['user_id']; $user = ORM::factory('user', $user_id); if ($user->loaded()) { $newkey = md5(sprintf('%s-%s-%s', $user->id, $user->email, microtime())); $newsecret = md5(sprintf('%s-%s-%s-%s', microtime(), $user->email, $user->id, $newkey)); $apikey = ORM::factory('user_apikey'); $apikey->apikey = $newkey; $apikey->apisecret = $newsecret; $apikey->user_id = $user->id; $apikey->save(); Message::instance()->set(sprintf('Added api key for "%s".', $user->username)); } else { Message::instance()->set('Could not add api key: invalid user.', Message::ERROR); } } else { Message::instance()->set('Missing or invalid user id.', Message::ERROR); } $this->request->redirect('admin/apikeys'); }
public function action_delete() { if (Request::$method !== 'POST') { Message::instance()->set('Bad request.'); $this->request->redirect('admin/announcements'); } $post = Validate::factory($_POST); $post->rule('user_event_id', 'not_empty')->rule('user_event_id', 'is_numeric'); if ($post->check()) { $post = (object) $post->as_array(); $evt = ORM::factory('user_event', $post->user_event_id); if ($evt && $evt->loaded()) { $evt->delete(); Message::instance()->set('Announcement deleted.', Message::SUCCESS); $this->request->redirect('admin/announcements'); } else { Message::instance()->set('Invalid announcement id.'); } } else { Message::instance()->set('Bad request.'); } $this->request->redirect('admin/announcements'); }
<link rel="shortcut icon" type="image/x-icon" href="assets/images/favicon.ico" /> <link rel="apple-touch-icon" href="assets/images/favicon-large.png"> <link rel="image_src" href="assets/images/favicon-large.png"> <?php echo isset($styles) ? Sourcemap_CSS::link_tags($styles) : ''; ?> </head> <body class="main admin"> <?php echo View::factory('partial/branding', array('page_title' => isset($page_title) ? $page_title : APPLONGNM)); ?> <div class="container"> <div class="messages"> <p><?php echo Message::instance()->get() ? Message::instance()->render() : false; ?> </p> </div> </div> <div id="admin-head" class="container"> <p><?php echo Breadcrumbs::instance()->get() ? Breadcrumbs::instance()->render() : false; ?> </p> </div> </div> <div id="wrapper"> <?php echo isset($content) ? $content : '<h2>There\'s nothing here.</h2>';
public function action_reset() { $this->template = View::factory('auth/reset_password'); $current_user = Auth::instance()->get_user(); $post = Validate::factory($_POST); $post->rule('new', 'not_empty')->rule('new_confirm', 'not_empty')->rule('new_confirm', 'matches', array('new'))->filter(true, 'trim'); if (strtolower(Request::$method) === 'post') { // make sure the user has a valid reset ticket or is logged in. $tregex = '/[A-Za-z0-9\\+\\/=]+-[A-Fa-f0-9]{32}-[A-Za-z0-9\\+\\/=]+/'; if (!$current_user && isset($_POST['t']) && preg_match($tregex, $_POST['t'])) { list($un, $h, $em) = explode('-', $_POST['t']); $un = base64_decode(strrev($un)); $em = base64_decode(strrev($em)); $user = ORM::factory('user')->where('email', '=', $em)->find(); if ($user->loaded()) { if ($user->username == $un) { $tgth = md5(sprintf('%s-%s-%s-%s-%s', $user->id, $user->username, $user->email, $user->last_login, $user->password)); if ($tgth === $h) { $current_user = $user; if ($post->check()) { $user->password = $post['new']; $user->save(); Auth::instance()->login($user->username, $post['new']); Message::instance()->set('Password reset.', Message::SUCCESS); // TODO: notify via email of reset? return $this->request->redirect('auth'); } else { // pass } } else { Message::instance()->set('That token has expired. Please create a new request.'); return $this->request->redirect('auth'); } } else { Message::instance()->set('Password reset failed. Please contact support for assistance.'); return $this->request->redirect('auth'); } } else { Message::instance()->set('We don\'t have this address on record. Please create a new request.'); return $this->request->redirect('auth'); } } if (!$current_user) { Message::instance()->set('You can\'t do that.'); $this->request->redirect('auth'); } elseif ($post->check()) { // && $tgth === $current_user->password) { // user is logged in...reset password... // TODO: notify user via email? $current_user->password = $post['new']; $current_user->save(); Message::instance()->set('Your password has been reset.', Message::SUCCESS); $this->request->redirect('auth'); } else { Message::instance()->set('Please try again.', Message::ERROR); if (isset($_POST['t'])) { $this->request->redirect('auth/reset?t=' . $_POST['t']); } else { $this->request->redirect('auth/reset'); } } } else { $get = Validate::factory($_GET); $get->rule('t', 'not_empty')->rule('t', 'regex', array('/[A-Za-z0-9\\+\\/=]+-[A-Fa-f0-9]{32}-[A-Za-z0-9\\+\\/=]+/')); if (!$current_user && isset($_GET['t'])) { if ($get->check()) { list($un, $h, $em) = explode('-', $get['t']); $un = base64_decode(strrev($un)); $em = base64_decode(strrev($em)); $user = ORM::factory('user')->where('email', '=', $em)->find(); if ($user->loaded()) { if ($user->username == $un) { $tgth = md5(sprintf('%s-%s-%s-%s-%s', $user->id, $user->username, $user->email, $user->last_login, $user->password)); if ($tgth === $h) { $current_user = $user; $this->template->ticket = $get['t']; } else { Message::instance()->set('That token has expired.'); return $this->request->redirect('auth'); } } else { Message::instance()->set('That didn\'t work.'); return $this->request->redirect('auth'); } } else { return $this->request->redirect('auth'); } } else { Message::instance()->set('That didn\'t work.'); return $this->request->redirect('auth'); } } elseif (!$current_user) { Message::instance()->set('You can\'t do that.'); $this->request->redirect('auth'); } } }
/** * Delete an article */ public function action_delete() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Article::action_delete'); // If deletion is not desired, redirect to list if (isset($_POST['no'])) { $this->request->redirect($this->request->uri(array('action' => 'list', 'id' => NULL))); } $this->template->content = View::factory('blog/admin/article_delete')->bind('article', $this->_resource); // Bind locally $article =& $this->_resource; $title = $article->title; // If deletion is confirmed if (isset($_POST['yes'])) { try { $article->delete(); Message::instance()->info('The article, :title, has been deleted.', array(':title' => $title)); if (!$this->_internal) { $this->request->redirect($this->request->uri(array('action' => 'list', 'id' => NULL))); } } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Error occured deleting article, id=' . $article->id . ', ' . $e->getMessage()); Message::instance()->error('An error occured deleting article, :title.', array(':title' => $title)); if (!$this->_internal) { $this->request->redirect($this->request->uri(array('action' => 'list', 'id' => NULL))); } } } }
/** * Delete a user */ public function action_delete() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Users::action_delete'); // If deletion is not desired, redirect to list if (isset($_POST['no'])) { $this->request->redirect($this->request->uri(array('action' => 'list'))); } $this->template->content = View::factory('admin/users/delete')->bind('user', $this->_resource); // Bind locally $user =& $this->_resource; $name = $user->username; // If deletion is confirmed if (isset($_POST['yes'])) { try { $user->delete(); Message::instance()->info('The user, :name, has been deleted.', array(':name' => $name)); if (!$this->_internal) { $this->request->redirect($this->request->uri(array('action' => 'list'))); } } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Error occured deleting user, id=' . $user->id . ', ' . $e->getMessage()); Message::instance()->error('An error occured deleting user, :name.', array(':name' => $name)); if (!$this->_internal) { $this->request->redirect($this->request->uri(array('action' => 'list'))); } } } }
/** * Delete a tag */ public function action_delete() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Tag::action_delete'); // Bind locally $tag = & $this->_resource; $name = $tag->name; if(Request::$is_ajax) { try { $tag->delete(); $this->request->response = json_encode( array('success' => TRUE, 'flash_class' => 'success', 'text'=>'The tag, '.$name.' has been deleted.') ); //return a json encoded result } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Error occured deleting tag, id='.$tag->id.', '.$e->getMessage()); $this->request->response = json_encode( array('success' => FALSE, 'flash_class' => "error", 'text'=> 'An error occured deleting tag,'.$name) ); } return; //end ajax } // If deletion is not desired, redirect to list if (isset($_POST['no'])) $this->request->redirect( $this->request->uri(array('action'=>'list', 'id'=>NULL)) ); $this->template->content = View::factory('blog/admin/tag/delete') ->bind('tag', $this->_resource); // If deletion is confirmed if (isset($_POST['yes'])) { try { $tag->delete(); Message::instance()->info('The tag, :name, has been deleted.', array(':name' => $name)); if ( ! $this->_internal) $this->request->redirect( $this->request->uri(array('action'=>'list', 'id'=>NULL)) ); } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Error occured deleting tag, id='.$tag->id.', '.$e->getMessage()); Message::instance()->error('An error occured deleting tag, :name.', array(':name' => $name)); if ( ! $this->_internal) $this->request->redirect( $this->request->uri(array('action'=>'list', 'id'=>NULL)) ); } } }
/** * Handles internal/external request-specific view settings */ public function after() { $content = $this->template->content; // If external request, insert into layout template if (!$this->_internal) { $view = isset($this->_view_map[$this->request->action]) ? $this->_view_map[$this->request->action] : $this->_view_map['default']; $this->template->content = View::factory($view)->set('menu', $this->_menu())->set('content', $content); } else { $messages = Message::instance()->get(); $this->template = $messages . $content; } parent::after(); }
<!-- should be no reason to edit this file --> <?php echo $header; echo $menu; ?> <div id="content" class="container_16 clearfix"> <?php $msg = Message::instance()->get(); if (!empty($msg)) { ?> <div class="grid_16"> <?php echo $msg; ?> </div> <?php } ?> <?php echo $content; ?> </div> <?php echo $footer;
public function action_visibility($supplychain_id = false) { $set_to = null; if ($supplychain_id && Request::$method === 'POST') { $sc = ORM::factory('supplychain', $supplychain_id); if ($sc->loaded()) { $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0; $owner_id = (int) $supplychain->user_id; if ($current_user_id && $supplychain->user_can($current_user_id, Sourcemap::WRITE)) { $p = Validate::factory($_POST); $p->rule('publish', 'regex', array('/(yes|no)/i'))->rule('publish', 'not_empty'); if ($p->check()) { $set_to = strtolower($p['publish']) == 'yes'; } else { Message::instance()->set('Missing required "publish" parameter.'); $this->request->redirect('/home'); } } else { Message::instance()->set('You don\'t have permission to do that.'); $this->request->redirect('/home'); } } else { Message::instance()->set('That map doesn\'t exist.'); $this->request->redirect('/home'); } } elseif (Request::$method === 'GET') { $sc = ORM::factory('supplychain', $supplychain_id); if ($sc->loaded()) { $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0; $owner_id = (int) $sc->user_id; if ($current_user_id && $sc->user_can($current_user_id, Sourcemap::WRITE)) { $g = Validate::factory($_GET); $g->rule('publish', 'regex', array('/(yes|no)/i'))->rule('publish', 'not_empty'); if ($g->check()) { $set_to = strtolower($g['publish']) == 'yes'; } else { Message::instance()->set('Missing required "publish" parameter.'); $this->request->redirect('/home'); } } else { Message::instance()->set('You don\'t have permission to do that.'); $this->request->redirect('/home'); } } else { Message::instance()->set('That map does not exist.'); $this->request->redirect('/home'); } } else { Message::instance()->set('Bad request.'); $this->request->redirect('/home'); } if ($set_to !== null) { if ($set_to === true) { $sc->other_perms |= $set_to; } else { $sc->other_perms &= ~Sourcemap::READ; } try { $sc->save(); Message::instance()->set('Map updated.', Message::SUCCESS); return $this->request->redirect('/home'); } catch (Exception $e) { $this->request->status = 500; Message::instance()->set('Couldn\\t update your supplychain. Please contact support.'); } } }
public function action_comment($scid) { if (!($current_user = Auth::instance()->get_user()) || !$current_user->loaded()) { $this->request->status = 403; Message::instance()->set('You must be logged in to comment.'); return $this->request->redirect(''); } $sc = ORM::factory('supplychain', $scid); if ($sc->loaded()) { $p = Validate::factory($_POST); $p->rule('body', 'not_empty'); if ($p->check()) { $new_comment = ORM::factory('supplychain_comment'); $new_comment->body = $p['body']; $new_comment->user_id = $current_user->id; $new_comment->supplychain_id = $scid; $new_comment->timestamp = time(); try { $new_comment->save(); Message::instance()->set('Your comment was saved.', Message::SUCCESS); } catch (Exception $e) { $this->request->status = 500; Message::instance()->set('There was a problem saving your comment.'); } return $this->request->redirect('view/' . $scid . '#comments'); } else { $this->request->status = 400; Message::instance()->set('What good is a comment if it\'s empty?'); return $this->request->redirect('view/' . $scid . '#comments'); } } else { $this->request->status = 400; Message::instance()->set('You can\'t comment on nothing.'); return $this->request->redirect(''); } }
/** * Handles internal/external request-specific view settings */ public function after() { $content = $this->template->content; if (Request::$is_ajax) { $this->auto_render = false; //Disable the auto renderer, we don't want a layout in our ajax response $this->request->headers['Content-Type'] = 'application/json'; } else { // If external request, insert into layout template if (!$this->_internal) { $view = isset($this->_view_map[$this->request->action]) ? $this->_view_map[$this->request->action] : $this->_view_map['default']; // Switch between standard menu and context menu $menu = isset($this->_view_menu_map[$this->request->action]) ? View::factory($this->_view_menu_map[$this->request->action]) : $this->_menu(); $this->template->content = View::factory($view)->set('menu', $menu)->set('content', $content); if ($user = $this->a2->get_user()) { $this->template->header->set('username', $user->username); } } else { $messages = Message::instance()->get(); $this->template = $messages . $content; } } parent::after(); }
public function action_delete_group($id) { $group = ORM::factory('usergroup', $id); try { $group->delete(); } catch (Exception $e) { Message::instance()->set('Could not delete the group, please try again.'); } $this->request->redirect("admin/groups/"); }
/** * Delete a comment */ public function action_delete() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Blog_Comment::action_delete'); $id = $this->request->param('id'); $this->template->content = Request::factory('comments/blog-admin/delete/' . $id)->execute()->response; // Check if deletion was successful if ($this->template->content === TRUE) { Message::instance()->info('Comment has been deleted'); $this->request->redirect($this->request->uri(array('action' => NULL, 'id' => NULL))); } // Check if deletion was unsuccessful or not attempted if ($this->template->content === FALSE) { if (isset($_POST['yes'])) { Message::instance()->error('An error occured deleting the comment'); } $this->request->redirect($this->request->uri(array('action' => NULL, 'id' => NULL))); } }
public function action_flag($id = null) { if (strtolower(Request::$method) == 'post') { if ($id) { $comment = ORM::factory('supplychain_comment', $id); if ($comment->loaded()) { // pass } else { Message::instance()->set('Invalid comment.'); $this->request->redirect('admin/comments'); } } else { Message::instance()->set('Invalid comment.'); $this->request->redirect('admin/comments'); } $flag_nm = isset($_POST['flag_nm']) ? $_POST['flag_nm'] : false; if ($flag_nm) { $flag_nm = strtolower($flag_nm); switch ($flag_nm) { case 'abuse': $flag = Sourcemap::ABUSE; break; case 'hidden': $flag = Sourcemap::HIDDEN; break; default: Message::instance()->set('Invalid flag.'); $this->request->redirect('admin/comments'); break; } if (isset($_POST['unflag'])) { $comment->flags = $comment->flags & ~$flag; } else { $comment->flags = $comment->flags | $flag; } $comment->save(); if ($flag_nm == 'hidden') { if (isset($_POST['unflag'])) { Message::instance()->set('Comment unhidden.'); } else { Message::instance()->set('Comment hidden.'); } } else { if (isset($_POST['unflag'])) { Message::instance()->set('Abuse flag removed.'); } else { Message::instance()->set('Comment flagged as abusive.'); } } } else { Message::instance()->set('No flag specified.'); } } $this->request->redirect('admin/comments'); }
public function action_confirm() { if (Auth::instance()->get_user()) { Message::instance()->set('You\'re already signed in. Sign out and click the ' . 'confirmation url again.', Message::INFO); return $this->request->redirect('home'); } $get = Validate::factory($_GET); $get->rule('t', 'regex', array('/^[A-Za-z0-9\\+\\/=]+-[A-Fa-f0-9]{32}$/')); if ($get->check()) { list($uh, $h) = explode('-', $get['t']); // check token $username = base64_decode(strrev($uh)); $user = ORM::factory('user')->where('username', '=', $username)->find(); $login = ORM::factory('role')->where('name', '=', 'login')->find(); if ($user->loaded()) { // see if acct is already confirmed if ($user->has('roles', $login)) { Message::instance()->set('That token has expired.'); return $this->request->redirect('auth'); } } else { Message::instance()->set('Invalid confirmation token.'); return $this->request->redirect('auth'); } // add login role $user->add('roles', $login); Message::instance()->set('Your account has been confirmed. Please Sign in (and start mapping).', Message::SUCCESS); Sourcemap_User_Event::factory(Sourcemap_User_Event::REGISTERED, $user->id)->trigger(); return $this->request->redirect('auth'); } else { Message::instance()->set('Invalid confirmation token.'); return $this->request->redirect('auth'); } }