public static function getConfiguration($name, $redirected = false) { $key = $redirected ? "{$redirected}.{$name}" : $name; $configurations = Model::load("system.configurations"); $value = $configurations->get(["fields" => "value", "conditions" => "key = '{$key}'"]); return $value[0]['value']; }
/** * Creates a new ModelField. The example below creates a ModelField which * lists client accounts for selection. * * @code * $clients = new ModelField("brokerage.setup.clients.client_id", "account"); * @endcode * @param $path The full path to the field in the module which is to be returned by this field. * @param $value The name of the field from the model whose value should be displayed in the list. */ public function __construct($path, $value) { global $redirectedPackage; $this->info = Model::resolvePath($path); $this->model = Model::load((substr($this->info["model"], 0, 1) == "." ? $redirectedPackage : "") . $this->info["model"]); $this->valueField = $value; $field = $this->model->getFields(array($value)); $this->setLabel($field[0]["label"]); $this->setDescription($field[0]["description"]); $this->setName($this->info["field"]); $params = array("fields" => array($this->info["field"], $this->valueField), "sort_field" => $this->valueField); if ($this->conditions != '') { $params['conditions'] = $this->conditions; } $data = $this->model->get($params, Model::MODE_ARRAY); $this->addOption("Add new " . Utils::singular($this->model->getEntity()), 'NEW'); foreach ($data as $datum) { if ($datum[1] == "") { $this->addOption($datum[0]); } else { $this->addOption($datum[1], $datum[0]); } } $modelPath = str_replace('.', '/', $this->model->package); $this->addAttribute('onchange', "fapiAddModelItem('{$modelPath}', this, '{$value}')"); }
public function index() { $post = array('alert' => ''); Model::load('admincp/pages'); if ($match = Uri::match('\\/pages\\/(\\w+)')) { if (method_exists("controlPages", $match[1])) { $method = $match[1]; $this->{$method}(); die; } } $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } if (Request::has('btnAction')) { actionProcess(); } if (Request::has('btnSearch')) { filterProcess(); } else { $post['pages'] = Misc::genSmallPage('admincp/pages', $curPage); $filterPending = ''; $post['theList'] = Pages::get(array('limitShow' => 20, 'limitPage' => $curPage, 'cacheTime' => 1)); } System::setTitle('Pages list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('pagesList', $post); View::make('admincp/footer'); }
public function index() { $post = array('alert' => ''); Model::load('admincp/theme'); if ($match = Uri::match('\\/theme\\/(\\w+)')) { if (method_exists("controlTheme", $match[1])) { $method = $match[1]; $this->{$method}(); die; } } if ($match = Uri::match('\\/activate\\/(\\w+)')) { $theName = $match[1]; try { Theme::setActivate($theName); $post['alert'] = '<div class="alert alert-success">Change theme success</div>'; Redirect::to(ADMINCP_URL . 'theme'); } catch (Exception $e) { $post['alert'] = '<div class="alert alert-warning">' . $e->getMessage() . '</div>'; } } $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } $post['listThemes'] = Theme::get(); $post['theme'] = Theme::getDefault(); System::setTitle('Theme list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('themeList', $post); View::make('admincp/footer'); }
public function test($test_text) { $model = Model::load('test', 1); $model->name = 'zmiana nazwy'; $model->save(); $this->template->test = $model->name; }
public function index() { $post = array('alert' => ''); Model::load('admincp/usergroups'); if ($match = Uri::match('\\/usergroups\\/(\\w+)')) { if (method_exists("controlUsergroups", $match[1])) { $method = $match[1]; $this->{$method}(); die; } } $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } if (Request::has('btnAction')) { actionProcess(); } // $valid=UserGroups::getThisPermission('can_addnew_usergroup'); $post['pages'] = Misc::genPage('admincp/usergroups', $curPage); $post['theList'] = UserGroups::get(array('cacheTime' => 1, 'limitShow' => 20, 'limitPage' => $curPage)); System::setTitle('Usergroups list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('usergroupsList', $post); View::make('admincp/footer'); }
public function index() { $post = array('alert' => ''); Model::load('admincp/comments'); if ($match = Uri::match('\\/comments\\/(\\w+)')) { if (method_exists("controlComments", $match[1])) { $method = $match[1]; $this->{$method}(); die; } } $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } if (Request::has('btnAction')) { actionProcess(); } if (Request::has('btnSearch')) { filterProcess(); } else { $post['pages'] = Misc::genSmallPage('admincp/comments', $curPage); $filterPending = ''; if (Uri::has('\\/status\\/pending')) { $filterPending = " AND c.status='0' "; } $post['theList'] = Comments::get(array('limitShow' => 20, 'limitPage' => $curPage, 'query' => "select c.*,p.title from " . Database::getPrefix() . "post p," . Database::getPrefix() . "comments c where c.postid=p.postid order by c.commentid desc", 'cacheTime' => 1)); } System::setTitle('Comments list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('commentsList', $post); View::make('admincp/footer'); }
private static function getModel() { if (PgFileStore::$model == null) { PgFileStore::$model = Model::load("system.binary_objects"); } return PgFileStore::$model; }
public function __construct() { parent::__construct(); $this->univ = Model::load('UnivModel'); $this->user = Model::load('UserModel'); $this->group = Model::load('GroupModel'); }
public function index() { $post = array('alert' => ''); Model::load('admincp/users'); if ($match = Uri::match('\\/users\\/(\\w+)')) { if (method_exists("controlUsers", $match[1])) { $method = $match[1]; $this->{$method}(); die; } } $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } if (Request::has('btnAction')) { actionProcess(); } if (Request::has('btnSearch')) { filterProcess(); } else { $post['pages'] = Misc::genSmallPage('admincp/users', $curPage); $prefix = ''; $prefixall = Database::isPrefixAll(); if ($prefixall != false || $prefixall == 'no') { $prefix = Database::getPrefix(); } $post['theList'] = Users::get(array('limitShow' => 20, 'limitPage' => $curPage, 'query' => "select u.*,ug.*,a.* from " . $prefix . "users u," . $prefix . "usergroups ug,address a where u.groupid=ug.groupid AND u.userid=a.userid order by u.userid desc", 'cacheTime' => 1)); } System::setTitle('User list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('userList', $post); View::make('admincp/footer'); }
/** * The method which displays the permissions so they could be setup. This * method is called by the application and it performs recursive calls to * the drawPermissions() method. * * @param $params array Passes the role_id through an array. * @return String */ public function permissions($params) { if ($_POST["is_sent"] == "yes") { //Save the permission values $this->permissions = Model::load(".permissions"); $permissions = $_POST; array_pop($permissions); foreach ($permissions as $permission => $value) { $this->permissions->delete("role_id = '{$params[0]}' AND permission = '{$permission}'"); $this->permissions->setData(array("role_id" => $params[0], "permission" => $permission, "value" => $value[0], "module" => $value[1])); $this->permissions->save(); } //Generate a new side menu for this role $menu = $this->generateMenus($params[0]); $flatened = $this->flatenMenu($menu); $sideMenu = Controller::load(array("system", "side_menu", "generate", serialize($menu))); file_put_contents("app/cache/menus/side_menu_{$params[0]}.html", $sideMenu->content); file_put_contents("app/cache/menus/menu_{$params[0]}.object", serialize($flatened)); User::log("Set permissions"); //, $permissions); } $path = $params; array_shift($path); $accum = Application::$prefix . "/system/roles/permissions/{$params[0]}"; $menu = "<a href='{$accum}'>Permissions</a>"; foreach ($path as $section) { $accum .= "/{$section}"; $menu .= " > <a href='{$accum}'>" . ucfirst($section) . "</a>"; } $path = implode("/", $path); $ret .= "<form class='fapi-form' method='post'>" . $menu . "<br/><hr/>" . $this->drawPermissions($this->getPermissionList("app/modules/{$path}", "app/modules"), $params[0]) . "<input type='hidden' name='is_sent' value='yes'/>" . $this->save . "</div></form>"; Application::setTitle("Role Permissions"); return $ret; }
/** * ブログの設定変更処理 */ private function settingEdit($white_list, $action) { $request = Request::getInstance(); $blog_settings_model = Model::load('BlogSettings'); $blog_id = $this->getBlogId(); // 初期表示時に編集データの取得&設定 if (!$request->get('blog_setting') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { Session::set('sig', App::genRandomString()); $blog_setting = $blog_settings_model->findByBlogId($blog_id); $request->set('blog_setting', $blog_setting); return; } // 更新処理 $errors = array(); $errors['blog_setting'] = $blog_settings_model->validate($request->get('blog_setting'), $blog_setting_data, $white_list); if (empty($errors['blog_setting'])) { // コメント確認からコメントを確認せずそのまま表示に変更した場合既存の承認待ちを全て承認済みに変更する $blog_setting = $blog_settings_model->findByBlogId($blog_id); if ($blog_setting['comment_confirm'] == Config::get('COMMENT.COMMENT_CONFIRM.CONFIRM') && $blog_setting_data['comment_confirm'] == Config::get('COMMENT.COMMENT_CONFIRM.THROUGH')) { Model::load('Comments')->updateApproval($blog_id); } // ブログの設定情報更新処理 if ($blog_settings_model->updateByBlogId($blog_setting_data, $blog_id)) { // 一覧ページへ遷移 $this->setInfoMessage(__("I have updated the configuration information of the blog")); $this->redirect(array('action' => $action)); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }
private function getInstance() { if (self::$instance === false) { self::$instance = Model::load('system.audit_trail'); self::$dataModel = Model::load('system.audit_trail_data'); } return self::$instance; }
/** * idとuser_idをキーとした更新 */ public function deleteByIdAndUserId($id, $user_id, $options = array()) { if (!parent::deleteByIdAndUserId($id, $user_id, $options)) { return false; } // 登録状態(id<>0)のプラグインを未登録(id=0)に戻す return Model::load('BlogPlugins')->update(array('plugin_id' => 0), 'plugin_id=?', array($id)); }
protected function performAjaxValidation(Model $model) { if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) { \Yii::$app->response->format = Response::FORMAT_JSON; echo json_encode(ActiveForm::validate($model)); \Yii::$app->end(); } }
public static function checkUnique($str, $params = array()) { $model = new Model($params["type"]); if (!is_array($params["conditions"])) { $params["conditions"] = array(); } $item = $model->load(array("conditions" => array_merge($params["conditions"], array($params["field"] => $str)))); return empty($item); }
/** * A utility function around the SQLDataStore::getMulti() method. This function * allows for dynamic fields. These dynamic fields are fields which are read * from a database table. * * @param array $params * @param int $mode * @return array * @see SQLDataStore::getMulti() */ public static function getReportData($params, $mode = SQLDatabaseModel::MODE_ASSOC) { $dynamicFields = array(); if (is_array($params["dynamicHeaders"])) { foreach ($params["dynamicHeaders"] as $key => $dynamicHeader) { $info = Model::resolvePath($dynamicHeader); $headers = Model::load($info["model"]); $data = $headers->get(array("fields" => array($headers->getKeyField(), $info["field"])), SQLDataBaseModel::MODE_ARRAY); foreach ($data as $dat) { $replacement[$dat[1]] = null; } $dynamicFields[$key]["replacement"] = $replacement; $dynamicFields[$key]["headers"] = $data; $dynamicFields[$key]["field"] = $params["dynamicFields"][$key]; $dynamicFields[$key]["keyField"] = count($params["fields"]); //array_search($headers->getKeyField(), $params["fields"]); $dynamicFields[$key]["replaceIndex"] = array_search($params["dynamicFields"][$key], $params["fields"]); $dynamicFields[$key]["numFields"] = count($data); $params["fields"][] = $headers->package . "." . $headers->getKeyField(); } } $data = SQLDBDataStore::getMulti($params, $mode); $numData = count($data); if ($numData == 0) { return $data; } elseif ($numData == 1) { foreach ($dynamicFields as $dynamicField) { array_splice($data[0], $dynamicField["replaceIndex"], 1, array_pad(array(), $dynamicField["numFields"], $data[0][$dynamicField["replaceIndex"]])); } } else { if (count($dynamicFields) == 0) { return $data; } $keys = array_keys($data[0]); $numReturnData = 0; for ($i = 0; $i < $numData;) { foreach ($dynamicFields as $dynamicField) { $base = $i; $returnData[] = $data[$i]; array_splic($returnData[$numReturnData], $dynamicField["replaceIndex"], 1, $dynamicField["replacement"]); foreach ($dynamicField["headers"] as $header) { for ($j = 0; $j < $dynamicField["numFields"]; $j++) { if ($data[$base + $j][$dynamicField["keyField"]] == $header[0]) { $returnData[$numReturnData][$header[1]] = $data[$base + $j][$keys[$dynamicField["replaceIndex"]]]; break; } } $i++; } unset($returnData[$numReturnData][$dynamicField["keyField"]]); $numReturnData++; } } $data = $returnData; } return $data; }
public static function api($action) { Model::load('api/pluginstore'); try { $result = loadApi($action); } catch (Exception $e) { throw new Exception($e->getMessage()); } return $result; }
public static function api($action) { Model::load('api/".Database::getPrefix()."pages'); try { $result = loadApi($action); } catch (Exception $e) { throw new Exception($e->getMessage()); } return $result; }
function testModelConnection() { $model = new Model(); $config = load_config(); $model->config = $config["database"]; $model->load(); global $test; echo "<br />"; $test->show(); }
/** * Performs AJAX validation. * * @param array|Model $model * * @throws ExitException */ public function performAjaxValidation($model) { if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax) { if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; echo json_encode(ActiveForm::validate($model)); Yii::$app->end(); } } }
public function index() { Model::load('admincp/dashboard'); $post = countStats(); // $headData=array('title'=>'Dashboard - '.ADMINCP_TITLE); System::setTitle('Dashboard - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('dashboard', $post); View::make('admincp/footer'); }
public function index() { if ($match = Uri::match('\\/jsonCategory')) { $keyword = String::encode(Request::get('keyword', '')); $loadData = Categories::get(array('where' => "where title LIKE '%{$keyword}%'", 'orderby' => 'order by title asc')); $total = count($loadData); $li = ''; for ($i = 0; $i < $total; $i++) { $li .= '<li><span data-method="category" data-id="' . $loadData[$i]['catid'] . '" >' . $loadData[$i]['title'] . '</span></li>'; } echo $li; die; } $post = array('alert' => ''); Model::load('admincp/categories'); $curPage = 0; if ($match = Uri::match('\\/page\\/(\\d+)')) { $curPage = $match[1]; } if (Request::has('btnAction')) { actionProcess(); } if (Request::has('btnAdd')) { try { insertProcess(); $post['alert'] = '<div class="alert alert-success">Add new category success.</div>'; } catch (Exception $e) { $post['alert'] = '<div class="alert alert-warning">' . $e->getMessage() . '</div>'; } } if (Request::has('btnSave')) { $match = Uri::match('\\/edit\\/(\\d+)'); try { updateProcess($match[1]); $post['alert'] = '<div class="alert alert-success">Update category success.</div>'; } catch (Exception $e) { $post['alert'] = '<div class="alert alert-warning">' . $e->getMessage() . '</div>'; } } if (Request::has('btnSearch')) { filterProcess(); } else { $post['pages'] = Misc::genSmallPage('admincp/categories', $curPage); $post['theList'] = Categories::get(array('limitShow' => 20, 'limitPage' => $curPage, 'orderby' => 'order by catid desc', 'cache' => 'no')); } if ($match = Uri::match('\\/edit\\/(\\d+)')) { $loadData = Categories::get(array('where' => "where catid='" . $match[1] . "'", 'cache' => 'no')); $post['edit'] = $loadData[0]; } System::setTitle('Categories list - ' . ADMINCP_TITLE); View::make('admincp/head'); self::makeContents('categoriesList', $post); View::make('admincp/footer'); }
protected function setupList() { parent::setupList(); $this->selectionList = new SelectionListToolbarItem($this->filterLabel); $this->addListItems(); if ($this->filterFieldModel == null) { $this->filterFieldModel = $this->model; } else { $this->filterFieldModel = Model::load($this->filterFieldModel); } $this->selectionList->onchange = "wyf.updateFilter('{$this->table->name}', '{$this->filterFieldModel->database}.{$this->filterField}', this.value)"; $this->toolbar->add($this->selectionList); }
public function index() { if ($match = Uri::match('^api\\/(\\w+)')) { Model::load('api'); try { apiProcess(); } catch (Exception $e) { echo $e->getMessage(); } } else { echo json_encode(array('error' => 'yes')); } }
protected function setupListView() { $this->selectionList = new SelectionListToolbarItem($this->filterLabel); $this->addListItems(); if ($this->filterFieldModel == null) { $this->filterFieldModel = $this->model; } else { $this->filterFieldModel = Model::load($this->filterFieldModel); } $this->selectionList->onchange = "wyf.updateFilter('defaultTable', '{$this->filterFieldModel->database}.{$this->filterField}', this.value)"; $this->listView->getToolbar()->add($this->selectionList); parent::setupListView(); }
/** * 記事の予約投稿、期間投稿処理 */ public function updateOpenStatus() { $blog_id = $this->getBlogId(); if (empty($blog_id)) { // blog_idが指定されていない場合は処理しない // cron実行時であればblog_id無し(全体)で処理を行う return; } $entriesModel = Model::load('Entries'); // 予約投稿処理 $entriesModel->updateReservation($blog_id); // 期間限定処理 $entriesModel->updateLimited($blog_id); }
public static function generate($userId) { $usersRolesModel = Model::load("auth.users_roles")->setQueryResolve(false); $roles = $usersRolesModel->getWithField2('user_id', $userId); self::$permissionsModel = Model::load('system.permissions'); $menu = []; foreach ($roles as $role) { $menu = self::mergeMenus($menu, self::generateMenus($role['role_id'])); } $flatened = self::flatenMenu($menu); $sideMenu = Controller::load(array("system", "side_menu", "generate", serialize($menu))); file_put_contents("app/cache/menus/side_menu_u{$userId}.html", $sideMenu->content); file_put_contents("app/cache/menus/menu_u{$userId}.object", serialize($flatened)); }
public static function roles_callback($data, $form) { $usersRolesModel = Model::load("auth.users_roles"); $usersRolesModel->datastore->beginTransaction(); $userId = array_pop($data); $loggedInUsersRoles = $usersRolesModel->getWithField("user_id", $_SESSION['user_id']); //this is for hackers who try to use scripts of a kind to bypass the UI..this throws an exception to prevent //the user from giving himself super user access //the exception is thrown and basically the use's roles are deleted from the table -> bug or not //If a user tries to set the role to 1 and the user is not super user throw exception foreach ($data as $role) { if ($role == 1) { foreach ($loggedInUsersRoles as $userRole) { if ($userRole['role_id'] == 1) { $throwException = false; break; } else { $throwException = true; } } if ($throwException) { throw new Exception('Unauthorised Action'); } } } //delete all the entries related to that user $usersRolesModel->delete('user_id', $userId); //defaults to true and changes to false if the logged in user is really superuser $throwException = true; foreach ($data as $role) { if ($role != 0) { $usersRolesModel->setData(array('user_id' => $userId, 'role_id' => $role)); $usersRolesModel->save(); } } $menuFile = __DIR__ . "/cache/menus/side_menu_u{$userId}.html"; $objectFile = __DIR__ . "/cache/menus/menu_u{$userId}.object"; //delete menu & object file for user if (file_exists($menuFile)) { unlink($menuFile); } if (file_exists($objectFile)) { unlink($objectFile); } //generate menu for user AuthMenu::generate($userId); $usersRolesModel->datastore->endTransaction(); Application::redirect("/auth/users?notification=Role(s) saved successfully"); return true; }
/** * ログイン中のブログかどうかを返却 */ protected function isLoginBlog() { // ログイン中判定 $admin_blog_id = $this->getAdminBlogId(); if (empty($admin_blog_id)) { return false; } // ログイン中のブログIDと判定 $blog_id = $this->getBlogId(); if ($admin_blog_id == $blog_id) { return true; } // ログイン判定 return Model::load('Blogs')->isUserHaveBlogId($this->getAdminUserId(), $blog_id); }