From 03b0cdd5869b962375cb32dd6abbda2146900766 Mon Sep 17 00:00:00 2001 From: pihel Date: Wed, 13 Aug 2014 22:51:49 +0400 Subject: [PATCH] #6 Prepare for DB update --- lang/en.php | 6 +++++- lang/ru.php | 6 +++++- lib/init.php | 22 ++++++++++++++-------- lib/settings.php | 6 +++++- lib/update.php | 15 ++++++++++++--- static/js/script.js | 8 ++++++++ static/js/update.js | 14 ++++++++++++++ 7 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 static/js/update.js diff --git a/lang/en.php b/lang/en.php index 1550561..2395f3e 100644 --- a/lang/en.php +++ b/lang/en.php @@ -236,7 +236,11 @@ class LangEn extends iLang { 215 => "Install", 216 => "Installs and configures. Please wait ...", 217 => "Installation was successful", - 218 => "Installation failed, contact support https://github.com/pihel/cash/issues" + 218 => "Installation failed, contact support https://github.com/pihel/cash/issues", + //update + 219 => "Updating ...", + 220 => "Manually change the version is forbidden", + 221 => "The version of the database" ); } diff --git a/lang/ru.php b/lang/ru.php index b1e0355..4bd3478 100644 --- a/lang/ru.php +++ b/lang/ru.php @@ -238,7 +238,11 @@ class LangRu extends iLang { 215 => "Установить", 216 => "Выполняется установка и настройка. Пожалуйста подождите...", 217 => "Установка прошла успешно", - 218 => "Установка завершилась с ошибкой, обратитесь в поддержку https://github.com/pihel/cash/issues" + 218 => "Установка завершилась с ошибкой, обратитесь в поддержку https://github.com/pihel/cash/issues", + //update + 219 => "Обновление...", + 220 => "Ручное изменение версии запрещено", + 221 => "Версия БД" ); } diff --git a/lib/init.php b/lib/init.php index 6e859ea..bf42d22 100755 --- a/lib/init.php +++ b/lib/init.php @@ -19,7 +19,7 @@ $extjs = 'extjs'; /* App version */ -$version = "1.030"; +$version = "1.031"; //$version = rand(); //for reset cache /* Path to imgs and js */ @@ -59,15 +59,21 @@ $ch = new Cash($db, $usr, $lng); $settings = array(); +$settings['version'] = $version; +$settings['demo'] = $demo; +$settings['debug'] = $debug; +$settings['static'] = $static; +$settings['extjs'] = $extjs; + +//setup or update +$settings['setup'] = 0; +$settings['update'] = 0; if( $upd->needSetup() ) { $settings['setup'] = 1; $settings['site_name'] = $lng->get(213); +} elseif( $upd->needUpdate() ) { + $settings['update'] = 1; + $settings['site_name'] = $lng->get(219); } else { - $settings = $ch->getSettings(); - $settings['setup'] = 0; + $settings = array_merge($settings, $ch->getSettings() ); } -$settings['version'] = $version; -$settings['demo'] = $demo; -$settings['debug'] = $debug; -$settings['static'] = $static; -$settings['extjs'] = $extjs; \ No newline at end of file diff --git a/lib/settings.php b/lib/settings.php index 2dc4a2b..415414d 100755 --- a/lib/settings.php +++ b/lib/settings.php @@ -128,7 +128,11 @@ public function setSetting($refb, $indx, $data) { $col = "id"; if($refb == "cashes_setting") { $col = "name"; - } + + if( in_array('version', $data) ) { + return $this->lng->get(220); + } //in_array + } //refb $set = ""; unset($data[$col]);//unset ID col diff --git a/lib/update.php b/lib/update.php index f624014..114c112 100644 --- a/lib/update.php +++ b/lib/update.php @@ -47,8 +47,10 @@ public function createData($pasw) { $this->db->exec("INSERT INTO cashes_type(name) VALUES(?)", $this->lng->get(205)); $this->db->exec("INSERT INTO cashes_type(name) VALUES(?)", $this->lng->get(206)); + global $settings; $this->db->exec("INSERT INTO cashes_setting(name, descr, value) VALUES(?, ?, ?)", "site_name", $this->lng->get(207), $this->lng->get(208)); - $this->db->exec("INSERT INTO cashes_setting(name, descr, value) VALUES(?, ?, ?)", "mail", $this->lng->get(209), ""); + $this->db->exec("INSERT INTO cashes_setting(name, descr, value) VALUES(?, ?, ?)", "mail", $this->lng->get(209), ""); + $this->db->exec("INSERT INTO cashes_setting(name, descr, value) VALUES(?, ?, ?)", "version", $this->lng->get(221), $settings['version'] ); $this->db->exec("INSERT INTO cashes_group(name) VALUES(?)", $this->lng->get(210)); $this->db->exec("INSERT INTO cashes_group(name) VALUES(?)", $this->lng->get(211)); @@ -76,6 +78,10 @@ public function clean() { $this->db->commit(); } //clean + public function difChange() { + // + } //difChange + } //DbUpdate @@ -102,8 +108,11 @@ public function needSetup() { } //needSetup public function needUpdate() { - global $version;//хранить гдето версию бд?? - return false; + global $settings; + $file_ver = doubleval( $settings['version'] ); + $db_ver = doubleval( $this->db->element("SELECT value FROM cashes_setting WHERE name = 'version'") ); + + return ( $file_ver > $db_ver && false ); //TODO } //needUpdate diff --git a/static/js/script.js b/static/js/script.js index 4795e29..460d48f 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -307,6 +307,12 @@ function setup() { }); } +function update() { + loadScript(settings.static + "/js/update.js", function() { + updateWindow.show(); + }); +} + function logout() { Ext.Ajax.request({ url: "ajax/logout.php", @@ -329,6 +335,8 @@ Ext.onReady(function(){ if(settings.setup == 1) { setup(); + } else if(settings.update == 1) { + update(); } else { checkAuth(); } diff --git a/static/js/update.js b/static/js/update.js new file mode 100644 index 0000000..0f12cee --- /dev/null +++ b/static/js/update.js @@ -0,0 +1,14 @@ +var updateWindow = new Ext.Window({ + frame:true, + border: false, + title: lang(219), + width: 400, + closable: false, + resizable: false, + items: [], + listeners: { + show: function(){ + // + } + } +}); \ No newline at end of file