Minor - format code

pull/2458/head
jmontoyaa 8 years ago
parent a9c6a8dceb
commit f85f4523ca
  1. 11
      plugin/vchamilo/ajax/service.php
  2. 37
      plugin/vchamilo/views/syncparams.controller.php
  3. 14
      plugin/vchamilo/views/syncparams.php

@ -1,20 +1,25 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../../../main/inc/global.inc.php';
api_protect_admin_script();
$action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true);
$plugin = VChamiloPlugin::create();
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
api_protect_admin_script();
if ($action === 'syncthis') {
switch ($action) {
case 'syncthis':
$res = include_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php';
if (!$res) {
echo '<span class="label label-success">Success</span>';
} else {
echo '<span class="label label-danger">Failure<br/>'.$errors.'</span>';
}
break;
}
exit;

@ -8,7 +8,8 @@ $result = Database::query($sql);
$vchamilos = Database::store_result($result, 'ASSOC');
// propagate in all known vchamilos a setting
if ($action == 'syncall') {
switch ($action) {
case 'syncall':
exit;
$keys = array_keys($_REQUEST);
$selection = preg_grep('/sel_.*/', $keys);
@ -32,7 +33,7 @@ if ($action == 'syncall') {
'access_url' => $setting['access_url'],
];
foreach ($vchamilos as $vcid => $chm) {
foreach ($vchamilos as $chm) {
$table = $chm['main_database'].".settings_current ";
$sql = " SELECT * FROM $table
WHERE
@ -50,16 +51,19 @@ if ($action == 'syncall') {
//$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database);
}
}
}
if ($action == 'syncthis') {
break;
case 'syncthis':
$settingId = isset($_GET['settingid']) ? $_GET['settingid'] : '';
if (is_numeric($settingId)) {
$delifempty = isset($_REQUEST['del']) ? $_REQUEST['del'] : '';
$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;
}
$params = [
'access_url_changeable' => $setting['access_url_changeable'],
'title' => $setting['title'],
@ -72,20 +76,19 @@ if ($action == 'syncthis') {
];
$errors = '';
foreach ($vchamilos as $vcid => $chm) {
$table = "settings_current";
foreach ($vchamilos as $instance) {
$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'],
'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 ($delifempty && empty($value)) {
if ($deleteIfEmpty && empty($value)) {
$sql = "DELETE FROM $table
WHERE
selected_value = '$value' AND
@ -93,9 +96,9 @@ if ($action == 'syncthis') {
access_url = '{$setting['access_url']}'
";
$connection->executeQuery($sql);
$case = "delete";
$case = 'delete';
} else {
$sql = " SELECT * FROM $table
$sql = "SELECT * FROM $table
WHERE
variable = '".$setting['variable']."' AND
access_url = '{$setting['access_url']}'
@ -117,6 +120,8 @@ if ($action == 'syncthis') {
} else {
return "Bad ID. Non numeric";
}
break;
}
return 0;

@ -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 = '
<input class="btn btn-default" type="button" name="syncthis" value="'.$plugin->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$param['id'].'\')" />
<input class="btn btn-default" type="button" name="syncthis"
value="'.$plugin->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$param['id'].'\')" />
<span id="res_'.$param['id'].'"></span>';
$data = [
$check,
isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'],
$param['category'],
$param['access_url'],
'<input type="text" disabled name="value_'.$param['id'].'" value="'.htmlspecialchars($param['selected_value'], ENT_COMPAT, 'UTF-8').'" />'.
'<input type="text" disabled name="value_'.$param['id'].'"
value="'.htmlspecialchars($param['selected_value'], ENT_COMPAT, 'UTF-8').'" />'.
'<br />Master value: '.$param['selected_value'],
$syncButton,
];
@ -54,7 +56,7 @@ foreach ($settings as $param) {
$table->setRowAttributes($row, ['id' => 'row_'.$param['id']], true);
}
$content = '<form name="settingsform" action="'.$thisurl.'">';
$content = '<form name="settingsform" action="'.$thisUrl.'">';
$content .= '<input type="hidden" name="what" value="" />';
$content .= $table->toHtml();
$content .= '</form>';
@ -68,9 +70,7 @@ function ajax_sync_setting(settingid) {
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);
$('#row_'+settingid).html('<td colspan=\"7\"><img src=\"'+webUrl+'plugin/vchamilo/pix/ajax_waiter.gif\" /></td>');
$.get(url, function (data) {
$('#row_'+settingid).html(spare);
$('#res_'+settingid).html(data);

Loading…
Cancel
Save