diff --git a/main/blog/blog.php b/main/blog/blog.php
index e71107eea6..ab0f428cd9 100755
--- a/main/blog/blog.php
+++ b/main/blog/blog.php
@@ -34,11 +34,11 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
PROCESSING
*/
-$safe_post_file_comment = isset($_GET['post_file_comment']) ? Security::remove_XSS($_POST['post_file_comment']) : null;
-$safe_comment_text = isset($_GET['comment_text']) ? Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY) : null;
-$safe_comment_title = isset($_GET['comment_title']) ? Security::remove_XSS($_POST['comment_title']) : null;
-$safe_task_name = isset($_GET['task_name']) ? Security::remove_XSS($_POST['task_name']) : null;
-$safe_task_description = isset($_GET['task_description']) ? Security::remove_XSS($_POST['task_description']) : null;
+$safe_post_file_comment = isset($_POST['post_file_comment']) ? Security::remove_XSS($_POST['post_file_comment']) : null;
+$safe_comment_text = isset($_POST['comment_text']) ? Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY) : null;
+$safe_comment_title = isset($_POST['comment_title']) ? Security::remove_XSS($_POST['comment_title']) : null;
+$safe_task_name = isset($_POST['task_name']) ? Security::remove_XSS($_POST['task_name']) : null;
+$safe_task_description = isset($_POST['task_description']) ? Security::remove_XSS($_POST['task_description']) : null;
if (!empty($_POST['new_post_submit'])) {
Blog:: create_post(
@@ -72,6 +72,7 @@ if (!empty($_POST['new_comment_submit'])) {
}
if (!empty($_POST['new_task_submit'])) {
+
Blog:: create_task(
$blog_id,
$safe_task_name,
@@ -106,7 +107,7 @@ if (!empty($_POST['assign_task_submit'])) {
$blog_id,
$_POST['task_user_id'],
$_POST['task_task_id'],
- $_POST['task_year'] . "-" . $_POST['task_month'] . "-" . $_POST['task_day']
+ $_POST['task_day']
);
$return_message = array(
'type' => 'confirmation',
@@ -119,7 +120,7 @@ if (isset($_POST['assign_task_edit_submit'])) {
$blog_id,
$_POST['task_user_id'],
$_POST['task_task_id'],
- $_POST['task_year'] . "-" . $_POST['task_month'] . "-" . $_POST['task_day'],
+ $_POST['task_day'],
$_POST['old_user_id'],
$_POST['old_task_id'],
$_POST['old_target_date']
@@ -219,9 +220,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'view_post') {
/*
DISPLAY
*/
-$htmlHeadXtra[] = '';
-// Set bredcrumb
+// Set breadcrumb
switch ($action) {
case 'new_post' :
$nameTools = get_lang('NewPost');
@@ -426,20 +426,19 @@ switch ($action) {
break;
case 'manage_tasks' :
if (api_is_allowed('BLOG_'.$blog_id, 'task_management')) {
- if (isset($_GET['do']) && $_GET['do'] == 'add')
- {
- Blog :: display_new_task_form($blog_id);
+ if (isset($_GET['do']) && $_GET['do'] == 'add') {
+ Blog:: display_new_task_form($blog_id);
}
- if (isset($_GET['do']) && $_GET['do'] == 'assign')
- {
- Blog :: display_assign_task_form($blog_id);
+ if (isset($_GET['do']) && $_GET['do'] == 'assign') {
+ Blog:: display_assign_task_form($blog_id);
}
- if (isset($_GET['do']) && $_GET['do'] == 'edit')
- {
- Blog :: display_edit_task_form($blog_id, intval($_GET['task_id']));
+ if (isset($_GET['do']) && $_GET['do'] == 'edit') {
+ Blog:: display_edit_task_form(
+ $blog_id,
+ intval($_GET['task_id'])
+ );
}
- if (isset($_GET['do']) && $_GET['do'] == 'edit_assignment')
- {
+ if (isset($_GET['do']) && $_GET['do'] == 'edit_assignment') {
Blog :: display_edit_assigned_task_form($blog_id, intval($_GET['task_id']), intval($_GET['user_id']));
}
Blog :: display_task_list($blog_id);
diff --git a/main/blog/calendar.php b/main/blog/calendar.php
deleted file mode 100755
index 65521034d2..0000000000
--- a/main/blog/calendar.php
+++ /dev/null
@@ -1,136 +0,0 @@
-
-
-
-Calendar
-
-
-
-
-
-
-
-
-
-
-
diff --git a/main/blog/tbl_change.js b/main/blog/tbl_change.js
deleted file mode 100755
index 1ecabb6e83..0000000000
--- a/main/blog/tbl_change.js
+++ /dev/null
@@ -1,159 +0,0 @@
-var day;
-var month;
-var year;
-var hour;
-var minute;
-var second;
-var clock_set = 0;
-
-/**
- * Opens calendar window.
- *
- * @param string form name
- * @param string field name
- */
-function openCalendar(form, field) {
- window.open("./calendar.php", "calendar", "width=260,height=250,status=no");
- day = eval("document." + form + "." + field + "day.options["+ "document." + form + "." + field + "day.selectedIndex].value");
- month = eval("document." + form + "." + field + "month.options["+ "document." + form + "." + field + "month.selectedIndex].value");
- month = month-1;
- year = eval("document." + form + "." + field + "year.options["+ "document." + form + "." + field + "year.selectedIndex].value");
- formName = form;
- fieldName =field;
-}
-
-/**
- * Formats number to two digits.
- *
- * @param int number to format.
- */
-function formatNum2(i, valtype) {
- f = (i < 10 ? '0' : '') + i;
- if (valtype && valtype != '') {
- switch(valtype) {
- case 'month':
- f = (f > 12 ? 12 : f);
- break;
-
- case 'day':
- f = (f > 31 ? 31 : f);
- break;
- }
- }
-
- return f;
-}
-
-/**
- * Formats number to four digits.
- *
- * @param int number to format.
- */
-function formatNum4(i) {
- return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
-}
-
-/**
- * Initializes calendar window.
- */
-function initCalendar() {
- if (!year && !month && !day) {
- day = window.opener.day;
- month = window.opener.month;
- year = window.opener.year;
- if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
- dt = new Date();
- year = dt.getFullYear();
- month = dt.getMonth();
- day = dt.getDate();
- }
- } else {
- /* Moving in calendar */
- if (month > 11) {
- month = 0;
- year++;
- }
- if (month < 0) {
- month = 11;
- year--;
- }
- }
-
- if (document.getElementById) {
- cnt = document.getElementById("calendar_data");
- } else if (document.all) {
- cnt = document.all["calendar_data"];
- }
-
- cnt.innerHTML = "";
-
- str = ""
-
- //heading table
- str += '| ';
- str += '« ';
- str += month_names[month];
- str += ' »';
- str += ' | ';
- str += '« ';
- str += year;
- str += ' »';
- str += ' |
|---|
';
-
- str += '';
- for (i = 0; i < 7; i++) {
- str += "| " + day_names[i] + " | ";
- }
- str += "
";
-
- var firstDay = new Date(year, month, 1).getDay();
- var lastDay = new Date(year, month + 1, 0).getDate();
-
- str += "";
-
- dayInWeek = 0;
- for (i = 0; i < firstDay; i++) {
- str += "| | ";
- dayInWeek++;
- }
- for (i = 1; i <= lastDay; i++) {
- if (dayInWeek == 7) {
- str += "
";
- dayInWeek = 0;
- }
-
- dispmonth = 1 + month;
- actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
- if (i == day) {
- style = ' class="selected"';
- } else {
- style = '';
- }
- str += "| " + i + " | "
- dayInWeek++;
- }
- for (i = dayInWeek; i < 7; i++) {
- str += " | ";
- }
-
- str += "
";
-
- cnt.innerHTML = str;
-}
-
-/**
- * Returns date from calendar.
- *
- * @param string date text
- */
-function returnDate(d,m,y) {
- cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"day.selectedIndex = "+(d-1);
- eval(cmd);
- cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"month.selectedIndex = "+m;
- eval(cmd);
- date = new Date();
- year = date.getFullYear()-1;
- cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"year.selectedIndex = "+(y-year);
- eval(cmd);
- window.close();
-}
diff --git a/main/inc/lib/blog.lib.php b/main/inc/lib/blog.lib.php
index df876a778b..944717dca5 100755
--- a/main/inc/lib/blog.lib.php
+++ b/main/inc/lib/blog.lib.php
@@ -1350,7 +1350,8 @@ class Blog
* @author Toon Keppens
*
*/
- public static function display_new_task_form ($blog_id) {
+ public static function display_new_task_form ($blog_id)
+ {
// Init
$colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
@@ -1526,37 +1527,30 @@ class Blog
}
/**
- * Displays assign task form
- * @author Toon Keppens
- *
+ * @param $blog_id
+ * @return FormValidator
*/
- public static function display_assign_task_form($blog_id)
+ public static function getTaskForm($blog_id)
{
// Init
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
- $day = date("d");
- $month = date("m");
- $year = date("Y");
- global $MonthsLong;
-
$course_id = api_get_course_int_id();
// Get users in this blog / make select list of it
- $sql = "SELECT user.user_id, user.firstname, user.lastname, user.username FROM $tbl_users user
+ $sql = "SELECT user.user_id, user.firstname, user.lastname, user.username
+ FROM $tbl_users user
INNER JOIN $tbl_blogs_rel_user blogs_rel_user
ON user.user_id = blogs_rel_user.user_id
WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
$result = Database::query($sql);
- $select_user_list = '';
-
// Get tasks in this blog / make select list of it
$sql = "
@@ -1572,109 +1566,50 @@ class Blog
WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
ORDER BY system_task, title";
$result = Database::query($sql);
- $select_task_list = '';
-
- // form
- echo '';
+ /**
+ * Displays assign task form
+ * @author Toon Keppens
+ *
+ */
+ public static function display_assign_task_form($blog_id)
+ {
+ $form = self::getTaskForm($blog_id);
+ $form->addHidden('assign_task_submit', 'true');
+ $form->display();
echo '';
}
- /**
+ /**
* Displays assign task form
* @author Toon Keppens
*
*/
- public static function display_edit_assigned_task_form ($blog_id, $task_id, $user_id) {
+ public static function display_edit_assigned_task_form($blog_id, $task_id, $user_id)
+ {
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
@@ -1682,9 +1617,6 @@ class Blog
$course_id = api_get_course_int_id();
- $year = date("Y");
- global $MonthsLong;
-
// Get assignd date;
$sql = "
SELECT target_date
@@ -1696,116 +1628,20 @@ class Blog
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
- $old_date = $row['target_date'];
- $date = explode('-', $row['target_date']);
-
- // Get users in this blog / make select list of it
- $sql = "
- SELECT user.user_id, user.firstname, user.lastname, user.username
- FROM $tbl_users user
- INNER JOIN $tbl_blogs_rel_user blogs_rel_user ON user.user_id = blogs_rel_user.user_id
- WHERE blogs_rel_user.c_id = $course_id AND blogs_rel_user.blog_id = '".(int)$blog_id."'";
- $result = Database::query($sql);
-
- $select_user_list = '';
-
- // Get tasks in this blog / make select list of it
- $sql = "
- SELECT
- blog_id,
- task_id,
- title,
- description,
- color,
- system_task
- FROM " . $tbl_blogs_tasks . "
- WHERE c_id = $course_id AND blog_id = " . (int)$blog_id . "
- ORDER BY system_task, title";
- $result = Database::query($sql);
-
- $select_task_list = '';
-
- // Display
- echo '';
+ $date = $row['target_date'];
+
+ $defaults = [
+ 'task_user_id' => $user_id,
+ 'task_task_id' => $task_id,
+ 'task_day' => $date
+ ];
+ $form = self::getTaskForm($blog_id);
+ $form->addHidden('old_task_id', $task_id);
+ $form->addHidden('old_user_id', $user_id);
+ $form->addHidden('old_target_date', $date);
+ $form->addHidden('assign_task_edit_submit', 'true');
+ $form->setDefaults($defaults);
+ $form->display();
}
/**
@@ -1816,9 +1652,8 @@ class Blog
* @param Integer $task_id
* @param Date $target_date
*/
- public static function assign_task ($blog_id, $user_id, $task_id, $target_date)
+ public static function assign_task($blog_id, $user_id, $task_id, $target_date)
{
-
$tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
$course_id = api_get_course_int_id();
@@ -1831,10 +1666,10 @@ class Blog
AND task_id = " . (int)$task_id . "
";
- $result = @Database::query($sql);
+ $result = Database::query($sql);
$row = Database::fetch_assoc($result);
- if($row['number'] == 0) {
+ if ($row['number'] == 0) {
$sql = "
INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
c_id,
@@ -1850,7 +1685,7 @@ class Blog
'" . Database::escape_string($target_date) . "'
)";
- $result = @Database::query($sql);
+ $result = Database::query($sql);
}
}
@@ -2039,7 +1874,7 @@ class Blog
if(!in_array($user['user_id'],$blog_member_ids)) {
$a_infosUser = UserManager :: get_user_info_by_id($user['user_id']);
$row = array ();
- $row[] = '';
+ $row[] = '';
$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
if ($is_western_name_order) {
$row[] = $a_infosUser["firstname"];
@@ -2129,7 +1964,7 @@ class Blog
while($myrow = Database::fetch_array($sql_result)) {
$row = array ();
- $row[] = '';
+ $row[] = '';
$username = api_htmlentities(sprintf(get_lang('LoginX'), $myrow["username"]), ENT_QUOTES);
if ($is_western_name_order) {
$row[] = $myrow["firstname"];
@@ -2161,7 +1996,7 @@ class Blog
//Link to register users
if($myrow["user_id"] != $_user['user_id']) {
- $row[] = "" . get_lang('UnRegister')."";
+ $row[] = "" . get_lang('UnRegister')."";
} else {
$row[] = '';
}
@@ -2318,38 +2153,34 @@ class Blog
if( Database::num_rows($result) > 0) {
while($blog_post = Database::fetch_array($result)) {
// If the day of this post is not yet in the array, add it.
- if(!in_array($blog_post['post_day'], $posts))
+ if (!in_array($blog_post['post_day'], $posts))
$posts[] = $blog_post['post_day'];
}
}
// Get tasks for this month
- if($_user['user_id']) {
+ if ($_user['user_id']) {
$sql = " SELECT task_rel_user.*, DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
FROM $tbl_blogs_tasks_rel_user task_rel_user
INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
WHERE
- task_rel_user.c_id = $course_id AND
- task.c_id = $course_id AND
- blog.c_id = $course_id AND
- task_rel_user.user_id = '".(int)$_user['user_id']."'
- AND MONTH(target_date) = '".(int)$month."'
- AND YEAR(target_date) = '".(int)$year."'
+ task_rel_user.c_id = $course_id AND
+ task.c_id = $course_id AND
+ blog.c_id = $course_id AND
+ task_rel_user.user_id = '".(int)$_user['user_id']."' AND
+ MONTH(target_date) = '".(int)$month."' AND
+ YEAR(target_date) = '".(int)$year."'
ORDER BY target_date ASC";
$result = Database::query($sql);
- if (Database::num_rows($result) > 0)
- {
- while($mytask = Database::fetch_array($result))
- {
-
+ if (Database::num_rows($result) > 0) {
+ while ($mytask = Database::fetch_array($result)) {
$tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
$tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
$tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
$tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
$tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
- //echo ''.stripslashes($mytask['title']) . '';
}
}
}
@@ -2358,38 +2189,34 @@ class Blog
"\n",
"| « | \n",
"", $monthName, " ", $year, " | \n",
- "» | \n", "
\n";
+ "» | \n", "";
echo "\n";
for($ii = 1; $ii < 8; $ii ++)
- echo "| ", $DaysShort[$ii % 7], " | \n";
+ echo "", $DaysShort[$ii % 7], " | ";
- echo "
\n";
+ echo "";
$curday = -1;
$today = getdate();
- while($curday <= $numberofdays[$month])
- {
- echo "\n";
-
- for($ii = 0; $ii < 7; $ii ++)
- {
- if(($curday == -1) && ($ii == $startdayofweek))
+ while ($curday <= $numberofdays[$month]) {
+ echo "
";
+ for ($ii = 0; $ii < 7; $ii ++) {
+ if (($curday == -1) && ($ii == $startdayofweek))
$curday = 1;
- if(($curday > 0) && ($curday <= $numberofdays[$month])) {
+ if (($curday > 0) && ($curday <= $numberofdays[$month])) {
$bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
$dayheader = "$curday";
- if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon']))
- {
+ if(($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
$dayheader = "$curday";
$class = "class=\"days_today\"";
}
- echo "\t| ";
+ echo " | ";
// If there are posts on this day, create a filter link.
if(in_array($curday, $posts))
@@ -2397,30 +2224,24 @@ class Blog
else
echo $dayheader;
- if (count($tasks) > 0)
- {
- if (is_array($tasks[$curday]))
- {
+ if (count($tasks) > 0) {
+ if (isset($tasks[$curday]) && is_array($tasks[$curday])) {
// Add tasks to calendar
- foreach ($tasks[$curday] as $task)
- {
- echo ' ';
+ foreach ($tasks[$curday] as $task) {
+ echo '
+ ';
}
}
}
- echo " | \n";
-
+ echo "";
$curday ++;
- }
- else
- echo " | \n";
+ } else
+ echo " | ";
}
-
- echo "
\n";
+ echo "";
}
-
- echo "\n";
+ echo "";
}
/**