@@ -122,8 +122,8 @@ public function getTypes()
122122 * @param array $usersToSend array('everyone') or a list of user/group ids
123123 * @param bool $addAsAnnouncement event as a *course* announcement
124124 * @param int $parentEventId
125- * @param array $attachmentArray $_FILES['']
126- * @param string $attachmentComment
125+ * @param array $attachmentArray array of $_FILES['']
126+ * @param array $attachmentCommentList
127127 * @param string $eventComment
128128 * @param string $color
129129 *
@@ -139,7 +139,7 @@ public function add_event(
139139 $ addAsAnnouncement = false ,
140140 $ parentEventId = null ,
141141 $ attachmentArray = array (),
142- $ attachmentComment = null ,
142+ $ attachmentCommentList = array () ,
143143 $ eventComment = null ,
144144 $ color = ''
145145 ) {
@@ -304,12 +304,16 @@ public function add_event(
304304
305305 // Add attachment.
306306 if (isset ($ attachmentArray ) && !empty ($ attachmentArray )) {
307- $ this ->addAttachment (
308- $ id ,
309- $ attachmentArray ,
310- $ attachmentComment ,
311- $ this ->course
312- );
307+ $ counter = 0 ;
308+ foreach ($ attachmentArray as $ attachmentItem ) {
309+ $ this ->addAttachment (
310+ $ id ,
311+ $ attachmentItem ,
312+ $ attachmentCommentList [$ counter ],
313+ $ this ->course
314+ );
315+ $ counter ++;
316+ }
313317 }
314318 }
315319 break ;
@@ -562,7 +566,7 @@ public function store_agenda_item_as_announcement($item_id, $sentTo = array())
562566 * @param string $content
563567 * @param array $usersToSend
564568 * @param array $attachmentArray
565- * @param string $attachmentComment
569+ * @param array $attachmentCommentList
566570 * @param string $comment
567571 * @param string $color
568572 * @param bool $addAnnouncement
@@ -578,7 +582,7 @@ public function edit_event(
578582 $ content ,
579583 $ usersToSend = array (),
580584 $ attachmentArray = array (),
581- $ attachmentComment = null ,
585+ $ attachmentCommentList = array () ,
582586 $ comment = null ,
583587 $ color = '' ,
584588 $ addAnnouncement = false
@@ -801,12 +805,17 @@ public function edit_event(
801805
802806 // Add attachment.
803807 if (isset ($ attachmentArray ) && !empty ($ attachmentArray )) {
804- $ this ->updateAttachment (
805- $ id ,
806- $ attachmentArray ,
807- $ attachmentComment ,
808- $ this ->course
809- );
808+ $ counter = 0 ;
809+ foreach ($ attachmentArray as $ attachmentItem ) {
810+ $ this ->updateAttachment (
811+ $ attachmentItem ['id ' ],
812+ $ id ,
813+ $ attachmentItem ,
814+ $ attachmentCommentList [$ counter ],
815+ $ this ->course
816+ );
817+ $ counter ++;
818+ }
810819 }
811820 }
812821 break ;
@@ -848,10 +857,11 @@ public function delete_event($id, $deleteAllItemsFromSerie = false)
848857 break ;
849858 case 'course ' :
850859 $ course_id = api_get_course_int_id ();
860+
851861 if (!empty ($ course_id ) && api_is_allowed_to_edit (null , true )) {
852862 // Delete
863+ $ eventInfo = $ this ->get_event ($ id );
853864 if ($ deleteAllItemsFromSerie ) {
854- $ eventInfo = $ this ->get_event ($ id );
855865 /* This is one of the children.
856866 Getting siblings and delete 'Em all + the father! */
857867 if (isset ($ eventInfo ['parent_event_id ' ]) && !empty ($ eventInfo ['parent_event_id ' ])) {
@@ -895,6 +905,12 @@ public function delete_event($id, $deleteAllItemsFromSerie = false)
895905 $ this ->table_repeat ,
896906 array ('cal_id = ? AND c_id = ? ' => array ($ id , $ course_id ))
897907 );
908+
909+ if (isset ($ eventInfo ['attachment ' ]) && !empty ($ eventInfo ['attachment ' ])) {
910+ foreach ($ eventInfo ['attachment ' ] as $ attachment ) {
911+ self ::deleteAttachmentFile ($ attachment ['id ' ], $ this ->course );
912+ }
913+ }
898914 }
899915 break ;
900916 case 'admin ' :
@@ -1152,7 +1168,7 @@ public function get_event($id)
11521168 $ event ['parent_info ' ] = $ this ->get_event ($ event ['parent_event_id ' ]);
11531169 }
11541170
1155- $ event ['attachment ' ] = $ this ->getAttachment ($ id , $ this ->course );
1171+ $ event ['attachment ' ] = $ this ->getAttachmentList ($ id , $ this ->course );
11561172 }
11571173 }
11581174 break ;
@@ -1439,13 +1455,16 @@ public function get_course_events($start, $end, $courseInfo, $groupId = 0, $sess
14391455 }
14401456
14411457 $ eventsAdded [] = $ event ['unique_id ' ];
1442- $ attachment = $ this ->getAttachment ($ row ['id ' ], $ courseInfo );
1458+ $ attachmentList = $ this ->getAttachmentList ($ row ['id ' ], $ courseInfo );
1459+
1460+ if (!empty ($ attachmentList )) {
1461+ foreach ($ attachmentList as $ attachment ) {
1462+ $ has_attachment = Display::return_icon ('attachment.gif ' , get_lang ('Attachment ' ));
1463+ $ user_filename = $ attachment ['filename ' ];
1464+ $ url = api_get_path (WEB_CODE_PATH ).'calendar/download.php?file= ' .$ attachment ['path ' ].'&course_id= ' .$ course_id .'& ' .api_get_cidreq ();
1465+ $ event ['attachment ' ] .= $ has_attachment .Display::url ($ user_filename , $ url ).'<br /> ' ;
1466+ }
14431467
1444- if (!empty ($ attachment )) {
1445- $ has_attachment = Display::return_icon ('attachment.gif ' , get_lang ('Attachment ' ));
1446- $ user_filename = $ attachment ['filename ' ];
1447- $ url = api_get_path (WEB_CODE_PATH ).'calendar/download.php?file= ' .$ attachment ['path ' ].'&course_id= ' .$ course_id .'& ' .api_get_cidreq ();
1448- $ event ['attachment ' ] = $ has_attachment .Display::url ($ user_filename , $ url );
14491468 } else {
14501469 $ event ['attachment ' ] = '' ;
14511470 }
@@ -1944,23 +1963,36 @@ public function getForm($params = array())
19441963 $ form ->addElement ('textarea ' , 'comment ' , get_lang ('Comment ' ));
19451964 }
19461965
1947- $ form ->addElement ('file ' , 'user_upload ' , get_lang ('AddAnAttachment ' ));
1948- if ($ showAttachmentForm ) {
1966+ //$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
1967+
1968+ $ form ->addElement ('advanced_settings ' , get_lang ('FilesAttachment ' ).'<span id="filepaths">
1969+ <div id="filepath_1">
1970+ <input type="file" name="attach_1"/><br />
1971+ ' .get_lang ('Description ' ).' <input type="text" name="legend[]" /><br /><br />
1972+ </div>
1973+ </span> ' );
1974+ $ form ->addElement ('advanced_settings ' ,'<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()"> ' .get_lang ('AddOneMoreFile ' ).'</a></span> ( ' .sprintf (get_lang ('MaximunFileSizeX ' ),format_file_size (api_get_setting ('message_max_upload_filesize ' ))).') ' );
1975+
1976+ //if ($showAttachmentForm) {
1977+
19491978 if (isset ($ params ['attachment ' ]) && !empty ($ params ['attachment ' ])) {
1950- $ attachment = $ params ['attachment ' ];
1951- $ params ['file_comment ' ] = $ attachment ['comment ' ];
1952- if (!empty ($ attachment ['path ' ])) {
1953- $ form ->addElement (
1954- 'checkbox ' ,
1955- 'delete_attachment ' ,
1956- null ,
1957- get_lang ('DeleteAttachment ' ).' ' .$ attachment ['filename ' ]
1958- );
1979+ $ attachmentList = $ params ['attachment ' ];
1980+ foreach ($ attachmentList as $ attachment ) {
1981+ $ params ['file_comment ' ] = $ attachment ['comment ' ];
1982+ if (!empty ($ attachment ['path ' ])) {
1983+ $ form ->addElement (
1984+ 'checkbox ' ,
1985+ 'delete_attachment[ ' .$ attachment ['id ' ].'] ' ,
1986+ null ,
1987+ get_lang ('DeleteAttachment ' ).': ' .$ attachment ['filename ' ]
1988+ );
1989+ }
19591990 }
1991+
19601992 }
1961- }
1993+ // }
19621994
1963- $ form ->addElement ('textarea ' , 'file_comment ' , get_lang ('FileComment ' ));
1995+ // $form->addElement('textarea', 'file_comment', get_lang('FileComment'));
19641996
19651997 if (!empty ($ id )) {
19661998 $ form ->addElement (
@@ -2079,18 +2111,50 @@ public static function getRepeatTypes()
20792111 * @param array $courseInfo
20802112 * @return array with the post info
20812113 */
2082- public function getAttachment ($ eventId , $ courseInfo )
2114+ public function getAttachmentList ($ eventId , $ courseInfo )
20832115 {
20842116 $ tableAttachment = Database::get_course_table (TABLE_AGENDA_ATTACHMENT );
20852117 $ courseId = intval ($ courseInfo ['real_id ' ]);
20862118 $ eventId = intval ($ eventId );
2087- $ row = array ();
2119+
20882120 $ sql = "SELECT id, path, filename, comment
20892121 FROM $ tableAttachment
20902122 WHERE
20912123 c_id = $ courseId AND
20922124 agenda_id = $ eventId " ;
20932125 $ result = Database::query ($ sql );
2126+ $ list = array ();
2127+ if (Database::num_rows ($ result ) != 0 ) {
2128+ $ list = Database::store_result ($ result , 'ASSOC ' );
2129+ }
2130+
2131+ return $ list ;
2132+ }
2133+
2134+
2135+ /**
2136+ * Show a list with all the attachments according to the post's id
2137+ * @param int $attachmentId
2138+ * @param int $eventId
2139+ * @param array $courseInfo
2140+ * @return array with the post info
2141+ */
2142+ public function getAttachment ($ attachmentId , $ eventId , $ courseInfo )
2143+ {
2144+ $ tableAttachment = Database::get_course_table (TABLE_AGENDA_ATTACHMENT );
2145+ $ courseId = intval ($ courseInfo ['real_id ' ]);
2146+ $ eventId = intval ($ eventId );
2147+ $ attachmentId = intval ($ attachmentId );
2148+
2149+ $ row = array ();
2150+ $ sql = "SELECT id, path, filename, comment
2151+ FROM $ tableAttachment
2152+ WHERE
2153+ c_id = $ courseId AND
2154+ agenda_id = $ eventId AND
2155+ id = $ attachmentId
2156+ " ;
2157+ $ result = Database::query ($ sql );
20942158 if (Database::num_rows ($ result ) != 0 ) {
20952159 $ row = Database::fetch_array ($ result , 'ASSOC ' );
20962160 }
@@ -2162,16 +2226,17 @@ public function addAttachment($eventId, $fileUserUpload, $comment, $courseInfo)
21622226 }
21632227
21642228 /**
2229+ * @param int $attachmentId
21652230 * @param int $eventId
21662231 * @param array $fileUserUpload
21672232 * @param string $comment
21682233 * @param array $courseInfo
21692234 */
2170- public function updateAttachment ($ eventId , $ fileUserUpload , $ comment , $ courseInfo )
2235+ public function updateAttachment ($ attachmentId , $ eventId , $ fileUserUpload , $ comment , $ courseInfo )
21712236 {
2172- $ attachment = $ this ->getAttachment ($ eventId , $ courseInfo );
2237+ $ attachment = $ this ->getAttachment ($ attachmentId , $ eventId , $ courseInfo );
21732238 if (!empty ($ attachment )) {
2174- $ this ->deleteAttachmentFile ($ attachment [ ' id ' ] , $ courseInfo );
2239+ $ this ->deleteAttachmentFile ($ attachmentId , $ courseInfo );
21752240 }
21762241 $ this ->addAttachment ($ eventId , $ fileUserUpload , $ comment , $ courseInfo );
21772242 }
0 commit comments