PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/php/wanted/index.php

http://sairuk-misc.googlecode.com/
PHP | 447 lines | 330 code | 48 blank | 69 comment | 22 complexity | f233200b0551a34f9d598b424eaf0d3a MD5 | raw file
  1. <?
  2. ########################################################################
  3. # Changelog:
  4. # 20101003 - sairuk
  5. # Added booko search
  6. # Added nzbs.org search
  7. # 20090410 - sairuk
  8. # Moved comments to tootips for titles
  9. # Added asterix to end of title if comment exists
  10. # 20090409 - sairuk
  11. # Fixed the delete function
  12. # 20090401 - sairuk
  13. # Searchs open in new window
  14. # Tweaked buttons
  15. # Added Commennt field for misc use
  16. # Added TvNZB search
  17. # Added Steam search
  18. # RSS feed now valid
  19. # 20090331 - sairuk
  20. # Added Custom searches using the plus symbol
  21. # Added NZBMatrix search
  22. # 20090329 - sairuk
  23. # Added RSS Feed for new items
  24. # 20090328 - sairuk
  25. # Removed Multiple Delete
  26. # Added Multiple Actioned Status
  27. # Added Strikethrough for Actioned in CSS
  28. # Added Deleted after # Days Actioned
  29. # Removed Checkboxes for Actioned Items
  30. # Created MISC CONFIG section
  31. # Created custom searchs, moved custom searchs to own
  32. ### DATABASE
  33. $svr = 'localhost';
  34. $db = 'sai_wanted_lists';
  35. $username = '';
  36. $password = '';
  37. $indpg = 'index.php';
  38. $tblnm = 'wanted';
  39. ### MISC
  40. $tbltl = 'WANTED LIST';
  41. $deldays = '3';
  42. $uri = '';
  43. ########################################################################
  44. //POST VARIABLES
  45. $atitle = $_POST["atitle"];
  46. $atype = $_POST["atype"];
  47. $acomm = $_POST["acomm"];
  48. $adate = date('c');
  49. $dtitle = $_POST["dtitle"];
  50. $i = 0;
  51. //Connect to DB
  52. $con = mysql_connect($svr,$username,$password);
  53. if(!$con)
  54. {
  55. die('Could not connect: ' . mysql_error());
  56. }
  57. mysql_select_db($db, $con);
  58. //Main Table Query
  59. $result = mysql_query("SELECT * FROM ". $tblnm ." ORDER BY Title");
  60. $types = mysql_query("SELECT * FROM Types ORDER BY types");
  61. /*
  62. //Old Multiple Delete Title[s]
  63. if ($dtitle)
  64. {
  65. array_walk($dtitle, 'wrap_each');
  66. $delete_ids = implode(",",$dtitle);
  67. mysql_query("DELETE FROM ". $tblnm ." WHERE Title IN ($delete_ids)");
  68. $dtitle = '';
  69. header('Location: '. $indpg );
  70. }
  71. */
  72. // Newer Mark as Actioned
  73. if ($dtitle)
  74. {
  75. foreach ( $dtitle as &$key ) {
  76. $delDate = date(c, strtotime("+$deldays day", time()));
  77. mysql_query("UPDATE ". $tblnm ." SET Actioned='Y',Compdate='$delDate' WHERE Title='$key' ");
  78. wrtRSSItem($uri,$key,'','COMPLETED','COMPLETED');
  79. }
  80. $dtitle = '';
  81. header('Location: '. $indpg );
  82. }
  83. // Add Title
  84. if ($atitle)
  85. {
  86. $atitle = str_replace("&","and",$atitle);
  87. //Add to DB
  88. mysql_query("INSERT INTO ". $tblnm ." (Title,Comment,Type,Date,Actioned) VALUES ('" . $atitle ."','" . $acomm ."','" . $atype ."','" . $adate ."','N')");
  89. wrtRSSItem($uri,$atitle,$acomm,$atype,'ADDED');
  90. $atitle = '';
  91. header('Location: '. $indpg );
  92. }
  93. // HTML Start Here otherwise will break screen refreshing
  94. ?>
  95. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  96. <html>
  97. <head>
  98. <meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
  99. <title><? echo $tbltl; ?></title>
  100. <style type="text/css">
  101. h2
  102. {
  103. font-family: courier;
  104. font-weight: bold;
  105. font-size: 20px;
  106. }
  107. td
  108. {
  109. white-space:nowrap;
  110. overflow:hidden;
  111. text-align: left;
  112. }
  113. thead
  114. {
  115. background: #AFC7C7;
  116. }
  117. thead td
  118. {
  119. font-weight: bold;
  120. color: #566D7E;
  121. border-width: 1px;
  122. border-style: solid;
  123. border-color: #566D7E;
  124. }
  125. tbody td
  126. {
  127. font-family: helvetica;
  128. font-size: 12px;
  129. padding-left: 4px;
  130. padding-right: 4px;
  131. padding-top: 2px;
  132. }
  133. table
  134. {
  135. table-layout: Fixed;
  136. }
  137. table.tblbrd
  138. {
  139. border-width: 1px;
  140. border-style: solid;
  141. border-color: #566D7E;
  142. }
  143. td.tblbot
  144. {
  145. border-bottom-width: 1px;
  146. border-bottom-style: solid;
  147. border-bottom-color: #566D7E;
  148. }
  149. td.del
  150. {
  151. border-bottom-width: 1px;
  152. border-bottom-style: solid;
  153. border-bottom-color: #566D7E;
  154. text-decoration: line-through;
  155. }
  156. td.itemtitle
  157. {
  158. min-width: 250px;
  159. width: 100%;
  160. }
  161. td.itemdate
  162. {
  163. width: 80px;
  164. }
  165. td.itemsearch
  166. {
  167. width: 100px;
  168. }
  169. td.ralign
  170. {
  171. text-align: right;
  172. padding-right: 3px;
  173. }
  174. input
  175. {
  176. background: #AFC7C7;
  177. }
  178. input.title
  179. {
  180. width: 340px;
  181. background: #AFC7C7;
  182. padding: 1px;
  183. }
  184. select
  185. {
  186. background: #AFC7C7;
  187. }
  188. a
  189. {
  190. color: #566D7E;
  191. text-decoration: none;
  192. }
  193. a:hover
  194. {
  195. color: #566D7E;
  196. text-decoration: underline;
  197. }
  198. </style>
  199. </head>
  200. <body>
  201. <center>
  202. <table class="tblbrd" width="70%" border="0">
  203. <tr>
  204. <td align="center" width="100%">
  205. <form action="<? $indpg; ?>" method="post">
  206. <center>
  207. <table width="100%" border="0">
  208. <tr>
  209. <td>
  210. Title: <input class="title" type="text" name="atitle" title="Input title of item"/>
  211. </td>
  212. <td>
  213. Comment: <input class="title" type="text" name="acomm" title="Input Comments for this item"/>
  214. </td>
  215. <td width="100px">
  216. Type: <select name="atype" title="Select type to Add">
  217. <?
  218. //ComboBox
  219. while($row = mysql_fetch_array($types))
  220. {
  221. if ( $row['types'] == 'Movie' ) {
  222. echo (' <option selected="selected">'.$row['types'].'</option> '."\n");
  223. } else {
  224. echo (' <option value="'.$row['types'].'">'.$row['types'].'</option> '."\n");
  225. }
  226. }
  227. ?>
  228. </select>
  229. </td>
  230. <td width="50px"><center><input type="submit" value="Add" title="Add"/></center></td>
  231. <td width="20px"><center><a href="wanted.rss"><img src="rss.jpg" height="20px" title="Rss Feed for New Items" border="0"/></center></a></td>
  232. <td width="20px"><center><a href="http://mimic/tflux/"><img src="tflux.png" height="20px" title="TorrentFlux-b4rt" border="0"/></a></center></td>
  233. </tr>
  234. </table>
  235. </form>
  236. </td>
  237. </tr>
  238. <tr>
  239. <td colspan="2" align="right">
  240. <form action="<? $indpg; ?>" method="post">
  241. <table border="0" width="100%">
  242. <thead>
  243. <tr>
  244. <td class="itemtitle">Title</td>
  245. <td class="itemdate">Type</td>
  246. <td class="itemdate">Added</td>
  247. <td class="itemsearch"><center>Search</center></td>
  248. <td width="20px"><center>C</center></td>
  249. </tr>
  250. </thead>
  251. <tbody>
  252. <?
  253. while($row = mysql_fetch_array($result))
  254. {
  255. if ( $row['Actioned'] == "Y")
  256. {
  257. $css = 'del';
  258. $candel = 'no';
  259. if ( $adate >= $row['Compdate'] )
  260. {
  261. mysql_query("DELETE FROM ". $tblnm ." WHERE Title='".$row['Title']."' ");
  262. }
  263. } else {
  264. $css = 'tblbot';
  265. $candel = '';
  266. }
  267. if ($row['Comment']) {
  268. $comment = '*';
  269. } else {
  270. $comment = '';
  271. }
  272. echo (' <tr>
  273. <td class="'.$css.'" title="'.$row['Comment'].'">'.$row['Title'].$comment.'</td>
  274. <td class="'.$css.'">'.$row['Type'].'</td>
  275. <td class="'.$css.'">'.$row['Date'].'</td>
  276. <td class="'.$css.'">'.srch_items($row['Title'],$row['Type']).'</td>
  277. ');
  278. if (!$candel) {
  279. echo ('
  280. <td><input type="checkbox" name="dtitle[]" size="60" value="'.$row['Title'].'" title="Select Item"/></td>
  281. </tr>
  282. ');
  283. } else {
  284. echo ('
  285. <td><center><abbr title="Completed">Y</abbr></center></td>
  286. </tr>
  287. ');
  288. }
  289. }
  290. ?>
  291. </tbody>
  292. <tfoot>
  293. <tr>
  294. <td colspan="6">
  295. <table width="100%" border="0">
  296. <td>&nbsp;</a></td>
  297. <td class="ralign" width="400px"><i>COMPLETED</i> items remain listed for <? echo $deldays ?> days</td>
  298. <td width="80px" colspan="2"><input type="submit" value="Completed" align="top" title="Mark Completed"/></td>
  299. </table>
  300. </td>
  301. </tr>
  302. </tfoot>
  303. </table>
  304. </form>
  305. </tr>
  306. </td>
  307. </tr>
  308. </table>
  309. </center>
  310. </body>
  311. </html>
  312. <?
  313. mysql_close($con);
  314. function wrap_each(&$item)
  315. {
  316. $item = "'$item'";
  317. }
  318. function srch_items($stitle,$stype)
  319. {
  320. ### QUOTATIONS
  321. $ebaysrch = '<a href="http://shop.ebay.com.au/?&_nkw=%22'. $stitle .'%22&_sacat=See-All-Categories" title="eBay" target="_blank">e</a>';
  322. $tnbsrch = '<a href="http://www.thenile.com.au/search.php?&s=%22'. $stitle .'%22" title="The Nile Bookshop" target="_blank">tN</a>';
  323. $stitle = preg_replace('/\s/','+',$stitle);
  324. ### PLUS SYMBOL
  325. $iphsrch = '<a href="http://iphonexe.com/apps/search.php?query='. $stitle .'&x=0&y=0" title="iPhoneEXE" target="_blank">iP</a>';
  326. $tvsrch = '<a href="http://www.tvnzb.com/index.php?st=&t='. $stitle .'" title="TvNZB" target="_blank">tv</a>';
  327. $ensrch = '<a href="http://members.easynews.com/global4/search.html?gps='. $stitle .'" title="EasyNews" target="_blank">E</a>';
  328. $googsrch = '<a href="http://www.google.com.au/search?q=%22'. $stitle .'%22" title="Google" target="_blank">G</a>';
  329. $nzbmsrch = '<a href="http://nzbmatrix.com/nzb-search.php?search='. $stitle .'&cat=0" title="NZBMatrix" target="_blank">nM</a>';
  330. $stmsrch = '<a href="http://store.steampowered.com/search/?term='. $stitle.' title="Steam" target="_blank">St</a>';
  331. $imdbsrch = '<a href="http://www.imdb.com/find?s=all&q='. $stitle.'&x=0&y=0" title="IMDb" target="_blank">i</a>';
  332. $vcqsrch = '<a href="http://www.vcdq.com/index.php?genre=5&searchstring='. $stitle .'&x=0&y=0" title="VCD Quality" target="_blank">V</a>';
  333. $nzborg = '<a href="http://www.nzbs.org/index.php?action=search&q='. $stitle .'&catid=0&age=" title="NZBorg" target="_blank">nZ</a>';
  334. $bookob = '<a href="http://www.booko.com.au/books/search?q='. $stitle .'&commit=Search&product_type=1" title="Booko Books" target="_blank">bB</a>';
  335. $bookod = '<a href="http://www.booko.com.au/books/search?q='. $stitle .'&commit=Search&product_type=2" title="Booko Booko DVDs" target="_blank">bD</a>';
  336. switch($stype)
  337. {
  338. case "Movie":
  339. $itemsrch = $ensrch.'|'.$nzborg.'|'.$vcqsrch.'|'.$googsrch.'|'.$imdbsrch.'|'.$ebaysrch;
  340. break;
  341. case "iPhone":
  342. $itemsrch = $ensrch.'|'.$googsrch.'|'.$iphsrch;
  343. break;
  344. case "Book":
  345. $itemsrch = $ensrch.'|'.$nzborg.'|'.$bookob.'|'.$googsrch.'|'.$ebaysrch.'|'.$tnbsrch;
  346. break;
  347. case "Steam":
  348. $itemsrch = $stmsrch.'|'.$googsrch;
  349. break;
  350. case "TV":
  351. $itemsrch = $ensrch.'|'.$tvsrch.'|'.$nzborg.'|'.$googsrch.'|'.$imdbsrch.'|'.$ebaysrch;
  352. break;
  353. default:
  354. $itemsrch = $ensrch.'|'.$googsrch.'|'.$ebaysrch;
  355. }
  356. return($itemsrch);
  357. }
  358. function addRSSItem($rssFile, $firstItem, $item)
  359. {
  360. if(!copy($rssFile, 'temp.rss')) die ('Backup Failed');
  361. $arrFile = file($rssFile);
  362. if(($fh = fopen($rssFile, 'w')) === 'FALSE') die ('Couldnt open '.$rssFile.' for writing');
  363. /*
  364. // Needs to be written to a new file at some point
  365. <?xml version="1.0" encoding="utf-8"?>
  366. <rss version="2.0">
  367. <channel>
  368. <title>The title of my RSS 2.0 Feed</title>
  369. <link>http://www.example.com/</link>
  370. <description>This is my rss 2 feed description</description>
  371. <lastBuildDate>Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate>
  372. <language>en-us</language>
  373. </channel>
  374. </rss>
  375. */
  376. $currLine = 0;
  377. $endLine = count($arrFile);
  378. while ($currLine <= $endLine)
  379. {
  380. if($currLine == $firstItem) fwrite($fh, $item);
  381. fwrite($fh, $arrFile[$currLine]);
  382. $currLine++;
  383. }
  384. unlink('temp.rss');
  385. }
  386. function wrtRSSItem($uri, $atitle, $acomm, $atype, $status) {
  387. //Add to RSS Feed
  388. $rssdate = date('r');
  389. $rssguid = $uri . '/' . preg_replace('/\s/','+',$atitle);
  390. $data = " <item>\n<title>[$status] - $atitle</title>\n".
  391. " <description>$acomm</description>\n".
  392. " <pubDate>$rssdate</pubDate>\n".
  393. " <link>$uri</link>\n".
  394. " <guid>$rssguid.$status</guid>\n".
  395. " </item>\n";
  396. addRSSItem('/var/www/wanted/wanted.rss',8,$data);
  397. }
  398. ?>