PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/sitelisting.php

https://github.com/adamfranco/segue-1.x
PHP | 380 lines | 257 code | 51 blank | 72 comment | 60 complexity | 047ffa8a7d4e54c98b6a1652b056ab2c MD5 | raw file
  1. <? /* $Id$ */
  2. // we need to include object files before session_start() or registered
  3. // objects will be broken.
  4. include("objects/objects.inc.php");
  5. $content = '';
  6. $numPerPage = 30;
  7. ob_start();
  8. session_start();
  9. // include all necessary files
  10. include("includes.inc.php");
  11. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  12. if ($_REQUEST[order])
  13. $order = $_REQUEST[order];
  14. if ($_REQUEST[site])
  15. $site = $_REQUEST[site];
  16. if ($_REQUEST[user])
  17. $user = $_REQUEST[user];
  18. if ($_REQUEST[title]) {
  19. $title = $_REQUEST[title];
  20. } else {
  21. $title = "";
  22. }
  23. if (!isset($order)
  24. || !preg_match('/^[a-z0-9_.]+( (ASC|DESC))?$/i', $order))
  25. $order = "editedtimestamp DESC";
  26. $orderby = " ORDER BY $order";
  27. if ($_REQUEST[clear]=="clear") {
  28. $type = "";
  29. $user = "";
  30. $site = "";
  31. $title = "";
  32. //$type = "%";
  33. //$active = "%";
  34. }
  35. //printpre ($_REQUEST);
  36. $w = array();$wExtra=array();
  37. //if ($_REQUEST[type]) $w[]="slot_type like '%$type%'";
  38. if ($cfg[allowpersonalsites] && $cfg[allowclasssites])
  39. $w[]="(slot_type='personal' OR slot_type='class' OR slot_type='other')";
  40. else if ($cfg[allowpersonalsites]) $w[]="(slot_type='personal' OR slot_type='other')";
  41. else if ($cfg[allowclasssites]) $w[]="slot_type='class'";
  42. if ($user) $wExtra[]="user_uname like '%".addslashes($user)."%'";
  43. if ($site) $wExtra[]="slot_name like '%".addslashes($site)."%'";
  44. if ($title) $wExtra[]="site_title like '%".addslashes($title)."%'";
  45. $w[] = "site_active='1'";
  46. $w[] = "site_listed='1'";
  47. //if ($_REQUEST[active]) $w[]="site_active like '%$active%'";
  48. if (count($w)) {
  49. $where = " where ".implode(" and ",$w);
  50. $where2 = " where ".implode(" and ",array_merge($w,$wExtra));
  51. }
  52. $query = "
  53. SELECT
  54. COUNT(*) AS log_count
  55. FROM
  56. slot
  57. INNER JOIN
  58. site
  59. ON
  60. FK_site = site_id
  61. INNER JOIN
  62. user
  63. ON
  64. FK_owner = user_id
  65. $where";
  66. $r=db_query($query);
  67. $a = db_fetch_assoc($r);
  68. $totalNumSites = $a[log_count];
  69. $query = "
  70. SELECT
  71. COUNT(*) AS log_count
  72. FROM
  73. slot
  74. INNER JOIN
  75. site
  76. ON
  77. FK_site = site_id
  78. INNER JOIN
  79. user
  80. ON
  81. FK_owner = user_id
  82. $where2";
  83. $r=db_query($query);
  84. $a = db_fetch_assoc($r);
  85. $numSites = $a[log_count];
  86. //printpre ($query);
  87. //if (!isset($lowerlimit)) $lowerlimit = 0;
  88. //if ($lowerlimit < 0) $lowerlimit = 0;
  89. //
  90. //$lowerlimit = addslashes($lowerlimit);
  91. //$limit = " limit $lowerlimit,$numPerPage";
  92. if (isset($_REQUEST['lowerlimit']))
  93. $lowerlimit = intval($_REQUEST['lowerlimit']);
  94. else
  95. $lowerlimit = 0;
  96. if ($lowerlimit < 0)
  97. $lowerlimit = 0;
  98. $limit = " limit $lowerlimit,$numPerPage";
  99. $query = "
  100. SELECT
  101. slot_type AS type,
  102. slot_name AS name,
  103. site_title AS title,
  104. site_theme AS theme,
  105. site_updated_tstamp AS editedtimestamp,
  106. site_active AS active,
  107. user_uname AS addedby,
  108. user_fname AS addedbyfull
  109. FROM
  110. slot
  111. INNER JOIN
  112. site
  113. ON
  114. FK_site = site_id
  115. INNER JOIN
  116. user
  117. ON
  118. FK_owner = user_id
  119. $where2$orderby$limit";
  120. $r = db_query($query);
  121. //print $query;
  122. ?>
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  124. <html>
  125. <head>
  126. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  127. <title>Segue: Public Site Listing</title>
  128. <? include("themes/common/logs_css.inc.php"); ?>
  129. <script type="text/javascript">
  130. // <![CDATA[
  131. function changeOrder(order) {
  132. f = document.searchform;
  133. f.order.value=order;
  134. f.submit();
  135. }
  136. // ]]>
  137. </script>
  138. <table width='100%' class='bg'>
  139. <tr><td class='bg'>
  140. <? print $content; ?>
  141. <div align='center' style='font-size: 14px;'><b><? echo $cfg[inst_name] ?> <? echo $site_name?> </b></div><br />
  142. <div align='left' style='font-size: 10px;'>
  143. Included here are all <b>class</b> sites and any other sites that requested to be included in this public listing of
  144. <? echo $cfg[inst_name] ?> sites. These are sorted by those that have been most recently updated.<br />
  145. <i>(Note: not all sites listed here are viewable to all users)</i>
  146. </div>
  147. <br />
  148. <? print "Total active listed Segue sites: ".$totalNumSites ?>
  149. </td></tr>
  150. </table>
  151. <table cellspacing='1' width='100%' id='maintable'>
  152. <tr>
  153. <td colspan='8'>
  154. <table width='100%'>
  155. <tr><td>
  156. <form action='<?echo "$PHP_SELF?$sid"?>' method='post' name='searchform'>
  157. <?
  158. // $r1 = db_query("select distinct type from sites order by type asc");
  159. ?>
  160. <!-- type: <select name='type'>
  161. <option value=''>all -->
  162. <?
  163. //while ($a=db_fetch_assoc($r1))
  164. // print "<option".(($type==$a[type])?" selected":"").">$a[type]\n";
  165. if (true) {
  166. ?>
  167. <!-- </select> -->
  168. site: <input type='text' name='site' size='10' value='<?echo $site ?>' />
  169. title: <input type='text' name='title' size='10' value='<?echo $title ?>' />
  170. user: <input type='text' name='user' size='10' value='<?echo $user ?>' />
  171. <!--
  172. type: <select name='type'>
  173. <option<?=($type=='%')?" selected":""?>>all
  174. <option<?=($type=='class')?" selected":""?>>class
  175. <option<?=($type=='other')?" selected":""?>>other
  176. <option<?=($type=='personal')?" selected":""?>>personal
  177. <option<?=($type=='system')?" selected":""?>>system
  178. </select>
  179. -->
  180. <input type='submit' value='go' />
  181. <input type='submit' name='clear' value='clear' />
  182. <input type='hidden' name='order' value='<? echo $order ?>' />
  183. <? } ?>
  184. </form>
  185. </td>
  186. <td align='right'>
  187. <?
  188. $tpages = ceil($numSites/$numPerPage);
  189. $curr = ceil(($lowerlimit+$numPerPage)/$numPerPage);
  190. $prev = $lowerlimit-$numPerPage;
  191. if ($prev < 0) $prev = 0;
  192. $next = $lowerlimit+$numPerPage;
  193. if ($next >= $numSites) $next = $numSites-$numPerPage;
  194. if ($next < 0) $next = 0;
  195. print "$curr of $tpages ";
  196. // print "(Prev: $prev LL: $lowerlimit Next: $next )";
  197. if ($prev != $lowerlimit)
  198. print "<input type='button' value='&lt;&lt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=$prev&type=$type&user=$user&title=$title&site=$site&order=$order\"' />\n";
  199. if ($next != $lowerlimit && $next > $lowerlimit)
  200. print "<input type='button' value='&gt;&gt;' onclick='window.location=\"$PHP_SELF?$sid&lowerlimit=$next&type=$type&user=$user&title=$title&site=$site&order=$order\"' />\n";
  201. ?>
  202. </td>
  203. </tr>
  204. </table>
  205. </td>
  206. </tr>
  207. <tr>
  208. <?
  209. print "<th><a href=# onclick=\"changeOrder('";
  210. if ($order =='editedtimestamp desc') print "editedtimestamp asc";
  211. else print "editedtimestamp desc";
  212. print "')\" style='color: #000'>Time";
  213. if ($order =='editedtimestamp asc') print " &or;";
  214. if ($order =='editedtimestamp desc') print " &and;";
  215. print "</a></th>";
  216. print "<th><a href=# onclick=\"changeOrder('";
  217. if ($order =='name asc') print "name desc";
  218. else print "name asc";
  219. print "')\" style='color: #000'>Site";
  220. if ($order =='name asc') print " &or;";
  221. if ($order =='name desc') print " &and;";
  222. print "</a></th>";
  223. // print "<th><a href=# onclick=\"changeOrder('";
  224. // if ($order =='active asc') print "active desc";
  225. // else print "active asc";
  226. // print "')\" style='color: #000'>Active";
  227. // if ($order =='active asc') print " &or;";
  228. // if ($order =='active desc') print " &and;";
  229. // print "</a></th>";
  230. print "<th><a href=# onclick=\"changeOrder('";
  231. if ($order =='type asc') print "type desc";
  232. else print "type asc";
  233. print "')\" style='color: #000'>Type";
  234. if ($order =='type asc') print " &or;";
  235. if ($order =='type desc') print " &and;";
  236. print "</a></th>";
  237. /* print "<th><a href=# onclick=\"changeOrder('"; */
  238. /* if ($order =='viewpermissions asc') print "viewpermissions desc"; */
  239. /* else print "viewpermissions asc"; */
  240. /* print "')\" style='color: #000'>View"; */
  241. /* if ($order =='viewpermissions asc') print " &or;"; */
  242. /* if ($order =='viewpermissions desc') print " &and;"; */
  243. /* print "</a></th>"; */
  244. // print "<th><a href=# onclick=\"changeOrder('";
  245. // if ($order =='theme asc') print "theme desc";
  246. // else print "theme asc";
  247. // print "')\" style='color: #000'>Theme";
  248. // if ($order =='theme asc') print " &or;";
  249. // if ($order =='theme desc') print " &and;";
  250. // print "</a></th>";
  251. print "<th><a href=# onclick=\"changeOrder('";
  252. if ($order =='title asc') print "title desc";
  253. else print "title asc";
  254. print "')\" style='color: #000'>Title";
  255. if ($order =='title asc') print " &or;";
  256. if ($order =='title desc') print " &and;";
  257. print "</a></th>";
  258. print "<th><a href=# onclick=\"changeOrder('";
  259. if ($order =='addedby asc') print "addedby desc";
  260. else print "addedby asc";
  261. print "')\" style='color: #000'>Owner";
  262. if ($order =='addedby asc') print " &or;";
  263. if ($order =='addedby desc') print " &and;";
  264. print "</a></th>";
  265. ?>
  266. </tr>
  267. <?
  268. $color = 0;
  269. $today = date(Ymd);
  270. $yesterday = date(Ymd)-1;
  271. if (db_num_rows($r)) {
  272. while ($a=db_fetch_assoc($r)) {
  273. print "<tr>";
  274. print "<td class='td$color'><span style='white-space: nowrap;'>";
  275. if (strncmp($today, $a[editedtimestamp], 8) == 0 || strncmp($yesterday, $a[editedtimestamp], 8) == 0) print "<b>";
  276. print timestamp2usdate($a[editedtimestamp],1);
  277. if (strncmp($today, $a[editedtimestamp], 8) == 0 || strncmp($yesterday, $a[editedtimestamp], 8) == 0) print "</b>";
  278. print "</span>";
  279. print "</td>";
  280. print "<td class='td$color'>$a[name]</td>";
  281. // print "<td class='td$color'><span style='color: #".(($a[active])?"090'>active":"900'>inactive")."</span></td>";
  282. print "<td class='td$color'>".((group::getClassesFromName($a[name]))?"group - ":"")."$a[type]</td>";
  283. /* print "<td class='td$color'><span style='color: #"; */
  284. /* if ($a[viewpermissions] == 'anyone') print "000"; */
  285. /* if ($a[viewpermissions] == 'midd') print "00c"; */
  286. /* if ($a[viewpermissions] == 'class') print "900"; */
  287. /* print "'>$a[viewpermissions]</span></td>"; */
  288. // print "<td class='td$color'>$a[theme]</td>";
  289. print "<td class='td$color'>";
  290. print "<a href='#' onclick='opener.window.location=\"index.php?$sid&action=site&site=$a[name]\"'>";
  291. print stripslashes($a[title]);
  292. print "</a>";
  293. print "</td>";
  294. print "<td class='td$color'>";
  295. print "$a[addedbyfull] ($a[addedby])";
  296. print "</td>";
  297. print "</tr>";
  298. $color = 1-$color;
  299. }
  300. } else {
  301. print "<tr><td colspan='5'>No sites found based on above criteria.</td></tr>";
  302. }
  303. ?>
  304. </table><br />
  305. <div align='right'><input type='button' value='Close Window' onclick='window.close()' /></div>
  306. <?
  307. // debug output -- handy :)
  308. /* print "<pre>"; */
  309. /* print "request:\n"; */
  310. /* print_r($_REQUEST); */
  311. /* print "\n\n"; */
  312. /* print "session:\n"; */
  313. /* print_r($_SESSION); */
  314. /* print "\n\n"; */
  315. /*
  316. if (is_object($thisPage)) {
  317. print "\n\n";
  318. print "thisPage:\n";
  319. print_r($thisPage);
  320. } /*else if (is_object($thisSection)) {
  321. print "\n\n";
  322. print "thisSection:\n";
  323. print_r($thisSection);
  324. } else if (is_object($thisSite)) {
  325. print "\n\n";
  326. print "thisSite:\n";
  327. print_r($thisSite);
  328. } */
  329. /* print "</pre>"; */