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 <?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../../../main/inc/global.inc.php'; require_once __DIR__.'/../../../main/inc/global.inc.php';
api_protect_admin_script();
$action = isset($_GET['what']) ? $_GET['what'] : ''; $action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true); define('CHAMILO_INTERNAL', true);
$plugin = VChamiloPlugin::create(); $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';
api_protect_admin_script(); switch ($action) {
case 'syncthis':
if ($action === 'syncthis') {
$res = include_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'; $res = include_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php';
if (!$res) { if (!$res) {
echo '<span class="label label-success">Success</span>'; echo '<span class="label label-success">Success</span>';
} else { } else {
echo '<span class="label label-danger">Failure<br/>'.$errors.'</span>'; 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'); $vchamilos = Database::store_result($result, 'ASSOC');
// propagate in all known vchamilos a setting // propagate in all known vchamilos a setting
if ($action == 'syncall') { switch ($action) {
case 'syncall':
exit; exit;
$keys = array_keys($_REQUEST); $keys = array_keys($_REQUEST);
$selection = preg_grep('/sel_.*/', $keys); $selection = preg_grep('/sel_.*/', $keys);
@ -32,7 +33,7 @@ if ($action == 'syncall') {
'access_url' => $setting['access_url'], 'access_url' => $setting['access_url'],
]; ];
foreach ($vchamilos as $vcid => $chm) { foreach ($vchamilos as $chm) {
$table = $chm['main_database'].".settings_current "; $table = $chm['main_database'].".settings_current ";
$sql = " SELECT * FROM $table $sql = " SELECT * FROM $table
WHERE WHERE
@ -50,16 +51,19 @@ if ($action == 'syncall') {
//$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':
if ($action == 'syncthis') {
$settingId = isset($_GET['settingid']) ? $_GET['settingid'] : ''; $settingId = isset($_GET['settingid']) ? $_GET['settingid'] : '';
if (is_numeric($settingId)) { if (is_numeric($settingId)) {
$delifempty = isset($_REQUEST['del']) ? $_REQUEST['del'] : ''; $deleteIfEmpty = isset($_REQUEST['del']) ? $_REQUEST['del'] : '';
$value = $_REQUEST['value']; $value = $_REQUEST['value'];
// Getting the local setting record. // Getting the local setting record.
$setting = api_get_settings_params_simple(['id' => $settingId]); $setting = api_get_settings_params_simple(['id' => $settingId]);
if (empty($setting)) {
return 0;
}
$params = [ $params = [
'access_url_changeable' => $setting['access_url_changeable'], 'access_url_changeable' => $setting['access_url_changeable'],
'title' => $setting['title'], 'title' => $setting['title'],
@ -72,20 +76,19 @@ if ($action == 'syncthis') {
]; ];
$errors = ''; $errors = '';
foreach ($vchamilos as $vcid => $chm) { foreach ($vchamilos as $instance) {
$table = "settings_current"; $table = 'settings_current';
$config = new \Doctrine\DBAL\Configuration(); $config = new \Doctrine\DBAL\Configuration();
$connectionParams = [ $connectionParams = [
'dbname' => $chm['main_database'], 'dbname' => $instance['main_database'],
'user' => $chm['db_user'], 'user' => $instance['db_user'],
'password' => $chm['db_password'], 'password' => $instance['db_password'],
'host' => $chm['db_host'], 'host' => $instance['db_host'],
'driver' => 'pdo_mysql', 'driver' => 'pdo_mysql',
]; ];
$connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
try { try {
if ($delifempty && empty($value)) { if ($deleteIfEmpty && empty($value)) {
$sql = "DELETE FROM $table $sql = "DELETE FROM $table
WHERE WHERE
selected_value = '$value' AND selected_value = '$value' AND
@ -93,9 +96,9 @@ if ($action == 'syncthis') {
access_url = '{$setting['access_url']}' access_url = '{$setting['access_url']}'
"; ";
$connection->executeQuery($sql); $connection->executeQuery($sql);
$case = "delete"; $case = 'delete';
} else { } else {
$sql = " SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE WHERE
variable = '".$setting['variable']."' AND variable = '".$setting['variable']."' AND
access_url = '{$setting['access_url']}' access_url = '{$setting['access_url']}'
@ -117,6 +120,8 @@ if ($action == 'syncthis') {
} else { } else {
return "Bad ID. Non numeric"; return "Bad ID. Non numeric";
} }
break;
} }
return 0; return 0;

@ -10,7 +10,7 @@ $action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true); define('CHAMILO_INTERNAL', true);
$plugin = VChamiloPlugin::create(); $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) { if ($action) {
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'); require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php');
@ -18,7 +18,7 @@ if ($action) {
$settings = api_get_settings(); $settings = api_get_settings();
$table = new HTML_Table(['class' => 'data_table', 'width' => '100%']); $table = new HTML_Table(['class' => 'table']);
$column = 0; $column = 0;
$row = 0; $row = 0;
$headers = [ $headers = [
@ -39,14 +39,16 @@ foreach ($settings as $param) {
$check = ''; $check = '';
$attrs = ['center' => 'left']; $attrs = ['center' => 'left'];
$syncButton = ' $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>'; <span id="res_'.$param['id'].'"></span>';
$data = [ $data = [
$check, $check,
isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'], isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'],
$param['category'], $param['category'],
$param['access_url'], $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'], '<br />Master value: '.$param['selected_value'],
$syncButton, $syncButton,
]; ];
@ -54,7 +56,7 @@ foreach ($settings as $param) {
$table->setRowAttributes($row, ['id' => 'row_'.$param['id']], true); $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 .= '<input type="hidden" name="what" value="" />';
$content .= $table->toHtml(); $content .= $table->toHtml();
$content .= '</form>'; $content .= '</form>';
@ -68,9 +70,7 @@ function ajax_sync_setting(settingid) {
var spare = $('#row_'+settingid).html(); var spare = $('#row_'+settingid).html();
var formobj = document.forms['settingsform']; 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>'); $('#row_'+settingid).html('<td colspan=\"7\"><img src=\"'+webUrl+'plugin/vchamilo/pix/ajax_waiter.gif\" /></td>');
$.get(url, function (data) { $.get(url, function (data) {
$('#row_'+settingid).html(spare); $('#row_'+settingid).html(spare);
$('#res_'+settingid).html(data); $('#res_'+settingid).html(data);

Loading…
Cancel
Save