protected function getTableMetaData() { $parentMeta = parent::getTableMetaData(); $tab = new DBTable($this->db, $this->gridQuery . ' LIMIT 1', null, DB::FETCH_ASSOC); if (!$tab->ok()) { return false; } foreach (array_keys($tab->getRow(0)) as $col) { if (!isset($this->columnTitles[$col])) { $this->columnTitles[$col] = $this->convertColumnToTitle($col); $this->cellAttributes[$col] = []; } } $displayColumns = array_keys($tab->getRow(0)); $columnNames = array_keys($this->columnTitles); foreach ($columnNames as $columnName) { if (!in_array($columnName, $displayColumns)) { unset($this->columnTitles[$columnName]); unset($this->cellAttributes[$columnName]); unset($this->displayType[$columnName]); } } return true; }
public function recentAlarms() { $sql = <<<SQL SELECT * FROM tblModJackAlert WHERE fldStatus='new' ORDER BY fldTimeStamp LIMIT 50 SQL; $html = '<h2>Recent Alerts</h2>'; $tab = new DBTable(DB::DEF, $sql, null, DB::FETCH_ASSOC); if ($tab->isEmpty()) { $html .= "There are no alerts at the moment"; } else { $html .= Tag::table() . Tag::tr() . Tag::th() . 'Type' . Tag::_th() . Tag::th() . 'Description' . Tag::_th() . Tag::th() . 'Time' . Tag::_th() . Tag::th() . 'Actions' . Tag::_th() . Tag::_tr(); $resp = MenuUtils::responseObject()->action(__CLASS__ . '->recentAlarmsAck()'); foreach ($tab as $row) { $style = ['class' => $row['fldType'] . '_row']; $html .= Tag::tr($style) . Tag::td($style) . Tag::e($row['fldType']) . Tag::_td() . Tag::td($style) . Tag::e($row['fldDescription']) . Tag::_td() . Tag::td($style) . Tag::e($row['fldTimeStamp']) . Tag::_td() . Tag::td($style) . Tag::linkButton('?' . $resp->set('fldModJackAlertID', $row['fldModJackAlertID'])->toUrl(), 'Ack') . Tag::_td() . Tag::_tr(); } $html .= Tag::_table(); } return $html; }
public static function migrate() { $maxRun = 0; $runItems = []; foreach (DBTable::factory(DB::DEF, 'SELECT * FROM tblMigration') as $row) { if ((int) $row['fldRun'] > $maxRun) { $maxRun = (int) $row['fldRun']; } if (!isset($runItems[$row['fldClass']])) { $runItems[$row['fldClass']] = []; } $runItems[$row['fldClass']][] = $row['fldMethod']; } $maxRun += 1; $html = ''; // Go through all the migration classes foreach (Cfg::get('migration', []) as $migrationClass) { $clazz = new \ReflectionClass($migrationClass); // If new class then just add empty list if (!isset($runItems[$migrationClass])) { $runItems[$migrationClass] = []; } // get a list of methods to run $methodList = []; foreach ($clazz->getMethods() as $method) { if (in_array($method->name, $runItems[$migrationClass])) { continue; } if (strpos($method->name, 'migrate') !== 0) { continue; } // Add the name to the list $methodList[] = $method->name; } // Sort so that it will be date ordered sort($methodList); foreach ($methodList as $method) { if (($result = call_user_func([$migrationClass, $method])) === false) { $html .= "There is a problem running {$migrationClass}::{$method}<br/>\n"; } else { $html .= $result; DB::exec(DB::DEF, 'INSERT INTO tblMigration (fldMigrationID,fldRun,fldClass,fldMethod) VALUES (?,?,?,?)', [DBMaintenance::dbNextNumber(DB::DEF, 'tblMigration'), $maxRun, $migrationClass, $method]); } } } return $html; }
/** * Generates a drop down box from almost anything * @param string $name nameof the select * @param array $displayList * @param array $attribs html attributes to generate * @param string $defaultValue matches the key in the displayList * @param boolean $blank true if you want to generate a blank row * @returns string The resulting HTML */ static function selectWithCategories($name, $resultset, $attribs = array()) { if (isset($attribs['default'])) { $defaultValue = $attribs['default']; unset($attribs['default']); } else { $defaultValue = Request::get($name, null); } $hasBlank = false; if (isset($attribs['hasBlank'])) { $hasBlank = $attribs['hasBlank']; unset($attribs['hasBlank']); } $optGroupAttrib = array(); if (isset($attribs['optGroupAttrib'])) { $optGroupAttrib = $attribs['optGroupAttrib']; unset($attribs['optGroupAttrib']); } if (is_array($resultset)) { if (count($resultset) == 0) { $tag = "* None Available *"; if ($defaultValue != null) { $tag .= Tag::hidden($name, $defaultValue); } } else { $tag = Tag::select($name, $attribs); if ($hasBlank) { $tag .= Tag::optiontag(' ', '', !isset($defaultValue) || $defaultValue == false); } foreach ($resultset as $category => $list) { $tag .= Tag::hTag('optgroup', array_merge($optGroupAttrib, array('label' => $category))); foreach ($list as $key => $val) { $tag .= Tag::optiontag(trim($key), $val, $defaultValue == $key); } $tag .= Tag::_hTag('optgroup'); } $tag .= Tag::_select(); } } else { if (is_object($resultset)) { /** FIXME **/ $table = new DBTable($resultset, DB::FETCH_NUM); if ($table->rowCount() == 0) { $tag = "* None Available *"; if ($defaultValue != null) { $tag .= Tag::hidden($name, $defaultValue); } } else { $tag = Tag::select($name, $attribs); if ($hasBlank) { $tag .= Tag::optiontag(' ', '', !isset($defaultValue) || $defaultValue == false); } $prevCategory = ''; foreach ($table as $row) { if ($prevCategory != $row[0]) { if ($prevCategory != '') { $tag .= Tag::_hTag('optgroup'); } $tag .= Tag::hTag('optgroup', array('label' => $row[0])); $prevCategory = $row[0]; } $tag .= Tag::optiontag($row[1], $row[2], $defaultValue == $row[1]); } $tag .= Tag::_hTag('optgroup'); $tag .= Tag::_select(); } } } return $tag; }
public function fileChecksum() { $messageArray = []; $dirList = PHPExt::dirSearch(Cfg::get('site_path'), '/^[^_].*$/'); $len = strlen(Cfg::get('site_path')) + 1; foreach ($dirList as &$path) { $path = substr($path, $len); } $tab = new DBTable(DB::DEF, 'SELECT * FROM tblFileCheck'); foreach ($tab as $row) { if (in_array($row['fldFileName'], $dirList)) { $fullPath = Cfg::get('site_path') . '/' . $row['fldFileName']; $fileSize = filesize($fullPath); $sha1 = sha1_file($fullPath); if ($fileSize != $row['fldSize']) { $messageArray[$row['fldFileName']] = 'Mismatch file size. was: ' . $row['fldSize'] . ' now: ' . $fileSize; } else { if ($sha1 != $row['fldCRC']) { $messageArray[$row['fldFileName']] = 'Mismatch SHA1. was: ' . $row['fldCRC'] . ' now: ' . $sha1; } } } else { $messageArray[$row['fldFileName']] = 'File deleted'; } } $oldFileList = $tab->getColumn('fldFileName'); foreach ($dirList as $fileName) { if (!in_array($fileName, $oldFileList)) { $messageArray[$fileName] = 'New file'; } } $html = ''; if (count($messageArray) != 0) { foreach ($messageArray as $key => $val) { $html .= $key . ': ' . $val . '<br/>'; } } else { $html = 'No Changes<br/>'; } $rebaseButton = Tag::linkButton('?' . Response::factory()->action(__CLASS__ . '->' . __FUNCTION__ . 'Rebase()'), 'Rebase'); return $rebaseButton . '<br/>' . $html . $rebaseButton; }
/** * @param $sets * @param $where * @return int */ public function update($sets, $where) { DBTable::clearCache(); $sets = $this->objToRel($sets); // This allows for dummy columns to be part of the object without the // DAO automatically accessing them in the queries. if ($this->ignoreCols != null) { foreach ($this->ignoreCols as $ignoreCol) { unset($sets[$ignoreCol]); } } $params = []; $sql = 'UPDATE ' . $this->tableName . ' ' . 'SET ' . join('=?, ', array_keys($sets)) . '=? ' . $this->toWhere($where, $params); return DB::exec($this->db, $sql, array_merge(array_values($sets), $params)); }
public function manageGroupsCallBack($id, $key) { $concat = DB::driver() == DB::MYSQL ? "CONCAT(fldFirstName,' ',fldLastName)" : "fldFirstName || ' ' || fldLastName"; $sql = <<<SQL SELECT {$concat} FROM tblUser WHERE fldUserID IN ( SELECT fldUserID FROM tblUserGroupMap WHERE fldGroupID=? ) SQL; $users = DBTable::factory(DB::DEF, $sql, $key, DB::FETCH_NUM)->getColumn(0); $userList = join(', ', $users); if ($userList == '') { $userList = '*None*'; } $this->resp->action(__CLASS__ . "->manageUsersToGroups()")->set('IDX', $id)->set('KEY', $key); return Tag::hRef('?' . $this->resp->toUrl(), $userList, ['title' => 'Click here to edit the users in this group']); }
/** Function to load the user Group details * @returns boolean * @private */ function _loadGroupTable() { // Load the first group because it is the Global Group $sql = DB::limit("SELECT * FROM tblGroup", 0, 1); $tab = new DBTable(DB::DEF, $sql, null, DB::FETCH_ASSOC); if ($tab->isEmpty()) { return false; } $fldGroup = []; $fldGroup[$tab->getValue("fldGroupID")] = $tab->getValue("fldName"); // get the groups that are related to this client $sql = "SELECT g.* FROM tblGroup g, tblUserGroupMap map " . "WHERE map.fldUserID='" . $this->prefs->get("fldIserID") . "' " . "AND map.fldGroupID=g.fldGroupID "; $tab = new DBTable(DB::DEF, $sql, null, DB::FETCH_ASSOC); if (!$tab->isEmpty()) { for ($i = 0; $i < $tab->getRowCount(); $i++) { $fldGroup[$tab->getValue("fldGroupID", $i)] = $tab->getValue("fldName", $i); } } $this->prefs->put("fldGroup", $fldGroup); // return true/success return TRUE; }
public static function getSecurityLevel($level) { if (self::$securityLevels == null) { $tab = new DBTable(DB::DEF, Admin::LEVEL_SQL, null, DB::FETCH_NUM); $valCol = $tab->getColumn(0); $namCol = $tab->getColumn(1); self::$securityLevels = array_merge(array_combine($valCol, $namCol), array_combine($namCol, $valCol)); } return self::$securityLevels[$level]; }