public function checkIntegrity($table) { echo "{$this->name}: "; $q = DB::fetchOne("SHOW COLUMNS FROM `{$table}` WHERE Field='{$this->dbname}'"); $err = ''; if (!$q) { $err .= ' Field not found'; DB::query("ALTER TABLE `{$table}` ADD `{$this->dbname}` " . $this->getType() . (!$this->allownull ? ' NOT NULL' : '') . ($this->extra != '' ? " {$this->extra}" : '') . ($this->default != null ? " DEFAULT '{$this->default}'" : '')); $err .= ': added!'; } else { if ($q['Type'] != $this->getType()) { $err .= " Type is {$q['Type']} but should be: " . $this->getType(); } if (($q['Key'] == 'PRI') != $this->primary) { if ($this->primary) { $err .= ' Should be primary'; } else { $err .= ' Should not be primary'; } } if ($q['Default'] != $this->default) { $err .= " Default is {$q['Default']} but should be: {$this->default}"; } if ($q['Extra'] != $this->extra) { $err .= " Extra is {$q['Extra']} but should be: {$this->extra}"; } } if ($err == '') { echo ' OK'; } else { echo $err; } echo '<br />'; }
private function checkGroupRight($right) { $q = DB::fetchOne("SELECT * FROM group_rights gr, group_profiles gp WHERE gr.`right`={$right} and allow='Deny' and gr.group_id=gp.group_id and gp.profile_id=" . $this->id); if ($q) { return false; } $q = DB::fetchOne("SELECT * FROM group_rights gr, group_profiles gp WHERE gr.`right`={$right} and allow='Allow' and gr.group_id=gp.group_id and gp.profile_id=" . $this->id); if ($q) { return true; } return false; }
public function save() { $this->errors = array(); if (!$this->validate()) { return false; } $ar = array(); foreach (static::getFields() as $f) { if (!($f->name == 'id' && empty($this->row[$f->dbname])) && !$f->skip()) { $ar[$f->dbname] = $f->toString(Functions::nz($this->row[$f->dbname], $f->default)); } } if (isset($this->row['id']) && $this->row['id'] != 0 && DB::fetchOne('SELECT id FROM ' . static::getName() . ' WHERE id=' . $this->row['id'])) { DB::ezQuery('UPDATE', static::getName(), $ar, 'id=' . $this->row['id']); } else { DB::ezQuery('INSERT', static::getName(), $ar); $this->row['id'] = DB::getLastId(); } return true; }
public static function findParent(&$table, $id) { $q = DB::fetchOne('SELECT * FROM ' . $table . ' WHERE delomraade_id=' . $id); if (!$q) { return false; } return $q['omraade_id']; }