Пример #1
0
 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 />';
 }
Пример #2
0
 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;
 }
Пример #3
0
 public function remove()
 {
     DB::query('DELETE FROM `' . static::getName() . '` WHERE id=' . $this->row['id']);
     unset($this->row['id']);
 }
Пример #4
0
 public function handleException($route, \Exception $e)
 {
     $reg = Registry::getInstance();
     $t = $reg->twig->loadTemplate('error.tpl');
     $c = array();
     $c['route'] = $route;
     $c['type'] = get_class($e);
     $c['msg'] = $e->getMessage();
     $trace = $e->getTrace();
     foreach ($trace as $key => $entry) {
         $file = file_get_contents($entry['file']);
         $lines = explode("\n", $file);
         $start = $entry['line'] - 5;
         $end = $entry['line'] + 5;
         $trace[$key]['lines'] = array();
         if ($start < 0) {
             $start = 0;
         }
         if ($end > count($lines)) {
             $end = count($lines);
         }
         for ($i = $start; $i < $end; ++$i) {
             $trace[$key]['lines'][$i] = str_replace(array("\t", ' '), array('&nbsp;&nbsp;&nbsp;', '&nbsp;'), $lines[$i]);
         }
     }
     $c['trace'] = $trace;
     $out = $t->render($c);
     if (Auth::isLoggedin()) {
         $userid = Auth::$profile->id;
     } else {
         $userid = 0;
     }
     if (!DEBUG) {
         DB::query("INSERT into errorlog(time,message,user_id) values(now(),'" . DB::escape($out) . "',{$userid})");
         if (isset($reg->admin_email)) {
             $ms = new MailService('smtp.gmail.com', 465, '*****@*****.**', 'edderkop');
             $ms->send_mail($reg->admin_email, '*****@*****.**', 'Error occured', '', $out);
         }
     }
     echo $out;
 }
Пример #5
0
 public static function display($dict, $subforminfo = false)
 {
     $table = Functions::nz($dict['table'], false);
     $tableclass = Functions::nz($dict['tableclass'], false);
     $where = Functions::nz($dict['where'], array());
     $order = Functions::nz($dict['order'], false);
     $fields = Functions::nz($dict['fields'], false);
     $method = Functions::nz($dict['method'], 'post');
     $deleteable = Functions::nz($dict['deleteable'], true);
     $action = Functions::nz($dict['action'], Functions::getArgs());
     $submitlabel = Functions::nz($dict['submitlabel'], 'Update');
     $addlabel = Functions::nz($dict['addlabel'], 'Add new');
     $links = Functions::nz($dict['links'], array());
     $subform = Functions::nz($dict['subform'], false);
     $rowanchor = Functions::nz($dict['rowanchor'], false);
     $displayheader = Functions::nz($dict['displayheader'], false);
     $onupdate = Functions::nz($dict['onupdate'], false);
     $ondelete = Functions::nz($dict['ondelete'], false);
     $safedelete = Functions::nz($dict['safedelete'], false);
     $addline = Functions::nz($dict['addline'], true);
     $continous = Functions::nz($dict['type'], 'continous') == 'continous';
     $out = array();
     if ($table) {
         $i = 0;
         while (isset(self::$formids[$formid = ($subforminfo ? $subforminfo['pre'] . '_' : '') . $table . '_' . $i])) {
             ++$i;
         }
         self::$formids[$formid] = true;
         $rs = self::getRS($table, $where, $order, $subforminfo);
         $allFields = array();
         $qryFields = $rs->fetchFields();
         foreach ($qryFields as $f) {
             $allFields[$f->name] = array('type' => $f->type);
         }
         if ($method == 'post' && isset($_POST[$formid . '_submit'])) {
             self::checkTableForm($formid, $table, $_POST, $fields, $subform, $allFields, $onupdate);
         } elseif ($method == 'get' && isset($_GET[$formid . '_submit'])) {
             self::checkTableForm($formid, $table, $_GET, $fields, $subform, $allFields, $onupdate);
         }
         if (isset($_GET['delete']) && isset($_GET['formid']) && $_GET['formid'] == $formid) {
             if ($ondelete) {
                 $ondelete($_GET['delete']);
             }
             DB::query("DELETE FROM {$table} WHERE id=" . $_GET['delete']);
             header('Location: ' . Functions::getArgs('delete;formid'));
         }
         if (!$fields) {
             $fields = array();
             foreach ($qryFields as $f) {
                 $fields[] = array('name' => $f->name);
             }
         }
         // generate pretty names
         foreach ($fields as $k => $f) {
             if (!Functions::nz($f['prettyname'], false)) {
                 $fields[$k]['prettyname'] = self::makePrettyName($f['name']);
             }
         }
         if (!$subforminfo) {
             $out[] = "<form name=\"{$formid}\" method=\"{$method}\" action=\"\">";
         } else {
             $out[] = "<input type=\"hidden\" name=\"{$subforminfo['pre']}_subforms[]\" value=\"{$formid}\" />";
         }
         if ($continous) {
             $out[] = '<table' . ($tableclass ? " class=\"{$tableclass}\"" : '') . '>';
             $cols = count($fields) + count($links);
             if ($deleteable) {
                 $cols++;
             }
             if ($displayheader) {
                 $out[] = '<thead>';
                 $out[] = '<tr>';
                 foreach ($fields as $f) {
                     $type = isset($f['type']) ? $f['type'] : $allFields[$f['name']]['type'];
                     if ($type != 'hidden') {
                         $out[] = "<th>{$f['prettyname']}</th>";
                     }
                 }
                 $out[] = '</tr>';
                 $out[] = '</thead>';
             }
             $line = 0;
             $out[] = '<tbody>';
             while ($row = $rs->next()) {
                 $out[] = "<input type=\"hidden\" name=\"{$formid}_id_{$line}\" value=\"{$row['id']}\" />";
                 $out[] = "<input type=\"hidden\" name=\"{$formid}_{$line}_dirty\" value=\"0\" />";
                 $out[] = '<tr>';
                 $firstfield = true;
                 foreach ($fields as $f) {
                     list($hidden, $str) = self::displayField($formid, $f, $allFields, $line, $row);
                     if (!$hidden) {
                         $out[] = '<td>';
                     }
                     if ($firstfield && !$hidden) {
                         if ($rowanchor) {
                             $out[] = "<a name=\"id{$row['id']}\"></a>";
                         }
                         $firstfield = false;
                     }
                     $out[] = $str;
                     if (!$hidden) {
                         $out[] = '</td>';
                     }
                 }
                 if ($deleteable) {
                     if (!$safedelete) {
                         $out[] = "<td><input class=\"btn btn-default\" type=\"button\" onClick=\"location='" . $action . "&formid={$formid}&delete={$row['id']}'\" value=\"Delete\" /></td>";
                     } else {
                         $out[] = "<td><input class=\"btn btn-default\" type=\"button\" onClick=\"ConfirmBox.display('Are you sure you want to delete this?','" . $action . "&formid={$formid}&delete={$row['id']}')\" value=\"Delete\" /></td>";
                     }
                 }
                 foreach ($links as $link) {
                     $url = str_replace('%id', $row['id'], $link['url']);
                     if (Functions::nz($link['fancybox'], false)) {
                         $onclick = "\$.fancybox({href:'{$url}'})";
                     } else {
                         $onclick = "location='{$url}'";
                     }
                     $out[] = "<td><input class=\"btn btn-default\" type=\"button\" onClick=\"{$onclick}\" value=\"{$link['label']}\" /></td>";
                 }
                 $out[] = '</tr>';
                 if ($subform) {
                     $dict = array('pre' => $formid, 'id' => $row['id']);
                     $subformdict = $subform;
                     foreach ($subformdict['fields'] as $k => $f) {
                         if (isset($f['default'])) {
                             $subformdict['fields'][$k]['default'] = str_replace('%id', $row['id'], $f['default']);
                         }
                     }
                     $out[] = '<tr><td></td><td colspan="' . ($cols - 1) . '">' . self::display($subformdict, $dict) . '</td></tr>';
                 }
                 ++$line;
             }
             if ($addline) {
                 $out[] = "<tr><td colspan=\"{$cols}\"><input type=\"hidden\" name=\"{$formid}_id_new\" value=\"0\" /><input class=\"btn btn-default\" type=\"button\" value=\"{$addlabel}\" onclick=\"Form.addnew('{$formid}',this)\" /></td></tr>";
                 $out[] = "<tr style=\"display: none\" id=\"{$formid}_addnew\">";
                 foreach ($fields as $f) {
                     list($hidden, $str) = self::displayField($formid, $f, $allFields);
                     if (!$hidden) {
                         $out[] = '<td>';
                     }
                     $out[] = $str;
                     if (!$hidden) {
                         $out[] = '</td>';
                     }
                 }
                 $out[] = '</tr>';
             }
             $out[] = '</tbody>';
             $out[] = '</table>';
         } else {
             $row = $rs->next();
             if ($row) {
                 $out[] = "<input type=\"hidden\" name=\"{$formid}_id_0\" value=\"{$row['id']}\" />";
                 $out[] = "<input type=\"hidden\" name=\"{$formid}_0_dirty\" value=\"0\" />";
             } else {
                 $out[] = "<input type=\"hidden\" name=\"{$formid}_id_new\" value=\"1\" />";
             }
             $out[] = '<table>';
             foreach ($fields as $f) {
                 if ($row) {
                     list($hidden, $str) = self::displayField($formid, $f, $allFields, 0, $row);
                 } else {
                     list($hidden, $str) = self::displayField($formid, $f, $allFields);
                 }
                 if (!$hidden) {
                     $out[] = "<tr><td>{$f['prettyname']}</td><td>";
                 }
                 $out[] = $str;
                 if (!$hidden) {
                     $out[] = '</td></tr>';
                 }
             }
             $out[] = '</table>';
         }
         if (!$subforminfo) {
             $out[] = "<input class=\"btn btn-default\" type=\"submit\" name=\"{$formid}_submit\" value=\"{$submitlabel}\" />";
             $out[] = '</form>';
         }
     }
     return implode("\n", $out);
 }
Пример #6
0
 private function solveEqualOperator($v, $f, $scope)
 {
     if ($v instanceof BaseModel) {
         $value = $v->id;
         $f = sprintf('%s_id', $f);
     } else {
         $value = sprintf("'%s'", DB::escape($v));
     }
     return "{$scope}.`{$f}` = {$value}";
 }
Пример #7
0
 private static function findChildrenSub($id, &$ar, $table)
 {
     $delomraade_id = 'delomraade_id';
     $rs = DB::fetch("SELECT * FROM {$table} WHERE omraade_id={$id}");
     while ($row = $rs->next()) {
         if (!in_array($row[$delomraade_id], $ar)) {
             $ar[] = $row[$delomraade_id];
             self::findChildrenSub($row[$delomraade_id], $ar, $table);
         }
     }
 }