public static function exec() { if (is_null(self::$me)) { self::$me = new String(); } return self::$me; }
public function create_user() { // If there are no users then let's create one. $db = Database::get_instance(); $db->query('SELECT * FROM `users` LIMIT 1'); if ($db->has_rows() && !Auth::get_instance()->logged_in()) { Flash::set('<p class="flash validation">Sorry but to create new users, you must be logged in.</p>'); Core_Helpers::redirect(WEB_ROOT . 'login/'); } $validator = Error::instance(); if (isset($_POST['email'])) { $validator->email($_POST['email'], 'email'); $validator->blank($_POST['username'], 'username'); $validator->blank($_POST['password'], 'password'); $validator->passwords($_POST['password'], $_POST['confirm_password'], 'confirm_password'); $user = new Users(); if ($user->select(array('username' => $_POST['username']))) { $validator->add('username', 'The username <strong>' . htmlspecialchars($_POST['username']) . '</strong> is already taken.'); } if ($validator->ok()) { $user = new Users(); $user->load($_POST); $user->level = 'admin'; $user->insert(); Flash::set('<p class="flash success">User created successfully.</p>'); Core_Helpers::redirect(WEB_ROOT . 'login/'); } } $this->data['error'] = $validator; $this->load_template('create_user'); }
public function edit() { $this->data['table'] = String::clean(Router::uri(3), '_'); $scaffolder = new Scaffolder($this->data['table'], intval(Router::uri(4))); $scaffolder->iterate(); $this->data['form'] = $scaffolder->display(); if (isset($_POST['submit'])) { if ($scaffolder->save_object()) { if (empty($_POST['redirect'])) { Flash::set('<div class="sub_menu_extension"><strong>Your entry was added succefully! You can edit it below.</strong></div>'); Core_Helpers::redirect('/admin/edit/' . Router::uri(3) . '/' . $scaffolder->current_id . '/'); } else { Flash::set('<div class="sub_menu_extension"><strong>Your entry was added succefully!</strong></div>'); Core_Helpers::redirect($_POST['redirect']); } } } $this->load_template('edit'); }