Passed
Push — 1.10.x ( e22269...acc912 )
by
unknown
49:56
created
main/wiki/wiki.inc.php 1 patch
Spacing   +647 added lines, -647 removed lines patch added patch discarded remove patch
@@ -99,25 +99,25 @@  discard block
 block discarded – undo
99 99
      **/
100 100
     public function links_to($input)
101 101
     {
102
-        $input_array = preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE);
102
+        $input_array = preg_split("/(\[\[|\]\])/", $input, -1, PREG_SPLIT_DELIM_CAPTURE);
103 103
         $all_links = array();
104 104
 
105 105
         foreach ($input_array as $key=>$value) {
106
-            if (isset($input_array[$key-1]) && $input_array[$key-1] == '[[' &&
107
-                isset($input_array[$key+1]) && $input_array[$key+1] == ']]'
106
+            if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' &&
107
+                isset($input_array[$key + 1]) && $input_array[$key + 1] == ']]'
108 108
             ) {
109 109
                 if (api_strpos($value, "|") !== false) {
110
-                    $full_link_array=explode("|", $value);
111
-                    $link=trim($full_link_array[0]);
112
-                    $title=trim($full_link_array[1]);
110
+                    $full_link_array = explode("|", $value);
111
+                    $link = trim($full_link_array[0]);
112
+                    $title = trim($full_link_array[1]);
113 113
                 } else {
114
-                    $link=trim($value);
115
-                    $title=trim($value);
114
+                    $link = trim($value);
115
+                    $title = trim($value);
116 116
                 }
117
-                unset($input_array[$key-1]);
118
-                unset($input_array[$key+1]);
117
+                unset($input_array[$key - 1]);
118
+                unset($input_array[$key + 1]);
119 119
                 //replace blank spaces by _ within the links. But to remove links at the end add a blank space
120
-                $all_links[]= Database::escape_string(str_replace(' ','_',$link)).' ';
120
+                $all_links[] = Database::escape_string(str_replace(' ', '_', $link)).' ';
121 121
             }
122 122
         }
123 123
         $output = implode($all_links);
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
      **/
132 132
     public function detect_external_link($input)
133 133
     {
134
-        $exlink='href=';
135
-        $exlinkStyle='class="wiki_link_ext" href=';
136
-        $output=str_replace($exlink, $exlinkStyle, $input);
134
+        $exlink = 'href=';
135
+        $exlinkStyle = 'class="wiki_link_ext" href=';
136
+        $output = str_replace($exlink, $exlinkStyle, $input);
137 137
         return $output;
138 138
     }
139 139
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     public function detect_anchor_link($input)
145 145
     {
146 146
         $anchorlink = 'href="#';
147
-        $anchorlinkStyle='class="wiki_anchor_link" href="#';
147
+        $anchorlinkStyle = 'class="wiki_anchor_link" href="#';
148 148
         $output = str_replace($anchorlink, $anchorlinkStyle, $input);
149 149
 
150 150
         return $output;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      **/
170 170
     public function detect_ftp_link($input)
171 171
     {
172
-        $ftplink='href="ftp';
172
+        $ftplink = 'href="ftp';
173 173
         $ftplinkStyle = 'class="wiki_ftp_link" href="ftp';
174 174
         $output = str_replace($ftplink, $ftplinkStyle, $input);
175 175
 
@@ -214,21 +214,21 @@  discard block
 block discarded – undo
214 214
     {
215 215
         $groupId = api_get_group_id();
216 216
         //now doubles brackets
217
-        $input_array = preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE);
217
+        $input_array = preg_split("/(\[\[|\]\])/", $input, -1, PREG_SPLIT_DELIM_CAPTURE);
218 218
 
219 219
         foreach ($input_array as $key => $value) {
220 220
             //now doubles brackets
221
-            if (isset($input_array[$key-1]) && $input_array[$key-1] == '[[' AND
222
-                $input_array[$key+1] == ']]'
221
+            if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' AND
222
+                $input_array[$key + 1] == ']]'
223 223
             ) {
224 224
                 // now full wikilink
225
-                if (api_strpos($value, "|") !== false){
226
-                    $full_link_array=explode("|", $value);
227
-                    $link=trim(strip_tags($full_link_array[0]));
228
-                    $title=trim($full_link_array[1]);
225
+                if (api_strpos($value, "|") !== false) {
226
+                    $full_link_array = explode("|", $value);
227
+                    $link = trim(strip_tags($full_link_array[0]));
228
+                    $title = trim($full_link_array[1]);
229 229
                 } else {
230
-                    $link=trim(strip_tags($value));
231
-                    $title=trim($value);
230
+                    $link = trim(strip_tags($value));
231
+                    $title = trim($value);
232 232
                 }
233 233
 
234 234
                 //if wikilink is homepage
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
                 }
241 241
 
242 242
                 // note: checkreflink checks if the link is still free. If it is not used then it returns true, if it is used, then it returns false. Now the title may be different
243
-                if (self::checktitle(strtolower(str_replace(' ','_',$link)))) {
243
+                if (self::checktitle(strtolower(str_replace(' ', '_', $link)))) {
244 244
                     $link = api_html_entity_decode($link);
245
-                    $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=addnew&amp;title='.Security::remove_XSS($link).'&group_id='.$groupId.'" class="new_wiki_link">'.$title.'</a>';
245
+                    $input_array[$key] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=addnew&amp;title='.Security::remove_XSS($link).'&group_id='.$groupId.'" class="new_wiki_link">'.$title.'</a>';
246 246
                 } else {
247
-                    $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=showpage&amp;title='.urlencode(strtolower(str_replace(' ','_',$link))).'&group_id='.$groupId.'" class="wiki_link">'.$title.'</a>';
247
+                    $input_array[$key] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=showpage&amp;title='.urlencode(strtolower(str_replace(' ', '_', $link))).'&group_id='.$groupId.'" class="wiki_link">'.$title.'</a>';
248 248
                 }
249
-                unset($input_array[$key-1]);
250
-                unset($input_array[$key+1]);
249
+                unset($input_array[$key - 1]);
250
+                unset($input_array[$key + 1]);
251 251
             }
252 252
         }
253
-        $output = implode('',$input_array);
253
+        $output = implode('', $input_array);
254 254
         return $output;
255 255
     }
256 256
 
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
         // are not made here, but through the interce buttons
293 293
 
294 294
         // cleaning the variables
295
-        if (api_get_setting('htmlpurifier_wiki') == 'true'){
295
+        if (api_get_setting('htmlpurifier_wiki') == 'true') {
296 296
             //$purifier = new HTMLPurifier();
297 297
             $values['content'] = Security::remove_XSS($values['content']);
298 298
         }
299
-        $version = intval($values['version']) + 1 ;
299
+        $version = intval($values['version']) + 1;
300 300
         $linkTo = self::links_to($values['content']); //and check links content
301 301
 
302 302
         //cleaning config variables
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             $_clean['startdate_assig'] = '0000-00-00 00:00:00';
320 320
         }
321 321
 
322
-        if (isset($values['initenddate']) && $values['initenddate']==1) {
322
+        if (isset($values['initenddate']) && $values['initenddate'] == 1) {
323 323
             $_clean['enddate_assig'] = $values['enddate_assig'];
324 324
         } else {
325 325
             $_clean['enddate_assig'] = '0000-00-00 00:00:00';
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
         }
331 331
 
332 332
         if (!empty($values['max_text']) || !empty($values['max_version'])) {
333
-            $_clean['max_text']	= $values['max_text'];
333
+            $_clean['max_text'] = $values['max_text'];
334 334
             $_clean['max_version'] = $values['max_version'];
335 335
         }
336 336
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
                 $groupId
382 382
             );
383 383
 
384
-            if ($values['page_id']== 0) {
384
+            if ($values['page_id'] == 0) {
385 385
                 $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
386 386
                         WHERE c_id = '.$course_id.' AND iid ="'.$id.'"';
387 387
                 Database::query($sql);
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
         $_course = $this->courseInfo;
466 466
         $r_user_id = api_get_user_id();
467 467
         $r_dtime = api_get_utc_datetime();
468
-        $r_version = $r_version+1;
468
+        $r_version = $r_version + 1;
469 469
         $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
470 470
         $session_id = api_get_session_id();
471 471
         $course_id = api_get_course_int_id();
@@ -570,9 +570,9 @@  discard block
 block discarded – undo
570 570
         // Unlike ordinary pages of pages of assignments.
571 571
         // Allow create a ordinary page although there is a assignment with the same name
572 572
         if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) {
573
-            $page = str_replace(' ','_',$values['title']."_uass".$assig_user_id);
573
+            $page = str_replace(' ', '_', $values['title']."_uass".$assig_user_id);
574 574
         } else {
575
-            $page = str_replace(' ','_',$values['title']);
575
+            $page = str_replace(' ', '_', $values['title']);
576 576
         }
577 577
         $_clean['reflink'] = $page;
578 578
         $_clean['title']   = trim($values['title']);
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 
609 609
         $groupId = api_get_group_id();
610 610
 
611
-        $_clean['linksto'] = self::links_to($_clean['content']);	//check wikilinks
611
+        $_clean['linksto'] = self::links_to($_clean['content']); //check wikilinks
612 612
 
613 613
         // cleaning config variables
614 614
         $_clean['task'] = isset($values['task']) ? $values['task'] : '';
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      */
725 725
     public function setForm($form, $row = array())
726 726
     {
727
-        $toolBar = api_is_allowed_to_edit(null,true)
727
+        $toolBar = api_is_allowed_to_edit(null, true)
728 728
             ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400')
729 729
             : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student');
730 730
 
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 
736 736
         $form->addElement('select', 'progress', get_lang('Progress'), $progress);
737 737
 
738
-        if ((api_is_allowed_to_edit(false,true) ||
738
+        if ((api_is_allowed_to_edit(false, true) ||
739 739
             api_is_platform_admin()) &&
740 740
             isset($row['reflink']) && $row['reflink'] != 'index'
741 741
         ) {
@@ -875,13 +875,13 @@  discard block
 block discarded – undo
875 875
         if ($newtitle) {
876 876
             $pageMIX = $newtitle; //display the page after it is created
877 877
         } else {
878
-            $pageMIX = $page;//display current page
878
+            $pageMIX = $page; //display current page
879 879
         }
880 880
 
881 881
         $filter = null;
882 882
         if (isset($_GET['view']) && $_GET['view']) {
883 883
             $_clean['view'] = Database::escape_string($_GET['view']);
884
-            $filter =' AND w.id="'.$_clean['view'].'"';
884
+            $filter = ' AND w.id="'.$_clean['view'].'"';
885 885
         }
886 886
 
887 887
         // First, check page visibility in the first page version
@@ -923,14 +923,14 @@  discard block
 block discarded – undo
923 923
         }
924 924
 
925 925
         // if both are empty and we are displaying the index page then we display the default text.
926
-        if ($row['content']=='' && $row['title']=='' && $page=='index') {
926
+        if ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
927 927
             if (api_is_allowed_to_edit(false, true) ||
928 928
                 api_is_platform_admin() ||
929 929
                 GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())
930 930
             ) {
931 931
                 //Table structure for better export to pdf
932
-                $default_table_for_content_Start='<table align="center" border="0"><tr><td align="center">';
933
-                $default_table_for_content_End='</td></tr></table>';
932
+                $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
933
+                $default_table_for_content_End = '</td></tr></table>';
934 934
                 $content = $default_table_for_content_Start.
935 935
                     sprintf(get_lang('DefaultContent'), api_get_path(WEB_IMG_PATH)).
936 936
                     $default_table_for_content_End;
@@ -945,23 +945,23 @@  discard block
 block discarded – undo
945 945
 
946 946
         //assignment mode: identify page type
947 947
         $icon_assignment = null;
948
-        if ($row['assignment']==1) {
949
-            $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
950
-        } elseif($row['assignment']==2) {
951
-            $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
948
+        if ($row['assignment'] == 1) {
949
+            $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
950
+        } elseif ($row['assignment'] == 2) {
951
+            $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
952 952
         }
953 953
 
954 954
         //task mode
955 955
         $icon_task = null;
956 956
         if (!empty($row['task'])) {
957
-            $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
957
+            $icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL);
958 958
         }
959 959
 
960 960
         // Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
961 961
         if ($KeyVisibility == "1" ||
962 962
             api_is_allowed_to_edit(false, true) ||
963 963
             api_is_platform_admin() ||
964
-            ($row['assignment'] == 2 && $KeyVisibility=="0" && (api_get_user_id() == $row['user_id']))
964
+            ($row['assignment'] == 2 && $KeyVisibility == "0" && (api_get_user_id() == $row['user_id']))
965 965
         ) {
966 966
             $actionsLeft = '';
967 967
 
@@ -986,13 +986,13 @@  discard block
 block discarded – undo
986 986
             $protect_page = null;
987 987
             $lock_unlock_protect = null;
988 988
             // page action: protecting (locking) the page
989
-            if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
990
-                if (self::check_protect_page()==1) {
989
+            if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
990
+                if (self::check_protect_page() == 1) {
991 991
                     $protect_page = Display::return_icon('lock.png', get_lang('PageLockedExtra'), '', ICON_SIZE_MEDIUM);
992
-                    $lock_unlock_protect='unlock';
992
+                    $lock_unlock_protect = 'unlock';
993 993
                 } else {
994 994
                     $protect_page = Display::return_icon('unlock.png', get_lang('PageUnlockedExtra'), '', ICON_SIZE_MEDIUM);
995
-                    $lock_unlock_protect='lock';
995
+                    $lock_unlock_protect = 'lock';
996 996
                 }
997 997
             }
998 998
 
@@ -1004,13 +1004,13 @@  discard block
 block discarded – undo
1004 1004
             $visibility_page = null;
1005 1005
             $lock_unlock_visibility = null;
1006 1006
             //page action: visibility
1007
-            if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1007
+            if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1008 1008
                 if (self::check_visibility_page() == 1) {
1009
-                    $visibility_page = Display::return_icon('visible.png', get_lang('ShowPageExtra'),'', ICON_SIZE_MEDIUM);
1009
+                    $visibility_page = Display::return_icon('visible.png', get_lang('ShowPageExtra'), '', ICON_SIZE_MEDIUM);
1010 1010
                     $lock_unlock_visibility = 'invisible';
1011 1011
 
1012 1012
                 } else {
1013
-                    $visibility_page = Display::return_icon('invisible.png', get_lang('HidePageExtra'),'', ICON_SIZE_MEDIUM);
1013
+                    $visibility_page = Display::return_icon('invisible.png', get_lang('HidePageExtra'), '', ICON_SIZE_MEDIUM);
1014 1014
                     $lock_unlock_visibility = 'visible';
1015 1015
                 }
1016 1016
             }
@@ -1022,11 +1022,11 @@  discard block
 block discarded – undo
1022 1022
 
1023 1023
             //page action: notification
1024 1024
             if (api_is_allowed_to_session_edit()) {
1025
-                if (self::check_notify_page($page)==1) {
1026
-                    $notify_page = Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'),'',ICON_SIZE_MEDIUM);
1025
+                if (self::check_notify_page($page) == 1) {
1026
+                    $notify_page = Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'), '', ICON_SIZE_MEDIUM);
1027 1027
                     $lock_unlock_notify_page = 'unlocknotify';
1028 1028
                 } else {
1029
-                    $notify_page = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'),'',ICON_SIZE_MEDIUM);
1029
+                    $notify_page = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'), '', ICON_SIZE_MEDIUM);
1030 1030
                     $lock_unlock_notify_page = 'locknotify';
1031 1031
                 }
1032 1032
             }
@@ -1038,33 +1038,33 @@  discard block
 block discarded – undo
1038 1038
                 ) {
1039 1039
                     // menu discuss page
1040 1040
                     $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=discuss&title='.api_htmlentities(urlencode($page)).'" '.self::is_active_navigation_tab('discuss').'>'.
1041
-                        Display::return_icon('discuss.png',get_lang('DiscussThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
1041
+                        Display::return_icon('discuss.png', get_lang('DiscussThisPage'), '', ICON_SIZE_MEDIUM).'</a>';
1042 1042
                 }
1043 1043
 
1044 1044
                 //menu history
1045 1045
                 $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=history&title='.api_htmlentities(urlencode($page)).'" '.self::is_active_navigation_tab('history').'>'.
1046
-                    Display::return_icon('history.png',get_lang('ShowPageHistory'),'',ICON_SIZE_MEDIUM).'</a>';
1046
+                    Display::return_icon('history.png', get_lang('ShowPageHistory'), '', ICON_SIZE_MEDIUM).'</a>';
1047 1047
                 //menu linkspages
1048 1048
                 $actionsRight .= '<a href="index.php?'.api_get_cidreq().'action=links&title='.api_htmlentities(urlencode($page)).'" '.self::is_active_navigation_tab('links').'>'.
1049
-                    Display::return_icon('what_link_here.png',get_lang('LinksPages'),'',ICON_SIZE_MEDIUM).'</a>';
1049
+                    Display::return_icon('what_link_here.png', get_lang('LinksPages'), '', ICON_SIZE_MEDIUM).'</a>';
1050 1050
 
1051 1051
                 //menu delete wikipage
1052
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1052
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1053 1053
                     $actionsRight .= '<a href="index.php?action=delete&'.api_get_cidreq().'&title='.api_htmlentities(urlencode($page)).'"'.self::is_active_navigation_tab('delete').'>'.
1054
-                        Display::return_icon('delete.png',get_lang('DeleteThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
1054
+                        Display::return_icon('delete.png', get_lang('DeleteThisPage'), '', ICON_SIZE_MEDIUM).'</a>';
1055 1055
                 }
1056 1056
 
1057 1057
                 $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_notify_page.'&title='.api_htmlentities(urlencode($page)).'">'.
1058 1058
                     $notify_page.'</a>';
1059 1059
 
1060 1060
                 // Page action: copy last version to doc area
1061
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1061
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1062 1062
                     $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export2doc&wiki_id='.$row['id'].'">'.
1063 1063
                         Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), '', ICON_SIZE_MEDIUM).'</a>';
1064 1064
                 }
1065 1065
 
1066 1066
                 $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf&wiki_id='.$row['id'].'">'.
1067
-                    Display::return_icon('pdf.png',get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a>';
1067
+                    Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
1068 1068
 
1069 1069
                 $unoconv = api_get_configuration_value('unoconv.binaries');
1070 1070
                 if ($unoconv) {
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
                     )
1121 1121
                 );
1122 1122
 
1123
-            $footerWiki = '<div id="wikifooter">'.get_lang('Progress').': '.($row['progress']*10).'%&nbsp;&nbsp;&nbsp;'.get_lang('Rating').': '.$row['score'].'&nbsp;&nbsp;&nbsp;'.get_lang('Words').': '.self::word_count($content).'</div>';
1123
+            $footerWiki = '<div id="wikifooter">'.get_lang('Progress').': '.($row['progress'] * 10).'%&nbsp;&nbsp;&nbsp;'.get_lang('Rating').': '.$row['score'].'&nbsp;&nbsp;&nbsp;'.get_lang('Words').': '.self::word_count($content).'</div>';
1124 1124
 
1125 1125
             echo Display::panel($pageWiki, $pageTitle, $footerWiki);
1126 1126
         } //end filter visibility
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 
1145 1145
         # strip all html tags
1146 1146
         $wc = strip_tags($document);
1147
-        $wc = html_entity_decode($wc, ENT_NOQUOTES, 'UTF-8');// TODO:test also old html_entity_decode(utf8_encode($wc))
1147
+        $wc = html_entity_decode($wc, ENT_NOQUOTES, 'UTF-8'); // TODO:test also old html_entity_decode(utf8_encode($wc))
1148 1148
 
1149 1149
         # remove 'words' that don't consist of alphanumerical characters or punctuation. And fix accents and some letters
1150 1150
         $pattern = "#[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@|á|é|í|ó|ú|à|è|ì|ò|ù|ä|ë|ï|ö|ü|Á|É|Í|Ó|Ú|À|È|Ò|Ù|Ä|Ë|Ï|Ö|Ü|â|ê|î|ô|û|Â|Ê|Î|Ô|Û|ñ|Ñ|ç|Ç)]+#";
@@ -1177,15 +1177,15 @@  discard block
 block discarded – undo
1177 1177
 
1178 1178
         $course_id = api_get_course_int_id();
1179 1179
 
1180
-        $sql='SELECT id FROM '.$tbl_wiki.'
1180
+        $sql = 'SELECT id FROM '.$tbl_wiki.'
1181 1181
               WHERE
1182 1182
                 c_id = '.$course_id.' AND
1183 1183
                 title="'.Database::escape_string($title).'" AND
1184 1184
                 '.$groupfilter.$condition_session.'
1185 1185
               ORDER BY id ASC';
1186
-        $result=Database::query($sql);
1187
-        $cant=Database::num_rows($result);
1188
-        if ($cant>0) {
1186
+        $result = Database::query($sql);
1187
+        $cant = Database::num_rows($result);
1188
+        if ($cant > 0) {
1189 1189
             return true;
1190 1190
         } else {
1191 1191
             return false;
@@ -1267,20 +1267,20 @@  discard block
 block discarded – undo
1267 1267
         $page = $this->page;
1268 1268
 
1269 1269
         $course_id = api_get_course_int_id();
1270
-        $sql='SELECT * FROM '.$tbl_wiki.'
1270
+        $sql = 'SELECT * FROM '.$tbl_wiki.'
1271 1271
               WHERE
1272 1272
                 c_id = '.$course_id.' AND
1273 1273
                 reflink="'.Database::escape_string($page).'" AND
1274 1274
                 '.$groupfilter.$condition_session.'
1275 1275
               ORDER BY id ASC';
1276 1276
 
1277
-        $result=Database::query($sql);
1278
-        $row=Database::fetch_array($result);
1277
+        $result = Database::query($sql);
1278
+        $row = Database::fetch_array($result);
1279 1279
         $status_editlock = $row['editlock'];
1280 1280
         $id = $row['id'];
1281 1281
 
1282 1282
         ///change status
1283
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1283
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1284 1284
             if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lock' && $status_editlock == 0) {
1285 1285
                 $status_editlock = 1;
1286 1286
             }
@@ -1292,13 +1292,13 @@  discard block
 block discarded – undo
1292 1292
                     WHERE c_id = '.$course_id.' AND id="'.$id.'"';
1293 1293
             Database::query($sql);
1294 1294
 
1295
-            $sql='SELECT * FROM '.$tbl_wiki.'
1295
+            $sql = 'SELECT * FROM '.$tbl_wiki.'
1296 1296
                   WHERE
1297 1297
                     c_id = '.$course_id.' AND
1298 1298
                     reflink="'.Database::escape_string($page).'" AND
1299 1299
                     '.$groupfilter.$condition_session.'
1300 1300
                   ORDER BY id ASC';
1301
-            $result=Database::query($sql);
1301
+            $result = Database::query($sql);
1302 1302
             $row = Database::fetch_array($result);
1303 1303
         }
1304 1304
 
@@ -1329,13 +1329,13 @@  discard block
 block discarded – undo
1329 1329
         $row = Database::fetch_array($result);
1330 1330
         $status_visibility = $row['visibility'];
1331 1331
         //change status
1332
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1333
-            if (isset($_GET['actionpage']) && $_GET['actionpage']=='visible' && $status_visibility==0) {
1334
-                $status_visibility=1;
1332
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1333
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'visible' && $status_visibility == 0) {
1334
+                $status_visibility = 1;
1335 1335
 
1336 1336
             }
1337
-            if (isset($_GET['actionpage']) && $_GET['actionpage']=='invisible' && $status_visibility==1) {
1338
-                $status_visibility=0;
1337
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'invisible' && $status_visibility == 1) {
1338
+                $status_visibility = 0;
1339 1339
             }
1340 1340
 
1341 1341
             $sql = 'UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string($status_visibility).'"
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
                         reflink="'.Database::escape_string($page).'" AND
1353 1353
                         '.$groupfilter.$condition_session.'
1354 1354
                     ORDER BY id ASC';
1355
-            $result=Database::query($sql);
1355
+            $result = Database::query($sql);
1356 1356
             $row = Database::fetch_array($result);
1357 1357
         }
1358 1358
 
1359 1359
         if (empty($row['id'])) {
1360
-            $row['visibility']= 1;
1360
+            $row['visibility'] = 1;
1361 1361
         }
1362 1362
 
1363 1363
         //show status
@@ -1384,18 +1384,18 @@  discard block
 block discarded – undo
1384 1384
                     reflink="'.Database::escape_string($page).'" AND
1385 1385
                     '.$groupfilter.$condition_session.'
1386 1386
                 ORDER BY id ASC';
1387
-        $result=Database::query($sql);
1388
-        $row=Database::fetch_array($result);
1387
+        $result = Database::query($sql);
1388
+        $row = Database::fetch_array($result);
1389 1389
 
1390 1390
         $status_visibility_disc = $row['visibility_disc'];
1391 1391
 
1392 1392
         //change status
1393
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1394
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='showdisc' && $status_visibility_disc==0) {
1395
-                $status_visibility_disc=1;
1393
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1394
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'showdisc' && $status_visibility_disc == 0) {
1395
+                $status_visibility_disc = 1;
1396 1396
             }
1397
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='hidedisc' && $status_visibility_disc==1) {
1398
-                $status_visibility_disc=0;
1397
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'hidedisc' && $status_visibility_disc == 1) {
1398
+                $status_visibility_disc = 0;
1399 1399
             }
1400 1400
 
1401 1401
             $sql = 'UPDATE '.$tbl_wiki.' SET visibility_disc="'.Database::escape_string($status_visibility_disc).'"
@@ -1443,14 +1443,14 @@  discard block
 block discarded – undo
1443 1443
         $result = Database::query($sql);
1444 1444
         $row = Database::fetch_array($result);
1445 1445
 
1446
-        $status_addlock_disc=$row['addlock_disc'];
1446
+        $status_addlock_disc = $row['addlock_disc'];
1447 1447
 
1448 1448
         //change status
1449 1449
         if (api_is_allowed_to_edit() || api_is_platform_admin()) {
1450
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='lockdisc' && $status_addlock_disc==0) {
1450
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lockdisc' && $status_addlock_disc == 0) {
1451 1451
                 $status_addlock_disc = 1;
1452 1452
             }
1453
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='unlockdisc' && $status_addlock_disc==1) {
1453
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlockdisc' && $status_addlock_disc == 1) {
1454 1454
                 $status_addlock_disc = 0;
1455 1455
             }
1456 1456
 
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
                         reflink="'.Database::escape_string($page).'" AND
1473 1473
                         '.$groupfilter.$condition_session.'
1474 1474
                     ORDER BY id ASC';
1475
-            $result=Database::query($sql);
1476
-            $row=Database::fetch_array($result);
1475
+            $result = Database::query($sql);
1476
+            $row = Database::fetch_array($result);
1477 1477
         }
1478 1478
 
1479 1479
         return $row['addlock_disc'];
@@ -1498,17 +1498,17 @@  discard block
 block discarded – undo
1498 1498
                     reflink="'.Database::escape_string($page).'" AND
1499 1499
                     '.$groupfilter.$condition_session.'
1500 1500
                 ORDER BY id ASC';
1501
-        $result=Database::query($sql);
1502
-        $row=Database::fetch_array($result);
1503
-        $status_ratinglock_disc=$row['ratinglock_disc'];
1501
+        $result = Database::query($sql);
1502
+        $row = Database::fetch_array($result);
1503
+        $status_ratinglock_disc = $row['ratinglock_disc'];
1504 1504
 
1505 1505
         //change status
1506
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
1507
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='lockrating' && $status_ratinglock_disc==0) {
1508
-                $status_ratinglock_disc=1;
1506
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
1507
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lockrating' && $status_ratinglock_disc == 0) {
1508
+                $status_ratinglock_disc = 1;
1509 1509
             }
1510
-            if (isset($_GET['actionpage']) && $_GET['actionpage'] =='unlockrating' && $status_ratinglock_disc==1) {
1511
-                $status_ratinglock_disc=0;
1510
+            if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlockrating' && $status_ratinglock_disc == 1) {
1511
+                $status_ratinglock_disc = 0;
1512 1512
             }
1513 1513
 
1514 1514
             $sql = 'UPDATE '.$tbl_wiki.'
@@ -1524,14 +1524,14 @@  discard block
 block discarded – undo
1524 1524
             // these three lines remain necessary. They do that by changing the
1525 1525
             // page state is made when you press the button and not have to wait
1526 1526
             // to change his page
1527
-            $sql='SELECT * FROM '.$tbl_wiki.'
1527
+            $sql = 'SELECT * FROM '.$tbl_wiki.'
1528 1528
                   WHERE
1529 1529
                     c_id = '.$course_id.' AND
1530 1530
                     reflink="'.Database::escape_string($page).'" AND
1531 1531
                     '.$groupfilter.$condition_session.'
1532 1532
                   ORDER BY id ASC';
1533
-            $result=Database::query($sql);
1534
-            $row=Database::fetch_array($result);
1533
+            $result = Database::query($sql);
1534
+            $row = Database::fetch_array($result);
1535 1535
         }
1536 1536
 
1537 1537
         return $row['ratinglock_disc'];
@@ -1556,24 +1556,24 @@  discard block
 block discarded – undo
1556 1556
         $sql = 'SELECT * FROM '.$tbl_wiki.'
1557 1557
                 WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.'
1558 1558
                 ORDER BY id ASC';
1559
-        $result=Database::query($sql);
1560
-        $row=Database::fetch_array($result);
1559
+        $result = Database::query($sql);
1560
+        $row = Database::fetch_array($result);
1561 1561
         $id = $row['id'];
1562
-        $sql='SELECT * FROM '.$tbl_wiki_mailcue.'
1562
+        $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1563 1563
               WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"';
1564
-        $result=Database::query($sql);
1565
-        $row=Database::fetch_array($result);
1564
+        $result = Database::query($sql);
1565
+        $row = Database::fetch_array($result);
1566 1566
 
1567 1567
         $idm = $row['id'];
1568 1568
 
1569 1569
         if (empty($idm)) {
1570
-            $status_notify=0;
1570
+            $status_notify = 0;
1571 1571
         } else {
1572
-            $status_notify=1;
1572
+            $status_notify = 1;
1573 1573
         }
1574 1574
 
1575 1575
         // Change status
1576
-        if (isset($_GET['actionpage']) && $_GET['actionpage'] =='locknotify' && $status_notify==0) {
1576
+        if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotify' && $status_notify == 0) {
1577 1577
             $sql = "SELECT id FROM $tbl_wiki_mailcue
1578 1578
                     WHERE c_id = $course_id AND id = $id AND user_id = $userId";
1579 1579
             $result = Database::query($sql);
@@ -1582,18 +1582,18 @@  discard block
 block discarded – undo
1582 1582
                 $exist = true;
1583 1583
             }
1584 1584
             if ($exist == false) {
1585
-                $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
1585
+                $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
1586 1586
                 ($course_id, '".$id."','".api_get_user_id()."','P','".$groupId."','".$session_id."')";
1587 1587
                 Database::query($sql);
1588 1588
             }
1589
-            $status_notify=1;
1589
+            $status_notify = 1;
1590 1590
         }
1591 1591
 
1592
-        if (isset($_GET['actionpage']) && $_GET['actionpage'] =='unlocknotify' && $status_notify==1) {
1592
+        if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlocknotify' && $status_notify == 1) {
1593 1593
             $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
1594 1594
                     WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P" AND c_id = '.$course_id;
1595 1595
             Database::query($sql);
1596
-            $status_notify=0;
1596
+            $status_notify = 0;
1597 1597
         }
1598 1598
 
1599 1599
         return $status_notify;
@@ -1619,9 +1619,9 @@  discard block
 block discarded – undo
1619 1619
         $sql = 'SELECT * FROM '.$tbl_wiki.'
1620 1620
                 WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.'
1621 1621
                 ORDER BY id ASC';
1622
-        $result=Database::query($sql);
1623
-        $row=Database::fetch_array($result);
1624
-        $id=$row['id'];
1622
+        $result = Database::query($sql);
1623
+        $row = Database::fetch_array($result);
1624
+        $id = $row['id'];
1625 1625
         $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1626 1626
                 WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"';
1627 1627
         $result = Database::query($sql);
@@ -1629,23 +1629,23 @@  discard block
 block discarded – undo
1629 1629
         $idm = $row['id'];
1630 1630
 
1631 1631
         if (empty($idm)) {
1632
-            $status_notify_disc=0;
1632
+            $status_notify_disc = 0;
1633 1633
         } else {
1634
-            $status_notify_disc=1;
1634
+            $status_notify_disc = 1;
1635 1635
         }
1636 1636
 
1637 1637
         //change status
1638
-        if (isset($_GET['actionpage']) && $_GET['actionpage'] =='locknotifydisc' && $status_notify_disc==0) {
1639
-            $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
1638
+        if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotifydisc' && $status_notify_disc == 0) {
1639
+            $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
1640 1640
             ($course_id, '".$id."','".api_get_user_id()."','D','".$groupId."','".$session_id."')";
1641 1641
             Database::query($sql);
1642
-            $status_notify_disc=1;
1642
+            $status_notify_disc = 1;
1643 1643
         }
1644
-        if (isset($_GET['actionpage']) && $_GET['actionpage'] =='unlocknotifydisc' && $status_notify_disc==1) {
1644
+        if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlocknotifydisc' && $status_notify_disc == 1) {
1645 1645
             $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
1646 1646
                     WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D" AND c_id = '.$course_id;
1647 1647
             Database::query($sql);
1648
-            $status_notify_disc=0;
1648
+            $status_notify_disc = 0;
1649 1649
         }
1650 1650
 
1651 1651
         return $status_notify_disc;
@@ -1660,7 +1660,7 @@  discard block
 block discarded – undo
1660 1660
         $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
1661 1661
         $course_id = api_get_course_int_id();
1662 1662
         $groupId = api_get_group_id();
1663
-        $session_id=api_get_session_id();
1663
+        $session_id = api_get_session_id();
1664 1664
 
1665 1665
         $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1666 1666
                 WHERE
@@ -1669,31 +1669,31 @@  discard block
 block discarded – undo
1669 1669
                     type="F" AND
1670 1670
                     group_id="'.$groupId.'" AND
1671 1671
                     session_id="'.$session_id.'"';
1672
-        $result=Database::query($sql);
1673
-        $row=Database::fetch_array($result);
1672
+        $result = Database::query($sql);
1673
+        $row = Database::fetch_array($result);
1674 1674
 
1675
-        $idm=$row['user_id'];
1675
+        $idm = $row['user_id'];
1676 1676
 
1677 1677
         if (empty($idm)) {
1678
-            $status_notify_all=0;
1678
+            $status_notify_all = 0;
1679 1679
         } else {
1680
-            $status_notify_all=1;
1680
+            $status_notify_all = 1;
1681 1681
         }
1682 1682
 
1683 1683
         //change status
1684
-        if (isset($_GET['actionpage']) && $_GET['actionpage'] =='locknotifyall' && $status_notify_all==0) {
1685
-            $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES
1684
+        if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotifyall' && $status_notify_all == 0) {
1685
+            $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES
1686 1686
             ($course_id, '".api_get_user_id()."','F','".$groupId."','".$session_id."')";
1687 1687
             Database::query($sql);
1688
-            $status_notify_all=1;
1688
+            $status_notify_all = 1;
1689 1689
         }
1690 1690
 
1691 1691
         if (isset($_GET['actionpage']) &&
1692 1692
             isset($_GET['actionpage']) &&
1693
-            $_GET['actionpage']  =='unlocknotifyall' &&
1693
+            $_GET['actionpage'] == 'unlocknotifyall' &&
1694 1694
             $status_notify_all == 1
1695 1695
         ) {
1696
-            $sql ='DELETE FROM '.$tbl_wiki_mailcue.'
1696
+            $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
1697 1697
                    WHERE
1698 1698
                     c_id = '.$course_id.' AND
1699 1699
                     user_id="'.api_get_user_id().'" AND
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
                     session_id="'.$session_id.'" AND
1703 1703
                     c_id = '.$course_id;
1704 1704
             Database::query($sql);
1705
-            $status_notify_all=0;
1705
+            $status_notify_all = 0;
1706 1706
         }
1707 1707
 
1708 1708
         //show status
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
     /**
1713 1713
      * Sends pending e-mails
1714 1714
      */
1715
-    public function check_emailcue($id_or_ref, $type, $lastime='', $lastuser='')
1715
+    public function check_emailcue($id_or_ref, $type, $lastime = '', $lastuser = '')
1716 1716
     {
1717 1717
         $tbl_wiki_mailcue = $this->tbl_wiki_mailcue;
1718 1718
         $tbl_wiki = $this->tbl_wiki;
@@ -1720,14 +1720,14 @@  discard block
 block discarded – undo
1720 1720
         $groupfilter = $this->groupfilter;
1721 1721
         $_course = $this->courseInfo;
1722 1722
         $groupId = api_get_group_id();
1723
-        $session_id=api_get_session_id();
1723
+        $session_id = api_get_session_id();
1724 1724
         $course_id = api_get_course_int_id();
1725 1725
 
1726
-        $group_properties  = GroupManager :: get_group_properties($groupId);
1726
+        $group_properties = GroupManager :: get_group_properties($groupId);
1727 1727
         $group_name = $group_properties['name'];
1728 1728
         $allow_send_mail = false; //define the variable to below
1729 1729
         $email_assignment = null;
1730
-        if ($type=='P') {
1730
+        if ($type == 'P') {
1731 1731
             //if modifying a wiki page
1732 1732
             //first, current author and time
1733 1733
             //Who is the author?
@@ -1738,22 +1738,22 @@  discard block
 block discarded – undo
1738 1738
             $year = substr($lastime, 0, 4);
1739 1739
             $month = substr($lastime, 5, 2);
1740 1740
             $day = substr($lastime, 8, 2);
1741
-            $hours=substr($lastime, 11,2);
1742
-            $minutes=substr($lastime, 14,2);
1743
-            $seconds=substr($lastime, 17,2);
1744
-            $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1741
+            $hours = substr($lastime, 11, 2);
1742
+            $minutes = substr($lastime, 14, 2);
1743
+            $seconds = substr($lastime, 17, 2);
1744
+            $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1745 1745
 
1746 1746
             //second, extract data from first reg
1747 1747
             $sql = 'SELECT * FROM '.$tbl_wiki.'
1748 1748
                     WHERE  c_id = '.$course_id.' AND reflink="'.$id_or_ref.'" AND '.$groupfilter.$condition_session.'
1749 1749
                     ORDER BY id ASC';
1750
-            $result=Database::query($sql);
1751
-            $row=Database::fetch_array($result);
1750
+            $result = Database::query($sql);
1751
+            $row = Database::fetch_array($result);
1752 1752
 
1753
-            $id=$row['id'];
1754
-            $email_page_name=$row['title'];
1755
-            if ($row['visibility']==1) {
1756
-                $allow_send_mail=true; //if visibility off - notify off
1753
+            $id = $row['id'];
1754
+            $email_page_name = $row['title'];
1755
+            if ($row['visibility'] == 1) {
1756
+                $allow_send_mail = true; //if visibility off - notify off
1757 1757
                 $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1758 1758
                         WHERE
1759 1759
                             c_id = '.$course_id.' AND
@@ -1763,10 +1763,10 @@  discard block
 block discarded – undo
1763 1763
                             group_id="'.$groupId.'" AND
1764 1764
                             session_id="'.$session_id.'"';
1765 1765
                 //type: P=page, D=discuss, F=full.
1766
-                $result=Database::query($sql);
1767
-                $emailtext=get_lang('EmailWikipageModified').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
1766
+                $result = Database::query($sql);
1767
+                $emailtext = get_lang('EmailWikipageModified').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
1768 1768
             }
1769
-        } elseif ($type=='D') {
1769
+        } elseif ($type == 'D') {
1770 1770
             //if added a post to discuss
1771 1771
 
1772 1772
             //first, current author and time
@@ -1778,25 +1778,25 @@  discard block
 block discarded – undo
1778 1778
             $year = substr($lastime, 0, 4);
1779 1779
             $month = substr($lastime, 5, 2);
1780 1780
             $day = substr($lastime, 8, 2);
1781
-            $hours=substr($lastime, 11,2);
1782
-            $minutes=substr($lastime, 14,2);
1783
-            $seconds=substr($lastime, 17,2);
1784
-            $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1781
+            $hours = substr($lastime, 11, 2);
1782
+            $minutes = substr($lastime, 14, 2);
1783
+            $seconds = substr($lastime, 17, 2);
1784
+            $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1785 1785
 
1786 1786
             //second, extract data from first reg
1787 1787
 
1788
-            $id=$id_or_ref; //$id_or_ref is id from tblwiki
1788
+            $id = $id_or_ref; //$id_or_ref is id from tblwiki
1789 1789
 
1790 1790
             $sql = 'SELECT * FROM '.$tbl_wiki.'
1791 1791
                     WHERE c_id = '.$course_id.' AND id="'.$id.'"
1792 1792
                     ORDER BY id ASC';
1793 1793
 
1794
-            $result=Database::query($sql);
1795
-            $row=Database::fetch_array($result);
1794
+            $result = Database::query($sql);
1795
+            $row = Database::fetch_array($result);
1796 1796
 
1797
-            $email_page_name=$row['title'];
1798
-            if ($row['visibility_disc']==1) {
1799
-                $allow_send_mail=true; //if visibility off - notify off
1797
+            $email_page_name = $row['title'];
1798
+            if ($row['visibility_disc'] == 1) {
1799
+                $allow_send_mail = true; //if visibility off - notify off
1800 1800
                 $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1801 1801
                         WHERE
1802 1802
                             c_id = '.$course_id.' AND
@@ -1807,22 +1807,22 @@  discard block
 block discarded – undo
1807 1807
                             session_id="'.$session_id.'"';
1808 1808
                 //type: P=page, D=discuss, F=full
1809 1809
                 $result = Database::query($sql);
1810
-                $emailtext=get_lang('EmailWikiPageDiscAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
1810
+                $emailtext = get_lang('EmailWikiPageDiscAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
1811 1811
             }
1812
-        } elseif($type=='A') {
1812
+        } elseif ($type == 'A') {
1813 1813
             //for added pages
1814
-            $id=0; //for tbl_wiki_mailcue
1814
+            $id = 0; //for tbl_wiki_mailcue
1815 1815
             $sql = 'SELECT * FROM '.$tbl_wiki.'
1816 1816
                     WHERE c_id = '.$course_id.'
1817 1817
                     ORDER BY id DESC'; //the added is always the last
1818 1818
 
1819
-            $result=Database::query($sql);
1820
-            $row=Database::fetch_array($result);
1821
-            $email_page_name=$row['title'];
1819
+            $result = Database::query($sql);
1820
+            $row = Database::fetch_array($result);
1821
+            $email_page_name = $row['title'];
1822 1822
 
1823 1823
             //Who is the author?
1824 1824
             $userinfo = api_get_user_info($row['user_id']);
1825
-            $email_user_author= get_lang('AddedBy').': '.$userinfo['complete_name'];
1825
+            $email_user_author = get_lang('AddedBy').': '.$userinfo['complete_name'];
1826 1826
 
1827 1827
             //When ?
1828 1828
             $year = substr($row['dtime'], 0, 4);
@@ -1831,33 +1831,33 @@  discard block
 block discarded – undo
1831 1831
             $hours = substr($row['dtime'], 11, 2);
1832 1832
             $minutes = substr($row['dtime'], 14, 2);
1833 1833
             $seconds = substr($row['dtime'], 17, 2);
1834
-            $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1835
-
1836
-            if($row['assignment']==0) {
1837
-                $allow_send_mail=true;
1838
-            } elseif($row['assignment']==1) {
1839
-                $email_assignment=get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')';
1840
-                $allow_send_mail=true;
1841
-            } elseif($row['assignment']==2) {
1842
-                $allow_send_mail=false; //Mode tasks: avoids notifications to all users about all users
1834
+            $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
1835
+
1836
+            if ($row['assignment'] == 0) {
1837
+                $allow_send_mail = true;
1838
+            } elseif ($row['assignment'] == 1) {
1839
+                $email_assignment = get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')';
1840
+                $allow_send_mail = true;
1841
+            } elseif ($row['assignment'] == 2) {
1842
+                $allow_send_mail = false; //Mode tasks: avoids notifications to all users about all users
1843 1843
             }
1844 1844
 
1845 1845
             $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1846 1846
                     WHERE c_id = '.$course_id.' AND  id="'.$id.'" AND type="F" AND group_id="'.$groupId.'" AND session_id="'.$session_id.'"';
1847 1847
             //type: P=page, D=discuss, F=full
1848
-            $result=Database::query($sql);
1848
+            $result = Database::query($sql);
1849 1849
 
1850
-            $emailtext = get_lang('EmailWikiPageAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('In').' '. get_lang('Wiki');
1851
-        } elseif ($type=='E') {
1852
-            $id=0;
1853
-            $allow_send_mail=true;
1850
+            $emailtext = get_lang('EmailWikiPageAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('In').' '.get_lang('Wiki');
1851
+        } elseif ($type == 'E') {
1852
+            $id = 0;
1853
+            $allow_send_mail = true;
1854 1854
 
1855 1855
             //Who is the author?
1856
-            $userinfo = api_get_user_info(api_get_user_id());	//current user
1856
+            $userinfo = api_get_user_info(api_get_user_id()); //current user
1857 1857
             $email_user_author = get_lang('DeletedBy').': '.$userinfo['complete_name'];
1858 1858
             //When ?
1859
-            $today = date('r');		//current time
1860
-            $email_date_changes=$today;
1859
+            $today = date('r'); //current time
1860
+            $email_date_changes = $today;
1861 1861
 
1862 1862
             $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'
1863 1863
                     WHERE
@@ -1871,16 +1871,16 @@  discard block
 block discarded – undo
1871 1871
         ///make and send email
1872 1872
         if ($allow_send_mail) {
1873 1873
             while ($row = Database::fetch_array($result)) {
1874
-                $userinfo = api_get_user_info($row['user_id']);	//$row['user_id'] obtained from tbl_wiki_mailcue
1874
+                $userinfo = api_get_user_info($row['user_id']); //$row['user_id'] obtained from tbl_wiki_mailcue
1875 1875
                 $name_to = $userinfo['complete_name'];
1876 1876
                 $email_to = $userinfo['email'];
1877 1877
                 $sender_name = api_get_setting('emailAdministrator');
1878 1878
                 $sender_email = api_get_setting('emailAdministrator');
1879 1879
                 $email_subject = get_lang('EmailWikiChanges').' - '.$_course['official_code'];
1880 1880
                 $email_body = get_lang('DearUser').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).',<br /><br />';
1881
-                if($session_id==0){
1881
+                if ($session_id == 0) {
1882 1882
                     $email_body .= $emailtext.' <strong>'.$_course['name'].' - '.$group_name.'</strong><br /><br /><br />';
1883
-                }else{
1883
+                } else {
1884 1884
                     $email_body .= $emailtext.' <strong>'.$_course['name'].' ('.api_get_session_name(api_get_session_id()).') - '.$group_name.'</strong><br /><br /><br />';
1885 1885
                 }
1886 1886
                 $email_body .= $email_user_author.' ('.$email_date_changes.')<br /><br /><br />';
@@ -1958,25 +1958,25 @@  discard block
 block discarded – undo
1958 1958
             $template);
1959 1959
 
1960 1960
         if (0 != $groupId) {
1961
-            $groupPart = '_group' . $groupId; // and add groupId to put the same document title in different groups
1962
-            $group_properties  = GroupManager :: get_group_properties($groupId);
1961
+            $groupPart = '_group'.$groupId; // and add groupId to put the same document title in different groups
1962
+            $group_properties = GroupManager :: get_group_properties($groupId);
1963 1963
             $groupPath = $group_properties['directory'];
1964 1964
         } else {
1965 1965
             $groupPart = '';
1966
-            $groupPath ='';
1966
+            $groupPath = '';
1967 1967
         }
1968 1968
 
1969
-        $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath;
1970
-        $exportFile = api_replace_dangerous_char($wikiTitle) . $groupPart;
1969
+        $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document'.$groupPath;
1970
+        $exportFile = api_replace_dangerous_char($wikiTitle).$groupPart;
1971 1971
         $wikiContents = trim(preg_replace("/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/", "$1", $wikiContents));
1972 1972
         //TODO: put link instead of title
1973 1973
 
1974 1974
         $wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
1975 1975
 
1976 1976
         // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents
1977
-        if (api_strpos($wikiContents,'../../courses/') !== false) {
1977
+        if (api_strpos($wikiContents, '../../courses/') !== false) {
1978 1978
             $web_course_path = api_get_path(WEB_COURSE_PATH);
1979
-            $wikiContents = str_replace('../../courses/',$web_course_path,$wikiContents);
1979
+            $wikiContents = str_replace('../../courses/', $web_course_path, $wikiContents);
1980 1980
         }
1981 1981
 
1982 1982
         $i = 1;
@@ -1985,8 +1985,8 @@  discard block
 block discarded – undo
1985 1985
             $i++;
1986 1986
         }
1987 1987
 
1988
-        $wikiFileName = $exportFile . '_' . $i . '.html';
1989
-        $exportPath = $exportDir . '/' . $wikiFileName;
1988
+        $wikiFileName = $exportFile.'_'.$i.'.html';
1989
+        $exportPath = $exportDir.'/'.$wikiFileName;
1990 1990
 
1991 1991
         file_put_contents($exportPath, $wikiContents);
1992 1992
         $doc_id = add_document(
@@ -2031,14 +2031,14 @@  discard block
 block discarded – undo
2031 2031
         $content_pdf = api_html_entity_decode($data['content'], ENT_QUOTES, api_get_system_encoding());
2032 2032
 
2033 2033
         //clean wiki links
2034
-        $content_pdf=trim(preg_replace("/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/", "$1", $content_pdf));
2034
+        $content_pdf = trim(preg_replace("/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/", "$1", $content_pdf));
2035 2035
         //TODO: It should be better to display the link insted of the tile but it is hard for [[title]] links
2036 2036
 
2037 2037
         $title_pdf = api_html_entity_decode($data['title'], ENT_QUOTES, api_get_system_encoding());
2038 2038
         $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
2039 2039
         $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding());
2040 2040
 
2041
-        $html='
2041
+        $html = '
2042 2042
         <!-- defines the headers/footers - this must occur before the headers/footers are set -->
2043 2043
 
2044 2044
         <!--mpdf
@@ -2093,9 +2093,9 @@  discard block
 block discarded – undo
2093 2093
         $session_id = $this->session_id;
2094 2094
         $groupId = api_get_group_id();
2095 2095
 
2096
-        if ($groupId==0) {
2096
+        if ($groupId == 0) {
2097 2097
             //extract course members
2098
-            if(!empty($session_id)) {
2098
+            if (!empty($session_id)) {
2099 2099
                 $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id);
2100 2100
             } else {
2101 2101
                 $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), 0);
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
         $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES));
2122 2122
         $name = $userinfo['complete_name']." - ".$username;
2123 2123
 
2124
-        $photo = '<img src="' . $userinfo['avatar'] . '" alt="' . $name . '"  width="40" height="50" align="top" title="' . $name . '"  />';
2124
+        $photo = '<img src="'.$userinfo['avatar'].'" alt="'.$name.'"  width="40" height="50" align="top" title="'.$name.'"  />';
2125 2125
 
2126 2126
         // teacher assignment title
2127 2127
         $title_orig = $values['title'];
@@ -2149,24 +2149,24 @@  discard block
 block discarded – undo
2149 2149
                 $userPicture = UserManager::getUserPicture($assig_user_id);
2150 2150
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $o_user_to_add['username'], ENT_QUOTES));
2151 2151
                 $name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname'])." . ".$username;
2152
-                $photo= '<img src="'.$userPicture.'" alt="'.$name.'"  width="40" height="50" align="bottom" title="'.$name.'"  />';
2152
+                $photo = '<img src="'.$userPicture.'" alt="'.$name.'"  width="40" height="50" align="bottom" title="'.$name.'"  />';
2153 2153
 
2154 2154
                 $is_tutor_of_group = GroupManager::is_tutor_of_group($assig_user_id, $groupId); //student is tutor
2155 2155
                 $is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $groupId) && GroupManager::is_subscribed($assig_user_id, $groupId);
2156 2156
                 // student is tutor and member
2157 2157
 
2158 2158
                 if ($is_tutor_and_member) {
2159
-                    $status_in_group=get_lang('GroupTutorAndMember');
2159
+                    $status_in_group = get_lang('GroupTutorAndMember');
2160 2160
                 } else {
2161
-                    if($is_tutor_of_group) {
2162
-                        $status_in_group=get_lang('GroupTutor');
2161
+                    if ($is_tutor_of_group) {
2162
+                        $status_in_group = get_lang('GroupTutor');
2163 2163
                     } else {
2164
-                        $status_in_group=" "; //get_lang('GroupStandardMember')
2164
+                        $status_in_group = " "; //get_lang('GroupStandardMember')
2165 2165
                     }
2166 2166
                 }
2167 2167
 
2168
-                if ($assignment_type==1) {
2169
-                    $values['title']= $title_orig;
2168
+                if ($assignment_type == 1) {
2169
+                    $values['title'] = $title_orig;
2170 2170
                     $values['content'] = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6">
2171 2171
                     <table border="0">
2172 2172
                     <tr><td style="font-size:24px">'.get_lang('AssignmentWork').'</td></tr>
@@ -2182,7 +2182,7 @@  discard block
 block discarded – undo
2182 2182
                         ).
2183 2183
                         ' [['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>';
2184 2184
                     //don't change this line without guaranteeing that users will be ordered by last names in the following format (surname, name)
2185
-                    $values['assignment']=2;
2185
+                    $values['assignment'] = 2;
2186 2186
                 }
2187 2187
                 $this->assig_user_id = $assig_user_id;
2188 2188
                 self::save_new_wiki($values);
@@ -2191,12 +2191,12 @@  discard block
 block discarded – undo
2191 2191
 
2192 2192
         foreach ($a_users_to_add as $o_user_to_add) {
2193 2193
             if ($o_user_to_add['user_id'] == $userId) {
2194
-                $assig_user_id=$o_user_to_add['user_id'];
2194
+                $assig_user_id = $o_user_to_add['user_id'];
2195 2195
                 if ($assignment_type == 1) {
2196
-                    $values['title']= $title_orig;
2197
-                    $values['comment']=get_lang('AssignmentDesc');
2196
+                    $values['title'] = $title_orig;
2197
+                    $values['comment'] = get_lang('AssignmentDesc');
2198 2198
                     sort($all_students_pages);
2199
-                    $values['content']=$content_orig_A.$content_orig_B.'<br/>
2199
+                    $values['content'] = $content_orig_A.$content_orig_B.'<br/>
2200 2200
                     <div align="center" style="font-size:18px; background-color: #F5F8FB; border:solid; border-color:#E6E6E6">
2201 2201
                     '.get_lang('AssignmentLinkstoStudentsPage').'
2202 2202
                     </div><br/>
@@ -2204,7 +2204,7 @@  discard block
 block discarded – undo
2204 2204
                     <ol>'.implode($all_students_pages).'</ol>
2205 2205
                     </div>
2206 2206
                     <br/>';
2207
-                    $values['assignment']=1;
2207
+                    $values['assignment'] = 1;
2208 2208
                 }
2209 2209
                 $this->assig_user_id = $assig_user_id;
2210 2210
                 self::save_new_wiki($values);
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
      * @param   int     Whether to search the contents (1) or just the titles (0)
2219 2219
      * @param int
2220 2220
      */
2221
-    public function display_wiki_search_results($search_term, $search_content=0, $all_vers=0)
2221
+    public function display_wiki_search_results($search_term, $search_content = 0, $all_vers = 0)
2222 2222
     {
2223 2223
         $tbl_wiki = $this->tbl_wiki;
2224 2224
         $condition_session = $this->condition_session;
@@ -2230,9 +2230,9 @@  discard block
 block discarded – undo
2230 2230
         echo '</legend>';
2231 2231
 
2232 2232
         //only by professors when page is hidden
2233
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
2234
-            if ($all_vers=='1') {
2235
-                if ($search_content=='1') {
2233
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
2234
+            if ($all_vers == '1') {
2235
+                if ($search_content == '1') {
2236 2236
                     $sql = "SELECT * FROM ".$tbl_wiki."
2237 2237
                             WHERE
2238 2238
                                 c_id = $course_id AND
@@ -2249,7 +2249,7 @@  discard block
 block discarded – undo
2249 2249
                     //search all pages and all versions
2250 2250
                 }
2251 2251
             } else {
2252
-                if ($search_content=='1') {
2252
+                if ($search_content == '1') {
2253 2253
                     $sql = "SELECT * FROM ".$tbl_wiki." s1
2254 2254
                             WHERE
2255 2255
                                 s1.c_id = $course_id AND
@@ -2300,7 +2300,7 @@  discard block
 block discarded – undo
2300 2300
                     //search all pages and all versions
2301 2301
                 }
2302 2302
             } else {
2303
-                if($search_content=='1') {
2303
+                if ($search_content == '1') {
2304 2304
                     $sql = "SELECT * FROM ".$tbl_wiki." s1
2305 2305
                             WHERE
2306 2306
                                 s1.c_id = $course_id AND
@@ -2348,17 +2348,17 @@  discard block
 block discarded – undo
2348 2348
                 $seconds = substr($obj->dtime, 17, 2);
2349 2349
 
2350 2350
                 //get type assignment icon
2351
-                if($obj->assignment==1) {
2352
-                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
2353
-                } elseif ($obj->assignment==2) {
2354
-                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
2355
-                } elseif ($obj->assignment==0) {
2351
+                if ($obj->assignment == 1) {
2352
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
2353
+                } elseif ($obj->assignment == 2) {
2354
+                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
2355
+                } elseif ($obj->assignment == 0) {
2356 2356
                     $ShowAssignment = Display::return_icon('px_transparent.gif');
2357 2357
                 }
2358 2358
                 $row = array();
2359 2359
                 $row[] = $ShowAssignment;
2360 2360
 
2361
-                if($all_vers=='1') {
2361
+                if ($all_vers == '1') {
2362 2362
                     $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&view='.$obj->id.'&session_id='.api_htmlentities(urlencode($_GET['$session_id'])).'&group_id='.api_htmlentities(urlencode($_GET['group_id'])).'">'.
2363 2363
                         api_htmlentities($obj->title).'</a>';
2364 2364
                 } else {
@@ -2369,21 +2369,21 @@  discard block
 block discarded – undo
2369 2369
                 $row[] = $obj->user_id != 0 ? UserManager::getUserProfileLink($userinfo) : get_lang('Anonymous').' ('.$obj->user_ip.')';
2370 2370
                 $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
2371 2371
 
2372
-                if ($all_vers=='1') {
2372
+                if ($all_vers == '1') {
2373 2373
                     $row[] = $obj->version;
2374 2374
                 } else {
2375 2375
                     $showdelete = '';
2376
-                    if (api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) {
2377
-                        $showdelete=' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2378
-                            Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
2376
+                    if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
2377
+                        $showdelete = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2378
+                            Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
2379 2379
                     }
2380 2380
                     $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=edit&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2381
-                        Display::return_icon('edit.png', get_lang('EditPage'),'',ICON_SIZE_SMALL).'</a>
2381
+                        Display::return_icon('edit.png', get_lang('EditPage'), '', ICON_SIZE_SMALL).'</a>
2382 2382
                         <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2383
-                        Display::return_icon('discuss.png', get_lang('Discuss'),'',ICON_SIZE_SMALL).'</a>
2383
+                        Display::return_icon('discuss.png', get_lang('Discuss'), '', ICON_SIZE_SMALL).'</a>
2384 2384
                         <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2385
-                        Display::return_icon('history.png', get_lang('History'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2386
-                        Display::return_icon('what_link_here.png', get_lang('LinksPages'),'',ICON_SIZE_SMALL).'</a>'.$showdelete;
2385
+                        Display::return_icon('history.png', get_lang('History'), '', ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
2386
+                        Display::return_icon('what_link_here.png', get_lang('LinksPages'), '', ICON_SIZE_SMALL).'</a>'.$showdelete;
2387 2387
                 }
2388 2388
                 $rows[] = $row;
2389 2389
             }
@@ -2408,16 +2408,16 @@  discard block
 block discarded – undo
2408 2408
                     'all_vers' => $all_vers,
2409 2409
                 )
2410 2410
             );
2411
-            $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
2412
-            $table->set_header(1,get_lang('Title'), true);
2411
+            $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;'));
2412
+            $table->set_header(1, get_lang('Title'), true);
2413 2413
             if ($all_vers == '1') {
2414
-                $table->set_header(2,get_lang('Author'), true);
2415
-                $table->set_header(3,get_lang('Date'), true);
2416
-                $table->set_header(4,get_lang('Version'), true);
2414
+                $table->set_header(2, get_lang('Author'), true);
2415
+                $table->set_header(3, get_lang('Date'), true);
2416
+                $table->set_header(4, get_lang('Version'), true);
2417 2417
             } else {
2418
-                $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true);
2419
-                $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
2420
-                $table->set_header(4,get_lang('Actions'), false, array ('style' => 'width:130px;'));
2418
+                $table->set_header(2, get_lang('Author').' ('.get_lang('LastVersion').')', true);
2419
+                $table->set_header(3, get_lang('Date').' ('.get_lang('LastVersion').')', true);
2420
+                $table->set_header(4, get_lang('Actions'), false, array('style' => 'width:130px;'));
2421 2421
             }
2422 2422
             $table->display();
2423 2423
         } else {
@@ -2430,14 +2430,14 @@  discard block
 block discarded – undo
2430 2430
      * @todo replace this function with the formvalidator datepicker
2431 2431
      *
2432 2432
      */
2433
-    public function draw_date_picker($prefix,$default='')
2433
+    public function draw_date_picker($prefix, $default = '')
2434 2434
     {
2435 2435
         if (empty($default)) {
2436 2436
             $default = date('Y-m-d H:i:s');
2437 2437
         }
2438 2438
         $parts = explode(' ', $default);
2439
-        list($d_year,$d_month,$d_day) = explode('-',$parts[0]);
2440
-        list($d_hour,$d_minute) = explode(':',$parts[1]);
2439
+        list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
2440
+        list($d_hour, $d_minute) = explode(':', $parts[1]);
2441 2441
 
2442 2442
         $month_list = array(
2443 2443
             1 => get_lang('JanuaryLong'),
@@ -2454,9 +2454,9 @@  discard block
 block discarded – undo
2454 2454
             12 => get_lang('DecemberLong'),
2455 2455
         );
2456 2456
 
2457
-        $minute = range(10,59);
2458
-        array_unshift($minute,'00','01','02','03','04','05','06','07','08','09');
2459
-        $date_form = self::make_select($prefix.'_day', array_combine(range(1,31),range(1,31)), $d_day);
2457
+        $minute = range(10, 59);
2458
+        array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09');
2459
+        $date_form = self::make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day);
2460 2460
         $date_form .= self::make_select($prefix.'_month', $month_list, $d_month);
2461 2461
         $date_form .= self::make_select(
2462 2462
                 $prefix.'_year',
@@ -2469,7 +2469,7 @@  discard block
 block discarded – undo
2469 2469
                 ),
2470 2470
                 $d_year
2471 2471
             ).'&nbsp;&nbsp;&nbsp;&nbsp;';
2472
-        $date_form .= self::make_select($prefix.'_hour', array_combine(range(0,23),range(0,23)), $d_hour).' : ';
2472
+        $date_form .= self::make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : ';
2473 2473
         $date_form .= self::make_select($prefix.'_minute', $minute, $d_minute);
2474 2474
 
2475 2475
         return $date_form;
@@ -2479,11 +2479,11 @@  discard block
 block discarded – undo
2479 2479
      * Draws an HTML form select with the given options
2480 2480
      *
2481 2481
      */
2482
-    public function make_select($name,$values,$checked='')
2482
+    public function make_select($name, $values, $checked = '')
2483 2483
     {
2484 2484
         $output = '<select name="'.$name.'" id="'.$name.'">';
2485
-        foreach($values as $key => $value) {
2486
-            $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
2485
+        foreach ($values as $key => $value) {
2486
+            $output .= '<option value="'.$key.'" '.(($checked == $key) ? 'selected="selected"' : '').'>'.$value.'</option>';
2487 2487
         }
2488 2488
         $output .= '</select>';
2489 2489
         return $output;
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
      */
2508 2508
     public function two_digits($number)
2509 2509
     {
2510
-        $number = (int)$number;
2510
+        $number = (int) $number;
2511 2511
         return ($number < 10) ? '0'.$number : $number;
2512 2512
     }
2513 2513
 
@@ -2525,7 +2525,7 @@  discard block
 block discarded – undo
2525 2525
                 WHERE c_id = '.$course_id.' AND id = '.$id.' ';
2526 2526
         $result = Database::query($sql);
2527 2527
         $data = array();
2528
-        while ($row=Database::fetch_array($result,'ASSOC'))   {
2528
+        while ($row = Database::fetch_array($result, 'ASSOC')) {
2529 2529
             $data = $row;
2530 2530
         }
2531 2531
         return $data;
@@ -2579,7 +2579,7 @@  discard block
 block discarded – undo
2579 2579
         $result = Database::query($sql);
2580 2580
         $data = array();
2581 2581
         if (Database::num_rows($result)) {
2582
-            $data = Database::fetch_array($result,'ASSOC');
2582
+            $data = Database::fetch_array($result, 'ASSOC');
2583 2583
         }
2584 2584
 
2585 2585
         return $data;
@@ -2673,9 +2673,9 @@  discard block
 block discarded – undo
2673 2673
         $result = self::getAllWiki();
2674 2674
         if (!empty($result)) {
2675 2675
             foreach ($result  as $is_editing_block) {
2676
-                $max_edit_time	= 1200; // 20 minutes
2677
-                $timestamp_edit	= strtotime($is_editing_block['time_edit']);
2678
-                $time_editing	= time()-$timestamp_edit;
2676
+                $max_edit_time = 1200; // 20 minutes
2677
+                $timestamp_edit = strtotime($is_editing_block['time_edit']);
2678
+                $time_editing = time() - $timestamp_edit;
2679 2679
 
2680 2680
                 // First prevent concurrent users and double version
2681 2681
                 if ($is_editing_block['is_editing'] == $userId) {
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
                     unset($_SESSION['_version']);
2685 2685
                 }
2686 2686
                 // Second checks if has exceeded the time that a page may be available or if a page was edited and saved by its author
2687
-                if ($time_editing > $max_edit_time || ($is_editing_block['is_editing'] == $userId && $action!='edit')) {
2687
+                if ($time_editing > $max_edit_time || ($is_editing_block['is_editing'] == $userId && $action != 'edit')) {
2688 2688
                     self::updateWikiIsEditing($is_editing_block['is_editing']);
2689 2689
                 }
2690 2690
             }
@@ -2732,7 +2732,7 @@  discard block
 block discarded – undo
2732 2732
                 FROM ".$tbl_wiki."
2733 2733
                 WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
2734 2734
 
2735
-        $allpages=Database::query($sql);
2735
+        $allpages = Database::query($sql);
2736 2736
         while ($row = Database::fetch_array($allpages)) {
2737 2737
             $total_versions = $row['TOTAL_VERS'];
2738 2738
             $total_visits = intval($row['TOTAL_VISITS']);
@@ -2742,30 +2742,30 @@  discard block
 block discarded – undo
2742 2742
                 WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
2743 2743
         $allpages = Database::query($sql);
2744 2744
 
2745
-        while ($row=Database::fetch_array($allpages)) {
2745
+        while ($row = Database::fetch_array($allpages)) {
2746 2746
             $total_words = $total_words + self::word_count($row['content']);
2747
-            $total_links 			= $total_links+substr_count($row['content'], "href=");
2748
-            $total_links_anchors 	= $total_links_anchors+substr_count($row['content'], 'href="#');
2749
-            $total_links_mail		= $total_links_mail+substr_count($row['content'], 'href="mailto');
2750
-            $total_links_ftp 		= $total_links_ftp+substr_count($row['content'], 'href="ftp');
2751
-            $total_links_irc		= $total_links_irc+substr_count($row['content'], 'href="irc');
2752
-            $total_links_news 		= $total_links_news+substr_count($row['content'], 'href="news');
2753
-            $total_wlinks 			= $total_wlinks+substr_count($row['content'], "[[");
2754
-            $total_images 			= $total_images+substr_count($row['content'], "<img");
2747
+            $total_links = $total_links + substr_count($row['content'], "href=");
2748
+            $total_links_anchors = $total_links_anchors + substr_count($row['content'], 'href="#');
2749
+            $total_links_mail		= $total_links_mail + substr_count($row['content'], 'href="mailto');
2750
+            $total_links_ftp 		= $total_links_ftp + substr_count($row['content'], 'href="ftp');
2751
+            $total_links_irc = $total_links_irc + substr_count($row['content'], 'href="irc');
2752
+            $total_links_news = $total_links_news + substr_count($row['content'], 'href="news');
2753
+            $total_wlinks 			= $total_wlinks + substr_count($row['content'], "[[");
2754
+            $total_images 			= $total_images + substr_count($row['content'], "<img");
2755 2755
             $clean_total_flash = preg_replace('/player.swf/', ' ', $row['content']);
2756
-            $total_flash			= $total_flash+substr_count($clean_total_flash, '.swf"');
2756
+            $total_flash = $total_flash + substr_count($clean_total_flash, '.swf"');
2757 2757
             //.swf" end quotes prevent insert swf through flvplayer (is not counted)
2758
-            $total_mp3				= $total_mp3+substr_count($row['content'], ".mp3");
2759
-            $total_flv_p = $total_flv_p+substr_count($row['content'], ".flv");
2760
-            $total_flv				=	$total_flv_p/5;
2761
-            $total_youtube			= $total_youtube+substr_count($row['content'], "http://www.youtube.com");
2762
-            $total_multimedia		= $total_multimedia+substr_count($row['content'], "video/x-msvideo");
2763
-            $total_tables			= $total_tables+substr_count($row['content'], "<table");
2758
+            $total_mp3				= $total_mp3 + substr_count($row['content'], ".mp3");
2759
+            $total_flv_p = $total_flv_p + substr_count($row['content'], ".flv");
2760
+            $total_flv				= $total_flv_p / 5;
2761
+            $total_youtube = $total_youtube + substr_count($row['content'], "http://www.youtube.com");
2762
+            $total_multimedia = $total_multimedia + substr_count($row['content'], "video/x-msvideo");
2763
+            $total_tables = $total_tables + substr_count($row['content'], "<table");
2764 2764
         }
2765 2765
 
2766 2766
         //check only last version of all pages (current page)
2767 2767
 
2768
-        $sql =' SELECT *, COUNT(*) AS TOTAL_PAGES, SUM(hits) AS TOTAL_VISITS_LV
2768
+        $sql = ' SELECT *, COUNT(*) AS TOTAL_PAGES, SUM(hits) AS TOTAL_VISITS_LV
2769 2769
                 FROM  '.$tbl_wiki.' s1
2770 2770
                 WHERE s1.c_id = '.$course_id.' AND id=(
2771 2771
                     SELECT MAX(s2.id)
@@ -2776,9 +2776,9 @@  discard block
 block discarded – undo
2776 2776
                         '.$groupfilter.' AND
2777 2777
                         session_id='.$session_id.')';
2778 2778
         $allpages = Database::query($sql);
2779
-        while ($row=Database::fetch_array($allpages)) {
2780
-            $total_pages	 		= $row['TOTAL_PAGES'];
2781
-            $total_visits_lv 		= intval($row['TOTAL_VISITS_LV']);
2779
+        while ($row = Database::fetch_array($allpages)) {
2780
+            $total_pages = $row['TOTAL_PAGES'];
2781
+            $total_visits_lv = intval($row['TOTAL_VISITS_LV']);
2782 2782
         }
2783 2783
 
2784 2784
         $total_words_lv = 0;
@@ -2810,29 +2810,29 @@  discard block
 block discarded – undo
2810 2810
                 )';
2811 2811
         $allpages = Database::query($sql);
2812 2812
 
2813
-        while ($row=Database::fetch_array($allpages)) {
2814
-            $total_words_lv 		= $total_words_lv+ self::word_count($row['content']);
2815
-            $total_links_lv 		= $total_links_lv+substr_count($row['content'], "href=");
2816
-            $total_links_anchors_lv	= $total_links_anchors_lv+substr_count($row['content'], 'href="#');
2817
-            $total_links_mail_lv 	= $total_links_mail_lv+substr_count($row['content'], 'href="mailto');
2818
-            $total_links_ftp_lv 	= $total_links_ftp_lv+substr_count($row['content'], 'href="ftp');
2819
-            $total_links_irc_lv 	= $total_links_irc_lv+substr_count($row['content'], 'href="irc');
2820
-            $total_links_news_lv 	= $total_links_news_lv+substr_count($row['content'], 'href="news');
2821
-            $total_wlinks_lv 		= $total_wlinks_lv+substr_count($row['content'], "[[");
2822
-            $total_images_lv 		= $total_images_lv+substr_count($row['content'], "<img");
2813
+        while ($row = Database::fetch_array($allpages)) {
2814
+            $total_words_lv 		= $total_words_lv + self::word_count($row['content']);
2815
+            $total_links_lv 		= $total_links_lv + substr_count($row['content'], "href=");
2816
+            $total_links_anchors_lv = $total_links_anchors_lv + substr_count($row['content'], 'href="#');
2817
+            $total_links_mail_lv 	= $total_links_mail_lv + substr_count($row['content'], 'href="mailto');
2818
+            $total_links_ftp_lv 	= $total_links_ftp_lv + substr_count($row['content'], 'href="ftp');
2819
+            $total_links_irc_lv 	= $total_links_irc_lv + substr_count($row['content'], 'href="irc');
2820
+            $total_links_news_lv 	= $total_links_news_lv + substr_count($row['content'], 'href="news');
2821
+            $total_wlinks_lv 		= $total_wlinks_lv + substr_count($row['content'], "[[");
2822
+            $total_images_lv 		= $total_images_lv + substr_count($row['content'], "<img");
2823 2823
             $clean_total_flash_lv = preg_replace('/player.swf/', ' ', $row['content']);
2824
-            $total_flash_lv			= $total_flash_lv+substr_count($clean_total_flash_lv, '.swf"');
2824
+            $total_flash_lv = $total_flash_lv + substr_count($clean_total_flash_lv, '.swf"');
2825 2825
             //.swf" end quotes prevent insert swf through flvplayer (is not counted)
2826
-            $total_mp3_lv			= $total_mp3_lv+substr_count($row['content'], ".mp3");
2827
-            $total_flv_p_lv = $total_flv_p_lv+substr_count($row['content'], ".flv");
2828
-            $total_flv_lv			= $total_flv_p_lv/5;
2829
-            $total_youtube_lv		= $total_youtube_lv+substr_count($row['content'], "http://www.youtube.com");
2830
-            $total_multimedia_lv	= $total_multimedia_lv+substr_count($row['content'], "video/x-msvideo");
2831
-            $total_tables_lv		= $total_tables_lv+substr_count($row['content'], "<table");
2826
+            $total_mp3_lv			= $total_mp3_lv + substr_count($row['content'], ".mp3");
2827
+            $total_flv_p_lv = $total_flv_p_lv + substr_count($row['content'], ".flv");
2828
+            $total_flv_lv			= $total_flv_p_lv / 5;
2829
+            $total_youtube_lv = $total_youtube_lv + substr_count($row['content'], "http://www.youtube.com");
2830
+            $total_multimedia_lv = $total_multimedia_lv + substr_count($row['content'], "video/x-msvideo");
2831
+            $total_tables_lv = $total_tables_lv + substr_count($row['content'], "<table");
2832 2832
         }
2833 2833
 
2834 2834
         //Total pages edited at this time
2835
-        $total_editing_now=0;
2835
+        $total_editing_now = 0;
2836 2836
         $sql = 'SELECT *, COUNT(*) AS TOTAL_EDITING_NOW
2837 2837
                 FROM  '.$tbl_wiki.' s1
2838 2838
                 WHERE is_editing!=0 AND s1.c_id = '.$course_id.' AND
@@ -2847,66 +2847,66 @@  discard block
 block discarded – undo
2847 2847
         )';
2848 2848
 
2849 2849
         // Can not use group by because the mark is set in the latest version
2850
-        $allpages=Database::query($sql);
2851
-        while ($row=Database::fetch_array($allpages)) {
2852
-            $total_editing_now	= $row['TOTAL_EDITING_NOW'];
2850
+        $allpages = Database::query($sql);
2851
+        while ($row = Database::fetch_array($allpages)) {
2852
+            $total_editing_now = $row['TOTAL_EDITING_NOW'];
2853 2853
         }
2854 2854
 
2855 2855
         // Total hidden pages
2856
-        $total_hidden=0;
2856
+        $total_hidden = 0;
2857 2857
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2858 2858
                 WHERE  c_id = '.$course_id.' AND visibility=0 AND '.$groupfilter.$condition_session.'
2859 2859
                 GROUP BY reflink';
2860 2860
         // or group by page_id. As the mark of hidden places it in all versions of the page, I can use group by to see the first
2861
-        $allpages=Database::query($sql);
2862
-        while ($row=Database::fetch_array($allpages)) {
2863
-            $total_hidden = $total_hidden+1;
2861
+        $allpages = Database::query($sql);
2862
+        while ($row = Database::fetch_array($allpages)) {
2863
+            $total_hidden = $total_hidden + 1;
2864 2864
         }
2865 2865
 
2866 2866
         //Total protect pages
2867
-        $total_protected=0;
2867
+        $total_protected = 0;
2868 2868
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2869 2869
                 WHERE  c_id = '.$course_id.' AND editlock=1 AND '.$groupfilter.$condition_session.'
2870 2870
                 GROUP BY reflink';
2871 2871
         // or group by page_id. As the mark of protected page is the first version of the page, I can use group by
2872 2872
 
2873
-        $allpages=Database::query($sql);
2874
-        while ($row=Database::fetch_array($allpages)) {
2875
-            $total_protected = $total_protected+1;
2873
+        $allpages = Database::query($sql);
2874
+        while ($row = Database::fetch_array($allpages)) {
2875
+            $total_protected = $total_protected + 1;
2876 2876
         }
2877 2877
 
2878 2878
         // Total empty versions.
2879
-        $total_empty_content=0;
2879
+        $total_empty_content = 0;
2880 2880
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2881 2881
                 WHERE
2882 2882
                     c_id = '.$course_id.' AND
2883 2883
                     content="" AND
2884 2884
                     '.$groupfilter.$condition_session.'';
2885 2885
         $allpages = Database::query($sql);
2886
-        while ($row=Database::fetch_array($allpages)) {
2887
-            $total_empty_content	= $total_empty_content+1;
2886
+        while ($row = Database::fetch_array($allpages)) {
2887
+            $total_empty_content = $total_empty_content + 1;
2888 2888
         }
2889 2889
 
2890 2890
         //Total empty pages (last version)
2891 2891
 
2892
-        $total_empty_content_lv=0;
2892
+        $total_empty_content_lv = 0;
2893 2893
         $sql = 'SELECT  * FROM  '.$tbl_wiki.' s1
2894 2894
                 WHERE s1.c_id = '.$course_id.' AND content="" AND id=(
2895 2895
                 SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
2896 2896
                 WHERE s1.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
2897
-        $allpages=Database::query($sql);
2897
+        $allpages = Database::query($sql);
2898 2898
         while ($row = Database::fetch_array($allpages)) {
2899
-            $total_empty_content_lv	= $total_empty_content_lv+1;
2899
+            $total_empty_content_lv = $total_empty_content_lv + 1;
2900 2900
         }
2901 2901
 
2902 2902
         // Total locked discuss pages
2903
-        $total_lock_disc=0;
2903
+        $total_lock_disc = 0;
2904 2904
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2905 2905
                 WHERE c_id = '.$course_id.' AND addlock_disc=0 AND '.$groupfilter.$condition_session.'
2906 2906
                 GROUP BY reflink';//group by because mark lock in all vers, then always is ok
2907
-        $allpages=Database::query($sql);
2907
+        $allpages = Database::query($sql);
2908 2908
         while ($row = Database::fetch_array($allpages)) {
2909
-            $total_lock_disc	= $total_lock_disc+1;
2909
+            $total_lock_disc = $total_lock_disc + 1;
2910 2910
         }
2911 2911
 
2912 2912
         // Total hidden discuss pages.
@@ -2917,7 +2917,7 @@  discard block
 block discarded – undo
2917 2917
         //group by because mark lock in all vers, then always is ok
2918 2918
         $allpages = Database::query($sql);
2919 2919
         while ($row = Database::fetch_array($allpages)) {
2920
-            $total_hidden_disc	= $total_hidden_disc+1;
2920
+            $total_hidden_disc = $total_hidden_disc + 1;
2921 2921
         }
2922 2922
 
2923 2923
         //Total versions with any short comment by user or system
@@ -2925,44 +2925,44 @@  discard block
 block discarded – undo
2925 2925
         $total_comment_version = 0;
2926 2926
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2927 2927
                 WHERE c_id = '.$course_id.' AND comment!="" AND '.$groupfilter.$condition_session.'';
2928
-        $allpages=Database::query($sql);
2928
+        $allpages = Database::query($sql);
2929 2929
         while ($row = Database::fetch_array($allpages)) {
2930
-            $total_comment_version	= $total_comment_version+1;
2930
+            $total_comment_version = $total_comment_version + 1;
2931 2931
         }
2932 2932
 
2933 2933
         // Total pages that can only be scored by teachers.
2934 2934
 
2935
-        $total_only_teachers_rating=0;
2935
+        $total_only_teachers_rating = 0;
2936 2936
         $sql = 'SELECT * FROM '.$tbl_wiki.'
2937 2937
                 WHERE c_id = '.$course_id.' AND
2938 2938
                 ratinglock_disc = 0 AND
2939 2939
                 '.$groupfilter.$condition_session.'
2940 2940
                 GROUP BY reflink';//group by because mark lock in all vers, then always is ok
2941
-        $allpages=Database::query($sql);
2942
-        while ($row=Database::fetch_array($allpages)) {
2943
-            $total_only_teachers_rating	= $total_only_teachers_rating+1;
2941
+        $allpages = Database::query($sql);
2942
+        while ($row = Database::fetch_array($allpages)) {
2943
+            $total_only_teachers_rating = $total_only_teachers_rating + 1;
2944 2944
         }
2945 2945
 
2946 2946
         // Total pages scored by peers
2947 2947
         // put always this line alfter check num all pages and num pages rated by teachers
2948
-        $total_rating_by_peers=$total_pages-$total_only_teachers_rating;
2948
+        $total_rating_by_peers = $total_pages - $total_only_teachers_rating;
2949 2949
 
2950 2950
         //Total pages identified as standard task
2951 2951
 
2952
-        $total_task=0;
2953
-        $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
2952
+        $total_task = 0;
2953
+        $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
2954 2954
               WHERE '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND
2955 2955
                '.$tbl_wiki_conf.'.task!="" AND
2956 2956
                '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
2957 2957
                 '.$tbl_wiki.'.'.$groupfilter.$condition_session;
2958 2958
         $allpages = Database::query($sql);
2959
-        while ($row=Database::fetch_array($allpages)) {
2960
-            $total_task=$total_task+1;
2959
+        while ($row = Database::fetch_array($allpages)) {
2960
+            $total_task = $total_task + 1;
2961 2961
         }
2962 2962
 
2963 2963
         //Total pages identified as teacher page (wiki portfolio mode - individual assignment)
2964 2964
 
2965
-        $total_teacher_assignment=0;
2965
+        $total_teacher_assignment = 0;
2966 2966
         $sql = 'SELECT  * FROM  '.$tbl_wiki.' s1
2967 2967
                 WHERE s1.c_id = '.$course_id.' AND assignment=1 AND id=(
2968 2968
                     SELECT MAX(s2.id)
@@ -2972,20 +2972,20 @@  discard block
 block discarded – undo
2972 2972
         //mark all versions, but do not use group by reflink because y want the pages not versions
2973 2973
         $allpages = Database::query($sql);
2974 2974
         while ($row = Database::fetch_array($allpages)) {
2975
-            $total_teacher_assignment=$total_teacher_assignment+1;
2975
+            $total_teacher_assignment = $total_teacher_assignment + 1;
2976 2976
         }
2977 2977
 
2978 2978
         //Total pages identifies as student page (wiki portfolio mode - individual assignment)
2979 2979
 
2980
-        $total_student_assignment=0;
2980
+        $total_student_assignment = 0;
2981 2981
         $sql = 'SELECT  * FROM  '.$tbl_wiki.' s1
2982 2982
                 WHERE s1.c_id = '.$course_id.' AND assignment=2 AND
2983 2983
                 id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
2984 2984
                 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
2985 2985
         //mark all versions, but do not use group by reflink because y want the pages not versions
2986
-        $allpages=Database::query($sql);
2987
-        while ($row=Database::fetch_array($allpages)) {
2988
-            $total_student_assignment = $total_student_assignment+1;
2986
+        $allpages = Database::query($sql);
2987
+        while ($row = Database::fetch_array($allpages)) {
2988
+            $total_student_assignment = $total_student_assignment + 1;
2989 2989
         }
2990 2990
 
2991 2991
         //Current Wiki status add new pages
@@ -2994,36 +2994,36 @@  discard block
 block discarded – undo
2994 2994
                 GROUP BY addlock';//group by because mark 0 in all vers, then always is ok
2995 2995
         $allpages = Database::query($sql);
2996 2996
         $wiki_add_lock = null;
2997
-        while ($row=Database::fetch_array($allpages)) {
2998
-            $wiki_add_lock=$row['addlock'];
2997
+        while ($row = Database::fetch_array($allpages)) {
2998
+            $wiki_add_lock = $row['addlock'];
2999 2999
         }
3000 3000
 
3001
-        if ($wiki_add_lock==1) {
3002
-            $status_add_new_pag=get_lang('Yes');
3001
+        if ($wiki_add_lock == 1) {
3002
+            $status_add_new_pag = get_lang('Yes');
3003 3003
         } else {
3004
-            $status_add_new_pag=get_lang('No');
3004
+            $status_add_new_pag = get_lang('No');
3005 3005
         }
3006 3006
 
3007 3007
         //Creation date of the oldest wiki page and version
3008 3008
 
3009
-        $first_wiki_date='0000-00-00 00:00:00';
3009
+        $first_wiki_date = '0000-00-00 00:00:00';
3010 3010
         $sql = 'SELECT * FROM '.$tbl_wiki.'
3011 3011
                 WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
3012 3012
                 ORDER BY dtime ASC LIMIT 1';
3013
-        $allpages=Database::query($sql);
3014
-        while ($row=Database::fetch_array($allpages)) {
3015
-            $first_wiki_date=$row['dtime'];
3013
+        $allpages = Database::query($sql);
3014
+        while ($row = Database::fetch_array($allpages)) {
3015
+            $first_wiki_date = $row['dtime'];
3016 3016
         }
3017 3017
 
3018 3018
         // Date of publication of the latest wiki version.
3019 3019
 
3020
-        $last_wiki_date='0000-00-00 00:00:00';
3020
+        $last_wiki_date = '0000-00-00 00:00:00';
3021 3021
         $sql = 'SELECT * FROM '.$tbl_wiki.'
3022 3022
                 WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
3023 3023
                 ORDER BY dtime DESC LIMIT 1';
3024
-        $allpages=Database::query($sql);
3025
-        while ($row=Database::fetch_array($allpages)) {
3026
-            $last_wiki_date=$row['dtime'];
3024
+        $allpages = Database::query($sql);
3025
+        while ($row = Database::fetch_array($allpages)) {
3026
+            $last_wiki_date = $row['dtime'];
3027 3027
         }
3028 3028
 
3029 3029
         // Average score of all wiki pages. (If a page has not scored zero rated)
@@ -3035,18 +3035,18 @@  discard block
 block discarded – undo
3035 3035
         // Do not use "count" because using "group by", would give a wrong value
3036 3036
         $allpages = Database::query($sql);
3037 3037
         $total_score = 0;
3038
-        while ($row=Database::fetch_array($allpages)) {
3039
-            $total_score = $total_score+$row['TOTAL_SCORE'];
3038
+        while ($row = Database::fetch_array($allpages)) {
3039
+            $total_score = $total_score + $row['TOTAL_SCORE'];
3040 3040
         }
3041 3041
 
3042 3042
         if (!empty($total_pages)) {
3043
-            $media_score = $total_score/$total_pages;
3043
+            $media_score = $total_score / $total_pages;
3044 3044
             //put always this line alfter check num all pages
3045 3045
         }
3046 3046
 
3047 3047
         // Average user progress in his pages.
3048 3048
 
3049
-        $media_progress=0;
3049
+        $media_progress = 0;
3050 3050
         $sql = 'SELECT  *, SUM(progress) AS TOTAL_PROGRESS
3051 3051
                 FROM  '.$tbl_wiki.' s1
3052 3052
                 WHERE s1.c_id = '.$course_id.' AND id=
@@ -3060,24 +3060,24 @@  discard block
 block discarded – undo
3060 3060
         // As the value is only the latest version I can not use group by
3061 3061
         $allpages = Database::query($sql);
3062 3062
         while ($row = Database::fetch_array($allpages)) {
3063
-            $total_progress	= $row['TOTAL_PROGRESS'];
3063
+            $total_progress = $row['TOTAL_PROGRESS'];
3064 3064
         }
3065 3065
 
3066 3066
         if (!empty($total_pages)) {
3067
-            $media_progress=$total_progress/$total_pages;
3067
+            $media_progress = $total_progress / $total_pages;
3068 3068
             //put always this line alfter check num all pages
3069 3069
         }
3070 3070
 
3071 3071
         //Total users that have participated in the Wiki
3072 3072
 
3073
-        $total_users=0;
3073
+        $total_users = 0;
3074 3074
         $sql = 'SELECT * FROM '.$tbl_wiki.'
3075 3075
                 WHERE  c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
3076 3076
                 GROUP BY user_id';
3077 3077
         //as the mark of user it in all versions of the page, I can use group by to see the first
3078
-        $allpages=Database::query($sql);
3079
-        while ($row=Database::fetch_array($allpages)) {
3080
-            $total_users = $total_users+1;
3078
+        $allpages = Database::query($sql);
3079
+        while ($row = Database::fetch_array($allpages)) {
3080
+            $total_users = $total_users + 1;
3081 3081
         }
3082 3082
 
3083 3083
         // Total of different IP addresses that have participated in the wiki
@@ -3085,9 +3085,9 @@  discard block
 block discarded – undo
3085 3085
         $sql = 'SELECT * FROM '.$tbl_wiki.'
3086 3086
               WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
3087 3087
               GROUP BY user_ip';
3088
-        $allpages=Database::query($sql);
3089
-        while ($row=Database::fetch_array($allpages)) {
3090
-            $total_ip	= $total_ip+1;
3088
+        $allpages = Database::query($sql);
3089
+        while ($row = Database::fetch_array($allpages)) {
3090
+            $total_ip = $total_ip + 1;
3091 3091
         }
3092 3092
 
3093 3093
         echo '<table class="data_table">';
@@ -3286,11 +3286,11 @@  discard block
 block discarded – undo
3286 3286
                 } else {
3287 3287
                     $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
3288 3288
                 }
3289
-                $row[] ='<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode($obj->user_id).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.$obj->NUM_EDIT.'</a>';
3289
+                $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode($obj->user_id).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.$obj->NUM_EDIT.'</a>';
3290 3290
                 $rows[] = $row;
3291 3291
             }
3292 3292
 
3293
-            $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC');
3293
+            $table = new SortableTableFromArrayConfig($rows, 1, 10, 'MostActiveUsersA_table', '', '', 'DESC');
3294 3294
             $table->set_additional_parameters(
3295 3295
                 array(
3296 3296
                     'cidReq' => Security::remove_XSS($_GET['cidReq']),
@@ -3299,8 +3299,8 @@  discard block
 block discarded – undo
3299 3299
                     'group_id' => Security::remove_XSS($_GET['group_id'])
3300 3300
                 )
3301 3301
             );
3302
-            $table->set_header(0,get_lang('Author'), true);
3303
-            $table->set_header(1,get_lang('Contributions'), true,array ('style' => 'width:30px;'));
3302
+            $table->set_header(0, get_lang('Author'), true);
3303
+            $table->set_header(1, get_lang('Contributions'), true, array('style' => 'width:30px;'));
3304 3304
             $table->display();
3305 3305
         }
3306 3306
     }
@@ -3316,8 +3316,8 @@  discard block
 block discarded – undo
3316 3316
         $groupfilter = $this->groupfilter;
3317 3317
         $tbl_wiki_discuss = $this->tbl_wiki_discuss;
3318 3318
 
3319
-        if (api_get_session_id()!=0 &&
3320
-            api_is_allowed_to_session_edit(false,true)==false
3319
+        if (api_get_session_id() != 0 &&
3320
+            api_is_allowed_to_session_edit(false, true) == false
3321 3321
         ) {
3322 3322
             api_not_allowed();
3323 3323
         }
@@ -3380,9 +3380,9 @@  discard block
 block discarded – undo
3380 3380
         //mode assignment: previous to show  page type
3381 3381
         $icon_assignment = null;
3382 3382
         if ($row['assignment'] == 1) {
3383
-            $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
3383
+            $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
3384 3384
         } elseif ($row['assignment'] == 2) {
3385
-            $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
3385
+            $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'), '', ICON_SIZE_SMALL);
3386 3386
         }
3387 3387
 
3388 3388
         $countWPost = null;
@@ -3393,23 +3393,23 @@  discard block
 block discarded – undo
3393 3393
             // Show discussion to students if isn't hidden.
3394 3394
             // Show page to all teachers if is hidden.
3395 3395
             // Mode assignments: If is hidden, show pages to student only if student is the author
3396
-            if ($row['visibility_disc']==1 ||
3397
-                api_is_allowed_to_edit(false,true) ||
3396
+            if ($row['visibility_disc'] == 1 ||
3397
+                api_is_allowed_to_edit(false, true) ||
3398 3398
                 api_is_platform_admin() ||
3399
-                ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))
3399
+                ($row['assignment'] == 2 && $row['visibility_disc'] == 0 && (api_get_user_id() == $row['user_id']))
3400 3400
             ) {
3401 3401
                 echo '<div id="wikititle">';
3402 3402
 
3403 3403
                 // discussion action: protecting (locking) the discussion
3404 3404
                 $addlock_disc = null;
3405 3405
                 $lock_unlock_disc = null;
3406
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3406
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3407 3407
                     if (self::check_addlock_discuss() == 1) {
3408
-                        $addlock_disc = Display::return_icon('unlock.png', get_lang('UnlockDiscussExtra'),'',ICON_SIZE_SMALL);
3409
-                        $lock_unlock_disc ='unlockdisc';
3408
+                        $addlock_disc = Display::return_icon('unlock.png', get_lang('UnlockDiscussExtra'), '', ICON_SIZE_SMALL);
3409
+                        $lock_unlock_disc = 'unlockdisc';
3410 3410
                     } else {
3411
-                        $addlock_disc = Display::return_icon('lock.png', get_lang('LockDiscussExtra'),'',ICON_SIZE_SMALL);
3412
-                        $lock_unlock_disc ='lockdisc';
3411
+                        $addlock_disc = Display::return_icon('lock.png', get_lang('LockDiscussExtra'), '', ICON_SIZE_SMALL);
3412
+                        $lock_unlock_disc = 'lockdisc';
3413 3413
                     }
3414 3414
                 }
3415 3415
                 echo '<span style="float:right">';
@@ -3419,13 +3419,13 @@  discard block
 block discarded – undo
3419 3419
                 // discussion action: visibility.  Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
3420 3420
                 $visibility_disc = null;
3421 3421
                 $hide_show_disc = null;
3422
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3423
-                    if (self::check_visibility_discuss()==1) {
3422
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3423
+                    if (self::check_visibility_discuss() == 1) {
3424 3424
                         /// TODO: 	Fix Mode assignments: If is hidden, show discussion to student only if student is the author
3425
-                        $visibility_disc = Display::return_icon('visible.png', get_lang('ShowDiscussExtra'),'',ICON_SIZE_SMALL);
3425
+                        $visibility_disc = Display::return_icon('visible.png', get_lang('ShowDiscussExtra'), '', ICON_SIZE_SMALL);
3426 3426
                         $hide_show_disc = 'hidedisc';
3427 3427
                     } else {
3428
-                        $visibility_disc = Display::return_icon('invisible.png', get_lang('HideDiscussExtra'),'',ICON_SIZE_SMALL);
3428
+                        $visibility_disc = Display::return_icon('invisible.png', get_lang('HideDiscussExtra'), '', ICON_SIZE_SMALL);
3429 3429
                         $hide_show_disc = 'showdisc';
3430 3430
                     }
3431 3431
                 }
@@ -3436,12 +3436,12 @@  discard block
 block discarded – undo
3436 3436
                 //discussion action: check add rating lock. Show/Hide list to rating for all student
3437 3437
                 $lock_unlock_rating_disc = null;
3438 3438
                 $ratinglock_disc = null;
3439
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3439
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3440 3440
                     if (self::check_ratinglock_discuss() == 1) {
3441
-                        $ratinglock_disc = Display::return_icon('star.png', get_lang('UnlockRatingDiscussExtra'),'',ICON_SIZE_SMALL);
3441
+                        $ratinglock_disc = Display::return_icon('star.png', get_lang('UnlockRatingDiscussExtra'), '', ICON_SIZE_SMALL);
3442 3442
                         $lock_unlock_rating_disc = 'unlockrating';
3443 3443
                     } else {
3444
-                        $ratinglock_disc = Display::return_icon('star_na.png', get_lang('LockRatingDiscussExtra'),'',ICON_SIZE_SMALL);
3444
+                        $ratinglock_disc = Display::return_icon('star_na.png', get_lang('LockRatingDiscussExtra'), '', ICON_SIZE_SMALL);
3445 3445
                         $lock_unlock_rating_disc = 'lockrating';
3446 3446
                     }
3447 3447
                 }
@@ -3452,11 +3452,11 @@  discard block
 block discarded – undo
3452 3452
 
3453 3453
                 //discussion action: email notification
3454 3454
                 if (self::check_notify_discuss($page) == 1) {
3455
-                    $notify_disc= Display::return_icon('messagebox_info.png', get_lang('NotifyDiscussByEmail'),'',ICON_SIZE_SMALL);
3456
-                    $lock_unlock_notify_disc='unlocknotifydisc';
3455
+                    $notify_disc = Display::return_icon('messagebox_info.png', get_lang('NotifyDiscussByEmail'), '', ICON_SIZE_SMALL);
3456
+                    $lock_unlock_notify_disc = 'unlocknotifydisc';
3457 3457
                 } else {
3458
-                    $notify_disc= Display::return_icon('mail.png', get_lang('CancelNotifyDiscussByEmail'),'',ICON_SIZE_SMALL);
3459
-                    $lock_unlock_notify_disc='locknotifydisc';
3458
+                    $notify_disc = Display::return_icon('mail.png', get_lang('CancelNotifyDiscussByEmail'), '', ICON_SIZE_SMALL);
3459
+                    $lock_unlock_notify_disc = 'locknotifydisc';
3460 3460
                 }
3461 3461
                 echo '<span style="float:right">';
3462 3462
                 echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_notify_disc.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$notify_disc.'</a>';
@@ -3468,22 +3468,22 @@  discard block
 block discarded – undo
3468 3468
 
3469 3469
                 echo '</div>';
3470 3470
 
3471
-                if ($row['addlock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3471
+                if ($row['addlock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3472 3472
                     //show comments but students can't add theirs
3473 3473
                     ?>
3474 3474
                     <form name="form1" method="post" action="">
3475 3475
                         <table>
3476 3476
                             <tr>
3477
-                                <td valign="top" ><?php echo get_lang('Comments');?>:</td>
3478
-                                <?php  echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post ?>
3477
+                                <td valign="top" ><?php echo get_lang('Comments'); ?>:</td>
3478
+                                <?php  echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">'; //prevent double post ?>
3479 3479
                                 <td><textarea name="comment" cols="80" rows="5" id="comment"></textarea></td>
3480 3480
                             </tr>
3481 3481
                             <tr>
3482 3482
                                 <?php
3483 3483
                                 //check if rating is allowed
3484
-                                if ($row['ratinglock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3484
+                                if ($row['ratinglock_disc'] == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3485 3485
                                     ?>
3486
-                                    <td><?php echo get_lang('Rating');?>: </td>
3486
+                                    <td><?php echo get_lang('Rating'); ?>: </td>
3487 3487
                                     <td valign="top"><select name="rating" id="rating">
3488 3488
                                             <option value="-" selected>-</option>
3489 3489
                                             <option value="0">0</option>
@@ -3500,7 +3500,7 @@  discard block
 block discarded – undo
3500 3500
                                         </select></td>
3501 3501
                                 <?php
3502 3502
                                 } else {
3503
-                                    echo '<input type=hidden name="rating" value="-">';// must pass a default value to avoid rate automatically
3503
+                                    echo '<input type=hidden name="rating" value="-">'; // must pass a default value to avoid rate automatically
3504 3504
                                 }
3505 3505
                                 ?>
3506 3506
                             </tr>
@@ -3540,12 +3540,12 @@  discard block
 block discarded – undo
3540 3540
                 $sql = "SELECT * FROM $tbl_wiki_discuss
3541 3541
                         WHERE c_id = $course_id AND publication_id='".$id."' AND NOT p_score='-'";
3542 3542
                 $result3 = Database::query($sql);
3543
-                $countWPost_score= Database::num_rows($result3);
3543
+                $countWPost_score = Database::num_rows($result3);
3544 3544
 
3545
-                echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;//
3545
+                echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score; //
3546 3546
 
3547
-                if ($countWPost_score!=0) {
3548
-                    $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10';
3547
+                if ($countWPost_score != 0) {
3548
+                    $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score, 2).' / 10';
3549 3549
                 } else {
3550 3550
                     $avg_WPost_score = $countWPost_score;
3551 3551
                 }
@@ -3563,16 +3563,16 @@  discard block
 block discarded – undo
3563 3563
 
3564 3564
                 echo '<hr noshade size="1">';
3565 3565
 
3566
-                while ($row=Database::fetch_array($result)) {
3566
+                while ($row = Database::fetch_array($result)) {
3567 3567
                     $userinfo = api_get_user_info($row['userc_id']);
3568
-                    if (($userinfo['status'])=="5") {
3569
-                        $author_status=get_lang('Student');
3568
+                    if (($userinfo['status']) == "5") {
3569
+                        $author_status = get_lang('Student');
3570 3570
                     } else {
3571
-                        $author_status=get_lang('Teacher');
3571
+                        $author_status = get_lang('Teacher');
3572 3572
                     }
3573 3573
 
3574 3574
                     $name = $userinfo['complete_name'];
3575
-                    $author_photo= '<img src="'.$userinfo['avatar'].'" alt="'.api_htmlentities($name).'"  width="40" height="50" align="top"  title="'.api_htmlentities($name).'"  />';
3575
+                    $author_photo = '<img src="'.$userinfo['avatar'].'" alt="'.api_htmlentities($name).'"  width="40" height="50" align="top"  title="'.api_htmlentities($name).'"  />';
3576 3576
 
3577 3577
                     //stars
3578 3578
                     $p_score = $row['p_score'];
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
         }
3652 3652
         echo '</div>';
3653 3653
 
3654
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
3654
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
3655 3655
             $sql = 'SELECT  *
3656 3656
                     FROM  '.$tbl_wiki.' s1
3657 3657
         		    WHERE s1.c_id = '.$course_id.' AND id=(
@@ -3677,26 +3677,26 @@  discard block
 block discarded – undo
3677 3677
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
3678 3678
 
3679 3679
                 //get type assignment icon
3680
-                if ($obj->assignment==1) {
3681
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
3682
-                } elseif ($obj->assignment==2) {
3683
-                    $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
3684
-                } elseif ($obj->assignment==0) {
3680
+                if ($obj->assignment == 1) {
3681
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
3682
+                } elseif ($obj->assignment == 2) {
3683
+                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
3684
+                } elseif ($obj->assignment == 0) {
3685 3685
                     $ShowAssignment = Display::return_icon('px_transparent.gif');
3686 3686
                 }
3687 3687
 
3688 3688
                 //get icon task
3689 3689
                 if (!empty($obj->task)) {
3690
-                    $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
3690
+                    $icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL);
3691 3691
                 } else {
3692
-                    $icon_task= Display::return_icon('px_transparent.gif');
3692
+                    $icon_task = Display::return_icon('px_transparent.gif');
3693 3693
                 }
3694 3694
 
3695 3695
                 $row = array();
3696 3696
                 $row[] = $ShowAssignment.$icon_task;
3697 3697
                 $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">
3698 3698
                 '.api_htmlentities($obj->title).'</a>';
3699
-                if ($obj->user_id <>0) {
3699
+                if ($obj->user_id <> 0) {
3700 3700
                     $row[] = UserManager::getUserProfileLink($userinfo);
3701 3701
                 }
3702 3702
                 else {
@@ -3704,29 +3704,29 @@  discard block
 block discarded – undo
3704 3704
                 }
3705 3705
                 $row[] = api_get_local_time($obj->dtime, null, date_default_timezone_get());
3706 3706
                 $showdelete = '';
3707
-                if (api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) {
3708
-                    $showdelete =' <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=delete&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3709
-                        Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
3707
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3708
+                    $showdelete = ' <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=delete&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3709
+                        Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
3710 3710
                 }
3711
-                if (api_is_allowed_to_session_edit(false,true) ) {
3711
+                if (api_is_allowed_to_session_edit(false, true)) {
3712 3712
                     $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=edit&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3713
-                        Display::return_icon('edit.png', get_lang('EditPage'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3714
-                        Display::return_icon('discuss.png', get_lang('Discuss'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3715
-                        Display::return_icon('history.png', get_lang('History'),'',ICON_SIZE_SMALL).'</a>
3713
+                        Display::return_icon('edit.png', get_lang('EditPage'), '', ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=discuss&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3714
+                        Display::return_icon('discuss.png', get_lang('Discuss'), '', ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=history&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3715
+                        Display::return_icon('history.png', get_lang('History'), '', ICON_SIZE_SMALL).'</a>
3716 3716
                         <a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=links&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3717
-                        Display::return_icon('what_link_here.png', get_lang('LinksPages'),'',ICON_SIZE_SMALL).'</a>'.$showdelete;
3717
+                        Display::return_icon('what_link_here.png', get_lang('LinksPages'), '', ICON_SIZE_SMALL).'</a>'.$showdelete;
3718 3718
                 }
3719 3719
                 $rows[] = $row;
3720 3720
             }
3721 3721
 
3722
-            $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
3723
-            $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action),'group_id'=>Security::remove_XSS($_GET['group_id'])));
3724
-            $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
3725
-            $table->set_header(1,get_lang('Title'), true);
3726
-            $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true);
3727
-            $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
3728
-            if (api_is_allowed_to_session_edit(false,true) ) {
3729
-                $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:130px;'));
3722
+            $table = new SortableTableFromArrayConfig($rows, 1, 10, 'AllPages_table', '', '', 'ASC');
3723
+            $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']), 'action'=>Security::remove_XSS($action), 'group_id'=>Security::remove_XSS($_GET['group_id'])));
3724
+            $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;'));
3725
+            $table->set_header(1, get_lang('Title'), true);
3726
+            $table->set_header(2, get_lang('Author').' ('.get_lang('LastVersion').')', true);
3727
+            $table->set_header(3, get_lang('Date').' ('.get_lang('LastVersion').')', true);
3728
+            if (api_is_allowed_to_session_edit(false, true)) {
3729
+                $table->set_header(4, get_lang('Actions'), true, array('style' => 'width:130px;'));
3730 3730
             }
3731 3731
             $table->display();
3732 3732
         }
@@ -3746,13 +3746,13 @@  discard block
 block discarded – undo
3746 3746
         $groupfilter = $this->groupfilter;
3747 3747
         $tbl_wiki_conf = $this->tbl_wiki_conf;
3748 3748
 
3749
-        if (api_is_allowed_to_session_edit(false,true) ) {
3750
-            if (self::check_notify_all()==1) {
3751
-                $notify_all= Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotNotifyChanges');
3752
-                $lock_unlock_notify_all='unlocknotifyall';
3749
+        if (api_is_allowed_to_session_edit(false, true)) {
3750
+            if (self::check_notify_all() == 1) {
3751
+                $notify_all = Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'), '', ICON_SIZE_SMALL).' '.get_lang('NotNotifyChanges');
3752
+                $lock_unlock_notify_all = 'unlocknotifyall';
3753 3753
             } else {
3754
-                $notify_all=Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotifyChanges');
3755
-                $lock_unlock_notify_all='locknotifyall';
3754
+                $notify_all = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'), '', ICON_SIZE_SMALL).' '.get_lang('NotifyChanges');
3755
+                $lock_unlock_notify_all = 'locknotifyall';
3756 3756
             }
3757 3757
         }
3758 3758
 
@@ -3760,7 +3760,7 @@  discard block
 block discarded – undo
3760 3760
         echo '<a href="index.php?action=recentchanges&amp;actionpage='.$lock_unlock_notify_all.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$notify_all.'</a>';
3761 3761
         echo '</span>'.get_lang('RecentChanges').'</div>';
3762 3762
 
3763
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
3763
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
3764 3764
             $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
3765 3765
         		WHERE 	'.$tbl_wiki_conf.'.c_id= '.$course_id.' AND
3766 3766
         				'.$tbl_wiki.'.c_id= '.$course_id.' AND
@@ -3788,19 +3788,19 @@  discard block
 block discarded – undo
3788 3788
                 $userinfo = api_get_user_info($obj->user_id);
3789 3789
 
3790 3790
                 //get type assignment icon
3791
-                if ($obj->assignment==1) {
3792
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
3793
-                } elseif ($obj->assignment==2) {
3794
-                    $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
3795
-                } elseif ($obj->assignment==0) {
3796
-                    $ShowAssignment=Display::return_icon('px_transparent.gif');
3791
+                if ($obj->assignment == 1) {
3792
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
3793
+                } elseif ($obj->assignment == 2) {
3794
+                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
3795
+                } elseif ($obj->assignment == 0) {
3796
+                    $ShowAssignment = Display::return_icon('px_transparent.gif');
3797 3797
                 }
3798 3798
 
3799 3799
                 // Get icon task
3800 3800
                 if (!empty($obj->task)) {
3801
-                    $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
3801
+                    $icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL);
3802 3802
                 } else {
3803
-                    $icon_task=Display::return_icon('px_transparent.gif');
3803
+                    $icon_task = Display::return_icon('px_transparent.gif');
3804 3804
                 }
3805 3805
 
3806 3806
                 $row = array();
@@ -3808,8 +3808,8 @@  discard block
 block discarded – undo
3808 3808
                 $row[] = $ShowAssignment.$icon_task;
3809 3809
                 $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&amp;view='.$obj->id.'&session_id='.api_get_session_id().'&group_id='.api_get_group_id().'">'.
3810 3810
                     api_htmlentities($obj->title).'</a>';
3811
-                $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
3812
-                if ($obj->user_id <> 0 ) {
3811
+                $row[] = $obj->version > 1 ? get_lang('EditedBy') : get_lang('AddedBy');
3812
+                if ($obj->user_id <> 0) {
3813 3813
                     $row[] = UserManager::getUserProfileLink($userinfo);
3814 3814
                 } else {
3815 3815
                     $row[] = get_lang('Anonymous').' ('.api_htmlentities($obj->user_ip).')';
@@ -3817,7 +3817,7 @@  discard block
 block discarded – undo
3817 3817
                 $rows[] = $row;
3818 3818
             }
3819 3819
 
3820
-            $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC');
3820
+            $table = new SortableTableFromArrayConfig($rows, 0, 10, 'RecentPages_table', '', '', 'DESC');
3821 3821
             $table->set_additional_parameters(
3822 3822
                 array(
3823 3823
                     'cidReq' =>api_get_course_id(),
@@ -3826,11 +3826,11 @@  discard block
 block discarded – undo
3826 3826
                     'group_id' => api_get_group_id()
3827 3827
                 )
3828 3828
             );
3829
-            $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
3830
-            $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
3831
-            $table->set_header(2,get_lang('Title'), true);
3832
-            $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;'));
3833
-            $table->set_header(4,get_lang('Author'), true);
3829
+            $table->set_header(0, get_lang('Date'), true, array('style' => 'width:200px;'));
3830
+            $table->set_header(1, get_lang('Type'), true, array('style' => 'width:30px;'));
3831
+            $table->set_header(2, get_lang('Title'), true);
3832
+            $table->set_header(3, get_lang('Actions'), true, array('style' => 'width:80px;'));
3833
+            $table->set_header(4, get_lang('Author'), true);
3834 3834
             $table->display();
3835 3835
         }
3836 3836
     }
@@ -3862,17 +3862,17 @@  discard block
 block discarded – undo
3862 3862
 
3863 3863
             //get type assignment icon
3864 3864
             $ShowAssignment = '';
3865
-            if ($row['assignment']==1) {
3866
-                $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
3867
-            } elseif ($row['assignment']==2) {
3868
-                $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
3869
-            } elseif ($row['assignment']==0) {
3870
-                $ShowAssignment=Display::return_icon('px_transparent.gif');
3865
+            if ($row['assignment'] == 1) {
3866
+                $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
3867
+            } elseif ($row['assignment'] == 2) {
3868
+                $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
3869
+            } elseif ($row['assignment'] == 0) {
3870
+                $ShowAssignment = Display::return_icon('px_transparent.gif');
3871 3871
             }
3872 3872
 
3873 3873
             //fix Title to reflink (link Main Page)
3874
-            if ($page==get_lang('DefaultTitle')) {
3875
-                $page='index';
3874
+            if ($page == get_lang('DefaultTitle')) {
3875
+                $page = 'index';
3876 3876
             }
3877 3877
 
3878 3878
             echo '<div id="wikititle">';
@@ -3883,11 +3883,11 @@  discard block
 block discarded – undo
3883 3883
             //fix index to title Main page into linksto
3884 3884
 
3885 3885
             if ($page == 'index') {
3886
-                $page = str_replace(' ','_',get_lang('DefaultTitle'));
3886
+                $page = str_replace(' ', '_', get_lang('DefaultTitle'));
3887 3887
             }
3888 3888
 
3889 3889
             //table
3890
-            if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
3890
+            if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
3891 3891
                 //only by professors if page is hidden
3892 3892
                 $sql = "SELECT * FROM ".$tbl_wiki." s1
3893 3893
                         WHERE s1.c_id = $course_id AND linksto LIKE '%".Database::escape_string($page)."%' AND id=(
@@ -3914,25 +3914,25 @@  discard block
 block discarded – undo
3914 3914
                     //get time
3915 3915
                     $year 	 = substr($obj->dtime, 0, 4);
3916 3916
                     $month	 = substr($obj->dtime, 5, 2);
3917
-                    $day 	 = substr($obj->dtime, 8, 2);
3918
-                    $hours   = substr($obj->dtime, 11,2);
3919
-                    $minutes = substr($obj->dtime, 14,2);
3920
-                    $seconds = substr($obj->dtime, 17,2);
3917
+                    $day = substr($obj->dtime, 8, 2);
3918
+                    $hours   = substr($obj->dtime, 11, 2);
3919
+                    $minutes = substr($obj->dtime, 14, 2);
3920
+                    $seconds = substr($obj->dtime, 17, 2);
3921 3921
 
3922 3922
                     //get type assignment icon
3923
-                    if ($obj->assignment==1) {
3924
-                        $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
3925
-                    } elseif ($obj->assignment==2) {
3926
-                        $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
3927
-                    } elseif ($obj->assignment==0) {
3928
-                        $ShowAssignment=Display::return_icon('px_transparent.gif');
3923
+                    if ($obj->assignment == 1) {
3924
+                        $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
3925
+                    } elseif ($obj->assignment == 2) {
3926
+                        $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
3927
+                    } elseif ($obj->assignment == 0) {
3928
+                        $ShowAssignment = Display::return_icon('px_transparent.gif');
3929 3929
                     }
3930 3930
 
3931 3931
                     $row = array();
3932
-                    $row[] =$ShowAssignment;
3932
+                    $row[] = $ShowAssignment;
3933 3933
                     $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
3934 3934
                         api_htmlentities($obj->title).'</a>';
3935
-                    if ($obj->user_id <>0) {
3935
+                    if ($obj->user_id <> 0) {
3936 3936
                         $row[] = UserManager::getUserProfileLink($userinfo);
3937 3937
                     }
3938 3938
                     else {
@@ -4041,7 +4041,7 @@  discard block
 block discarded – undo
4041 4041
             '&session_id='.$this->session_id.'&group_id='.$this->group_id.'">
4042 4042
             </a></div>';
4043 4043
 
4044
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
4044
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
4045 4045
             //only by professors if page is hidden
4046 4046
             $sql = 'SELECT * FROM '.$tbl_wiki.'
4047 4047
                     WHERE
@@ -4066,19 +4066,19 @@  discard block
 block discarded – undo
4066 4066
                 // Get time
4067 4067
                 $year 	 = substr($obj->dtime, 0, 4);
4068 4068
                 $month	 = substr($obj->dtime, 5, 2);
4069
-                $day 	 = substr($obj->dtime, 8, 2);
4070
-                $hours   = substr($obj->dtime, 11,2);
4071
-                $minutes = substr($obj->dtime, 14,2);
4072
-                $seconds = substr($obj->dtime, 17,2);
4069
+                $day = substr($obj->dtime, 8, 2);
4070
+                $hours   = substr($obj->dtime, 11, 2);
4071
+                $minutes = substr($obj->dtime, 14, 2);
4072
+                $seconds = substr($obj->dtime, 17, 2);
4073 4073
 
4074 4074
                 //get type assignment icon
4075 4075
                 $ShowAssignment = '';
4076
-                if ($obj->assignment==1) {
4077
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
4078
-                } elseif ($obj->assignment==2) {
4079
-                    $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
4080
-                } elseif ($obj->assignment==0) {
4081
-                    $ShowAssignment= Display::return_icon('px_transparent.gif');
4076
+                if ($obj->assignment == 1) {
4077
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
4078
+                } elseif ($obj->assignment == 2) {
4079
+                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
4080
+                } elseif ($obj->assignment == 0) {
4081
+                    $ShowAssignment = Display::return_icon('px_transparent.gif');
4082 4082
                 }
4083 4083
 
4084 4084
                 $row = array();
@@ -4094,7 +4094,7 @@  discard block
 block discarded – undo
4094 4094
 
4095 4095
             }
4096 4096
 
4097
-            $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC');
4097
+            $table = new SortableTableFromArrayConfig($rows, 2, 10, 'UsersContributions_table', '', '', 'ASC');
4098 4098
             $table->set_additional_parameters(
4099 4099
                 array(
4100 4100
                     'cidReq' => Security::remove_XSS($_GET['cidReq']),
@@ -4104,13 +4104,13 @@  discard block
 block discarded – undo
4104 4104
                     'group_id' => intval($_GET['group_id']),
4105 4105
                 )
4106 4106
             );
4107
-            $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
4108
-            $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
4109
-            $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;'));
4110
-            $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;'));
4111
-            $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;'));
4112
-            $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;'));
4113
-            $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;'));
4107
+            $table->set_header(0, get_lang('Date'), true, array('style' => 'width:200px;'));
4108
+            $table->set_header(1, get_lang('Type'), true, array('style' => 'width:30px;'));
4109
+            $table->set_header(2, get_lang('Title'), true, array('style' => 'width:200px;'));
4110
+            $table->set_header(3, get_lang('Version'), true, array('style' => 'width:30px;'));
4111
+            $table->set_header(4, get_lang('Comment'), true, array('style' => 'width:200px;'));
4112
+            $table->set_header(5, get_lang('Progress'), true, array('style' => 'width:30px;'));
4113
+            $table->set_header(6, get_lang('Rating'), true, array('style' => 'width:30px;'));
4114 4114
             $table->display();
4115 4115
         }
4116 4116
     }
@@ -4128,7 +4128,7 @@  discard block
 block discarded – undo
4128 4128
 
4129 4129
         echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
4130 4130
 
4131
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
4131
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
4132 4132
             $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
4133 4133
                     WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
4134 4134
                     GROUP BY reflink';//TODO:check MAX and group by return last version
@@ -4146,12 +4146,12 @@  discard block
 block discarded – undo
4146 4146
             while ($obj = Database::fetch_object($allpages)) {
4147 4147
                 //get type assignment icon
4148 4148
                 $ShowAssignment = '';
4149
-                if ($obj->assignment==1) {
4150
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
4151
-                } elseif ($obj->assignment==2) {
4152
-                    $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
4153
-                } elseif ($obj->assignment==0) {
4154
-                    $ShowAssignment= Display::return_icon('px_transparent.gif');
4149
+                if ($obj->assignment == 1) {
4150
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
4151
+                } elseif ($obj->assignment == 2) {
4152
+                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
4153
+                } elseif ($obj->assignment == 0) {
4154
+                    $ShowAssignment = Display::return_icon('px_transparent.gif');
4155 4155
                 }
4156 4156
 
4157 4157
                 $row = array();
@@ -4179,9 +4179,9 @@  discard block
 block discarded – undo
4179 4179
                     'group_id' => intval($_GET['group_id']),
4180 4180
                 )
4181 4181
             );
4182
-            $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
4183
-            $table->set_header(1,get_lang('Title'), true);
4184
-            $table->set_header(2,get_lang('Changes'), true);
4182
+            $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;'));
4183
+            $table->set_header(1, get_lang('Title'), true);
4184
+            $table->set_header(2, get_lang('Changes'), true);
4185 4185
             $table->display();
4186 4186
         }
4187 4187
     }
@@ -4206,7 +4206,7 @@  discard block
 block discarded – undo
4206 4206
         /* Only teachers and platform admin can edit the index page.
4207 4207
         Only teachers and platform admin can edit an assignment teacher*/
4208 4208
         if (($current_row['reflink'] == 'index' || $current_row['reflink'] == '' || $current_row['assignment'] == 1) &&
4209
-            (!api_is_allowed_to_edit(false,true) && $this->group_id == 0)
4209
+            (!api_is_allowed_to_edit(false, true) && $this->group_id == 0)
4210 4210
         ) {
4211 4211
             self::setMessage(
4212 4212
                 Display::display_normal_message(get_lang('OnlyEditPagesCourseManager'), false, true)
@@ -4216,7 +4216,7 @@  discard block
 block discarded – undo
4216 4216
             // check if is a wiki group
4217 4217
             if ($current_row['group_id'] != 0) {
4218 4218
                 //Only teacher, platform admin and group members can edit a wiki group
4219
-                if (api_is_allowed_to_edit(false,true) ||
4219
+                if (api_is_allowed_to_edit(false, true) ||
4220 4220
                     api_is_platform_admin() ||
4221 4221
                     GroupManager :: is_user_in_group($userId, $this->group_id)
4222 4222
                 ) {
@@ -4234,9 +4234,9 @@  discard block
 block discarded – undo
4234 4234
             //$icon_assignment = null;
4235 4235
             if ($current_row['assignment'] == 1) {
4236 4236
                 self::setMessage(Display::display_normal_message(get_lang('EditAssignmentWarning'), false, true));
4237
-            } elseif($current_row['assignment']==2) {
4238
-                if (($userId == $current_row['user_id'])==false) {
4239
-                    if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
4237
+            } elseif ($current_row['assignment'] == 2) {
4238
+                if (($userId == $current_row['user_id']) == false) {
4239
+                    if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
4240 4240
                         $PassEdit = true;
4241 4241
                     } else {
4242 4242
                         self::setMessage(Display::display_warning_message(get_lang('LockByTeacher'), false, true));
@@ -4250,11 +4250,11 @@  discard block
 block discarded – undo
4250 4250
             //show editor if edit is allowed
4251 4251
             if ($PassEdit) {
4252 4252
                 if ($current_row['editlock'] == 1 &&
4253
-                    (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)
4253
+                    (api_is_allowed_to_edit(false, true) == false || api_is_platform_admin() == false)
4254 4254
                 ) {
4255 4255
                     self::setMessage(Display::display_normal_message(get_lang('PageLockedExtra'), false, true));
4256 4256
                 } else {
4257
-                    if ($last_row['is_editing']!=0 && $last_row['is_editing'] != $userId) {
4257
+                    if ($last_row['is_editing'] != 0 && $last_row['is_editing'] != $userId) {
4258 4258
                         // Checking for concurrent users
4259 4259
                         $timestamp_edit = strtotime($last_row['time_edit']);
4260 4260
                         $time_editing = time() - $timestamp_edit;
@@ -4263,7 +4263,7 @@  discard block
 block discarded – undo
4263 4263
                         $userinfo = api_get_user_info($last_row['is_editing']);
4264 4264
                         $is_being_edited = get_lang('ThisPageisBeginEditedBy').' <a href='.$userinfo['profile_url'].'>'.
4265 4265
                             Display::tag('span', $userinfo['complete_name_with_username']).
4266
-                            get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes');
4266
+                            get_lang('ThisPageisBeginEditedTryLater').' '.date("i", $rest_time).' '.get_lang('MinMinutes');
4267 4267
                         self::setMessage(Display::display_normal_message($is_being_edited, false, true));
4268 4268
                     } else {
4269 4269
                         self::setMessage(Display::display_confirmation_message(
@@ -4371,9 +4371,9 @@  discard block
 block discarded – undo
4371 4371
                 GROUP BY reflink
4372 4372
                 ORDER BY reflink ASC';
4373 4373
         $allpages = Database::query($sql);
4374
-        while ($row=Database::fetch_array($allpages)) {
4375
-            if ($row['reflink']=='index') {
4376
-                $row['reflink']=str_replace(' ', '_', get_lang('DefaultTitle'));
4374
+        while ($row = Database::fetch_array($allpages)) {
4375
+            if ($row['reflink'] == 'index') {
4376
+                $row['reflink'] = str_replace(' ', '_', get_lang('DefaultTitle'));
4377 4377
             }
4378 4378
             $pages[] = $row['reflink'];
4379 4379
         }
@@ -4391,16 +4391,16 @@  discard block
 block discarded – undo
4391 4391
 
4392 4392
         $allpages = Database::query($sql);
4393 4393
 
4394
-        while ($row=Database::fetch_array($allpages)) {
4394
+        while ($row = Database::fetch_array($allpages)) {
4395 4395
             //remove self reference
4396
-            $row['linksto']= str_replace($row["reflink"], " ", trim($row["linksto"]));
4396
+            $row['linksto'] = str_replace($row["reflink"], " ", trim($row["linksto"]));
4397 4397
             $refs = explode(" ", trim($row["linksto"]));
4398 4398
 
4399 4399
             // Find linksto into reflink. If found ->page is linked
4400 4400
             foreach ($refs as $v) {
4401 4401
                 if (in_array($v, $pages)) {
4402
-                    if (trim($v)!="") {
4403
-                        $linked[]=$v;
4402
+                    if (trim($v) != "") {
4403
+                        $linked[] = $v;
4404 4404
                     }
4405 4405
                 }
4406 4406
             }
@@ -4412,12 +4412,12 @@  discard block
 block discarded – undo
4412 4412
         $rows = array();
4413 4413
         foreach ($linked as $linked_show) {
4414 4414
             $row = array();
4415
-            $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode(str_replace('_',' ',$linked_show))).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
4416
-                str_replace('_',' ',$linked_show).'</a>';
4415
+            $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode(str_replace('_', ' ', $linked_show))).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
4416
+                str_replace('_', ' ', $linked_show).'</a>';
4417 4417
             $rows[] = $row;
4418 4418
         }
4419 4419
 
4420
-        $table = new SortableTableFromArrayConfig($rows,0,10,'LinkedPages_table','','','DESC');
4420
+        $table = new SortableTableFromArrayConfig($rows, 0, 10, 'LinkedPages_table', '', '', 'DESC');
4421 4421
         $table->set_additional_parameters(
4422 4422
             array(
4423 4423
                 'cidReq' => Security::remove_XSS($_GET['cidReq']),
@@ -4426,7 +4426,7 @@  discard block
 block discarded – undo
4426 4426
                 'group_id' => intval($_GET['group_id']),
4427 4427
             )
4428 4428
         );
4429
-        $table->set_header(0,get_lang('Title'), true);
4429
+        $table->set_header(0, get_lang('Title'), true);
4430 4430
         $table->display();
4431 4431
     }
4432 4432
 
@@ -4451,8 +4451,8 @@  discard block
 block discarded – undo
4451 4451
                 WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
4452 4452
                 GROUP BY reflink
4453 4453
                 ORDER BY reflink ASC';
4454
-        $allpages=Database::query($sql);
4455
-        while ($row=Database::fetch_array($allpages)) {
4454
+        $allpages = Database::query($sql);
4455
+        while ($row = Database::fetch_array($allpages)) {
4456 4456
             $pages[] = $row['reflink'];
4457 4457
         }
4458 4458
 
@@ -4467,14 +4467,14 @@  discard block
 block discarded – undo
4467 4467
                 )';
4468 4468
         $allpages = Database::query($sql);
4469 4469
         $array_refs_linked = array();
4470
-        while ($row=Database::fetch_array($allpages)) {
4471
-            $row['linksto']= str_replace($row["reflink"], " ", trim($row["linksto"])); //remove self reference
4470
+        while ($row = Database::fetch_array($allpages)) {
4471
+            $row['linksto'] = str_replace($row["reflink"], " ", trim($row["linksto"])); //remove self reference
4472 4472
             $refs = explode(" ", trim($row["linksto"]));
4473
-            foreach ($refs as $ref_linked){
4474
-                if ($ref_linked==str_replace(' ','_',get_lang('DefaultTitle'))) {
4475
-                    $ref_linked='index';
4473
+            foreach ($refs as $ref_linked) {
4474
+                if ($ref_linked == str_replace(' ', '_', get_lang('DefaultTitle'))) {
4475
+                    $ref_linked = 'index';
4476 4476
                 }
4477
-                $array_refs_linked[]= $ref_linked;
4477
+                $array_refs_linked[] = $ref_linked;
4478 4478
             }
4479 4479
         }
4480 4480
 
@@ -4496,20 +4496,20 @@  discard block
 block discarded – undo
4496 4496
 		                '.$groupfilter.$condition_session.' AND
4497 4497
 		                reflink="'.Database::escape_string($orphaned_show).'"
4498 4498
                     GROUP BY reflink';
4499
-            $allpages=Database::query($sql);
4500
-            while ($row=Database::fetch_array($allpages)) {
4501
-                $orphaned_title=$row['title'];
4502
-                $orphaned_visibility=$row['visibility'];
4503
-                if ($row['assignment']==1) {
4504
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png','','',ICON_SIZE_SMALL);
4505
-                } elseif ($row['assignment']==2) {
4506
-                    $ShowAssignment=Display::return_icon('wiki_work.png','','',ICON_SIZE_SMALL);
4507
-                } elseif ($row['assignment']==0) {
4508
-                    $ShowAssignment= Display::return_icon('px_transparent.gif');
4499
+            $allpages = Database::query($sql);
4500
+            while ($row = Database::fetch_array($allpages)) {
4501
+                $orphaned_title = $row['title'];
4502
+                $orphaned_visibility = $row['visibility'];
4503
+                if ($row['assignment'] == 1) {
4504
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', '', '', ICON_SIZE_SMALL);
4505
+                } elseif ($row['assignment'] == 2) {
4506
+                    $ShowAssignment = Display::return_icon('wiki_work.png', '', '', ICON_SIZE_SMALL);
4507
+                } elseif ($row['assignment'] == 0) {
4508
+                    $ShowAssignment = Display::return_icon('px_transparent.gif');
4509 4509
                 }
4510 4510
             }
4511 4511
 
4512
-            if (!api_is_allowed_to_edit(false,true) || !api_is_platform_admin() && $orphaned_visibility==0){
4512
+            if (!api_is_allowed_to_edit(false, true) || !api_is_platform_admin() && $orphaned_visibility == 0) {
4513 4513
                 continue;
4514 4514
             }
4515 4515
 
@@ -4521,7 +4521,7 @@  discard block
 block discarded – undo
4521 4521
             $rows[] = $row;
4522 4522
         }
4523 4523
 
4524
-        $table = new SortableTableFromArrayConfig($rows,1, 10, 'OrphanedPages_table','','','DESC');
4524
+        $table = new SortableTableFromArrayConfig($rows, 1, 10, 'OrphanedPages_table', '', '', 'DESC');
4525 4525
         $table->set_additional_parameters(
4526 4526
             array(
4527 4527
                 'cidReq' => Security::remove_XSS($_GET['cidReq']),
@@ -4530,8 +4530,8 @@  discard block
 block discarded – undo
4530 4530
                 'group_id' => intval($_GET['group_id']),
4531 4531
             )
4532 4532
         );
4533
-        $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
4534
-        $table->set_header(1,get_lang('Title'), true);
4533
+        $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;'));
4534
+        $table->set_header(1, get_lang('Title'), true);
4535 4535
         $table->display();
4536 4536
     }
4537 4537
 
@@ -4553,11 +4553,11 @@  discard block
 block discarded – undo
4553 4553
                 WHERE  c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
4554 4554
                 GROUP BY reflink
4555 4555
                 ORDER BY reflink ASC';
4556
-        $allpages=Database::query($sql);
4556
+        $allpages = Database::query($sql);
4557 4557
 
4558
-        while ($row=Database::fetch_array($allpages)) {
4559
-            if ($row['reflink']=='index'){
4560
-                $row['reflink']=str_replace(' ','_',get_lang('DefaultTitle'));
4558
+        while ($row = Database::fetch_array($allpages)) {
4559
+            if ($row['reflink'] == 'index') {
4560
+                $row['reflink'] = str_replace(' ', '_', get_lang('DefaultTitle'));
4561 4561
             }
4562 4562
             $pages[] = $row['reflink'];
4563 4563
         }
@@ -4571,31 +4571,31 @@  discard block
 block discarded – undo
4571 4571
 
4572 4572
         $allpages = Database::query($sql);
4573 4573
 
4574
-        while ($row=Database::fetch_array($allpages)) {
4574
+        while ($row = Database::fetch_array($allpages)) {
4575 4575
             $refs = explode(" ", trim($row["linksto"]));
4576 4576
             // Find linksto into reflink. If not found ->page is wanted
4577 4577
             foreach ($refs as $v) {
4578 4578
 
4579 4579
                 if (!in_array($v, $pages)) {
4580
-                    if (trim($v)!="") {
4581
-                        $wanted[]=$v;
4580
+                    if (trim($v) != "") {
4581
+                        $wanted[] = $v;
4582 4582
                     }
4583 4583
                 }
4584 4584
             }
4585 4585
         }
4586 4586
 
4587
-        $wanted = array_unique($wanted);//make a unique list
4587
+        $wanted = array_unique($wanted); //make a unique list
4588 4588
 
4589 4589
         //show table
4590 4590
         $rows = array();
4591 4591
         foreach ($wanted as $wanted_show) {
4592 4592
             $row = array();
4593 4593
             $wanted_show = Security::remove_XSS($wanted_show);
4594
-            $row[] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq=&action=addnew&title='.str_replace('_',' ',$wanted_show).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'" class="new_wiki_link">'.str_replace('_',' ',$wanted_show).'</a>';//meter un remove xss en lugar de htmlentities
4594
+            $row[] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq=&action=addnew&title='.str_replace('_', ' ', $wanted_show).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'" class="new_wiki_link">'.str_replace('_', ' ', $wanted_show).'</a>'; //meter un remove xss en lugar de htmlentities
4595 4595
             $rows[] = $row;
4596 4596
         }
4597 4597
 
4598
-        $table = new SortableTableFromArrayConfig($rows,0,10,'WantedPages_table','','','DESC');
4598
+        $table = new SortableTableFromArrayConfig($rows, 0, 10, 'WantedPages_table', '', '', 'DESC');
4599 4599
         $table->set_additional_parameters(
4600 4600
             array(
4601 4601
                 'cidReq' => Security::remove_XSS($_GET['cidReq']),
@@ -4604,7 +4604,7 @@  discard block
 block discarded – undo
4604 4604
                 'group_id' => intval($_GET['group_id']),
4605 4605
             )
4606 4606
         );
4607
-        $table->set_header(0,get_lang('Title'), true);
4607
+        $table->set_header(0, get_lang('Title'), true);
4608 4608
         $table->display();
4609 4609
     }
4610 4610
 
@@ -4621,7 +4621,7 @@  discard block
 block discarded – undo
4621 4621
 
4622 4622
         echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
4623 4623
 
4624
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
4624
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
4625 4625
             $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
4626 4626
                     WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
4627 4627
                     GROUP BY reflink';
@@ -4642,11 +4642,11 @@  discard block
 block discarded – undo
4642 4642
             while ($obj = Database::fetch_object($allpages)) {
4643 4643
                 //get type assignment icon
4644 4644
                 $ShowAssignment = '';
4645
-                if ($obj->assignment==1) {
4646
-                    $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
4647
-                } elseif ($obj->assignment==2) {
4648
-                    $ShowAssignment=$ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
4649
-                } elseif ($obj->assignment==0) {
4645
+                if ($obj->assignment == 1) {
4646
+                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
4647
+                } elseif ($obj->assignment == 2) {
4648
+                    $ShowAssignment = $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
4649
+                } elseif ($obj->assignment == 0) {
4650 4650
                     $ShowAssignment = Display::return_icon('px_transparent.gif');
4651 4651
                 }
4652 4652
 
@@ -4675,7 +4675,7 @@  discard block
 block discarded – undo
4675 4675
                     'group_id' => intval($_GET['group_id']),
4676 4676
                 )
4677 4677
             );
4678
-            $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
4678
+            $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;'));
4679 4679
             $table->set_header(1, get_lang('Title'), true);
4680 4680
             $table->set_header(2, get_lang('Visits'), true);
4681 4681
             $table->display();
@@ -4700,8 +4700,8 @@  discard block
 block discarded – undo
4700 4700
 
4701 4701
         if (api_is_allowed_to_session_edit(false, true) && api_is_allowed_to_edit()) {
4702 4702
             // menu add page
4703
-            $actionsLeft .= '<a href="index.php?cidReq=' . $_course['id'] . '&action=addnew&session_id=' . $session_id . '&group_id=' . $groupId . '"' . self::is_active_navigation_tab('addnew').'>'
4704
-            . Display::return_icon('add.png', get_lang('AddNew'), '', ICON_SIZE_MEDIUM) . '</a>';
4703
+            $actionsLeft .= '<a href="index.php?cidReq='.$_course['id'].'&action=addnew&session_id='.$session_id.'&group_id='.$groupId.'"'.self::is_active_navigation_tab('addnew').'>'
4704
+            . Display::return_icon('add.png', get_lang('AddNew'), '', ICON_SIZE_MEDIUM).'</a>';
4705 4705
         }
4706 4706
 
4707 4707
         $lock_unlock_addnew = null;
@@ -4709,12 +4709,12 @@  discard block
 block discarded – undo
4709 4709
 
4710 4710
         if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
4711 4711
             // page action: enable or disable the adding of new pages
4712
-            if (self::check_addnewpagelock()==0) {
4712
+            if (self::check_addnewpagelock() == 0) {
4713 4713
                 $protect_addnewpage = Display::return_icon('off.png', get_lang('AddOptionProtected'));
4714
-                $lock_unlock_addnew ='unlockaddnew';
4714
+                $lock_unlock_addnew = 'unlockaddnew';
4715 4715
             } else {
4716 4716
                 $protect_addnewpage = Display::return_icon('on.png', get_lang('AddOptionUnprotected'));
4717
-                $lock_unlock_addnew ='lockaddnew';
4717
+                $lock_unlock_addnew = 'lockaddnew';
4718 4718
             }
4719 4719
         }
4720 4720
 
@@ -4734,7 +4734,7 @@  discard block
 block discarded – undo
4734 4734
             get_lang('RecentChanges').'</a>';
4735 4735
 
4736 4736
 
4737
-        echo Display::toolbarAction('toolbar-wiki', array( 0 => $actionsLeft));
4737
+        echo Display::toolbarAction('toolbar-wiki', array(0 => $actionsLeft));
4738 4738
     }
4739 4739
 
4740 4740
     /**
@@ -4752,7 +4752,7 @@  discard block
 block discarded – undo
4752 4752
             return;
4753 4753
         }
4754 4754
 
4755
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
4755
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
4756 4756
             self::setMessage('<div id="wikititle">'.get_lang('DeletePageHistory').'</div>');
4757 4757
 
4758 4758
             if ($page == "index") {
@@ -4794,7 +4794,7 @@  discard block
 block discarded – undo
4794 4794
         $userId = api_get_user_id();
4795 4795
 
4796 4796
         if (api_get_session_id() != 0 &&
4797
-            api_is_allowed_to_session_edit(false,true) == false
4797
+            api_is_allowed_to_session_edit(false, true) == false
4798 4798
         ) {
4799 4799
             api_not_allowed();
4800 4800
         }
@@ -4817,12 +4817,12 @@  discard block
 block discarded – undo
4817 4817
                 Display::display_error_message(get_lang('MustSelectPage'), false, true)
4818 4818
             );
4819 4819
             return;
4820
-        } elseif ($row['content']=='' && $row['title']=='' && $page=='index') {
4820
+        } elseif ($row['content'] == '' && $row['title'] == '' && $page == 'index') {
4821 4821
 
4822 4822
             // Table structure for better export to pdf
4823 4823
             $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
4824 4824
             $default_table_for_content_End = '</td></tr></table>';
4825
-            $content = $default_table_for_content_Start.sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)).$default_table_for_content_End;
4825
+            $content = $default_table_for_content_Start.sprintf(get_lang('DefaultContent'), api_get_path(WEB_IMG_PATH)).$default_table_for_content_End;
4826 4826
             $title = get_lang('DefaultTitle');
4827 4827
             $page_id = 0;
4828 4828
         } else {
@@ -4847,7 +4847,7 @@  discard block
 block discarded – undo
4847 4847
             // Check if is a wiki group
4848 4848
             if (!empty($groupId)) {
4849 4849
                 //Only teacher, platform admin and group members can edit a wiki group
4850
-                if (api_is_allowed_to_edit(false,true) ||
4850
+                if (api_is_allowed_to_edit(false, true) ||
4851 4851
                     api_is_platform_admin() ||
4852 4852
                     GroupManager :: is_user_in_group($userId, $groupId)
4853 4853
                 ) {
@@ -4860,7 +4860,7 @@  discard block
 block discarded – undo
4860 4860
                     );
4861 4861
                 }
4862 4862
             } else {
4863
-                $PassEdit=true;
4863
+                $PassEdit = true;
4864 4864
             }
4865 4865
 
4866 4866
             $icon_assignment = null;
@@ -4870,10 +4870,10 @@  discard block
 block discarded – undo
4870 4870
                     Display::return_message(get_lang('EditAssignmentWarning'))
4871 4871
                 );
4872 4872
 
4873
-                $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
4873
+                $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
4874 4874
             } elseif ($row['assignment'] == 2) {
4875
-                $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
4876
-                if (($userId == $row['user_id'])==false) {
4875
+                $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'), '', ICON_SIZE_SMALL);
4876
+                if (($userId == $row['user_id']) == false) {
4877 4877
                     if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
4878 4878
                         $PassEdit = true;
4879 4879
                     } else {
@@ -4893,7 +4893,7 @@  discard block
 block discarded – undo
4893 4893
             if ($PassEdit) {
4894 4894
                 //show editor if edit is allowed
4895 4895
                 if ($row['editlock'] == 1 &&
4896
-                    (api_is_allowed_to_edit(false, true) == false || api_is_platform_admin()==false)
4896
+                    (api_is_allowed_to_edit(false, true) == false || api_is_platform_admin() == false)
4897 4897
                 ) {
4898 4898
                     Display::addFlash(
4899 4899
                         Display::return_message(
@@ -4904,8 +4904,8 @@  discard block
 block discarded – undo
4904 4904
                     // Check tasks
4905 4905
 
4906 4906
                     if (!empty($row['startdate_assig']) &&
4907
-                        $row['startdate_assig']!='0000-00-00 00:00:00' &&
4908
-                        time()<strtotime($row['startdate_assig'])
4907
+                        $row['startdate_assig'] != '0000-00-00 00:00:00' &&
4908
+                        time() < strtotime($row['startdate_assig'])
4909 4909
                     ) {
4910 4910
                         $message = get_lang('TheTaskDoesNotBeginUntil').': '.api_get_local_time($row['startdate_assig'], null, date_default_timezone_get());
4911 4911
 
@@ -4922,10 +4922,10 @@  discard block
 block discarded – undo
4922 4922
                     }
4923 4923
 
4924 4924
                     if (!empty($row['enddate_assig']) &&
4925
-                        $row['enddate_assig']!='0000-00-00 00:00:00' &&
4925
+                        $row['enddate_assig'] != '0000-00-00 00:00:00' &&
4926 4926
                         time() > strtotime($row['enddate_assig']) &&
4927
-                        $row['enddate_assig']!='0000-00-00 00:00:00' &&
4928
-                        $row['delayedsubmit']==0
4927
+                        $row['enddate_assig'] != '0000-00-00 00:00:00' &&
4928
+                        $row['delayedsubmit'] == 0
4929 4929
                     ) {
4930 4930
                         $message = get_lang('TheDeadlineHasBeenCompleted').': '.api_get_local_time($row['enddate_assig'], null, date_default_timezone_get());
4931 4931
                         Display::addFlash(
@@ -4934,20 +4934,20 @@  discard block
 block discarded – undo
4934 4934
                                 'warning'
4935 4935
                             )
4936 4936
                         );
4937
-                        if (!api_is_allowed_to_edit(false,true)) {
4937
+                        if (!api_is_allowed_to_edit(false, true)) {
4938 4938
                             $this->redirectHome();
4939 4939
                         }
4940 4940
                     }
4941 4941
 
4942
-                    if (!empty($row['max_version']) && $row['version']>=$row['max_version']) {
4943
-                        $message=get_lang('HasReachedMaxiNumVersions');
4942
+                    if (!empty($row['max_version']) && $row['version'] >= $row['max_version']) {
4943
+                        $message = get_lang('HasReachedMaxiNumVersions');
4944 4944
                         Display::addFlash(
4945 4945
                             Display::return_message(
4946 4946
                                 $message,
4947 4947
                                 'warning'
4948 4948
                             )
4949 4949
                         );
4950
-                        if (!api_is_allowed_to_edit(false,true)) {
4950
+                        if (!api_is_allowed_to_edit(false, true)) {
4951 4951
                             $this->redirectHome();
4952 4952
                         }
4953 4953
                     }
@@ -4960,50 +4960,50 @@  discard block
 block discarded – undo
4960 4960
                                 'warning'
4961 4961
                             )
4962 4962
                         );
4963
-                        if (!api_is_allowed_to_edit(false,true)) {
4963
+                        if (!api_is_allowed_to_edit(false, true)) {
4964 4964
                             $this->redirectHome();
4965 4965
                         }
4966 4966
                     }
4967 4967
 
4968 4968
                     if (!empty($row['task'])) {
4969 4969
                         //previous change 0 by text
4970
-                        if ($row['startdate_assig']=='0000-00-00 00:00:00') {
4971
-                            $message_task_startdate  =get_lang('No');
4970
+                        if ($row['startdate_assig'] == '0000-00-00 00:00:00') {
4971
+                            $message_task_startdate = get_lang('No');
4972 4972
                         } else {
4973 4973
                             $message_task_startdate = api_get_local_time($row['startdate_assig'], null, date_default_timezone_get());
4974 4974
                         }
4975 4975
 
4976
-                        if ($row['enddate_assig']=='0000-00-00 00:00:00') {
4976
+                        if ($row['enddate_assig'] == '0000-00-00 00:00:00') {
4977 4977
                             $message_task_enddate = get_lang('No');
4978 4978
                         } else {
4979 4979
                             $message_task_enddate = api_get_local_time($row['enddate_assig'], null, date_default_timezone_get());
4980 4980
                         }
4981 4981
 
4982
-                        if ($row['delayedsubmit']==0) {
4983
-                            $message_task_delayedsubmit=get_lang('No');
4982
+                        if ($row['delayedsubmit'] == 0) {
4983
+                            $message_task_delayedsubmit = get_lang('No');
4984 4984
                         } else {
4985
-                            $message_task_delayedsubmit=get_lang('Yes');
4985
+                            $message_task_delayedsubmit = get_lang('Yes');
4986 4986
                         }
4987 4987
 
4988
-                        if ($row['max_version']==0) {
4989
-                            $message_task_max_version=get_lang('No');
4988
+                        if ($row['max_version'] == 0) {
4989
+                            $message_task_max_version = get_lang('No');
4990 4990
                         } else {
4991
-                            $message_task_max_version=$row['max_version'];
4991
+                            $message_task_max_version = $row['max_version'];
4992 4992
                         }
4993 4993
 
4994
-                        if ($row['max_text']==0) {
4995
-                            $message_task_max_text=get_lang('No');
4994
+                        if ($row['max_text'] == 0) {
4995
+                            $message_task_max_text = get_lang('No');
4996 4996
                         } else {
4997
-                            $message_task_max_text=$row['max_text'];
4997
+                            $message_task_max_text = $row['max_text'];
4998 4998
                         }
4999 4999
 
5000 5000
                         // Comp message
5001
-                        $message_task='<b>'.get_lang('DescriptionOfTheTask').'</b><p>'.$row['task'].'</p><hr>';
5002
-                        $message_task.='<p>'.get_lang('StartDate').': '.$message_task_startdate.'</p>';
5003
-                        $message_task.='<p>'.get_lang('EndDate').': '.$message_task_enddate;
5004
-                        $message_task.=' ('.get_lang('AllowLaterSends').') '.$message_task_delayedsubmit.'</p>';
5005
-                        $message_task.='<p>'.get_lang('OtherSettings').': '.get_lang('NMaxVersion').': '.$message_task_max_version;
5006
-                        $message_task.=' '.get_lang('NMaxWords').': '.$message_task_max_text;
5001
+                        $message_task = '<b>'.get_lang('DescriptionOfTheTask').'</b><p>'.$row['task'].'</p><hr>';
5002
+                        $message_task .= '<p>'.get_lang('StartDate').': '.$message_task_startdate.'</p>';
5003
+                        $message_task .= '<p>'.get_lang('EndDate').': '.$message_task_enddate;
5004
+                        $message_task .= ' ('.get_lang('AllowLaterSends').') '.$message_task_delayedsubmit.'</p>';
5005
+                        $message_task .= '<p>'.get_lang('OtherSettings').': '.get_lang('NMaxVersion').': '.$message_task_max_version;
5006
+                        $message_task .= ' '.get_lang('NMaxWords').': '.$message_task_max_text;
5007 5007
                         // Display message
5008 5008
                         Display::addFlash(
5009 5009
                             Display::return_message(
@@ -5014,11 +5014,11 @@  discard block
 block discarded – undo
5014 5014
 
5015 5015
                     $feedback_message = '';
5016 5016
                     if ($row['progress'] == $row['fprogress1'] && !empty($row['fprogress1'])) {
5017
-                        $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback1']).'</p>';
5017
+                        $feedback_message = '<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback1']).'</p>';
5018 5018
                     } elseif ($row['progress'] == $row['fprogress2'] && !empty($row['fprogress2'])) {
5019
-                        $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback2']).'</p>';
5019
+                        $feedback_message = '<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback2']).'</p>';
5020 5020
                     } elseif ($row['progress'] == $row['fprogress3'] && !empty($row['fprogress3'])) {
5021
-                        $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback3']).'</p>';
5021
+                        $feedback_message = '<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback3']).'</p>';
5022 5022
                     }
5023 5023
 
5024 5024
                     if (!empty($feedback_message)) {
@@ -5043,14 +5043,14 @@  discard block
 block discarded – undo
5043 5043
                                 WHERE c_id = '.$course_id.' AND id="'.$row['id'].'"';
5044 5044
                         Database::query($sql);
5045 5045
                     } elseif ($row['is_editing'] != $userId) {
5046
-                        $timestamp_edit=strtotime($row['time_edit']);
5046
+                        $timestamp_edit = strtotime($row['time_edit']);
5047 5047
                         $time_editing = time() - $timestamp_edit;
5048 5048
                         $max_edit_time = 1200; // 20 minutes
5049 5049
                         $rest_time = $max_edit_time - $time_editing;
5050 5050
 
5051 5051
                         $userinfo = api_get_user_info($row['is_editing']);
5052 5052
                         $is_being_edited = get_lang('ThisPageisBeginEditedBy').' '.UserManager::getUserProfileLink($userinfo).'
5053
-                            '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
5053
+                            '.get_lang('ThisPageisBeginEditedTryLater').' '.date("i", $rest_time).' '.get_lang('MinMinutes').'';
5054 5054
 
5055 5055
                         Display::addFlash(
5056 5056
                             Display::return_message(
@@ -5064,7 +5064,7 @@  discard block
 block discarded – undo
5064 5064
                     // Form.
5065 5065
                     $url = api_get_self().'?action=edit&title='.urlencode($page).'&session_id='.api_get_session_id().'&group_id='.api_get_group_id().'&'.api_get_cidreq();
5066 5066
                     $form = new FormValidator('wiki', 'post', $url);
5067
-                    $form->addElement('header', $icon_assignment.str_repeat('&nbsp;',3).api_htmlentities($title));
5067
+                    $form->addElement('header', $icon_assignment.str_repeat('&nbsp;', 3).api_htmlentities($title));
5068 5068
                     self::setForm($form, $row);
5069 5069
                     $form->addElement('hidden', 'title');
5070 5070
                     $form->addElement('button', 'SaveWikiChange', get_lang('Save'));
@@ -5087,7 +5087,7 @@  discard block
 block discarded – undo
5087 5087
                             );
5088 5088
                         } elseif (!self::double_post($_POST['wpost_id'])) {
5089 5089
                             //double post
5090
-                        } elseif ($_POST['version']!='' && $_SESSION['_version'] !=0 && $_POST['version'] != $_SESSION['_version']) {
5090
+                        } elseif ($_POST['version'] != '' && $_SESSION['_version'] != 0 && $_POST['version'] != $_SESSION['_version']) {
5091 5091
                             //prevent concurrent users and double version
5092 5092
                             Display::addFlash(
5093 5093
                                 Display::return_message(
@@ -5149,7 +5149,7 @@  discard block
 block discarded – undo
5149 5149
         $KeyAssignment = null;
5150 5150
         $KeyTitle = null;
5151 5151
         $KeyUserId = null;
5152
-        while ($row=Database::fetch_array($result)) {
5152
+        while ($row = Database::fetch_array($result)) {
5153 5153
             $KeyVisibility = $row['visibility'];
5154 5154
             $KeyAssignment = $row['assignment'];
5155 5155
             $KeyTitle = $row['title'];
@@ -5158,7 +5158,7 @@  discard block
 block discarded – undo
5158 5158
         $icon_assignment = null;
5159 5159
         if ($KeyAssignment == 1) {
5160 5160
             $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
5161
-        } elseif($KeyAssignment == 2) {
5161
+        } elseif ($KeyAssignment == 2) {
5162 5162
             $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'), '', ICON_SIZE_SMALL);
5163 5163
         }
5164 5164
 
@@ -5166,10 +5166,10 @@  discard block
 block discarded – undo
5166 5166
 
5167 5167
         //if the page is hidden and is a job only sees its author and professor
5168 5168
         if ($KeyVisibility == 1 ||
5169
-            api_is_allowed_to_edit(false,true) ||
5169
+            api_is_allowed_to_edit(false, true) ||
5170 5170
             api_is_platform_admin() ||
5171 5171
             (
5172
-                $KeyAssignment==2 && $KeyVisibility==0 &&
5172
+                $KeyAssignment == 2 && $KeyVisibility == 0 &&
5173 5173
                 ($userId == $KeyUserId)
5174 5174
             )
5175 5175
         ) {
@@ -5199,7 +5199,7 @@  discard block
 block discarded – undo
5199 5199
                     get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
5200 5200
                 echo '<br/><br/>';
5201 5201
 
5202
-                $counter=0;
5202
+                $counter = 0;
5203 5203
                 $total_versions = Database::num_rows($result);
5204 5204
 
5205 5205
                 while ($row = Database::fetch_array($result)) {
@@ -5207,10 +5207,10 @@  discard block
 block discarded – undo
5207 5207
                     $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
5208 5208
 
5209 5209
                     echo '<li style="margin-bottom: 5px;">';
5210
-                    ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle='';
5211
-                    ($counter==0) ? $newchecked=' checked': $newchecked='';
5212
-                    ($counter==$total_versions-1) ? $newstyle='style="visibility: hidden;"':$newstyle='';
5213
-                    ($counter==1) ? $oldchecked=' checked':$oldchecked='';
5210
+                    ($counter == 0) ? $oldstyle = 'style="visibility: hidden;"' : $oldstyle = '';
5211
+                    ($counter == 0) ? $newchecked = ' checked' : $newchecked = '';
5212
+                    ($counter == $total_versions - 1) ? $newstyle = 'style="visibility: hidden;"' : $newstyle = '';
5213
+                    ($counter == 1) ? $oldchecked = ' checked' : $oldchecked = '';
5214 5214
                     echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
5215 5215
                     echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
5216 5216
                     echo '<a href="'.api_get_self().'?action=showpage&amp;title='.api_htmlentities(urlencode($page)).'&amp;view='.$row['id'].'">';
@@ -5228,7 +5228,7 @@  discard block
 block discarded – undo
5228 5228
                     $comment = $row['comment'];
5229 5229
                     if (!empty($comment)) {
5230 5230
                         echo get_lang('Comments').': '.api_htmlentities(api_substr($row['comment'], 0, 100));
5231
-                        if (api_strlen($row['comment'])>100) {
5231
+                        if (api_strlen($row['comment']) > 100) {
5232 5232
                             echo '... ';
5233 5233
                         }
5234 5234
                     } else {
@@ -5253,8 +5253,8 @@  discard block
 block discarded – undo
5253 5253
 
5254 5254
                 $sql_new = "SELECT * FROM $tbl_wiki
5255 5255
                             WHERE c_id = $course_id AND id='".Database::escape_string($_POST['new'])."'";
5256
-                $result_new=Database::query($sql_new);
5257
-                $version_new=Database::fetch_array($result_new);
5256
+                $result_new = Database::query($sql_new);
5257
+                $version_new = Database::fetch_array($result_new);
5258 5258
                 $oldTime = isset($version_old['dtime']) ? $version_old['dtime'] : null;
5259 5259
                 $oldContent = isset($version_old['content']) ? $version_old['content'] : null;
5260 5260
 
@@ -5281,9 +5281,9 @@  discard block
 block discarded – undo
5281 5281
 
5282 5282
 
5283 5283
                 if (isset($_POST['HistoryDifferences'])) {
5284
-                    echo '<table>'.diff($oldContent, $version_new['content'], true, 'format_table_line' ).'</table>'; // format_line mode is better for words
5284
+                    echo '<table>'.diff($oldContent, $version_new['content'], true, 'format_table_line').'</table>'; // format_line mode is better for words
5285 5285
                     echo '<br />';
5286
-                    echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
5286
+                    echo '<strong>'.get_lang('Legend').'</strong><div class="diff">'."\n";
5287 5287
                     echo '<table><tr>';
5288 5288
                     echo  '<td>';
5289 5289
                     echo '</td><td>';
@@ -5302,7 +5302,7 @@  discard block
 block discarded – undo
5302 5302
                     $renderer = new Text_Diff_Renderer_inline();
5303 5303
                     echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render($diff); // Code inline
5304 5304
                     echo '<br />';
5305
-                    echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
5305
+                    echo '<strong>'.get_lang('Legend').'</strong><div class="diff">'."\n";
5306 5306
                     echo '<table><tr>';
5307 5307
                     echo  '<td>';
5308 5308
                     echo '</td><td>';
@@ -5350,7 +5350,7 @@  discard block
 block discarded – undo
5350 5350
         echo '<td style="vertical-align:top">';
5351 5351
         echo '<ul>';
5352 5352
         // Submenu Statistics
5353
-        if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
5353
+        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
5354 5354
             echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=statistics&session_id='.$session_id.'&group_id='.$groupId.'">'.get_lang('Statistics').'</a></li>';
5355 5355
         }
5356 5356
         echo '      </ul>';
@@ -5423,7 +5423,7 @@  discard block
 block discarded – undo
5423 5423
                 break;
5424 5424
             case 'deletewiki':
5425 5425
                 $title = '<div class="actions">'.get_lang('DeleteWiki').'</div>';
5426
-                if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
5426
+                if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
5427 5427
                     $message = get_lang('ConfirmDeleteWiki');
5428 5428
                     $message .= '<p>
5429 5429
                         <a href="index.php?'.api_get_cidreq().'">'.get_lang('No').'</a>
@@ -5454,14 +5454,14 @@  discard block
 block discarded – undo
5454 5454
                 self::getLinks($page);
5455 5455
                 break;
5456 5456
             case 'addnew':
5457
-                if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
5457
+                if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
5458 5458
                     api_not_allowed();
5459 5459
                 }
5460 5460
                 echo '<div class="actions">'.get_lang('AddNew').'</div>';
5461 5461
                 echo '<br/>';
5462 5462
                 //first, check if page index was created. chektitle=false
5463 5463
                 if (self::checktitle('index')) {
5464
-                    if (api_is_allowed_to_edit(false,true) ||
5464
+                    if (api_is_allowed_to_edit(false, true) ||
5465 5465
                         api_is_platform_admin() ||
5466 5466
                         GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())
5467 5467
                     ) {
@@ -5469,10 +5469,10 @@  discard block
 block discarded – undo
5469 5469
                     } else {
5470 5470
                         self::setMessage(Display::display_normal_message(get_lang('WikiStandBy'), false, true));
5471 5471
                     }
5472
-                } elseif (self::check_addnewpagelock()==0 && (api_is_allowed_to_edit(false, true)==false || api_is_platform_admin()==false)) {
5472
+                } elseif (self::check_addnewpagelock() == 0 && (api_is_allowed_to_edit(false, true) == false || api_is_platform_admin() == false)) {
5473 5473
                     self::setMessage(Display::display_error_message(get_lang('AddPagesLocked'), false, true));
5474 5474
                 } else {
5475
-                    if (api_is_allowed_to_edit(false,true) ||
5475
+                    if (api_is_allowed_to_edit(false, true) ||
5476 5476
                         api_is_platform_admin() ||
5477 5477
                         GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) ||
5478 5478
                         $_GET['group_id'] == 0
Please login to merge, or discard this patch.
main/inc/lib/attendance.lib.php 1 patch
Indentation   +1704 added lines, -1704 removed lines patch added patch discarded remove patch
@@ -11,50 +11,50 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Attendance
13 13
 {
14
-	private $session_id;
15
-	private $course_id;
16
-	private $date_time;
17
-	private $name;
18
-	private $description;
19
-	private $attendance_qualify_title;
20
-	private $attendance_weight;
21
-	private $course_int_id;
22
-	public $category_id;
23
-
24
-	// constants
25
-	const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
-	const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
-	const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
-
29
-	/**
30
-	 * Constructor
31
-	 */
32
-	public function __construct()
33
-	{
34
-		//$this->course_int_id = api_get_course_int_id();
35
-	}
36
-
37
-	/**
38
-	 * Get the total number of attendance inside current course and current session
39
-	 * @see SortableTable#get_total_number_of_items()
40
-	 */
41
-	public static function get_number_of_attendances($active = -1)
42
-	{
43
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
-		$session_id = api_get_session_id();
45
-		$condition_session = api_get_session_condition($session_id);
46
-		$course_id = api_get_course_int_id();
47
-		$sql = "SELECT COUNT(att.id) AS total_number_of_items
14
+    private $session_id;
15
+    private $course_id;
16
+    private $date_time;
17
+    private $name;
18
+    private $description;
19
+    private $attendance_qualify_title;
20
+    private $attendance_weight;
21
+    private $course_int_id;
22
+    public $category_id;
23
+
24
+    // constants
25
+    const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
+    const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
+    const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
+
29
+    /**
30
+     * Constructor
31
+     */
32
+    public function __construct()
33
+    {
34
+        //$this->course_int_id = api_get_course_int_id();
35
+    }
36
+
37
+    /**
38
+     * Get the total number of attendance inside current course and current session
39
+     * @see SortableTable#get_total_number_of_items()
40
+     */
41
+    public static function get_number_of_attendances($active = -1)
42
+    {
43
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
+        $session_id = api_get_session_id();
45
+        $condition_session = api_get_session_condition($session_id);
46
+        $course_id = api_get_course_int_id();
47
+        $sql = "SELECT COUNT(att.id) AS total_number_of_items
48 48
 				FROM $tbl_attendance att
49 49
 		        WHERE c_id = $course_id $condition_session ";
50
-		if ($active == 1 || $active == 0) {
51
-			$sql .= "AND att.active = $active";
52
-		}
53
-		$res = Database::query($sql);
54
-		$obj = Database::fetch_object($res);
50
+        if ($active == 1 || $active == 0) {
51
+            $sql .= "AND att.active = $active";
52
+        }
53
+        $res = Database::query($sql);
54
+        $obj = Database::fetch_object($res);
55 55
 
56
-		return $obj->total_number_of_items;
57
-	}
56
+        return $obj->total_number_of_items;
57
+    }
58 58
 
59 59
     /**
60 60
      * Get attendance list only the id, name and attendance_qualify_max fields
@@ -90,36 +90,36 @@  discard block
 block discarded – undo
90 90
         return $data;
91 91
     }
92 92
 
93
-	/**
94
-	 * Get the attendaces to display on the current page (fill the sortable-table)
95
-	 * @param   int     offset of first user to recover
96
-	 * @param   int     Number of users to get
97
-	 * @param   int     Column to sort on
98
-	 * @param   string  Order (ASC,DESC)
99
-	 * @see SortableTable#get_table_data($from)
100
-	 */
101
-	public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
-	{
103
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
-		$course_id = api_get_course_int_id();
105
-		$session_id = api_get_session_id();
106
-		$condition_session = api_get_session_condition($session_id);
107
-		$column = intval($column);
108
-		$from = intval($from);
109
-		$number_of_items = intval($number_of_items);
110
-
111
-		if (!in_array($direction, array('ASC','DESC'))) {
112
-			$direction = 'ASC';
113
-		}
114
-
115
-		$active_plus = '';
116
-		if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
-			!api_is_allowed_to_edit(null, true)
118
-		) {
119
-			$active_plus = ' AND att.active = 1';
120
-		}
121
-
122
-		$sql = "SELECT
93
+    /**
94
+     * Get the attendaces to display on the current page (fill the sortable-table)
95
+     * @param   int     offset of first user to recover
96
+     * @param   int     Number of users to get
97
+     * @param   int     Column to sort on
98
+     * @param   string  Order (ASC,DESC)
99
+     * @see SortableTable#get_table_data($from)
100
+     */
101
+    public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
+    {
103
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
+        $course_id = api_get_course_int_id();
105
+        $session_id = api_get_session_id();
106
+        $condition_session = api_get_session_condition($session_id);
107
+        $column = intval($column);
108
+        $from = intval($from);
109
+        $number_of_items = intval($number_of_items);
110
+
111
+        if (!in_array($direction, array('ASC','DESC'))) {
112
+            $direction = 'ASC';
113
+        }
114
+
115
+        $active_plus = '';
116
+        if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
+            !api_is_allowed_to_edit(null, true)
118
+        ) {
119
+            $active_plus = ' AND att.active = 1';
120
+        }
121
+
122
+        $sql = "SELECT
123 123
                     att.id AS col0,
124 124
                     att.name AS col1,
125 125
                     att.description AS col2,
@@ -134,318 +134,318 @@  discard block
 block discarded – undo
134 134
 				ORDER BY col$column $direction
135 135
 				LIMIT $from,$number_of_items ";
136 136
 
137
-		$res = Database::query($sql);
138
-		$attendances = array ();
139
-		$user_info = api_get_user_info();
140
-		$allowDelete = api_get_setting('allow_delete_attendance');
141
-
142
-		while ($attendance = Database::fetch_row($res)) {
143
-
144
-			$student_param = '';
145
-			if (api_is_drh() && $_GET['student_id']) {
146
-				$student_param = '&student_id='.intval($_GET['student_id']);
147
-			}
148
-
149
-			$session_star = '';
150
-
151
-			if (api_get_session_id() == $attendance[6]) {
152
-				$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
153
-			}
154
-			if ($attendance[5] == 1) {
155
-
156
-				$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
157
-					api_get_user_id(),
158
-					api_get_course_info()
159
-				);
160
-
161
-				if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
162
-					// Link to edit
163
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
-				} else {
165
-					// Link to view
166
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
-				}
168
-
169
-			} else {
170
-				$attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
171
-			}
172
-
173
-			if ($attendance[5] == 1) {
174
-				$attendance[3] = '<center>'.$attendance[3].'</center>';
175
-			} else {
176
-				$attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
177
-			}
178
-
179
-			$attendance[3] = '<center>'.$attendance[3].'</center>';
180
-			if (api_is_allowed_to_edit(null, true)) {
181
-				$actions  = '';
182
-				$actions .= '<center>';
183
-
184
-				if (api_is_platform_admin()) {
185
-					$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
186
-						Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
187
-					// Visible
188
-					if ($attendance[5] == 1) {
189
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
190
-							Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
191
-					} else {
192
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
193
-							Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
194
-						$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
195
-					}
196
-					if ($allowDelete === 'true') {
197
-						$actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' .
198
-							Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
199
-					}
200
-				} else {
201
-					$is_locked_attendance = self::is_locked_attendance($attendance[0]);
202
-					if ($is_locked_attendance) {
203
-						$actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
204
-						$actions .= Display::return_icon('visible.png', get_lang('Hide'));
205
-					} else {
206
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
207
-							Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
208
-
209
-						if ($attendance[5] == 1) {
210
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
211
-								Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
212
-						} else {
213
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
214
-								Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
215
-							$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
216
-						}
217
-						if ($allowDelete === 'true') {
218
-							$actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
219
-								Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
220
-						}
221
-					}
222
-				}
223
-
224
-				// display lock/unlock icon
225
-				$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
226
-
227
-				if ($is_done_all_calendar) {
228
-					$locked   = $attendance[4];
229
-					if ($locked == 0) {
230
-						if (api_is_platform_admin()) {
231
-							$message_alert = get_lang('AreYouSureToLockTheAttendance');
232
-						} else {
233
-							$message_alert = get_lang('UnlockMessageInformation');
234
-						}
235
-						$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
137
+        $res = Database::query($sql);
138
+        $attendances = array ();
139
+        $user_info = api_get_user_info();
140
+        $allowDelete = api_get_setting('allow_delete_attendance');
141
+
142
+        while ($attendance = Database::fetch_row($res)) {
143
+
144
+            $student_param = '';
145
+            if (api_is_drh() && $_GET['student_id']) {
146
+                $student_param = '&student_id='.intval($_GET['student_id']);
147
+            }
148
+
149
+            $session_star = '';
150
+
151
+            if (api_get_session_id() == $attendance[6]) {
152
+                $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
153
+            }
154
+            if ($attendance[5] == 1) {
155
+
156
+                $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
157
+                    api_get_user_id(),
158
+                    api_get_course_info()
159
+                );
160
+
161
+                if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
162
+                    // Link to edit
163
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
+                } else {
165
+                    // Link to view
166
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
+                }
168
+
169
+            } else {
170
+                $attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
171
+            }
172
+
173
+            if ($attendance[5] == 1) {
174
+                $attendance[3] = '<center>'.$attendance[3].'</center>';
175
+            } else {
176
+                $attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
177
+            }
178
+
179
+            $attendance[3] = '<center>'.$attendance[3].'</center>';
180
+            if (api_is_allowed_to_edit(null, true)) {
181
+                $actions  = '';
182
+                $actions .= '<center>';
183
+
184
+                if (api_is_platform_admin()) {
185
+                    $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
186
+                        Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
187
+                    // Visible
188
+                    if ($attendance[5] == 1) {
189
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
190
+                            Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
191
+                    } else {
192
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
193
+                            Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
194
+                        $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
195
+                    }
196
+                    if ($allowDelete === 'true') {
197
+                        $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' .
198
+                            Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
199
+                    }
200
+                } else {
201
+                    $is_locked_attendance = self::is_locked_attendance($attendance[0]);
202
+                    if ($is_locked_attendance) {
203
+                        $actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
204
+                        $actions .= Display::return_icon('visible.png', get_lang('Hide'));
205
+                    } else {
206
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
207
+                            Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
208
+
209
+                        if ($attendance[5] == 1) {
210
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
211
+                                Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
212
+                        } else {
213
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
214
+                                Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
215
+                            $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
216
+                        }
217
+                        if ($allowDelete === 'true') {
218
+                            $actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
219
+                                Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
220
+                        }
221
+                    }
222
+                }
223
+
224
+                // display lock/unlock icon
225
+                $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
226
+
227
+                if ($is_done_all_calendar) {
228
+                    $locked   = $attendance[4];
229
+                    if ($locked == 0) {
230
+                        if (api_is_platform_admin()) {
231
+                            $message_alert = get_lang('AreYouSureToLockTheAttendance');
232
+                        } else {
233
+                            $message_alert = get_lang('UnlockMessageInformation');
234
+                        }
235
+                        $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
236 236
                             Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
237
-					} else {
238
-						if (api_is_platform_admin()) {
239
-							$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
240
-									Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
241
-						} else {
242
-							$actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
243
-						}
244
-					}
245
-				}
246
-				$actions .= '</center>';
247
-
248
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
249
-			} else {
250
-				$attendance[0] = '&nbsp;';
251
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
252
-			}
253
-		}
254
-		return $attendances;
255
-	}
256
-
257
-	/**
258
-	 * Get the attendances by id to display on the current page
259
-	 * @param  int     $attendance_id
260
-	 * @return array   attendance data
261
-	 */
262
-	public function get_attendance_by_id($attendance_id)
263
-	{
264
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
265
-		$attendance_id = intval($attendance_id);
266
-		$course_id = api_get_course_int_id();
267
-		$attendance_data = array();
268
-		$sql = "SELECT * FROM $tbl_attendance
237
+                    } else {
238
+                        if (api_is_platform_admin()) {
239
+                            $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
240
+                                    Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
241
+                        } else {
242
+                            $actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
243
+                        }
244
+                    }
245
+                }
246
+                $actions .= '</center>';
247
+
248
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
249
+            } else {
250
+                $attendance[0] = '&nbsp;';
251
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
252
+            }
253
+        }
254
+        return $attendances;
255
+    }
256
+
257
+    /**
258
+     * Get the attendances by id to display on the current page
259
+     * @param  int     $attendance_id
260
+     * @return array   attendance data
261
+     */
262
+    public function get_attendance_by_id($attendance_id)
263
+    {
264
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
265
+        $attendance_id = intval($attendance_id);
266
+        $course_id = api_get_course_int_id();
267
+        $attendance_data = array();
268
+        $sql = "SELECT * FROM $tbl_attendance
269 269
 				WHERE c_id = $course_id AND id = '$attendance_id'";
270
-		$res = Database::query($sql);
271
-		if (Database::num_rows($res) > 0) {
272
-			while ($row = Database::fetch_array($res)) {
273
-				$attendance_data = $row;
274
-			}
275
-		}
276
-		return $attendance_data;
277
-	}
278
-
279
-	/**
280
-	 * Add attendances sheet inside table. This is the *list of* dates, not
281
-	 * a specific date in itself.
282
-	 * @param  bool   true for adding link in gradebook or false otherwise (optional)
283
-	 * @return int    last attendance id
284
-	 */
285
-	public function attendance_add($link_to_gradebook = false)
286
-	{
287
-		$_course = api_get_course_info();
288
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
289
-		$table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
290
-		$session_id = api_get_session_id();
291
-		$user_id = api_get_user_id();
292
-		$course_code = $_course['code'];
293
-		$course_id = $_course['real_id'];
294
-		$title_gradebook= $this->attendance_qualify_title;
295
-		$value_calification = 0;
296
-		$weight_calification = floatval($this->attendance_weight);
297
-
298
-		$params = [
299
-			'c_id' => $course_id,
300
-			'name' => $this->name,
301
-			'description' => $this->description,
302
-			'attendance_qualify_title' => $title_gradebook,
303
-			'attendance_weight' => $weight_calification,
304
-			'session_id' => $session_id,
305
-			'active' => 1,
306
-			'attendance_qualify_max' => 0,
307
-			'locked' => 0
308
-		];
309
-		$last_id = Database::insert($tbl_attendance, $params);
310
-
311
-		if (!empty($last_id)) {
312
-
313
-			$sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
314
-			Database::query($sql);
315
-
316
-			api_item_property_update(
317
-				$_course,
318
-				TOOL_ATTENDANCE,
319
-				$last_id,
320
-				"AttendanceAdded",
321
-				$user_id
322
-			);
323
-
324
-		}
325
-		// add link to gradebook
326
-		if ($link_to_gradebook && !empty($this->category_id)) {
327
-			$description = '';
270
+        $res = Database::query($sql);
271
+        if (Database::num_rows($res) > 0) {
272
+            while ($row = Database::fetch_array($res)) {
273
+                $attendance_data = $row;
274
+            }
275
+        }
276
+        return $attendance_data;
277
+    }
278
+
279
+    /**
280
+     * Add attendances sheet inside table. This is the *list of* dates, not
281
+     * a specific date in itself.
282
+     * @param  bool   true for adding link in gradebook or false otherwise (optional)
283
+     * @return int    last attendance id
284
+     */
285
+    public function attendance_add($link_to_gradebook = false)
286
+    {
287
+        $_course = api_get_course_info();
288
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
289
+        $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
290
+        $session_id = api_get_session_id();
291
+        $user_id = api_get_user_id();
292
+        $course_code = $_course['code'];
293
+        $course_id = $_course['real_id'];
294
+        $title_gradebook= $this->attendance_qualify_title;
295
+        $value_calification = 0;
296
+        $weight_calification = floatval($this->attendance_weight);
297
+
298
+        $params = [
299
+            'c_id' => $course_id,
300
+            'name' => $this->name,
301
+            'description' => $this->description,
302
+            'attendance_qualify_title' => $title_gradebook,
303
+            'attendance_weight' => $weight_calification,
304
+            'session_id' => $session_id,
305
+            'active' => 1,
306
+            'attendance_qualify_max' => 0,
307
+            'locked' => 0
308
+        ];
309
+        $last_id = Database::insert($tbl_attendance, $params);
310
+
311
+        if (!empty($last_id)) {
312
+
313
+            $sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
314
+            Database::query($sql);
315
+
316
+            api_item_property_update(
317
+                $_course,
318
+                TOOL_ATTENDANCE,
319
+                $last_id,
320
+                "AttendanceAdded",
321
+                $user_id
322
+            );
323
+
324
+        }
325
+        // add link to gradebook
326
+        if ($link_to_gradebook && !empty($this->category_id)) {
327
+            $description = '';
328 328
             $link_info = GradebookUtils::is_resource_in_course_gradebook(
329 329
                 $course_code,
330 330
                 7,
331 331
                 $last_id,
332 332
                 $session_id
333 333
             );
334
-			$link_id = $link_info['id'];
335
-			if (!$link_info) {
336
-				GradebookUtils::add_resource_to_course_gradebook(
337
-					$this->category_id,
338
-					$course_code,
339
-					7,
340
-					$last_id,
341
-					$title_gradebook,
342
-					$weight_calification,
343
-					$value_calification,
344
-					$description,
345
-					1,
346
-					$session_id
347
-				);
348
-			} else {
349
-				Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
350
-			}
351
-		}
352
-		return $last_id;
353
-	}
354
-
355
-	/**
356
-	 * edit attendances inside table
357
-	 * @param 	int	   attendance id
358
-	 * @param  	bool   true for adding link in gradebook or false otherwise (optional)
359
-	 * @return 	int    last id
360
-	 */
361
-	public function attendance_edit($attendance_id, $link_to_gradebook = false)
362
-	{
363
-		$_course = api_get_course_info();
364
-		$tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
365
-		$table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
366
-
367
-		$session_id = api_get_session_id();
368
-		$user_id = api_get_user_id();
369
-		$attendance_id = intval($attendance_id);
370
-		$course_code = $_course['code'];
371
-		$course_id = $_course['real_id'];
372
-		$title_gradebook = $this->attendance_qualify_title;
373
-		$value_calification = 0;
374
-		$weight_calification = floatval($this->attendance_weight);
375
-
376
-		if (!empty($attendance_id)) {
377
-
378
-			$params = [
379
-				'name' => $this->name,
380
-				'description' => $this->description,
381
-				'attendance_qualify_title' => $title_gradebook,
382
-				'attendance_weight' => $weight_calification
383
-			];
384
-			Database::update(
385
-				$tbl_attendance,
386
-				$params,
387
-				['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
388
-			);
389
-
390
-			api_item_property_update(
391
-				$_course,
392
-				TOOL_ATTENDANCE,
393
-				$attendance_id,
394
-				"AttendanceUpdated",
395
-				$user_id
396
-			);
397
-
398
-			// add link to gradebook
399
-			if ($link_to_gradebook && !empty($this->category_id)) {
400
-				$description = '';
401
-				$link_info = GradebookUtils::is_resource_in_course_gradebook(
402
-					$course_code,
403
-					7,
404
-					$attendance_id,
405
-					$session_id
406
-				);
407
-				if (!$link_info) {
408
-					GradebookUtils::add_resource_to_course_gradebook(
409
-						$this->category_id,
410
-						$course_code,
411
-						7,
412
-						$attendance_id,
413
-						$title_gradebook,
414
-						$weight_calification,
415
-						$value_calification,
416
-						$description,
417
-						1,
418
-						$session_id
419
-					);
420
-				} else {
421
-					Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].'');
422
-				}
423
-			}
424
-			return $attendance_id;
425
-		}
426
-		return null;
427
-	}
428
-
429
-	/**
430
-	 * Restore attendance
431
-	 * @param 	int|array	   one or many attendances id
432
-	 * @return 	int    		   affected rows
433
-	 */
434
-	public function attendance_restore($attendance_id)
435
-	{
436
-		$_course = api_get_course_info();
437
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
438
-		$user_id = api_get_user_id();
439
-		$course_id = $_course['real_id'];
440
-		if (is_array($attendance_id)) {
441
-			foreach ($attendance_id as $id) {
442
-				$id	= intval($id);
443
-				$sql = "UPDATE $tbl_attendance SET active = 1
334
+            $link_id = $link_info['id'];
335
+            if (!$link_info) {
336
+                GradebookUtils::add_resource_to_course_gradebook(
337
+                    $this->category_id,
338
+                    $course_code,
339
+                    7,
340
+                    $last_id,
341
+                    $title_gradebook,
342
+                    $weight_calification,
343
+                    $value_calification,
344
+                    $description,
345
+                    1,
346
+                    $session_id
347
+                );
348
+            } else {
349
+                Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
350
+            }
351
+        }
352
+        return $last_id;
353
+    }
354
+
355
+    /**
356
+     * edit attendances inside table
357
+     * @param 	int	   attendance id
358
+     * @param  	bool   true for adding link in gradebook or false otherwise (optional)
359
+     * @return 	int    last id
360
+     */
361
+    public function attendance_edit($attendance_id, $link_to_gradebook = false)
362
+    {
363
+        $_course = api_get_course_info();
364
+        $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
365
+        $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
366
+
367
+        $session_id = api_get_session_id();
368
+        $user_id = api_get_user_id();
369
+        $attendance_id = intval($attendance_id);
370
+        $course_code = $_course['code'];
371
+        $course_id = $_course['real_id'];
372
+        $title_gradebook = $this->attendance_qualify_title;
373
+        $value_calification = 0;
374
+        $weight_calification = floatval($this->attendance_weight);
375
+
376
+        if (!empty($attendance_id)) {
377
+
378
+            $params = [
379
+                'name' => $this->name,
380
+                'description' => $this->description,
381
+                'attendance_qualify_title' => $title_gradebook,
382
+                'attendance_weight' => $weight_calification
383
+            ];
384
+            Database::update(
385
+                $tbl_attendance,
386
+                $params,
387
+                ['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
388
+            );
389
+
390
+            api_item_property_update(
391
+                $_course,
392
+                TOOL_ATTENDANCE,
393
+                $attendance_id,
394
+                "AttendanceUpdated",
395
+                $user_id
396
+            );
397
+
398
+            // add link to gradebook
399
+            if ($link_to_gradebook && !empty($this->category_id)) {
400
+                $description = '';
401
+                $link_info = GradebookUtils::is_resource_in_course_gradebook(
402
+                    $course_code,
403
+                    7,
404
+                    $attendance_id,
405
+                    $session_id
406
+                );
407
+                if (!$link_info) {
408
+                    GradebookUtils::add_resource_to_course_gradebook(
409
+                        $this->category_id,
410
+                        $course_code,
411
+                        7,
412
+                        $attendance_id,
413
+                        $title_gradebook,
414
+                        $weight_calification,
415
+                        $value_calification,
416
+                        $description,
417
+                        1,
418
+                        $session_id
419
+                    );
420
+                } else {
421
+                    Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].'');
422
+                }
423
+            }
424
+            return $attendance_id;
425
+        }
426
+        return null;
427
+    }
428
+
429
+    /**
430
+     * Restore attendance
431
+     * @param 	int|array	   one or many attendances id
432
+     * @return 	int    		   affected rows
433
+     */
434
+    public function attendance_restore($attendance_id)
435
+    {
436
+        $_course = api_get_course_info();
437
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
438
+        $user_id = api_get_user_id();
439
+        $course_id = $_course['real_id'];
440
+        if (is_array($attendance_id)) {
441
+            foreach ($attendance_id as $id) {
442
+                $id	= intval($id);
443
+                $sql = "UPDATE $tbl_attendance SET active = 1
444 444
 						WHERE c_id = $course_id AND id = '$id'";
445
-				$result = Database::query($sql);
446
-				$affected_rows = Database::affected_rows($result);
447
-				if (!empty($affected_rows)) {
448
-					// update row item property table
445
+                $result = Database::query($sql);
446
+                $affected_rows = Database::affected_rows($result);
447
+                if (!empty($affected_rows)) {
448
+                    // update row item property table
449 449
                     api_item_property_update(
450 450
                         $_course,
451 451
                         TOOL_ATTENDANCE,
@@ -453,16 +453,16 @@  discard block
 block discarded – undo
453 453
                         "restore",
454 454
                         $user_id
455 455
                     );
456
-				}
457
-			}
458
-		} else  {
459
-			$attendance_id	= intval($attendance_id);
460
-			$sql = "UPDATE $tbl_attendance SET active = 1
456
+                }
457
+            }
458
+        } else  {
459
+            $attendance_id	= intval($attendance_id);
460
+            $sql = "UPDATE $tbl_attendance SET active = 1
461 461
 					WHERE c_id = $course_id AND id = '$attendance_id'";
462
-			$result = Database::query($sql);
463
-			$affected_rows = Database::affected_rows($result);
464
-			if (!empty($affected_rows)) {
465
-				// update row item property table
462
+            $result = Database::query($sql);
463
+            $affected_rows = Database::affected_rows($result);
464
+            if (!empty($affected_rows)) {
465
+                // update row item property table
466 466
                 api_item_property_update(
467 467
                     $_course,
468 468
                     TOOL_ATTENDANCE,
@@ -470,33 +470,33 @@  discard block
 block discarded – undo
470 470
                     "restore",
471 471
                     $user_id
472 472
                 );
473
-			}
474
-		}
475
-
476
-		return $affected_rows;
477
-	}
478
-
479
-	/**
480
-	 * Delete attendances
481
-	 * @param 	int|array	$attendance_id   one or many attendances id
482
-	 * @return 	int    		   affected rows
483
-	 */
484
-	public function attendance_delete($attendance_id)
485
-	{
486
-		$_course = api_get_course_info();
487
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
473
+            }
474
+        }
475
+
476
+        return $affected_rows;
477
+    }
478
+
479
+    /**
480
+     * Delete attendances
481
+     * @param 	int|array	$attendance_id   one or many attendances id
482
+     * @return 	int    		   affected rows
483
+     */
484
+    public function attendance_delete($attendance_id)
485
+    {
486
+        $_course = api_get_course_info();
487
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
488 488
         $user_id = api_get_user_id();
489 489
         $course_id = $_course['real_id'];
490 490
 
491
-		if (is_array($attendance_id)) {
492
-			foreach ($attendance_id as $id) {
493
-				$id	= intval($id);
494
-				$sql = "UPDATE $tbl_attendance SET active = 2
491
+        if (is_array($attendance_id)) {
492
+            foreach ($attendance_id as $id) {
493
+                $id	= intval($id);
494
+                $sql = "UPDATE $tbl_attendance SET active = 2
495 495
 						WHERE c_id = $course_id AND id = '$id'";
496
-				$result = Database::query($sql);
497
-				$affected_rows = Database::affected_rows($result);
498
-				if (!empty($affected_rows)) {
499
-					// update row item property table
496
+                $result = Database::query($sql);
497
+                $affected_rows = Database::affected_rows($result);
498
+                if (!empty($affected_rows)) {
499
+                    // update row item property table
500 500
                     api_item_property_update(
501 501
                         $_course,
502 502
                         TOOL_ATTENDANCE,
@@ -504,142 +504,142 @@  discard block
 block discarded – undo
504 504
                         "delete",
505 505
                         $user_id
506 506
                     );
507
-				}
508
-			}
509
-		} else  {
510
-			$attendance_id= intval($attendance_id);
511
-			$sql = "UPDATE $tbl_attendance SET active = 2
507
+                }
508
+            }
509
+        } else  {
510
+            $attendance_id= intval($attendance_id);
511
+            $sql = "UPDATE $tbl_attendance SET active = 2
512 512
 					WHERE c_id = $course_id AND id = '$attendance_id'";
513 513
 
514
-			$result = Database::query($sql);
515
-			$affected_rows = Database::affected_rows($result);
516
-			if (!empty($affected_rows)) {
517
-				// update row item property table
518
-				api_item_property_update(
519
-					$_course,
520
-					TOOL_ATTENDANCE,
521
-					$attendance_id,
522
-					"delete",
523
-					$user_id
524
-				);
525
-			}
526
-		}
527
-
528
-		return $affected_rows;
529
-	}
530
-
531
-	/**
532
-	 * Changes visibility
533
-	 * @param int|array	$attendanceId   one or many attendances id
534
-	 * @param int status
514
+            $result = Database::query($sql);
515
+            $affected_rows = Database::affected_rows($result);
516
+            if (!empty($affected_rows)) {
517
+                // update row item property table
518
+                api_item_property_update(
519
+                    $_course,
520
+                    TOOL_ATTENDANCE,
521
+                    $attendance_id,
522
+                    "delete",
523
+                    $user_id
524
+                );
525
+            }
526
+        }
527
+
528
+        return $affected_rows;
529
+    }
530
+
531
+    /**
532
+     * Changes visibility
533
+     * @param int|array	$attendanceId   one or many attendances id
534
+     * @param int status
535 535
      *
536
-	 * @return 	int affected rows
537
-	 */
538
-	public function changeVisibility($attendanceId, $status = 1)
539
-	{
540
-		$_course = api_get_course_info();
541
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
542
-		$user_id = api_get_user_id();
543
-		$course_id = $_course['real_id'];
544
-		$status = intval($status);
545
-
546
-		$action = 'visible';
547
-		if ($status == 0) {
548
-			$action = 'invisible';
549
-		}
550
-
551
-		if (is_array($attendanceId)) {
552
-			foreach ($attendanceId as $id) {
553
-				$id	= intval($id);
554
-				$sql = "UPDATE $tbl_attendance SET active = $status
536
+     * @return 	int affected rows
537
+     */
538
+    public function changeVisibility($attendanceId, $status = 1)
539
+    {
540
+        $_course = api_get_course_info();
541
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
542
+        $user_id = api_get_user_id();
543
+        $course_id = $_course['real_id'];
544
+        $status = intval($status);
545
+
546
+        $action = 'visible';
547
+        if ($status == 0) {
548
+            $action = 'invisible';
549
+        }
550
+
551
+        if (is_array($attendanceId)) {
552
+            foreach ($attendanceId as $id) {
553
+                $id	= intval($id);
554
+                $sql = "UPDATE $tbl_attendance SET active = $status
555 555
 						WHERE c_id = $course_id AND id = '$id'";
556
-				$result = Database::query($sql);
557
-				$affected_rows = Database::affected_rows($result);
558
-				if (!empty($affected_rows)) {
559
-					// update row item property table
560
-					api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
561
-				}
562
-			}
563
-		} else  {
564
-			$attendanceId	= intval($attendanceId);
565
-			$sql = "UPDATE $tbl_attendance SET active = $status
556
+                $result = Database::query($sql);
557
+                $affected_rows = Database::affected_rows($result);
558
+                if (!empty($affected_rows)) {
559
+                    // update row item property table
560
+                    api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
561
+                }
562
+            }
563
+        } else  {
564
+            $attendanceId	= intval($attendanceId);
565
+            $sql = "UPDATE $tbl_attendance SET active = $status
566 566
 					WHERE c_id = $course_id AND id = '$attendanceId'";
567
-			$result = Database::query($sql);
568
-			$affected_rows = Database::affected_rows($result);
569
-			if (!empty($affected_rows)) {
570
-				// update row item property table
571
-				api_item_property_update(
572
-					$_course,
573
-					TOOL_ATTENDANCE,
574
-					$attendanceId,
575
-					$action,
576
-					$user_id
577
-				);
578
-			}
579
-		}
580
-
581
-		return $affected_rows;
582
-	}
583
-
584
-	/**
585
-	 * Lock or unlock an attendance
586
-	 * @param   int     attendance id
587
-	 * @param   bool    True to lock or false otherwise
588
-	 */
589
-	public function lock_attendance($attendance_id, $lock = true)
590
-	{
591
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
592
-		$course_id = api_get_course_int_id();
593
-		$attendance_id = intval($attendance_id);
594
-		$locked = ($lock)?1:0;
595
-		$upd = "UPDATE $tbl_attendance SET locked = $locked
567
+            $result = Database::query($sql);
568
+            $affected_rows = Database::affected_rows($result);
569
+            if (!empty($affected_rows)) {
570
+                // update row item property table
571
+                api_item_property_update(
572
+                    $_course,
573
+                    TOOL_ATTENDANCE,
574
+                    $attendanceId,
575
+                    $action,
576
+                    $user_id
577
+                );
578
+            }
579
+        }
580
+
581
+        return $affected_rows;
582
+    }
583
+
584
+    /**
585
+     * Lock or unlock an attendance
586
+     * @param   int     attendance id
587
+     * @param   bool    True to lock or false otherwise
588
+     */
589
+    public function lock_attendance($attendance_id, $lock = true)
590
+    {
591
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
592
+        $course_id = api_get_course_int_id();
593
+        $attendance_id = intval($attendance_id);
594
+        $locked = ($lock)?1:0;
595
+        $upd = "UPDATE $tbl_attendance SET locked = $locked
596 596
 				WHERE c_id = $course_id AND id = $attendance_id";
597
-		$result = Database::query($upd);
598
-		$affected_rows = Database::affected_rows($result);
599
-		if ($affected_rows && $lock) {
600
-			// Save attendance sheet log
601
-			$lastedit_date = api_get_utc_datetime();
602
-			$lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
603
-			$lastedit_user_id = api_get_user_id();
604
-			$this->save_attendance_sheet_log(
605
-				$attendance_id,
606
-				$lastedit_date,
607
-				$lastedit_type,
608
-				$lastedit_user_id
609
-			);
610
-		}
611
-		return $affected_rows;
612
-	}
613
-
614
-	/**
615
-	 * Get registered users inside current course
616
-	 * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
617
-	 * @param int $groupId
618
-	 * @return 	array  users data
619
-	 */
620
-	public function get_users_rel_course($attendance_id = 0, $groupId = null)
621
-	{
622
-		$current_session_id = api_get_session_id();
623
-		$current_course_id  = api_get_course_id();
624
-		$currentCourseIntId = api_get_course_int_id();
625
-
626
-		$studentInGroup = array();
627
-
628
-		if (!empty($current_session_id)) {
629
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
630
-				$current_course_id,
631
-				$current_session_id,
632
-				'',
633
-				'lastname'
634
-			);
635
-		} else {
636
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
637
-				$current_course_id,
638
-				0,
639
-				'',
640
-				'lastname'
641
-			);
642
-		}
597
+        $result = Database::query($upd);
598
+        $affected_rows = Database::affected_rows($result);
599
+        if ($affected_rows && $lock) {
600
+            // Save attendance sheet log
601
+            $lastedit_date = api_get_utc_datetime();
602
+            $lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
603
+            $lastedit_user_id = api_get_user_id();
604
+            $this->save_attendance_sheet_log(
605
+                $attendance_id,
606
+                $lastedit_date,
607
+                $lastedit_type,
608
+                $lastedit_user_id
609
+            );
610
+        }
611
+        return $affected_rows;
612
+    }
613
+
614
+    /**
615
+     * Get registered users inside current course
616
+     * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
617
+     * @param int $groupId
618
+     * @return 	array  users data
619
+     */
620
+    public function get_users_rel_course($attendance_id = 0, $groupId = null)
621
+    {
622
+        $current_session_id = api_get_session_id();
623
+        $current_course_id  = api_get_course_id();
624
+        $currentCourseIntId = api_get_course_int_id();
625
+
626
+        $studentInGroup = array();
627
+
628
+        if (!empty($current_session_id)) {
629
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
630
+                $current_course_id,
631
+                $current_session_id,
632
+                '',
633
+                'lastname'
634
+            );
635
+        } else {
636
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
637
+                $current_course_id,
638
+                0,
639
+                '',
640
+                'lastname'
641
+            );
642
+        }
643 643
 
644 644
         if (!empty($groupId)) {
645 645
             $students = GroupManager::getStudents($groupId);
@@ -650,192 +650,192 @@  discard block
 block discarded – undo
650 650
             }
651 651
         }
652 652
 
653
-		// get registered users inside current course
654
-		$a_users = array();
655
-		foreach ($a_course_users as $key => $user_data) {
656
-			$value = array();
657
-			$uid = $user_data['user_id'];
658
-			$userInfo = api_get_user_info($uid);
659
-
660
-			$status = $user_data['status'];
661
-
662
-			if (!empty($groupId)) {
663
-				if (!isset($studentInGroup[$uid])) {
664
-					continue;
665
-				}
666
-			}
667
-
668
-			$user_status_in_session = null;
669
-			$user_status_in_course  = null;
670
-
671
-			if (api_get_session_id()) {
672
-				$user_status_in_session = SessionManager::get_user_status_in_course_session(
673
-					$uid,
674
-					$currentCourseIntId,
675
-					$current_session_id
676
-				);
677
-			} else {
678
-				$user_status_in_course = CourseManager::get_user_in_course_status(
679
-					$uid,
680
-					$current_course_id
681
-				);
682
-			}
683
-
684
-			// Not taking into account DRH or COURSEMANAGER
685
-			if ($uid <= 1 ||
686
-				$status == DRH ||
687
-				$user_status_in_course == COURSEMANAGER ||
688
-				$user_status_in_session == 2
689
-			) {
690
-				continue;
691
-			}
692
-
693
-			if (!empty($attendance_id)) {
694
-				$user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
695
-				$value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
696
-				$value['result_color_bar'] 	= $user_faults['color_bar'];
697
-			}
653
+        // get registered users inside current course
654
+        $a_users = array();
655
+        foreach ($a_course_users as $key => $user_data) {
656
+            $value = array();
657
+            $uid = $user_data['user_id'];
658
+            $userInfo = api_get_user_info($uid);
659
+
660
+            $status = $user_data['status'];
661
+
662
+            if (!empty($groupId)) {
663
+                if (!isset($studentInGroup[$uid])) {
664
+                    continue;
665
+                }
666
+            }
667
+
668
+            $user_status_in_session = null;
669
+            $user_status_in_course  = null;
670
+
671
+            if (api_get_session_id()) {
672
+                $user_status_in_session = SessionManager::get_user_status_in_course_session(
673
+                    $uid,
674
+                    $currentCourseIntId,
675
+                    $current_session_id
676
+                );
677
+            } else {
678
+                $user_status_in_course = CourseManager::get_user_in_course_status(
679
+                    $uid,
680
+                    $current_course_id
681
+                );
682
+            }
683
+
684
+            // Not taking into account DRH or COURSEMANAGER
685
+            if ($uid <= 1 ||
686
+                $status == DRH ||
687
+                $user_status_in_course == COURSEMANAGER ||
688
+                $user_status_in_session == 2
689
+            ) {
690
+                continue;
691
+            }
692
+
693
+            if (!empty($attendance_id)) {
694
+                $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
695
+                $value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
696
+                $value['result_color_bar'] 	= $user_faults['color_bar'];
697
+            }
698 698
 
699 699
             $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false);
700 700
 
701
-			$value['photo'] = $photo;
702
-			$value['firstname'] = $user_data['firstname'];
703
-			$value['lastname'] = $user_data['lastname'];
704
-			$value['username'] = $user_data['username'];
705
-			$value['user_id'] = $uid;
706
-
707
-			//Sending only 5 items in the array instead of 60
708
-			$a_users[$key] = $value;
709
-		}
710
-
711
-		return $a_users;
712
-	}
713
-
714
-	/**
715
-	 * add attendances sheet inside table
716
-	 * @param 	int	   $calendar_id attendance calendar id
717
-	 * @param  	array  $users_present present users during current class
718
-	 * @param	int	   $attendance_id
719
-	 * @return 	int    affected rows
720
-	 */
721
-	public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
722
-	{
723
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
724
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
725
-
726
-		$calendar_id = intval($calendar_id);
727
-		$attendance_id = intval($attendance_id);
728
-		$users = $this->get_users_rel_course();
729
-		$course_id = api_get_course_int_id();
730
-
731
-		$user_ids = array_keys($users);
732
-		$users_absent = array_diff($user_ids,$users_present);
733
-		$affected_rows = 0;
734
-
735
-		// get last edit type
736
-		$calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
737
-		$lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
738
-		if ($calendar_data['done_attendance']) {
739
-			$lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
740
-		}
741
-
742
-		// save users present in class
743
-		foreach ($users_present as $user_present) {
744
-			$uid = intval($user_present);
745
-			// check if user already was registered with the $calendar_id
746
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
701
+            $value['photo'] = $photo;
702
+            $value['firstname'] = $user_data['firstname'];
703
+            $value['lastname'] = $user_data['lastname'];
704
+            $value['username'] = $user_data['username'];
705
+            $value['user_id'] = $uid;
706
+
707
+            //Sending only 5 items in the array instead of 60
708
+            $a_users[$key] = $value;
709
+        }
710
+
711
+        return $a_users;
712
+    }
713
+
714
+    /**
715
+     * add attendances sheet inside table
716
+     * @param 	int	   $calendar_id attendance calendar id
717
+     * @param  	array  $users_present present users during current class
718
+     * @param	int	   $attendance_id
719
+     * @return 	int    affected rows
720
+     */
721
+    public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
722
+    {
723
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
724
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
725
+
726
+        $calendar_id = intval($calendar_id);
727
+        $attendance_id = intval($attendance_id);
728
+        $users = $this->get_users_rel_course();
729
+        $course_id = api_get_course_int_id();
730
+
731
+        $user_ids = array_keys($users);
732
+        $users_absent = array_diff($user_ids,$users_present);
733
+        $affected_rows = 0;
734
+
735
+        // get last edit type
736
+        $calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
737
+        $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
738
+        if ($calendar_data['done_attendance']) {
739
+            $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
740
+        }
741
+
742
+        // save users present in class
743
+        foreach ($users_present as $user_present) {
744
+            $uid = intval($user_present);
745
+            // check if user already was registered with the $calendar_id
746
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
747 747
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
748
-			$rs  = Database::query($sql);
749
-			if (Database::num_rows($rs) == 0) {
750
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
748
+            $rs  = Database::query($sql);
749
+            if (Database::num_rows($rs) == 0) {
750
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
751 751
 						c_id					= $course_id,
752 752
 						user_id 				= '$uid',
753 753
 						attendance_calendar_id 	= '$calendar_id',
754 754
 						presence 				= 1";
755
-				$result = Database::query($sql);
755
+                $result = Database::query($sql);
756 756
 
757
-				$affected_rows += Database::affected_rows($result);
758
-			} else {
759
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 1
757
+                $affected_rows += Database::affected_rows($result);
758
+            } else {
759
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 1
760 760
 						WHERE
761 761
 							c_id = $course_id AND
762 762
 							user_id ='$uid' AND
763 763
 							attendance_calendar_id = '$calendar_id'
764 764
 						";
765
-				$result = Database::query($sql);
766
-				$affected_rows += Database::affected_rows($result);
767
-			}
768
-		}
769
-
770
-		// save users absent in class
771
-		foreach ($users_absent as $user_absent) {
772
-			$uid = intval($user_absent);
773
-			// check if user already was registered with the $calendar_id
774
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
765
+                $result = Database::query($sql);
766
+                $affected_rows += Database::affected_rows($result);
767
+            }
768
+        }
769
+
770
+        // save users absent in class
771
+        foreach ($users_absent as $user_absent) {
772
+            $uid = intval($user_absent);
773
+            // check if user already was registered with the $calendar_id
774
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
775 775
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
776
-			$rs  = Database::query($sql);
777
-			if (Database::num_rows($rs) == 0) {
778
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
776
+            $rs  = Database::query($sql);
777
+            if (Database::num_rows($rs) == 0) {
778
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
779 779
 						c_id = $course_id,
780 780
 						user_id ='$uid',
781 781
 						attendance_calendar_id = '$calendar_id',
782 782
 						presence = 0";
783
-				$result = Database::query($sql);
783
+                $result = Database::query($sql);
784 784
 
785
-				Database::insert_id();
785
+                Database::insert_id();
786 786
 
787
-				$affected_rows += Database::affected_rows($result);
788
-			} else {
789
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 0
787
+                $affected_rows += Database::affected_rows($result);
788
+            } else {
789
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 0
790 790
 						WHERE
791 791
 							c_id = $course_id AND
792 792
 							user_id ='$uid' AND
793 793
 							attendance_calendar_id = '$calendar_id'";
794
-				$result = Database::query($sql);
795
-				$affected_rows += Database::affected_rows($result);
796
-			}
797
-		}
794
+                $result = Database::query($sql);
795
+                $affected_rows += Database::affected_rows($result);
796
+            }
797
+        }
798 798
 
799
-		// update done_attendance inside attendance calendar table
800
-		$sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
799
+        // update done_attendance inside attendance calendar table
800
+        $sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
801 801
 				WHERE  c_id = $course_id AND id = '$calendar_id'";
802
-		Database::query($sql);
803
-
804
-		// save users' results
805
-		$this->update_users_results($user_ids, $attendance_id);
806
-
807
-		if ($affected_rows) {
808
-			//save attendance sheet log
809
-			$lastedit_date = api_get_utc_datetime();
810
-			$lastedit_user_id = api_get_user_id();
811
-			$calendar_date_value = $calendar_data['date_time'];
812
-			$this->save_attendance_sheet_log(
813
-				$attendance_id,
814
-				$lastedit_date,
815
-				$lastedit_type,
816
-				$lastedit_user_id,
817
-				$calendar_date_value
818
-			);
819
-		}
820
-
821
-		return $affected_rows;
822
-	}
823
-
824
-	/**
825
-	 * update users' attendance results
826
-	 * @param 	array  $user_ids registered users inside current course
827
-	 * @param	int	   $attendance_id
828
-	 * @return 	void
829
-	 */
830
-	public function update_users_results($user_ids, $attendance_id)
831
-	{
832
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
833
-		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
834
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
835
-		$course_id = api_get_course_int_id();
836
-
837
-		$attendance_id = intval($attendance_id);
838
-		// fill results about presence of students
802
+        Database::query($sql);
803
+
804
+        // save users' results
805
+        $this->update_users_results($user_ids, $attendance_id);
806
+
807
+        if ($affected_rows) {
808
+            //save attendance sheet log
809
+            $lastedit_date = api_get_utc_datetime();
810
+            $lastedit_user_id = api_get_user_id();
811
+            $calendar_date_value = $calendar_data['date_time'];
812
+            $this->save_attendance_sheet_log(
813
+                $attendance_id,
814
+                $lastedit_date,
815
+                $lastedit_type,
816
+                $lastedit_user_id,
817
+                $calendar_date_value
818
+            );
819
+        }
820
+
821
+        return $affected_rows;
822
+    }
823
+
824
+    /**
825
+     * update users' attendance results
826
+     * @param 	array  $user_ids registered users inside current course
827
+     * @param	int	   $attendance_id
828
+     * @return 	void
829
+     */
830
+    public function update_users_results($user_ids, $attendance_id)
831
+    {
832
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
833
+        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
834
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
835
+        $course_id = api_get_course_int_id();
836
+
837
+        $attendance_id = intval($attendance_id);
838
+        // fill results about presence of students
839 839
         $attendance_calendar = $this->get_attendance_calendar(
840 840
             $attendance_id,
841 841
             'all',
@@ -843,82 +843,82 @@  discard block
 block discarded – undo
843 843
             null,
844 844
             true
845 845
         );
846
-		$calendar_ids = array();
847
-		// get all dates from calendar by current attendance
848
-		foreach ($attendance_calendar as $cal) {
849
-			$calendar_ids[] = $cal['id'];
850
-		}
851
-
852
-		// get count of presences by users inside current attendance and save like results
853
-		if (count($user_ids) > 0) {
854
-			foreach ($user_ids as $uid) {
855
-				$count_presences = 0;
856
-				if (count($calendar_ids) > 0) {
857
-					$sql = "SELECT count(presence) as count_presences
846
+        $calendar_ids = array();
847
+        // get all dates from calendar by current attendance
848
+        foreach ($attendance_calendar as $cal) {
849
+            $calendar_ids[] = $cal['id'];
850
+        }
851
+
852
+        // get count of presences by users inside current attendance and save like results
853
+        if (count($user_ids) > 0) {
854
+            foreach ($user_ids as $uid) {
855
+                $count_presences = 0;
856
+                if (count($calendar_ids) > 0) {
857
+                    $sql = "SELECT count(presence) as count_presences
858 858
 							FROM $tbl_attendance_sheet
859 859
 					        WHERE
860 860
 					        	c_id = $course_id AND
861 861
 					        	user_id = '$uid' AND
862 862
 					        	attendance_calendar_id IN (".implode(',', $calendar_ids).") AND
863 863
 					        	presence = 1";
864
-					$rs_count  = Database::query($sql);
865
-					$row_count = Database::fetch_array($rs_count);
866
-					$count_presences = $row_count['count_presences'];
867
-				}
864
+                    $rs_count  = Database::query($sql);
865
+                    $row_count = Database::fetch_array($rs_count);
866
+                    $count_presences = $row_count['count_presences'];
867
+                }
868 868
 
869
-				// save results
870
-				$sql = "SELECT id FROM $tbl_attendance_result
869
+                // save results
870
+                $sql = "SELECT id FROM $tbl_attendance_result
871 871
 						WHERE
872 872
 							c_id = $course_id AND
873 873
 							user_id = '$uid' AND
874 874
 							attendance_id = '$attendance_id' ";
875
-				$rs_check_result = Database::query($sql);
875
+                $rs_check_result = Database::query($sql);
876 876
 
877
-				if (Database::num_rows($rs_check_result) > 0) {
878
-					// update result
879
-					$sql = "UPDATE $tbl_attendance_result SET
877
+                if (Database::num_rows($rs_check_result) > 0) {
878
+                    // update result
879
+                    $sql = "UPDATE $tbl_attendance_result SET
880 880
 							score = '$count_presences'
881 881
 							WHERE
882 882
 								c_id = $course_id AND
883 883
 								user_id='$uid' AND
884 884
 								attendance_id='$attendance_id'";
885
-					Database::query($sql);
886
-				} else {
887
-					// insert new result
888
-					$sql = "INSERT INTO $tbl_attendance_result SET
885
+                    Database::query($sql);
886
+                } else {
887
+                    // insert new result
888
+                    $sql = "INSERT INTO $tbl_attendance_result SET
889 889
 							c_id = $course_id ,
890 890
 							user_id			= '$uid',
891 891
 							attendance_id 	= '$attendance_id',
892 892
 							score			= '$count_presences'";
893
-					Database::query($sql);
893
+                    Database::query($sql);
894 894
 
895
-					$insertId = Database::insert_id();
895
+                    $insertId = Database::insert_id();
896 896
                     if ($insertId) {
897 897
                         $sql = "UPDATE $tbl_attendance_result SET id = iid WHERE iid = $insertId";
898 898
                         Database::query($sql);
899 899
                     }
900
-				}
901
-			}
902
-		}
900
+                }
901
+            }
902
+        }
903 903
 
904
-		// update attendance qualify max
905
-		$count_done_calendar = self::get_done_attendance_calendar($attendance_id);
904
+        // update attendance qualify max
905
+        $count_done_calendar = self::get_done_attendance_calendar($attendance_id);
906 906
 
907
-		$sql = "UPDATE $tbl_attendance SET
907
+        $sql = "UPDATE $tbl_attendance SET
908 908
 				attendance_qualify_max = '$count_done_calendar'
909 909
 				WHERE c_id = $course_id AND id = '$attendance_id'";
910
-		Database::query($sql);
911
-	}
912
-
913
-	/**
914
-	 * update attendance_sheet_log table, is used as history of an attendance sheet
915
-	 * @param   int     Attendance id
916
-	 * @param   string  Last edit datetime
917
-	 * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
918
-	 * @param   int     Last edit user id
919
-	 * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
920
-	 * @return  int     Affected rows
921
-	 */
910
+        Database::query($sql);
911
+    }
912
+
913
+    /**
914
+     * update attendance_sheet_log table, is used as history of an attendance sheet
915
+     * @param   int     Attendance id
916
+     * @param   string  Last edit datetime
917
+     * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
918
+     * @param   int     Last edit user id
919
+     * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
920
+     * @return  int     Affected rows
921
+     */
922 922
     public function save_attendance_sheet_log(
923 923
         $attendance_id,
924 924
         $lastedit_date,
@@ -926,22 +926,22 @@  discard block
 block discarded – undo
926 926
         $lastedit_user_id,
927 927
         $calendar_date_value = null
928 928
     ) {
929
-		$course_id = api_get_course_int_id();
929
+        $course_id = api_get_course_int_id();
930 930
 
931
-		// define table
932
-		$tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
931
+        // define table
932
+        $tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
933 933
 
934
-		// protect data
935
-		$attendance_id = intval($attendance_id);
936
-		$lastedit_user_id = intval($lastedit_user_id);
934
+        // protect data
935
+        $attendance_id = intval($attendance_id);
936
+        $lastedit_user_id = intval($lastedit_user_id);
937 937
 
938
-		if (isset($calendar_date_value)) {
939
-			$calendar_date_value = $calendar_date_value;
940
-		} else {
941
-			$calendar_date_value = '';
942
-		}
938
+        if (isset($calendar_date_value)) {
939
+            $calendar_date_value = $calendar_date_value;
940
+        } else {
941
+            $calendar_date_value = '';
942
+        }
943 943
 
944
-		// save data
944
+        // save data
945 945
         $params = [
946 946
             'c_id' => $course_id,
947 947
             'attendance_id' => $attendance_id,
@@ -950,228 +950,228 @@  discard block
 block discarded – undo
950 950
             'lastedit_user_id' => $lastedit_user_id,
951 951
             'calendar_date_value' => $calendar_date_value,
952 952
         ];
953
-		$insertId = Database::insert($tbl_attendance_sheet_log, $params);
953
+        $insertId = Database::insert($tbl_attendance_sheet_log, $params);
954 954
         if ($insertId) {
955 955
             $sql = "UPDATE $tbl_attendance_sheet_log SET id = iid WHERE iid = $insertId";
956 956
             Database::query($sql);
957 957
         }
958 958
 
959
-		return $insertId;
960
-	}
961
-
962
-	/**
963
-	 * Get number of done attendances inside current sheet
964
-	 * @param	int	   attendance id
965
-	 * @return 	int	   number of done attendances
966
-	 */
967
-	public static function get_done_attendance_calendar($attendance_id)
968
-	{
969
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
970
-		$attendance_id = intval($attendance_id);
971
-		$course_id = api_get_course_int_id();
972
-		$sql = "SELECT count(done_attendance) as count
959
+        return $insertId;
960
+    }
961
+
962
+    /**
963
+     * Get number of done attendances inside current sheet
964
+     * @param	int	   attendance id
965
+     * @return 	int	   number of done attendances
966
+     */
967
+    public static function get_done_attendance_calendar($attendance_id)
968
+    {
969
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
970
+        $attendance_id = intval($attendance_id);
971
+        $course_id = api_get_course_int_id();
972
+        $sql = "SELECT count(done_attendance) as count
973 973
                 FROM $tbl_attendance_calendar
974 974
                 WHERE
975 975
                     c_id = $course_id AND
976 976
                     attendance_id = '$attendance_id' AND
977 977
                     done_attendance = 1
978 978
                 ";
979
-		$rs  = Database::query($sql);
980
-		$row = Database::fetch_array($rs);
981
-		$count = $row['count'];
982
-		return $count;
983
-	}
984
-
985
-	/**
986
-	 * Get results of faults (absents) by user
987
-	 * @param int $user_id
988
-	 * @param int $attendance_id
989
-	 * @param int $groupId
990
-	 * @return 	array  results containing number of faults, total done attendance,
991
-	 * percent of faults and color depend on result (red, orange)
992
-	 */
993
-	public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
994
-	{
995
-		// initializing database table and variables
996
-		$user_id 		= intval($user_id);
997
-		$attendance_id 	= intval($attendance_id);
998
-		$results = array();
999
-		$calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1000
-		// $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
979
+        $rs  = Database::query($sql);
980
+        $row = Database::fetch_array($rs);
981
+        $count = $row['count'];
982
+        return $count;
983
+    }
984
+
985
+    /**
986
+     * Get results of faults (absents) by user
987
+     * @param int $user_id
988
+     * @param int $attendance_id
989
+     * @param int $groupId
990
+     * @return 	array  results containing number of faults, total done attendance,
991
+     * percent of faults and color depend on result (red, orange)
992
+     */
993
+    public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
994
+    {
995
+        // initializing database table and variables
996
+        $user_id 		= intval($user_id);
997
+        $attendance_id 	= intval($attendance_id);
998
+        $results = array();
999
+        $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1000
+        // $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
1001 1001
         $total_done_attendance 	= self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
1002
-		$attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1002
+        $attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1003 1003
 
1004
-		//This is the main change of the BT#1381
1005
-		//$total_done_attendance = $calendar_count;
1004
+        //This is the main change of the BT#1381
1005
+        //$total_done_attendance = $calendar_count;
1006 1006
 
1007
-		// calculate results
1008
-		$faults = $total_done_attendance - $attendance_user_score;
1007
+        // calculate results
1008
+        $faults = $total_done_attendance - $attendance_user_score;
1009 1009
 
1010 1010
         if (empty($calendar_count)) {
1011 1011
             $faults = 0;
1012 1012
         }
1013 1013
 
1014 1014
         $faults = $faults > 0 ? $faults : 0;
1015
-		$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1015
+        $faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1016 1016
         $results['faults'] = $faults;
1017 1017
         $results['total'] = $calendar_count;
1018 1018
         $results['faults_porcent'] = $faults_porcent;
1019
-		$color_bar = '';
1019
+        $color_bar = '';
1020 1020
 
1021 1021
         if ($faults_porcent > 25) {
1022 1022
             $color_bar = '#f28989';
1023
-		} else if ($faults_porcent > 10) {
1024
-			$color_bar = '#F90';
1025
-		}
1026
-		$results['color_bar'] = $color_bar;
1027
-
1028
-		return $results;
1029
-	}
1030
-
1031
-	/**
1032
-	 * Get results of faults average for all courses by user
1033
-	 * @param	int	   $user_id
1034
-	 * @return 	array  results containing number of faults, total done attendance,
1035
-	 * percentage of faults and color depend on result (red, orange)
1036
-	 */
1037
-	public function get_faults_average_inside_courses($user_id)
1038
-	{
1039
-		// get all courses of current user
1040
-		$courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1041
-
1042
-		$user_id = intval($user_id);
1043
-		$results = array();
1044
-		$total_faults = $total_weight = $porcent = 0;
1045
-		foreach ($courses as $course) {
1046
-			//$course_code = $course['code'];
1047
-			//$course_info = api_get_course_info($course_code);
1048
-			$course_id = $course['real_id'];
1049
-			$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1050
-
1051
-			$attendances_by_course = $this->get_attendances_list($course_id);
1052
-
1053
-			foreach ($attendances_by_course as $attendance) {
1054
-				// get total faults and total weight
1055
-				$total_done_attendance 	= $attendance['attendance_qualify_max'];
1056
-				$sql = "SELECT score
1023
+        } else if ($faults_porcent > 10) {
1024
+            $color_bar = '#F90';
1025
+        }
1026
+        $results['color_bar'] = $color_bar;
1027
+
1028
+        return $results;
1029
+    }
1030
+
1031
+    /**
1032
+     * Get results of faults average for all courses by user
1033
+     * @param	int	   $user_id
1034
+     * @return 	array  results containing number of faults, total done attendance,
1035
+     * percentage of faults and color depend on result (red, orange)
1036
+     */
1037
+    public function get_faults_average_inside_courses($user_id)
1038
+    {
1039
+        // get all courses of current user
1040
+        $courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1041
+
1042
+        $user_id = intval($user_id);
1043
+        $results = array();
1044
+        $total_faults = $total_weight = $porcent = 0;
1045
+        foreach ($courses as $course) {
1046
+            //$course_code = $course['code'];
1047
+            //$course_info = api_get_course_info($course_code);
1048
+            $course_id = $course['real_id'];
1049
+            $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1050
+
1051
+            $attendances_by_course = $this->get_attendances_list($course_id);
1052
+
1053
+            foreach ($attendances_by_course as $attendance) {
1054
+                // get total faults and total weight
1055
+                $total_done_attendance 	= $attendance['attendance_qualify_max'];
1056
+                $sql = "SELECT score
1057 1057
 						FROM $tbl_attendance_result
1058 1058
                         WHERE
1059 1059
                         	c_id = $course_id AND
1060 1060
                         	user_id = $user_id AND
1061 1061
                         	attendance_id = ".$attendance['id'];
1062
-				$rs = Database::query($sql);
1063
-				$score = 0;
1064
-				if (Database::num_rows($rs) > 0) {
1065
-					$row = Database::fetch_array($rs);
1066
-					$score = $row['score'];
1067
-				}
1068
-				$faults = $total_done_attendance-$score;
1069
-				$faults = $faults > 0 ? $faults:0;
1070
-				$total_faults += $faults;
1071
-				$total_weight += $total_done_attendance;
1072
-			}
1073
-		}
1074
-
1075
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1076
-		$results['faults'] 	= $total_faults;
1077
-		$results['total']	= $total_weight;
1078
-		$results['porcent'] = $porcent;
1079
-
1080
-		return $results;
1081
-	}
1082
-
1083
-	/**
1084
-	 * Get results of faults average by course
1085
-	 * @param	int	   $user_id
1086
-	 * @param 	string	$course_code
1087
-	 * @param	int	   Session id (optional)
1088
-	 * @return 	array  results containing number of faults,
1089
-	 * total done attendance, porcent of faults and color depend on result (red, orange)
1090
-	 */
1091
-	public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1092
-	{
1093
-		// Database tables and variables
1094
-		$course_info = api_get_course_info($course_code);
1095
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1096
-		$user_id = intval($user_id);
1097
-		$results = array();
1098
-		$total_faults = $total_weight = $porcent = 0;
1099
-		$attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1100
-
1101
-		foreach ($attendances_by_course as $attendance) {
1102
-			// Get total faults and total weight
1103
-			$total_done_attendance 	= $attendance['attendance_qualify_max'];
1104
-			$sql = "SELECT score FROM $tbl_attendance_result
1105
-					WHERE
1062
+                $rs = Database::query($sql);
1063
+                $score = 0;
1064
+                if (Database::num_rows($rs) > 0) {
1065
+                    $row = Database::fetch_array($rs);
1066
+                    $score = $row['score'];
1067
+                }
1068
+                $faults = $total_done_attendance-$score;
1069
+                $faults = $faults > 0 ? $faults:0;
1070
+                $total_faults += $faults;
1071
+                $total_weight += $total_done_attendance;
1072
+            }
1073
+        }
1074
+
1075
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1076
+        $results['faults'] 	= $total_faults;
1077
+        $results['total']	= $total_weight;
1078
+        $results['porcent'] = $porcent;
1079
+
1080
+        return $results;
1081
+    }
1082
+
1083
+    /**
1084
+     * Get results of faults average by course
1085
+     * @param	int	   $user_id
1086
+     * @param 	string	$course_code
1087
+     * @param	int	   Session id (optional)
1088
+     * @return 	array  results containing number of faults,
1089
+     * total done attendance, porcent of faults and color depend on result (red, orange)
1090
+     */
1091
+    public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1092
+    {
1093
+        // Database tables and variables
1094
+        $course_info = api_get_course_info($course_code);
1095
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1096
+        $user_id = intval($user_id);
1097
+        $results = array();
1098
+        $total_faults = $total_weight = $porcent = 0;
1099
+        $attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1100
+
1101
+        foreach ($attendances_by_course as $attendance) {
1102
+            // Get total faults and total weight
1103
+            $total_done_attendance 	= $attendance['attendance_qualify_max'];
1104
+            $sql = "SELECT score FROM $tbl_attendance_result
1105
+					WHERE
1106 1106
 						c_id = {$course_info['real_id']} AND
1107 1107
 						user_id = $user_id AND
1108 1108
 						attendance_id=".$attendance['id'];
1109
-			$rs = Database::query($sql);
1110
-			$score = 0;
1111
-			if (Database::num_rows($rs) > 0) {
1112
-				$row = Database::fetch_array($rs);
1113
-				$score = $row['score'];
1114
-			}
1115
-			$faults = $total_done_attendance-$score;
1116
-			$faults = $faults > 0 ? $faults:0;
1117
-			$total_faults += $faults;
1118
-			$total_weight += $total_done_attendance;
1119
-		}
1120
-
1121
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1122
-		$results['faults'] 	= $total_faults;
1123
-		$results['total']	= $total_weight;
1124
-		$results['porcent'] = $porcent;
1125
-
1126
-		return $results;
1127
-	}
1128
-
1129
-	/**
1130
-	 * Get registered users' attendance sheet inside current course
1131
-	 * @param	int	   $attendance_id
1132
-	 * @param	int	   $user_id for showing data for only one user (optional)
1133
-	 * @return 	array  users attendance sheet data
1134
-	 */
1135
-	public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1136
-	{
1137
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1138
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1139
-
1140
-		$attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1141
-		$calendar_ids = array();
1142
-		// get all dates from calendar by current attendance
1143
-		foreach ($attendance_calendar as $cal) {
1144
-			$calendar_ids[] = $cal['id'];
1145
-		}
1146
-
1147
-		$course_id = api_get_course_int_id();
1148
-
1149
-		$data = array();
1150
-		if (empty($user_id)) {
1151
-			// get all registered users inside current course
1152
-			$users = $this->get_users_rel_course();
1153
-			$user_ids = array_keys($users);
1154
-			if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1155
-				foreach ($user_ids as $uid) {
1156
-					$sql = "SELECT * FROM $tbl_attendance_sheet
1109
+            $rs = Database::query($sql);
1110
+            $score = 0;
1111
+            if (Database::num_rows($rs) > 0) {
1112
+                $row = Database::fetch_array($rs);
1113
+                $score = $row['score'];
1114
+            }
1115
+            $faults = $total_done_attendance-$score;
1116
+            $faults = $faults > 0 ? $faults:0;
1117
+            $total_faults += $faults;
1118
+            $total_weight += $total_done_attendance;
1119
+        }
1120
+
1121
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1122
+        $results['faults'] 	= $total_faults;
1123
+        $results['total']	= $total_weight;
1124
+        $results['porcent'] = $porcent;
1125
+
1126
+        return $results;
1127
+    }
1128
+
1129
+    /**
1130
+     * Get registered users' attendance sheet inside current course
1131
+     * @param	int	   $attendance_id
1132
+     * @param	int	   $user_id for showing data for only one user (optional)
1133
+     * @return 	array  users attendance sheet data
1134
+     */
1135
+    public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1136
+    {
1137
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1138
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1139
+
1140
+        $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1141
+        $calendar_ids = array();
1142
+        // get all dates from calendar by current attendance
1143
+        foreach ($attendance_calendar as $cal) {
1144
+            $calendar_ids[] = $cal['id'];
1145
+        }
1146
+
1147
+        $course_id = api_get_course_int_id();
1148
+
1149
+        $data = array();
1150
+        if (empty($user_id)) {
1151
+            // get all registered users inside current course
1152
+            $users = $this->get_users_rel_course();
1153
+            $user_ids = array_keys($users);
1154
+            if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1155
+                foreach ($user_ids as $uid) {
1156
+                    $sql = "SELECT * FROM $tbl_attendance_sheet
1157 1157
 					        WHERE
1158 1158
 					        	c_id = $course_id AND
1159 1159
 					        	user_id = '$uid' AND
1160 1160
 					        	attendance_calendar_id IN(".implode(',',$calendar_ids).")
1161 1161
 							";
1162
-					$res = Database::query($sql);
1163
-					if (Database::num_rows($res) > 0) {
1164
-						while ($row = Database::fetch_array($res)) {
1165
-							$data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1166
-						}
1167
-					}
1168
-				}
1169
-			}
1170
-		} else {
1171
-			// Get attendance for current user
1172
-			$user_id = intval($user_id);
1173
-			if (count($calendar_ids) > 0) {
1174
-				$sql = "SELECT cal.date_time, att.presence
1162
+                    $res = Database::query($sql);
1163
+                    if (Database::num_rows($res) > 0) {
1164
+                        while ($row = Database::fetch_array($res)) {
1165
+                            $data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1166
+                        }
1167
+                    }
1168
+                }
1169
+            }
1170
+        } else {
1171
+            // Get attendance for current user
1172
+            $user_id = intval($user_id);
1173
+            if (count($calendar_ids) > 0) {
1174
+                $sql = "SELECT cal.date_time, att.presence
1175 1175
                         FROM $tbl_attendance_sheet att
1176 1176
 						INNER JOIN  $tbl_attendance_calendar cal
1177 1177
 						ON cal.id = att.attendance_calendar_id
@@ -1181,87 +1181,87 @@  discard block
 block discarded – undo
1181 1181
 							att.user_id = '$user_id' AND
1182 1182
 							att.attendance_calendar_id IN (".implode(',',$calendar_ids).")
1183 1183
                         ORDER BY date_time";
1184
-				$res = Database::query($sql);
1185
-				if (Database::num_rows($res) > 0) {
1186
-					while ($row = Database::fetch_array($res)) {
1187
-						$row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1188
-						$data[$user_id][] = $row;
1189
-					}
1190
-				}
1191
-			}
1192
-		}
1193
-		return $data;
1194
-	}
1195
-
1196
-	/**
1197
-	 * Get next attendance calendar without presences (done attendances)
1198
-	 * @param	int	attendance id
1199
-	 * @return 	int attendance calendar id
1200
-	 */
1201
-	public function get_next_attendance_calendar_id($attendance_id)
1202
-	{
1203
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1204
-		$attendance_id = intval($attendance_id);
1205
-		$course_id = api_get_course_int_id();
1206
-
1207
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1184
+                $res = Database::query($sql);
1185
+                if (Database::num_rows($res) > 0) {
1186
+                    while ($row = Database::fetch_array($res)) {
1187
+                        $row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1188
+                        $data[$user_id][] = $row;
1189
+                    }
1190
+                }
1191
+            }
1192
+        }
1193
+        return $data;
1194
+    }
1195
+
1196
+    /**
1197
+     * Get next attendance calendar without presences (done attendances)
1198
+     * @param	int	attendance id
1199
+     * @return 	int attendance calendar id
1200
+     */
1201
+    public function get_next_attendance_calendar_id($attendance_id)
1202
+    {
1203
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1204
+        $attendance_id = intval($attendance_id);
1205
+        $course_id = api_get_course_int_id();
1206
+
1207
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1208 1208
 		        WHERE
1209 1209
 		        	c_id = $course_id AND
1210 1210
 		        	attendance_id = '$attendance_id' AND
1211 1211
 		        	done_attendance = 0
1212 1212
 		        ORDER BY date_time
1213 1213
 		        LIMIT 1";
1214
-		$rs = Database::query($sql);
1215
-		$next_calendar_id = 0;
1216
-		if (Database::num_rows($rs) > 0) {
1217
-			$row = Database::fetch_array($rs);
1218
-			$next_calendar_id = $row['id'];
1219
-		}
1220
-		return $next_calendar_id;
1221
-	}
1222
-
1223
-	/**
1224
-	 * Get next attendance calendar datetime without presences (done attendances)
1225
-	 * @param	int	attendance id
1226
-	 * @return 	int UNIX time format datetime
1227
-	 */
1228
-	public function get_next_attendance_calendar_datetime($attendance_id)
1229
-	{
1230
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1231
-		$course_id = api_get_course_int_id();
1232
-		$attendance_id = intval($attendance_id);
1233
-		$sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1214
+        $rs = Database::query($sql);
1215
+        $next_calendar_id = 0;
1216
+        if (Database::num_rows($rs) > 0) {
1217
+            $row = Database::fetch_array($rs);
1218
+            $next_calendar_id = $row['id'];
1219
+        }
1220
+        return $next_calendar_id;
1221
+    }
1222
+
1223
+    /**
1224
+     * Get next attendance calendar datetime without presences (done attendances)
1225
+     * @param	int	attendance id
1226
+     * @return 	int UNIX time format datetime
1227
+     */
1228
+    public function get_next_attendance_calendar_datetime($attendance_id)
1229
+    {
1230
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1231
+        $course_id = api_get_course_int_id();
1232
+        $attendance_id = intval($attendance_id);
1233
+        $sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1234 1234
 				WHERE
1235 1235
 					c_id = $course_id AND
1236 1236
 					attendance_id = '$attendance_id' AND
1237 1237
 					done_attendance = 0
1238 1238
 				ORDER BY date_time
1239 1239
 				LIMIT 1";
1240
-		$rs = Database::query($sql);
1241
-		$next_calendar_datetime = 0;
1242
-		if (Database::num_rows($rs) > 0) {
1243
-			$row = Database::fetch_array($rs);
1244
-			$next_calendar_datetime = api_get_local_time($row['date_time']);
1245
-		}
1246
-
1247
-		return $next_calendar_datetime;
1248
-	}
1249
-
1250
-	/**
1251
-	 * Get user' score from current attendance
1252
-	 * @param	int	$user_id
1253
-	 * @param	int $attendance_id
1254
-	 * @return	int score
1255
-	 */
1256
-	public function get_user_score($user_id, $attendance_id, $groupId = null)
1257
-	{
1258
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1240
+        $rs = Database::query($sql);
1241
+        $next_calendar_datetime = 0;
1242
+        if (Database::num_rows($rs) > 0) {
1243
+            $row = Database::fetch_array($rs);
1244
+            $next_calendar_datetime = api_get_local_time($row['date_time']);
1245
+        }
1246
+
1247
+        return $next_calendar_datetime;
1248
+    }
1249
+
1250
+    /**
1251
+     * Get user' score from current attendance
1252
+     * @param	int	$user_id
1253
+     * @param	int $attendance_id
1254
+     * @return	int score
1255
+     */
1256
+    public function get_user_score($user_id, $attendance_id, $groupId = null)
1257
+    {
1258
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1259 1259
         $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1260 1260
         $tbl_attendance_cal_rel_group = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1261 1261
         $tbl_attendance_cal = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1262
-		$user_id = intval($user_id);
1263
-		$attendance_id = intval($attendance_id);
1264
-		$course_id = api_get_course_int_id();
1262
+        $user_id = intval($user_id);
1263
+        $attendance_id = intval($attendance_id);
1264
+        $course_id = api_get_course_int_id();
1265 1265
         if (empty($groupId)) {
1266 1266
             $sql = "SELECT score FROM $tbl_attendance_result
1267 1267
                     WHERE
@@ -1285,68 +1285,68 @@  discard block
 block discarded – undo
1285 1285
                         )
1286 1286
                     ";
1287 1287
         }
1288
-		$rs = Database::query($sql);
1289
-		$score = 0;
1290
-		if (Database::num_rows($rs) > 0) {
1291
-			$row = Database::fetch_array($rs);
1292
-			$score = $row['score'];
1293
-		}
1294
-
1295
-		return $score;
1296
-	}
1297
-
1298
-	/**
1299
-	 * Get attendance calendar data by id
1300
-	 * @param	int	attendance calendar id
1301
-	 * @return	array attendance calendar data
1302
-	 */
1303
-	public function get_attendance_calendar_by_id($calendar_id)
1304
-	{
1305
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1306
-		$calendar_id = intval($calendar_id);
1307
-		$course_id = api_get_course_int_id();
1308
-		$sql = "SELECT * FROM $tbl_attendance_calendar
1288
+        $rs = Database::query($sql);
1289
+        $score = 0;
1290
+        if (Database::num_rows($rs) > 0) {
1291
+            $row = Database::fetch_array($rs);
1292
+            $score = $row['score'];
1293
+        }
1294
+
1295
+        return $score;
1296
+    }
1297
+
1298
+    /**
1299
+     * Get attendance calendar data by id
1300
+     * @param	int	attendance calendar id
1301
+     * @return	array attendance calendar data
1302
+     */
1303
+    public function get_attendance_calendar_by_id($calendar_id)
1304
+    {
1305
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1306
+        $calendar_id = intval($calendar_id);
1307
+        $course_id = api_get_course_int_id();
1308
+        $sql = "SELECT * FROM $tbl_attendance_calendar
1309 1309
 				WHERE c_id = $course_id AND id = '$calendar_id' ";
1310
-		$rs = Database::query($sql);
1311
-		$data = array();
1312
-		if (Database::num_rows($rs) > 0) {
1313
-			while ($row = Database::fetch_array($rs)) {
1314
-				$row['date_time'] = api_get_local_time($row['date_time']);
1315
-				$data = $row;
1316
-			}
1317
-		}
1318
-
1319
-		return $data;
1320
-	}
1321
-
1322
-	/**
1323
-	 * Get all attendance calendar data inside current attendance
1324
-	 * @param int	$attendance_id
1325
-	 * @param string $type
1326
-	 * @param int $calendar_id
1327
-	 * @param int $groupId
1328
-	 * @param bool $showAll = false show group calendar items or not
1329
-	 *
1330
-	 * @return	array attendance calendar data
1331
-	 */
1332
-	public function get_attendance_calendar(
1333
-		$attendance_id,
1334
-		$type = 'all',
1335
-		$calendar_id = null,
1336
-		$groupId = null,
1337
-		$showAll = false
1338
-	) {
1339
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1310
+        $rs = Database::query($sql);
1311
+        $data = array();
1312
+        if (Database::num_rows($rs) > 0) {
1313
+            while ($row = Database::fetch_array($rs)) {
1314
+                $row['date_time'] = api_get_local_time($row['date_time']);
1315
+                $data = $row;
1316
+            }
1317
+        }
1318
+
1319
+        return $data;
1320
+    }
1321
+
1322
+    /**
1323
+     * Get all attendance calendar data inside current attendance
1324
+     * @param int	$attendance_id
1325
+     * @param string $type
1326
+     * @param int $calendar_id
1327
+     * @param int $groupId
1328
+     * @param bool $showAll = false show group calendar items or not
1329
+     *
1330
+     * @return	array attendance calendar data
1331
+     */
1332
+    public function get_attendance_calendar(
1333
+        $attendance_id,
1334
+        $type = 'all',
1335
+        $calendar_id = null,
1336
+        $groupId = null,
1337
+        $showAll = false
1338
+    ) {
1339
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1340 1340
         $tbl_acrg = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1341
-		$attendance_id = intval($attendance_id);
1342
-		$course_id = api_get_course_int_id();
1343
-		$groupCondition = null;
1341
+        $attendance_id = intval($attendance_id);
1342
+        $course_id = api_get_course_int_id();
1343
+        $groupCondition = null;
1344 1344
 
1345
-		if ($showAll) {
1346
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1345
+        if ($showAll) {
1346
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1347 1347
 					WHERE c_id = $course_id AND attendance_id = '$attendance_id'";
1348
-		} else {
1349
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1348
+        } else {
1349
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1350 1350
 					WHERE
1351 1351
 						c_id = $course_id AND
1352 1352
 						attendance_id = '$attendance_id' AND
@@ -1355,11 +1355,11 @@  discard block
 block discarded – undo
1355 1355
 							WHERE c_id = $course_id AND group_id != 0 AND group_id IS NOT NULL
1356 1356
 						)
1357 1357
 					";
1358
-		}
1358
+        }
1359 1359
 
1360
-		if (!empty($groupId)) {
1361
-			$groupId = intval($groupId);
1362
-			$sql = "SELECT c.* FROM $tbl_attendance_calendar c
1360
+        if (!empty($groupId)) {
1361
+            $groupId = intval($groupId);
1362
+            $sql = "SELECT c.* FROM $tbl_attendance_calendar c
1363 1363
 					INNER JOIN $tbl_acrg g
1364 1364
 					ON c.c_id = g.c_id AND c.id = g.calendar_id
1365 1365
 					WHERE
@@ -1367,62 +1367,62 @@  discard block
 block discarded – undo
1367 1367
 					    g.group_id = '$groupId' AND
1368 1368
 					    c.attendance_id = '$attendance_id'
1369 1369
                    ";
1370
-		}
1371
-
1372
-		if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1373
-			$type = 'all';
1374
-		}
1375
-
1376
-		switch ($type) {
1377
-			case 'calendar_id':
1378
-				$calendar_id = intval($calendar_id);
1379
-				if (!empty($calendar_id)) {
1380
-					$sql.= " AND c.id = $calendar_id";
1381
-				}
1382
-				break;
1383
-			case 'today':
1384
-				//$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1385
-				break;
1386
-			case 'all_done':
1387
-				$sql .= " AND done_attendance = 1 ";
1388
-				break;
1389
-			case 'all_not_done':
1390
-				$sql .= " AND done_attendance = 0 ";
1391
-				break;
1392
-			case 'all':
1393
-			default:
1394
-				break;
1395
-		}
1396
-		$sql .= " ORDER BY date_time ";
1370
+        }
1397 1371
 
1398
-		$rs = Database::query($sql);
1399
-		$data = array();
1400
-		if (Database::num_rows($rs) > 0) {
1401
-			while ($row = Database::fetch_array($rs,'ASSOC')) {
1402
-				$row['db_date_time'] = $row['date_time'];
1403
-				$row['date_time'] = api_get_local_time($row['date_time']);
1404
-				$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1405
-				$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1406
-				$row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1407
-				if ($type == 'today') {
1408
-					if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1409
-						$data[] = $row;
1410
-					}
1411
-				} else {
1412
-					$data[] = $row;
1413
-				}
1414
-			}
1415
-		}
1416
-
1417
-		return $data;
1418
-	}
1419
-
1420
-	/**
1421
-	 * Get number of attendance calendar inside current attendance
1422
-	 * @param	int	$attendance_id
1423
-	 * @param	int	$groupId
1424
-	 * @return	int number of dates in attendance calendar
1425
-	 */
1372
+        if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1373
+            $type = 'all';
1374
+        }
1375
+
1376
+        switch ($type) {
1377
+            case 'calendar_id':
1378
+                $calendar_id = intval($calendar_id);
1379
+                if (!empty($calendar_id)) {
1380
+                    $sql.= " AND c.id = $calendar_id";
1381
+                }
1382
+                break;
1383
+            case 'today':
1384
+                //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1385
+                break;
1386
+            case 'all_done':
1387
+                $sql .= " AND done_attendance = 1 ";
1388
+                break;
1389
+            case 'all_not_done':
1390
+                $sql .= " AND done_attendance = 0 ";
1391
+                break;
1392
+            case 'all':
1393
+            default:
1394
+                break;
1395
+        }
1396
+        $sql .= " ORDER BY date_time ";
1397
+
1398
+        $rs = Database::query($sql);
1399
+        $data = array();
1400
+        if (Database::num_rows($rs) > 0) {
1401
+            while ($row = Database::fetch_array($rs,'ASSOC')) {
1402
+                $row['db_date_time'] = $row['date_time'];
1403
+                $row['date_time'] = api_get_local_time($row['date_time']);
1404
+                $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1405
+                $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1406
+                $row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1407
+                if ($type == 'today') {
1408
+                    if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1409
+                        $data[] = $row;
1410
+                    }
1411
+                } else {
1412
+                    $data[] = $row;
1413
+                }
1414
+            }
1415
+        }
1416
+
1417
+        return $data;
1418
+    }
1419
+
1420
+    /**
1421
+     * Get number of attendance calendar inside current attendance
1422
+     * @param	int	$attendance_id
1423
+     * @param	int	$groupId
1424
+     * @return	int number of dates in attendance calendar
1425
+     */
1426 1426
     public static function get_number_of_attendance_calendar($attendance_id, $groupId = 0, $done_attendance = NULL, $userId = 0)
1427 1427
     {
1428 1428
         $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
@@ -1508,112 +1508,112 @@  discard block
 block discarded – undo
1508 1508
 
1509 1509
 
1510 1510
     /**
1511
-	 * Get count dates inside attendance calendar by attendance id
1512
-	 * @param	int	$attendance_id
1513
-	 * @return	int     count of dates
1514
-	 */
1515
-	public static function get_count_dates_inside_attendance_calendar($attendance_id)
1516
-	{
1517
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1518
-		$attendance_id = intval($attendance_id);
1519
-		$course_id = api_get_course_int_id();
1520
-		$sql = "SELECT count(id) FROM $tbl_attendance_calendar
1511
+     * Get count dates inside attendance calendar by attendance id
1512
+     * @param	int	$attendance_id
1513
+     * @return	int     count of dates
1514
+     */
1515
+    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1516
+    {
1517
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1518
+        $attendance_id = intval($attendance_id);
1519
+        $course_id = api_get_course_int_id();
1520
+        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1521 1521
                 WHERE
1522 1522
                 	c_id = $course_id AND
1523 1523
                 	attendance_id = '$attendance_id'";
1524
-		$rs = Database::query($sql);
1525
-		$count = 0;
1526
-		if (Database::num_rows($rs) > 0) {
1527
-			$row = Database::fetch_row($rs);
1528
-			$count = $row[0];
1529
-		}
1530
-		return $count;
1531
-	}
1532
-
1533
-	/**
1534
-	 * check if all calendar of an attendance is done
1535
-	 * @param   int     $attendance_id
1536
-	 * @return  bool    True if all calendar is done, otherwise false
1537
-	 */
1538
-	public static function is_all_attendance_calendar_done($attendance_id)
1539
-	{
1540
-		$attendance_id = intval($attendance_id);
1541
-		$done_calendar = self::get_done_attendance_calendar($attendance_id);
1542
-		$count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1543
-		$number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1544
-
1545
-		$result = false;
1546
-		if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1547
-			$result = true;
1548
-		}
1549
-		return $result;
1550
-	}
1551
-
1552
-	/**
1553
-	 * check if an attendance is locked
1554
-	 * @param   int $attendance_id
1555
-	 * @param   bool
1556
-	 */
1557
-	public static function is_locked_attendance($attendance_id)
1558
-	{
1559
-		//use gradebook lock
1560
-		$result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1561
-		return $result;
1562
-	}
1563
-
1564
-	/**
1565
-	 * Add new datetime inside attendance calendar table
1566
-	 * @param	int		$attendance_id
1567
-	 * @param 	array 	$groupList
1568
-	 * @return	int affected rows
1569
-	 */
1570
-	public function attendance_calendar_add($attendance_id, $groupList = array())
1571
-	{
1572
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1573
-		$affected_rows = 0;
1574
-		$attendance_id = intval($attendance_id);
1575
-		$course_id = api_get_course_int_id();
1576
-		// check if datetime already exists inside the table
1577
-		/*$sql = "SELECT id FROM $tbl_attendance_calendar
1524
+        $rs = Database::query($sql);
1525
+        $count = 0;
1526
+        if (Database::num_rows($rs) > 0) {
1527
+            $row = Database::fetch_row($rs);
1528
+            $count = $row[0];
1529
+        }
1530
+        return $count;
1531
+    }
1532
+
1533
+    /**
1534
+     * check if all calendar of an attendance is done
1535
+     * @param   int     $attendance_id
1536
+     * @return  bool    True if all calendar is done, otherwise false
1537
+     */
1538
+    public static function is_all_attendance_calendar_done($attendance_id)
1539
+    {
1540
+        $attendance_id = intval($attendance_id);
1541
+        $done_calendar = self::get_done_attendance_calendar($attendance_id);
1542
+        $count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1543
+        $number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1544
+
1545
+        $result = false;
1546
+        if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1547
+            $result = true;
1548
+        }
1549
+        return $result;
1550
+    }
1551
+
1552
+    /**
1553
+     * check if an attendance is locked
1554
+     * @param   int $attendance_id
1555
+     * @param   bool
1556
+     */
1557
+    public static function is_locked_attendance($attendance_id)
1558
+    {
1559
+        //use gradebook lock
1560
+        $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1561
+        return $result;
1562
+    }
1563
+
1564
+    /**
1565
+     * Add new datetime inside attendance calendar table
1566
+     * @param	int		$attendance_id
1567
+     * @param 	array 	$groupList
1568
+     * @return	int affected rows
1569
+     */
1570
+    public function attendance_calendar_add($attendance_id, $groupList = array())
1571
+    {
1572
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1573
+        $affected_rows = 0;
1574
+        $attendance_id = intval($attendance_id);
1575
+        $course_id = api_get_course_int_id();
1576
+        // check if datetime already exists inside the table
1577
+        /*$sql = "SELECT id FROM $tbl_attendance_calendar
1578 1578
 		        WHERE
1579 1579
 		        	c_id = $course_id AND
1580 1580
 		        	date_time='".Database::escape_string($this->date_time)."' AND
1581 1581
 		        	attendance_id = '$attendance_id'";
1582 1582
 		$rs = Database::query($sql);
1583 1583
 		if (Database::num_rows($rs) == 0) {*/
1584
-			$params = array(
1585
-				'c_id' =>  $course_id,
1586
-				'date_time' => $this->date_time,
1587
-				'attendance_id' => $attendance_id,
1584
+            $params = array(
1585
+                'c_id' =>  $course_id,
1586
+                'date_time' => $this->date_time,
1587
+                'attendance_id' => $attendance_id,
1588 1588
                 'done_attendance' => 0
1589
-			);
1590
-			$id = Database::insert($tbl_attendance_calendar, $params);
1591
-
1592
-			if ($id) {
1593
-				$sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1594
-				Database::query($sql);
1595
-				$affected_rows++;
1596
-			}
1597
-			$this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1598
-		//}
1599
-
1600
-		// update locked attendance
1601
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1602
-		if (!$is_all_calendar_done) {
1603
-			self::lock_attendance($attendance_id, false);
1604
-		} else {
1605
-			self::lock_attendance($attendance_id);
1606
-		}
1607
-		return $affected_rows;
1608
-	}
1609
-
1610
-	/**
1611
-	 * @param int   $calendarId
1612
-	 * @param int 	$courseId
1613
-	 * @param array $groupList
1614
-	 */
1615
-	public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1616
-	{
1589
+            );
1590
+            $id = Database::insert($tbl_attendance_calendar, $params);
1591
+
1592
+            if ($id) {
1593
+                $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1594
+                Database::query($sql);
1595
+                $affected_rows++;
1596
+            }
1597
+            $this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1598
+        //}
1599
+
1600
+        // update locked attendance
1601
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1602
+        if (!$is_all_calendar_done) {
1603
+            self::lock_attendance($attendance_id, false);
1604
+        } else {
1605
+            self::lock_attendance($attendance_id);
1606
+        }
1607
+        return $affected_rows;
1608
+    }
1609
+
1610
+    /**
1611
+     * @param int   $calendarId
1612
+     * @param int 	$courseId
1613
+     * @param array $groupList
1614
+     */
1615
+    public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1616
+    {
1617 1617
         if (empty($groupList)) {
1618 1618
             return false;
1619 1619
         }
@@ -1641,506 +1641,506 @@  discard block
 block discarded – undo
1641 1641
                 Database::insert($table, $params);
1642 1642
             }
1643 1643
         }
1644
-	}
1645
-
1646
-	/**
1647
-	 * @param int $calendarId
1648
-	 * @param int $courseId
1649
-	 * @param int $groupId
1650
-	 * @return array
1651
-	 */
1652
-	public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1653
-	{
1654
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1655
-		return Database::select(
1656
-			'*',
1657
-			$table,
1658
-			array('where'=>
1659
-				array(
1660
-					'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1661
-				)
1662
-			)
1663
-		);
1664
-	}
1665
-
1666
-	/**
1667
-	 * @param int $calendarId
1668
-	 * @param int $courseId
1669
-	 * @param int $groupId
1670
-	 * @return array
1671
-	 */
1672
-	public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1673
-	{
1674
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1675
-		return Database::select(
1676
-			'*',
1677
-			$table,
1678
-			array('where'=>
1679
-				array(
1680
-					'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1681
-				)
1682
-			)
1683
-		);
1684
-	}
1685
-
1686
-	/**
1687
-	 * @param int $calendarId
1688
-	 * @param int $courseId
1689
-	 * @param int $groupId
1644
+    }
1645
+
1646
+    /**
1647
+     * @param int $calendarId
1648
+     * @param int $courseId
1649
+     * @param int $groupId
1650
+     * @return array
1651
+     */
1652
+    public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1653
+    {
1654
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1655
+        return Database::select(
1656
+            '*',
1657
+            $table,
1658
+            array('where'=>
1659
+                array(
1660
+                    'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1661
+                )
1662
+            )
1663
+        );
1664
+    }
1665
+
1666
+    /**
1667
+     * @param int $calendarId
1668
+     * @param int $courseId
1669
+     * @param int $groupId
1670
+     * @return array
1671
+     */
1672
+    public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1673
+    {
1674
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1675
+        return Database::select(
1676
+            '*',
1677
+            $table,
1678
+            array('where'=>
1679
+                array(
1680
+                    'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1681
+                )
1682
+            )
1683
+        );
1684
+    }
1685
+
1686
+    /**
1687
+     * @param int $calendarId
1688
+     * @param int $courseId
1689
+     * @param int $groupId
1690 1690
      *
1691
-	 * @return array
1692
-	 */
1693
-	public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1694
-	{
1695
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1696
-		Database::delete(
1697
-			$table,
1698
-			array(
1699
-				'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1700
-			)
1701
-		);
1702
-	}
1703
-
1704
-	/**
1705
-	 * save repeated date inside attendance calendar table
1706
-	 * @param int $attendance_id
1707
-	 * @param int $start_date start date in tms
1708
-	 * @param int $end_date end date in tms
1709
-	 * @param string $repeat_type daily, weekly, monthlyByDate
1710
-	 * @param array $groupList
1711
-	 */
1712
-	public function attendance_repeat_calendar_add(
1713
-		$attendance_id,
1714
-		$start_date,
1715
-		$end_date,
1716
-		$repeat_type,
1717
-		$groupList = array()
1718
-	) {
1719
-		$attendance_id = intval($attendance_id);
1720
-		// save start date
1721
-		$datetimezone = api_get_utc_datetime($start_date);
1722
-		$this->set_date_time($datetimezone);
1723
-		$this->attendance_calendar_add($attendance_id, $groupList);
1724
-
1725
-		// 86400 = 24 hours in seconds
1726
-		// 604800 = 1 week in seconds
1727
-		// Saves repeated dates
1728
-		switch ($repeat_type) {
1729
-			case 'daily':
1730
-				$j = 1;
1731
-				for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1732
-					$datetimezone = api_get_utc_datetime($i);
1733
-					$this->set_date_time($datetimezone);
1734
-					$this->attendance_calendar_add($attendance_id, $groupList);
1735
-					$j++;
1736
-				}
1737
-				break;
1738
-			case 'weekly':
1739
-				$j = 1;
1740
-				for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1741
-					$datetimezone = api_get_utc_datetime($i);
1742
-					$this->set_date_time($datetimezone);
1743
-					$this->attendance_calendar_add($attendance_id, $groupList);
1744
-					$j++;
1745
-				}
1746
-				break;
1747
-			case 'monthlyByDate':
1748
-				$j = 1;
1749
-				//@todo fix bug with february
1750
-				for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1751
-					$datetimezone = api_get_utc_datetime($i);
1752
-					$this->set_date_time($datetimezone);
1753
-					$this->attendance_calendar_add($attendance_id, $groupList);
1754
-					$j++;
1755
-				}
1756
-				break;
1757
-		}
1758
-	}
1759
-
1760
-	/**
1761
-	 * Adds x months to a UNIX timestamp
1762
-	 * @param   int     The timestamp
1763
-	 * @param   int     The number of years to add
1764
-	 * @return  int     The new timestamp
1765
-	 */
1766
-	private function add_month($timestamp, $num=1)
1767
-	{
1768
-		$values = api_get_utc_datetime($timestamp);
1769
-		$values = str_replace(array(':','-',' '), '/', $values);
1770
-		list($y, $m, $d, $h, $n, $s) = split('/',$values);
1771
-		if($m+$num>12) {
1772
-			$y += floor($num/12);
1773
-			$m += $num%12;
1774
-		} else {
1775
-			$m += $num;
1776
-		}
1777
-		//date_default_timezone_set('UTC');
1778
-		// return mktime($h, $n, $s, $m, $d, $y);
1779
-		$result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1780
-		if (!empty($result)) {
1781
-			return $result;
1782
-		}
1783
-		return false;
1784
-	}
1785
-
1786
-	/**
1787
-	 * edit a datetime inside attendance calendar table
1788
-	 * @param	int	attendance calendar id
1789
-	 * @param	int	attendance id
1790
-	 * @return	int affected rows
1791
-	 */
1792
-	public function attendance_calendar_edit($calendar_id, $attendance_id)
1793
-	{
1794
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1795
-		$affected_rows = 0;
1796
-		$attendance_id = intval($attendance_id);
1797
-		$course_id = api_get_course_int_id();
1798
-		// check if datetime already exists inside the table
1799
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1691
+     * @return array
1692
+     */
1693
+    public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1694
+    {
1695
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1696
+        Database::delete(
1697
+            $table,
1698
+            array(
1699
+                'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1700
+            )
1701
+        );
1702
+    }
1703
+
1704
+    /**
1705
+     * save repeated date inside attendance calendar table
1706
+     * @param int $attendance_id
1707
+     * @param int $start_date start date in tms
1708
+     * @param int $end_date end date in tms
1709
+     * @param string $repeat_type daily, weekly, monthlyByDate
1710
+     * @param array $groupList
1711
+     */
1712
+    public function attendance_repeat_calendar_add(
1713
+        $attendance_id,
1714
+        $start_date,
1715
+        $end_date,
1716
+        $repeat_type,
1717
+        $groupList = array()
1718
+    ) {
1719
+        $attendance_id = intval($attendance_id);
1720
+        // save start date
1721
+        $datetimezone = api_get_utc_datetime($start_date);
1722
+        $this->set_date_time($datetimezone);
1723
+        $this->attendance_calendar_add($attendance_id, $groupList);
1724
+
1725
+        // 86400 = 24 hours in seconds
1726
+        // 604800 = 1 week in seconds
1727
+        // Saves repeated dates
1728
+        switch ($repeat_type) {
1729
+            case 'daily':
1730
+                $j = 1;
1731
+                for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1732
+                    $datetimezone = api_get_utc_datetime($i);
1733
+                    $this->set_date_time($datetimezone);
1734
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1735
+                    $j++;
1736
+                }
1737
+                break;
1738
+            case 'weekly':
1739
+                $j = 1;
1740
+                for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1741
+                    $datetimezone = api_get_utc_datetime($i);
1742
+                    $this->set_date_time($datetimezone);
1743
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1744
+                    $j++;
1745
+                }
1746
+                break;
1747
+            case 'monthlyByDate':
1748
+                $j = 1;
1749
+                //@todo fix bug with february
1750
+                for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1751
+                    $datetimezone = api_get_utc_datetime($i);
1752
+                    $this->set_date_time($datetimezone);
1753
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1754
+                    $j++;
1755
+                }
1756
+                break;
1757
+        }
1758
+    }
1759
+
1760
+    /**
1761
+     * Adds x months to a UNIX timestamp
1762
+     * @param   int     The timestamp
1763
+     * @param   int     The number of years to add
1764
+     * @return  int     The new timestamp
1765
+     */
1766
+    private function add_month($timestamp, $num=1)
1767
+    {
1768
+        $values = api_get_utc_datetime($timestamp);
1769
+        $values = str_replace(array(':','-',' '), '/', $values);
1770
+        list($y, $m, $d, $h, $n, $s) = split('/',$values);
1771
+        if($m+$num>12) {
1772
+            $y += floor($num/12);
1773
+            $m += $num%12;
1774
+        } else {
1775
+            $m += $num;
1776
+        }
1777
+        //date_default_timezone_set('UTC');
1778
+        // return mktime($h, $n, $s, $m, $d, $y);
1779
+        $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1780
+        if (!empty($result)) {
1781
+            return $result;
1782
+        }
1783
+        return false;
1784
+    }
1785
+
1786
+    /**
1787
+     * edit a datetime inside attendance calendar table
1788
+     * @param	int	attendance calendar id
1789
+     * @param	int	attendance id
1790
+     * @return	int affected rows
1791
+     */
1792
+    public function attendance_calendar_edit($calendar_id, $attendance_id)
1793
+    {
1794
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1795
+        $affected_rows = 0;
1796
+        $attendance_id = intval($attendance_id);
1797
+        $course_id = api_get_course_int_id();
1798
+        // check if datetime already exists inside the table
1799
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1800 1800
 		        WHERE
1801 1801
 		        	c_id = $course_id AND
1802 1802
 		        	date_time = '".Database::escape_string($this->date_time)."' AND
1803 1803
 		        	attendance_id = '$attendance_id'";
1804
-		$rs = Database::query($sql);
1804
+        $rs = Database::query($sql);
1805 1805
 
1806
-		if (Database::num_rows($rs) == 0) {
1807
-			$sql = "UPDATE $tbl_attendance_calendar
1806
+        if (Database::num_rows($rs) == 0) {
1807
+            $sql = "UPDATE $tbl_attendance_calendar
1808 1808
 					SET date_time='".Database::escape_string($this->date_time)."'
1809 1809
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1810
-			Database::query($sql);
1811
-		}
1812
-
1813
-		// update locked attendance
1814
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1815
-		if (!$is_all_calendar_done) {
1816
-			self::lock_attendance($attendance_id, false);
1817
-		} else {
1818
-			self::lock_attendance($attendance_id);
1819
-		}
1820
-
1821
-		return $affected_rows;
1822
-	}
1823
-
1824
-	/**
1825
-	 * delete a datetime from attendance calendar table
1826
-	 * @param	int		attendance calendar id
1827
-	 * @param	int		attendance id
1828
-	 * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1829
-	 * @return	int affected rows
1830
-	 */
1831
-	public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1832
-	{
1833
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1834
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1835
-
1836
-		$attendance_id = intval($attendance_id);
1837
-		// get all registered users inside current course
1838
-		$users = $this->get_users_rel_course();
1839
-		$user_ids = array_keys($users);
1840
-		$course_id = api_get_course_int_id();
1841
-		$affected_rows = 0;
1842
-		if ($all_delete) {
1843
-			$attendance_calendar = $this->get_attendance_calendar($attendance_id);
1844
-			// get all dates from calendar by current attendance
1845
-			if (!empty($attendance_calendar)) {
1846
-				foreach ($attendance_calendar as $cal) {
1847
-					// delete all data from attendance sheet
1848
-					$sql = "DELETE FROM $tbl_attendance_sheet
1810
+            Database::query($sql);
1811
+        }
1812
+
1813
+        // update locked attendance
1814
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1815
+        if (!$is_all_calendar_done) {
1816
+            self::lock_attendance($attendance_id, false);
1817
+        } else {
1818
+            self::lock_attendance($attendance_id);
1819
+        }
1820
+
1821
+        return $affected_rows;
1822
+    }
1823
+
1824
+    /**
1825
+     * delete a datetime from attendance calendar table
1826
+     * @param	int		attendance calendar id
1827
+     * @param	int		attendance id
1828
+     * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1829
+     * @return	int affected rows
1830
+     */
1831
+    public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1832
+    {
1833
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1834
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1835
+
1836
+        $attendance_id = intval($attendance_id);
1837
+        // get all registered users inside current course
1838
+        $users = $this->get_users_rel_course();
1839
+        $user_ids = array_keys($users);
1840
+        $course_id = api_get_course_int_id();
1841
+        $affected_rows = 0;
1842
+        if ($all_delete) {
1843
+            $attendance_calendar = $this->get_attendance_calendar($attendance_id);
1844
+            // get all dates from calendar by current attendance
1845
+            if (!empty($attendance_calendar)) {
1846
+                foreach ($attendance_calendar as $cal) {
1847
+                    // delete all data from attendance sheet
1848
+                    $sql = "DELETE FROM $tbl_attendance_sheet
1849 1849
 							WHERE c_id = $course_id AND attendance_calendar_id = '".intval($cal['id'])."'";
1850
-					Database::query($sql);
1851
-					// delete data from attendance calendar
1852
-					$sql = "DELETE FROM $tbl_attendance_calendar
1850
+                    Database::query($sql);
1851
+                    // delete data from attendance calendar
1852
+                    $sql = "DELETE FROM $tbl_attendance_calendar
1853 1853
 							WHERE c_id = $course_id AND id = '".intval($cal['id'])."'";
1854
-					Database::query($sql);
1855
-
1856
-					$this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1857
-					$affected_rows++;
1858
-				}
1859
-			}
1860
-		} else {
1861
-			// delete just one row from attendance sheet by the calendar id
1862
-			$sql = "DELETE FROM $tbl_attendance_sheet
1854
+                    Database::query($sql);
1855
+
1856
+                    $this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1857
+                    $affected_rows++;
1858
+                }
1859
+            }
1860
+        } else {
1861
+            // delete just one row from attendance sheet by the calendar id
1862
+            $sql = "DELETE FROM $tbl_attendance_sheet
1863 1863
 					WHERE c_id = $course_id AND attendance_calendar_id = '".intval($calendar_id)."'";
1864
-			Database::query($sql);
1865
-			// delete data from attendance calendar
1866
-			$sql = "DELETE FROM $tbl_attendance_calendar
1864
+            Database::query($sql);
1865
+            // delete data from attendance calendar
1866
+            $sql = "DELETE FROM $tbl_attendance_calendar
1867 1867
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1868
-			Database::query($sql);
1869
-
1870
-			$this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1871
-			$affected_rows++;
1872
-		}
1873
-
1874
-		// update users' results
1875
-		$this->update_users_results($user_ids, $attendance_id);
1876
-
1877
-		return $affected_rows;
1878
-	}
1879
-
1880
-	/** Setters for fields of attendances tables **/
1881
-	public function set_session_id($session_id)
1882
-	{
1883
-		$this->session_id = $session_id;
1884
-	}
1885
-
1886
-	public function set_course_id($course_id)
1887
-	{
1888
-		$this->course_id = $course_id;
1889
-	}
1890
-
1891
-	public function set_date_time($datetime)
1892
-	{
1893
-		$this->date_time = $datetime;
1894
-	}
1895
-
1896
-	public function set_name($name)
1897
-	{
1898
-		$this->name = $name;
1899
-	}
1900
-
1901
-	public function set_description($description)
1902
-	{
1903
-		$this->description = $description;
1904
-	}
1905
-
1906
-	public function set_attendance_qualify_title($attendance_qualify_title)
1907
-	{
1908
-		$this->attendance_qualify_title = $attendance_qualify_title;
1909
-	}
1910
-
1911
-	public function set_attendance_weight($attendance_weight)
1912
-	{
1913
-		$this->attendance_weight = $attendance_weight;
1914
-	}
1915
-
1916
-	/** Getters for fields of attendances tables **/
1917
-	public function get_session_id()
1918
-	{
1919
-		return $this->session_id;
1920
-	}
1921
-
1922
-	public function get_course_id()
1923
-	{
1924
-		return $this->course_id;
1925
-	}
1926
-
1927
-	public function get_date_time()
1928
-	{
1929
-		return $this->date_time;
1930
-	}
1931
-
1932
-	public function get_name()
1933
-	{
1934
-		return $this->name;
1935
-	}
1936
-
1937
-	public function get_description()
1938
-	{
1939
-		return $this->description;
1940
-	}
1941
-
1942
-	public function get_attendance_qualify_title()
1943
-	{
1944
-		return $this->attendance_qualify_title;
1945
-	}
1946
-
1947
-	public function get_attendance_weight()
1948
-	{
1949
-		return $this->attendance_weight;
1950
-	}
1951
-
1952
-	/**
1953
-	 * @param string $startDate in UTC time
1954
-	 * @param string $endDate in UTC time
1955
-	 *
1956
-	 * @return array
1957
-	 */
1958
-	public function getAttendanceLogin($startDate, $endDate)
1959
-	{
1960
-		if (empty($startDate) || $startDate == '0000-00-00' ||
1961
-			empty($endDate) || $endDate == '0000-00-00'
1962
-		) {
1963
-			return false;
1964
-		}
1965
-
1966
-		$sessionId = api_get_session_id();
1967
-		$courseCode  = api_get_course_id();
1968
-		if (!empty($sessionId)) {
1969
-			$users = CourseManager:: get_user_list_from_course_code(
1970
-				$courseCode,
1971
-				$sessionId,
1972
-				'',
1973
-				'lastname',
1974
-				0
1975
-			);
1976
-		} else {
1977
-			$users = CourseManager:: get_user_list_from_course_code(
1978
-				$courseCode,
1979
-				0,
1980
-				'',
1981
-				'lastname',
1982
-				STUDENT
1983
-			);
1984
-		}
1985
-
1986
-		$dateTimeStartOriginal = new DateTime($startDate);
1987
-		$dateTimeStart = new DateTime($startDate);
1988
-		$dateTimeEnd= new DateTime($endDate);
1989
-		$interval = $dateTimeStart->diff($dateTimeEnd);
1990
-		$days = intval($interval->format('%a'));
1991
-
1992
-		$dateList = array($dateTimeStart->format('Y-m-d'));
1993
-		$headers = array(
1994
-			get_lang('User'),
1995
-			$dateTimeStart->format('Y-m-d')
1996
-		);
1997
-
1998
-		for ($i = 0; $i < $days; $i++) {
1999
-			$dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
2000
-			$date = $dateTimeStart->format('Y-m-d');
2001
-			$dateList[] = $date;
2002
-			$headers[] = $date;
2003
-		}
2004
-
2005
-		$accessData = CourseManager::getCourseAccessPerCourseAndSession(
2006
-			$courseCode,
2007
-			$sessionId,
2008
-			$dateTimeStartOriginal->format('Y-m-d H:i:s'),
2009
-			$dateTimeEnd->format('Y-m-d H:i:s')
2010
-		);
2011
-
2012
-		$results = array();
2013
-		if (!empty($accessData)) {
2014
-			foreach ($accessData as $data) {
2015
-				$onlyDate = substr($data['login_course_date'], 0, 10);
2016
-				$results[$data['user_id']][$onlyDate] = true;
2017
-			}
2018
-		}
2019
-
2020
-		return array(
2021
-			'users' => $users,
2022
-			'dateList' => $dateList,
2023
-			'headers' => $headers,
2024
-			'results' => $results
2025
-		);
2026
-	}
2027
-
2028
-	/**
2029
-	 * @param string $startDate in UTC time
2030
-	 * @param string $endDate in UTC time
2031
-	 *
2032
-	 * @return string
2033
-	 */
2034
-	public function getAttendanceLoginTable($startDate, $endDate)
2035
-	{
2036
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2037
-
2038
-		if (!$data) {
2039
-			return null;
2040
-		}
2041
-
2042
-		$headers = $data['headers'];
2043
-		$dateList = $data['dateList'];
2044
-		$users = $data['users'];
2045
-		$results = $data['results'];
2046
-
2047
-		$table = new HTML_Table(array('class' => 'data_table'));
2048
-		$row = 0;
2049
-		$column = 0;
2050
-		foreach ($headers as $header) {
2051
-			$table->setHeaderContents($row, $column, $header);
2052
-			$column++;
2053
-		}
2054
-		$row = 1;
2055
-		foreach ($users as $user) {
2056
-			$table->setCellContents(
2057
-				$row,
2058
-				0,
2059
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2060
-			);
2061
-			$row ++;
2062
-		}
2063
-
2064
-		$column = 1;
2065
-		$row = 1;
2066
-		foreach ($users as $user) {
2067
-			foreach ($dateList as $date) {
2068
-				$status = null;
2069
-				if (isset($results[$user['user_id']]) &&
2070
-					isset($results[$user['user_id']][$date])
2071
-				) {
2072
-					$status = 'X';
2073
-				}
2074
-				$table->setCellContents($row, $column, $status);
2075
-				$column++;
2076
-			}
2077
-			$row++;
2078
-			$column = 1;
2079
-		}
2080
-
2081
-		return $table->toHtml();
2082
-	}
2083
-
2084
-	/**
2085
-	 * @param string $startDate in UTC time
2086
-	 * @param string $endDate in UTC time
2087
-	 *
2088
-	 * @return string
2089
-	 */
2090
-	public function exportAttendanceLogin($startDate, $endDate)
2091
-	{
2092
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2093
-
2094
-		if (!$data) {
2095
-			return null;
2096
-		}
2097
-		$users = $data['users'];
2098
-		$results = $data['results'];
2099
-
2100
-		$table = new HTML_Table(array('class' => 'data_table'));
2101
-
2102
-		$table->setHeaderContents(0, 0, get_lang('User'));
2103
-		$table->setHeaderContents(0, 1, get_lang('Date'));
2104
-
2105
-		$row = 1;
2106
-		foreach ($users as $user) {
2107
-			$table->setCellContents(
2108
-				$row,
2109
-				0,
2110
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2111
-			);
2112
-			$row++;
2113
-		}
2114
-		$table->setColAttributes(0, array('style' => 'width:28%'));
2115
-
2116
-		$row = 1;
2117
-		foreach ($users as $user) {
2118
-			if (isset($results[$user['user_id']]) &&
2119
-				!empty($results[$user['user_id']])
2120
-			) {
2121
-				$dates = implode(', ', array_keys($results[$user['user_id']]));
2122
-				$table->setCellContents($row, 1, $dates);
2123
-			}
2124
-			$row++;
2125
-		}
2126
-
2127
-		//$tableToString = null;
2128
-
2129
-		//$sessionInfo = api_get_session_info(api_get_session_id());
2130
-		//if (!empty($sessionInfo)) {
2131
-		/*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
1868
+            Database::query($sql);
1869
+
1870
+            $this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1871
+            $affected_rows++;
1872
+        }
1873
+
1874
+        // update users' results
1875
+        $this->update_users_results($user_ids, $attendance_id);
1876
+
1877
+        return $affected_rows;
1878
+    }
1879
+
1880
+    /** Setters for fields of attendances tables **/
1881
+    public function set_session_id($session_id)
1882
+    {
1883
+        $this->session_id = $session_id;
1884
+    }
1885
+
1886
+    public function set_course_id($course_id)
1887
+    {
1888
+        $this->course_id = $course_id;
1889
+    }
1890
+
1891
+    public function set_date_time($datetime)
1892
+    {
1893
+        $this->date_time = $datetime;
1894
+    }
1895
+
1896
+    public function set_name($name)
1897
+    {
1898
+        $this->name = $name;
1899
+    }
1900
+
1901
+    public function set_description($description)
1902
+    {
1903
+        $this->description = $description;
1904
+    }
1905
+
1906
+    public function set_attendance_qualify_title($attendance_qualify_title)
1907
+    {
1908
+        $this->attendance_qualify_title = $attendance_qualify_title;
1909
+    }
1910
+
1911
+    public function set_attendance_weight($attendance_weight)
1912
+    {
1913
+        $this->attendance_weight = $attendance_weight;
1914
+    }
1915
+
1916
+    /** Getters for fields of attendances tables **/
1917
+    public function get_session_id()
1918
+    {
1919
+        return $this->session_id;
1920
+    }
1921
+
1922
+    public function get_course_id()
1923
+    {
1924
+        return $this->course_id;
1925
+    }
1926
+
1927
+    public function get_date_time()
1928
+    {
1929
+        return $this->date_time;
1930
+    }
1931
+
1932
+    public function get_name()
1933
+    {
1934
+        return $this->name;
1935
+    }
1936
+
1937
+    public function get_description()
1938
+    {
1939
+        return $this->description;
1940
+    }
1941
+
1942
+    public function get_attendance_qualify_title()
1943
+    {
1944
+        return $this->attendance_qualify_title;
1945
+    }
1946
+
1947
+    public function get_attendance_weight()
1948
+    {
1949
+        return $this->attendance_weight;
1950
+    }
1951
+
1952
+    /**
1953
+     * @param string $startDate in UTC time
1954
+     * @param string $endDate in UTC time
1955
+     *
1956
+     * @return array
1957
+     */
1958
+    public function getAttendanceLogin($startDate, $endDate)
1959
+    {
1960
+        if (empty($startDate) || $startDate == '0000-00-00' ||
1961
+            empty($endDate) || $endDate == '0000-00-00'
1962
+        ) {
1963
+            return false;
1964
+        }
1965
+
1966
+        $sessionId = api_get_session_id();
1967
+        $courseCode  = api_get_course_id();
1968
+        if (!empty($sessionId)) {
1969
+            $users = CourseManager:: get_user_list_from_course_code(
1970
+                $courseCode,
1971
+                $sessionId,
1972
+                '',
1973
+                'lastname',
1974
+                0
1975
+            );
1976
+        } else {
1977
+            $users = CourseManager:: get_user_list_from_course_code(
1978
+                $courseCode,
1979
+                0,
1980
+                '',
1981
+                'lastname',
1982
+                STUDENT
1983
+            );
1984
+        }
1985
+
1986
+        $dateTimeStartOriginal = new DateTime($startDate);
1987
+        $dateTimeStart = new DateTime($startDate);
1988
+        $dateTimeEnd= new DateTime($endDate);
1989
+        $interval = $dateTimeStart->diff($dateTimeEnd);
1990
+        $days = intval($interval->format('%a'));
1991
+
1992
+        $dateList = array($dateTimeStart->format('Y-m-d'));
1993
+        $headers = array(
1994
+            get_lang('User'),
1995
+            $dateTimeStart->format('Y-m-d')
1996
+        );
1997
+
1998
+        for ($i = 0; $i < $days; $i++) {
1999
+            $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
2000
+            $date = $dateTimeStart->format('Y-m-d');
2001
+            $dateList[] = $date;
2002
+            $headers[] = $date;
2003
+        }
2004
+
2005
+        $accessData = CourseManager::getCourseAccessPerCourseAndSession(
2006
+            $courseCode,
2007
+            $sessionId,
2008
+            $dateTimeStartOriginal->format('Y-m-d H:i:s'),
2009
+            $dateTimeEnd->format('Y-m-d H:i:s')
2010
+        );
2011
+
2012
+        $results = array();
2013
+        if (!empty($accessData)) {
2014
+            foreach ($accessData as $data) {
2015
+                $onlyDate = substr($data['login_course_date'], 0, 10);
2016
+                $results[$data['user_id']][$onlyDate] = true;
2017
+            }
2018
+        }
2019
+
2020
+        return array(
2021
+            'users' => $users,
2022
+            'dateList' => $dateList,
2023
+            'headers' => $headers,
2024
+            'results' => $results
2025
+        );
2026
+    }
2027
+
2028
+    /**
2029
+     * @param string $startDate in UTC time
2030
+     * @param string $endDate in UTC time
2031
+     *
2032
+     * @return string
2033
+     */
2034
+    public function getAttendanceLoginTable($startDate, $endDate)
2035
+    {
2036
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2037
+
2038
+        if (!$data) {
2039
+            return null;
2040
+        }
2041
+
2042
+        $headers = $data['headers'];
2043
+        $dateList = $data['dateList'];
2044
+        $users = $data['users'];
2045
+        $results = $data['results'];
2046
+
2047
+        $table = new HTML_Table(array('class' => 'data_table'));
2048
+        $row = 0;
2049
+        $column = 0;
2050
+        foreach ($headers as $header) {
2051
+            $table->setHeaderContents($row, $column, $header);
2052
+            $column++;
2053
+        }
2054
+        $row = 1;
2055
+        foreach ($users as $user) {
2056
+            $table->setCellContents(
2057
+                $row,
2058
+                0,
2059
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2060
+            );
2061
+            $row ++;
2062
+        }
2063
+
2064
+        $column = 1;
2065
+        $row = 1;
2066
+        foreach ($users as $user) {
2067
+            foreach ($dateList as $date) {
2068
+                $status = null;
2069
+                if (isset($results[$user['user_id']]) &&
2070
+                    isset($results[$user['user_id']][$date])
2071
+                ) {
2072
+                    $status = 'X';
2073
+                }
2074
+                $table->setCellContents($row, $column, $status);
2075
+                $column++;
2076
+            }
2077
+            $row++;
2078
+            $column = 1;
2079
+        }
2080
+
2081
+        return $table->toHtml();
2082
+    }
2083
+
2084
+    /**
2085
+     * @param string $startDate in UTC time
2086
+     * @param string $endDate in UTC time
2087
+     *
2088
+     * @return string
2089
+     */
2090
+    public function exportAttendanceLogin($startDate, $endDate)
2091
+    {
2092
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2093
+
2094
+        if (!$data) {
2095
+            return null;
2096
+        }
2097
+        $users = $data['users'];
2098
+        $results = $data['results'];
2099
+
2100
+        $table = new HTML_Table(array('class' => 'data_table'));
2101
+
2102
+        $table->setHeaderContents(0, 0, get_lang('User'));
2103
+        $table->setHeaderContents(0, 1, get_lang('Date'));
2104
+
2105
+        $row = 1;
2106
+        foreach ($users as $user) {
2107
+            $table->setCellContents(
2108
+                $row,
2109
+                0,
2110
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2111
+            );
2112
+            $row++;
2113
+        }
2114
+        $table->setColAttributes(0, array('style' => 'width:28%'));
2115
+
2116
+        $row = 1;
2117
+        foreach ($users as $user) {
2118
+            if (isset($results[$user['user_id']]) &&
2119
+                !empty($results[$user['user_id']])
2120
+            ) {
2121
+                $dates = implode(', ', array_keys($results[$user['user_id']]));
2122
+                $table->setCellContents($row, 1, $dates);
2123
+            }
2124
+            $row++;
2125
+        }
2126
+
2127
+        //$tableToString = null;
2128
+
2129
+        //$sessionInfo = api_get_session_info(api_get_session_id());
2130
+        //if (!empty($sessionInfo)) {
2131
+        /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
2132 2132
 			sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/
2133
-		//}
2134
-
2135
-		$tableToString = $table->toHtml();
2136
-
2137
-		$params = array(
2138
-			'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2139
-			'pdf_title' => get_lang('Attendance'),
2140
-			'course_code' => api_get_course_id(),
2141
-			'show_real_course_teachers' => true
2142
-		);
2143
-		$pdf = new PDF('A4', null, $params);
2144
-		$pdf->html_to_pdf_with_template($tableToString);
2145
-	}
2133
+        //}
2134
+
2135
+        $tableToString = $table->toHtml();
2136
+
2137
+        $params = array(
2138
+            'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2139
+            'pdf_title' => get_lang('Attendance'),
2140
+            'course_code' => api_get_course_id(),
2141
+            'show_real_course_teachers' => true
2142
+        );
2143
+        $pdf = new PDF('A4', null, $params);
2144
+        $pdf->html_to_pdf_with_template($tableToString);
2145
+    }
2146 2146
 }
Please login to merge, or discard this patch.
main/inc/lib/formvalidator/Element/SelectLanguage.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@
 block discarded – undo
6 6
 */
7 7
 class SelectLanguage extends HTML_QuickForm_select
8 8
 {
9
-	/**
10
-	 * Class constructor
11
-	 */
9
+    /**
10
+     * Class constructor
11
+     */
12 12
     public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
13
-	{
14
-		parent::__construct($elementName, $elementLabel, $options, $attributes);
15
-		// Get all languages
16
-		$languages = api_get_languages();
17
-		$this->_options = array();
18
-		$this->_values = array();
19
-		foreach ($languages['name'] as $index => $name) {
20
-			if($languages['folder'][$index] == api_get_setting('platformLanguage')) {
21
-				$this->addOption($name,$languages['folder'][$index],array('selected'=>'selected'));
22
-			} else {
23
-				$this->addOption($name,$languages['folder'][$index]);
24
-			}
25
-		}
26
-	}
13
+    {
14
+        parent::__construct($elementName, $elementLabel, $options, $attributes);
15
+        // Get all languages
16
+        $languages = api_get_languages();
17
+        $this->_options = array();
18
+        $this->_values = array();
19
+        foreach ($languages['name'] as $index => $name) {
20
+            if($languages['folder'][$index] == api_get_setting('platformLanguage')) {
21
+                $this->addOption($name,$languages['folder'][$index],array('selected'=>'selected'));
22
+            } else {
23
+                $this->addOption($name,$languages['folder'][$index]);
24
+            }
25
+        }
26
+    }
27 27
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
 		$this->_options = array();
18 18
 		$this->_values = array();
19 19
 		foreach ($languages['name'] as $index => $name) {
20
-			if($languages['folder'][$index] == api_get_setting('platformLanguage')) {
21
-				$this->addOption($name,$languages['folder'][$index],array('selected'=>'selected'));
20
+			if ($languages['folder'][$index] == api_get_setting('platformLanguage')) {
21
+				$this->addOption($name, $languages['folder'][$index], array('selected'=>'selected'));
22 22
 			} else {
23
-				$this->addOption($name,$languages['folder'][$index]);
23
+				$this->addOption($name, $languages['folder'][$index]);
24 24
 			}
25 25
 		}
26 26
 	}
Please login to merge, or discard this patch.
main/inc/lib/blog.lib.php 2 patches
Indentation   +1831 added lines, -1832 removed lines patch added patch discarded remove patch
@@ -6,114 +6,113 @@  discard block
 block discarded – undo
6 6
  *
7 7
  * Contains several functions dealing with displaying,
8 8
  * editing,... of a blog
9
-
10 9
  * @package chamilo.blogs
11 10
  * @author Toon Keppens <[email protected]>
12 11
  * @author Julio Montoya - Cleaning code
13 12
  */
14 13
 class Blog
15 14
 {
16
-	/**
17
-	 * Get the title of a blog
18
-	 * @author Toon Keppens
19
-	 *
20
-	 * @param int $blog_id
21
-	 *
22
-	 * @return String Blog Title
23
-	 */
24
-	public static function get_blog_title ($blog_id)
25
-	{
26
-	    $course_id = api_get_course_int_id();
27
-
28
-		if (is_numeric($blog_id)) {
29
-			$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
30
-
31
-			$sql = "SELECT blog_name
15
+    /**
16
+     * Get the title of a blog
17
+     * @author Toon Keppens
18
+     *
19
+     * @param int $blog_id
20
+     *
21
+     * @return String Blog Title
22
+     */
23
+    public static function get_blog_title ($blog_id)
24
+    {
25
+        $course_id = api_get_course_int_id();
26
+
27
+        if (is_numeric($blog_id)) {
28
+            $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
29
+
30
+            $sql = "SELECT blog_name
32 31
 					FROM " . $tbl_blogs . "
33 32
 					WHERE c_id = $course_id AND blog_id = " . intval($blog_id);
34 33
 
35
-			$result = Database::query($sql);
36
-			$blog = Database::fetch_array($result);
37
-
38
-			return stripslashes($blog['blog_name']);
39
-		}
40
-	}
41
-
42
-
43
-	/**
44
-	 * Get the description of a blog
45
-	 * @author Toon Keppens
46
-	 *
47
-	 * @param Integer $blog_id
48
-	 *
49
-	 * @return String Blog description
50
-	 */
51
-	public static function get_blog_subtitle($blog_id)
52
-	{
53
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
54
-	  	$course_id = api_get_course_int_id();
55
-		$sql = "SELECT blog_subtitle FROM $tbl_blogs
34
+            $result = Database::query($sql);
35
+            $blog = Database::fetch_array($result);
36
+
37
+            return stripslashes($blog['blog_name']);
38
+        }
39
+    }
40
+
41
+
42
+    /**
43
+     * Get the description of a blog
44
+     * @author Toon Keppens
45
+     *
46
+     * @param Integer $blog_id
47
+     *
48
+     * @return String Blog description
49
+     */
50
+    public static function get_blog_subtitle($blog_id)
51
+    {
52
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
53
+            $course_id = api_get_course_int_id();
54
+        $sql = "SELECT blog_subtitle FROM $tbl_blogs
56 55
 				WHERE c_id = $course_id AND blog_id ='".intval($blog_id)."'";
57
-		$result = Database::query($sql);
58
-		$blog = Database::fetch_array($result);
59
-
60
-		return stripslashes($blog['blog_subtitle']);
61
-	}
62
-
63
-	/**
64
-	 * Get the users of a blog
65
-	 * @author Toon Keppens
66
-	 *
67
-	 * @param Integer $blog_id
68
-	 *
69
-	 * @return Array Returns an array with [userid]=>[username]
70
-	 */
71
-	public static function get_blog_users($blog_id)
72
-	{
73
-		// Database table definitions
74
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
75
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
76
-
77
-		$course_id = api_get_course_int_id();
78
-
79
-		// Get blog members
80
-		$sql = "SELECT user.user_id, user.firstname, user.lastname
56
+        $result = Database::query($sql);
57
+        $blog = Database::fetch_array($result);
58
+
59
+        return stripslashes($blog['blog_subtitle']);
60
+    }
61
+
62
+    /**
63
+     * Get the users of a blog
64
+     * @author Toon Keppens
65
+     *
66
+     * @param Integer $blog_id
67
+     *
68
+     * @return Array Returns an array with [userid]=>[username]
69
+     */
70
+    public static function get_blog_users($blog_id)
71
+    {
72
+        // Database table definitions
73
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
74
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
75
+
76
+        $course_id = api_get_course_int_id();
77
+
78
+        // Get blog members
79
+        $sql = "SELECT user.user_id, user.firstname, user.lastname
81 80
 				FROM " . $tbl_blogs_rel_user . " blogs_rel_user
82 81
 				INNER JOIN " . $tbl_users . " user
83 82
 				ON blogs_rel_user.user_id = user.user_id
84 83
 				WHERE
85 84
 				    blogs_rel_user.c_id = $course_id AND
86 85
 					blogs_rel_user.blog_id = '" . (int)$blog_id."'";
87
-		$result = Database::query($sql);
88
-		$blog_members = array ();
89
-		while($user = Database::fetch_array($result)) {
90
-			$blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
91
-		}
92
-
93
-		return $blog_members;
94
-	}
95
-
96
-	/**
97
-	 * Creates a new blog in the given course
98
-	 * @author Toon Keppens
99
-	 * @param int $course_id Id
100
-	 * @param string $title
101
-	 * @param Text $description
102
-	 */
103
-	public static function create_blog($title, $subtitle)
104
-	{
105
-		$_user = api_get_user_info();
86
+        $result = Database::query($sql);
87
+        $blog_members = array ();
88
+        while($user = Database::fetch_array($result)) {
89
+            $blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
90
+        }
91
+
92
+        return $blog_members;
93
+    }
94
+
95
+    /**
96
+     * Creates a new blog in the given course
97
+     * @author Toon Keppens
98
+     * @param int $course_id Id
99
+     * @param string $title
100
+     * @param Text $description
101
+     */
102
+    public static function create_blog($title, $subtitle)
103
+    {
104
+        $_user = api_get_user_info();
106 105
         $course_id = api_get_course_int_id();
107 106
 
108
-		$current_date=date('Y-m-d H:i:s',time());
109
-		$session_id = api_get_session_id();
110
-		// Tabel definitions
107
+        $current_date=date('Y-m-d H:i:s',time());
108
+        $session_id = api_get_session_id();
109
+        // Tabel definitions
111 110
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
112 111
         $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
113 112
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
114 113
 
115
-		//verified if exist blog
116
-		$sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
114
+        //verified if exist blog
115
+        $sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.'
117 116
 			  	WHERE
118 117
 			  	    c_id = '.$course_id.' AND
119 118
 			  	    blog_name="'.Database::escape_string($title).'" AND
@@ -122,9 +121,9 @@  discard block
 block discarded – undo
122 121
         $info_count = Database::result($res, 0, 0);
123 122
 
124 123
         if ($info_count == 0) {
125
-			// Create the blog
124
+            // Create the blog
126 125
             $params = [
127
-				'blog_id' => 0,
126
+                'blog_id' => 0,
128 127
                 'c_id' => $course_id,
129 128
                 'blog_name' => $title,
130 129
                 'blog_subtitle' =>  $subtitle,
@@ -132,14 +131,14 @@  discard block
 block discarded – undo
132 131
                 'visibility' => 1 ,
133 132
                 'session_id' => $session_id,
134 133
             ];
135
-			$this_blog_id = Database::insert($tbl_blogs, $params);
134
+            $this_blog_id = Database::insert($tbl_blogs, $params);
136 135
 
137
-			if ($this_blog_id > 0) {
136
+            if ($this_blog_id > 0) {
138 137
 
139 138
                 $sql = "UPDATE $tbl_blogs SET blog_id = iid WHERE iid = $this_blog_id";
140 139
                 Database::query($sql);
141 140
 
142
-				// insert into item_property
141
+                // insert into item_property
143 142
                 api_item_property_update(
144 143
                     api_get_course_info(),
145 144
                     TOOL_BLOGS,
@@ -147,12 +146,12 @@  discard block
 block discarded – undo
147 146
                     'BlogAdded',
148 147
                     api_get_user_id()
149 148
                 );
150
-			}
149
+            }
151 150
 
152
-			// Make first post. :)
151
+            // Make first post. :)
153 152
 
154 153
             $params = [
155
-				'post_id' => 0,
154
+                'post_id' => 0,
156 155
                 'c_id' => $course_id,
157 156
                 'title' => get_lang("Welcome"),
158 157
                 'full_text' => get_lang('FirstPostText'),
@@ -166,10 +165,10 @@  discard block
 block discarded – undo
166 165
                 Database::query($sql);
167 166
             }
168 167
 
169
-			// Put it on course homepage
170
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
168
+            // Put it on course homepage
169
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
171 170
 					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')";
172
-			Database::query($sql);
171
+            Database::query($sql);
173 172
 
174 173
             $toolId = Database::insert_id();
175 174
             if ($toolId) {
@@ -177,37 +176,37 @@  discard block
 block discarded – undo
177 176
                 Database::query($sql);
178 177
             }
179 178
 
180
-			// Subscribe the teacher to this blog
181
-			Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * Update title and subtitle of a blog in the given course
187
-	 * @author Toon Keppens
188
-	 * @param int $course_id Id
189
-	 * @param string $title
190
-	 * @param string $description
191
-	 */
192
-	public static function edit_blog($blog_id, $title, $subtitle)
193
-	{
194
-		// Table definitions
195
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
196
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
179
+            // Subscribe the teacher to this blog
180
+            Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
181
+        }
182
+    }
183
+
184
+    /**
185
+     * Update title and subtitle of a blog in the given course
186
+     * @author Toon Keppens
187
+     * @param int $course_id Id
188
+     * @param string $title
189
+     * @param string $description
190
+     */
191
+    public static function edit_blog($blog_id, $title, $subtitle)
192
+    {
193
+        // Table definitions
194
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
195
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
197 196
 
198 197
         $course_id = api_get_course_int_id();
199 198
 
200
-		// Update the blog
201
-		$sql = "UPDATE $tbl_blogs SET
199
+        // Update the blog
200
+        $sql = "UPDATE $tbl_blogs SET
202 201
 		        blog_name = '".Database::escape_string($title)."',
203 202
 		        blog_subtitle = '".Database::escape_string($subtitle)."'
204 203
 		        WHERE
205 204
 		            c_id = $course_id AND
206 205
 		            blog_id ='".Database::escape_string((int)$blog_id)."'
207 206
                 LIMIT 1";
208
-		Database::query($sql);
207
+        Database::query($sql);
209 208
 
210
-		//update item_property (update)
209
+        //update item_property (update)
211 210
         api_item_property_update(
212 211
             api_get_course_info(),
213 212
             TOOL_BLOGS,
@@ -216,21 +215,21 @@  discard block
 block discarded – undo
216 215
             api_get_user_id()
217 216
         );
218 217
 
219
-		// Update course homepage link
220
-		$sql = "UPDATE $tbl_tool SET
218
+        // Update course homepage link
219
+        $sql = "UPDATE $tbl_tool SET
221 220
 		        name = '".Database::escape_string($title)."'
222 221
 		        WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1";
223
-		Database::query($sql);
224
-	}
225
-
226
-	/**
227
-	 * Deletes a blog and it's posts from the course database
228
-	 * @author Toon Keppens
229
-	 * @param Integer $blog_id
230
-	 */
231
-	public static function delete_blog($blog_id)
232
-	{
233
-		// Init
222
+        Database::query($sql);
223
+    }
224
+
225
+    /**
226
+     * Deletes a blog and it's posts from the course database
227
+     * @author Toon Keppens
228
+     * @param Integer $blog_id
229
+     */
230
+    public static function delete_blog($blog_id)
231
+    {
232
+        // Init
234 233
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
235 234
         $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
236 235
         $tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS);
@@ -241,34 +240,34 @@  discard block
 block discarded – undo
241 240
         $course_id = api_get_course_int_id();
242 241
         $blog_id = intval($blog_id);
243 242
 
244
-		// Delete posts from DB and the attachments
245
-		delete_all_blog_attachment($blog_id);
243
+        // Delete posts from DB and the attachments
244
+        delete_all_blog_attachment($blog_id);
246 245
 
247
-		//Delete comments
248
-		$sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
249
-   		Database::query($sql);
246
+        //Delete comments
247
+        $sql = "DELETE FROM $tbl_blogs_comment WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
248
+            Database::query($sql);
250 249
 
251
-		// Delete posts
252
-   		$sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
253
-   		Database::query($sql);
250
+        // Delete posts
251
+            $sql = "DELETE FROM $tbl_blogs_posts WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
252
+            Database::query($sql);
254 253
 
255
-		// Delete tasks
256
-		$sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
257
-		Database::query($sql);
254
+        // Delete tasks
255
+        $sql = "DELETE FROM $tbl_blogs_tasks WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
256
+        Database::query($sql);
258 257
 
259
-		// Delete ratings
260
-		$sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
261
-		Database::query($sql);
258
+        // Delete ratings
259
+        $sql = "DELETE FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
260
+        Database::query($sql);
262 261
 
263
-		// Delete blog
264
-		$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
265
-		Database::query($sql);
262
+        // Delete blog
263
+        $sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
264
+        Database::query($sql);
266 265
 
267
-		// Delete from course homepage
268
-		$sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
269
-		Database::query($sql);
266
+        // Delete from course homepage
267
+        $sql = "DELETE FROM $tbl_tool WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".$blog_id."'";
268
+        Database::query($sql);
270 269
 
271
-		//update item_property (delete)
270
+        //update item_property (delete)
272 271
         api_item_property_update(
273 272
             api_get_course_info(),
274 273
             TOOL_BLOGS,
@@ -276,152 +275,152 @@  discard block
 block discarded – undo
276 275
             'delete',
277 276
             api_get_user_id()
278 277
         );
279
-	}
280
-
281
-	/**
282
-	 * Creates a new post in a given blog
283
-	 * @author Toon Keppens
284
-	 * @param String $title
285
-	 * @param String $full_text
286
-	 * @param Integer $blog_id
287
-	 */
288
-	public static function create_post($title, $full_text, $file_comment, $blog_id)
289
-	{
290
-		$_user = api_get_user_info();
291
-		$_course = api_get_course_info();
292
-		$course_id = $_course['real_id'];
293
-
294
-		$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
295
-		$upload_ok=true;
296
-		$has_attachment=false;
297
-		$current_date = api_get_utc_datetime();
298
-
299
-		if (!empty($_FILES['user_upload']['name'])) {
300
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
301
-			$has_attachment=true;
302
-		}
303
-
304
-		if ($upload_ok) {
305
-			// Table Definitions
306
-			$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
307
-
308
-			// Create the post
309
-			$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
278
+    }
279
+
280
+    /**
281
+     * Creates a new post in a given blog
282
+     * @author Toon Keppens
283
+     * @param String $title
284
+     * @param String $full_text
285
+     * @param Integer $blog_id
286
+     */
287
+    public static function create_post($title, $full_text, $file_comment, $blog_id)
288
+    {
289
+        $_user = api_get_user_info();
290
+        $_course = api_get_course_info();
291
+        $course_id = $_course['real_id'];
292
+
293
+        $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
294
+        $upload_ok=true;
295
+        $has_attachment=false;
296
+        $current_date = api_get_utc_datetime();
297
+
298
+        if (!empty($_FILES['user_upload']['name'])) {
299
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
300
+            $has_attachment=true;
301
+        }
302
+
303
+        if ($upload_ok) {
304
+            // Table Definitions
305
+            $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
306
+
307
+            // Create the post
308
+            $sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
310 309
 					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');";
311 310
 
312
-			Database::query($sql);
313
-			$last_post_id = Database::insert_id();
311
+            Database::query($sql);
312
+            $last_post_id = Database::insert_id();
314 313
 
315 314
             if ($last_post_id) {
316 315
                 $sql = "UPDATE $tbl_blogs_posts SET post_id = iid WHERE iid = $last_post_id";
317 316
                 Database::query($sql);
318 317
             }
319 318
 
320
-			if ($has_attachment) {
321
-				$courseDir   = $_course['path'].'/upload/blog';
322
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
323
-				$updir = $sys_course_path.$courseDir;
324
-
325
-				// Try to add an extension to the file if it hasn't one
326
-				$new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
327
-
328
-				// user's file name
329
-				$file_name = $_FILES['user_upload']['name'];
330
-
331
-				if (!filter_extension($new_file_name)) {
332
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
333
-				} else {
334
-					$new_file_name = uniqid('');
335
-					$new_path = $updir.'/'.$new_file_name;
336
-					$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
337
-					$comment = Database::escape_string($file_comment);
338
-
339
-					// Storing the attachments if any
340
-					if ($result) {
341
-						$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
342
-							   "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."',  '".$blog_id."', '0' )";
343
-						Database::query($sql);
319
+            if ($has_attachment) {
320
+                $courseDir   = $_course['path'].'/upload/blog';
321
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
322
+                $updir = $sys_course_path.$courseDir;
323
+
324
+                // Try to add an extension to the file if it hasn't one
325
+                $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
326
+
327
+                // user's file name
328
+                $file_name = $_FILES['user_upload']['name'];
329
+
330
+                if (!filter_extension($new_file_name)) {
331
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
332
+                } else {
333
+                    $new_file_name = uniqid('');
334
+                    $new_path = $updir.'/'.$new_file_name;
335
+                    $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
336
+                    $comment = Database::escape_string($file_comment);
337
+
338
+                    // Storing the attachments if any
339
+                    if ($result) {
340
+                        $sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
341
+                                "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval($_FILES['user_upload']['size'])."',  '".$blog_id."', '0' )";
342
+                        Database::query($sql);
344 343
                         $id = Database::insert_id();
345 344
                         if ($id) {
346 345
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
347 346
                             Database::query($sql);
348 347
                         }
349
-					}
350
-				}
351
-			}
352
-		} else {
353
-			Display::display_error_message(get_lang('UplNoFileUploaded'));
354
-		}
355
-	}
356
-
357
-	/**
358
-	 * Edits a post in a given blog
359
-	 * @author Toon Keppens
360
-	 * @param Integer $blog_id
361
-	 * @param String $title
362
-	 * @param String $full_text
363
-	 * @param Integer $blog_id
364
-	 */
365
-	public static function edit_post($post_id, $title, $full_text, $blog_id)
366
-	{
367
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
348
+                    }
349
+                }
350
+            }
351
+        } else {
352
+            Display::display_error_message(get_lang('UplNoFileUploaded'));
353
+        }
354
+    }
355
+
356
+    /**
357
+     * Edits a post in a given blog
358
+     * @author Toon Keppens
359
+     * @param Integer $blog_id
360
+     * @param String $title
361
+     * @param String $full_text
362
+     * @param Integer $blog_id
363
+     */
364
+    public static function edit_post($post_id, $title, $full_text, $blog_id)
365
+    {
366
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
368 367
         $course_id = api_get_course_int_id();
369 368
 
370
-		// Create the post
371
-		$sql = "UPDATE $tbl_blogs_posts SET
369
+        // Create the post
370
+        $sql = "UPDATE $tbl_blogs_posts SET
372 371
 		        title = '" . Database::escape_string($title)."',
373 372
 		        full_text = '" . Database::escape_string($full_text)."'
374 373
 		        WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."'
375 374
 		        LIMIT 1 ";
376
-		Database::query($sql);
377
-	}
378
-
379
-	/**
380
-	 * Deletes an article and it's comments
381
-	 * @author Toon Keppens
382
-	 * @param int $blog_id
383
-	 * @param int $post_id
384
-	 */
385
-	public static function delete_post($blog_id, $post_id)
386
-	{
387
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
388
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
389
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
375
+        Database::query($sql);
376
+    }
377
+
378
+    /**
379
+     * Deletes an article and it's comments
380
+     * @author Toon Keppens
381
+     * @param int $blog_id
382
+     * @param int $post_id
383
+     */
384
+    public static function delete_post($blog_id, $post_id)
385
+    {
386
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
387
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
388
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
390 389
 
391 390
         $course_id = api_get_course_int_id();
392 391
 
393
-		// Delete ratings on this comment
394
-		$sql = "DELETE FROM $tbl_blogs_rating
392
+        // Delete ratings on this comment
393
+        $sql = "DELETE FROM $tbl_blogs_rating
395 394
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'";
396
-		Database::query($sql);
395
+        Database::query($sql);
397 396
 
398
-		// Delete the post
399
-		$sql = "DELETE FROM $tbl_blogs_posts
397
+        // Delete the post
398
+        $sql = "DELETE FROM $tbl_blogs_posts
400 399
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."'";
401
-		Database::query($sql);
400
+        Database::query($sql);
402 401
 
403
-		// Delete the comments
404
-		$sql = "DELETE FROM $tbl_blogs_comments
402
+        // Delete the comments
403
+        $sql = "DELETE FROM $tbl_blogs_comments
405 404
 				WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'";
406
-		Database::query($sql);
407
-
408
-		// Delete posts and attachments
409
-		delete_all_blog_attachment($blog_id,$post_id);
410
-	}
411
-
412
-	/**
413
-	 * Creates a comment on a post in a given blog
414
-	 * @author Toon Keppens
415
-	 * @param String $title
416
-	 * @param String $full_text
417
-	 * @param Integer $blog_id
418
-	 * @param Integer $post_id
419
-	 * @param Integer $parent_id
420
-	 */
421
-	public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
422
-	{
423
-		$_user = api_get_user_info();
424
-		$_course = api_get_course_info();
405
+        Database::query($sql);
406
+
407
+        // Delete posts and attachments
408
+        delete_all_blog_attachment($blog_id,$post_id);
409
+    }
410
+
411
+    /**
412
+     * Creates a comment on a post in a given blog
413
+     * @author Toon Keppens
414
+     * @param String $title
415
+     * @param String $full_text
416
+     * @param Integer $blog_id
417
+     * @param Integer $post_id
418
+     * @param Integer $parent_id
419
+     */
420
+    public static function create_comment($title, $full_text, $file_comment, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
421
+    {
422
+        $_user = api_get_user_info();
423
+        $_course = api_get_course_info();
425 424
         $blog_table_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
426 425
 
427 426
         $upload_ok = true;
@@ -429,55 +428,55 @@  discard block
 block discarded – undo
429 428
         $current_date = api_get_utc_datetime();
430 429
         $course_id = api_get_course_int_id();
431 430
 
432
-		if (!empty($_FILES['user_upload']['name'])) {
433
-			$upload_ok = process_uploaded_file($_FILES['user_upload']);
434
-			$has_attachment=true;
435
-		}
431
+        if (!empty($_FILES['user_upload']['name'])) {
432
+            $upload_ok = process_uploaded_file($_FILES['user_upload']);
433
+            $has_attachment=true;
434
+        }
436 435
 
437
-		if ($upload_ok) {
438
-			// Table Definition
439
-			$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
436
+        if ($upload_ok) {
437
+            // Table Definition
438
+            $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
440 439
 
441
-			// Create the comment
442
-			$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
440
+            // Create the comment
441
+            $sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
443 442
 					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
444
-			Database::query($sql);
443
+            Database::query($sql);
445 444
 
446
-			// Empty post values, or they are shown on the page again
447
-			$last_id = Database::insert_id();
445
+            // Empty post values, or they are shown on the page again
446
+            $last_id = Database::insert_id();
448 447
 
449 448
             if ($last_id) {
450 449
                 $sql = "UPDATE $tbl_blogs_comments SET comment_id = iid WHERE iid = $last_id";
451 450
                 Database::query($sql);
452 451
             }
453 452
 
454
-			if ($has_attachment) {
455
-				$courseDir   = $_course['path'].'/upload/blog';
456
-				$sys_course_path = api_get_path(SYS_COURSE_PATH);
457
-				$updir = $sys_course_path.$courseDir;
458
-
459
-				// Try to add an extension to the file if it hasn't one
460
-				$new_file_name = add_ext_on_mime(
461
-					stripslashes($_FILES['user_upload']['name']),
462
-					$_FILES['user_upload']['type']
463
-				);
464
-
465
-				// user's file name
466
-				$file_name =$_FILES['user_upload']['name'];
467
-
468
-				if (!filter_extension($new_file_name)) {
469
-					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
470
-				} else {
471
-					$new_file_name = uniqid('');
472
-					$new_path=$updir.'/'.$new_file_name;
473
-					$result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
474
-					$comment = Database::escape_string($file_comment);
475
-
476
-					// Storing the attachments if any
477
-					if ($result) {
478
-						$sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
479
-							 "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."',  '".$blog_id."', '".$last_id."'  )";
480
-						Database::query($sql);
453
+            if ($has_attachment) {
454
+                $courseDir   = $_course['path'].'/upload/blog';
455
+                $sys_course_path = api_get_path(SYS_COURSE_PATH);
456
+                $updir = $sys_course_path.$courseDir;
457
+
458
+                // Try to add an extension to the file if it hasn't one
459
+                $new_file_name = add_ext_on_mime(
460
+                    stripslashes($_FILES['user_upload']['name']),
461
+                    $_FILES['user_upload']['type']
462
+                );
463
+
464
+                // user's file name
465
+                $file_name =$_FILES['user_upload']['name'];
466
+
467
+                if (!filter_extension($new_file_name)) {
468
+                    Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
469
+                } else {
470
+                    $new_file_name = uniqid('');
471
+                    $new_path=$updir.'/'.$new_file_name;
472
+                    $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
473
+                    $comment = Database::escape_string($file_comment);
474
+
475
+                    // Storing the attachments if any
476
+                    if ($result) {
477
+                        $sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
478
+                                "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."',  '".$blog_id."', '".$last_id."'  )";
479
+                        Database::query($sql);
481 480
 
482 481
                         $id = Database::insert_id();
483 482
 
@@ -485,91 +484,91 @@  discard block
 block discarded – undo
485 484
                             $sql = "UPDATE $blog_table_attachment SET id = iid WHERE iid = $id";
486 485
                             Database::query($sql);
487 486
                         }
488
-					}
489
-				}
490
-			}
491
-		}
492
-	}
493
-
494
-	/**
495
-	 * Deletes a comment from a blogpost
496
-	 * @author Toon Keppens
497
-	 * @param int $blog_id
498
-	 * @param int $comment_id
499
-	 */
500
-	public static function delete_comment($blog_id, $post_id, $comment_id)
501
-	{
502
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
503
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
504
-		$blog_id = intval($blog_id);
505
-		$post_id = intval($post_id);
506
-		$comment_id = intval($comment_id);
487
+                    }
488
+                }
489
+            }
490
+        }
491
+    }
492
+
493
+    /**
494
+     * Deletes a comment from a blogpost
495
+     * @author Toon Keppens
496
+     * @param int $blog_id
497
+     * @param int $comment_id
498
+     */
499
+    public static function delete_comment($blog_id, $post_id, $comment_id)
500
+    {
501
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
502
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
503
+        $blog_id = intval($blog_id);
504
+        $post_id = intval($post_id);
505
+        $comment_id = intval($comment_id);
507 506
         $course_id = api_get_course_int_id();
508 507
 
509
-		delete_all_blog_attachment($blog_id, $post_id, $comment_id);
508
+        delete_all_blog_attachment($blog_id, $post_id, $comment_id);
510 509
 
511
-		// Delete ratings on this comment
512
-		$sql = "DELETE FROM $tbl_blogs_rating
510
+        // Delete ratings on this comment
511
+        $sql = "DELETE FROM $tbl_blogs_rating
513 512
 				WHERE
514 513
 				    c_id = $course_id AND
515 514
 				    blog_id = '".$blog_id."' AND
516 515
 				    item_id = '".$comment_id."' AND
517 516
 				    rating_type = 'comment'";
518
-		Database::query($sql);
517
+        Database::query($sql);
519 518
 
520
-		// select comments that have the selected comment as their parent
521
-		$sql = "SELECT comment_id FROM $tbl_blogs_comments
519
+        // select comments that have the selected comment as their parent
520
+        $sql = "SELECT comment_id FROM $tbl_blogs_comments
522 521
 				WHERE c_id = $course_id AND parent_comment_id = '".$comment_id."'";
523
-		$result = Database::query($sql);
522
+        $result = Database::query($sql);
524 523
 
525
-		// Delete them recursively
526
-		while ($comment = Database::fetch_array($result)) {
527
-			Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
528
-		}
524
+        // Delete them recursively
525
+        while ($comment = Database::fetch_array($result)) {
526
+            Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
527
+        }
529 528
 
530
-		// Finally, delete the selected comment to
531
-		$sql = "DELETE FROM $tbl_blogs_comments
529
+        // Finally, delete the selected comment to
530
+        $sql = "DELETE FROM $tbl_blogs_comments
532 531
 				WHERE c_id = $course_id AND comment_id = '".$comment_id."'";
533
-		Database::query($sql);
534
-	}
535
-
536
-	/**
537
-	 * Creates a new task in a blog
538
-	 * @author Toon Keppens
539
-	 * @param Integer $blog_id
540
-	 * @param String $title
541
-	 * @param String $description
542
-	 * @param String $color
543
-	 */
544
-	public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
545
-	{
546
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
547
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
548
-
549
-		$course_id = api_get_course_int_id();
550
-
551
-		// Create the task
552
-		$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
532
+        Database::query($sql);
533
+    }
534
+
535
+    /**
536
+     * Creates a new task in a blog
537
+     * @author Toon Keppens
538
+     * @param Integer $blog_id
539
+     * @param String $title
540
+     * @param String $description
541
+     * @param String $color
542
+     */
543
+    public static function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
544
+    {
545
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
546
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
547
+
548
+        $course_id = api_get_course_int_id();
549
+
550
+        // Create the task
551
+        $sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
553 552
 				VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');";
554
-		Database::query($sql);
553
+        Database::query($sql);
555 554
 
556
-		$task_id = Database::insert_id();
555
+        $task_id = Database::insert_id();
557 556
 
558 557
         if ($task_id) {
559 558
             $sql = "UPDATE $tbl_blogs_tasks SET task_id = iid WHERE iid = $task_id";
560 559
             Database::query($sql);
561 560
         }
562 561
 
563
-		$tool = 'BLOG_' . $blog_id;
562
+        $tool = 'BLOG_' . $blog_id;
564 563
 
565
-		if ($articleDelete == 'on') {
566
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
564
+        if ($articleDelete == 'on') {
565
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
567 566
 					'" . (int)$course_id . "',
568 567
 					'" . (int)$task_id . "',
569 568
 					'" . Database::escape_string($tool) . "',
570 569
 					'article_delete'
571 570
 				)";
572
-			Database::query($sql);
571
+            Database::query($sql);
573 572
 
574 573
             $id = Database::insert_id();
575 574
 
@@ -579,172 +578,172 @@  discard block
 block discarded – undo
579 578
             }
580 579
         }
581 580
 
582
-		if ($articleEdit == 'on') {
583
-			$sql = "
581
+        if ($articleEdit == 'on') {
582
+            $sql = "
584 583
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
585 584
 					'" . (int)$course_id . "',
586 585
 					'" . (int)$task_id . "',
587 586
 					'" . Database::escape_string($tool) . "',
588 587
 					'article_edit'
589 588
 				)";
590
-			Database::query($sql);
589
+            Database::query($sql);
591 590
             $id = Database::insert_id();
592 591
 
593 592
             if ($id) {
594 593
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
595 594
                 Database::query($sql);
596 595
             }
597
-		}
596
+        }
598 597
 
599
-		if ($commentsDelete == 'on') {
600
-			$sql = "
598
+        if ($commentsDelete == 'on') {
599
+            $sql = "
601 600
 				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
602 601
 					'" . (int)$course_id . "',
603 602
 					'" . (int)$task_id . "',
604 603
 					'" . Database::escape_string($tool) . "',
605 604
 					'article_comments_delete'
606 605
 				)";
607
-			Database::query($sql);
606
+            Database::query($sql);
608 607
             $id = Database::insert_id();
609 608
 
610 609
             if ($id) {
611 610
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
612 611
                 Database::query($sql);
613 612
             }
614
-		}
615
-	}
616
-
617
-	/**
618
-	 * Edit a task in a blog
619
-	 * @author Toon Keppens
620
-	 * @param Integer $task_id
621
-	 * @param String $title
622
-	 * @param String $description
623
-	 * @param String $color
624
-	 */
625
-	public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
626
-	{
627
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
628
-		$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
613
+        }
614
+    }
615
+
616
+    /**
617
+     * Edit a task in a blog
618
+     * @author Toon Keppens
619
+     * @param Integer $task_id
620
+     * @param String $title
621
+     * @param String $description
622
+     * @param String $color
623
+     */
624
+    public static function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
625
+    {
626
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
627
+        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
629 628
 
630 629
         $course_id = api_get_course_int_id();
631 630
 
632
-		// Create the task
633
-		$sql = "UPDATE $tbl_blogs_tasks SET
631
+        // Create the task
632
+        $sql = "UPDATE $tbl_blogs_tasks SET
634 633
 					title = '".Database::escape_string($title)."',
635 634
 					description = '".Database::escape_string($description)."',
636 635
 					color = '".Database::escape_string($color)."'
637 636
 				WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1";
638
-		Database::query($sql);
637
+        Database::query($sql);
639 638
 
640
-		$tool = 'BLOG_' . $blog_id;
639
+        $tool = 'BLOG_' . $blog_id;
641 640
 
642
-		$sql = "DELETE FROM " . $tbl_tasks_permissions . "
641
+        $sql = "DELETE FROM " . $tbl_tasks_permissions . "
643 642
 				WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
644
-		Database::query($sql);
643
+        Database::query($sql);
645 644
 
646
-		if ($articleDelete == 'on') {
647
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
645
+        if ($articleDelete == 'on') {
646
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
648 647
 					'" . (int)$course_id . "',
649 648
 					'" . (int)$task_id . "',
650 649
 					'" . Database::escape_string($tool) . "',
651 650
 					'article_delete'
652 651
 				)";
653
-			Database::query($sql);
652
+            Database::query($sql);
654 653
             $id = Database::insert_id();
655 654
 
656 655
             if ($id) {
657 656
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
658 657
                 Database::query($sql);
659 658
             }
660
-		}
659
+        }
661 660
 
662
-		if ($articleEdit == 'on') {
663
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
661
+        if ($articleEdit == 'on') {
662
+            $sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
664 663
 					'" . (int)$course_id . "',
665 664
 					'" . (int)$task_id . "',
666 665
 					'" . Database::escape_string($tool) . "',
667 666
 					'article_edit'
668 667
 				)";
669
-			Database::query($sql);
668
+            Database::query($sql);
670 669
             $id = Database::insert_id();
671 670
 
672 671
             if ($id) {
673 672
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
674 673
                 Database::query($sql);
675 674
             }
676
-		}
675
+        }
677 676
 
678
-		if ($commentsDelete == 'on') {
679
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
677
+        if ($commentsDelete == 'on') {
678
+            $sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
680 679
 					'" . (int)$course_id . "',
681 680
 					'" . (int)$task_id . "',
682 681
 					'" . Database::escape_string($tool) . "',
683 682
 					'article_comments_delete'
684 683
 				)";
685
-			Database::query($sql);
684
+            Database::query($sql);
686 685
             $id = Database::insert_id();
687 686
 
688 687
             if ($id) {
689 688
                 $sql = "UPDATE $tbl_tasks_permissions SET id = iid WHERE iid = $id";
690 689
                 Database::query($sql);
691 690
             }
692
-		}
693
-	}
694
-
695
-	/**
696
-	 * Deletes a task from a blog
697
-	 * @param Integer $blog_id
698
-	 * @param Integer $task_id
699
-	 */
700
-	public static function delete_task($blog_id, $task_id)
701
-	{
702
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
703
-		$course_id = api_get_course_int_id();
704
-
705
-		// Delete posts
706
-		$sql = "DELETE FROM $tbl_blogs_tasks
691
+        }
692
+    }
693
+
694
+    /**
695
+     * Deletes a task from a blog
696
+     * @param Integer $blog_id
697
+     * @param Integer $task_id
698
+     */
699
+    public static function delete_task($blog_id, $task_id)
700
+    {
701
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
702
+        $course_id = api_get_course_int_id();
703
+
704
+        // Delete posts
705
+        $sql = "DELETE FROM $tbl_blogs_tasks
707 706
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'";
708
-		Database::query($sql);
709
-	}
710
-
711
-	/**
712
-	 * Deletes an assigned task from a blog
713
-	 * @param Integer $blog_id
714
-	 * @param Integer $assignment_id
715
-	 */
716
-	public static function delete_assigned_task($blog_id, $task_id, $user_id)
717
-	{
718
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
707
+        Database::query($sql);
708
+    }
709
+
710
+    /**
711
+     * Deletes an assigned task from a blog
712
+     * @param Integer $blog_id
713
+     * @param Integer $assignment_id
714
+     */
715
+    public static function delete_assigned_task($blog_id, $task_id, $user_id)
716
+    {
717
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
719 718
         $course_id = api_get_course_int_id();
720 719
 
721
-		// Delete posts
722
-		$sql = "DELETE FROM $tbl_blogs_tasks_rel_user
720
+        // Delete posts
721
+        $sql = "DELETE FROM $tbl_blogs_tasks_rel_user
723 722
 				WHERE
724 723
 				    c_id = $course_id AND
725 724
 				    blog_id = '".(int)$blog_id."' AND
726 725
 				    task_id = '".(int)$task_id."' AND
727 726
 				    user_id = '".(int)$user_id."'";
728
-		Database::query($sql);
729
-	}
730
-
731
-	/**
732
-	 * Get personal task list
733
-	 * @author Toon Keppens
734
-	 * @return Returns an unsorted list (<ul></ul>) with the users' tasks
735
-	 */
736
-	public static function get_personal_task_list()
737
-	{
738
-		$_user = api_get_user_info();
739
-
740
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
741
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
742
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
743
-
744
-		$course_id = api_get_course_int_id();
745
-
746
-		if ($_user['user_id']) {
747
-			$sql = "SELECT task_rel_user.*, task.title, blog.blog_name
727
+        Database::query($sql);
728
+    }
729
+
730
+    /**
731
+     * Get personal task list
732
+     * @author Toon Keppens
733
+     * @return Returns an unsorted list (<ul></ul>) with the users' tasks
734
+     */
735
+    public static function get_personal_task_list()
736
+    {
737
+        $_user = api_get_user_info();
738
+
739
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
740
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
741
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
742
+
743
+        $course_id = api_get_course_int_id();
744
+
745
+        if ($_user['user_id']) {
746
+            $sql = "SELECT task_rel_user.*, task.title, blog.blog_name
748 747
                     FROM $tbl_blogs_tasks_rel_user task_rel_user
749 748
                     INNER JOIN $tbl_blogs_tasks task
750 749
                     ON task_rel_user.task_id = task.task_id
@@ -758,85 +757,85 @@  discard block
 block discarded – undo
758 757
                         task_rel_user.user_id = ".(int)$_user['user_id']."
759 758
                     ORDER BY target_date ASC";
760 759
 
761
-			$result = Database::query($sql);
762
-
763
-			if (Database::num_rows($result) > 0) {
764
-				echo '<ul>';
765
-				while ($mytask = Database::fetch_array($result)) {
766
-					echo '<li><a href="blog.php?action=execute_task&blog_id=' . $mytask['blog_id'] . '&task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
767
-				}
768
-				echo '<ul>';
769
-			} else {
770
-				echo get_lang('NoTasks');
771
-			}
772
-		} else {
773
-			echo get_lang('NoTasks');
774
-		}
775
-	}
776
-
777
-	/**
778
-	 * Changes the visibility of a blog
779
-	 * @author Toon Keppens
780
-	 * @param Integer $blog_id
781
-	 */
782
-	public static function change_blog_visibility($blog_id)
783
-	{
784
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
785
-		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
786
-		$course_id = api_get_course_int_id();
787
-
788
-		// Get blog properties
789
-		$sql = "SELECT blog_name, visibility FROM $tbl_blogs
760
+            $result = Database::query($sql);
761
+
762
+            if (Database::num_rows($result) > 0) {
763
+                echo '<ul>';
764
+                while ($mytask = Database::fetch_array($result)) {
765
+                    echo '<li><a href="blog.php?action=execute_task&blog_id=' . $mytask['blog_id'] . '&task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
766
+                }
767
+                echo '<ul>';
768
+            } else {
769
+                echo get_lang('NoTasks');
770
+            }
771
+        } else {
772
+            echo get_lang('NoTasks');
773
+        }
774
+    }
775
+
776
+    /**
777
+     * Changes the visibility of a blog
778
+     * @author Toon Keppens
779
+     * @param Integer $blog_id
780
+     */
781
+    public static function change_blog_visibility($blog_id)
782
+    {
783
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
784
+        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
785
+        $course_id = api_get_course_int_id();
786
+
787
+        // Get blog properties
788
+        $sql = "SELECT blog_name, visibility FROM $tbl_blogs
790 789
 				WHERE c_id = $course_id AND blog_id='".(int)$blog_id."'";
791
-		$result = Database::query($sql);
792
-		$blog = Database::fetch_array($result);
793
-		$visibility = $blog['visibility'];
794
-		$title = $blog['blog_name'];
795
-
796
-		if ($visibility == 1) {
797
-			// Change visibility state, remove from course home.
798
-			$sql = "UPDATE $tbl_blogs SET visibility = '0'
790
+        $result = Database::query($sql);
791
+        $blog = Database::fetch_array($result);
792
+        $visibility = $blog['visibility'];
793
+        $title = $blog['blog_name'];
794
+
795
+        if ($visibility == 1) {
796
+            // Change visibility state, remove from course home.
797
+            $sql = "UPDATE $tbl_blogs SET visibility = '0'
799 798
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
800
-			Database::query($sql);
799
+            Database::query($sql);
801 800
 
802
-			$sql = "DELETE FROM $tbl_tool
801
+            $sql = "DELETE FROM $tbl_tool
803 802
 					WHERE c_id = $course_id AND name = '".Database::escape_string($title)."' LIMIT 1";
804
-			Database::query($sql);
805
-		} else {
806
-			// Change visibility state, add to course home.
807
-			$sql = "UPDATE $tbl_blogs SET visibility = '1'
803
+            Database::query($sql);
804
+        } else {
805
+            // Change visibility state, add to course home.
806
+            $sql = "UPDATE $tbl_blogs SET visibility = '1'
808 807
 					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
809
-			Database::query($sql);
808
+            Database::query($sql);
810 809
 
811
-			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
810
+            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
812 811
 					VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
813
-			Database::query($sql);
812
+            Database::query($sql);
814 813
             $id = Database::insert_id();
815 814
 
816 815
             if ($id) {
817 816
                 $sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $id";
818 817
                 Database::query($sql);
819 818
             }
820
-		}
821
-	}
822
-
823
-	/**
824
-	 * Shows the posts of a blog
825
-	 * @author Toon Keppens
826
-	 *
827
-	 * @param Integer $blog_id
828
-	 */
829
-	public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
819
+        }
820
+    }
821
+
822
+    /**
823
+     * Shows the posts of a blog
824
+     * @author Toon Keppens
825
+     *
826
+     * @param Integer $blog_id
827
+     */
828
+    public static function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
830 829
     {
831
-		// Init
832
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
833
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
834
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
830
+        // Init
831
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
832
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
833
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
835 834
 
836
-		$course_id = api_get_course_int_id();
835
+        $course_id = api_get_course_int_id();
837 836
 
838
-		// Get posts and authors
839
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
837
+        // Get posts and authors
838
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
840 839
 		        FROM $tbl_blogs_posts post
841 840
                 INNER JOIN $tbl_users user
842 841
                 ON post.author_id = user.user_id
@@ -844,131 +843,131 @@  discard block
 block discarded – undo
844 843
 						post.c_id = $course_id AND
845 844
 						$filter
846 845
 				ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
847
-		$result = Database::query($sql);
848
-
849
-		// Display
850
-		if(Database::num_rows($result) > 0) {
851
-		    $limit = 200;
852
-			while ($blog_post = Database::fetch_array($result)) {
853
-				// Get number of comments
854
-				$sql = "SELECT COUNT(1) as number_of_comments
846
+        $result = Database::query($sql);
847
+
848
+        // Display
849
+        if(Database::num_rows($result) > 0) {
850
+            $limit = 200;
851
+            while ($blog_post = Database::fetch_array($result)) {
852
+                // Get number of comments
853
+                $sql = "SELECT COUNT(1) as number_of_comments
855 854
 						FROM $tbl_blogs_comments
856 855
 						WHERE
857 856
 						    c_id = $course_id AND
858 857
 						    blog_id = '".(int)$blog_id."' AND
859 858
 						    post_id = '" . (int)$blog_post['post_id']."'";
860
-				$tmp = Database::query($sql);
861
-				$blog_post_comments = Database::fetch_array($tmp);
862
-
863
-				// Prepare data
864
-				$blog_post_id = $blog_post['post_id'];
865
-				$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
866
-				$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
867
-
868
-				// Create an introduction text (but keep FULL sentences)
869
-				$words = 0;
870
-				$blog_post_text_cut = cut($blog_post_text, $limit) ;
871
-				$words = strlen($blog_post_text);
872
-
873
-				if ($words >= $limit) {
874
-					$readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</div>';
875
-					$introduction_text = $blog_post_text_cut;
876
-				} else {
877
-				    $introduction_text = $blog_post_text;
878
-					$readMoreLink = '';
879
-				}
880
-
881
-				$introduction_text = stripslashes($introduction_text);
882
-
883
-				echo '<div class="blogpost">';
884
-				echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
885
-				echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . $blog_post_date . '</a></span>';
886
-				echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
887
-				echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
888
-
889
-				$file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
890
-
891
-				if (!empty($file_name_array)) {
892
-					echo '<br /><br />';
893
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
894
-					echo '<a href="download.php?file=';
895
-					echo $file_name_array['path'];
896
-					echo ' "> '.$file_name_array['filename'].' </a><br />';
897
-					echo '</span>';
898
-				}
899
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
900
-				echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - <a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>';
901
-				echo '</div>';
902
-			}
903
-		} else {
904
-			if($filter == '1=1') {
905
-				echo get_lang('NoArticles');
906
-			} else {
907
-				echo get_lang('NoArticleMatches');
908
-			}
909
-		}
859
+                $tmp = Database::query($sql);
860
+                $blog_post_comments = Database::fetch_array($tmp);
861
+
862
+                // Prepare data
863
+                $blog_post_id = $blog_post['post_id'];
864
+                $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
865
+                $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
866
+
867
+                // Create an introduction text (but keep FULL sentences)
868
+                $words = 0;
869
+                $blog_post_text_cut = cut($blog_post_text, $limit) ;
870
+                $words = strlen($blog_post_text);
871
+
872
+                if ($words >= $limit) {
873
+                    $readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</div>';
874
+                    $introduction_text = $blog_post_text_cut;
875
+                } else {
876
+                    $introduction_text = $blog_post_text;
877
+                    $readMoreLink = '';
878
+                }
879
+
880
+                $introduction_text = stripslashes($introduction_text);
881
+
882
+                echo '<div class="blogpost">';
883
+                echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
884
+                echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . $blog_post_date . '</a></span>';
885
+                echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
886
+                echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
887
+
888
+                $file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
889
+
890
+                if (!empty($file_name_array)) {
891
+                    echo '<br /><br />';
892
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
893
+                    echo '<a href="download.php?file=';
894
+                    echo $file_name_array['path'];
895
+                    echo ' "> '.$file_name_array['filename'].' </a><br />';
896
+                    echo '</span>';
897
+                }
898
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
899
+                echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - <a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>';
900
+                echo '</div>';
901
+            }
902
+        } else {
903
+            if($filter == '1=1') {
904
+                echo get_lang('NoArticles');
905
+            } else {
906
+                echo get_lang('NoArticleMatches');
907
+            }
908
+        }
910 909
 }
911 910
 
912
-	/**
913
-	 * Display the search results
914
-	 *
915
-	 * @param Integer $blog_id
916
-	 * @param String $query_string
917
-	 */
918
-	public static function display_search_results ($blog_id, $query_string)
919
-	{
920
-		// Init
921
-		$query_string = Database::escape_string($query_string);
922
-		$query_string_parts = explode(' ',$query_string);
923
-		$query_string = array();
924
-		foreach ($query_string_parts as $query_part) {
925
-			$query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
926
-		}
927
-		$query_string = '('.implode('OR',$query_string) . ')';
928
-
929
-		// Display the posts
930
-		echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
931
-		Blog::display_blog_posts($blog_id, $query_string);
932
-	}
933
-
934
-	/**
935
-	 * Display posts from a certain date
936
-	 *
937
-	 * @param Integer $blog_id
938
-	 * @param String $query_string
939
-	 */
940
-	public static function display_day_results($blog_id, $query_string)
941
-	{
942
-		$date_output = $query_string;
943
-		$date = explode('-',$query_string);
944
-		$query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
945
-
946
-		// Put date in correct output format
947
-		$date_output = api_format_date($date_output, DATE_FORMAT_LONG);
948
-
949
-		// Display the posts
950
-		echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
951
-		Blog::display_blog_posts($blog_id, $query_string);
952
-	}
953
-
954
-	/**
955
-	 * Displays a post and his comments
956
-	 *
957
-	 * @param Integer $blog_id
958
-	 * @param Integer $post_id
959
-	 */
960
-	public static function display_post($blog_id, $post_id)
961
-	{
962
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
963
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
964
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
965
-
966
-		global $charset, $dateFormatLong;
967
-
968
-		$course_id = api_get_course_int_id();
969
-
970
-		// Get posts and author
971
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
911
+    /**
912
+     * Display the search results
913
+     *
914
+     * @param Integer $blog_id
915
+     * @param String $query_string
916
+     */
917
+    public static function display_search_results ($blog_id, $query_string)
918
+    {
919
+        // Init
920
+        $query_string = Database::escape_string($query_string);
921
+        $query_string_parts = explode(' ',$query_string);
922
+        $query_string = array();
923
+        foreach ($query_string_parts as $query_part) {
924
+            $query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
925
+        }
926
+        $query_string = '('.implode('OR',$query_string) . ')';
927
+
928
+        // Display the posts
929
+        echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
930
+        Blog::display_blog_posts($blog_id, $query_string);
931
+    }
932
+
933
+    /**
934
+     * Display posts from a certain date
935
+     *
936
+     * @param Integer $blog_id
937
+     * @param String $query_string
938
+     */
939
+    public static function display_day_results($blog_id, $query_string)
940
+    {
941
+        $date_output = $query_string;
942
+        $date = explode('-',$query_string);
943
+        $query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
944
+
945
+        // Put date in correct output format
946
+        $date_output = api_format_date($date_output, DATE_FORMAT_LONG);
947
+
948
+        // Display the posts
949
+        echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
950
+        Blog::display_blog_posts($blog_id, $query_string);
951
+    }
952
+
953
+    /**
954
+     * Displays a post and his comments
955
+     *
956
+     * @param Integer $blog_id
957
+     * @param Integer $post_id
958
+     */
959
+    public static function display_post($blog_id, $post_id)
960
+    {
961
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
962
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
963
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
964
+
965
+        global $charset, $dateFormatLong;
966
+
967
+        $course_id = api_get_course_int_id();
968
+
969
+        // Get posts and author
970
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
972 971
 		        FROM $tbl_blogs_posts post
973 972
 					INNER JOIN $tbl_users user
974 973
 					ON post.author_id = user.user_id
@@ -977,113 +976,113 @@  discard block
 block discarded – undo
977 976
                     post.blog_id = '".(int)$blog_id."' AND
978 977
                     post.post_id = '".(int)$post_id."'
979 978
                 ORDER BY post_id DESC";
980
-		$result = Database::query($sql);
981
-		$blog_post = Database::fetch_array($result);
979
+        $result = Database::query($sql);
980
+        $blog_post = Database::fetch_array($result);
982 981
 
983
-		// Get number of comments
984
-		$sql = "SELECT COUNT(1) as number_of_comments
982
+        // Get number of comments
983
+        $sql = "SELECT COUNT(1) as number_of_comments
985 984
 		        FROM $tbl_blogs_comments
986 985
 				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
987
-		$result = Database::query($sql);
988
-		$blog_post_comments = Database::fetch_array($result);
986
+        $result = Database::query($sql);
987
+        $blog_post_comments = Database::fetch_array($result);
989 988
 
990
-		// Prepare data
991
-		$blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
992
-		$blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
993
-		$blog_post_actions = "";
989
+        // Prepare data
990
+        $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
991
+        $blog_post_date = api_convert_and_format_date($blog_post['date_creation'], null, date_default_timezone_get());
992
+        $blog_post_actions = "";
994 993
 
995
-		$task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
994
+        $task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
996 995
 
997
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
998
-			$blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '">';
999
-			$blog_post_actions .=  Display::return_icon('edit.png');
1000
-			$blog_post_actions .= '</a>';
996
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
997
+            $blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '">';
998
+            $blog_post_actions .=  Display::return_icon('edit.png');
999
+            $blog_post_actions .= '</a>';
1001 1000
         }
1002 1001
 
1003
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
1004
-			$blog_post_actions .= '<a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&do=delete_article&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;">';
1002
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
1003
+            $blog_post_actions .= '<a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&do=delete_article&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;">';
1005 1004
             $blog_post_actions .= Display::return_icon('delete.png');
1006 1005
             $blog_post_actions .= '</a>';
1007 1006
         }
1008 1007
 
1009
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1010
-			$rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1008
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1009
+            $rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1011 1010
 
1012
-		$blog_post_text=stripslashes($blog_post_text);
1011
+        $blog_post_text=stripslashes($blog_post_text);
1013 1012
 
1014
-		// Display post
1015
-		echo '<div class="blogpost">';
1016
-		echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
1017
-		echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1018
-		echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1013
+        // Display post
1014
+        echo '<div class="blogpost">';
1015
+        echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
1016
+        echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1017
+        echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1019 1018
 
1020
-		$file_name_array = get_blog_attachment($blog_id, $post_id);
1019
+        $file_name_array = get_blog_attachment($blog_id, $post_id);
1021 1020
 
1022 1021
         if (!empty($file_name_array)) {
1023
-			echo ' <br />';
1024
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1025
-			echo '<a href="download.php?file=';
1026
-			echo $file_name_array['path'];
1027
-			echo ' "> '.$file_name_array['filename'].' </a>';
1028
-			echo '</span>';
1029
-			echo '<span class="attachment_comment">';
1030
-			echo $file_name_array['comment'];
1031
-			echo '</span>';
1032
-			echo '<br />';
1033
-		}
1022
+            echo ' <br />';
1023
+            echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1024
+            echo '<a href="download.php?file=';
1025
+            echo $file_name_array['path'];
1026
+            echo ' "> '.$file_name_array['filename'].' </a>';
1027
+            echo '</span>';
1028
+            echo '<span class="attachment_comment">';
1029
+            echo $file_name_array['comment'];
1030
+            echo '</span>';
1031
+            echo '<br />';
1032
+        }
1034 1033
         $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1035
-		echo '<span class="blogpost_info">'.get_lang('Author').': ' .Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post',$blog_id,$post_id).$rating_select.'</span>';
1036
-		echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1037
-		echo '</div>';
1038
-
1039
-		// Display comments if there are any
1040
-		if($blog_post_comments['number_of_comments'] > 0) {
1041
-			echo '<div class="comments">';
1042
-				echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1043
-				Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1044
-			echo '</div>';
1045
-		}
1046
-
1047
-		// Display comment form
1048
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1049
-			Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1050
-		}
1051
-	}
1052
-
1053
-	/**
1054
-	 * Adds rating to a certain post or comment
1055
-	 * @author Toon Keppens
1056
-	 *
1057
-	 * @param String $type
1058
-	 * @param Integer $blog_id
1059
-	 * @param Integer $item_id
1060
-	 * @param Integer $rating
1061
-	 *
1062
-	 * @return Boolean success
1063
-	 */
1064
-	public static function add_rating($type, $blog_id, $item_id, $rating)
1065
-	{
1066
-		$_user = api_get_user_info();
1067
-
1068
-		// Init
1069
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1070
-		$course_id = api_get_course_int_id();
1071
-
1072
-		// Check if the user has already rated this post/comment
1073
-		$sql = "SELECT rating_id FROM $tbl_blogs_rating
1034
+        echo '<span class="blogpost_info">'.get_lang('Author').': ' .Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post',$blog_id,$post_id).$rating_select.'</span>';
1035
+        echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1036
+        echo '</div>';
1037
+
1038
+        // Display comments if there are any
1039
+        if($blog_post_comments['number_of_comments'] > 0) {
1040
+            echo '<div class="comments">';
1041
+                echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1042
+                Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1043
+            echo '</div>';
1044
+        }
1045
+
1046
+        // Display comment form
1047
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1048
+            Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1049
+        }
1050
+    }
1051
+
1052
+    /**
1053
+     * Adds rating to a certain post or comment
1054
+     * @author Toon Keppens
1055
+     *
1056
+     * @param String $type
1057
+     * @param Integer $blog_id
1058
+     * @param Integer $item_id
1059
+     * @param Integer $rating
1060
+     *
1061
+     * @return Boolean success
1062
+     */
1063
+    public static function add_rating($type, $blog_id, $item_id, $rating)
1064
+    {
1065
+        $_user = api_get_user_info();
1066
+
1067
+        // Init
1068
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1069
+        $course_id = api_get_course_int_id();
1070
+
1071
+        // Check if the user has already rated this post/comment
1072
+        $sql = "SELECT rating_id FROM $tbl_blogs_rating
1074 1073
                 WHERE
1075 1074
                     c_id = $course_id AND
1076 1075
                     blog_id = '".(int)$blog_id."' AND
1077 1076
                     item_id = '".(int)$item_id."' AND
1078 1077
                     rating_type = '".Database::escape_string($type)."' AND
1079 1078
                     user_id = '".(int)$_user['user_id']."'";
1080
-		$result = Database::query($sql);
1079
+        $result = Database::query($sql);
1081 1080
 
1082 1081
         // Add rating
1083
-		if (Database::num_rows($result) == 0) {
1084
-			$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1082
+        if (Database::num_rows($result) == 0) {
1083
+            $sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1085 1084
 					VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
1086
-			Database::query($sql);
1085
+            Database::query($sql);
1087 1086
 
1088 1087
             $id = Database::insert_id();
1089 1088
             if ($id) {
@@ -1091,107 +1090,107 @@  discard block
 block discarded – undo
1091 1090
                 Database::query($sql);
1092 1091
             }
1093 1092
 
1094
-			return true;
1093
+            return true;
1095 1094
         } else {
1096
-			return false;
1097
-		}
1098
-	}
1099
-
1100
-	/**
1101
-	 * Shows the rating of user
1102
-	 *
1103
-	 * @param String $type
1104
-	 * @param Integer $blog_id
1105
-	 * @param Integer $item_id
1106
-	 *
1107
-	 * @return array()
1108
-	 */
1109
-	public static function display_rating($type, $blog_id, $item_id)
1110
-	{
1111
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1112
-		$course_id = api_get_course_int_id();
1113
-
1114
-		// Calculate rating
1115
-		$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1095
+            return false;
1096
+        }
1097
+    }
1098
+
1099
+    /**
1100
+     * Shows the rating of user
1101
+     *
1102
+     * @param String $type
1103
+     * @param Integer $blog_id
1104
+     * @param Integer $item_id
1105
+     *
1106
+     * @return array()
1107
+     */
1108
+    public static function display_rating($type, $blog_id, $item_id)
1109
+    {
1110
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1111
+        $course_id = api_get_course_int_id();
1112
+
1113
+        // Calculate rating
1114
+        $sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1116 1115
 				WHERE
1117 1116
 				    c_id = $course_id AND
1118 1117
 				    blog_id = '".(int)$blog_id."' AND
1119 1118
 				    item_id = '".(int)$item_id."' AND
1120 1119
 				    rating_type = '".Database::escape_string($type)."' ";
1121
-		$result = Database::query($sql);
1122
-		$result = Database::fetch_array($result);
1123
-		return round($result['rating'], 2);
1124
-	}
1125
-
1126
-	/**
1127
-	 * Shows the rating form if not already rated by that user
1128
-	 * @author Toon Keppens
1129
-	 *
1130
-	 * @param String $type
1131
-	 * @param Integer $blog_id
1132
-	 * @param Integer $item_id
1133
-	 *
1134
-	 *@return String
1135
-	 */
1136
-	public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1137
-	{
1138
-		$_user = api_get_user_info();
1139
-		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1120
+        $result = Database::query($sql);
1121
+        $result = Database::fetch_array($result);
1122
+        return round($result['rating'], 2);
1123
+    }
1124
+
1125
+    /**
1126
+     * Shows the rating form if not already rated by that user
1127
+     * @author Toon Keppens
1128
+     *
1129
+     * @param String $type
1130
+     * @param Integer $blog_id
1131
+     * @param Integer $item_id
1132
+     *
1133
+     *@return String
1134
+     */
1135
+    public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1136
+    {
1137
+        $_user = api_get_user_info();
1138
+        $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
1140 1139
         $course_id = api_get_course_int_id();
1141 1140
 
1142 1141
         if ($type == 'post') {
1143
-			// Check if the user has already rated this post
1144
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1142
+            // Check if the user has already rated this post
1143
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1145 1144
 					WHERE c_id = $course_id AND
1146 1145
 					blog_id = '".(int)$blog_id."'
1147 1146
 					AND item_id = '".(int)$post_id."'
1148 1147
 					AND rating_type = '".Database::escape_string($type)."'
1149 1148
 					AND user_id = '".(int)$_user['user_id']."'";
1150
-			$result = Database::query($sql);
1149
+            $result = Database::query($sql);
1151 1150
             // Add rating
1152 1151
             if (Database::num_rows($result) == 0) {
1153
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
1152
+                return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
1154 1153
             } else {
1155
-				return '';
1156
-			}
1157
-		}
1154
+                return '';
1155
+            }
1156
+        }
1158 1157
 
1159 1158
         if ($type = 'comment') {
1160
-			// Check if the user has already rated this comment
1161
-			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1159
+            // Check if the user has already rated this comment
1160
+            $sql = "SELECT rating_id FROM $tbl_blogs_rating
1162 1161
 					WHERE c_id = $course_id AND blog_id = '".(int)$blog_id ."'
1163 1162
 					AND item_id = '".(int)$comment_id."'
1164 1163
 					AND rating_type = '".Database::escape_string($type)."'
1165 1164
 					AND user_id = '".(int)$_user['user_id']."'";
1166
-			$result = Database::query($sql);
1165
+            $result = Database::query($sql);
1167 1166
 
1168 1167
             if (Database::num_rows($result) == 0) {
1169
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
1168
+                return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
1170 1169
             } else {
1171
-				return '';
1172
-			}
1173
-		}
1174
-	}
1175
-
1176
-	/**
1177
-	 * This functions gets all replys to a post, threaded.
1178
-	 *
1179
-	 * @param Integer $current
1180
-	 * @param Integer $current_level
1181
-	 * @param Integer $blog_id
1182
-	 * @param Integer $post_id
1183
-	 */
1184
-	public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1185
-	{
1186
-		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1187
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1188
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1189
-		global $charset;
1190
-
1191
-		$course_id = api_get_course_int_id();
1192
-
1193
-		// Select top level comments
1194
-		$next_level = $current_level + 1;
1170
+                return '';
1171
+            }
1172
+        }
1173
+    }
1174
+
1175
+    /**
1176
+     * This functions gets all replys to a post, threaded.
1177
+     *
1178
+     * @param Integer $current
1179
+     * @param Integer $current_level
1180
+     * @param Integer $blog_id
1181
+     * @param Integer $post_id
1182
+     */
1183
+    public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
1184
+    {
1185
+        $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
1186
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1187
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1188
+        global $charset;
1189
+
1190
+        $course_id = api_get_course_int_id();
1191
+
1192
+        // Select top level comments
1193
+        $next_level = $current_level + 1;
1195 1194
         $sql = "SELECT comments.*, user.lastname, user.firstname, user.username, task.color
1196 1195
                 FROM $tbl_blogs_comments comments
1197 1196
                 INNER JOIN $tbl_users user
@@ -1203,11 +1202,11 @@  discard block
 block discarded – undo
1203 1202
                     parent_comment_id = $current AND
1204 1203
                     comments.blog_id = '".(int)$blog_id."' AND
1205 1204
                     comments.post_id = '".(int)$post_id."'";
1206
-		$result = Database::query($sql);
1205
+        $result = Database::query($sql);
1207 1206
 
1208
-		while($comment = Database::fetch_array($result)) {
1209
-			// Select the children recursivly
1210
-			$tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1207
+        while($comment = Database::fetch_array($result)) {
1208
+            // Select the children recursivly
1209
+            $tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1211 1210
 			        FROM $tbl_blogs_comments comments
1212 1211
 					INNER JOIN $tbl_users user
1213 1212
 					ON comments.author_id = user.user_id
@@ -1216,15 +1215,15 @@  discard block
 block discarded – undo
1216 1215
 						comment_id = $current
1217 1216
 						AND blog_id = '".(int)$blog_id."'
1218 1217
 						AND post_id = '".(int)$post_id."'";
1219
-			$tmp = Database::query($tmp);
1220
-			$tmp = Database::fetch_array($tmp);
1221
-			$parent_cat = $tmp['parent_comment_id'];
1222
-			$border_color = '';
1223
-
1224
-			// Prepare data
1225
-			$comment_text = make_clickable(stripslashes($comment['comment']));
1226
-			$blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1227
-			$blog_comment_actions = "";
1218
+            $tmp = Database::query($tmp);
1219
+            $tmp = Database::fetch_array($tmp);
1220
+            $parent_cat = $tmp['parent_comment_id'];
1221
+            $border_color = '';
1222
+
1223
+            // Prepare data
1224
+            $comment_text = make_clickable(stripslashes($comment['comment']));
1225
+            $blog_comment_date = api_convert_and_format_date($comment['date_creation'], null, date_default_timezone_get());
1226
+            $blog_comment_actions = "";
1228 1227
             if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_delete', $task_id)) {
1229 1228
                 $blog_comment_actions .= '<a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$post_id.'&do=delete_comment&comment_id='.$comment['comment_id'].'&task_id='.$task_id.'" title="'.get_lang(
1230 1229
                         'DeleteThisComment'
@@ -1239,167 +1238,167 @@  discard block
 block discarded – undo
1239 1238
                 $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']);
1240 1239
             }
1241 1240
 
1242
-			if (!is_null($comment['task_id'])) {
1243
-				$border_color = ' border-left: 3px solid #' . $comment['color'];
1244
-			}
1245
-
1246
-			$comment_text = stripslashes($comment_text);
1247
-
1248
-			// Output...
1249
-			$margin = $current_level * 30;
1250
-			echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1251
-				echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
1252
-				echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1253
-				echo '<span class="blogpost_text">' . $comment_text . '</span>';
1254
-
1255
-				$file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1256
-				if (!empty($file_name_array)) {
1257
-					echo '<br /><br />';
1258
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1259
-					echo '<a href="download.php?file=';
1260
-					echo $file_name_array['path'];
1261
-					echo ' "> '.$file_name_array['filename'].' </a>';
1262
-					echo '<span class="attachment_comment">';
1263
-					echo $file_name_array['comment'];
1264
-					echo '</span><br />';
1265
-				}
1266
-                $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1267
-				echo '<span class="blogpost_comment_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($comment['firstname'], $comment['lastname']), array('title'=>$username)).' - '.get_lang('Rating').': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']).$rating_select.'</span>';
1268
-				echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1269
-			echo '</div>';
1270
-
1271
-			// Go further down the tree.
1272
-			Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1273
-		}
1274
-	}
1275
-
1276
-	/**
1277
-	 * Displays the form to create a new post
1278
-	 * @author Toon Keppens
1279
-	 *
1280
-	 * @param Integer $blog_id
1281
-	 */
1282
-	public static function display_form_new_post($blog_id)
1283
-	{
1284
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1285
-			$form = new FormValidator(
1286
-				'add_post',
1287
-				'post',
1288
-				api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1289
-				null,
1290
-				array('enctype' => 'multipart/form-data')
1291
-			);
1292
-			$form->addHidden('post_title_edited', 'false');
1293
-			$form->addHeader(get_lang('NewPost'));
1294
-			$form->addText('title', get_lang('Title'));
1295
-			$config = array();
1296
-			if (!api_is_allowed_to_edit()) {
1297
-				$config['ToolbarSet'] = 'ProjectStudent';
1298
-			} else {
1299
-				$config['ToolbarSet'] = 'Project';
1300
-			}
1301
-			$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1302
-			$form->addFile('user_upload', get_lang('AddAnAttachment'));
1303
-			$form->addTextarea('post_file_comment', get_lang('FileComment'));
1304
-			$form->addHidden('new_post_submit', 'true');
1305
-			$form->addButton('save', get_lang('Save'));
1306
-
1307
-			$form->display();
1308
-		} else {
1309
-			api_not_allowed();
1310
-		}
1311
-	}
1312
-
1313
-	/**
1314
-	 * Displays the form to edit a post
1315
-	 * @author Toon Keppens
1316
-	 *
1317
-	 * @param Integer $blog_id
1318
-	 */
1319
-	public static function display_form_edit_post($blog_id, $post_id)
1320
-	{
1321
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1322
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1323
-
1324
-		$course_id = api_get_course_int_id();
1325
-
1326
-		// Get posts and author
1327
-		$sql = "SELECT post.*, user.lastname, user.firstname
1328
-				FROM $tbl_blogs_posts post
1329
-				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1330
-				WHERE
1331
-				post.c_id 			= $course_id AND
1332
-				post.blog_id 		= '".(int)$blog_id ."'
1333
-				AND post.post_id	= '".(int)$post_id."'
1334
-				ORDER BY post_id DESC";
1335
-		$result = Database::query($sql);
1336
-		$blog_post = Database::fetch_array($result);
1337
-
1338
-		// Form
1339
-		$form = new FormValidator(
1340
-			'edit_post',
1341
-			'post',
1342
-			api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id=' . intval($_GET['post_id']) . '&blog_id=' . intval($blog_id) . '&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1343
-		);
1344
-
1345
-		$form->addHeader(get_lang('EditPost'));
1346
-		$form->addText('title', get_lang('Title'));
1347
-
1348
-		if (!api_is_allowed_to_edit()) {
1349
-			$config['ToolbarSet'] = 'ProjectStudent';
1350
-		} else {
1351
-			$config['ToolbarSet'] = 'Project';
1352
-		}
1353
-		$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1354
-
1355
-		$form->addHidden('action', '');
1356
-		$form->addHidden('edit_post_submit', 'true');
1357
-		$form->addHidden('post_id', intval($_GET['post_id']));
1358
-		$form->addButton('save', get_lang('Save'));
1359
-		$form->setDefaults($blog_post);
1360
-		$form->display();
1361
-	}
1362
-
1363
-	/**
1364
-	 * Displays a list of tasks in this blog
1365
-	 * @author Toon Keppens
1366
-	 *
1367
-	 * @param Integer $blog_id
1368
-	 */
1369
-	public static function display_task_list($blog_id)
1241
+            if (!is_null($comment['task_id'])) {
1242
+                $border_color = ' border-left: 3px solid #' . $comment['color'];
1243
+            }
1244
+
1245
+            $comment_text = stripslashes($comment_text);
1246
+
1247
+            // Output...
1248
+            $margin = $current_level * 30;
1249
+            echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1250
+                echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
1251
+                echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1252
+                echo '<span class="blogpost_text">' . $comment_text . '</span>';
1253
+
1254
+                $file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1255
+                if (!empty($file_name_array)) {
1256
+                    echo '<br /><br />';
1257
+                    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1258
+                    echo '<a href="download.php?file=';
1259
+                    echo $file_name_array['path'];
1260
+                    echo ' "> '.$file_name_array['filename'].' </a>';
1261
+                    echo '<span class="attachment_comment">';
1262
+                    echo $file_name_array['comment'];
1263
+                    echo '</span><br />';
1264
+                }
1265
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1266
+                echo '<span class="blogpost_comment_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($comment['firstname'], $comment['lastname']), array('title'=>$username)).' - '.get_lang('Rating').': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']).$rating_select.'</span>';
1267
+                echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1268
+            echo '</div>';
1269
+
1270
+            // Go further down the tree.
1271
+            Blog::get_threaded_comments($comment['comment_id'], $next_level, $blog_id, $post_id);
1272
+        }
1273
+    }
1274
+
1275
+    /**
1276
+     * Displays the form to create a new post
1277
+     * @author Toon Keppens
1278
+     *
1279
+     * @param Integer $blog_id
1280
+     */
1281
+    public static function display_form_new_post($blog_id)
1282
+    {
1283
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1284
+            $form = new FormValidator(
1285
+                'add_post',
1286
+                'post',
1287
+                api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1288
+                null,
1289
+                array('enctype' => 'multipart/form-data')
1290
+            );
1291
+            $form->addHidden('post_title_edited', 'false');
1292
+            $form->addHeader(get_lang('NewPost'));
1293
+            $form->addText('title', get_lang('Title'));
1294
+            $config = array();
1295
+            if (!api_is_allowed_to_edit()) {
1296
+                $config['ToolbarSet'] = 'ProjectStudent';
1297
+            } else {
1298
+                $config['ToolbarSet'] = 'Project';
1299
+            }
1300
+            $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1301
+            $form->addFile('user_upload', get_lang('AddAnAttachment'));
1302
+            $form->addTextarea('post_file_comment', get_lang('FileComment'));
1303
+            $form->addHidden('new_post_submit', 'true');
1304
+            $form->addButton('save', get_lang('Save'));
1305
+
1306
+            $form->display();
1307
+        } else {
1308
+            api_not_allowed();
1309
+        }
1310
+    }
1311
+
1312
+    /**
1313
+     * Displays the form to edit a post
1314
+     * @author Toon Keppens
1315
+     *
1316
+     * @param Integer $blog_id
1317
+     */
1318
+    public static function display_form_edit_post($blog_id, $post_id)
1319
+    {
1320
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1321
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1322
+
1323
+        $course_id = api_get_course_int_id();
1324
+
1325
+        // Get posts and author
1326
+        $sql = "SELECT post.*, user.lastname, user.firstname
1327
+				FROM $tbl_blogs_posts post
1328
+				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1329
+				WHERE
1330
+				post.c_id 			= $course_id AND
1331
+				post.blog_id 		= '".(int)$blog_id ."'
1332
+				AND post.post_id	= '".(int)$post_id."'
1333
+				ORDER BY post_id DESC";
1334
+        $result = Database::query($sql);
1335
+        $blog_post = Database::fetch_array($result);
1336
+
1337
+        // Form
1338
+        $form = new FormValidator(
1339
+            'edit_post',
1340
+            'post',
1341
+            api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id=' . intval($_GET['post_id']) . '&blog_id=' . intval($blog_id) . '&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1342
+        );
1343
+
1344
+        $form->addHeader(get_lang('EditPost'));
1345
+        $form->addText('title', get_lang('Title'));
1346
+
1347
+        if (!api_is_allowed_to_edit()) {
1348
+            $config['ToolbarSet'] = 'ProjectStudent';
1349
+        } else {
1350
+            $config['ToolbarSet'] = 'Project';
1351
+        }
1352
+        $form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
1353
+
1354
+        $form->addHidden('action', '');
1355
+        $form->addHidden('edit_post_submit', 'true');
1356
+        $form->addHidden('post_id', intval($_GET['post_id']));
1357
+        $form->addButton('save', get_lang('Save'));
1358
+        $form->setDefaults($blog_post);
1359
+        $form->display();
1360
+    }
1361
+
1362
+    /**
1363
+     * Displays a list of tasks in this blog
1364
+     * @author Toon Keppens
1365
+     *
1366
+     * @param Integer $blog_id
1367
+     */
1368
+    public static function display_task_list($blog_id)
1370 1369
     {
1371
-		global $charset;
1370
+        global $charset;
1372 1371
         $course_id = api_get_course_int_id();
1373 1372
 
1374
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1375
-			$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1376
-			$counter = 0;
1377
-			global $color2;
1373
+        if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1374
+            $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1375
+            $counter = 0;
1376
+            global $color2;
1378 1377
 
1379
-			echo '<div class="actions">';
1380
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1378
+            echo '<div class="actions">';
1379
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1381 1380
             echo Display::return_icon('blog_newtasks.gif', get_lang('AddTasks'));
1382 1381
             echo get_lang('AddTasks') . '</a> ';
1383
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1382
+            echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1384 1383
             echo Display::return_icon('blog_task.gif', get_lang('AssignTasks'));
1385 1384
             echo get_lang('AssignTasks') . '</a>';
1386
-			?>
1385
+            ?>
1387 1386
 				<a href="<?php echo api_get_self(); ?>?action=manage_rights&blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights') ?>">
1388 1387
                     <?php echo Display::return_icon('blog_admin_users.png', get_lang('RightsManager'),'',ICON_SIZE_SMALL). get_lang('RightsManager') ?></a>
1389 1388
 			<?php
1390
-			echo '</div>';
1389
+            echo '</div>';
1391 1390
 
1392
-			echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1393
-			echo "<table class=\"data_table\">";
1394
-			echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1395
-					 "<th width='240'><b>",get_lang('Title'),"</b></th>",
1396
-					 "<th><b>",get_lang('Description'),"</b></th>",
1397
-					 "<th><b>",get_lang('Color'),"</b></th>",
1398
-					 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1399
-				"</tr>";
1391
+            echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1392
+            echo "<table class=\"data_table\">";
1393
+            echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1394
+                        "<th width='240'><b>",get_lang('Title'),"</b></th>",
1395
+                        "<th><b>",get_lang('Description'),"</b></th>",
1396
+                        "<th><b>",get_lang('Color'),"</b></th>",
1397
+                        "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1398
+                "</tr>";
1400 1399
 
1401 1400
 
1402
-			$sql = " SELECT
1401
+            $sql = " SELECT
1403 1402
                         blog_id,
1404 1403
                         task_id,
1405 1404
                         blog_id,
@@ -1410,64 +1409,64 @@  discard block
 block discarded – undo
1410 1409
                     FROM " . $tbl_blogs_tasks . "
1411 1410
                     WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1412 1411
                     ORDER BY system_task, title";
1413
-			$result = Database::query($sql);
1412
+            $result = Database::query($sql);
1414 1413
 
1415
-			while ($task = Database::fetch_array($result)) {
1416
-				$counter++;
1417
-				$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1418
-				$delete_icon = ($task['system_task'] == '1') ? "delete_na.png" : "delete.png";
1419
-				$delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1420
-				$delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1421
-				$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1414
+            while ($task = Database::fetch_array($result)) {
1415
+                $counter++;
1416
+                $css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1417
+                $delete_icon = ($task['system_task'] == '1') ? "delete_na.png" : "delete.png";
1418
+                $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1419
+                $delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1420
+                $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1422 1421
 
1423
-				echo '<tr class="' . $css_class . '" valign="top">';
1422
+                echo '<tr class="' . $css_class . '" valign="top">';
1424 1423
                 echo '<td width="240">'.Security::remove_XSS($task['title']).'</td>';
1425 1424
                 echo '<td>'.Security::remove_XSS($task['description']).'</td>';
1426 1425
                 echo '<td><span style="background-color: #'.$task['color'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>';
1427 1426
                 echo '<td width="50">';
1428 1427
                 echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$task['blog_id'].'&do=edit&task_id='.$task['task_id'].'">';
1429 1428
                 echo Display::return_icon('edit.png', get_lang('EditTask'));
1430
-                      echo "</a>";
1431
-                      echo '<a href="'.$delete_link.'"';
1432
-                      echo $delete_confirm;
1433
-                       echo '>';
1429
+                        echo "</a>";
1430
+                        echo '<a href="'.$delete_link.'"';
1431
+                        echo $delete_confirm;
1432
+                        echo '>';
1434 1433
                         echo Display::return_icon($delete_icon, $delete_title);
1435
-                       echo "</a>";
1436
-                     echo '</td>';
1437
-                   echo '</tr>';
1438
-			}
1439
-			echo "</table>";
1440
-		}
1441
-	}
1442
-
1443
-	/**
1444
-	 * Displays a list of tasks assigned to a user in this blog
1445
-	 * @author Toon Keppens
1446
-	 *
1447
-	 * @param Integer $blog_id
1448
-	 */
1449
-	public static function display_assigned_task_list ($blog_id)
1434
+                        echo "</a>";
1435
+                        echo '</td>';
1436
+                    echo '</tr>';
1437
+            }
1438
+            echo "</table>";
1439
+        }
1440
+    }
1441
+
1442
+    /**
1443
+     * Displays a list of tasks assigned to a user in this blog
1444
+     * @author Toon Keppens
1445
+     *
1446
+     * @param Integer $blog_id
1447
+     */
1448
+    public static function display_assigned_task_list ($blog_id)
1450 1449
     {
1451
-		// Init
1452
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1453
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1454
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1455
-		$counter = 0;
1456
-		global $charset,$color2;
1457
-
1458
-		echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1459
-		echo "<table class=\"data_table\">";
1460
-		echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1461
-				 "<th width='240'><b>",get_lang('Member'),"</b></th>",
1462
-				 "<th><b>",get_lang('Task'),"</b></th>",
1463
-				 "<th><b>",get_lang('Description'),"</b></th>",
1464
-				 "<th><b>",get_lang('TargetDate'),"</b></th>",
1465
-				 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1466
-			"</tr>";
1467
-
1468
-		$course_id = api_get_course_int_id();
1469
-
1470
-		$sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1450
+        // Init
1451
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1452
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1453
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1454
+        $counter = 0;
1455
+        global $charset,$color2;
1456
+
1457
+        echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1458
+        echo "<table class=\"data_table\">";
1459
+        echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1460
+                    "<th width='240'><b>",get_lang('Member'),"</b></th>",
1461
+                    "<th><b>",get_lang('Task'),"</b></th>",
1462
+                    "<th><b>",get_lang('Description'),"</b></th>",
1463
+                    "<th><b>",get_lang('TargetDate'),"</b></th>",
1464
+                    "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1465
+            "</tr>";
1466
+
1467
+        $course_id = api_get_course_int_id();
1468
+
1469
+        $sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, user.username, task.description, task.system_task, task.blog_id, task.task_id
1471 1470
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
1472 1471
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
1473 1472
 				INNER JOIN $tbl_users user ON task_rel_user.user_id = user.user_id
@@ -1476,15 +1475,15 @@  discard block
 block discarded – undo
1476 1475
 					task.c_id = $course_id AND
1477 1476
 					task_rel_user.blog_id = '".(int)$blog_id."'
1478 1477
 				ORDER BY target_date ASC";
1479
-		$result = Database::query($sql);
1478
+        $result = Database::query($sql);
1480 1479
 
1481
-		while ($assignment = Database::fetch_array($result)) {
1482
-			$counter++;
1483
-			$css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1484
-			$delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png";
1485
-			$delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1486
-			$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1487
-			$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1480
+        while ($assignment = Database::fetch_array($result)) {
1481
+            $counter++;
1482
+            $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1483
+            $delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png";
1484
+            $delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1485
+            $delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1486
+            $delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1488 1487
 
1489 1488
             $username = api_htmlentities(sprintf(get_lang('LoginX'), $assignment['username']), ENT_QUOTES);
1490 1489
 
@@ -1499,26 +1498,26 @@  discard block
 block discarded – undo
1499 1498
             echo '<td>'.$assignment['target_date'].'</td>';
1500 1499
             echo '<td width="50">';
1501 1500
             echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=edit_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'">';
1502
-	            echo Display::return_icon('edit.png', get_lang('EditTask'));
1503
-				echo "</a>";
1504
-				echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'" ';
1505
-				echo 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1501
+                echo Display::return_icon('edit.png', get_lang('EditTask'));
1502
+                echo "</a>";
1503
+                echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete_assignment&task_id='.$assignment['task_id'].'&user_id='.$assignment['user_id'].'" ';
1504
+                echo 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1506 1505
                 echo Display::return_icon($delete_icon, $delete_title);
1507
-				echo "</a>";
1508
-				echo '</td>';
1509
-				echo '</tr>';
1510
-		}
1511
-		echo "</table>";
1512
-	}
1513
-
1514
-	/**
1515
-	 * Displays new task form
1516
-	 * @author Toon Keppens
1517
-	 *
1518
-	 */
1519
-	public static function display_new_task_form ($blog_id)
1520
-	{
1521
-		// Init
1506
+                echo "</a>";
1507
+                echo '</td>';
1508
+                echo '</tr>';
1509
+        }
1510
+        echo "</table>";
1511
+    }
1512
+
1513
+    /**
1514
+     * Displays new task form
1515
+     * @author Toon Keppens
1516
+     *
1517
+     */
1518
+    public static function display_new_task_form ($blog_id)
1519
+    {
1520
+        // Init
1522 1521
         $colors = array(
1523 1522
             'FFFFFF',
1524 1523
             'FFFF99',
@@ -1537,14 +1536,14 @@  discard block
 block discarded – undo
1537 1536
             '000000'
1538 1537
         );
1539 1538
 
1540
-		// form
1541
-		echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1539
+        // form
1540
+        echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1542 1541
 
1543
-		// form title
1544
-		echo '<legend>'.get_lang('AddTask').'</legend>';
1542
+        // form title
1543
+        echo '<legend>'.get_lang('AddTask').'</legend>';
1545 1544
 
1546
-		// task title
1547
-		echo '	<div class="control-group">
1545
+        // task title
1546
+        echo '	<div class="control-group">
1548 1547
 					<label class="control-label">
1549 1548
 						<span class="form_required">*</span>' . get_lang('Title') . '
1550 1549
 					</label>
@@ -1553,8 +1552,8 @@  discard block
 block discarded – undo
1553 1552
 					</div>
1554 1553
 				</div>';
1555 1554
 
1556
-		// task comment
1557
-		echo '	<div class="control-group">
1555
+        // task comment
1556
+        echo '	<div class="control-group">
1558 1557
 					<label class="control-label">
1559 1558
 						' . get_lang('Description') . '
1560 1559
 					</label>
@@ -1563,8 +1562,8 @@  discard block
 block discarded – undo
1563 1562
 					</div>
1564 1563
 				</div>';
1565 1564
 
1566
-		// task management
1567
-		echo '	<div class="control-group">
1565
+        // task management
1566
+        echo '	<div class="control-group">
1568 1567
 					<label class="control-label">
1569 1568
 						' . get_lang('TaskManager') . '
1570 1569
 					</label>
@@ -1585,12 +1584,12 @@  discard block
 block discarded – undo
1585 1584
                         echo '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1586 1585
                     echo '</tr>';
1587 1586
                 echo '</table>';
1588
-		echo '		</div>
1587
+        echo '		</div>
1589 1588
 				</div>';
1590 1589
 
1591 1590
 
1592
-		// task color
1593
-		echo '	<div class="control-group">
1591
+        // task color
1592
+        echo '	<div class="control-group">
1594 1593
 					<label class="control-label">
1595 1594
 						' . get_lang('Color') . '
1596 1595
 					</label>
@@ -1601,40 +1600,40 @@  discard block
 block discarded – undo
1601 1600
                     echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1602 1601
                 }
1603 1602
         echo '</select>';
1604
-		echo '		</div>
1603
+        echo '		</div>
1605 1604
 				</div>';
1606 1605
 
1607
-		// submit
1608
-		echo '	<div class="control-group">
1606
+        // submit
1607
+        echo '	<div class="control-group">
1609 1608
 					<div class="controls">
1610 1609
 							<input type="hidden" name="action" value="" />
1611 1610
 							<input type="hidden" name="new_task_submit" value="true" />
1612 1611
 						<button class="save" type="submit" name="Submit">' . get_lang('Save') . '</button>
1613 1612
 					</div>
1614 1613
 				</div>';
1615
-		echo '</form>';
1614
+        echo '</form>';
1616 1615
 
1617
-		echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1618
-	}
1616
+        echo '<div style="clear:both; margin-bottom: 10px;"></div>';
1617
+    }
1619 1618
 
1620 1619
 
1621
-	/**
1622
-	 * Displays edit task form
1623
-	 * @author Toon Keppens
1624
-	 *
1625
-	 */
1626
-	public static function display_edit_task_form ($blog_id, $task_id) {
1627
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1620
+    /**
1621
+     * Displays edit task form
1622
+     * @author Toon Keppens
1623
+     *
1624
+     */
1625
+    public static function display_edit_task_form ($blog_id, $task_id) {
1626
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1628 1627
         $course_id = api_get_course_int_id();
1629 1628
 
1630
-		$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1629
+        $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1631 1630
 
1632
-		$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1633
-		$result = Database::query($sql);
1634
-		$task = Database::fetch_array($result);
1631
+        $sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1632
+        $result = Database::query($sql);
1633
+        $task = Database::fetch_array($result);
1635 1634
 
1636
-		// Display
1637
-		echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1635
+        // Display
1636
+        echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1638 1637
 					<legend>' . get_lang('EditTask') . '</legend>
1639 1638
 					<table width="100%" border="0" cellspacing="2">
1640 1639
 						<tr>
@@ -1646,42 +1645,42 @@  discard block
 block discarded – undo
1646 1645
 					   <td><textarea name="task_description" cols="45">'.Security::remove_XSS($task['description']).'</textarea></td>
1647 1646
 						</tr>';
1648 1647
 
1649
-						/* edit by Kevin Van Den Haute ([email protected]) */
1650
-						$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1648
+                        /* edit by Kevin Van Den Haute ([email protected]) */
1649
+                        $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1651 1650
 
1652
-						$sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1651
+                        $sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1653 1652
 							     WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
1654
-						$result = Database::query($sql);
1655
-
1656
-						$arrPermissions = array();
1657
-
1658
-						while ($row = Database::fetch_array($result))
1659
-							$arrPermissions[] = $row['action'];
1660
-
1661
-						    echo '<tr>';
1662
-							echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1663
-							echo '<td>';
1664
-								echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1665
-									echo '<tr>';
1666
-										echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1667
-										echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1668
-									echo '</tr>';
1669
-									echo '<tr>';
1670
-										echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1671
-										echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1672
-										echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1673
-									echo '</tr>';
1674
-									echo '<tr>';
1675
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1676
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1677
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1678
-									echo '</tr>';
1679
-								echo '</table>';
1680
-							echo '</td>';
1681
-						echo '</tr>';
1682
-						/* end of edit */
1683
-
1684
-						echo '<tr>
1653
+                        $result = Database::query($sql);
1654
+
1655
+                        $arrPermissions = array();
1656
+
1657
+                        while ($row = Database::fetch_array($result))
1658
+                            $arrPermissions[] = $row['action'];
1659
+
1660
+                            echo '<tr>';
1661
+                            echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1662
+                            echo '<td>';
1663
+                                echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1664
+                                    echo '<tr>';
1665
+                                        echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1666
+                                        echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1667
+                                    echo '</tr>';
1668
+                                    echo '<tr>';
1669
+                                        echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1670
+                                        echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1671
+                                        echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1672
+                                    echo '</tr>';
1673
+                                    echo '<tr>';
1674
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1675
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1676
+                                        echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1677
+                                    echo '</tr>';
1678
+                                echo '</table>';
1679
+                            echo '</td>';
1680
+                        echo '</tr>';
1681
+                        /* end of edit */
1682
+
1683
+                        echo '<tr>
1685 1684
 					   <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
1686 1685
 					   <td>
1687 1686
 					   	<select name="task_color" id="color" style="width: 150px; background-color: #' . $task['color'] . '" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
@@ -1690,7 +1689,7 @@  discard block
 block discarded – undo
1690 1689
                                 $style = 'style="background-color: #' . $color . '"';
1691 1690
                                 echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1692 1691
                             }
1693
-		echo '			   </select>
1692
+        echo '			   </select>
1694 1693
 						  </td>
1695 1694
 						</tr>
1696 1695
 						<tr>
@@ -1703,34 +1702,34 @@  discard block
 block discarded – undo
1703 1702
 						</tr>
1704 1703
 					</table>
1705 1704
 				</form>';
1706
-	}
1707
-
1708
-	/**
1709
-	 * @param $blog_id
1710
-	 * @return FormValidator
1711
-	 */
1712
-	public static function getTaskForm($blog_id)
1713
-	{
1714
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1715
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1716
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1717
-		$course_id = api_get_course_int_id();
1718
-
1719
-		// Get users in this blog / make select list of it
1720
-		$sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1705
+    }
1706
+
1707
+    /**
1708
+     * @param $blog_id
1709
+     * @return FormValidator
1710
+     */
1711
+    public static function getTaskForm($blog_id)
1712
+    {
1713
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1714
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1715
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1716
+        $course_id = api_get_course_int_id();
1717
+
1718
+        // Get users in this blog / make select list of it
1719
+        $sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
1721 1720
 				FROM $tbl_users user
1722 1721
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
1723 1722
 				ON user.user_id = blogs_rel_user.user_id
1724 1723
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
1725
-		$result = Database::query($sql);
1724
+        $result = Database::query($sql);
1726 1725
 
1727
-		$options = array();
1728
-		while ($user = Database::fetch_array($result)) {
1729
-			$options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1730
-		}
1726
+        $options = array();
1727
+        while ($user = Database::fetch_array($result)) {
1728
+            $options[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
1729
+        }
1731 1730
 
1732
-		// Get tasks in this blog / make select list of it
1733
-		$sql = "
1731
+        // Get tasks in this blog / make select list of it
1732
+        $sql = "
1734 1733
 			SELECT
1735 1734
 				blog_id,
1736 1735
 				task_id,
@@ -1742,97 +1741,97 @@  discard block
 block discarded – undo
1742 1741
 			FROM $tbl_blogs_tasks
1743 1742
 			WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1744 1743
 			ORDER BY system_task, title";
1745
-		$result = Database::query($sql);
1746
-
1747
-		$taskOptions = array();
1748
-		while ($task = Database::fetch_array($result)) {
1749
-			$taskOptions[$task['task_id']] = stripslashes($task['title']);
1750
-		}
1751
-
1752
-		$form = new FormValidator(
1753
-			'assign_task',
1754
-			'post',
1755
-			api_get_path(
1756
-				WEB_CODE_PATH
1757
-			).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1758
-		);
1759
-
1760
-		$form->addHeader(get_lang('AssignTask'));
1761
-		$form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1762
-		$form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1763
-		$form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1764
-
1765
-		$form->addHidden('action', '');
1766
-		$form->addButtonSave(get_lang('Ok'));
1767
-
1768
-		return $form;
1769
-	}
1770
-
1771
-	/**
1772
-	 * Displays assign task form
1773
-	 * @author Toon Keppens
1774
-	 *
1775
-	 */
1776
-	public static function display_assign_task_form($blog_id)
1777
-	{
1778
-		$form = self::getTaskForm($blog_id);
1779
-		$form->addHidden('assign_task_submit', 'true');
1780
-		$form->display();
1781
-		echo '<div style="clear: both; margin-bottom:10px;"></div>';
1782
-	}
1783
-
1784
-	/**
1785
-	 * Displays assign task form
1786
-	 * @author Toon Keppens
1787
-	 *
1788
-	 */
1789
-	public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1790
-	{
1791
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1792
-
1793
-		$course_id = api_get_course_int_id();
1794
-
1795
-		// Get assignd date;
1796
-		$sql = "
1744
+        $result = Database::query($sql);
1745
+
1746
+        $taskOptions = array();
1747
+        while ($task = Database::fetch_array($result)) {
1748
+            $taskOptions[$task['task_id']] = stripslashes($task['title']);
1749
+        }
1750
+
1751
+        $form = new FormValidator(
1752
+            'assign_task',
1753
+            'post',
1754
+            api_get_path(
1755
+                WEB_CODE_PATH
1756
+            ).'blog/blog.php?action=manage_tasks&blog_id='.$blog_id
1757
+        );
1758
+
1759
+        $form->addHeader(get_lang('AssignTask'));
1760
+        $form->addSelect('task_user_id', get_lang('SelectUser'), $options);
1761
+        $form->addSelect('task_task_id', get_lang('SelectTask'), $taskOptions);
1762
+        $form->addDatePicker('task_day', get_lang('SelectTargetDate'));
1763
+
1764
+        $form->addHidden('action', '');
1765
+        $form->addButtonSave(get_lang('Ok'));
1766
+
1767
+        return $form;
1768
+    }
1769
+
1770
+    /**
1771
+     * Displays assign task form
1772
+     * @author Toon Keppens
1773
+     *
1774
+     */
1775
+    public static function display_assign_task_form($blog_id)
1776
+    {
1777
+        $form = self::getTaskForm($blog_id);
1778
+        $form->addHidden('assign_task_submit', 'true');
1779
+        $form->display();
1780
+        echo '<div style="clear: both; margin-bottom:10px;"></div>';
1781
+    }
1782
+
1783
+    /**
1784
+     * Displays assign task form
1785
+     * @author Toon Keppens
1786
+     *
1787
+     */
1788
+    public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1789
+    {
1790
+        $tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1791
+
1792
+        $course_id = api_get_course_int_id();
1793
+
1794
+        // Get assignd date;
1795
+        $sql = "
1797 1796
 			SELECT target_date
1798 1797
 			FROM $tbl_blogs_tasks_rel_user
1799 1798
 			WHERE c_id = $course_id AND
1800 1799
 			      blog_id = '".(int)$blog_id."' AND
1801 1800
 			      user_id = '".(int)$user_id."' AND
1802 1801
 			      task_id = '".(int)$task_id."'";
1803
-		$result = Database::query($sql);
1804
-		$row = Database::fetch_assoc($result);
1805
-
1806
-		$date = $row['target_date'];
1807
-
1808
-		$defaults = [
1809
-			'task_user_id' => $user_id,
1810
-			'task_task_id' => $task_id,
1811
-			'task_day' => $date
1812
-		];
1813
-		$form = self::getTaskForm($blog_id);
1814
-		$form->addHidden('old_task_id', $task_id);
1815
-		$form->addHidden('old_user_id', $user_id);
1816
-		$form->addHidden('old_target_date', $date);
1817
-		$form->addHidden('assign_task_edit_submit', 'true');
1818
-		$form->setDefaults($defaults);
1819
-		$form->display();
1820
-	}
1821
-
1822
-	/**
1823
-	 * Assigns a task to a user in a blog
1824
-	 *
1825
-	 * @param Integer $blog_id
1826
-	 * @param Integer $user_id
1827
-	 * @param Integer $task_id
1828
-	 * @param Date $target_date
1829
-	 */
1830
-	public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1831
-	{
1832
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1833
-		$course_id = api_get_course_int_id();
1834
-
1835
-		$sql = "
1802
+        $result = Database::query($sql);
1803
+        $row = Database::fetch_assoc($result);
1804
+
1805
+        $date = $row['target_date'];
1806
+
1807
+        $defaults = [
1808
+            'task_user_id' => $user_id,
1809
+            'task_task_id' => $task_id,
1810
+            'task_day' => $date
1811
+        ];
1812
+        $form = self::getTaskForm($blog_id);
1813
+        $form->addHidden('old_task_id', $task_id);
1814
+        $form->addHidden('old_user_id', $user_id);
1815
+        $form->addHidden('old_target_date', $date);
1816
+        $form->addHidden('assign_task_edit_submit', 'true');
1817
+        $form->setDefaults($defaults);
1818
+        $form->display();
1819
+    }
1820
+
1821
+    /**
1822
+     * Assigns a task to a user in a blog
1823
+     *
1824
+     * @param Integer $blog_id
1825
+     * @param Integer $user_id
1826
+     * @param Integer $task_id
1827
+     * @param Date $target_date
1828
+     */
1829
+    public static function assign_task($blog_id, $user_id, $task_id, $target_date)
1830
+    {
1831
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1832
+        $course_id = api_get_course_int_id();
1833
+
1834
+        $sql = "
1836 1835
 			SELECT COUNT(*) as 'number'
1837 1836
 			FROM " . $tbl_blogs_tasks_rel_user . "
1838 1837
 			WHERE c_id = $course_id AND
@@ -1841,11 +1840,11 @@  discard block
 block discarded – undo
1841 1840
 			AND	task_id = " . (int)$task_id . "
1842 1841
 		";
1843 1842
 
1844
-		$result = Database::query($sql);
1845
-		$row = Database::fetch_assoc($result);
1843
+        $result = Database::query($sql);
1844
+        $row = Database::fetch_assoc($result);
1846 1845
 
1847
-		if ($row['number'] == 0) {
1848
-			$sql = "
1846
+        if ($row['number'] == 0) {
1847
+            $sql = "
1849 1848
 				INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
1850 1849
 					c_id,
1851 1850
 					blog_id,
@@ -1860,9 +1859,9 @@  discard block
 block discarded – undo
1860 1859
 					'" . Database::escape_string($target_date) . "'
1861 1860
 				)";
1862 1861
 
1863
-			Database::query($sql);
1864
-		}
1865
-	}
1862
+            Database::query($sql);
1863
+        }
1864
+    }
1866 1865
 
1867 1866
     /**
1868 1867
      * @param $blog_id
@@ -1882,11 +1881,11 @@  discard block
 block discarded – undo
1882 1881
         $old_task_id,
1883 1882
         $old_target_date
1884 1883
     ) {
1885
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1884
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1886 1885
 
1887
-		$course_id = api_get_course_int_id();
1886
+        $course_id = api_get_course_int_id();
1888 1887
 
1889
-		$sql = "SELECT COUNT(*) as 'number'
1888
+        $sql = "SELECT COUNT(*) as 'number'
1890 1889
                 FROM " . $tbl_blogs_tasks_rel_user . "
1891 1890
                 WHERE
1892 1891
                     c_id = $course_id AND
@@ -1895,11 +1894,11 @@  discard block
 block discarded – undo
1895 1894
                     task_id = " . (int)$task_id . "
1896 1895
             ";
1897 1896
 
1898
-		$result = Database::query($sql);
1899
-		$row = Database::fetch_assoc($result);
1897
+        $result = Database::query($sql);
1898
+        $row = Database::fetch_assoc($result);
1900 1899
 
1901
-		if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1902
-			$sql = "
1900
+        if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1901
+            $sql = "
1903 1902
 				UPDATE " . $tbl_blogs_tasks_rel_user . "
1904 1903
 				SET
1905 1904
 					user_id = " . (int)$user_id . ",
@@ -1912,76 +1911,76 @@  discard block
 block discarded – undo
1912 1911
 					task_id = " . (int)$old_task_id . " AND
1913 1912
 					target_date = '" . Database::escape_string($old_target_date) . "'
1914 1913
 			";
1915
-			Database::query($sql);
1916
-		}
1917
-	}
1918
-
1919
-	/**
1920
-	 * Displays a list with posts a user can select to execute his task.
1921
-	 *
1922
-	 * @param Integer $blog_id
1923
-	 * @param unknown_type $task_id
1924
-	 */
1925
-	public static function display_select_task_post($blog_id, $task_id)
1914
+            Database::query($sql);
1915
+        }
1916
+    }
1917
+
1918
+    /**
1919
+     * Displays a list with posts a user can select to execute his task.
1920
+     *
1921
+     * @param Integer $blog_id
1922
+     * @param unknown_type $task_id
1923
+     */
1924
+    public static function display_select_task_post($blog_id, $task_id)
1926 1925
     {
1927
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1928
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1929
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1930
-		$course_id = api_get_course_int_id();
1926
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1927
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
1928
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1929
+        $course_id = api_get_course_int_id();
1931 1930
 
1932 1931
 
1933
-		$sql = "SELECT title, description FROM $tbl_blogs_tasks
1932
+        $sql = "SELECT title, description FROM $tbl_blogs_tasks
1934 1933
 				WHERE task_id = '".(int)$task_id."'
1935 1934
 				AND c_id = $course_id";
1936
-		$result = Database::query($sql);
1937
-		$row = Database::fetch_assoc($result);
1938
-		// Get posts and authors
1939
-		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
1935
+        $result = Database::query($sql);
1936
+        $row = Database::fetch_assoc($result);
1937
+        // Get posts and authors
1938
+        $sql = "SELECT post.*, user.lastname, user.firstname, user.username
1940 1939
 				FROM $tbl_blogs_posts post
1941 1940
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1942 1941
 				WHERE post.blog_id = '".(int)$blog_id."' AND post.c_id = $course_id
1943 1942
 				ORDER BY post_id DESC
1944 1943
 				LIMIT 0, 100";
1945
-		$result = Database::query($sql);
1944
+        $result = Database::query($sql);
1946 1945
 
1947
-		// Display
1948
-		echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1949
-		echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1946
+        // Display
1947
+        echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1948
+        echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1950 1949
 
1951
-		if (Database::num_rows($result) > 0) {
1952
-			while($blog_post = Database::fetch_array($result)) {
1953
-			    $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1954
-				echo '<a href="blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '<br />';
1955
-			}
1950
+        if (Database::num_rows($result) > 0) {
1951
+            while($blog_post = Database::fetch_array($result)) {
1952
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1953
+                echo '<a href="blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '<br />';
1954
+            }
1956 1955
         } else {
1957 1956
             echo get_lang('NoArticles');
1958 1957
         }
1959
-	}
1960
-
1961
-	/**
1962
-	 * Subscribes a user to a given blog
1963
-	 * @author Toon Keppens
1964
-	 *
1965
-	 * @param Integer $blog_id
1966
-	 * @param Integer $user_id
1967
-	 */
1968
-	public static function set_user_subscribed($blog_id, $user_id)
1958
+    }
1959
+
1960
+    /**
1961
+     * Subscribes a user to a given blog
1962
+     * @author Toon Keppens
1963
+     *
1964
+     * @param Integer $blog_id
1965
+     * @param Integer $user_id
1966
+     */
1967
+    public static function set_user_subscribed($blog_id, $user_id)
1969 1968
     {
1970
-		// Init
1971
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1972
-		$tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1969
+        // Init
1970
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
1971
+        $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
1973 1972
 
1974
-		$course_id = api_get_course_int_id();
1973
+        $course_id = api_get_course_int_id();
1975 1974
 
1976
-		// Subscribe the user
1977
-		$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1975
+        // Subscribe the user
1976
+        $sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1978 1977
 		        VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
1979
-		Database::query($sql);
1978
+        Database::query($sql);
1980 1979
 
1981
-		// Give this user basic rights
1982
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1980
+        // Give this user basic rights
1981
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1983 1982
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
1984
-		Database::query($sql);
1983
+        Database::query($sql);
1985 1984
 
1986 1985
         $id = Database::insert_id();
1987 1986
         if ($id) {
@@ -1989,9 +1988,9 @@  discard block
 block discarded – undo
1989 1988
             Database::query($sql);
1990 1989
         }
1991 1990
 
1992
-		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1991
+        $sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1993 1992
 		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
1994
-		Database::query($sql);
1993
+        Database::query($sql);
1995 1994
 
1996 1995
         $id = Database::insert_id();
1997 1996
         if ($id) {
@@ -1999,197 +1998,197 @@  discard block
 block discarded – undo
1999 1998
             Database::query($sql);
2000 1999
         }
2001 2000
 
2002
-	}
2001
+    }
2003 2002
 
2004
-	/**
2005
-	 * Unsubscribe a user from a given blog
2006
-	 * @author Toon Keppens
2007
-	 *
2008
-	 * @param Integer $blog_id
2009
-	 * @param Integer $user_id
2010
-	 */
2011
-	public static function set_user_unsubscribed($blog_id, $user_id)
2003
+    /**
2004
+     * Unsubscribe a user from a given blog
2005
+     * @author Toon Keppens
2006
+     *
2007
+     * @param Integer $blog_id
2008
+     * @param Integer $user_id
2009
+     */
2010
+    public static function set_user_unsubscribed($blog_id, $user_id)
2012 2011
     {
2013
-		// Init
2012
+        // Init
2014 2013
         $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2015 2014
         $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
2016 2015
 
2017
-		// Unsubscribe the user
2018
-		$sql = "DELETE FROM $tbl_blogs_rel_user
2016
+        // Unsubscribe the user
2017
+        $sql = "DELETE FROM $tbl_blogs_rel_user
2019 2018
 		        WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
2020
-		Database::query($sql);
2019
+        Database::query($sql);
2021 2020
 
2022
-		// Remove this user's permissions.
2023
-		$sql = "DELETE FROM $tbl_user_permissions
2021
+        // Remove this user's permissions.
2022
+        $sql = "DELETE FROM $tbl_user_permissions
2024 2023
 		        WHERE user_id = '".(int)$user_id."'";
2025
-		Database::query($sql);
2026
-	}
2027
-
2028
-	/**
2029
-	 * Displays the form to register users in a blog (in a course)
2030
-	 * The listed users are users subcribed in the course.
2031
-	 * @author Toon Keppens
2032
-	 *
2033
-	 * @param Integer $blog_id
2034
-	 *
2035
-	 * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2036
-	 */
2037
-	public static function display_form_user_subscribe($blog_id)
2038
-	{
2039
-		$_course = api_get_course_info();
2040
-		$is_western_name_order = api_is_western_name_order();
2041
-		$session_id = api_get_session_id();
2042
-		$course_id = $_course['real_id'];
2043
-
2044
-		$currentCourse = $_course['code'];
2045
-		$tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2046
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2047
-
2048
-		echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2049
-
2050
-		$properties["width"] = "100%";
2051
-
2052
-		// Get blog members' id.
2053
-		$sql = "SELECT user.user_id FROM $tbl_users user
2024
+        Database::query($sql);
2025
+    }
2026
+
2027
+    /**
2028
+     * Displays the form to register users in a blog (in a course)
2029
+     * The listed users are users subcribed in the course.
2030
+     * @author Toon Keppens
2031
+     *
2032
+     * @param Integer $blog_id
2033
+     *
2034
+     * @return Html Form with sortable table with users to subcribe in a blog, in a course.
2035
+     */
2036
+    public static function display_form_user_subscribe($blog_id)
2037
+    {
2038
+        $_course = api_get_course_info();
2039
+        $is_western_name_order = api_is_western_name_order();
2040
+        $session_id = api_get_session_id();
2041
+        $course_id = $_course['real_id'];
2042
+
2043
+        $currentCourse = $_course['code'];
2044
+        $tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2045
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2046
+
2047
+        echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
2048
+
2049
+        $properties["width"] = "100%";
2050
+
2051
+        // Get blog members' id.
2052
+        $sql = "SELECT user.user_id FROM $tbl_users user
2054 2053
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2055 2054
 				ON user.user_id = blogs_rel_user.user_id
2056 2055
 				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".intval($blog_id)."'";
2057
-		$result = Database::query($sql);
2058
-
2059
-		$blog_member_ids = array();
2060
-		while($user = Database::fetch_array($result)) {
2061
-			$blog_member_ids[] = $user['user_id'];
2062
-		}
2063
-
2064
-		// Set table headers
2065
-		$column_header[] = array ('', false, '');
2066
-		if ($is_western_name_order) {
2067
-			$column_header[] = array(get_lang('FirstName'), true, '');
2068
-			$column_header[] = array(get_lang('LastName'), true, '');
2069
-		} else {
2070
-			$column_header[] = array(get_lang('LastName'), true, '');
2071
-			$column_header[] = array(get_lang('FirstName'), true, '');
2072
-		}
2073
-		$column_header[] = array(get_lang('Email'), false, '');
2074
-		$column_header[] = array(get_lang('Register'), false, '');
2056
+        $result = Database::query($sql);
2057
+
2058
+        $blog_member_ids = array();
2059
+        while($user = Database::fetch_array($result)) {
2060
+            $blog_member_ids[] = $user['user_id'];
2061
+        }
2062
+
2063
+        // Set table headers
2064
+        $column_header[] = array ('', false, '');
2065
+        if ($is_western_name_order) {
2066
+            $column_header[] = array(get_lang('FirstName'), true, '');
2067
+            $column_header[] = array(get_lang('LastName'), true, '');
2068
+        } else {
2069
+            $column_header[] = array(get_lang('LastName'), true, '');
2070
+            $column_header[] = array(get_lang('FirstName'), true, '');
2071
+        }
2072
+        $column_header[] = array(get_lang('Email'), false, '');
2073
+        $column_header[] = array(get_lang('Register'), false, '');
2075 2074
 
2076 2075
         $student_list = CourseManager:: get_student_list_from_course_code(
2077 2076
             $currentCourse,
2078 2077
             false,
2079 2078
             $session_id
2080 2079
         );
2081
-		$user_data = array();
2082
-
2083
-		// Add users that are not in this blog to the list.
2084
-		foreach ($student_list as $key=>$user) {
2085
-			if(isset($user['id_user'])) {
2086
-				$user['user_id'] = $user['id_user'];
2087
-			}
2088
-			if(!in_array($user['user_id'],$blog_member_ids)) {
2089
-				$a_infosUser = api_get_user_info($user['user_id']);
2090
-				$row = array ();
2091
-				$row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2092
-				$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2093
-				if ($is_western_name_order) {
2094
-					$row[] = $a_infosUser["firstname"];
2095
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2096
-				} else {
2097
-					$row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2098
-					$row[] = $a_infosUser["firstname"];
2099
-				}
2100
-				$row[] = Display::icon_mailto_link($a_infosUser["email"]);
2101
-
2102
-				//Link to register users
2103
-				if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2104
-					$row[] = "<a class=\"btn btn-primary \" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
2105
-				} else {
2106
-					$row[] = '';
2107
-				}
2108
-				$user_data[] = $row;
2109
-			}
2110
-		}
2111
-
2112
-		// Display
2113
-		$query_vars['action'] = 'manage_members';
2114
-		$query_vars['blog_id'] = $blog_id;
2115
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2116
-			Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2117
-			$link = '';
2118
-			$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2119
-			$link .= "blog_id=$blog_id&";
2120
-
2121
-			echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2122
-			echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2123
-			echo get_lang('WithSelected') . ' : ';
2124
-			echo '<select name="action">';
2125
-			echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2126
-			echo '</select>';
2127
-			echo '<input type="hidden" name="register" value="true" />';
2128
-			echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2129
-		echo '</form>';
2130
-	}
2131
-
2132
-	/**
2133
-	 * Displays the form to register users in a blog (in a course)
2134
-	 * The listed users are users subcribed in the course.
2135
-	 * @author Toon Keppens
2136
-	 *
2137
-	 * @param Integer $blog_id
2138
-	 *
2139
-	 * @return Html Form with sortable table with users to unsubcribe from a blog.
2140
-	 */
2141
-	public static function display_form_user_unsubscribe ($blog_id)
2142
-	{
2143
-		$_user = api_get_user_info();
2144
-		$is_western_name_order = api_is_western_name_order();
2145
-
2146
-		// Init
2147
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2148
-		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2149
-
2150
-		echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2151
-
2152
-		$properties["width"] = "100%";
2153
-		//table column titles
2154
-		$column_header[] = array ('', false, '');
2155
-		if ($is_western_name_order) {
2156
-			$column_header[] = array (get_lang('FirstName'), true, '');
2157
-			$column_header[] = array (get_lang('LastName'), true, '');
2158
-		} else {
2159
-			$column_header[] = array (get_lang('LastName'), true, '');
2160
-			$column_header[] = array (get_lang('FirstName'), true, '');
2161
-		}
2162
-		$column_header[] = array (get_lang('Email'), false, '');
2163
-		$column_header[] = array (get_lang('TaskManager'), true, '');
2164
-		$column_header[] = array (get_lang('UnRegister'), false, '');
2165
-
2166
-		$course_id = api_get_course_int_id();
2167
-
2168
-		$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2080
+        $user_data = array();
2081
+
2082
+        // Add users that are not in this blog to the list.
2083
+        foreach ($student_list as $key=>$user) {
2084
+            if(isset($user['id_user'])) {
2085
+                $user['user_id'] = $user['id_user'];
2086
+            }
2087
+            if(!in_array($user['user_id'],$blog_member_ids)) {
2088
+                $a_infosUser = api_get_user_info($user['user_id']);
2089
+                $row = array ();
2090
+                $row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2091
+                $username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2092
+                if ($is_western_name_order) {
2093
+                    $row[] = $a_infosUser["firstname"];
2094
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2095
+                } else {
2096
+                    $row[] = Display::tag('span', $a_infosUser["lastname"], array('title'=>$username));
2097
+                    $row[] = $a_infosUser["firstname"];
2098
+                }
2099
+                $row[] = Display::icon_mailto_link($a_infosUser["email"]);
2100
+
2101
+                //Link to register users
2102
+                if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2103
+                    $row[] = "<a class=\"btn btn-primary \" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
2104
+                } else {
2105
+                    $row[] = '';
2106
+                }
2107
+                $user_data[] = $row;
2108
+            }
2109
+        }
2110
+
2111
+        // Display
2112
+        $query_vars['action'] = 'manage_members';
2113
+        $query_vars['blog_id'] = $blog_id;
2114
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2115
+            Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2116
+            $link = '';
2117
+            $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2118
+            $link .= "blog_id=$blog_id&";
2119
+
2120
+            echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2121
+            echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2122
+            echo get_lang('WithSelected') . ' : ';
2123
+            echo '<select name="action">';
2124
+            echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2125
+            echo '</select>';
2126
+            echo '<input type="hidden" name="register" value="true" />';
2127
+            echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2128
+        echo '</form>';
2129
+    }
2130
+
2131
+    /**
2132
+     * Displays the form to register users in a blog (in a course)
2133
+     * The listed users are users subcribed in the course.
2134
+     * @author Toon Keppens
2135
+     *
2136
+     * @param Integer $blog_id
2137
+     *
2138
+     * @return Html Form with sortable table with users to unsubcribe from a blog.
2139
+     */
2140
+    public static function display_form_user_unsubscribe ($blog_id)
2141
+    {
2142
+        $_user = api_get_user_info();
2143
+        $is_western_name_order = api_is_western_name_order();
2144
+
2145
+        // Init
2146
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2147
+        $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2148
+
2149
+        echo '<legend>'.get_lang('UnsubscribeMembers').'</legend>';
2150
+
2151
+        $properties["width"] = "100%";
2152
+        //table column titles
2153
+        $column_header[] = array ('', false, '');
2154
+        if ($is_western_name_order) {
2155
+            $column_header[] = array (get_lang('FirstName'), true, '');
2156
+            $column_header[] = array (get_lang('LastName'), true, '');
2157
+        } else {
2158
+            $column_header[] = array (get_lang('LastName'), true, '');
2159
+            $column_header[] = array (get_lang('FirstName'), true, '');
2160
+        }
2161
+        $column_header[] = array (get_lang('Email'), false, '');
2162
+        $column_header[] = array (get_lang('TaskManager'), true, '');
2163
+        $column_header[] = array (get_lang('UnRegister'), false, '');
2164
+
2165
+        $course_id = api_get_course_int_id();
2166
+
2167
+        $sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2169 2168
                 FROM $tbl_users user INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2170 2169
                 ON user.user_id = blogs_rel_user.user_id
2171 2170
                 WHERE blogs_rel_user.c_id = $course_id AND  blogs_rel_user.blog_id = '".(int)$blog_id."'";
2172 2171
 
2173
-		if (!($sql_result = Database::query($sql))) {
2174
-			return false;
2175
-		}
2176
-
2177
-		$user_data = array ();
2178
-
2179
-		while ($myrow = Database::fetch_array($sql_result)) {
2180
-			$row = array ();
2181
-			$row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2182
-			$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2183
-			if ($is_western_name_order) {
2184
-				$row[] = $myrow["firstname"];
2185
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2186
-			} else {
2187
-				$row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2188
-				$row[] = $myrow["firstname"];
2189
-			}
2190
-			$row[] = Display::icon_mailto_link($myrow["email"]);
2191
-
2192
-			$sql = "SELECT bt.title task
2172
+        if (!($sql_result = Database::query($sql))) {
2173
+            return false;
2174
+        }
2175
+
2176
+        $user_data = array ();
2177
+
2178
+        while ($myrow = Database::fetch_array($sql_result)) {
2179
+            $row = array ();
2180
+            $row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2181
+            $username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2182
+            if ($is_western_name_order) {
2183
+                $row[] = $myrow["firstname"];
2184
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2185
+            } else {
2186
+                $row[] = Display::tag('span', $myrow["lastname"], array('title'=>$username));
2187
+                $row[] = $myrow["firstname"];
2188
+            }
2189
+            $row[] = Display::icon_mailto_link($myrow["email"]);
2190
+
2191
+            $sql = "SELECT bt.title task
2193 2192
 					FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER) . " btu
2194 2193
 					INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS) . " bt
2195 2194
 					ON btu.task_id = bt.task_id
@@ -2197,158 +2196,158 @@  discard block
 block discarded – undo
2197 2196
 							bt.c_id 	= $course_id  AND
2198 2197
 							btu.blog_id = $blog_id AND
2199 2198
 							btu.user_id = " . $myrow['user_id'];
2200
-			$sql_res = Database::query($sql);
2201
-
2202
-			$task = '';
2203
-
2204
-			while($r = Database::fetch_array($sql_res)) {
2205
-				$task .= stripslashes($r['task']) . ', ';
2206
-			}
2207
-			//echo $task;
2208
-			$task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2209
-			$row[] = $task;
2210
-			//Link to register users
2211
-
2212
-			if ($myrow["user_id"] != $_user['user_id']) {
2213
-				$row[] = "<a class=\"btn btn-primary\" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=" . $myrow['user_id']."\">" . get_lang('UnRegister')."</a>";
2214
-			} else {
2215
-				$row[] = '';
2216
-			}
2217
-
2218
-			$user_data[] = $row;
2219
-		}
2220
-
2221
-		$query_vars['action'] = 'manage_members';
2222
-		$query_vars['blog_id'] = $blog_id;
2223
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2224
-		Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2225
-		$link = '';
2226
-		$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2227
-		$link .= "blog_id=$blog_id&";
2228
-
2229
-		echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2230
-		echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2231
-		echo get_lang('WithSelected') . ' : ';
2232
-		echo '<select name="action">';
2233
-		echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2234
-		echo '</select>';
2235
-		echo '<input type="hidden" name="unregister" value="true" />';
2236
-		echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2237
-		echo '</form>';
2238
-	}
2239
-
2240
-	/**
2241
-	 * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2242
-	 * The blog admin can thus select what a certain user can do in the current blog
2243
-	 *
2244
-	 * @param Integer $blog_id
2245
-	 */
2246
-	public static function display_form_user_rights ($blog_id)
2199
+            $sql_res = Database::query($sql);
2200
+
2201
+            $task = '';
2202
+
2203
+            while($r = Database::fetch_array($sql_res)) {
2204
+                $task .= stripslashes($r['task']) . ', ';
2205
+            }
2206
+            //echo $task;
2207
+            $task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
2208
+            $row[] = $task;
2209
+            //Link to register users
2210
+
2211
+            if ($myrow["user_id"] != $_user['user_id']) {
2212
+                $row[] = "<a class=\"btn btn-primary\" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=" . $myrow['user_id']."\">" . get_lang('UnRegister')."</a>";
2213
+            } else {
2214
+                $row[] = '';
2215
+            }
2216
+
2217
+            $user_data[] = $row;
2218
+        }
2219
+
2220
+        $query_vars['action'] = 'manage_members';
2221
+        $query_vars['blog_id'] = $blog_id;
2222
+        echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2223
+        Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2224
+        $link = '';
2225
+        $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2226
+        $link .= "blog_id=$blog_id&";
2227
+
2228
+        echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2229
+        echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2230
+        echo get_lang('WithSelected') . ' : ';
2231
+        echo '<select name="action">';
2232
+        echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2233
+        echo '</select>';
2234
+        echo '<input type="hidden" name="unregister" value="true" />';
2235
+        echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2236
+        echo '</form>';
2237
+    }
2238
+
2239
+    /**
2240
+     * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
2241
+     * The blog admin can thus select what a certain user can do in the current blog
2242
+     *
2243
+     * @param Integer $blog_id
2244
+     */
2245
+    public static function display_form_user_rights ($blog_id)
2246
+    {
2247
+        echo '<legend>'.get_lang('RightsManager').'</legend>';
2248
+        echo '<br />';
2249
+
2250
+        // Integration of patricks permissions system.
2251
+        require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2252
+    }
2253
+
2254
+    /**
2255
+     * Displays the form to create a new post
2256
+     * @author Toon Keppens
2257
+     *
2258
+     * @param Integer $blog_id
2259
+     */
2260
+    public static function display_new_comment_form($blog_id, $post_id, $title)
2247 2261
     {
2248
-		echo '<legend>'.get_lang('RightsManager').'</legend>';
2249
-		echo '<br />';
2250
-
2251
-		// Integration of patricks permissions system.
2252
-		require_once api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php';
2253
-	}
2254
-
2255
-	/**
2256
-	 * Displays the form to create a new post
2257
-	 * @author Toon Keppens
2258
-	 *
2259
-	 * @param Integer $blog_id
2260
-	 */
2261
-	public static function display_new_comment_form($blog_id, $post_id, $title)
2262
-	{
2263
-		$form = new FormValidator(
2264
-			'add_post',
2265
-			'post',
2266
-			api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=" . intval($blog_id)  . "&post_id=".intval($post_id)."&".api_get_cidreq(),
2267
-			null,
2268
-			array('enctype' => 'multipart/form-data')
2269
-		);
2270
-
2271
-		$header = get_lang('AddNewComment');
2272
-		if (isset($_GET['task_id'])) {
2273
-			$header = get_lang('ExecuteThisTask');
2274
-		}
2275
-		$form->addHeader($header);
2276
-		$form->addText('title', get_lang('Title'));
2277
-
2278
-		$config = array();
2279
-		if (!api_is_allowed_to_edit()) {
2280
-			$config['ToolbarSet'] = 'ProjectComment';
2281
-		} else {
2282
-			$config['ToolbarSet'] = 'ProjectCommentStudent';
2283
-		}
2284
-		$form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2285
-		$form->addFile('user_upload', get_lang('AddAnAttachment'));
2286
-
2287
-		$form->addTextarea('post_file_comment', get_lang('FileComment'));
2288
-
2289
-		$form->addHidden('action', null);
2290
-		$form->addHidden('comment_parent_id', 0);
2291
-
2292
-		if (isset($_GET['task_id'])) {
2293
-			$form->addHidden('new_task_execution_submit', 'true');
2294
-			$form->addHidden('task_id', intval($_GET['task_id']));
2295
-		} else {
2296
-			$form->addHidden('new_comment_submit', 'true');
2297
-		}
2298
-		$form->addButton('save', get_lang('Save'));
2299
-		$form->display();
2300
-	}
2301
-
2302
-
2303
-	/**
2304
-	 * show the calender of the given month
2305
-	 * @author Patrick Cool
2306
-	 * @author Toon Keppens
2307
-	 *
2308
-	 * @param Array $blogitems an array containing all the blog items for the given month
2309
-	 * @param Integer $month: the integer value of the month we are viewing
2310
-	 * @param Integer $year: the 4-digit year indication e.g. 2005
2311
-	 * @param String $monthName: the language variable for the mont name
2312
-	 *
2313
-	 * @return html code
2314
-	*/
2315
-	public static function display_minimonthcalendar($month, $year, $blog_id)
2316
-	{
2317
-		// Init
2318
-		$_user = api_get_user_info();
2319
-		global $DaysShort;
2320
-		global $MonthsLong;
2321
-
2322
-		$posts = array();
2323
-		$tasks = array();
2324
-
2325
-		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2326
-		$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2327
-		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2328
-		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2329
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2330
-
2331
-		$course_id = api_get_course_int_id();
2332
-
2333
-		//Handle leap year
2334
-		$numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2335
-
2336
-		if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2337
-			$numberofdays[2] = 29;
2338
-
2339
-		//Get the first day of the month
2340
-		$dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2341
-		$monthName = $MonthsLong[$month-1];
2342
-
2343
-		//Start the week on monday
2344
-		$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2345
-		$blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2346
-		$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2347
-		$backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2348
-		$forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2349
-
2350
-		// Get posts for this month
2351
-		$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2262
+        $form = new FormValidator(
2263
+            'add_post',
2264
+            'post',
2265
+            api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=" . intval($blog_id)  . "&post_id=".intval($post_id)."&".api_get_cidreq(),
2266
+            null,
2267
+            array('enctype' => 'multipart/form-data')
2268
+        );
2269
+
2270
+        $header = get_lang('AddNewComment');
2271
+        if (isset($_GET['task_id'])) {
2272
+            $header = get_lang('ExecuteThisTask');
2273
+        }
2274
+        $form->addHeader($header);
2275
+        $form->addText('title', get_lang('Title'));
2276
+
2277
+        $config = array();
2278
+        if (!api_is_allowed_to_edit()) {
2279
+            $config['ToolbarSet'] = 'ProjectComment';
2280
+        } else {
2281
+            $config['ToolbarSet'] = 'ProjectCommentStudent';
2282
+        }
2283
+        $form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
2284
+        $form->addFile('user_upload', get_lang('AddAnAttachment'));
2285
+
2286
+        $form->addTextarea('post_file_comment', get_lang('FileComment'));
2287
+
2288
+        $form->addHidden('action', null);
2289
+        $form->addHidden('comment_parent_id', 0);
2290
+
2291
+        if (isset($_GET['task_id'])) {
2292
+            $form->addHidden('new_task_execution_submit', 'true');
2293
+            $form->addHidden('task_id', intval($_GET['task_id']));
2294
+        } else {
2295
+            $form->addHidden('new_comment_submit', 'true');
2296
+        }
2297
+        $form->addButton('save', get_lang('Save'));
2298
+        $form->display();
2299
+    }
2300
+
2301
+
2302
+    /**
2303
+     * show the calender of the given month
2304
+     * @author Patrick Cool
2305
+     * @author Toon Keppens
2306
+     *
2307
+     * @param Array $blogitems an array containing all the blog items for the given month
2308
+     * @param Integer $month: the integer value of the month we are viewing
2309
+     * @param Integer $year: the 4-digit year indication e.g. 2005
2310
+     * @param String $monthName: the language variable for the mont name
2311
+     *
2312
+     * @return html code
2313
+     */
2314
+    public static function display_minimonthcalendar($month, $year, $blog_id)
2315
+    {
2316
+        // Init
2317
+        $_user = api_get_user_info();
2318
+        global $DaysShort;
2319
+        global $MonthsLong;
2320
+
2321
+        $posts = array();
2322
+        $tasks = array();
2323
+
2324
+        $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2325
+        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
2326
+        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
2327
+        $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
2328
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2329
+
2330
+        $course_id = api_get_course_int_id();
2331
+
2332
+        //Handle leap year
2333
+        $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2334
+
2335
+        if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2336
+            $numberofdays[2] = 29;
2337
+
2338
+        //Get the first day of the month
2339
+        $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2340
+        $monthName = $MonthsLong[$month-1];
2341
+
2342
+        //Start the week on monday
2343
+        $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2344
+        $blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2345
+        $filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2346
+        $backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2347
+        $forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2348
+
2349
+        // Get posts for this month
2350
+        $sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
2352 2351
 				FROM $tbl_blogs_posts post
2353 2352
 				INNER JOIN $tbl_users user
2354 2353
 				ON post.author_id = user.user_id
@@ -2358,20 +2357,20 @@  discard block
 block discarded – undo
2358 2357
 					MONTH(date_creation) = '".(int)$month."' AND
2359 2358
 					YEAR(date_creation) = '".(int)$year."'
2360 2359
 				ORDER BY date_creation";
2361
-		$result = Database::query($sql);
2362
-
2363
-		// We will create an array of days on which there are posts.
2364
-		if( Database::num_rows($result) > 0) {
2365
-			while($blog_post = Database::fetch_array($result)) {
2366
-				// If the day of this post is not yet in the array, add it.
2367
-				if (!in_array($blog_post['post_day'], $posts))
2368
-					$posts[] = $blog_post['post_day'];
2369
-			}
2370
-		}
2371
-
2372
-		// Get tasks for this month
2373
-		if ($_user['user_id']) {
2374
-			$sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2360
+        $result = Database::query($sql);
2361
+
2362
+        // We will create an array of days on which there are posts.
2363
+        if( Database::num_rows($result) > 0) {
2364
+            while($blog_post = Database::fetch_array($result)) {
2365
+                // If the day of this post is not yet in the array, add it.
2366
+                if (!in_array($blog_post['post_day'], $posts))
2367
+                    $posts[] = $blog_post['post_day'];
2368
+            }
2369
+        }
2370
+
2371
+        // Get tasks for this month
2372
+        if ($_user['user_id']) {
2373
+            $sql = " SELECT task_rel_user.*,  DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
2375 2374
 				FROM $tbl_blogs_tasks_rel_user task_rel_user
2376 2375
 				INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
2377 2376
 				INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
@@ -2383,85 +2382,85 @@  discard block
 block discarded – undo
2383 2382
 					MONTH(target_date) = '".(int)$month."' AND
2384 2383
 					YEAR(target_date) = '".(int)$year."'
2385 2384
 				ORDER BY target_date ASC";
2386
-			$result = Database::query($sql);
2387
-
2388
-			if (Database::num_rows($result) > 0) {
2389
-				while ($mytask = Database::fetch_array($result)) {
2390
-					$tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2391
-					$tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2392
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2393
-					$tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2394
-					$tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2395
-				}
2396
-			}
2397
-		}
2398
-
2399
-		echo 	'<table id="smallcalendar" class="table table-responsive">',
2400
-				"<tr id=\"title\">",
2401
-				"<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>",
2402
-				"<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>",
2403
-				"<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>", "</tr>";
2404
-
2405
-		echo "<tr>";
2406
-
2407
-		for($ii = 1; $ii < 8; $ii ++)
2408
-			echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2409
-
2410
-		echo "</tr>";
2411
-
2412
-		$curday = -1;
2413
-		$today = getdate();
2414
-
2415
-		while ($curday <= $numberofdays[$month]) {
2416
-			echo "<tr>";
2417
-			for ($ii = 0; $ii < 7; $ii ++) {
2418
-				if (($curday == -1) && ($ii == $startdayofweek))
2419
-					$curday = 1;
2420
-
2421
-			 	if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2422
-					$bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2423
-					$dayheader = "$curday";
2424
-
2425
-					if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2426
-						$dayheader = "$curday";
2427
-						$class = "class=\"days_today\"";
2428
-					}
2429
-
2430
-					echo "<td " . $class.">";
2431
-
2432
-					// If there are posts on this day, create a filter link.
2433
-					if(in_array($curday, $posts))
2434
-						echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2435
-					else
2436
-						echo $dayheader;
2437
-
2438
-					if (count($tasks) > 0) {
2439
-						if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2440
-							// Add tasks to calendar
2441
-							foreach ($tasks[$curday] as $task) {
2442
-								echo '<a href="blog.php?action=execute_task&blog_id=' . $task['blog_id'] . '&task_id='.stripslashes($task['task_id']) . '" title="' . $task['title'] . ' : ' . get_lang('InBlog') . ' : ' . $task['blog_name'] . ' - ' . get_lang('ExecuteThisTask') . '">';
2443
-								echo Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask'));
2385
+            $result = Database::query($sql);
2386
+
2387
+            if (Database::num_rows($result) > 0) {
2388
+                while ($mytask = Database::fetch_array($result)) {
2389
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
2390
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
2391
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
2392
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
2393
+                    $tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
2394
+                }
2395
+            }
2396
+        }
2397
+
2398
+        echo 	'<table id="smallcalendar" class="table table-responsive">',
2399
+                "<tr id=\"title\">",
2400
+                "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&laquo;</a></th>",
2401
+                "<th align=\"center\" width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>",
2402
+                "<th width=\"10%\" align=\"right\"><a href=\"", $forewardsURL, "\">&raquo;</a></th>", "</tr>";
2403
+
2404
+        echo "<tr>";
2405
+
2406
+        for($ii = 1; $ii < 8; $ii ++)
2407
+            echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2408
+
2409
+        echo "</tr>";
2410
+
2411
+        $curday = -1;
2412
+        $today = getdate();
2413
+
2414
+        while ($curday <= $numberofdays[$month]) {
2415
+            echo "<tr>";
2416
+            for ($ii = 0; $ii < 7; $ii ++) {
2417
+                if (($curday == -1) && ($ii == $startdayofweek))
2418
+                    $curday = 1;
2419
+
2420
+                    if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2421
+                    $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2422
+                    $dayheader = "$curday";
2423
+
2424
+                    if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2425
+                        $dayheader = "$curday";
2426
+                        $class = "class=\"days_today\"";
2427
+                    }
2428
+
2429
+                    echo "<td " . $class.">";
2430
+
2431
+                    // If there are posts on this day, create a filter link.
2432
+                    if(in_array($curday, $posts))
2433
+                        echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2434
+                    else
2435
+                        echo $dayheader;
2436
+
2437
+                    if (count($tasks) > 0) {
2438
+                        if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2439
+                            // Add tasks to calendar
2440
+                            foreach ($tasks[$curday] as $task) {
2441
+                                echo '<a href="blog.php?action=execute_task&blog_id=' . $task['blog_id'] . '&task_id='.stripslashes($task['task_id']) . '" title="' . $task['title'] . ' : ' . get_lang('InBlog') . ' : ' . $task['blog_name'] . ' - ' . get_lang('ExecuteThisTask') . '">';
2442
+                                echo Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask'));
2444 2443
                                 echo '</a>';
2445
-							}
2446
-						}
2447
-					}
2448
-
2449
-					echo "</td>";
2450
-					$curday ++;
2451
-				} else
2452
-					echo "<td>&nbsp;</td>";
2453
-			}
2454
-			echo "</tr>";
2455
-		}
2456
-		echo "</table>";
2457
-	}
2458
-
2459
-	/**
2460
-	 * Blog admin | Display the form to add a new blog.
2461
-	 *
2462
-	 */
2463
-	public static function display_new_blog_form()
2464
-	{
2444
+                            }
2445
+                        }
2446
+                    }
2447
+
2448
+                    echo "</td>";
2449
+                    $curday ++;
2450
+                } else
2451
+                    echo "<td>&nbsp;</td>";
2452
+            }
2453
+            echo "</tr>";
2454
+        }
2455
+        echo "</table>";
2456
+    }
2457
+
2458
+    /**
2459
+     * Blog admin | Display the form to add a new blog.
2460
+     *
2461
+     */
2462
+    public static function display_new_blog_form()
2463
+    {
2465 2464
         $form = new FormValidator('add_blog', 'post', 'blog_admin.php?action=add');
2466 2465
         $form->addElement('header', get_lang('AddBlog'));
2467 2466
         $form->addElement('text', 'blog_name', get_lang('Title'));
@@ -2471,34 +2470,34 @@  discard block
 block discarded – undo
2471 2470
         $form->addButtonSave(get_lang('SaveProject'));
2472 2471
 
2473 2472
         $defaults = array(
2474
-			'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2475
-        	'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2476
-		);
2473
+            'blog_name' => isset($_POST['blog_name']) ? Security::remove_XSS($_POST['blog_name']) : null,
2474
+            'blog_subtitle' => isset($_POST['blog_subtitle']) ? Security::remove_XSS($_POST['blog_subtitle']) : null
2475
+        );
2477 2476
         $form->setDefaults($defaults);
2478 2477
         $form->display();
2479
-	}
2480
-
2481
-	/**
2482
-	 * Blog admin | Display the form to edit a blog.
2483
-	 *
2484
-	 */
2485
-	public static function display_edit_blog_form($blog_id)
2486
-	{
2487
-	    $course_id = api_get_course_int_id();
2488
-		$blog_id= intval($blog_id);
2489
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2490
-
2491
-		$sql = "SELECT blog_id, blog_name, blog_subtitle
2478
+    }
2479
+
2480
+    /**
2481
+     * Blog admin | Display the form to edit a blog.
2482
+     *
2483
+     */
2484
+    public static function display_edit_blog_form($blog_id)
2485
+    {
2486
+        $course_id = api_get_course_int_id();
2487
+        $blog_id= intval($blog_id);
2488
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2489
+
2490
+        $sql = "SELECT blog_id, blog_name, blog_subtitle
2492 2491
 		        FROM $tbl_blogs
2493 2492
 		        WHERE c_id = $course_id AND blog_id = '".$blog_id."'";
2494
-		$result = Database::query($sql);
2495
-		$blog = Database::fetch_array($result);
2493
+        $result = Database::query($sql);
2494
+        $blog = Database::fetch_array($result);
2496 2495
 
2497
-		// the form contained errors but we do not want to lose the changes the user already did
2498
-		if ($_POST) {
2499
-			$blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2500
-			$blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2501
-		}
2496
+        // the form contained errors but we do not want to lose the changes the user already did
2497
+        if ($_POST) {
2498
+            $blog['blog_name'] = Security::remove_XSS($_POST['blog_name']);
2499
+            $blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2500
+        }
2502 2501
 
2503 2502
         $form = new FormValidator('edit_blog', 'post','blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']));
2504 2503
         $form->addElement('header', get_lang('EditBlog'));
@@ -2514,76 +2513,76 @@  discard block
 block discarded – undo
2514 2513
         $defaults['blog_subtitle'] = $blog['blog_subtitle'];
2515 2514
         $form->setDefaults($defaults);
2516 2515
         $form->display();
2517
-	}
2516
+    }
2518 2517
 
2519
-	/**
2520
-	 * Blog admin | Returns table with blogs in this course
2521
-	 */
2522
-	public static function display_blog_list()
2518
+    /**
2519
+     * Blog admin | Returns table with blogs in this course
2520
+     */
2521
+    public static function display_blog_list()
2523 2522
     {
2524
-		global $charset;
2525
-		$_user = api_get_user_info();
2523
+        global $charset;
2524
+        $_user = api_get_user_info();
2526 2525
         $course_id = api_get_course_int_id();
2527 2526
 
2528
-		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2527
+        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2529 2528
 
2530
-		//condition for the session
2531
-		$session_id = api_get_session_id();
2529
+        //condition for the session
2530
+        $session_id = api_get_session_id();
2532 2531
 
2533
-		$sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2532
+        $sql = "SELECT blog_name, blog_subtitle, visibility, blog_id, session_id
2534 2533
 				FROM $tbl_blogs WHERE c_id = $course_id
2535 2534
 				ORDER BY date_creation DESC";
2536
-		$result = Database::query($sql);
2537
-		$list_info = array();
2538
-		if (Database::num_rows($result)) {
2539
-			while ($row_project=Database::fetch_row($result)) {
2540
-				$list_info[]=$row_project;
2541
-			}
2542
-		}
2543
-
2544
-		$list_content_blog = array();
2545
-		$list_body_blog = array();
2546
-
2547
-		if (is_array($list_info)) {
2548
-			foreach ($list_info as $key => $info_log) {
2549
-				// Validation when belongs to a session
2550
-				$session_img = api_get_session_image($info_log[4], $_user['status']);
2551
-
2552
-				$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2553
-				$title = $info_log[0];
2535
+        $result = Database::query($sql);
2536
+        $list_info = array();
2537
+        if (Database::num_rows($result)) {
2538
+            while ($row_project=Database::fetch_row($result)) {
2539
+                $list_info[]=$row_project;
2540
+            }
2541
+        }
2542
+
2543
+        $list_content_blog = array();
2544
+        $list_body_blog = array();
2545
+
2546
+        if (is_array($list_info)) {
2547
+            foreach ($list_info as $key => $info_log) {
2548
+                // Validation when belongs to a session
2549
+                $session_img = api_get_session_image($info_log[4], $_user['status']);
2550
+
2551
+                $url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2552
+                $title = $info_log[0];
2554 2553
                         $image = Display::return_icon('blog.png', $title);
2555
-    			$list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">' . $image . '</a></div><a href="'.$url_start_blog.'">' .$title. '</a>' . $session_img;
2554
+                $list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">' . $image . '</a></div><a href="'.$url_start_blog.'">' .$title. '</a>' . $session_img;
2556 2555
 
2557
-				$list_body_blog[] = $list_name;
2558
-				$list_body_blog[] = $info_log[1];
2556
+                $list_body_blog[] = $list_name;
2557
+                $list_body_blog[] = $info_log[1];
2559 2558
 
2560
-				$visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2561
-				$visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2562
-			 	$my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2559
+                $visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2560
+                $visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2561
+                    $my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2563 2562
                                 $my_image.= Display::return_icon('edit.png', get_lang('EditBlog'));
2564 2563
 
2565
-				$my_image.= "</a>";
2566
-				$my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2567
-				$my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2564
+                $my_image.= "</a>";
2565
+                $my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2566
+                $my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2568 2567
                                 $my_image.= Display::return_icon('delete.png', get_lang('DeleteBlog'));
2569 2568
 
2570
-				$my_image.= "</a>";
2571
-				$my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2569
+                $my_image.= "</a>";
2570
+                $my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2572 2571
                                 $my_image.= Display::return_icon($visibility_icon . '.gif', get_lang($visibility_info));
2573 2572
 
2574
-				$my_image.= "</a>";
2575
-				$list_body_blog[]=$my_image;
2576
-				$list_content_blog[]=$list_body_blog;
2577
-				$list_body_blog = array();
2578
-			}
2579
-
2580
-			$table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2581
-			$table->set_header(0, get_lang('Title'));
2582
-			$table->set_header(1, get_lang('SubTitle'));
2583
-			$table->set_header(2, get_lang('Modify'));
2584
-			$table->display();
2585
-		}
2586
-	}
2573
+                $my_image.= "</a>";
2574
+                $list_body_blog[]=$my_image;
2575
+                $list_content_blog[]=$list_body_blog;
2576
+                $list_body_blog = array();
2577
+            }
2578
+
2579
+            $table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2580
+            $table->set_header(0, get_lang('Title'));
2581
+            $table->set_header(1, get_lang('SubTitle'));
2582
+            $table->set_header(2, get_lang('Modify'));
2583
+            $table->display();
2584
+        }
2585
+    }
2587 2586
 }
2588 2587
 
2589 2588
 /**
@@ -2603,34 +2602,34 @@  discard block
 block discarded – undo
2603 2602
  */
2604 2603
 function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
2605 2604
 {
2606
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2607
-
2608
-	$blog_id = intval($blog_id);
2609
-	$comment_id = intval($comment_id);
2610
-	$post_id = intval($post_id);
2611
-	$row=array();
2612
-	$where='';
2613
-	if (!empty ($post_id) && is_numeric($post_id)) {
2614
-		$where.=' AND post_id ="'.$post_id.'" ';
2615
-	}
2616
-
2617
-	if (!empty ($comment_id) && is_numeric($comment_id)) {
2618
-		if (!empty ($post_id)) {
2619
-			$where.= ' AND ';
2620
-		}
2621
-		$where.=' comment_id ="'.$comment_id.'" ';
2622
-	}
2605
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2606
+
2607
+    $blog_id = intval($blog_id);
2608
+    $comment_id = intval($comment_id);
2609
+    $post_id = intval($post_id);
2610
+    $row=array();
2611
+    $where='';
2612
+    if (!empty ($post_id) && is_numeric($post_id)) {
2613
+        $where.=' AND post_id ="'.$post_id.'" ';
2614
+    }
2615
+
2616
+    if (!empty ($comment_id) && is_numeric($comment_id)) {
2617
+        if (!empty ($post_id)) {
2618
+            $where.= ' AND ';
2619
+        }
2620
+        $where.=' comment_id ="'.$comment_id.'" ';
2621
+    }
2623 2622
 
2624 2623
     $course_id = api_get_course_int_id();
2625 2624
 
2626
-	$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2625
+    $sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2627 2626
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2628 2627
 
2629
-	$result=Database::query($sql);
2630
-	if (Database::num_rows($result)!=0) {
2631
-		$row=Database::fetch_array($result);
2632
-	}
2633
-	return $row;
2628
+    $result=Database::query($sql);
2629
+    if (Database::num_rows($result)!=0) {
2630
+        $row=Database::fetch_array($result);
2631
+    }
2632
+    return $row;
2634 2633
 }
2635 2634
 
2636 2635
 /**
@@ -2644,16 +2643,16 @@  discard block
 block discarded – undo
2644 2643
 
2645 2644
 function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
2646 2645
 {
2647
-	$_course = api_get_course_info();
2648
-	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2649
-	$blog_id = intval($blog_id);
2650
-	$comment_id = intval($comment_id);
2651
-	$post_id = intval($post_id);
2646
+    $_course = api_get_course_info();
2647
+    $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2648
+    $blog_id = intval($blog_id);
2649
+    $comment_id = intval($comment_id);
2650
+    $post_id = intval($post_id);
2652 2651
 
2653 2652
     $course_id = api_get_course_int_id();
2654
-	$where = null;
2653
+    $where = null;
2655 2654
 
2656
-	// delete files in DB
2655
+    // delete files in DB
2657 2656
     if (!empty ($post_id) && is_numeric($post_id)) {
2658 2657
         $where .= ' AND post_id ="'.$post_id.'" ';
2659 2658
     }
@@ -2665,25 +2664,25 @@  discard block
 block discarded – undo
2665 2664
         $where .= ' comment_id ="'.$comment_id.'" ';
2666 2665
     }
2667 2666
 
2668
-	// delete all files in directory
2669
-	$courseDir   = $_course['path'].'/upload/blog';
2670
-	$sys_course_path = api_get_path(SYS_COURSE_PATH);
2671
-	$updir = $sys_course_path.$courseDir;
2667
+    // delete all files in directory
2668
+    $courseDir   = $_course['path'].'/upload/blog';
2669
+    $sys_course_path = api_get_path(SYS_COURSE_PATH);
2670
+    $updir = $sys_course_path.$courseDir;
2672 2671
 
2673
-	$sql = 'SELECT path FROM '.$blog_table_attachment.'
2672
+    $sql = 'SELECT path FROM '.$blog_table_attachment.'
2674 2673
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2675
-	$result=Database::query($sql);
2676
-
2677
-	while ($row=Database::fetch_row($result)) {
2678
-		$file=$updir.'/'.$row[0];
2679
-		if (Security::check_abs_path($file,$updir) )
2680
-		{
2681
-			@ unlink($file);
2682
-		}
2683
-	}
2684
-	$sql = 'DELETE FROM '. $blog_table_attachment.'
2674
+    $result=Database::query($sql);
2675
+
2676
+    while ($row=Database::fetch_row($result)) {
2677
+        $file=$updir.'/'.$row[0];
2678
+        if (Security::check_abs_path($file,$updir) )
2679
+        {
2680
+            @ unlink($file);
2681
+        }
2682
+    }
2683
+    $sql = 'DELETE FROM '. $blog_table_attachment.'
2685 2684
 	        WHERE c_id = '.$course_id.' AND  blog_id ="'.intval($blog_id).'"  '.$where;
2686
-	Database::query($sql);
2685
+    Database::query($sql);
2687 2686
 }
2688 2687
 
2689 2688
 /**
@@ -2693,12 +2692,12 @@  discard block
 block discarded – undo
2693 2692
  */
2694 2693
 function get_blog_post_from_user($course_code, $user_id)
2695 2694
 {
2696
-	$tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2697
-	$tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2698
-	$course_info 	= api_get_course_info($course_code);
2699
-	$course_id 		= $course_info['real_id'];
2695
+    $tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2696
+    $tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2697
+    $course_info 	= api_get_course_info($course_code);
2698
+    $course_id 		= $course_info['real_id'];
2700 2699
 
2701
-	$sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2700
+    $sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
2702 2701
 			FROM $tbl_blogs blog
2703 2702
 			INNER JOIN  $tbl_blog_post post
2704 2703
 			ON (blog.blog_id = post.blog_id)
@@ -2707,19 +2706,19 @@  discard block
 block discarded – undo
2707 2706
 				post.c_id = $course_id AND
2708 2707
 				author_id =  $user_id AND visibility = 1
2709 2708
 			ORDER BY post.date_creation DESC ";
2710
-	$result = Database::query($sql);
2711
-	$return_data = '';
2712
-
2713
-	if (Database::num_rows($result)!=0) {
2714
-		while ($row=Database::fetch_array($result)) {
2715
-			$return_data.=  '<div class="clear"></div><br />';
2716
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png',get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2717
-			$return_data.=  '<br / >';
2718
-			$return_data.= $row['full_text'];
2719
-			$return_data.= '<br /><br />';
2720
-		}
2721
-	}
2722
-	return $return_data;
2709
+    $result = Database::query($sql);
2710
+    $return_data = '';
2711
+
2712
+    if (Database::num_rows($result)!=0) {
2713
+        while ($row=Database::fetch_array($result)) {
2714
+            $return_data.=  '<div class="clear"></div><br />';
2715
+            $return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png',get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2716
+            $return_data.=  '<br / >';
2717
+            $return_data.= $row['full_text'];
2718
+            $return_data.= '<br /><br />';
2719
+        }
2720
+    }
2721
+    return $return_data;
2723 2722
 }
2724 2723
 
2725 2724
 /**
@@ -2736,7 +2735,7 @@  discard block
 block discarded – undo
2736 2735
     $course_info = api_get_course_info($course_code);
2737 2736
     $course_id = $course_info['real_id'];
2738 2737
 
2739
-	$sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2738
+    $sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation
2740 2739
 			FROM $tbl_blogs blog INNER JOIN  $tbl_blog_comment comment
2741 2740
 			ON (blog.blog_id = comment.blog_id)
2742 2741
 			WHERE 	blog.c_id = $course_id AND
@@ -2744,18 +2743,18 @@  discard block
 block discarded – undo
2744 2743
 					author_id =  $user_id AND
2745 2744
 					visibility = 1
2746 2745
 			ORDER BY blog_name";
2747
-	$result = Database::query($sql);
2748
-	$return_data = '';
2749
-	if (Database::num_rows($result)!=0) {
2750
-		while ($row=Database::fetch_array($result)) {
2751
-			$return_data.=  '<div class="clear"></div><br />';
2752
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2753
-			$return_data.=  '<br / >';
2754
-			//$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2755
-			$return_data.=  $row['comment'];
2756
-			$return_data.=  '<br />';
2757
-		}
2758
-	}
2759
-	return $return_data;
2746
+    $result = Database::query($sql);
2747
+    $return_data = '';
2748
+    if (Database::num_rows($result)!=0) {
2749
+        while ($row=Database::fetch_array($result)) {
2750
+            $return_data.=  '<div class="clear"></div><br />';
2751
+            $return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2752
+            $return_data.=  '<br / >';
2753
+            //$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2754
+            $return_data.=  $row['comment'];
2755
+            $return_data.=  '<br />';
2756
+        }
2757
+    }
2758
+    return $return_data;
2760 2759
 }
2761 2760
 
Please login to merge, or discard this patch.
Spacing   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @return String Blog Title
23 23
 	 */
24
-	public static function get_blog_title ($blog_id)
24
+	public static function get_blog_title($blog_id)
25 25
 	{
26 26
 	    $course_id = api_get_course_int_id();
27 27
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 			$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
30 30
 
31 31
 			$sql = "SELECT blog_name
32
-					FROM " . $tbl_blogs . "
33
-					WHERE c_id = $course_id AND blog_id = " . intval($blog_id);
32
+					FROM " . $tbl_blogs."
33
+					WHERE c_id = $course_id AND blog_id = ".intval($blog_id);
34 34
 
35 35
 			$result = Database::query($sql);
36 36
 			$blog = Database::fetch_array($result);
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
 
79 79
 		// Get blog members
80 80
 		$sql = "SELECT user.user_id, user.firstname, user.lastname
81
-				FROM " . $tbl_blogs_rel_user . " blogs_rel_user
82
-				INNER JOIN " . $tbl_users . " user
81
+				FROM " . $tbl_blogs_rel_user." blogs_rel_user
82
+				INNER JOIN " . $tbl_users." user
83 83
 				ON blogs_rel_user.user_id = user.user_id
84 84
 				WHERE
85 85
 				    blogs_rel_user.c_id = $course_id AND
86
-					blogs_rel_user.blog_id = '" . (int)$blog_id."'";
86
+					blogs_rel_user.blog_id = '".(int) $blog_id."'";
87 87
 		$result = Database::query($sql);
88
-		$blog_members = array ();
89
-		while($user = Database::fetch_array($result)) {
88
+		$blog_members = array();
89
+		while ($user = Database::fetch_array($result)) {
90 90
 			$blog_members[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
91 91
 		}
92 92
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		$_user = api_get_user_info();
106 106
         $course_id = api_get_course_int_id();
107 107
 
108
-		$current_date=date('Y-m-d H:i:s',time());
108
+		$current_date = date('Y-m-d H:i:s', time());
109 109
 		$session_id = api_get_session_id();
110 110
 		// Tabel definitions
111 111
         $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                 'blog_name' => $title,
130 130
                 'blog_subtitle' =>  $subtitle,
131 131
                 'date_creation' => $current_date,
132
-                'visibility' => 1 ,
132
+                'visibility' => 1,
133 133
                 'session_id' => $session_id,
134 134
             ];
135 135
 			$this_blog_id = Database::insert($tbl_blogs, $params);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 
169 169
 			// Put it on course homepage
170 170
 			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id, target)
171
-					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')";
171
+					VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int) $this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id', '')";
172 172
 			Database::query($sql);
173 173
 
174 174
             $toolId = Database::insert_id();
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		        blog_subtitle = '".Database::escape_string($subtitle)."'
204 204
 		        WHERE
205 205
 		            c_id = $course_id AND
206
-		            blog_id ='".Database::escape_string((int)$blog_id)."'
206
+		            blog_id ='".Database::escape_string((int) $blog_id)."'
207 207
                 LIMIT 1";
208 208
 		Database::query($sql);
209 209
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		// Update course homepage link
220 220
 		$sql = "UPDATE $tbl_tool SET
221 221
 		        name = '".Database::escape_string($title)."'
222
-		        WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int)$blog_id."' LIMIT 1";
222
+		        WHERE c_id = $course_id AND link = 'blog/blog.php?blog_id=".(int) $blog_id."' LIMIT 1";
223 223
 		Database::query($sql);
224 224
 	}
225 225
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 		Database::query($sql);
262 262
 
263 263
 		// Delete blog
264
-		$sql ="DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
264
+		$sql = "DELETE FROM $tbl_blogs WHERE c_id = $course_id AND blog_id ='".$blog_id."'";
265 265
 		Database::query($sql);
266 266
 
267 267
 		// Delete from course homepage
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
 		$course_id = $_course['real_id'];
293 293
 
294 294
 		$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
295
-		$upload_ok=true;
296
-		$has_attachment=false;
295
+		$upload_ok = true;
296
+		$has_attachment = false;
297 297
 		$current_date = api_get_utc_datetime();
298 298
 
299 299
 		if (!empty($_FILES['user_upload']['name'])) {
300 300
 			$upload_ok = process_uploaded_file($_FILES['user_upload']);
301
-			$has_attachment=true;
301
+			$has_attachment = true;
302 302
 		}
303 303
 
304 304
 		if ($upload_ok) {
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 
308 308
 			// Create the post
309 309
 			$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
310
-					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');";
310
+					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."','".$current_date."', '".(int) $blog_id."', '".(int) $_user['user_id']."');";
311 311
 
312 312
 			Database::query($sql);
313 313
 			$last_post_id = Database::insert_id();
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
             }
319 319
 
320 320
 			if ($has_attachment) {
321
-				$courseDir   = $_course['path'].'/upload/blog';
321
+				$courseDir = $_course['path'].'/upload/blog';
322 322
 				$sys_course_path = api_get_path(SYS_COURSE_PATH);
323 323
 				$updir = $sys_course_path.$courseDir;
324 324
 
@@ -369,9 +369,9 @@  discard block
 block discarded – undo
369 369
 
370 370
 		// Create the post
371 371
 		$sql = "UPDATE $tbl_blogs_posts SET
372
-		        title = '" . Database::escape_string($title)."',
372
+		        title = '".Database::escape_string($title)."',
373 373
 		        full_text = '" . Database::escape_string($full_text)."'
374
-		        WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."'
374
+		        WHERE c_id = $course_id AND post_id ='".(int) $post_id."' AND blog_id ='".(int) $blog_id."'
375 375
 		        LIMIT 1 ";
376 376
 		Database::query($sql);
377 377
 	}
@@ -392,21 +392,21 @@  discard block
 block discarded – undo
392 392
 
393 393
 		// Delete ratings on this comment
394 394
 		$sql = "DELETE FROM $tbl_blogs_rating
395
-				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'";
395
+				WHERE c_id = $course_id AND blog_id = '".(int) $blog_id."' AND item_id = '".(int) $post_id."' AND rating_type = 'post'";
396 396
 		Database::query($sql);
397 397
 
398 398
 		// Delete the post
399 399
 		$sql = "DELETE FROM $tbl_blogs_posts
400
-				WHERE c_id = $course_id AND post_id = '".(int)$post_id."'";
400
+				WHERE c_id = $course_id AND post_id = '".(int) $post_id."'";
401 401
 		Database::query($sql);
402 402
 
403 403
 		// Delete the comments
404 404
 		$sql = "DELETE FROM $tbl_blogs_comments
405
-				WHERE c_id = $course_id AND post_id = '".(int)$post_id."' AND blog_id = '".(int)$blog_id."'";
405
+				WHERE c_id = $course_id AND post_id = '".(int) $post_id."' AND blog_id = '".(int) $blog_id."'";
406 406
 		Database::query($sql);
407 407
 
408 408
 		// Delete posts and attachments
409
-		delete_all_blog_attachment($blog_id,$post_id);
409
+		delete_all_blog_attachment($blog_id, $post_id);
410 410
 	}
411 411
 
412 412
 	/**
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	{
423 423
 		$_user = api_get_user_info();
424 424
 		$_course = api_get_course_info();
425
-        $blog_table_attachment 	= Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
425
+        $blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
426 426
 
427 427
         $upload_ok = true;
428 428
         $has_attachment = false;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 
432 432
 		if (!empty($_FILES['user_upload']['name'])) {
433 433
 			$upload_ok = process_uploaded_file($_FILES['user_upload']);
434
-			$has_attachment=true;
434
+			$has_attachment = true;
435 435
 		}
436 436
 
437 437
 		if ($upload_ok) {
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
 			// Create the comment
442 442
 			$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
443
-					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
443
+					VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($full_text)."', '".(int) $_user['user_id']."','".$current_date."', '".(int) $blog_id."', '".(int) $post_id."', '".(int) $parent_id."', '".(int) $task_id."')";
444 444
 			Database::query($sql);
445 445
 
446 446
 			// Empty post values, or they are shown on the page again
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
             }
453 453
 
454 454
 			if ($has_attachment) {
455
-				$courseDir   = $_course['path'].'/upload/blog';
455
+				$courseDir = $_course['path'].'/upload/blog';
456 456
 				$sys_course_path = api_get_path(SYS_COURSE_PATH);
457 457
 				$updir = $sys_course_path.$courseDir;
458 458
 
@@ -463,19 +463,19 @@  discard block
 block discarded – undo
463 463
 				);
464 464
 
465 465
 				// user's file name
466
-				$file_name =$_FILES['user_upload']['name'];
466
+				$file_name = $_FILES['user_upload']['name'];
467 467
 
468 468
 				if (!filter_extension($new_file_name)) {
469 469
 					Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
470 470
 				} else {
471 471
 					$new_file_name = uniqid('');
472
-					$new_path=$updir.'/'.$new_file_name;
473
-					$result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
472
+					$new_path = $updir.'/'.$new_file_name;
473
+					$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
474 474
 					$comment = Database::escape_string($file_comment);
475 475
 
476 476
 					// Storing the attachments if any
477 477
 					if ($result) {
478
-						$sql='INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
478
+						$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size,blog_id,comment_id) '.
479 479
 							 "VALUES ($course_id, '".Database::escape_string($file_name)."', '".$comment."', '".Database::escape_string($new_file_name)."' , '".$post_id."', '".$_FILES['user_upload']['size']."',  '".$blog_id."', '".$last_id."'  )";
480 480
 						Database::query($sql);
481 481
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 
525 525
 		// Delete them recursively
526 526
 		while ($comment = Database::fetch_array($result)) {
527
-			Blog::delete_comment($blog_id,$post_id,$comment['comment_id']);
527
+			Blog::delete_comment($blog_id, $post_id, $comment['comment_id']);
528 528
 		}
529 529
 
530 530
 		// Finally, delete the selected comment to
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 
551 551
 		// Create the task
552 552
 		$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task)
553
-				VALUES ($course_id , '".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');";
553
+				VALUES ($course_id , '".(int) $blog_id."', '".Database::escape_string($title)."', '".Database::escape_string($description)."', '".Database::escape_string($color)."', '0');";
554 554
 		Database::query($sql);
555 555
 
556 556
 		$task_id = Database::insert_id();
@@ -560,13 +560,13 @@  discard block
 block discarded – undo
560 560
             Database::query($sql);
561 561
         }
562 562
 
563
-		$tool = 'BLOG_' . $blog_id;
563
+		$tool = 'BLOG_'.$blog_id;
564 564
 
565 565
 		if ($articleDelete == 'on') {
566
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " ( c_id,  task_id, tool, action) VALUES (
567
-					'" . (int)$course_id . "',
568
-					'" . (int)$task_id . "',
569
-					'" . Database::escape_string($tool) . "',
566
+			$sql = " INSERT INTO ".$tbl_tasks_permissions." ( c_id,  task_id, tool, action) VALUES (
567
+					'" . (int) $course_id."',
568
+					'" . (int) $task_id."',
569
+					'" . Database::escape_string($tool)."',
570 570
 					'article_delete'
571 571
 				)";
572 572
 			Database::query($sql);
@@ -581,10 +581,10 @@  discard block
 block discarded – undo
581 581
 
582 582
 		if ($articleEdit == 'on') {
583 583
 			$sql = "
584
-				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
585
-					'" . (int)$course_id . "',
586
-					'" . (int)$task_id . "',
587
-					'" . Database::escape_string($tool) . "',
584
+				INSERT INTO " . $tbl_tasks_permissions." (c_id, task_id, tool, action ) VALUES (
585
+					'" . (int) $course_id."',
586
+					'" . (int) $task_id."',
587
+					'" . Database::escape_string($tool)."',
588 588
 					'article_edit'
589 589
 				)";
590 590
 			Database::query($sql);
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 
599 599
 		if ($commentsDelete == 'on') {
600 600
 			$sql = "
601
-				INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action ) VALUES (
602
-					'" . (int)$course_id . "',
603
-					'" . (int)$task_id . "',
604
-					'" . Database::escape_string($tool) . "',
601
+				INSERT INTO " . $tbl_tasks_permissions." (c_id, task_id, tool, action ) VALUES (
602
+					'" . (int) $course_id."',
603
+					'" . (int) $task_id."',
604
+					'" . Database::escape_string($tool)."',
605 605
 					'article_comments_delete'
606 606
 				)";
607 607
 			Database::query($sql);
@@ -634,20 +634,20 @@  discard block
 block discarded – undo
634 634
 					title = '".Database::escape_string($title)."',
635 635
 					description = '".Database::escape_string($description)."',
636 636
 					color = '".Database::escape_string($color)."'
637
-				WHERE c_id = $course_id AND task_id ='".(int)$task_id."' LIMIT 1";
637
+				WHERE c_id = $course_id AND task_id ='".(int) $task_id."' LIMIT 1";
638 638
 		Database::query($sql);
639 639
 
640
-		$tool = 'BLOG_' . $blog_id;
640
+		$tool = 'BLOG_'.$blog_id;
641 641
 
642
-		$sql = "DELETE FROM " . $tbl_tasks_permissions . "
643
-				WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
642
+		$sql = "DELETE FROM ".$tbl_tasks_permissions."
643
+				WHERE c_id = $course_id AND task_id = '".(int) $task_id."'";
644 644
 		Database::query($sql);
645 645
 
646 646
 		if ($articleDelete == 'on') {
647
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " ( c_id, task_id, tool, action) VALUES (
648
-					'" . (int)$course_id . "',
649
-					'" . (int)$task_id . "',
650
-					'" . Database::escape_string($tool) . "',
647
+			$sql = "INSERT INTO ".$tbl_tasks_permissions." ( c_id, task_id, tool, action) VALUES (
648
+					'" . (int) $course_id."',
649
+					'" . (int) $task_id."',
650
+					'" . Database::escape_string($tool)."',
651 651
 					'article_delete'
652 652
 				)";
653 653
 			Database::query($sql);
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 		}
661 661
 
662 662
 		if ($articleEdit == 'on') {
663
-			$sql = "INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
664
-					'" . (int)$course_id . "',
665
-					'" . (int)$task_id . "',
666
-					'" . Database::escape_string($tool) . "',
663
+			$sql = "INSERT INTO ".$tbl_tasks_permissions." (c_id, task_id, tool, action) VALUES (
664
+					'" . (int) $course_id."',
665
+					'" . (int) $task_id."',
666
+					'" . Database::escape_string($tool)."',
667 667
 					'article_edit'
668 668
 				)";
669 669
 			Database::query($sql);
@@ -676,10 +676,10 @@  discard block
 block discarded – undo
676 676
 		}
677 677
 
678 678
 		if ($commentsDelete == 'on') {
679
-			$sql = " INSERT INTO " . $tbl_tasks_permissions . " (c_id, task_id, tool, action) VALUES (
680
-					'" . (int)$course_id . "',
681
-					'" . (int)$task_id . "',
682
-					'" . Database::escape_string($tool) . "',
679
+			$sql = " INSERT INTO ".$tbl_tasks_permissions." (c_id, task_id, tool, action) VALUES (
680
+					'" . (int) $course_id."',
681
+					'" . (int) $task_id."',
682
+					'" . Database::escape_string($tool)."',
683 683
 					'article_comments_delete'
684 684
 				)";
685 685
 			Database::query($sql);
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 
705 705
 		// Delete posts
706 706
 		$sql = "DELETE FROM $tbl_blogs_tasks
707
-				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND task_id = '".(int)$task_id."'";
707
+				WHERE c_id = $course_id AND blog_id = '".(int) $blog_id."' AND task_id = '".(int) $task_id."'";
708 708
 		Database::query($sql);
709 709
 	}
710 710
 
@@ -722,9 +722,9 @@  discard block
 block discarded – undo
722 722
 		$sql = "DELETE FROM $tbl_blogs_tasks_rel_user
723 723
 				WHERE
724 724
 				    c_id = $course_id AND
725
-				    blog_id = '".(int)$blog_id."' AND
726
-				    task_id = '".(int)$task_id."' AND
727
-				    user_id = '".(int)$user_id."'";
725
+				    blog_id = '".(int) $blog_id."' AND
726
+				    task_id = '".(int) $task_id."' AND
727
+				    user_id = '".(int) $user_id."'";
728 728
 		Database::query($sql);
729 729
 	}
730 730
 
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		$_user = api_get_user_info();
739 739
 
740 740
 		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
741
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
741
+		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
742 742
 		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
743 743
 
744 744
 		$course_id = api_get_course_int_id();
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
                         task.c_id = $course_id AND
756 756
                         blog.c_id = $course_id AND
757 757
                         task_rel_user.c_id = $course_id AND
758
-                        task_rel_user.user_id = ".(int)$_user['user_id']."
758
+                        task_rel_user.user_id = ".(int) $_user['user_id']."
759 759
                     ORDER BY target_date ASC";
760 760
 
761 761
 			$result = Database::query($sql);
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			if (Database::num_rows($result) > 0) {
764 764
 				echo '<ul>';
765 765
 				while ($mytask = Database::fetch_array($result)) {
766
-					echo '<li><a href="blog.php?action=execute_task&blog_id=' . $mytask['blog_id'] . '&task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
766
+					echo '<li><a href="blog.php?action=execute_task&blog_id='.$mytask['blog_id'].'&task_id='.stripslashes($mytask['task_id']).'" title="[Blog: '.stripslashes($mytask['blog_name']).'] '.get_lang('ExecuteThisTask').'">'.stripslashes($mytask['title']).'</a></li>';
767 767
 				}
768 768
 				echo '<ul>';
769 769
 			} else {
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 		// Get blog properties
789 789
 		$sql = "SELECT blog_name, visibility FROM $tbl_blogs
790
-				WHERE c_id = $course_id AND blog_id='".(int)$blog_id."'";
790
+				WHERE c_id = $course_id AND blog_id='".(int) $blog_id."'";
791 791
 		$result = Database::query($sql);
792 792
 		$blog = Database::fetch_array($result);
793 793
 		$visibility = $blog['visibility'];
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 		if ($visibility == 1) {
797 797
 			// Change visibility state, remove from course home.
798 798
 			$sql = "UPDATE $tbl_blogs SET visibility = '0'
799
-					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
799
+					WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."' LIMIT 1";
800 800
 			Database::query($sql);
801 801
 
802 802
 			$sql = "DELETE FROM $tbl_tool
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
 		} else {
806 806
 			// Change visibility state, add to course home.
807 807
 			$sql = "UPDATE $tbl_blogs SET visibility = '1'
808
-					WHERE c_id = $course_id AND blog_id ='".(int)$blog_id."' LIMIT 1";
808
+					WHERE c_id = $course_id AND blog_id ='".(int) $blog_id."' LIMIT 1";
809 809
 			Database::query($sql);
810 810
 
811 811
 			$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, target )
812
-					VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
812
+					VALUES ($course_id, '".Database::escape_string($title)."', 'blog/blog.php?blog_id=".(int) $blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
813 813
 			Database::query($sql);
814 814
             $id = Database::insert_id();
815 815
 
@@ -840,14 +840,14 @@  discard block
 block discarded – undo
840 840
 		        FROM $tbl_blogs_posts post
841 841
                 INNER JOIN $tbl_users user
842 842
                 ON post.author_id = user.user_id
843
-				WHERE 	post.blog_id = '".(int)$blog_id."' AND
843
+				WHERE 	post.blog_id = '".(int) $blog_id."' AND
844 844
 						post.c_id = $course_id AND
845 845
 						$filter
846
-				ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
846
+				ORDER BY post_id DESC LIMIT 0,".(int) $max_number_of_posts;
847 847
 		$result = Database::query($sql);
848 848
 
849 849
 		// Display
850
-		if(Database::num_rows($result) > 0) {
850
+		if (Database::num_rows($result) > 0) {
851 851
 		    $limit = 200;
852 852
 			while ($blog_post = Database::fetch_array($result)) {
853 853
 				// Get number of comments
@@ -855,8 +855,8 @@  discard block
 block discarded – undo
855 855
 						FROM $tbl_blogs_comments
856 856
 						WHERE
857 857
 						    c_id = $course_id AND
858
-						    blog_id = '".(int)$blog_id."' AND
859
-						    post_id = '" . (int)$blog_post['post_id']."'";
858
+						    blog_id = '".(int) $blog_id."' AND
859
+						    post_id = '" . (int) $blog_post['post_id']."'";
860 860
 				$tmp = Database::query($sql);
861 861
 				$blog_post_comments = Database::fetch_array($tmp);
862 862
 
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
 
868 868
 				// Create an introduction text (but keep FULL sentences)
869 869
 				$words = 0;
870
-				$blog_post_text_cut = cut($blog_post_text, $limit) ;
870
+				$blog_post_text_cut = cut($blog_post_text, $limit);
871 871
 				$words = strlen($blog_post_text);
872 872
 
873 873
 				if ($words >= $limit) {
874
-					$readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</div>';
874
+					$readMoreLink = ' <div class="link" onclick="document.getElementById(\'blogpost_text_'.$blog_post_id.'\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_'.$blog_post_id.'\').style.display=\'none\'">'.get_lang('ReadMore').'</div>';
875 875
 					$introduction_text = $blog_post_text_cut;
876 876
 				} else {
877 877
 				    $introduction_text = $blog_post_text;
@@ -881,27 +881,27 @@  discard block
 block discarded – undo
881 881
 				$introduction_text = stripslashes($introduction_text);
882 882
 
883 883
 				echo '<div class="blogpost">';
884
-				echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
885
-				echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . $blog_post_date . '</a></span>';
886
-				echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">' . $introduction_text.$readMoreLink.'</div>';
887
-				echo '<div class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</div>';
884
+				echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$blog_post['post_id'].'#add_comment" title="'.get_lang('ReadPost').'" >'.stripslashes($blog_post['title']).'</a></span>';
885
+				echo '<span class="blogpost_date"><a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$blog_post['post_id'].'#add_comment" title="'.get_lang('ReadPost').'" >'.$blog_post_date.'</a></span>';
886
+				echo '<div class="blogpost_introduction" id="blogpost_introduction_'.$blog_post_id.'">'.$introduction_text.$readMoreLink.'</div>';
887
+				echo '<div class="blogpost_text" id="blogpost_text_'.$blog_post_id.'" style="display: none">'.$blog_post_text.'</div>';
888 888
 
889
-				$file_name_array = get_blog_attachment($blog_id,$blog_post_id,0);
889
+				$file_name_array = get_blog_attachment($blog_id, $blog_post_id, 0);
890 890
 
891 891
 				if (!empty($file_name_array)) {
892 892
 					echo '<br /><br />';
893
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
893
+					echo Display::return_icon('attachment.gif', get_lang('Attachment'));
894 894
 					echo '<a href="download.php?file=';
895 895
 					echo $file_name_array['path'];
896 896
 					echo ' "> '.$file_name_array['filename'].' </a><br />';
897 897
 					echo '</span>';
898 898
 				}
899 899
 				$username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
900
-				echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)) .' - <a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>';
900
+				echo '<span class="blogpost_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - <a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$blog_post['post_id'].'#add_comment" title="'.get_lang('ReadPost').'" >'.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].'</a></span>';
901 901
 				echo '</div>';
902 902
 			}
903 903
 		} else {
904
-			if($filter == '1=1') {
904
+			if ($filter == '1=1') {
905 905
 				echo get_lang('NoArticles');
906 906
 			} else {
907 907
 				echo get_lang('NoArticleMatches');
@@ -915,19 +915,19 @@  discard block
 block discarded – undo
915 915
 	 * @param Integer $blog_id
916 916
 	 * @param String $query_string
917 917
 	 */
918
-	public static function display_search_results ($blog_id, $query_string)
918
+	public static function display_search_results($blog_id, $query_string)
919 919
 	{
920 920
 		// Init
921 921
 		$query_string = Database::escape_string($query_string);
922
-		$query_string_parts = explode(' ',$query_string);
922
+		$query_string_parts = explode(' ', $query_string);
923 923
 		$query_string = array();
924 924
 		foreach ($query_string_parts as $query_part) {
925
-			$query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
925
+			$query_string[] = " full_text LIKE '%".$query_part."%' OR title LIKE '%".$query_part."%' ";
926 926
 		}
927
-		$query_string = '('.implode('OR',$query_string) . ')';
927
+		$query_string = '('.implode('OR', $query_string).')';
928 928
 
929 929
 		// Display the posts
930
-		echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
930
+		echo '<span class="blogpost_title">'.get_lang('SearchResults').'</span>';
931 931
 		Blog::display_blog_posts($blog_id, $query_string);
932 932
 	}
933 933
 
@@ -940,14 +940,14 @@  discard block
 block discarded – undo
940 940
 	public static function display_day_results($blog_id, $query_string)
941 941
 	{
942 942
 		$date_output = $query_string;
943
-		$date = explode('-',$query_string);
944
-		$query_string = ' DAYOFMONTH(date_creation) =' . intval($date[2]) . ' AND MONTH(date_creation) =' . intval($date[1]) . ' AND YEAR(date_creation) =' . intval($date[0]);
943
+		$date = explode('-', $query_string);
944
+		$query_string = ' DAYOFMONTH(date_creation) ='.intval($date[2]).' AND MONTH(date_creation) ='.intval($date[1]).' AND YEAR(date_creation) ='.intval($date[0]);
945 945
 
946 946
 		// Put date in correct output format
947 947
 		$date_output = api_format_date($date_output, DATE_FORMAT_LONG);
948 948
 
949 949
 		// Display the posts
950
-		echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
950
+		echo '<span class="blogpost_title">'.get_lang('PostsOf').': '.$date_output.'</span>';
951 951
 		Blog::display_blog_posts($blog_id, $query_string);
952 952
 	}
953 953
 
@@ -974,8 +974,8 @@  discard block
 block discarded – undo
974 974
 					ON post.author_id = user.user_id
975 975
                 WHERE
976 976
                     post.c_id = $course_id AND
977
-                    post.blog_id = '".(int)$blog_id."' AND
978
-                    post.post_id = '".(int)$post_id."'
977
+                    post.blog_id = '".(int) $blog_id."' AND
978
+                    post.post_id = '".(int) $post_id."'
979 979
                 ORDER BY post_id DESC";
980 980
 		$result = Database::query($sql);
981 981
 		$blog_post = Database::fetch_array($result);
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 		// Get number of comments
984 984
 		$sql = "SELECT COUNT(1) as number_of_comments
985 985
 		        FROM $tbl_blogs_comments
986
-				WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
986
+				WHERE c_id = $course_id AND blog_id = '".(int) $blog_id."' AND post_id = '".(int) $post_id."'";
987 987
 		$result = Database::query($sql);
988 988
 		$blog_post_comments = Database::fetch_array($result);
989 989
 
@@ -994,34 +994,34 @@  discard block
 block discarded – undo
994 994
 
995 995
 		$task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? intval($_GET['task_id']) : 0;
996 996
 
997
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id)) {
998
-			$blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '">';
999
-			$blog_post_actions .=  Display::return_icon('edit.png');
997
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_edit', $task_id)) {
998
+			$blog_post_actions .= '<a href="blog.php?action=edit_post&blog_id='.$blog_id.'&post_id='.$post_id.'&article_id='.$blog_post['post_id'].'&task_id='.$task_id.'" title="'.get_lang('EditThisPost').'">';
999
+			$blog_post_actions .= Display::return_icon('edit.png');
1000 1000
 			$blog_post_actions .= '</a>';
1001 1001
         }
1002 1002
 
1003
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id)) {
1004
-			$blog_post_actions .= '<a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $post_id . '&do=delete_article&article_id=' . $blog_post['post_id'] . '&task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;">';
1003
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_delete', $task_id)) {
1004
+			$blog_post_actions .= '<a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$post_id.'&do=delete_article&article_id='.$blog_post['post_id'].'&task_id='.$task_id.'" title="'.get_lang('DeleteThisArticle').'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;">';
1005 1005
             $blog_post_actions .= Display::return_icon('delete.png');
1006 1006
             $blog_post_actions .= '</a>';
1007 1007
         }
1008 1008
 
1009
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
1010
-			$rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
1009
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_rate'))
1010
+			$rating_select = Blog::display_rating_form('post', $blog_id, $post_id);
1011 1011
 
1012
-		$blog_post_text=stripslashes($blog_post_text);
1012
+		$blog_post_text = stripslashes($blog_post_text);
1013 1013
 
1014 1014
 		// Display post
1015 1015
 		echo '<div class="blogpost">';
1016
-		echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id=' . $blog_id . '&post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
1017
-		echo '<span class="blogpost_date">' . $blog_post_date . '</span>';
1018
-		echo '<span class="blogpost_text">' . $blog_post_text . '</span><br />';
1016
+		echo '<span class="blogpost_title"><a href="blog.php?action=view_post&blog_id='.$blog_id.'&post_id='.$blog_post['post_id'].'" title="'.get_lang('ReadPost').'" >'.stripslashes($blog_post['title']).'</a></span>';
1017
+		echo '<span class="blogpost_date">'.$blog_post_date.'</span>';
1018
+		echo '<span class="blogpost_text">'.$blog_post_text.'</span><br />';
1019 1019
 
1020 1020
 		$file_name_array = get_blog_attachment($blog_id, $post_id);
1021 1021
 
1022 1022
         if (!empty($file_name_array)) {
1023 1023
 			echo ' <br />';
1024
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1024
+			echo Display::return_icon('attachment.gif', get_lang('Attachment'));
1025 1025
 			echo '<a href="download.php?file=';
1026 1026
 			echo $file_name_array['path'];
1027 1027
 			echo ' "> '.$file_name_array['filename'].' </a>';
@@ -1032,20 +1032,20 @@  discard block
 block discarded – undo
1032 1032
 			echo '<br />';
1033 1033
 		}
1034 1034
         $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1035
-		echo '<span class="blogpost_info">'.get_lang('Author').': ' .Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post',$blog_id,$post_id).$rating_select.'</span>';
1036
-		echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
1035
+		echo '<span class="blogpost_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username)).' - '.get_lang('Comments').': '.$blog_post_comments['number_of_comments'].' - '.get_lang('Rating').': '.Blog::display_rating('post', $blog_id, $post_id).$rating_select.'</span>';
1036
+		echo '<span class="blogpost_actions">'.$blog_post_actions.'</span>';
1037 1037
 		echo '</div>';
1038 1038
 
1039 1039
 		// Display comments if there are any
1040
-		if($blog_post_comments['number_of_comments'] > 0) {
1040
+		if ($blog_post_comments['number_of_comments'] > 0) {
1041 1041
 			echo '<div class="comments">';
1042
-				echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
1042
+				echo '<span class="blogpost_title">'.get_lang('Comments').'</span><br />';
1043 1043
 				Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
1044 1044
 			echo '</div>';
1045 1045
 		}
1046 1046
 
1047 1047
 		// Display comment form
1048
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_comments_add')) {
1048
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_comments_add')) {
1049 1049
 			Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
1050 1050
 		}
1051 1051
 	}
@@ -1073,16 +1073,16 @@  discard block
 block discarded – undo
1073 1073
 		$sql = "SELECT rating_id FROM $tbl_blogs_rating
1074 1074
                 WHERE
1075 1075
                     c_id = $course_id AND
1076
-                    blog_id = '".(int)$blog_id."' AND
1077
-                    item_id = '".(int)$item_id."' AND
1076
+                    blog_id = '".(int) $blog_id."' AND
1077
+                    item_id = '".(int) $item_id."' AND
1078 1078
                     rating_type = '".Database::escape_string($type)."' AND
1079
-                    user_id = '".(int)$_user['user_id']."'";
1079
+                    user_id = '".(int) $_user['user_id']."'";
1080 1080
 		$result = Database::query($sql);
1081 1081
 
1082 1082
         // Add rating
1083 1083
 		if (Database::num_rows($result) == 0) {
1084 1084
 			$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
1085
-					VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
1085
+					VALUES ($course_id, '".(int) $blog_id."', '".Database::escape_string($type)."', '".(int) $item_id."', '".(int) $_user['user_id']."', '".Database::escape_string($rating)."')";
1086 1086
 			Database::query($sql);
1087 1087
 
1088 1088
             $id = Database::insert_id();
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
 		$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating
1116 1116
 				WHERE
1117 1117
 				    c_id = $course_id AND
1118
-				    blog_id = '".(int)$blog_id."' AND
1119
-				    item_id = '".(int)$item_id."' AND
1118
+				    blog_id = '".(int) $blog_id."' AND
1119
+				    item_id = '".(int) $item_id."' AND
1120 1120
 				    rating_type = '".Database::escape_string($type)."' ";
1121 1121
 		$result = Database::query($sql);
1122 1122
 		$result = Database::fetch_array($result);
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
 	 *
1134 1134
 	 *@return String
1135 1135
 	 */
1136
-	public static function display_rating_form ($type, $blog_id, $post_id, $comment_id = NULL)
1136
+	public static function display_rating_form($type, $blog_id, $post_id, $comment_id = NULL)
1137 1137
 	{
1138 1138
 		$_user = api_get_user_info();
1139 1139
 		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
@@ -1143,14 +1143,14 @@  discard block
 block discarded – undo
1143 1143
 			// Check if the user has already rated this post
1144 1144
 			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1145 1145
 					WHERE c_id = $course_id AND
1146
-					blog_id = '".(int)$blog_id."'
1147
-					AND item_id = '".(int)$post_id."'
1146
+					blog_id = '".(int) $blog_id."'
1147
+					AND item_id = '".(int) $post_id."'
1148 1148
 					AND rating_type = '".Database::escape_string($type)."'
1149
-					AND user_id = '".(int)$_user['user_id']."'";
1149
+					AND user_id = '".(int) $_user['user_id']."'";
1150 1150
 			$result = Database::query($sql);
1151 1151
             // Add rating
1152 1152
             if (Database::num_rows($result) == 0) {
1153
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
1153
+				return ' - '.get_lang('RateThis').': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$post_id.'" name="frm_rating_'.$type.'_'.$post_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$post_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /></form>';
1154 1154
             } else {
1155 1155
 				return '';
1156 1156
 			}
@@ -1159,14 +1159,14 @@  discard block
 block discarded – undo
1159 1159
         if ($type = 'comment') {
1160 1160
 			// Check if the user has already rated this comment
1161 1161
 			$sql = "SELECT rating_id FROM $tbl_blogs_rating
1162
-					WHERE c_id = $course_id AND blog_id = '".(int)$blog_id ."'
1163
-					AND item_id = '".(int)$comment_id."'
1162
+					WHERE c_id = $course_id AND blog_id = '".(int) $blog_id."'
1163
+					AND item_id = '".(int) $comment_id."'
1164 1164
 					AND rating_type = '".Database::escape_string($type)."'
1165
-					AND user_id = '".(int)$_user['user_id']."'";
1165
+					AND user_id = '".(int) $_user['user_id']."'";
1166 1166
 			$result = Database::query($sql);
1167 1167
 
1168 1168
             if (Database::num_rows($result) == 0) {
1169
-				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
1169
+				return ' - '.get_lang('RateThis').': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$comment_id.'" name="frm_rating_'.$type.'_'.$comment_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$comment_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /><input type="hidden" name="comment_id" value="'.$comment_id.'" /></form>';
1170 1170
             } else {
1171 1171
 				return '';
1172 1172
 			}
@@ -1201,11 +1201,11 @@  discard block
 block discarded – undo
1201 1201
                 WHERE
1202 1202
                     comments.c_id = $course_id AND
1203 1203
                     parent_comment_id = $current AND
1204
-                    comments.blog_id = '".(int)$blog_id."' AND
1205
-                    comments.post_id = '".(int)$post_id."'";
1204
+                    comments.blog_id = '".(int) $blog_id."' AND
1205
+                    comments.post_id = '".(int) $post_id."'";
1206 1206
 		$result = Database::query($sql);
1207 1207
 
1208
-		while($comment = Database::fetch_array($result)) {
1208
+		while ($comment = Database::fetch_array($result)) {
1209 1209
 			// Select the children recursivly
1210 1210
 			$tmp = "SELECT comments.*, user.lastname, user.firstname, user.username
1211 1211
 			        FROM $tbl_blogs_comments comments
@@ -1214,8 +1214,8 @@  discard block
 block discarded – undo
1214 1214
 					WHERE
1215 1215
 						comments.c_id = $course_id AND
1216 1216
 						comment_id = $current
1217
-						AND blog_id = '".(int)$blog_id."'
1218
-						AND post_id = '".(int)$post_id."'";
1217
+						AND blog_id = '".(int) $blog_id."'
1218
+						AND post_id = '".(int) $post_id."'";
1219 1219
 			$tmp = Database::query($tmp);
1220 1220
 			$tmp = Database::fetch_array($tmp);
1221 1221
 			$parent_cat = $tmp['parent_comment_id'];
@@ -1240,22 +1240,22 @@  discard block
 block discarded – undo
1240 1240
             }
1241 1241
 
1242 1242
 			if (!is_null($comment['task_id'])) {
1243
-				$border_color = ' border-left: 3px solid #' . $comment['color'];
1243
+				$border_color = ' border-left: 3px solid #'.$comment['color'];
1244 1244
 			}
1245 1245
 
1246 1246
 			$comment_text = stripslashes($comment_text);
1247 1247
 
1248 1248
 			// Output...
1249 1249
 			$margin = $current_level * 30;
1250
-			echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
1251
-				echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
1252
-				echo '<span class="blogpost_comment_date">' . $blog_comment_date . '</span>';
1253
-				echo '<span class="blogpost_text">' . $comment_text . '</span>';
1250
+			echo '<div class="blogpost_comment" style="margin-left: '.$margin.'px;'.$border_color.'">';
1251
+				echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\''.$comment['comment_id'].'\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']).'\'" title="'.get_lang('ReplyToThisComment').'" >'.stripslashes($comment['title']).'</a></span>';
1252
+				echo '<span class="blogpost_comment_date">'.$blog_comment_date.'</span>';
1253
+				echo '<span class="blogpost_text">'.$comment_text.'</span>';
1254 1254
 
1255
-				$file_name_array = get_blog_attachment($blog_id,$post_id, $comment['comment_id']);
1255
+				$file_name_array = get_blog_attachment($blog_id, $post_id, $comment['comment_id']);
1256 1256
 				if (!empty($file_name_array)) {
1257 1257
 					echo '<br /><br />';
1258
-					echo Display::return_icon('attachment.gif',get_lang('Attachment'));
1258
+					echo Display::return_icon('attachment.gif', get_lang('Attachment'));
1259 1259
 					echo '<a href="download.php?file=';
1260 1260
 					echo $file_name_array['path'];
1261 1261
 					echo ' "> '.$file_name_array['filename'].' </a>';
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
 				}
1266 1266
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $comment['username']), ENT_QUOTES);
1267 1267
 				echo '<span class="blogpost_comment_info">'.get_lang('Author').': '.Display::tag('span', api_get_person_name($comment['firstname'], $comment['lastname']), array('title'=>$username)).' - '.get_lang('Rating').': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']).$rating_select.'</span>';
1268
-				echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
1268
+				echo '<span class="blogpost_actions">'.$blog_comment_actions.'</span>';
1269 1269
 			echo '</div>';
1270 1270
 
1271 1271
 			// Go further down the tree.
@@ -1281,11 +1281,11 @@  discard block
 block discarded – undo
1281 1281
 	 */
1282 1282
 	public static function display_form_new_post($blog_id)
1283 1283
 	{
1284
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1284
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_add')) {
1285 1285
 			$form = new FormValidator(
1286 1286
 				'add_post',
1287 1287
 				'post',
1288
-				api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=" . $blog_id . "&" . api_get_cidreq(),
1288
+				api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=".$blog_id."&".api_get_cidreq(),
1289 1289
 				null,
1290 1290
 				array('enctype' => 'multipart/form-data')
1291 1291
 			);
@@ -1329,8 +1329,8 @@  discard block
 block discarded – undo
1329 1329
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1330 1330
 				WHERE
1331 1331
 				post.c_id 			= $course_id AND
1332
-				post.blog_id 		= '".(int)$blog_id ."'
1333
-				AND post.post_id	= '".(int)$post_id."'
1332
+				post.blog_id 		= '".(int) $blog_id."'
1333
+				AND post.post_id	= '".(int) $post_id."'
1334 1334
 				ORDER BY post_id DESC";
1335 1335
 		$result = Database::query($sql);
1336 1336
 		$blog_post = Database::fetch_array($result);
@@ -1339,7 +1339,7 @@  discard block
 block discarded – undo
1339 1339
 		$form = new FormValidator(
1340 1340
 			'edit_post',
1341 1341
 			'post',
1342
-			api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id=' . intval($_GET['post_id']) . '&blog_id=' . intval($blog_id) . '&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1342
+			api_get_path(WEB_CODE_PATH).'blog/blog.php?action=edit_post&post_id='.intval($_GET['post_id']).'&blog_id='.intval($blog_id).'&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id'])
1343 1343
 		);
1344 1344
 
1345 1345
 		$form->addHeader(get_lang('EditPost'));
@@ -1371,31 +1371,31 @@  discard block
 block discarded – undo
1371 1371
 		global $charset;
1372 1372
         $course_id = api_get_course_int_id();
1373 1373
 
1374
-		if (api_is_allowed('BLOG_' . $blog_id, 'article_add')) {
1374
+		if (api_is_allowed('BLOG_'.$blog_id, 'article_add')) {
1375 1375
 			$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1376 1376
 			$counter = 0;
1377 1377
 			global $color2;
1378 1378
 
1379 1379
 			echo '<div class="actions">';
1380
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=add">';
1380
+			echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$blog_id.'&do=add">';
1381 1381
             echo Display::return_icon('blog_newtasks.gif', get_lang('AddTasks'));
1382
-            echo get_lang('AddTasks') . '</a> ';
1383
-			echo '<a href="' .api_get_self(). '?action=manage_tasks&blog_id=' . $blog_id . '&do=assign">';
1382
+            echo get_lang('AddTasks').'</a> ';
1383
+			echo '<a href="'.api_get_self().'?action=manage_tasks&blog_id='.$blog_id.'&do=assign">';
1384 1384
             echo Display::return_icon('blog_task.gif', get_lang('AssignTasks'));
1385
-            echo get_lang('AssignTasks') . '</a>';
1385
+            echo get_lang('AssignTasks').'</a>';
1386 1386
 			?>
1387 1387
 				<a href="<?php echo api_get_self(); ?>?action=manage_rights&blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights') ?>">
1388
-                    <?php echo Display::return_icon('blog_admin_users.png', get_lang('RightsManager'),'',ICON_SIZE_SMALL). get_lang('RightsManager') ?></a>
1388
+                    <?php echo Display::return_icon('blog_admin_users.png', get_lang('RightsManager'), '', ICON_SIZE_SMALL).get_lang('RightsManager') ?></a>
1389 1389
 			<?php
1390 1390
 			echo '</div>';
1391 1391
 
1392
-			echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
1392
+			echo '<span class="blogpost_title">'.get_lang('TaskList').'</span><br />';
1393 1393
 			echo "<table class=\"data_table\">";
1394 1394
 			echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1395
-					 "<th width='240'><b>",get_lang('Title'),"</b></th>",
1396
-					 "<th><b>",get_lang('Description'),"</b></th>",
1397
-					 "<th><b>",get_lang('Color'),"</b></th>",
1398
-					 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1395
+					 "<th width='240'><b>", get_lang('Title'), "</b></th>",
1396
+					 "<th><b>", get_lang('Description'), "</b></th>",
1397
+					 "<th><b>", get_lang('Color'), "</b></th>",
1398
+					 "<th width='50'><b>", get_lang('Modify'), "</b></th>",
1399 1399
 				"</tr>";
1400 1400
 
1401 1401
 
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
                         description,
1408 1408
                         color,
1409 1409
                         system_task
1410
-                    FROM " . $tbl_blogs_tasks . "
1411
-                    WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1410
+                    FROM " . $tbl_blogs_tasks."
1411
+                    WHERE c_id = $course_id AND blog_id = ".(int) $blog_id."
1412 1412
                     ORDER BY system_task, title";
1413 1413
 			$result = Database::query($sql);
1414 1414
 
@@ -1417,10 +1417,10 @@  discard block
 block discarded – undo
1417 1417
 				$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1418 1418
 				$delete_icon = ($task['system_task'] == '1') ? "delete_na.png" : "delete.png";
1419 1419
 				$delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1420
-				$delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $task['blog_id'] . '&do=delete&task_id=' . $task['task_id'];
1421
-				$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1420
+				$delete_link = ($task['system_task'] == '1') ? '#' : api_get_self().'?action=manage_tasks&blog_id='.$task['blog_id'].'&do=delete&task_id='.$task['task_id'];
1421
+				$delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1422 1422
 
1423
-				echo '<tr class="' . $css_class . '" valign="top">';
1423
+				echo '<tr class="'.$css_class.'" valign="top">';
1424 1424
                 echo '<td width="240">'.Security::remove_XSS($task['title']).'</td>';
1425 1425
                 echo '<td>'.Security::remove_XSS($task['description']).'</td>';
1426 1426
                 echo '<td><span style="background-color: #'.$task['color'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>';
@@ -1446,23 +1446,23 @@  discard block
 block discarded – undo
1446 1446
 	 *
1447 1447
 	 * @param Integer $blog_id
1448 1448
 	 */
1449
-	public static function display_assigned_task_list ($blog_id)
1449
+	public static function display_assigned_task_list($blog_id)
1450 1450
     {
1451 1451
 		// Init
1452 1452
 		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
1453 1453
 		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1454 1454
 		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1455 1455
 		$counter = 0;
1456
-		global $charset,$color2;
1456
+		global $charset, $color2;
1457 1457
 
1458
-		echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
1458
+		echo '<span class="blogpost_title">'.get_lang('AssignedTasks').'</span><br />';
1459 1459
 		echo "<table class=\"data_table\">";
1460 1460
 		echo	"<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
1461
-				 "<th width='240'><b>",get_lang('Member'),"</b></th>",
1462
-				 "<th><b>",get_lang('Task'),"</b></th>",
1463
-				 "<th><b>",get_lang('Description'),"</b></th>",
1464
-				 "<th><b>",get_lang('TargetDate'),"</b></th>",
1465
-				 "<th width='50'><b>",get_lang('Modify'),"</b></th>",
1461
+				 "<th width='240'><b>", get_lang('Member'), "</b></th>",
1462
+				 "<th><b>", get_lang('Task'), "</b></th>",
1463
+				 "<th><b>", get_lang('Description'), "</b></th>",
1464
+				 "<th><b>", get_lang('TargetDate'), "</b></th>",
1465
+				 "<th width='50'><b>", get_lang('Modify'), "</b></th>",
1466 1466
 			"</tr>";
1467 1467
 
1468 1468
 		$course_id = api_get_course_int_id();
@@ -1474,17 +1474,17 @@  discard block
 block discarded – undo
1474 1474
 				WHERE
1475 1475
 				    task_rel_user.c_id = $course_id AND
1476 1476
 					task.c_id = $course_id AND
1477
-					task_rel_user.blog_id = '".(int)$blog_id."'
1477
+					task_rel_user.blog_id = '".(int) $blog_id."'
1478 1478
 				ORDER BY target_date ASC";
1479 1479
 		$result = Database::query($sql);
1480 1480
 
1481 1481
 		while ($assignment = Database::fetch_array($result)) {
1482 1482
 			$counter++;
1483
-			$css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
1483
+			$css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
1484 1484
 			$delete_icon = ($assignment['system_task'] == '1') ? "delete_na.png" : "delete.png";
1485 1485
 			$delete_title = ($assignment['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
1486
-			$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&blog_id=' . $assignment['blog_id'] . '&do=delete&task_id=' . $assignment['task_id'];
1487
-			$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
1486
+			$delete_link = ($assignment['system_task'] == '1') ? '#' : api_get_self().'?action=manage_tasks&blog_id='.$assignment['blog_id'].'&do=delete&task_id='.$assignment['task_id'];
1487
+			$delete_confirm = ($assignment['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;"';
1488 1488
 
1489 1489
             $username = api_htmlentities(sprintf(get_lang('LoginX'), $assignment['username']), ENT_QUOTES);
1490 1490
 
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
 	 * @author Toon Keppens
1517 1517
 	 *
1518 1518
 	 */
1519
-	public static function display_new_task_form ($blog_id)
1519
+	public static function display_new_task_form($blog_id)
1520 1520
 	{
1521 1521
 		// Init
1522 1522
         $colors = array(
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
         );
1539 1539
 
1540 1540
 		// form
1541
-		echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">';
1541
+		echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&blog_id='.$blog_id.'">';
1542 1542
 
1543 1543
 		// form title
1544 1544
 		echo '<legend>'.get_lang('AddTask').'</legend>';
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
 		// task title
1547 1547
 		echo '	<div class="control-group">
1548 1548
 					<label class="control-label">
1549
-						<span class="form_required">*</span>' . get_lang('Title') . '
1549
+						<span class="form_required">*</span>' . get_lang('Title').'
1550 1550
 					</label>
1551 1551
 					<div class="controls">
1552 1552
 						<input name="task_name" type="text" size="70" />
@@ -1556,7 +1556,7 @@  discard block
 block discarded – undo
1556 1556
 		// task comment
1557 1557
 		echo '	<div class="control-group">
1558 1558
 					<label class="control-label">
1559
-						' . get_lang('Description') . '
1559
+						' . get_lang('Description').'
1560 1560
 					</label>
1561 1561
 					<div class="controls">
1562 1562
 						<textarea name="task_description" cols="45"></textarea>
@@ -1566,18 +1566,18 @@  discard block
 block discarded – undo
1566 1566
 		// task management
1567 1567
 		echo '	<div class="control-group">
1568 1568
 					<label class="control-label">
1569
-						' . get_lang('TaskManager') . '
1569
+						' . get_lang('TaskManager').'
1570 1570
 					</label>
1571 1571
 					<div class="controls">';
1572 1572
                 echo '<table class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1573 1573
                     echo '<tr>';
1574
-                        echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1575
-                        echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1574
+                        echo '<th colspan="2" style="width:223px;">'.get_lang('ArticleManager').'</th>';
1575
+                        echo '<th width:223px;>'.get_lang('CommentManager').'</th>';
1576 1576
                     echo '</tr>';
1577 1577
                     echo '<tr>';
1578
-                        echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1579
-                        echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1580
-                        echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1578
+                        echo '<th style="width:111px;"><label for="articleDelete">'.get_lang('Delete').'</label></th>';
1579
+                        echo '<th style="width:112px;"><label for="articleEdit">'.get_lang('Edit').'</label></th>';
1580
+                        echo '<th style="width:223px;"><label for="commentsDelete">'.get_lang('Delete').'</label></th>';
1581 1581
                     echo '</tr>';
1582 1582
                     echo '<tr>';
1583 1583
                         echo '<td style="text-align:center;"><input id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
@@ -1592,13 +1592,13 @@  discard block
 block discarded – undo
1592 1592
 		// task color
1593 1593
 		echo '	<div class="control-group">
1594 1594
 					<label class="control-label">
1595
-						' . get_lang('Color') . '
1595
+						' . get_lang('Color').'
1596 1596
 					</label>
1597 1597
 					<div class="controls">';
1598 1598
         echo '<select name="task_color" id="color" style="width: 150px; background-color: #eeeeee" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
1599 1599
                 foreach ($colors as $color) {
1600
-                    $style = 'style="background-color: #' . $color . '"';
1601
-                    echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1600
+                    $style = 'style="background-color: #'.$color.'"';
1601
+                    echo '<option value="'.$color.'" '.$style.'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1602 1602
                 }
1603 1603
         echo '</select>';
1604 1604
 		echo '		</div>
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
 					<div class="controls">
1610 1610
 							<input type="hidden" name="action" value="" />
1611 1611
 							<input type="hidden" name="new_task_submit" value="true" />
1612
-						<button class="save" type="submit" name="Submit">' . get_lang('Save') . '</button>
1612
+						<button class="save" type="submit" name="Submit">' . get_lang('Save').'</button>
1613 1613
 					</div>
1614 1614
 				</div>';
1615 1615
 		echo '</form>';
@@ -1623,34 +1623,34 @@  discard block
 block discarded – undo
1623 1623
 	 * @author Toon Keppens
1624 1624
 	 *
1625 1625
 	 */
1626
-	public static function display_edit_task_form ($blog_id, $task_id) {
1626
+	public static function display_edit_task_form($blog_id, $task_id) {
1627 1627
 		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
1628 1628
         $course_id = api_get_course_int_id();
1629 1629
 
1630
-		$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
1630
+		$colors = array('FFFFFF', 'FFFF99', 'FFCC99', 'FF9933', 'FF6699', 'CCFF99', 'CC9966', '66FF00', '9966FF', 'CF3F3F', '990033', '669933', '0033FF', '003366', '000000');
1631 1631
 
1632
-		$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int)$task_id."'";
1632
+		$sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE c_id = $course_id AND task_id = '".(int) $task_id."'";
1633 1633
 		$result = Database::query($sql);
1634 1634
 		$task = Database::fetch_array($result);
1635 1635
 
1636 1636
 		// Display
1637
-		echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id=' . $blog_id . '">
1638
-					<legend>' . get_lang('EditTask') . '</legend>
1637
+		echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&blog_id='.$blog_id.'">
1638
+					<legend>' . get_lang('EditTask').'</legend>
1639 1639
 					<table width="100%" border="0" cellspacing="2">
1640 1640
 						<tr>
1641
-					   <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
1642
-					   <td><input name="task_name" type="text" size="70" value="'.Security::remove_XSS($task['title']) . '" /></td>
1641
+					   <td align="right">' . get_lang('Title').':&nbsp;&nbsp;</td>
1642
+					   <td><input name="task_name" type="text" size="70" value="'.Security::remove_XSS($task['title']).'" /></td>
1643 1643
 						</tr>
1644 1644
 						<tr>
1645
-					   <td align="right">' . get_lang('Description') . ':&nbsp;&nbsp;</td>
1645
+					   <td align="right">' . get_lang('Description').':&nbsp;&nbsp;</td>
1646 1646
 					   <td><textarea name="task_description" cols="45">'.Security::remove_XSS($task['description']).'</textarea></td>
1647 1647
 						</tr>';
1648 1648
 
1649 1649
 						/* edit by Kevin Van Den Haute ([email protected]) */
1650 1650
 						$tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
1651 1651
 
1652
-						$sql = " SELECT id, action FROM " . $tbl_tasks_permissions . "
1653
-							     WHERE c_id = $course_id AND task_id = '" . (int)$task_id."'";
1652
+						$sql = " SELECT id, action FROM ".$tbl_tasks_permissions."
1653
+							     WHERE c_id = $course_id AND task_id = '".(int) $task_id."'";
1654 1654
 						$result = Database::query($sql);
1655 1655
 
1656 1656
 						$arrPermissions = array();
@@ -1659,22 +1659,22 @@  discard block
 block discarded – undo
1659 1659
 							$arrPermissions[] = $row['action'];
1660 1660
 
1661 1661
 						    echo '<tr>';
1662
-							echo '<td style="text-align:right; vertical-align:top;">' . get_lang('TaskManager') . ':&nbsp;&nbsp;</td>';
1662
+							echo '<td style="text-align:right; vertical-align:top;">'.get_lang('TaskManager').':&nbsp;&nbsp;</td>';
1663 1663
 							echo '<td>';
1664 1664
 								echo '<table  class="data_table" cellspacing="0" style="border-collapse:collapse; width:446px;">';
1665 1665
 									echo '<tr>';
1666
-										echo '<th colspan="2" style="width:223px;">' . get_lang('ArticleManager') . '</th>';
1667
-										echo '<th width:223px;>' . get_lang('CommentManager') . '</th>';
1666
+										echo '<th colspan="2" style="width:223px;">'.get_lang('ArticleManager').'</th>';
1667
+										echo '<th width:223px;>'.get_lang('CommentManager').'</th>';
1668 1668
 									echo '</tr>';
1669 1669
 									echo '<tr>';
1670
-										echo '<th style="width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>';
1671
-										echo '<th style="width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>';
1672
-										echo '<th style="width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>';
1670
+										echo '<th style="width:111px;"><label for="articleDelete">'.get_lang('Delete').'</label></th>';
1671
+										echo '<th style="width:112px;"><label for="articleEdit">'.get_lang('Edit').'</label></th>';
1672
+										echo '<th style="width:223px;"><label for="commentsDelete">'.get_lang('Delete').'</label></th>';
1673 1673
 									echo '</tr>';
1674 1674
 									echo '<tr>';
1675
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1676
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1677
-										echo '<td style="text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1675
+										echo '<td style="text-align:center;"><input '.((in_array('article_delete', $arrPermissions)) ? 'checked ' : '').'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>';
1676
+										echo '<td style="text-align:center;"><input '.((in_array('article_edit', $arrPermissions)) ? 'checked ' : '').'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>';
1677
+										echo '<td style="text-align:center;"><input '.((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '').'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>';
1678 1678
 									echo '</tr>';
1679 1679
 								echo '</table>';
1680 1680
 							echo '</td>';
@@ -1682,13 +1682,13 @@  discard block
 block discarded – undo
1682 1682
 						/* end of edit */
1683 1683
 
1684 1684
 						echo '<tr>
1685
-					   <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
1685
+					   <td align="right">' . get_lang('Color').':&nbsp;&nbsp;</td>
1686 1686
 					   <td>
1687
-					   	<select name="task_color" id="color" style="width: 150px; background-color: #' . $task['color'] . '" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
1687
+					   	<select name="task_color" id="color" style="width: 150px; background-color: #' . $task['color'].'" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
1688 1688
                             foreach ($colors as $color) {
1689 1689
                                 $selected = ($color == $task['color']) ? ' selected' : '';
1690
-                                $style = 'style="background-color: #' . $color . '"';
1691
-                                echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1690
+                                $style = 'style="background-color: #'.$color.'"';
1691
+                                echo '<option value="'.$color.'" '.$style.' '.$selected.' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
1692 1692
                             }
1693 1693
 		echo '			   </select>
1694 1694
 						  </td>
@@ -1697,9 +1697,9 @@  discard block
 block discarded – undo
1697 1697
 							<td align="right">&nbsp;</td>
1698 1698
 							<td><br /><input type="hidden" name="action" value="" />
1699 1699
 							<input type="hidden" name="edit_task_submit" value="true" />
1700
-							<input type="hidden" name="task_id" value="' . $task['task_id'] . '" />
1701
-							<input type="hidden" name="blog_id" value="' . $task['blog_id'] . '" />
1702
-							<button class="save" type="submit" name="Submit">' . get_lang('Save') . '</button></td>
1700
+							<input type="hidden" name="task_id" value="' . $task['task_id'].'" />
1701
+							<input type="hidden" name="blog_id" value="' . $task['blog_id'].'" />
1702
+							<button class="save" type="submit" name="Submit">' . get_lang('Save').'</button></td>
1703 1703
 						</tr>
1704 1704
 					</table>
1705 1705
 				</form>';
@@ -1721,7 +1721,7 @@  discard block
 block discarded – undo
1721 1721
 				FROM $tbl_users user
1722 1722
 				INNER JOIN $tbl_blogs_rel_user blogs_rel_user
1723 1723
 				ON user.user_id = blogs_rel_user.user_id
1724
-				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
1724
+				WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int) $blog_id."'";
1725 1725
 		$result = Database::query($sql);
1726 1726
 
1727 1727
 		$options = array();
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
 				color,
1741 1741
 				system_task
1742 1742
 			FROM $tbl_blogs_tasks
1743
-			WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
1743
+			WHERE c_id = $course_id AND blog_id = ".(int) $blog_id."
1744 1744
 			ORDER BY system_task, title";
1745 1745
 		$result = Database::query($sql);
1746 1746
 
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
 	 */
1789 1789
 	public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
1790 1790
 	{
1791
-		$tbl_blogs_tasks_rel_user 	= Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1791
+		$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
1792 1792
 
1793 1793
 		$course_id = api_get_course_int_id();
1794 1794
 
@@ -1797,9 +1797,9 @@  discard block
 block discarded – undo
1797 1797
 			SELECT target_date
1798 1798
 			FROM $tbl_blogs_tasks_rel_user
1799 1799
 			WHERE c_id = $course_id AND
1800
-			      blog_id = '".(int)$blog_id."' AND
1801
-			      user_id = '".(int)$user_id."' AND
1802
-			      task_id = '".(int)$task_id."'";
1800
+			      blog_id = '".(int) $blog_id."' AND
1801
+			      user_id = '".(int) $user_id."' AND
1802
+			      task_id = '".(int) $task_id."'";
1803 1803
 		$result = Database::query($sql);
1804 1804
 		$row = Database::fetch_assoc($result);
1805 1805
 
@@ -1834,11 +1834,11 @@  discard block
 block discarded – undo
1834 1834
 
1835 1835
 		$sql = "
1836 1836
 			SELECT COUNT(*) as 'number'
1837
-			FROM " . $tbl_blogs_tasks_rel_user . "
1837
+			FROM " . $tbl_blogs_tasks_rel_user."
1838 1838
 			WHERE c_id = $course_id AND
1839
-			blog_id = " . (int)$blog_id . "
1840
-			AND	user_id = " . (int)$user_id . "
1841
-			AND	task_id = " . (int)$task_id . "
1839
+			blog_id = ".(int) $blog_id."
1840
+			AND	user_id = " . (int) $user_id."
1841
+			AND	task_id = " . (int) $task_id."
1842 1842
 		";
1843 1843
 
1844 1844
 		$result = Database::query($sql);
@@ -1846,18 +1846,18 @@  discard block
 block discarded – undo
1846 1846
 
1847 1847
 		if ($row['number'] == 0) {
1848 1848
 			$sql = "
1849
-				INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
1849
+				INSERT INTO " . $tbl_blogs_tasks_rel_user." (
1850 1850
 					c_id,
1851 1851
 					blog_id,
1852 1852
 					user_id,
1853 1853
 					task_id,
1854 1854
 					target_date
1855 1855
 				) VALUES (
1856
-					'" . (int)$course_id . "',
1857
-					'" . (int)$blog_id . "',
1858
-					'" . (int)$user_id . "',
1859
-					'" . (int)$task_id . "',
1860
-					'" . Database::escape_string($target_date) . "'
1856
+					'" . (int) $course_id."',
1857
+					'" . (int) $blog_id."',
1858
+					'" . (int) $user_id."',
1859
+					'" . (int) $task_id."',
1860
+					'" . Database::escape_string($target_date)."'
1861 1861
 				)";
1862 1862
 
1863 1863
 			Database::query($sql);
@@ -1887,12 +1887,12 @@  discard block
 block discarded – undo
1887 1887
 		$course_id = api_get_course_int_id();
1888 1888
 
1889 1889
 		$sql = "SELECT COUNT(*) as 'number'
1890
-                FROM " . $tbl_blogs_tasks_rel_user . "
1890
+                FROM " . $tbl_blogs_tasks_rel_user."
1891 1891
                 WHERE
1892 1892
                     c_id = $course_id AND
1893
-                    blog_id = " . (int)$blog_id . " AND
1894
-                    user_id = " . (int)$user_id . " AND
1895
-                    task_id = " . (int)$task_id . "
1893
+                    blog_id = ".(int) $blog_id." AND
1894
+                    user_id = " . (int) $user_id." AND
1895
+                    task_id = " . (int) $task_id."
1896 1896
             ";
1897 1897
 
1898 1898
 		$result = Database::query($sql);
@@ -1900,17 +1900,17 @@  discard block
 block discarded – undo
1900 1900
 
1901 1901
 		if ($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id)) {
1902 1902
 			$sql = "
1903
-				UPDATE " . $tbl_blogs_tasks_rel_user . "
1903
+				UPDATE " . $tbl_blogs_tasks_rel_user."
1904 1904
 				SET
1905
-					user_id = " . (int)$user_id . ",
1906
-					task_id = " . (int)$task_id . ",
1907
-					target_date = '" . Database::escape_string($target_date) . "'
1905
+					user_id = " . (int) $user_id.",
1906
+					task_id = " . (int) $task_id.",
1907
+					target_date = '" . Database::escape_string($target_date)."'
1908 1908
 				WHERE
1909 1909
 					c_id = $course_id AND
1910
-					blog_id = " . (int)$blog_id . " AND
1911
-					user_id = " . (int)$old_user_id . " AND
1912
-					task_id = " . (int)$old_task_id . " AND
1913
-					target_date = '" . Database::escape_string($old_target_date) . "'
1910
+					blog_id = ".(int) $blog_id." AND
1911
+					user_id = " . (int) $old_user_id." AND
1912
+					task_id = " . (int) $old_task_id." AND
1913
+					target_date = '" . Database::escape_string($old_target_date)."'
1914 1914
 			";
1915 1915
 			Database::query($sql);
1916 1916
 		}
@@ -1931,7 +1931,7 @@  discard block
 block discarded – undo
1931 1931
 
1932 1932
 
1933 1933
 		$sql = "SELECT title, description FROM $tbl_blogs_tasks
1934
-				WHERE task_id = '".(int)$task_id."'
1934
+				WHERE task_id = '".(int) $task_id."'
1935 1935
 				AND c_id = $course_id";
1936 1936
 		$result = Database::query($sql);
1937 1937
 		$row = Database::fetch_assoc($result);
@@ -1939,19 +1939,19 @@  discard block
 block discarded – undo
1939 1939
 		$sql = "SELECT post.*, user.lastname, user.firstname, user.username
1940 1940
 				FROM $tbl_blogs_posts post
1941 1941
 				INNER JOIN $tbl_users user ON post.author_id = user.user_id
1942
-				WHERE post.blog_id = '".(int)$blog_id."' AND post.c_id = $course_id
1942
+				WHERE post.blog_id = '".(int) $blog_id."' AND post.c_id = $course_id
1943 1943
 				ORDER BY post_id DESC
1944 1944
 				LIMIT 0, 100";
1945 1945
 		$result = Database::query($sql);
1946 1946
 
1947 1947
 		// Display
1948
-		echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
1949
-		echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
1948
+		echo '<span class="blogpost_title">'.get_lang('SelectTaskArticle').' "'.stripslashes($row['title']).'"</span>';
1949
+		echo '<span style="font-style: italic;"">'.stripslashes($row['description']).'</span><br><br>';
1950 1950
 
1951 1951
 		if (Database::num_rows($result) > 0) {
1952
-			while($blog_post = Database::fetch_array($result)) {
1952
+			while ($blog_post = Database::fetch_array($result)) {
1953 1953
 			    $username = api_htmlentities(sprintf(get_lang('LoginX'), $blog_post['username']), ENT_QUOTES);
1954
-				echo '<a href="blog.php?action=execute_task&blog_id=' . $blog_id . '&task_id=' . $task_id . '&post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))) . '<br />';
1954
+				echo '<a href="blog.php?action=execute_task&blog_id='.$blog_id.'&task_id='.$task_id.'&post_id='.$blog_post['post_id'].'#add_comment">'.stripslashes($blog_post['title']).'</a>, '.get_lang('WrittenBy').' '.stripslashes(Display::tag('span', api_get_person_name($blog_post['firstname'], $blog_post['lastname']), array('title'=>$username))).'<br />';
1955 1955
 			}
1956 1956
         } else {
1957 1957
             echo get_lang('NoArticles');
@@ -1975,12 +1975,12 @@  discard block
 block discarded – undo
1975 1975
 
1976 1976
 		// Subscribe the user
1977 1977
 		$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id )
1978
-		        VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
1978
+		        VALUES ($course_id, '".(int) $blog_id."', '".(int) $user_id."');";
1979 1979
 		Database::query($sql);
1980 1980
 
1981 1981
 		// Give this user basic rights
1982 1982
 		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1983
-		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
1983
+		        VALUES ($course_id, '".(int) $user_id."','BLOG_".(int) $blog_id."','article_add')";
1984 1984
 		Database::query($sql);
1985 1985
 
1986 1986
         $id = Database::insert_id();
@@ -1990,7 +1990,7 @@  discard block
 block discarded – undo
1990 1990
         }
1991 1991
 
1992 1992
 		$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action)
1993
-		        VALUES ($course_id, '".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
1993
+		        VALUES ($course_id, '".(int) $user_id."','BLOG_".(int) $blog_id."','article_comments_add')";
1994 1994
 		Database::query($sql);
1995 1995
 
1996 1996
         $id = Database::insert_id();
@@ -2016,12 +2016,12 @@  discard block
 block discarded – undo
2016 2016
 
2017 2017
 		// Unsubscribe the user
2018 2018
 		$sql = "DELETE FROM $tbl_blogs_rel_user
2019
-		        WHERE blog_id = '".(int)$blog_id."' AND user_id = '".(int)$user_id."'";
2019
+		        WHERE blog_id = '".(int) $blog_id."' AND user_id = '".(int) $user_id."'";
2020 2020
 		Database::query($sql);
2021 2021
 
2022 2022
 		// Remove this user's permissions.
2023 2023
 		$sql = "DELETE FROM $tbl_user_permissions
2024
-		        WHERE user_id = '".(int)$user_id."'";
2024
+		        WHERE user_id = '".(int) $user_id."'";
2025 2025
 		Database::query($sql);
2026 2026
 	}
2027 2027
 
@@ -2042,7 +2042,7 @@  discard block
 block discarded – undo
2042 2042
 		$course_id = $_course['real_id'];
2043 2043
 
2044 2044
 		$currentCourse = $_course['code'];
2045
-		$tbl_users 			= Database::get_main_table(TABLE_MAIN_USER);
2045
+		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
2046 2046
 		$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
2047 2047
 
2048 2048
 		echo '<legend>'.get_lang('SubscribeMembers').'</legend>';
@@ -2057,12 +2057,12 @@  discard block
 block discarded – undo
2057 2057
 		$result = Database::query($sql);
2058 2058
 
2059 2059
 		$blog_member_ids = array();
2060
-		while($user = Database::fetch_array($result)) {
2060
+		while ($user = Database::fetch_array($result)) {
2061 2061
 			$blog_member_ids[] = $user['user_id'];
2062 2062
 		}
2063 2063
 
2064 2064
 		// Set table headers
2065
-		$column_header[] = array ('', false, '');
2065
+		$column_header[] = array('', false, '');
2066 2066
 		if ($is_western_name_order) {
2067 2067
 			$column_header[] = array(get_lang('FirstName'), true, '');
2068 2068
 			$column_header[] = array(get_lang('LastName'), true, '');
@@ -2082,13 +2082,13 @@  discard block
 block discarded – undo
2082 2082
 
2083 2083
 		// Add users that are not in this blog to the list.
2084 2084
 		foreach ($student_list as $key=>$user) {
2085
-			if(isset($user['id_user'])) {
2085
+			if (isset($user['id_user'])) {
2086 2086
 				$user['user_id'] = $user['id_user'];
2087 2087
 			}
2088
-			if(!in_array($user['user_id'],$blog_member_ids)) {
2088
+			if (!in_array($user['user_id'], $blog_member_ids)) {
2089 2089
 				$a_infosUser = api_get_user_info($user['user_id']);
2090
-				$row = array ();
2091
-				$row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
2090
+				$row = array();
2091
+				$row[] = '<input type="checkbox" name="user[]" value="'.$a_infosUser['user_id'].'" '.((isset($_GET['selectall']) && $_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '').'/>';
2092 2092
 				$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
2093 2093
 				if ($is_western_name_order) {
2094 2094
 					$row[] = $a_infosUser["firstname"];
@@ -2100,8 +2100,8 @@  discard block
 block discarded – undo
2100 2100
 				$row[] = Display::icon_mailto_link($a_infosUser["email"]);
2101 2101
 
2102 2102
 				//Link to register users
2103
-				if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']){
2104
-					$row[] = "<a class=\"btn btn-primary \" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
2103
+				if ($a_infosUser["user_id"] != $_SESSION['_user']['user_id']) {
2104
+					$row[] = "<a class=\"btn btn-primary \" href=\"".api_get_self()."?action=manage_members&blog_id=$blog_id&register=yes&user_id=".$a_infosUser["user_id"]."\">".get_lang('Register')."</a>";
2105 2105
 				} else {
2106 2106
 					$row[] = '';
2107 2107
 				}
@@ -2112,20 +2112,20 @@  discard block
 block discarded – undo
2112 2112
 		// Display
2113 2113
 		$query_vars['action'] = 'manage_members';
2114 2114
 		$query_vars['blog_id'] = $blog_id;
2115
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2116
-			Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2115
+		echo '<form method="post" action="blog.php?action=manage_members&blog_id='.$blog_id.'">';
2116
+			Display::display_sortable_table($column_header, $user_data, null, null, $query_vars);
2117 2117
 			$link = '';
2118
-			$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : '';
2118
+			$link .= isset ($_GET['action']) ? 'action='.Security::remove_XSS($_GET['action']).'&' : '';
2119 2119
 			$link .= "blog_id=$blog_id&";
2120 2120
 
2121
-			echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
2122
-			echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2123
-			echo get_lang('WithSelected') . ' : ';
2121
+			echo '<a href="blog.php?'.$link.'selectall=subscribe">'.get_lang('SelectAll').'</a> - ';
2122
+			echo '<a href="blog.php?'.$link.'">'.get_lang('UnSelectAll').'</a> ';
2123
+			echo get_lang('WithSelected').' : ';
2124 2124
 			echo '<select name="action">';
2125
-			echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
2125
+			echo '<option value="select_subscribe">'.get_lang('Register').'</option>';
2126 2126
 			echo '</select>';
2127 2127
 			echo '<input type="hidden" name="register" value="true" />';
2128
-			echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2128
+			echo '<button class="save" type="submit">'.get_lang('Ok').'</button>';
2129 2129
 		echo '</form>';
2130 2130
 	}
2131 2131
 
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
 	 *
2139 2139
 	 * @return Html Form with sortable table with users to unsubcribe from a blog.
2140 2140
 	 */
2141
-	public static function display_form_user_unsubscribe ($blog_id)
2141
+	public static function display_form_user_unsubscribe($blog_id)
2142 2142
 	{
2143 2143
 		$_user = api_get_user_info();
2144 2144
 		$is_western_name_order = api_is_western_name_order();
@@ -2151,34 +2151,34 @@  discard block
 block discarded – undo
2151 2151
 
2152 2152
 		$properties["width"] = "100%";
2153 2153
 		//table column titles
2154
-		$column_header[] = array ('', false, '');
2154
+		$column_header[] = array('', false, '');
2155 2155
 		if ($is_western_name_order) {
2156
-			$column_header[] = array (get_lang('FirstName'), true, '');
2157
-			$column_header[] = array (get_lang('LastName'), true, '');
2156
+			$column_header[] = array(get_lang('FirstName'), true, '');
2157
+			$column_header[] = array(get_lang('LastName'), true, '');
2158 2158
 		} else {
2159
-			$column_header[] = array (get_lang('LastName'), true, '');
2160
-			$column_header[] = array (get_lang('FirstName'), true, '');
2159
+			$column_header[] = array(get_lang('LastName'), true, '');
2160
+			$column_header[] = array(get_lang('FirstName'), true, '');
2161 2161
 		}
2162
-		$column_header[] = array (get_lang('Email'), false, '');
2163
-		$column_header[] = array (get_lang('TaskManager'), true, '');
2164
-		$column_header[] = array (get_lang('UnRegister'), false, '');
2162
+		$column_header[] = array(get_lang('Email'), false, '');
2163
+		$column_header[] = array(get_lang('TaskManager'), true, '');
2164
+		$column_header[] = array(get_lang('UnRegister'), false, '');
2165 2165
 
2166 2166
 		$course_id = api_get_course_int_id();
2167 2167
 
2168 2168
 		$sql = "SELECT user.user_id, user.lastname, user.firstname, user.email, user.username
2169 2169
                 FROM $tbl_users user INNER JOIN $tbl_blogs_rel_user blogs_rel_user
2170 2170
                 ON user.user_id = blogs_rel_user.user_id
2171
-                WHERE blogs_rel_user.c_id = $course_id AND  blogs_rel_user.blog_id = '".(int)$blog_id."'";
2171
+                WHERE blogs_rel_user.c_id = $course_id AND  blogs_rel_user.blog_id = '".(int) $blog_id."'";
2172 2172
 
2173 2173
 		if (!($sql_result = Database::query($sql))) {
2174 2174
 			return false;
2175 2175
 		}
2176 2176
 
2177
-		$user_data = array ();
2177
+		$user_data = array();
2178 2178
 
2179 2179
 		while ($myrow = Database::fetch_array($sql_result)) {
2180
-			$row = array ();
2181
-			$row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
2180
+			$row = array();
2181
+			$row[] = '<input type="checkbox" name="user[]" value="'.$myrow['user_id'].'" '.((isset($_GET['selectall']) && $_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '').'/>';
2182 2182
 			$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
2183 2183
 			if ($is_western_name_order) {
2184 2184
 				$row[] = $myrow["firstname"];
@@ -2190,19 +2190,19 @@  discard block
 block discarded – undo
2190 2190
 			$row[] = Display::icon_mailto_link($myrow["email"]);
2191 2191
 
2192 2192
 			$sql = "SELECT bt.title task
2193
-					FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER) . " btu
2194
-					INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS) . " bt
2193
+					FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER)." btu
2194
+					INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS)." bt
2195 2195
 					ON btu.task_id = bt.task_id
2196 2196
 					WHERE 	btu.c_id 	= $course_id  AND
2197 2197
 							bt.c_id 	= $course_id  AND
2198 2198
 							btu.blog_id = $blog_id AND
2199
-							btu.user_id = " . $myrow['user_id'];
2199
+							btu.user_id = ".$myrow['user_id'];
2200 2200
 			$sql_res = Database::query($sql);
2201 2201
 
2202 2202
 			$task = '';
2203 2203
 
2204
-			while($r = Database::fetch_array($sql_res)) {
2205
-				$task .= stripslashes($r['task']) . ', ';
2204
+			while ($r = Database::fetch_array($sql_res)) {
2205
+				$task .= stripslashes($r['task']).', ';
2206 2206
 			}
2207 2207
 			//echo $task;
2208 2208
 			$task = (api_strlen(trim($task)) != 0) ? api_substr($task, 0, api_strlen($task) - 2) : get_lang('Reader');
@@ -2210,7 +2210,7 @@  discard block
 block discarded – undo
2210 2210
 			//Link to register users
2211 2211
 
2212 2212
 			if ($myrow["user_id"] != $_user['user_id']) {
2213
-				$row[] = "<a class=\"btn btn-primary\" href=\"" .api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=" . $myrow['user_id']."\">" . get_lang('UnRegister')."</a>";
2213
+				$row[] = "<a class=\"btn btn-primary\" href=\"".api_get_self()."?action=manage_members&blog_id=$blog_id&unregister=yes&user_id=".$myrow['user_id']."\">".get_lang('UnRegister')."</a>";
2214 2214
 			} else {
2215 2215
 				$row[] = '';
2216 2216
 			}
@@ -2220,20 +2220,20 @@  discard block
 block discarded – undo
2220 2220
 
2221 2221
 		$query_vars['action'] = 'manage_members';
2222 2222
 		$query_vars['blog_id'] = $blog_id;
2223
-		echo '<form method="post" action="blog.php?action=manage_members&blog_id=' . $blog_id . '">';
2224
-		Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
2223
+		echo '<form method="post" action="blog.php?action=manage_members&blog_id='.$blog_id.'">';
2224
+		Display::display_sortable_table($column_header, $user_data, null, null, $query_vars);
2225 2225
 		$link = '';
2226
-		$link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : '';
2226
+		$link .= isset ($_GET['action']) ? 'action='.Security::remove_XSS($_GET['action']).'&' : '';
2227 2227
 		$link .= "blog_id=$blog_id&";
2228 2228
 
2229
-		echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
2230
-		echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
2231
-		echo get_lang('WithSelected') . ' : ';
2229
+		echo '<a href="blog.php?'.$link.'selectall=unsubscribe">'.get_lang('SelectAll').'</a> - ';
2230
+		echo '<a href="blog.php?'.$link.'">'.get_lang('UnSelectAll').'</a> ';
2231
+		echo get_lang('WithSelected').' : ';
2232 2232
 		echo '<select name="action">';
2233
-		echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
2233
+		echo '<option value="select_unsubscribe">'.get_lang('UnRegister').'</option>';
2234 2234
 		echo '</select>';
2235 2235
 		echo '<input type="hidden" name="unregister" value="true" />';
2236
-		echo '<button class="save" type="submit">' . get_lang('Ok') . '</button>';
2236
+		echo '<button class="save" type="submit">'.get_lang('Ok').'</button>';
2237 2237
 		echo '</form>';
2238 2238
 	}
2239 2239
 
@@ -2243,7 +2243,7 @@  discard block
 block discarded – undo
2243 2243
 	 *
2244 2244
 	 * @param Integer $blog_id
2245 2245
 	 */
2246
-	public static function display_form_user_rights ($blog_id)
2246
+	public static function display_form_user_rights($blog_id)
2247 2247
     {
2248 2248
 		echo '<legend>'.get_lang('RightsManager').'</legend>';
2249 2249
 		echo '<br />';
@@ -2263,7 +2263,7 @@  discard block
 block discarded – undo
2263 2263
 		$form = new FormValidator(
2264 2264
 			'add_post',
2265 2265
 			'post',
2266
-			api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=" . intval($blog_id)  . "&post_id=".intval($post_id)."&".api_get_cidreq(),
2266
+			api_get_path(WEB_CODE_PATH)."blog/blog.php?action=view_post&blog_id=".intval($blog_id)."&post_id=".intval($post_id)."&".api_get_cidreq(),
2267 2267
 			null,
2268 2268
 			array('enctype' => 'multipart/form-data')
2269 2269
 		);
@@ -2331,21 +2331,21 @@  discard block
 block discarded – undo
2331 2331
 		$course_id = api_get_course_int_id();
2332 2332
 
2333 2333
 		//Handle leap year
2334
-		$numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2334
+		$numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
2335 2335
 
2336
-		if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2336
+		if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
2337 2337
 			$numberofdays[2] = 29;
2338 2338
 
2339 2339
 		//Get the first day of the month
2340 2340
 		$dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
2341
-		$monthName = $MonthsLong[$month-1];
2341
+		$monthName = $MonthsLong[$month - 1];
2342 2342
 
2343 2343
 		//Start the week on monday
2344 2344
 		$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
2345 2345
 		$blogId = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
2346 2346
 		$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
2347
-		$backwardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
2348
-		$forewardsURL = api_get_self()."?blog_id=" . $blogId."&filter=" . $filter."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
2347
+		$backwardsURL = api_get_self()."?blog_id=".$blogId."&filter=".$filter."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year);
2348
+		$forewardsURL = api_get_self()."?blog_id=".$blogId."&filter=".$filter."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year);
2349 2349
 
2350 2350
 		// Get posts for this month
2351 2351
 		$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname
@@ -2354,15 +2354,15 @@  discard block
 block discarded – undo
2354 2354
 				ON post.author_id = user.user_id
2355 2355
 				WHERE
2356 2356
 					post.c_id = $course_id AND
2357
-					post.blog_id = '".(int)$blog_id."' AND
2358
-					MONTH(date_creation) = '".(int)$month."' AND
2359
-					YEAR(date_creation) = '".(int)$year."'
2357
+					post.blog_id = '".(int) $blog_id."' AND
2358
+					MONTH(date_creation) = '".(int) $month."' AND
2359
+					YEAR(date_creation) = '".(int) $year."'
2360 2360
 				ORDER BY date_creation";
2361 2361
 		$result = Database::query($sql);
2362 2362
 
2363 2363
 		// We will create an array of days on which there are posts.
2364
-		if( Database::num_rows($result) > 0) {
2365
-			while($blog_post = Database::fetch_array($result)) {
2364
+		if (Database::num_rows($result) > 0) {
2365
+			while ($blog_post = Database::fetch_array($result)) {
2366 2366
 				// If the day of this post is not yet in the array, add it.
2367 2367
 				if (!in_array($blog_post['post_day'], $posts))
2368 2368
 					$posts[] = $blog_post['post_day'];
@@ -2379,9 +2379,9 @@  discard block
 block discarded – undo
2379 2379
 					task_rel_user.c_id = $course_id AND
2380 2380
 					task.c_id = $course_id AND
2381 2381
 					blog.c_id = $course_id AND
2382
-					task_rel_user.user_id = '".(int)$_user['user_id']."' AND
2383
-					MONTH(target_date) = '".(int)$month."' AND
2384
-					YEAR(target_date) = '".(int)$year."'
2382
+					task_rel_user.user_id = '".(int) $_user['user_id']."' AND
2383
+					MONTH(target_date) = '".(int) $month."' AND
2384
+					YEAR(target_date) = '".(int) $year."'
2385 2385
 				ORDER BY target_date ASC";
2386 2386
 			$result = Database::query($sql);
2387 2387
 
@@ -2404,7 +2404,7 @@  discard block
 block discarded – undo
2404 2404
 
2405 2405
 		echo "<tr>";
2406 2406
 
2407
-		for($ii = 1; $ii < 8; $ii ++)
2407
+		for ($ii = 1; $ii < 8; $ii++)
2408 2408
 			echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
2409 2409
 
2410 2410
 		echo "</tr>";
@@ -2414,24 +2414,24 @@  discard block
 block discarded – undo
2414 2414
 
2415 2415
 		while ($curday <= $numberofdays[$month]) {
2416 2416
 			echo "<tr>";
2417
-			for ($ii = 0; $ii < 7; $ii ++) {
2417
+			for ($ii = 0; $ii < 7; $ii++) {
2418 2418
 				if (($curday == -1) && ($ii == $startdayofweek))
2419 2419
 					$curday = 1;
2420 2420
 
2421 2421
 			 	if (($curday > 0) && ($curday <= $numberofdays[$month])) {
2422
-					$bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
2422
+					$bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
2423 2423
 					$dayheader = "$curday";
2424 2424
 
2425
-					if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2425
+					if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
2426 2426
 						$dayheader = "$curday";
2427 2427
 						$class = "class=\"days_today\"";
2428 2428
 					}
2429 2429
 
2430
-					echo "<td " . $class.">";
2430
+					echo "<td ".$class.">";
2431 2431
 
2432 2432
 					// If there are posts on this day, create a filter link.
2433
-					if(in_array($curday, $posts))
2434
-						echo '<a href="blog.php?blog_id=' . $blog_id . '&filter=' . $year . '-' . $month . '-' . $curday . '&month=' . $month . '&year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
2433
+					if (in_array($curday, $posts))
2434
+						echo '<a href="blog.php?blog_id='.$blog_id.'&filter='.$year.'-'.$month.'-'.$curday.'&month='.$month.'&year='.$year.'" title="'.get_lang('ViewPostsOfThisDay').'">'.$curday.'</a>';
2435 2435
 					else
2436 2436
 						echo $dayheader;
2437 2437
 
@@ -2439,7 +2439,7 @@  discard block
 block discarded – undo
2439 2439
 						if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
2440 2440
 							// Add tasks to calendar
2441 2441
 							foreach ($tasks[$curday] as $task) {
2442
-								echo '<a href="blog.php?action=execute_task&blog_id=' . $task['blog_id'] . '&task_id='.stripslashes($task['task_id']) . '" title="' . $task['title'] . ' : ' . get_lang('InBlog') . ' : ' . $task['blog_name'] . ' - ' . get_lang('ExecuteThisTask') . '">';
2442
+								echo '<a href="blog.php?action=execute_task&blog_id='.$task['blog_id'].'&task_id='.stripslashes($task['task_id']).'" title="'.$task['title'].' : '.get_lang('InBlog').' : '.$task['blog_name'].' - '.get_lang('ExecuteThisTask').'">';
2443 2443
 								echo Display::return_icon('blog_task.gif', get_lang('ExecuteThisTask'));
2444 2444
                                 echo '</a>';
2445 2445
 							}
@@ -2447,7 +2447,7 @@  discard block
 block discarded – undo
2447 2447
 					}
2448 2448
 
2449 2449
 					echo "</td>";
2450
-					$curday ++;
2450
+					$curday++;
2451 2451
 				} else
2452 2452
 					echo "<td>&nbsp;</td>";
2453 2453
 			}
@@ -2485,7 +2485,7 @@  discard block
 block discarded – undo
2485 2485
 	public static function display_edit_blog_form($blog_id)
2486 2486
 	{
2487 2487
 	    $course_id = api_get_course_int_id();
2488
-		$blog_id= intval($blog_id);
2488
+		$blog_id = intval($blog_id);
2489 2489
 		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
2490 2490
 
2491 2491
 		$sql = "SELECT blog_id, blog_name, blog_subtitle
@@ -2500,7 +2500,7 @@  discard block
 block discarded – undo
2500 2500
 			$blog['blog_subtitle'] = Security::remove_XSS($_POST['blog_subtitle']);
2501 2501
 		}
2502 2502
 
2503
-        $form = new FormValidator('edit_blog', 'post','blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']));
2503
+        $form = new FormValidator('edit_blog', 'post', 'blog_admin.php?action=edit&blog_id='.intval($_GET['blog_id']));
2504 2504
         $form->addElement('header', get_lang('EditBlog'));
2505 2505
         $form->addElement('text', 'blog_name', get_lang('Title'));
2506 2506
         $form->addElement('textarea', 'blog_subtitle', get_lang('SubTitle'));
@@ -2536,8 +2536,8 @@  discard block
 block discarded – undo
2536 2536
 		$result = Database::query($sql);
2537 2537
 		$list_info = array();
2538 2538
 		if (Database::num_rows($result)) {
2539
-			while ($row_project=Database::fetch_row($result)) {
2540
-				$list_info[]=$row_project;
2539
+			while ($row_project = Database::fetch_row($result)) {
2540
+				$list_info[] = $row_project;
2541 2541
 			}
2542 2542
 		}
2543 2543
 
@@ -2549,35 +2549,35 @@  discard block
 block discarded – undo
2549 2549
 				// Validation when belongs to a session
2550 2550
 				$session_img = api_get_session_image($info_log[4], $_user['status']);
2551 2551
 
2552
-				$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq();
2552
+				$url_start_blog = 'blog.php'."?"."blog_id=".$info_log[3]."&".api_get_cidreq();
2553 2553
 				$title = $info_log[0];
2554 2554
                         $image = Display::return_icon('blog.png', $title);
2555
-    			$list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">' . $image . '</a></div><a href="'.$url_start_blog.'">' .$title. '</a>' . $session_img;
2555
+    			$list_name = '<div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_blog.'">'.$image.'</a></div><a href="'.$url_start_blog.'">'.$title.'</a>'.$session_img;
2556 2556
 
2557 2557
 				$list_body_blog[] = $list_name;
2558 2558
 				$list_body_blog[] = $info_log[1];
2559 2559
 
2560
-				$visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible';
2561
-				$visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible';
2562
-			 	$my_image = '<a href="' .api_get_self(). '?action=edit&blog_id=' . $info_log[3] . '">';
2563
-                                $my_image.= Display::return_icon('edit.png', get_lang('EditBlog'));
2560
+				$visibility_icon = ($info_log[2] == 0) ? 'invisible' : 'visible';
2561
+				$visibility_info = ($info_log[2] == 0) ? 'Visible' : 'Invisible';
2562
+			 	$my_image = '<a href="'.api_get_self().'?action=edit&blog_id='.$info_log[3].'">';
2563
+                                $my_image .= Display::return_icon('edit.png', get_lang('EditBlog'));
2564 2564
 
2565
-				$my_image.= "</a>";
2566
-				$my_image.= '<a href="' .api_get_self(). '?action=delete&blog_id=' . $info_log[3] . '" ';
2567
-				$my_image.= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;" >';
2568
-                                $my_image.= Display::return_icon('delete.png', get_lang('DeleteBlog'));
2565
+				$my_image .= "</a>";
2566
+				$my_image .= '<a href="'.api_get_self().'?action=delete&blog_id='.$info_log[3].'" ';
2567
+				$my_image .= 'onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;" >';
2568
+                                $my_image .= Display::return_icon('delete.png', get_lang('DeleteBlog'));
2569 2569
 
2570
-				$my_image.= "</a>";
2571
-				$my_image.= '<a href="' .api_get_self(). '?action=visibility&blog_id=' . $info_log[3] . '">';
2572
-                                $my_image.= Display::return_icon($visibility_icon . '.gif', get_lang($visibility_info));
2570
+				$my_image .= "</a>";
2571
+				$my_image .= '<a href="'.api_get_self().'?action=visibility&blog_id='.$info_log[3].'">';
2572
+                                $my_image .= Display::return_icon($visibility_icon.'.gif', get_lang($visibility_info));
2573 2573
 
2574
-				$my_image.= "</a>";
2575
-				$list_body_blog[]=$my_image;
2576
-				$list_content_blog[]=$list_body_blog;
2574
+				$my_image .= "</a>";
2575
+				$list_body_blog[] = $my_image;
2576
+				$list_content_blog[] = $list_body_blog;
2577 2577
 				$list_body_blog = array();
2578 2578
 			}
2579 2579
 
2580
-			$table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project');
2580
+			$table = new SortableTableFromArrayConfig($list_content_blog, 1, 20, 'project');
2581 2581
 			$table->set_header(0, get_lang('Title'));
2582 2582
 			$table->set_header(1, get_lang('SubTitle'));
2583 2583
 			$table->set_header(2, get_lang('Modify'));
@@ -2601,34 +2601,34 @@  discard block
 block discarded – undo
2601 2601
  * @author Julio Montoya Dokeos
2602 2602
  * @version avril 2008, dokeos 1.8.5
2603 2603
  */
2604
-function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
2604
+function get_blog_attachment($blog_id, $post_id = null, $comment_id = null)
2605 2605
 {
2606 2606
 	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
2607 2607
 
2608 2608
 	$blog_id = intval($blog_id);
2609 2609
 	$comment_id = intval($comment_id);
2610 2610
 	$post_id = intval($post_id);
2611
-	$row=array();
2612
-	$where='';
2611
+	$row = array();
2612
+	$where = '';
2613 2613
 	if (!empty ($post_id) && is_numeric($post_id)) {
2614
-		$where.=' AND post_id ="'.$post_id.'" ';
2614
+		$where .= ' AND post_id ="'.$post_id.'" ';
2615 2615
 	}
2616 2616
 
2617 2617
 	if (!empty ($comment_id) && is_numeric($comment_id)) {
2618 2618
 		if (!empty ($post_id)) {
2619
-			$where.= ' AND ';
2619
+			$where .= ' AND ';
2620 2620
 		}
2621
-		$where.=' comment_id ="'.$comment_id.'" ';
2621
+		$where .= ' comment_id ="'.$comment_id.'" ';
2622 2622
 	}
2623 2623
 
2624 2624
     $course_id = api_get_course_int_id();
2625 2625
 
2626
-	$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.'
2626
+	$sql = 'SELECT path, filename, comment FROM '.$blog_table_attachment.'
2627 2627
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2628 2628
 
2629
-	$result=Database::query($sql);
2630
-	if (Database::num_rows($result)!=0) {
2631
-		$row=Database::fetch_array($result);
2629
+	$result = Database::query($sql);
2630
+	if (Database::num_rows($result) != 0) {
2631
+		$row = Database::fetch_array($result);
2632 2632
 	}
2633 2633
 	return $row;
2634 2634
 }
@@ -2642,7 +2642,7 @@  discard block
 block discarded – undo
2642 2642
  * @version avril 2008, dokeos 1.8.5
2643 2643
  */
2644 2644
 
2645
-function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
2645
+function delete_all_blog_attachment($blog_id, $post_id = null, $comment_id = null)
2646 2646
 {
2647 2647
 	$_course = api_get_course_info();
2648 2648
 	$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
@@ -2666,22 +2666,22 @@  discard block
 block discarded – undo
2666 2666
     }
2667 2667
 
2668 2668
 	// delete all files in directory
2669
-	$courseDir   = $_course['path'].'/upload/blog';
2669
+	$courseDir = $_course['path'].'/upload/blog';
2670 2670
 	$sys_course_path = api_get_path(SYS_COURSE_PATH);
2671 2671
 	$updir = $sys_course_path.$courseDir;
2672 2672
 
2673 2673
 	$sql = 'SELECT path FROM '.$blog_table_attachment.'
2674 2674
 	        WHERE c_id = '.$course_id.' AND blog_id ="'.intval($blog_id).'"  '.$where;
2675
-	$result=Database::query($sql);
2675
+	$result = Database::query($sql);
2676 2676
 
2677
-	while ($row=Database::fetch_row($result)) {
2678
-		$file=$updir.'/'.$row[0];
2679
-		if (Security::check_abs_path($file,$updir) )
2677
+	while ($row = Database::fetch_row($result)) {
2678
+		$file = $updir.'/'.$row[0];
2679
+		if (Security::check_abs_path($file, $updir))
2680 2680
 		{
2681 2681
 			@ unlink($file);
2682 2682
 		}
2683 2683
 	}
2684
-	$sql = 'DELETE FROM '. $blog_table_attachment.'
2684
+	$sql = 'DELETE FROM '.$blog_table_attachment.'
2685 2685
 	        WHERE c_id = '.$course_id.' AND  blog_id ="'.intval($blog_id).'"  '.$where;
2686 2686
 	Database::query($sql);
2687 2687
 }
@@ -2694,8 +2694,8 @@  discard block
 block discarded – undo
2694 2694
 function get_blog_post_from_user($course_code, $user_id)
2695 2695
 {
2696 2696
 	$tbl_blogs 		= Database::get_course_table(TABLE_BLOGS);
2697
-	$tbl_blog_post 	= Database::get_course_table(TABLE_BLOGS_POSTS);
2698
-	$course_info 	= api_get_course_info($course_code);
2697
+	$tbl_blog_post = Database::get_course_table(TABLE_BLOGS_POSTS);
2698
+	$course_info = api_get_course_info($course_code);
2699 2699
 	$course_id 		= $course_info['real_id'];
2700 2700
 
2701 2701
 	$sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation
@@ -2710,13 +2710,13 @@  discard block
 block discarded – undo
2710 2710
 	$result = Database::query($sql);
2711 2711
 	$return_data = '';
2712 2712
 
2713
-	if (Database::num_rows($result)!=0) {
2714
-		while ($row=Database::fetch_array($result)) {
2715
-			$return_data.=  '<div class="clear"></div><br />';
2716
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png',get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2717
-			$return_data.=  '<br / >';
2718
-			$return_data.= $row['full_text'];
2719
-			$return_data.= '<br /><br />';
2713
+	if (Database::num_rows($result) != 0) {
2714
+		while ($row = Database::fetch_array($result)) {
2715
+			$return_data .= '<div class="clear"></div><br />';
2716
+			$return_data .= '<div class="actions" style="margin-left:5px;margin-right:5px;">'.Display::return_icon('blog_article.png', get_lang('BlogPosts')).' '.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.$my_course_id.' " >'.get_lang('SeeBlog').'</a></div></div>';
2717
+			$return_data .= '<br / >';
2718
+			$return_data .= $row['full_text'];
2719
+			$return_data .= '<br /><br />';
2720 2720
 		}
2721 2721
 	}
2722 2722
 	return $return_data;
@@ -2746,14 +2746,14 @@  discard block
 block discarded – undo
2746 2746
 			ORDER BY blog_name";
2747 2747
 	$result = Database::query($sql);
2748 2748
 	$return_data = '';
2749
-	if (Database::num_rows($result)!=0) {
2750
-		while ($row=Database::fetch_array($result)) {
2751
-			$return_data.=  '<div class="clear"></div><br />';
2752
-			$return_data.=  '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2753
-			$return_data.=  '<br / >';
2749
+	if (Database::num_rows($result) != 0) {
2750
+		while ($row = Database::fetch_array($result)) {
2751
+			$return_data .= '<div class="clear"></div><br />';
2752
+			$return_data .= '<div class="actions" style="margin-left:5px;margin-right:5px;">'.$row['title'].'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:right;margin-top:-18px"><a href="../blog/blog.php?blog_id='.$row['blog_id'].'&gidReq=&cidReq='.Security::remove_XSS($course_code).' " >'.get_lang('SeeBlog').'</a></div></div>';
2753
+			$return_data .= '<br / >';
2754 2754
 			//$return_data.=  '<strong>'.$row['title'].'</strong>'; echo '<br>';*/
2755
-			$return_data.=  $row['comment'];
2756
-			$return_data.=  '<br />';
2755
+			$return_data .= $row['comment'];
2756
+			$return_data .= '<br />';
2757 2757
 		}
2758 2758
 	}
2759 2759
 	return $return_data;
Please login to merge, or discard this patch.
main/exercice/answer.class.php 1 patch
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
         return [];
156 156
     }
157 157
 
158
-     /**
159
-     * returns all answer ids from this question Id
160
-     *
161
-     * @author Yoselyn Castillo
162
-     * @return array - $id (answer ids)
163
-     */
158
+        /**
159
+         * returns all answer ids from this question Id
160
+         *
161
+         * @author Yoselyn Castillo
162
+         * @return array - $id (answer ids)
163
+         */
164 164
     public function selectAnswerId()
165 165
     {
166 166
         $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         }
181 181
 
182 182
         return $id;
183
-	}
183
+    }
184 184
 
185 185
     /**
186 186
      * Reads answer information from the data base ordered by parameter
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public function readOrderedBy($field, $order='ASC')
192 192
     {
193
-		$field = Database::escape_string($field);
194
-		if (empty($field)) {
195
-			$field = 'position';
196
-		}
193
+        $field = Database::escape_string($field);
194
+        if (empty($field)) {
195
+            $field = 'position';
196
+        }
197 197
 
198
-		if ($order != 'ASC' && $order!='DESC') {
199
-			$order = 'ASC';
200
-		}
198
+        if ($order != 'ASC' && $order!='DESC') {
199
+            $order = 'ASC';
200
+        }
201 201
 
202
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
203
-		$TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
204
-		$questionId = intval($this->questionId);
202
+        $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
203
+        $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
204
+        $questionId = intval($this->questionId);
205 205
 
206
-		$sql = "SELECT type FROM $TBL_QUIZ
206
+        $sql = "SELECT type FROM $TBL_QUIZ
207 207
 		        WHERE c_id = {$this->course_id} AND id = $questionId";
208
-		$result_question = Database::query($sql);
209
-		$questionType = Database::fetch_array($result_question);
208
+        $result_question = Database::query($sql);
209
+        $questionType = Database::fetch_array($result_question);
210 210
 
211 211
         if ($questionType['type'] == DRAGGABLE) {
212 212
             // Random is done by submit.js.tpl
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
             return true;
216 216
         }
217 217
 
218
-		$sql = "SELECT
218
+        $sql = "SELECT
219 219
 		            answer,
220 220
 		            correct,
221 221
 		            comment,
@@ -230,16 +230,16 @@  discard block
 block discarded – undo
230 230
                     c_id = {$this->course_id} AND
231 231
                     question_id='".$questionId."'
232 232
                 ORDER BY $field $order";
233
-		$result=Database::query($sql);
234
-
235
-		$i = 1;
236
-		// while a record is found
237
-		$doubt_data = null;
238
-		while ($object = Database::fetch_object($result)) {
239
-		    if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
240
-		        $doubt_data = $object;
233
+        $result=Database::query($sql);
234
+
235
+        $i = 1;
236
+        // while a record is found
237
+        $doubt_data = null;
238
+        while ($object = Database::fetch_object($result)) {
239
+            if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
240
+                $doubt_data = $object;
241 241
                 continue;
242
-		    }
242
+            }
243 243
             $this->answer[$i] = $object->answer;
244 244
             $this->correct[$i] = $object->correct;
245 245
             $this->comment[$i] = $object->comment;
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
             $this->destination[$i] = $object->destination;
251 251
             $this->autoId[$i] = $object->id_auto;
252 252
             $i++;
253
-		}
253
+        }
254 254
 
255
-		if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
255
+        if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
256 256
             $this->answer[$i] = $doubt_data->answer;
257 257
             $this->correct[$i] = $doubt_data->correct;
258 258
             $this->comment[$i] = $doubt_data->comment;
@@ -263,86 +263,86 @@  discard block
 block discarded – undo
263 263
             $this->destination[$i] = $doubt_data->destination;
264 264
             $this->autoId[$i] = $doubt_data->id_auto;
265 265
             $i++;
266
-	    }
266
+        }
267 267
         $this->nbrAnswers = $i-1;
268
-	}
269
-
270
-	/**
271
-	 * returns the autoincrement id identificator
272
-	 *
273
-	 * @author Juan Carlos Ra�a
274
-	 * @return integer - answer num
275
-	 */
268
+    }
269
+
270
+    /**
271
+     * returns the autoincrement id identificator
272
+     *
273
+     * @author Juan Carlos Ra�a
274
+     * @return integer - answer num
275
+     */
276 276
     public function selectAutoId($id)
277 277
     {
278
-		return isset($this->autoId[$id]) ? $this->autoId[$id] : 0;
279
-	}
280
-
281
-	/**
282
-	 * returns the number of answers in this question
283
-	 *
284
-	 * @author Olivier Brouckaert
285
-	 * @return integer - number of answers
286
-	 */
287
-	public function selectNbrAnswers()
278
+        return isset($this->autoId[$id]) ? $this->autoId[$id] : 0;
279
+    }
280
+
281
+    /**
282
+     * returns the number of answers in this question
283
+     *
284
+     * @author Olivier Brouckaert
285
+     * @return integer - number of answers
286
+     */
287
+    public function selectNbrAnswers()
288 288
     {
289
-		return $this->nbrAnswers;
290
-	}
291
-
292
-	/**
293
-	 * returns the question ID which the answers belong to
294
-	 *
295
-	 * @author Olivier Brouckaert
296
-	 * @return integer - the question ID
297
-	 */
298
-	public function selectQuestionId()
289
+        return $this->nbrAnswers;
290
+    }
291
+
292
+    /**
293
+     * returns the question ID which the answers belong to
294
+     *
295
+     * @author Olivier Brouckaert
296
+     * @return integer - the question ID
297
+     */
298
+    public function selectQuestionId()
299 299
     {
300
-		return $this->questionId;
301
-	}
302
-
303
-	/**
304
-	 * returns the question ID of the destination question
305
-	 *
306
-	 * @author Julio Montoya
307
-	 * @return integer - the question ID
308
-	 */
309
-	public function selectDestination($id)
300
+        return $this->questionId;
301
+    }
302
+
303
+    /**
304
+     * returns the question ID of the destination question
305
+     *
306
+     * @author Julio Montoya
307
+     * @return integer - the question ID
308
+     */
309
+    public function selectDestination($id)
310 310
     {
311
-		return isset($this->destination[$id]) ? $this->destination[$id] : null;
312
-	}
311
+        return isset($this->destination[$id]) ? $this->destination[$id] : null;
312
+    }
313 313
 
314 314
     /**
315
-	 * returns the answer title
316
-	 *
317
-	 * @author Olivier Brouckaert
318
-	 * @param - integer $id - answer ID
319
-	 * @return string - answer title
320
-	 */
321
-	public function selectAnswer($id)
322
-	{
323
-		return isset($this->answer[$id]) ? $this->answer[$id] : null;
324
-	}
325
-
326
-	/**
327
-	 * return array answer by id else return a bool
328
-	 */
329
-	public function selectAnswerByAutoId($auto_id)
330
-	{
331
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
332
-
333
-		$auto_id = intval($auto_id);
334
-		$sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER
315
+     * returns the answer title
316
+     *
317
+     * @author Olivier Brouckaert
318
+     * @param - integer $id - answer ID
319
+     * @return string - answer title
320
+     */
321
+    public function selectAnswer($id)
322
+    {
323
+        return isset($this->answer[$id]) ? $this->answer[$id] : null;
324
+    }
325
+
326
+    /**
327
+     * return array answer by id else return a bool
328
+     */
329
+    public function selectAnswerByAutoId($auto_id)
330
+    {
331
+        $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
332
+
333
+        $auto_id = intval($auto_id);
334
+        $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER
335 335
 				WHERE c_id = {$this->course_id} AND id_auto='$auto_id'";
336
-		$rs = Database::query($sql);
336
+        $rs = Database::query($sql);
337 337
 
338
-		if (Database::num_rows($rs) > 0) {
339
-			$row = Database::fetch_array($rs, 'ASSOC');
338
+        if (Database::num_rows($rs) > 0) {
339
+            $row = Database::fetch_array($rs, 'ASSOC');
340 340
 
341
-			return $row;
342
-		}
341
+            return $row;
342
+        }
343 343
 
344
-		return false;
345
-	}
344
+        return false;
345
+    }
346 346
 
347 347
     /**
348 348
      * returns the answer title from an answer's position
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
      * @param - integer $id - answer ID
352 352
      * @return bool - answer title
353 353
      */
354
-	public function selectAnswerIdByPosition($pos)
355
-	{
356
-		foreach ($this->position as $k => $v) {
357
-			if ($v != $pos) {
358
-				continue;
359
-			}
354
+    public function selectAnswerIdByPosition($pos)
355
+    {
356
+        foreach ($this->position as $k => $v) {
357
+            if ($v != $pos) {
358
+                continue;
359
+            }
360 360
 
361
-			return $k;
362
-		}
361
+            return $k;
362
+        }
363 363
 
364
-		return false;
365
-	}
364
+        return false;
365
+    }
366 366
 
367 367
     /**
368 368
      * Returns a list of answers
@@ -371,18 +371,18 @@  discard block
 block discarded – undo
371 371
      * of (id, answer, comment, grade) and grade=weighting
372 372
      */
373 373
     public function getAnswersList($decode = false)
374
-     {
375
-	 	$list = array();
376
-         for ($i = 1; $i <= $this->nbrAnswers; $i++) {
377
-             if (!empty($this->answer[$i])) {
378
-
379
-	 			//Avoid problems when parsing elements with accents
380
-	 			if ($decode) {
381
-	        		$this->answer[$i] 	= api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
382
-	        		$this->comment[$i]	= api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
383
-	 			}
384
-
385
-	 			$list[] = array(
374
+        {
375
+            $list = array();
376
+            for ($i = 1; $i <= $this->nbrAnswers; $i++) {
377
+                if (!empty($this->answer[$i])) {
378
+
379
+                    //Avoid problems when parsing elements with accents
380
+                    if ($decode) {
381
+                    $this->answer[$i] 	= api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
382
+                    $this->comment[$i]	= api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
383
+                    }
384
+
385
+                    $list[] = array(
386 386
                     'id' => $i,
387 387
                     'answer' => $this->answer[$i],
388 388
                     'comment' => $this->comment[$i],
@@ -391,134 +391,134 @@  discard block
 block discarded – undo
391 391
                     'hotspot_type' => $this->hotspot_type[$i],
392 392
                     'correct' => $this->correct[$i],
393 393
                     'destination' => $this->destination[$i]
394
-				);
394
+                );
395
+            }
395 396
             }
396
-	 	}
397 397
 
398
-	 	return $list;
399
-	 }
398
+            return $list;
399
+        }
400 400
 
401
-	/**
402
-	 * Returns a list of grades
403
-	 * @author Yannick Warnier <[email protected]>
404
-	 * @return array	List of grades where grade=weighting (?)
405
-	 */
401
+    /**
402
+     * Returns a list of grades
403
+     * @author Yannick Warnier <[email protected]>
404
+     * @return array	List of grades where grade=weighting (?)
405
+     */
406 406
     public function getGradesList()
407
-     {
408
-	 	$list = array();
409
-	 	for ($i = 0; $i<$this->nbrAnswers;$i++){
410
-	 		if(!empty($this->answer[$i])){
411
-	 			$list[$i] = $this->weighting[$i];
412
-	 		}
413
-	 	}
414
-	 	return $list;
415
-	 }
416
-
417
-	 /**
418
-	  * Returns the question type
419
-	  * @author	Yannick Warnier <[email protected]>
420
-	  * @return	integer	The type of the question this answer is bound to
421
-	  */
407
+        {
408
+            $list = array();
409
+            for ($i = 0; $i<$this->nbrAnswers;$i++){
410
+                if(!empty($this->answer[$i])){
411
+                    $list[$i] = $this->weighting[$i];
412
+                }
413
+            }
414
+            return $list;
415
+        }
416
+
417
+        /**
418
+         * Returns the question type
419
+         * @author	Yannick Warnier <[email protected]>
420
+         * @return	integer	The type of the question this answer is bound to
421
+         */
422 422
     public function getQuestionType()
423
-     {
424
-	 	$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
425
-	 	$sql = "SELECT type FROM $TBL_QUESTIONS
423
+        {
424
+            $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
425
+            $sql = "SELECT type FROM $TBL_QUESTIONS
426 426
 	 	        WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'";
427
-	 	$res = Database::query($sql);
428
-	 	if (Database::num_rows($res)<=0){
429
-	 		return null;
430
-	 	}
431
-	 	$row = Database::fetch_array($res);
432
-
433
-	 	return $row['type'];
434
-	 }
435
-
436
-
437
-	/**
438
-	 * tells if answer is correct or not
439
-	 *
440
-	 * @author Olivier Brouckaert
441
-	 * @param - integer $id - answer ID
442
-	 * @return integer - 0 if bad answer, not 0 if good answer
443
-	 */
427
+            $res = Database::query($sql);
428
+            if (Database::num_rows($res)<=0){
429
+                return null;
430
+            }
431
+            $row = Database::fetch_array($res);
432
+
433
+            return $row['type'];
434
+        }
435
+
436
+
437
+    /**
438
+     * tells if answer is correct or not
439
+     *
440
+     * @author Olivier Brouckaert
441
+     * @param - integer $id - answer ID
442
+     * @return integer - 0 if bad answer, not 0 if good answer
443
+     */
444 444
     public function isCorrect($id)
445
-	{
446
-		return isset($this->correct[$id]) ? $this->correct[$id] : null;
447
-	}
448
-
449
-	/**
450
-	 * returns answer comment
451
-	 *
452
-	 * @author Olivier Brouckaert
453
-	 * @param - integer $id - answer ID
454
-	 * @return string - answer comment
455
-	 */
445
+    {
446
+        return isset($this->correct[$id]) ? $this->correct[$id] : null;
447
+    }
448
+
449
+    /**
450
+     * returns answer comment
451
+     *
452
+     * @author Olivier Brouckaert
453
+     * @param - integer $id - answer ID
454
+     * @return string - answer comment
455
+     */
456 456
     public function selectComment($id)
457
-	{
457
+    {
458 458
         return isset($this->comment[$id]) ? $this->comment[$id] : null;
459
-	}
460
-
461
-	/**
462
-	 * returns answer weighting
463
-	 *
464
-	 * @author Olivier Brouckaert
465
-	 * @param - integer $id - answer ID
466
-	 * @return integer - answer weighting
467
-	 */
459
+    }
460
+
461
+    /**
462
+     * returns answer weighting
463
+     *
464
+     * @author Olivier Brouckaert
465
+     * @param - integer $id - answer ID
466
+     * @return integer - answer weighting
467
+     */
468 468
     public function selectWeighting($id)
469
-	{
470
-		return isset($this->weighting[$id]) ? $this->weighting[$id] : null;
471
-	}
472
-
473
-	/**
474
-	 * returns answer position
475
-	 *
476
-	 * @author Olivier Brouckaert
477
-	 * @param - integer $id - answer ID
478
-	 * @return integer - answer position
479
-	 */
480
-	function selectPosition($id)
481
-	{
482
-		return isset($this->position[$id]) ? $this->position[$id] : null;
483
-	}
484
-
485
-	/**
486
-	 * returns answer hotspot coordinates
487
-	 *
488
-	 * @author	Olivier Brouckaert
489
-	 * @param	integer	Answer ID
490
-	 * @return	integer	Answer position
491
-	 */
469
+    {
470
+        return isset($this->weighting[$id]) ? $this->weighting[$id] : null;
471
+    }
472
+
473
+    /**
474
+     * returns answer position
475
+     *
476
+     * @author Olivier Brouckaert
477
+     * @param - integer $id - answer ID
478
+     * @return integer - answer position
479
+     */
480
+    function selectPosition($id)
481
+    {
482
+        return isset($this->position[$id]) ? $this->position[$id] : null;
483
+    }
484
+
485
+    /**
486
+     * returns answer hotspot coordinates
487
+     *
488
+     * @author	Olivier Brouckaert
489
+     * @param	integer	Answer ID
490
+     * @return	integer	Answer position
491
+     */
492 492
     public function selectHotspotCoordinates($id)
493
-	{
494
-		return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
495
-	}
496
-
497
-	/**
498
-	 * returns answer hotspot type
499
-	 *
500
-	 * @author	Toon Keppens
501
-	 * @param	integer		Answer ID
502
-	 * @return	integer		Answer position
503
-	 */
493
+    {
494
+        return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
495
+    }
496
+
497
+    /**
498
+     * returns answer hotspot type
499
+     *
500
+     * @author	Toon Keppens
501
+     * @param	integer		Answer ID
502
+     * @return	integer		Answer position
503
+     */
504 504
     public function selectHotspotType($id)
505
-	{
506
-		return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
507
-	}
508
-
509
-	/**
510
-	 * Creates a new answer
511
-	 *
512
-	 * @author Olivier Brouckaert
513
-	 * @param string 	$answer answer title
514
-	 * @param integer 	$correct 0 if bad answer, not 0 if good answer
515
-	 * @param string 	$comment answer comment
516
-	 * @param integer 	$weighting answer weighting
517
-	 * @param integer 	$position answer position
518
-	 * @param array    $new_hotspot_coordinates Coordinates for hotspot exercises (optional)
519
-	 * @param integer	$new_hotspot_type Type for hotspot exercises (optional)
505
+    {
506
+        return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
507
+    }
508
+
509
+    /**
510
+     * Creates a new answer
511
+     *
512
+     * @author Olivier Brouckaert
513
+     * @param string 	$answer answer title
514
+     * @param integer 	$correct 0 if bad answer, not 0 if good answer
515
+     * @param string 	$comment answer comment
516
+     * @param integer 	$weighting answer weighting
517
+     * @param integer 	$position answer position
518
+     * @param array    $new_hotspot_coordinates Coordinates for hotspot exercises (optional)
519
+     * @param integer	$new_hotspot_type Type for hotspot exercises (optional)
520 520
      * @param string   $destination
521
-	 */
521
+     */
522 522
     public function createAnswer(
523 523
         $answer,
524 524
         $correct,
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
         $new_hotspot_type = null,
530 530
         $destination = ''
531 531
     ) {
532
-		$this->new_nbrAnswers++;
532
+        $this->new_nbrAnswers++;
533 533
         $id = $this->new_nbrAnswers;
534 534
         $this->new_answer[$id] = $answer;
535 535
         $this->new_correct[$id] = $correct;
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         $this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates;
540 540
         $this->new_hotspot_type[$id] = $new_hotspot_type;
541 541
         $this->new_destination[$id] = $destination;
542
-	}
542
+    }
543 543
 
544 544
     /**
545 545
      * Updates an answer
@@ -582,31 +582,31 @@  discard block
 block discarded – undo
582 582
         ];
583 583
 
584 584
         Database::update($answerTable, $params, ['id_auto = ?' => $autoId]);
585
-	}
585
+    }
586 586
 
587
-	/**
588
-	 * Records answers into the data base
589
-	 *
590
-	 * @author Olivier Brouckaert
591
-	 */
587
+    /**
588
+     * Records answers into the data base
589
+     *
590
+     * @author Olivier Brouckaert
591
+     */
592 592
     public function save()
593 593
     {
594
-		$answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
595
-		$questionId = intval($this->questionId);
594
+        $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
595
+        $questionId = intval($this->questionId);
596 596
 
597
-		$c_id = $this->course['real_id'];
597
+        $c_id = $this->course['real_id'];
598 598
         $correctList = [];
599 599
         $answerList = [];
600 600
 
601
-		for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
602
-			$answer = $this->new_answer[$i];
603
-			$correct = $this->new_correct[$i];
604
-			$comment = $this->new_comment[$i];
605
-			$weighting = $this->new_weighting[$i];
606
-			$position = $this->new_position[$i];
607
-			$hotspot_coordinates = $this->new_hotspot_coordinates[$i];
608
-			$hotspot_type = $this->new_hotspot_type[$i];
609
-			$destination = $this->new_destination[$i];
601
+        for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
602
+            $answer = $this->new_answer[$i];
603
+            $correct = $this->new_correct[$i];
604
+            $comment = $this->new_comment[$i];
605
+            $weighting = $this->new_weighting[$i];
606
+            $position = $this->new_position[$i];
607
+            $hotspot_coordinates = $this->new_hotspot_coordinates[$i];
608
+            $hotspot_type = $this->new_hotspot_type[$i];
609
+            $destination = $this->new_destination[$i];
610 610
             $autoId = $this->selectAutoId($i);
611 611
 
612 612
             if (!isset($this->position[$i])) {
@@ -704,36 +704,36 @@  discard block
 block discarded – undo
704 704
             }
705 705
         }
706 706
 
707
-		// moves $new_* arrays
708
-		$this->answer = $this->new_answer;
709
-		$this->correct = $this->new_correct;
710
-		$this->comment = $this->new_comment;
711
-		$this->weighting = $this->new_weighting;
712
-		$this->position = $this->new_position;
713
-		$this->hotspot_coordinates = $this->new_hotspot_coordinates;
714
-		$this->hotspot_type = $this->new_hotspot_type;
715
-
716
-		$this->nbrAnswers = $this->new_nbrAnswers;
717
-		$this->destination = $this->new_destination;
718
-		// clears $new_* arrays
719
-
720
-		$this->cancel();
721
-	}
722
-
723
-	/**
724
-	 * Duplicates answers by copying them into another question
725
-	 *
726
-	 * @author Olivier Brouckaert
727
-	 * @param  int question id
707
+        // moves $new_* arrays
708
+        $this->answer = $this->new_answer;
709
+        $this->correct = $this->new_correct;
710
+        $this->comment = $this->new_comment;
711
+        $this->weighting = $this->new_weighting;
712
+        $this->position = $this->new_position;
713
+        $this->hotspot_coordinates = $this->new_hotspot_coordinates;
714
+        $this->hotspot_type = $this->new_hotspot_type;
715
+
716
+        $this->nbrAnswers = $this->new_nbrAnswers;
717
+        $this->destination = $this->new_destination;
718
+        // clears $new_* arrays
719
+
720
+        $this->cancel();
721
+    }
722
+
723
+    /**
724
+     * Duplicates answers by copying them into another question
725
+     *
726
+     * @author Olivier Brouckaert
727
+     * @param  int question id
728 728
      * @param  array destination course info (result of the function api_get_course_info() )
729
-	 */
729
+     */
730 730
     public function duplicate($newQuestionId, $course_info = null)
731 731
     {
732 732
         if (empty($course_info)) {
733 733
             $course_info = $this->course;
734 734
         }
735 735
 
736
-		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
736
+        $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
737 737
         $fixed_list = array();
738 738
 
739 739
         if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 
748 748
             if (!empty($origin_options)) {
749 749
                 foreach ($origin_options as $item) {
750
-            	   $new_option_list[] = $item['id'];
750
+                    $new_option_list[] = $item['id'];
751 751
                 }
752 752
             }
753 753
 
@@ -761,12 +761,12 @@  discard block
 block discarded – undo
761 761
             }
762 762
         }
763 763
 
764
-		// if at least one answer
765
-		if ($this->nbrAnswers) {
766
-			// inserts new answers into data base
767
-			$c_id = $course_info['real_id'];
764
+        // if at least one answer
765
+        if ($this->nbrAnswers) {
766
+            // inserts new answers into data base
767
+            $c_id = $course_info['real_id'];
768 768
 
769
-			for ($i=1;$i <= $this->nbrAnswers;$i++) {
769
+            for ($i=1;$i <= $this->nbrAnswers;$i++) {
770 770
                 if ($this->course['id'] != $course_info['id']) {
771 771
                     $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
772 772
                         $this->answer[$i],
@@ -780,8 +780,8 @@  discard block
 block discarded – undo
780 780
                     );
781 781
                 }
782 782
 
783
-				$answer = $this->answer[$i];
784
-				$correct = $this->correct[$i];
783
+                $answer = $this->answer[$i];
784
+                $correct = $this->correct[$i];
785 785
 
786 786
                 if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
787 787
                     self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE
@@ -789,12 +789,12 @@  discard block
 block discarded – undo
789 789
                     $correct = $fixed_list[intval($correct)];
790 790
                 }
791 791
 
792
-				$comment = $this->comment[$i];
793
-				$weighting = $this->weighting[$i];
794
-				$position = $this->position[$i];
795
-				$hotspot_coordinates = $this->hotspot_coordinates[$i];
796
-				$hotspot_type = $this->hotspot_type[$i];
797
-				$destination = $this->destination[$i];
792
+                $comment = $this->comment[$i];
793
+                $weighting = $this->weighting[$i];
794
+                $position = $this->position[$i];
795
+                $hotspot_coordinates = $this->hotspot_coordinates[$i];
796
+                $hotspot_type = $this->hotspot_type[$i];
797
+                $destination = $this->destination[$i];
798 798
 
799 799
                 $params = [
800 800
                     'c_id' => $c_id,
@@ -814,9 +814,9 @@  discard block
 block discarded – undo
814 814
                     $sql = "UPDATE $TBL_REPONSES SET id = iid, id_auto = iid WHERE iid = $id";
815 815
                     Database::query($sql);
816 816
                 }
817
-			}
817
+            }
818 818
         }
819
-	}
819
+    }
820 820
 
821 821
     /**
822 822
      * Get the necessary JavaScript for some answers
Please login to merge, or discard this patch.
main/dropbox/dropbox_class.inc.php 1 patch
Indentation   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
         }
78 78
     }
79 79
 
80
-	/**
81
-	 * private function creating a new work object
82
-	 *
83
-	 * @param int $uploader_id
84
-	 * @param string $title
85
-	 * @param string $description
86
-	 * @param string $author
87
-	 * @param string $filename
88
-	 * @param int $filesize
89
-	 *
90
-	 * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
-	 * 			As a consequence this parameter can be removed
92
-	 */
93
-	public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
80
+    /**
81
+     * private function creating a new work object
82
+     *
83
+     * @param int $uploader_id
84
+     * @param string $title
85
+     * @param string $description
86
+     * @param string $author
87
+     * @param string $filename
88
+     * @param int $filesize
89
+     *
90
+     * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
+     * 			As a consequence this parameter can be removed
92
+     */
93
+    public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
94 94
     {
95 95
         $dropbox_cnf = getDropboxConf();
96 96
 
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
         // Check if object exists already. If it does, the old object is used
109 109
         // with updated information (authors, description, upload_date)
110 110
         $this->isOldWork = false;
111
-		$sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
111
+        $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
112 112
 				WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'";
113 113
         $result = Database::query($sql);
114
-		$res = Database::fetch_array($result);
115
-		if ($res) {
116
-			$this->isOldWork = true;
117
-		}
118
-		// Insert or update the dropbox_file table and set the id property
119
-		if ($this->isOldWork) {
120
-			$this->id = $res['id'];
121
-			$this->upload_date = $res['upload_date'];
114
+        $res = Database::fetch_array($result);
115
+        if ($res) {
116
+            $this->isOldWork = true;
117
+        }
118
+        // Insert or update the dropbox_file table and set the id property
119
+        if ($this->isOldWork) {
120
+            $this->id = $res['id'];
121
+            $this->upload_date = $res['upload_date'];
122 122
 
123 123
             $params = [
124 124
                 'filesize' => $this->filesize,
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
                 ['c_id = ? AND id = ?' => [$course_id, $this->id]]
136 136
             );
137 137
 
138
-		} else {
139
-			$this->upload_date = $this->last_upload_date;
140
-			$params = [
138
+        } else {
139
+            $this->upload_date = $this->last_upload_date;
140
+            $params = [
141 141
                 'c_id' => $course_id,
142 142
                 'uploader_id' => $this->uploader_id,
143 143
                 'filename' => $this->filename,
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
                 'last_upload_date' => $this->last_upload_date,
150 150
                 'session_id' => api_get_session_id(),
151 151
                 'cat_id' => 0
152
-			];
152
+            ];
153 153
 
154
-			$this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
-			if ($this->id) {
156
-				$sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
-				Database::query($sql);
158
-			}
159
-		}
154
+            $this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
+            if ($this->id) {
156
+                $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
+                Database::query($sql);
158
+            }
159
+        }
160 160
 
161 161
         $sql = "SELECT count(file_id) as count
162 162
         		FROM ".$dropbox_cnf['tbl_person']."
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
                     VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")";
171 171
             Database::query($sql);
172 172
         }
173
-	}
174
-
175
-	/**
176
-	 * private function creating existing object by retreiving info from db
177
-	 *
178
-	 * @param int $id
179
-	 */
180
-	public function _createExistingWork($id)
173
+    }
174
+
175
+    /**
176
+     * private function creating existing object by retreiving info from db
177
+     *
178
+     * @param int $id
179
+     */
180
+    public function _createExistingWork($id)
181 181
     {
182
-	    $course_id = api_get_course_int_id();
182
+        $course_id = api_get_course_int_id();
183 183
         $dropbox_cnf = getDropboxConf();
184 184
 
185 185
         $action = isset($_GET['action']) ? $_GET['action'] : null;
@@ -229,52 +229,52 @@  discard block
 block discarded – undo
229 229
             }
230 230
             $this->feedback2= $feedback2;
231 231
         }
232
-	}
232
+    }
233 233
 }
234 234
 
235 235
 class Dropbox_SentWork extends Dropbox_Work
236 236
 {
237
-	public $recipients;	//array of ['id']['name'] arrays
238
-
239
-	/**
240
-	 * Constructor calls private functions to create a new work or retreive an existing work from DB
241
-	 * depending on the number of parameters
242
-	 *
243
-	 * @param unknown_type $arg1
244
-	 * @param unknown_type $arg2
245
-	 * @param unknown_type $arg3
246
-	 * @param unknown_type $arg4
247
-	 * @param unknown_type $arg5
248
-	 * @param unknown_type $arg6
249
-	 * @param unknown_type $arg7
250
-	 * @return Dropbox_SentWork
251
-	 */
252
-	public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
237
+    public $recipients;	//array of ['id']['name'] arrays
238
+
239
+    /**
240
+     * Constructor calls private functions to create a new work or retreive an existing work from DB
241
+     * depending on the number of parameters
242
+     *
243
+     * @param unknown_type $arg1
244
+     * @param unknown_type $arg2
245
+     * @param unknown_type $arg3
246
+     * @param unknown_type $arg4
247
+     * @param unknown_type $arg5
248
+     * @param unknown_type $arg6
249
+     * @param unknown_type $arg7
250
+     * @return Dropbox_SentWork
251
+     */
252
+    public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
253 253
     {
254
-		if (func_num_args() > 1) {
255
-		    $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
-		} else {
257
-			$this->_createExistingSentWork($arg1);
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * private function creating a new SentWork object
263
-	 *
264
-	 * @param int $uploader_id
265
-	 * @param string $title
266
-	 * @param string $description
267
-	 * @param string $author
268
-	 * @param string $filename
269
-	 * @param int $filesize
270
-	 * @param array $recipient_ids
271
-	 */
272
-	public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
254
+        if (func_num_args() > 1) {
255
+            $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
+        } else {
257
+            $this->_createExistingSentWork($arg1);
258
+        }
259
+    }
260
+
261
+    /**
262
+     * private function creating a new SentWork object
263
+     *
264
+     * @param int $uploader_id
265
+     * @param string $title
266
+     * @param string $description
267
+     * @param string $author
268
+     * @param string $filename
269
+     * @param int $filesize
270
+     * @param array $recipient_ids
271
+     */
272
+    public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
273 273
     {
274 274
         $dropbox_cnf = getDropboxConf();
275 275
         $_course = api_get_course_info();
276 276
 
277
-		// Call constructor of Dropbox_Work object
277
+        // Call constructor of Dropbox_Work object
278 278
         parent::__construct(
279 279
             $uploader_id,
280 280
             $title,
@@ -284,31 +284,31 @@  discard block
 block discarded – undo
284 284
             $filesize
285 285
         );
286 286
 
287
-		$course_id = api_get_course_int_id();
288
-
289
-		// Do sanity checks on recipient_ids array & property fillin
290
-		// The sanity check for ex-coursemembers is already done in base constructor
291
-		settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
287
+        $course_id = api_get_course_int_id();
292 288
 
293
-		$justSubmit = false;
294
-		if ( is_int($recipient_ids)) {
295
-			$justSubmit = true;
296
-			$recipient_ids = array($recipient_ids + $this->id);
297
-		} elseif ( count($recipient_ids) == 0) {
298
-			$justSubmit = true;
299
-			$recipient_ids = array($uploader_id);
300
-		}
289
+        // Do sanity checks on recipient_ids array & property fillin
290
+        // The sanity check for ex-coursemembers is already done in base constructor
291
+        settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
292
+
293
+        $justSubmit = false;
294
+        if ( is_int($recipient_ids)) {
295
+            $justSubmit = true;
296
+            $recipient_ids = array($recipient_ids + $this->id);
297
+        } elseif ( count($recipient_ids) == 0) {
298
+            $justSubmit = true;
299
+            $recipient_ids = array($uploader_id);
300
+        }
301 301
 
302
-		if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
-			die(get_lang('GeneralError').' (code 209)');
304
-		}
302
+        if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
+            die(get_lang('GeneralError').' (code 209)');
304
+        }
305 305
 
306
-		foreach ($recipient_ids as $rec) {
307
-			if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
-			//if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
-				//this check is done when validating submitted data
310
-			$this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
-		}
306
+        foreach ($recipient_ids as $rec) {
307
+            if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
+            //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
+                //this check is done when validating submitted data
310
+            $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
+        }
312 312
 
313 313
         $table_post = $dropbox_cnf['tbl_post'];
314 314
         $table_person = $dropbox_cnf['tbl_person'];
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
         $user  = api_get_user_id();
318 318
         $now = api_get_utc_datetime();
319 319
 
320
-		// Insert data in dropbox_post and dropbox_person table for each recipient
321
-		foreach ($this->recipients as $rec) {
320
+        // Insert data in dropbox_post and dropbox_person table for each recipient
321
+        foreach ($this->recipients as $rec) {
322 322
             $file_id = (int)$this->id;
323 323
             $user_id = (int)$rec['id'];
324
-			$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
324
+            $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
325 325
                     VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)";
326
-	        Database::query($sql);
326
+            Database::query($sql);
327 327
             // If work already exists no error is generated
328 328
 
329 329
             /**
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
                 }
341 341
             }
342 342
 
343
-			// Update item_property table for each recipient
344
-			if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
-			    $ownerid = getUserOwningThisMailing($ownerid);
346
-			}
347
-			if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
-			    $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
-			}
343
+            // Update item_property table for each recipient
344
+            if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
+                $ownerid = getUserOwningThisMailing($ownerid);
346
+            }
347
+            if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
+                $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
+            }
350 350
             api_item_property_update(
351 351
                 $_course,
352 352
                 TOOL_DROPBOX,
@@ -356,92 +356,92 @@  discard block
 block discarded – undo
356 356
                 null,
357 357
                 $recipid
358 358
             );
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * private function creating existing object by retreiving info from db
364
-	 *
365
-	 * @param unknown_type $id
366
-	 */
367
-	public function _createExistingSentWork($id)
359
+        }
360
+    }
361
+
362
+    /**
363
+     * private function creating existing object by retreiving info from db
364
+     *
365
+     * @param unknown_type $id
366
+     */
367
+    public function _createExistingSentWork($id)
368 368
     {
369 369
         $dropbox_cnf = getDropboxConf();
370 370
         $id = intval($id);
371 371
 
372
-		$course_id = api_get_course_int_id();
372
+        $course_id = api_get_course_int_id();
373 373
 
374
-		// Call constructor of Dropbox_Work object
375
-		parent::__construct($id);
374
+        // Call constructor of Dropbox_Work object
375
+        parent::__construct($id);
376 376
 
377
-		// Fill in recipients array
378
-		$this->recipients = array();
379
-		$sql = "SELECT dest_user_id, feedback_date, feedback
377
+        // Fill in recipients array
378
+        $this->recipients = array();
379
+        $sql = "SELECT dest_user_id, feedback_date, feedback
380 380
 				FROM ".$dropbox_cnf['tbl_post']."
381 381
 				WHERE c_id = $course_id AND file_id = ".intval($id)."";
382 382
         $result = Database::query($sql);
383
-		while ($res = Database::fetch_array($result, 'ASSOC')) {
384
-
385
-			// Check for deleted users
386
-			$dest_user_id = $res['dest_user_id'];
387
-			$user_info = api_get_user_info($dest_user_id);
388
-			//$this->category = $res['cat_id'];
389
-			if (!$user_info) {
390
-				$this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
-			} else {
392
-				$this->recipients[] = array(
383
+        while ($res = Database::fetch_array($result, 'ASSOC')) {
384
+
385
+            // Check for deleted users
386
+            $dest_user_id = $res['dest_user_id'];
387
+            $user_info = api_get_user_info($dest_user_id);
388
+            //$this->category = $res['cat_id'];
389
+            if (!$user_info) {
390
+                $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
+            } else {
392
+                $this->recipients[] = array(
393 393
                     'id' => $dest_user_id,
394 394
                     'name' => $user_info['complete_name'],
395 395
                     'user_id' => $dest_user_id,
396
-				    'feedback_date' => $res['feedback_date'],
396
+                    'feedback_date' => $res['feedback_date'],
397 397
                     'feedback' => $res['feedback']
398 398
                 );
399
-			}
400
-		}
401
-	}
399
+            }
400
+        }
401
+    }
402 402
 }
403 403
 
404 404
 class Dropbox_Person
405 405
 {
406
-	// The receivedWork and the sentWork arrays are sorted.
407
-	public $receivedWork;	// an array of Dropbox_Work objects
408
-	public $sentWork;		// an array of Dropbox_SentWork objects
409
-
410
-	public $userId = 0;
411
-	public $isCourseAdmin = false;
412
-	public $isCourseTutor = false;
413
-	public $_orderBy = '';	// private property that determines by which field
414
-
415
-	/**
416
-	 * Constructor for recreating the Dropbox_Person object
417
-	 *
418
-	 * @param int $userId
419
-	 * @param bool $isCourseAdmin
420
-	 * @param bool $isCourseTutor
421
-	 * @return Dropbox_Person
422
-	 */
423
-	public function __construct($userId, $isCourseAdmin, $isCourseTutor)
406
+    // The receivedWork and the sentWork arrays are sorted.
407
+    public $receivedWork;	// an array of Dropbox_Work objects
408
+    public $sentWork;		// an array of Dropbox_SentWork objects
409
+
410
+    public $userId = 0;
411
+    public $isCourseAdmin = false;
412
+    public $isCourseTutor = false;
413
+    public $_orderBy = '';	// private property that determines by which field
414
+
415
+    /**
416
+     * Constructor for recreating the Dropbox_Person object
417
+     *
418
+     * @param int $userId
419
+     * @param bool $isCourseAdmin
420
+     * @param bool $isCourseTutor
421
+     * @return Dropbox_Person
422
+     */
423
+    public function __construct($userId, $isCourseAdmin, $isCourseTutor)
424 424
     {
425
-	    $course_id = api_get_course_int_id();
425
+        $course_id = api_get_course_int_id();
426 426
 
427
-		// Fill in properties
427
+        // Fill in properties
428 428
         $this->userId = $userId;
429 429
         $this->isCourseAdmin = $isCourseAdmin;
430 430
         $this->isCourseTutor = $isCourseTutor;
431 431
         $this->receivedWork = array();
432 432
         $this->sentWork = array();
433 433
 
434
-		// Note: perhaps include an ex coursemember check to delete old files
434
+        // Note: perhaps include an ex coursemember check to delete old files
435 435
 
436
-		$session_id = api_get_session_id();
437
-		$condition_session = api_get_session_condition($session_id);
436
+        $session_id = api_get_session_id();
437
+        $condition_session = api_get_session_condition($session_id);
438 438
 
439
-		$post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
-		$person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
-		$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
439
+        $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
+        $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
+        $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
442 442
 
443 443
         // Find all entries where this person is the recipient
444
-		$sql = "SELECT DISTINCT r.file_id, r.cat_id
444
+        $sql = "SELECT DISTINCT r.file_id, r.cat_id
445 445
                 FROM $post_tbl r
446 446
                 INNER JOIN $person_tbl p
447 447
                     ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id )
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
                      r.dest_user_id = ".intval($this->userId)." $condition_session ";
451 451
 
452 452
         $result = Database::query($sql);
453
-		while ($res = Database::fetch_array($result)) {
454
-			$temp = new Dropbox_Work($res['file_id']);
455
-			$temp->category = $res['cat_id'];
456
-			$this->receivedWork[] = $temp;
457
-		}
458
-		// Find all entries where this person is the sender/uploader
453
+        while ($res = Database::fetch_array($result)) {
454
+            $temp = new Dropbox_Work($res['file_id']);
455
+            $temp->category = $res['cat_id'];
456
+            $this->receivedWork[] = $temp;
457
+        }
458
+        // Find all entries where this person is the sender/uploader
459 459
         $sql = "SELECT DISTINCT f.id
460 460
 				FROM $file_tbl f
461 461
 				INNER JOIN $person_tbl p
@@ -466,260 +466,260 @@  discard block
 block discarded – undo
466 466
                     $condition_session
467 467
                 ";
468 468
         $result = Database::query($sql);
469
-		while ($res = Database::fetch_array($result)) {
470
-			$this->sentWork[] = new Dropbox_SentWork($res['id']);
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * This private method is used by the usort function in  the
476
-	 * orderSentWork and orderReceivedWork methods.
477
-	 * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
-	 * private property _orderBy
479
-	 *
480
-	 * @param unknown_type $a
481
-	 * @param unknown_type $b
482
-	 * @return -1, 0 or 1 dependent of the result of the comparison.
483
-	 */
484
-	function _cmpWork($a, $b)
469
+        while ($res = Database::fetch_array($result)) {
470
+            $this->sentWork[] = new Dropbox_SentWork($res['id']);
471
+        }
472
+    }
473
+
474
+    /**
475
+     * This private method is used by the usort function in  the
476
+     * orderSentWork and orderReceivedWork methods.
477
+     * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
+     * private property _orderBy
479
+     *
480
+     * @param unknown_type $a
481
+     * @param unknown_type $b
482
+     * @return -1, 0 or 1 dependent of the result of the comparison.
483
+     */
484
+    function _cmpWork($a, $b)
485 485
     {
486
-		$sort = $this->_orderBy;
487
-		$aval = $a->$sort;
488
-		$bval = $b->$sort;
489
-		if ($sort == 'recipients') {
490
-		    // The recipients property is an array so we do the comparison based
491
-		    // on the first item of the recipients array
492
-		    $aval = $aval[0]['name'];
493
-			$bval = $bval[0]['name'];
494
-		}
495
-		if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
-			return $aval < $bval ? -1 : 1;
497
-		} elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
-			return api_strnatcmp($aval, $bval);
499
-		} else {
500
-		    return api_strcasecmp($aval, $bval);
501
-		}
502
-	}
503
-
504
-	/**
505
-	 * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
-	 * $sort can be lastDate, firstDate, title, size, ...
507
-	 *
508
-	 * @param unknown_type $sort
509
-	 */
510
-	function orderSentWork($sort)
486
+        $sort = $this->_orderBy;
487
+        $aval = $a->$sort;
488
+        $bval = $b->$sort;
489
+        if ($sort == 'recipients') {
490
+            // The recipients property is an array so we do the comparison based
491
+            // on the first item of the recipients array
492
+            $aval = $aval[0]['name'];
493
+            $bval = $bval[0]['name'];
494
+        }
495
+        if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
+            return $aval < $bval ? -1 : 1;
497
+        } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
+            return api_strnatcmp($aval, $bval);
499
+        } else {
500
+            return api_strcasecmp($aval, $bval);
501
+        }
502
+    }
503
+
504
+    /**
505
+     * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
+     * $sort can be lastDate, firstDate, title, size, ...
507
+     *
508
+     * @param unknown_type $sort
509
+     */
510
+    function orderSentWork($sort)
511 511
     {
512
-		switch($sort) {
513
-			case 'lastDate':
514
-				$this->_orderBy = 'last_upload_date';
515
-				break;
516
-			case 'firstDate':
517
-				$this->_orderBy = 'upload_date';
518
-				break;
519
-			case 'title':
520
-				$this->_orderBy = 'title';
521
-				break;
522
-			case 'size':
523
-				$this->_orderBy = 'filesize';
524
-				break;
525
-			case 'author':
526
-				$this->_orderBy = 'author';
527
-				break;
528
-			case 'recipient':
529
-				$this->_orderBy = 'recipients';
530
-				break;
531
-			default:
532
-				$this->_orderBy = 'last_upload_date';
533
-		}
534
-
535
-		usort($this->sentWork, array($this, '_cmpWork'));
536
-	}
537
-
538
-	/**
539
-	 * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
-	 * $sort can be lastDate, firstDate, title, size, ...
541
-	 * @param unknown_type $sort
542
-	 */
543
-	function orderReceivedWork($sort)
512
+        switch($sort) {
513
+            case 'lastDate':
514
+                $this->_orderBy = 'last_upload_date';
515
+                break;
516
+            case 'firstDate':
517
+                $this->_orderBy = 'upload_date';
518
+                break;
519
+            case 'title':
520
+                $this->_orderBy = 'title';
521
+                break;
522
+            case 'size':
523
+                $this->_orderBy = 'filesize';
524
+                break;
525
+            case 'author':
526
+                $this->_orderBy = 'author';
527
+                break;
528
+            case 'recipient':
529
+                $this->_orderBy = 'recipients';
530
+                break;
531
+            default:
532
+                $this->_orderBy = 'last_upload_date';
533
+        }
534
+
535
+        usort($this->sentWork, array($this, '_cmpWork'));
536
+    }
537
+
538
+    /**
539
+     * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
+     * $sort can be lastDate, firstDate, title, size, ...
541
+     * @param unknown_type $sort
542
+     */
543
+    function orderReceivedWork($sort)
544 544
     {
545
-		switch($sort) {
546
-			case 'lastDate':
547
-				$this->_orderBy = 'last_upload_date';
548
-				break;
549
-			case 'firstDate':
550
-				$this->_orderBy = 'upload_date';
551
-				break;
552
-			case 'title':
553
-				$this->_orderBy = 'title';
554
-				break;
555
-			case 'size':
556
-				$this->_orderBy = 'filesize';
557
-				break;
558
-			case 'author':
559
-				$this->_orderBy = 'author';
560
-				break;
561
-			case 'sender':
562
-				$this->_orderBy = 'uploaderName';
563
-				break;
564
-			default:
565
-				$this->_orderBy = 'last_upload_date';
566
-		}
567
-
568
-		usort($this->receivedWork, array($this, '_cmpWork'));
569
-	}
570
-
571
-	/**
572
-	 * Deletes all the received work of this person
573
-	 */
574
-	function deleteAllReceivedWork()
545
+        switch($sort) {
546
+            case 'lastDate':
547
+                $this->_orderBy = 'last_upload_date';
548
+                break;
549
+            case 'firstDate':
550
+                $this->_orderBy = 'upload_date';
551
+                break;
552
+            case 'title':
553
+                $this->_orderBy = 'title';
554
+                break;
555
+            case 'size':
556
+                $this->_orderBy = 'filesize';
557
+                break;
558
+            case 'author':
559
+                $this->_orderBy = 'author';
560
+                break;
561
+            case 'sender':
562
+                $this->_orderBy = 'uploaderName';
563
+                break;
564
+            default:
565
+                $this->_orderBy = 'last_upload_date';
566
+        }
567
+
568
+        usort($this->receivedWork, array($this, '_cmpWork'));
569
+    }
570
+
571
+    /**
572
+     * Deletes all the received work of this person
573
+     */
574
+    function deleteAllReceivedWork()
575 575
     {
576
-	    $course_id = api_get_course_int_id();
576
+        $course_id = api_get_course_int_id();
577 577
         $dropbox_cnf = getDropboxConf();
578
-		// Delete entries in person table concerning received works
579
-		foreach ($this->receivedWork as $w) {
578
+        // Delete entries in person table concerning received works
579
+        foreach ($this->receivedWork as $w) {
580 580
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
581 581
 			        WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
582
-			Database::query($sql);
583
-		}
582
+            Database::query($sql);
583
+        }
584 584
         // Check for unused files
585
-		removeUnusedFiles();
586
-	}
585
+        removeUnusedFiles();
586
+    }
587 587
 
588
-	/**
589
-	 * Deletes all the received categories and work of this person
590
-	 */
591
-	function deleteReceivedWorkFolder($id)
588
+    /**
589
+     * Deletes all the received categories and work of this person
590
+     */
591
+    function deleteReceivedWorkFolder($id)
592 592
     {
593 593
         $dropbox_cnf = getDropboxConf();
594 594
         $course_id = api_get_course_int_id();
595 595
 
596
-		$id = intval($id);
597
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
596
+        $id = intval($id);
597
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
598 598
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
599
-		if (!Database::query($sql)) return false;
600
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
599
+        if (!Database::query($sql)) return false;
600
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
601 601
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
602
-		if (!Database::query($sql)) return false;
603
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
602
+        if (!Database::query($sql)) return false;
603
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
604 604
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
605
-		if (!Database::query($sql)) return false;
606
-		return true;
607
-	}
608
-
609
-	/**
610
-	 * Deletes a received dropbox file of this person with id=$id
611
-	 *
612
-	 * @param integer $id
613
-	 */
614
-	function deleteReceivedWork($id)
605
+        if (!Database::query($sql)) return false;
606
+        return true;
607
+    }
608
+
609
+    /**
610
+     * Deletes a received dropbox file of this person with id=$id
611
+     *
612
+     * @param integer $id
613
+     */
614
+    function deleteReceivedWork($id)
615 615
     {
616
-	    $course_id = api_get_course_int_id();
616
+        $course_id = api_get_course_int_id();
617 617
         $dropbox_cnf = getDropboxConf();
618
-		$id = intval($id);
619
-
620
-		// index check
621
-		$found = false;
622
-		foreach ($this->receivedWork as $w) {
623
-			if ($w->id == $id) {
624
-			   $found = true;
625
-			   break;
626
-			}
627
-		}
628
-
629
-		if (!$found) {
630
-			if (!$this->deleteReceivedWorkFolder($id)) {
631
-				die(get_lang('GeneralError').' (code 216)');
632
-			}
633
-		}
634
-		// Delete entries in person table concerning received works
618
+        $id = intval($id);
619
+
620
+        // index check
621
+        $found = false;
622
+        foreach ($this->receivedWork as $w) {
623
+            if ($w->id == $id) {
624
+                $found = true;
625
+                break;
626
+            }
627
+        }
628
+
629
+        if (!$found) {
630
+            if (!$this->deleteReceivedWorkFolder($id)) {
631
+                die(get_lang('GeneralError').' (code 216)');
632
+            }
633
+        }
634
+        // Delete entries in person table concerning received works
635 635
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
636 636
                 WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'";
637
-		Database::query($sql);
638
-		removeUnusedFiles();	// Check for unused files
639
-	}
640
-
641
-	/**
642
-	 * Deletes all the sent dropbox files of this person
643
-	 */
644
-	function deleteAllSentWork()
637
+        Database::query($sql);
638
+        removeUnusedFiles();	// Check for unused files
639
+    }
640
+
641
+    /**
642
+     * Deletes all the sent dropbox files of this person
643
+     */
644
+    function deleteAllSentWork()
645 645
     {
646
-	    $course_id = api_get_course_int_id();
646
+        $course_id = api_get_course_int_id();
647 647
         $dropbox_cnf = getDropboxConf();
648
-		//delete entries in person table concerning sent works
649
-		foreach ($this->sentWork as $w) {
648
+        //delete entries in person table concerning sent works
649
+        foreach ($this->sentWork as $w) {
650 650
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
651 651
                     WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
652
-			Database::query($sql);
653
-			removeMoreIfMailing($w->id);
654
-		}
655
-		removeUnusedFiles();	// Check for unused files
656
-	}
657
-
658
-	/**
659
-	 * Deletes a sent dropbox file of this person with id=$id
660
-	 *
661
-	 * @param unknown_type $id
662
-	 */
663
-	function deleteSentWork($id)
652
+            Database::query($sql);
653
+            removeMoreIfMailing($w->id);
654
+        }
655
+        removeUnusedFiles();	// Check for unused files
656
+    }
657
+
658
+    /**
659
+     * Deletes a sent dropbox file of this person with id=$id
660
+     *
661
+     * @param unknown_type $id
662
+     */
663
+    function deleteSentWork($id)
664 664
     {
665
-	    $course_id = api_get_course_int_id();
665
+        $course_id = api_get_course_int_id();
666 666
         $dropbox_cnf = getDropboxConf();
667 667
 
668
-		$id = intval($id);
669
-
670
-		// index check
671
-		$found = false;
672
-		foreach ($this->sentWork as $w) {
673
-			if ($w->id == $id) {
674
-			   $found = true;
675
-			   break;
676
-			}
677
-		}
678
-		if (!$found) {
679
-			if (!$this->deleteReceivedWorkFolder($id)) {
680
-				die(get_lang('GeneralError').' (code 219)');
681
-			}
682
-		}
683
-		//$file_id = $this->sentWork[$index]->id;
684
-		// Delete entries in person table concerning sent works
668
+        $id = intval($id);
669
+
670
+        // index check
671
+        $found = false;
672
+        foreach ($this->sentWork as $w) {
673
+            if ($w->id == $id) {
674
+                $found = true;
675
+                break;
676
+            }
677
+        }
678
+        if (!$found) {
679
+            if (!$this->deleteReceivedWorkFolder($id)) {
680
+                die(get_lang('GeneralError').' (code 219)');
681
+            }
682
+        }
683
+        //$file_id = $this->sentWork[$index]->id;
684
+        // Delete entries in person table concerning sent works
685 685
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
686 686
                 WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'";
687
-		Database::query($sql);
688
-		removeMoreIfMailing($id);
689
-		removeUnusedFiles();	// Check for unused files
690
-	}
691
-
692
-	/**
693
-	 * Updates feedback for received work of this person with id=$id
694
-	 *
695
-	 * @param string $id
696
-	 * @param string $text
697
-	 */
698
-	function updateFeedback($id, $text)
687
+        Database::query($sql);
688
+        removeMoreIfMailing($id);
689
+        removeUnusedFiles();	// Check for unused files
690
+    }
691
+
692
+    /**
693
+     * Updates feedback for received work of this person with id=$id
694
+     *
695
+     * @param string $id
696
+     * @param string $text
697
+     */
698
+    function updateFeedback($id, $text)
699 699
     {
700
-	    $course_id = api_get_course_int_id();
700
+        $course_id = api_get_course_int_id();
701 701
         $_course = api_get_course_info();
702 702
         $dropbox_cnf = getDropboxConf();
703 703
 
704
-		$id = intval($id);
705
-
706
-		// index check
707
-		$found = false;
708
-		$wi = -1;
709
-		foreach ($this->receivedWork as $w) {
710
-			$wi++;
711
-			if ($w->id == $id){
712
-			   $found = true;
713
-			   break;
714
-			}  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
715
-		}
716
-		if (!$found) {
717
-			die(get_lang('GeneralError').' (code 221)');
718
-		}
719
-
720
-		$feedback_date = api_get_utc_datetime();
721
-		$this->receivedWork[$wi]->feedback_date = $feedback_date;
722
-		$this->receivedWork[$wi]->feedback = $text;
704
+        $id = intval($id);
705
+
706
+        // index check
707
+        $found = false;
708
+        $wi = -1;
709
+        foreach ($this->receivedWork as $w) {
710
+            $wi++;
711
+            if ($w->id == $id){
712
+                $found = true;
713
+                break;
714
+            }  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
715
+        }
716
+        if (!$found) {
717
+            die(get_lang('GeneralError').' (code 221)');
718
+        }
719
+
720
+        $feedback_date = api_get_utc_datetime();
721
+        $this->receivedWork[$wi]->feedback_date = $feedback_date;
722
+        $this->receivedWork[$wi]->feedback = $text;
723 723
 
724 724
         $params = [
725 725
             'feedback_date' => $feedback_date,
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
             ]
738 738
         );
739 739
 
740
-		// Update item_property table
740
+        // Update item_property table
741 741
 
742
-		if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
743
-		    $ownerid = getUserOwningThisMailing($ownerid);
744
-		}
742
+        if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
743
+            $ownerid = getUserOwningThisMailing($ownerid);
744
+        }
745 745
         api_item_property_update(
746 746
             $_course,
747 747
             TOOL_DROPBOX,
@@ -752,31 +752,31 @@  discard block
 block discarded – undo
752 752
             $ownerid
753 753
         );
754 754
 
755
-	}
755
+    }
756 756
 
757
-	/**
758
-	 * Filter the received work
759
-	 * @param string $type
760
-	 * @param string $value
761
-	 */
762
-	function filter_received_work($type, $value)
757
+    /**
758
+     * Filter the received work
759
+     * @param string $type
760
+     * @param string $value
761
+     */
762
+    function filter_received_work($type, $value)
763 763
     {
764 764
         $dropbox_cnf = getDropboxConf();
765
-    	$new_received_work = array();
766
-		foreach ($this->receivedWork as $work) {
767
-			switch ($type) {
768
-				case 'uploader_id':
769
-					if ($work->uploader_id == $value ||
770
-						($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
765
+        $new_received_work = array();
766
+        foreach ($this->receivedWork as $work) {
767
+            switch ($type) {
768
+                case 'uploader_id':
769
+                    if ($work->uploader_id == $value ||
770
+                        ($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
771 771
                         getUserOwningThisMailing($work->uploader_id) == $value)
772 772
                     ) {
773
-						$new_received_work[] = $work;
774
-					}
775
-					break;
776
-				default:
777
-					$new_received_work[] = $work;
778
-			}
779
-		}
780
-		$this->receivedWork = $new_received_work;
781
-	}
773
+                        $new_received_work[] = $work;
774
+                    }
775
+                    break;
776
+                default:
777
+                    $new_received_work[] = $work;
778
+            }
779
+        }
780
+        $this->receivedWork = $new_received_work;
781
+    }
782 782
 }
Please login to merge, or discard this patch.
main/gradebook/lib/scoredisplay.class.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         //Setting custom enabled
45 45
         $value = api_get_setting('gradebook_score_display_custom');
46 46
         $value = $value['my_display_custom'];
47
-        $this->custom_enabled  = $value == 'true' ? true : false;
47
+        $this->custom_enabled = $value == 'true' ? true : false;
48 48
 
49 49
         if ($this->custom_enabled) {
50 50
             $params = array('category = ?' =>  array('Gradebook'));
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
                 sort($portal_displays);
62 62
             }
63 63
             $this->custom_display = $portal_displays;
64
-            if (count($this->custom_display)>0) {
64
+            if (count($this->custom_display) > 0) {
65 65
                 $value = api_get_setting('gradebook_score_display_upperlimit');
66 66
                 $value = $value['my_display_upperlimit'];
67
-                $this->upperlimit_included  = $value == 'true' ? true : false;
67
+                $this->upperlimit_included = $value == 'true' ? true : false;
68 68
                 $this->custom_display_conv = $this->convert_displays($this->custom_display);
69 69
             }
70 70
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             //Load course settings
76 76
             if ($this->custom_enabled) {
77 77
                 $this->custom_display = $this->get_custom_displays();
78
-                if (count($this->custom_display)> 0) {
78
+                if (count($this->custom_display) > 0) {
79 79
                     $this->custom_display_conv = $this->convert_displays($this->custom_display);
80 80
                 }
81 81
             }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     /**
104 104
      * Compare the custom display of 2 scores, can be useful in sorting
105 105
      */
106
-    public static function compare_scores_by_custom_display ($score1, $score2)
106
+    public static function compare_scores_by_custom_display($score1, $score2)
107 107
     {
108 108
         if (!isset($score1)) {
109 109
             return (isset($score2) ? 1 : 0);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             if ($custom1 == $custom2) {
117 117
                 return 0;
118 118
             } else {
119
-                return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1);
119
+                return (($score1[0] / $score1[1]) < ($score2[0] / $score2[1]) ? -1 : 1);
120 120
             }
121 121
         }
122 122
     }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         }
185 185
 
186 186
         $sql = 'SELECT id FROM '.$tbl_gradebook_category.'
187
-                WHERE course_code = "'.$curr_course_code.'" '. $session_condition;
187
+                WHERE course_code = "'.$curr_course_code.'" '.$session_condition;
188 188
         $rs  = Database::query($sql);
189 189
         $category_id = 0;
190 190
         if (Database::num_rows($rs) > 0) {
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         );
254 254
 
255 255
         $tbl_display = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
256
-        foreach($display as $value => $text) {
256
+        foreach ($display as $value => $text) {
257 257
             $params = array(
258 258
                 'score' => $value,
259 259
                 'display' => $text,
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         $my_score = $score == 0 ? 1 : $score;
310 310
 
311 311
         if ($type == SCORE_BAR) {
312
-            $percentage = $my_score[0]/$my_score[1]*100;
312
+            $percentage = $my_score[0] / $my_score[1] * 100;
313 313
 
314 314
             return Display::bar_progress($percentage);
315 315
         }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             case SCORE_PERCENT :                        // XX %
351 351
                 return $this->display_as_percent($score);
352 352
             case SCORE_DIV_PERCENT :                    // X / Y (XX %)
353
-                return $this->display_as_div($score).' (' . $this->display_as_percent($score) . ')';
353
+                return $this->display_as_div($score).' ('.$this->display_as_percent($score).')';
354 354
             case SCORE_AVERAGE :                        // XX %
355 355
                 return $this->display_as_percent($score);
356 356
             case SCORE_DECIMAL :                        // 0.50  (X/Y)
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
                 if (!empty($custom)) {
361 361
                     $custom = ' - '.$custom;
362 362
                 }
363
-                return $this->display_as_div($score).' (' . $this->display_as_percent($score) . ')'.$custom;
363
+                return $this->display_as_div($score).' ('.$this->display_as_percent($score).')'.$custom;
364 364
             case SCORE_DIV_SIMPLE_WITH_CUSTOM :         // X - Good!
365 365
                 $custom = $this->display_custom($score);
366 366
 
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
      */
413 413
     private function display_as_decimal($score)
414 414
     {
415
-        $score_denom = ($score[1]==0) ? 1 : $score[1];
415
+        $score_denom = ($score[1] == 0) ? 1 : $score[1];
416 416
 
417
-        return $this->format_score($score[0]/$score_denom);
417
+        return $this->format_score($score[0] / $score_denom);
418 418
     }
419 419
 
420 420
     /**
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
      */
423 423
     private function display_as_percent($score)
424 424
     {
425
-        $score_denom = ($score[1]==0) ? 1 : $score[1];
425
+        $score_denom = ($score[1] == 0) ? 1 : $score[1];
426 426
 
427
-        return $this->format_score($score[0]/$score_denom*100) . ' %';
427
+        return $this->format_score($score[0] / $score_denom * 100).' %';
428 428
     }
429 429
 
430 430
     /**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         } else {
441 441
             $score[0] = isset($score[0]) ? $this->format_score($score[0]) : 0;
442 442
             $score[1] = isset($score[1]) ? $this->format_score($score[1]) : 0;
443
-            return  $score[0] . ' / ' . $score[1];
443
+            return  $score[0].' / '.$score[1];
444 444
         }
445 445
     }
446 446
 
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     private function display_custom($score)
452 452
     {
453
-        $my_score_denom= ($score[1]==0) ? 1 : $score[1];
453
+        $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
454 454
         $scaledscore = $score[0] / $my_score_denom;
455 455
         if ($this->upperlimit_included) {
456 456
             foreach ($this->custom_display_conv as $displayitem) {
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
                 ORDER BY score';
515 515
         $result = Database::query($sql);
516 516
 
517
-        return Database::store_result($result,'ASSOC');
517
+        return Database::store_result($result, 'ASSOC');
518 518
     }
519 519
 
520 520
     /**
Please login to merge, or discard this patch.