public static function create($db) { if (!self::$obj) { self::$obj = new modulelist($db); } return self::$obj; }
function __construct() { global $amp_conf, $db; $this->amp_conf =& $amp_conf; $this->auth = new RestAuth($this); $this->db =& $db; //import our db object $this->hash_algo = 'sha256'; $this->opts = restapi_opts_get(); if ($this->opts['logging'] == 'enabled') { $this->log = new RestLogger($this); } else { $this->log = NULL; } $this->mods = modulelist::create($this->db); //matched routes, if any $this->_register_routes(); $this->res = new stdClass(); $this->res->nonce = restapi_tokens_generate(); //setup $this->req $this->_get_req(); if ($this->log) { $this->log->init(); } }
/** Internal use only */ function _setenabled($modulename, $enabled) { global $db; $sql = 'UPDATE modules SET enabled = ' . ($enabled ? '1' : '0') . ' WHERE modulename = "' . $db->escapeSimple($modulename) . '"'; $results = $db->query($sql); if (DB::IsError($results)) { die_freepbx($sql . "<br>\n" . $results->getMessage()); } $modulelist =& modulelist::create($db); $modulelist->invalidate(); }
public function usermanShowPage() { if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'showgroup': case 'addgroup': case 'adduser': case 'showuser': $enabled = null; if ($_REQUEST['action'] == "showuser") { $enabled = $this->userman->getModuleSettingByID($_REQUEST['user'], 'restapi', 'restapi_token_status', true); $tokens = restapi_user_get_user_tokens($_REQUEST['user']); } else { $tokens = array(); } $displayvars = array("mode" => in_array($_REQUEST['action'], array("showgroup", "addgroup")) ? "group" : "user", "enabled" => $enabled); $tokens = !empty($tokens) ? $tokens : array(); $displayvars['user_list_all'] = array(); if (in_array($_REQUEST['action'], array("showgroup", "addgroup"))) { $displayvars['user_list_all']['self'] = _("User Primary Extension"); } $cul = array(); foreach (core_users_list() as $list) { $cul[$list[0]] = array("name" => $list[1], "vmcontext" => $list[2]); $displayvars['user_list_all'][$list[0]] = $list[1] . " <" . $list[0] . ">"; } // Get list of modules that have been API enabled. $api = new \Api(); $api_mods = array(); foreach ($api->maps as $verb => $urls) { foreach ($urls as $url => $maps) { foreach ($maps as $map => $details) { $api_mods[$details["module"]] = 1; } } } unset($api); //modules global $db; $mods = \modulelist::create($db); $displayvars['module_list'] = array(); foreach ($mods->module_array as $mod) { if (isset($mod['rawname']) && isset($api_mods[$mod['rawname']])) { $displayvars['module_list'][$mod['rawname']] = $mod['name']; } } asort($displayvars['module_list']); $displayvars['module_list'] = array('*' => _('All')) + $displayvars['module_list']; //everything else $rest_template = $displayvars; if (!empty($tokens)) { foreach ($tokens as $token) { $displayvars['tokens'][] = array_merge($rest_template, restapi_tokens_get($token)); } } else { $displayvars['tokens'][0] = array_merge($rest_template, restapi_tokens_get()); $displayvars['tokens'][0]['token'] = \restapi_tokens_generate(); $displayvars['tokens'][0]['tokenkey'] = \restapi_tokens_generate(); $displayvars['tokens'][0]['id'] = 0; $displayvars['tokens'][0]['users'] = array("self"); $displayvars['tokens'][0]['rate'] = 1000; } if ($displayvars['mode'] == "user") { } else { //group mode $enabled = $this->userman->getModuleSettingByGID($_REQUEST['group'], 'restapi', 'restapi_token_status'); $users = $this->userman->getModuleSettingByGID($_REQUEST['group'], 'restapi', 'restapi_users'); $modules = $this->userman->getModuleSettingByGID($_REQUEST['group'], 'restapi', 'restapi_modules'); $rate = $this->userman->getModuleSettingByGID($_REQUEST['group'], 'restapi', 'restapi_rate'); $displayvars['tokens'][0] = array_merge($rest_template, restapi_tokens_get()); $displayvars['tokens'][0]['token'] = 1; $displayvars['tokens'][0]['tokenkey'] = 1; $displayvars['tokens'][0]['id'] = 0; if (!$enabled) { $displayvars['tokens'][0]['users'] = is_array($users) ? $users : array("self"); $displayvars['enabled'] = $enabled; } else { $displayvars['tokens'][0]['users'] = is_array($users) ? $users : array("self"); $displayvars['tokens'][0]['rate'] = !empty($rate) ? $rate : "1000"; $displayvars['tokens'][0]['modules'] = is_array($modules) ? $modules : array(); $displayvars['enabled'] = $enabled; } } return array(array("title" => _("Rest API"), "rawname" => "restapi", "content" => load_view(__DIR__ . '/views/hook_userman.php', $displayvars))); break; } } }
require_once ROOT . '/class/datagrid.class.php'; $page = new page(); $page->startPanel('title', 'title'); $page->add('Thinkedit 2.0'); $page->endPanel('title'); $module_selector = new dropdown(); $module_selector->setId('module_list'); $module_selector->setTitle('Choisissez un type d\'élément à éditer'); $modules = $thinkedit->getModuleList(); $module_selector->persist(); foreach ($modules as $module) { $module_selector->add($module, $module); } $page->startPanel('module_list'); $page->add($module_selector->render()); $page->endPanel('module_list'); if ($module_selector->getSelected()) { $list = new modulelist(); $list->setType($module_selector->getSelected()); $modules = $list->load(); $datagrid = new datagrid(); $datagrid->addColumn('id', 'Id'); $datagrid->addColumn('title', 'Title'); foreach ($modules as $module) { $datagrid->add($module->getArray()); } $page->startPanel('datagrid'); $page->add($datagrid->render()); $page->endPanel('datagrid'); } echo $page->render();