From f85f4523ca19d71e9f6f4eb2abafb0c20234d572 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Mon, 26 Feb 2018 09:39:50 +0100 Subject: [PATCH] Minor - format code --- plugin/vchamilo/ajax/service.php | 23 ++- .../vchamilo/views/syncparams.controller.php | 169 +++++++++--------- plugin/vchamilo/views/syncparams.php | 16 +- 3 files changed, 109 insertions(+), 99 deletions(-) diff --git a/plugin/vchamilo/ajax/service.php b/plugin/vchamilo/ajax/service.php index abdf052865..3e06c298b2 100644 --- a/plugin/vchamilo/ajax/service.php +++ b/plugin/vchamilo/ajax/service.php @@ -1,20 +1,25 @@ Success'; - } else { - echo 'Failure
'.$errors.'
'; - } +switch ($action) { + case 'syncthis': + $res = include_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'; + if (!$res) { + echo 'Success'; + } else { + echo 'Failure
'.$errors.'
'; + } + break; } + +exit; diff --git a/plugin/vchamilo/views/syncparams.controller.php b/plugin/vchamilo/views/syncparams.controller.php index 5d83a3b563..44bc842625 100644 --- a/plugin/vchamilo/views/syncparams.controller.php +++ b/plugin/vchamilo/views/syncparams.controller.php @@ -8,115 +8,120 @@ $result = Database::query($sql); $vchamilos = Database::store_result($result, 'ASSOC'); // propagate in all known vchamilos a setting -if ($action == 'syncall') { - exit; - $keys = array_keys($_REQUEST); - $selection = preg_grep('/sel_.*/', $keys); +switch ($action) { + case 'syncall': + exit; + $keys = array_keys($_REQUEST); + $selection = preg_grep('/sel_.*/', $keys); - foreach ($selection as $selkey) { - $settingId = str_replace('sel_', '', $selkey); + foreach ($selection as $selkey) { + $settingId = str_replace('sel_', '', $selkey); - if (!is_numeric($settingId)) { - continue; - } + if (!is_numeric($settingId)) { + continue; + } - $value = $_REQUEST[$selkey]; + $value = $_REQUEST[$selkey]; - $setting = api_get_settings_params_simple(['id' => $settingId]); + $setting = api_get_settings_params_simple(['id' => $settingId]); - $params = [ - 'title' => $setting['title'], - 'variable' => $setting['variable'], - 'subkey' => $setting['subkey'], - 'category' => $setting['category'], - 'access_url' => $setting['access_url'], - ]; + $params = [ + 'title' => $setting['title'], + 'variable' => $setting['variable'], + 'subkey' => $setting['subkey'], + 'category' => $setting['category'], + 'access_url' => $setting['access_url'], + ]; - foreach ($vchamilos as $vcid => $chm) { - $table = $chm['main_database'].".settings_current "; - $sql = " SELECT * FROM $table + foreach ($vchamilos as $chm) { + $table = $chm['main_database'].".settings_current "; + $sql = " SELECT * FROM $table WHERE variable = '{{$setting['variable']}}' AND access_url = '{$setting['access_url']}' "; - $result = Database::query($sql); + $result = Database::query($sql); - if (Database::num_rows($result)) { - $sql = "UPDATE $table SET + if (Database::num_rows($result)) { + $sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId"; - Database::query($sql); + Database::query($sql); + } + //$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database); } - //$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database); } - } -} + break; + case 'syncthis': + $settingId = isset($_GET['settingid']) ? $_GET['settingid'] : ''; + + if (is_numeric($settingId)) { + $deleteIfEmpty = isset($_REQUEST['del']) ? $_REQUEST['del'] : ''; + $value = $_REQUEST['value']; + // Getting the local setting record. + $setting = api_get_settings_params_simple(['id' => $settingId]); + if (empty($setting)) { + return 0; + } -if ($action == 'syncthis') { - $settingId = isset($_GET['settingid']) ? $_GET['settingid'] : ''; - - if (is_numeric($settingId)) { - $delifempty = isset($_REQUEST['del']) ? $_REQUEST['del'] : ''; - $value = $_REQUEST['value']; - // Getting the local setting record. - $setting = api_get_settings_params_simple(['id' => $settingId]); - $params = [ - 'access_url_changeable' => $setting['access_url_changeable'], - 'title' => $setting['title'], - 'variable' => $setting['variable'], - 'subkey' => $setting['subkey'], - 'category' => $setting['category'], - 'type' => $setting['type'], - 'comment' => $setting['comment'], - 'access_url' => $setting['access_url'], - ]; - - $errors = ''; - foreach ($vchamilos as $vcid => $chm) { - $table = "settings_current"; - - $config = new \Doctrine\DBAL\Configuration(); - $connectionParams = [ - 'dbname' => $chm['main_database'], - 'user' => $chm['db_user'], - 'password' => $chm['db_password'], - 'host' => $chm['db_host'], - 'driver' => 'pdo_mysql', + $params = [ + 'access_url_changeable' => $setting['access_url_changeable'], + 'title' => $setting['title'], + 'variable' => $setting['variable'], + 'subkey' => $setting['subkey'], + 'category' => $setting['category'], + 'type' => $setting['type'], + 'comment' => $setting['comment'], + 'access_url' => $setting['access_url'], ]; - $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); - try { - if ($delifempty && empty($value)) { - $sql = "DELETE FROM $table + + $errors = ''; + foreach ($vchamilos as $instance) { + $table = 'settings_current'; + $config = new \Doctrine\DBAL\Configuration(); + $connectionParams = [ + 'dbname' => $instance['main_database'], + 'user' => $instance['db_user'], + 'password' => $instance['db_password'], + 'host' => $instance['db_host'], + 'driver' => 'pdo_mysql', + ]; + $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); + try { + if ($deleteIfEmpty && empty($value)) { + $sql = "DELETE FROM $table WHERE selected_value = '$value' AND variable = '{{$setting['variable']}}' AND access_url = '{$setting['access_url']}' - "; - $connection->executeQuery($sql); - $case = "delete"; - } else { - $sql = " SELECT * FROM $table - WHERE - variable = '".$setting['variable']."' AND - access_url = '{$setting['access_url']}' - "; - $result = $connection->fetchAll($sql); - - if (!empty($result)) { - $sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId"; + "; $connection->executeQuery($sql); + $case = 'delete'; } else { - $connection->insert($table, $params); + $sql = "SELECT * FROM $table + WHERE + variable = '".$setting['variable']."' AND + access_url = '{$setting['access_url']}' + "; + $result = $connection->fetchAll($sql); + + if (!empty($result)) { + $sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId"; + $connection->executeQuery($sql); + } else { + $connection->insert($table, $params); + } } + } catch (Exception $e) { + echo $e->getMessage(); } - } catch (Exception $e) { - echo $e->getMessage(); } + return $errors; + } else { + return "Bad ID. Non numeric"; } - return $errors; - } else { - return "Bad ID. Non numeric"; - } + + break; } return 0; diff --git a/plugin/vchamilo/views/syncparams.php b/plugin/vchamilo/views/syncparams.php index f70028b127..f6276762e7 100644 --- a/plugin/vchamilo/views/syncparams.php +++ b/plugin/vchamilo/views/syncparams.php @@ -10,7 +10,7 @@ $action = isset($_GET['what']) ? $_GET['what'] : ''; define('CHAMILO_INTERNAL', true); $plugin = VChamiloPlugin::create(); -$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; +$thisUrl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; if ($action) { require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'); @@ -18,7 +18,7 @@ if ($action) { $settings = api_get_settings(); -$table = new HTML_Table(['class' => 'data_table', 'width' => '100%']); +$table = new HTML_Table(['class' => 'table']); $column = 0; $row = 0; $headers = [ @@ -39,14 +39,16 @@ foreach ($settings as $param) { $check = ''; $attrs = ['center' => 'left']; $syncButton = ' - + '; $data = [ $check, isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'], $param['category'], $param['access_url'], - ''. + ''. '
Master value: '.$param['selected_value'], $syncButton, ]; @@ -54,7 +56,7 @@ foreach ($settings as $param) { $table->setRowAttributes($row, ['id' => 'row_'.$param['id']], true); } -$content = '
'; +$content = ''; $content .= ''; $content .= $table->toHtml(); $content .= '
'; @@ -67,10 +69,8 @@ function ajax_sync_setting(settingid) { var webUrl = '".api_get_path(WEB_PATH)."'; var spare = $('#row_'+settingid).html(); var formobj = document.forms['settingsform']; - var url = webUrl + 'plugin/vchamilo/ajax/service.php?what=syncthis&settingid='+settingid+'&value='+encodeURIComponent(formobj.elements['value_'+settingid].value); - + var url = webUrl + 'plugin/vchamilo/ajax/service.php?what=syncthis&settingid='+settingid+'&value='+encodeURIComponent(formobj.elements['value_'+settingid].value); $('#row_'+settingid).html(''); - $.get(url, function (data) { $('#row_'+settingid).html(spare); $('#res_'+settingid).html(data);