function view($args) { $id = array_shift($args); $permission = R::load('permission', $id); if (!is_numeric($id) && !$permission->getID()) { $this->redirect(PACKAGE_URL); } $allgroups = R::findAll('group'); foreach ($allgroups as $key => $group) { foreach ($permission->sharedGroup as $group_c) { if ($group->id == $group_c->id) { $allgroups[$key]->checked = true; } } } // echo $permission->name;exit; $view = new G2_TwigView('pages/view'); $view->permission = $permission; $view->allGroups = $allgroups; $form = new G2_FormMagic($view->get_render()); if ($form->is_posted()) { $groups = R::loadAll('group', array_keys($form->data()['groups'])); $permission->sharedGroup = $groups; R::store($permission); Admin_Alert::add_message("\"{$permission->name}\" permission was updated"); $this->redirect(PACKAGE_URL); } echo $form->parse(); }
function render() { $messages = isset($_SESSION['alerts']['messages']) ? $_SESSION['alerts']['messages'] : []; if (empty($messages) && !empty($this->messages)) { $messages = $this->messages; } if (!empty($messages)) { $view = new G2_TwigView('parts/alert'); $s = []; foreach ($messages as $message) { if (!isset($message['rendered'])) { $s[] = $message; } } $view->set('messages', $s); $alert = $view->get_render(); $this->messages = []; unset($_SESSION['alerts']); // $this->messages = []; // $this->rendered = true; return $alert; } else { return false; } }
function form(RedBeanPHP\OODBBean $page) { //Check if object is loaded //Load areas connected to this page $areas = $page->ownArea; //Load form html $view = new G2_TwigView('forms/page/page'); //Create processors $areasP = []; $data = []; foreach ($areas as $area) { $areaP = new Theme_Area_Processor($area); $areasP[$area->id] = $areaP; $data[$area->id] = $areaP->render(); } $view->areas = $areasP; $view->page = $page; $form = new G2_FormMagic($view->get_render()); if (!$form->is_posted()) { $form->set_data($data); } if ($form->is_posted()) { //Field Validate the content $data = $form->data(); foreach ($data as $area_id => $value) { $areasP[$area_id]->set_value($value); $message = $areasP[$area_id]->validate(); if ($message !== true) { $form->invalidate($area_id, $message); } } foreach ($form->get_uploaded_files() as $key => $file) { $areasP[$key]->set_value($file); $message = $areasP[$key]->validate(); if ($message !== true) { $form->invalidate($area_id, $message); } } } if ($form->is_posted() && $form->validate()) { $data = $form->data(); foreach ($data as $area_id => $value) { $areasP[$area_id]->set_value($value); $areasP[$area_id]->save(); } foreach ($form->get_uploaded_files() as $key => $file) { $areasP[$key]->set_value($file); $areasP[$key]->save(); } return true; } echo $form->parse(); }
function crud($posttype, RedBeanPHP\OODBBean $post_object) { $fields = $this->get_fields($posttype, false); $view = new G2_TwigView('post_form'); $view->fields = $fields; $form = new G2_FormMagic($view->get_render()); if (!$form->is_posted() && $post_object->getID()) { $data = []; foreach ($post_object->ownPostdata as $postdata) { $data[$postdata->postmeta->fieldname] = $postdata->value; } $form->set_data($data); } if ($form->is_posted()) { $old = clone $post_object; //Save fields to correct db locations $postdatas = []; foreach ($form->data() as $field => $value) { // First Match the field with the correct postdata record from the current post unset($postdata); foreach ($post_object->ownPostdata as &$data) { if ($data->postmeta->fieldname == $field) { $postdata = $data; } } if (!isset($postdata)) { $postdata = R::dispense('postdata'); $postdata->postmeta = R::findOne('postmeta', 'fieldname = :field AND post_type = :type', ['type' => $posttype, 'field' => $field]); } $postdata->value = $value; R::store($postdata); $postdatas[] = $postdata; } $post_object->ownPostdata = $postdatas; $post_object->post_type = $posttype; if (!$post_object->getID()) { $post_object->date_created = date('Y-m-d H:i:s'); } $post_object->date_modified = date('Y-m-d H:i:s'); $files = $form->get_uploaded_files(); R::store($post_object); //Save files to Audit::create($old, $post_object, 'An Post was saved'); return true; } echo $form->parse(); }
function changes($args) { $id = array_shift($args); if (!is_numeric($id) || !($audit = R::load('audit', $id))) { $this->redirect(PACKAGE_URL); } $update_form = new G2_TwigView('forms/audit'); $update_form = new G2_FormMagic($update_form->get_render()); if ($update_form->is_posted() && $update_form->validate()) { foreach ($update_form->data() as $field => $data) { $audit->{$field} = $data; } R::store($audit); } $update_form->set_data($audit->export()); $view = new G2_TwigView('pages/changes'); $view->audit = current(Audit::deserialize([$audit])); $view->update_form = $update_form->parse(); $view->render(); }
function load_banners($page, $classes = '') { $page = $this->find_page($page); $images = $page->images; $view = new G2_TwigView('widgets/banner'); foreach ($images as $im) { if (isset($im->content)) { $view->set('is_banner', 'true'); break; } } // if(isset($page->content)){ // $content = new G2_TwigView("banner-content/$page->content"); // if($content->exists()){ // $view->set('content',$content->get_render()); // } // } $view->set('images', $images); $view->set('classes', $classes); return $view->get_render(); }
function crud($args) { $id = array_shift($args); if (!empty($id) && is_numeric($id)) { $list = R::load(Package_Mail::MAIL_LIST, $id); if ($list->isEmpty()) { $this->redirect(PACKAGE_URL); } } else { $list = R::dispense(Package_Mail::MAIL_LIST); } $form_view = new G2_TwigView('forms/maillist'); $form_view->set('addresses', $list->sharedMailaddress); $form_view->set('list', $list); $form = new G2_FormMagic($form_view->get_render()); if ($form->is_posted()) { var_dump($_POST); exit; } $view = new G2_TwigView('pages/crud'); $view->set('form', $form->parse()); $view->render(); }
/** * Renders the breadcrumb string * @param type $page */ function render() { $view = new G2_TwigView('parts/breadcrumbs'); $view->crumbs = $this->info; return $view->get_render(); }
function crud($args) { $id = array_shift($args); //Check if user is loaded if (!empty($id) && is_numeric($id)) { $user = R::load('user', $id); if ($user->isEmpty()) { $this->redirect(PACKAGE_URL); } } else { $user = R::dispense('user'); } $old = clone $user; $form_view = new G2_TwigView('forms/user'); $form_view->set('groups', R::findAll('group')); // Sets group information $form_view->set('user', $user); $form = new G2_FormMagic($form_view->get_render()); // var_dump($user->export()); if (empty($_POST)) { $data = $user->export(); $groups = []; foreach ($user->sharedGroup as $bean) { $groups[] = $bean->name; } $data['sharedGroup'] = $groups; $form->set_data($data); // var_dump($data);exit; } if ($form->is_posted() && $form->validate()) { $data = $form->data(); // var_dump($data);exit; if ($data['password'] != $user->password) { //The Users password changed. Need to re encrypt $data['password'] = G()->hash_pass($data['password']); } foreach ($data as $field => $value) { if (is_array($user->{$field}) && Mvc_Functions::startsWith($field, 'shared')) { $bean = strtolower(substr($field, strlen('shared'))); $bean_ar = []; foreach ($value as $name) { $bean_ar[] = G()->load_group($name); } $user->{"shared" . ucfirst($bean)} = $bean_ar; } else { $user->{$field} = $value; } } if (empty($user->sharedGroup)) { $user->sharedGroup = [G()->load_group('default')]; } R::store($user); if (empty($old->id)) { Audit::create($old, $user, 'New user was created'); } else { Audit::create($old, $user, 'User details was updated'); } $this->redirect(PACKAGE_URL . 'crud/' . $user->id); } $view = new G2_TwigView('pages/crud'); $view->set('form', $form->parse()); $view->render(); }
public function render() { $view = new G2_TwigView('components/quickrender'); $view->this = $this; $view->render(); }
function index() { $view = new G2_TwigView('test'); $view->set('title', 'asasssss'); $view->render(); }
function login() { $this->template->set_template_file('templates/signup.twig'); $view = new G2_TwigView('pages/login'); $login_form = new G2_TwigView('forms/login'); $login_form = new G2_FormMagic($login_form->get_render()); G()->create_user_if_not_exist('admin', 'g2design123'); if ($login_form->is_posted() && $login_form->validate()) { $data = $login_form->data(); $username = $data['username']; $password = $data['password']; if ($user = G()->check_login($username, $password)) { G()->log_in_user($user); $this->redirect($this->get_package_uri() . 'index'); } else { $login_form->invalidate('username', 'Login Fails. Please check your details and try again'); } } $login_form = $login_form->parse(); $view->set('login_form', $login_form); $view->render(); }
public function get_dashboard_widget($package_url) { $widget = new G2_TwigView('widgets/dashboard'); $widget->package_url = $package_url; return $widget->get_render(); }