Julio Montoya 12 years ago
parent
commit
5684339faa

+ 50 - 38
main/calendar/agenda.inc.php

@@ -82,7 +82,6 @@ function get_calendar_items($select_month, $select_year, $select_day = false)
 
     $group_id = api_get_group_id();
 
-
     $session_condition = api_get_session_condition(api_get_session_id());
 
     if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
@@ -1556,6 +1555,9 @@ function change_visibility($tool, $id, $visibility)
  */
 function display_courseadmin_links($filter = 0)
 {
+    if (!api_get_course_int_id()) {
+        return "<a href='agenda_js.php?type=personal'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
+    }
     $form = null;
     if (!isset($_GET['action'])) {
         $form = show_to($filter, 'selected_form_id_search');
@@ -1563,6 +1565,7 @@ function display_courseadmin_links($filter = 0)
     } else {
         $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
     }
+
     $actions .= "<a href='agenda.php?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&action=add'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM)."</a>";
     $actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM)."</a>";
     $actions .= $form;
@@ -1595,7 +1598,7 @@ function display_student_links()
  * get all the information of the agenda_item from the database
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @param integer the id of the agenda item we are getting all the information of
- * @return an associative array that contains all the information of the agenda item. The keys are the database fields
+ * @return array an associative array that contains all the information of the agenda item. The keys are the database fields
  */
 function get_agenda_item($id)
 {
@@ -1651,16 +1654,11 @@ function get_agenda_item($id)
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @author Julio Montoya Adding UTC support
  */
-function store_edited_agenda_item($id_attach, $file_comment)
+function store_edited_agenda_item($event_id, $id_attach, $file_comment)
 {
-    global $_course;
-
-    // database definitions
-    $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
-
     // STEP 1: editing the calendar_event table
     // 1.a.  some filtering of the input data
-    $id = (int) $_POST['id'];
+    $id = $event_id;
     $title = strip_tags(trim($_POST['title'])); // no html allowed in the title
     $content = trim($_POST['content']);
     $start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
@@ -1670,19 +1668,23 @@ function store_edited_agenda_item($id_attach, $file_comment)
     if ($_POST['empty_end_date'] == 'on') {
         $end_date = "0000-00-00 00:00:00";
     }
+    $course_info = api_get_course_info();
 
-    $course_id = api_get_course_int_id();
-
-    // 1.b. the actual saving in calendar_event table
     $agendaObj = new Agenda();
-    $agendaObj->set_course(api_get_course_info());
-    $agendaObj->type = 'course';
-    $all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0;
+    if (empty($course_info)) {
+        $agendaObj->type = 'personal';
+    } else {
+        $agendaObj->set_course($course_info);
+        $agendaObj->type = 'course';
 
+        if (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id)) {
+            return false;
+        }
+    }
+
+    $all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0;
     $agendaObj->edit_event($id, $start_date, $end_date, $all_day, null, $title, $content);
 
-    $start_date = api_get_utc_datetime($start_date);
-    $end_date = api_get_utc_datetime($end_date);
 
     if (empty($id_attach)) {
         add_agenda_attachment_file($file_comment, $id);
@@ -1749,7 +1751,7 @@ function save_edit_agenda_item($id, $title, $content, $start_date, $end_date)
 
 /**
  * This is the function that deletes an agenda item.
- * The agenda item is no longer fycically deleted but the visibility in the item_property table is set to 2
+ * The agenda item is no longer physically deleted but the visibility in the item_property table is set to 2
  * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
  * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
  * by the course administrator
@@ -2286,41 +2288,47 @@ function show_add_form($id = '')
     }
 
     $default_no_empty_end_date = 0;
+    $course_info = null;
 
     // if the id is set then we are editing an agenda item
     if (!empty($id)) {
-
-        $item_2_edit = get_agenda_item($id);
+        $course_info = api_get_course_info();
 
         $agendaObj = new Agenda();
-        $agendaObj->set_course(api_get_course_info());
-        $agendaObj->type = 'course';
+        if (!empty($course_info)) {
+            $agendaObj->set_course($course_info);
+            $agendaObj->type = 'course';
+        } else {
+            $agendaObj->type = 'personal';
+        }
         $agendaItem = $agendaObj->get_event($id);
 
-        $title = $item_2_edit['title'];
-        $content = $item_2_edit['content'];
+        $title = $agendaItem['title'];
+        $content = $agendaItem['text'];
 
         // start date
-        if ($item_2_edit['start_date'] != '0000-00-00 00:00:00') {
-            $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']);
-            list($datepart, $timepart) = explode(" ", $item_2_edit['start_date']);
+        if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
+            $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
+            list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
             list($year, $month, $day) = explode("-", $datepart);
             list($hours, $minutes, $seconds) = explode(":", $timepart);
         }
 
         // end date
-        if ($item_2_edit['end_date'] != '0000-00-00 00:00:00') {
-            $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']);
-            list($datepart, $timepart) = explode(" ", $item_2_edit['end_date']);
+        if ($agendaItem['end_date'] != '0000-00-00 00:00:00') {
+            $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
+            list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
             list($end_year, $end_month, $end_day) = explode("-", $datepart);
 
             list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
-        } elseif ($item_2_edit['end_date'] == '0000-00-00 00:00:00') {
+        } elseif ($agendaItem['end_date'] == '0000-00-00 00:00:00') {
             $default_no_empty_end_date = 1;
         }
         // attachments
-        edit_added_resources("Agenda", $id);
-        $to = $item_2_edit['to'];
+        //edit_added_resources("Agenda", $id);
+        //$to = $item_2_edit['to'];
+    } else {
+        $to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
     }
     $content = stripslashes($content);
     $title = stripslashes($title);
@@ -2331,11 +2339,12 @@ function show_add_form($id = '')
         unset_session_resources();
     }
     $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
+    $course_url = empty($course_info) ? null : api_get_cidreq();
     ?>
 
     <!-- START OF THE FORM  -->
 
-    <form class="form-horizontal" enctype="multipart/form-data"  action="<?php echo api_get_self().'?origin='.$origin.'&'.api_get_cidreq()."&sort=asc&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
+    <form class="form-horizontal" enctype="multipart/form-data"  action="<?php echo api_get_self().'?origin='.$origin.'&'.$course_url."&sort=asc&toolgroup=".api_get_group_id().'&action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
         <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
         <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo $_GET['action']; ?>" />
         <input type="hidden" name="id_attach" value="<?php echo isset($_REQUEST['id_attach']) ? intval($_REQUEST['id_attach']) : null; ?>" />
@@ -2361,8 +2370,8 @@ function show_add_form($id = '')
     if (isset($title))
         echo $title;
     echo '" />
-							</div>
-						</div>';
+			</div>
+			</div>';
 
     // selecting the users / groups
     $group_id = api_get_group_id();
@@ -2601,7 +2610,7 @@ function show_add_form($id = '')
                     </td>
                 </tr>
                 <tr>
-                    <td><label for="repeat_type"><?php echo get_lang('RepeatType'); ?></label></td>
+                    <td><label><?php echo get_lang('RepeatType'); ?></label></td>
                     <td>
                         <select name="repeat_type">
                             <option value="daily"><?php echo get_lang('RepeatDaily'); ?></option>
@@ -2614,7 +2623,7 @@ function show_add_form($id = '')
                     </td>
                 </tr>
                 <tr>
-                    <td><label for="repeat_end_day"><?php echo get_lang('RepeatEnd'); ?></label></td>
+                    <td><label><?php echo get_lang('RepeatEnd'); ?></label></td>
                     <td>
                         <select name="repeat_end_day">
                         <?php
@@ -2701,6 +2710,8 @@ function show_add_form($id = '')
                         //echo '<textarea class="span5"  rows="4" name="content">'.$content.'</textarea>';
                         echo '</div>
 			</div>';
+
+            if ($agendaObj->type != 'personal') {
                         // File attachment
                         echo '	<div class="control-group">
 				<label class="control-label">
@@ -2709,6 +2720,7 @@ function show_add_form($id = '')
                     <input type="file" name="user_upload"/>  '.get_lang('Comment').' <input name="file_comment" type="text" size="20" />
                 </div>
              </div>';
+            }
                         // the submit button for storing the calendar item
                     echo '		<div class="control-group">
 					<label class="control-label">

+ 8 - 0
main/calendar/agenda.lib.php

@@ -180,6 +180,10 @@ class Agenda
 
         switch ($this->type) {
             case 'personal':
+                $eventInfo = $this->get_event($id);
+                if ($eventInfo['user'] != api_get_user_id()) {
+                    break;
+                }
                 $attributes['title'] = $title;
                 $attributes['text'] = $content;
                 $attributes['date'] = $start;
@@ -361,7 +365,9 @@ class Agenda
 
     /**
      * Gets a single event
+     *
      * @param int event id
+     * @return array
      */
     function get_event($id)
     {
@@ -375,6 +381,8 @@ class Agenda
                 if (Database::num_rows($result)) {
                     $event = Database::fetch_array($result, 'ASSOC');
                     $event['description'] = $event['text'];
+                    $event['start_date'] = $event['date'];
+                    $event['end_date'] = $event['endate'];
                 }
                 break;
             case 'course':

+ 34 - 14
main/calendar/agenda.php

@@ -17,7 +17,11 @@ $use_anonymous = true;
 require_once '../inc/global.inc.php';
 $current_course_tool = TOOL_CALENDAR_EVENT;
 
-api_protect_course_script(true);
+$course_info = api_get_course_info();
+
+if (!empty($course_info)) {
+    api_protect_course_script(true);
+}
 
 //session
 if (isset($_GET['id_session'])) {
@@ -42,9 +46,23 @@ require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 
 if (!empty($addresources)) {
     // When the "Add Resource" button is clicked we store all the form data into a session
-    $form_elements = array('day' => Security::remove_XSS($_POST['fday']), 'month' => Security::remove_XSS($_POST['fmonth']), 'year' => Security::remove_XSS($_POST['fyear']), 'hour' => Security::remove_XSS($_POST['fhour']), 'minutes' => Security::remove_XSS($_POST['fminute']),
-        'end_day' => Security::remove_XSS($_POST['end_fday']), 'end_month' => Security::remove_XSS($_POST['end_fmonth']), 'end_year' => Security::remove_XSS($_POST['end_fyear']), 'end_hours' => Security::remove_XSS($_POST['end_fhour']), 'end_minutes' => Security::remove_XSS($_POST['end_fminute']),
-        'title' => Security::remove_XSS(stripslashes($_POST['title'])), 'content' => Security::remove_XSS(stripslashes($_POST['content'])), 'id' => Security::remove_XSS($_POST['id']), 'action' => Security::remove_XSS($_POST['action']), 'to' => Security::remove_XSS($_POST['selectedform']));
+    $form_elements = array(
+        'day' => Security::remove_XSS($_POST['fday']),
+        'month' => Security::remove_XSS($_POST['fmonth']),
+        'year' => Security::remove_XSS($_POST['fyear']),
+        'hour' => Security::remove_XSS($_POST['fhour']),
+        'minutes' => Security::remove_XSS($_POST['fminute']),
+        'end_day' => Security::remove_XSS($_POST['end_fday']),
+        'end_month' => Security::remove_XSS($_POST['end_fmonth']),
+        'end_year' => Security::remove_XSS($_POST['end_fyear']),
+        'end_hours' => Security::remove_XSS($_POST['end_fhour']),
+        'end_minutes' => Security::remove_XSS($_POST['end_fminute']),
+        'title' => Security::remove_XSS(stripslashes($_POST['title'])),
+        'content' => Security::remove_XSS(stripslashes($_POST['content'])),
+        'id' => Security::remove_XSS($_POST['id']),
+        'action' => Security::remove_XSS($_POST['action']),
+        'to' => Security::remove_XSS($_POST['selectedform'])
+    );
     $_SESSION['formelements'] = $form_elements;
     // this is to correctly handle edits
     if ($id) {
@@ -187,14 +205,18 @@ if (api_is_allowed_to_edit(false, true) OR
 
 echo '</div>';
 
-$event_id = isset($_GET['id']) ? $_GET['id'] : null;
-
+$event_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
 $type = isset($_GET['type']) ? $_GET['type'] : null;
+
 if ($type == 'fromjs') {
     $id_list = explode('_', $event_id);
     $event_id = $id_list[1];
 }
 
+if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
+    api_not_allowed();
+}
+
 $course_info = api_get_course_info();
 
 if (api_is_allowed_to_edit(false, true) OR
@@ -262,14 +284,12 @@ if (api_is_allowed_to_edit(false, true) OR
             }
             break;
         case 'edit':
-            if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
-                // a coach can only delete an element belonging to his session
-                if ($_POST['submit_event']) {
-                    store_edited_agenda_item($_REQUEST['id_attach'], $_REQUEST['file_comment']);
-                    $action = 'view';
-                } else {
-                    show_add_form($event_id);
-                }
+            // a coach can only delete an element belonging to his session
+            if ($_POST['submit_event']) {
+                store_edited_agenda_item($event_id, $_REQUEST['id_attach'], $_REQUEST['file_comment']);
+                $action = 'view';
+            } else {
+                show_add_form($event_id);
             }
             break;
         case "delete":

+ 5 - 1
main/inc/lib/auth.lib.php

@@ -500,7 +500,11 @@ class Auth {
             $sql = "SELECT * FROM $tbl_course WHERE id IN($id_in)";
         } else {
             $category_code = Database::escape_string($category_code);
-            $sql = "SELECT * FROM $tbl_course WHERE category_code='$category_code' $without_special_courses ORDER BY title ";
+            if (empty($category_code)) {
+                $sql = "SELECT * FROM $tbl_course WHERE 1=1 $without_special_courses ORDER BY title ";
+            } else {
+                $sql = "SELECT * FROM $tbl_course WHERE category_code='$category_code' $without_special_courses ORDER BY title ";
+            }
 
             //showing only the courses of the current Chamilo access_url_id
             if ($_configuration['multiple_access_urls']) {

+ 5 - 3
main/template/default/agenda/month.tpl

@@ -284,6 +284,8 @@ $(document).ready(function() {
                             url =  "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
                             window.location.href = url;
 						},
+
+                        {% if type == 'not_available' %}
 						'{{ "Edit"|get_lang }}' : function() {
 
 							var bValid = true;
@@ -307,14 +309,14 @@ $(document).ready(function() {
 								}
 							});
 						},
+                        {% endif %}
 
-                        {% if type == 'course' %}
-                        '{{ "AdvancedEdit"|get_lang }}' : function() {
+                        '{{ "Edit"|get_lang }}' : function() {
                             url =  "agenda.php?action=edit&type=fromjs&id=" + calEvent.id+'&course_id='+calEvent.course_id+"";
                             window.location.href = url;
                             $("#dialog-form").dialog( "close" );
                         },
-                        {% endif %}
+
 						'{{ "Delete"|get_lang }}': function() {
 							$.ajax({
 								url: delete_url,