Skip to content

Commit

Permalink
Add settings for forum posts widget
Browse files Browse the repository at this point in the history
  • Loading branch information
drlippman committed Jan 10, 2014
1 parent d060620 commit 452963f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 9 deletions.
11 changes: 11 additions & 0 deletions actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,17 @@
exit;
}
}
} else if ($_GET['action']=="forumwidgetsettings") {
$checked = $_POST['checked'];
$all = explode(',',$_POST['allcourses']);
foreach ($all as $k=>$v) {
$all[$k] = intval($v);
}
$tohide = array_diff($all,$checked);
$hidelist = implode(',', $tohide);
$query = "UPDATE imas_users SET hideonpostswidget='$hidelist' WHERE id='$userid'";
mysql_query($query) or die("Query failed : " . mysql_error());

} else if ($_GET['action']=="googlegadget") {
if (isset($_GET['clear'])) {
$query = "UPDATE imas_users SET remoteaccess='' WHERE id='$userid'";
Expand Down
1 change: 1 addition & 0 deletions dbsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
. ' `hasuserimg` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\','
. ' `remoteaccess` VARCHAR(10) NOT NULL DEFAULT \'\', '
. ' `listperpage` TINYINT(3) UNSIGNED NOT NULL DEFAULT \'20\', '
. ' `hideonpostswidget` TEXT NOT NULL, '
. ' INDEX (`lastaccess`), INDEX (`rights`), '
. ' UNIQUE (`SID`)'
. ' )'
Expand Down
49 changes: 49 additions & 0 deletions forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,55 @@
echo "<p>Email: <input type=text name=\"email\"/></p>";
echo "<p><input type=submit value=\"Submit\" /></p></form>";
break;
case "forumwidgetsettings":
$query = "SELECT hideonpostswidget FROM imas_users WHERE id='$userid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$hidelist = explode(',', mysql_result($result,0,0));

echo '<div id="headerforms" class="pagetitle"><h2>Forum Widget Settings</h2></div>';
echo '<p>The most recent 10 posts from each course show in the New Forum Posts widget. Select the courses you want to show in the widget.</p>';
echo "<form method=post action=\"actions.php?action=forumwidgetsettings$gb\">\n";
$allcourses = array();
$query = "SELECT ic.id,ic.name FROM imas_courses AS ic JOIN imas_teachers AS it ON ic.id=it.courseid WHERE it.userid='$userid' ORDER BY ic.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<p><b>Courses you\'re teaching:</b> Check: <a href="#" onclick="$(\'.teaching\').prop(\'checked\',true);return false;">All</a> <a href="#" onclick="$(\'.teaching\').prop(\'checked\',false);return false;">None</a>';
while ($row = mysql_fetch_row($result)) {
$allcourses[] = $row[0];
echo '<br/><input type="checkbox" name="checked[]" class="teaching" value="'.$row[0].'" ';
if (!in_array($row[0],$hidelist)) {echo 'checked="checked"';}
echo '/> '.$row[1];
}
echo '</p>';
}
$query = "SELECT ic.id,ic.name FROM imas_courses AS ic JOIN imas_tutors AS it ON ic.id=it.courseid WHERE it.userid='$userid' ORDER BY ic.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<p><b>Courses you\'re tutoring:</b> Check: <a href="#" onclick="$(\'.tutoring\').prop(\'checked\',true);return false;">All</a> <a href="#" onclick="$(\'.tutoring\').prop(\'checked\',false);return false;">None</a>';
while ($row = mysql_fetch_row($result)) {
$allcourses[] = $row[0];
echo '<br/><input type="checkbox" name="checked[]" class="tutoring" value="'.$row[0].'" ';
if (!in_array($row[0],$hidelist)) {echo 'checked="checked"';}
echo '/> '.$row[1];
}
echo '</p>';
}
$query = "SELECT ic.id,ic.name FROM imas_courses AS ic JOIN imas_students AS it ON ic.id=it.courseid WHERE it.userid='$userid' ORDER BY ic.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<p><b>Courses you\'re taking:</b> Check: <a href="#" onclick="$(\'.taking\').prop(\'checked\',true);return false;">All</a> <a href="#" onclick="$(\'.taking\').prop(\'checked\',false);return false;">None</a>';
while ($row = mysql_fetch_row($result)) {
$allcourses[] = $row[0];
echo '<br/><input type="checkbox" name="checked[]" class="taking" value="'.$row[0].'" ';
if (!in_array($row[0],$hidelist)) {echo 'checked="checked"';}
echo '/> '.$row[1];
}
echo '</p>';
}
echo '<input type="hidden" name="allcourses" value="'.implode(',',$allcourses).'"/>';
echo '<input type="submit" value="Save Changes"/>';
echo '</form>';
break;
case "googlegadget":
$query = "SELECT remoteaccess FROM imas_users WHERE id='$userid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
Expand Down
29 changes: 22 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

//pagelayout: array of arrays. pagelayout[0] = fullwidth header, [1] = left bar 25%, [2] = rigth bar 75%
//[3]: 0 for newmsg note next to courses, 1 for newpost note next to courses
$query = "SELECT homelayout FROM imas_users WHERE id='$userid'";
$query = "SELECT homelayout,hideonpostswidget FROM imas_users WHERE id='$userid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$homelayout = mysql_result($result,0,0);
list($homelayout,$hideonpostswidget) = mysql_fetch_row($result);
if ($hideonpostswidget!='') {
$hideonpostswidget = explode(',',$hideonpostswidget);
} else {
$hideonpostswidget = array();
}

$pagelayout = explode('|',$homelayout);
foreach($pagelayout as $k=>$v) {
Expand Down Expand Up @@ -98,7 +103,9 @@
$noclass = false;
$page_studentCourseData[] = $line;
$page_coursenames[$line['id']] = $line['name'];
$postcheckstucids[] = $line['id'];
if (!in_array($line['id'],$hideonpostswidget)) {
$postcheckstucids[] = $line['id'];
}
}
}
}
Expand All @@ -119,7 +126,9 @@
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$page_teacherCourseData[] = $line;
$page_coursenames[$line['id']] = $line['name'];
$postcheckcids[] = $line['id'];
if (!in_array($line['id'],$hideonpostswidget)) {
$postcheckstucids[] = $line['id'];
}
}
}
}
Expand All @@ -138,7 +147,9 @@
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$page_tutorCourseData[] = $line;
$page_coursenames[$line['id']] = $line['name'];
$postcheckstucids[] = $line['id'];
if (!in_array($line['id'],$hideonpostswidget)) {
$postcheckstucids[] = $line['id'];
}
}
}

Expand Down Expand Up @@ -412,9 +423,13 @@ function printMessagesGadget() {

}
function printPostsGadget() {
global $page_newpostlist, $page_coursenames, $postthreads;
global $page_newpostlist, $page_coursenames, $postthreads,$imasroot;

echo '<div class="block">';
//echo "<span class=\"floatright\"><a href=\"#\" onclick=\"GB_show('Forum Widget Settings','$imasroot/forms.php?action=forumwidgetsettings&greybox=true',800,'auto')\" title=\"Forum Widget Settings\"><img style=\"vertical-align:top\" src=\"$imasroot/img/gears.png\"/></a></span>";
echo "<span class=\"floatright\"><a href=\"forms.php?action=forumwidgetsettings\"><img style=\"vertical-align:top\" src=\"$imasroot/img/gears.png\"/></a></span>";

echo '<div class="block"><h3>', _('New forum posts'), '</h3></div>';
echo '<h3>', _('New forum posts'), '</h3></div>';
echo '<div class="blockitems">';
if (count($page_newpostlist)==0) {
echo '<p>', _('No new posts'), '</p>';
Expand Down
10 changes: 8 additions & 2 deletions upgrade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
//change counter; increase by 1 each time a change is made
//TODO: change linked text tex to mediumtext
$latest = 80;
$latest = 81;


@set_time_limit(0);
Expand Down Expand Up @@ -1366,7 +1366,13 @@
echo "and requires updating your local loginpage.php file. See changes to loginpage.php.dist; changes are ";
echo "on lines 9, 69, and 75-76.</p>";
}

if ($last<81) {
$query = 'ALTER TABLE imas_users ADD `hideonpostswidget` TEXT NOT NULL';
$res = mysql_query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".mysql_error()."</p>";
}
}
/*$handle = fopen("upgradecounter.txt",'w');
if ($handle===false) {
echo '<p>Error: unable open upgradecounter.txt for writing</p>';
Expand Down

0 comments on commit 452963f

Please sign in to comment.