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 function kitchen_sink($scid) { $scid = (int) $scid; if (($sc = ORM::factory('supplychain', $scid)) && $sc->loaded()) { $rows = $this->_db->query(Database::SELECT, sprintf("select s.id as stop_id, ST_AsText(s.geometry) as geometry, \n sa.key as attr_k, sa.value as attr_v, s.local_stop_id as local_stop_id\n from stop as s left outer join stop_attribute as sa on\n (s.supplychain_id=sa.supplychain_id and s.local_stop_id=sa.local_stop_id)\n where s.supplychain_id = %d\n order by sa.id desc", $scid), true)->as_array(); $stops = array(); foreach ($rows as $i => $row) { if (!isset($stops[$row->local_stop_id])) { $stops[$row->local_stop_id] = (object) array('local_stop_id' => $row->local_stop_id, 'id' => $row->local_stop_id, 'geometry' => $row->geometry, 'attributes' => (object) array()); } if ($row->attr_k) { $stops[$row->local_stop_id]->attributes->{$row->attr_k} = $row->attr_v; } } $hops = array(); $sql = sprintf("select h.id as hop_id, h.from_stop_id, h.to_stop_id,\n ST_AsText(h.geometry) as geometry, ha.key as attr_k, ha.value as attr_v\n from hop as h \n left outer join hop_attribute as ha on (\n h.supplychain_id=ha.supplychain_id and\n h.from_stop_id=ha.from_stop_id and\n h.to_stop_id=ha.to_stop_id\n )\n where h.supplychain_id = %d order by h.id asc", $scid); $rows = $this->_db->query(Database::SELECT, $sql, true); foreach ($rows as $i => $row) { $hkey = sprintf("%d-%d", $row->from_stop_id, $row->to_stop_id); if (!isset($hops[$hkey])) { $hops[$hkey] = (object) array('from_stop_id' => $row->from_stop_id, 'to_stop_id' => $row->to_stop_id, 'geometry' => $row->geometry, 'attributes' => (object) array()); } if ($row->attr_k) { $hops[$hkey]->attributes->{$row->attr_k} = $row->attr_v; } } $sql = sprintf("select sca.key as attr_k, sca.value as attr_v\n from supplychain_attribute as sca\n where sca.supplychain_id=%d", $scid); $owner = $sc->owner; $cat = $sc->taxonomy; $sc = (object) $sc->as_array(); $sc->attributes = new stdClass(); $rows = $this->_db->query(Database::SELECT, $sql, true); foreach ($rows as $i => $row) { $sc->attributes->{$row->attr_k} = $row->attr_v; } $sc->stops = array_values($stops); $sc->hops = array_values($hops); $sc->owner = (object) array('id' => $owner->id, 'name' => $owner->username, 'avatar' => Gravatar::avatar($owner->email)); $sc->user_id = $owner->id; $sc->taxonomy = $cat && $cat->loaded() ? Sourcemap_Taxonomy::load_ancestors($cat->id) : null; } else { throw new Exception('Supplychain not found.'); } return $sc; }
public function action_create() { if (!Auth::instance()->get_user()) { Message::instance()->set('You must be signed in to create maps.'); $this->request->redirect('auth'); } $supplychain_id = '4'; 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 ($supplychain->user_can($current_user_id, Sourcemap::READ)) { $this->layout->supplychain_id = $supplychain_id; $this->template->supplychain_id = $supplychain_id; $this->layout->scripts = array('map-view'); $this->layout->styles = array('sites/default/assets/styles/reset.css', 'assets/styles/base.less', 'assets/styles/general.less'); // comments $c = $supplychain->comments->find_all(); $comment_data = array(); foreach ($c as $i => $comment) { $arr = $comment->as_array(); $arr['username'] = $comment->user->username; $arr['avatar'] = Gravatar::avatar($comment->user->email); $comment_data[] = (object) $arr; } $this->template->comments = $comment_data; $this->template->can_comment = (bool) $current_user_id; // 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'); } }
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License along with this * program. If not, see <http://www.gnu.org/licenses/>.*/ ?> <td><?php echo $item->id; ?> </td> <td><a href="admin/users/<?php echo $item->id; ?> "><?php echo Html::chars($item->username); ?> </a></td> <td><?php echo Html::chars($item->email); ?> </td> <td><img width="32px" height="32px" src="<?php echo Gravatar::avatar($item->email, 32); ?> " /></td> <form name="delete-users" method="post" action="admin/users/<?php echo $item->id; ?> /delete_user"> <td><input type ="submit" value="delete" /></form></td>
<div class="container"> <h1 class="dashboard-title">Your profile</h1> <div class="dashboard-top"> <div class="dashboard-top-left"> <div> <h2 class="user-name"><?php echo HTML::chars($user->username); ?> </h2> </div> <hr /> <div id="user-profile"> <div class="user-gravatar"> <img src="<?php echo Gravatar::avatar($user->email, 128); ?> " /> </div> <ul class="user-details"> <li>Username: <span><?php echo HTML::chars($user->username); ?> </span><li> <li>Email: <span><?php echo HTML::chars($user->email); ?> </span><li> <li>Last Signed In: <span><?php echo date('F j, Y', $user->last_login); ?>