Minor - format code

pull/2487/head
jmontoyaa 7 years ago
parent 62fab6a26e
commit d9d30144a5
  1. 1
      main/exercise/Annotation.php
  2. 1
      main/exercise/evalmathnotation.php
  3. 36
      main/exercise/export/scorm/scorm_classes.php
  4. 16
      main/gradebook/lib/be/abstractlink.class.php
  5. 94
      main/gradebook/lib/be/category.class.php
  6. 115
      main/gradebook/lib/fe/exportgradebook.php
  7. 8
      main/inc/lib/attendance.lib.php
  8. 107
      main/inc/lib/fileManage.lib.php
  9. 91
      main/inc/lib/message.lib.php
  10. 1
      main/inc/lib/portfolio.class.php
  11. 9
      main/inc/lib/sessionmanager.lib.php

@ -129,5 +129,4 @@ class Annotation extends Question
return parent::return_header($exercise, $counter, $score); // TODO: Change the autogenerated stub
}
}

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
require_once "../inc/global.inc.php";
echo "<pre>".
get_lang('SummationPlus')."\n".
get_lang('SubstractionMinus')."\n".

@ -31,8 +31,11 @@ class ScormQuestion extends Question
* @param integer $js_id
* @return string|array
*/
public static function export_question($questionId, $standalone = true, $js_id)
{
public static function export_question(
$questionId,
$standalone = true,
$js_id
) {
$question = new ScormQuestion();
$qst = $question->read($questionId);
if (!$qst) {
@ -119,7 +122,7 @@ class ScormQuestion extends Question
return true;
}
function export()
public function export()
{
$html = $this->getQuestionHTML();
$js = $this->getQuestionJS();
@ -154,7 +157,7 @@ class ScormQuestion extends Question
/**
* Returns an HTML-formatted question
*/
function getQuestionHTML()
public function getQuestionHTML()
{
$title = $this->selectTitle();
$description = $this->selectDescription();
@ -209,7 +212,7 @@ class ScormAnswerMultipleChoice extends Answer
/**
* Return HTML code for possible answers
*/
function export()
public function export()
{
$js = '';
$html = '<tr><td colspan="2"><table width="100%">';
@ -322,7 +325,7 @@ class ScormAnswerTrueFalse extends Answer
*
* @author Amand Tihon <amand@alrj.org>
*/
function export()
public function export()
{
$js = '';
$html = '<tr><td colspan="2"><table width="100%">';
@ -375,7 +378,7 @@ class ScormAnswerFillInBlanks extends Answer
* As a side effect, it stores two lists in the class :
* the missing words and their respective weightings.
*/
function export()
public function export()
{
global $charset;
$js = '';
@ -451,7 +454,7 @@ class ScormAnswerMatching extends Answer
* Export the question part as a matrix-choice, with only one possible answer per line.
* @author Amand Tihon <amand@alrj.org>
*/
function export()
public function export()
{
$js = '';
$html = '<tr><td colspan="2"><table width="100%">';
@ -555,7 +558,7 @@ class ScormAnswerFree extends Answer
* the missing words and their respective weightings.
*
*/
function export()
public function export()
{
$js = '';
$identifier = 'question_'.$this->questionJSId.'_free';
@ -598,7 +601,7 @@ class ScormAnswerHotspot extends Answer
* Returns the javascript code that goes with HotSpot exercises
* @return string The JavaScript code
*/
function get_js_header()
public function get_js_header()
{
if ($this->standalone) {
$header = '<script>';
@ -626,6 +629,7 @@ class ScormAnswerHotspot extends Answer
return $header;
}
/**
* Export the text with missing words.
*
@ -633,7 +637,7 @@ class ScormAnswerHotspot extends Answer
* the missing words and their respective weightings.
*
*/
function export()
public function export()
{
$js = $this->get_js_header();
$html = '<tr><td colspan="2"><table width="100%">';
@ -715,7 +719,7 @@ class ScormAssessmentItem
* This opens the <item> block, with correct attributes.
*
*/
function start_page()
public function start_page()
{
$head = '';
if ($this->standalone) {
@ -731,7 +735,7 @@ class ScormAssessmentItem
* End the XML flow, closing the </item> tag.
*
*/
function end_page()
public function end_page()
{
if ($this->standalone) {
return '</html>';
@ -743,7 +747,7 @@ class ScormAssessmentItem
/**
* Start document header
*/
function start_header()
public function start_header()
{
if ($this->standalone) {
return '<head>';
@ -755,7 +759,7 @@ class ScormAssessmentItem
/**
* Print CSS inclusion
*/
function css()
public function css()
{
$css = '';
if ($this->standalone) {
@ -775,7 +779,7 @@ class ScormAssessmentItem
/**
* End document header
*/
function end_header()
public function end_header()
{
if ($this->standalone) {
return '</head>';

@ -228,6 +228,7 @@ abstract class AbstractLink implements GradebookItem
* @param string $course_code
* @param integer $category_id
* @param integer $visible
* @return array
*/
public static function load(
$id = null,
@ -468,11 +469,14 @@ abstract class AbstractLink implements GradebookItem
// links can only be moved to categories inside this course
$targets = array();
$level = 0;
$crscats = Category::load(null, null, $this->get_course_code(), 0);
foreach ($crscats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
}
return $targets;
@ -487,7 +491,11 @@ abstract class AbstractLink implements GradebookItem
$subcats = Category::load(null, null, null, $catid);
foreach ($subcats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
}
return $targets;
}
@ -511,6 +519,7 @@ abstract class AbstractLink implements GradebookItem
* To keep consistency, do not call this method but LinkFactory::find_links instead.
* @todo can be written more efficiently using a new (but very complex) sql query
* @param string $name_mask
* @return array
*/
public function find_links($name_mask, $selectcat)
{
@ -622,6 +631,7 @@ abstract class AbstractLink implements GradebookItem
* @param int $userId
* @param array $studentList Array with user id and scores
* Example: [1 => 5.00, 2 => 8.00]
* @return array
*/
public static function getCurrentUserRanking($userId, $studentList)
{

@ -727,8 +727,8 @@ class Category implements GradebookItem
*/
public function delete()
{
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'DELETE FROM '.$tbl_grade_categories.' WHERE id = '.intval($this->id);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'DELETE FROM '.$table.' WHERE id = '.intval($this->id);
Database::query($sql);
}
@ -847,11 +847,9 @@ class Category implements GradebookItem
if (isset($score) && isset($score[0])) {
// Get a percentage score to compare to minimum certificate score
//$certification_score = $score[0] / $score[1] * 100;
// $certification_score = $score[0] / $score[1] * 100;
// Get real score not a percentage.
$certification_score = $score[0];
if ($certification_score >= $this->certificate_min_score) {
return true;
}
@ -874,6 +872,8 @@ class Category implements GradebookItem
* Calculate the score of this category
* @param integer $stud_id student id (default: all students - then the average is returned)
* @param integer $session_id
* @param string $course_code
* @param int $session_id
* @return array (score sum, weight sum)
* or null if no scores available
*/
@ -930,7 +930,6 @@ class Category implements GradebookItem
}
$students = array();
if (!empty($evals)) {
/** @var Evaluation $eval */
foreach ($evals as $eval) {
@ -1178,6 +1177,9 @@ class Category implements GradebookItem
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$course_code = Database::escape_string($course_code);
$session_id = (int) $session_id;
$sql = "SELECT * FROM $tbl_grade_categories WHERE parent_id = 0";
if (!api_is_allowed_to_edit()) {
@ -1189,9 +1191,9 @@ class Category implements GradebookItem
// session, we don't check his registration to these, but this
// could be an improvement
if (!empty($session_id)) {
$sql .= " AND course_code = '".Database::escape_string($course_code)."' AND session_id = ".(int) $session_id;
$sql .= " AND course_code = '".$course_code."' AND session_id = ".$session_id;
} else {
$sql .= " AND course_code = '".Database::escape_string($course_code)."' AND session_id is null OR session_id=0";
$sql .= " AND course_code = '".$course_code."' AND session_id is null OR session_id=0";
}
} else {
//no optional parameter, proceed as usual
@ -1211,9 +1213,9 @@ class Category implements GradebookItem
// if he doesn't have the rights to view this course and this
// session, we don't check his registration to these, but this
// could be an improvement
$sql .= " AND course_code = '".Database::escape_string($course_code)."'";
$sql .= " AND course_code = '".$course_code."'";
if (!empty($session_id)) {
$sql .= " AND session_id = ".(int) $session_id;
$sql .= " AND session_id = ".$session_id;
} else {
$sql .= "AND session_id IS NULL OR session_id=0";
}
@ -1230,7 +1232,7 @@ class Category implements GradebookItem
}
} elseif (api_is_platform_admin()) {
if (isset($session_id) && $session_id != 0) {
$sql .= ' AND session_id='.intval($session_id);
$sql .= ' AND session_id='.$session_id;
} else {
$sql .= ' AND coalesce(session_id,0)=0';
}
@ -1334,7 +1336,7 @@ class Category implements GradebookItem
// - category inside a course
// -> movable to root, independent categories or categories inside the course
$user = (api_is_platform_admin() ? null : api_get_user_id());
$user = api_is_platform_admin() ? null : api_get_user_id();
$targets = array();
$level = 0;
@ -1376,8 +1378,16 @@ class Category implements GradebookItem
$subcats = self::load(null, null, null, $catid);
foreach ($subcats as $cat) {
if ($this->can_be_moved_to_cat($cat)) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
$targets[] = array(
$cat->get_id(),
$cat->get_name(),
$level + 1
);
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
}
}
@ -1419,7 +1429,15 @@ class Category implements GradebookItem
{
$cats = self::load(null, null, null, $this->id, null);
$evals = Evaluation::load(null, null, null, $this->id, null);
$links = LinkFactory::load(null, null, null, null, null, $this->id, null);
$links = LinkFactory::load(
null,
null,
null,
null,
null,
$this->id,
null
);
foreach ($cats as $cat) {
$cat->set_course_code($this->get_course_code());
@ -1449,7 +1467,7 @@ class Category implements GradebookItem
// course or platform admin
if (api_is_allowed_to_edit()) {
$user = (api_is_platform_admin() ? null : api_get_user_id());
$user = api_is_platform_admin() ? null : api_get_user_id();
$cats = self::get_root_categories_for_teacher($user);
foreach ($cats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
@ -1479,8 +1497,17 @@ class Category implements GradebookItem
if (!empty($subcats)) {
foreach ($subcats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = self::add_subtree($targets, $level + 1, $cat->get_id(), $visible);
$targets[] = array(
$cat->get_id(),
$cat->get_name(),
$level + 1
);
$targets = self::add_subtree(
$targets,
$level + 1,
$cat->get_id(),
$visible
);
}
}
@ -1555,7 +1582,15 @@ class Category implements GradebookItem
{
$cats = self::load(null, null, null, $this->id, null);
$evals = Evaluation::load(null, null, null, $this->id, null);
$links = LinkFactory::load(null, null, null, null, null, $this->id, null);
$links = LinkFactory::load(
null,
null,
null,
null,
null,
$this->id,
null
);
if (!empty($cats)) {
foreach ($cats as $cat) {
$cat->set_visible($this->is_visible());
@ -1582,7 +1617,10 @@ class Category implements GradebookItem
*/
public function has_evaluations_with_results_for_student($stud_id)
{
$evals = Evaluation::get_evaluations_with_result_for_student($this->id, $stud_id);
$evals = Evaluation::get_evaluations_with_result_for_student(
$this->id,
$stud_id
);
if (count($evals) != 0) {
return true;
} else {
@ -1611,8 +1649,11 @@ class Category implements GradebookItem
* @param array $cats optional: if defined, the categories will be added to this array
* @return array
*/
public function get_independent_categories_with_result_for_student($cat_id, $stud_id, $cats = array())
{
public function get_independent_categories_with_result_for_student(
$cat_id,
$stud_id,
$cats = array()
) {
$creator = api_is_allowed_to_edit() && !api_is_platform_admin() ? api_get_user_id() : null;
$crsindcats = self::load(
@ -1652,8 +1693,12 @@ class Category implements GradebookItem
* @return array Array of subcategories
*/
public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null)
{
public function get_subcategories(
$stud_id = null,
$course_code = null,
$session_id = null,
$order = null
) {
if (!empty($session_id)) {
/*$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT id FROM '.$tbl_grade_categories. ' WHERE session_id = '.$session_id;
@ -1819,7 +1864,6 @@ class Category implements GradebookItem
$this->id,
api_is_allowed_to_edit() ? null : 1
);
//} elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) {
} else {
// All students -> only for course/platform admin
$links = LinkFactory::load(

@ -7,14 +7,15 @@
/**
* Prints an HTML page with a table containing the gradebook data
* @param array Array containing the data to be printed in the table
* @param array Table headers
* @param string View to print as a title for the table
* @param string Course name to print as title for the table
* @param array Array containing the data to be printed in the table
* @param array Table headers
* @param string View to print as a title for the table
* @param string Course name to print as title for the table
* @return string
*/
function print_table($data_array, $header_names, $view, $coursename)
{
$printdata = '<!DOCTYPE html
$printdata = '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
@ -25,10 +26,10 @@ function print_table($data_array, $header_names, $view, $coursename)
<style type="text/css">
body {
font-size: 12px;
color: #000;
margin: 10px;
padding: 0;
font-size: 12px;
color: #000;
margin: 10px;
padding: 0;
}
a:link {text-decoration: none; font-weight : bold; color : black;}
@ -36,31 +37,31 @@ a:visited {text-decoration: none; font-weight : bold; color : black;}
a:active {text-decoration: none; font-weight : bold; color : black;}
.data_table{
border-collapse: collapse;
width: 100%;
padding: 5px;
border: 1px;
border-collapse: collapse;
width: 100%;
padding: 5px;
border: 1px;
}
.data_table th{
padding: 5px;
vertical-align: top;
border-top: 1px solid black;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
padding: 5px;
vertical-align: top;
border-top: 1px solid black;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
}
.data_table tr.row_odd{
background-color: #fafafa;
background-color: #fafafa;
}
.data_table tr.row_even{
background-color: #fff;
background-color: #fff;
}
.data_table td{
padding: 5px;
vertical-align: top;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
padding: 5px;
vertical-align: top;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
}
</style>
</head>
@ -98,13 +99,13 @@ a:active {text-decoration: none; font-weight : bold; color : black;}
function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf)
{
$mpdf = new mPDF('UTF-8', 'A4-L', '', '', 15, 10, 35, 20, 4, 2, 'L');
$mpdf->useOnlyCoreFonts = true;
$mpdf->mirrorMargins = 0;
// Use different Odd/Even headers and footers and mirror margins
$mpdf->useOnlyCoreFonts = true;
$mpdf->mirrorMargins = 0;
if (is_array($headers_pdf)) {
// preparing headers pdf
$header = '
// Use different Odd/Even headers and footers and mirror margins
if (is_array($headers_pdf)) {
// preparing headers pdf
$header = '
<table width="100%" cellspacing="1" cellpadding="1" border="0" class="strong">
<tr>
<td ROWSPAN="3" style="text-align: left;" class="title">
@ -159,7 +160,7 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
$items_per_page = count($data_table);
}
$count_pages = ceil(count($data_table) / $items_per_page);
$count_pages = ceil(count($data_table) / $items_per_page);
$content_table = '';
for ($x = 0; $x < $count_pages; $x++) {
$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
@ -167,7 +168,6 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
$content_table .= '<tr>';
$i = 0;
if (is_array($headers_table)) {
foreach ($headers_table as $head_table) {
if (!empty($head_table[0])) {
$width = (!empty($head_table[1]) ? $head_table[1].'%' : '');
@ -186,7 +186,7 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
foreach ($data_table as $data) {
$content_table .= '<tr>';
$content_table .= '<td>'.($item < 10 ? '0'.$item : $item).'</td>';
foreach ($data as $key => $content) {
foreach ($data as $key => $content) {
if (isset($content)) {
$key == 1 ? $align = 'align="left"' : $align = 'align="center"';
$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
@ -195,13 +195,17 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
$content_table .= '</tr>';
$i++;
$item++;
if ($i > $items_per_page) { break; }
if ($i > $items_per_page) {
break;
}
}
} else {
$content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
}
$content_table .= '</table>';
if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
if ($x < ($count_pages - 1)) {
$content_table .= '<pagebreak />';
}
}
$html = $content_table;
@ -219,13 +223,12 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
exit;
}
/**
* This function get a content html for export inside a pdf file
* @param array table headers
* @param array table body
* @param array pdf headers
* @param array pdf footers
* @param array table headers
* @param array table body
* @param array pdf headers
* @param array pdf footers
* @return void
*/
function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf)
@ -293,7 +296,7 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
foreach ($data_table as $data) {
$content_table .= '<tr>';
$content_table .= '<td>'.($item < 10 ? '0'.$item : $item).'</td>';
foreach ($data as $key => $content) {
foreach ($data as $key => $content) {
if (isset($content)) {
$key == 1 ? $align = 'align="left"' : $align = 'align="center"';
$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
@ -302,13 +305,17 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
$content_table .= '</tr>';
$i++;
$item++;
if ($i > $items_per_page) { break; }
if ($i > $items_per_page) {
break;
}
}
} else {
$content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
}
$content_table .= '</table>';
if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
if ($x < ($count_pages - 1)) {
$content_table .= '<pagebreak />';
}
}
$pdf = new PDF();
$pdf->set_custom_footer($footer);
@ -320,17 +327,17 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
/**
* Exports the data as a table on a PDF page
* @param resource The PDF object (ezpdf class) used to generate the file
* @param array The data array
* @param array Table headers
* @param string Format (portrait or landscape)
* @param resource The PDF object (ezpdf class) used to generate the file
* @param array The data array
* @param array Table headers
* @param string Format (portrait or landscape)
*/
function export_pdf($pdf, $newarray, $header_names, $format)
{
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetCmMargins(0, 0, 0, 0);
$pdf->ezSetY(($format == 'portrait') ? '820' : '570');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetCmMargins(0, 0, 0, 0);
$pdf->ezSetY(($format == 'portrait') ? '820' : '570');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
if ($format == 'portrait') {
$pdf->line(40, 790, 540, 790);
$pdf->line(40, 40, 540, 40);
@ -346,5 +353,5 @@ function export_pdf($pdf, $newarray, $header_names, $format)
'rowGap' => 3,
'width' => (($format == 'portrait') ? '500' : '750'),
));
$pdf->ezStream();
$pdf->ezStream();
}

@ -99,8 +99,12 @@ class Attendance
* @see SortableTable#get_table_data($from)
* @return array
*/
public static function get_attendance_data($from, $number_of_items, $column, $direction)
{
public static function get_attendance_data(
$from,
$number_of_items,
$column,
$direction
) {
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();

@ -4,9 +4,9 @@
use Symfony\Component\Filesystem\Filesystem;
/**
* This is the file manage library for Chamilo.
* Include/require it in your code to use its functionality.
* @package chamilo.library
* This is the file manage library for Chamilo.
* Include/require it in your code to use its functionality.
* @package chamilo.library
*/
/**
@ -66,7 +66,7 @@ function my_delete($file)
* @author Amary <MasterNES@aol.com> (from Nexen.net)
* @author Olivier Brouckaert <oli.brouckaert@skynet.be>
*
* @param string $dir directory to remove
* @param string $dir directory to remove
*/
function removeDir($dir)
{
@ -130,40 +130,40 @@ function folder_is_empty($in_folder)
* @return boolean true if succeed, false otherwise
* @see rename() uses the check_name_exist() and php2phps() functions
*/
function my_rename($file_path, $new_file_name) {
$save_dir = getcwd();
$path = dirname($file_path);
$old_file_name = basename($file_path);
$new_file_name = api_replace_dangerous_char($new_file_name);
function my_rename($file_path, $new_file_name)
{
$save_dir = getcwd();
$path = dirname($file_path);
$old_file_name = basename($file_path);
$new_file_name = api_replace_dangerous_char($new_file_name);
// If no extension, take the old one
if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
$new_file_name .= substr($old_file_name, $dotpos);
}
// If no extension, take the old one
if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
$new_file_name .= substr($old_file_name, $dotpos);
}
// Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
// This is useful for folder names, where otherwise '.' would be sticky
// Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
// This is useful for folder names, where otherwise '.' would be sticky
// Extension PHP is not allowed, change to PHPS
$new_file_name = php2phps($new_file_name);
// Extension PHP is not allowed, change to PHPS
$new_file_name = php2phps($new_file_name);
if ($new_file_name == $old_file_name) {
return $old_file_name;
}
if ($new_file_name == $old_file_name) {
return $old_file_name;
}
if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
return false;
}
// On a Windows server, it would be better not to do the above check
// because it succeeds for some new names resembling the old name.
// But on Unix/Linux the check must be done because rename overwrites.
if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
return false;
}
// On a Windows server, it would be better not to do the above check
// because it succeeds for some new names resembling the old name.
// But on Unix/Linux the check must be done because rename overwrites.
chdir($path);
$res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
chdir($save_dir);
chdir($path);
$res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
chdir($save_dir);
return $res;
return $res;
}
/**
@ -214,14 +214,16 @@ function move($source, $target, $forceMove = true, $moveContent = false)
if ($forceMove && !$isWindowsOS && $canExec) {
if ($moveContent) {
$base = basename($source);
$out = []; $retVal = -1;
$out = [];
$retVal = -1;
exec('mv '.$source.'/* '.$target.'/'.$base, $out, $retVal);
if ($retVal !== 0) {
return false; // mv should return 0 on success
}
exec('rm -rf '.$source);
} else {
$out = []; $retVal = -1;
$out = [];
$retVal = -1;
exec("mv $source $target", $out, $retVal);
if ($retVal !== 0) {
error_log("Chamilo error fileManage.lib.php: mv $source $target\n");
@ -267,33 +269,34 @@ function copyDirTo($source, $destination, $move = true)
* Extracting extension of a filename
*
* @returns array
* @param string $filename filename
* @param string $filename filename
*/
function getextension($filename)
{
$bouts = explode('.', $filename);
return array(array_pop($bouts), implode('.', $bouts));
$bouts = explode('.', $filename);
return array(array_pop($bouts), implode('.', $bouts));
}
/**
* Calculation size of a directory
*
* @returns integer size
* @param string $root path of dir to measure
* @param boolean $recursive if true , include subdirectory in total
* @param string $root path of dir to measure
* @param boolean $recursive if true , include subdirectory in total
*/
function dirsize($root, $recursive = true) {
$dir = @opendir($root);
$size = 0;
while ($file = @readdir($dir)) {
if (!in_array($file, array('.', '..'))) {
if (is_dir($root.'/'.$file)) {
$size += $recursive ? dirsize($root.'/'.$file) : 0;
} else {
$size += @filesize($root.'/'.$file);
}
}
}
@closedir($dir);
return $size;
function dirsize($root, $recursive = true)
{
$dir = @opendir($root);
$size = 0;
while ($file = @readdir($dir)) {
if (!in_array($file, array('.', '..'))) {
if (is_dir($root.'/'.$file)) {
$size += $recursive ? dirsize($root.'/'.$file) : 0;
} else {
$size += @filesize($root.'/'.$file);
}
}
}
@closedir($dir);
return $size;
}

@ -101,9 +101,14 @@ class MessageManager
* @param int $from
* @param int $number_of_items
* @param string $direction
* @return array
*/
public static function get_message_data($from, $number_of_items, $column, $direction)
{
public static function get_message_data(
$from,
$number_of_items,
$column,
$direction
) {
$from = intval($from);
$number_of_items = intval($number_of_items);
@ -497,9 +502,9 @@ class MessageManager
if (!empty($drhList)) {
foreach ($drhList as $drhInfo) {
$message = sprintf(
get_lang('CopyOfMessageSentToXUser'),
$userInfo['complete_name']
).' <br />'.$message;
get_lang('CopyOfMessageSentToXUser'),
$userInfo['complete_name']
).' <br />'.$message;
self::send_message_simple(
$drhInfo['user_id'],
@ -633,7 +638,6 @@ class MessageManager
* @param int receiver user id (optional)
* @param int sender user id (optional)
* @param int group id (optional)
* @return void
*/
public static function save_message_attachment_file(
$file_attach,
@ -662,7 +666,6 @@ class MessageManager
// User-reserved directory where photos have to be placed.*
$userGroup = new UserGroup();
if (!empty($group_id)) {
$path_user_info = $userGroup->get_group_picture_path_by_id($group_id, 'system', true);
} else {
@ -697,7 +700,6 @@ class MessageManager
* @param int message id
* @param int message user id (receiver user id or sender user id)
* @param int group id (optional)
* @return void
*/
public static function delete_message_attachment_file(
$message_id,
@ -917,8 +919,9 @@ class MessageManager
*/
public static function exist_message($user_id, $id)
{
if ($id != strval(intval($id)) || $user_id != strval(intval($user_id)))
if ($id != strval(intval($id)) || $user_id != strval(intval($user_id))) {
return false;
}
$table_message = Database::get_main_table(TABLE_MESSAGE);
$query = "SELECT id FROM $table_message
WHERE
@ -940,8 +943,12 @@ class MessageManager
* @param string
* @return array
*/
public static function get_message_data_sent($from, $number_of_items, $column, $direction)
{
public static function get_message_data_sent(
$from,
$number_of_items,
$column,
$direction
) {
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!isset($direction)) {
@ -1087,7 +1094,10 @@ class MessageManager
$user_sender_id = $row['user_sender_id'];
// get file attachments by message id
$files_attachments = self::get_links_message_attachment_files($message_id, $source);
$files_attachments = self::get_links_message_attachment_files(
$message_id,
$source
);
$title = Security::remove_XSS($row['title'], STUDENT, true);
$content = Security::remove_XSS($row['content'], STUDENT, true);
@ -1251,7 +1261,8 @@ class MessageManager
Display::url(
Security::remove_XSS($topic['title'], STUDENT, true),
api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$group_id.'&topic_id='.$topic['id']
), array('class' => 'title')
),
array('class' => 'title')
);
$actions = '';
if ($my_group_role == GROUP_USER_PERMISSION_ADMIN ||
@ -1558,8 +1569,12 @@ class MessageManager
* @param int indent for nested view
* @return void
*/
public static function message_recursive_sort($rows, &$messages, $seed = 0, $indent = 0)
{
public static function message_recursive_sort(
$rows,
&$messages,
$seed = 0,
$indent = 0
) {
if ($seed > 0 && isset($rows[$seed]["id"])) {
$messages[$rows[$seed]["id"]] = $rows[$seed];
$messages[$rows[$seed]["id"]]["indent_cnt"] = $indent;
@ -1647,8 +1662,17 @@ class MessageManager
public static function generate_message_form()
{
$form = new FormValidator('send_message');
$form->addText('subject', get_lang('Subject'), false, ['id' => 'subject_id']);
$form->addTextarea('content', get_lang('Message'), ['id' => 'content_id', 'rows' => '5']);
$form->addText(
'subject',
get_lang('Subject'),
false,
['id' => 'subject_id']
);
$form->addTextarea(
'content',
get_lang('Message'),
['id' => 'content_id', 'rows' => '5']
);
return $form->returnForm();
}
@ -1661,7 +1685,11 @@ class MessageManager
public static function generate_invitation_form($id, $params = array())
{
$form = new FormValidator('send_invitation');
$form->addTextarea('content', get_lang('AddPersonalMessage'), ['id' => 'content_invitation_id', 'rows' => 5]);
$form->addTextarea(
'content',
get_lang('AddPersonalMessage'),
['id' => 'content_invitation_id', 'rows' => 5]
);
return $form->returnForm();
}
@ -1682,16 +1710,22 @@ class MessageManager
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'mark_as_unread' :
$number_of_selected_messages = count($_POST['id']);
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $index => $message_id) {
self::update_message_status(api_get_user_id(), $message_id, MESSAGE_STATUS_UNREAD);
self::update_message_status(
api_get_user_id(),
$message_id,
MESSAGE_STATUS_UNREAD
);
}
}
$html .= Display::return_message(api_xml_http_response_encode($success_unread), 'normal', false);
$html .= Display::return_message(
api_xml_http_response_encode($success_unread),
'normal',
false
);
break;
case 'mark_as_read' :
$number_of_selected_messages = count($_POST['id']);
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $index => $message_id) {
self::update_message_status(api_get_user_id(), $message_id, MESSAGE_STATUS_NEW);
@ -1700,7 +1734,6 @@ class MessageManager
$html .= Display::return_message(api_xml_http_response_encode($success_read), 'normal', false);
break;
case 'delete' :
$number_of_selected_messages = count($_POST['id']);
foreach ($_POST['id'] as $index => $message_id) {
self::delete_message_by_user_receiver(api_get_user_id(), $message_id);
}
@ -1903,7 +1936,12 @@ class MessageManager
)
);
$result = Database::select('COUNT(1) AS qty', $messageAttachmentTable, $conditions, 'first');
$result = Database::select(
'COUNT(1) AS qty',
$messageAttachmentTable,
$conditions,
'first'
);
if (!empty($result)) {
if ($result['qty'] > 0) {
@ -1955,7 +1993,10 @@ class MessageManager
);
$tplMailBody->assign('user', $user);
$tplMailBody->assign('is_western_name_order', api_is_western_name_order());
$tplMailBody->assign('manageUrl', api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user->getId());
$tplMailBody->assign(
'manageUrl',
api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user->getId()
);
$layoutContent = $tplMailBody->get_template('mail/new_user_mail_to_admin.tpl');

@ -7,6 +7,7 @@
* Once external libraries are moved to their own directory it would be worth
* moving them to their own files under a common portfolio directory.
* @package chamilo.portfolio
* @deprecated
*/
/**
* Init

@ -666,8 +666,13 @@ class SessionManager
* @param array options order and limit keys
* @return array table with user name, lp name, progress
*/
public static function get_session_lp_progress($sessionId = 0, $courseId = 0, $date_from, $date_to, $options)
{
public static function get_session_lp_progress(
$sessionId = 0,
$courseId = 0,
$date_from,
$date_to,
$options
) {
//escaping vars
$sessionId = $sessionId == 'T' ? 'T' : intval($sessionId);
$courseId = intval($courseId);

Loading…
Cancel
Save