Minor - Format code, add intval

1.10.x
Julio Montoya 10 years ago
parent 04bb557b2f
commit 3e56e9b27b
  1. 1
      main/inc/lib/GamificationUtils.php
  2. 1
      main/inc/lib/display.lib.php
  3. 14
      main/inc/lib/event_email_template.class.php
  4. 56
      main/inc/lib/glossary.lib.php
  5. 106
      main/inc/lib/legal.lib.php
  6. 12
      main/inc/lib/login_redirection.class.php
  7. 93
      main/inc/lib/nanogong.lib.php
  8. 233
      main/inc/lib/specific_fields_manager.lib.php
  9. 39
      main/inc/lib/statistics.lib.php
  10. 511
      main/inc/lib/statsUtils.lib.inc.php
  11. 28
      main/inc/lib/sub_language.class.php
  12. 4
      main/inc/lib/surveymanager.lib.php
  13. 6
      main/inc/lib/thematic.lib.php

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* GamificationUtils class
* Functions to manage the gamification mode

@ -398,7 +398,6 @@ class Display
$column_order = array(),
$form_actions = array()
) {
global $origin;
$column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
$default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;

@ -103,18 +103,4 @@ class EventEmailTemplate extends Model {
$row = Database::select('count(*) as count', $this->table, array(),'first');
return $row['count'];
}
/*
public function save($params) {
$id = parent::save($params);
if (!empty($id)) {
event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
}
return $id;
}
public function delete($id) {
parent::delete($id);
event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
} */
}

@ -261,21 +261,25 @@ class GlossaryManager
// Database table definition
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
$t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
if (empty($glossary_id)) { return false; }
$sql = "SELECT g.glossary_id as glossary_id,
g.name as glossary_title,
g.description as glossary_comment,
g.display_order as glossary_display_order,
ip.insert_date as insert_date,
ip.lastedit_date as update_date,
g.session_id
FROM $t_glossary g, $t_item_propery ip
WHERE g.glossary_id = ip.ref AND
tool = '".TOOL_GLOSSARY."' AND
g.glossary_id = '".intval($glossary_id)."' AND
g.c_id = ".api_get_course_int_id()." AND
ip.c_id = ".api_get_course_int_id()."
";
if (empty($glossary_id)) {
return false;
}
$sql = "SELECT
g.glossary_id as glossary_id,
g.name as glossary_title,
g.description as glossary_comment,
g.display_order as glossary_display_order,
ip.insert_date as insert_date,
ip.lastedit_date as update_date,
g.session_id
FROM $t_glossary g, $t_item_propery ip
WHERE
g.glossary_id = ip.ref AND
tool = '".TOOL_GLOSSARY."' AND
g.glossary_id = '".intval($glossary_id)."' AND
g.c_id = ".api_get_course_int_id()." AND
ip.c_id = ".api_get_course_int_id()."
";
$result = Database::query($sql);
if ($result === false || Database::num_rows($result) != 1) {
return false;
@ -354,7 +358,7 @@ class GlossaryManager
Display::return_icon('view_text.png',get_lang('TableView'),'',ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
if (!$_SESSION['glossary_view'] OR $_SESSION['glossary_view'] == 'table') {
if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') {
$table = new SortableTable(
'glossary',
array('GlossaryManager', 'get_number_glossary_terms'),
@ -410,9 +414,12 @@ class GlossaryManager
$session_id = intval($session_id);
$sql_filter = api_get_session_condition($session_id, true, true);
$sql = "SELECT count(glossary_id) as total FROM $t_glossary WHERE c_id = $course_id $sql_filter";
$sql = "SELECT count(glossary_id) as total
FROM $t_glossary WHERE c_id = $course_id $sql_filter";
$res = Database::query($sql);
if ($res === false) { return 0; }
if ($res === false) {
return 0;
}
$obj = Database::fetch_object($res);
return $obj->total;
}
@ -481,13 +488,6 @@ class GlossaryManager
}
if (api_is_allowed_to_edit(null,true)) {
// Date treatment for timezones
/*if (!empty($data[2]) && $data[2] != '0000-00-00 00:00:00:') {
$array[2] = api_get_local_time($data[2], null, date_default_timezone_get());
}
if (!empty($data[3]) && $data[3] != '0000-00-00 00:00:00:') {
$array[3] = api_get_local_time($data[3], null, date_default_timezone_get());
}*/
$array[2] = $data[2];
}
$return[] = $array;
@ -605,8 +605,10 @@ class GlossaryManager
$found = true;
}
}
$sql1 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($next_display_order)."' WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($current_id)."'";
$sql2 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($current_display_order)."' WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($next_id)."'";
$sql1 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($next_display_order)."'
WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($current_id)."'";
$sql2 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($current_display_order)."'
WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($next_id)."'";
Database::query($sql1);
Database::query($sql2);
if ($message)

@ -8,7 +8,7 @@
*/
class LegalManager
{
private function __construct ()
private function __construct()
{
}
@ -101,7 +101,8 @@ class LegalManager
$language= Database::escape_string($language);
$sql = "SELECT * FROM $legal_conditions_table
WHERE language_id = '".$language."'
ORDER BY version DESC LIMIT 1 ";
ORDER BY version DESC
LIMIT 1 ";
$result = Database::query($sql);
return Database::fetch_array($result);
@ -114,21 +115,22 @@ class LegalManager
*/
public static function get_last_version($language)
{
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$language= Database::escape_string($language);
$sql = "SELECT version FROM $legal_conditions_table
WHERE language_id = '".$language."'
ORDER BY version DESC LIMIT 1 ";
$result = Database::query($sql);
if (Database::num_rows($result)>0){
$version = Database::fetch_array($result);
$version = explode(':',$version[0]);
return $version[0];
} else {
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$language = intval($language);
$sql = "SELECT version FROM $legal_conditions_table
WHERE language_id = '".$language."'
ORDER BY version DESC
LIMIT 1 ";
$result = Database::query($sql);
if (Database::num_rows($result)>0){
$version = Database::fetch_array($result);
$version = explode(':',$version[0]);
return $version[0];
} else {
return false;
}
return false;
}
}
/**
@ -139,55 +141,30 @@ class LegalManager
*/
public static function show_last_condition($term_preview)
{
$preview = '';
switch ($term_preview['type']) {
/*// scroll box
case 0:
$preview ='<fieldset>
<legend>'.get_lang('TermsAndConditions').'</legend>';
$preview .= '<div class="form-item">
<label>'.get_lang('TermsAndConditions').': </label>
<div class="resizable-textarea">
<span>
<textarea id="" class="form-textarea resizable textarea-processed" readonly="readonly" name="" rows="10" cols="60">';
$preview .= $term_preview['content'];
$preview .= '</textarea>
<div class="grippie" style="margin-right: -2px;"/>
</span>
</div>
</div>
<div id="edit-legal-accept-wrapper" class="form-item">
<label class="option" for="edit-legal-accept">
<input id="edit-legal-accept" class="form-checkbox" type="checkbox" value="1" name="legal_accept"/>
<strong>'.get_lang('Accept').'</strong>
'.get_lang('TermsAndConditions').'
</label>
</div>
</fieldset>';
break;*/
// HTML
case 0:
$preview = '';
switch ($term_preview['type']) {
case 0:
if (!empty($term_preview['content'])) {
$preview = '<div class="legal-terms">'.$term_preview['content'].'</div><br />';
}
$preview .= get_lang('ByClickingRegisterYouAgreeTermsAndConditions');
$preview .= get_lang('ByClickingRegisterYouAgreeTermsAndConditions');
break;
// Page link
case 1:
$preview ='<fieldset>
<legend>'.get_lang('TermsAndConditions').'</legend>';
$preview .= '<div id="legal-accept-wrapper" class="form-item">
<label class="option" for="legal-accept">
<input id="legal-accept" type="checkbox" value="1" name="legal_accept"/>
'.get_lang('IHaveReadAndAgree').'
<a href="#">'.get_lang('TermsAndConditions').'</a>
</label>
</div>
</fieldset>';
// Page link
case 1:
$preview ='<fieldset>
<legend>'.get_lang('TermsAndConditions').'</legend>';
$preview .= '<div id="legal-accept-wrapper" class="form-item">
<label class="option" for="legal-accept">
<input id="legal-accept" type="checkbox" value="1" name="legal_accept"/>
'.get_lang('IHaveReadAndAgree').'
<a href="#">'.get_lang('TermsAndConditions').'</a>
</label>
</div>
</fieldset>';
break;
default:
default:
break;
}
}
return $preview;
}
@ -237,7 +214,9 @@ class LegalManager
public static function count()
{
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$sql = "SELECT count(*) as count_result FROM $legal_conditions_table ORDER BY legal_id DESC ";
$sql = "SELECT count(*) as count_result
FROM $legal_conditions_table
ORDER BY legal_id DESC ";
$result = Database::query($sql);
$url = Database::fetch_array($result,'ASSOC');
$result = $url['count_result'];
@ -251,12 +230,13 @@ class LegalManager
* @param int The language id
* @return int The current type of terms and conditions
*/
public static function get_type_of_terms_and_conditions($legal_id,$language_id)
public static function get_type_of_terms_and_conditions($legal_id, $language_id)
{
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$legal_id = intval($legal_id);
$language_id = Database::escape_string($language_id);
$sql = 'SELECT type FROM '.$legal_conditions_table.' WHERE legal_id="'.$legal_id.'" AND language_id="'.$language_id.'"';
$language_id = intval($language_id);
$sql = 'SELECT type FROM '.$legal_conditions_table.'
WHERE legal_id="'.$legal_id.'" AND language_id="'.$language_id.'"';
$rs = Database::query($sql);
return Database::result($rs,0,'type');

@ -12,16 +12,6 @@ Class LoginRedirection {
global $param;
$param = isset($param) ? $param : '';
$redirect_url = '';
/*
//If session request url is setted, we go there
if (!empty($_SESSION['request_uri'])) {
$req = $_SESSION['request_uri'];
unset($_SESSION['request_uri']);
header('location: '.$req);
exit();
}
*/
if (api_is_student() && !api_get_setting('student_page_after_login') == '') {
$redirect_url = html_entity_decode(api_get_setting('student_page_after_login'));
if ($redirect_url[0] == "/") {
@ -60,4 +50,4 @@ Class LoginRedirection {
exit();
}
}
}

@ -37,7 +37,6 @@ class Nanogong
*/
public function create_user_folder()
{
//COURSE123/exercises/session_id/exercise_id/question_id/user_id
if (empty($this->store_path)) {
return false;
@ -78,46 +77,45 @@ class Nanogong
*/
public function set_parameters($params = array())
{
// Setting course id
if (isset($params['course_id'])) {
$this->course_id = intval($params['course_id']);
} else {
$this->course_id = $params['course_id'] = api_get_course_int_id();
}
//Setting course id
if (isset($params['course_id'])) {
$this->course_id = intval($params['course_id']);
} else {
$this->course_id = $params['course_id'] = api_get_course_int_id();
}
//Setting course info
if (isset($this->course_id)) {
$this->course_info = api_get_course_info_by_id($this->course_id);
}
//Setting course info
if (isset($this->course_id)) {
$this->course_info = api_get_course_info_by_id($this->course_id);
}
//Setting session id
if (isset($params['session_id'])) {
$this->session_id = intval($params['session_id']);
} else {
$this->session_id = $params['session_id'] = api_get_session_id();
}
//Setting session id
if (isset($params['session_id'])) {
$this->session_id = intval($params['session_id']);
} else {
$this->session_id = $params['session_id'] = api_get_session_id();
}
//Setting user ids
if (isset($params['user_id'])) {
$this->user_id = intval($params['user_id']);
} else {
$this->user_id = $params['user_id'] = api_get_user_id();
}
//Setting user ids
if (isset($params['user_id'])) {
$this->user_id = intval($params['user_id']);
} else {
$this->user_id = $params['user_id'] = api_get_user_id();
}
//Setting user ids
if (isset($params['exercise_id'])) {
$this->exercise_id = intval($params['exercise_id']);
} else {
$this->exercise_id = 0;
}
//Setting user ids
if (isset($params['exercise_id'])) {
$this->exercise_id = intval($params['exercise_id']);
} else {
$this->exercise_id = 0;
}
//Setting user ids
if (isset($params['question_id'])) {
$this->question_id = intval($params['question_id']);
} else {
$this->question_id = 0;
}
//Setting user ids
if (isset($params['question_id'])) {
$this->question_id = intval($params['question_id']);
} else {
$this->question_id = 0;
}
$this->can_edit = false;
@ -130,15 +128,12 @@ class Nanogong
}
//Settings the params array
$this->params = $params;
$this->store_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/exercises/';
$this->params = $params;
$this->store_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/exercises/';
$this->create_user_folder();
$this->store_path = $this->store_path.implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)).'/';
$this->filename = $this->generate_filename();
$this->store_filename = $this->store_path.$this->filename;
$this->store_path = $this->store_path.implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)).'/';
$this->filename = $this->generate_filename();
$this->store_filename = $this->store_path.$this->filename;
}
/**
@ -240,8 +235,8 @@ class Nanogong
$attempt_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql = "SELECT filename FROM $attempt_table
WHERE
exe_id = ".$this->params['exe_id']." AND
user_id = ".$this->params['user_id']." AND
exe_id = ".$this->params['exe_id']." AND
user_id = ".$this->params['user_id']." AND
question_id = ".$this->params['question_id']." AND
session_id = ".$this->params['session_id']." AND
course_code = '".$this->course_info['code']."'
@ -272,8 +267,6 @@ class Nanogong
*/
public function get_public_url($force_download = 0)
{
//$params = $this->get_params(true);
//$url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params;
$params = $this->get_params();
$filename = basename($this->load_filename_if_exists());
$url = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/exercises/'.$params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename;
@ -286,7 +279,6 @@ class Nanogong
*/
public function upload_file($is_nano = false)
{
if (!empty($_FILES)) {
$upload_ok = process_uploaded_file($_FILES['file'], false);
@ -413,7 +405,6 @@ class Nanogong
return $html;
}
/*
var filename = document.getElementById("audio_title").value+".wav";
var filename = filename.replace(/\s/g, "_");//replace spaces by _
@ -607,7 +598,6 @@ class Nanogong
$html .= '<a href="#" class="btn btn-default" onclick="send_voice()" />'.get_lang('SendRecord').'</a>';
$html .= '</form></div>';
$html .= Display::url(get_lang('ProblemsRecordingUploadYourOwnAudioFile'), 'javascript:void(0)', array('onclick' => 'show_simple_upload_form();'));
$html .= '<br /><br /><div id="no_nanogong_div">';
@ -665,7 +655,6 @@ class Nanogong
. $params_string
. '&TB_iframe=true';
$html = '<br />';
$html = Display::url(
get_lang('RecordAnswer'),
$url,

@ -3,9 +3,7 @@
* Manage specific tools
* @package chamilo.library
*/
/**
* Code
*/
// Database table definitions
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$table_sf_val = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
@ -14,41 +12,44 @@ $table_sf_val = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
* Add a specific field
* @param string $name specific field name
*/
function add_specific_field($name) {
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$name = trim($name);
if (empty($name)) {
return FALSE;
}
$sql = 'INSERT INTO %s(id, code, name) VALUES(NULL, \'%s\', \'%s\')';
$_safe_name = Database::escape_string($name);
$_safe_code = substr($_safe_name,0,1);
$_safe_code = get_specific_field_code_from_name($_safe_code);
if ($_safe_code === false) { return false; }
$sql = sprintf($sql, $table_sf, $_safe_code, $_safe_name);
$result = Database::query($sql);
if ($result) {
return Database::insert_id();
}
else {
return FALSE;
}
function add_specific_field($name)
{
$table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$name = trim($name);
if (empty($name)) {
return false;
}
$sql = 'INSERT INTO %s(id, code, name) VALUES(NULL, \'%s\', \'%s\')';
$_safe_name = Database::escape_string($name);
$_safe_code = substr($_safe_name, 0, 1);
$_safe_code = get_specific_field_code_from_name($_safe_code);
if ($_safe_code === false) {
return false;
}
$sql = sprintf($sql, $table_sf, $_safe_code, $_safe_name);
$result = Database::query($sql);
if ($result) {
return Database::insert_id();
} else {
return false;
}
}
/**
* Delete a specific field
* @param int $id specific field id
*/
function delete_specific_field($id) {
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$id = (int)$id;
if (!is_numeric($id)) {
return FALSE;
}
$sql = 'DELETE FROM %s WHERE id=%s LIMIT 1';
$sql = sprintf($sql, $table_sf, $id);
$result = Database::query($sql);
//TODO also delete the corresponding values
function delete_specific_field($id)
{
$table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$id = (int)$id;
if (!is_numeric($id)) {
return false;
}
$sql = 'DELETE FROM %s WHERE id=%s LIMIT 1';
$sql = sprintf($sql, $table_sf, $id);
Database::query($sql);
//TODO also delete the corresponding values
}
/**
@ -56,15 +57,16 @@ function delete_specific_field($id) {
* @param int $id specific field id
* @param string $name new field name
*/
function edit_specific_field($id, $name) {
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$id = (int)$id;
if (!is_numeric($id)) {
return FALSE;
}
$sql = 'UPDATE %s SET name = \'%s\' WHERE id = %s LIMIT 1';
$sql = sprintf($sql, $table_sf, $name, $id);
$result = Database::query($sql);
function edit_specific_field($id, $name)
{
$table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$id = (int)$id;
if (!is_numeric($id)) {
return false;
}
$sql = 'UPDATE %s SET name = \'%s\' WHERE id = %s LIMIT 1';
$sql = sprintf($sql, $table_sf, $name, $id);
$result = Database::query($sql);
}
/**
@ -72,27 +74,28 @@ function edit_specific_field($id, $name) {
* @param array $order_by a list of fields on which to sort
* @return array An array with all specific fields, at platform level
*/
function get_specific_field_list($conditions = array(), $order_by = array()) {
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$return_array = array();
$sql = "SELECT * FROM $table_sf";
if (count($conditions) > 0) {
$sql .= ' WHERE ';
$conditions_string_array = array();
foreach ($conditions as $field => $value) {
$conditions_string_array[] = $field.' = '. $value;
}
$sql .= implode(' AND ', $conditions_string_array);
}
if (count($order_by) > 0) {
$sql .= ' ORDER BY '.implode(',',$order_by);
}
$sql_result = Database::query($sql);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
function get_specific_field_list($conditions = array(), $order_by = array())
{
$table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$return_array = array();
$sql = "SELECT * FROM $table_sf";
if (count($conditions) > 0) {
$sql .= ' WHERE ';
$conditions_string_array = array();
foreach ($conditions as $field => $value) {
$conditions_string_array[] = $field.' = '.$value;
}
$sql .= implode(' AND ', $conditions_string_array);
}
if (count($order_by) > 0) {
$sql .= ' ORDER BY '.implode(',', $order_by);
}
$sql_result = Database::query($sql);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
}
/**
@ -100,8 +103,11 @@ function get_specific_field_list($conditions = array(), $order_by = array()) {
* @param array $order_by a list of fields on which sort
* @return array An array with all users of the platform.
*/
function get_specific_field_values_list($conditions = array(), $order_by = array()) {
$table_sfv = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
function get_specific_field_values_list(
$conditions = array(),
$order_by = array()
) {
$table_sfv = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$return_array = array();
$sql = "SELECT * FROM $table_sfv";
if (count($conditions) > 0) {
@ -120,17 +126,18 @@ function get_specific_field_values_list($conditions = array(), $order_by = array
$conditions_string_array = array();
foreach ($conditions as $field => $value) {
$conditions_string_array[] = $field.' = '. $value;
$conditions_string_array[] = $field.' = '.$value;
}
$sql .= implode(' AND ', $conditions_string_array);
}
if (count($order_by) > 0) {
$sql .= ' ORDER BY '.implode(',',$order_by);
$sql .= ' ORDER BY '.implode(',', $order_by);
}
$sql_result = Database::query($sql);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
}
@ -141,17 +148,31 @@ function get_specific_field_values_list($conditions = array(), $order_by = array
* @param int $ref_id representative id inside one tool item
* @return array
*/
function get_specific_field_values_list_by_prefix($prefix, $course_code, $tool_id, $ref_id) {
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$table_sfv = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$sql = 'SELECT sfv.value FROM %s sf LEFT JOIN %s sfv ON sf.id = sfv.field_id' .
' WHERE sf.code = \'%s\' AND sfv.c_id = \'%s\' AND tool_id = \'%s\' AND sfv.ref_id = %s';
$sql = sprintf($sql, $table_sf, $table_sfv, $prefix, $course_code, $tool_id, $ref_id);
$sql_result = Database::query($sql);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
function get_specific_field_values_list_by_prefix(
$prefix,
$course_code,
$tool_id,
$ref_id
) {
$table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$table_sfv = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$sql = 'SELECT sfv.value FROM %s sf LEFT JOIN %s sfv ON sf.id = sfv.field_id'.
' WHERE sf.code = \'%s\' AND sfv.c_id = \'%s\' AND tool_id = \'%s\' AND sfv.ref_id = %s';
$sql = sprintf(
$sql,
$table_sf,
$table_sfv,
$prefix,
$course_code,
$tool_id,
$ref_id
);
$sql_result = Database::query($sql);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
}
/**
@ -162,14 +183,30 @@ function get_specific_field_values_list_by_prefix($prefix, $course_code, $tool_i
* @param int $ref_id intern id inside specific tool table
* @param string $value specific field value
*/
function add_specific_field_value($id_specific_field, $course_id, $tool_id, $ref_id, $value) {
$table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
function add_specific_field_value(
$id_specific_field,
$course_id,
$tool_id,
$ref_id,
$value
) {
$table_sf_values = Database:: get_main_table(
TABLE_MAIN_SPECIFIC_FIELD_VALUES
);
$value = trim($value);
if (empty($value)) {
return false;
}
$sql = 'INSERT INTO %s(id, course_code, tool_id, ref_id, field_id, value) VALUES(NULL, \'%s\', \'%s\', %s, %s, \'%s\')';
$sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field, Database::escape_string($value));
$sql = sprintf(
$sql,
$table_sf_values,
$course_id,
$tool_id,
$ref_id,
$id_specific_field,
Database::escape_string($value)
);
$result = Database::query($sql);
if ($result) {
return Database::insert_id();
@ -186,10 +223,10 @@ function add_specific_field_value($id_specific_field, $course_id, $tool_id, $ref
* @param int $ref_id intern id inside specific tool table
*/
function delete_all_specific_field_value($course_id, $id_specific_field, $tool_id, $ref_id) {
$table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$sql = 'DELETE FROM %s WHERE course_code = \'%s\' AND tool_id = \'%s\' AND ref_id = %s AND field_id = %s';
$sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field);
$result = Database::query($sql);
$table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$sql = 'DELETE FROM %s WHERE course_code = \'%s\' AND tool_id = \'%s\' AND ref_id = %s AND field_id = %s';
$sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field);
Database::query($sql);
}
/**
@ -216,8 +253,32 @@ function delete_all_values_for_item($course_id, $tool_id, $ref_id) {
function get_specific_field_code_from_name($name) {
// Z is used internally by Xapian
// O & C already used by tool_id and course_id
$list = array('A','B','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y');
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$list = array(
'A',
'B',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
);
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$sql = "SELECT code FROM $table_sf ORDER BY code";
$res = Database::query($sql);
$code = strtoupper(substr($name,0,1));

@ -52,6 +52,7 @@ class Statistics
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->number;
}
@ -69,7 +70,8 @@ class Statistics
$access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
$sql = "SELECT COUNT(*) AS number
FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
WHERE u.c_id = c.id AND access_url_id='".$current_url_id."'";
if (isset ($visibility)) {
$sql .= " AND visibility = ".intval($visibility);
@ -139,6 +141,7 @@ class Statistics
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->number;
}
@ -152,7 +155,8 @@ class Statistics
$access_url_rel_session_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
if (api_is_multiple_url_enabled()) {
$current_url_id = api_get_current_access_url_id();
$sql = "SELECT COUNT(id) AS number FROM ".$session_table." as s, ".$access_url_rel_session_table." as u WHERE u.session_id=s.id AND access_url_id='".$current_url_id."'";
$sql = "SELECT COUNT(id) AS number FROM ".$session_table." as s, ".$access_url_rel_session_table." as u
WHERE u.session_id=s.id AND access_url_id='".$current_url_id."'";
} else {
$sql = "SELECT COUNT(id) AS number FROM ".$session_table." ";
}
@ -173,9 +177,13 @@ class Statistics
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT count(default_id) AS total_number_of_items FROM $track_e_default, $table_user user, $access_url_rel_user_table url WHERE default_user_id = user.user_id AND user.user_id=url.user_id AND access_url_id='".$current_url_id."'";
$sql = "SELECT count(default_id) AS total_number_of_items
FROM $track_e_default, $table_user user, $access_url_rel_user_table url
WHERE default_user_id = user.user_id AND user.user_id=url.user_id AND access_url_id='".$current_url_id."'";
} else {
$sql = "SELECT count(default_id) AS total_number_of_items FROM $track_e_default, $table_user user WHERE default_user_id = user.user_id ";
$sql = "SELECT count(default_id) AS total_number_of_items
FROM $track_e_default, $table_user user
WHERE default_user_id = user.user_id ";
}
if (isset($_GET['keyword'])) {
@ -185,6 +193,7 @@ class Statistics
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->total_number_of_items;
}
@ -198,14 +207,12 @@ class Statistics
*/
public static function getActivitiesData($from, $numberOfItems, $column, $direction)
{
global $dateTimeFormatLong;
$track_e_default = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
$column = intval($column);
$from = intval($from);
$track_e_default = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
$column = intval($column);
$from = intval($from);
$numberOfItems = intval($numberOfItems);
if (!in_array($direction, array('ASC','DESC'))) {
@ -289,6 +296,7 @@ class Statistics
}
$activities[] = $row;
}
return $activities;
}
@ -305,6 +313,7 @@ class Statistics
while ($category = Database::fetch_object($res)) {
$categories[$category->code] = $category->name;
}
return $categories;
}
@ -326,6 +335,7 @@ class Statistics
foreach ($data as $index => $value) {
$result[$index] = (int) round($value * $delta);
}
return $result;
}
@ -399,7 +409,10 @@ class Statistics
$period = get_lang('PeriodMonth');
$periodCollection = api_get_months_long();
$sql = "SELECT DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date , count( login_id ) AS number_of_logins FROM ".$table.$table_url.$where_url." GROUP BY stat_date ORDER BY login_date DESC";
$sql = "SELECT DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date , count( login_id ) AS number_of_logins
FROM ".$table.$table_url.$where_url."
GROUP BY stat_date
ORDER BY login_date DESC";
$sql_last_x = null;
switch ($type) {

@ -8,104 +8,104 @@
*/
class StatsUtils
{
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc return one result from a sql query (1 single result)
*/
public static function getOneResult($sql)
{
$query = Database::query($sql);
if ($query !== false) {
$res = @Database::fetch_array($query, 'NUM');
} else {
$res = array();
}
return $res[0];
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc return one result from a sql query (1 single result)
*/
public static function getOneResult($sql)
{
$query = Database::query($sql);
if ($query !== false) {
$res = @Database::fetch_array($query, 'NUM');
} else {
$res = array();
}
return $res[0];
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a 1 column tab
*/
public static function getManyResults1Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i++] = $resA[0];
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a 1 column tab
*/
public static function getManyResults1Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i++] = $resA[0];
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query
*/
public static function getManyResults2Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i][0] = $resA[0];
$resu[$i][1] = $resA[1];
$i++;
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query
*/
public static function getManyResults2Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i][0] = $resA[0];
$resu[$i][1] = $resA[1];
$i++;
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a 3 column tab
* in $resu[$i][0], $resu[$i][1],$resu[$i][2]
*/
public static function getManyResults3Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i][0] = $resA[0];
$resu[$i][1] = $resA[1];
$resu[$i][2] = $resA[2];
$i++;
}
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a 3 column tab
* in $resu[$i][0], $resu[$i][1],$resu[$i][2]
*/
public static function getManyResults3Col($sql)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
$resu[$i][0] = $resA[0];
$resu[$i][1] = $resA[1];
$resu[$i][2] = $resA[2];
$i++;
}
}
return $resu;
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a X column tab
* in $resu[$i][0], $resu[$i][1],$resu[$i][2],...
* this function is more 'standard' but use a little
* more ressources
* So I encourage to use the dedicated for 1, 2 or 3
* columns of results
*/
public static function getManyResultsXCol($sql, $X)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
for ($j = 0; $j < $X; $j++) {
$resu[$i][$j] = $resA[$j];
}
$i++;
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @desc Return many results of a query in a X column tab
* in $resu[$i][0], $resu[$i][1],$resu[$i][2],...
* this function is more 'standard' but use a little
* more ressources
* So I encourage to use the dedicated for 1, 2 or 3
* columns of results
*/
public static function getManyResultsXCol($sql, $X)
{
$res = Database::query($sql);
if ($res !== false) {
$i = 0;
while ($resA = Database::fetch_array($res, 'NUM')) {
for ($j = 0; $j < $X; $j++) {
$resu[$i][$j] = $resA[$j];
}
$i++;
}
}
return $resu;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
@ -115,170 +115,169 @@ class StatsUtils
* the number of time this hours was found.
* key 'total' return the sum of all number of time hours
* appear
*/
public static function hoursTab($sql)
{
$hours_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
$last_hours = -1;
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
if ($date_array['hours'] == $last_hours) {
$hours_array[$date_array['hours']]++;
} else {
$hours_array[$date_array['hours']] = 1;
$last_hours = $date_array['hours'];
}
$hours_array['total']++;
}
Database::free_result($res);
}
return $hours_array;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @return days_array
* @desc Return an assoc array. Keys are the days, values are
* the number of time this hours was found.
* key "total" return the sum of all number of time days
* appear
*/
public static function daysTab($sql)
{
$MonthsShort = api_get_months_short();
$days_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
$last_day = -1;
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
$display_date = $date_array['mday'] . ' ' . $MonthsShort[$date_array['mon'] - 1] . ' ' . $date_array['year'];
if ($date_array['mday'] == $last_day) {
$days_array[$display_date]++;
} else {
$days_array[$display_date] = 1;
$last_day = $display_date;
}
$days_array['total']++;
}
Database::free_result($res);
}
return $days_array;
}
*/
public static function hoursTab($sql)
{
$hours_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
$last_hours = -1;
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
if ($date_array['hours'] == $last_hours) {
$hours_array[$date_array['hours']]++;
} else {
$hours_array[$date_array['hours']] = 1;
$last_hours = $date_array['hours'];
}
$hours_array['total']++;
}
Database::free_result($res);
}
return $hours_array;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @return month_array
* @desc Return an assoc array. Keys are the days, values are
* the number of time this hours was found.
* key "total" return the sum of all number of time days
* appear
*/
public static function monthTab($sql)
{
$MonthsLong = api_get_months_long();
$month_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
// init tab with all months
for ($i = 0; $i < 12; $i++) {
$month_array[$MonthsLong[$i]] = 0;
}
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
$month_array[$MonthsLong[$date_array['mon'] - 1]]++;
$month_array['total']++;
}
Database::free_result($res);
}
return $month_array;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @return days_array
* @desc Return an assoc array. Keys are the days, values are
* the number of time this hours was found.
* key "total" return the sum of all number of time days
* appear
*/
public static function daysTab($sql)
{
$MonthsShort = api_get_months_short();
$days_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
$last_day = -1;
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
$display_date = $date_array['mday'] . ' ' . $MonthsShort[$date_array['mon'] - 1] . ' ' . $date_array['year'];
if ($date_array['mday'] == $last_day) {
$days_array[$display_date]++;
} else {
$days_array[$display_date] = 1;
$last_day = $display_date;
}
$days_array['total']++;
}
Database::free_result($res);
}
return $days_array;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param period_array : an array provided by hoursTab($sql) or daysTab($sql)
* @param periodTitle : title of the first column, type of period
* @param linkOnPeriod :
* @desc Display a 4 column array
* Columns are : hour of day, graph, number of hits and %
* First line are titles
* next are informations
* Last is total number of hits
*/
public static function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???')
{
echo "<table width='100%' cellpadding='0' cellspacing='1' border='0' align=center class='minitext'>";
// titles
echo "<tr bgcolor='#E6E6E6' align='center'>
<td width='15%' >
<b>$periodTitle</b>
</td>
<td width='60%'>
&nbsp;
</td>
<td width='10%'>
<b>" . get_lang('Hits') . "</b>
</td>
<td width='15%'>
<b>%</b>
</td>
</tr>
";
$factor = 4;
$maxSize = $factor * 100; //pixels
while (list($periodPiece, $cpt) = each($period_array)) {
if ($periodPiece != 'total') {
$pourcent = round(100 * $cpt / $period_array['total']);
$barwidth = $factor * $pourcent;
echo "<tr>
<td align='center' width='15%'>";
echo $periodPiece;
echo "</td>
<td width='60%' style='padding-top: 3px;' align='center'>"
// display hitbar
. "<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
if ($pourcent != 0) {
echo "<img src='../img/bar_1u.gif' width='$barwidth' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
// display 100% bar
if ($pourcent != 100 && $pourcent != 0) {
echo "<img src='../img/bar_1m.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
if ($pourcent != 100) {
echo "<img src='../img/bar_1r.gif' width='" . ($maxSize - $barwidth) . "' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
echo "<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />
</td>
<td align='center' width='10%'>
$cpt
</td>
<td align='center' width='15%'>
$pourcent %
</td>
</tr>
";
}
}
echo "<tr bgcolor='#E6E6E6'>
<td width='15%' align='center'>
" . get_lang('Total') . "
</td>
<td align='right' width='60%'>
&nbsp;
</td>
<td align='center' width='10%'>
" . $period_array['total'] . "
</td>
<td width='15%'>
&nbsp;
</td>
</tr>
";
echo "</table>";
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param sql : a sql query (as a string)
* @return month_array
* @desc Return an assoc array. Keys are the days, values are
* the number of time this hours was found.
* key "total" return the sum of all number of time days
* appear
*/
public static function monthTab($sql)
{
$MonthsLong = api_get_months_long();
$month_array = array('total' => 0);
$res = Database::query($sql);
if ($res !== false) {
// init tab with all months
for ($i = 0; $i < 12; $i++) {
$month_array[$MonthsLong[$i]] = 0;
}
while ($row = Database::fetch_row($res)) {
$date_array = getdate($row[0]);
$month_array[$MonthsLong[$date_array['mon'] - 1]]++;
$month_array['total']++;
}
Database::free_result($res);
}
return $month_array;
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @param period_array : an array provided by hoursTab($sql) or daysTab($sql)
* @param periodTitle : title of the first column, type of period
* @param linkOnPeriod :
* @desc Display a 4 column array
* Columns are : hour of day, graph, number of hits and %
* First line are titles
* next are informations
* Last is total number of hits
*/
public static function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???')
{
echo "<table width='100%' cellpadding='0' cellspacing='1' border='0' align=center class='minitext'>";
// titles
echo "<tr bgcolor='#E6E6E6' align='center'>
<td width='15%' >
<b>$periodTitle</b>
</td>
<td width='60%'>
&nbsp;
</td>
<td width='10%'>
<b>" . get_lang('Hits') . "</b>
</td>
<td width='15%'>
<b>%</b>
</td>
</tr>
";
$factor = 4;
$maxSize = $factor * 100; //pixels
while (list($periodPiece, $cpt) = each($period_array)) {
if ($periodPiece != 'total') {
$pourcent = round(100 * $cpt / $period_array['total']);
$barwidth = $factor * $pourcent;
echo "<tr>
<td align='center' width='15%'>";
echo $periodPiece;
echo "</td>
<td width='60%' style='padding-top: 3px;' align='center'>"
// display hitbar
. "<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
if ($pourcent != 0) {
echo "<img src='../img/bar_1u.gif' width='$barwidth' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
// display 100% bar
if ($pourcent != 100 && $pourcent != 0) {
echo "<img src='../img/bar_1m.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
if ($pourcent != 100) {
echo "<img src='../img/bar_1r.gif' width='" . ($maxSize - $barwidth) . "' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />";
}
echo "<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits &ndash; $pourcent %' />
</td>
<td align='center' width='10%'>
$cpt
</td>
<td align='center' width='15%'>
$pourcent %
</td>
</tr>
";
}
}
echo "<tr bgcolor='#E6E6E6'>
<td width='15%' align='center'>
" . get_lang('Total') . "
</td>
<td align='right' width='60%'>
&nbsp;
</td>
<td align='center' width='10%'>
" . $period_array['total'] . "
</td>
<td width='15%'>
&nbsp;
</td>
</tr>
";
echo "</table>";
}
}

@ -4,7 +4,6 @@
/**
* Class SubLanguageManager
* @package chamilo.admin.sublanguage
* @todo clean this lib and move to main/inc/lib
*/
class SubLanguageManager
{
@ -76,6 +75,7 @@ class SubLanguageManager
while ($row = Database::fetch_array($rs, 'ASSOC')) {
$all_information = $row;
}
return $all_information;
}
@ -226,7 +226,9 @@ class SubLanguageManager
public static function check_if_exist_language_by_id($language_id)
{
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql = 'SELECT count(*) as count FROM ' . $tbl_admin_languages . ' WHERE id="' . intval($language_id) . '"';
$sql = 'SELECT count(*) as count
FROM ' . $tbl_admin_languages . '
WHERE id="' . intval($language_id) . '"';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if (Database::result($rs, 0, 'count') == 1) {
@ -247,7 +249,9 @@ class SubLanguageManager
public static function get_name_of_language_by_id($language_id)
{
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql = 'SELECT original_name FROM ' . $tbl_admin_languages . ' WHERE id= ' . intval($language_id) . '';
$sql = 'SELECT original_name
FROM ' . $tbl_admin_languages . '
WHERE id= ' . intval($language_id) . '';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
return Database::result($rs, 0, 'original_name');
@ -320,8 +324,9 @@ class SubLanguageManager
public static function make_unavailable_language($language_id)
{
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql_make_unavailable = "UPDATE $tbl_admin_languages SET available='0' WHERE id = " . intval($language_id) . "";
$result = Database::query($sql_make_unavailable);
$sql = "UPDATE $tbl_admin_languages SET available='0'
WHERE id = " . intval($language_id) . "";
$result = Database::query($sql);
return $result !== false; //only return false on sql error
}
@ -333,8 +338,9 @@ class SubLanguageManager
public static function make_available_language($language_id)
{
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql_make_available = "UPDATE $tbl_admin_languages SET available='1' WHERE id = " . intval($language_id) . "";
$result = Database::query($sql_make_available);
$sql = "UPDATE $tbl_admin_languages SET available='1'
WHERE id = " . intval($language_id) . "";
$result = Database::query($sql);
return $result !== false; //only return false on sql error
}
@ -350,10 +356,12 @@ class SubLanguageManager
}
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql_update = "SELECT english_name FROM " . $tbl_admin_languages . " WHERE id= " . intval($language_id) . "";
$result = Database::query($sql_update);
$sql = "SELECT english_name FROM " . $tbl_admin_languages . "
WHERE id= " . intval($language_id) . "";
$result = Database::query($sql);
$lang = Database::fetch_array($result);
$sql_update_2 = "UPDATE " . $tbl_settings_current . " SET selected_value='" . $lang['english_name'] . "' WHERE variable='platformLanguage'";
$sql_update_2 = "UPDATE " . $tbl_settings_current . " SET selected_value='" . $lang['english_name'] . "'
WHERE variable='platformLanguage'";
$result_2 = Database::query($sql_update_2);
Event::addEvent(
LOG_PLATFORM_LANGUAGE_CHANGE,

@ -18,9 +18,9 @@ class SurveyTree
public function __construct()
{
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// searching
$search_restriction = SurveyUtil::survey_search_restriction();

@ -157,8 +157,8 @@ class Thematic
public function get_max_thematic_item($use_session = true)
{
// Database table definition
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id();
if ($use_session) {
$condition_session = api_get_session_condition($session_id);
} else {
@ -166,7 +166,7 @@ class Thematic
}
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(display_order) FROM $tbl_thematic
WHERE c_id = $course_id AND active = 1 $condition_session";
WHERE c_id = $course_id AND active = 1 $condition_session";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);

Loading…
Cancel
Save