/** * Gives all the attributes that can be used for the import. * * @return array the attributes */ public function getUsableAttributes() { $selected = $value == 'new' ? false : true; $criteria = []; if (!in_array($value, array('new', 'none', ''))) { $db = Db::getInstance(); $rows = $db->getRows('SELECT * FROM atk_exportcriteria WHERE id = ' . (int) $value); $criteria = unserialize($rows[0]['criteria']); } $atts = []; $attriblist = $this->invoke('getExportAttributes'); foreach ($attriblist as $key => $value) { $flags = $value->m_flags; $class = strtolower(get_class($value)); if ($value->hasFlag(Attribute::AF_AUTOKEY) || $value->hasFlag(Attribute::AF_HIDE_VIEW) || !(strpos($class, 'dummy') === false) || !(strpos($class, 'image') === false) || !(strpos($class, 'tabbedpane') === false)) { continue; } if (method_exists($this->m_node, 'getExportAttributeGroup')) { $group = $this->m_node->getExportAttributeGroup($value->m_name); } else { $group = $value->m_tabs[0]; } if (in_array($group, $atts)) { $atts[$group] = []; } // selected options based on a new selection, or no selection if (empty($criteria)) { $atts[$group][] = array('name' => $key, 'text' => $value->label(), 'checked' => $selected == true ? !$value->hasFlag(Attribute::AF_HIDE_LIST) : false); } else { $atts[$group][] = array('name' => $key, 'text' => $value->label(), 'checked' => in_array('export_' . $key, $criteria) ? true : false); } } return $atts; }
/** * Wrapper for escapeSQL function. * * @param string $string The string to escape. * @param bool $wildcard Set to true to convert wildcard chars ('%'). * False (default) will leave them unescaped. * * @return string A SQL compatible version of the input string. */ public static function escapeSQL($string, $wildcard = false) { $db = Db::getInstance(); return $db->escapeSQL($string, $wildcard); }
/** * Get details for the query. * * @param array $queries Array with queries * @param int $id The index in the queries array we want the details from * * @return string The query details */ public function queryDetails($queries, $id) { $output = '<h1>Query</h1>'; $query = $queries[$id]['query']; $output .= $this->highlightQuery($query); $db = Db::getInstance(); if (strtolower(substr(trim($query), 0, 6)) == 'select') { $output .= '<h1>Resultset</h1>'; $result = $db->getRows($query); if (count($result)) { $output .= $this->arrToTable($result, $_REQUEST['full'], $id); } else { $output .= 'Query returned no rows'; } $output .= '<h1>Explain plan</h1>'; $result = $db->getRows('EXPLAIN ' . $query); $output .= $this->arrToTable($result); } if ($queries[$id]['trace'] != '') { $output .= '<h1>Backtrace</h1>'; $output .= $queries[$id]['trace']; } return $output; }
public function selectUser($user) { $usertable = Config::getGlobal('auth_usertable'); $sspifield = Config::getGlobal('auth_sspi_accountfield'); $leveltable = Config::getGlobal('auth_leveltable'); $levelfield = Config::getGlobal('auth_levelfield'); $userpk = Config::getGlobal('auth_userpk'); $userfk = Config::getGlobal('auth_userfk', $userpk); $grouptable = Config::getGlobal('auth_grouptable'); $groupfield = Config::getGlobal('auth_groupfield'); $groupparentfield = Config::getGlobal('auth_groupparentfield'); $db = Db::getInstance(Config::getGlobal('auth_database')); if ($usertable == $leveltable || $leveltable == '') { // Level and userid are stored in the same table. // This means one user can only have one level. $query = "SELECT * FROM {$usertable} WHERE {$sspifield} ='{$user}'"; } else { // Level and userid are stored in two separate tables. This could // mean (but doesn't have to) that a user can have more than one // level. $qryobj = $db->createQuery(); $qryobj->addTable($usertable); $qryobj->addField("{$usertable}.*"); $qryobj->addField('usergroup.*'); $qryobj->addJoin($leveltable, 'usergroup', "{$usertable}.{$userpk} = usergroup.{$userfk}", true); $qryobj->addCondition("{$usertable}.{$sspifield} = '{$user}'"); if (!empty($groupparentfield)) { $qryobj->addField("grp.{$groupparentfield}"); $qryobj->addJoin($grouptable, 'grp', "usergroup.{$levelfield} = grp.{$groupfield}", true); } $query = $qryobj->buildSelect(); } $recs = $db->getRows($query); return $recs; }
/** * This function returns the list of users that may login. This can be * used to display a dropdown of users from which to choose. * * @return array List of users as an associative array with the following * format: array of records, each record is an associative * array with a userid and a username field. */ public function getUserList() { $db = Db::getInstance(Config::getGlobal('auth_database')); $query = 'SELECT * FROM ' . Config::getGlobal('auth_usertable'); $accountdisablefield = Config::getGlobal('auth_accountdisablefield'); $accountenableexpression = Config::getGlobal('auth_accountenableexpression'); if ($accountenableexpression != '') { $query .= " WHERE {$accountenableexpression}"; if ($accountdisablefield != '') { $query .= " AND {$accountdisablefield} = 0"; } } else { if ($accountdisablefield != '') { $query .= " WHERE {$accountdisablefield} = 0"; } } $recs = $db->getRows($query); $userlist = []; $stringparser = new StringParser(Config::getGlobal('auth_userdescriptor')); for ($i = 0, $_i = count($recs); $i < $_i; ++$i) { $userlist[] = array('userid' => $recs[$i][Config::getGlobal('auth_userfield')], 'username' => $stringparser->parse($recs[$i])); } usort($userlist, array('auth_db', 'userListCompare')); return $userlist; }
/** * Get the database connection for this node. * * @return Db Database connection instance */ public function getDb() { if ($this->m_db == null) { return Db::getInstance(); } else { if (is_object($this->m_db)) { return $this->m_db; } else { // must be a named connection return Db::getInstance($this->m_db); } } }
private function rememberMeDeleteToken($id) { $db = Db::getInstance(); $dbTable = Config::getGlobal('auth_rememberme_dbtable'); $sql = "DELETE FROM `{$dbTable}` WHERE id = ?"; $stmt = $db->prepare($sql); $stmt->execute([$id]); $db->commit(); }
/** * Get database instance for this attribute. Will return the owner * instance database instance unless the owner instance is not set * in which case the default instance will be returned. * * @return Db database instance */ public function getDb() { if (is_object($this->getOwnerInstance())) { return $this->getOwnerInstance()->getDb(); } return Db::getInstance(); }
/** * Build and execute DROP VIEW query. * * @param string $name - name of view * * @return true if view create successfully * false if error take place */ public function executeDropView($name) { if (!isset($this->m_db)) { $this->m_db = Db::getInstance(); } $query = $this->dropView($name); if ($query != '') { return $this->m_db->query($query); } else { Tools::atkdebug('ddl::executeDropView: nothing to do!'); } return false; }