This commit is contained in:
Ibnu Maksum 2021-11-08 19:56:30 +07:00
parent a2bd40f443
commit 5682aeb0b1
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 237 additions and 233 deletions

View File

@ -1,34 +1,39 @@
<?php <?php
/** /**
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/) * PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing * @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
**/ **/
Class Password{ class Password
{
public static function _crypt($password) { public static function _crypt($password)
return crypt($password); {
return sha1($password);
} }
public static function _verify($user_input, $hashed_password){ public static function _verify($user_input, $hashed_password)
if (crypt($user_input, $hashed_password) == $hashed_password) { {
if (sha1($user_input) == $hashed_password) {
return true; return true;
} }
return false; return false;
} }
public static function _uverify($user_input, $hashed_password){ public static function _uverify($user_input, $hashed_password)
{
if ($user_input == $hashed_password) { if ($user_input == $hashed_password) {
return true; return true;
} }
return false; return false;
} }
public static function _gen(){ public static function _gen()
{
$pass = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#!123456789', 8)), 0, 8); $pass = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#!123456789', 8)), 0, 8);
return $pass; return $pass;
} }
}
}

View File

@ -1,14 +1,15 @@
<?php <?php
/** /**
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/) * PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing * @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
**/ **/
_admin(); _admin();
$ui->assign('_title', $_L['Settings'].'- '. $config['CompanyName']); $ui->assign('_title', $_L['Settings'] . '- ' . $config['CompanyName']);
$ui->assign('_system_menu', 'settings'); $ui->assign('_system_menu', 'settings');
$action = $routes['1']; $action = $routes['1'];
@ -17,84 +18,84 @@ $ui->assign('_admin', $admin);
switch ($action) { switch ($action) {
case 'app': case 'app':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$ui->display('app-settings.tpl'); $ui->display('app-settings.tpl');
break; break;
case 'localisation': case 'localisation':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$lan = ORM::for_table('tbl_language')->find_many(); $lan = ORM::for_table('tbl_language')->find_many();
$ui->assign('lan',$lan); $ui->assign('lan', $lan);
$timezonelist = Timezone::timezoneList(); $timezonelist = Timezone::timezoneList();
$ui->assign('tlist',$timezonelist); $ui->assign('tlist', $timezonelist);
$ui->assign('xjq', ' $("#tzone").select2(); '); $ui->assign('xjq', ' $("#tzone").select2(); ');
$ui->display('app-localisation.tpl'); $ui->display('app-localisation.tpl');
break; break;
case 'users': case 'users':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/users.js"></script>'); $ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/users.js"></script>');
$username = _post('username'); $username = _post('username');
if ($username != ''){ if ($username != '') {
$paginator = Paginator::bootstrap('tbl_users','username','%'.$username.'%'); $paginator = Paginator::bootstrap('tbl_users', 'username', '%' . $username . '%');
$d = ORM::for_table('tbl_users')->where_like('username','%'.$username.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); $d = ORM::for_table('tbl_users')->where_like('username', '%' . $username . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many();
}else{ } else {
$paginator = Paginator::bootstrap('tbl_users'); $paginator = Paginator::bootstrap('tbl_users');
$d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); $d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many();
} }
$ui->assign('d',$d); $ui->assign('d', $d);
$ui->assign('paginator',$paginator); $ui->assign('paginator', $paginator);
$ui->display('users.tpl'); $ui->display('users.tpl');
break; break;
case 'users-add': case 'users-add':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$ui->display('users-add.tpl'); $ui->display('users-add.tpl');
break; break;
case 'users-edit': case 'users-edit':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$id = $routes['2']; $id = $routes['2'];
$d = ORM::for_table('tbl_users')->find_one($id); $d = ORM::for_table('tbl_users')->find_one($id);
if($d){ if ($d) {
$ui->assign('d',$d); $ui->assign('d', $d);
$ui->display('users-edit.tpl'); $ui->display('users-edit.tpl');
}else{ } else {
r2(U . 'settings/users', 'e', $_L['Account_Not_Found']); r2(U . 'settings/users', 'e', $_L['Account_Not_Found']);
} }
break; break;
case 'users-delete': case 'users-delete':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$id = $routes['2']; $id = $routes['2'];
if(($admin['id']) == $id){ if (($admin['id']) == $id) {
r2(U . 'settings/users', 'e', 'Sorry You can\'t delete yourself'); r2(U . 'settings/users', 'e', 'Sorry You can\'t delete yourself');
} }
$d = ORM::for_table('tbl_users')->find_one($id); $d = ORM::for_table('tbl_users')->find_one($id);
if($d){ if ($d) {
$d->delete(); $d->delete();
r2(U . 'settings/users', 's', $_L['User_Delete_Ok']); r2(U . 'settings/users', 's', $_L['User_Delete_Ok']);
}else{ } else {
r2(U . 'settings/users', 'e', $_L['Account_Not_Found']); r2(U . 'settings/users', 'e', $_L['Account_Not_Found']);
} }
break; break;
@ -106,39 +107,39 @@ switch ($action) {
$cpassword = _post('cpassword'); $cpassword = _post('cpassword');
$user_type = _post('user_type'); $user_type = _post('user_type');
$msg = ''; $msg = '';
if(Validator::Length($username,16,2) == false){ if (Validator::Length($username, 16, 2) == false) {
$msg .= 'Username should be between 3 to 15 characters'. '<br>'; $msg .= 'Username should be between 3 to 15 characters' . '<br>';
} }
if(Validator::Length($fullname,26,2) == false){ if (Validator::Length($fullname, 26, 2) == false) {
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>'; $msg .= 'Full Name should be between 3 to 25 characters' . '<br>';
} }
if(!Validator::Length($password,15,5)){ if (!Validator::Length($password, 15, 5)) {
$msg .= 'Password should be between 6 to 15 characters'. '<br>'; $msg .= 'Password should be between 6 to 15 characters' . '<br>';
} }
if($password != $cpassword){ if ($password != $cpassword) {
$msg .= 'Passwords does not match'. '<br>'; $msg .= 'Passwords does not match' . '<br>';
} }
$d = ORM::for_table('tbl_users')->where('username',$username)->find_one(); $d = ORM::for_table('tbl_users')->where('username', $username)->find_one();
if($d){ if ($d) {
$msg .= $_L['account_already_exist']. '<br>'; $msg .= $_L['account_already_exist'] . '<br>';
} }
$date_now = date("Y-m-d H:i:s"); $date_now = date("Y-m-d H:i:s");
if($msg == ''){ if ($msg == '') {
$password = Password::_crypt($password); $password = Password::_crypt($password);
$d = ORM::for_table('tbl_users')->create(); $d = ORM::for_table('tbl_users')->create();
$d->username = $username; $d->username = $username;
$d->fullname = $fullname; $d->fullname = $fullname;
$d->password = $password; $d->password = $password;
$d->user_type = $user_type; $d->user_type = $user_type;
$d->status = 'Active'; $d->status = 'Active';
$d->creationdate = $date_now; $d->creationdate = $date_now;
$d->save(); $d->save();
_log('['.$admin['username'].']: '.$_L['account_created_successfully'],'Admin',$admin['id']); _log('[' . $admin['username'] . ']: ' . $_L['account_created_successfully'], 'Admin', $admin['id']);
r2(U . 'settings/users', 's', $_L['account_created_successfully']); r2(U . 'settings/users', 's', $_L['account_created_successfully']);
}else{ } else {
r2(U . 'settings/users-add', 'e', $msg); r2(U . 'settings/users-add', 'e', $msg);
} }
break; break;
@ -150,54 +151,54 @@ switch ($action) {
$cpassword = _post('cpassword'); $cpassword = _post('cpassword');
$msg = ''; $msg = '';
if(Validator::Length($username,16,2) == false){ if (Validator::Length($username, 16, 2) == false) {
$msg .= 'Username should be between 3 to 15 characters'. '<br>'; $msg .= 'Username should be between 3 to 15 characters' . '<br>';
} }
if(Validator::Length($fullname,26,2) == false){ if (Validator::Length($fullname, 26, 2) == false) {
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>'; $msg .= 'Full Name should be between 3 to 25 characters' . '<br>';
} }
if($password != ''){ if ($password != '') {
if(!Validator::Length($password,15,5)){ if (!Validator::Length($password, 15, 5)) {
$msg .= 'Password should be between 6 to 15 characters'. '<br>'; $msg .= 'Password should be between 6 to 15 characters' . '<br>';
} }
if($password != $cpassword){ if ($password != $cpassword) {
$msg .= 'Passwords does not match'. '<br>'; $msg .= 'Passwords does not match' . '<br>';
} }
} }
$id = _post('id'); $id = _post('id');
$d = ORM::for_table('tbl_users')->find_one($id); $d = ORM::for_table('tbl_users')->find_one($id);
if($d){ if ($d) {
}else{ } else {
$msg .= $_L['Data_Not_Found']. '<br>'; $msg .= $_L['Data_Not_Found'] . '<br>';
} }
if($d['username'] != $username){ if ($d['username'] != $username) {
$c = ORM::for_table('tbl_users')->where('username',$username)->find_one(); $c = ORM::for_table('tbl_users')->where('username', $username)->find_one();
if($c){ if ($c) {
$msg .= $_L['account_already_exist']. '<br>'; $msg .= $_L['account_already_exist'] . '<br>';
} }
} }
if($msg == ''){ if ($msg == '') {
$d->username = $username; $d->username = $username;
if($password != ''){ if ($password != '') {
$password = Password::_crypt($password); $password = Password::_crypt($password);
$d->password = $password; $d->password = $password;
} }
$d->fullname = $fullname; $d->fullname = $fullname;
if(($admin['id']) != $id){ if (($admin['id']) != $id) {
$user_type = _post('user_type'); $user_type = _post('user_type');
$d->user_type = $user_type; $d->user_type = $user_type;
} }
$d->save(); $d->save();
_log('['.$admin['username'].']: '.$_L['User_Updated_Successfully'],'Admin',$admin['id']); _log('[' . $admin['username'] . ']: ' . $_L['User_Updated_Successfully'], 'Admin', $admin['id']);
r2(U . 'settings/users', 's', 'User Updated Successfully'); r2(U . 'settings/users', 's', 'User Updated Successfully');
}else{ } else {
r2(U . 'settings/users-edit/'.$id, 'e', $msg); r2(U . 'settings/users-edit/' . $id, 'e', $msg);
} }
break; break;
@ -205,156 +206,156 @@ switch ($action) {
$company = _post('company'); $company = _post('company');
$theme = _post('theme'); $theme = _post('theme');
$address = _post('address'); $address = _post('address');
if($company == '' OR $theme == '' OR $address == ''){ if ($company == '' or $theme == '' or $address == '') {
r2(U.'settings/app','e',$_L['All_field_is_required']); r2(U . 'settings/app', 'e', $_L['All_field_is_required']);
}else{ } else {
$d = ORM::for_table('tbl_appconfig')->where('setting','CompanyName')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'CompanyName')->find_one();
$d->value = $company; $d->value = $company;
$d->save(); $d->save();
$d = ORM::for_table('tbl_appconfig')->where('setting','address')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'address')->find_one();
$d->value = $address; $d->value = $address;
$d->save(); $d->save();
$phone = _post('phone'); $phone = _post('phone');
$d = ORM::for_table('tbl_appconfig')->where('setting','phone')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'phone')->find_one();
$d->value = $phone; $d->value = $phone;
$d->save(); $d->save();
$d = ORM::for_table('tbl_appconfig')->where('setting','theme')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'theme')->find_one();
$d->value = $theme; $d->value = $theme;
$d->save(); $d->save();
$note = _post('note'); $note = _post('note');
$d = ORM::for_table('tbl_appconfig')->where('setting','note')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'note')->find_one();
$d->value = $note; $d->value = $note;
$d->save(); $d->save();
_log('['.$admin['username'].']: '.$_L['Settings_Saved_Successfully'],'Admin',$admin['id']); _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']);
r2(U.'settings/app','s',$_L['Settings_Saved_Successfully']); r2(U . 'settings/app', 's', $_L['Settings_Saved_Successfully']);
} }
break; break;
case 'localisation-post': case 'localisation-post':
$tzone = _post('tzone'); $tzone = _post('tzone');
$date_format = _post('date_format'); $date_format = _post('date_format');
$lan = _post('lan'); $lan = _post('lan');
if($tzone == '' OR $date_format == '' OR $lan == ''){ if ($tzone == '' or $date_format == '' or $lan == '') {
r2(U.'settings/app','e',$_L['All_field_is_required']); r2(U . 'settings/app', 'e', $_L['All_field_is_required']);
}else{ } else {
$d = ORM::for_table('tbl_appconfig')->where('setting','timezone')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'timezone')->find_one();
$d->value = $tzone; $d->value = $tzone;
$d->save(); $d->save();
$d = ORM::for_table('tbl_appconfig')->where('setting','date_format')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'date_format')->find_one();
$d->value = $date_format; $d->value = $date_format;
$d->save(); $d->save();
$dec_point = $_POST['dec_point']; $dec_point = $_POST['dec_point'];
if(strlen($dec_point) == '1'){ if (strlen($dec_point) == '1') {
$d = ORM::for_table('tbl_appconfig')->where('setting','dec_point')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'dec_point')->find_one();
$d->value = $dec_point; $d->value = $dec_point;
$d->save(); $d->save();
} }
$thousands_sep = $_POST['thousands_sep']; $thousands_sep = $_POST['thousands_sep'];
if(strlen($thousands_sep) == '1'){ if (strlen($thousands_sep) == '1') {
$d = ORM::for_table('tbl_appconfig')->where('setting','thousands_sep')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'thousands_sep')->find_one();
$d->value = $thousands_sep; $d->value = $thousands_sep;
$d->save(); $d->save();
} }
$currency_code = $_POST['currency_code']; $currency_code = $_POST['currency_code'];
$d = ORM::for_table('tbl_appconfig')->where('setting','currency_code')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'currency_code')->find_one();
$d->value = $currency_code; $d->value = $currency_code;
$d->save(); $d->save();
$d = ORM::for_table('tbl_appconfig')->where('setting','language')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'language')->find_one();
$d->value = $lan; $d->value = $lan;
$d->save(); $d->save();
_log('['.$admin['username'].']: '.$_L['Settings_Saved_Successfully'],'Admin',$admin['id']); _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']);
r2(U.'settings/localisation','s',$_L['Settings_Saved_Successfully']); r2(U . 'settings/localisation', 's', $_L['Settings_Saved_Successfully']);
} }
break; break;
case 'change-password': case 'change-password':
if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){ if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$ui->display('change-password.tpl'); $ui->display('change-password.tpl');
break; break;
case 'change-password-post': case 'change-password-post':
$password = _post('password'); $password = _post('password');
if($password != ''){ if ($password != '') {
$d = ORM::for_table('tbl_users')->where('username',$admin['username'])->find_one(); $d = ORM::for_table('tbl_users')->where('username', $admin['username'])->find_one();
if($d){ if ($d) {
$d_pass = $d['password']; $d_pass = $d['password'];
if(Password::_verify($password,$d_pass) == true){ if (Password::_verify($password, $d_pass) == true) {
$npass = _post('npass'); $npass = _post('npass');
$cnpass = _post('cnpass'); $cnpass = _post('cnpass');
if(!Validator::Length($npass,15,5)){ if (!Validator::Length($npass, 15, 5)) {
r2(U.'settings/change-password','e','New Password must be 6 to 14 character'); r2(U . 'settings/change-password', 'e', 'New Password must be 6 to 14 character');
} }
if($npass != $cnpass){ if ($npass != $cnpass) {
r2(U.'settings/change-password','e','Both Password should be same'); r2(U . 'settings/change-password', 'e', 'Both Password should be same');
} }
$npass = Password::_crypt($npass); $npass = Password::_crypt($npass);
$d->password = $npass; $d->password = $npass;
$d->save(); $d->save();
_msglog('s',$_L['Password_Changed_Successfully']); _msglog('s', $_L['Password_Changed_Successfully']);
_log('['.$admin['username'].']: Password changed successfully','Admin',$admin['id']); _log('[' . $admin['username'] . ']: Password changed successfully', 'Admin', $admin['id']);
r2(U.'admin'); r2(U . 'admin');
}else{ } else {
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']); r2(U . 'settings/change-password', 'e', $_L['Incorrect_Current_Password']);
} }
}else{ } else {
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']); r2(U . 'settings/change-password', 'e', $_L['Incorrect_Current_Password']);
} }
}else{ } else {
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']); r2(U . 'settings/change-password', 'e', $_L['Incorrect_Current_Password']);
} }
break; break;
case 'dbstatus': case 'dbstatus':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$dbc = new mysqli($db_host,$db_user ,$db_password,$db_name); $dbc = new mysqli($db_host, $db_user, $db_password, $db_name);
if ($result = $dbc->query('SHOW TABLE STATUS')) { if ($result = $dbc->query('SHOW TABLE STATUS')) {
$size = 0; $size = 0;
$decimals = 2; $decimals = 2;
$tables = array(); $tables = array();
while($row = $result->fetch_array()){ while ($row = $result->fetch_array()) {
$size += $row["Data_length"] + $row["Index_length"]; $size += $row["Data_length"] + $row["Index_length"];
$total_size = ($row[ "Data_length" ] + $row[ "Index_length" ]) / 1024; $total_size = ($row["Data_length"] + $row["Index_length"]) / 1024;
$tables[$row['Name']]['size'] = number_format($total_size,'0'); $tables[$row['Name']]['size'] = number_format($total_size, '0');
$tables[$row['Name']]['rows'] = $row[ "Rows" ]; $tables[$row['Name']]['rows'] = $row["Rows"];
$tables[$row['Name']]['name'] = $row[ "Name" ]; $tables[$row['Name']]['name'] = $row["Name"];
} }
$mbytes = number_format($size/(1024*1024),$decimals,$config['dec_point'],$config['thousands_sep']); $mbytes = number_format($size / (1024 * 1024), $decimals, $config['dec_point'], $config['thousands_sep']);
$ui->assign('tables',$tables); $ui->assign('tables', $tables);
$ui->assign('dbsize',$mbytes); $ui->assign('dbsize', $mbytes);
$ui->display('dbstatus.tpl'); $ui->display('dbstatus.tpl');
} }
break; break;
case 'dbbackup': case 'dbbackup':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
try { try {
$mysqli = new mysqli($db_host,$db_user ,$db_password,$db_name); $mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
throw new Exception("Failed to connect to MySQL: " . $mysqli->connect_error); throw new Exception("Failed to connect to MySQL: " . $mysqli->connect_error);
} }
@ -365,50 +366,49 @@ switch ($action) {
header('Content-Type: application/force-download'); header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header('Content-Type: application/download'); header('Content-Type: application/download');
header('Content-Disposition: attachment;filename="backup_'.date('Y-m-d_h_i_s') . '.sql"'); header('Content-Disposition: attachment;filename="backup_' . date('Y-m-d_h_i_s') . '.sql"');
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
ob_start(); ob_start();
$f_output = fopen("php://output", 'w'); $f_output = fopen("php://output", 'w');
print("-- pjl SQL Dump\n"); print("-- pjl SQL Dump\n");
print("-- Server version:".$mysqli->server_info."\n"); print("-- Server version:" . $mysqli->server_info . "\n");
print("-- Generated: ".date('Y-m-d h:i:s')."\n"); print("-- Generated: " . date('Y-m-d h:i:s') . "\n");
print('-- Current PHP version: '.phpversion()."\n"); print('-- Current PHP version: ' . phpversion() . "\n");
print('-- Host: '.$db_host."\n"); print('-- Host: ' . $db_host . "\n");
print('-- Database:'.$db_name."\n"); print('-- Database:' . $db_name . "\n");
$aTables = array(); $aTables = array();
$strSQL = 'SHOW TABLES'; $strSQL = 'SHOW TABLES';
if (!$res_tables = $mysqli->query($strSQL)) if (!$res_tables = $mysqli->query($strSQL))
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL); throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
while($row = $res_tables->fetch_array()) { while ($row = $res_tables->fetch_array()) {
$aTables[] = $row[0]; $aTables[] = $row[0];
} }
$res_tables->free(); $res_tables->free();
foreach($aTables as $table) foreach ($aTables as $table) {
{
print("-- --------------------------------------------------------\n"); print("-- --------------------------------------------------------\n");
print("-- Structure for '". $table."'\n"); print("-- Structure for '" . $table . "'\n");
print("--\n\n"); print("--\n\n");
$strSQL = 'SHOW CREATE TABLE '.$table; $strSQL = 'SHOW CREATE TABLE ' . $table;
if (!$res_create = $mysqli->query($strSQL)) if (!$res_create = $mysqli->query($strSQL))
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL); throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
$row_create = $res_create->fetch_assoc(); $row_create = $res_create->fetch_assoc();
print("\n".$row_create['Create Table'].";\n"); print("\n" . $row_create['Create Table'] . ";\n");
print("-- --------------------------------------------------------\n"); print("-- --------------------------------------------------------\n");
print('-- Dump Data for `'. $table."`\n"); print('-- Dump Data for `' . $table . "`\n");
print("--\n\n"); print("--\n\n");
$res_create->free(); $res_create->free();
$strSQL = 'SELECT * FROM '.$table; $strSQL = 'SELECT * FROM ' . $table;
if (!$res_select = $mysqli->query($strSQL)) if (!$res_select = $mysqli->query($strSQL))
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL); throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
$fields_info = $res_select->fetch_fields(); $fields_info = $res_select->fetch_fields();
@ -417,18 +417,17 @@ switch ($action) {
$strValues = ''; $strValues = '';
foreach ($fields_info as $field) { foreach ($fields_info as $field) {
if ($strFields != '') $strFields .= ','; if ($strFields != '') $strFields .= ',';
$strFields .= "`".$field->name."`"; $strFields .= "`" . $field->name . "`";
if ($strValues != '') $strValues .= ','; if ($strValues != '') $strValues .= ',';
$strValues .= '"'.preg_replace('/[^(\x20-\x7F)\x0A]*/','',$values[$field->name].'"'); $strValues .= '"' . preg_replace('/[^(\x20-\x7F)\x0A]*/', '', $values[$field->name] . '"');
} }
print("INSERT INTO ".$table." (".$strFields.") VALUES (".$strValues.");\n"); print("INSERT INTO " . $table . " (" . $strFields . ") VALUES (" . $strValues . ");\n");
} }
print("\n\n\n"); print("\n\n\n");
$res_select->free(); $res_select->free();
} }
_log('['.$admin['username'].']: '.$_L['Download_Database_Backup'],'Admin',$admin['id']); _log('[' . $admin['username'] . ']: ' . $_L['Download_Database_Backup'], 'Admin', $admin['id']);
} catch (Exception $e) { } catch (Exception $e) {
print($e->getMessage()); print($e->getMessage());
} }
@ -438,41 +437,41 @@ switch ($action) {
$mysqli->close(); $mysqli->close();
break; break;
case 'language': case 'language':
if($admin['user_type'] != 'Admin'){ if ($admin['user_type'] != 'Admin') {
r2(U."dashboard",'e',$_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
$ui->display('language-add.tpl'); $ui->display('language-add.tpl');
break; break;
case 'lang-post': case 'lang-post':
$name = _post('name'); $name = _post('name');
$folder = _post('folder'); $folder = _post('folder');
$translator = _post('translator'); $translator = _post('translator');
if ($name == '' OR $folder == ''){ if ($name == '' or $folder == '') {
$msg .= $_L['All_field_is_required']. '<br>'; $msg .= $_L['All_field_is_required'] . '<br>';
}
$d = ORM::for_table('tbl_language')->where('name',$name)->find_one();
if($d){
$msg .= $_L['Lang_already_exist']. '<br>';
} }
if($msg == ''){
$b = ORM::for_table('tbl_language')->create(); $d = ORM::for_table('tbl_language')->where('name', $name)->find_one();
if ($d) {
$msg .= $_L['Lang_already_exist'] . '<br>';
}
if ($msg == '') {
$b = ORM::for_table('tbl_language')->create();
$b->name = $name; $b->name = $name;
$b->folder = $folder; $b->folder = $folder;
$b->author = $translator; $b->author = $translator;
$b->save(); $b->save();
r2(U . 'settings/localisation', 's', $_L['Created_Successfully']); r2(U . 'settings/localisation', 's', $_L['Created_Successfully']);
}else{ } else {
r2(U . 'settings/language', 'e', $msg); r2(U . 'settings/language', 'e', $msg);
} }
break; break;
default: default:
echo 'action not defined'; echo 'action not defined';
} }