PageRenderTime 96ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/email.php

https://github.com/adamfranco/segue-1.x
PHP | 1196 lines | 766 code | 219 blank | 211 comment | 220 complexity | 725ddede9e6a9f0c33dffe11557eb0c6 MD5 | raw file
  1. <?
  2. include("objects/objects.inc.php");
  3. $content = '';
  4. $message = '';
  5. ob_start();
  6. session_start();
  7. // include all necessary files
  8. include("includes.inc.php");
  9. /* if ($_SESSION['ltype'] != 'admin') { */
  10. /* // take them right to the user lookup page */
  11. /* header("Location: username_lookup.php"); */
  12. /* exit; */
  13. /* } */
  14. //printpre($curraction);
  15. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  16. /******************************************************************************
  17. * Action: list, review, user
  18. ******************************************************************************/
  19. if ($_REQUEST['action']) {
  20. $curraction = $_REQUEST['action'];
  21. $action = $_REQUEST['action'];
  22. } else {
  23. $action = 'list';
  24. $curraction = 'list';
  25. }
  26. if ($_REQUEST['email']) {
  27. if ($_REQUEST['action'] == 'send') {
  28. $curraction = 'send';
  29. } else {
  30. $curraction = 'email';
  31. }
  32. $action = 'email';
  33. }
  34. /******************************************************************************
  35. * Determine which subsets of participants will be checked
  36. ******************************************************************************/
  37. if ($_REQUEST[checkclass] == "Check Class only") $_REQUEST[checkgroup] = "Check Class only";
  38. //$checkgroup = $_REQUEST['checkgroup'];
  39. //$checkgroup = "Check Class only";
  40. if ($curraction != "list" && $curraction != "review") $_SESSION[editors] = $_REQUEST['editors'];
  41. //$_SESSION[editors] = $_REQUEST['editors'];
  42. //printpre($_SESSION[editors]);
  43. //printpre($_REQUEST);
  44. /******************************************************************************
  45. * Scope: site, discussion/assessment
  46. ******************************************************************************/
  47. if ($_REQUEST['scope'])
  48. $scope = $_REQUEST['scope'];
  49. else if ($_REQUEST['storyid'])
  50. $scope = 'discussion';
  51. else
  52. $scope = 'site';
  53. $sql = $_REQUEST['sql'];
  54. $query_custom = $_REQUEST['newquery'];
  55. /******************************************************************************
  56. * Sort order:
  57. ******************************************************************************/
  58. if ($_REQUEST['order']) {
  59. $order = urldecode($_REQUEST['order']);
  60. } else if (!$_REQUEST['order'] && $action == "user") {
  61. $order = "discussion_tstamp DESC";
  62. } else if (!isset($order)
  63. || !preg_match('/^[a-z0-9_.]+( (ASC|DESC))?$/i', $order)) {
  64. $order = "user_fname ASC";
  65. }
  66. $orderby = " ORDER BY $order";
  67. /******************************************************************************
  68. * Username and id or findall
  69. ******************************************************************************/
  70. if ($_REQUEST['findall']) {
  71. $userid = "'%'";
  72. $useruname = "";
  73. $find = "";
  74. } else if ($_REQUEST['find']) {
  75. $findall = "";
  76. } else if ($_REQUEST['useruname']) {
  77. $useruname = $_REQUEST['useruname'];
  78. $userid = db_get_value ("user", "user_id", "user_uname = '".addslashes($useruname)."'");
  79. if (!$userid) error("invalid username");
  80. $userfname = db_get_value ("user", "user_fname", "user_id = '".addslashes($userid)."'");
  81. } else if ($_REQUEST['userid']) {
  82. $userid = $_REQUEST['userid'];
  83. } else {
  84. $userid = $_SESSION['aid'];
  85. }
  86. // if full name and not username (ie clicking full name to review...)
  87. if ($_REQUEST['userfname'] && !$_REQUEST['useruname']) {
  88. $userfname = urldecode($_REQUEST['userfname']);
  89. $userfname = db_get_value ("user", "user_fname", "user_id = '".addslashes($userid)."'");
  90. $useruname = db_get_value ("user", "user_uname", "user_id = '".addslashes($userid)."'");
  91. }
  92. /******************************************************************************
  93. * Story and Site ids
  94. ******************************************************************************/
  95. if ($_REQUEST['storyid']) $storyid = $_REQUEST['storyid'];
  96. $siteid = $_REQUEST['siteid'];
  97. $class_id = $_REQUEST['site'];
  98. $site = $_REQUEST['site'];
  99. /******************************************************************************
  100. * STUDENT and CLASS if class get all members of class from ldap
  101. * returns array with uname, fname and type
  102. ******************************************************************************/
  103. $students = array();
  104. $roster_ids = array();
  105. if (isclass($class_id)) {
  106. $students = getclassstudents($class_id);
  107. foreach (array_keys($students) as $key) {
  108. $roster_ids[] = $students[$key][id];
  109. }
  110. //printpre($students);
  111. }
  112. /******************************************************************************
  113. * Add Participants to Roster
  114. ******************************************************************************/
  115. if ($_REQUEST[addtoclass] == "Add Checked to Roster") {
  116. $_SESSION[editors] = $_REQUEST[editors];
  117. foreach($_SESSION[editors] as $studentid) {
  118. //get ids of all student currently in class
  119. $currentstudents = array();
  120. foreach (array_keys($students) as $key) {
  121. $currentstudents[] = $students[$key][id];
  122. }
  123. //add to class roster only if not currently a student
  124. if (!in_array($studentid, $currentstudents)) {
  125. //print "Participants added to roster";
  126. $user_id = $studentid;
  127. $ugroup_id = getClassUGroupId($class_id);
  128. // add them to the ugroup
  129. $query = "
  130. INSERT INTO
  131. ugroup_user
  132. SET
  133. FK_user='".addslashes($user_id)."',
  134. FK_ugroup='".addslashes($ugroup_id)."'
  135. ";
  136. //printpre($query);
  137. db_query($query);
  138. }
  139. }
  140. unset($_SESSION[editors]);
  141. unset($_SESSION[roster_ids]);
  142. unset($_SESSION[non_roster_ids]);
  143. unset($_SESSION[logged_participants_ids]);
  144. $students = getclassstudents($class_id);
  145. foreach (array_keys($students) as $key) {
  146. $roster_ids[] = $students[$key][id];
  147. }
  148. }
  149. /******************************************************************************
  150. * Query: WHERE clause
  151. * story, site, and/or user or
  152. * all users, all sites
  153. ******************************************************************************/
  154. if ($_REQUEST['findall'] && !$_REQUEST['find']) {
  155. $where = "user_id > 0";
  156. } else if ($_REQUEST['find']) {
  157. $useruname = $_REQUEST['useruname'];
  158. $userid = db_get_value ("user", "user_id", "user_uname = '".addslashes($useruname)."'");
  159. if ($userid) {
  160. $where = "user_id = '".addslashes($userid)."'";
  161. } else {
  162. error("invalid username");
  163. $where = "user_id > 0";
  164. }
  165. } else if ($scope == "site") {
  166. $where = "site_id = '".addslashes($siteid)."'";
  167. } else if ($action != "user") {
  168. $where = "story_id = '".addslashes($storyid)."'";
  169. } else if ($userid && $action == "user") {
  170. $where = "user_id = '".addslashes($userid)."'";
  171. }
  172. if ($_REQUEST['userid'] && !$_REQUEST['findall'] && $action == "review" && $_REQUEST['userfname']) {
  173. $where .= " AND user_id = '".addslashes($userid)."'";
  174. }
  175. if ($_REQUEST['findsite'] && $action == "review") {
  176. $findsite = $_REQUEST['findsite'];
  177. $where .= " AND slotname = ''".addslashes($findsite)."''";
  178. }
  179. /******************************************************************************
  180. * Query: SELECT and ORDER clauses
  181. ******************************************************************************/
  182. if ($action == "review" || $action == "user") {
  183. $select = "user_id, user_fname, user_uname, user_email, discussion_rate, discussion_tstamp, discussion_id, discussion_subject, story_id, page_id, page_title, story_text_short, section_id, site_id, slot_name";
  184. if (!isset($order)) $order = "discussion_tstamp ASC";
  185. // action = list, email
  186. } else {
  187. $select = "DISTINCT user_id, user_fname, user_uname, user_email";
  188. $order = "user_fname ASC";
  189. }
  190. /******************************************************************************
  191. * Query: NUMBER of post for given user (i.e. number of posts for WHERE clause)
  192. ******************************************************************************/
  193. $query = "
  194. SELECT
  195. user_id
  196. FROM
  197. discussion
  198. INNER JOIN story ON FK_story = story_id
  199. INNER JOIN page ON FK_page = page_id
  200. INNER JOIN section ON FK_section = section_id
  201. INNER JOIN site ON FK_site = site_id
  202. INNER JOIN user ON FK_author = user_id
  203. WHERE
  204. $where
  205. ";
  206. $r = db_query($query);
  207. $a = db_fetch_assoc($r);
  208. $numrows = db_num_rows($r);
  209. /******************************************************************************
  210. * Query: NUMBER and ID's of participants (i.e. distinct users)
  211. ******************************************************************************/
  212. $query = "
  213. SELECT
  214. DISTINCT user_id
  215. FROM
  216. discussion
  217. INNER JOIN story ON FK_story = story_id
  218. INNER JOIN page ON FK_page = page_id
  219. INNER JOIN section ON FK_section = section_id
  220. INNER JOIN site ON FK_site = site_id
  221. INNER JOIN user ON FK_author = user_id
  222. WHERE
  223. $where
  224. ";
  225. $r = db_query($query);
  226. $a = db_fetch_assoc($r);
  227. $numparticipants = db_num_rows($r);
  228. $logged_participants = db_query($query);
  229. //print $numparticipants."<br />";
  230. if ($action == "list") $numrows = $numparticipants;
  231. //print $numrows."<br />";
  232. ///******************************************************************************
  233. // * Query: GET ids of all participants discussion post information based on select:
  234. // * 1. select summary info for each user
  235. // * 2. select all post info for all specified users
  236. // ******************************************************************************/
  237. //
  238. // $query = "
  239. // SELECT
  240. // $select
  241. // FROM
  242. // discussion
  243. // INNER JOIN story ON FK_story = story_id
  244. // INNER JOIN page ON FK_page = page_id
  245. // INNER JOIN section ON FK_section = section_id
  246. // INNER JOIN site ON section.FK_site = site.site_id
  247. // INNER JOIN slot ON slot.FK_site = site.site_id
  248. // INNER JOIN user ON FK_author = user_id
  249. // WHERE
  250. // $where $orderby
  251. // ";
  252. //
  253. // //printpre($_REQUEST);
  254. // //printpre("where: ".$where);
  255. // //printpre($query);
  256. // //printpre($curraction);
  257. // //$r = db_query($query);
  258. // //$r2 = db_query($query);
  259. // $logged_participants = db_query($query);
  260. printerr();
  261. /******************************************************************************
  262. * SUBSETS of participants
  263. * $logged_participants_ids = ids of all users who have posted to discussion
  264. * $roster_ids = ids of all participants in roster
  265. * $non_roster_ids = ids of all participants not in roster
  266. ******************************************************************************/
  267. $non_roster_ids = array();
  268. $logged_participants_ids = array();
  269. while ($a = db_fetch_assoc($logged_participants)) {
  270. $logged_participant_id = $a[user_id];
  271. $logged_participants_ids[] = $a[user_id];
  272. if (!in_array($logged_participant_id, $roster_ids)) {
  273. $non_roster_ids[] = $logged_participant_id;
  274. }
  275. }
  276. //printpre($roster_ids);
  277. //printpre($non_roster_ids);
  278. //printpre($_SESSION[editors]);
  279. /******************************************************************************
  280. * define limits for pagination of results
  281. ******************************************************************************/
  282. //if (!isset($lowerlimit)) $lowerlimit = 0;
  283. //if (!isset($range)) $range = 30;
  284. //if ($lowerlimit < 0) $lowerlimit = 0;
  285. if (isset($_REQUEST['range']))
  286. $range = intval($_REQUEST['range']);
  287. else
  288. $range = 30;
  289. if (isset($_REQUEST['lowerlimit']))
  290. $lowerlimit = intval($_REQUEST['lowerlimit']);
  291. else
  292. $lowerlimit = 0;
  293. if ($lowerlimit < 0)
  294. $lowerlimit = 0;
  295. $limit = " limit $lowerlimit,30";
  296. if ($action != "list") $limit = " LIMIT $lowerlimit,$range";
  297. /******************************************************************************
  298. * Query: GET all discussion post information based on select:
  299. * 1. select summary info for each user
  300. * 2. select all post info for all specified users
  301. ******************************************************************************/
  302. $query = "
  303. SELECT
  304. $select
  305. FROM
  306. discussion
  307. INNER JOIN story ON FK_story = story_id
  308. INNER JOIN page ON FK_page = page_id
  309. INNER JOIN section ON FK_section = section_id
  310. INNER JOIN site ON section.FK_site = site.site_id
  311. INNER JOIN slot ON slot.FK_site = site.site_id
  312. INNER JOIN user ON FK_author = user_id
  313. WHERE
  314. $where $orderby $limit
  315. ";
  316. //printpre($_REQUEST);
  317. //printpre("where: ".$where);
  318. //printpre($query);
  319. //printpre($curraction);
  320. $r = db_query($query);
  321. $r2 = db_query($query);
  322. //$logged_participants = db_query($query);
  323. printerr();
  324. /******************************************************************************
  325. * Print out HTML
  326. ******************************************************************************/
  327. ?>
  328. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  329. <html>
  330. <head>
  331. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  332. <?
  333. if ($action == "user") {
  334. print "<title>Your Posts</title>";
  335. } else {
  336. print "<title>Participants</title>";
  337. }
  338. include("themes/common/logs_css.inc.php"); ?>
  339. <script type="text/javascript">
  340. // <![CDATA[
  341. function changeOrder(order) {
  342. f = document.searchform;
  343. f.order.value=order;
  344. f.submit();
  345. }
  346. function doWindow(name,width,height) {
  347. var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
  348. win.focus();
  349. }
  350. function sendWindow(name,width,height,url) {
  351. var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
  352. win.document.location=url.replace(/&amp;/, '&');
  353. win.focus();
  354. }
  355. function checkAll() {
  356. field = document.forms[1].elements['editors[]'];
  357. for (i = 0; i < field.length; i++)
  358. field[i].checked = true ;
  359. }
  360. function uncheckAll() {
  361. field = document.forms[1].elements['editors[]'];
  362. for (i = 0; i < field.length; i++)
  363. field[i].checked = false ;
  364. }
  365. function checkGroup() {
  366. selectField = document.forms[1].elements['groupcheck'];
  367. groupName = selectField.value;
  368. field = document.forms[1].elements['editors[]'];
  369. classIds = new Array ();
  370. <?
  371. foreach ($roster_ids as $id)
  372. print "\n\t\tclassIds.push('".$id."');";
  373. ?>
  374. otherIds = new Array ();
  375. <?
  376. foreach ($non_roster_ids as $id)
  377. print "\n\t\totherIds.push('".$id."');";
  378. ?>
  379. switch(groupName) {
  380. case 'all':
  381. checkAll();
  382. break;
  383. case 'un_all':
  384. uncheckAll();
  385. break;
  386. case 'class':
  387. checkArrayMembersInField(classIds, field, true);
  388. break;
  389. case 'un_class':
  390. checkArrayMembersInField(classIds, field, false);
  391. break;
  392. case 'other':
  393. checkArrayMembersInField(otherIds, field, true);
  394. break;
  395. case 'un_other':
  396. checkArrayMembersInField(otherIds, field, false);
  397. break;
  398. }
  399. }
  400. function checkArrayMembersInField (arrayToCheck, field, checkValue) {
  401. for (i=0; i<arrayToCheck.length; i++) {
  402. id = arrayToCheck[i];
  403. for (j = 0; j < field.length; j++) {
  404. if (field[j].value == id)
  405. field[j].checked = checkValue;
  406. }
  407. }
  408. }
  409. function doFieldChange(user,scope,site,section,page,story,field,what) {
  410. f = document.addform;
  411. f.fieldchange.value = 1;
  412. f.puser.value = user;
  413. f.pscope.value = scope;
  414. f.psite.value = site;
  415. f.psection.value = section;
  416. f.ppage.value = page;
  417. f.pstory.value = story;
  418. f.pfield.value = field;
  419. f.pwhat.value = what;
  420. f.submit();
  421. }
  422. // ]]>
  423. </script>
  424. </head>
  425. <body>
  426. <?
  427. //printpre($_REQUEST);
  428. /******************************************************************************
  429. * If admin print out admin tools (e.g. add/edit users, classes, slots updates
  430. ******************************************************************************/
  431. if ($_SESSION['ltype']=='admin') {
  432. print "\n\t<table width='100%' class='bg'>";
  433. print "\n\t\t<tr>\n\t\t\t<td class='bg'>";
  434. print "\n\t\t\t\tLogs: <a href='viewsites.php?$sid&amp;site=$site'>sites</a>";
  435. print "\n\t\t\t\t | <a href='viewlogs.php?$sid&amp;site=$site'>users</a>";
  436. print "\n\t\t\t</td>\n\t\t\t<td align='right' class='bg'>";
  437. print "\n\t\t\t\t<a href='users.php?$sid&amp;site=$site'>add/edit users</a> | ";
  438. print "\n\t\t\t\t<a href='classes.php?$sid&amp;site=$site'>add/edit classes</a> | ";
  439. print "\n\t\t\t\t<a href='add_slot.php?$sid&amp;site=$site'>add/edit slots</a> | ";
  440. print "\n\t\t\t\t<a href='update.php?$sid&amp;site=$site'>segue updates</a>";
  441. print "\n\t\t\t</td>\n\t\t</tr>";
  442. print "\n\t</table>";
  443. }
  444. /******************************************************************************
  445. * Links: Roster | Participation | Logs | Your Posts
  446. ******************************************************************************/
  447. print "\n\t<table width='100%' class='bg'>";
  448. // for admins print out participation select and where and order by sql
  449. print "\n\t\t<tr>\n\t\t\t<td class='bg'>";
  450. if ($_SESSION['ltype']=='admin') {
  451. //print $action.": ";
  452. //print "WHERE ".$where." ORDER BY ";
  453. //print $order;
  454. }
  455. print "\n\t\t\t</td>";
  456. print "\n\t\t\t<td class='bg' align='right'>";
  457. // roster
  458. if (isclass($_REQUEST[site])) print "\n\t\t\t\t<a href='add_students.php?$sid&amp;name=$site&amp;scope=$scope&amp;storyid=".$_REQUEST['storyid']."'>Roster</a> |";
  459. // participation (not link when coming from home)
  460. if ($_REQUEST[from] != "home") {
  461. if ($action == "user") {
  462. print "\n\t\t\t\t <a href='email.php?$sid&amp;siteid=$siteid&amp;storyid=$storyid&amp;site=$site&amp;scope=$scope&amp;action=list'>Participation</a>";
  463. } else {
  464. print " Participation";
  465. }
  466. if ($action == "user") {
  467. print " - Your Posts";
  468. } else {
  469. print "\n\t\t\t\t - <a href='email.php?$sid&amp;siteid=$siteid&amp;storyid=$storyid&amp;scope=$scope&amp;site=$site&amp;action=user'>Your Posts</a>";
  470. }
  471. // logs (not link when coming from home)
  472. print "\n\t\t\t\t | <a href='viewlogs.php?$sid&amp;site=$site&amp;storyid=$storyid&amp;scope=$scope&amp;'>Logs</a>";
  473. } else {
  474. print "\n\t\t\t\t Your Posts";
  475. }
  476. print "\n\t\t\t</td>\n\t\t</tr>";
  477. print "\n\t</table>\n\t<br />";
  478. ?>
  479. <?=$content?>
  480. <table cellspacing='1' width='100%' id='maintable'>
  481. <tr>
  482. <td>
  483. <form action="<? echo $PHP_SELF ?>" method='get' name='searchform'>
  484. <table cellspacing='1' width='100%'>
  485. <tr>
  486. <td>
  487. <input type='hidden' name='order' value='<? echo urlencode($order) ?>' />
  488. <input type='hidden' name='action' value='<? echo $action ?>' />
  489. <input type='hidden' name='checkgroup' value='<? echo $checkgroup ?>' />
  490. <input type='hidden' name='storyid' value='<? echo $storyid ?>' />
  491. <input type='hidden' name='siteid' value='<? echo $siteid ?>' />
  492. <input type='hidden' name='site' value='<? echo $site ?>' />
  493. <input type='hidden' name='userid' value='<? echo $userid ?>' />
  494. <input type='hidden' name='from' value='<? echo $from ?>' />
  495. <input type='hidden' name='findall' value='<? echo $findall ?>' />
  496. <input type='hidden' name='find' value='<? echo $find ?>' />
  497. <input type='hidden' name='findsite' value='<? echo $findsite ?>' />
  498. <input type='hidden' name='userfname' value='<? echo urlencode($userfname) ?>' />
  499. </td>
  500. <td align='right'>
  501. <?
  502. //$order = urlencode($order);
  503. if ($curraction == 'user') {
  504. $getvariables = "storyid=$storyid&siteid=$siteid&scope=$scope";
  505. } else {
  506. $getvariables = "storyid=$storyid&siteid=$siteid&site=$site&scope=$scope";
  507. }
  508. if ($userid) {
  509. $userfname = urlencode($userfname);
  510. $getusers = "&userid=$userid&userfname=$userfname";
  511. }
  512. $tpages = ceil($numrows/$range);
  513. $curr = ceil(($lowerlimit+$range)/$range);
  514. $prev = $lowerlimit-$range;
  515. if ($prev < 0) $prev = 0;
  516. $next = $lowerlimit+$range;
  517. if ($next >= $numrows) $next = $numrows-$range;
  518. if ($next < 0) $next = 0;
  519. if ($action != "list") {
  520. print "$curr of $tpages ";
  521. if ($prev != $lowerlimit)
  522. if (!$userfname) {
  523. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&lt;&lt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=".$prev."&".$getvariables."&action=".$curraction."\"' />";
  524. } else {
  525. //$userfname = urlencode($userfname);
  526. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&lt;&lt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=".$prev."&".$getvariables."&action=$curraction&userfname=$userfname&userid=$userid\"' />";
  527. }
  528. if ($next != $lowerlimit && $next > $lowerlimit)
  529. if (!$userfname) {
  530. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&gt;&gt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=".$next."&".$getvariables."&action=$curraction\"' />";
  531. } else {
  532. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&gt;&gt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=".$next."&".$getvariables."&action=$curraction&userfname=$userfname&userid=$userid\"' />";
  533. }
  534. }
  535. ?>
  536. </td>
  537. </tr>
  538. </table>
  539. </form>
  540. <form action="<? echo $PHP_SELF ?>" method='post'>
  541. <input type='hidden' name='storyid' value='<? echo $storyid ?>' />
  542. <input type='hidden' name='siteid' value='<? echo $siteid ?>' />
  543. <input type='hidden' name='site' value='<? echo $site ?>' />
  544. <?
  545. if ($numparticipants == 0) {
  546. print "No participants found. Try extending the scope to all participants in the site";
  547. }
  548. /******************************************************************************
  549. * depending on action print out either:
  550. * list of participants
  551. * email UI
  552. * sent email confirmation
  553. ******************************************************************************/
  554. /******************************************************************************
  555. * Navigation Email | List | Review participants in discussion or site
  556. ******************************************************************************/
  557. print "\n\t\t\t\t<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td style='font-size: 12px'>";
  558. // lists all participants with summary of posts and avg. rating
  559. if ($curraction == "list") {
  560. //print "<a href='$PHP_SELF?$sid&amp;action=email&".$getvariables.$getusers."'>Email</a> | ";
  561. print "\n\t\t\t\t\t\t\tList | ";
  562. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;".htmlspecialchars($getvariables)."&amp;order=$order'>Review</a> - ";
  563. print $numparticipants." participants";
  564. // reviews posts by a given user to a given site/discussion/assessment
  565. // or reviews all posts by all users to a given site/discussion/assessment
  566. } else if ($curraction == 'review') {
  567. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=list&amp;".htmlspecialchars($getvariables)."&amp;order=user_fname'>List</a> | ";
  568. if ($_REQUEST['userid']) {
  569. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;".htmlspecialchars($getvariables)."'>Review all</a> - ";
  570. print $numrows." posts from ".urldecode($userfname);
  571. } else {
  572. print "\n\t\t\t\t\t\t\tReview - ";
  573. print $numrows." posts from ".$numparticipants." participants";
  574. }
  575. // displays all posts of a given user across all sites
  576. } else if ($curraction == 'user') {
  577. if ($_SESSION['ltype'] == "admin") {
  578. print "\n\t\t\t\t\t\t\tusername: <input type='text' name='useruname' value='".$useruname."' class='textfield' />";
  579. print "\n\t\t\t\t\t\t\t <input type='submit' name='find' value='Find' />";
  580. print "\n\t\t\t\t\t\t\t <input type='submit' name='findall' value='Find All' /> ";
  581. }
  582. if ($userid) {
  583. print "\n\t\t\t\t\t\t\t".$numrows." posts";
  584. }
  585. print "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
  586. // emails all participants currently listed
  587. } else if ($curraction == 'email') {
  588. //print "Email | ";
  589. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=list&amp;".htmlspecialchars($getvariables)."&amp;order=user_fname'>List</a> | ";
  590. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;".htmlspecialchars($getvariables)."'>Review</a> - ";
  591. print $numparticipants." participants";
  592. // sends email to all participants in email list
  593. } else if ($curraction == 'send') {
  594. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=list&amp;".htmlspecialchars($getvariables)."&amp;order=user_fname'>List</a> | ";
  595. print "\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;".htmlspecialchars($getvariables).htmlspecialchars($getusers)."&amp;order=$order'>Review</a> - ";
  596. print "\n\t\t\t\t\t\t\t".$numparticipants." participants";
  597. }
  598. // if action is not listing of a user's posts across all sites, then include scope
  599. // select (i.e. participants in this discussions/assessment or in this site
  600. if ($curraction != 'user') {
  601. print " in this ";
  602. print "\n\t\t\t\t\t\t\t<select name='scope'>";
  603. // if viewed from roster, then no storyid and no specific discussion/assessment is viewable
  604. if ($_REQUEST[storyid] != "") {
  605. print "\n\t\t\t\t\t\t\t\t<option value='discussion'";
  606. if ($scope=='discussion')
  607. print " selected='selected'";
  608. print ">discussion/assessment</option>";
  609. }
  610. if ($scope=='site' || $_REQUEST[site] != "") {
  611. print "\n\t\t\t\t\t\t\t\t<option";
  612. ($scope=='site')? print " value='site' selected='selected'": print "";
  613. print ">site</option>";
  614. }
  615. print "\n\t\t\t\t\t\t\t</select>";
  616. print "\n\t\t\t\t\t\t\t<input type='submit' name='update' value='Update' />";
  617. print "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
  618. /******************************************************************************
  619. * Buttons:
  620. * check all/uncheck all buttons, check class only
  621. * add checked to roster, email checked participants
  622. ******************************************************************************/
  623. $selectbuttons .= "\n\t\t\t\t\t\t\t<select name='groupcheck' onchange='checkGroup()'>";
  624. $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value=''>Check...</option>";
  625. $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='all'>Check All</option>";
  626. $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='un_all'>Uncheck All</option>";
  627. if (isclass($_REQUEST[site])) $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='class'>Check Roster Participants</option>";
  628. if (isclass($_REQUEST[site])) $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='un_class'>Uncheck Roster Participants</option>";
  629. if (isclass($_REQUEST[site])) $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='other'>Check Other Participants</option>";
  630. if (isclass($_REQUEST[site])) $selectbuttons .= "\n\t\t\t\t\t\t\t\t<option value='un_other'>uncheck Other Participants</option>";
  631. $selectbuttons .= "\n\t\t\t\t\t\t\t</select> ";
  632. if (isclass($_REQUEST[site])) $buttons .= "\n\t\t\t\t\t\t\t<input type='submit' name='addtoclass' value='Add Checked to Roster' /> ";
  633. $buttons .= "\n\t\t\t\t\t\t\t<input type='submit' name='email' value='Email Checked Participants-&gt;' onclick=\"for (var i = 0; i < this.form.elements.length; i++) {if (this.form.elements[i].name == 'editors[]' && this.form.elements[i].checked) {return true;}} alert('None selected'); return false;\" />";
  634. if ($action != 'email') {
  635. print "\n\t\t\t\t\t<tr>";
  636. print "\n\t\t\t\t\t\t<td align='left' colspan='2'>";
  637. print $selectbuttons;
  638. print $buttons;
  639. print "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
  640. }
  641. }
  642. ?>
  643. </table>
  644. <?
  645. /******************************************************************************
  646. * if action is email, then compile to list and print out email UI
  647. ******************************************************************************/
  648. if ($curraction == 'email') {
  649. $emaillist = array();
  650. foreach ($_REQUEST[editors] as $editor) {
  651. $editor_email = db_get_value("user","user_email", "user_id ='".addslashes($editor)."'");
  652. $editor_fname = db_get_value("user","user_fname", "user_id ='".addslashes($editor)."'");
  653. $editor_femail = $editor_fname."<".$editor_email.">";
  654. array_push($emaillist, $editor_femail);
  655. $emaillist = array_unique($emaillist);
  656. }
  657. $to = implode(", ", $emaillist);
  658. //compile from and cc into headers
  659. if ($_SESSION['ltype']=='admin' && $_SESSION['lfname'] != $_SESSION['afname']) {
  660. $from = $_SESSION['lfname']." as ".$_SESSION['afname']." <".$_SESSION['aemail'].">";
  661. } else {
  662. $from = $_SESSION['afname']." <".$_SESSION['aemail'].">";
  663. }
  664. $headers = "From: ".$from."\n";
  665. $headers .= "Cc: ".$from."\n";
  666. //add content type to header
  667. $html = 1;
  668. if ($html == 1) {
  669. $headers .= "Content-Type: text/html\n";
  670. }
  671. //$text = "email text here";
  672. //$textarea = "email";
  673. ?>
  674. <form action="<? echo $PHP_SELF ?>" method='post' name='emailform'>
  675. <table width='100%'>
  676. <tr>
  677. <td align='right'>To:</td>
  678. <td><? echo $to ?></td>
  679. <td align='right'></td>
  680. </tr>
  681. <? if ($_SESSION['ltype']=='admin' && $_SESSION['lfname'] != $_SESSION['afname']) {
  682. print "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='right'>From:</td>\n\t\t\t\t\t\t\t\t<td>".$_SESSION['lfname']." as ".$_SESSION['afname']."</td>\n\t\t\t\t\t\t\t\t<td align='right'></td>\n\t\t\t\t\t\t\t</tr>";
  683. } else {
  684. print "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='right'>From:</td>\n\t\t\t\t\t\t\t\t<td>".$_SESSION['afname']."</td>\n\t\t\t\t\t\t\t\t<td align='right'></td>\n\t\t\t\t\t\t\t</tr>";
  685. }
  686. ?>
  687. <tr>
  688. <td align='right'>Cc:</td>
  689. <td><? echo $_SESSION['afname'] ?></td>
  690. <td align='right'></td>
  691. </tr>
  692. <tr>
  693. <td align='right'>Subject</td>
  694. <td>
  695. <input type='text' name='subject' value='' size='50' />
  696. <input type='submit' name='email' value='Send' />
  697. </td>
  698. <td align='left'></td>
  699. </tr>
  700. <tr>
  701. <td></td>
  702. <td align='left'>
  703. <?
  704. require_once("htmleditor/editor.inc.php");
  705. include("sniffer.inc.php");
  706. addeditor ("body",80,20,$text,"discuss");
  707. print $content;
  708. ?>
  709. </td>
  710. <td align='right'></td>
  711. </tr>
  712. </table>
  713. <input type='hidden' name='action' value='send' />
  714. <input type='hidden' name='scope' value='<? echo $scope ?>' />
  715. <input type='hidden' name='storyid' value='<? echo $storyid ?>' />
  716. <input type='hidden' name='siteid' value='<? echo $siteid ?>' />
  717. <input type='hidden' name='site' value='<? echo $site ?>' />
  718. <input type='hidden' name='to' value='<? echo $to ?>' />
  719. <input type='hidden' name='headers' value='<? echo $headers ?>' />
  720. </form>
  721. <?
  722. // $r = db_query($query);
  723. exit();
  724. /******************************************************************************
  725. * if action is send then mail subject and body
  726. ******************************************************************************/
  727. } else if ($curraction == 'send') {
  728. $to = $_REQUEST[to];
  729. $body = $_REQUEST[body];
  730. $headers = $_REQUEST[headers];
  731. if ($_SESSION['ltype']=='admin' && $_SESSION['lfname'] != $_SESSION['afname']) {
  732. $subject = $_REQUEST[subject]." (sent by Segue Admin: ".$_SESSION['lfname'].")";
  733. } else {
  734. $subject = $_REQUEST[subject];
  735. }
  736. print "\n\t\t\t\t\t<table>";
  737. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>To:</td>\n\t\t\t\t\t\t<td>".$to."</td>\n\t\t\t\t\t</tr>";
  738. print "\n\t\t\t\t\t<br /><hr />"; // BAD!
  739. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>From:</td>\n\t\t\t\t\t\t<td>".$_SESSION['afname']."</td>\n\t\t\t\t\t</tr>";
  740. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Cc:</td>\n\t\t\t\t\t\t<td>".$_SESSION['afname']."</td>\n\t\t\t\t\t</tr>";
  741. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Subject:</td>\n\t\t\t\t\t<td>".$subject."</td>\n\t\t\t\t\t</tr>";
  742. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td>".$body."</td>\n\t\t\t\t\t</tr>";
  743. print "\n\t\t\t</table>";
  744. if (!mail($to, $subject, $body, $headers))
  745. print "\n\t\t\t\tAN ERROR OCCURED SENDING MAIL!";
  746. ;
  747. exit();
  748. }
  749. // }
  750. /******************************************************************************
  751. * Print out table of participant names
  752. ******************************************************************************/
  753. ?>
  754. <table width='100%'>
  755. <tr>
  756. <th>edit</th>
  757. <?
  758. print "\n\t\t\t\t\t\t<th><a href='#' onclick=\"changeOrder('";
  759. if ($order =='user_fname desc') print "user_fname asc";
  760. else print "user_fname desc";
  761. print "')\">Participant Name";
  762. if ($order =='user_fname asc') print " &or;";
  763. if ($order =='user_fname desc') print " &and;";
  764. print "</a></th>";
  765. if ($curraction == 'review' || $curraction == 'user') {
  766. if ($curraction == 'user')
  767. print "\n\t\t\t\t\t\t<th>Site</th>";
  768. print "\n\t\t\t\t\t\t<th>Page > Topic</th>";
  769. print "\n\t\t\t\t\t\t<th>discussion_subject</th>";
  770. print "\n\t\t\t\t\t\t<th><a href='#' onclick=\"changeOrder('";
  771. if ($order =='discussion_rate asc') print "discussion_rate desc";
  772. else print "discussion_rate asc";
  773. print "')\">Rating<br />Grade";
  774. if ($order =='discussion_rate asc') print " &or;";
  775. if ($order =='discussion_rate desc') print " &and;";
  776. print "</a></th>";
  777. print "\n\t\t\t\t\t\t<th><a href='#' onclick=\"changeOrder('";
  778. if ($order =='discussion_tstamp asc') print "discussion_tstamp desc";
  779. else print "discussion_tstamp asc";
  780. print "')\">Date Time";
  781. if ($order =='discussion_tstamp asc') print " &or;";
  782. if ($order =='discussion_tstamp desc') print " &and;";
  783. print "</a></th>";
  784. } else {
  785. print "\n\t\t\t\t\t\t<th>Email</th>";
  786. print "\n\t\t\t\t\t\t<th># of Posts</th>";
  787. print "\n\t\t\t\t\t\t<th>Avg. Rating/Grade</th>";
  788. }
  789. ?>
  790. </tr>
  791. <?
  792. /******************************************************************************
  793. * if a class site, print out list of students
  794. * if student has participated get post stats
  795. * get # of posts and avg. rating
  796. ******************************************************************************/
  797. $color = 0;
  798. $logged_students_id = array();
  799. if (is_array($students) && $curraction == 'list' && isclass($_REQUEST[site])) {
  800. $rostercount = count($students);
  801. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='4'>\n\t\t\t\t\t\t\t<b>".$rostercount." Participants from Roster</b>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
  802. foreach (array_keys($students) as $key) {
  803. $e = $students[$key][id];
  804. // if (!$_SESSION[editors]) {
  805. // $checkstatus = " checked='checked'";
  806. // } else if (in_array($e,$_SESSION[editors])) {
  807. // $checkstatus = " checked='checked'";
  808. // } else {
  809. // $checkstatus = "";
  810. // }
  811. print "\n\t\t\t\t\t<tr>";
  812. // if not in logged participant array, then just print out name
  813. if (!in_array($students[$key]['id'], $logged_participants_ids)) {
  814. print "\n\t\t\t\t\t\t<td class='td$color' align='center'>\n\t\t\t\t\t\t\t<input type='checkbox' name='editors[]' value='$e' ".$checkstatus." /></td>";
  815. print "\n\t\t\t\t\t\t<td class='td$color'>".$students[$key][fname]."</td>";
  816. print "\n\t\t\t\t\t\t<td class='td$color'>".$students[$key][email]."</td>";
  817. print "\n\t\t\t\t\t\t<td class='td$color'>0</td>";
  818. print "\n\t\t\t\t\t\t<td class='td$color'></td>";
  819. // if in logged participants, then query for post and print summary
  820. } else {
  821. $userid = $students[$key]['id'];
  822. $postcount = getNumPosts($userid);
  823. $avg_rating = getAvgRating($userid);
  824. print "\n\t\t\t\t\t\t<td class='td$color' align='center'>\n\t\t\t\t\t\t\t<input type='checkbox' name='editors[]' value='$e' ".$checkstatus." />\n\t\t\t\t\t\t</td>";
  825. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;userid=".$students[$key][id]."&amp;userfname=".urlencode($students[$key][fname])."&amp;".htmlspecialchars($getvariables)."'>".$students[$key][fname]."</a\n\t\t\t\t\t\t></td>";
  826. print "\n\t\t\t\t\t\t<td class='td$color'>".$students[$key][email]."</td>";
  827. print "\n\t\t\t\t\t\t<td class='td$color'>".$postcount."</td>";
  828. print "\n\t\t\t\t\t\t<td class='td$color'>".$avg_rating."</td>";
  829. $logged_students_id[] = $students[$key][id];
  830. }
  831. print "\n\t\t\t\t\t</tr>";
  832. $color = 1-$color;
  833. }
  834. }
  835. if ($curraction == 'list' && is_array($students) && isclass($_REQUEST[site]))
  836. print "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='4'>\n\t\t\t\t\t\t\t<b>Participants not in Roster</b>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
  837. $logged_participants = array();
  838. while ($a = db_fetch_assoc($r)) {
  839. $userid = $a['user_id'];
  840. $e = $a['user_id'];
  841. /******************************************************************************
  842. * if listing participants and site has roster,
  843. * include here only non-roster participants (roster participants listed above)
  844. * for each participant get # of posts and avg. rating
  845. ******************************************************************************/
  846. if (!in_array($userid, $logged_students_id) && $curraction == 'list') {
  847. $userid = $a[user_id];
  848. $logged_participants[] = $a[user_uname];
  849. $postcount = getNumPosts($userid);
  850. $avg_rating = getAvgRating($userid);
  851. // if (!$_SESSION[editors]) {
  852. // $checkstatus = " checked='checked'";
  853. // } else if (in_array($e,$_SESSION[editors])) {
  854. // $checkstatus = " checked='checked'";
  855. // } else {
  856. // $checkstatus = "";
  857. // }
  858. print "\n\t\t\t\t\t<tr>";
  859. print "\n\t\t\t\t\t\t<td class='td$color' align='center'>\n\t\t\t\t\t\t\t<input type='checkbox' name='editors[]' value='$e' ".$checkstatus." />\n\t\t\t\t\t\t</td>";
  860. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;userid=".$a['user_id']."&amp;userfname=".urlencode($a['user_fname'])."&amp;".htmlspecialchars($getvariables)."'>".$a['user_fname']."</a>\n\t\t\t\t\t\t</td>";
  861. print "\n\t\t\t\t\t\t<td class='td$color'>".$a['user_email']."</td>";
  862. print "\n\t\t\t\t\t\t<td class='td$color'>".$postcount."</td>";
  863. print "\n\t\t\t\t\t\t<td class='td$color'>".$avg_rating."</td>";
  864. print "\n\t\t\t\t\t</tr>";
  865. }
  866. $discussion_date = $a['discussion_tstamp'];
  867. $discussion_date = timestamp2usdate($discussion_date);
  868. if ($action == "user") $sitename = $a['slot_name'];
  869. $page_link = $_full_uri."/index.php?action=site&amp;site=".$a['slot_name']."&amp;section=".$a['section_id']."&amp;page=".$a['page_id'];
  870. $fullstory_link = $_full_uri."/index.php?action=site&amp;site=".$a['slot_name']."&amp;section=".$a['section_id']."&amp;page=".$a['page_id']."&amp;story=".$a['story_id']."&amp;detail=".$a['story_id'];
  871. $dicuss_link = $_full_uri."/index.php?action=site&amp;site=".$a['slot_name']."&amp;section=".$a['section_id']."&amp;page=".$a['page_id']."&amp;story=".$a['story_id']."&amp;detail=".$a['story_id']."#".$a['discussion_id'];
  872. $shory_text_all = strip_tags(urldecode($a['story_text_short']));
  873. $shory_text = substr($shory_text_all,0,15)."...";
  874. $discussion_subject_all = urldecode($a['discussion_subject']);
  875. $discussion_subject = substr($discussion_subject_all,0,15)."...";
  876. /******************************************************************************
  877. * Print Participants (depends on curraction
  878. * Review: participant name, page > topic, discussion subject, rating, time
  879. * User: participant name, site, page > topic, discussion subject, rating, time
  880. * List: participant name, email, # of posts, average rating
  881. ******************************************************************************/
  882. if ($curraction == 'review' || $curraction == 'user') {
  883. print "\n\t\t\t\t\t<tr>";
  884. // user full name
  885. if ($curraction == 'user') {
  886. print "\n\t\t\t\t\t\t<td class='td$color' align='center'>\n\t\t\t\t\t\t\t<input type='checkbox' name='editors[]' value='$e' ".$checkstatus." />\n\t\t\t\t\t\t</td>";
  887. print "\n\t\t\t\t\t\t<td class='td$color'>".$a['user_fname']." (".$a['user_uname'].")</td>";
  888. } else {
  889. print "\n\t\t\t\t\t\t<td class='td$color' align='center'>\n\t\t\t\t\t\t\t<input type='checkbox' name='editors[]' value='$e' ".$checkstatus." />\n\t\t\t\t\t\t</td>";
  890. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='$PHP_SELF?$sid&amp;action=review&amp;userid=".$a['user_id']."&amp;userfname=".urlencode($a['user_fname'])."&amp;".htmlspecialchars($getvariables)."'>".$a['user_fname']."</a>\n\t\t\t\t\t\t</td>";
  891. }
  892. //site links
  893. if ($curraction == 'user') {
  894. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='#' onclick='opener.window.location=\"$_full_uri/index.php?action=site&site=".$a['slot_name']."\"'>".$a['slot_name']."</a>\n\t\t\t\t\t\t</td>";
  895. }
  896. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='#' onclick='opener.window.location=\"$page_link\"'>".$a['page_title']."</a> &gt; \n\t\t\t\t\t\t\t<a href='#' onclick='opener.window.location=\"$fullstory_link\"'>".$shory_text."</a>\n\t\t\t\t\t\t</td>";
  897. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='#' onclick='opener.window.location=\"$dicuss_link\"'>".$discussion_subject."</a>\n\t\t\t\t\t\t</td>";
  898. print "\n\t\t\t\t\t\t<td class='td$color'>".$a['discussion_rate']."</td>";
  899. print "\n\t\t\t\t\t\t<td class='td$color'>\n\t\t\t\t\t\t\t<a href='#' onclick='opener.window.location=\"$dicuss_link\"'>".$discussion_date."</a>\n\t\t\t\t\t\t</td>";
  900. print "\n\t\t\t\t\t</tr>";
  901. }
  902. $color = 1-$color;
  903. }
  904. ?>
  905. </table>
  906. <?
  907. if ($action != 'email') {
  908. // print $selectbuttons;
  909. print $buttons;
  910. }
  911. ?>
  912. </form>
  913. </td>
  914. </tr>
  915. </table>
  916. <br />
  917. <div align='right'>
  918. <input type='button' value='Close Window' onclick='window.close()' />
  919. </div>
  920. <?
  921. function getNumPosts ($userid) {
  922. global $where, $orderby, $limit;
  923. $query2 = "
  924. SELECT
  925. user_id, user_email, discussion_rate, discussion_tstamp
  926. FROM
  927. discussion
  928. INNER JOIN story ON FK_story = story_id
  929. INNER JOIN page ON FK_page = page_id
  930. INNER JOIN section ON FK_section = section_id
  931. INNER JOIN site ON FK_site = site_id
  932. INNER JOIN user ON FK_author = user_id
  933. WHERE
  934. $where AND user_id = '".addslashes($userid)."'
  935. ";
  936. $r2 = db_query($query2);
  937. //$a2 = db_fetch_assoc($r2);
  938. $postcount = db_num_rows($r2);
  939. return $postcount;
  940. }
  941. function getAvgRating ($userid) {
  942. global $where, $orderby, $limit;
  943. $query2 = "
  944. SELECT
  945. user_id, user_email, discussion_rate, discussion_tstamp
  946. FROM
  947. discussion
  948. INNER JOIN story ON FK_story = story_id
  949. INNER JOIN page ON FK_page = page_id
  950. INNER JOIN section ON FK_section = section_id
  951. INNER JOIN site ON FK_site = site_id
  952. INNER JOIN user ON FK_author = user_id
  953. WHERE
  954. $where AND user_id = '".addslashes($userid)."'
  955. ";
  956. $r2 = db_query($query2);
  957. $postcount = db_num_rows($r2);
  958. $rating_sum = 0;
  959. if ($postcount == 1) {
  960. $avg_rating = $a2['discussion_rate'];
  961. } else {
  962. $adjpostcount = $postcount;
  963. while ($a2 = db_fetch_assoc($r2)) {
  964. if ($a2['discussion_rate'] == 0)
  965. $adjpostcount = $adjpostcount - 1;
  966. $rating_sum = $rating_sum + $a2['discussion_rate'];
  967. }
  968. if ($adjpostcount)
  969. $avg_rating = round($rating_sum/$adjpostcount, 1);
  970. else
  971. $avg_rating = "n/a";
  972. }
  973. return $avg_rating;
  974. }
  975. ?>
  976. </body>
  977. </html>