Config.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. class Route_Config extends RouteBase {
  4. public function handleAuth() {
  5. if (!User::logged()) {
  6. throw new HttpException('Unauthorized', 401);
  7. }
  8. }
  9. public function defaultAction() {
  10. SE_Layout::gora();
  11. ?>
  12. <div class="container">
  13. <h1>Config</h1>
  14. ...
  15. </div>
  16. <?php
  17. SE_Layout::dol();
  18. }
  19. public function reinstallAction() {
  20. $this->reinstall();
  21. die('OK');
  22. }
  23. public function runAction() {
  24. $msgId = V::get('_msgId', 0, $_REQUEST, 'int');
  25. if ($msgId > 0) {
  26. $this->runByMessageId($msgId);
  27. }
  28. $jsonData = new stdClass();
  29. $jsonData->type = 'success';
  30. $jsonData->msg = 'Gotowe';
  31. echo json_encode($jsonData);
  32. exit;
  33. }
  34. public function reinstall() {
  35. $sqlList = array();
  36. //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_CONFIG`";
  37. $sqlList['InstallTable'] = <<<SQL
  38. CREATE TABLE IF NOT EXISTS `CRM_CONFIG` (
  39. `ID` int(11) NOT NULL AUTO_INCREMENT,
  40. `CONF_KEY` varchar(64) NOT NULL,
  41. `CONF_VAL` text NOT NULL,
  42. PRIMARY KEY (`ID`),
  43. UNIQUE KEY `CONF_KEY` (`CONF_KEY`)
  44. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  45. SQL;
  46. $db = DB::getDB();
  47. if ($db->has_errors()) {
  48. throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
  49. }
  50. foreach ($sqlList as $sqlName => $sql) {
  51. $res = $db->query($sql);
  52. if ($db->has_errors()) {
  53. throw new Exception("DB Errors at sql '{$sqlName}': " . implode("\n<br>", $db->get_errors()));
  54. }
  55. }
  56. }
  57. }