|
|
|
@ -106,7 +106,7 @@ class Agenda { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($add_as_announcement) && !empty($add_as_announcement)) { |
|
|
|
|
self::store_agenda_item_as_announcement($id); |
|
|
|
|
self::store_agenda_item_as_announcement($id, $users_to_send); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -124,15 +124,18 @@ class Agenda { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* copycat of the agenda.inc.php @todo try to fix it */ |
|
|
|
|
|
|
|
|
|
function store_agenda_item_as_announcement($item_id){ |
|
|
|
|
$table_agenda = Database::get_course_table(TABLE_AGENDA); |
|
|
|
|
$table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param agenda_id |
|
|
|
|
* @sent agenda event to |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
function store_agenda_item_as_announcement($item_id, $sent_to = array()){ |
|
|
|
|
$table_agenda = Database::get_course_table(TABLE_AGENDA); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
//check params |
|
|
|
|
if(empty($item_id) or $item_id != strval(intval($item_id))) {return -1;} |
|
|
|
|
if (empty($item_id) or $item_id != strval(intval($item_id))) { return -1; } |
|
|
|
|
//get the agenda item |
|
|
|
|
|
|
|
|
|
$item_id = Database::escape_string($item_id); |
|
|
|
@ -140,60 +143,14 @@ class Agenda { |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
|
|
if (Database::num_rows($res)>0) { |
|
|
|
|
$row = Database::fetch_array($res); |
|
|
|
|
|
|
|
|
|
//we have the agenda event, copy it |
|
|
|
|
//get the maximum value for display order in announcement table |
|
|
|
|
$sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id "; |
|
|
|
|
$res_max = Database::query($sql_max); |
|
|
|
|
$row_max = Database::fetch_array($res_max); |
|
|
|
|
$max = intval($row_max[0])+1; |
|
|
|
|
//build the announcement text |
|
|
|
|
$content = $row['content']; |
|
|
|
|
//insert announcement |
|
|
|
|
$session_id = api_get_session_id(); |
|
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
|
|
|
|
|
|
|
|
$sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) " . |
|
|
|
|
"VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')"; |
|
|
|
|
$res_ins = Database::query($sql_ins); |
|
|
|
|
|
|
|
|
|
if ($res_ins) { |
|
|
|
|
$ann_id = Database::insert_id(); |
|
|
|
|
|
|
|
|
|
AnnouncementManager::send_email($ann_id); |
|
|
|
|
|
|
|
|
|
//Now also get the list of item_properties rows for this agenda_item (calendar_event) |
|
|
|
|
//and copy them into announcement item_properties |
|
|
|
|
$table_props = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
|
$sql_props = "SELECT * FROM $table_props WHERE c_id = $course_id AND tool ='calendar_event' AND ref='$item_id'"; |
|
|
|
|
$res_props = Database::query($sql_props); |
|
|
|
|
|
|
|
|
|
if (Database::num_rows($res_props)>0) { |
|
|
|
|
while ($row_props = Database::fetch_array($res_props)) { |
|
|
|
|
//insert into announcement item_property |
|
|
|
|
$time = api_get_utc_datetime(); |
|
|
|
|
$sql_ins_props = "INSERT INTO $table_props " . |
|
|
|
|
"(c_id, tool, insert_user_id, insert_date, " . |
|
|
|
|
"lastedit_date, ref, lastedit_type," . |
|
|
|
|
"lastedit_user_id, to_group_id, to_user_id, " . |
|
|
|
|
"visibility, start_visible, end_visible)" . |
|
|
|
|
" VALUES " . |
|
|
|
|
"($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."'," . |
|
|
|
|
"'$time','$ann_id','AnnouncementAdded'," . |
|
|
|
|
"'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."'," . |
|
|
|
|
"'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')"; |
|
|
|
|
$res_ins_props = Database::query($sql_ins_props); |
|
|
|
|
if ($res_ins_props <= 0) { |
|
|
|
|
return -1; |
|
|
|
|
} else { |
|
|
|
|
//copy was a success |
|
|
|
|
return $ann_id; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return -1; |
|
|
|
|
//Sending announcement |
|
|
|
|
if (!empty($sent_to)) { |
|
|
|
|
$id = AnnouncementManager::add_announcement($row['title'], $row['content'], $sent_to, null, null, $row['end_date']); |
|
|
|
|
AnnouncementManager::send_email($id); |
|
|
|
|
} |
|
|
|
|
return $id; |
|
|
|
|
} |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|