Minor - format code

pull/2458/head
jmontoyaa 8 years ago
parent a9c6a8dceb
commit f85f4523ca
  1. 23
      plugin/vchamilo/ajax/service.php
  2. 169
      plugin/vchamilo/views/syncparams.controller.php
  3. 16
      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') {
$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>';
}
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,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;

@ -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>';
@ -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('<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