| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* For licensing terms, see /license.txt */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Chamilo\CoreBundle\Entity\Course; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Chamilo\CoreBundle\Entity\ResourceLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Chamilo\CoreBundle\Entity\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Chamilo\CoreBundle\Enums\ActionIcon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Chamilo\CoreBundle\Enums\ObjectIcon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Chamilo\CoreBundle\Enums\StateIcon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Chamilo\CoreBundle\Framework\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Chamilo\CourseBundle\Entity\CDocument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Chamilo\CourseBundle\Entity\CStudentPublication; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Chamilo\CourseBundle\Entity\CStudentPublicationAssignment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Chamilo\CourseBundle\Entity\CStudentPublicationComment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use ChamiloSession as Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  *  @author Thomas, Hugues, Christophe - original version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  *  @author Patrick Cool <[email protected]>, Ghent University - | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * ability for course admins to specify wether uploaded documents are visible or invisible by default. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  *  @author Roan Embrechts, code refactoring and virtual course support | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  *  @author Frederic Vauthier, directories management | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  *  @author Julio Montoya <[email protected]> BeezNest 2011 LOTS of bug fixes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  *  @todo   this lib should be convert in a static class and moved to main/inc/lib | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Displays action links (for admins, authorized groups members and authorized students). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @param   int Whether to show tool options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @param   int Whether to show upload form option | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @param bool $isTutor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | function displayWorkActionLinks($id, $action, $isTutor) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     $id = $my_back_id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     if ('list' === $action) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $my_back_id = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     $output = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     $origin = api_get_origin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     if (!empty($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_back_id.'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, sprintf(get_lang('Back to %s'), get_lang('Assignment list'))). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     if (($isTutor || api_is_allowed_to_edit(null, true)) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         'learnpath' !== $origin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         // Create dir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         if (empty($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=create_dir">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $output .= Display::getMdiIcon(ActionIcon::ADD, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Create assignment')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             $output .= '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     if (api_is_allowed_to_edit(null, true) && 'learnpath' !== $origin && 'list' === $action) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $output .= '<a id="open-view-list" href="#">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             Display::getMdiIcon(StateIcon::LIST_VIEW, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('View students')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     if ('' !== $output) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         echo Display::toolbarAction('toolbar', [$output]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  * @param int    $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | function get_work_data_by_path($path, $courseId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     $path = Database::escape_string($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     $courseId = (int) $courseId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     if (empty($courseId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $courseId = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     $sql = "SELECT *  FROM $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             WHERE url = '$path' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     $return = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $return = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | function get_work_data_by_id($id, $courseId = 0, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     $webCodePath = api_get_path(WEB_CODE_PATH); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     $studentPublication = $repo->find($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     if (null === $studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     $work = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     if ($studentPublication) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $workId = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $work['iid'] = $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $work['description'] = $studentPublication->getDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $work['url'] = $repo->getResourceFileDownloadUrl($studentPublication).'?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $work['active'] = $studentPublication->getActive(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $work['allow_text_assignment'] = $studentPublication->getAllowTextAssignment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         //$work['c_id'] = $studentPublication->getCId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $work['user_id'] = $studentPublication->getUser()->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $work['parent_id'] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         if (null !== $studentPublication->getPublicationParent()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             $work['parent_id'] = $studentPublication->getPublicationParent()->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $work['qualification'] = $studentPublication->getQualification(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $work['contains_file'] = $studentPublication->getContainsFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $work['title'] = $studentPublication->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $url = $repo->getResourceFileDownloadUrl($studentPublication); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $work['download_url'] = $url.'?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $work['view_url'] = $webCodePath.'work/view.php?id='.$workId.'&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $showUrl = $work['show_url'] = $webCodePath.'work/show_file.php?id='.$workId.'&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $work['show_content'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         if ($studentPublication->getContainsFile()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             $fileType = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             if (in_array($fileType, ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 $work['show_content'] = Display::img($showUrl, $studentPublication->getTitle(), null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             } elseif (false !== strpos($fileType, 'video/')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                 $work['show_content'] = Display::tag( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                     'video', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                     get_lang('File format not supported'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                     ['src' => $showUrl] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $fieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $work['extra'] = $fieldValue->getAllValuesForAnItem($id, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     return $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  * @param int $user_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  * @param int $work_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | function get_work_count_by_student($user_id, $work_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     $user_id = (int) $user_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     $work_id = (int) $work_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     $session_id = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     $sessionCondition = api_get_session_condition($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     $sql = "SELECT COUNT(*) as count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             FROM  $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                 parent_id = $work_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                 user_id = $user_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 active IN (0, 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |                 $sessionCondition"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     $return = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $return = Database::fetch_row($result, 'ASSOC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $return = (int) ($return[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | function get_work_assignment_by_id($id, $courseId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     $courseId = (int) $courseId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     if (empty($courseId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         $courseId = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     $sql = "SELECT * FROM $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |             WHERE publication_id = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     $return = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $return = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |     return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  * @param int    $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  * @param array  $my_folder_data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  * @param string $add_in_where_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  * @param int    $course_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  * @param int    $session_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  * @return CStudentPublication[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | function getWorkList($id, $my_folder_data, $add_in_where_query = null, $course_id = 0, $session_id = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     $course_id = $course_id ?: api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     $session_id = $session_id ?: api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |     $condition_session = api_get_session_condition($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     $group_id = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     if ($group_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         $groupInfo = GroupManager::get_group_properties($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         if ($groupInfo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit(null, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |     $linkInfo = GradebookUtils::isResourceInCourseGradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         api_get_course_int_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         api_get_session_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     if ($linkInfo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         $workInGradeBookLinkId = $linkInfo['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         if ($workInGradeBookLinkId && $is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             if (0 == (int) ($my_folder_data['qualification'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                 echo Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                     get_lang('Max weight need to be provided'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                     'warning' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     $course = api_get_course_entity($course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     $session = api_get_session_entity($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     $group = api_get_group_entity($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |     $qb = $repo->getResourcesByCourse($course, $session, $group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |     $contains_file_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     // Get list from database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |     if ($is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         $qb->andWhere($qb->expr()->in('resource.active', [1, 0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |         $qb->andWhere($qb->expr()->isNull('resource.publicationParent')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |     /*$active_condition = ' active IN (0, 1)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |     $sql = "SELECT * FROM $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |                 c_id = $course_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |                 $add_in_where_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |                 $condition_session AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |                 $active_condition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |                 (parent_id = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |                 $contains_file_query AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |                 post_group_id = $groupIid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |             ORDER BY sent_date DESC";*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         if (!empty($group_id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |             // set to select only messages posted by the user's group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |             $group_query = " WHERE c_id = $course_id AND post_group_id = $groupIid"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |             $subdirs_query = ' AND parent_id = 0'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |             $group_query = " WHERE c_id = $course_id AND (post_group_id = '0' OR post_group_id is NULL) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |             $subdirs_query = ' AND parent_id = 0'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         //@todo how we can active or not an assignment? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         $active_condition = ' AND active IN (1, 0)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |         $sql = "SELECT * FROM  $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |                 $group_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |                 $subdirs_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |                 $add_in_where_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |                 $active_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |                 $condition_session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |                 ORDER BY title"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |     return $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |     $work_parents = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |     $sql_result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |     if (Database::num_rows($sql_result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         while ($work = Database::fetch_object($sql_result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |             if (0 == $work->parent_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |                 $work_parents[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     return $work_parents; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |  * @param int $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |  * @param int $course_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | function getUniqueStudentAttemptsTotal($workId, $groupId, $course_id, $sessionId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |     $user_table = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |     $course_id = (int) $course_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |     $groupId = (int) $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |     $sessionCondition = api_get_session_condition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |         true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |         'w.session_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |     if ($groupId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |         $groupInfo = GroupManager::get_group_properties($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |         $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |     $sql = "SELECT count(DISTINCT u.id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |             FROM $work_table w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |             INNER JOIN $user_table u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |             ON w.user_id = u.id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |                 w.parent_id = $workId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |                 w.post_group_id = $groupIid AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |                 w.active IN (0, 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |             "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |     $res_document = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |     $rowCount = Database::fetch_row($res_document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |     return $rowCount[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |  * @param mixed $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  * @param int   $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |  * @param int   $course_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |  * @param int   $userId       user id to filter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |  * @param array $onlyUserList only parse this user list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |  * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  | function getUniqueStudentAttempts( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |     $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |     $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |     $userId = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |     $onlyUserList = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |     $user_table = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |     $course_id = (int) $course_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |     $workCondition = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |     if (is_array($workId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |         $workId = array_map('intval', $workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         $workId = implode("','", $workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |         $workCondition = " w.parent_id IN ('".$workId."') AND"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |         $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |         $workCondition = ' w.parent_id = '.$workId.' AND'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |     $groupId = (int) $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |     $studentCondition = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |     if (!empty($onlyUserList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |         $onlyUserList = array_map('intval', $onlyUserList); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |         $studentCondition = "AND u.id IN ('".implode("', '", $onlyUserList)."') "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |         if (empty($userId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |             return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |     if ($groupId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |         $groupInfo = GroupManager::get_group_properties($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |         $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |     $sessionCondition = api_get_session_condition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |         true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         'w.session_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |     $sql = "SELECT count(*) FROM ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |                 SELECT count(*), w.parent_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |                 FROM $work_table w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |                 INNER JOIN $user_table u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |                 ON w.user_id = u.id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |                     w.filetype = 'file' AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |                     $workCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |                     w.post_group_id = $groupIid AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |                     w.active IN (0, 1) $studentCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |                 "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |     if (!empty($userId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |         $userId = (int) $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |         $sql .= ' AND u.id = '.$userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |     $sql .= ' GROUP BY u.id, w.parent_id) as t'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |     $row = Database::fetch_row($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |     return $row[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |  * Shows the work list (student view). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  | function showStudentWorkGrid() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |     $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_student&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |     $columns = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |         get_lang('Type'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |         get_lang('Title'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |         get_lang('Deadline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |         get_lang('Feedback'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |         get_lang('Last upload'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |     $columnModel = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |         ['name' => 'type', 'index' => 'type', 'width' => '30', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |         ['name' => 'title', 'index' => 'title', 'width' => '250', 'align' => 'left'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |         ['name' => 'expires_on', 'index' => 'expires_on', 'width' => '80', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |         ['name' => 'feedback', 'index' => 'feedback', 'width' => '80', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |         ['name' => 'last_upload', 'index' => 'feedback', 'width' => '125', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |     if (0 == $courseInfo['show_score']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |         $columnModel[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |             'name' => 'others', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |             'index' => 'others', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |             'width' => '80', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |             'align' => 'left', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         $columns[] = get_lang('Others'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |         'autowidth' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |         'height' => 'auto', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |     $html = '<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |         $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |             '.Display::grid_js('workList', $url, $columns, $columnModel, $params, [], null, true).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |     </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |     $html .= Display::grid_html('workList'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |     return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |  * Shows the work list (student view). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  | function showStudentAllWorkGrid($withResults = 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |     $withResults = (int) $withResults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_all_work_student&with_results='.$withResults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |     $columns = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |         get_lang('Type'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |         get_lang('Title'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |         get_lang('Deadline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |     $id = 'workList'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |     if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |         $id = 'workListWithResults'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |         $columns[] = get_lang('Feedback'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |         $columns[] = get_lang('Last upload'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |     $columnModel = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |         ['name' => 'type', 'index' => 'type', 'width' => '50', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |         ['name' => 'title', 'index' => 'title', 'width' => '600', 'align' => 'left'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |         ['name' => 'expires_on', 'index' => 'expires_on', 'width' => '125', 'align' => 'center', 'sortable' => 'false'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |     if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |         $columnModel[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |             'name' => 'feedback', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |             'index' => 'feedback', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |             'width' => '150', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |             'align' => 'center', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |         $columnModel[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |             'name' => 'last_upload', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |             'index' => 'last_upload', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |             'width' => '150', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |             'align' => 'center', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |         'autowidth' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |         'height' => 'auto', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |     $html = '<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |         $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |             '.Display::grid_js($id, $url, $columns, $columnModel, $params, [], null, true).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |     </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |     $html .= Display::grid_html($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |     return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |  * Shows the work list (teacher view). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  | function showTeacherWorkGrid() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |     $columnModel = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |             'name' => 'type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  |             'index' => 'type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |             'width' => '35', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |             'align' => 'center', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |             'name' => 'title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |             'index' => 'title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |             'width' => '300', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |             'align' => 'left', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |             'wrap_cell' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |         ['name' => 'sent_date', 'index' => 'sent_date', 'width' => '125', 'align' => 'center'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |         ['name' => 'expires_on', 'index' => 'expires_on', 'width' => '125', 'align' => 'center'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |             'name' => 'amount', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |             'index' => 'amount', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |             'width' => '110', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |             'align' => 'center', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |             'name' => 'actions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  |             'index' => 'actions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |             'width' => '110', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |             'align' => 'left', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_teacher&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |     $deleteUrl = api_get_path(WEB_AJAX_PATH).'work.ajax.php?a=delete_work&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |     $columns = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |         get_lang('Type'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  |         get_lang('Title'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  |         get_lang('Sent date'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |         get_lang('Deadline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  |         get_lang('Number submitted'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |         get_lang('Detail'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |         'multiselect' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |         'autowidth' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |         'height' => 'auto', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |     $html = '<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |     $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |         '.Display::grid_js('workList', $url, $columns, $columnModel, $params, [], null, true).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |         $("#workList").jqGrid( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |             "navGrid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |             "#workList_pager", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |             { edit: false, add: false, del: true }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |             { height:280, reloadAfterSubmit:false }, // edit options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  |             { height:280, reloadAfterSubmit:false }, // add options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |             { reloadAfterSubmit:false, url: "'.$deleteUrl.'" }, // del options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |             { width:500 } // search options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |     </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |     $html .= Display::grid_html('workList'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |     return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |  * Builds the form that enables the user to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  |  * move a document from one directory to another | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |  * This function has been copied from the document/document.inc.php library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |  * @param array  $folders | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  |  * @param string $curdirpath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  |  * @param string $move_file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |  * @param string $group_dir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 649 |  |  |  * @return string html form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 650 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 651 |  |  | function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 652 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 653 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 654 |  |  |     $move_file = (int) $move_file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 655 |  |  |     $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 656 |  |  |     $sql = "SELECT title, url FROM $tbl_work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 657 |  |  |             WHERE iid ='".$move_file."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 658 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 659 |  |  |     $row = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 660 |  |  |     $title = empty($row['title']) ? basename($row['url']) : $row['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 661 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 662 |  |  |     $form = new FormValidator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 663 |  |  |         'move_to_form', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 664 |  |  |         'post', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 665 |  |  |         api_get_self().'?'.api_get_cidreq().'&curdirpath='.Security::remove_XSS($curdirpath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 666 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 667 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 668 |  |  |     $form->addHeader(get_lang('Move the file').' - '.Security::remove_XSS($title)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 669 |  |  |     $form->addHidden('item_id', $move_file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 670 |  |  |     $form->addHidden('action', 'move_to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 671 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 672 |  |  |     // Group documents cannot be uploaded in the root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 673 |  |  |     $options = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 674 |  |  |     if ('' == $group_dir) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 675 |  |  |         if (is_array($folders)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 676 |  |  |             foreach ($folders as $fid => $folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 677 |  |  |                 //you cannot move a file to: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 678 |  |  |                 //1. current directory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 679 |  |  |                 //2. inside the folder you want to move | 
            
                                                                                                            
                            
            
                                    
            
            
                | 680 |  |  |                 //3. inside a subfolder of the folder you want to move | 
            
                                                                                                            
                            
            
                                    
            
            
                | 681 |  |  |                 if (($curdirpath != $folder) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 682 |  |  |                     ($folder != $move_file) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 683 |  |  |                     (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 684 |  |  |                 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 685 |  |  |                     $options[$fid] = $folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 686 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 687 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 688 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 689 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 690 |  |  |         if ('/' != $curdirpath) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 691 |  |  |             $form .= '<option value="0">/ ('.get_lang('root').')</option>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 692 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 693 |  |  |         foreach ($folders as $fid => $folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 694 |  |  |             if (($curdirpath != $folder) && ($folder != $move_file) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 695 |  |  |                 (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 696 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 697 |  |  |                 //cannot copy dir into his own subdir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 698 |  |  |                 $display_folder = substr($folder, strlen($group_dir)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 699 |  |  |                 $display_folder = '' == $display_folder ? '/ ('.get_lang('root').')' : $display_folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 700 |  |  |                 //$form .= '<option value="'.$fid.'">'.$display_folder.'</option>'."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 701 |  |  |                 $options[$fid] = $display_folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 702 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 703 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 704 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 705 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 706 |  |  |     $form->addSelect('move_to_id', get_lang('Select'), $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 707 |  |  |     $form->addButtonSend(get_lang('Move the file'), 'move_file_submit'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 708 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 709 |  |  |     return $form->returnForm(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 710 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 711 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 712 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 713 |  |  |  * creates a new directory trying to find a directory name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 714 |  |  |  * that doesn't already exist. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 715 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 716 |  |  |  * @author Hugues Peeters <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 717 |  |  |  * @author Bert Vanderkimpen | 
            
                                                                                                            
                            
            
                                    
            
            
                | 718 |  |  |  * @author Yannick Warnier <[email protected]> Adaptation for work tool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 719 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 720 |  |  |  * @param string $workDir        Base work dir (.../work) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 721 |  |  |  * @param string $desiredDirName complete path of the desired name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 722 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 723 |  |  |  * @return string actual directory name if it succeeds, boolean false otherwise | 
            
                                                                                                            
                            
            
                                    
            
            
                | 724 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 725 |  |  | function create_unexisting_work_directory($workDir, $desiredDirName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 726 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 727 |  |  |     $counter = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 728 |  |  |     $workDir = ('/' == substr($workDir, -1, 1) ? $workDir : $workDir.'/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 729 |  |  |     $checkDirName = $desiredDirName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 730 |  |  |     while (file_exists($workDir.$checkDirName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 731 |  |  |         $counter++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 732 |  |  |         $checkDirName = $desiredDirName.$counter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 733 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 734 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 735 |  |  |     /*if (@mkdir($workDir.$checkDirName, api_get_permissions_for_new_directories())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 736 |  |  |         return $checkDirName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 737 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 738 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 739 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 740 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 741 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 742 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 743 |  |  |  * Delete a work-tool directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 744 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 745 |  |  |  * @param int $id work directory id to delete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 746 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 747 |  |  |  * @return int -1 on error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 748 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 749 |  |  | function deleteDirWork($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 750 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 751 |  |  |     $locked = api_resource_is_locked_by_gradebook($id, LINK_STUDENTPUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 752 |  |  |     if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 753 |  |  |         echo Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 754 |  |  |             get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 755 |  |  |                 'This option is not available because this activity is contained by an assessment, which is currently locked. To unlock the assessment, ask your platform administrator.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 756 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 757 |  |  |             'warning' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 758 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 759 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 760 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 761 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 762 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 763 |  |  |     $_course = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 764 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 765 |  |  |     $work_data = get_work_data_by_id($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 766 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 767 |  |  |     if (empty($work_data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 768 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 769 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 770 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 771 |  |  |     //$base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 772 |  |  |     //$work_data_url = $base_work_dir.$work_data['url']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 773 |  |  |     //$check = Security::check_abs_path($work_data_url.'/', $base_work_dir.'/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 774 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 775 |  |  |     $TSTDPUBASG = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 776 |  |  |     $t_agenda = Database::get_course_table(TABLE_AGENDA); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 777 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 778 |  |  |     $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 779 |  |  |     $check = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 780 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 781 |  |  |     if ($check) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 782 |  |  |         $consideredWorkingTime = api_get_setting('work.considered_working_time'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 783 |  |  |         if (!empty($consideredWorkingTime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 784 |  |  |             $fieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 785 |  |  |             $resultExtra = $fieldValue->getAllValuesForAnItem( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 786 |  |  |                 $work_data['id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 787 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 788 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 789 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 790 |  |  |             $workingTime = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 791 |  |  |             foreach ($resultExtra as $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 792 |  |  |                 $field = $field['value']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 793 |  |  |                 if ($consideredWorkingTime == $field->getField()->getVariable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 794 |  |  |                     $workingTime = $field->getFieldValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 795 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 796 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 797 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 798 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 799 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 800 |  |  |             $courseUsers = CourseManager::get_user_list_from_course_code($_course['code'], $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 801 |  |  |             if (!empty($workingTime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 802 |  |  |                 foreach ($courseUsers as $user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 803 |  |  |                     $userWorks = get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 804 |  |  |                         0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 805 |  |  |                         100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 806 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 807 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 808 |  |  |                         $work_data['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 809 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 810 |  |  |                         $user['user_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 811 |  |  |                         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 812 |  |  |                         $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 813 |  |  |                         $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 814 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 815 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 816 |  |  |                     if (1 != count($userWorks)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 817 |  |  |                         continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 818 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 819 |  |  |                     Event::eventRemoveVirtualCourseTime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 820 |  |  |                         $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 821 |  |  |                         $user['user_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 822 |  |  |                         $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 823 |  |  |                         $workingTime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 824 |  |  |                         $work_data['iid'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 825 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 826 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 827 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 828 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 829 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 830 |  |  |         // Deleting all contents inside the folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 831 |  |  |         $sql = "UPDATE $table SET active = 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 832 |  |  |                 WHERE filetype = 'folder' AND iid = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 833 |  |  |         Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 834 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 835 |  |  |         $sql = "UPDATE $table SET active = 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 836 |  |  |                 WHERE parent_id = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 837 |  |  |         Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 838 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 839 |  |  |         /*$new_dir = $work_data_url.'_DELETED_'.$id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 840 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 841 |  |  |         if ('true' == api_get_setting('permanently_remove_deleted_files')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 842 |  |  |             my_delete($work_data_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 843 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 844 |  |  |             if (file_exists($work_data_url)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 845 |  |  |                 rename($work_data_url, $new_dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 846 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 847 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 848 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 849 |  |  |         // Gets calendar_id from student_publication_assigment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 850 |  |  |         $sql = "SELECT add_to_calendar FROM $TSTDPUBASG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 851 |  |  |                 WHERE publication_id = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 852 |  |  |         $res = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 853 |  |  |         $calendar_id = Database::fetch_row($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 854 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 855 |  |  |         // delete from agenda if it exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 856 |  |  |         if (!empty($calendar_id[0])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 857 |  |  |             $sql = "DELETE FROM $t_agenda | 
            
                                                                                                            
                            
            
                                    
            
            
                | 858 |  |  |                     WHERE id = '".$calendar_id[0]."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 859 |  |  |             Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 860 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 861 |  |  |         $sql = "DELETE FROM $TSTDPUBASG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 862 |  |  |                 WHERE publication_id = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 863 |  |  |         Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 864 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 865 |  |  |         SkillModel::deleteSkillsFromItem($id, ITEM_TYPE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 866 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 867 |  |  |         Event::addEvent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 868 |  |  |             LOG_WORK_DIR_DELETE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 869 |  |  |             LOG_WORK_DATA, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 870 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 871 |  |  |                 'id' => $work_data['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 872 |  |  |                 'url' => $work_data['url'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 873 |  |  |                 'title' => $work_data['title'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 874 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 875 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 876 |  |  |             api_get_user_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 877 |  |  |             api_get_course_int_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 878 |  |  |             $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 879 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 880 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 881 |  |  |         $linkInfo = GradebookUtils::isResourceInCourseGradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 882 |  |  |             api_get_course_int_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 883 |  |  |             3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 884 |  |  |             $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 885 |  |  |             $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 886 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 887 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 888 |  |  |         if (false !== $linkInfo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 889 |  |  |             $link_id = $linkInfo['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 890 |  |  |             GradebookUtils::remove_resource_from_course_gradebook($link_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 891 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 892 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 893 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 894 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 895 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 896 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 897 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 898 |  |  |  * Get the path of a document in the student_publication table (path relative to the course directory). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 899 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 900 |  |  |  * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 901 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 902 |  |  |  * @return string Path (or -1 on error) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 903 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 904 |  |  | function get_work_path($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 905 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 906 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 907 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 908 |  |  |     $sql = 'SELECT url FROM '.$table.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 909 |  |  |             WHERE id='.(int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 910 |  |  |     $res = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 911 |  |  |     if (Database::num_rows($res)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 912 |  |  |         $row = Database::fetch_array($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 913 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 914 |  |  |         return $row['url']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 915 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 916 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 917 |  |  |     return -1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 918 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 919 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 920 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 921 |  |  |  * Update the url of a work in the student_publication table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 922 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 923 |  |  |  * @param int    $id        of the work to update | 
            
                                                                                                            
                            
            
                                    
            
            
                | 924 |  |  |  * @param string $new_path  Destination directory where the work has been moved (must end with a '/') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 925 |  |  |  * @param int    $parent_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 926 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 927 |  |  |  * @return mixed Int -1 on error, sql query result on success | 
            
                                                                                                            
                            
            
                                    
            
            
                | 928 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 929 |  |  | function updateWorkUrl($id, $new_path, $parent_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 930 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 931 |  |  |     if (empty($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 932 |  |  |         return -1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 933 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 934 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 935 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 936 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 937 |  |  |     $parent_id = (int) $parent_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 938 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 939 |  |  |     $sql = "SELECT * FROM $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 940 |  |  |             WHERE iid = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 941 |  |  |     $res = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 942 |  |  |     if (1 != Database::num_rows($res)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 943 |  |  |         return -1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 944 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 945 |  |  |         $row = Database::fetch_array($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 946 |  |  |         $filename = basename($row['url']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 947 |  |  |         $new_url = $new_path.$filename; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 948 |  |  |         $new_url = Database::escape_string($new_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 949 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 950 |  |  |         $sql = "UPDATE $table SET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 951 |  |  |                    url = '$new_url', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 952 |  |  |                    parent_id = '$parent_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 953 |  |  |                 WHERE iid = $id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 954 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 955 |  |  |         return Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 956 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 957 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 958 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 959 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 960 |  |  |  * Update the url of a dir in the student_publication table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 961 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 962 |  |  |  * @param array  $work_data work original data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 963 |  |  |  * @param string $newPath   Example: "folder1" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 964 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 965 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 966 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 967 |  |  | function updateDirName($work_data, $newPath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 968 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 969 |  |  |     $work_id = (int) ($work_data['iid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 970 |  |  |     $oldPath = $work_data['url']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 971 |  |  |     $originalNewPath = Database::escape_string($newPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 972 |  |  |     $newPath = Database::escape_string($newPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 973 |  |  |     $newPath = api_replace_dangerous_char($newPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 974 |  |  |     $newPath = disable_dangerous_file($newPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 975 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 976 |  |  |     if ($oldPath == '/'.$newPath) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 977 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 978 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 979 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 980 |  |  |     if (!empty($newPath)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 981 |  |  |         $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 982 |  |  |         $sql = "UPDATE $table SET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 983 |  |  |                     title = '".$originalNewPath."' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 984 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 985 |  |  |                     iid = $work_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 986 |  |  |         Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 987 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 988 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 989 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 990 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 991 |  |  |  * returns all the javascript that is required for easily | 
            
                                                                                                            
                            
            
                                    
            
            
                | 992 |  |  |  * validation when you create a work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 993 |  |  |  * this goes into the $htmlHeadXtra[] array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 994 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 995 |  |  | function to_javascript_work() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 996 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 997 |  |  |     return '<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 998 |  |  |         function updateDocumentTitle(value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 999 |  |  |             var temp = value.indexOf("/"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1000 |  |  |             //linux path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1001 |  |  |             if(temp != -1){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1002 |  |  |                 temp=value.split("/"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1003 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1004 |  |  |                 temp=value.split("\\\"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1005 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1006 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1007 |  |  |             var fullFilename = temp[temp.length - 1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1008 |  |  |             var baseFilename = fullFilename; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1009 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1010 |  |  |             // get file extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1011 |  |  |             var fileExtension = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1012 |  |  |             if (fullFilename.match(/\..+/)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1013 |  |  |                 fileInfo = fullFilename.match(/(.*)\.([^.]+)$/); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1014 |  |  |                 if (fileInfo.length > 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1015 |  |  |                     fileExtension = "."+fileInfo[fileInfo.length - 1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1016 |  |  |                     baseFilename = fileInfo[fileInfo.length - 2]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1017 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1018 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1019 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1020 |  |  |             document.getElementById("file_upload").value = baseFilename; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1021 |  |  |             document.getElementById("file_extension").value = fileExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1022 |  |  |             $("#contains_file_id").attr("value", 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1023 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1024 |  |  |         function setFocus() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1025 |  |  |             $("#work_title").focus(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1026 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1027 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1028 |  |  |         $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1029 |  |  |             setFocus(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1030 |  |  |             var checked = $("#expiry_date").attr("checked"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1031 |  |  |             if (checked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1032 |  |  |                 $("#option2").show(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1033 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1034 |  |  |                 $("#option2").hide(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1035 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1036 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1037 |  |  |             var checkedEndDate = $("#end_date").attr("checked"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1038 |  |  |             if (checkedEndDate) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1039 |  |  |                 $("#option3").show(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1040 |  |  |                 $("#ends_on").attr("checked", true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1041 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1042 |  |  |                 $("#option3").hide(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1043 |  |  |                 $("#ends_on").attr("checked", false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1044 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1045 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1046 |  |  |             $("#expiry_date").click(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1047 |  |  |                 $("#option2").toggle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1048 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1049 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1050 |  |  |             $("#end_date").click(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1051 |  |  |                 $("#option3").toggle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1052 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1053 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1054 |  |  |     </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1055 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1056 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1057 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1058 |  |  |  * @param int $work_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1059 |  |  |  * @param int $onlyMeUserId show only my works | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1060 |  |  |  * @param int $notMeUserId  show works from everyone except me | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1061 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1062 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1063 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1064 |  |  | function get_count_work($work_id, $onlyMeUserId = null, $notMeUserId = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1065 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1066 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1067 |  |  |     $user_table = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1068 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1069 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit(null, true) || api_is_coach(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1070 |  |  |     $session_id = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1071 |  |  |     $condition_session = api_get_session_condition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1072 |  |  |         $session_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1073 |  |  |         true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1074 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1075 |  |  |         'link.session_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1076 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1077 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1078 |  |  |     $group_id = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1079 |  |  |     $course_info = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1080 |  |  |     $course_id = $course_info['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1081 |  |  |     $work_id = (int) $work_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1082 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1083 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1084 |  |  |     if ($group_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1085 |  |  |         $groupInfo = GroupManager::get_group_properties($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1086 |  |  |         if ($groupInfo && isset($groupInfo['iid'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1087 |  |  |             $groupIid = (int) $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1088 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1089 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1090 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1091 |  |  |     if (!empty($group_id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1092 |  |  |         // set to select only messages posted by the user's group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1093 |  |  |         $extra_conditions = " work.post_group_id = '".$groupIid."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1094 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1095 |  |  |         $extra_conditions = " (work.post_group_id = '0' or work.post_group_id IS NULL) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1096 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1097 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1098 |  |  |     if ($is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1099 |  |  |         $extra_conditions .= ' AND work.active IN (0, 1) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1100 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1101 |  |  |         $extra_conditions .= ' AND work.active IN (0, 1) AND accepted = 1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1102 |  |  |         if (isset($course_info['show_score']) && 1 == $course_info['show_score']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1103 |  |  |             $extra_conditions .= ' AND work.user_id = '.api_get_user_id().' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1104 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1105 |  |  |             $extra_conditions .= ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1106 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1109 |  |  |     $extra_conditions .= ' AND work.parent_id  = '.$work_id.'  '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1110 |  |  |     $where_condition = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1111 |  |  |     if (!empty($notMeUserId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1112 |  |  |         $where_condition .= ' AND u.id <> '.(int) $notMeUserId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1115 |  |  |     if (!empty($onlyMeUserId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1116 |  |  |         $where_condition .= ' AND u.id =  '.(int) $onlyMeUserId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1119 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1120 |  |  |     $typeId = $repo->getResourceType()->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1121 |  |  |     $visibility = ResourceLink::VISIBILITY_PUBLISHED; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1123 |  |  |     $sql = "SELECT count(*) as count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1124 |  |  |             FROM resource_node node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1125 |  |  |             INNER JOIN resource_link link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1126 |  |  |             ON (link.resource_node_id = node.id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1127 |  |  |             INNER JOIN $work_table work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1128 |  |  |             ON (node.id = work.resource_node_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1129 |  |  |             INNER JOIN $user_table u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1130 |  |  |             ON (work.user_id = u.id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1131 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1132 |  |  |                 link.c_id = $course_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1133 |  |  |                 resource_type_id = $typeId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1134 |  |  |                 link.visibility = $visibility AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1135 |  |  |             $extra_conditions $where_condition $condition_session"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1137 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1139 |  |  |     $users_with_work = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1140 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1141 |  |  |         $result = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1142 |  |  |         $users_with_work = $result['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1143 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1145 |  |  |     return $users_with_work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1146 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1148 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1149 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1150 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1151 |  |  |  * @param string $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1152 |  |  |  * @param string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1153 |  |  |  * @param string $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1154 |  |  |  * @param bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1155 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1156 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1157 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1158 |  |  | function getWorkListStudent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1159 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1160 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1161 |  |  |     $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1162 |  |  |     $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1163 |  |  |     $where_condition, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1164 |  |  |     $getCount = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1165 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1166 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1167 |  |  |     $workTableAssignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1168 |  |  |     $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1169 |  |  |     $course_id = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1170 |  |  |     $session_id = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1171 |  |  |     $condition_session = api_get_session_condition($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1172 |  |  |     $group_id = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1173 |  |  |     $userId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1175 |  |  |     $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh($userId, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1177 |  |  |     if (!in_array($direction, ['asc', 'desc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1178 |  |  |         $direction = 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1179 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1180 |  |  |     if (!empty($where_condition)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1181 |  |  |         $where_condition = ' AND '.$where_condition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1182 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1184 |  |  |     $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1185 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1186 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1188 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1189 |  |  |     if ($group_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1190 |  |  |         $groupInfo = GroupManager::get_group_properties($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1191 |  |  |         if ($groupInfo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1192 |  |  |             $groupIid = (int) $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1193 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1196 |  |  |     if (!empty($groupIid)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1197 |  |  |         $group_query = " WHERE w.c_id = $course_id AND post_group_id = $groupIid"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1198 |  |  |         $subdirs_query = 'AND w.parent_id = 0'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1199 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1200 |  |  |         $group_query = " WHERE w.c_id = $course_id AND (post_group_id = '0' or post_group_id is NULL)  "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1201 |  |  |         $subdirs_query = 'AND w.parent_id = 0'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1202 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1204 |  |  |     $active_condition = ' AND active IN (1, 0)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1206 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1207 |  |  |         $select = 'SELECT count(w.iid) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1208 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1209 |  |  |         $select = 'SELECT w.*, a.expires_on, expires_on, ends_on, enable_qualification '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1210 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1212 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1213 |  |  |     $course = api_get_course_entity($course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1214 |  |  |     $session = api_get_session_entity($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1215 |  |  |     $group = api_get_group_entity($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1217 |  |  |     $qb = $repo->getResourcesByCourse($course, $session, $group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1218 |  |  |     $qb->andWhere($qb->expr()->in('resource.active', [1, 0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1219 |  |  |     $qb->andWhere($qb->expr()->isNull('resource.publicationParent')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1220 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1221 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1222 |  |  |         $qb->select('count(resource)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1224 |  |  |         return (int) $qb->getQuery()->getSingleScalarResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1225 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1226 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1227 |  |  |     $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1228 |  |  |         ->setFirstResult($start) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1229 |  |  |         ->setMaxResults($limit) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1230 |  |  |     ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1231 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1232 |  |  |     /*$sql = "$select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1233 |  |  |             FROM $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1234 |  |  |             LEFT JOIN $workTableAssignment a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1235 |  |  |             ON (a.publication_id = w.iid AND a.c_id = w.c_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1236 |  |  |                 $group_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1237 |  |  |                 $subdirs_query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1238 |  |  |                 $active_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1239 |  |  |                 $condition_session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1240 |  |  |                 $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1241 |  |  |             "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1243 |  |  |     $sql .= " ORDER BY `$column` $direction "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1245 |  |  |     if (!empty($start) && !empty($limit)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1246 |  |  |         $sql .= " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1247 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1249 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1251 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1252 |  |  |         $row = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1254 |  |  |         return $row['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1255 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1257 |  |  |     $works = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1258 |  |  |     $url = api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1259 |  |  |     if ($isDrhOfCourse) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1260 |  |  |         $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1261 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1263 |  |  |     $studentPublications = $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1264 |  |  |     $urlOthers = api_get_path(WEB_CODE_PATH).'work/work_list_others.php?'.api_get_cidreq().'&id='; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1265 |  |  |     //while ($work = Database::fetch_assoc($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1266 |  |  |     $icon = Display::getMdiIcon(ObjectIcon::ASSIGNMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1268 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1269 |  |  |     foreach ($studentPublications as $studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1270 |  |  |         $workId = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1271 |  |  |         $assignment = $studentPublication->getAssignment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1272 |  |  |         $isSubscribed = userIsSubscribedToWork($userId, $workId, $course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1273 |  |  |         if (false === $isSubscribed) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1274 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1275 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1276 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1277 |  |  |         /*$visibility = api_get_item_visibility($courseInfo, 'work', $workId, $session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1278 |  |  |         if ($visibility != 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1279 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1280 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1282 |  |  |         $work['type'] = $icon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1283 |  |  |         $work['expires_on'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1284 |  |  |         if ($assignment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1285 |  |  |             $work['expires_on'] = api_get_local_time($assignment->getExpiresOn()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1286 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1287 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1288 |  |  |         $title = $studentPublication->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1289 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1290 |  |  |         /*$whereCondition = " AND u.id = $userId "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1291 |  |  |         $workList = get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1292 |  |  |             0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1293 |  |  |             1000, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1294 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1295 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1296 |  |  |             $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1297 |  |  |             $whereCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1298 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1299 |  |  |         $count = getTotalWorkComment($workList, $courseInfo);*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1300 |  |  |         $count = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1301 |  |  |         //$lastWork = getLastWorkStudentFromParentByUser($userId, $work, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1302 |  |  |         $lastWork = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1303 |  |  |         if (null !== $count && !empty($count)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1304 |  |  |             $urlView = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$lastWork['iid'].'&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1305 |  |  |             $feedback = ' '.Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1306 |  |  |                 Display::getMdiIcon('comment-multiple-outline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1307 |  |  |                 $urlView, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1308 |  |  |                 ['title' => get_lang('View')] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1309 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1311 |  |  |             $work['feedback'] = ' '.Display::label($count.' '.get_lang('Feedback'), 'info').$feedback; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1312 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1313 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1314 |  |  |         if (!empty($lastWork)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1315 |  |  |             $work['last_upload'] = !empty($lastWork['qualification']) ? $lastWork['qualification_rounded'].' - ' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1316 |  |  |             $work['last_upload'] .= api_get_local_time($lastWork['sent_date']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1317 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1319 |  |  |         $work['title'] = Display::url($title, $url.'&id='.$workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1320 |  |  |         $work['others'] = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1321 |  |  |             Display::getMdiIcon(ObjectIcon::GROUP, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Others')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1322 |  |  |             $urlOthers.$workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1323 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1324 |  |  |         $works[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1325 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1326 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1327 |  |  |     return $works; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1328 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1330 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1331 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1332 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1333 |  |  |  * @param string $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1334 |  |  |  * @param string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1335 |  |  |  * @param string $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1336 |  |  |  * @param bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1337 |  |  |  * @param int    $withResults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1338 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1339 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1340 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1341 |  |  | function getAllWorkListStudent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1342 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1343 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1344 |  |  |     $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1345 |  |  |     $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1346 |  |  |     $where_condition, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1347 |  |  |     $getCount = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1348 |  |  |     $withResults = 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1349 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1350 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1351 |  |  |     $workTableAssignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1352 |  |  |     $userId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1353 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1354 |  |  |     if (empty($userId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1355 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1356 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1358 |  |  |     $courses = CourseManager::get_courses_list_by_user_id($userId, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1360 |  |  |     if (!empty($where_condition)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1361 |  |  |         $where_condition = ' AND '.$where_condition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1362 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1363 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1364 |  |  |     if (!in_array($direction, ['asc', 'desc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1365 |  |  |         $direction = 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1366 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1367 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1368 |  |  |     $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1369 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1370 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1371 |  |  |     $courseQuery = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1372 |  |  |     $courseList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1373 |  |  |     foreach ($courses as $course) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1374 |  |  |         $course_id = $course['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1375 |  |  |         $courseInfo = api_get_course_info_by_id($course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1376 |  |  |         $session_id = isset($course['session_id']) ? $course['session_id'] : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1377 |  |  |         $conditionSession = api_get_session_condition($session_id, true, false, 'w.session_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1378 |  |  |         $parentCondition = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1379 |  |  |         if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1380 |  |  |             $parentCondition = 'AND ww.parent_id is NOT NULL'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1381 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1382 |  |  |         $courseQuery[] = " (w.c_id = $course_id $conditionSession $parentCondition )"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1383 |  |  |         $courseList[$course_id] = $courseInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1384 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1385 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1386 |  |  |     $courseQueryToString = implode(' OR ', $courseQuery); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1387 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1388 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1389 |  |  |         if (empty($courseQuery)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1390 |  |  |             return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1391 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1392 |  |  |         $select = 'SELECT count(DISTINCT(w.iid)) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1393 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1394 |  |  |         if (empty($courseQuery)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1395 |  |  |             return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1396 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1397 |  |  |         $select = 'SELECT DISTINCT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1398 |  |  |                         w.url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1399 |  |  |                         w.iid, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1400 |  |  |                         w.c_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1401 |  |  |                         w.session_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1402 |  |  |                         a.expires_on, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1403 |  |  |                         a.ends_on, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1404 |  |  |                         a.enable_qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1405 |  |  |                         w.qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1406 |  |  |                         a.publication_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1407 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1408 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1409 |  |  |     $checkSentWork = " LEFT JOIN $workTable ww | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1410 |  |  |                        ON (ww.c_id = w.c_id AND ww.parent_id = w.iid AND ww.user_id = $userId ) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1411 |  |  |     $where = ' AND ww.url IS NULL '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1412 |  |  |     $expirationCondition = " AND (a.expires_on IS NULL OR a.expires_on > '".api_get_utc_datetime()."') "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1413 |  |  |     if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1414 |  |  |         $where = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1415 |  |  |         $checkSentWork = " LEFT JOIN $workTable ww | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1416 |  |  |                            ON ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1417 |  |  |                             ww.c_id = w.c_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1418 |  |  |                             ww.parent_id = w.iid AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1419 |  |  |                             ww.user_id = $userId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1420 |  |  |                             a.expires_on IS NULL AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1421 |  |  |                             ww.parent_id is NOT NULL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1422 |  |  |                         ) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1423 |  |  |         $expirationCondition = " OR ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1424 |  |  |                 ww.parent_id is NULL AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1425 |  |  |                 a.expires_on IS NOT NULL AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1426 |  |  |                 a.expires_on < '".api_get_utc_datetime()."' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1427 |  |  |             ) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1428 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1429 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1430 |  |  |     $sql = "$select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1431 |  |  |             FROM $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1432 |  |  |             LEFT JOIN $workTableAssignment a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1433 |  |  |             ON (a.publication_id = w.iid AND a.c_id = w.c_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1434 |  |  |             $checkSentWork | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1435 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1436 |  |  |                 w.parent_id = 0 AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1437 |  |  |                 w.active IN (1, 0) AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1438 |  |  |                 ($courseQueryToString) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1439 |  |  |                 $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1440 |  |  |                 $expirationCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1441 |  |  |                 $where | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1442 |  |  |             "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1443 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1444 |  |  |     $sql .= " ORDER BY `$column` $direction "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1445 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1446 |  |  |     if (!empty($start) && !empty($limit)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1447 |  |  |         $sql .= " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1448 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1449 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1450 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1451 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1452 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1453 |  |  |         $row = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1454 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1455 |  |  |         if ($row) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1456 |  |  |             return (int) $row['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1457 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1458 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1459 |  |  |         return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1460 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1461 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1462 |  |  |     $works = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1463 |  |  |     while ($work = Database::fetch_assoc($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1464 |  |  |         $courseId = $work['c_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1465 |  |  |         $courseInfo = $courseList[$work['c_id']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1466 |  |  |         $sessionId = $work['session_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1467 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1468 |  |  |         $cidReq = api_get_cidreq_params($courseId, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1469 |  |  |         $url = api_get_path(WEB_CODE_PATH).'work/work_list.php?'.$cidReq; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1470 |  |  |         $isSubscribed = userIsSubscribedToWork($userId, $work['iid'], $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1471 |  |  |         if (false == $isSubscribed) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1472 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1473 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1474 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1475 |  |  |         /*$visibility = api_get_item_visibility($courseInfo, 'work', $work['iid'], $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1476 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1477 |  |  |         if (1 != $visibility) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1478 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1479 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1480 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1481 |  |  |         $work['type'] = Display::getMdiIcon(ObjectIcon::ASSIGNMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1482 |  |  |         $work['expires_on'] = empty($work['expires_on']) ? null : api_get_local_time($work['expires_on']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1483 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1484 |  |  |         if (empty($work['title'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1485 |  |  |             $work['title'] = basename($work['url']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1486 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1487 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1488 |  |  |         if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1489 |  |  |             $whereCondition = " AND u.id = $userId "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1490 |  |  |             $workList = get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1491 |  |  |                 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1492 |  |  |                 1000, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1493 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1494 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1495 |  |  |                 $work['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1496 |  |  |                 $whereCondition, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1497 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1498 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1499 |  |  |                 $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1500 |  |  |                 $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1501 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1502 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1503 |  |  |             $count = getTotalWorkComment($workList, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1504 |  |  |             $lastWork = getLastWorkStudentFromParentByUser($userId, $work, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1506 |  |  |             if (!is_null($count) && !empty($count)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1507 |  |  |                 $urlView = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$lastWork['iid'].'&'.$cidReq; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1508 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1509 |  |  |                 $feedback = ' '.Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1510 |  |  |                         Display::getMdiIcon('comment-outline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1511 |  |  |                         $urlView, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1512 |  |  |                         ['title' => get_lang('View')] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1513 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1514 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1515 |  |  |                 $work['feedback'] = ' '.Display::label($count.' '.get_lang('Feedback'), 'info').$feedback; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1516 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1517 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1518 |  |  |             if (!empty($lastWork)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1519 |  |  |                 $work['last_upload'] = (!empty($lastWork['qualification'])) ? $lastWork['qualification_rounded'].' - ' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1520 |  |  |                 $work['last_upload'] .= api_get_local_time($lastWork['sent_date']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1521 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1522 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1523 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1524 |  |  |         $work['title'] = Display::url($work['title'], $url.'&id='.$work['iid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1525 |  |  |         $works[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1526 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1527 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1528 |  |  |     return $works; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1529 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1530 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1531 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1532 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1533 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1534 |  |  |  * @param ?string $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1535 |  |  |  * @param ?string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1536 |  |  |  * @param ?string $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1537 |  |  |  * @param ?bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1538 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1539 |  |  |  * @return int|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1540 |  |  |  * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1541 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1542 |  |  | function getWorkListTeacher( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1543 |  |  |     int $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1544 |  |  |     int $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1545 |  |  |     ?string $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1546 |  |  |     ?string $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1547 |  |  |     ?string $where_condition, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1548 |  |  |     ?bool $getCount = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1549 |  |  | ): int|array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1550 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1551 |  |  |     $session_id = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1552 |  |  |     $group_id = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1553 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1554 |  |  |     if ($group_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1555 |  |  |         $groupInfo = GroupManager::get_group_properties($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1556 |  |  |         $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1557 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1558 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1559 |  |  |     if (empty($direction) || !in_array($direction, ['asc', 'desc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1560 |  |  |         $direction = 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1561 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1562 |  |  |     if (!empty($where_condition)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1563 |  |  |         $where_condition = ' AND '.$where_condition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1564 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1565 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1566 |  |  |     $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1567 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1568 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1569 |  |  |     $works = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1570 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1571 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1572 |  |  |     $course = api_get_course_entity($course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1573 |  |  |     $session = api_get_session_entity($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1574 |  |  |     $group = api_get_group_entity($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1575 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1576 |  |  |     // Get list from database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1577 |  |  |     if ($is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1578 |  |  |         $active_condition = ' active IN (0, 1)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1579 |  |  |         if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1580 |  |  |             $select = ' SELECT count(w.iid) as count'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1581 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1582 |  |  |             $select = ' SELECT w.*, a.expires_on, expires_on, ends_on, enable_qualification '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1583 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1584 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1585 |  |  |         $qb = $repo->getResourcesByCourse($course, $session, $group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1586 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1587 |  |  |         $qb->andWhere($qb->expr()->in('resource.active', [1, 0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1588 |  |  |         $qb->andWhere($qb->expr()->isNull('resource.publicationParent')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1589 |  |  |         if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1590 |  |  |             $qb->select('count(resource)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1591 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1592 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1593 |  |  |         $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1594 |  |  |             ->setFirstResult($start) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1595 |  |  |             ->setMaxResults($limit) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1596 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1597 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1598 |  |  |         /*$sql = " $select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1599 |  |  |                 FROM $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1600 |  |  |                 LEFT JOIN $workTableAssignment a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1601 |  |  |                 ON (a.publication_id = w.iid AND a.c_id = w.c_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1602 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1603 |  |  |                     w.c_id = $course_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1604 |  |  |                     $condition_session AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1605 |  |  |                     $active_condition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1606 |  |  |                     parent_id = 0 AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1607 |  |  |                     post_group_id = $groupIid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1608 |  |  |                     $where_condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1609 |  |  |                 ORDER BY `$column` $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1610 |  |  |                 LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1611 |  |  |         $result = Database::query($sql);*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1612 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1613 |  |  |         if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1614 |  |  |             return (int) $qb->getQuery()->getSingleScalarResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1615 |  |  |             /*$row = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1616 |  |  |             return (int) $row['count'];*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1617 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1618 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1619 |  |  |         $studentPublications = $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1620 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1621 |  |  |         $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1622 |  |  |         $blockEdition = ('true' === api_get_setting('work.block_student_publication_edition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1623 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1624 |  |  |         //while ($work = Database::fetch_assoc($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1625 |  |  |         $icon = Display::getMdiIcon(ObjectIcon::ASSIGNMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1626 |  |  |         /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1627 |  |  |         foreach ($studentPublications as $studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1628 |  |  |             $workId = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1629 |  |  |             $work = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1630 |  |  |             $work['iid'] = $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1631 |  |  |             $work['type'] = $icon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1632 |  |  |             $assignment = $studentPublication->getAssignment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1633 |  |  |             $work['expires_on'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1634 |  |  |             if ($assignment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1635 |  |  |                 $work['expires_on'] = api_get_local_time($assignment->getExpiresOn()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1636 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1637 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1638 |  |  |             /*$countUniqueAttempts = getUniqueStudentAttemptsTotal( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1639 |  |  |                 $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1640 |  |  |                 $group_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1641 |  |  |                 $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1642 |  |  |                 $session_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1643 |  |  |             );*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1644 |  |  |             $countUniqueAttempts = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1645 |  |  |             $totalUsers = getStudentSubscribedToWork( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1646 |  |  |                 $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1647 |  |  |                 $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1648 |  |  |                 $group_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1649 |  |  |                 $session_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1650 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1651 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1652 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1653 |  |  |             $work['amount'] = Display::label($countUniqueAttempts.'/'.$totalUsers, 'success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1654 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1655 |  |  |             //$visibility = api_get_item_visibility($courseInfo, 'work', $workId, $session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1656 |  |  |             $isVisible = $studentPublication->isVisible($course, $session); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1657 |  |  |             if ($isVisible) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1658 |  |  |                 $icon = ActionIcon::VISIBLE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1659 |  |  |                 $text = get_lang('Visible'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1660 |  |  |                 $action = 'invisible'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1661 |  |  |                 $class = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1662 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1663 |  |  |                 $icon = ActionIcon::INVISIBLE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1664 |  |  |                 $text = get_lang('invisible'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1665 |  |  |                 $action = 'visible'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1666 |  |  |                 $class = 'muted'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1667 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1668 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1669 |  |  |             $visibilityLink = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1670 |  |  |                 Display::getMdiIcon($icon, 'ch-tool-icon', null, ICON_SIZE_SMALL, $text), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1671 |  |  |                 api_get_path(WEB_CODE_PATH).'work/work.php?id='.$workId.'&action='.$action.'&'.api_get_cidreq() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1672 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1673 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1674 |  |  |             $title = $studentPublication->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1675 |  |  |             $work['title'] = Display::url($title, $url.'&id='.$workId, ['class' => $class]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1676 |  |  |             $work['title'] .= ' '.Display::label(get_count_work($workId), 'success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1677 |  |  |             $work['sent_date'] = api_get_local_time($studentPublication->getSentDate()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1678 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1679 |  |  |             if ($blockEdition && !api_is_platform_admin()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1680 |  |  |                 $editLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1681 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1682 |  |  |                 $editLink = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1683 |  |  |                     Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1684 |  |  |                     api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1685 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1686 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1687 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1688 |  |  |             $correctionLink = ' '.Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1689 |  |  |                 Display::getMdiIcon(ActionIcon::UPLOAD, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Upload corrections')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1690 |  |  |                 api_get_path(WEB_CODE_PATH).'work/upload_corrections.php?'.api_get_cidreq().'&id='.$workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1691 |  |  |             ).' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1692 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1693 |  |  |             if ($countUniqueAttempts > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1694 |  |  |                 $downloadLink = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1695 |  |  |                     Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Save')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1696 |  |  |                     api_get_path(WEB_CODE_PATH).'work/downloadfolder.inc.php?id='.$workId.'&'.api_get_cidreq() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1697 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1698 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1699 |  |  |                 $downloadLink = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1700 |  |  |                     Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Save')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1701 |  |  |                     '#' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1702 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1703 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1704 |  |  |             if (!api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1705 |  |  |                 $editLink = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1706 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1707 |  |  |             $work['actions'] = $visibilityLink.$correctionLink.$downloadLink.$editLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1708 |  |  |             $works[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1709 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1710 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1711 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1712 |  |  |     return $works; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1713 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1714 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1715 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1716 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1717 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1718 |  |  |  * @param string $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1719 |  |  |  * @param string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1720 |  |  |  * @param int    $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1721 |  |  |  * @param int    $studentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1722 |  |  |  * @param string $whereCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1723 |  |  |  * @param bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1724 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1725 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1726 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1727 |  |  | function get_work_user_list_from_documents( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1728 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1729 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1730 |  |  |     $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1731 |  |  |     $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1732 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1733 |  |  |     $studentId = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1734 |  |  |     $whereCondition = '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1735 |  |  |     $getCount = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1736 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1737 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1738 |  |  |         $select1 = ' SELECT count(u.id) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1739 |  |  |         $select2 = ' SELECT count(u.id) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1740 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1741 |  |  |         $select1 = ' SELECT DISTINCT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1742 |  |  |                         u.firstname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1743 |  |  |                         u.lastname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1744 |  |  |                         u.id as user_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1745 |  |  |                         w.title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1746 |  |  |                         w.parent_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1747 |  |  |                         w.document_id document_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1748 |  |  |                         w.iid, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1749 |  |  |                         qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1750 |  |  |                         qualificator_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1751 |  |  |                         w.sent_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1752 |  |  |                         w.contains_file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1753 |  |  |                         w.url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1754 |  |  |                     '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1755 |  |  |         $select2 = ' SELECT DISTINCT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1756 |  |  |                         u.firstname, u.lastname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1757 |  |  |                         u.id as user_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1758 |  |  |                         d.title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1759 |  |  |                         w.parent_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1760 |  |  |                         d.iid document_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1761 |  |  |                         0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1762 |  |  |                         0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1763 |  |  |                         0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1764 |  |  |                         w.sent_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1765 |  |  |                         w.contains_file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1766 |  |  |                         w.url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1767 |  |  |                     '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1768 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1769 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1770 |  |  |     $documentTable = Database::get_course_table(TABLE_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1771 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1772 |  |  |     $workRelDocument = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1773 |  |  |     $userTable = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1774 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1775 |  |  |     $courseId = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1776 |  |  |     $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1777 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1778 |  |  |     if (empty($studentId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1779 |  |  |         $studentId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1780 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1781 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1782 |  |  |     $studentId = (int) $studentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1783 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1784 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1785 |  |  |     $userCondition = " AND u.id = $studentId "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1786 |  |  |     $sessionCondition = api_get_session_condition($sessionId, true, false, 'w.session_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1787 |  |  |     $workCondition = " AND w_rel.work_id = $workId"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1788 |  |  |     $workParentCondition = " AND w.parent_id = $workId"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1789 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1790 |  |  |     $sql = "( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1791 |  |  |                 $select1 FROM $userTable u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1792 |  |  |                 INNER JOIN $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1793 |  |  |                 ON (u.id = w.user_id AND w.active IN (0, 1) AND w.filetype = 'file') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1794 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1795 |  |  |                     w.c_id = $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1796 |  |  |                     $userCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1797 |  |  |                     $sessionCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1798 |  |  |                     $whereCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1799 |  |  |                     $workParentCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1800 |  |  |             ) UNION ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1801 |  |  |                 $select2 FROM $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1802 |  |  |                 INNER JOIN $workRelDocument w_rel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1803 |  |  |                 ON (w_rel.work_id = w.iid AND w.active IN (0, 1) AND w_rel.c_id = w.c_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1804 |  |  |                 INNER JOIN $documentTable d | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1805 |  |  |                 ON (w_rel.document_id = d.iid AND d.c_id = w.c_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1806 |  |  |                 INNER JOIN $userTable u ON (u.id = $studentId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1807 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1808 |  |  |                     w.c_id = $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1809 |  |  |                     $workCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1810 |  |  |                     $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1811 |  |  |                     d.iid NOT IN ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1812 |  |  |                         SELECT w.document_id id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1813 |  |  |                         FROM $workTable w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1814 |  |  |                         WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1815 |  |  |                             user_id = $studentId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1816 |  |  |                             c_id = $courseId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1817 |  |  |                             filetype = 'file' AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1818 |  |  |                             active IN (0, 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1819 |  |  |                             $sessionCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1820 |  |  |                             $workParentCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1821 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1822 |  |  |             )"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1823 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1824 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1825 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1826 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1827 |  |  |     $direction = in_array(strtolower($direction), ['desc', 'asc']) ? $direction : 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1828 |  |  |     $column = Database::escape_string($column); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1829 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1830 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1831 |  |  |         $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1832 |  |  |         $result = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1833 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1834 |  |  |         return $result['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1835 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1836 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1837 |  |  |     $sql .= " ORDER BY `$column` $direction"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1838 |  |  |     $sql .= " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1839 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1840 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1841 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1842 |  |  |     $currentUserId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1843 |  |  |     $work_data = get_work_data_by_id($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1844 |  |  |     $qualificationExists = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1845 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1846 |  |  |     if (!empty($work_data['qualification']) && (int) ($work_data['qualification']) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1847 |  |  |         $qualificationExists = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1848 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1849 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1850 |  |  |     $urlAdd = api_get_path(WEB_CODE_PATH).'work/upload_from_template.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1851 |  |  |     $urlEdit = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1852 |  |  |     $urlDelete = api_get_path(WEB_CODE_PATH).'work/work_list.php?action=delete&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1853 |  |  |     $urlView = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1854 |  |  |     $urlDownload = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1855 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1856 |  |  |     $editIcon = Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1857 |  |  |     $addIcon = Display::getMdiIcon(ActionIcon::ADD, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Add')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1858 |  |  |     $deleteIcon = Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1859 |  |  |     $viewIcon = Display::getMdiIcon(ObjectIcon::DEFAULT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1860 |  |  |     $saveIcon = Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Save')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1861 |  |  |     $allowEdition = 1 == api_get_course_setting('student_delete_own_publication'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1862 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1863 |  |  |     $workList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1864 |  |  |     while ($row = Database::fetch_assoc($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1865 |  |  |         $userId = $row['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1866 |  |  |         $documentId = $row['document_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1867 |  |  |         $itemId = $row['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1868 |  |  |         $addLinkShowed = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1869 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1870 |  |  |         if (empty($documentId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1871 |  |  |             $url = $urlEdit.'&item_id='.$row['iid'].'&id='.$workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1872 |  |  |             $editLink = Display::url($editIcon, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1873 |  |  |             if (1 != $allowEdition) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1874 |  |  |                 $editLink = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1875 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1876 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1877 |  |  |             $documentToWork = getDocumentToWorkPerUser($documentId, $workId, $courseId, $sessionId, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1878 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1879 |  |  |             if (empty($documentToWork)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1880 |  |  |                 $url = $urlAdd.'&document_id='.$documentId.'&id='.$workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1881 |  |  |                 $editLink = Display::url($addIcon, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1882 |  |  |                 $addLinkShowed = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1883 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1884 |  |  |                 $row['title'] = $documentToWork['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1885 |  |  |                 $row['sent_date'] = $documentToWork['sent_date']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1886 |  |  |                 $newWorkId = $documentToWork['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1887 |  |  |                 $url = $urlEdit.'&item_id='.$newWorkId.'&id='.$workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1888 |  |  |                 $editLink = Display::url($editIcon, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1889 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1890 |  |  |                 if (1 != $allowEdition) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1891 |  |  |                     $editLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1892 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1893 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1894 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1895 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1896 |  |  |         $downloadLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1897 |  |  |         // If URL is present then there's a file to download keep BC. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1898 |  |  |         if ($row['contains_file'] || !empty($row['url'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1899 |  |  |             $downloadLink = Display::url($saveIcon, $urlDownload.'&id='.$row['iid']).' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1900 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1901 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1902 |  |  |         $viewLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1903 |  |  |         if (!empty($itemId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1904 |  |  |             $viewLink = Display::url($viewIcon, $urlView.'&id='.$itemId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1905 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1906 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1907 |  |  |         $deleteLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1908 |  |  |         if (1 == $allowEdition && !empty($itemId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1909 |  |  |             $deleteLink = Display::url($deleteIcon, $urlDelete.'&item_id='.$itemId.'&id='.$workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1910 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1911 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1912 |  |  |         $row['type'] = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1913 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1914 |  |  |         if ($qualificationExists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1915 |  |  |             if (empty($row['qualificator_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1916 |  |  |                 $status = Display::label(get_lang('Not reviewed'), 'warning'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1917 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1918 |  |  |                 $status = Display::label(get_lang('Reviewed'), 'success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1919 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1920 |  |  |             $row['qualificator_id'] = $status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1921 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1922 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1923 |  |  |         if (!empty($row['qualification'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1924 |  |  |             $row['qualification'] = Display::label($row['qualification'], 'info'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1925 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1926 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1927 |  |  |         if (!empty($row['sent_date'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1928 |  |  |             $row['sent_date'] = Display::dateToStringAgoAndLongDate($row['sent_date']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1929 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1930 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1931 |  |  |         if ($userId == $currentUserId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1932 |  |  |             $row['actions'] = $downloadLink.$viewLink.$editLink.$deleteLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1933 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1934 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1935 |  |  |         if ($addLinkShowed) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1936 |  |  |             $row['qualification'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1937 |  |  |             $row['qualificator_id'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1938 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1939 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1940 |  |  |         $workList[] = $row; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1941 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1942 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1943 |  |  |     return $workList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1944 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1945 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1946 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1947 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1948 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1949 |  |  |  * @param int    $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1950 |  |  |  * @param string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1951 |  |  |  * @param int    $work_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1952 |  |  |  * @param string $whereCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1953 |  |  |  * @param int    $studentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1954 |  |  |  * @param bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1955 |  |  |  * @param int    $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1956 |  |  |  * @param int    $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1957 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1958 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1959 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1960 |  |  | function get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1961 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1962 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1963 |  |  |     $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1964 |  |  |     $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1965 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1966 |  |  |     $whereCondition = '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1967 |  |  |     $studentId = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1968 |  |  |     $getCount = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1969 |  |  |     $courseId = 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1970 |  |  |     $sessionId = 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1971 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1972 |  |  |     $session_id = $sessionId ? (int) $sessionId : api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1973 |  |  |     $groupId = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1974 |  |  |     $course_info = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1975 |  |  |     $course_info = empty($course_info) ? api_get_course_info_by_id($courseId) : $course_info; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1976 |  |  |     $courseId = isset($course_info['real_id']) ? $course_info['real_id'] : $courseId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1977 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1978 |  |  |     $course = api_get_course_entity($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1979 |  |  |     $session = api_get_session_entity($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1980 |  |  |     $group = api_get_group_entity($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1981 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1982 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1983 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1984 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1985 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1986 |  |  |     $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1987 |  |  |     $compilation = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1988 |  |  |     if ('true' === api_get_setting('work.allow_compilatio_tool')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1989 |  |  |         $compilation = new Compilatio(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1990 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1991 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1992 |  |  |     if (!in_array($direction, ['asc', 'desc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1993 |  |  |         $direction = 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1994 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1995 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1996 |  |  |     //$work_data = get_work_data_by_id($workId, $courseId, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1997 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1998 |  |  |     $condition_session = api_get_session_condition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1999 |  |  |         $session_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2000 |  |  |         true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2001 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2002 |  |  |         'work.session_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2003 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2004 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2005 |  |  |     $locked = api_resource_is_locked_by_gradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2006 |  |  |         $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2007 |  |  |         LINK_STUDENTPUBLICATION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2008 |  |  |         $course_info['code'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2009 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2010 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2011 |  |  |     $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2012 |  |  |         api_get_user_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2013 |  |  |         $course_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2014 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2015 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2016 |  |  |     $isDrhOfSession = !empty(SessionManager::getSessionFollowedByDrh(api_get_user_id(), $session_id)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2017 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2018 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2019 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2020 |  |  |     $studentPublication = $repo->find($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2021 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2022 |  |  |     if (null !== $studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2023 |  |  |         /*if (!empty($group_id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2024 |  |  |             // set to select only messages posted by the user's group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2025 |  |  |             $extra_conditions = " work.post_group_id = '".$groupIid."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2026 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2027 |  |  |             $extra_conditions = " (work.post_group_id = '0' OR work.post_group_id is NULL) "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2028 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2029 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2030 |  |  |         /*if ($is_allowed_to_edit || $isDrhOfCourse || $isDrhOfSession) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2031 |  |  |             $extra_conditions .= ' AND work.active IN (0, 1) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2032 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2033 |  |  |             if (isset($course_info['show_score']) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2034 |  |  |                 1 == $course_info['show_score'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2035 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2036 |  |  |                 $extra_conditions .= ' AND (u.id = '.api_get_user_id().' AND work.active IN (0, 1)) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2037 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2038 |  |  |                 $extra_conditions .= ' AND work.active IN (0, 1) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2039 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2040 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2041 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2042 |  |  |         $extra_conditions .= " AND parent_id  = $workId ";*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2043 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2044 |  |  |         $select = 'SELECT DISTINCT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2045 |  |  |                         u.id as user_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2046 |  |  |                         work.iid as id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2047 |  |  |                         title as title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2048 |  |  |                         description, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2049 |  |  |                         url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2050 |  |  |                         sent_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2051 |  |  |                         contains_file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2052 |  |  |                         has_properties, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2053 |  |  |                         view_properties, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2054 |  |  |                         qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2055 |  |  |                         weight, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2056 |  |  |                         allow_text_assignment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2057 |  |  |                         u.firstname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2058 |  |  |                         u.lastname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2059 |  |  |                         u.username, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2060 |  |  |                         parent_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2061 |  |  |                         accepted, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2062 |  |  |                         qualificator_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2063 |  |  |                         '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2064 |  |  |         if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2065 |  |  |             $select = 'SELECT DISTINCT count(u.id) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2066 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2067 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2068 |  |  |         /*$work_assignment = get_work_assignment_by_id($workId, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2069 |  |  |         if (!empty($studentId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2070 |  |  |             $studentId = (int) $studentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2071 |  |  |             $whereCondition .= " AND u.id = $studentId "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2072 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2073 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2074 |  |  |         $qb = $repo->getStudentAssignments($studentPublication, $course, $session, $group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2075 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2076 |  |  |         if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2077 |  |  |             $qb->select('count(resource)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2078 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2079 |  |  |             return $qb->getQuery()->getSingleScalarResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2080 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2081 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2082 |  |  |         $qb->setFirstResult($start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2083 |  |  |         $qb->setMaxResults($limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2084 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2085 |  |  |         $assignments = $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2086 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2087 |  |  |         /*$sql = " $select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2088 |  |  |                 FROM $work_table work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2089 |  |  |                 INNER JOIN $user_table u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2090 |  |  |                 ON (work.user_id = u.id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2091 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2092 |  |  |                     work.c_id = $course_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2093 |  |  |                     $extra_conditions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2094 |  |  |                     $whereCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2095 |  |  |                     $condition_session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2096 |  |  |                     AND u.status != ".INVITEE." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2097 |  |  |                 ORDER BY `$column` $direction"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2098 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2099 |  |  |         if (!empty($start) && !empty($limit)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2100 |  |  |             $sql .= " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2101 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2102 |  |  |         $result = Database::query($sql);*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2103 |  |  |         $works = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2104 |  |  |         /*if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2105 |  |  |             $work = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2106 |  |  |             if ($work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2107 |  |  |                 return (int) $work['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2108 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2110 |  |  |             return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2111 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2113 |  |  |         $url = api_get_path(WEB_CODE_PATH).'work/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2114 |  |  |         $unoconv = api_get_setting('platform.unoconv_binaries'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2115 |  |  |         $loadingText = addslashes(get_lang('Loading')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2116 |  |  |         $uploadedText = addslashes(get_lang('Uploaded.')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2117 |  |  |         $failsUploadText = addslashes(get_lang('No file was uploaded.')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2118 |  |  |         $failsUploadIcon = Display::getMdiIcon( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2119 |  |  |             StateIcon::INCOMPLETE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2120 |  |  |             'ch-tool-icon', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2121 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2122 |  |  |             ICON_SIZE_TINY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2123 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2124 |  |  |         $saveIcon = Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Save')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2126 |  |  |         $correctionIcon = Display::getMdiIcon(ActionIcon::ACCEPT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Correction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2128 |  |  |         $correctionIconSmall = Display::getMdiIcon(ActionIcon::ACCEPT, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Correction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2130 |  |  |         $rateIcon = Display::getMdiIcon(ActionIcon::GRADE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Correct and rate')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2132 |  |  |         $blockEdition = ('true' === api_get_setting('work.block_student_publication_edition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2133 |  |  |         $blockScoreEdition = ('true' === api_get_setting('work.block_student_publication_score_edition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2134 |  |  |         $loading = Display::getMdiIcon('loading', 'animate-spin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2135 |  |  |         $router = Container::getRouter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2136 |  |  |         $studentDeleteOwnPublication = api_get_course_setting('student_delete_own_publication'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2137 |  |  |         /** @var CStudentPublication $assignment */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2138 |  |  |         foreach ($assignments as $assignment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2139 |  |  |             $item_id = $assignment->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2140 |  |  |             // Get the author ID for that document from the item_property table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2141 |  |  |             $is_author = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2142 |  |  |             $can_read = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2143 |  |  |             $owner_id = $assignment->getUser()->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2144 |  |  |             /* Because a bug found when saving items using the api_item_property_update() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2145 |  |  |                the field $item_property_data['insert_user_id'] is not reliable. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2146 |  |  |             if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2147 |  |  |                 $is_author = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2148 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2150 |  |  |             if (0 == $course_info['show_score']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2151 |  |  |                 $can_read = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2152 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2153 |  |  |             $qualification = $assignment->getQualification(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2154 |  |  |             $qualification_exists = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2155 |  |  |             if (!empty($qualification) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2156 |  |  |                 (int) ($qualification) > 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2157 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2158 |  |  |                 $qualification_exists = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2159 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2161 |  |  |             $qualification_string = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2162 |  |  |             if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2163 |  |  |                 if ('' == $qualification) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2164 |  |  |                     $qualification_string = Display::label('-'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2165 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2166 |  |  |                     $qualification_string = formatWorkScore($qualification, $qualification); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2167 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2168 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2169 |  |  |             $work['iid'] = $assignment->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2170 |  |  |             $work['qualification_score'] = $studentPublication->getQualification(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2171 |  |  |             $add_string = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2172 |  |  |             $time_expires = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2173 |  |  |             $assignmentConfiguration = $studentPublication->getAssignment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2174 |  |  |             $expiresOn = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2175 |  |  |             if (!empty($assignmentConfiguration)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2176 |  |  |                 $expiresOn = $assignmentConfiguration->getExpiresOn(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2177 |  |  |                 if (!empty($expiresOn)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2178 |  |  |                     $time_expires = api_strtotime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2179 |  |  |                         $expiresOn->format('Y-m-d H:i:s'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2180 |  |  |                         'UTC' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2181 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2182 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2183 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2185 |  |  |             if (!empty($expiresOn) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2186 |  |  |                 !empty($time_expires) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2187 |  |  |                 ($time_expires < api_strtotime($studentPublication->getSentDate(), 'UTC')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2188 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2189 |  |  |                 $add_string = Display::label(get_lang('Expired'), 'important').' - '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2190 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2192 |  |  |             $accepted = $studentPublication->getAccepted(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2193 |  |  |             if (($can_read && $accepted) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2194 |  |  |                 $is_author || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2195 |  |  |                 ($is_allowed_to_edit || api_is_drh()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2196 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2197 |  |  |                 // Firstname, lastname, username | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2198 |  |  |                 $work['fullname'] = Display::div( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2199 |  |  |                     UserManager::formatUserFullName($assignment->getUser()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2200 |  |  |                     ['class' => 'work-name'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2201 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2202 |  |  |                 // Title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2203 |  |  |                 $title = $assignment->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2204 |  |  |                 $work['title_clean'] = $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2205 |  |  |                 $title = Security::remove_XSS($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2206 |  |  |                 if (strlen($title) > 30) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2207 |  |  |                     $short_title = substr($title, 0, 27).'...'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2208 |  |  |                     $work['title'] = Display::span($short_title, ['class' => 'work-title', 'title' => $title]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2209 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2210 |  |  |                     $work['title'] = Display::div($title, ['class' => 'work-title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2211 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2213 |  |  |                 // Type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2214 |  |  |                 //$work['type'] = DocumentManager::build_document_icon_tag('file', $studentPublication->getUrl()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2215 |  |  |                 $work['type'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2217 |  |  |                 // File name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2218 |  |  |                 $linkToDownload = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2219 |  |  |                 // If URL is present then there's a file to download keep BC. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2220 |  |  |                 if ($studentPublication->getContainsFile()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2221 |  |  |                     $downloadUrl = $repo->getResourceFileDownloadUrl($assignment).'?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2222 |  |  |                     $linkToDownload = '<a href="'.$downloadUrl.'">'.$saveIcon.'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2223 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2225 |  |  |                 $feedback = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2226 |  |  |                 $count = count($studentPublication->getComments()); // getWorkCommentCount($item_id, $course_info); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2227 |  |  |                 if (null !== $count && !empty($count)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2228 |  |  |                     if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2229 |  |  |                         $feedback .= ' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2230 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2231 |  |  |                     $feedback .= Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2232 |  |  |                         $count.' '.Display::getMdiIcon('comment-multiple-outline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2233 |  |  |                         $url.'view.php?'.api_get_cidreq().'&id='.$item_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2234 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2235 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2236 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2237 |  |  |                 $correction = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2238 |  |  |                 $hasCorrection = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2239 |  |  |                 $correctionEntity = $assignment->getCorrection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2240 |  |  |                 if (null !== $correctionEntity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2241 |  |  |                     $downloadUrl = $repo->getResourceFileDownloadUrl($assignment).'?'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2242 |  |  |                     $hasCorrection = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2243 |  |  |                         $correctionIcon, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2244 |  |  |                         $downloadUrl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2245 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2246 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2248 |  |  |                 if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2249 |  |  |                     $work['qualification'] = $qualification_string.$feedback; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2250 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2251 |  |  |                     $work['qualification'] = $qualification_string.$feedback.$hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2252 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2254 |  |  |                 $work['qualification_only'] = $qualification_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2255 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2256 |  |  |                 // Date. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2257 |  |  |                 $sendDate = $studentPublication->getSentDate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2258 |  |  |                 $sendDateToString = $studentPublication->getSentDate()->format('Y-m-d H:i:s'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2260 |  |  |                 $work_date = api_get_local_time($sendDate); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2261 |  |  |                 $date = date_to_str_ago($sendDate).' '.$work_date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2262 |  |  |                 $work['formatted_date'] = $work_date.' '.$add_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2263 |  |  |                 $work['expiry_note'] = $add_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2264 |  |  |                 $work['sent_date_from_db'] = $sendDateToString; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2265 |  |  |                 $work['sent_date'] = '<div class="work-date" title="'.$date.'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2266 |  |  |                     $add_string.' '.Display::dateToStringAgoAndLongDate($sendDate). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2267 |  |  |                     '</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2268 |  |  |                 $work['status'] = $hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2269 |  |  |                 $work['has_correction'] = $hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2271 |  |  |                 // Actions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2272 |  |  |                 $action = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2273 |  |  |                 $qualificatorId = $assignment->getQualificatorId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2274 |  |  |                 if (api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2275 |  |  |                     if ($blockScoreEdition && !api_is_platform_admin() && !empty($studentPublication->getQualification())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2276 |  |  |                         $rateLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2277 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2278 |  |  |                         $rateLink = '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2279 |  |  |                             href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2280 |  |  |                             $rateIcon.'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2281 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2282 |  |  |                     $action .= $rateLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2283 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2284 |  |  |                     if ($unoconv && empty($assignment->getContainsFile())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2285 |  |  |                         $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2286 |  |  |                             href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=export_to_doc&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2287 |  |  |                             title="'.get_lang('Export to .doc').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2288 |  |  |                             Display::getMdiIcon(ActionIcon::EXPORT_DOC, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Export to .doc')).'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2289 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2291 |  |  |                     $alreadyUploaded = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2292 |  |  |                     if ($correctionEntity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2293 |  |  |                         $alreadyUploaded = '<br />'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2294 |  |  |                             $assignment->getResourceNode()->getTitle().' '.$correctionIconSmall; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2295 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2296 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2297 |  |  |                     $correction = ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2298 |  |  |                         <form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2299 |  |  |                         id="file_upload_'.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2300 |  |  |                         class="work_correction_file_upload file_upload_small fileinput-button" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2301 |  |  |                         action="'.api_get_path(WEB_AJAX_PATH).'work.ajax.php?'.api_get_cidreq().'&a=upload_correction_file&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2302 |  |  |                         method="POST" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2303 |  |  |                         enctype="multipart/form-data" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2304 |  |  |                         > | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2305 |  |  |                         <div id="progress_'.$item_id.'" class="text-center button-load"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2306 |  |  |                             '.addslashes(get_lang('Click or drop one file here')).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2307 |  |  |                             '.Display::getMdiIcon(ActionIcon::UPLOAD, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Correction')).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2308 |  |  |                             '.$alreadyUploaded.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2309 |  |  |                         </div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2310 |  |  |                         <input id="file_'.$item_id.'" type="file" name="file" class="" multiple> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2311 |  |  |                         </form> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2312 |  |  |                     '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2313 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2314 |  |  |                     $correction .= "<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2315 |  |  |                     $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2316 |  |  |                         $('.work_correction_file_upload').each(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2317 |  |  |                             $(this).fileupload({ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2318 |  |  |                                 dropZone: $(this) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2319 |  |  |                             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2320 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2322 |  |  |                         $('#file_upload_".$item_id."').fileupload({ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2323 |  |  |                             add: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2324 |  |  |                                 $('#progress_$item_id').html(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2325 |  |  |                                 data.context = $('#progress_$item_id').html('$loadingText <br /> <em class=\"fa fa-spinner fa-pulse fa-fw\"></em>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2326 |  |  |                                 data.submit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2327 |  |  |                                 $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2328 |  |  |                             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2329 |  |  |                             dragover: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2330 |  |  |                                 $(this).addClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2331 |  |  |                             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2332 |  |  |                             done: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2333 |  |  |                                 if (data._response.result.name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2334 |  |  |                                     $('#progress_$item_id').html('$uploadedText '+data._response.result.result+'<br />'+data._response.result.name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2335 |  |  |                                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2336 |  |  |                                     $('#progress_$item_id').html('$failsUploadText $failsUploadIcon'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2337 |  |  |                                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2338 |  |  |                                 $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2339 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2340 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2341 |  |  |                         $('#file_upload_".$item_id."').on('dragleave', function (e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2342 |  |  |                             // dragleave callback implementation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2343 |  |  |                             $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2344 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2345 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2346 |  |  |                     </script>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2348 |  |  |                     if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2349 |  |  |                         if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2350 |  |  |                             $action .= Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Correct and rate')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2351 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2352 |  |  |                             $action .= Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Comment')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2353 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2354 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2355 |  |  |                         if ($blockEdition && !api_is_platform_admin()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2356 |  |  |                             $editLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2357 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2358 |  |  |                             if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2359 |  |  |                                 $editLink = '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2360 |  |  |                                     href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$workId.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2361 |  |  |                                     title="'.get_lang('Edit').'"  >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2362 |  |  |                                     Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2363 |  |  |                             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2364 |  |  |                                 $editLink = '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2365 |  |  |                                     href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$workId.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2366 |  |  |                                     title="'.get_lang('Edit').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2367 |  |  |                                     Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2368 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2369 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2370 |  |  |                         $action .= $editLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2371 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2372 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2373 |  |  |                     if ($assignment->getContainsFile()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2374 |  |  |                         if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2375 |  |  |                             $action .= Display::getMdiIcon(ActionIcon::MOVE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Move')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2376 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2377 |  |  |                             $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2378 |  |  |                                 href="'.$url.'work.php?'.api_get_cidreq().'&action=move&item_id='.$item_id.'&id='.$workId.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2379 |  |  |                                 title="'.get_lang('Move').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2380 |  |  |                                 Display::getMdiIcon(ActionIcon::MOVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2381 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2382 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2383 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2384 |  |  |                     if ($assignment->getAccepted()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2385 |  |  |                         $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2386 |  |  |                             href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=make_invisible&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2387 |  |  |                             title="'.get_lang('invisible').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2388 |  |  |                             Display::getMdiIcon(ActionIcon::INVISIBLE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('invisible')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2389 |  |  |                             '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2390 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2391 |  |  |                         $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2392 |  |  |                             href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=make_visible&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2393 |  |  |                             title="'.get_lang('Visible').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2394 |  |  |                             Display::getMdiIcon(ActionIcon::VISIBLE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Visible')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2395 |  |  |                             '</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2396 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2397 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2398 |  |  |                     if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2399 |  |  |                         $action .= Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Delete')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2400 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2401 |  |  |                         $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2402 |  |  |                             href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=delete&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2403 |  |  |                             onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2404 |  |  |                             title="'.get_lang('Delete').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2405 |  |  |                             Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2406 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2407 |  |  |                 } elseif ($is_author && (empty($qualificatorId) || 0 == $qualificatorId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2408 |  |  |                     $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2409 |  |  |                             href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2410 |  |  |                             title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2411 |  |  |                         Display::getMdiIcon(ObjectIcon::DEFAULT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2412 |  |  |                         '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2413 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2414 |  |  |                     if (1 == $studentDeleteOwnPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2415 |  |  |                         if (api_is_allowed_to_session_edit(false, true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2416 |  |  |                             $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2417 |  |  |                                 href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$workId.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2418 |  |  |                                 title="'.get_lang('Edit').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2419 |  |  |                                 Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Comment')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2420 |  |  |                                 '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2421 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2422 |  |  |                         $action .= ' <a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2423 |  |  |                             href="'.$url.'work_list.php?'.api_get_cidreq().'&action=delete&item_id='.$item_id.'&id='.$workId.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2424 |  |  |                             onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2425 |  |  |                             title="'.get_lang('Delete').'"  >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2426 |  |  |                             Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2427 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2428 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2429 |  |  |                     $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2430 |  |  |                         href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2431 |  |  |                         title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2432 |  |  |                         Display::getMdiIcon(ObjectIcon::DEFAULT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View')). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2433 |  |  |                         '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2434 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2435 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2436 |  |  |                 // Status. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2437 |  |  |                 if (empty($qualificatorId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2438 |  |  |                     $qualificator_id = Display::label(get_lang('Not reviewed'), 'warning'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2439 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2440 |  |  |                     $qualificator_id = Display::label(get_lang('Reviewed'), 'success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2441 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2442 |  |  |                 $work['qualificator_id'] = $qualificator_id.' '.$hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2443 |  |  |                 $work['actions'] = '<div class="work-action">'.$linkToDownload.$action.'</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2444 |  |  |                 $work['correction'] = $correction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2445 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2446 |  |  |                 if (!empty($compilation)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2447 |  |  |                     throw new Exception('compilatio'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2448 |  |  |                     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2449 |  |  |                     $compilationId = $compilation->getCompilatioId($item_id, $course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2450 |  |  |                     if ($compilationId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2451 |  |  |                         $actionCompilatio = "<div id='id_avancement".$item_id."' class='compilation_block'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2452 |  |  |                             ".$loading.' '.get_lang('Connecting with the Compilatio server').'</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2453 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2454 |  |  |                         $workDirectory = api_get_path(SYS_COURSE_PATH).$course_info['directory']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2455 |  |  |                         if (!Compilatio::verifiFileType($dbTitle)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2456 |  |  |                             $actionCompilatio = get_lang('File format not supported'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2457 |  |  |                         } elseif (filesize($workDirectory.'/'.$work['url']) > $compilation->getMaxFileSize()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2458 |  |  |                             $sizeFile = round(filesize($workDirectory.'/'.$work['url']) / 1000000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2459 |  |  |                             $actionCompilatio = get_lang('The file is too big to upload.').': '.format_file_size($sizeFile).'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2460 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2461 |  |  |                             $actionCompilatio = "<div id='id_avancement".$item_id."' class='compilation_block'>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2462 |  |  |                             $actionCompilatio .= Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2463 |  |  |                                 get_lang('Analyse'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2464 |  |  |                                 'javascript:void(0)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2465 |  |  |                                 [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2466 |  |  |                                     'class' => 'getSingleCompilatio btn btn--primary btn-xs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2467 |  |  |                                     'onclick' => "getSingleCompilatio($item_id);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2468 |  |  |                                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2469 |  |  |                             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2470 |  |  |                             $actionCompilatio .= get_lang('with Compilatio'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2471 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2472 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2473 |  |  |                     $work['compilatio'] = $actionCompilatio;*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2474 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2475 |  |  |                 $works[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2476 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2477 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2478 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2479 |  |  |         return $works; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2480 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2481 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2482 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2483 |  |  | function getAllWork( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2484 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2485 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2486 |  |  |     $column, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2487 |  |  |     $direction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2488 |  |  |     $whereCondition = '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2489 |  |  |     $getCount = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2490 |  |  |     $courseId = 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2491 |  |  |     $status = 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2492 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2493 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2494 |  |  |     $user_table = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2495 |  |  |     $userId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2496 |  |  |     if (empty($userId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2497 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2498 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2499 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2500 |  |  |     $courses = CourseManager::get_courses_list_by_user_id($userId, false, false, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2501 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2502 |  |  |     if (!empty($whereCondition)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2503 |  |  |         $whereCondition = ' AND '.$whereCondition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2504 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2505 |  |  |     $whereCondition = Database::escape_string($whereCondition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2506 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2507 |  |  |     if (!in_array($direction, ['asc', 'desc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2508 |  |  |         $direction = 'desc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2509 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2510 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2511 |  |  |     $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2512 |  |  |     $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2513 |  |  |     $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2514 |  |  |     $courseQuery = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2515 |  |  |     $courseList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2516 |  |  |     $withResults = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2517 |  |  |     foreach ($courses as $course) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2518 |  |  |         $courseIdItem = $course['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2519 |  |  |         if (!empty($courseId) && $courseIdItem != $courseId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2520 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2521 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2522 |  |  |         $courseInfo = api_get_course_info_by_id($courseIdItem); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2523 |  |  |         $session_id = isset($course['session_id']) ? $course['session_id'] : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2524 |  |  |         //$conditionSession = api_get_session_condition($session_id, true, false, 'w.session_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2525 |  |  |         $conditionSession = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2526 |  |  |         $parentCondition = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2527 |  |  |         if ($withResults) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2528 |  |  |             $parentCondition = 'AND ww.parent_id is NOT NULL'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2529 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2530 |  |  |         $courseQuery[] = " (work.c_id = $courseIdItem $conditionSession $parentCondition )"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2531 |  |  |         $courseList[$courseIdItem] = $courseInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2532 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2533 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2534 |  |  |     $courseQueryToString = implode(' OR ', $courseQuery); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2535 |  |  |     $compilation = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2536 |  |  |     /*if (api_get_configuration_value('allow_compilatio_tool')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2537 |  |  |         $compilation = new Compilatio(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2538 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2539 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2540 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2541 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2542 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2543 |  |  |         if (empty($courseQuery)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2544 |  |  |             return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2545 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2546 |  |  |         $select = 'SELECT DISTINCT count(u.id) as count '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2547 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2548 |  |  |         $select = 'SELECT DISTINCT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2549 |  |  |                     u.id as user_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2550 |  |  |                     work.id as id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2551 |  |  |                     title as title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2552 |  |  |                     description, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2553 |  |  |                     url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2554 |  |  |                     sent_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2555 |  |  |                     contains_file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2556 |  |  |                     has_properties, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2557 |  |  |                     view_properties, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2558 |  |  |                     qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2559 |  |  |                     weight, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2560 |  |  |                     allow_text_assignment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2561 |  |  |                     u.firstname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2562 |  |  |                     u.lastname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2563 |  |  |                     u.username, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2564 |  |  |                     parent_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2565 |  |  |                     accepted, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2566 |  |  |                     qualificator_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2567 |  |  |                     url_correction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2568 |  |  |                     title_correction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2569 |  |  |                     work.c_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2570 |  |  |                     work.session_id '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2571 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2572 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2573 |  |  |     $statusCondition = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2574 |  |  |     if (!empty($status)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2575 |  |  |         switch ($status) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2576 |  |  |             case 2: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2577 |  |  |                 $statusCondition = ' AND (qualificator_id IS NULL OR qualificator_id = 0) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2578 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2579 |  |  |             case 3: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2580 |  |  |                 $statusCondition = ' AND (qualificator_id <> 0 AND qualificator_id IS NOT NULL) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2581 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2582 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2583 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2584 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2585 |  |  |     $sql = " $select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2586 |  |  |             FROM $work_table work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2587 |  |  |             INNER JOIN $user_table u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2588 |  |  |             ON (work.user_id = u.id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2589 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2590 |  |  |                 work.parent_id <> 0 AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2591 |  |  |                 work.active IN (1, 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2592 |  |  |                 $whereCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2593 |  |  |                 ($courseQueryToString) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2594 |  |  |                 $statusCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2595 |  |  |                 AND u.status != ".INVITEE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2596 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2597 |  |  |     $sql .= " ORDER BY `$column` $direction "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2598 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2599 |  |  |     if (!empty($start) && !empty($limit)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2600 |  |  |         $sql .= " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2601 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2602 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2603 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2604 |  |  |     $works = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2605 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2606 |  |  |         $work = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2607 |  |  |         if ($work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2608 |  |  |             return (int) $work['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2609 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2610 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2611 |  |  |         return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2612 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2613 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2614 |  |  |     $url = api_get_path(WEB_CODE_PATH).'work/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2615 |  |  |     $unoconv = api_get_setting('platform.unoconv_binaries'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2616 |  |  |     $loadingText = addslashes(get_lang('Loading')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2617 |  |  |     $uploadedText = addslashes(get_lang('Uploaded.')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2618 |  |  |     $failsUploadText = addslashes(get_lang('No file was uploaded.')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2619 |  |  |     $failsUploadIcon = Display::getMdiIcon( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2620 |  |  |         StateIcon::INCOMPLETE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2621 |  |  |         'ch-tool-icon', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2622 |  |  |         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2623 |  |  |         ICON_SIZE_TINY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2624 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2625 |  |  |     $saveIcon = Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Save')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2626 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2627 |  |  |     $correctionIcon = Display::getMdiIcon(ActionIcon::ACCEPT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Correction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2628 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2629 |  |  |     $correctionIconSmall = Display::getMdiIcon(ActionIcon::ACCEPT, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Correction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2630 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2631 |  |  |     $rateIcon = Display::getMdiIcon(ActionIcon::GRADE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Correct and rate')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2632 |  |  |     $parentList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2633 |  |  |     $blockEdition = ('true' === api_get_setting('work.block_student_publication_edition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2634 |  |  |     $blockScoreEdition = ('true' === api_get_setting('work.block_student_publication_score_edition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2635 |  |  |     $loading = Display::getMdiIcon('loading', 'animate-spin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2636 |  |  |     $qualification_exists = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2637 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2638 |  |  |     while ($work = Database::fetch_assoc($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2639 |  |  |         $courseId = $work['c_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2640 |  |  |         $courseInfo = $courseList[$work['c_id']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2641 |  |  |         $sessionId = $work['session_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2642 |  |  |         $cidReq = 'cidReq='.$courseInfo['code'].'&id_session='.$sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2643 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2644 |  |  |         $item_id = $workId = $work['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2645 |  |  |         $dbTitle = $work['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2646 |  |  |         // Get the author ID for that document from the item_property table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2647 |  |  |         $is_author = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2648 |  |  |         $can_read = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2649 |  |  |         $owner_id = $work['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2650 |  |  |         //$visibility = api_get_item_visibility($courseInfo, 'work', $work['id'], $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2651 |  |  |         $studentPublication = $repo->find($work['iid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2652 |  |  |         $workId = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2653 |  |  |         $isVisible = $studentPublication->isVisible(api_get_course_entity(), api_get_session_entity()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2654 |  |  |         if (false === $isVisible) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2655 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2656 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2657 |  |  |         /*$locked = api_resource_is_locked_by_gradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2658 |  |  |             $item_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2659 |  |  |             LINK_STUDENTPUBLICATION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2660 |  |  |             $courseInfo['code'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2661 |  |  |         );*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2662 |  |  |         $locked = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2663 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2664 |  |  |         /* Because a bug found when saving items using the api_item_property_update() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2665 |  |  |            the field $item_property_data['insert_user_id'] is not reliable. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2666 |  |  |         if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2667 |  |  |             $is_author = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2668 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2669 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2670 |  |  |         /*if ($course_info['show_score'] == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2671 |  |  |             $can_read = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2672 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2673 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2674 |  |  |         $qualification_string = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2675 |  |  |         if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2676 |  |  |             if ('' == $work['qualification']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2677 |  |  |                 $qualification_string = Display::label('-'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2678 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2679 |  |  |                 $qualification_string = formatWorkScore($work['qualification'], $work['qualification']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2680 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2681 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2682 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2683 |  |  |         $work_assignment = get_work_assignment_by_id($workId, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2684 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2685 |  |  |         $work['qualification_score'] = $work['qualification']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2686 |  |  |         $add_string = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2687 |  |  |         $time_expires = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2688 |  |  |         if (!empty($work_assignment['expires_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2689 |  |  |             $time_expires = api_strtotime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2690 |  |  |                 $work_assignment['expires_on'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2691 |  |  |                 'UTC' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2692 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2693 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2694 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2695 |  |  |         if (!empty($work_assignment['expires_on']) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2696 |  |  |             !empty($time_expires) && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2697 |  |  |             $add_string = Display::label(get_lang('Expired'), 'important').' - '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2698 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2699 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2700 |  |  |         if (($can_read && '1' == $work['accepted']) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2701 |  |  |             ($is_author && in_array($work['accepted'], ['1', '0'])) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2702 |  |  |             ($is_allowed_to_edit || api_is_drh()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2703 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2704 |  |  |             // Firstname, lastname, username | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2705 |  |  |             $work['fullname'] = Display::div( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2706 |  |  |                 api_get_person_name($work['firstname'], $work['lastname']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2707 |  |  |                 ['class' => 'work-name'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2708 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2709 |  |  |             // Title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2710 |  |  |             $work['title_clean'] = $work['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2711 |  |  |             $work['title'] = Security::remove_XSS($work['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2712 |  |  |             if (strlen($work['title']) > 30) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2713 |  |  |                 $short_title = substr($work['title'], 0, 27).'...'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2714 |  |  |                 $work['title'] = Display::span($short_title, ['class' => 'work-title', 'title' => $work['title']]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2715 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2716 |  |  |                 $work['title'] = Display::div($work['title'], ['class' => 'work-title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2717 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2718 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2719 |  |  |             // Type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2720 |  |  |             $work['type'] = DocumentManager::build_document_icon_tag('file', $work['url']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2721 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2722 |  |  |             // File name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2723 |  |  |             $linkToDownload = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2724 |  |  |             // If URL is present then there's a file to download keep BC. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2725 |  |  |             if ($work['contains_file'] || !empty($work['url'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2726 |  |  |                 $linkToDownload = '<a href="'.$url.'download.php?id='.$item_id.'&'.$cidReq.'">'.$saveIcon.'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2727 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2728 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2729 |  |  |             $feedback = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2730 |  |  |             $count = getWorkCommentCount($item_id, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2731 |  |  |             if (!is_null($count) && !empty($count)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2732 |  |  |                 if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2733 |  |  |                     $feedback .= ' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2734 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2735 |  |  |                 $feedback .= Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2736 |  |  |                     $count.' '.Display::getMdiIcon('comment-multiple-outline', 'ch-tool-icon', null, ICON_SIZE_SMALL), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2737 |  |  |                     $url.'view.php?'.$cidReq.'&id='.$item_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2738 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2739 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2740 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2741 |  |  |             $correction = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2742 |  |  |             $hasCorrection = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2743 |  |  |             if (!empty($work['url_correction'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2744 |  |  |                 $hasCorrection = Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2745 |  |  |                     $correctionIcon, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2746 |  |  |                     api_get_path(WEB_CODE_PATH).'work/download.php?id='.$item_id.'&'.$cidReq.'&correction=1' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2747 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2748 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2749 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2750 |  |  |             if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2751 |  |  |                 $work['qualification'] = $qualification_string.$feedback; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2752 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2753 |  |  |                 $work['qualification'] = $qualification_string.$feedback.$hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2754 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2755 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2756 |  |  |             $work['qualification_only'] = $qualification_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2757 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2758 |  |  |             // Date. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2759 |  |  |             $work_date = api_get_local_time($work['sent_date']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2760 |  |  |             $date = date_to_str_ago($work['sent_date']).' '.$work_date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2761 |  |  |             $work['formatted_date'] = $work_date.' '.$add_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2762 |  |  |             $work['expiry_note'] = $add_string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2763 |  |  |             $work['sent_date_from_db'] = $work['sent_date']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2764 |  |  |             $work['sent_date'] = '<div class="work-date" title="'.$date.'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2765 |  |  |                 $add_string.' '.Display::dateToStringAgoAndLongDate($work['sent_date']).'</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2766 |  |  |             $work['status'] = $hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2767 |  |  |             $work['has_correction'] = $hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2768 |  |  |             $work['course'] = $courseInfo['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2769 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2770 |  |  |             if (isset($parentList[$work['parent_id']])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2771 |  |  |                 $parent = $parentList[$work['parent_id']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2772 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2773 |  |  |                 $parent = get_work_data_by_id($work['parent_id'], $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2774 |  |  |                 $parentList[$work['parent_id']] = $parent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2775 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2776 |  |  |             $work['work_name'] = $parent['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2777 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2778 |  |  |             // Actions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2779 |  |  |             $action = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2780 |  |  |             if (api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2781 |  |  |                 if ($blockScoreEdition && !api_is_platform_admin() && !empty($work['qualification_score'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2782 |  |  |                     $rateLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2783 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2784 |  |  |                     $rateLink = '<a href="'.$url.'view.php?'.$cidReq.'&id='.$item_id.'" title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2785 |  |  |                         $rateIcon.'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2786 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2787 |  |  |                 $action .= $rateLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2788 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2789 |  |  |                 if ($unoconv && empty($work['contains_file'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2790 |  |  |                     $action .= '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2791 |  |  |                         href="'.$url.'work_list_all.php?'.$cidReq.'&id='.$workId.'&action=export_to_doc&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2792 |  |  |                         title="'.get_lang('Export to .doc').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2793 |  |  |                         Display::getMdiIcon(ActionIcon::EXPORT_DOC, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Export to .doc')).'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2794 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2795 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2796 |  |  |                 $alreadyUploaded = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2797 |  |  |                 if (!empty($work['url_correction'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2798 |  |  |                     $alreadyUploaded = '<br />'.$work['title_correction'].' '.$correctionIconSmall; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2799 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2800 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2801 |  |  |                 $correction = ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2802 |  |  |                     <form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2803 |  |  |                     id="file_upload_'.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2804 |  |  |                     class="work_correction_file_upload file_upload_small fileinput-button" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2805 |  |  |                     action="'.api_get_path(WEB_AJAX_PATH).'work.ajax.php?'.$cidReq.'&a=upload_correction_file&item_id='.$item_id.'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2806 |  |  |                     method="POST" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2807 |  |  |                     enctype="multipart/form-data" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2808 |  |  |                     > | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2809 |  |  |                     <div id="progress_'.$item_id.'" class="text-center button-load"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2810 |  |  |                         '.addslashes(get_lang('Click or drop one file here')).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2811 |  |  |                         '.Display::getMdiIcon(ActionIcon::UPLOAD, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Correction')).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2812 |  |  |                         '.$alreadyUploaded.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2813 |  |  |                     </div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2814 |  |  |                     <input id="file_'.$item_id.'" type="file" name="file" class="" multiple> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2815 |  |  |                     </form> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2816 |  |  |                 '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2817 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2818 |  |  |                 $correction .= "<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2819 |  |  |                 $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2820 |  |  |                     $('.work_correction_file_upload').each(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2821 |  |  |                         $(this).fileupload({ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2822 |  |  |                             dropZone: $(this) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2823 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2824 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2825 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2826 |  |  |                     $('#file_upload_".$item_id."').fileupload({ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2827 |  |  |                         add: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2828 |  |  |                             $('#progress_$item_id').html(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2829 |  |  |                             data.context = $('#progress_$item_id').html('$loadingText <br /> <em class=\"fa fa-spinner fa-pulse fa-fw\"></em>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2830 |  |  |                             data.submit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2831 |  |  |                             $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2832 |  |  |                         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2833 |  |  |                         dragover: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2834 |  |  |                             $(this).addClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2835 |  |  |                         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2836 |  |  |                         done: function (e, data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2837 |  |  |                             if (data._response.result.name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2838 |  |  |                                 $('#progress_$item_id').html('$uploadedText '+data._response.result.result+'<br />'+data._response.result.name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2839 |  |  |                             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2840 |  |  |                                 $('#progress_$item_id').html('$failsUploadText $failsUploadIcon'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2841 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2842 |  |  |                             $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2843 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2844 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2845 |  |  |                     $('#file_upload_".$item_id."').on('dragleave', function (e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2846 |  |  |                         // dragleave callback implementation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2847 |  |  |                         $(this).removeClass('hover'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2848 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2849 |  |  |                 }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2850 |  |  |                 </script>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2851 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2852 |  |  |                 if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2853 |  |  |                     if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2854 |  |  |                         $action .= Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Correct and rate')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2855 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2856 |  |  |                         $action .= Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Comment')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2857 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2858 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2859 |  |  |                     if ($blockEdition && !api_is_platform_admin()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2860 |  |  |                         $editLink = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2861 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2862 |  |  |                         $editIcon = Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2863 |  |  |                         if ($qualification_exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2864 |  |  |                             $editLink = '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2865 |  |  |                                 href="'.$url.'edit.php?'.$cidReq.'&item_id='.$item_id.'&id='.$work['parent_id'].'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2866 |  |  |                                 title="'.get_lang('Edit').'"  >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2867 |  |  |                                 $editIcon. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2868 |  |  |                             '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2869 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2870 |  |  |                             $editLink = '<a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2871 |  |  |                                 href="'.$url.'edit.php?'.$cidReq.'&item_id='.$item_id.'&id='.$work['parent_id'].'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2872 |  |  |                                 title="'.get_lang('Update').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2873 |  |  |                                 $editIcon.'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2874 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2875 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2876 |  |  |                     $action .= $editLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2877 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2878 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2879 |  |  |                 /*if ($work['contains_file']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2880 |  |  |                     if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2881 |  |  |                         $action .= Display::getMdiIcon(ActionIcon::MOVE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Move')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2882 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2883 |  |  |                         $action .= '<a href="'.$url.'work.php?'.$cidReq.'&action=move&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Move').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2884 |  |  |                             Display::getMdiIcon(ActionIcon::MOVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2885 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2886 |  |  |                 }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2887 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2888 |  |  |                 /*if ($work['accepted'] == '1') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2889 |  |  |                     $action .= '<a href="'.$url.'work_list_all.php?'.$cidReq.'&id='.$workId.'&action=make_invisible&item_id='.$item_id.'" title="'.get_lang('Invisible').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2890 |  |  |                         Display::getMdiIcon(ActionIcon::INVISIBLE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Invisible')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2891 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2892 |  |  |                     $action .= '<a href="'.$url.'work_list_all.php?'.$cidReq.'&id='.$workId.'&action=make_visible&item_id='.$item_id.'" title="'.get_lang('Visible').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2893 |  |  |                         Display::getMdiIcon(ActionIcon::VISIBLE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Visible')).'</a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2894 |  |  |                 }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2895 |  |  |                 /*if ($locked) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2896 |  |  |                     $action .= Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Delete')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2897 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2898 |  |  |                     $action .= '<a href="'.$url.'work_list_all.php?'.$cidReq.'&id='.$workId.'&action=delete&item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2899 |  |  |                         Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2900 |  |  |                 }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2901 |  |  |             } elseif ($is_author && (empty($work['qualificator_id']) || 0 == $work['qualificator_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2902 |  |  |                 $action .= '<a href="'.$url.'view.php?'.$cidReq.'&id='.$item_id.'" title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2903 |  |  |                     Display::getMdiIcon(ObjectIcon::DEFAULT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2904 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2905 |  |  |                 if (1 == api_get_course_setting('student_delete_own_publication')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2906 |  |  |                     if (api_is_allowed_to_session_edit(false, true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2907 |  |  |                         $action .= '<a href="'.$url.'edit.php?'.$cidReq.'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Update').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2908 |  |  |                             Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Comment')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2909 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2910 |  |  |                     $action .= ' <a href="'.$url.'work_list.php?'.$cidReq.'&action=delete&item_id='.$item_id.'&id='.$work['parent_id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2911 |  |  |                         Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2912 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2913 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2914 |  |  |                 $action .= '<a href="'.$url.'view.php?'.$cidReq.'&id='.$item_id.'" title="'.get_lang('View').'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2915 |  |  |                     Display::getMdiIcon(ObjectIcon::DEFAULT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View')).'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2916 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2917 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2918 |  |  |             // Status. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2919 |  |  |             if (empty($work['qualificator_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2920 |  |  |                 $qualificator_id = Display::label(get_lang('Not reviewed'), 'warning'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2921 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2922 |  |  |                 $qualificator_id = Display::label(get_lang('Reviewed'), 'success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2923 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2924 |  |  |             $work['qualificator_id'] = $qualificator_id.' '.$hasCorrection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2925 |  |  |             $work['actions'] = '<div class="work-action">'.$linkToDownload.$action.'</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2926 |  |  |             $work['correction'] = $correction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2927 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2928 |  |  |             /*if (!empty($compilation) && $is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2929 |  |  |                 $compilationId = $compilation->getCompilatioId($item_id, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2930 |  |  |                 if ($compilationId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2931 |  |  |                     $actionCompilatio = "<div id='id_avancement".$item_id."' class='compilation_block'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2932 |  |  |                         ".$loading.' '.get_lang('Connecting with the Compilatio server').'</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2933 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2934 |  |  |                     $workDirectory = api_get_path(SYS_COURSE_PATH).$courseInfo['directory']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2935 |  |  |                     if (!Compilatio::verifiFileType($dbTitle)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2936 |  |  |                         $actionCompilatio = get_lang('File format not supported'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2937 |  |  |                     } elseif (filesize($workDirectory.'/'.$work['url']) > $compilation->getMaxFileSize()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2938 |  |  |                         $sizeFile = round(filesize($workDirectory.'/'.$work['url']) / 1000000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2939 |  |  |                         $actionCompilatio = get_lang('The file is too big to upload.').': '.format_file_size($sizeFile).'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2940 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2941 |  |  |                         $actionCompilatio = "<div id='id_avancement".$item_id."' class='compilation_block'>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2942 |  |  |                         $actionCompilatio .= Display::url( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2943 |  |  |                             get_lang('Analyse'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2944 |  |  |                             'javascript:void(0)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2945 |  |  |                             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2946 |  |  |                                 'class' => 'getSingleCompilatio btn btn--primary btn-xs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2947 |  |  |                                 'onclick' => "getSingleCompilatio($item_id);", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2948 |  |  |                             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2949 |  |  |                         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2950 |  |  |                         $actionCompilatio .= get_lang('with Compilatio'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2951 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2952 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2953 |  |  |                 $work['compilatio'] = $actionCompilatio; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2954 |  |  |             }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2955 |  |  |             $works[] = $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2956 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2957 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2958 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2959 |  |  |     return $works; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2960 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2961 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2962 |  |  |  * Send reminder to users who have not given the task. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2963 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2964 |  |  |  * @param int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2965 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2966 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2967 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2968 |  |  |  * @author cvargas [email protected] cfasanando, [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2969 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2970 |  |  | function send_reminder_users_without_publication($task_data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2971 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2972 |  |  |     $_course = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2973 |  |  |     $task_id = $task_data['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2974 |  |  |     $task_title = !empty($task_data['title']) ? $task_data['title'] : basename($task_data['url']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2975 |  |  |     $subject = '['.api_get_setting('siteName').'] '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2976 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2977 |  |  |     // The body can be as long as you wish, and any combination of text and variables | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2978 |  |  |     $content = get_lang('Please remember you still have to send an assignment')."\n".get_lang('Course name').' : '.$_course['name']."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2979 |  |  |     $content .= get_lang('Assignment name').' : '.$task_title."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2980 |  |  |     $list_users = get_list_users_without_publication($task_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2981 |  |  |     $mails_sent_to = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2982 |  |  |     foreach ($list_users as $user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2983 |  |  |         $name_user = api_get_person_name($user[1], $user[0], null, PERSON_NAME_EMAIL_ADDRESS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2984 |  |  |         $dear_line = get_lang('Dear').' '.api_get_person_name($user[1], $user[0]).", \n\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2985 |  |  |         $body = $dear_line.$content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2986 |  |  |         MessageManager::send_message($user[3], $subject, $body); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2987 |  |  |         $mails_sent_to[] = $name_user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2988 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2989 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2990 |  |  |     return $mails_sent_to; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2991 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2992 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2993 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2994 |  |  |  * @param int $workId    The work ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2995 |  |  |  * @param int $courseId  The course ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2996 |  |  |  * @param int $sessionId Optional. The session ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2997 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2998 |  |  | function sendEmailToDrhOnHomeworkCreation($workId, $courseId, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2999 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3000 |  |  |     $courseInfo = api_get_course_info_by_id($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3001 |  |  |     $assignment = get_work_assignment_by_id($workId, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3002 |  |  |     $work = get_work_data_by_id($workId, $courseId, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3003 |  |  |     $workInfo = array_merge($assignment, $work); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3004 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3005 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3006 |  |  |         $students = CourseManager::get_student_list_from_course_code($courseInfo['code']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3007 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3008 |  |  |         $students = CourseManager::get_student_list_from_course_code($courseInfo['code'], true, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3009 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3010 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3011 |  |  |     $bodyView = new Template(null, false, false, false, false, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3012 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3013 |  |  |     foreach ($students as $student) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3014 |  |  |         $studentInfo = api_get_user_info($student['user_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3015 |  |  |         if (empty($studentInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3016 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3017 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3018 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3019 |  |  |         $hrms = UserManager::getDrhListFromUser($student['id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3020 |  |  |         foreach ($hrms as $hrm) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3021 |  |  |             $hrmName = api_get_person_name($hrm['firstname'], $hrm['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3022 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3023 |  |  |             $bodyView->assign('hrm_name', $hrmName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3024 |  |  |             $bodyView->assign('student', $studentInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3025 |  |  |             $bodyView->assign('course', $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3026 |  |  |             $bodyView->assign('course_link', api_get_course_url($courseInfo['real_id'], $sessionId)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3027 |  |  |             $bodyView->assign('work', $workInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3028 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3029 |  |  |             $bodyTemplate = $bodyView->get_template('mail/new_work_alert_hrm.tpl'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3030 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3031 |  |  |             MessageManager::send_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3032 |  |  |                 $hrm['id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3033 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3034 |  |  |                     get_lang('%s got a new assignment in course %s'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3035 |  |  |                     $student['firstname'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3036 |  |  |                     $courseInfo['title'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3037 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3038 |  |  |                 $bodyView->fetch($bodyTemplate) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3039 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3040 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3041 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3042 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3043 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3044 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3045 |  |  |  * Sends an email to the students of a course when a homework is created. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3046 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3047 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3048 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3049 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3050 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3051 |  |  |  * @author Guillaume Viguier <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3052 |  |  |  * @author Julio Montoya <[email protected]> Adding session support - 2011 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3053 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3054 |  |  | function sendEmailToStudentsOnHomeworkCreation($workId, $courseId, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3055 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3056 |  |  |     $courseInfo = api_get_course_info_by_id($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3057 |  |  |     $courseCode = $courseInfo['code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3058 |  |  |     // Get the students of the course | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3059 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3060 |  |  |         $students = CourseManager::get_student_list_from_course_code($courseCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3061 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3062 |  |  |         $students = CourseManager::get_student_list_from_course_code($courseCode, true, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3063 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3064 |  |  |     $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('An assignment was created'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3065 |  |  |     $currentUser = api_get_user_info(api_get_user_id()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3066 |  |  |     if (!empty($students)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3067 |  |  |         foreach ($students as $student) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3068 |  |  |             $user_info = api_get_user_info($student['user_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3069 |  |  |             if (!empty($user_info)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3070 |  |  |                 $link = api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3071 |  |  |                 $emailbody = get_lang('Dear').' '.$user_info['complete_name'].",\n\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3072 |  |  |                 $emailbody .= get_lang('An assignment has been added to course').' '.$courseCode.'. '."\n\n". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3073 |  |  |                     '<a href="'.$link.'">'.get_lang('Please check the assignments page.').'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3074 |  |  |                 $emailbody .= "\n\n".$currentUser['complete_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3075 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3076 |  |  |                 MessageManager::send_message_simple( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3077 |  |  |                     $student['user_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3078 |  |  |                     $emailsubject, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3079 |  |  |                     $emailbody | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3080 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3081 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3082 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3083 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3084 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3085 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3086 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3087 |  |  |  * @param string $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3088 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3089 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3090 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3091 |  |  | function is_work_exist_by_url($url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3092 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3093 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3094 |  |  |     $url = Database::escape_string($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3095 |  |  |     $sql = "SELECT id FROM $table WHERE url='$url'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3096 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3097 |  |  |     if (Database::num_rows($result) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3098 |  |  |         $row = Database::fetch_row($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3099 |  |  |         if (empty($row)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3100 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3101 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3102 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3103 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3104 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3105 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3107 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3109 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3110 |  |  |  * Check if a user is the author of a work document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3111 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3112 |  |  |  * @param int $itemId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3113 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3114 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3115 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3116 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3117 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3118 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3119 |  |  | function user_is_author($itemId, $userId = null, $courseId = 0, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3120 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3121 |  |  |     $userId = (int) $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3123 |  |  |     if (empty($itemId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3124 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3127 |  |  |     if (empty($userId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3128 |  |  |         $userId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3129 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3131 |  |  |     $isAuthor = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3132 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3134 |  |  |     if ($is_allowed_to_edit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3135 |  |  |         $isAuthor = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3136 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3137 |  |  |         if (empty($courseId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3138 |  |  |             $courseId = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3139 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3140 |  |  |         if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3141 |  |  |             $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3142 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3144 |  |  |         $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3145 |  |  |         /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3146 |  |  |         $studentPublication = $repo->find($itemId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3147 |  |  |         if ($studentPublication->getResourceNode()->getCreator()->getId() === $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3148 |  |  |             $isAuthor = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3149 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3151 |  |  |         /*$data = api_get_item_property_info($courseId, 'work', $itemId, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3152 |  |  |         if ($data['insert_user_id'] == $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3153 |  |  |             $isAuthor = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3154 |  |  |         }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3156 |  |  |         $workData = get_work_data_by_id($itemId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3157 |  |  |         if ($workData['user_id'] == $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3158 |  |  |             $isAuthor = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3160 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3162 |  |  |     if (!$isAuthor) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3163 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3166 |  |  |     return $isAuthor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3167 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3169 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3170 |  |  |  * Get list of users who have not given the task. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3171 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3172 |  |  |  * @param int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3173 |  |  |  * @param int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3174 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3175 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3176 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3177 |  |  |  * @author cvargas | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3178 |  |  |  * @author Julio Montoya <[email protected]> Fixing query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3179 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3180 |  |  | function get_list_users_without_publication($task_id, $studentId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3181 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3182 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3183 |  |  |     $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3184 |  |  |     $table_user = Database::get_main_table(TABLE_MAIN_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3185 |  |  |     $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3187 |  |  |     $users = getAllUserToWork($task_id, api_get_course_int_id()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3188 |  |  |     $users = array_column($users, 'user_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3190 |  |  |     // Condition for the session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3191 |  |  |     $session_id = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3192 |  |  |     $course_id = api_get_course_int_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3193 |  |  |     $task_id = (int) $task_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3194 |  |  |     $sessionCondition = api_get_session_condition($session_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3196 |  |  |     if (0 == $session_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3197 |  |  |         $sql = "SELECT user_id as id FROM $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3198 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3199 |  |  |                     parent_id = '$task_id' AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3200 |  |  |                     active IN (0, 1)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3201 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3202 |  |  |         $sql = "SELECT user_id as id FROM $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3203 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3204 |  |  |                     parent_id = '$task_id' $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3205 |  |  |                     active IN (0, 1)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3206 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3208 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3209 |  |  |     $users_with_tasks = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3210 |  |  |     while ($row = Database::fetch_array($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3211 |  |  |         $users_with_tasks[] = $row['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3214 |  |  |     if (0 == $session_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3215 |  |  |         $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3216 |  |  |                       FROM $table_course_user AS cu, $table_user AS u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3217 |  |  |                       WHERE u.status != 1 and cu.c_id='".$course_id."' AND u.id = cu.user_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3218 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3219 |  |  |         $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3220 |  |  |                       FROM $session_course_rel_user AS cu, $table_user AS u | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3221 |  |  |                       WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3222 |  |  |                         u.status != 1 AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3223 |  |  |                         cu.c_id='".$course_id."' AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3224 |  |  |                         u.id = cu.user_id AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3225 |  |  |                         cu.session_id = '".$session_id."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3226 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3228 |  |  |     if (!empty($studentId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3229 |  |  |         $sql_users .= ' AND u.id = '.(int) $studentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3230 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3231 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3232 |  |  |     $group_id = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3233 |  |  |     $new_group_user_list = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3234 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3235 |  |  |     if ($group_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3236 |  |  |         $group = api_get_group_entity($group_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3237 |  |  |         $group_user_list = GroupManager::get_subscribed_users($group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3238 |  |  |         if (!empty($group_user_list)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3239 |  |  |             foreach ($group_user_list as $group_user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3240 |  |  |                 $new_group_user_list[] = $group_user['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3241 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3242 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3243 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3245 |  |  |     $result_users = Database::query($sql_users); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3246 |  |  |     $users_without_tasks = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3247 |  |  |     while ($rowUsers = Database::fetch_array($result_users)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3248 |  |  |         $userId = $rowUsers['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3249 |  |  |         if (in_array($userId, $users_with_tasks)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3250 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3251 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3253 |  |  |         if ($group_id && !in_array($userId, $new_group_user_list)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3254 |  |  |             continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3255 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3257 |  |  |         if (!empty($users)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3258 |  |  |             if (!in_array($userId, $users)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3259 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3260 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3261 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3263 |  |  |         $row_users = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3264 |  |  |         $row_users[0] = $rowUsers['lastname']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3265 |  |  |         $row_users[1] = $rowUsers['firstname']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3266 |  |  |         $row_users[2] = Display::encrypted_mailto_link($rowUsers['email']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3267 |  |  |         $row_users[3] = $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3268 |  |  |         $users_without_tasks[] = $row_users; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3269 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3271 |  |  |     return $users_without_tasks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3272 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3274 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3275 |  |  |  * Display list of users who have not given the task. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3276 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3277 |  |  |  * @param int task id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3278 |  |  |  * @param int $studentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3279 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3280 |  |  |  * @author cvargas [email protected] cfasanando, [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3281 |  |  |  * @author Julio Montoya <[email protected]> Fixes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3282 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3283 |  |  | function display_list_users_without_publication($task_id, $studentId = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3284 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3285 |  |  |     $origin = api_get_origin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3286 |  |  |     $table_header[] = [get_lang('Last name'), true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3287 |  |  |     $table_header[] = [get_lang('First name'), true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3288 |  |  |     $table_header[] = [get_lang('E-mail'), true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3289 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3290 |  |  |     $data = get_list_users_without_publication($task_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3292 |  |  |     $sorting_options = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3293 |  |  |     $sorting_options['column'] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3294 |  |  |     $paging_options = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3295 |  |  |     $my_params = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3296 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3297 |  |  |     if (isset($_GET['edit_dir'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3298 |  |  |         $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3299 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3300 |  |  |     if (isset($_GET['list'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3301 |  |  |         $my_params['list'] = Security::remove_XSS($_GET['list']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3302 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3303 |  |  |     $my_params['origin'] = $origin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3304 |  |  |     $my_params['id'] = (int) ($_GET['id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3305 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3306 |  |  |     //$column_show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3307 |  |  |     $column_show[] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3308 |  |  |     $column_show[] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3309 |  |  |     $column_show[] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3310 |  |  |     Display::display_sortable_config_table( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3311 |  |  |         'work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3312 |  |  |         $table_header, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3313 |  |  |         $data, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3314 |  |  |         $sorting_options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3315 |  |  |         $paging_options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3316 |  |  |         $my_params, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3317 |  |  |         $column_show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3318 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3319 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3320 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3321 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3322 |  |  |  * @param int $documentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3323 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3324 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3325 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3326 |  |  | function addDocumentToWork($documentId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3327 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3328 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3329 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3330 |  |  |         'document_id' => $documentId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3331 |  |  |         'work_id' => $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3332 |  |  |         'c_id' => $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3333 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3334 |  |  |     Database::insert($table, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3335 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3336 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3337 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3338 |  |  |  * @param int $documentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3339 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3340 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3341 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3342 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3343 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3344 |  |  | function getDocumentToWork($documentId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3345 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3346 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3347 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3348 |  |  |         'document_id = ? and work_id = ? and c_id = ?' => [$documentId, $workId, $courseId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3349 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3350 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3351 |  |  |     return Database::select('*', $table, ['where' => $params]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3352 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3353 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3354 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3355 |  |  |  * @param int $documentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3356 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3357 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3358 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3359 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3360 |  |  |  * @param int $active | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3361 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3362 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3363 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3364 |  |  | function getDocumentToWorkPerUser($documentId, $workId, $courseId, $sessionId, $userId, $active = 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3365 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3366 |  |  |     $workRel = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3367 |  |  |     $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3368 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3369 |  |  |     $documentId = (int) $documentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3370 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3371 |  |  |     $courseId = (int) $courseId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3372 |  |  |     $userId = (int) $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3373 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3374 |  |  |     $active = (int) $active; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3375 |  |  |     $sessionCondition = api_get_session_condition($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3376 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3377 |  |  |     $sql = "SELECT w.* FROM $work w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3378 |  |  |             INNER JOIN $workRel rel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3379 |  |  |             ON (w.parent_id = rel.work_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3380 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3381 |  |  |                 w.document_id = $documentId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3382 |  |  |                 w.parent_id = $workId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3383 |  |  |                 w.c_id = $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3384 |  |  |                 $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3385 |  |  |                 user_id = $userId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3386 |  |  |                 active = $active | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3387 |  |  |             "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3388 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3389 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3390 |  |  |     $workInfo = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3391 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3392 |  |  |         $workInfo = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3393 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3394 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3395 |  |  |     return $workInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3396 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3397 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3398 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3399 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3400 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3401 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3402 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3403 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3404 |  |  | function getAllDocumentToWork($workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3405 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3406 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3407 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3408 |  |  |         'work_id = ?' => [$workId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3409 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3410 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3411 |  |  |     return Database::select('*', $table, ['where' => $params]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3412 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3413 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3414 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3415 |  |  |  * @param int $documentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3416 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3417 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3418 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3419 |  |  | function deleteDocumentToWork($documentId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3420 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3421 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3422 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3423 |  |  |         'document_id = ? and work_id = ? and c_id = ?' => [$documentId, $workId, $courseId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3424 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3425 |  |  |     Database::delete($table, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3426 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3428 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3429 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3430 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3431 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3432 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3433 |  |  | function addUserToWork($userId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3434 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3435 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3436 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3437 |  |  |         'user_id' => $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3438 |  |  |         'work_id' => $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3439 |  |  |         'c_id' => $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3440 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3441 |  |  |     Database::insert($table, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3442 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3443 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3444 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3445 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3446 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3447 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3448 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3449 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3450 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3451 |  |  | function getUserToWork($userId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3452 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3453 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3454 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3455 |  |  |         'user_id = ? and work_id = ? and c_id = ?' => [$userId, $workId, $courseId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3456 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3457 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3458 |  |  |     return Database::select('*', $table, ['where' => $params]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3459 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3460 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3461 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3462 |  |  |  * @param int  $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3463 |  |  |  * @param int  $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3464 |  |  |  * @param bool $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3465 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3466 |  |  |  * @return array|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3467 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3468 |  |  | function getAllUserToWork($workId, $courseId, $getCount = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3469 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3470 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3471 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3472 |  |  |         'work_id = ?' => [$workId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3473 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3474 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3475 |  |  |         $count = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3476 |  |  |         $result = Database::select( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3477 |  |  |             'count(user_id) as count', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3478 |  |  |             $table, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3479 |  |  |             ['where' => $params], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3480 |  |  |             'simple' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3481 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3482 |  |  |         if (!empty($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3483 |  |  |             $count = (int) ($result['count']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3484 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3485 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3486 |  |  |         return $count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3487 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3488 |  |  |         return Database::select('*', $table, ['where' => $params]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3489 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3490 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3491 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3492 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3493 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3494 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3495 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3496 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3497 |  |  | function deleteUserToWork($userId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3498 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3499 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3500 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3501 |  |  |         'user_id = ? and work_id = ? and c_id = ?' => [$userId, $workId, $courseId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3502 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3503 |  |  |     Database::delete($table, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3504 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3506 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3507 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3508 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3509 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3510 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3511 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3512 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3513 |  |  | function userIsSubscribedToWork($userId, $workId, $courseId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3514 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3515 |  |  |     $subscribedUsers = getAllUserToWork($workId, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3517 |  |  |     if (empty($subscribedUsers)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3518 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3519 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3520 |  |  |         $subscribedUsersList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3521 |  |  |         foreach ($subscribedUsers as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3522 |  |  |             $subscribedUsersList[] = $item['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3523 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3524 |  |  |         if (in_array($userId, $subscribedUsersList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3525 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3526 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3527 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3528 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3529 |  |  |     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3530 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3531 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3532 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3533 |  |  |  * Get the list of students that have to submit their work. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3534 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3535 |  |  |  * @param int  $workId    The internal ID of the assignment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3536 |  |  |  * @param int  $courseId  The course ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3537 |  |  |  * @param int  $groupId   The group ID, if any | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3538 |  |  |  * @param int  $sessionId The session ID, if any | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3539 |  |  |  * @param bool $getCount  Whether we want just the amount or the full result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3540 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3541 |  |  |  * @return array|int An integer (if we just asked for the count) or an array of users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3542 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3543 |  |  | function getStudentSubscribedToWork( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3544 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3545 |  |  |     $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3546 |  |  |     $groupId = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3547 |  |  |     $sessionId = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3548 |  |  |     $getCount = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3549 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3550 |  |  |     $usersInWork = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3551 |  |  |     $usersInCourse = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3552 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3553 |  |  |     if (empty($groupId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3554 |  |  |         $courseInfo = api_get_course_info_by_id($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3555 |  |  |         $status = STUDENT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3556 |  |  |         if (!empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3557 |  |  |             $status = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3558 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3559 |  |  |         $usersInCourse = CourseManager::get_user_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3560 |  |  |             $courseInfo['code'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3561 |  |  |             $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3562 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3563 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3564 |  |  |             $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3565 |  |  |             $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3566 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3567 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3568 |  |  |         $usersInCourse = GroupManager::get_users( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3569 |  |  |             $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3570 |  |  |             false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3571 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3572 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3573 |  |  |             $getCount, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3574 |  |  |             $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3575 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3576 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3577 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3578 |  |  |     $usersInWork = getAllUserToWork($workId, $courseId, $getCount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3579 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3580 |  |  |     if (empty($usersInWork)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3581 |  |  |         return $usersInCourse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3582 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3583 |  |  |         return $usersInWork; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3584 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3585 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3586 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3587 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3588 |  |  |  * @param int  $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3589 |  |  |  * @param int  $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3590 |  |  |  * @param int  $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3591 |  |  |  * @param bool $forceAccessForCourseAdmins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3592 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3593 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3594 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3595 |  |  | function allowOnlySubscribedUser($userId, $workId, $courseId, $forceAccessForCourseAdmins = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3596 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3597 |  |  |     if (api_is_platform_admin() || api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3598 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3599 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3600 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3601 |  |  |     if ($forceAccessForCourseAdmins) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3602 |  |  |         if (api_is_course_admin() || api_is_coach()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3603 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3604 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3605 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3606 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3607 |  |  |     return userIsSubscribedToWork($userId, $workId, $courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3608 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3609 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3610 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3611 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3612 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3613 |  |  |  * @param int   $documentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3614 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3615 |  |  |  * @return CDocument | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3616 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3617 |  |  | function getDocumentTemplateFromWork($workId, $courseInfo, $documentId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3618 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3619 |  |  |     $documents = getAllDocumentToWork($workId, $courseInfo['real_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3620 |  |  |     $docRepo = Container::getDocumentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3621 |  |  |     if (!empty($documents)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3622 |  |  |         foreach ($documents as $doc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3623 |  |  |             if ($documentId !== $doc['document_id']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3624 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3625 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3626 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3627 |  |  |             /** @var CDocument $docData */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3628 |  |  |             $docData = $docRepo->find($doc['document_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3629 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3630 |  |  |             return $docData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3631 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3632 |  |  |             /*$fileInfo = pathinfo($docData['path']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3633 |  |  |             if ('html' == $fileInfo['extension']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3634 |  |  |                 if (file_exists($docData['absolute_path']) && is_file($docData['absolute_path'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3635 |  |  |                     $docData['file_content'] = file_get_contents($docData['absolute_path']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3636 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3637 |  |  |                     return $docData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3638 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3639 |  |  |             }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3640 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3641 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3642 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3643 |  |  |     return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3644 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3645 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3646 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3647 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3648 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3649 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3650 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3651 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3652 |  |  | function getAllDocumentsFromWorkToString($workId, $courseInfo) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3653 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3654 |  |  |     $documents = getAllDocumentToWork($workId, $courseInfo['real_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3655 |  |  |     $docRepo = Container::getDocumentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3656 |  |  |     $content = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3657 |  |  |     if (!empty($documents)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3658 |  |  |         $content .= '<ul class="nav nav-list well">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3659 |  |  |         $content .= '<li class="nav-header">'.get_lang('Documents').'</li>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3660 |  |  |         foreach ($documents as $doc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3661 |  |  |             /** @var CDocument $docData */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3662 |  |  |             $docData = $docRepo->find($doc['document_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3663 |  |  |             $url = $docRepo->getResourceFileUrl($docData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3664 |  |  |             if ($docData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3665 |  |  |                 $content .= '<li> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3666 |  |  |                                 <a class="link_to_download" target="_blank" href="'.$url.'">'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3667 |  |  |                                     $docData->getTitle().' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3668 |  |  |                                 </a> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3669 |  |  |                             </li>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3670 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3671 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3672 |  |  |         $content .= '</ul><br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3673 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3674 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3675 |  |  |     return $content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3676 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3677 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3678 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3679 |  |  |  * Returns fck editor toolbar. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3680 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3681 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3682 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3683 |  |  | function getWorkDescriptionToolbar() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3684 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3685 |  |  |     return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3686 |  |  |         'ToolbarStartExpanded' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3687 |  |  |         'ToolbarSet' => 'Work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3688 |  |  |         'Width' => '100%', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3689 |  |  |         'Height' => '400', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3690 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3691 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3692 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3693 |  |  | function getWorkComments(CStudentPublication $work) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3694 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3695 |  |  |     $comments = $work->getComments(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3696 |  |  |     $commentList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3697 |  |  |     if (!empty($comments)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3698 |  |  |         foreach ($comments as $comment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3699 |  |  |             //$userInfo = api_get_user_info($comment['user_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3700 |  |  |             //$comment['picture'] = $userInfo['avatar']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3701 |  |  |             //$comment['complete_name'] = $userInfo['complete_name_with_username']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3702 |  |  |             $commentList[] = getWorkComment($comment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3703 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3704 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3705 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3706 |  |  |     return $commentList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3707 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3708 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3709 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3710 |  |  |  * Get total score from a work list. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3711 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3712 |  |  |  * @param $workList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3713 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3714 |  |  |  * @return int|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3715 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3716 |  |  | function getTotalWorkScore($workList) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3717 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3718 |  |  |     $count = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3719 |  |  |     foreach ($workList as $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3720 |  |  |         $count += $data['qualification_score']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3721 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3722 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3723 |  |  |     return $count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3724 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3725 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3726 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3727 |  |  |  * Get comment count from a work list (docs sent by students). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3728 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3729 |  |  |  * @param array $workList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3730 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3731 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3732 |  |  |  * @return int|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3733 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3734 |  |  | function getTotalWorkComment($workList, $courseInfo = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3735 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3736 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3737 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3738 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3739 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3740 |  |  |     $count = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3741 |  |  |     foreach ($workList as $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3742 |  |  |         $count += getWorkCommentCount($data['id'], $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3743 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3744 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3745 |  |  |     return $count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3746 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3747 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3748 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3749 |  |  |  * Get comment count for a specific work sent by a student. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3750 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3751 |  |  |  * @param int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3752 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3753 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3754 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3755 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3756 |  |  | function getWorkCommentCount($id, $courseInfo = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3757 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3758 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3759 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3760 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3761 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3762 |  |  |     $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3763 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3764 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3765 |  |  |     $sql = "SELECT count(*) as count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3766 |  |  |             FROM $commentTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3767 |  |  |             WHERE work_id = $id AND c_id = ".$courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3768 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3769 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3770 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3771 |  |  |         $comment = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3772 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3773 |  |  |         return $comment['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3774 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3775 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3776 |  |  |     return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3777 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3778 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3779 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3780 |  |  |  * Get comment count for a specific parent. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3781 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3782 |  |  |  * @param int   $parentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3783 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3784 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3785 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3786 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3787 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3788 |  |  | function getWorkCommentCountFromParent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3789 |  |  |     $parentId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3790 |  |  |     $courseInfo = [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3791 |  |  |     $sessionId = 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3792 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3793 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3794 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3795 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3796 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3797 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3798 |  |  |         $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3799 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3800 |  |  |         $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3801 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3802 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3803 |  |  |     $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3804 |  |  |     $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3805 |  |  |     $parentId = (int) $parentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3806 |  |  |     $sessionCondition = api_get_session_condition($sessionId, false, false, 'w.session_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3807 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3808 |  |  |     $sql = "SELECT count(*) as count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3809 |  |  |             FROM $commentTable c | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3810 |  |  |             INNER JOIN $work w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3811 |  |  |             ON c.c_id = w.c_id AND w.iid = c.work_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3812 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3813 |  |  |                 $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3814 |  |  |                 parent_id = $parentId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3815 |  |  |                 w.c_id = ".$courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3816 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3817 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3818 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3819 |  |  |         $comment = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3820 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3821 |  |  |         return $comment['count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3822 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3823 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3824 |  |  |     return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3825 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3826 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3827 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3828 |  |  |  * Get last work information from parent. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3829 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3830 |  |  |  * @param int   $parentId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3831 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3832 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3833 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3834 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3835 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3836 |  |  | function getLastWorkStudentFromParent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3837 |  |  |     $parentId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3838 |  |  |     $courseInfo = [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3839 |  |  |     $sessionId = 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3840 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3841 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3842 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3843 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3844 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3845 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3846 |  |  |         $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3847 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3848 |  |  |         $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3849 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3850 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3851 |  |  |     $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3852 |  |  |     $sessionCondition = api_get_session_condition($sessionId, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3853 |  |  |     $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3854 |  |  |     $parentId = (int) $parentId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3855 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3856 |  |  |     $sql = "SELECT w.* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3857 |  |  |             FROM $commentTable c INNER JOIN $work w | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3858 |  |  |             ON c.c_id = w.c_id AND w.iid = c.work_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3859 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3860 |  |  |                 $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3861 |  |  |                 parent_id = $parentId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3862 |  |  |                 w.c_id = ".$courseInfo['real_id'].' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3863 |  |  |             ORDER BY w.sent_date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3864 |  |  |             LIMIT 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3865 |  |  |             '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3866 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3867 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3868 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3869 |  |  |         return Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3870 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3871 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3872 |  |  |     return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3873 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3874 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3875 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3876 |  |  |  * Get last work information from parent. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3877 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3878 |  |  |  * @param int   $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3879 |  |  |  * @param array $parentInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3880 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3881 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3882 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3883 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3884 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3885 |  |  | function getLastWorkStudentFromParentByUser( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3886 |  |  |     $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3887 |  |  |     $parentInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3888 |  |  |     $courseInfo = [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3889 |  |  |     $sessionId = 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3890 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3891 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3892 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3893 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3894 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3895 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3896 |  |  |         $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3897 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3898 |  |  |         $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3899 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3900 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3901 |  |  |     $userId = (int) $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3902 |  |  |     $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3903 |  |  |     if (empty($parentInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3904 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3905 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3906 |  |  |     $parentId = $parentInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3907 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3908 |  |  |     $sessionCondition = api_get_session_condition($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3909 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3910 |  |  |     $sql = "SELECT * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3911 |  |  |             FROM $work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3912 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3913 |  |  |                 user_id = $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3914 |  |  |                 $sessionCondition AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3915 |  |  |                 parent_id = $parentId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3916 |  |  |                 c_id = ".$courseInfo['real_id'].' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3917 |  |  |             ORDER BY sent_date DESC | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3918 |  |  |             LIMIT 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3919 |  |  |             '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3920 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3921 |  |  |     if (Database::num_rows($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3922 |  |  |         $work = Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3923 |  |  |         $work['qualification_rounded'] = formatWorkScore($work['qualification'], $parentInfo['qualification']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3924 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3925 |  |  |         return $work; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3926 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3927 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3928 |  |  |     return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3929 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3930 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3931 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3932 |  |  |  * @param float $score | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3933 |  |  |  * @param int   $weight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3934 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3935 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3936 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3937 |  |  | function formatWorkScore($score, $weight) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3938 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3939 |  |  |     $label = 'info'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3940 |  |  |     $weight = (int) $weight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3941 |  |  |     $relativeScore = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3942 |  |  |     if (!empty($weight)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3943 |  |  |         $relativeScore = $score / $weight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3944 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3945 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3946 |  |  |     if ($relativeScore < 0.5) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3947 |  |  |         $label = 'important'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3948 |  |  |     } elseif ($relativeScore < 0.75) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3949 |  |  |         $label = 'warning'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3950 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3951 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3952 |  |  |     $scoreBasedInModel = ExerciseLib::convertScoreToModel($relativeScore * 100); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3953 |  |  |     if (empty($scoreBasedInModel)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3954 |  |  |         $finalScore = api_number_format($score, 1).' / '.$weight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3955 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3956 |  |  |         return Display::label( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3957 |  |  |             $finalScore, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3958 |  |  |             $label | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3959 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3960 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3961 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3962 |  |  |     return $scoreBasedInModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3963 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3964 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3965 |  |  | function getWorkComment(CStudentPublicationComment $commentEntity, array $courseInfo = []): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3966 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3967 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3968 |  |  |         $courseInfo = api_get_course_info(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3969 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3970 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3971 |  |  |     if (empty($courseInfo['real_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3972 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3973 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3974 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3975 |  |  |     $repo = Container::getStudentPublicationCommentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3976 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3977 |  |  |     $comment = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3978 |  |  |     if ($commentEntity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3979 |  |  |         $filePath = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3980 |  |  |         $fileUrl = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3981 |  |  |         $deleteUrl = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3982 |  |  |         $fileName = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3983 |  |  |         $id = $commentEntity->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3984 |  |  |         if ($commentEntity->getResourceNode()->hasResourceFile()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3985 |  |  |             $fileUrl = $repo->getResourceFileDownloadUrl($commentEntity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3986 |  |  |             $workId = $commentEntity->getPublication()->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3987 |  |  |             $filePath = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3988 |  |  |             $deleteUrl = api_get_path(WEB_CODE_PATH). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3989 |  |  |                 'work/view.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_attachment&comment_id='.$id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3990 |  |  |             $fileName = $commentEntity->getResourceNode()->getResourceFiles()->first()->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3991 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3992 |  |  |         $comment['comment'] = $commentEntity->getComment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3993 |  |  |         $comment['delete_file_url'] = $deleteUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3994 |  |  |         $comment['file_path'] = $filePath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3995 |  |  |         $comment['file_url'] = $fileUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3996 |  |  |         $comment['file_name_to_show'] = $fileName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3997 |  |  |         $comment['sent_at_with_label'] = Display::dateToStringAgoAndLongDate($commentEntity->getSentAt()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3998 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3999 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4000 |  |  |     return $comment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4001 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4002 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4003 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4004 |  |  |  * @param int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4005 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4006 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4007 |  |  | function deleteCommentFile($id, $courseInfo = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4008 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4009 |  |  |     $repo = Container::getStudentPublicationCommentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4010 |  |  |     $em = Database::getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4011 |  |  |     $criteria = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4012 |  |  |         'iid' => $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4013 |  |  |         'cId' => $courseInfo['real_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4014 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4015 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4016 |  |  |     /** @var CStudentPublicationComment $commentEntity */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4017 |  |  |     $commentEntity = $repo->findOneBy($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4018 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4019 |  |  |     foreach ($commentEntity->getResourceNode()->getResourceFiles() as $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4020 |  |  |         $em->remove($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4021 |  |  |         $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4022 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4023 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4024 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4025 |  |  |     if (isset($workComment['file']) && !empty($workComment['file'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4026 |  |  |         if (file_exists($workComment['file_path'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4027 |  |  |             $result = my_delete($workComment['file_path']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4028 |  |  |             if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4029 |  |  |                 $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4030 |  |  |                 $params = ['file' => '']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4031 |  |  |                 Database::update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4032 |  |  |                     $commentTable, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4033 |  |  |                     $params, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4034 |  |  |                     ['id = ? AND c_id = ? ' => [$workComment['iid'], $workComment['c_id']]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4035 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4036 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4037 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4038 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4039 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4040 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4041 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4042 |  |  |  * Adds a comments to the work document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4043 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4044 |  |  |  * @param array               $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4045 |  |  |  * @param int                 $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4046 |  |  |  * @param array               $parentWork | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4047 |  |  |  * @param CStudentPublication $work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4048 |  |  |  * @param array               $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4049 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4050 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4051 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4052 |  |  | function addWorkComment($courseInfo, $userId, $parentWork, CStudentPublication $studentPublication, $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4053 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4054 |  |  |     $fileData = isset($data['attachment']) ? $data['attachment'] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4055 |  |  |     // If no attachment and no comment then don't save comment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4056 |  |  |     if (empty($fileData['name']) && empty($data['comment'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4057 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4058 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4059 |  |  |     $courseId = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4060 |  |  |     $courseEntity = api_get_course_entity($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4061 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4062 |  |  |     $request = Container::getRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4063 |  |  |     $file = $request->files->get('attachment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4064 |  |  |     if (is_array($file)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4065 |  |  |         $file = $file[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4066 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4067 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4068 |  |  |     $em = Database::getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4069 |  |  |     $comment = (new CStudentPublicationComment()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4070 |  |  |         ->setComment($data['comment']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4071 |  |  |         ->setUser(api_get_user_entity($userId)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4072 |  |  |         ->setPublication($studentPublication) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4073 |  |  |         ->setParent($studentPublication) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4074 |  |  |         ->addCourseLink( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4075 |  |  |             $courseEntity, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4076 |  |  |             api_get_session_entity(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4077 |  |  |             api_get_group_entity() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4078 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4079 |  |  |     ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4080 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4081 |  |  |     $repo = Container::getStudentPublicationCommentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4082 |  |  |     $repo->create($comment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4083 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4084 |  |  |     if ($file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4085 |  |  |         $repo->addFile($comment, $file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4086 |  |  |         $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4087 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4088 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4089 |  |  |     $userIdListToSend = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4090 |  |  |     if (api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4091 |  |  |         if (isset($data['send_email']) && $data['send_email']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4092 |  |  |             // Teacher sends a feedback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4093 |  |  |             $userIdListToSend = [$studentPublication->getUser()->getId()]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4094 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4095 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4096 |  |  |         $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4097 |  |  |         if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4098 |  |  |             $teachers = CourseManager::get_teacher_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4099 |  |  |                 $courseInfo['code'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4100 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4101 |  |  |             if (!empty($teachers)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4102 |  |  |                 $userIdListToSend = array_keys($teachers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4103 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4104 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4105 |  |  |             $teachers = SessionManager::getCoachesByCourseSession( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4106 |  |  |                 $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4107 |  |  |                 $courseInfo['real_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4108 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4110 |  |  |             if (!empty($teachers)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4111 |  |  |                 $userIdListToSend = array_values($teachers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4112 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4115 |  |  |         $sendNotification = api_get_course_setting('email_to_teachers_on_new_work_feedback'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4116 |  |  |         if (1 != $sendNotification) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4117 |  |  |             $userIdListToSend = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4119 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4120 |  |  |     $id = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4121 |  |  |     $title = $studentPublication->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4122 |  |  |     $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4123 |  |  |     $subject = sprintf(get_lang("There's a new feedback in work: %s"), $parentWork['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4124 |  |  |     $content = sprintf(get_lang("There's a new feedback in work: %s <a href='%s'>Click here</a> to see it."), $title, $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4126 |  |  |     if (!empty($data['comment'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4127 |  |  |         $content .= '<br /><b>'.get_lang('Comment').':</b><br />'.$data['comment']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4128 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4130 |  |  |     if (!empty($userIdListToSend)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4131 |  |  |         foreach ($userIdListToSend as $userIdToSend) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4132 |  |  |             MessageManager::send_message_simple( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4133 |  |  |                 $userIdToSend, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4134 |  |  |                 $subject, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4135 |  |  |                 $content | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4136 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4137 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4138 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4140 |  |  |     /*if (!empty($commentId) && !empty($fileData)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4141 |  |  |         $workParent = get_work_data_by_id($work['parent_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4142 |  |  |         if (!empty($workParent)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4143 |  |  |             //$newFileName = 'comment_'.$commentId.'_'.php2phps(api_replace_dangerous_char($fileData['name'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4144 |  |  |             //$newFilePath = $uploadDir.'/'.$newFileName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4145 |  |  |             $result = move_uploaded_file($fileData['tmp_name'], $newFilePath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4146 |  |  |             if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4147 |  |  |                 $params = ['file' => $newFileName]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4148 |  |  |                 Database::update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4149 |  |  |                     $commentTable, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4150 |  |  |                     $params, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4151 |  |  |                     ['id = ? AND c_id = ? ' => [$commentId, $work['c_id']]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4152 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4153 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4154 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4155 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4156 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4158 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4159 |  |  |  * @param array $workParent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4160 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4161 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4162 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4163 |  |  | function getWorkCommentForm(CStudentPublication $work, $workParent) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4164 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4165 |  |  |     $id = $work->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4167 |  |  |     $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$id.'&action=send_comment&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4168 |  |  |     $form = new FormValidator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4169 |  |  |         'work_comment', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4170 |  |  |         'post', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4171 |  |  |         $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4172 |  |  |         '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4173 |  |  |         ['enctype' => 'multipart/form-data'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4174 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4176 |  |  |     $qualification = $workParent['qualification']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4178 |  |  |     $isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_to_edit(false, false, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4179 |  |  |     $allowEdition = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4180 |  |  |     if ($isCourseManager) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4181 |  |  |         $allowEdition = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4182 |  |  |         if (!empty($work->getQualification()) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4183 |  |  |             ('true' === api_get_setting('work.block_student_publication_score_edition')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4184 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4185 |  |  |             $allowEdition = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4186 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4187 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4189 |  |  |     if (api_is_platform_admin()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4190 |  |  |         $allowEdition = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4191 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4193 |  |  |     if ($allowEdition) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4194 |  |  |         if (!empty($qualification) && intval($qualification) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4195 |  |  |             $model = ExerciseLib::getCourseScoreModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4196 |  |  |             if (empty($model)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4197 |  |  |                 $form->addFloat( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4198 |  |  |                     'qualification', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4199 |  |  |                     [get_lang('Score'), ' / '.$qualification], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4200 |  |  |                     false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4201 |  |  |                     [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4202 |  |  |                     false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4203 |  |  |                     0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4204 |  |  |                     $qualification | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4205 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4206 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4207 |  |  |                 ExerciseLib::addScoreModelInput( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4208 |  |  |                     $form, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4209 |  |  |                     'qualification', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4210 |  |  |                     $qualification, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4211 |  |  |                     $work->getQualification() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4212 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4213 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4214 |  |  |             $form->addFile('file', get_lang('Correction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4215 |  |  |             $form->setDefaults(['qualification' => $work->getQualification()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4216 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4217 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4219 |  |  |     SkillModel::addSkillsToUserForm( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4220 |  |  |         $form, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4221 |  |  |         ITEM_TYPE_STUDENT_PUBLICATION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4222 |  |  |         $workParent['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4223 |  |  |         $work->getUser()->getId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4224 |  |  |         $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4225 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4226 |  |  |     $form->addHtmlEditor('comment', get_lang('Comment'), false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4227 |  |  |     $form->addFile('attachment', get_lang('Attachment')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4228 |  |  |     $form->addElement('hidden', 'iid', $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4230 |  |  |     if (api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4231 |  |  |         $form->addCheckBox( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4232 |  |  |             'send_email', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4233 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4234 |  |  |             get_lang('Send mail to student') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4235 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4236 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4238 |  |  |     $form->addButtonSend(get_lang('Send'), 'button'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4239 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4240 |  |  |     return $form->returnForm(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4241 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4243 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4244 |  |  |  * @param array $homework result of get_work_assignment_by_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4245 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4246 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4247 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4248 |  |  | function getWorkDateValidationStatus($homework) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4249 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4250 |  |  |     $message = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4251 |  |  |     $has_expired = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4252 |  |  |     $has_ended = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4254 |  |  |     if (!empty($homework)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4255 |  |  |         if (!empty($homework['expires_on']) || !empty($homework['ends_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4256 |  |  |             $time_now = time(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4258 |  |  |             if (!empty($homework['expires_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4259 |  |  |                 $time_expires = api_strtotime($homework['expires_on'], 'UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4260 |  |  |                 $difference = $time_expires - $time_now; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4261 |  |  |                 if ($difference < 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4262 |  |  |                     $has_expired = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4263 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4264 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4265 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4266 |  |  |             if (empty($homework['expires_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4267 |  |  |                 $has_expired = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4268 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4269 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4270 |  |  |             if (!empty($homework['ends_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4271 |  |  |                 $time_ends = api_strtotime($homework['ends_on'], 'UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4272 |  |  |                 $difference2 = $time_ends - $time_now; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4273 |  |  |                 if ($difference2 < 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4274 |  |  |                     $has_ended = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4275 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4276 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4278 |  |  |             $ends_on = api_convert_and_format_date($homework['ends_on']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4279 |  |  |             $expires_on = api_convert_and_format_date($homework['expires_on']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4280 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4282 |  |  |         if ($has_ended) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4283 |  |  |             $message = Display::return_message(get_lang('End date already passed').' '.$ends_on, 'error'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4284 |  |  |         } elseif ($has_expired) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4285 |  |  |             $message = Display::return_message(get_lang('Expiry date already passed').' '.$expires_on, 'warning'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4286 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4287 |  |  |             if ($has_expired) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4288 |  |  |                 $message = Display::return_message(get_lang('Deadline for assignments').' '.$expires_on); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4289 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4290 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4291 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4293 |  |  |     return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4294 |  |  |         'message' => $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4295 |  |  |         'has_ended' => $has_ended, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4296 |  |  |         'has_expired' => $has_expired, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4297 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4298 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4300 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4301 |  |  |  * @param FormValidator $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4302 |  |  |  * @param int           $uploadFormType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4303 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4304 |  |  | function setWorkUploadForm($form, $uploadFormType = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4305 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4306 |  |  |     $form->addHeader(get_lang('Upload a document')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4307 |  |  |     $form->addHidden('contains_file', 0, ['id' => 'contains_file_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4308 |  |  |     $form->addHidden('active', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4309 |  |  |     $form->addHidden('accepted', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4310 |  |  |     $form->addElement('text', 'title', get_lang('Title'), ['id' => 'file_upload']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4311 |  |  |     $form->addElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4312 |  |  |         'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4313 |  |  |         'extension', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4314 |  |  |         get_lang('File extension'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4315 |  |  |         ['id' => 'file_extension', 'readonly' => 'readonly'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4316 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4317 |  |  |     $form->addRule('title', get_lang('Required field'), 'required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4319 |  |  |     switch ($uploadFormType) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4320 |  |  |         case 0: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4321 |  |  |             // File and text. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4322 |  |  |             $form->addElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4323 |  |  |                 'file', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4324 |  |  |                 'file', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4325 |  |  |                 get_lang('Upload a document'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4326 |  |  |                 'size="40" onchange="updateDocumentTitle(this.value)"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4327 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4328 |  |  |             $form->addProgress(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4329 |  |  |             $form->addHtmlEditor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4330 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4331 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4332 |  |  |         case 1: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4333 |  |  |             // Only text. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4334 |  |  |             $form->addHtmlEditor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4335 |  |  |             $form->addRule('description', get_lang('Required field'), 'required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4336 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4337 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4338 |  |  |         case 2: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4339 |  |  |             // Only file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4340 |  |  |             $form->addElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4341 |  |  |                 'file', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4342 |  |  |                 'file', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4343 |  |  |                 get_lang('Upload a document'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4344 |  |  |                 'size="40" onchange="updateDocumentTitle(this.value)"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4345 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4346 |  |  |             $form->addProgress(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4347 |  |  |             $form->addRule('file', get_lang('Required field'), 'required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4348 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4349 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4350 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4351 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4352 |  |  |     $form->addButtonUpload(get_lang('Upload'), 'submitWork'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4353 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4355 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4356 |  |  |  * @param array  $my_folder_data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4357 |  |  |  * @param Course $course | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4358 |  |  |  * @param bool   $isCorrection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4359 |  |  |  * @param array  $workInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4360 |  |  |  * @param array  $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4361 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4362 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4363 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4364 |  |  | function uploadWork($my_folder_data, $course, $isCorrection = false, $workInfo = [], $file = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4365 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4366 |  |  |     if (isset($_FILES['file']) && !empty($_FILES['file'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4367 |  |  |         $file = $_FILES['file']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4368 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4369 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4370 |  |  |     if (empty($file['size'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4371 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4372 |  |  |             'error' => Display:: return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4373 |  |  |                 get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4374 |  |  |                     'There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4375 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4376 |  |  |                 'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4377 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4378 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4379 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4380 |  |  |     //$updir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work/'; //directory path to upload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4381 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4382 |  |  |     // Try to add an extension to the file if it has'nt one | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4383 |  |  |     $filename = add_ext_on_mime(stripslashes($file['name']), $file['type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4384 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4385 |  |  |     // Replace dangerous characters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4386 |  |  |     $filename = api_replace_dangerous_char($filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4387 |  |  |     //$filename = api_replace_dangerous_char($filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4388 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4389 |  |  |     $filename = php2phps($filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4390 |  |  |     $filesize = filesize($file['tmp_name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4391 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4392 |  |  |     if (empty($filesize)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4393 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4394 |  |  |             'error' => Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4395 |  |  |                 get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4396 |  |  |                     'There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4397 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4398 |  |  |                 'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4399 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4400 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4401 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4402 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4403 |  |  |     /*if (!filter_extension($new_file_name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4404 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4405 |  |  |             'error' => Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4406 |  |  |                 get_lang('File upload failed: this file extension or file type is prohibited'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4407 |  |  |                 'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4408 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4409 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4410 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4411 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4412 |  |  |     $repo = Container::getDocumentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4413 |  |  |     $totalSpace = $repo->getTotalSpaceByCourse($course); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4414 |  |  |     $course_max_space = DocumentManager::get_course_quota($course->getCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4415 |  |  |     $total_size = $filesize + $totalSpace; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4416 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4417 |  |  |     if ($total_size > $course_max_space) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4418 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4419 |  |  |             'error' => Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4420 |  |  |                 get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4421 |  |  |                     'The upload has failed. Either you have exceeded your maximum quota, or there is not enough disk space.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4422 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4423 |  |  |                 'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4424 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4425 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4426 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4428 |  |  |     // Compose a unique file name to avoid any conflict | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4429 |  |  |     $new_file_name = api_get_unique_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4430 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4431 |  |  |     if ($isCorrection) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4432 |  |  |         if (!empty($workInfo['url'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4433 |  |  |             $new_file_name = basename($workInfo['url']).'_correction'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4434 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4435 |  |  |             $new_file_name .= '_correction'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4436 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4437 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4438 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4439 |  |  |     //$curdirpath = basename($my_folder_data['url']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4440 |  |  |     // If we come from the group tools the groupid will be saved in $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4441 |  |  |     /*if (is_dir($updir.$curdirpath) || empty($curdirpath)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4442 |  |  |         $result = move_uploaded_file( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4443 |  |  |             $file['tmp_name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4444 |  |  |             $updir.$curdirpath.'/'.$new_file_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4445 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4446 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4447 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4448 |  |  |             'error' => Display :: return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4449 |  |  |                 get_lang('Target folder doesn\'t exist on the server.'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4450 |  |  |                 'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4451 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4452 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4453 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4454 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4455 |  |  |     /*if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4456 |  |  |         //$url = 'work/'.$curdirpath.'/'.$new_file_name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4457 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4458 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4459 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4460 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4461 |  |  |     return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4462 |  |  |         //'url' => $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4463 |  |  |         'filename' => $filename, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4464 |  |  |         'filesize' => $filesize, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4465 |  |  |         'error' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4466 |  |  |         'file' => $file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4467 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4468 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4469 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4470 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4471 |  |  |  * Send an e-mail to users related to this work. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4472 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4473 |  |  |  * @param array $workInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4474 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4475 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4476 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4477 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4478 |  |  | function sendAlertToUsers($workInfo, $workId, $courseInfo, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4479 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4480 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4481 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4482 |  |  |     if (empty($workInfo) || empty($courseInfo) || empty($workId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4483 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4484 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4485 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4486 |  |  |     $courseCode = $courseInfo['code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4487 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4488 |  |  |     $workData = get_work_data_by_id($workId, $courseInfo['real_id'], $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4489 |  |  |     // last value is to check this is not "just" an edit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4490 |  |  |     // YW Tis part serve to send a e-mail to the tutors when a new file is sent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4491 |  |  |     $send = api_get_course_setting('email_alert_manager_on_new_doc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4492 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4493 |  |  |     $userList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4494 |  |  |     if (SEND_EMAIL_EVERYONE == $send || SEND_EMAIL_TEACHERS == $send) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4495 |  |  |         // Lets predefine some variables. Be sure to change the from address! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4496 |  |  |         if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4497 |  |  |             // Teachers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4498 |  |  |             $userList = CourseManager::get_user_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4499 |  |  |                 $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4500 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4501 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4502 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4503 |  |  |                 COURSEMANAGER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4504 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4505 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4506 |  |  |             // Coaches | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4507 |  |  |             $userList = CourseManager::get_user_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4508 |  |  |                 $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4509 |  |  |                 $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4510 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4511 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4512 |  |  |                 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4513 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4514 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4515 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4517 |  |  |     if (SEND_EMAIL_EVERYONE == $send || SEND_EMAIL_STUDENTS == $send) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4518 |  |  |         // Send mail only to sender | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4519 |  |  |         $studentList = [[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4520 |  |  |            'user_id' => api_get_user_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4521 |  |  |         ]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4522 |  |  |         $userList = array_merge($userList, $studentList); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4523 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4524 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4525 |  |  |     if ($send) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4526 |  |  |         $folderUrl = api_get_path(WEB_CODE_PATH). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4527 |  |  |             "work/work_list_all.php?cid=".$courseInfo['real_id']."&sid=".$sessionId."&id=".$workInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4528 |  |  |         $fileUrl = api_get_path(WEB_CODE_PATH). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4529 |  |  |             "work/view.php?cid=".$courseInfo['real_id']."&sid=".$sessionId."&id=".$workData['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4530 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4531 |  |  |         foreach ($userList as $userData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4532 |  |  |             $userId = $userData['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4533 |  |  |             $userInfo = api_get_user_info($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4534 |  |  |             if (empty($userInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4535 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4536 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4537 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4538 |  |  |             $userPostedADocument = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4539 |  |  |                 get_lang('User %s has posted a document in the Assignments tool in the course %s'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4540 |  |  |                 $userInfo['complete_name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4541 |  |  |                 $courseInfo['name'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4542 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4543 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4544 |  |  |             $subject = "[".api_get_setting('siteName')."] ".$userPostedADocument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4545 |  |  |             $message = $userPostedADocument."<br />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4546 |  |  |             $message .= get_lang('Date sent')." : ".api_format_date(api_get_local_time())."<br />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4547 |  |  |             $message .= get_lang('Assignment name')." : ".Display::url($workInfo['title'], $folderUrl)."<br />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4548 |  |  |             $message .= get_lang('Filename')." : ".$workData['title']."<br />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4549 |  |  |             $message .= '<a href="'.$fileUrl.'">'.get_lang('Download link')."</a><br />"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4550 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4551 |  |  |             MessageManager::send_message_simple( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4552 |  |  |                 $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4553 |  |  |                 $subject, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4554 |  |  |                 $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4555 |  |  |                 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4556 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4557 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4558 |  |  |                 false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4559 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4560 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4561 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4562 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4563 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4564 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4565 |  |  |  * Check if the current uploaded work filename already exists in the current assement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4566 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4567 |  |  |  * @param string $filename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4568 |  |  |  * @param int    $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4569 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4570 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4571 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4572 |  |  | function checkExistingWorkFileName($filename, $workId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4573 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4574 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4575 |  |  |     $filename = Database::escape_string($filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4576 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4577 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4578 |  |  |     $sql = "SELECT title FROM $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4579 |  |  |             WHERE parent_id = $workId AND title = '$filename' AND active = 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4580 |  |  |     $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4581 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4582 |  |  |     return Database::fetch_assoc($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4583 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4584 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4585 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4586 |  |  |  * @param array $workInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4587 |  |  |  * @param array $values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4588 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4589 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4590 |  |  |  * @param int   $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4591 |  |  |  * @param int   $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4592 |  |  |  * @param array $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4593 |  |  |  * @param bool  $checkDuplicated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4594 |  |  |  * @param bool  $showFlashMessage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4595 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4596 |  |  |  * @return CStudentPublication|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4597 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4598 |  |  | function processWorkForm( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4599 |  |  |     $workInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4600 |  |  |     $values, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4601 |  |  |     $courseInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4602 |  |  |     $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4603 |  |  |     $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4604 |  |  |     $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4605 |  |  |     $file = [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4606 |  |  |     $checkDuplicated = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4607 |  |  |     $showFlashMessage = true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4608 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4609 |  |  |     $courseId = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4610 |  |  |     $courseEntity = api_get_course_entity($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4611 |  |  |     $groupId = (int) $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4612 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4613 |  |  |     $userId = (int) $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4614 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4615 |  |  |     $extension = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4616 |  |  |     if (isset($values['extension'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4617 |  |  |         $extension = $values['extension']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4618 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4619 |  |  |         $fileInfo = pathinfo($values['title']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4620 |  |  |         if (isset($fileInfo['extension']) && !empty($fileInfo['extension'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4621 |  |  |             $extension = '.'.$fileInfo['extension']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4622 |  |  |             $values['title'] = $fileInfo['filename']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4623 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4624 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4625 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4626 |  |  |     $title = $values['title'].$extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4627 |  |  |     $description = isset($values['description']) ? $values['description'] : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4628 |  |  |     $containsFile = isset($values['contains_file']) && !empty($values['contains_file']) ? (int) $values['contains_file'] : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4629 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4630 |  |  |     $saveWork = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4631 |  |  |     $filename = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4632 |  |  |     $url = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4633 |  |  |     $filesize = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4634 |  |  |     $workData = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4635 |  |  |     $message = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4636 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4637 |  |  |     if ($containsFile) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4638 |  |  |         $saveWork = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4639 |  |  |         if ($checkDuplicated) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4640 |  |  |             if (checkExistingWorkFileName($file['name'], $workInfo['iid'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4641 |  |  |                 $saveWork = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4642 |  |  |                 $result['error'] = get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4643 |  |  |                     'You have already sent this file or another file with the same name. Please make sure you only upload each file once.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4644 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4645 |  |  |                 $workData['error'] = get_lang(' already exists.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4646 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4647 |  |  |                 $result = uploadWork($workInfo, $courseEntity, false, [], $file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4648 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4649 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4650 |  |  |             $result = uploadWork($workInfo, $courseEntity, false, [], $file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4651 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4652 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4653 |  |  |         if (isset($result['error'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4654 |  |  |             $saveWork = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4655 |  |  |             if ($showFlashMessage) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4656 |  |  |                 $message = $result['error']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4657 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4658 |  |  |             if (empty($result['error'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4659 |  |  |                 $saveWork = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4660 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4661 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4662 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4663 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4664 |  |  |     if ($saveWork) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4665 |  |  |         $filename = isset($result['filename']) ? $result['filename'] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4666 |  |  |         if (empty($title)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4667 |  |  |             $title = isset($result['title']) && !empty($result['title']) ? $result['title'] : get_lang('Untitled'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4668 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4669 |  |  |         $filesize = isset($result['filesize']) ? $result['filesize'] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4670 |  |  |         $url = isset($result['url']) ? $result['url'] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4671 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4672 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4673 |  |  |     if (empty($title)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4674 |  |  |         $title = get_lang('Untitled'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4675 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4676 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4677 |  |  |     $studentPublication = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4678 |  |  |     if ($saveWork) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4679 |  |  |         $documentId = isset($values['document_id']) ? (int) $values['document_id'] : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4680 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4681 |  |  |         $request = Container::getRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4682 |  |  |         $content = $request->files->get('file'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4683 |  |  |         if (is_array($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4684 |  |  |             $content = $content[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4685 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4686 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4687 |  |  |         if (empty($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4688 |  |  |             $content = $request->files->get('files'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4689 |  |  |             if (is_array($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4690 |  |  |                 $content = $content[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4691 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4692 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4693 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4694 |  |  |         $session = api_get_session_entity($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4695 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4696 |  |  |         $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4697 |  |  |         $parentResource = $repo->find($workInfo['iid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4698 |  |  |         $user = api_get_user_entity($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4699 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4700 |  |  |         $studentPublication = (new CStudentPublication()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4701 |  |  |             ->setFiletype('file') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4702 |  |  |             ->setTitle($title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4703 |  |  |             ->setDescription($description) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4704 |  |  |             ->setContainsFile($containsFile) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4705 |  |  |             ->setActive(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4706 |  |  |             ->setAccepted(true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4707 |  |  |             ->setQualificatorId(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4708 |  |  |             ->setWeight(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4709 |  |  |             ->setAllowTextAssignment(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4710 |  |  |             ->setPostGroupId(api_get_group_id()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4711 |  |  |             ->setPublicationParent($parentResource) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4712 |  |  |             ->setFilesize($filesize) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4713 |  |  |             ->setUser($user) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4714 |  |  |             ->setDocumentId($documentId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4715 |  |  |             ->setParent($parentResource) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4716 |  |  |             ->addCourseLink($courseEntity, $session, api_get_group_entity()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4717 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4718 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4719 |  |  |         $em = Database::getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4720 |  |  |         $em->persist($studentPublication); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4721 |  |  |         $repo->addFile($studentPublication, $content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4722 |  |  |         $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4723 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4724 |  |  |         $workId = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4725 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4726 |  |  |         if ($workId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4727 |  |  |             sendAlertToUsers($workInfo, $workId, $courseInfo, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4728 |  |  |             Event::event_upload($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4729 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4730 |  |  |             // The following feature requires the creation of a work-type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4731 |  |  |             // extra_field and the following setting in the configuration file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4732 |  |  |             // (until moved to the database). It allows te teacher to set a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4733 |  |  |             // "considered work time", meaning the time we assume a student | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4734 |  |  |             // would have spent, approximately, to prepare the task before | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4735 |  |  |             // handing it in Chamilo, adding this time to the student total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4736 |  |  |             // course use time, as a register of time spent *before* his | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4737 |  |  |             // connection to the platform to hand the work in. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4738 |  |  |             $consideredWorkingTime = api_get_setting('work.considered_working_time'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4739 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4740 |  |  |             if (!empty($consideredWorkingTime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4741 |  |  |                 // Get the "considered work time" defined for this work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4742 |  |  |                 $fieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4743 |  |  |                 $resultExtra = $fieldValue->getAllValuesForAnItem( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4744 |  |  |                     $workInfo['iid'], //the ID of the work *folder*, not the document uploaded by the student | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4745 |  |  |                     true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4746 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4747 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4748 |  |  |                 $workingTime = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4749 |  |  |                 foreach ($resultExtra as $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4750 |  |  |                     $field = $field['value']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4751 |  |  |                     if ($consideredWorkingTime == $field->getField()->getVariable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4752 |  |  |                         $workingTime = $field->getFieldValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4753 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4754 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4755 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4756 |  |  |                 // If no time was defined, or a time of "0" was set, do nothing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4757 |  |  |                 if (!empty($workingTime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4758 |  |  |                     // If some time is set, get the list of docs handed in by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4759 |  |  |                     // this student (to make sure we count the time only once) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4760 |  |  |                     $userWorks = get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4761 |  |  |                         0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4762 |  |  |                         100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4763 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4764 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4765 |  |  |                         $workInfo['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4766 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4767 |  |  |                         $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4768 |  |  |                         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4769 |  |  |                         $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4770 |  |  |                         $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4771 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4772 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4773 |  |  |                     if (1 === count($userWorks)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4774 |  |  |                         // The student only uploaded one doc so far, so add the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4775 |  |  |                         // considered work time to his course connection time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4776 |  |  |                         Event::eventAddVirtualCourseTime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4777 |  |  |                             $courseId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4778 |  |  |                             $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4779 |  |  |                             $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4780 |  |  |                             $workingTime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4781 |  |  |                             $workInfo['iid'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4782 |  |  |                         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4783 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4784 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4785 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4786 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4787 |  |  |             if ($showFlashMessage) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4788 |  |  |                 Display::addFlash(Display::return_message(get_lang('The file has been added to the list of publications.'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4789 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4790 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4791 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4792 |  |  |         if ($showFlashMessage) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4793 |  |  |             Display::addFlash( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4794 |  |  |                 Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4795 |  |  |                     $message ?: get_lang('Impossible to save the document'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4796 |  |  |                     'error' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4797 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4798 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4799 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4800 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4801 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4802 |  |  |     return $studentPublication; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4803 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4804 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4805 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4806 |  |  |  * Creates a new task (directory) in the assignment tool. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4807 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4808 |  |  |  * @param array $formValues | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4809 |  |  |  * @param int   $user_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4810 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4811 |  |  |  * @param int   $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4812 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4813 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4814 |  |  |  * @return bool|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4815 |  |  |  * @note $params can have the following elements, but should at least have the 2 first ones: ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4816 |  |  |  *       'new_dir' => 'some-name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4817 |  |  |  *       'description' => 'some-desc', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4818 |  |  |  *       'qualification' => 20 (e.g. 20), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4819 |  |  |  *       'weight' => 50 (percentage) to add to gradebook (e.g. 50), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4820 |  |  |  *       'allow_text_assignment' => 0/1/2, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4821 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4822 |  |  |  * @todo Rename createAssignment or createWork, or something like that | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4823 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4824 |  |  | function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4825 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4826 |  |  |     $user_id = (int) $user_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4827 |  |  |     $groupId = (int) $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4828 |  |  |     $sessionId = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4829 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4830 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4831 |  |  |     $groupInfo = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4832 |  |  |     if (!empty($groupId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4833 |  |  |         $groupInfo = GroupManager::get_group_properties($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4834 |  |  |         $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4835 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4836 |  |  |     $session = api_get_session_entity($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4837 |  |  |     $course_id = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4838 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4839 |  |  |     $enableEndDate = isset($formValues['enableEndDate']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4840 |  |  |     $enableExpiryDate = isset($formValues['enableExpiryDate']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4841 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4842 |  |  |     if ($enableEndDate && $enableExpiryDate && $formValues['expires_on'] > $formValues['ends_on']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4843 |  |  |         Display::addFlash( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4844 |  |  |             Display::return_message( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4845 |  |  |                 get_lang( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4846 |  |  |                     'The date of effective blocking of sending the work can not be before the displayed posting deadline.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4847 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4848 |  |  |                 'warning' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4849 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4850 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4851 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4852 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4853 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4854 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4855 |  |  |     $today = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4856 |  |  |     $title = $formValues['work_title'] ?? $formValues['new_dir']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4857 |  |  |     $courseEntity = api_get_course_entity($course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4858 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4859 |  |  |     $studentPublication = new CStudentPublication(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4860 |  |  |     $studentPublication | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4861 |  |  |         ->setTitle($title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4862 |  |  |         ->setDescription($formValues['description']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4863 |  |  |         ->setActive(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4864 |  |  |         ->setAccepted(true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4865 |  |  |         ->setFiletype('folder') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4866 |  |  |         ->setPostGroupId($groupIid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4867 |  |  |         ->setSentDate($today) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4868 |  |  |         ->setQualification('' != $formValues['qualification'] ? $formValues['qualification'] : 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4869 |  |  |         ->setWeight(!empty($formValues['weight']) ? $formValues['weight'] : 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4870 |  |  |         ->setAllowTextAssignment(1 === (int) $formValues['allow_text_assignment'] ? 1 : 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4871 |  |  |         ->setUser(api_get_user_entity($user_id)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4872 |  |  |         ->setParent($courseEntity) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4873 |  |  |         ->addCourseLink( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4874 |  |  |             $courseEntity, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4875 |  |  |             $session, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4876 |  |  |             api_get_group_entity() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4877 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4878 |  |  |     ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4879 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4880 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4881 |  |  |     $repo->create($studentPublication); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4882 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4883 |  |  |     // Folder created | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4884 |  |  |     /*api_item_property_update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4885 |  |  |         $courseInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4886 |  |  |         'work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4887 |  |  |         $studentPublication->getIid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4888 |  |  |         'DirectoryCreated', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4889 |  |  |         $user_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4890 |  |  |         $groupInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4891 |  |  |     );*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4892 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4893 |  |  |     updatePublicationAssignment( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4894 |  |  |         $studentPublication->getIid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4895 |  |  |         $formValues, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4896 |  |  |         $courseInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4897 |  |  |         $groupIid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4898 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4899 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4900 |  |  |     // Added the new Work ID to the extra field values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4901 |  |  |     $formValues['item_id'] = $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4902 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4903 |  |  |     $workFieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4904 |  |  |     $workFieldValue->saveFieldValues($formValues); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4905 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4906 |  |  |     $sendEmailAlert = api_get_course_setting('email_alert_students_on_new_homework'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4907 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4908 |  |  |     switch ($sendEmailAlert) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4909 |  |  |         case 1: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4910 |  |  |             sendEmailToStudentsOnHomeworkCreation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4911 |  |  |                 $studentPublication->getIid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4912 |  |  |                 $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4913 |  |  |                 $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4914 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4915 |  |  |             //no break | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4916 |  |  |         case 2: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4917 |  |  |             sendEmailToDrhOnHomeworkCreation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4918 |  |  |                 $studentPublication->getIid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4919 |  |  |                 $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4920 |  |  |                 $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4921 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4922 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4923 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4924 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4925 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4926 |  |  |     return $studentPublication->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4927 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4928 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4929 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4930 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4931 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4932 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4933 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4934 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4935 |  |  | function agendaExistsForWork($workId, $courseInfo) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4936 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4937 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4938 |  |  |     $courseId = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4939 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4940 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4941 |  |  |     $sql = "SELECT add_to_calendar FROM $workTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4942 |  |  |             WHERE c_id = $courseId AND publication_id = ".$workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4943 |  |  |     $res = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4944 |  |  |     if (Database::num_rows($res)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4945 |  |  |         $row = Database::fetch_assoc($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4946 |  |  |         if (!empty($row['add_to_calendar'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4947 |  |  |             return $row['add_to_calendar']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4948 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4949 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4950 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4951 |  |  |     return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4952 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4953 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4954 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4955 |  |  |  * Update work description, qualification, weight, allow_text_assignment. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4956 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4957 |  |  |  * @param int   $workId     (iid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4958 |  |  |  * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4959 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4960 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4961 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4962 |  |  | function updateWork($workId, $params, $courseInfo, $sessionId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4963 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4964 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4965 |  |  |     $filteredParams = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4966 |  |  |         'description' => $params['description'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4967 |  |  |         'qualification' => $params['qualification'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4968 |  |  |         'weight' => (float) $params['weight'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4969 |  |  |         'allow_text_assignment' => $params['allow_text_assignment'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4970 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4971 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4972 |  |  |     Database::update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4973 |  |  |         $workTable, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4974 |  |  |         $filteredParams, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4975 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4976 |  |  |             'iid = ?' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4977 |  |  |                 $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4978 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4979 |  |  |         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4980 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4981 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4982 |  |  |     $workFieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4983 |  |  |     $workFieldValue->saveFieldValues($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4984 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4985 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4986 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4987 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4988 |  |  |  * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4989 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4990 |  |  |  * @param int   $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4991 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4992 |  |  | function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4993 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4994 |  |  |     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4995 |  |  |     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4996 |  |  |     $workId = (int) $workId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4997 |  |  |     $now = api_get_utc_datetime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4998 |  |  |     $course_id = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4999 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5000 |  |  |     // Insert into agenda | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5001 |  |  |     $agendaId = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5002 |  |  |     if (isset($params['add_to_calendar']) && 1 == $params['add_to_calendar']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5003 |  |  |         // Setting today date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5004 |  |  |         $date = $end_date = $now; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5005 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5006 |  |  |         if (isset($params['enableExpiryDate'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5007 |  |  |             $end_date = $params['expires_on']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5008 |  |  |             $date = $end_date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5009 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5010 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5011 |  |  |         $title = sprintf(get_lang('Handing over of task %s'), $params['new_dir']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5012 |  |  |         $description = $params['description'] ?? ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5013 |  |  |         $content = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId.'">' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5014 |  |  |             .$params['new_dir'].'</a>'.$description; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5015 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5016 |  |  |         $agendaId = agendaExistsForWork($workId, $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5017 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5018 |  |  |         // Add/edit agenda | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5019 |  |  |         $agenda = new Agenda('course'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5020 |  |  |         $agenda->set_course($courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5021 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5022 |  |  |         if (!empty($agendaId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5023 |  |  |             // add_to_calendar is set but it doesnt exists then invalidate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5024 |  |  |             $eventInfo = $agenda->get_event($agendaId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5025 |  |  |             if (empty($eventInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5026 |  |  |                 $agendaId = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5027 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5028 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5029 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5030 |  |  |         $eventColor = $agenda->eventStudentPublicationColor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5031 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5032 |  |  |         if (empty($agendaId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5033 |  |  |             $agendaId = $agenda->addEvent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5034 |  |  |                 $date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5035 |  |  |                 $end_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5036 |  |  |                 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5037 |  |  |                 $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5038 |  |  |                 $content, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5039 |  |  |                 ['GROUP:'.$groupId], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5040 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5041 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5042 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5043 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5044 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5045 |  |  |                 $eventColor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5046 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5047 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5048 |  |  |             $agenda->editEvent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5049 |  |  |                 $agendaId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5050 |  |  |                 $end_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5051 |  |  |                 $end_date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5052 |  |  |                 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5053 |  |  |                 $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5054 |  |  |                 $content, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5055 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5056 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5057 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5058 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5059 |  |  |                 $eventColor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5060 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5061 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5062 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5063 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5064 |  |  |     $qualification = !empty($params['qualification']) ? 1 : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5065 |  |  |     $expiryDate = isset($params['enableExpiryDate']) && 1 == (int) $params['enableExpiryDate'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5066 |  |  |         ? api_get_utc_datetime($params['expires_on']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5067 |  |  |         : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5068 |  |  |     $endDate = isset($params['enableEndDate']) && 1 == (int) $params['enableEndDate'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5069 |  |  |         ? api_get_utc_datetime($params['ends_on']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5070 |  |  |         : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5071 |  |  |     $data = get_work_assignment_by_id($workId, $course_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5072 |  |  |     if (!empty($expiryDate)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5073 |  |  |         $expiryDateCondition = "expires_on = '".Database::escape_string($expiryDate)."', "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5074 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5075 |  |  |         $expiryDateCondition = 'expires_on = null, '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5076 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5077 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5078 |  |  |     if (!empty($endDate)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5079 |  |  |         $endOnCondition = "ends_on = '".Database::escape_string($endDate)."', "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5080 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5081 |  |  |         $endOnCondition = 'ends_on = null, '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5082 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5083 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5084 |  |  |     /** @var CStudentPublication $publication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5085 |  |  |     $publication = Container::getStudentPublicationRepository()->find($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5086 |  |  |     $em = Database::getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5087 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5088 |  |  |     if (empty($data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5089 |  |  |         $assignment = new CStudentPublicationAssignment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5090 |  |  |     /*$sql = "INSERT INTO $table SET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5091 |  |  |             c_id = $course_id , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5092 |  |  |             $expiryDateCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5093 |  |  |             $endOnCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5094 |  |  |             add_to_calendar = $agendaId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5095 |  |  |             enable_qualification = '$qualification', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5096 |  |  |             publication_id = '$workId'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5097 |  |  |     Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5098 |  |  |     $my_last_id = Database::insert_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5099 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5100 |  |  |     if ($my_last_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5101 |  |  |         $sql = "UPDATE $workTable SET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5102 |  |  |                     has_properties  = $my_last_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5103 |  |  |                     view_properties = 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5104 |  |  |                 WHERE iid = $workId"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5105 |  |  |         Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5106 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5107 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5108 |  |  |         $assignment = $em->getRepository(CStudentPublicationAssignment::class)->find($data['iid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5109 |  |  |         /*$sql = "UPDATE $table SET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5110 |  |  |                     $expiryDateCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5111 |  |  |                     $endOnCondition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5112 |  |  |                     add_to_calendar  = $agendaId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5113 |  |  |                     enable_qualification = '".$qualification."' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5114 |  |  |                 WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5115 |  |  |                     publication_id = $workId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5116 |  |  |                     iid = ".$data['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5117 |  |  |         Database::query($sql);*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5120 |  |  |     $assignment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5121 |  |  |         ->setEventCalendarId($agendaId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5122 |  |  |         ->setEnableQualification(1 === $qualification) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5123 |  |  |         ->setPublication($publication) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5124 |  |  |     ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5125 |  |  |     if (!empty($expiryDate)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5126 |  |  |         $assignment->setExpiresOn(api_get_utc_datetime($expiryDate, true, true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5129 |  |  |     if (!empty($endDate)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5130 |  |  |         $assignment->setEndsOn(api_get_utc_datetime($endDate, true, true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5132 |  |  |     $em->persist($assignment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5133 |  |  |     $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5135 |  |  |     if (empty($data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5136 |  |  |         $publication | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5137 |  |  |             ->setHasProperties($assignment->getIid()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5138 |  |  |             ->setViewProperties(true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5139 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5142 |  |  |     $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5144 |  |  |     if (!empty($params['category_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5145 |  |  |         $link_info = GradebookUtils::isResourceInCourseGradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5146 |  |  |             $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5147 |  |  |             LINK_STUDENTPUBLICATION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5148 |  |  |             $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5149 |  |  |             api_get_session_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5150 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5152 |  |  |         $linkId = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5153 |  |  |         if (!empty($link_info)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5154 |  |  |             $linkId = $link_info['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5155 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5157 |  |  |         if (isset($params['make_calification']) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5158 |  |  |             1 == $params['make_calification'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5159 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5160 |  |  |             if (empty($linkId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5161 |  |  |                 GradebookUtils::add_resource_to_course_gradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5162 |  |  |                     $params['category_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5163 |  |  |                     $courseInfo['real_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5164 |  |  |                     LINK_STUDENTPUBLICATION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5165 |  |  |                     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5166 |  |  |                     $params['new_dir'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5167 |  |  |                     api_float_val($params['weight']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5168 |  |  |                     api_float_val($params['qualification']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5169 |  |  |                     $params['description'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5170 |  |  |                     1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5171 |  |  |                     api_get_session_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5172 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5173 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5174 |  |  |                 GradebookUtils::updateResourceFromCourseGradebook( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5175 |  |  |                     $linkId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5176 |  |  |                     $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5177 |  |  |                     $params['weight'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5178 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5179 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5180 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5181 |  |  |             // Delete everything of the gradebook for this $linkId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5182 |  |  |             GradebookUtils::remove_resource_from_course_gradebook($linkId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5183 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5184 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5185 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5187 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5188 |  |  |  * Delete all work by student. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5189 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5190 |  |  |  * @return array return deleted items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5191 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5192 |  |  | function deleteAllWorkPerUser(User $user, Course $course) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5193 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5194 |  |  |     $deletedItems = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5195 |  |  |     //$workPerUser = getWorkPerUser($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5196 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5197 |  |  |     $works = $repo->getStudentPublicationByUser($user, $course); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5199 |  |  |     foreach ($works as $workData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5200 |  |  |         /** @var CStudentPublication[] $results */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5201 |  |  |         $results = $workData['results']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5202 |  |  |         foreach ($results as $userResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5203 |  |  |             $result = deleteWorkItem($userResult->getIid(), $course); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5204 |  |  |             if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5205 |  |  |                 $deletedItems[] = $userResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5206 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5208 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5210 |  |  |     return $deletedItems; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5211 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5213 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5214 |  |  |  * @param int    $item_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5215 |  |  |  * @param Course $course  course info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5216 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5217 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5218 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5219 |  |  | function deleteWorkItem($item_id, Course $course) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5220 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5221 |  |  |     $item_id = (int) $item_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5223 |  |  |     if (empty($item_id) || null === $course) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5224 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5225 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5226 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5227 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5228 |  |  |     $is_allowed_to_edit = api_is_allowed_to_edit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5229 |  |  |     $file_deleted = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5230 |  |  |     $is_author = user_is_author($item_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5231 |  |  |     $work_data = get_work_data_by_id($item_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5232 |  |  |     $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5233 |  |  |     $course_id = $course->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5234 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5235 |  |  |     if (($is_allowed_to_edit && false == $locked) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5236 |  |  |         ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5237 |  |  |             false == $locked && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5238 |  |  |             $is_author && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5239 |  |  |             1 == api_get_course_setting('student_delete_own_publication') && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5240 |  |  |             0 == $work_data['qualificator_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5241 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5242 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5243 |  |  |         // We found the current user is the author | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5244 |  |  |         $sql = "SELECT contains_file, user_id, parent_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5245 |  |  |                 FROM $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5246 |  |  |                 WHERE iid = $item_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5247 |  |  |         $result = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5248 |  |  |         $row = Database::fetch_array($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5249 |  |  |         $count = Database::num_rows($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5251 |  |  |         if ($count > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5252 |  |  |             // If the "considered_working_time" option is enabled, check | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5253 |  |  |             // whether some time should be removed from track_e_course_access | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5254 |  |  |             $consideredWorkingTime = api_get_setting('work.considered_working_time'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5255 |  |  |             if ($consideredWorkingTime) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5256 |  |  |                 $userWorks = get_work_user_list( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5257 |  |  |                     0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5258 |  |  |                     100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5259 |  |  |                     null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5260 |  |  |                     null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5261 |  |  |                     $row['parent_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5262 |  |  |                     null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5263 |  |  |                     $row['user_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5264 |  |  |                     false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5265 |  |  |                     $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5266 |  |  |                     $row['session_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5267 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5268 |  |  |                 // We're only interested in deleting the time if this is the latest work sent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5269 |  |  |                 if (1 == count($userWorks)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5270 |  |  |                     // Get the "considered work time" defined for this work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5271 |  |  |                     $fieldValue = new ExtraFieldValue('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5272 |  |  |                     $resultExtra = $fieldValue->getAllValuesForAnItem( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5273 |  |  |                         $row['parent_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5274 |  |  |                         true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5275 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5276 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5277 |  |  |                     $workingTime = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5278 |  |  |                     foreach ($resultExtra as $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5279 |  |  |                         $field = $field['value']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5280 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5281 |  |  |                         if ($consideredWorkingTime == $field->getField()->getVariable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5282 |  |  |                             $workingTime = $field->getFieldValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5283 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5284 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5285 |  |  |                     // If no time was defined, or a time of "0" was set, do nothing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5286 |  |  |                     if (!empty($workingTime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5287 |  |  |                         $sessionId = empty($row['session_id']) ? 0 : $row['session_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5288 |  |  |                         // Getting false from the following call would mean the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5289 |  |  |                         // time record | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5290 |  |  |                         Event::eventRemoveVirtualCourseTime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5291 |  |  |                             $course_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5292 |  |  |                             $row['user_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5293 |  |  |                             $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5294 |  |  |                             $workingTime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5295 |  |  |                             $row['parent_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5296 |  |  |                         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5297 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5298 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5299 |  |  |             } // end of considered_working_time check section | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5300 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5301 |  |  |             $em = Database::getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5302 |  |  |             $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5303 |  |  |             /** @var CStudentPublication $work */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5304 |  |  |             $work = $repo->find($item_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5305 |  |  |             $work->setActive(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5306 |  |  |             $repo->update($work); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5307 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5308 |  |  |             /*$repo = Container::getStudentPublicationAssignmentRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5309 |  |  |             $params = ['cId' => $course_id, 'publicationId' => $item_id]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5311 |  |  |             $items = $repo->findBy($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5312 |  |  |             foreach ($items as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5313 |  |  |                 $repo->delete($item); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5314 |  |  |             }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5316 |  |  |             $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5317 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5318 |  |  |             /*$sql = "DELETE FROM $TSTDPUBASG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5319 |  |  |                     WHERE c_id = $course_id AND publication_id = $item_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5320 |  |  |             Database::query($sql);*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5322 |  |  |             Compilatio::plagiarismDeleteDoc($course_id, $item_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5323 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5324 |  |  |             /*api_item_property_update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5325 |  |  |                 $courseInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5326 |  |  |                 'work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5327 |  |  |                 $item_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5328 |  |  |                 'DocumentDeleted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5329 |  |  |                 api_get_user_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5330 |  |  |             );*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5331 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5332 |  |  |             Event::addEvent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5333 |  |  |                 LOG_WORK_FILE_DELETE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5334 |  |  |                 LOG_WORK_DATA, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5335 |  |  |                 [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5336 |  |  |                     'id' => $work_data['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5337 |  |  |                     'url' => $work_data['url'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5338 |  |  |                     'title' => $work_data['title'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5339 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5340 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5341 |  |  |                 api_get_user_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5342 |  |  |                 api_get_course_int_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5343 |  |  |                 api_get_session_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5344 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5345 |  |  |             $file_deleted = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5346 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5347 |  |  |             if (1 == $row['contains_file']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5348 |  |  |                 /*if (!empty($work)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5349 |  |  |                     if (api_get_setting('permanently_remove_deleted_files') === 'true') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5350 |  |  |                         my_delete($currentCourseRepositorySys.'/'.$work); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5351 |  |  |                         $file_deleted = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5352 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5353 |  |  |                         $extension = pathinfo($work, PATHINFO_EXTENSION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5354 |  |  |                         $new_dir = $work.'_DELETED_'.$item_id.'.'.$extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5356 |  |  |                         if (file_exists($currentCourseRepositorySys.'/'.$work)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5357 |  |  |                             rename($currentCourseRepositorySys.'/'.$work, $currentCourseRepositorySys.'/'.$new_dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5358 |  |  |                             $file_deleted = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5359 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5360 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5361 |  |  |                 }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5362 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5363 |  |  |                 $file_deleted = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5364 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5365 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5366 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5367 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5368 |  |  |     return $file_deleted; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5369 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5371 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5372 |  |  |  * @param FormValidator $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5373 |  |  |  * @param array         $defaults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5374 |  |  |  * @param int           $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5375 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5376 |  |  |  * @return FormValidator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5377 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5378 |  |  | function getFormWork($form, $defaults = [], $workId = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5379 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5380 |  |  |     $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5381 |  |  |     if (!empty($defaults)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5382 |  |  |         if (isset($defaults['submit'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5383 |  |  |             unset($defaults['submit']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5384 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5385 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5386 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5387 |  |  |     // Create the form that asks for the directory name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5388 |  |  |     $form->addText('new_dir', get_lang('Assignment name')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5389 |  |  |     $form->addHtmlEditor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5390 |  |  |         'description', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5391 |  |  |         get_lang('Description'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5392 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5393 |  |  |         false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5394 |  |  |         getWorkDescriptionToolbar() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5395 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5396 |  |  |     $form->addButtonAdvancedSettings('advanced_params', get_lang('Advanced settings')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5397 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5398 |  |  |     if (!empty($defaults) && (isset($defaults['enableEndDate']) || isset($defaults['enableExpiryDate']))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5399 |  |  |         $form->addHtml('<div id="advanced_params_options" style="display:block">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5400 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5401 |  |  |         $form->addHtml('<div id="advanced_params_options" style="display:none">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5402 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5403 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5404 |  |  |     // ScoreOfAssignment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5405 |  |  |     $form->addText('qualification', get_lang('Score'), false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5406 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5407 |  |  |     if (0 != $sessionId && Gradebook::is_active() || 0 == $sessionId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5408 |  |  |         $form->addElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5409 |  |  |             'checkbox', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5410 |  |  |             'make_calification', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5411 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5412 |  |  |             get_lang('Add to gradebook'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5413 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5414 |  |  |                 'id' => 'make_calification_id', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5415 |  |  |                 'onclick' => "javascript: if(this.checked) { document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5416 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5417 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5418 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5419 |  |  |         // QualificationOfAssignment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5420 |  |  |         $form->addHidden('make_calification', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5421 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5422 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5423 |  |  |     if (!empty($defaults) && isset($defaults['category_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5424 |  |  |         $form->addHtml('<div id=\'option1\' style="display:block">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5425 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5426 |  |  |         $form->addHtml('<div id=\'option1\' style="display:none">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5427 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5428 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5429 |  |  |     // Loading Gradebook select | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5430 |  |  |     GradebookUtils::load_gradebook_select_in_tool($form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5431 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5432 |  |  |     $form->addElement('text', 'weight', get_lang('Weight inside assessment')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5433 |  |  |     $form->addHtml('</div>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5434 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5435 |  |  |     $form->addCheckBox( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5436 |  |  |         'enableExpiryDate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5437 |  |  |         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5438 |  |  |         get_lang('Enable handing over deadline (visible to learners)'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5439 |  |  |         ['id' => 'expiry_date'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5440 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5441 |  |  |     if (isset($defaults['enableExpiryDate']) && $defaults['enableExpiryDate']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5442 |  |  |         $form->addHtml('<div id="option2" style="display: block;">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5443 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5444 |  |  |         $form->addHtml('<div id="option2" style="display: none;">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5445 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5446 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5447 |  |  |     $timeNextWeek = time() + 86400 * 7; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5448 |  |  |     $nextWeek = substr(api_get_local_time($timeNextWeek), 0, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5449 |  |  |     if (!isset($defaults['expires_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5450 |  |  |         $date = substr($nextWeek, 0, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5451 |  |  |         $defaults['expires_on'] = $date.' 23:59'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5452 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5453 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5454 |  |  |     $form->addElement('date_time_picker', 'expires_on', get_lang('Posted sending deadline')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5455 |  |  |     $form->addHtml('</div>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5456 |  |  |     $form->addCheckBox( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5457 |  |  |         'enableEndDate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5458 |  |  |         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5459 |  |  |         get_lang('Enable final acceptance date (invisible to learners)'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5460 |  |  |         ['id' => 'end_date'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5461 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5462 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5463 |  |  |     if (!isset($defaults['ends_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5464 |  |  |         $nextDay = substr(api_get_local_time($timeNextWeek + 86400), 0, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5465 |  |  |         $date = substr($nextDay, 0, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5466 |  |  |         $defaults['ends_on'] = $date.' 23:59'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5467 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5468 |  |  |     if (isset($defaults['enableEndDate']) && $defaults['enableEndDate']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5469 |  |  |         $form->addHtml('<div id="option3" style="display: block;">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5470 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5471 |  |  |         $form->addHtml('<div id="option3" style="display: none;">'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5472 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5473 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5474 |  |  |     $form->addElement('date_time_picker', 'ends_on', get_lang('Ends at (completely closed)')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5475 |  |  |     $form->addHtml('</div>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5476 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5477 |  |  |     $form->addCheckBox('add_to_calendar', null, get_lang('Add to calendar')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5478 |  |  |     $form->addSelect('allow_text_assignment', get_lang('Document type'), getUploadDocumentType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5479 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5480 |  |  |     // Extra fields | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5481 |  |  |     $extraField = new ExtraField('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5482 |  |  |     $extra = $extraField->addElements($form, $workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5483 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5484 |  |  |     $htmlHeadXtra[] = ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5485 |  |  |         <script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5486 |  |  |         $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5487 |  |  |             '.$extra['jquery_ready_content'].' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5488 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5489 |  |  |         </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5490 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5491 |  |  |     $form->addHtml('</div>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5492 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5493 |  |  |     $skillList = SkillModel::addSkillsToForm($form, ITEM_TYPE_STUDENT_PUBLICATION, $workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5494 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5495 |  |  |     if (!empty($defaults)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5496 |  |  |         $defaults['skills'] = array_keys($skillList); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5497 |  |  |         $form->setDefaults($defaults); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5498 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5499 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5500 |  |  |     return $form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5501 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5502 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5503 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5504 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5505 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5506 |  |  | function getUploadDocumentType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5507 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5508 |  |  |     return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5509 |  |  |         0 => get_lang('Allow files or online text'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5510 |  |  |         1 => get_lang('Allow only text'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5511 |  |  |         2 => get_lang('Allow only files'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5512 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5513 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5514 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5515 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5516 |  |  |  * @param int   $itemId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5517 |  |  |  * @param array $course_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5518 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5519 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5520 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5521 |  |  | function makeVisible($itemId, $course_info) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5522 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5523 |  |  |     $itemId = (int) $itemId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5524 |  |  |     if (empty($course_info) || empty($itemId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5525 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5526 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5527 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5528 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5529 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5530 |  |  |     $studentPublication = $repo->find($itemId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5531 |  |  |     if ($studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5532 |  |  |         $studentPublication->setAccepted(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5533 |  |  |         $repo->update($studentPublication); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5534 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5535 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5536 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5537 |  |  |     $course_id = $course_info['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5538 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5539 |  |  |     $sql = "UPDATE $work_table SET accepted = 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5540 |  |  |             WHERE c_id = $course_id AND id = $itemId"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5541 |  |  |     Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5542 |  |  |     api_item_property_update($course_info, 'work', $itemId, 'visible', api_get_user_id()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5543 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5544 |  |  |     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5545 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5546 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5547 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5548 |  |  |  * @param int   $itemId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5549 |  |  |  * @param array $course_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5550 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5551 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5552 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5553 |  |  | function makeInvisible($itemId, $course_info) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5554 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5555 |  |  |     $itemId = (int) $itemId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5556 |  |  |     if (empty($course_info) || empty($itemId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5557 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5558 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5559 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5560 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5561 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5562 |  |  |     $studentPublication = $repo->find($itemId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5563 |  |  |     if ($studentPublication) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5564 |  |  |         $studentPublication->setAccepted(0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5565 |  |  |         $repo->update($studentPublication); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5566 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5567 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5568 |  |  |     /*api_item_property_update( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5569 |  |  |         $course_info, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5570 |  |  |         'work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5571 |  |  |         $itemId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5572 |  |  |         'invisible', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5573 |  |  |         api_get_user_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5574 |  |  |     );*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5575 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5576 |  |  |     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5577 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5578 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5579 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5580 |  |  |  * @param int    $item_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5581 |  |  |  * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5582 |  |  |  * @param array  $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5583 |  |  |  * @param int    $groupId    iid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5584 |  |  |  * @param int    $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5585 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5586 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5587 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5588 |  |  | function generateMoveForm($item_id, $path, $courseInfo, $groupId, $sessionId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5589 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5590 |  |  |     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5591 |  |  |     $courseId = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5592 |  |  |     $folders = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5593 |  |  |     $session_id = (int) $sessionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5594 |  |  |     $groupId = (int) $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5595 |  |  |     $sessionCondition = empty($sessionId) ? ' AND (session_id = 0 OR session_id IS NULL) ' : " AND session_id='".$session_id."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5596 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5597 |  |  |     $groupIid = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5598 |  |  |     if ($groupId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5599 |  |  |         $groupInfo = GroupManager::get_group_properties($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5600 |  |  |         $groupIid = $groupInfo['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5601 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5602 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5603 |  |  |     $sql = "SELECT iid, url, title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5604 |  |  |             FROM $work_table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5605 |  |  |             WHERE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5606 |  |  |                 c_id = $courseId AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5607 |  |  |                 active IN (0, 1) AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5608 |  |  |                 parent_id = 0 AND | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5609 |  |  |                 post_group_id = $groupIid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5610 |  |  |                 $sessionCondition"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5611 |  |  |     $res = Database::query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5612 |  |  |     while ($folder = Database::fetch_array($res)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5613 |  |  |         $title = empty($folder['title']) ? basename($folder['url']) : $folder['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5614 |  |  |         $folders[$folder['iid']] = $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5615 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5616 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5617 |  |  |     return build_work_move_to_selector($folders, $path, $item_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5618 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5619 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5620 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5621 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5622 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5623 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5624 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5625 |  |  | function showStudentList($workId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5626 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5627 |  |  |     $columnModel = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5628 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5629 |  |  |             'name' => 'student', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5630 |  |  |             'index' => 'student', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5631 |  |  |             'width' => '350px', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5632 |  |  |             'align' => 'left', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5633 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5634 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5635 |  |  |         [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5636 |  |  |             'name' => 'works', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5637 |  |  |             'index' => 'works', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5638 |  |  |             'align' => 'center', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5639 |  |  |             'sortable' => 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5640 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5641 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5642 |  |  |     $token = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5643 |  |  |     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_student_list_overview&work_id='.$workId.'&'.api_get_cidreq(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5644 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5645 |  |  |     $columns = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5646 |  |  |         get_lang('Learners'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5647 |  |  |         get_lang('Assignments'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5648 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5649 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5650 |  |  |     $order = api_is_western_name_order() ? 'firstname' : 'lastname'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5651 |  |  |     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5652 |  |  |         'autowidth' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5653 |  |  |         'height' => 'auto', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5654 |  |  |         'rowNum' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5655 |  |  |         'sortname' => $order, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5656 |  |  |         'sortorder' => 'asc', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5657 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5658 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5659 |  |  |     $html = '<script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5660 |  |  |     $(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5661 |  |  |         '.Display::grid_js('studentList', $url, $columns, $columnModel, $params, [], null, true).' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5662 |  |  |         $("#workList").jqGrid( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5663 |  |  |             "navGrid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5664 |  |  |             "#studentList_pager", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5665 |  |  |             { edit: false, add: false, del: false }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5666 |  |  |             { height:280, reloadAfterSubmit:false }, // edit options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5667 |  |  |             { height:280, reloadAfterSubmit:false }, // add options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5668 |  |  |             { width:500 } // search options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5669 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5670 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5671 |  |  |     </script>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5672 |  |  |     $html .= Display::grid_html('studentList'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5673 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5674 |  |  |     return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5675 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5676 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5677 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5678 |  |  |  * @param string $courseCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5679 |  |  |  * @param int    $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5680 |  |  |  * @param int    $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5681 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5682 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5683 |  |  |  * @param string $sidx | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5684 |  |  |  * @param string $sord | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5685 |  |  |  * @param $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5686 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5687 |  |  |  * @return array|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5688 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5689 |  |  | function getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sidx, $sord, $getCount = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5690 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5691 |  |  |     if (!empty($groupId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5692 |  |  |         $userList = GroupManager::get_users( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5693 |  |  |             $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5694 |  |  |             false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5695 |  |  |             $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5696 |  |  |             $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5697 |  |  |             $getCount, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5698 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5699 |  |  |             $sidx, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5700 |  |  |             $sord | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5701 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5702 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5703 |  |  |         $limitString = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5704 |  |  |         if (!empty($start) && !empty($limit)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5705 |  |  |             $start = (int) $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5706 |  |  |             $limit = (int) $limit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5707 |  |  |             $limitString = " LIMIT $start, $limit"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5708 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5709 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5710 |  |  |         $orderBy = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5711 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5712 |  |  |         if (!empty($sidx) && !empty($sord)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5713 |  |  |             if (in_array($sidx, ['firstname', 'lastname'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5714 |  |  |                 $orderBy = "ORDER BY `$sidx` $sord"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5715 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5716 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5717 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5718 |  |  |         if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5719 |  |  |             $userList = CourseManager::get_user_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5720 |  |  |                 $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5721 |  |  |                 $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5722 |  |  |                 $limitString, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5723 |  |  |                 $orderBy, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5724 |  |  |                 STUDENT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5725 |  |  |                 $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5726 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5727 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5728 |  |  |             $userList = CourseManager::get_user_list_from_course_code( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5729 |  |  |                 $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5730 |  |  |                 $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5731 |  |  |                 $limitString, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5732 |  |  |                 $orderBy, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5733 |  |  |                 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5734 |  |  |                 $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5735 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5736 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5737 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5738 |  |  |         if (false == $getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5739 |  |  |             $userList = array_keys($userList); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5740 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5741 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5742 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5743 |  |  |     return $userList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5744 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5745 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5746 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5747 |  |  |  * @param int    $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5748 |  |  |  * @param string $courseCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5749 |  |  |  * @param int    $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5750 |  |  |  * @param int    $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5751 |  |  |  * @param int    $start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5752 |  |  |  * @param int    $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5753 |  |  |  * @param int    $sidx | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5754 |  |  |  * @param string $sord | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5755 |  |  |  * @param bool   $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5756 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5757 |  |  |  * @return array|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5758 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5759 |  |  | function getWorkUserListData( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5760 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5761 |  |  |     $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5762 |  |  |     $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5763 |  |  |     $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5764 |  |  |     $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5765 |  |  |     $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5766 |  |  |     $sidx, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5767 |  |  |     $sord, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5768 |  |  |     $getCount = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5769 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5770 |  |  |     $my_folder_data = get_work_data_by_id($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5771 |  |  |     $workParents = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5772 |  |  |     if (empty($my_folder_data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5773 |  |  |         $workParents = getWorkList($workId, $my_folder_data, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5774 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5775 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5776 |  |  |     $workIdList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5777 |  |  |     if (!empty($workParents)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5778 |  |  |         foreach ($workParents as $work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5779 |  |  |             $workIdList[] = $work->getIid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5780 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5781 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5782 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5783 |  |  |     $courseInfo = api_get_course_info($courseCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5784 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5785 |  |  |     $userList = getWorkUserList( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5786 |  |  |         $courseCode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5787 |  |  |         $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5788 |  |  |         $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5789 |  |  |         $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5790 |  |  |         $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5791 |  |  |         $sidx, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5792 |  |  |         $sord, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5793 |  |  |         $getCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5794 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5795 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5796 |  |  |     if ($getCount) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5797 |  |  |         return $userList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5798 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5799 |  |  |     $results = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5800 |  |  |     if (!empty($userList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5801 |  |  |         foreach ($userList as $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5802 |  |  |             $user = api_get_user_info($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5803 |  |  |             $link = api_get_path(WEB_CODE_PATH).'work/student_work.php?'.api_get_cidreq().'&studentId='.$user['user_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5804 |  |  |             $url = Display::url(api_get_person_name($user['firstname'], $user['lastname']), $link); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5805 |  |  |             $userWorks = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5806 |  |  |             if (!empty($workIdList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5807 |  |  |                 $userWorks = getUniqueStudentAttempts( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5808 |  |  |                     $workIdList, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5809 |  |  |                     $groupId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5810 |  |  |                     $courseInfo['real_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5811 |  |  |                     $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5812 |  |  |                     $user['user_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5813 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5814 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5815 |  |  |             $works = $userWorks.' / '.count($workParents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5816 |  |  |             $results[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5817 |  |  |                 'student' => $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5818 |  |  |                 'works' => Display::url($works, $link), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5819 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5820 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5821 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5822 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5823 |  |  |     return $results; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5824 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5825 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5826 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5827 |  |  |  * @param int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5828 |  |  |  * @param array $course_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5829 |  |  |  * @param bool  $isCorrection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5830 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5831 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5832 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5833 |  |  | function downloadFile($id, $course_info, $isCorrection) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5834 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5835 |  |  |     return getFile( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5836 |  |  |         $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5837 |  |  |         $course_info, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5838 |  |  |         true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5839 |  |  |         $isCorrection, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5840 |  |  |         api_is_course_admin() || api_is_coach() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5841 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5842 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5843 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5844 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5845 |  |  |  * @param int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5846 |  |  |  * @param array $course_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5847 |  |  |  * @param bool  $download | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5848 |  |  |  * @param bool  $isCorrection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5849 |  |  |  * @param bool  $forceAccessForCourseAdmins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5850 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5851 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5852 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5853 |  |  | function getFile($id, $course_info, $download = true, $isCorrection = false, $forceAccessForCourseAdmins = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5854 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5855 |  |  |     $file = getFileContents($id, $course_info, 0, $isCorrection, $forceAccessForCourseAdmins); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5856 |  |  |     var_dump($file); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5857 |  |  |     exit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5858 |  |  |     if (!empty($file) && isset($file['entity'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5859 |  |  |         /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5860 |  |  |         $studentPublication = $file['entity']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5861 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5862 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5863 |  |  |     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5864 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5865 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5866 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5867 |  |  |  * Get the file contents for an assigment. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5868 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5869 |  |  |  * @param int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5870 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5871 |  |  |  * @param int   $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5872 |  |  |  * @param bool  $correction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5873 |  |  |  * @param bool  $forceAccessForCourseAdmins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5874 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5875 |  |  |  * @return array|bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5876 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5877 |  |  | function getFileContents($id, $courseInfo, $sessionId = 0, $correction = false, $forceAccessForCourseAdmins = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5878 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5879 |  |  |     $id = (int) $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5880 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5881 |  |  |     if (empty($courseInfo) || empty($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5882 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5883 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5884 |  |  |     if (empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5885 |  |  |         $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5886 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5887 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5888 |  |  |     $courseEntity = api_get_course_entity($courseInfo['real_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5889 |  |  |     $sessionEntity = api_get_session_entity($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5890 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5891 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5892 |  |  |     /** @var CStudentPublication $studentPublication */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5893 |  |  |     $studentPublication = $repo->find($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5894 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5895 |  |  |     if (empty($studentPublication)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5896 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5897 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5898 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5899 |  |  |     if ($correction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5900 |  |  |         //$row['url'] = $row['url_correction']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5901 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5902 |  |  |     $hasFile = $studentPublication->getResourceNode()->hasResourceFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5903 |  |  |     if (!$hasFile) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5904 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5905 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5906 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5907 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5908 |  |  |     $item_info = api_get_item_property_info( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5909 |  |  |         api_get_course_int_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5910 |  |  |         'work', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5911 |  |  |         $row['iid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5912 |  |  |         $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5913 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5914 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5915 |  |  |     if (empty($item_info)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5916 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5917 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5918 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5919 |  |  |     $isAllow = allowOnlySubscribedUser( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5920 |  |  |         api_get_user_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5921 |  |  |         $studentPublication->getPublicationParent()->getIid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5922 |  |  |         $courseInfo['real_id'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5923 |  |  |         $forceAccessForCourseAdmins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5924 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5925 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5926 |  |  |     if (!$isAllow) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5927 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5928 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5929 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5930 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5931 |  |  |     field show_score in table course : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5932 |  |  |         0 =>    New documents are visible for all users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5933 |  |  |         1 =>    New documents are only visible for the teacher(s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5934 |  |  |     field visibility in table item_property : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5935 |  |  |         0 => eye closed, invisible for all students | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5936 |  |  |         1 => eye open | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5937 |  |  |     field accepted in table c_student_publication : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5938 |  |  |         0 => eye closed, invisible for all students | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5939 |  |  |         1 => eye open | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5940 |  |  |     ( We should have visibility == accepted, otherwise there is an | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5941 |  |  |     inconsistency in the Database) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5942 |  |  |     field value in table c_course_setting : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5943 |  |  |         0 => Allow learners to delete their own publications = NO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5944 |  |  |         1 => Allow learners to delete their own publications = YES | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5945 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5946 |  |  |     +------------------+-------------------------+------------------------+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5947 |  |  |     |Can download work?| doc visible for all = 0 | doc visible for all = 1| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5948 |  |  |     +------------------+-------------------------+------------------------+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5949 |  |  |     |  visibility = 0  | editor only             | editor only            | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5950 |  |  |     |                  |                         |                        | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5951 |  |  |     +------------------+-------------------------+------------------------+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5952 |  |  |     |  visibility = 1  | editor                  | editor                 | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5953 |  |  |     |                  | + owner of the work     | + any student          | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5954 |  |  |     +------------------+-------------------------+------------------------+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5955 |  |  |     (editor = teacher + admin + anybody with right api_is_allowed_to_edit) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5956 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5957 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5958 |  |  |     $work_is_visible = $studentPublication->isVisible($courseEntity, $sessionEntity) && $studentPublication->getAccepted(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5959 |  |  |     $doc_visible_for_all = 0 === (int) $courseInfo['show_score']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5960 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5961 |  |  |     $is_editor = api_is_allowed_to_edit(true, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5962 |  |  |     $student_is_owner_of_work = user_is_author($studentPublication->getIid(), api_get_user_id()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5963 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5964 |  |  |     if ($is_editor || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5965 |  |  |         $student_is_owner_of_work || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5966 |  |  |         ($forceAccessForCourseAdmins && $isAllow) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5967 |  |  |         ($doc_visible_for_all && $work_is_visible) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5968 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5969 |  |  |         $title = $studentPublication->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5970 |  |  |         $titleCorrection = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5971 |  |  |         if ($correction && $studentPublication->getCorrection()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5972 |  |  |             $title = $titleCorrection = $studentPublication->getCorrection()->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5973 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5974 |  |  |         if ($hasFile) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5975 |  |  |             $title = $studentPublication->getResourceNode()->getResourceFiles()->first()->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5976 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5977 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5978 |  |  |         $title = str_replace(' ', '_', $title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5979 |  |  |         if (false == $correction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5980 |  |  |             $userInfo = $studentPublication->getUser(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5981 |  |  |             if ($userInfo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5982 |  |  |                 $date = api_get_local_time($studentPublication->getSentDate()->format('Y-m-d H:i:s')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5983 |  |  |                 $date = str_replace([':', '-', ' '], '_', $date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5984 |  |  |                 $title = $date.'_'.$studentPublication->getUser()->getUsername().'_'.$title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5985 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5986 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5987 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5988 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5989 |  |  |             //'path' => $full_file_name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5990 |  |  |             'title' => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5991 |  |  |             'title_correction' => $titleCorrection, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5992 |  |  |             'entity' => $studentPublication, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5993 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5994 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5995 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5996 |  |  |     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5997 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5998 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5999 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6000 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6001 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6002 |  |  | function exportAllWork(User $user, Course $course, $format = 'pdf') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6003 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6004 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6005 |  |  |     $works = $repo->getStudentPublicationByUser($user, $course, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6006 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6007 |  |  |     switch ($format) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6008 |  |  |         case 'pdf': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6009 |  |  |             if (!empty($works)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6010 |  |  |                 $pdf = new PDF(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6011 |  |  |                 $content = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6012 |  |  |                 foreach ($works as $workData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6013 |  |  |                     /** @var CStudentPublication $work */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6014 |  |  |                     $work = $workData['work']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6015 |  |  |                     /** @var CStudentPublication[] $results */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6016 |  |  |                     $results = $workData['results']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6017 |  |  |                     foreach ($results as $userResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6018 |  |  |                         $content .= $userResult->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6019 |  |  |                         // No need to use api_get_local_time() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6020 |  |  |                         $content .= $userResult->getSentDate()->format('Y-m-d H:i:s'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6021 |  |  |                         $content .= $userResult->getQualification(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6022 |  |  |                         $content .= $userResult->getDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6023 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6024 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6025 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6026 |  |  |                 if (!empty($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6027 |  |  |                     $pdf->content_to_pdf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6028 |  |  |                         $content, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6029 |  |  |                         null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6030 |  |  |                         api_replace_dangerous_char(UserManager::formatUserFullName($user)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6031 |  |  |                         $course->getCode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6032 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6033 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6034 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6035 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6036 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6037 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6038 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6039 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6040 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6041 |  |  |  * @param int    $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6042 |  |  |  * @param array  $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6043 |  |  |  * @param int    $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6044 |  |  |  * @param string $format | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6045 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6046 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6047 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6048 |  |  | function exportAllStudentWorkFromPublication( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6049 |  |  |     $workId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6050 |  |  |     $courseInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6051 |  |  |     $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6052 |  |  |     $format = 'pdf' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6053 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6054 |  |  |     if (empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6055 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6056 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6057 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6058 |  |  |     $workData = get_work_data_by_id($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6059 |  |  |     if (empty($workData)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6060 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6061 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6062 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6063 |  |  |     $assignment = get_work_assignment_by_id($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6064 |  |  |     $courseCode = $courseInfo['code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6065 |  |  |     $header = get_lang('Course').': '.$courseInfo['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6066 |  |  |     $teachers = CourseManager::getTeacherListFromCourseCodeToString($courseCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6067 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6068 |  |  |     if (!empty($sessionId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6069 |  |  |         $sessionInfo = api_get_session_info($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6070 |  |  |         if (!empty($sessionInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6071 |  |  |             $header .= ' - '.$sessionInfo['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6072 |  |  |             $header .= '<br />'.$sessionInfo['description']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6073 |  |  |             $teachers = SessionManager::getCoachesByCourseSessionToString( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6074 |  |  |                 $sessionId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6075 |  |  |                 $courseInfo['real_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6076 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6077 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6078 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6079 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6080 |  |  |     $header .= '<br />'.get_lang('Trainers').': '.$teachers.'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6081 |  |  |     $header .= '<br />'.get_lang('Date').': '.api_get_local_time().'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6082 |  |  |     $header .= '<br />'.get_lang('Assignment name').': '.$workData['title'].'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6083 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6084 |  |  |     $content = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6085 |  |  |     $expiresOn = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6086 |  |  |     if (!empty($assignment) && isset($assignment['expires_on'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6087 |  |  |         $content .= '<br /><strong>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6088 |  |  |             get_lang('Posted deadline for sending the work (Visible to the learner)').'</strong>: '. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6089 |  |  |             api_get_local_time($assignment['expires_on']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6090 |  |  |         $expiresOn = api_get_local_time($assignment['expires_on']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6091 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6092 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6093 |  |  |     if (!empty($workData['description'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6094 |  |  |         $content .= '<br /><strong>'.get_lang('Description').'</strong>: '.$workData['description']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6095 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6096 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6097 |  |  |     $workList = get_work_user_list(null, null, null, null, $workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6098 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6099 |  |  |     switch ($format) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6100 |  |  |         case 'pdf': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6101 |  |  |             if (!empty($workList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6102 |  |  |                 $table = new HTML_Table(['class' => 'data_table']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6103 |  |  |                 $headers = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6104 |  |  |                     get_lang('Name'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6105 |  |  |                     get_lang('User'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6106 |  |  |                     get_lang('Deadline'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6107 |  |  |                     get_lang('Sent date'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6108 |  |  |                     get_lang('Filename'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6109 |  |  |                     get_lang('Score'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6110 |  |  |                     get_lang('Feedback'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6111 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6113 |  |  |                 $column = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6114 |  |  |                 foreach ($headers as $header) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6115 |  |  |                     $table->setHeaderContents(0, $column, $header); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6116 |  |  |                     $column++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6117 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6119 |  |  |                 $row = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6120 |  |  |                 //$pdf->set_custom_header($header); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6121 |  |  |                 /** @var array $work */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6122 |  |  |                 foreach ($workList as $work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6123 |  |  |                     $content .= '<hr />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6124 |  |  |                     // getWorkComments need c_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6125 |  |  |                     $work['c_id'] = $courseInfo['real_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6126 |  |  |                     //$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6127 |  |  |                     $score = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6128 |  |  |                     if (!empty($work['qualification_only'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6129 |  |  |                         $score = $work['qualification_only']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6130 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6132 |  |  |                     $comments = getWorkComments($work); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6133 |  |  |                     $feedback = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6134 |  |  |                     if (!empty($comments)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6135 |  |  |                         $content .= '<h4>'.get_lang('Feedback').': </h4>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6136 |  |  |                         foreach ($comments as $comment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6137 |  |  |                             $feedback .= get_lang('User').': '.$comment['complete_name'].'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6138 |  |  |                             $feedback .= $comment['comment'].'<br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6139 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6140 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6141 |  |  |                     $table->setCellContents($row, 0, strip_tags($workData['title'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6142 |  |  |                     $table->setCellContents($row, 1, strip_tags($work['fullname'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6143 |  |  |                     $table->setCellContents($row, 2, $expiresOn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6144 |  |  |                     $table->setCellContents($row, 3, api_get_local_time($work['sent_date_from_db'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6145 |  |  |                     $table->setCellContents($row, 4, strip_tags($work['title'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6146 |  |  |                     $table->setCellContents($row, 5, $score); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6147 |  |  |                     $table->setCellContents($row, 6, $feedback); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6148 |  |  |                     $row++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6149 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6151 |  |  |                 $content = $table->toHtml(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6152 |  |  |                 if (!empty($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6153 |  |  |                     $params = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6154 |  |  |                         'filename' => $workData['title'].'_'.api_get_local_time(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6155 |  |  |                         'pdf_title' => api_replace_dangerous_char($workData['title']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6156 |  |  |                         'course_code' => $courseInfo['code'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6157 |  |  |                     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6158 |  |  |                     $pdf = new PDF('A4', null, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6159 |  |  |                     $pdf->html_to_pdf_with_template($content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6160 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6161 |  |  |                 exit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6162 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6164 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6166 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6168 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6169 |  |  |  * Downloads all user files per user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6170 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6171 |  |  |  * @param int   $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6172 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6173 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6174 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6175 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6176 |  |  | function downloadAllFilesPerUser($userId, $courseInfo) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6177 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6178 |  |  |     throw new Exception('downloadAllFilesPerUser'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6179 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6180 |  |  |     $userInfo = api_get_user_info($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6182 |  |  |     if (empty($userInfo) || empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6183 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6184 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6186 |  |  |     $tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6187 |  |  |     $coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6188 |  |  |     $zip = new PclZip($tempZipFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6189 |  |  |     $workPerUser = getWorkPerUser($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6191 |  |  |     if (!empty($workPerUser)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6192 |  |  |         $files = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6193 |  |  |         foreach ($workPerUser as $work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6194 |  |  |             $work = $work['work']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6195 |  |  |             foreach ($work->user_results as $userResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6196 |  |  |                 if (empty($userResult['url']) || empty($userResult['contains_file'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6197 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6198 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6199 |  |  |                 $data = getFileContents($userResult['iid'], $courseInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6200 |  |  |                 if (!empty($data) && isset($data['path'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6201 |  |  |                     $files[basename($data['path'])] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6202 |  |  |                         'title' => $data['title'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6203 |  |  |                         'path' => $data['path'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6204 |  |  |                     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6205 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6206 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6209 |  |  |         if (!empty($files)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6210 |  |  |             Session::write('files', $files); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6211 |  |  |             foreach ($files as $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6212 |  |  |                 $zip->add( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6213 |  |  |                     $data['path'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6214 |  |  |                     PCLZIP_OPT_REMOVE_PATH, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6215 |  |  |                     $coursePath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6216 |  |  |                     PCLZIP_CB_PRE_ADD, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6217 |  |  |                     'preAddAllWorkStudentCallback' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6218 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6219 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6222 |  |  |         // Start download of created file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6223 |  |  |         $name = basename(api_replace_dangerous_char($userInfo['complete_name'])).'.zip'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6224 |  |  |         Event::event_download($name.'.zip (folder)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6225 |  |  |         if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6226 |  |  |             DocumentManager::file_send_for_download($tempZipFile, true, $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6227 |  |  |             @unlink($tempZipFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6228 |  |  |             exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6229 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6230 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6231 |  |  |     exit;*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6232 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6233 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6234 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6235 |  |  |  * @param $p_event | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6236 |  |  |  * @param array $p_header | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6237 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6238 |  |  |  * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6239 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6240 |  |  | function preAddAllWorkStudentCallback($p_event, &$p_header) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6241 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6242 |  |  |     $files = Session::read('files'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6243 |  |  |     if (isset($files[basename($p_header['stored_filename'])])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6244 |  |  |         $p_header['stored_filename'] = $files[basename($p_header['stored_filename'])]['title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6245 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6246 |  |  |         return 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6247 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6249 |  |  |     return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6250 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6252 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6253 |  |  |  * Get all work created by a user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6254 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6255 |  |  |  * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6256 |  |  |  * @param int $courseId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6257 |  |  |  * @param int $sessionId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6258 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6259 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6260 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6261 |  |  | function getWorkCreatedByUser($userId, $courseId, $sessionId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6262 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6263 |  |  |     $repo = Container::getStudentPublicationRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6265 |  |  |     $courseEntity = api_get_course_entity($courseId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6266 |  |  |     $sessionEntity = api_get_session_entity($sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6268 |  |  |     $qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6269 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6270 |  |  |     $qb->andWhere('node.creator = :creator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6271 |  |  |     $qb->setParameter('creator', $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6272 |  |  |     $items = $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6274 |  |  |     $list = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6275 |  |  |     if (!empty($items)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6276 |  |  |         /** @var CStudentPublication $work */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6277 |  |  |         foreach ($items as $work) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6278 |  |  |             $list[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6279 |  |  |                 $work->getTitle(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6280 |  |  |                 api_get_local_time($work->getResourceNode()->getCreatedAt()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6281 |  |  |                 api_get_local_time($work->getResourceNode()->getUpdatedAt()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6282 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6283 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6284 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6286 |  |  |     return $list; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6287 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6288 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6289 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6290 |  |  |  * @param array $courseInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6291 |  |  |  * @param int   $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6292 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6293 |  |  |  * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6294 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6295 |  |  | function protectWork($courseInfo, $workId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6296 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6297 |  |  |     $userId = api_get_user_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6298 |  |  |     $groupId = api_get_group_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6299 |  |  |     $sessionId = api_get_session_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6300 |  |  |     $workData = get_work_data_by_id($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6302 |  |  |     if (empty($workData) || empty($courseInfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6303 |  |  |         api_not_allowed(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6304 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6305 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6306 |  |  |     if (api_is_platform_admin() || api_is_allowed_to_edit()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6307 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6308 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6309 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6310 |  |  |     $workId = $workData['iid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6311 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6312 |  |  |     if (1 != $workData['active']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6313 |  |  |         api_not_allowed(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6314 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6316 |  |  |     /*$visibility = api_get_item_visibility($courseInfo, 'work', $workId, $sessionId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6317 |  |  |     if ($visibility != 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6318 |  |  |         api_not_allowed(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6319 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6320 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6321 |  |  |     $isAllow = allowOnlySubscribedUser($userId, $workId, $courseInfo['real_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6322 |  |  |     if (empty($isAllow)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6323 |  |  |         api_not_allowed(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6324 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6325 |  |  |     if (!empty($groupId)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6326 |  |  |         $group = api_get_group_entity($groupId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6327 |  |  |         $showWork = GroupManager::userHasAccess( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6328 |  |  |             $userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6329 |  |  |             $group, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6330 |  |  |             GroupManager::GROUP_TOOL_WORK | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6331 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6332 |  |  |         if (!$showWork) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6333 |  |  |             api_not_allowed(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6334 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6335 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6336 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6337 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 6338 |  |  | function deleteCorrection(CStudentPublication $work) | 
            
                                                                        
                            
            
                                    
            
            
                | 6339 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 6340 |  |  |     $correctionNode = $work->getCorrection(); | 
            
                                                                        
                            
            
                                    
            
            
                | 6341 |  |  |     if (null !== $correctionNode) { | 
            
                                                                        
                            
            
                                    
            
            
                | 6342 |  |  |         $em = Database::getManager(); | 
            
                                                                        
                            
            
                                    
            
            
                | 6343 |  |  |         $em->remove($correctionNode); | 
            
                                                                        
                            
            
                                    
            
            
                | 6344 |  |  |         $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6345 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6346 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6348 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6349 |  |  |  * @param int $workId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6350 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6351 |  |  |  * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6352 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6353 |  |  | function workGetExtraFieldData($workId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6354 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6355 |  |  |     $sessionField = new ExtraField('work'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6356 |  |  |     $extraFieldData = $sessionField->getDataAndFormattedValues($workId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6357 |  |  |     $result = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6358 |  |  |     if (!empty($extraFieldData)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6359 |  |  |         $result .= '<div class="well">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6360 |  |  |         foreach ($extraFieldData as $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6361 |  |  |             $result .= $data['text'].': <b>'.$data['value'].'</b>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6362 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6363 |  |  |         $result .= '</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6364 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6365 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6366 |  |  |     return $result; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6367 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 6368 |  |  |  |